Skip to content

Commit 859b719

Browse files
guybedfordtargos
authored andcommitted
module: skip preserveSymlinks for main
PR-URL: #19388 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bb32bc8 commit 859b719

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/internal/loader/DefaultResolve.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ function resolve(specifier, parentURL) {
6666
throw e;
6767
}
6868

69-
if (!preserveSymlinks) {
69+
const isMain = parentURL === undefined;
70+
71+
if (!preserveSymlinks || isMain) {
7072
const real = realpathSync(getPathFromURL(url), {
7173
[internalFS.realpathCacheKey]: realpathCache
7274
});
@@ -80,7 +82,6 @@ function resolve(specifier, parentURL) {
8082

8183
let format = extensionFormatMap[ext];
8284
if (!format) {
83-
const isMain = parentURL === undefined;
8485
if (isMain)
8586
format = 'cjs';
8687
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)