node/test/es-module/test-esm-package-map-basic.mjs
Maël Nison 2f2b81095b
loader: implement package maps
Signed-off-by: Mael Nison <nison.mael@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62239
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-06-12 16:02:01 +00:00

31 lines
1.2 KiB
JavaScript

// Test that package maps resolve direct, subpath, and transitive dependencies.
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.mjs';
const packageMapPath = fixtures.path('package-map/package-map.json');
const cwd = fixtures.path('package-map/root');
// Resolves a direct dependency.
spawnSyncAndAssert(process.execPath, [
'--no-warnings',
'--experimental-package-map', packageMapPath,
'--input-type=module',
'--eval', `import dep from 'dep-a'; console.log(dep);`,
], { cwd }, { stdout: /dep-a-value/, trim: true });
// Resolves a subpath export.
spawnSyncAndAssert(process.execPath, [
'--no-warnings',
'--experimental-package-map', packageMapPath,
'--input-type=module',
'--eval', `import util from 'dep-a/lib/util'; console.log(util);`,
], { cwd }, { stdout: /dep-a-util/, trim: true });
// Resolves transitive dependency from allowed package.
spawnSyncAndAssert(process.execPath, [
'--no-warnings',
'--experimental-package-map', packageMapPath,
'--input-type=module',
'--eval', `import depB from 'dep-b'; console.log(depB);`,
], { cwd }, { stdout: /dep-b using dep-a-value/, trim: true });