From 236596590ce5746c66a36bee9ca81203553bd7a2 Mon Sep 17 00:00:00 2001 From: David Goldstein Date: Tue, 10 Apr 2018 07:40:56 +0000 Subject: [PATCH] module: add --preserve-symlinks-main Add `--preserve-symlinks-main` option which behaves like `--preserve-symlinks` but for `require.main`. PR-URL: https://github.com/nodejs/node/pull/19911 Reviewed-By: James M Snell --- doc/api/cli.md | 23 ++++++++ doc/node.1 | 5 +- lib/internal/modules/cjs/loader.js | 17 +++++- lib/internal/modules/esm/default_resolve.js | 3 +- src/node.cc | 16 +++++- src/node_config.cc | 2 + src/node_internals.h | 5 ++ .../test-esm-preserve-symlinks-main.js | 57 +++++++++++++++++++ 8 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 test/es-module/test-esm-preserve-symlinks-main.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 6d055d9d03a..d76c49615c9 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -217,6 +217,29 @@ are linked from more than one location in the dependency tree (Node.js would see those as two separate modules and would attempt to load the module multiple times, causing an exception to be thrown). +The `--preserve-symlinks` flag does not apply to the main module, which allows +`node --preserve-symlinks node_module/.bin/` to work. To apply the same +behavior for the main module, also use `--preserve-symlinks-main`. + +### `--preserve-symlinks-main` + + +Instructs the module loader to preserve symbolic links when resolving and +caching the main module (`require.main`). + +This flag exists so that the main module can be opted-in to the same behavior +that `--preserve-symlinks` gives to all other imports; they are separate flags, +however, for backward compatibility with older Node.js versions. + +Note that `--preserve-symlinks-main` does not imply `--preserve-symlinks`; it +is expected that `--preserve-symlinks-main` will be used in addition to +`--preserve-symlinks` when it is not desirable to follow symlinks before +resolving relative paths. + +See `--preserve-symlinks` for more information. + ### `--prof-process`