-
Notifications
You must be signed in to change notification settings - Fork 28.3k
/
test-esm-specifiers-symlink.mjs
40 lines (37 loc) Β· 1.36 KB
/
test-esm-specifiers-symlink.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
}));