diff --git a/lib/config/exec.js b/lib/config/exec.js index d1128b65..de0cd306 100644 --- a/lib/config/exec.js +++ b/lib/config/exec.js @@ -19,10 +19,12 @@ function execFromPackage() { if (pkg.main !== undefined) { // no app found to run - so give them a tip and get the feck out return { exec: null, script: pkg.main }; - } else if (pkg.scripts && pkg.scripts.start) { + } + + if (pkg.scripts && pkg.scripts.start) { return { exec: pkg.scripts.start }; } - } catch (e) {} + } catch (e) { } return null; } @@ -84,7 +86,7 @@ function exec(nodemonOptions, execMap) { execDefined = true; } - options.execArgs = []; + options.execArgs = nodemonOptions.execArgs || []; if (Array.isArray(options.exec)) { options.execArgs = options.exec; diff --git a/lib/config/load.js b/lib/config/load.js index e79afee9..73ae2753 100644 --- a/lib/config/load.js +++ b/lib/config/load.js @@ -79,6 +79,7 @@ function load(settings, options, config, callback) { args: options.args, scriptPosition: options.scriptPosition, nodeArgs: options.nodeArgs, + execArgs: options.execArgs, ext: options.ext, env: options.env, }, options.execMap); @@ -172,7 +173,7 @@ function normaliseRules(options, ready) { */ function loadFile(options, config, dir, ready) { if (!ready) { - ready = function () {}; + ready = function () { }; } var callback = function (settings) { @@ -216,7 +217,7 @@ function loadFile(options, config, dir, ready) { function loadPackageJSON(config, ready) { if (!ready) { - ready = function () {}; + ready = function () { }; } utils.log.detail('Looking in package.json for nodemonConfig'); diff --git a/lib/monitor/match.js b/lib/monitor/match.js index d9f43d9f..c214b149 100644 --- a/lib/monitor/match.js +++ b/lib/monitor/match.js @@ -137,9 +137,9 @@ function match(files, monitor, ext) { if (aIsIgnore || bIsIgnore) { if (aIsIgnore) { return -1; - } else { - return 1; } + + return 1; } if (r === 0) { @@ -151,7 +151,9 @@ function match(files, monitor, ext) { if (prefix === '!') { return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1); - } else if (s.slice(0, 2) === '..') { + } + + if (s.slice(0, 2) === '..') { return path.resolve(process.cwd(), s); } return '**' + (prefix !== path.sep ? path.sep : '') + s; diff --git a/lib/monitor/run.js b/lib/monitor/run.js index cb36ba63..2baebff4 100644 --- a/lib/monitor/run.js +++ b/lib/monitor/run.js @@ -8,7 +8,7 @@ var watch = require('./watch').watch; var config = require('../config'); var child = null; // the actual child process we spawn var killedAfterChange = false; -var noop = function () {}; +var noop = function () { }; var restart = null; var psTree = require('ps-tree'); var hasPS = true; @@ -39,8 +39,8 @@ function run(options) { if (config.options.stdout) { stdio = ['pipe', - process.stdout, - process.stderr,]; + process.stdout, + process.stderr,]; } var sh = 'sh'; @@ -63,9 +63,9 @@ function run(options) { // if the executable path contains a space the whole string must be quoted // to get windows treat it as 1 argument for cmd.exe if (executable.indexOf(' ') !== -1 && executable[0] !== '\"' - && executable[executable.length - 1] !== '\"') { + && executable[executable.length - 1] !== '\"') { // remove all quotes from executable (possible backward compat hacks) - executable = executable.replace (/\"/g, ''); + executable = executable.replace(/\"/g, ''); } } @@ -155,7 +155,9 @@ function run(options) { // exit the monitor, but do it gracefully if (signal === config.signal) { return restart(); - } else if (code === 0) { // clean exit - wait until file change to restart + } + + if (code === 0) { // clean exit - wait until file change to restart if (runCmd) { utils.log.status('clean exit - waiting for changes before restart'); } @@ -170,7 +172,7 @@ function run(options) { } } else { utils.log.fail('app crashed - waiting for file changes before' + - ' starting...'); + ' starting...'); child = null; } } @@ -258,7 +260,7 @@ function run(options) { function kill(child, signal, callback) { if (!callback) { - callback = function () {}; + callback = function () { }; } if (utils.isWindows) { diff --git a/lib/utils/index.js b/lib/utils/index.js index 7d1355ab..b6cde7b5 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -68,10 +68,9 @@ var utils = (module.exports = { // around it to indicate that it is a single argument if (arg.indexOf(' ') === -1) { return arg; - } else { - // this should correctly escape nested quotes - return JSON.stringify(arg); } + // this should correctly escape nested quotes + return JSON.stringify(arg); }) ) .join(' ') diff --git a/package-lock.json b/package-lock.json index b1b38db5..68dc552f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -440,12 +440,6 @@ "repeat-element": "1.1.2" } }, - "browser-stdout": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz", - "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=", - "dev": true - }, "builtin-modules": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", @@ -956,9 +950,9 @@ "dev": true }, "diff": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz", - "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz", + "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=", "dev": true }, "dom-serializer": { @@ -2416,9 +2410,9 @@ "dev": true }, "growl": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", - "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==", + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.8.1.tgz", + "integrity": "sha1-Sy3sjZB+k9szZiTc7AGDUC+MlCg=", "dev": true }, "handlebars": { @@ -2544,12 +2538,6 @@ "sntp": "1.0.9" } }, - "he": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", - "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", - "dev": true - }, "hoek": { "version": "2.16.3", "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", @@ -3009,6 +2997,30 @@ } } }, + "jade": { + "version": "0.26.3", + "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + }, + "mkdirp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", + "dev": true + } + } + }, "js-yaml": { "version": "3.10.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz", @@ -3541,50 +3553,74 @@ "dev": true }, "mocha": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-4.0.1.tgz", - "integrity": "sha512-evDmhkoA+cBNiQQQdSKZa2b9+W2mpLoj50367lhy+Klnx9OV8XlCIhigUnn1gaTFLQCa0kdNhEGDr0hCXOQFDw==", - "dev": true, - "requires": { - "browser-stdout": "1.3.0", - "commander": "2.11.0", - "debug": "3.1.0", - "diff": "3.3.1", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.3", - "he": "1.1.1", - "mkdirp": "0.5.1", - "supports-color": "4.4.0" + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-2.3.3.tgz", + "integrity": "sha1-lkiMSb/XHYalGMuUHikag/SNiFY=", + "dev": true, + "requires": { + "commander": "2.3.0", + "debug": "2.0.0", + "diff": "1.4.0", + "escape-string-regexp": "1.0.2", + "glob": "3.2.3", + "growl": "1.8.1", + "jade": "0.26.3", + "mkdirp": "0.5.0", + "supports-color": "1.2.0" }, "dependencies": { "commander": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", - "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", + "integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=", "dev": true }, "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.0.0.tgz", + "integrity": "sha1-ib2d9nMrUSVrxnBTQrugLtEhMe8=", "dev": true, "requires": { - "ms": "2.0.0" + "ms": "0.6.2" } }, + "escape-string-regexp": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz", + "integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=", + "dev": true + }, "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz", + "integrity": "sha1-4xPusknHr/qlxHUoaw4RW1mDlGc=", "dev": true, "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", + "graceful-fs": "2.0.3", "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" + "minimatch": "0.2.14" + } + }, + "graceful-fs": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz", + "integrity": "sha1-fNLNsiiko/Nule+mzBQt59GhNtA=", + "dev": true + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "minimatch": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", + "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" } }, "minimist": { @@ -3594,22 +3630,25 @@ "dev": true }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", + "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", "dev": true, "requires": { "minimist": "0.0.8" } }, + "ms": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz", + "integrity": "sha1-2JwhJMb9wTU9Zai3e/GqxLGTcIw=", + "dev": true + }, "supports-color": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", - "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", - "dev": true, - "requires": { - "has-flag": "2.0.0" - } + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.0.tgz", + "integrity": "sha1-/x7R5hFp0Gs88tWI4YixjYhH4X4=", + "dev": true } } }, @@ -4592,6 +4631,12 @@ "integrity": "sha1-jvqjBPHxSM89LpVYYpkPmrnqYo8=", "dev": true }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", diff --git a/package.json b/package.json index d1338ac0..9cf83074 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,12 @@ "lint": "jscs lib/**/*.js -v", ":spec": "node_modules/.bin/mocha --timeout 30000 --ui bdd test/**/*.test.js", "test": "npm run lint && npm run spec", - "spec": "for FILE in test/**/*.test.js; do echo $FILE; TEST=1 mocha --timeout 30000 $FILE; if [ $? -ne 0 ]; then exit 1; fi; sleep 1; done", + "spec": "for FILE in test/**/*.test.js; do echo $FILE; TEST=1 mocha --exit --timeout 30000 $FILE; if [ $? -ne 0 ]; then exit 1; fi; sleep 1; done", "postspec": "npm run clean", "clean": "rm -rf test/fixtures/test*.js", "web": "node web", - "semantic-release": "semantic-release pre && npm publish && semantic-release post" + "semantic-release": "semantic-release pre && npm publish && semantic-release post", + "postinstall": "node -e \"console.log('\\u001b[32mLove nodemon? You can now support the project via the open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[96m\\u001b[1mhttps://opencollective.com/nodemon/donate\\u001b[0m\\n')\"" }, "devDependencies": { "@commitlint/cli": "^3.1.3", @@ -46,7 +47,7 @@ "husky": "^0.14.3", "istanbul": "^0.4.5", "jscs": "^3.0.7", - "mocha": "^4.0.1", + "mocha": "^2.3.3", "semantic-release": "^8.2.0", "should": "~4.0.0" }, diff --git a/test/config/load.test.js b/test/config/load.test.js index 9e179acb..df36d1a7 100644 --- a/test/config/load.test.js +++ b/test/config/load.test.js @@ -22,7 +22,7 @@ function commandToString(command) { describe('config load', function () { var pwd = process.cwd(), - oldhome = utils.home; + oldhome = utils.home; afterEach(function () { process.chdir(pwd); @@ -81,8 +81,8 @@ describe('config load', function () { utils.home = path.resolve(pwd, 'test/fixtures/legacy'); var config = {}, - settings = {}, - options = {}; + settings = {}, + options = {}; load(settings, options, config, function (config) { assert(config.ignore.length === 5, '5 rules found: ' + config.ignore); @@ -93,8 +93,8 @@ describe('config load', function () { it('should read global config', function (done) { var config = {}, - settings = { quiet: true }, - options = {}; + settings = { quiet: true }, + options = {}; load(settings, options, config, function (config) { assert(config.verbose, 'we are verbose'); @@ -110,10 +110,10 @@ describe('config load', function () { it('should read package.json config', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/package-json-settings'); process.chdir(dir); - + var config = {}, - settings = { quiet: true }, - options = {}; + settings = { quiet: true }, + options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); done(); @@ -122,8 +122,8 @@ describe('config load', function () { it('should give local files preference', function (done) { var config = {}, - settings = { quiet: true }, - options = {}; + settings = { quiet: true }, + options = {}; load(settings, options, config, function (config) { removeRegExp(config); assert.ok(config.ignore.indexOf('one') !== -1, 'ignore contains "one": ' + config.ignore); @@ -136,10 +136,10 @@ describe('config load', function () { it('should give local files preference over package.json config', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/nodemon-settings-and-package-json-settings'); process.chdir(dir); - + var config = {}, - settings = { quiet: true }, - options = {}; + settings = { quiet: true }, + options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); done(); @@ -149,10 +149,10 @@ describe('config load', function () { it('should give package.json config preference', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/package-json-settings'); process.chdir(dir); - + var config = {}, - settings = { quiet: true }, - options = {}; + settings = { quiet: true }, + options = {}; load(settings, options, config, function (config) { removeRegExp(config); assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); @@ -165,8 +165,8 @@ describe('config load', function () { it('should give user specified settings preference', function (done) { var config = {}, - settings = { ignore: ['one'], watch: ['one'], quiet: true }, - options = {}; + settings = { ignore: ['one'], watch: ['one'], quiet: true }, + options = {}; load(settings, options, config, function (config) { removeRegExp(config); assert(config.ignore.indexOf('one') !== -1, '"one" is ignored: ' + config.ignore); @@ -178,10 +178,10 @@ describe('config load', function () { it('should give user specified settings preference over package.json config', function (done) { var dir = path.resolve(pwd, 'test/fixtures/packages/package-json-settings'); process.chdir(dir); - + var config = {}, - settings = { exec: 'foo-user', quiet: true }, - options = {}; + settings = { exec: 'foo-user', quiet: true }, + options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo-user', 'exec is "foo-user": ' + config.exec); done(); @@ -193,8 +193,8 @@ describe('config load', function () { process.chdir(dir); var config = {}, - settings = { 'script': './index.js', }, - options = {}; + settings = { 'script': './index.js', }, + options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); @@ -207,8 +207,8 @@ describe('config load', function () { process.chdir(dir); var config = {}, - settings = {}, - options = {}; + settings = {}, + options = {}; load(settings, options, config, function (config) { assert.deepEqual(config.exec, 'foo', 'exec is "foo": ' + config.exec); @@ -238,10 +238,10 @@ describe('config load', function () { var settings = { script: './index.js', verbose: true, - ignore: ['*/artic/templates/*' ], + ignore: ['*/artic/templates/*'], ext: 'js coffee json', - watch: [ '*.coffee' ], - execMap: {js: 'node --harmony', coffee: 'node --harmony', }, + watch: ['*.coffee'], + execMap: { js: 'node --harmony', coffee: 'node --harmony', }, }; var config = {}; var options = {}; @@ -255,7 +255,7 @@ describe('config load', function () { it('should merge ignore rules', function (done) { load({ - ignore: ['*/artic/templates/*', 'views/*' ], + ignore: ['*/artic/templates/*', 'views/*'], }, {}, {}, function (config) { assert.equal(config.ignore.length, defaults.ignoreRoot.length + 2); done(); @@ -264,7 +264,7 @@ describe('config load', function () { it('should allow user to override ignoreRoot', function (done) { load({ - ignore: ['*/artic/templates/*', 'views/*' ], + ignore: ['*/artic/templates/*', 'views/*'], ignoreRoot: ['.git'], }, {}, {}, function (config) { assert.equal(config.ignore.length, 3); @@ -290,4 +290,14 @@ describe('config load', function () { done(); }); }); -}); \ No newline at end of file + + it('should allow user to set execArgs', done => { + const execArgs = ['--inspect'] + load({ + execArgs, + }, {}, {}, config => { + assert.deepEqual(config.execArgs, execArgs); + done(); + }) + }); +});