@parcel/feature-flags 2.12.1-dev.3238 → 2.12.1-dev.3262
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.js +14 -2
- package/lib/types.d.ts +7 -0
- package/package.json +2 -2
- package/src/index.js +11 -0
- package/src/types.js +6 -0
- package/test/feature-flags.test.js +21 -0
package/lib/index.js
CHANGED
@@ -4,8 +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
|
-
exampleFeature: false
|
11
|
-
|
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,4 +1,11 @@
|
|
1
1
|
export type FeatureFlags = {
|
2
2
|
// This feature flag mostly exists to test the feature flag system, and doesn't have any build/runtime effect
|
3
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;
|
4
11
|
};
|
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.3262+8b1749694",
|
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": "
|
27
|
+
"gitHead": "8b1749694c0ef79cefdacad40bb90c869a93993a"
|
28
28
|
}
|
package/src/index.js
CHANGED
@@ -7,4 +7,15 @@ 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
CHANGED
@@ -3,4 +3,10 @@
|
|
3
3
|
export type FeatureFlags = {|
|
4
4
|
// This feature flag mostly exists to test the feature flag system, and doesn't have any build/runtime effect
|
5
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,
|
6
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
|
+
});
|