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 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);
} }
} }
}; };

View File

@ -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;