Skip to content

Commit

Permalink
ignore external imports - fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 2, 2020
1 parent ce85e39 commit a182c69
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const { rollup } = require('rollup');
const acorn = require('acorn');
const virtual = require('rollup-plugin-virtual');

exports.check = input => {
Expand All @@ -18,10 +19,21 @@ exports.check = input => {
}).then(bundle => bundle.generate({
format: 'esm'
})).then(result => {
console.log(result.output[0].code);
const { code } = result.output[0];

const ast = acorn.parse(code, {
ecmaVersion: 11,
sourceType: 'module'
});

const nodes = ast.body.filter(node => {
return node.type !== 'ImportDeclaration';
});

console.log(code);

return {
shaken: result.output[0].code.trim() === ''
shaken: nodes.length === 0
};
});
};
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"homepage": "https://github.com/Rich-Harris/agadoo#readme",
"dependencies": {
"acorn": "^7.1.0",
"rollup": "^1",
"rollup-plugin-virtual": "^1.0.1"
},
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const c = require('kleur');
const child_process = require('child_process');

const exec = cmd => new Promise((fulfil, reject) => {
child_process.exec(cmd, err => {
child_process.exec(cmd, (err, stdout, stderr) => {
if (err) {
reject(err);
} else {
Expand Down Expand Up @@ -49,9 +49,9 @@ async function main() {

try {
await exec(`agadoo`);
failed = true;
console.log(`${c.bold().red('✗')} ${dir}`);
} catch (err) {
failed = true;
console.log(`${c.bold().green('✓')} ${dir}`);
}
}
Expand Down
1 change: 1 addition & 0 deletions test/pass/external-imports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit a182c69

Please sign in to comment.