Skip to content

Commit 141be92

Browse files
committed
module: skip preserveSymlinks for main
PR-URL: #19388 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2540581 commit 141be92

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/internal/modules/esm/default_resolve.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ function resolve(specifier, parentURL) {
6969
throw e;
7070
}
7171

72-
if (!preserveSymlinks) {
72+
const isMain = parentURL === undefined;
73+
74+
if (!preserveSymlinks || isMain) {
7375
const real = realpathSync(getPathFromURL(url), {
7476
[internalFS.realpathCacheKey]: realpathCache
7577
});
@@ -83,7 +85,6 @@ function resolve(specifier, parentURL) {
8385

8486
let format = extensionFormatMap[ext];
8587
if (!format) {
86-
const isMain = parentURL === undefined;
8788
if (isMain)
8889
format = 'cjs';
8990
else
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const path = require('path');
6+
const { spawn } = require('child_process');
7+
const tmpdir = require('../common/tmpdir');
8+
const fs = require('fs');
9+
tmpdir.refresh();
10+
11+
const realPath = path.resolve(__dirname, '../fixtures/es-modules/symlink.mjs');
12+
const symlinkPath = path.resolve(tmpdir.path, 'symlink.js');
13+
14+
try {
15+
fs.symlinkSync(realPath, symlinkPath);
16+
} catch (err) {
17+
if (err.code !== 'EPERM') throw err;
18+
common.skip('insufficient privileges for symlinks');
19+
}
20+
21+
spawn(process.execPath,
22+
['--experimental-modules', '--preserve-symlinks', symlinkPath],
23+
{ stdio: 'inherit' }).on('exit', (code) => {
24+
assert.strictEqual(code, 0);
25+
});

test/fixtures/es-modules/symlink.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var symlinked = true;

0 commit comments

Comments
 (0)