Update plugin signature
This commit is contained in:
parent
c5ada301e1
commit
6228f0de5c
|
@ -1,8 +1,6 @@
|
||||||
import URL from 'whatwg-url';
|
import URL from 'whatwg-url';
|
||||||
import warning from 'warning';
|
import warning from 'warning';
|
||||||
|
|
||||||
import { origin } from '../config';
|
|
||||||
|
|
||||||
const bareIdentifierFormat = /^((?:@[^/]+\/)?[^/]+)(\/.*)?$/;
|
const bareIdentifierFormat = /^((?:@[^/]+\/)?[^/]+)(\/.*)?$/;
|
||||||
|
|
||||||
function isValidURL(value) {
|
function isValidURL(value) {
|
||||||
|
@ -21,7 +19,7 @@ function isBareIdentifier(value) {
|
||||||
return value.charAt(0) !== '.' && value.charAt(0) !== '/';
|
return value.charAt(0) !== '.' && value.charAt(0) !== '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
function rewriteValue(/* StringLiteral */ node, dependencies) {
|
function rewriteValue(/* StringLiteral */ node, origin, dependencies) {
|
||||||
if (isAbsoluteURL(node.value)) {
|
if (isAbsoluteURL(node.value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +45,7 @@ function rewriteValue(/* StringLiteral */ node, dependencies) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function unpkgRewrite(dependencies = {}) {
|
export default function unpkgRewrite(origin, dependencies = {}) {
|
||||||
return {
|
return {
|
||||||
manipulateOptions(opts, parserOpts) {
|
manipulateOptions(opts, parserOpts) {
|
||||||
parserOpts.plugins.push(
|
parserOpts.plugins.push(
|
||||||
|
@ -65,10 +63,10 @@ export default function unpkgRewrite(dependencies = {}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewriteValue(path.node.arguments[0], dependencies);
|
rewriteValue(path.node.arguments[0], origin, dependencies);
|
||||||
},
|
},
|
||||||
ExportAllDeclaration(path) {
|
ExportAllDeclaration(path) {
|
||||||
return rewriteValue(path.node.source, dependencies);
|
rewriteValue(path.node.source, origin, dependencies);
|
||||||
},
|
},
|
||||||
ExportNamedDeclaration(path) {
|
ExportNamedDeclaration(path) {
|
||||||
if (!path.node.source) {
|
if (!path.node.source) {
|
||||||
|
@ -80,10 +78,10 @@ export default function unpkgRewrite(dependencies = {}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewriteValue(path.node.source, dependencies);
|
rewriteValue(path.node.source, origin, dependencies);
|
||||||
},
|
},
|
||||||
ImportDeclaration(path) {
|
ImportDeclaration(path) {
|
||||||
return rewriteValue(path.node.source, dependencies);
|
rewriteValue(path.node.source, origin, dependencies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import babel from '@babel/core';
|
import babel from '@babel/core';
|
||||||
|
|
||||||
|
import { origin } from '../config';
|
||||||
import unpkgRewrite from '../plugins/unpkgRewrite';
|
import unpkgRewrite from '../plugins/unpkgRewrite';
|
||||||
|
|
||||||
export default function rewriteBareModuleIdentifiers(code, packageConfig) {
|
export default function rewriteBareModuleIdentifiers(code, packageConfig) {
|
||||||
|
@ -14,7 +15,7 @@ export default function rewriteBareModuleIdentifiers(code, packageConfig) {
|
||||||
// because we haven't installed dependencies so
|
// because we haven't installed dependencies so
|
||||||
// we can't load plugins; see #84
|
// we can't load plugins; see #84
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
plugins: [unpkgRewrite(dependencies)]
|
plugins: [unpkgRewrite(origin, dependencies)]
|
||||||
};
|
};
|
||||||
|
|
||||||
return babel.transform(code, options).code;
|
return babel.transform(code, options).code;
|
||||||
|
|
Loading…
Reference in New Issue