Skip to content

Commit

Permalink
chore: remove legacy .nodemon support
Browse files Browse the repository at this point in the history
As part of a semi-clean up from bump to 3.x
  • Loading branch information
remy committed Jul 7, 2023
1 parent 04302b8 commit 7881f05
Show file tree
Hide file tree
Showing 6 changed files with 1,447 additions and 8,866 deletions.
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
4 changes: 3 additions & 1 deletion faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ For example, on `lib/app.js` being changed:

## My .nodemonignore is being ignored

_The legacy `.nodemonignore` was dropped in nodemon@3_

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 (and the _legacy_ format config is ignored).
Expand Down Expand Up @@ -336,7 +338,7 @@ nodemon --ext '*' --watch public --exec 'python -m SimpleHTTPServer'

Based on [this issue](https://github.com/remy/nodemon/issues/2056).

Sometimes when using the `--inspect` flag, nodemon will try to start the a process before the old process is finished.
Sometimes when using the `--inspect` flag, nodemon will try to start the a process before the old process is finished.

This will cause an error trying to up the new process because of the debugger service:

Expand Down
91 changes: 28 additions & 63 deletions lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var existsSync = fs.existsSync || path.existsSync;
function findAppScript() {
// nodemon has been run alone, so try to read the package file
// or try to read the index.js file

var pkg = existsSync(path.join(process.cwd(), 'package.json')) && require(path.join(process.cwd(), 'package.json'));

var pkg =
existsSync(path.join(process.cwd(), 'package.json')) &&
require(path.join(process.cwd(), 'package.json'));
if ((!pkg || pkg.main == undefined) && existsSync('./index.js')) {
return 'index.js';
}
Expand Down Expand Up @@ -64,7 +66,6 @@ function load(settings, options, config, callback) {
options.ignore = defaults.ignore.concat(options.ignore);
}


// add in any missing defaults
options = utils.merge(options, defaults);

Expand All @@ -76,11 +77,14 @@ function load(settings, options, config, callback) {
}
// if the script is found as a result of not being on the command
// line, then we move any of the pre double-dash args in execArgs
const n = options.scriptPosition === null ?
options.args.length : options.scriptPosition;

options.execArgs = (options.execArgs || [])
.concat(options.args.splice(0, n));
const n =
options.scriptPosition === null
? options.args.length
: options.scriptPosition;

options.execArgs = (options.execArgs || []).concat(
options.args.splice(0, n)
);
options.scriptPosition = null;

options.script = found;
Expand All @@ -104,53 +108,11 @@ function load(settings, options, config, callback) {
normaliseRules(options, callback);
};

// if we didn't pick up a nodemon.json file & there's no cli ignores
// then try loading an old style .nodemonignore file
if (config.loaded.length === 0) {
var legacy = loadLegacyIgnore.bind(null, options, config, ready);

// first try .nodemonignore, if that doesn't exist, try nodemon-ignore
return legacy('.nodemonignore', function () {
legacy('nodemon-ignore', function (options) {
ready(options);
});
});
}

ready(options);
});
});
}

/**
* Loads the old style nodemonignore files which is a list of patterns
* in a file to ignore
*
* @param {Object} options nodemon user options
* @param {Function} success
* @param {String} filename ignore file (.nodemonignore or nodemon-ignore)
* @param {Function} fail (optional) failure callback
*/
function loadLegacyIgnore(options, config, success, filename, fail) {
var ignoreFile = path.join(process.cwd(), filename);

exists(ignoreFile, function (exists) {
if (exists) {
config.loaded.push(ignoreFile);
return parse(ignoreFile, function (error, rules) {
options.ignore = rules.raw;
success(options);
});
}

if (fail) {
fail(options);
} else {
success(options);
}
});
}

function normaliseRules(options, ready) {
// convert ignore and watch options to rules/regexp
rules.watch.add(options.watch);
Expand All @@ -172,7 +134,7 @@ function normaliseRules(options, ready) {
*/
function loadFile(options, config, dir, ready) {
if (!ready) {
ready = function () { };
ready = function () {};
}

var callback = function (settings) {
Expand Down Expand Up @@ -224,29 +186,32 @@ function loadFile(options, config, dir, ready) {

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

const dir = process.cwd();
const filename = path.join(dir, 'package.json');
const packageLoadOptions = { configFile: filename };
return loadFile(packageLoadOptions, config, dir, settings => {
return loadFile(packageLoadOptions, config, dir, (settings) => {
ready(settings.nodemonConfig || {});
});
}

function mutateExecOptions(options) {
// work out the execOptions based on the final config we have
options.execOptions = exec({
script: options.script,
exec: options.exec,
args: options.args,
scriptPosition: options.scriptPosition,
nodeArgs: options.nodeArgs,
execArgs: options.execArgs,
ext: options.ext,
env: options.env,
}, options.execMap);
options.execOptions = exec(
{
script: options.script,
exec: options.exec,
args: options.args,
scriptPosition: options.scriptPosition,
nodeArgs: options.nodeArgs,
execArgs: options.execArgs,
ext: options.ext,
env: options.env,
},
options.execMap
);

// clean up values that we don't need at the top level
delete options.scriptPosition;
Expand Down
Loading

0 comments on commit 7881f05

Please sign in to comment.