From 1883341ddb021db00458aec6b938467802e4413b Mon Sep 17 00:00:00 2001 From: Noam Okman Date: Sat, 27 Aug 2016 12:44:06 +0300 Subject: [PATCH] use depcheck --- .travis.yml | 2 +- bin/check-deps.js | 108 ------------------------------------------- bin/list-deps.sh | 10 ---- bin/release-_post.sh | 2 +- package.json | 4 +- 5 files changed, 5 insertions(+), 121 deletions(-) delete mode 100755 bin/check-deps.js delete mode 100755 bin/list-deps.sh diff --git a/.travis.yml b/.travis.yml index 93c35a8e..abcb8e44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: node_js node_js: - 'node' -install: npm install standard +install: npm install standard depcheck diff --git a/bin/check-deps.js b/bin/check-deps.js deleted file mode 100755 index 1423f73c..00000000 --- a/bin/check-deps.js +++ /dev/null @@ -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 -} diff --git a/bin/list-deps.sh b/bin/list-deps.sh deleted file mode 100755 index b1ff6c32..00000000 --- a/bin/list-deps.sh +++ /dev/null @@ -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 diff --git a/bin/release-_post.sh b/bin/release-_post.sh index c1ca2f1d..cdc937c8 100755 --- a/bin/release-_post.sh +++ b/bin/release-_post.sh @@ -7,4 +7,4 @@ npm run package -- --sign git push git push --tags npm publish -./node_modules/.bin/gh-release +npm run gh-release diff --git a/package.json b/package.json index aa6fa447..b7ab5044 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "babel-plugin-transform-object-rest-spread": "^6.8.0", "babel-plugin-transform-react-jsx": "^6.8.0", "cross-zip": "^2.0.1", + "depcheck": "^0.6.4", "electron-osx-sign": "^0.3.0", "electron-packager": "^7.0.0", "electron-winstaller": "^2.3.0", @@ -97,7 +98,8 @@ "package": "node ./bin/package.js", "prepublish": "npm run build", "start": "npm run build && electron .", - "test": "standard && node ./bin/check-deps.js", + "test": "standard && depcheck", + "gh-release": "gh-release", "update-authors": "./bin/update-authors.sh", "watch": "nodemon --exec 'npm run start' --ext js,pug,css" }