mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
// Lazy dynamic-import() edges, exercised differentially against Node:
|
|
// every import() here targets a module that DOES NOT EXIST, so under Node
|
|
// the package loads fine and each import() REJECTS with Node's
|
|
// ERR_MODULE_NOT_FOUND at evaluation — scriptc must build (embedding a
|
|
// throwing ESM stub per blocked edge) and reject byte-identically at the
|
|
// same awaits. The catch happens in here (island-side) so the rejection's
|
|
// own properties print without crossing the island boundary.
|
|
const fmt = (e) => e.name + "@" + e.code + "@" + JSON.stringify(e.message);
|
|
|
|
// A bare specifier no node_modules anywhere provides: Node names the
|
|
// PACKAGE and the importing file.
|
|
export async function probeBare() {
|
|
try {
|
|
await import("ghost-bare-pkg");
|
|
return "loaded";
|
|
} catch (e) {
|
|
return fmt(e);
|
|
}
|
|
}
|
|
|
|
// A relative path that resolves to nothing: Node names the RESOLVED
|
|
// absolute path and carries its file:// url on the error.
|
|
export async function probeRel() {
|
|
try {
|
|
await import("./missing-rel.js");
|
|
return "loaded";
|
|
} catch (e) {
|
|
return fmt(e) + "@" + String(e.url);
|
|
}
|
|
}
|
|
|
|
// Present but never called: must not break the build or the run.
|
|
export function neverCalledImport() {
|
|
return import("never-imported-pkg");
|
|
}
|
|
|
|
// The TRANSITIVE half: ./subgraph.js exists, but its STATIC import targets
|
|
// a ghost package — Node links the subgraph at THIS import() and rejects
|
|
// it with the missing package's name and the SUB-module as the importer.
|
|
export async function probeSubgraph() {
|
|
try {
|
|
await import("./subgraph.js");
|
|
return "loaded";
|
|
} catch (e) {
|
|
return fmt(e);
|
|
}
|
|
}
|