|
| 1 | +import * as common from '../common/index.mjs'; |
| 2 | +import path from 'path'; |
| 3 | +import fs from 'fs/promises'; |
| 4 | +import tmpdir from '../common/tmpdir.js'; |
| 5 | +import { spawn } from 'child_process'; |
| 6 | +import assert from 'assert'; |
| 7 | + |
| 8 | +tmpdir.refresh(); |
| 9 | +const tmpDir = tmpdir.path; |
| 10 | + |
| 11 | +// Create the following file structure: |
| 12 | +// βββ index.mjs |
| 13 | +// βββ subfolder |
| 14 | +// β βββ index.mjs |
| 15 | +// β βββ node_modules |
| 16 | +// β βββ package-a |
| 17 | +// β βββ index.mjs |
| 18 | +// βββ symlink.mjs -> ./subfolder/index.mjs |
| 19 | +const entry = path.join(tmpDir, 'index.mjs'); |
| 20 | +const symlink = path.join(tmpDir, 'symlink.mjs'); |
| 21 | +const real = path.join(tmpDir, 'subfolder', 'index.mjs'); |
| 22 | +const packageDir = path.join(tmpDir, 'subfolder', 'node_modules', 'package-a'); |
| 23 | +const packageEntry = path.join(packageDir, 'index.mjs'); |
| 24 | +try { |
| 25 | + await fs.symlink(real, symlink); |
| 26 | +} catch (err) { |
| 27 | + if (err.code !== 'EPERM') throw err; |
| 28 | + common.skip('insufficient privileges for symlinks'); |
| 29 | +} |
| 30 | +await fs.mkdir(packageDir, { recursive: true }); |
| 31 | +await Promise.all([ |
| 32 | + fs.writeFile(entry, 'import "./symlink.mjs";'), |
| 33 | + fs.writeFile(real, 'export { a } from "package-a/index.mjs"'), |
| 34 | + fs.writeFile(packageEntry, 'export const a = 1;'), |
| 35 | +]); |
| 36 | + |
| 37 | +spawn(process.execPath, ['--experimental-specifier-resolution=node', entry], |
| 38 | + { stdio: 'inherit' }).on('exit', common.mustCall((code) => { |
| 39 | + assert.strictEqual(code, 0); |
| 40 | +})); |
0 commit comments