diff options
author | James M Snell <jasnell@gmail.com> | 2016-05-02 16:31:20 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-05-13 11:43:47 -0700 |
commit | 5d38d543cdd25962fadc49a997798d156a41e4c7 (patch) | |
tree | 04b538b19025ddaf9017cbce4aa35fb004e6a145 /lib | |
parent | f52b2f116bf510e2af8750061ac6f8a0c9caa653 (diff) | |
download | android-node-v8-5d38d543cdd25962fadc49a997798d156a41e4c7.tar.gz android-node-v8-5d38d543cdd25962fadc49a997798d156a41e4c7.tar.bz2 android-node-v8-5d38d543cdd25962fadc49a997798d156a41e4c7.zip |
src,module: add --preserve-symlinks command line flag
Add the `--preserve-symlinks` flag. This makes the changes added
in #5950 conditional. By default the old behavior is used. With
the flag set, symlinks are preserved, switching to the new
behavior. This should be considered to be a temporary solution
until we figure out how to solve the symlinked peer dependency
problem in a more general way that does not break everything
else.
Additional test cases are included.
PR-URL: https://github.com/nodejs/node/pull/6537
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/module.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/module.js b/lib/module.js index 344ea97af9..ccbb5ba0e0 100644 --- a/lib/module.js +++ b/lib/module.js @@ -10,6 +10,7 @@ const fs = require('fs'); const path = require('path'); const internalModuleReadFile = process.binding('fs').internalModuleReadFile; const internalModuleStat = process.binding('fs').internalModuleStat; +const preserveSymlinks = !!process.binding('config').preserveSymlinks; // If obj.hasOwnProperty has been overridden, then calling // obj.hasOwnProperty(prop) will break. @@ -109,14 +110,15 @@ function tryPackage(requestPath, exts, isMain) { } // check if the file exists and is not a directory -// resolve to the absolute realpath if running main module, -// otherwise resolve to absolute while keeping symlinks intact. +// if using --preserve-symlinks and isMain is false, +// keep symlinks intact, otherwise resolve to the +// absolute realpath. function tryFile(requestPath, isMain) { const rc = stat(requestPath); - if (isMain) { - return rc === 0 && fs.realpathSync(requestPath); + if (preserveSymlinks && !isMain) { + return rc === 0 && path.resolve(requestPath); } - return rc === 0 && path.resolve(requestPath); + return rc === 0 && fs.realpathSync(requestPath); } // given a path check a the file exists with any of the set extensions @@ -159,7 +161,7 @@ Module._findPath = function(request, paths, isMain) { if (!trailingSlash) { const rc = stat(basePath); if (rc === 0) { // File. - if (!isMain) { + if (preserveSymlinks && !isMain) { filename = path.resolve(basePath); } else { filename = fs.realpathSync(basePath); |