Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: skip preserveSymlinks for main #19388

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function resolve(specifier, parentURL) {
throw e;
}

if (!preserveSymlinks) {
const isMain = parentURL === undefined;

if (!preserveSymlinks || isMain) {
const real = realpathSync(getPathFromURL(url), {
[internalFS.realpathCacheKey]: realpathCache
});
Expand All @@ -83,7 +85,6 @@ function resolve(specifier, parentURL) {

let format = extensionFormatMap[ext];
if (!format) {
const isMain = parentURL === undefined;
if (isMain)
format = 'cjs';
else
Expand Down
25 changes: 25 additions & 0 deletions test/es-module/test-esm-symlink-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const path = require('path');
const { spawn } = require('child_process');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
tmpdir.refresh();

const realPath = path.resolve(__dirname, '../fixtures/es-modules/symlink.mjs');
const symlinkPath = path.resolve(tmpdir.path, 'symlink.js');

try {
fs.symlinkSync(realPath, symlinkPath);
} catch (err) {
if (err.code !== 'EPERM') throw err;
common.skip('insufficient privileges for symlinks');
}

spawn(process.execPath,
['--experimental-modules', '--preserve-symlinks', symlinkPath],
{ stdio: 'inherit' }).on('exit', (code) => {
assert.strictEqual(code, 0);
});
1 change: 1 addition & 0 deletions test/fixtures/es-modules/symlink.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var symlinked = true;