@parcel/feature-flags 2.12.1-nightly.3142 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.js CHANGED
@@ -4,6 +4,21 @@ 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;
9
+ // We need to do these gymnastics as we don't want flow-to-ts to touch DEFAULT_FEATURE_FLAGS,
10
+ // but we want to export FeatureFlags for Flow
7
11
  const DEFAULT_FEATURE_FLAGS = exports.DEFAULT_FEATURE_FLAGS = {
8
- exampleFeature: false
9
- };
12
+ exampleFeature: false,
13
+ useWatchmanWatcher: false,
14
+ importRetry: false
15
+ };
16
+ let featureFlagValues = {
17
+ ...DEFAULT_FEATURE_FLAGS
18
+ };
19
+ function setFeatureFlags(flags) {
20
+ featureFlagValues = flags;
21
+ }
22
+ function getFeatureFlag(flagName) {
23
+ return featureFlagValues[flagName];
24
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export type FeatureFlags = {
2
+ // This feature flag mostly exists to test the feature flag system, and doesn't have any build/runtime effect
3
+ readonly exampleFeature: boolean;
4
+
5
+ /**
6
+ * Use node.js implementation of @parcel/watcher watchman backend
7
+ */
8
+ readonly useWatchmanWatcher: boolean;
9
+
10
+ /**
11
+ * Configure runtime to enable retriable dynamic imports
12
+ */
13
+ importRetry: boolean;
14
+ };
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@parcel/feature-flags",
3
- "version": "2.12.1-nightly.3142+40c370f09",
4
- "description": "Blazing fast, zero configuration web application bundler",
3
+ "version": "2.13.0",
4
+ "description": "Provides internal feature-flags for the parcel codebase.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -16,9 +16,13 @@
16
16
  },
17
17
  "main": "lib/index.js",
18
18
  "source": "src/index.js",
19
- "types": "index.d.ts",
19
+ "types": "lib/types.d.ts",
20
+ "scripts": {
21
+ "build-ts": "mkdir -p lib && flow-to-ts src/types.js > lib/types.d.ts",
22
+ "check-ts": "tsc --noEmit lib/types.d.ts"
23
+ },
20
24
  "engines": {
21
25
  "node": ">= 16.0.0"
22
26
  },
23
- "gitHead": "40c370f09a1c4b7eee5a6ad2b1b74fb95a04f389"
27
+ "gitHead": "a53f8f3ba1025c7ea8653e9719e0a61ef9717079"
24
28
  }
package/src/index.js CHANGED
@@ -1,10 +1,22 @@
1
1
  // @flow strict
2
2
 
3
- export type FeatureFlags = {|
4
- // This feature flag mostly exists to test the feature flag system, and doesn't have any build/runtime effect
5
- +exampleFeature: boolean,
6
- |};
3
+ import type {FeatureFlags as _FeatureFlags} from './types';
4
+ // We need to do these gymnastics as we don't want flow-to-ts to touch DEFAULT_FEATURE_FLAGS,
5
+ // but we want to export FeatureFlags for Flow
6
+ export type FeatureFlags = _FeatureFlags;
7
7
 
8
8
  export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
9
9
  exampleFeature: false,
10
+ useWatchmanWatcher: false,
11
+ importRetry: false,
10
12
  };
13
+
14
+ let featureFlagValues: FeatureFlags = {...DEFAULT_FEATURE_FLAGS};
15
+
16
+ export function setFeatureFlags(flags: FeatureFlags) {
17
+ featureFlagValues = flags;
18
+ }
19
+
20
+ export function getFeatureFlag(flagName: $Keys<FeatureFlags>): boolean {
21
+ return featureFlagValues[flagName];
22
+ }
package/src/types.js ADDED
@@ -0,0 +1,14 @@
1
+ // @flow strict
2
+
3
+ export type FeatureFlags = {|
4
+ // This feature flag mostly exists to test the feature flag system, and doesn't have any build/runtime effect
5
+ +exampleFeature: boolean,
6
+ /**
7
+ * Use node.js implementation of @parcel/watcher watchman backend
8
+ */
9
+ +useWatchmanWatcher: boolean,
10
+ /**
11
+ * Configure runtime to enable retriable dynamic imports
12
+ */
13
+ importRetry: boolean,
14
+ |};
@@ -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
+ });