Skip to content

Commit 3c2b829

Browse files
authored
Add CLI support to set Feature Flag values (#9554)
Add `--feature-flag` support to the CLI for overriding feature flag defaults.
1 parent 56e5f40 commit 3c2b829

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/core/parcel/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@parcel/core": "2.12.0",
2626
"@parcel/diagnostic": "2.12.0",
2727
"@parcel/events": "2.12.0",
28+
"@parcel/feature-flags": "2.12.0",
2829
"@parcel/fs": "2.12.0",
2930
"@parcel/logger": "2.12.0",
3031
"@parcel/package-manager": "2.12.0",

packages/core/parcel/src/cli.js

+26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import commander from 'commander';
1212
import path from 'path';
1313
import getPort from 'get-port';
1414
import {version} from '../package.json';
15+
import {DEFAULT_FEATURE_FLAGS} from '@parcel/feature-flags';
1516

1617
const program = new commander.Command();
1718

@@ -103,6 +104,30 @@ const commonOptions = {
103104
},
104105
[],
105106
],
107+
'--feature-flag <name=value>': [
108+
'sets the value of a feature flag',
109+
(value, previousValue) => {
110+
let [name, val] = value.split('=');
111+
if (name in DEFAULT_FEATURE_FLAGS) {
112+
let featureFlagValue;
113+
if (typeof DEFAULT_FEATURE_FLAGS[name] === 'boolean') {
114+
if (val !== 'true' && val !== 'false') {
115+
throw new Error(
116+
`Feature flag ${name} must be set to true or false`,
117+
);
118+
}
119+
featureFlagValue = val;
120+
}
121+
previousValue[name] = featureFlagValue ?? String(val);
122+
} else {
123+
INTERNAL_ORIGINAL_CONSOLE.warn(
124+
`Unknown feature flag ${name} specified, it will be ignored`,
125+
);
126+
}
127+
return previousValue;
128+
},
129+
{},
130+
],
106131
};
107132

108133
var hmrOptions = {
@@ -509,5 +534,6 @@ async function normalizeOptions(
509534
publicUrl: command.publicUrl,
510535
distDir: command.distDir,
511536
},
537+
featureFlags: command.featureFlag,
512538
};
513539
}

0 commit comments

Comments
 (0)