@datadog/flagging-core

中文文档
3.4.0发布于 2026/10/30Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2550.7万

Runtime-agnostic flag-evaluation logic for Datadog Flagging

原始使用文档
文档目录4 节
  1. Configuration parsing entry points
  2. Preparing activation timestamps
  3. Adding a public entry point
  4. End-user license agreement

Datadog OpenFeature Core Library

Configuration parsing entry points

The default @datadog/flagging-core entry point parses precomputed configuration without loading the protobuf decoder. To parse both precomputed and rules-based configuration, opt into the full parser:

import { configurationFromString, configurationToString } from '@datadog/flagging-core/rules-based'

The /rules-based entry point is available through both the package's exports map and a physical rules-based/package.json for resolvers that do not support package exports:

  • Modern resolvers use the existing modular CommonJS/ESM implementations.
  • Legacy resolvers use self-contained CommonJS/ESM compatibility bundles generated from the same source during yarn build / package preparation. These include the required protobuf code, so consumers do not have to resolve its /wire or /codegenv2 subpaths.
  • Both paths expose the same API and reuse the same TypeScript declarations. The default entry point stays modular and does not import the compatibility bundles or protobuf decoder.

The compatibility bundles increase the npm package size, but only applications using the legacy rules-based entry point include them in their application bundle. They retain dependency copyright/license notices and source maps, and are left unminified for the application bundler to optimize.

The packed-package smoke test covers Android and iOS bundles with Metro package exports both enabled and disabled, including legacy CommonJS and ESM resolution. It executes those bundles in Node without BigInt, TextEncoder, or TextDecoder; this checks fallback behavior but does not replace execution tests on an actual Hermes or JavaScriptCore runtime.

Preparing activation timestamps

Rules configurations are snapshots. The protobuf decoder prepares randomization activation timestamps once, and the Node provider prepares JSON configurations in setConfiguration. Invalid activation marks only the affected flag as a parse error, regardless of opt-out mode. Evaluation compares the prepared seconds and fractional seconds without reparsing the timestamp; using a JavaScript Date here would lose the nanosecond precision needed at the opt-out cutoff.

Direct JSON core consumers can call prepareUniversalFlagConfiguration(configuration) when receiving configuration. Existing low-level evaluation calls still accept raw configurations and prepare each flag once on first use. Replace changed flags instead of mutating prepared flags in place. Preparation does not change the serialized configuration.

Adding a public entry point

packages/core/package.json exports is the single source of truth for public paths. To add @datadog/flagging-core/foo:

  1. Create src/foo.ts with the intended exports. Keep any required initialization in this source entry point, rather than adding it to a bundler-specific list.

  2. Add its modern mapping to exports:

    {
      "./foo": {
        "types": "./cjs/foo.d.ts",
        "import": "./esm/foo.js",
        "require": "./cjs/foo.js",
        "default": "./esm/foo.js"
      }
    }
    
  3. Run yarn workspace @datadog/flagging-core build and commit the generated metadata with the source change. Add the feature's behavior tests as usual.

The build generates the physical fallback manifests, publish-file list, legacy declaration mappings, and compatibility-bundle side-effect entries. It discovers and builds a CJS/ESM compatibility bundle for every public JavaScript subpath automatically. Do not edit those fallback manifests or register new paths in the Webpack configuration or smoke fixtures.

Concrete nested subpaths are supported; wildcard exports and mismatched CJS/ESM/type targets fail with an actionable error. Removing a path from exports and rebuilding removes its owned fallback manifest and derived metadata without deleting unrelated files.

yarn check:entrypoints checks generated metadata without changing files. CI runs it before building, and prepack checks it before packing so a stale publish-file list cannot silently omit a new entry point. The packed-package tests discover every declared path and generate static imports for the full Metro matrix. The default entry point remains separate and light.

End-user license agreement

https://www.datadoghq.com/legal/eula

版本与发布记录

@datadog/flagging-core 共发布 51 个版本,首次发布于 2025/07/15;过去 12 个月发布了 23 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.4.0latest2026/10/3012 天前
3.3.02026/10/2814 天前
3.2.02026/10/101 个月前
3.1.12026/09/261 个月前
3.1.02026/09/241 个月前
3.0.12026/09/221 个月前

其他发布通道:alpha → 0.1.0-preview.2,preview → 0.1.0-preview.14。

关于 @datadog/flagging-core 的常见问题

@datadog/flagging-core 是什么?

Runtime-agnostic flag-evaluation logic for Datadog Flagging

如何安装 @datadog/flagging-core?

在项目目录运行 npm install @datadog/flagging-core,或使用 pnpm add / yarn add / bun add。

@datadog/flagging-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@datadog/flagging-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@datadog/flagging-core 可以商用吗?

@datadog/flagging-core 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@datadog/flagging-core 的下载量有多少?

根据 npm 官方下载统计,@datadog/flagging-core 在 2026/10/12 – 2026/11/10 这 30 天内被下载 25,506,992 次,日均约 850,233 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@datadog/flagging-core 还在维护吗?

最新版本 3.4.0 发布于 2026/10/30(12 天前);至今共发布 51 个版本,其中过去 12 个月发布了 23 个;首次发布于 2025/07/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。