diff --git a/src/__tests__/__snapshots__/preval.test.js.snap b/src/__tests__/__snapshots__/preval.test.js.snap index c64a807ba..af4f883ac 100644 --- a/src/__tests__/__snapshots__/preval.test.js.snap +++ b/src/__tests__/__snapshots__/preval.test.js.snap @@ -407,7 +407,7 @@ CSS: ; } -Dependencies: NA +Dependencies: core-js/modules/es6.string.raw `; diff --git a/src/babel/evaluate.js b/src/babel/evaluate.js index 3d6466d84..44c2ac241 100644 --- a/src/babel/evaluate.js +++ b/src/babel/evaluate.js @@ -107,41 +107,6 @@ module.exports = function evaluate( }); } - // Collect the list of dependencies that we import - const dependencies = requirements.reduce((deps, req) => { - if (t.isImportDeclaration(req.path.parentPath)) { - deps.push(req.path.parentPath.node.source.value); - } else { - req.path.traverse({ - CallExpression(p) { - const { callee, arguments: args } = p.node; - - let name; - - if (callee.name === 'require' && args.length === 1) { - if ( - args[0].type === 'Literal' || - args[0].type === 'StringLiteral' - ) { - name = args[0].value; - } else if ( - args[0].type === 'TemplateLiteral' && - args[0].quasis.length === 1 - ) { - name = args[0].quasis[0].value.cooked; - } - } - - if (name) { - deps.push(name); - } - }, - }); - } - - return deps; - }, []); - const expression = t.expressionStatement( t.assignmentExpression( '=', @@ -182,6 +147,7 @@ module.exports = function evaluate( const m = new Module(filename); + m.dependencies = []; m.transform = typeof transformer !== 'undefined' ? transformer @@ -278,6 +244,6 @@ module.exports = function evaluate( return { value: m.exports, - dependencies, + dependencies: ((m.dependencies: any): string[]), }; }; diff --git a/src/babel/module.js b/src/babel/module.js index e8a844817..39695914c 100644 --- a/src/babel/module.js +++ b/src/babel/module.js @@ -81,6 +81,8 @@ class Module { extensions: string[]; + dependencies: ?(string[]); + transform: ?(text: string) => { code: string }; constructor(filename: string) { @@ -159,6 +161,8 @@ class Module { ); } + this.dependencies && this.dependencies.push(id); + let m = cache[filename]; if (!m) {