mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
fix(javascript): preserve TypeScript loader and dependency semantics
Share loader selection across static findings and module relationships: CTS static imports and re-exports use CommonJS lookup while dynamic imports retain ESM lookup. Retain runtime import-equals dependencies, bindings, and exported names; do not resolve require file-URL strings as local artifacts. Restore import-map descriptions in CLI help. Validated resolver and semantic tests, application reconstruction boundaries, and CLI help. Installed TypeScript NodeNext emission and Node require behavior were checked independently. Refs #2056, #2057, #2058, #2053.
This commit is contained in:
@@ -64,6 +64,17 @@ export interface ResolveArtifactPathInput {
|
||||
readonly moduleKind?: "import" | "require";
|
||||
}
|
||||
|
||||
/** Loader selected by a source-level JavaScript module reference. */
|
||||
export const moduleKindForJavaScriptReference = (
|
||||
sourcePath: string,
|
||||
referenceKind: "static-import" | "dynamic-import" | "require",
|
||||
): "import" | "require" =>
|
||||
referenceKind === "require" ||
|
||||
(referenceKind === "static-import" &&
|
||||
posix.extname(sourcePath).toLowerCase() === ".cts")
|
||||
? "require"
|
||||
: "import";
|
||||
|
||||
const EXTENSIONS = [
|
||||
".js",
|
||||
".cjs",
|
||||
@@ -189,7 +200,12 @@ const contextualCandidate = (
|
||||
if (context === "html-reference") return htmlCandidate(input);
|
||||
if (context === "module-specifier") {
|
||||
const fileUrl = fileUrlPath(declared);
|
||||
if (fileUrl !== undefined) return fileUrl;
|
||||
if (fileUrl !== undefined)
|
||||
return input.moduleKind === "require"
|
||||
? unresolvedCandidate("external", [
|
||||
"Node CommonJS require specifiers do not resolve file URLs as local artifacts.",
|
||||
])
|
||||
: fileUrl;
|
||||
if (hasScheme(declared))
|
||||
return unresolvedCandidate("external", [
|
||||
"URL and Node builtin schemes are outside static artifact module resolution.",
|
||||
|
||||
Reference in New Issue
Block a user