Repository: fgnass/node-dev
Pull request #273 (2022-03-04 08:19:03)

Add --preserve-symlinks node option
- Add --preserve-symlinks node option
- Update tap to v15.1.6
- Update eslint to v8.10.0
- [README] Fix typo
- Add more explicit test for "All command-line arguments that are not node-dev options are passed on to the node process."

As requested in #272 


Patch:
diff --git a/README.md b/README.md
index 3026ee0..f47cde8 100644
--- a/README.md
+++ b/README.md
@@ -51,7 +51,11 @@ There are a couple of command-line options that can be used to control which fil
 
 ## Passing arguments to node
 
-All command-line arguments that are no `node-dev` options are passed on to the `node` process.
+All command-line arguments that are not `node-dev` options are passed on to the `node` process.
+
+Please note: you may need to separate your script from other command line options with `--`, for example:
+
+`node-dev --some-node-args -- my-script.js`
 
 # Installation
 
diff --git a/lib/cli.js b/lib/cli.js
index 4ff9d15..3efcaa0 100644
--- a/lib/cli.js
+++ b/lib/cli.js
@@ -10,7 +10,7 @@ const argify = key => ({ arg: `--${key}`, key });
 const resolvePath = p => resolve(process.cwd(), p);
 
 const nodeAlias = { require: 'r' };
-const nodeBoolean = ['expose_gc'];
+const nodeBoolean = ['expose_gc', 'preserve-symlinks'];
 const nodeOptional = ['inspect', 'inspect-brk'];
 const nodeString = ['require'];
 
@@ -22,25 +22,27 @@ const alias = Object.assign({}, nodeAlias);
 const boolean = [...nodeBoolean, ...nodeDevBoolean];
 const string = [...nodeString, ...nodeDevString];
 
-const nodeArgsReducer = opts => (out, { arg, key }) => {
-  const value = opts[key];
+const nodeArgsReducer =
+  opts =>
+  (out, { arg, key }) => {
+    const value = opts[key];
 
-  if (typeof value === 'boolean') {
-    value && out.push(arg);
-  } else if (typeof value !== 'undefined') {
-    arrayify(value).forEach(v => {
-      if (arg.includes('=')) {
-        out.push(`${arg.split('=')[0]}=${v}`);
-      } else {
-        out.push(`${arg}=${v}`);
-      }
-    });
-  }
+    if (typeof value === 'boolean') {
+      value && out.push(arg);
+    } else if (typeof value !== 'undefined') {
+      arrayify(value).forEach(v => {
+        if (arg.includes('=')) {
+          out.push(`${arg.split('=')[0]}=${v}`);
+        } else {
+          out.push(`${arg}=${v}`);
+        }
+      });
+    }
 
-  delete opts[key];
+    delete opts[key];
 
-  return out;
-};
+    return out;
+  };
 
 const nodeOptionalFactory = args => arg => {
   const isNodeOptional = nodeOptional.includes(arg.substring(2));
@@ -67,7 +69,6 @@ module.exports = argv => {
   assert(script, 'Could not parse command line arguments');
 
   const opts = minimist(args, { alias, boolean, default: getConfig(script) });
-
   const nodeArgs = [...nodeBoolean.map(argify), ...nodeString.map(argify), ...unknownArgs]
     .sort((a, b) => a.key - b.key)
     .reduce(nodeArgsReducer(opts), [...nodeOptionalArgs]);
diff --git a/package.json b/package.json
index e6959ad..b49f5f9 100644
--- a/package.json
+++ b/package.json
@@ -42,12 +42,12 @@
   },
   "devDependencies": {
     "@types/node": "^16.11.3",
-    "eslint": "^8.0.1",
+    "eslint": "^8.10.0",
     "eslint-plugin-import": "^2.22.1",
     "husky": "^7.0.4",
     "lint-staged": "^11.2.3",
     "prettier": "^2.2.1",
-    "tap": "^15.0.2",
+    "tap": "^15.1.6",
     "tap-xunit": "^2.4.1",
     "touch": "^3.1.0",
     "ts-node": "^10.3.1",


Test patch:
diff --git a/test/cli.js b/test/cli.js
index 6ff81dd..e882646 100644
--- a/test/cli.js
+++ b/test/cli.js
@@ -86,6 +86,13 @@ tap.test('--expose_gc gc.js foo', t => {
   t.end();
 });
 
+tap.test('--preserve-symlinks test', t => {
+  const argv = 'node bin/node-dev --preserve-symlinks test'.split(' ');
+  const { nodeArgs } = cli(argv);
+  t.same(nodeArgs, ['--preserve-symlinks']);
+  t.end();
+});
+
 tap.test('clear is not enabled by default', t => {
   const {
     opts: { clear }
@@ -283,3 +290,28 @@ tap.test('Repeated single dash without =', t => {
   t.same(nodeArgs, ['-u=value1', '-u=value2']);
   t.end();
 });
+
+tap.test(
+  'All command-line arguments that are not `node-dev` options are passed on to the `node` process.',
+  t => {
+    // Everything except clear gets passed to node.
+    // Don't forget to use -- to delimit!
+    const argv =
+      'node bin/node-dev --all --command-line --arguments --clear --that --are --not --node-dev --options -- test'.split(
+        ' '
+      );
+    const { nodeArgs } = cli(argv);
+
+    t.same(nodeArgs, [
+      '--all',
+      '--command-line',
+      '--arguments',
+      '--that',
+      '--are',
+      '--not',
+      '--node-dev',
+      '--options'
+    ]);
+    t.end();
+  }
+);