mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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>
This commit is contained in:
1 parent
b4fb95eade
commit
95b7560d8e
13 files changed
+271
-9
No files matched your search
+8
-6
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user