@exodus/feature-flags

中文文档
6.5.0发布于 2026/10/10MITTypeScriptES Module近 30 天下载 1.1万

Module for monitoring/controlling the currently available features based on remoteConfig, device geolocation, etc

原始使用文档
文档目录10 节
  1. Usage
  2. background
  3. UI-side
  4. Gradual rollout
  5. Usage examples without @exodus/headless
  6. Components
  7. remoteConfigFeatureFlagAtoms
  8. featureFlagAtoms
  9. featureFlagsAtom
  10. featureFlags

@exodus/feature-flags

Modules and atoms for monitoring/controlling the currently available features based on remoteConfig, device geolocation, etc. See also @exodus/feature-control.

Usage

We recommend you use this feature via @exodus/headless, as follows in the below example:

  1. Specify your feature flags when configuring the @exodus/headless instance.
  2. Consume/control feature flags:
  • In your modules/atoms/plugins/features, use the featureFlagAtoms dependency.
  • In the UI:
    • Use the selectors.featureFlags.create(featureFlagName) selector to read the current flag value.
    • Use exodus.featureFlags.enable(featureFlagName) and exodus.featureFlags.disable(featureFlagName) if you need to toggle the flag value at runtime.

See example code below.

background

import createExodus from '@exodus/headless'

const featureFlags = {
  // ... other feature flags,
  dogeMode: {
    localDefaults: {
      // `true` if feature is shipped (available at runtime), `false` otherwise
      available: true,
      // controls whether the feature is enabled by default
      // NOTE: if `available` is false, `enabled` can NOT be true, or you can expect an error
      enabled: true,
    },
    remoteConfig: {
      // path to flag in remote config schema
      path: 'features.dogeMode',
      supportedOverrides: {
        // can be enabled/disabled for all users via remote config
        enabled: true,
        // can be enabled/disabled for users in certain geolocations via remote config
        geolocation: true,
        // can be enabled/disabled for users on certain app versions via remote config
        shutdownSemver: true,
        // can be rolled out to a share of users via remote config, see "Gradual rollout"
        rollout: true,
      },
    },
  },
}

const exodusContainer = createExodus({
  port,
  adapters,
  config: {
    // ...,
    featureFlags,
  },
})

const checkDogeModePlugin = {
  id: 'checkDogeModePlugin',
  factory: ({ featureFlagAtoms }) => {
    const onStart = () => {
      featureFlagAtoms.dogeMode?.get().then(({ isOn }) => {
        console.log('>>> is dogeMode enabled?', isOn)
      })
    }

    return {
      onStart,
    }
  },
  dependencies: ['featureFlagAtoms'],
}

exodusContainer.register({
  definition: checkDogeModePlugin,
})

const exodus = exodusContainer.resolve()
// ... continue as usual

UI-side

import selectors from '~/ui/flux/selectors'

const dogeModeFeatureName = 'dogeMode'

const HomePage = () => {
  const dogeMode = useSelector(selectors.featureFlags.create(dogeModeFeatureName))
  useEffect(() => {
    if (Math.random() < 0.001) {
      exodus.featureFlags.enable(dogeModeFeatureName)
    }
  }, [dogeMode])

  return dogeMode?.isOn ? <DogeMode /> : <NormalMode />
}

Gradual rollout

With supportedOverrides.rollout, set rollout in remote config to an integer from 0 to 100:

{ "features": { "dogeMode": { "enabled": true, "rollout": 10 } } }

Each user gets a bucket from 0 to 99: sha256(featureName + ":" + telemetryId), first 4 bytes, mod 100. The flag is on when the bucket is less than rollout. Thus:

  • A user stays in the same cohort when you increase rollout, and on all devices with the same seed.
  • Each flag has an independent cohort.
  • Renaming the flag gives new cohorts.
  • An invalid rollout value turns the flag off.
  • The flag keeps its local default until the wallet is unlocked, because telemetryId comes from the seed.

Rollout requires the analyticsUserIdAtom dependency (from @exodus/analytics).

Usage examples without @exodus/headless

See the examples folder

Components

remoteConfigFeatureFlagAtoms

An atom collection { [featureName]: atom }, where each atom emits the current remote-config value for that feature flag:

{
  isOn: Boolean,
  unavailableStatus: ?String
}

featureFlagAtoms

An atom collection { [featureName]: atom }, where each atom emits the current status of its feature flag:

{
  isOn: Boolean,
  unavailableStatus: ?String
}

featureFlagsAtom

An atom that emits the current status of all feature flags as an object map:

{
  [featureName]: {
    isOn: Boolean,
    unavailableStatus: ?String
  }
}

featureFlags

Module that overrides local values for feature flags based on remoteConfig and geolocation. It writes values to atoms in featureFlagAtoms, but it might be easier to observe the aggregate feature flags atom featureFlagsAtom.

版本与发布记录

@exodus/feature-flags 共发布 30 个版本,首次发布于 2023/01/21;过去 12 个月发布了 8 个版本。

版本发布日期距今
6.5.0latest2026/10/101 个月前
6.4.12026/07/084 个月前
6.4.02026/07/074 个月前
6.3.22026/05/285 个月前
6.3.12026/05/265 个月前
6.3.02026/05/096 个月前

关于 @exodus/feature-flags 的常见问题

@exodus/feature-flags 是什么?

Module for monitoring/controlling the currently available features based on remoteConfig, device geolocation, etc

如何安装 @exodus/feature-flags?

在项目目录运行 npm install @exodus/feature-flags,或使用 pnpm add / yarn add / bun add。

@exodus/feature-flags 支持 TypeScript 吗?

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

@exodus/feature-flags 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@exodus/feature-flags 可以商用吗?

@exodus/feature-flags 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/feature-flags 的下载量有多少?

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

@exodus/feature-flags 还在维护吗?

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