@parcel/feature-flags 2.12.1-dev.3171 → 2.12.1-dev.3186

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.js CHANGED
@@ -4,9 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DEFAULT_FEATURE_FLAGS = void 0;
7
+ exports.getFeatureFlag = getFeatureFlag;
8
+ exports.setFeatureFlags = setFeatureFlags;
7
9
  // We need to do these gymnastics as we don't want flow-to-ts to touch DEFAULT_FEATURE_FLAGS,
8
10
  // but we want to export FeatureFlags for Flow
9
11
  const DEFAULT_FEATURE_FLAGS = exports.DEFAULT_FEATURE_FLAGS = {
10
- yarnWatcher: false,
11
- exampleFeature: false
12
- };
12
+ exampleFeature: false,
13
+ configKeyInvalidation: false
14
+ };
15
+ let featureFlagValues = {
16
+ ...DEFAULT_FEATURE_FLAGS
17
+ };
18
+ function setFeatureFlags(flags) {
19
+ featureFlagValues = flags;
20
+ }
21
+ function getFeatureFlag(flagName) {
22
+ return featureFlagValues[flagName];
23
+ }
package/lib/types.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  export type FeatureFlags = {
2
- readonly yarnWatcher: boolean;
3
2
  // This feature flag mostly exists to test the feature flag system, and doesn't have any build/runtime effect
4
3
  readonly exampleFeature: boolean;
4
+
5
+ /**
6
+ * Enables content hash based invalidation for config keys used in plugins.
7
+ * This allows Assets not to be invalidated when using
8
+ * `config.getConfigFrom(..., {packageKey: '...'})` and the value itself hasn't changed.
9
+ */
10
+ readonly configKeyInvalidation: boolean;
5
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/feature-flags",
3
- "version": "2.12.1-dev.3171+79b158883",
3
+ "version": "2.12.1-dev.3186+2449643f7",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -24,5 +24,5 @@
24
24
  "engines": {
25
25
  "node": ">= 16.0.0"
26
26
  },
27
- "gitHead": "79b158883170daac9cd17bdecfebff163bc99e52"
27
+ "gitHead": "2449643f7b1774d2e9f8c4bd13d6fa8ac66f23e6"
28
28
  }
package/src/index.js CHANGED
@@ -6,6 +6,16 @@ import type {FeatureFlags as _FeatureFlags} from './types';
6
6
  export type FeatureFlags = _FeatureFlags;
7
7
 
8
8
  export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
9
- yarnWatcher: false,
10
9
  exampleFeature: false,
10
+ configKeyInvalidation: false,
11
11
  };
12
+
13
+ let featureFlagValues: FeatureFlags = {...DEFAULT_FEATURE_FLAGS};
14
+
15
+ export function setFeatureFlags(flags: FeatureFlags) {
16
+ featureFlagValues = flags;
17
+ }
18
+
19
+ export function getFeatureFlag(flagName: $Keys<FeatureFlags>): boolean {
20
+ return featureFlagValues[flagName];
21
+ }
package/src/types.js CHANGED
@@ -1,7 +1,12 @@
1
1
  // @flow strict
2
2
 
3
3
  export type FeatureFlags = {|
4
- +yarnWatcher: boolean,
5
4
  // This feature flag mostly exists to test the feature flag system, and doesn't have any build/runtime effect
6
5
  +exampleFeature: boolean,
6
+ /**
7
+ * Enables content hash based invalidation for config keys used in plugins.
8
+ * This allows Assets not to be invalidated when using
9
+ * `config.getConfigFrom(..., {packageKey: '...'})` and the value itself hasn't changed.
10
+ */
11
+ +configKeyInvalidation: boolean,
7
12
  |};
@@ -0,0 +1,21 @@
1
+ // @flow strict
2
+ import assert from 'assert';
3
+ import {getFeatureFlag, DEFAULT_FEATURE_FLAGS, setFeatureFlags} from '../src';
4
+
5
+ describe('feature-flag test', () => {
6
+ beforeEach(() => {
7
+ setFeatureFlags(DEFAULT_FEATURE_FLAGS);
8
+ });
9
+
10
+ it('has defaults', () => {
11
+ assert.equal(
12
+ getFeatureFlag('exampleFeature'),
13
+ DEFAULT_FEATURE_FLAGS.exampleFeature,
14
+ );
15
+ });
16
+
17
+ it('can override', () => {
18
+ setFeatureFlags({...DEFAULT_FEATURE_FLAGS, exampleFeature: true});
19
+ assert.equal(getFeatureFlag('exampleFeature'), true);
20
+ });
21
+ });