-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loader: fix esm resolve for symlink file
Fix: #42195 PR-URL: #42197 Fixes: #42195 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
- Loading branch information
1 parent
6ac99b3
commit e886fdc
Showing
2 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as common from '../common/index.mjs'; | ||
import path from 'path'; | ||
import fs from 'fs/promises'; | ||
import tmpdir from '../common/tmpdir.js'; | ||
import { spawn } from 'child_process'; | ||
import assert from 'assert'; | ||
|
||
tmpdir.refresh(); | ||
const tmpDir = tmpdir.path; | ||
|
||
// Create the following file structure: | ||
// βββ index.mjs | ||
// βββ subfolder | ||
// β βββ index.mjs | ||
// β βββ node_modules | ||
// β βββ package-a | ||
// β βββ index.mjs | ||
// βββ symlink.mjs -> ./subfolder/index.mjs | ||
const entry = path.join(tmpDir, 'index.mjs'); | ||
const symlink = path.join(tmpDir, 'symlink.mjs'); | ||
const real = path.join(tmpDir, 'subfolder', 'index.mjs'); | ||
const packageDir = path.join(tmpDir, 'subfolder', 'node_modules', 'package-a'); | ||
const packageEntry = path.join(packageDir, 'index.mjs'); | ||
try { | ||
await fs.symlink(real, symlink); | ||
} catch (err) { | ||
if (err.code !== 'EPERM') throw err; | ||
common.skip('insufficient privileges for symlinks'); | ||
} | ||
await fs.mkdir(packageDir, { recursive: true }); | ||
await Promise.all([ | ||
fs.writeFile(entry, 'import "./symlink.mjs";'), | ||
fs.writeFile(real, 'export { a } from "package-a/index.mjs"'), | ||
fs.writeFile(packageEntry, 'export const a = 1;'), | ||
]); | ||
|
||
spawn(process.execPath, ['--experimental-specifier-resolution=node', entry], | ||
{ stdio: 'inherit' }).on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0); | ||
})); |