2019-01-06 00:50:05 +00:00
|
|
|
import babel from '@babel/core';
|
2018-09-04 22:58:52 +00:00
|
|
|
|
2019-01-24 00:03:27 +00:00
|
|
|
import { origin } from '../config';
|
2019-01-06 00:50:05 +00:00
|
|
|
import unpkgRewrite from '../plugins/unpkgRewrite';
|
2018-09-04 22:58:52 +00:00
|
|
|
|
2019-01-06 00:50:05 +00:00
|
|
|
export default function rewriteBareModuleIdentifiers(code, packageConfig) {
|
2018-09-04 22:58:52 +00:00
|
|
|
const dependencies = Object.assign(
|
|
|
|
{},
|
|
|
|
packageConfig.peerDependencies,
|
|
|
|
packageConfig.dependencies
|
|
|
|
);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
// Ignore .babelrc and package.json babel config
|
|
|
|
// because we haven't installed dependencies so
|
|
|
|
// we can't load plugins; see #84
|
|
|
|
babelrc: false,
|
2019-01-24 00:03:27 +00:00
|
|
|
plugins: [unpkgRewrite(origin, dependencies)]
|
2018-09-04 22:58:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return babel.transform(code, options).code;
|
|
|
|
}
|