-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
41 lines (33 loc) · 797 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import path from 'path';
import { rollup } from 'rollup';
import * as acorn from 'acorn';
import virtual from '@rollup/plugin-virtual';
export async function check(input) {
const resolved = path.resolve(input);
const bundle = await rollup({
input: '__agadoo__',
plugins: [
virtual({
__agadoo__: `import ${JSON.stringify(resolved)}`
})
],
onwarn: (warning, handle) => {
if (warning.code !== 'EMPTY_BUNDLE') handle(warning);
}
});
const result = await bundle.generate({
format: 'esm'
});
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: nodes.length === 0
};
}