Update plugin signature

This commit is contained in:
Michael Jackson 2019-01-23 16:03:27 -08:00
parent c5ada301e1
commit 6228f0de5c
2 changed files with 8 additions and 9 deletions

View File

@ -1,8 +1,6 @@
import URL from 'whatwg-url';
import warning from 'warning';
import { origin } from '../config';
const bareIdentifierFormat = /^((?:@[^/]+\/)?[^/]+)(\/.*)?$/;
function isValidURL(value) {
@ -21,7 +19,7 @@ function isBareIdentifier(value) {
return value.charAt(0) !== '.' && value.charAt(0) !== '/';
}
function rewriteValue(/* StringLiteral */ node, dependencies) {
function rewriteValue(/* StringLiteral */ node, origin, dependencies) {
if (isAbsoluteURL(node.value)) {
return;
}
@ -47,7 +45,7 @@ function rewriteValue(/* StringLiteral */ node, dependencies) {
}
}
export default function unpkgRewrite(dependencies = {}) {
export default function unpkgRewrite(origin, dependencies = {}) {
return {
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push(
@ -65,10 +63,10 @@ export default function unpkgRewrite(dependencies = {}) {
return;
}
rewriteValue(path.node.arguments[0], dependencies);
rewriteValue(path.node.arguments[0], origin, dependencies);
},
ExportAllDeclaration(path) {
return rewriteValue(path.node.source, dependencies);
rewriteValue(path.node.source, origin, dependencies);
},
ExportNamedDeclaration(path) {
if (!path.node.source) {
@ -80,10 +78,10 @@ export default function unpkgRewrite(dependencies = {}) {
return;
}
rewriteValue(path.node.source, dependencies);
rewriteValue(path.node.source, origin, dependencies);
},
ImportDeclaration(path) {
return rewriteValue(path.node.source, dependencies);
rewriteValue(path.node.source, origin, dependencies);
}
}
};

View File

@ -1,5 +1,6 @@
import babel from '@babel/core';
import { origin } from '../config';
import unpkgRewrite from '../plugins/unpkgRewrite';
export default function rewriteBareModuleIdentifiers(code, packageConfig) {
@ -14,7 +15,7 @@ export default function rewriteBareModuleIdentifiers(code, packageConfig) {
// because we haven't installed dependencies so
// we can't load plugins; see #84
babelrc: false,
plugins: [unpkgRewrite(dependencies)]
plugins: [unpkgRewrite(origin, dependencies)]
};
return babel.transform(code, options).code;