镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
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;