[babel 8] Remove module-specific options from @babel/core (#12724)
This commit is contained in:
parent
6b39bafab6
commit
8e8954b470
@ -98,17 +98,19 @@ commander.option(
|
||||
"The root from which all sources are relative.",
|
||||
);
|
||||
|
||||
// Config params for certain module output formats.
|
||||
commander.option(
|
||||
"--module-root [filename]",
|
||||
// eslint-disable-next-line max-len
|
||||
"Optional prefix for the AMD module formatter that will be prepended to the filename on module definitions.",
|
||||
);
|
||||
commander.option("-M, --module-ids", "Insert an explicit id for modules.");
|
||||
commander.option(
|
||||
"--module-id [string]",
|
||||
"Specify a custom name for module ids.",
|
||||
);
|
||||
if (!process.env.BABEL_8_BREAKING) {
|
||||
// Config params for certain module output formats.
|
||||
commander.option(
|
||||
"--module-root [filename]",
|
||||
// eslint-disable-next-line max-len
|
||||
"Optional prefix for the AMD module formatter that will be prepended to the filename on module definitions.",
|
||||
);
|
||||
commander.option("-M, --module-ids", "Insert an explicit id for modules.");
|
||||
commander.option(
|
||||
"--module-id [string]",
|
||||
"Specify a custom name for module ids.",
|
||||
);
|
||||
}
|
||||
|
||||
// "babel" command specific arguments that are not passed to @babel/core.
|
||||
commander.option(
|
||||
@ -277,9 +279,6 @@ export default function parseArgv(args: Array<string>): CmdOptions | null {
|
||||
sourceMaps: opts.sourceMaps,
|
||||
sourceFileName: opts.sourceFileName,
|
||||
sourceRoot: opts.sourceRoot,
|
||||
moduleRoot: opts.moduleRoot,
|
||||
moduleIds: opts.moduleIds,
|
||||
moduleId: opts.moduleId,
|
||||
|
||||
// Commander will default the "--no-" arguments to true, but we want to
|
||||
// leave them undefined so that @babel/core can handle the
|
||||
@ -289,6 +288,15 @@ export default function parseArgv(args: Array<string>): CmdOptions | null {
|
||||
comments: opts.comments === true ? undefined : opts.comments,
|
||||
};
|
||||
|
||||
if (!process.env.BABEL_8_BREAKING) {
|
||||
// $FlowIgnore
|
||||
Object.assign(babelOptions, {
|
||||
moduleRoot: opts.moduleRoot,
|
||||
moduleIds: opts.moduleIds,
|
||||
moduleId: opts.moduleId,
|
||||
});
|
||||
}
|
||||
|
||||
// If the @babel/cli version is newer than the @babel/core version, and we have added
|
||||
// new options for @babel/core, we'll potentially get option validation errors from
|
||||
// @babel/core. To avoid that, we delete undefined options, so @babel/core will only
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
"@babel/code-frame": "workspace:^7.12.13",
|
||||
"@babel/generator": "workspace:^7.13.9",
|
||||
"@babel/helper-compilation-targets": "workspace:^7.13.13",
|
||||
"@babel/helper-module-transforms": "workspace:^7.13.12",
|
||||
"@babel/helper-module-transforms": "condition:BABEL_8_BREAKING ? : workspace:^7.13.12",
|
||||
"@babel/helpers": "workspace:^7.13.10",
|
||||
"@babel/parser": "workspace:^7.13.13",
|
||||
"@babel/template": "workspace:^7.12.13",
|
||||
|
||||
@ -173,18 +173,6 @@ const COMMON_VALIDATORS: ValidatorSet = {
|
||||
sourceRoot: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "sourceRoot">,
|
||||
>),
|
||||
getModuleId: (assertFunction: Validator<
|
||||
$PropertyType<ValidatedOptions, "getModuleId">,
|
||||
>),
|
||||
moduleRoot: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "moduleRoot">,
|
||||
>),
|
||||
moduleIds: (assertBoolean: Validator<
|
||||
$PropertyType<ValidatedOptions, "moduleIds">,
|
||||
>),
|
||||
moduleId: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "moduleId">,
|
||||
>),
|
||||
parserOpts: (assertObject: Validator<
|
||||
$PropertyType<ValidatedOptions, "parserOpts">,
|
||||
>),
|
||||
@ -192,6 +180,15 @@ const COMMON_VALIDATORS: ValidatorSet = {
|
||||
$PropertyType<ValidatedOptions, "generatorOpts">,
|
||||
>),
|
||||
};
|
||||
if (!process.env.BABEL_8_BREAKING) {
|
||||
Object.assign(COMMON_VALIDATORS, {
|
||||
getModuleId: assertFunction,
|
||||
moduleRoot: assertString,
|
||||
moduleIds: assertBoolean,
|
||||
moduleId: assertString,
|
||||
});
|
||||
}
|
||||
|
||||
export type InputOptions = ValidatedOptions;
|
||||
|
||||
export type ValidatedOptions = {
|
||||
@ -253,12 +250,6 @@ export type ValidatedOptions = {
|
||||
sourceFileName?: string,
|
||||
sourceRoot?: string,
|
||||
|
||||
// AMD/UMD/SystemJS module naming options.
|
||||
getModuleId?: Function,
|
||||
moduleRoot?: string,
|
||||
moduleIds?: boolean,
|
||||
moduleId?: string,
|
||||
|
||||
// Deprecate top level parserOpts
|
||||
parserOpts?: {},
|
||||
// Deprecate top level generatorOpts
|
||||
|
||||
@ -13,9 +13,9 @@ export default function normalizeOptions(config: ResolvedConfig): {} {
|
||||
sourceType = "module",
|
||||
inputSourceMap,
|
||||
sourceMaps = !!inputSourceMap,
|
||||
|
||||
moduleRoot,
|
||||
sourceRoot = moduleRoot,
|
||||
sourceRoot = process.env.BABEL_8_BREAKING
|
||||
? undefined
|
||||
: config.options.moduleRoot,
|
||||
|
||||
sourceFileName = path.basename(filenameRelative),
|
||||
|
||||
|
||||
@ -44,11 +44,14 @@ export default class PluginPass {
|
||||
return this.file.addImport();
|
||||
}
|
||||
|
||||
getModuleName(): ?string {
|
||||
return this.file.getModuleName();
|
||||
}
|
||||
|
||||
buildCodeFrameError(node: ?NodeLocation, msg: string, Error?: typeof Error) {
|
||||
return this.file.buildCodeFrameError(node, msg, Error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!process.env.BABEL_8_BREAKING) {
|
||||
// $FlowIgnore
|
||||
PluginPass.prototype.getModuleName = function getModuleName(): ?string {
|
||||
return this.file.getModuleName();
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,21 +1,51 @@
|
||||
type RootOptions = {
|
||||
filename?: string;
|
||||
filenameRelative?: string;
|
||||
sourceRoot?: string;
|
||||
};
|
||||
|
||||
type PluginOptions = {
|
||||
moduleId?: string;
|
||||
moduleIds?: boolean;
|
||||
getModuleId?: (moduleName: string) => string | null | undefined;
|
||||
moduleRoot?: string;
|
||||
};
|
||||
|
||||
if (!process.env.BABEL_8_BREAKING) {
|
||||
const originalGetModuleName = getModuleName;
|
||||
|
||||
// @ts-expect-error TS doesn't like reassigning a function.
|
||||
// eslint-disable-next-line no-func-assign
|
||||
getModuleName = function getModuleName(
|
||||
rootOpts: RootOptions & PluginOptions,
|
||||
pluginOpts: PluginOptions,
|
||||
): string | null {
|
||||
return originalGetModuleName(rootOpts, {
|
||||
moduleId: pluginOpts.moduleId ?? rootOpts.moduleId,
|
||||
moduleIds: pluginOpts.moduleIds ?? rootOpts.moduleIds,
|
||||
getModuleId: pluginOpts.getModuleId ?? rootOpts.getModuleId,
|
||||
moduleRoot: pluginOpts.moduleRoot ?? rootOpts.moduleRoot,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default function getModuleName(
|
||||
rootOpts: any,
|
||||
pluginOpts: any,
|
||||
): string | undefined | null {
|
||||
rootOpts: RootOptions,
|
||||
pluginOpts: PluginOptions,
|
||||
): string | null {
|
||||
const {
|
||||
filename,
|
||||
filenameRelative = filename,
|
||||
|
||||
sourceRoot = pluginOpts.moduleRoot ?? rootOpts.moduleRoot,
|
||||
sourceRoot = pluginOpts.moduleRoot,
|
||||
} = rootOpts;
|
||||
|
||||
const {
|
||||
moduleId = rootOpts.moduleId,
|
||||
moduleIds = rootOpts.moduleIds ?? !!moduleId,
|
||||
moduleId,
|
||||
moduleIds = !!moduleId,
|
||||
|
||||
getModuleId = rootOpts.getModuleId,
|
||||
getModuleId,
|
||||
|
||||
moduleRoot = rootOpts.moduleRoot ?? sourceRoot,
|
||||
moduleRoot = sourceRoot,
|
||||
} = pluginOpts;
|
||||
|
||||
if (!moduleIds) return null;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"plugins": [["transform-modules-amd", { "loose": true }]]
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name",
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
"my custom module name": "foo.bar"
|
||||
},
|
||||
"exactGlobals": true,
|
||||
"loose": true
|
||||
"loose": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
]
|
||||
],
|
||||
"moduleId": "my custom module name"
|
||||
]
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
"my custom module name": "foo.bar.baz.qux"
|
||||
},
|
||||
"exactGlobals": true,
|
||||
"loose": true
|
||||
"loose": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
]
|
||||
],
|
||||
"moduleId": "my custom module name"
|
||||
]
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
"my custom module name": "baz"
|
||||
},
|
||||
"exactGlobals": true,
|
||||
"loose": true
|
||||
"loose": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
]
|
||||
],
|
||||
"moduleId": "my custom module name"
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleId": "MyLib",
|
||||
"plugins": [["transform-modules-umd", { "loose": true }]]
|
||||
"plugins": [["transform-modules-umd", { "loose": true, "moduleId": "MyLib" }]]
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"plugins": [["transform-modules-umd", { "loose": true }]]
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"plugins": [
|
||||
[
|
||||
"transform-modules-umd",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
"globals": {
|
||||
"my custom module name": "foo.bar"
|
||||
},
|
||||
"exactGlobals": true
|
||||
"exactGlobals": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
]
|
||||
],
|
||||
"moduleId": "my custom module name"
|
||||
]
|
||||
}
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
"globals": {
|
||||
"my custom module name": "foo.bar.baz.qux"
|
||||
},
|
||||
"exactGlobals": true
|
||||
"exactGlobals": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
]
|
||||
],
|
||||
"moduleId": "my custom module name"
|
||||
]
|
||||
}
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
"globals": {
|
||||
"my custom module name": "baz"
|
||||
},
|
||||
"exactGlobals": true
|
||||
"exactGlobals": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
]
|
||||
],
|
||||
"moduleId": "my custom module name"
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleId": "MyLib"
|
||||
"plugins": [["transform-modules-umd", { "moduleId": "MyLib" }]]
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"sourceType": "module",
|
||||
"moduleIds": true
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"plugins": [
|
||||
[
|
||||
"transform-modules-umd",
|
||||
|
||||
41
yarn.lock
41
yarn.lock
@ -204,7 +204,7 @@ __metadata:
|
||||
"@babel/code-frame": "workspace:^7.12.13"
|
||||
"@babel/generator": "workspace:^7.13.9"
|
||||
"@babel/helper-compilation-targets": "workspace:^7.13.13"
|
||||
"@babel/helper-module-transforms": "workspace:^7.13.12"
|
||||
"@babel/helper-module-transforms": "condition:BABEL_8_BREAKING ? : workspace:^7.13.12"
|
||||
"@babel/helper-transform-fixture-test-runner": "workspace:*"
|
||||
"@babel/helpers": "workspace:^7.13.10"
|
||||
"@babel/parser": "workspace:^7.13.13"
|
||||
@ -639,6 +639,30 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-module-transforms-BABEL_8_BREAKING-false@npm:@babel/helper-module-transforms@workspace:^7.13.12, @babel/helper-module-transforms@workspace:^7.13.0, @babel/helper-module-transforms@workspace:packages/babel-helper-module-transforms":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/helper-module-transforms@workspace:packages/babel-helper-module-transforms"
|
||||
dependencies:
|
||||
"@babel/helper-module-imports": "workspace:^7.13.12"
|
||||
"@babel/helper-replace-supers": "workspace:^7.13.12"
|
||||
"@babel/helper-simple-access": "workspace:^7.13.12"
|
||||
"@babel/helper-split-export-declaration": "workspace:^7.12.13"
|
||||
"@babel/helper-validator-identifier": "workspace:^7.12.11"
|
||||
"@babel/template": "workspace:^7.12.13"
|
||||
"@babel/traverse": "workspace:^7.13.0"
|
||||
"@babel/types": "workspace:^7.13.12"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-module-transforms@condition:BABEL_8_BREAKING ? : workspace:^7.13.12":
|
||||
version: 0.0.0-condition-130862
|
||||
resolution: "@babel/helper-module-transforms@condition:BABEL_8_BREAKING?:workspace:^7.13.12#130862"
|
||||
dependencies:
|
||||
"@babel/helper-module-transforms-BABEL_8_BREAKING-false": "npm:@babel/helper-module-transforms@workspace:^7.13.12"
|
||||
checksum: 099f985d9558228aa29430a51630015ea02a47f2714cc392f0105921e768c4998a70686942c51defe174cd5ed9f221ab0e4505a611f40e7a68158748c4bbfb8e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-module-transforms@npm:^7.12.1, @babel/helper-module-transforms@npm:^7.12.13, @babel/helper-module-transforms@npm:^7.13.0":
|
||||
version: 7.13.0
|
||||
resolution: "@babel/helper-module-transforms@npm:7.13.0"
|
||||
@ -656,21 +680,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-module-transforms@workspace:^7.13.0, @babel/helper-module-transforms@workspace:^7.13.12, @babel/helper-module-transforms@workspace:packages/babel-helper-module-transforms":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/helper-module-transforms@workspace:packages/babel-helper-module-transforms"
|
||||
dependencies:
|
||||
"@babel/helper-module-imports": "workspace:^7.13.12"
|
||||
"@babel/helper-replace-supers": "workspace:^7.13.12"
|
||||
"@babel/helper-simple-access": "workspace:^7.13.12"
|
||||
"@babel/helper-split-export-declaration": "workspace:^7.12.13"
|
||||
"@babel/helper-validator-identifier": "workspace:^7.12.11"
|
||||
"@babel/template": "workspace:^7.12.13"
|
||||
"@babel/traverse": "workspace:^7.13.0"
|
||||
"@babel/types": "workspace:^7.13.12"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-optimise-call-expression@npm:^7.12.13":
|
||||
version: 7.12.13
|
||||
resolution: "@babel/helper-optimise-call-expression@npm:7.12.13"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user