forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-deps.js
70 lines (61 loc) · 1.75 KB
/
check-deps.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
const dependencyCheck = require('dependency-check')
const path = require('path')
// [start-readme]
//
// This script checks which modules you have used in your code and then makes sure
// they are listed as dependencies in your package.json, or vice-versa
//
// https://github.com/dependency-check-team/dependency-check
//
// The `ignore` array is for client-side or build-time stuff that doesn't get `require()d` in the normal way.
//
// [end-readme]
const main = async () => {
const data = await dependencyCheck({
entries: [
path.posix.join(__dirname, '..', '*', '*.js'),
path.posix.join('!', __dirname, '..', 'javascripts', '*.js'),
path.posix.join(__dirname, '..', 'script', 'graphql', '*.js')
],
path: path.join(__dirname, '..'),
noDefaultEntries: true
})
const extra = dependencyCheck.extra(data.package, data.used, {
excludeDev: true,
ignore: [
'@babel/*',
'@primer/*',
'instantsearch.js',
'querystring',
'pa11y-ci',
'sass',
'babel-loader',
'cross-env',
'css-loader',
'resolve-url-loader',
'sass-loader',
'style-loader',
'webpack-cli',
'browser-date-formatter',
'html-truncate',
'platform-utils',
'search-with-your-keyboard',
'uuid',
'imurmurhash',
'js-cookie'
]
})
if (extra.length) {
console.error(`Packages in package.json not used in your code: ${extra.join(', ')}`)
}
const missing = dependencyCheck.missing(data.package, data.used)
if (missing.length) {
console.error(`Dependencies not listed in package.json: ${missing.join(', ')}`)
}
if (extra.length || missing.length) process.exit(1)
}
main().catch(err => {
console.error(err)
process.exit(1)
})