Skip to content

Commit

Permalink
lib: fix --preserve-symlinks-main
Browse files Browse the repository at this point in the history
Fixed resolving relative imports when symlink to main file called without file extension

Fixies: nodejs#41000
  • Loading branch information
per4uk committed Dec 29, 2023
1 parent f6a83cd commit c06b027
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ function tryPackage(requestPath, exts, isMain, originalPath) {
}

/**
* Check if the file exists and is not a directory if using `--preserve-symlinks` and `isMain` is false, keep symlinks
* intact, otherwise resolve to the absolute realpath.
* Check if the file exists and is not a directory if using `--preserve-symlinks` and `isMain` is false or
* `--preserve-symlinks-main` and `isMain` is true , keep symlinks intact, otherwise resolve to the absolute realpath.
* @param {string} requestPath The path to the file to load.
* @param {boolean} isMain Whether the file is the main module.
*/
Expand All @@ -480,6 +480,9 @@ function tryFile(requestPath, isMain) {
if (getOptionValue('--preserve-symlinks') && !isMain) {
return path.resolve(requestPath);
}
if (getOptionValue('--preserve-symlinks-main') && isMain) {
return path.resolve(requestPath);
}
return toRealPath(requestPath);
}

Expand Down

0 comments on commit c06b027

Please sign in to comment.