Skip to content

Commit

Permalink
module: skip preserveSymlinks for main
Browse files Browse the repository at this point in the history
PR-URL: #19388
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
guybedford committed Apr 1, 2018
1 parent 2540581 commit 141be92
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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;

0 comments on commit 141be92

Please sign in to comment.