@vltpkg/graph 1.0.0-rc.12 → 1.0.0-rc.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -22
- package/dist/diff.d.ts +2 -0
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +5 -1
- package/dist/diff.js.map +1 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +10 -2
- package/dist/graph.js.map +1 -1
- package/dist/ideal/append-nodes.d.ts.map +1 -1
- package/dist/ideal/append-nodes.js +20 -5
- package/dist/ideal/append-nodes.js.map +1 -1
- package/dist/ideal/peers.d.ts +23 -1
- package/dist/ideal/peers.d.ts.map +1 -1
- package/dist/ideal/peers.js +103 -4
- package/dist/ideal/peers.js.map +1 -1
- package/dist/ideal/refresh-ideal-graph.d.ts.map +1 -1
- package/dist/ideal/refresh-ideal-graph.js +6 -0
- package/dist/ideal/refresh-ideal-graph.js.map +1 -1
- package/dist/lockfile/types.d.ts +1 -0
- package/dist/lockfile/types.d.ts.map +1 -1
- package/dist/lockfile/types.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js.map +1 -1
- package/dist/reify/check-needed-build.d.ts +5 -0
- package/dist/reify/check-needed-build.d.ts.map +1 -1
- package/dist/reify/check-needed-build.js +18 -7
- package/dist/reify/check-needed-build.js.map +1 -1
- package/dist/reify/extract-node.d.ts.map +1 -1
- package/dist/reify/extract-node.js.map +1 -1
- package/dist/reify/index.js +1 -1
- package/dist/reify/index.js.map +1 -1
- package/dist/visualization/mermaid-output.d.ts +2 -1
- package/dist/visualization/mermaid-output.d.ts.map +1 -1
- package/dist/visualization/mermaid-output.js +28 -16
- package/dist/visualization/mermaid-output.js.map +1 -1
- package/package.json +22 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lockfile/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{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A;QACzB;YACE,OAAO,cAAc,CAAA;IACzB,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,KAAyB,EACe,EAAE;IAC1C,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,gBAAgB;YACnB,OAAO,QAAQ,CAAA;QACjB,KAAK,eAAe;YAClB,OAAO,OAAO,CAAA;QAChB,KAAK,gBAAgB;YACnB,OAAO,QAAQ,CAAA;QACjB;YACE,OAAO,MAAM,CAAA;IACjB,CAAC;AACH,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type {\n Integrity,\n NormalizedManifest,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport type { Graph } from '../graph.ts'\n\n/**\n * Platform requirements for a lockfile node\n */\nexport type LockfilePlatform = {\n engines?: Record<string, string>\n os?: string[] | string\n cpu?: string[] | string\n libc?: string[] | string\n}\n\n/**\n * This is the main type definition for the contents of the\n * `vlt-lock.json` file.\n *\n * The nodes and edges information from the lockfile are used to reconstruct\n * a {@link Graph} representing a previous install.\n */\nexport type LockfileData = {\n lockfileVersion: number\n options: SpecOptions & {\n modifiers?: Record<string, string> | undefined\n }\n nodes: Record<DepID, LockfileNode>\n edges: LockfileEdges\n}\n\nexport const getFlagNumFromNode = (node: {\n optional?: boolean\n dev?: boolean\n}) =>\n node.optional && node.dev ? LockfileNodeFlagDevOptional\n : node.optional ? LockfileNodeFlagOptional\n : node.dev ? LockfileNodeFlagDev\n : LockfileNodeFlagNone\n\nexport const getBooleanFlagsFromNum = (flags: LockfileNodeFlags) => ({\n dev: !!(flags & LockfileNodeFlagDev),\n optional: !!(flags & LockfileNodeFlagOptional),\n})\n\nexport const LockfileNodeFlagNone = 0\nexport const LockfileNodeFlagOptional = 1\nexport const LockfileNodeFlagDev = 2\nexport const LockfileNodeFlagDevOptional = 3\n\n/**\n * Bit flags indicating whether a node is optional and/or dev.\n */\nexport type LockfileNodeFlags = 0 | 1 | 2 | 3\n\n/**\n * Build state constants for lockfile nodes\n */\nexport const BuildStateNone = undefined\nexport const BuildStateNeeded = 1\nexport const BuildStateBuilt = 2\nexport const BuildStateFailed = 3\n\n/**\n * Build state for a node - tracks whether it needs building, has been built, or failed\n */\nexport type LockfileBuildState = undefined | 1 | 2 | 3\n\nexport const getBuildStateFromNode = (node: {\n buildState?: 'none' | 'needed' | 'built' | 'failed'\n}): LockfileBuildState => {\n switch (node.buildState) {\n case 'needed':\n return BuildStateNeeded\n case 'built':\n return BuildStateBuilt\n case 'failed':\n return BuildStateFailed\n default:\n return BuildStateNone\n }\n}\n\nexport const getBuildStateFromNum = (\n state: LockfileBuildState,\n): 'none' | 'needed' | 'built' | 'failed' => {\n switch (state) {\n case BuildStateNeeded:\n return 'needed'\n case BuildStateBuilt:\n return 'built'\n case BuildStateFailed:\n return 'failed'\n default:\n return 'none'\n }\n}\n\n/**\n * Lockfile representation of a node from the install graph.\n */\nexport type LockfileNode = [\n flags: LockfileNodeFlags,\n name?: string | null,\n integrity?: Integrity | null,\n resolved?: string | null,\n location?: string | null,\n manifest?: NormalizedManifest | null,\n rawManifest?: NormalizedManifest | null,\n platform?: LockfilePlatform | null,\n bins?: Record<string, string> | null,\n buildState?: LockfileBuildState | null,\n]\n\n/**\n * Lockfile edges are stored as a record object where the key\n * is `${from.id} ${spec.name}` and the value is\n * `${type} ${spec.bareSpec} ${to.id | 'MISSING'}`\n *\n * Storing them in a record like this means that we are guaranteed to\n * never end up with duplicates, and a standard `JSON.stringify()`\n * will nicely print them out one line per edge.\n */\nexport type LockfileEdges = {\n [key: LockfileEdgeKey]: LockfileEdgeValue\n}\n\n/** `${from} ${dep name}` */\nexport type LockfileEdgeKey = `${DepID} ${string}`\n\n/** `${type} ${spec} ${to}` */\nexport type LockfileEdgeValue =\n `${DependencyTypeShort} ${Spec['bareSpec']} ${DepID | 'MISSING'}`\n"]}
|
package/dist/node.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ export declare class Node implements NodeLike {
|
|
|
117
117
|
engines?: Record<string, string>;
|
|
118
118
|
os?: string[] | string;
|
|
119
119
|
cpu?: string[] | string;
|
|
120
|
+
libc?: string[] | string;
|
|
120
121
|
};
|
|
121
122
|
/**
|
|
122
123
|
* Record of binary names to their paths in the package, if any.
|
|
@@ -223,6 +224,7 @@ export declare class Node implements NodeLike {
|
|
|
223
224
|
engines?: Record<string, string>;
|
|
224
225
|
os?: string[] | string;
|
|
225
226
|
cpu?: string[] | string;
|
|
227
|
+
libc?: string[] | string;
|
|
226
228
|
} | undefined;
|
|
227
229
|
buildState: "none" | "needed" | "built" | "failed";
|
|
228
230
|
};
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAO7C,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACT,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAKvC,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,qBAAa,IAAK,YAAW,QAAQ;;IACnC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAOD;;;;;;OAMG;IACH,IAAI,QAAQ,IAGW,OAAO,CAD7B;IACD,IAAI,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAS7B;I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G,CAAC,KAAc,EAAiB,EAAE;IACtD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,IAAI,IAAI;QACb,IAAI,IAAI,KAAK;QACb,UAAU,IAAI,KAAK;QAClB,KAAc,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,oBAAoB,CAC7D,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAQ,EAAE;IAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,SAAS,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACtD,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import type { PathScurry } from 'path-scurry'\nimport {\n isPackageNameConfused,\n getId,\n hydrateTuple,\n splitDepID,\n} from '@vltpkg/dep-id'\nimport type { DepID, DepIDTuple } from '@vltpkg/dep-id'\nimport { typeError } from '@vltpkg/error-cause'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport { expandNormalizedManifestSymbols } from '@vltpkg/types'\nimport type {\n Integrity,\n NormalizedManifest,\n DependencyTypeShort,\n GraphLike,\n NodeLike,\n} from '@vltpkg/types'\nimport { Edge } from './edge.ts'\nimport type { Graph } from './graph.ts'\nimport { stringifyNode } from './stringify-node.ts'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { GraphModifier } from './modifiers.ts'\n\nexport type NodeOptions = SpecOptions & {\n projectRoot: string\n graph: GraphLike\n}\n\nexport class Node implements NodeLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Node'\n }\n\n #options: SpecOptions\n #location?: string\n #rawManifest?: NormalizedManifest\n\n #optional = false\n /**\n * True if a node is only reachable via optional or peerOptional edges from\n * any importer.\n *\n * Setting this to false, if previously set to true, will also unset\n * the flag on any optional-flagged non-optional dependencies.\n */\n get optional() {\n return this.#optional\n }\n set optional(optional: boolean) {\n const before = this.#optional\n this.#optional = optional\n if (before && !optional) {\n // unset for all deps, as well\n for (const { to, optional } of this.edgesOut.values()) {\n if (!optional && to?.optional) to.optional = false\n }\n }\n }\n\n isOptional(): this is Node & { optional: true } {\n return this.#optional\n }\n\n #dev = false\n /**\n * True if a node is only reachable via dev edges from any importer.\n *\n * Setting this to false, if previously set to true, will also unset\n * the flag on any dev-flagged non-dev dependencies.\n */\n get dev() {\n return this.#dev\n }\n set dev(dev: boolean) {\n const before = this.#dev\n this.#dev = dev\n if (before && !dev) {\n // unset for all deps, as well\n for (const { to, dev } of this.edgesOut.values()) {\n if (!dev && to?.dev) to.dev = false\n }\n }\n }\n\n isDev(): this is Node & { dev: true } {\n return this.#dev\n }\n\n /**\n * True if there's a manifest-confused package name.\n */\n confused = false\n\n /**\n * True if this node has been extracted to the file system.\n */\n extracted = false\n\n /**\n * List of edges coming into this node.\n */\n edgesIn = new Set<Edge>()\n\n /**\n * List of edges from this node into other nodes. This usually represents\n * that the connected node is a direct dependency of this node.\n */\n edgesOut = new Map<string, Edge>()\n\n /**\n * A `mainImporter` node may have workspace connected to it,\n * equivalent to its `edgesOut` linked deps.\n */\n workspaces: Map<string, Edge> | undefined\n\n /**\n * A reference to the {@link DepID} this node represents in the graph.\n */\n id: DepID\n\n /**\n * True if this node is an importer node.\n */\n importer = false\n\n /**\n * True if this node is the project root node.\n */\n mainImporter = false\n\n /**\n * A reference to the graph this node is a part of.\n */\n graph: Graph\n\n /**\n * The manifest integrity value.\n */\n integrity?: Integrity\n\n /**\n * The manifest this node represents in the graph.\n */\n manifest?: NormalizedManifest\n\n /**\n * Project where this node resides\n */\n projectRoot: string\n\n /**\n * For registry nodes, this is the registry we fetched them from.\n * Needed because their un-prefixed dependencies need to come from\n * the same registry, if it's not the default.\n */\n registry?: string\n\n /**\n * If this node has been modified as part of applying a {@link GraphModifier}\n * then this field will contain the modifier query that was applied.\n * Otherwise, it will be `undefined`.\n */\n modifier: string | undefined\n\n /**\n * The name of the package represented by this node, this is usually\n * equivalent to `manifest.name` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package names instead.\n */\n #name?: string\n get name() {\n if (this.#name) return this.#name\n this.#name = this.id\n return this.#name\n }\n\n /**\n * The version of the package represented by this node, this is usually\n * equivalent to `manifest.version` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package versions instead.\n */\n version?: string\n\n /**\n * An address {@link PackageInfoClient} may use to extract this package.\n */\n resolved?: string\n\n /**\n * Platform requirements (engines, os, cpu) extracted from manifest.\n * Stored separately for optional dependencies to enable platform checks\n * when manifest is not loaded.\n */\n platform?: {\n engines?: Record<string, string>\n os?: string[] | string\n cpu?: string[] | string\n }\n\n /**\n * Record of binary names to their paths in the package, if any.\n */\n bins?: Record<string, string>\n\n /**\n * True if this node has been built as part of the reify step.\n */\n built = false\n\n /**\n * Build state of this node - tracks whether it needs building, has been built, or failed.\n * - 'none': No build state (default)\n * - 'needed': Node needs to be built\n * - 'built': Node has been successfully built\n * - 'failed': Node build has failed\n */\n buildState: 'none' | 'needed' | 'built' | 'failed' = 'none'\n\n /**\n * Deterministic unique string used to identify (and ultimately duplicate)\n * nodes that are affected by a peer context set modified resolution.\n * These are appended to the node {@link DepID} as the `extra` suffix.\n */\n peerSetHash?: string\n\n /**\n * True if this node is detached from the graph.\n * This is used to indicate that the node is not part of the graph\n * although the node is still available as part of the resolution process.\n * Allows for skipping fetching manifests for detached nodes.\n */\n detached = false\n\n /**\n * The file system location for this node.\n */\n get location(): string {\n if (this.#location) {\n return this.#location\n }\n this.#location = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`\n // if using the default location, it is in the store\n this.inVltStore = () => true\n return this.#location\n }\n\n set location(location: string) {\n this.#location = location\n // reset memoization, since it might be elsewhere now\n if (this.inVltStore !== Node.prototype.inVltStore) {\n this.inVltStore = Node.prototype.inVltStore\n }\n }\n\n /**\n * The resolved location of the node in the file system.\n */\n resolvedLocation(scurry: PathScurry): string {\n return scurry.cwd.resolve(this.location).fullpath()\n }\n\n /**\n * The location of the node_modules folder where this node's edgesOut\n * should be linked into. For nodes in the store, this is the parent\n * directory, since they're extracted into a node_modules folder\n * side by side with links to their deps. For nodes outside of the store\n * (ie, importers and arbitrary link deps) this is the node_modules folder\n * directly inside the node's directory.\n */\n nodeModules(scurry: PathScurry): string {\n const loc = this.resolvedLocation(scurry)\n return this.inVltStore() ?\n loc.substring(0, loc.length - this.name.length - 1)\n : scurry.resolve(loc, 'node_modules')\n }\n\n constructor(\n options: NodeOptions,\n id?: DepID,\n manifest?: NormalizedManifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) {\n this.#options = options\n this.projectRoot = options.projectRoot\n if (id) {\n this.id = id\n } else {\n if (!manifest || !spec) {\n throw typeError(\n 'A new Node needs either a manifest & spec or an id parameter',\n {\n manifest,\n },\n )\n }\n this.id = getId(spec, manifest)\n }\n this.graph = options.graph as Graph\n this.manifest = manifest\n\n this.#name = name || this.manifest?.name\n this.version = version || this.manifest?.version\n }\n\n /**\n * return true if this node is located in the vlt store\n * memoized the first time it's called, since the store location\n * doesn't change within the context of a single operation.\n */\n inVltStore(): boolean {\n // technically this just means it's in *a* vlt store, but we can safely\n // assume that a user won't construct a path like this by accident,\n // and there's only ever one store in any given project.\n const inStore = this.location.endsWith(\n `.vlt/${this.id}/node_modules/${this.name}`,\n )\n this.inVltStore = () => inStore\n return inStore\n }\n\n #registryNodeResolved(tuple: DepIDTuple) {\n const spec = hydrateTuple(tuple, this.#name, this.#options)\n this.resolved =\n this.manifest?.dist?.tarball || spec.conventionalRegistryTarball\n this.integrity ??= this.manifest?.dist?.integrity\n }\n\n get options() {\n return this.#options\n }\n\n /* c8 ignore next */\n set options(_opts: SpecOptions) {}\n\n equals(other: Node) {\n return this.id === other.id && this.location === other.location\n }\n\n /**\n * Sets the node as an importer along with its location.\n */\n setImporterLocation(location: string) {\n this.#location = location\n this.importer = true\n }\n\n /**\n * Sets the appropriate resolve / integrity value for this node.\n * Note that other places might also set these values, like for\n * example the lockfile that might have already have this info.\n */\n setResolved() {\n // file | remote | workspace type of ids all points to a URI that\n // can be used as the `resolved` value, so we split the dep id\n // for these cases.\n const tuple = splitDepID(this.id)\n const [type, resolved] = tuple\n switch (type) {\n case 'remote': {\n this.resolved = resolved\n this.integrity ??= this.manifest?.dist?.integrity\n break\n }\n case 'registry':\n this.#registryNodeResolved(tuple)\n break\n default:\n this.resolved = resolved\n break\n }\n }\n\n setDefaultLocation() {\n const def = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`\n\n // only relocate if the location is in node_modules already\n if (\n !this.importer &&\n (!this.#location ||\n (this.#location !== def &&\n /^(?:\\.\\/)?node_modules\\//.test(this.#location)))\n ) {\n this.#location = def\n }\n }\n\n /**\n * Add an edge from this node connecting it to a direct dependency.\n */\n addEdgesTo(type: DependencyTypeShort, spec: Spec, node?: Node) {\n const edge = new Edge(type, spec, this, node)\n node?.edgesIn.add(edge)\n this.edgesOut.set(spec.name, edge)\n return edge\n }\n\n /**\n * The raw manifest before any modifications.\n * If not set, falls back to the current manifest.\n */\n get rawManifest(): NormalizedManifest | undefined {\n return this.#rawManifest ?? this.manifest\n }\n\n /**\n * Sets this node as having a manifest-confused manifest.\n */\n setConfusedManifest(\n fixed: NormalizedManifest,\n confused?: NormalizedManifest,\n ) {\n this.manifest = fixed\n this.#rawManifest = confused\n this.confused = true\n this.#name = this.manifest.name\n }\n\n /**\n * Sets this node as having a manifest-confused manifest.\n */\n maybeSetConfusedManifest(\n spec: Spec,\n confused?: NormalizedManifest,\n ) {\n if (isPackageNameConfused(spec, this.manifest?.name)) {\n this.setConfusedManifest(\n {\n ...this.manifest,\n name: spec.name,\n },\n confused,\n )\n }\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n version: this.version,\n location: this.location,\n importer: this.importer,\n manifest:\n this.manifest &&\n expandNormalizedManifestSymbols(this.manifest),\n projectRoot: this.projectRoot,\n integrity: this.integrity,\n resolved: this.resolved,\n dev: this.dev,\n optional: this.optional,\n confused: this.confused,\n modifier: this.modifier,\n platform: this.platform,\n buildState: this.buildState,\n ...(this.peerSetHash ?\n { peerSetHash: this.peerSetHash }\n : undefined),\n ...(this.confused ?\n { rawManifest: this.#rawManifest }\n : undefined),\n }\n }\n\n toString() {\n return stringifyNode(this)\n }\n}\n\nexport const isNode = (value: unknown): value is Node => {\n return (\n typeof value === 'object' &&\n value != null &&\n 'id' in value &&\n 'manifest' in value &&\n (value as Node)[Symbol.toStringTag] === '@vltpkg/graph.Node'\n )\n}\n\nexport const asNode = (value: unknown): Node => {\n if (!isNode(value)) {\n throw typeError('Expected a node', { found: value })\n }\n return value\n}\n"]}
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,KAAK,EACL,YAAY,EACZ,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAA;AAQ/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AASnD,MAAM,OAAO,IAAI;IACf,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IAED,QAAQ,CAAa;IACrB,SAAS,CAAS;IAClB,YAAY,CAAqB;IAEjC,SAAS,GAAG,KAAK,CAAA;IACjB;;;;;;OAMG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IACD,IAAI,QAAQ,CAAC,QAAiB;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAA;QAC7B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QACzB,IAAI,MAAM,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QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACpB,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;gBACnC,CAAC,CAAC,SAAS,CAAC;YACZ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACjB,EAAE,WAAW,EAAE,IAAI,CAAC,YAAY,EAAE;gBACpC,CAAC,CAAC,SAAS,CAAC;SACb,CAAA;IACH,CAAC;IAED,QAAQ;QACN,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE;IACtD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,IAAI,IAAI;QACb,IAAI,IAAI,KAAK;QACb,UAAU,IAAI,KAAK;QAClB,KAAc,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,oBAAoB,CAC7D,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAQ,EAAE;IAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,SAAS,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACtD,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import type { PathScurry } from 'path-scurry'\nimport {\n isPackageNameConfused,\n getId,\n hydrateTuple,\n splitDepID,\n} from '@vltpkg/dep-id'\nimport type { DepID, DepIDTuple } from '@vltpkg/dep-id'\nimport { typeError } from '@vltpkg/error-cause'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport { expandNormalizedManifestSymbols } from '@vltpkg/types'\nimport type {\n Integrity,\n NormalizedManifest,\n DependencyTypeShort,\n GraphLike,\n NodeLike,\n} from '@vltpkg/types'\nimport { Edge } from './edge.ts'\nimport type { Graph } from './graph.ts'\nimport { stringifyNode } from './stringify-node.ts'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { GraphModifier } from './modifiers.ts'\n\nexport type NodeOptions = SpecOptions & {\n projectRoot: string\n graph: GraphLike\n}\n\nexport class Node implements NodeLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Node'\n }\n\n #options: SpecOptions\n #location?: string\n #rawManifest?: NormalizedManifest\n\n #optional = false\n /**\n * True if a node is only reachable via optional or peerOptional edges from\n * any importer.\n *\n * Setting this to false, if previously set to true, will also unset\n * the flag on any optional-flagged non-optional dependencies.\n */\n get optional() {\n return this.#optional\n }\n set optional(optional: boolean) {\n const before = this.#optional\n this.#optional = optional\n if (before && !optional) {\n // unset for all deps, as well\n for (const { to, optional } of this.edgesOut.values()) {\n if (!optional && to?.optional) to.optional = false\n }\n }\n }\n\n isOptional(): this is Node & { optional: true } {\n return this.#optional\n }\n\n #dev = false\n /**\n * True if a node is only reachable via dev edges from any importer.\n *\n * Setting this to false, if previously set to true, will also unset\n * the flag on any dev-flagged non-dev dependencies.\n */\n get dev() {\n return this.#dev\n }\n set dev(dev: boolean) {\n const before = this.#dev\n this.#dev = dev\n if (before && !dev) {\n // unset for all deps, as well\n for (const { to, dev } of this.edgesOut.values()) {\n if (!dev && to?.dev) to.dev = false\n }\n }\n }\n\n isDev(): this is Node & { dev: true } {\n return this.#dev\n }\n\n /**\n * True if there's a manifest-confused package name.\n */\n confused = false\n\n /**\n * True if this node has been extracted to the file system.\n */\n extracted = false\n\n /**\n * List of edges coming into this node.\n */\n edgesIn = new Set<Edge>()\n\n /**\n * List of edges from this node into other nodes. This usually represents\n * that the connected node is a direct dependency of this node.\n */\n edgesOut = new Map<string, Edge>()\n\n /**\n * A `mainImporter` node may have workspace connected to it,\n * equivalent to its `edgesOut` linked deps.\n */\n workspaces: Map<string, Edge> | undefined\n\n /**\n * A reference to the {@link DepID} this node represents in the graph.\n */\n id: DepID\n\n /**\n * True if this node is an importer node.\n */\n importer = false\n\n /**\n * True if this node is the project root node.\n */\n mainImporter = false\n\n /**\n * A reference to the graph this node is a part of.\n */\n graph: Graph\n\n /**\n * The manifest integrity value.\n */\n integrity?: Integrity\n\n /**\n * The manifest this node represents in the graph.\n */\n manifest?: NormalizedManifest\n\n /**\n * Project where this node resides\n */\n projectRoot: string\n\n /**\n * For registry nodes, this is the registry we fetched them from.\n * Needed because their un-prefixed dependencies need to come from\n * the same registry, if it's not the default.\n */\n registry?: string\n\n /**\n * If this node has been modified as part of applying a {@link GraphModifier}\n * then this field will contain the modifier query that was applied.\n * Otherwise, it will be `undefined`.\n */\n modifier: string | undefined\n\n /**\n * The name of the package represented by this node, this is usually\n * equivalent to `manifest.name` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package names instead.\n */\n #name?: string\n get name() {\n if (this.#name) return this.#name\n this.#name = this.id\n return this.#name\n }\n\n /**\n * The version of the package represented by this node, this is usually\n * equivalent to `manifest.version` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package versions instead.\n */\n version?: string\n\n /**\n * An address {@link PackageInfoClient} may use to extract this package.\n */\n resolved?: string\n\n /**\n * Platform requirements (engines, os, cpu) extracted from manifest.\n * Stored separately for optional dependencies to enable platform checks\n * when manifest is not loaded.\n */\n platform?: {\n engines?: Record<string, string>\n os?: string[] | string\n cpu?: string[] | string\n libc?: string[] | string\n }\n\n /**\n * Record of binary names to their paths in the package, if any.\n */\n bins?: Record<string, string>\n\n /**\n * True if this node has been built as part of the reify step.\n */\n built = false\n\n /**\n * Build state of this node - tracks whether it needs building, has been built, or failed.\n * - 'none': No build state (default)\n * - 'needed': Node needs to be built\n * - 'built': Node has been successfully built\n * - 'failed': Node build has failed\n */\n buildState: 'none' | 'needed' | 'built' | 'failed' = 'none'\n\n /**\n * Deterministic unique string used to identify (and ultimately duplicate)\n * nodes that are affected by a peer context set modified resolution.\n * These are appended to the node {@link DepID} as the `extra` suffix.\n */\n peerSetHash?: string\n\n /**\n * True if this node is detached from the graph.\n * This is used to indicate that the node is not part of the graph\n * although the node is still available as part of the resolution process.\n * Allows for skipping fetching manifests for detached nodes.\n */\n detached = false\n\n /**\n * The file system location for this node.\n */\n get location(): string {\n if (this.#location) {\n return this.#location\n }\n this.#location = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`\n // if using the default location, it is in the store\n this.inVltStore = () => true\n return this.#location\n }\n\n set location(location: string) {\n this.#location = location\n // reset memoization, since it might be elsewhere now\n if (this.inVltStore !== Node.prototype.inVltStore) {\n this.inVltStore = Node.prototype.inVltStore\n }\n }\n\n /**\n * The resolved location of the node in the file system.\n */\n resolvedLocation(scurry: PathScurry): string {\n return scurry.cwd.resolve(this.location).fullpath()\n }\n\n /**\n * The location of the node_modules folder where this node's edgesOut\n * should be linked into. For nodes in the store, this is the parent\n * directory, since they're extracted into a node_modules folder\n * side by side with links to their deps. For nodes outside of the store\n * (ie, importers and arbitrary link deps) this is the node_modules folder\n * directly inside the node's directory.\n */\n nodeModules(scurry: PathScurry): string {\n const loc = this.resolvedLocation(scurry)\n return this.inVltStore() ?\n loc.substring(0, loc.length - this.name.length - 1)\n : scurry.resolve(loc, 'node_modules')\n }\n\n constructor(\n options: NodeOptions,\n id?: DepID,\n manifest?: NormalizedManifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) {\n this.#options = options\n this.projectRoot = options.projectRoot\n if (id) {\n this.id = id\n } else {\n if (!manifest || !spec) {\n throw typeError(\n 'A new Node needs either a manifest & spec or an id parameter',\n {\n manifest,\n },\n )\n }\n this.id = getId(spec, manifest)\n }\n this.graph = options.graph as Graph\n this.manifest = manifest\n\n this.#name = name || this.manifest?.name\n this.version = version || this.manifest?.version\n }\n\n /**\n * return true if this node is located in the vlt store\n * memoized the first time it's called, since the store location\n * doesn't change within the context of a single operation.\n */\n inVltStore(): boolean {\n // technically this just means it's in *a* vlt store, but we can safely\n // assume that a user won't construct a path like this by accident,\n // and there's only ever one store in any given project.\n const inStore = this.location.endsWith(\n `.vlt/${this.id}/node_modules/${this.name}`,\n )\n this.inVltStore = () => inStore\n return inStore\n }\n\n #registryNodeResolved(tuple: DepIDTuple) {\n const spec = hydrateTuple(tuple, this.#name, this.#options)\n this.resolved =\n this.manifest?.dist?.tarball || spec.conventionalRegistryTarball\n this.integrity ??= this.manifest?.dist?.integrity\n }\n\n get options() {\n return this.#options\n }\n\n /* c8 ignore next */\n set options(_opts: SpecOptions) {}\n\n equals(other: Node) {\n return this.id === other.id && this.location === other.location\n }\n\n /**\n * Sets the node as an importer along with its location.\n */\n setImporterLocation(location: string) {\n this.#location = location\n this.importer = true\n }\n\n /**\n * Sets the appropriate resolve / integrity value for this node.\n * Note that other places might also set these values, like for\n * example the lockfile that might have already have this info.\n */\n setResolved() {\n // file | remote | workspace type of ids all points to a URI that\n // can be used as the `resolved` value, so we split the dep id\n // for these cases.\n const tuple = splitDepID(this.id)\n const [type, resolved] = tuple\n switch (type) {\n case 'remote': {\n this.resolved = resolved\n this.integrity ??= this.manifest?.dist?.integrity\n break\n }\n case 'registry':\n this.#registryNodeResolved(tuple)\n break\n default:\n this.resolved = resolved\n break\n }\n }\n\n setDefaultLocation() {\n const def = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`\n\n // only relocate if the location is in node_modules already\n if (\n !this.importer &&\n (!this.#location ||\n (this.#location !== def &&\n /^(?:\\.\\/)?node_modules\\//.test(this.#location)))\n ) {\n this.#location = def\n }\n }\n\n /**\n * Add an edge from this node connecting it to a direct dependency.\n */\n addEdgesTo(type: DependencyTypeShort, spec: Spec, node?: Node) {\n const edge = new Edge(type, spec, this, node)\n node?.edgesIn.add(edge)\n this.edgesOut.set(spec.name, edge)\n return edge\n }\n\n /**\n * The raw manifest before any modifications.\n * If not set, falls back to the current manifest.\n */\n get rawManifest(): NormalizedManifest | undefined {\n return this.#rawManifest ?? this.manifest\n }\n\n /**\n * Sets this node as having a manifest-confused manifest.\n */\n setConfusedManifest(\n fixed: NormalizedManifest,\n confused?: NormalizedManifest,\n ) {\n this.manifest = fixed\n this.#rawManifest = confused\n this.confused = true\n this.#name = this.manifest.name\n }\n\n /**\n * Sets this node as having a manifest-confused manifest.\n */\n maybeSetConfusedManifest(\n spec: Spec,\n confused?: NormalizedManifest,\n ) {\n if (isPackageNameConfused(spec, this.manifest?.name)) {\n this.setConfusedManifest(\n {\n ...this.manifest,\n name: spec.name,\n },\n confused,\n )\n }\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n version: this.version,\n location: this.location,\n importer: this.importer,\n manifest:\n this.manifest &&\n expandNormalizedManifestSymbols(this.manifest),\n projectRoot: this.projectRoot,\n integrity: this.integrity,\n resolved: this.resolved,\n dev: this.dev,\n optional: this.optional,\n confused: this.confused,\n modifier: this.modifier,\n platform: this.platform,\n buildState: this.buildState,\n ...(this.peerSetHash ?\n { peerSetHash: this.peerSetHash }\n : undefined),\n ...(this.confused ?\n { rawManifest: this.#rawManifest }\n : undefined),\n }\n }\n\n toString() {\n return stringifyNode(this)\n }\n}\n\nexport const isNode = (value: unknown): value is Node => {\n return (\n typeof value === 'object' &&\n value != null &&\n 'id' in value &&\n 'manifest' in value &&\n (value as Node)[Symbol.toStringTag] === '@vltpkg/graph.Node'\n )\n}\n\nexport const asNode = (value: unknown): Node => {\n if (!isNode(value)) {\n throw typeError('Expected a node', { found: value })\n }\n return value\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PathScurry } from 'path-scurry';
|
|
2
|
+
import type { PackageJson } from '@vltpkg/package-json';
|
|
2
3
|
import type { Diff } from '../diff.ts';
|
|
3
4
|
import type { Node } from '../node.ts';
|
|
4
5
|
/**
|
|
@@ -19,6 +20,10 @@ export type CheckNeededBuildOptions = {
|
|
|
19
20
|
* PathScurry instance for filesystem access
|
|
20
21
|
*/
|
|
21
22
|
scurry: PathScurry;
|
|
23
|
+
/**
|
|
24
|
+
* PackageJson instance for reading manifests from disk
|
|
25
|
+
*/
|
|
26
|
+
packageJson: PackageJson;
|
|
22
27
|
};
|
|
23
28
|
/**
|
|
24
29
|
* Check which nodes need to be built and set buildState accordingly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-needed-build.d.ts","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGtC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,eAAe,EAAE,IAAI,EAAE,CAAA;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IACV;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"check-needed-build.d.ts","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGtC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,eAAe,EAAE,IAAI,EAAE,CAAA;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IACV;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;IAClB;;OAEG;IACH,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAkED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAClB,uBAAuB,KAC/B,SAkBF,CAAA"}
|
|
@@ -6,14 +6,25 @@ import { join } from 'node:path';
|
|
|
6
6
|
* 3. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)
|
|
7
7
|
* 4. Has binary files that need to be linked
|
|
8
8
|
*/
|
|
9
|
-
const nodeNeedsBuild = (node, scurry) => {
|
|
9
|
+
const nodeNeedsBuild = (node, scurry, packageJson) => {
|
|
10
10
|
// If the node has already been built during reify, no need to build again
|
|
11
11
|
if (node.built)
|
|
12
12
|
return false;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
// If the manifest is not available on the node, read it from disk.
|
|
14
|
+
// This can happen when the ideal graph is loaded from a lockfile
|
|
15
|
+
// and there's no actual graph available to hydrate the manifest data from.
|
|
16
|
+
let manifest = node.manifest;
|
|
17
|
+
if (!manifest) {
|
|
18
|
+
try {
|
|
19
|
+
manifest = packageJson.read(node.resolvedLocation(scurry));
|
|
20
|
+
node.manifest = manifest;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// If the manifest cannot be read (missing/corrupted), treat as
|
|
24
|
+
// "no build needed" to avoid failing the entire reification.
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
17
28
|
const { scripts = {} } = manifest;
|
|
18
29
|
// Check for install lifecycle scripts
|
|
19
30
|
const runInstall = !!(scripts.install ||
|
|
@@ -46,9 +57,9 @@ const nodeNeedsBuild = (node, scurry) => {
|
|
|
46
57
|
* @returns {BuildData} The BuildData object containing Node objects that need building
|
|
47
58
|
*/
|
|
48
59
|
export const checkNeededBuild = (options) => {
|
|
49
|
-
const { diff, scurry } = options;
|
|
60
|
+
const { diff, scurry, packageJson } = options;
|
|
50
61
|
// Filter nodes to only include those that actually need to be built
|
|
51
|
-
const nodesToBuild = [...diff.nodes.add].filter(node => nodeNeedsBuild(node, scurry));
|
|
62
|
+
const nodesToBuild = [...diff.nodes.add].filter(node => nodeNeedsBuild(node, scurry, packageJson));
|
|
52
63
|
// Set buildState = 'needed' on all nodes that require building
|
|
53
64
|
for (const node of nodesToBuild) {
|
|
54
65
|
node.buildState = 'needed';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-needed-build.js","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"check-needed-build.js","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AA2BhC;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,CACrB,IAAU,EACV,MAAkB,EAClB,WAAwB,EACf,EAAE;IACX,0EAA0E;IAC1E,IAAI,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAE5B,mEAAmE;IACnE,iEAAiE;IACjE,2EAA2E;IAC3E,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;IAC5B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,IAAI,CAAC;YACH,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA;YAC1D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,+DAA+D;YAC/D,6DAA6D;YAC7D,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAA;IAEjC,sCAAsC;IACtC,MAAM,UAAU,GAAG,CAAC,CAAC,CACnB,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,UAAU;QAClB,OAAO,CAAC,WAAW,CACpB,CAAA;IACD,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAE3B,gEAAgE;IAChE,sEAAsE;IACtE,2EAA2E;IAC3E,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CAAA","sourcesContent":["import type { PathScurry } from 'path-scurry'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\nimport { join } from 'node:path'\n\n/**\n * Build data containing the queue of DepIDs that need building\n */\nexport type BuildData = {\n needsBuildNodes: Node[]\n}\n\n/**\n * Options for checking needed build data\n */\nexport type CheckNeededBuildOptions = {\n /**\n * The diff object containing nodes to process\n */\n diff: Diff\n /**\n * PathScurry instance for filesystem access\n */\n scurry: PathScurry\n /**\n * PackageJson instance for reading manifests from disk\n */\n packageJson: PackageJson\n}\n\n/**\n * Checks if a node needs to be built based on the conditions from build.ts:\n * 1. Has install lifecycle scripts (install, preinstall, postinstall)\n * 2. Has binding.gyp file with no install/preinstall scripts (implicit install)\n * 3. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)\n * 4. Has binary files that need to be linked\n */\nconst nodeNeedsBuild = (\n node: Node,\n scurry: PathScurry,\n packageJson: PackageJson,\n): boolean => {\n // If the node has already been built during reify, no need to build again\n if (node.built) return false\n\n // If the manifest is not available on the node, read it from disk.\n // This can happen when the ideal graph is loaded from a lockfile\n // and there's no actual graph available to hydrate the manifest data from.\n let manifest = node.manifest\n if (!manifest) {\n try {\n manifest = packageJson.read(node.resolvedLocation(scurry))\n node.manifest = manifest\n } catch {\n // If the manifest cannot be read (missing/corrupted), treat as\n // \"no build needed\" to avoid failing the entire reification.\n return false\n }\n }\n\n const { scripts = {} } = manifest\n\n // Check for install lifecycle scripts\n const runInstall = !!(\n scripts.install ||\n scripts.preinstall ||\n scripts.postinstall\n )\n if (runInstall) return true\n\n // Check for binding.gyp file (npm's implicit install detection)\n // \"If there is a binding.gyp file in the root of your package and you\n // haven't defined your own install or preinstall scripts, npm will default\n // the install command to compile using node-gyp via node-gyp rebuild\"\n const hasBindingGyp =\n scurry\n .lstatSync(join(node.resolvedLocation(scurry), 'binding.gyp'))\n ?.isFile() ?? false\n if (hasBindingGyp && !scripts.install && !scripts.preinstall)\n return true\n\n // Check for prepare scripts on importers or git dependencies\n const prepable =\n node.id.startsWith('git') || node.importer || !node.inVltStore()\n const runPrepare =\n !!(\n (scripts.prepare || scripts.preprepare || scripts.postprepare)\n /* c8 ignore next 2 */\n ) && prepable\n if (runPrepare) return true\n\n return false\n}\n\n/**\n * Check which nodes need to be built and set buildState accordingly\n * Marks nodes with buildState = 'needed' for those that require\n * install lifecycle scripts as part of `vlt build`\n * @returns {BuildData} The BuildData object containing Node objects that need building\n */\nexport const checkNeededBuild = (\n options: CheckNeededBuildOptions,\n): BuildData => {\n const { diff, scurry, packageJson } = options\n\n // Filter nodes to only include those that actually need to be built\n const nodesToBuild = [...diff.nodes.add].filter(node =>\n nodeNeedsBuild(node, scurry, packageJson),\n )\n\n // Set buildState = 'needed' on all nodes that require building\n for (const node of nodesToBuild) {\n node.buildState = 'needed'\n }\n\n const buildData: BuildData = {\n needsBuildNodes: nodesToBuild,\n }\n\n return buildData\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-node.d.ts","sourceRoot":"","sources":["../../src/reify/extract-node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAItC;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB;IACE,OAAO,EAAE,IAAI,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;CACX,GACD;IACE,OAAO,EAAE,KAAK,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAgBL;;;GAGG;AACH,eAAO,MAAM,WAAW,SAChB,IAAI,UACF,UAAU,WACT,cAAc,WACd,WAAW,eACP,iBAAiB,SACvB,IAAI,KACV,OAAO,CAAC,aAAa,
|
|
1
|
+
{"version":3,"file":"extract-node.d.ts","sourceRoot":"","sources":["../../src/reify/extract-node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAItC;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB;IACE,OAAO,EAAE,IAAI,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;CACX,GACD;IACE,OAAO,EAAE,KAAK,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAgBL;;;GAGG;AACH,eAAO,MAAM,WAAW,SAChB,IAAI,UACF,UAAU,WACT,cAAc,WACd,WAAW,eACP,iBAAiB,SACvB,IAAI,KACV,OAAO,CAAC,aAAa,CA2EvB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-node.js","sourceRoot":"","sources":["../../src/reify/extract-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAMrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC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AM,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACxC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;YACnC,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAChC,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qBAAqB;QACrB,IAAI,wBAAwB,EAAE,CAAC;YAC7B,wBAAwB,EAAE,CAAA;YAC1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;QACxC,CAAC;QACD,oBAAoB;QACpB,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { hydrate } from '@vltpkg/dep-id'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { platformCheck } from '@vltpkg/pick-manifest'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { PathScurry } from 'path-scurry'\nimport type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\nimport { optionalFail } from './optional-fail.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\n\n/**\n * Result of the extraction operation.\n * Either the extracted package data or an error if extraction failed.\n */\nexport type ExtractResult =\n | {\n success: true\n node: Node\n }\n | {\n success: false\n node: Node\n error: unknown\n }\n\n/**\n * Returns a function that handles removing\n * a failed optional node from its graph.\n * Returns undefined for non-optional nodes when no diff is provided.\n */\nconst getOptionalFailedNodeRemover = (node: Node, diff?: Diff) => {\n return (\n diff ? optionalFail(diff, node)\n : node.isOptional() ?\n () => removeOptionalSubgraph(node.graph, node)\n : undefined\n )\n}\n\n/**\n * Extract a single node to the file system.\n * Returns a promise that resolves when the extraction is complete.\n */\nexport const extractNode = async (\n node: Node,\n scurry: PathScurry,\n remover: RollbackRemove,\n options: SpecOptions,\n packageInfo: PackageInfoClient,\n diff?: Diff,\n): Promise<ExtractResult> => {\n node.extracted = true\n const { manifest = {} } = node\n const target = node.resolvedLocation(scurry)\n const from = scurry.resolve('')\n const spec = hydrate(node.id, node.name, options)\n const removeOptionalFailedNode = getOptionalFailedNodeRemover(\n node,\n diff,\n )\n const { integrity, resolved } = node\n\n // Use platform data from node if available (from lockfile), otherwise fall back to manifest\n const platformData = node.platform ?? manifest\n\n // Check if we should skip this node due to platform incompatibility or deprecation\n if (\n removeOptionalFailedNode &&\n (manifest.deprecated ||\n !platformCheck(\n platformData,\n process.version,\n process.platform,\n process.arch,\n // libc is auto-detected by platformCheck when not provided\n ))\n ) {\n removeOptionalFailedNode()\n return {\n success: false,\n node,\n error: new Error('Platform check failed or package deprecated'),\n }\n }\n\n try {\n await remover.rm(target)\n\n if (removeOptionalFailedNode) {\n try {\n const result = await packageInfo.extract(spec, target, {\n from,\n integrity,\n resolved,\n })\n // Store computed integrity for git/remote deps\n if (result.integrity && !node.integrity) {\n node.integrity = result.integrity\n }\n return { success: true, node }\n } catch (error) {\n removeOptionalFailedNode()\n return { success: false, node, error }\n }\n } else {\n const result = await packageInfo.extract(spec, target, {\n from,\n integrity,\n resolved,\n })\n // Store computed integrity for git/remote deps\n if (result.integrity && !node.integrity) {\n node.integrity = result.integrity\n }\n return { success: true, node }\n }\n } catch (error) {\n /* c8 ignore start */\n if (removeOptionalFailedNode) {\n removeOptionalFailedNode()\n return { success: false, node, error }\n }\n /* c8 ignore stop */\n throw error\n }\n}\n"]}
|
package/dist/reify/index.js
CHANGED
|
@@ -119,7 +119,7 @@ const reify_ = async (options, diff, remover) => {
|
|
|
119
119
|
await internalHoist(diff.to, options, remover);
|
|
120
120
|
// looks up all nodes setting buildState = 'needed'
|
|
121
121
|
// on nodes that require building
|
|
122
|
-
checkNeededBuild({ diff, scurry });
|
|
122
|
+
checkNeededBuild({ diff, scurry, packageJson });
|
|
123
123
|
// Filter nodes allowed to run scripts if allowScripts query is provided
|
|
124
124
|
const allowScriptsNodes = await filterNodesByQuery(diff.to, allowScripts);
|
|
125
125
|
// ensure that all added bins are chmod +x
|
package/dist/reify/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAKtD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,oBAAoB,EA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,CAAC,CAAA;IAElD,6DAA6D;IAC7D,wBAAwB,EAAE,EAAE,CAAA;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;IAExD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,YAAY,CACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAC7C,CAAA;IACH,CAAC;IAED,4BAA4B;IAC5B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { graphStep } from '@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { checkNeededBuild } from './check-needed-build.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport type { NodeLike } from '@vltpkg/types'\nimport { binChmodAll } from './bin-chmod.ts'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n/**\n * Filter nodes using a DSS query string\n */\nconst filterNodesByQuery = async (\n graph: Graph,\n allowScriptsQuery?: string,\n): Promise<Set<DepID>> => {\n // shortcut no packages included\n if (\n allowScriptsQuery === ':not(*)' /* c8 ignore next */ ||\n !allowScriptsQuery\n ) {\n return new Set()\n }\n // shortcut all packages included\n if (allowScriptsQuery === '*') {\n return new Set(graph.nodes.keys())\n }\n /* c8 ignore start */\n const securityArchive =\n Query.hasSecuritySelectors(allowScriptsQuery) ?\n await SecurityArchive.start({\n nodes: [...graph.nodes.values()],\n })\n : undefined\n /* c8 ignore stop */\n\n const edges = graph.edges\n const nodes = new Set<NodeLike>(graph.nodes.values())\n const importers = graph.importers\n\n const query = new Query({\n edges,\n nodes,\n importers,\n securityArchive,\n })\n\n const { nodes: resultNodes } = await query.search(\n allowScriptsQuery,\n {\n signal: new AbortController().signal,\n },\n )\n\n return new Set(resultNodes.map(node => node.id))\n}\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n allowScripts: string\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n remover: RollbackRemove\n}\n\nexport type ReifyResult = {\n /**\n * The diff object that was used to reify the project.\n */\n diff: Diff\n /**\n * Optional queue of DepIDs that requires building (running lifecycle scripts\n * and binary linking) after the reification is complete.\n */\n buildQueue?: DepID[]\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (\n options: ReifyOptions,\n): Promise<ReifyResult> => {\n const done = graphStep('reify')\n\n const { graph, scurry, remover } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const noModifiedDependencies =\n !options.add?.modifiedDependencies &&\n !options.remove?.modifiedDependencies\n const skipOptionalOnly = noModifiedDependencies && diff.optionalOnly\n const res: ReifyResult = { diff }\n if (!diff.hasChanges() || skipOptionalOnly) {\n // nothing to do, so just return the diff\n done()\n return res\n }\n\n let success = false\n try {\n const { buildQueue } = await reify_(options, diff, remover)\n remover.confirm()\n success = true\n res.buildQueue = buildQueue\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return res\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n): Promise<Omit<ReifyResult, 'diff'>> => {\n const res: Omit<ReifyResult, 'diff'> = {}\n const {\n add,\n remove,\n packageInfo,\n packageJson,\n scurry,\n allowScripts,\n } = options\n const saveImportersPackageJson =\n /* c8 ignore next */\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions = addEdges(diff, scurry, remover)\n if (edgeActions.length) await callLimit(edgeActions, { limit })\n\n await internalHoist(diff.to, options, remover)\n\n // looks up all nodes setting buildState = 'needed'\n // on nodes that require building\n checkNeededBuild({ diff, scurry })\n\n // Filter nodes allowed to run scripts if allowScripts query is provided\n const allowScriptsNodes = await filterNodesByQuery(\n diff.to,\n allowScripts,\n )\n\n // ensure that all added bins are chmod +x\n await binChmodAll(diff.nodes.add, scurry)\n\n // run install lifecycle scripts and link any binary files\n await build(diff, packageJson, scurry, allowScriptsNodes)\n\n // set the buildQueue on the result object containing\n // an array with all the ids of nodes that need building\n res.buildQueue = [...diff.nodes.add]\n .filter(node => node.buildState === 'needed')\n .map(node => node.id)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n // TODO: add tests to cover this\n /* c8 ignore start */\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n /* c8 ignore stop */\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n\n // returns the result object\n return res\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAKtD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,g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AI,CAAC,mBAAmB,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;IACD,oBAAoB;IACpB,UAAU,CAAC,OAAO,CAAC,CAAA;IAEnB,iCAAiC;IACjC,MAAM,SAAS,GAAuB,WAAW,CAC/C,IAAI,EACJ,OAAO,EACP,MAAM,CACP,CAAA;IACD,IAAI,SAAS,CAAC,MAAM;QAAE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IAElD,6DAA6D;IAC7D,wBAAwB,EAAE,EAAE,CAAA;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;IAExD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,YAAY,CACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAC7C,CAAA;IACH,CAAC;IAED,4BAA4B;IAC5B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { graphStep } from '@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { checkNeededBuild } from './check-needed-build.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport type { NodeLike } from '@vltpkg/types'\nimport { binChmodAll } from './bin-chmod.ts'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n/**\n * Filter nodes using a DSS query string\n */\nconst filterNodesByQuery = async (\n graph: Graph,\n allowScriptsQuery?: string,\n): Promise<Set<DepID>> => {\n // shortcut no packages included\n if (\n allowScriptsQuery === ':not(*)' /* c8 ignore next */ ||\n !allowScriptsQuery\n ) {\n return new Set()\n }\n // shortcut all packages included\n if (allowScriptsQuery === '*') {\n return new Set(graph.nodes.keys())\n }\n /* c8 ignore start */\n const securityArchive =\n Query.hasSecuritySelectors(allowScriptsQuery) ?\n await SecurityArchive.start({\n nodes: [...graph.nodes.values()],\n })\n : undefined\n /* c8 ignore stop */\n\n const edges = graph.edges\n const nodes = new Set<NodeLike>(graph.nodes.values())\n const importers = graph.importers\n\n const query = new Query({\n edges,\n nodes,\n importers,\n securityArchive,\n })\n\n const { nodes: resultNodes } = await query.search(\n allowScriptsQuery,\n {\n signal: new AbortController().signal,\n },\n )\n\n return new Set(resultNodes.map(node => node.id))\n}\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n allowScripts: string\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n remover: RollbackRemove\n}\n\nexport type ReifyResult = {\n /**\n * The diff object that was used to reify the project.\n */\n diff: Diff\n /**\n * Optional queue of DepIDs that requires building (running lifecycle scripts\n * and binary linking) after the reification is complete.\n */\n buildQueue?: DepID[]\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (\n options: ReifyOptions,\n): Promise<ReifyResult> => {\n const done = graphStep('reify')\n\n const { graph, scurry, remover } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const noModifiedDependencies =\n !options.add?.modifiedDependencies &&\n !options.remove?.modifiedDependencies\n const skipOptionalOnly = noModifiedDependencies && diff.optionalOnly\n const res: ReifyResult = { diff }\n if (!diff.hasChanges() || skipOptionalOnly) {\n // nothing to do, so just return the diff\n done()\n return res\n }\n\n let success = false\n try {\n const { buildQueue } = await reify_(options, diff, remover)\n remover.confirm()\n success = true\n res.buildQueue = buildQueue\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return res\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n): Promise<Omit<ReifyResult, 'diff'>> => {\n const res: Omit<ReifyResult, 'diff'> = {}\n const {\n add,\n remove,\n packageInfo,\n packageJson,\n scurry,\n allowScripts,\n } = options\n const saveImportersPackageJson =\n /* c8 ignore next */\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions = addEdges(diff, scurry, remover)\n if (edgeActions.length) await callLimit(edgeActions, { limit })\n\n await internalHoist(diff.to, options, remover)\n\n // looks up all nodes setting buildState = 'needed'\n // on nodes that require building\n checkNeededBuild({ diff, scurry, packageJson })\n\n // Filter nodes allowed to run scripts if allowScripts query is provided\n const allowScriptsNodes = await filterNodesByQuery(\n diff.to,\n allowScripts,\n )\n\n // ensure that all added bins are chmod +x\n await binChmodAll(diff.nodes.add, scurry)\n\n // run install lifecycle scripts and link any binary files\n await build(diff, packageJson, scurry, allowScriptsNodes)\n\n // set the buildQueue on the result object containing\n // an array with all the ids of nodes that need building\n res.buildQueue = [...diff.nodes.add]\n .filter(node => node.buildState === 'needed')\n .map(node => node.id)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n // TODO: add tests to cover this\n /* c8 ignore start */\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n /* c8 ignore stop */\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n\n // returns the result object\n return res\n}\n"]}
|
|
@@ -3,6 +3,7 @@ export type MermaidOutputGraph = {
|
|
|
3
3
|
edges: EdgeLike[];
|
|
4
4
|
importers: Set<NodeLike>;
|
|
5
5
|
nodes: NodeLike[];
|
|
6
|
+
highlightSelection?: boolean;
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
8
9
|
* Generates a short identifier for a given index following the pattern:
|
|
@@ -13,5 +14,5 @@ export declare function generateShortId(index: number): string;
|
|
|
13
14
|
/**
|
|
14
15
|
* Returns a mermaid string representation of the graph.
|
|
15
16
|
*/
|
|
16
|
-
export declare function mermaidOutput(
|
|
17
|
+
export declare function mermaidOutput(options: MermaidOutputGraph): string;
|
|
17
18
|
//# sourceMappingURL=mermaid-output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid-output.d.ts","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"mermaid-output.d.ts","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAiBD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA0BrD;AA8ID;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,kBAAkB,UA8ExD"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Edge } from "../edge.js";
|
|
2
2
|
import { Node } from "../node.js";
|
|
3
3
|
let missingCount = 0;
|
|
4
|
+
const isSelected = (options, edge, node) => (!node || options.nodes.includes(node)) &&
|
|
5
|
+
/* c8 ignore next */ (!edge || options.edges.includes(edge));
|
|
4
6
|
/**
|
|
5
7
|
* Generates a short identifier for a given index following the pattern:
|
|
6
8
|
* 0 -> a, 1 -> b, ..., 25 -> z, 26 -> A, ..., 51 -> Z, 52 -> aa, 53 -> ab, etc.
|
|
@@ -58,29 +60,35 @@ function createDepIdMapping(importers) {
|
|
|
58
60
|
* been labeled. This tracking is shared across multiple importers to prevent duplicate
|
|
59
61
|
* labels in the output.
|
|
60
62
|
*/
|
|
61
|
-
const nodeRef = (node, labeledNodes, depIdMapping) => {
|
|
63
|
+
const nodeRef = (node, labeledNodes, depIdMapping, options) => {
|
|
62
64
|
const shortId = depIdMapping.get(node.id) /* c8 ignore next - should not be possible */ ?? '';
|
|
65
|
+
const selectedClass = (options.highlightSelection &&
|
|
66
|
+
isSelected(options, undefined, node)) ?
|
|
67
|
+
':::selected'
|
|
68
|
+
: '';
|
|
63
69
|
if (labeledNodes.has(node.id)) {
|
|
64
|
-
return shortId;
|
|
70
|
+
return shortId + selectedClass;
|
|
65
71
|
}
|
|
66
72
|
labeledNodes.add(node.id);
|
|
67
|
-
return `${shortId}("${String(node).replaceAll('@', '#64;')}")`;
|
|
73
|
+
return `${shortId}("${String(node).replaceAll('@', '#64;')}")${selectedClass}`;
|
|
68
74
|
};
|
|
69
|
-
function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, node, isImporter = false) {
|
|
75
|
+
function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, node, isImporter = false) {
|
|
70
76
|
if (seenNodes.has(node.id) || !includedItems.get(node)) {
|
|
71
77
|
return '';
|
|
72
78
|
}
|
|
73
79
|
seenNodes.add(node.id);
|
|
74
80
|
// For importers, render the node label first as a standalone line before processing edges,
|
|
75
81
|
// since they appear at the top of the graph. Non-importer nodes are labeled inline as part of edge definitions.
|
|
76
|
-
const nodeLabel = isImporter ?
|
|
82
|
+
const nodeLabel = isImporter ?
|
|
83
|
+
nodeRef(node, labeledNodes, depIdMapping, options)
|
|
84
|
+
: '';
|
|
77
85
|
// Include both regular edges and workspace edges (if any)
|
|
78
86
|
const allEdges = [
|
|
79
87
|
...node.edgesOut.values(),
|
|
80
88
|
...(node.workspaces?.values() ?? []),
|
|
81
89
|
];
|
|
82
90
|
const edges = allEdges
|
|
83
|
-
.map(e => parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, e))
|
|
91
|
+
.map(e => parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options, e))
|
|
84
92
|
.filter(Boolean)
|
|
85
93
|
.join('\n');
|
|
86
94
|
// Only render node standalone for importers, others are rendered as part of edges
|
|
@@ -90,12 +98,12 @@ function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, node, i
|
|
|
90
98
|
}
|
|
91
99
|
return edges;
|
|
92
100
|
}
|
|
93
|
-
function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, edge) {
|
|
101
|
+
function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options, edge) {
|
|
94
102
|
if (!includedItems.get(edge)) {
|
|
95
103
|
return '';
|
|
96
104
|
}
|
|
97
105
|
const edgeType = edge.type === 'prod' ? '' : ` (${edge.type})`;
|
|
98
|
-
const edgeResult = nodeRef(edge.from, labeledNodes, depIdMapping) +
|
|
106
|
+
const edgeResult = nodeRef(edge.from, labeledNodes, depIdMapping, options) +
|
|
99
107
|
` -->|"${String(edge.spec).replaceAll('@', '#64;')}${edgeType}"| `;
|
|
100
108
|
const missingLabel = edge.type.endsWith('ptional') ? 'Missing Optional' : 'Missing';
|
|
101
109
|
if (!edge.to) {
|
|
@@ -103,14 +111,15 @@ function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, edge) {
|
|
|
103
111
|
}
|
|
104
112
|
// Label the target node first so that if it's referenced again later in the graph,
|
|
105
113
|
// it will use the short identifier instead of repeating the full label.
|
|
106
|
-
const toRef = nodeRef(edge.to, labeledNodes, depIdMapping);
|
|
107
|
-
const childEdges = parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, edge.to);
|
|
114
|
+
const toRef = nodeRef(edge.to, labeledNodes, depIdMapping, options);
|
|
115
|
+
const childEdges = parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, edge.to);
|
|
108
116
|
return edgeResult + toRef + (childEdges ? '\n' + childEdges : '');
|
|
109
117
|
}
|
|
110
118
|
/**
|
|
111
119
|
* Returns a mermaid string representation of the graph.
|
|
112
120
|
*/
|
|
113
|
-
export function mermaidOutput(
|
|
121
|
+
export function mermaidOutput(options) {
|
|
122
|
+
const { edges, importers, nodes, highlightSelection } = options;
|
|
114
123
|
const seen = new Set();
|
|
115
124
|
const includedItems = new Map();
|
|
116
125
|
const traverse = new Set([...importers].map(i => ({ self: i, parent: undefined })));
|
|
@@ -155,10 +164,13 @@ export function mermaidOutput({ edges, importers, nodes, }) {
|
|
|
155
164
|
const labeledNodes = new Set();
|
|
156
165
|
// Track nodes that have been processed (shared across all importers to avoid duplicates)
|
|
157
166
|
const seenNodes = new Set();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
const graphOutput = [...importers]
|
|
168
|
+
.map(i => parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, i, true))
|
|
169
|
+
.filter(Boolean)
|
|
170
|
+
.join('\n');
|
|
171
|
+
const styleDefinition = highlightSelection ?
|
|
172
|
+
'\nclassDef selected fill:gold,color:#242424'
|
|
173
|
+
: '';
|
|
174
|
+
return 'flowchart TD\n' + graphOutput + styleDefinition;
|
|
163
175
|
}
|
|
164
176
|
//# sourceMappingURL=mermaid-output.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid-output.js","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AACA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I,CAAC,GAAG,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChD,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;IAED,2CAA2C;IAC3C,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAA;IAElD,8EAA8E;IAC9E,MAAM,YAAY,GAAG,IAAI,GAAG,EAAS,CAAA;IAErC,yFAAyF;IACzF,MAAM,SAAS,GAAG,IAAI,GAAG,EAAS,CAAA;IAElC,OAAO,CACL,gBAAgB;QAChB,CAAC,GAAG,SAAS,CAAC;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,CACP,SAAS,CACP,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,CAAC,EACD,IAAI,CACL,CACF;aACA,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,IAAI,CAAC,CACd,CAAA;AACH,CAAC","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { Edge } from '../edge.ts'\nimport { Node } from '../node.ts'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\n\nexport type MermaidOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n}\n\ntype TraverseItem = {\n self: EdgeLike | NodeLike\n parent: EdgeLike | NodeLike | undefined\n}\n\nlet missingCount = 0\n\n/**\n * Generates a short identifier for a given index following the pattern:\n * 0 -> a, 1 -> b, ..., 25 -> z, 26 -> A, ..., 51 -> Z, 52 -> aa, 53 -> ab, etc.\n * This implements a bijective base-52 numbering system where a-z = 0-25, A-Z = 26-51\n */\nexport function generateShortId(index: number): string {\n const base = 52\n\n // Helper function to convert a digit (0-51) to character\n const digitToChar = (digit: number): string => {\n if (digit < 26) {\n // a-z (0-25)\n return String.fromCharCode(97 + digit)\n } else {\n // A-Z (26-51)\n return String.fromCharCode(65 + (digit - 26))\n }\n }\n\n // Bijective base-52 conversion\n let result = ''\n let num = index + 1 // Convert to 1-based for bijective base\n\n while (num > 0) {\n num-- // Adjust for 0-based indexing in each position\n const remainder = num % base\n result = digitToChar(remainder) + result\n num = Math.floor(num / base)\n }\n\n return result\n}\n\n/**\n * Creates a mapping from DepID to short identifier\n */\nfunction createDepIdMapping(\n importers: Set<NodeLike>,\n): Map<DepID, string> {\n const mapping = new Map<DepID, string>()\n const uniqueDepIds = new Set<DepID>()\n\n // Collect all unique DepIDs from nodes & importers\n const [importer] = importers\n if (importer) {\n for (const node of importer.graph.nodes.values()) {\n uniqueDepIds.add(node.id)\n }\n }\n\n // Create mapping for each unique DepID\n let index = 0\n for (const depId of uniqueDepIds) {\n mapping.set(depId, generateShortId(index++))\n }\n\n return mapping\n}\n\n/**\n * Returns a node reference: on the first occurrence of a node, returns the full label;\n * on subsequent occurrences, returns just the shortId.\n *\n * Note: Mutates the `labeledNodes` set as a side effect to track which nodes have already\n * been labeled. This tracking is shared across multiple importers to prevent duplicate\n * labels in the output.\n */\nconst nodeRef = (\n node: NodeLike,\n labeledNodes: Set<DepID>,\n depIdMapping: Map<DepID, string>,\n): string => {\n const shortId =\n depIdMapping.get(\n node.id,\n ) /* c8 ignore next - should not be possible */ ?? ''\n if (labeledNodes.has(node.id)) {\n return shortId\n }\n labeledNodes.add(node.id)\n return `${shortId}(\"${String(node).replaceAll('@', '#64;')}\")`\n}\n\nfunction parseNode(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n node: NodeLike,\n isImporter = false,\n) {\n if (seenNodes.has(node.id) || !includedItems.get(node)) {\n return ''\n }\n seenNodes.add(node.id)\n // For importers, render the node label first as a standalone line before processing edges,\n // since they appear at the top of the graph. Non-importer nodes are labeled inline as part of edge definitions.\n const nodeLabel =\n isImporter ? nodeRef(node, labeledNodes, depIdMapping) : ''\n // Include both regular edges and workspace edges (if any)\n const allEdges = [\n ...node.edgesOut.values(),\n ...(node.workspaces?.values() ?? []),\n ]\n const edges: string = allEdges\n .map(e =>\n parseEdge(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n e,\n ),\n )\n .filter(Boolean)\n .join('\\n')\n // Only render node standalone for importers, others are rendered as part of edges\n if (isImporter) {\n /* c8 ignore next */\n return `${nodeLabel}${edges.length ? '\\n' : ''}${edges}`\n }\n return edges\n}\n\nfunction parseEdge(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n edge: EdgeLike,\n) {\n if (!includedItems.get(edge)) {\n return ''\n }\n\n const edgeType = edge.type === 'prod' ? '' : ` (${edge.type})`\n const edgeResult =\n nodeRef(edge.from, labeledNodes, depIdMapping) +\n ` -->|\"${String(edge.spec).replaceAll('@', '#64;')}${edgeType}\"| `\n\n const missingLabel =\n edge.type.endsWith('ptional') ? 'Missing Optional' : 'Missing'\n if (!edge.to) {\n return edgeResult + `missing-${missingCount++}(${missingLabel})`\n }\n\n // Label the target node first so that if it's referenced again later in the graph,\n // it will use the short identifier instead of repeating the full label.\n const toRef = nodeRef(edge.to, labeledNodes, depIdMapping)\n const childEdges = parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n edge.to,\n )\n return edgeResult + toRef + (childEdges ? '\\n' + childEdges : '')\n}\n\n/**\n * Returns a mermaid string representation of the graph.\n */\nexport function mermaidOutput({\n edges,\n importers,\n nodes,\n}: MermaidOutputGraph) {\n const seen = new Set<EdgeLike | NodeLike>()\n const includedItems = new Map<EdgeLike | NodeLike, boolean>()\n const traverse = new Set<TraverseItem>(\n [...importers].map(i => ({ self: i, parent: undefined })),\n )\n\n for (const item of traverse) {\n if (seen.has(item.self)) continue\n seen.add(item.self)\n\n if (item.self instanceof Edge) {\n // Workspace edges are stored in mainImporter.workspaces and not in graph.edges,\n // so we need to check for workspace spec type to always include them\n if (\n edges.includes(item.self) ||\n item.self.spec.type === 'workspace'\n ) {\n includedItems.set(item.self, true)\n }\n if (item.self.to) {\n traverse.add({ self: item.self.to, parent: item.self })\n }\n }\n\n if (item.self instanceof Node) {\n if (nodes.includes(item.self)) {\n includedItems.set(item.self, true)\n }\n for (const edge of item.self.edgesOut.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n // Also traverse workspace edges (only mainImporter has these)\n if (item.self.workspaces) {\n for (const edge of item.self.workspaces.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n }\n }\n }\n\n for (const item of [...traverse].reverse()) {\n if (includedItems.has(item.self) && item.parent) {\n includedItems.set(item.parent, true)\n }\n }\n\n // Create DepID to short identifier mapping\n const depIdMapping = createDepIdMapping(importers)\n\n // Track nodes that have had their label printed (shared across all importers)\n const labeledNodes = new Set<DepID>()\n\n // Track nodes that have been processed (shared across all importers to avoid duplicates)\n const seenNodes = new Set<DepID>()\n\n return (\n 'flowchart TD\\n' +\n [...importers]\n .map(i =>\n parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n i,\n true, // isImporter\n ),\n )\n .filter(Boolean)\n .join('\\n')\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mermaid-output.js","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAejC,IAAI,YAAY,GAAG,CAAC,CAAA;AAEpB,MAAM,UAAU,GAAG,CACjB,OAA2B,EAC3B,IAAe,EACf,IAAe,EACf,EAAE,CACF,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvC,oBAAoB,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,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MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;oBACjD,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;gBACjD,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChD,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;IAED,2CAA2C;IAC3C,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAA;IAElD,8EAA8E;IAC9E,MAAM,YAAY,GAAG,IAAI,GAAG,EAAS,CAAA;IAErC,yFAAyF;IACzF,MAAM,SAAS,GAAG,IAAI,GAAG,EAAS,CAAA;IAElC,MAAM,WAAW,GAAG,CAAC,GAAG,SAAS,CAAC;SAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,CACP,SAAS,CACP,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,OAAO,EACP,CAAC,EACD,IAAI,CACL,CACF;SACA,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,eAAe,GACnB,kBAAkB,CAAC,CAAC;QAClB,6CAA6C;QAC/C,CAAC,CAAC,EAAE,CAAA;IAEN,OAAO,gBAAgB,GAAG,WAAW,GAAG,eAAe,CAAA;AACzD,CAAC","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { Edge } from '../edge.ts'\nimport { Node } from '../node.ts'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\n\nexport type MermaidOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n highlightSelection?: boolean\n}\n\ntype TraverseItem = {\n self: EdgeLike | NodeLike\n parent: EdgeLike | NodeLike | undefined\n}\n\nlet missingCount = 0\n\nconst isSelected = (\n options: MermaidOutputGraph,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n (!node || options.nodes.includes(node)) &&\n /* c8 ignore next */ (!edge || options.edges.includes(edge))\n\n/**\n * Generates a short identifier for a given index following the pattern:\n * 0 -> a, 1 -> b, ..., 25 -> z, 26 -> A, ..., 51 -> Z, 52 -> aa, 53 -> ab, etc.\n * This implements a bijective base-52 numbering system where a-z = 0-25, A-Z = 26-51\n */\nexport function generateShortId(index: number): string {\n const base = 52\n\n // Helper function to convert a digit (0-51) to character\n const digitToChar = (digit: number): string => {\n if (digit < 26) {\n // a-z (0-25)\n return String.fromCharCode(97 + digit)\n } else {\n // A-Z (26-51)\n return String.fromCharCode(65 + (digit - 26))\n }\n }\n\n // Bijective base-52 conversion\n let result = ''\n let num = index + 1 // Convert to 1-based for bijective base\n\n while (num > 0) {\n num-- // Adjust for 0-based indexing in each position\n const remainder = num % base\n result = digitToChar(remainder) + result\n num = Math.floor(num / base)\n }\n\n return result\n}\n\n/**\n * Creates a mapping from DepID to short identifier\n */\nfunction createDepIdMapping(\n importers: Set<NodeLike>,\n): Map<DepID, string> {\n const mapping = new Map<DepID, string>()\n const uniqueDepIds = new Set<DepID>()\n\n // Collect all unique DepIDs from nodes & importers\n const [importer] = importers\n if (importer) {\n for (const node of importer.graph.nodes.values()) {\n uniqueDepIds.add(node.id)\n }\n }\n\n // Create mapping for each unique DepID\n let index = 0\n for (const depId of uniqueDepIds) {\n mapping.set(depId, generateShortId(index++))\n }\n\n return mapping\n}\n\n/**\n * Returns a node reference: on the first occurrence of a node, returns the full label;\n * on subsequent occurrences, returns just the shortId.\n *\n * Note: Mutates the `labeledNodes` set as a side effect to track which nodes have already\n * been labeled. This tracking is shared across multiple importers to prevent duplicate\n * labels in the output.\n */\nconst nodeRef = (\n node: NodeLike,\n labeledNodes: Set<DepID>,\n depIdMapping: Map<DepID, string>,\n options: MermaidOutputGraph,\n): string => {\n const shortId =\n depIdMapping.get(\n node.id,\n ) /* c8 ignore next - should not be possible */ ?? ''\n const selectedClass =\n (\n options.highlightSelection &&\n isSelected(options, undefined, node)\n ) ?\n ':::selected'\n : ''\n if (labeledNodes.has(node.id)) {\n return shortId + selectedClass\n }\n labeledNodes.add(node.id)\n return `${shortId}(\"${String(node).replaceAll('@', '#64;')}\")${selectedClass}`\n}\n\nfunction parseNode(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n options: MermaidOutputGraph,\n node: NodeLike,\n isImporter = false,\n) {\n if (seenNodes.has(node.id) || !includedItems.get(node)) {\n return ''\n }\n seenNodes.add(node.id)\n // For importers, render the node label first as a standalone line before processing edges,\n // since they appear at the top of the graph. Non-importer nodes are labeled inline as part of edge definitions.\n const nodeLabel =\n isImporter ?\n nodeRef(node, labeledNodes, depIdMapping, options)\n : ''\n // Include both regular edges and workspace edges (if any)\n const allEdges = [\n ...node.edgesOut.values(),\n ...(node.workspaces?.values() ?? []),\n ]\n const edges: string = allEdges\n .map(e =>\n parseEdge(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n options,\n e,\n ),\n )\n .filter(Boolean)\n .join('\\n')\n // Only render node standalone for importers, others are rendered as part of edges\n if (isImporter) {\n /* c8 ignore next */\n return `${nodeLabel}${edges.length ? '\\n' : ''}${edges}`\n }\n return edges\n}\n\nfunction parseEdge(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n options: MermaidOutputGraph,\n edge: EdgeLike,\n) {\n if (!includedItems.get(edge)) {\n return ''\n }\n\n const edgeType = edge.type === 'prod' ? '' : ` (${edge.type})`\n const edgeResult =\n nodeRef(edge.from, labeledNodes, depIdMapping, options) +\n ` -->|\"${String(edge.spec).replaceAll('@', '#64;')}${edgeType}\"| `\n\n const missingLabel =\n edge.type.endsWith('ptional') ? 'Missing Optional' : 'Missing'\n if (!edge.to) {\n return edgeResult + `missing-${missingCount++}(${missingLabel})`\n }\n\n // Label the target node first so that if it's referenced again later in the graph,\n // it will use the short identifier instead of repeating the full label.\n const toRef = nodeRef(edge.to, labeledNodes, depIdMapping, options)\n const childEdges = parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n options,\n edge.to,\n )\n return edgeResult + toRef + (childEdges ? '\\n' + childEdges : '')\n}\n\n/**\n * Returns a mermaid string representation of the graph.\n */\nexport function mermaidOutput(options: MermaidOutputGraph) {\n const { edges, importers, nodes, highlightSelection } = options\n const seen = new Set<EdgeLike | NodeLike>()\n const includedItems = new Map<EdgeLike | NodeLike, boolean>()\n const traverse = new Set<TraverseItem>(\n [...importers].map(i => ({ self: i, parent: undefined })),\n )\n\n for (const item of traverse) {\n if (seen.has(item.self)) continue\n seen.add(item.self)\n\n if (item.self instanceof Edge) {\n // Workspace edges are stored in mainImporter.workspaces and not in graph.edges,\n // so we need to check for workspace spec type to always include them\n if (\n edges.includes(item.self) ||\n item.self.spec.type === 'workspace'\n ) {\n includedItems.set(item.self, true)\n }\n if (item.self.to) {\n traverse.add({ self: item.self.to, parent: item.self })\n }\n }\n\n if (item.self instanceof Node) {\n if (nodes.includes(item.self)) {\n includedItems.set(item.self, true)\n }\n for (const edge of item.self.edgesOut.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n // Also traverse workspace edges (only mainImporter has these)\n if (item.self.workspaces) {\n for (const edge of item.self.workspaces.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n }\n }\n }\n\n for (const item of [...traverse].reverse()) {\n if (includedItems.has(item.self) && item.parent) {\n includedItems.set(item.parent, true)\n }\n }\n\n // Create DepID to short identifier mapping\n const depIdMapping = createDepIdMapping(importers)\n\n // Track nodes that have had their label printed (shared across all importers)\n const labeledNodes = new Set<DepID>()\n\n // Track nodes that have been processed (shared across all importers to avoid duplicates)\n const seenNodes = new Set<DepID>()\n\n const graphOutput = [...importers]\n .map(i =>\n parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n options,\n i,\n true, // isImporter\n ),\n )\n .filter(Boolean)\n .join('\\n')\n\n const styleDefinition =\n highlightSelection ?\n '\\nclassDef selected fill:gold,color:#242424'\n : ''\n\n return 'flowchart TD\\n' + graphOutput + styleDefinition\n}\n"]}
|