UNPKG

1.31 kBJavaScriptView Raw
1// @ts-check
2const depcheck = require('depcheck');
3const path = require('path');
4
5const check = new Promise((resolve, reject) => {
6 depcheck(
7 path.join(__dirname, '..'),
8 {
9 ignoreDirs: ['test-fixtures'], ignoreMatches: [
10 // "@types/*" dependencies are type declarations that are
11 // automatically loaded by TypeScript during build. depcheck can't
12 // detect this so we ignore them here.
13
14 '@types/*',
15 // Also it can't yet parse files that use async iteration.
16 // TODO(rictic): remove these
17 'mz',
18 'multipipe',
19 'polymer-bundler',
20 'parse5',
21 'dom5',
22 '@babel/traverse',
23 'stream',
24 'html-minifier',
25 '@polymer/esm-amd-loader',
26 'babel-plugin-minify-guarded-expressions',
27 ]
28 },
29 resolve);
30 })
31 .then((result) => {
32 const invalidFiles = Object.keys(result.invalidFiles) || [];
33 const invalidJsFiles = invalidFiles.filter((f) => f.endsWith('.js'));
34
35 const unused = new Set(result.dependencies);
36 if (unused.size > 0) {
37 console.log('Unused dependencies:', unused);
38 throw new Error('Unused dependencies');
39 }
40 });
41
42check.catch((e) => {
43 console.error(e);
44 process.exit(1);
45});