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 <varungore1@gmail.com>
Co-authored-by: Paolo Valletta <paovalletta@hotmail.it>
This commit is contained in:
morluto
2026-10-14 16:53:16 +08:00
parent 1d826f304f
commit 7e5cffa2ae
15 changed files with 589 additions and 36 deletions
@@ -1,4 +1,5 @@
import type { JavaScriptSourceSelection } from "./javascriptSourceSelection.js";
import type { ArtifactOccurrence } from "../artifactGraph.js";
/** Whether an inventoried path has a source extension read by the analyzer. */
export const isJavaScriptSourcePath = (path: string): boolean =>
@@ -34,9 +35,8 @@ export interface JavaScriptArtifactFile {
}
/**
* One inventoried regular file outside the JavaScript-relevant kinds. Its presence
* was inventoried, including unavailable or unhashed members. The source projection
* does not read its bytes; references remain present-but-unanalyzed rather than absent.
* One inventoried regular file not backed by analyzed source bytes. Its inventory
* occurrence remains available even when content is opaque or unavailable.
*/
export interface JavaScriptUnanalyzedArtifactFile {
readonly path: string;
@@ -44,6 +44,14 @@ export interface JavaScriptUnanalyzedArtifactFile {
readonly sha256: string | null;
readonly bytes: number | null;
readonly inventory_artifact_id: string | null;
readonly inventory_occurrence_id?: string;
readonly kind?: JavaScriptArtifactFileKind;
readonly artifact_kind?: ArtifactOccurrence["artifact_kind"];
readonly hash_status?:
| "verified"
| "mismatched"
| "not-hashed"
| "unavailable";
readonly limitations?: readonly string[];
}
@@ -66,6 +74,8 @@ export interface JavaScriptArtifactFileSet {
readonly files: readonly JavaScriptArtifactFile[];
/** Borrowed inventory lookup for regular files the source projection does not read. */
readonly unanalyzed_files?: JavaScriptUnanalyzedArtifactLookup;
/** Relevant inventoried files whose bytes were unavailable. */
readonly unavailable_relevant_files: readonly JavaScriptUnanalyzedArtifactFile[];
readonly containers: readonly JavaScriptArtifactContainer[];
readonly text_bytes_read: number;
readonly invalid_utf8_files: number;