Skip to content

Commit

Permalink
Support Babel shorthand presets/plugins from scoped packages with def…
Browse files Browse the repository at this point in the history
…ault prefix

Babel name normalization docs: https://babeljs.io/docs/options#name-normalization
  • Loading branch information
miluoshi committed Jun 19, 2023
1 parent db82f29 commit a92dd68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/special/babel.js
Expand Up @@ -34,6 +34,11 @@ function contain(array, dep, prefix, babelScope) {

const fullPrefix = scope ? `${scope}/${prefix}` : prefix;

// Support scoped plugin/preset with default name, e.g. preset with name '@scope' uses '@scope/babel-preset' dep
if (fullPrefix.endsWith('-') && dep === fullPrefix.slice(0, -1)) {
return true;
}

if (prefix && dep.indexOf(fullPrefix) === 0) {
const identifier = dep.substring(fullPrefix.length);
return contain(array, scope ? `${scope}/${identifier}` : identifier, false);
Expand Down
14 changes: 14 additions & 0 deletions test/special/babel.js
Expand Up @@ -54,6 +54,13 @@ const testCases = [
},
{
name: 'recognize the scoped short-name plugin',
deps: ['@scope/babel-plugin'],
options: {
plugins: ['@scope'],
},
},
{
name: 'recognize the scoped short-name plugin with custom suffix',
deps: ['@scope/babel-plugin-syntax-jsx'],
options: {
plugins: ['@scope/syntax-jsx'],
Expand All @@ -75,6 +82,13 @@ const testCases = [
},
{
name: 'recognize the scoped short-name preset',
deps: ['@scope/babel-preset'],
options: {
presets: ['@scope'],
},
},
{
name: 'recognize the scoped short-name preset with custom suffix',
deps: ['@scope/babel-preset-es2015'],
options: {
presets: ['@scope/es2015'],
Expand Down

0 comments on commit a92dd68

Please sign in to comment.