Allow @foo/babel-plugin as an unexpanded plugin name, and @foo as a shorthand for it.
This commit is contained in:
parent
5895277b32
commit
add5f8d0fe
@ -15,8 +15,9 @@ const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-plugin-)/;
|
|||||||
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-preset-)/;
|
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-preset-)/;
|
||||||
const BABEL_PLUGIN_ORG_RE = /^(@babel\/)(?!plugin-|[^/]+\/)/;
|
const BABEL_PLUGIN_ORG_RE = /^(@babel\/)(?!plugin-|[^/]+\/)/;
|
||||||
const BABEL_PRESET_ORG_RE = /^(@babel\/)(?!preset-|[^/]+\/)/;
|
const BABEL_PRESET_ORG_RE = /^(@babel\/)(?!preset-|[^/]+\/)/;
|
||||||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-plugin-|[^/]+\/)/;
|
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-plugin(?:-|\/|$)|[^/]+\/)/;
|
||||||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-preset-|[^/]+\/)/;
|
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?!babel-preset(?:-|\/|$)|[^/]+\/)/;
|
||||||
|
const OTHER_ORG_DEFAULT_RE = /^(@(?!babel$)[^/]+)$/;
|
||||||
|
|
||||||
export function resolvePlugin(name: string, dirname: string): string | null {
|
export function resolvePlugin(name: string, dirname: string): string | null {
|
||||||
return resolveStandardizedName("plugin", name, dirname);
|
return resolveStandardizedName("plugin", name, dirname);
|
||||||
@ -80,6 +81,8 @@ function standardizeName(type: "plugin" | "preset", name: string) {
|
|||||||
isPreset ? OTHER_PRESET_ORG_RE : OTHER_PLUGIN_ORG_RE,
|
isPreset ? OTHER_PRESET_ORG_RE : OTHER_PLUGIN_ORG_RE,
|
||||||
`$1babel-${type}-`,
|
`$1babel-${type}-`,
|
||||||
)
|
)
|
||||||
|
// @foo -> @foo/babel-preset
|
||||||
|
.replace(OTHER_ORG_DEFAULT_RE, `$1/babel-${type}`)
|
||||||
// module:mypreset -> mypreset
|
// module:mypreset -> mypreset
|
||||||
.replace(EXACT_RE, "")
|
.replace(EXACT_RE, "")
|
||||||
);
|
);
|
||||||
|
|||||||
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/babel-plugin/index.js
generated
vendored
Normal file
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/babel-plugin/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function() {
|
||||||
|
return {};
|
||||||
|
};
|
||||||
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/babel-preset/index.js
generated
vendored
Normal file
3
packages/babel-core/test/fixtures/resolution/foo-org-paths/node_modules/@foo/babel-preset/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function() {
|
||||||
|
return {};
|
||||||
|
};
|
||||||
@ -154,6 +154,66 @@ describe("addon resolution", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should find @foo/babel-plugin when specified", function() {
|
||||||
|
process.chdir("foo-org-paths");
|
||||||
|
|
||||||
|
babel.transform("", {
|
||||||
|
filename: "filename.js",
|
||||||
|
babelrc: false,
|
||||||
|
plugins: ["@foo/babel-plugin"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should find @foo/babel-preset when specified", function() {
|
||||||
|
process.chdir("foo-org-paths");
|
||||||
|
|
||||||
|
babel.transform("", {
|
||||||
|
filename: "filename.js",
|
||||||
|
babelrc: false,
|
||||||
|
presets: ["@foo/babel-preset"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should find @foo/babel-plugin/index when specified", function() {
|
||||||
|
process.chdir("foo-org-paths");
|
||||||
|
|
||||||
|
babel.transform("", {
|
||||||
|
filename: "filename.js",
|
||||||
|
babelrc: false,
|
||||||
|
plugins: ["@foo/babel-plugin/index"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should find @foo/babel-preset/index when specified", function() {
|
||||||
|
process.chdir("foo-org-paths");
|
||||||
|
|
||||||
|
babel.transform("", {
|
||||||
|
filename: "filename.js",
|
||||||
|
babelrc: false,
|
||||||
|
presets: ["@foo/babel-preset/index"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should find @foo/babel-plugin when just scope given", function() {
|
||||||
|
process.chdir("foo-org-paths");
|
||||||
|
|
||||||
|
babel.transform("", {
|
||||||
|
filename: "filename.js",
|
||||||
|
babelrc: false,
|
||||||
|
plugins: ["@foo"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should find @foo/babel-preset when just scope given", function() {
|
||||||
|
process.chdir("foo-org-paths");
|
||||||
|
|
||||||
|
babel.transform("", {
|
||||||
|
filename: "filename.js",
|
||||||
|
babelrc: false,
|
||||||
|
presets: ["@foo"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should find relative path presets", function() {
|
it("should find relative path presets", function() {
|
||||||
process.chdir("relative-paths");
|
process.chdir("relative-paths");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user