• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import * as common from '../common/index.mjs';
2import path from 'path';
3import fs from 'fs/promises';
4import tmpdir from '../common/tmpdir.js';
5import { spawn } from 'child_process';
6import assert from 'assert';
7
8tmpdir.refresh();
9const 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
19const entry = path.join(tmpDir, 'index.mjs');
20const symlink = path.join(tmpDir, 'symlink.mjs');
21const real = path.join(tmpDir, 'subfolder', 'index.mjs');
22const packageDir = path.join(tmpDir, 'subfolder', 'node_modules', 'package-a');
23const packageEntry = path.join(packageDir, 'index.mjs');
24try {
25  await fs.symlink(real, symlink);
26} catch (err) {
27  if (err.code !== 'EPERM') throw err;
28  common.skip('insufficient privileges for symlinks');
29}
30await fs.mkdir(packageDir, { recursive: true });
31await 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
37spawn(process.execPath, ['--experimental-specifier-resolution=node', entry],
38      { stdio: 'inherit' }).on('exit', common.mustCall((code) => {
39  assert.strictEqual(code, 0);
40}));
41