use depcheck (#841)
* use depcheck to replace our own check-dependencies script * ignore packges used in npm scripts
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- 'node'
|
- 'node'
|
||||||
install: npm install standard
|
install: npm install standard depcheck
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
var fs = require('fs')
|
|
||||||
var cp = require('child_process')
|
|
||||||
|
|
||||||
// We can't use `builtin-modules` here since our TravisCI
|
|
||||||
// setup expects this file to run with no dependencies
|
|
||||||
var BUILT_IN_NODE_MODULES = [
|
|
||||||
'assert',
|
|
||||||
'buffer',
|
|
||||||
'child_process',
|
|
||||||
'cluster',
|
|
||||||
'console',
|
|
||||||
'constants',
|
|
||||||
'crypto',
|
|
||||||
'dgram',
|
|
||||||
'dns',
|
|
||||||
'domain',
|
|
||||||
'events',
|
|
||||||
'fs',
|
|
||||||
'http',
|
|
||||||
'https',
|
|
||||||
'module',
|
|
||||||
'net',
|
|
||||||
'os',
|
|
||||||
'path',
|
|
||||||
'process',
|
|
||||||
'punycode',
|
|
||||||
'querystring',
|
|
||||||
'readline',
|
|
||||||
'repl',
|
|
||||||
'stream',
|
|
||||||
'string_decoder',
|
|
||||||
'timers',
|
|
||||||
'tls',
|
|
||||||
'tty',
|
|
||||||
'url',
|
|
||||||
'util',
|
|
||||||
'v8',
|
|
||||||
'vm',
|
|
||||||
'zlib'
|
|
||||||
]
|
|
||||||
|
|
||||||
var BUILT_IN_ELECTRON_MODULES = [ 'electron' ]
|
|
||||||
|
|
||||||
var BUILT_IN_DEPS = [].concat(BUILT_IN_NODE_MODULES, BUILT_IN_ELECTRON_MODULES)
|
|
||||||
|
|
||||||
var EXECUTABLE_DEPS = [
|
|
||||||
'babel-cli',
|
|
||||||
'babel-plugin-syntax-jsx',
|
|
||||||
'babel-plugin-transform-es2015-destructuring',
|
|
||||||
'babel-plugin-transform-object-rest-spread',
|
|
||||||
'babel-plugin-transform-react-jsx',
|
|
||||||
'gh-release',
|
|
||||||
'nodemon',
|
|
||||||
'standard'
|
|
||||||
]
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
||||||
// Scans codebase for missing or unused dependencies. Exits with code 0 on success.
|
|
||||||
function main () {
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
console.error('Sorry, check-deps only works on Mac and Linux')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var usedDeps = findUsedDeps()
|
|
||||||
var packageDeps = findPackageDeps()
|
|
||||||
|
|
||||||
var missingDeps = usedDeps.filter(
|
|
||||||
(dep) => !includes(packageDeps, dep) && !includes(BUILT_IN_DEPS, dep)
|
|
||||||
)
|
|
||||||
var unusedDeps = packageDeps.filter(
|
|
||||||
(dep) => !includes(usedDeps, dep) && !includes(EXECUTABLE_DEPS, dep)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (missingDeps.length > 0) {
|
|
||||||
console.error('Missing package dependencies: ' + missingDeps)
|
|
||||||
}
|
|
||||||
if (unusedDeps.length > 0) {
|
|
||||||
console.error('Unused package dependencies: ' + unusedDeps)
|
|
||||||
}
|
|
||||||
if (missingDeps.length + unusedDeps.length > 0) {
|
|
||||||
process.exitCode = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds all dependencies specified in `package.json`
|
|
||||||
function findPackageDeps () {
|
|
||||||
var pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
|
|
||||||
|
|
||||||
var deps = Object.keys(pkg.dependencies)
|
|
||||||
var devDeps = Object.keys(pkg.devDependencies)
|
|
||||||
var optionalDeps = Object.keys(pkg.optionalDependencies)
|
|
||||||
|
|
||||||
return [].concat(deps, devDeps, optionalDeps)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds all dependencies that used with `require()`
|
|
||||||
function findUsedDeps () {
|
|
||||||
var stdout = cp.execSync('./bin/list-deps.sh')
|
|
||||||
return stdout.toString().trim().split('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
function includes (arr, elem) {
|
|
||||||
return arr.indexOf(elem) >= 0
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# This is a truly heinous hack, but it works pretty nicely.
|
|
||||||
# Find all modules we're requiring---even conditional requires.
|
|
||||||
|
|
||||||
grep "require('" src/ bin/ -R |
|
|
||||||
grep '.js:' |
|
|
||||||
sed "s/.*require('\([^'\/]*\).*/\1/" |
|
|
||||||
grep -v '^\.' |
|
|
||||||
sort |
|
|
||||||
uniq
|
|
||||||
@@ -7,4 +7,4 @@ npm run package -- --sign
|
|||||||
git push
|
git push
|
||||||
git push --tags
|
git push --tags
|
||||||
npm publish
|
npm publish
|
||||||
./node_modules/.bin/gh-release
|
npm run gh-release
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
"babel-plugin-transform-object-rest-spread": "^6.8.0",
|
"babel-plugin-transform-object-rest-spread": "^6.8.0",
|
||||||
"babel-plugin-transform-react-jsx": "^6.8.0",
|
"babel-plugin-transform-react-jsx": "^6.8.0",
|
||||||
"cross-zip": "^2.0.1",
|
"cross-zip": "^2.0.1",
|
||||||
|
"depcheck": "^0.6.4",
|
||||||
"electron-osx-sign": "^0.3.0",
|
"electron-osx-sign": "^0.3.0",
|
||||||
"electron-packager": "^7.0.0",
|
"electron-packager": "^7.0.0",
|
||||||
"electron-winstaller": "^2.3.0",
|
"electron-winstaller": "^2.3.0",
|
||||||
@@ -97,7 +98,8 @@
|
|||||||
"package": "node ./bin/package.js",
|
"package": "node ./bin/package.js",
|
||||||
"prepublish": "npm run build",
|
"prepublish": "npm run build",
|
||||||
"start": "npm run build && electron .",
|
"start": "npm run build && electron .",
|
||||||
"test": "standard && node ./bin/check-deps.js",
|
"test": "standard && depcheck --ignores=babel-cli,nodemon,gh-release",
|
||||||
|
"gh-release": "gh-release",
|
||||||
"update-authors": "./bin/update-authors.sh",
|
"update-authors": "./bin/update-authors.sh",
|
||||||
"watch": "nodemon --exec 'npm run start' --ext js,pug,css"
|
"watch": "nodemon --exec 'npm run start' --ext js,pug,css"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user