Skip to content

Commit

Permalink
refactor: small tweaks to ES6-ish
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Jan 6, 2018
1 parent 6e7ce4b commit 8cb26bf
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 26 deletions.
12 changes: 6 additions & 6 deletions doc/rules.md
Expand Up @@ -12,23 +12,23 @@ Given a nodemon.json file that contains:
Then nodemon detects changes, but what causes nodemon to restart? The ignored files or the watched files? Which wins?

```js
var files = ['server/foo.coffee', 'server/app.js'];
const files = ['server/foo.coffee', 'server/app.js'];

// afterIgnore = ['server/app.js'] now since foo.coffee matches *.coffee
var afterIgnore = files.filter(applyIgnore);
const afterIgnore = files.filter(applyIgnore);

// watch = ['server/foo.coffee'] as it's under the watch
var watched = files.filter(applyWatch);
const watched = files.filter(applyWatch);
```

What about:

```js
var files = ['test/app.js', 'test/app.coffee'];
const files = ['test/app.js', 'test/app.coffee'];

// afterIgnore = ['test/app.js'] now since test/app.coffee matches *.coffee
var afterIgnore = files.filter(applyIgnore);
const afterIgnore = files.filter(applyIgnore);

// watch.length = 2 as watch implies test/*.*
var watched = files.filter(applyWatch);
const watched = files.filter(applyWatch);
```
6 changes: 3 additions & 3 deletions faq.md
Expand Up @@ -38,7 +38,7 @@ nodemon -x 'mocha test/bad.test.js || exit 1'

# Can't install nodemon: permission issue

You may need to install nodemon using `sudo` (which isn't recommended, but I understand it's unavoidable in some environemnts). If the install fails with this appearing in the npm error log, then you need the following workaround.
You may need to install nodemon using `sudo` (which isn't recommended, but I understand it's unavoidable in some environments). If the install fails with this appearing in the npm error log, then you need the following workaround.

```
gyp WARN EACCES user "root" does not have permission to access the dev dir "<some-local-dir>"
Expand Down Expand Up @@ -198,9 +198,9 @@ For example, on `lib/app.js` being changed:

## My .nodemonignore is being ignored

The new `nodemon.json` superceeds the `.nodemonignore` file, so if you have both, the `.nodemonignore` is not used at all.
The new `nodemon.json` supersedes the `.nodemonignore` file, so if you have both, the `.nodemonignore` is not used at all.

Note that if you have a `nodemon.json` in your `$HOME` path, then this will also supersede the old ignore file.
Note that if you have a `nodemon.json` in your `$HOME` path, then this will also supersede the old ignore file (and the _legacy_ format config is ignored).

## nodemon does nothing

Expand Down
13 changes: 5 additions & 8 deletions lib/config/load.js
Expand Up @@ -202,16 +202,13 @@ function loadFile(options, config, dir, ready) {

function loadPackageJSON(config, ready) {
if (!ready) {
ready = function () { };
ready = () => {};
}

var dir = process.cwd();
var filename = path.join(dir, 'package.json');
var packageLoadOptions = { configFile: filename };
return loadFile(packageLoadOptions, config, dir, function (settings) {
if (settings.nodemonConfig) {
utils.log.detail('using config in package.json');
}
const dir = process.cwd();
const filename = path.join(dir, 'package.json');
const packageLoadOptions = { configFile: filename };
return loadFile(packageLoadOptions, config, dir, settings => {
ready(settings.nodemonConfig || {});
});
}
Expand Down
8 changes: 5 additions & 3 deletions lib/nodemon.js
Expand Up @@ -81,12 +81,14 @@ function nodemon(settings) {
// always echo out the current version
utils.log.info(version.pinned);

const cwd = process.cwd();

if (config.options.cwd) {
utils.log.detail('process root: ' + process.cwd());
utils.log.detail('process root: ' + cwd);
}

config.loaded.forEach(function (filename) {
utils.log.detail('reading config ' + filename);
config.loaded.map(file => file.replace(cwd, '.')).forEach(file => {
utils.log.detail('reading config ' + file);
});

// echo out notices about running state
Expand Down
14 changes: 8 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions test/config/load-logging.test.js
@@ -0,0 +1,83 @@
'use strict';
/*global describe, it, afterEach, beforeEach, after */
const load = require('../../lib/config/load');
const utils = require('../../lib/utils')
const path = require('path');
const testUtils = require('../utils');
const assert = require('assert');
const noop = {};

describe('config logging', () => {
const pwd = process.cwd();
const oldHome = utils.home;

beforeEach(() => {
// move to the fixtures directory to allow for config loading
process.chdir(path.resolve(pwd, 'test/fixtures'));
utils.home = path.resolve(pwd, ['test', 'fixtures', 'global'].join(path.sep));
});

afterEach(() => {
process.chdir(pwd);
utils.home = oldHome;
});

it('should show package is being used', done => {
process.chdir(path.resolve(pwd, 'test/fixtures/packages/package-json-settings'));
const config = {};

load(noop, noop, config, () => {
assert.equal(config.loaded.length, 2, 'global nodemon and local package');
done();
});
});

it('should not read package if no nodemonConfig', done => {
utils.home = process.cwd();
process.chdir(path.resolve(pwd, 'test/fixtures'));
const config = {};

load(noop, noop, config, () => {
const files = config.loaded.map(_ => path.relative(pwd, _));
assert.equal(files.length, 1, 'global nodemon');
assert.deepEqual(files, ['test/fixtures/nodemon.json'], 'global nodemon');
done();
});
});

it('should ignore legacy if new format is found', done => {
utils.home = process.cwd();
process.chdir(path.resolve(pwd, 'test/fixtures/legacy'));
const config = {};

load(noop, noop, config, () => {
const loaded = config.loaded.map(_ => path.relative(pwd, _));
assert.equal(loaded.length, 1, 'global nodemon is loaded and legacy is ignored');
done();
});
});

it('should load legacy if no nodemon.json found', done => {
utils.home = path.resolve(pwd, 'test/fixtures/configs'); // no valid nodemon.json files
process.chdir(path.resolve(pwd, 'test/fixtures/legacy'));
const config = {};

load(noop, noop, config, () => {
const loaded = config.loaded.map(_ => path.relative(pwd, _));
assert.equal(loaded.length, 1, 'legacy loaded');
done();
});
});

it('should load nothing if nothing found', done => {
utils.home = path.resolve(pwd, 'test/fixtures/configs'); // no valid nodemon.json files
process.chdir(pwd);
const config = {};

load(noop, noop, config, () => {
const loaded = config.loaded.map(_ => path.relative(pwd, _));
assert.deepEqual(loaded, [], 'nothing loaded');
done();
});
});
});

0 comments on commit 8cb26bf

Please sign in to comment.