@parcel/feature-flags 2.12.1-dev.3151 → 2.12.1-dev.3185
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.js +16 -2
- package/lib/types.d.ts +11 -0
- package/lib/types.js +1 -0
- package/package.json +7 -3
- package/src/index.js +15 -4
- package/src/types.js +12 -0
- package/test/feature-flags.test.js +21 -0
package/lib/index.js
CHANGED
@@ -4,6 +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;
|
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
|
+
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
ADDED
@@ -0,0 +1,11 @@
|
|
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
|
+
* 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;
|
11
|
+
};
|
package/lib/types.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/feature-flags",
|
3
|
-
"version": "2.12.1-dev.
|
3
|
+
"version": "2.12.1-dev.3185+298c035e0",
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
5
5
|
"license": "MIT",
|
6
6
|
"publishConfig": {
|
@@ -16,9 +16,13 @@
|
|
16
16
|
},
|
17
17
|
"main": "lib/index.js",
|
18
18
|
"source": "src/index.js",
|
19
|
-
"types": "
|
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": "
|
27
|
+
"gitHead": "298c035e0ffb82d7c5579ce233cc35dce2fe1061"
|
24
28
|
}
|
package/src/index.js
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
// @flow strict
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
+
configKeyInvalidation: false,
|
10
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
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
+
* 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,
|
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
|
+
});
|