Files
rea/src/domain/javascript/javascriptModuleResolutionMode.ts
T
7e5cffa2ae fix(javascript): preserve loader ownership and unavailable artifact facts
Preserve missing ASAR companion occurrence identity, declared size and unknown content in graph nodes and resolution limitations. Apply URL text semantics once for ESM lookup while preserving literal CommonJS paths and original specifiers. Keep CJS wrapper var bindings and assignment history, recognizing only untouched wrapper redeclarations.

Validation: real ASAR producer workflow and CLI/MCP path/coverage cases; semantic reassignment controls. Context7 Node documentation and direct Node wrapper execution confirm wrapper behavior.

Fixes #3213
Fixes #3214
Fixes #3223
Related: #3278, #3254

Co-authored-by: Geronimo <[email protected]>
Co-authored-by: Paolo Valletta <[email protected]>
2026-10-14 16:54:08 +08:00

24 lines
965 B
TypeScript

import { posix } from "node:path";
/** Loader evidence retained for a source-level module reference. */
export type JavaScriptModuleResolutionMode =
| "import"
| "require"
| "compiler-dependent";
/** Derive source mode only when syntax or an explicit source format owns it. */
export const moduleResolutionModeForJavaScriptReference = (
sourcePath: string,
referenceKind: "static-import" | "dynamic-import" | "require",
explicitMode?: JavaScriptModuleResolutionMode,
): JavaScriptModuleResolutionMode => {
if (explicitMode !== undefined) return explicitMode;
if (referenceKind === "require") return "require";
if (referenceKind === "dynamic-import") return "import";
const extension = posix.extname(sourcePath).toLowerCase();
if (extension === ".cjs" || extension === ".cts") return "require";
if (extension === ".mts") return "import";
if (extension === ".ts" || extension === ".tsx") return "compiler-dependent";
return "import";
};