Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI support to set Feature Flag values #9554

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/parcel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@parcel/core": "2.12.0",
"@parcel/diagnostic": "2.12.0",
"@parcel/events": "2.12.0",
"@parcel/feature-flags": "2.12.0",
"@parcel/fs": "2.12.0",
"@parcel/logger": "2.12.0",
"@parcel/package-manager": "2.12.0",
Expand Down
26 changes: 26 additions & 0 deletions packages/core/parcel/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import commander from 'commander';
import path from 'path';
import getPort from 'get-port';
import {version} from '../package.json';
import {DEFAULT_FEATURE_FLAGS} from '@parcel/feature-flags';

const program = new commander.Command();

Expand Down Expand Up @@ -103,6 +104,30 @@ const commonOptions = {
},
[],
],
'--feature-flag <name=value>': [
'sets the value of a feature flag',
(value, previousValue) => {
let [name, val] = value.split('=');
if (name in DEFAULT_FEATURE_FLAGS) {
let featureFlagValue;
if (typeof DEFAULT_FEATURE_FLAGS[name] === 'boolean') {
if (val !== 'true' && val !== 'false') {
throw new Error(
`Feature flag ${name} must be set to true or false`,
);
}
featureFlagValue = val;
}
previousValue[name] = featureFlagValue ?? String(val);
} else {
INTERNAL_ORIGINAL_CONSOLE.warn(
`Unknown feature flag ${name} specified, it will be ignored`,
);
}
return previousValue;
},
{},
],
};

var hmrOptions = {
Expand Down Expand Up @@ -509,5 +534,6 @@ async function normalizeOptions(
publicUrl: command.publicUrl,
distDir: command.distDir,
},
featureFlags: command.featureFlag,
};
}
Loading