@vltpkg/graph 0.0.0-10 → 0.0.0-12
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/dist/esm/graph.js +1 -1
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
- package/dist/esm/lockfile/load-nodes.js +4 -1
- package/dist/esm/lockfile/load-nodes.js.map +1 -1
- package/dist/esm/lockfile/save.d.ts +2 -2
- package/dist/esm/lockfile/save.d.ts.map +1 -1
- package/dist/esm/lockfile/save.js +5 -2
- package/dist/esm/lockfile/save.js.map +1 -1
- package/dist/esm/lockfile/types.d.ts +2 -1
- package/dist/esm/lockfile/types.d.ts.map +1 -1
- package/dist/esm/lockfile/types.js.map +1 -1
- package/dist/esm/node.d.ts +15 -0
- package/dist/esm/node.d.ts.map +1 -1
- package/dist/esm/node.js +32 -1
- package/dist/esm/node.js.map +1 -1
- package/dist/esm/types.d.ts +6 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
- package/dist/esm/visualization/human-readable-output.js +5 -3
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/package.json +21 -20
package/dist/esm/graph.js
CHANGED
|
@@ -248,7 +248,7 @@ export class Graph {
|
|
|
248
248
|
return toFoundNode;
|
|
249
249
|
}
|
|
250
250
|
// creates a new node and edges to its parent
|
|
251
|
-
const toNode = this.addNode(depId, manifest);
|
|
251
|
+
const toNode = this.addNode(depId, manifest, spec);
|
|
252
252
|
toNode.registry = spec.registry;
|
|
253
253
|
toNode.dev = flags.dev;
|
|
254
254
|
toNode.optional = flags.optional;
|
package/dist/esm/graph.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAA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,SAAS,CACP,WAAW,CAAC,EAAE,EACd,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,CAAC,QAAQ,EAClB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,QAAQ,CACd,EACD,CAAC;gBACD,IAAI,CAAC,EAAE,GAAG,WAAW,CAAA;YACvB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACzC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO,YAAY,CAAC;YAClB,GAAG,IAAI,CAAC,QAAQ;YAChB,KAAK,EAAE,IAAI;YACX,aAAa,EAAE,IAAI;SACpB,CAAC,CAAA;IACJ,CAAC;IAED,CAAC,cAAc,CAAC,CAAC,CAAS,EAAE,OAAuB;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;QAC1B,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAA;IAChE,CAAC;CACF","sourcesContent":["import { getId, joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport { satisfies } from '@vltpkg/satisfies'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { Manifest, DependencySaveType } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport { inspect } from 'node:util'\nimport type { InspectOptions } from 'node:util'\nimport type { Edge } from './edge.ts'\nimport { lockfileData } from './lockfile/save.ts'\nimport { Node } from './node.ts'\nimport type { NodeOptions } from './node.ts'\nimport type { GraphLike, NodeLike } from './types.ts'\nimport { resolveSaveType } from './resolve-save-type.ts'\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\n// this is always the same, but we don't hard code it as a string,\n// in case the DepID module needs to change its delimiter again ever.\nconst mainDepID = joinDepIDTuple(['file', '.'])\n\nexport type ManifestInventory = Map<DepID, Manifest>\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\nexport type GraphOptions = SpecOptions & {\n /**\n * The main importer manifest info.\n */\n mainManifest: Manifest\n /**\n * An inventory of seen manifests.\n */\n manifests?: ManifestInventory\n /**\n * A {@link Monorepo} object, for managing workspaces\n */\n monorepo?: Monorepo\n /**\n * Root of the project this graph represents\n */\n projectRoot: string\n}\n\nexport class Graph implements GraphLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Graph'\n }\n\n #options: GraphOptions\n\n #nodeOptions: NodeOptions\n\n /**\n * A {@link Monorepo} instance, used for managing workspaces.\n */\n monorepo?: Monorepo\n\n /**\n * An inventory with all manifests related to an install.\n */\n manifests: ManifestInventory\n\n /**\n * A set of all edges in this graph.\n */\n edges = new Set<Edge>()\n\n /**\n * Map registered dep ids to the node that represent them in the graph.\n */\n nodes = new Map<DepID, Node>()\n\n /**\n * Map of nodes by their name\n */\n nodesByName = new Map<string, Set<Node>>()\n\n /**\n * Cached resolutions for spec lookups\n */\n resolutions = new Map<string, Node>()\n\n /**\n * Reverse map of resolutions\n */\n resolutionsReverse = new Map<Node, Set<string>>()\n\n /**\n * A set of importer nodes in this graph.\n */\n importers = new Set<Node>()\n\n /**\n * The {@link Node} that represents the project root `package.json`.\n */\n mainImporter: Node\n\n /**\n * A set of extraneous dependencies found when building the graph.\n */\n extraneousDependencies = new Set<Edge>()\n\n /**\n * The root of the project this graph represents\n */\n projectRoot: string\n\n constructor(options: GraphOptions) {\n const { mainManifest, monorepo } = options\n this.#options = options\n this.manifests = getMap(options.manifests)\n this.projectRoot = options.projectRoot\n this.#nodeOptions = {\n ...this.#options,\n graph: this,\n }\n\n // add the project root node\n const mainImporterLocation = '.'\n const mainImporterSpec = Spec.parse(\n mainManifest.name || '(root)',\n mainImporterLocation,\n )\n const mainImporter = this.addNode(\n mainDepID,\n mainManifest,\n mainImporterSpec,\n )\n mainImporter.setImporterLocation(mainImporterLocation)\n mainImporter.mainImporter = true\n this.mainImporter = mainImporter\n this.importers.add(mainImporter)\n this.manifests.set(mainImporter.id, mainManifest)\n\n // uses the monorepo instance in order to retrieve info on\n // workspaces and create importer nodes for each of them\n this.monorepo = monorepo\n if (this.monorepo) {\n for (const ws of this.monorepo) {\n const wsNode = this.addNode(\n ws.id,\n ws.manifest,\n undefined,\n ws.name,\n )\n wsNode.setImporterLocation(`./${ws.path}`)\n if (wsNode.manifest) {\n this.manifests.set(wsNode.id, wsNode.manifest)\n }\n this.importers.add(wsNode)\n }\n }\n }\n\n /**\n * Delete all nodes that are unreachable from the importers.\n * The collection of deleted nodes is returned.\n *\n * NOTE: This can be extremely slow for large graphs, and is almost always\n * unnecessary! Only call when it is known that some unreachable nodes may\n * have been created, for example when deleting the unneeded subgraph when an\n * optional node fails to resolve/install.\n */\n gc() {\n const { nodes } = this\n this.nodes = new Map()\n const marked = new Set(this.importers)\n for (const imp of marked) {\n // don't delete the importer!\n nodes.delete(imp.id)\n this.nodes.set(imp.id, imp)\n for (const { to } of imp.edgesOut.values()) {\n if (!to || marked.has(to)) continue\n marked.add(to)\n nodes.delete(to.id)\n this.nodes.set(to.id, to)\n }\n }\n for (const node of nodes.values()) {\n this.removeNode(node)\n }\n return nodes\n }\n\n /**\n * Create a new edge between two nodes of the graph in case both exist,\n * in case the destination node does not exists, then a dangling edge,\n * pointing to nothing will be created to represent that missing dependency.\n */\n addEdge(\n type: DependencySaveType,\n spec: Spec,\n from: NodeLike,\n to?: NodeLike,\n ) {\n // fix any nameless spec\n if (spec.name === '(unknown)') {\n if (to) {\n spec.name = to.name /* c8 ignore next */ || '(unknown)'\n spec.spec = `${to.name}@${spec.bareSpec}`\n } else {\n throw error(\n 'Impossible to place a missing, nameless dependency',\n { spec },\n )\n }\n }\n const existing = from.edgesOut.get(spec.name)\n if (existing) {\n const edge = existing as Edge\n if (\n edge.type === type &&\n edge.spec.bareSpec === spec.bareSpec\n ) {\n if (to && to !== edge.to) {\n edge.to = to as Node\n edge.to.edgesIn.add(edge)\n }\n return edge\n }\n this.edges.delete(edge)\n }\n const f = from as Node\n const edgeOut = f.addEdgesTo(\n resolveSaveType(from, spec.name, type),\n spec,\n to as Node | undefined,\n )\n this.edges.add(edgeOut)\n return edgeOut\n }\n\n /**\n * Find an existing node to satisfy a dependency\n */\n findResolution(spec: Spec, fromNode: Node) {\n const f = spec.final\n // if it's a file: dep, then the fromNode location matters\n const fromPref =\n f.type === 'file' ? fromNode.location + ' : ' : ''\n const sf = fromPref + String(f)\n const cached = this.resolutions.get(sf)\n if (cached) return cached\n const nbn = this.nodesByName.get(f.name)\n if (!nbn) return undefined\n for (const node of nbn) {\n if (\n satisfies(\n node.id,\n f,\n fromNode.location,\n this.projectRoot,\n this.monorepo,\n )\n ) {\n this.resolutions.set(sf, node)\n // always set by now, because the node was added at some point\n this.resolutionsReverse.get(node)?.add(sf)\n return node\n }\n }\n }\n\n /**\n * Create a new node in the graph.\n */\n addNode(\n id?: DepID,\n manifest?: Manifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) {\n const node = new Node(\n this.#nodeOptions,\n id,\n manifest,\n spec,\n name,\n version,\n )\n this.nodes.set(node.id, node)\n const nbn = this.nodesByName.get(node.name) ?? new Set()\n nbn.add(node)\n this.nodesByName.set(node.name, nbn)\n if (spec) {\n const f = String(spec.final)\n // if it's a file: type, then that is fromNode-specific,\n // so we can't shortcut add it here.\n if (spec.final.type !== 'file') {\n this.resolutions.set(f, node)\n const rrev = this.resolutionsReverse.get(node) ?? new Set()\n rrev.add(f)\n this.resolutionsReverse.set(node, rrev)\n }\n }\n if (manifest) {\n this.manifests.set(node.id, manifest)\n }\n return node\n }\n\n /**\n * Place a new package into the graph representation, creating the new\n * edges and possibly new nodes that are to be expected when traversing\n * the graph in a top-down direction, e.g: from importers to leafs.\n *\n * For different uses that are not a direct top-down traversal of the graph\n * consider using `addNode()` and `addEdge()` instead.\n */\n placePackage(\n fromNode: Node,\n depType: DependencySaveType,\n spec: Spec,\n manifest?: Manifest,\n id?: DepID,\n ) {\n // if no manifest is available, then create an edge that has no\n // reference to any other node, representing a missing dependency\n if (!manifest && !id) {\n this.addEdge(depType, spec, fromNode)\n return\n }\n\n // flags set on the node we're about to create or find.\n const flags = {\n dev: fromNode.dev || depType === 'dev',\n optional:\n fromNode.optional ||\n depType === 'optional' ||\n depType === 'peerOptional',\n }\n\n const depId = id || (manifest && getId(spec, manifest))\n\n /* c8 ignore start - should not be possible */\n if (!depId) {\n throw error('Could not find dep id when placing package', {\n spec,\n manifest,\n })\n }\n /* c8 ignore stop */\n\n // if a node for this package is already represented by a node\n // in the graph, then just creates a new edge to that node\n const toFoundNode = this.nodes.get(depId)\n if (toFoundNode) {\n this.addEdge(depType, spec, fromNode, toFoundNode)\n // the current only stays dev/optional if this dep lets it remain so\n // if it's not already, we don't make it dev or optional.\n toFoundNode.dev &&= flags.dev\n toFoundNode.optional &&= flags.optional\n return toFoundNode\n }\n\n // creates a new node and edges to its parent\n const toNode = this.addNode(depId, manifest)\n toNode.registry = spec.registry\n toNode.dev = flags.dev\n toNode.optional = flags.optional\n this.addEdge(depType, spec, fromNode, toNode)\n return toNode\n }\n\n /**\n * Removes a node and its relevant edges from the graph.\n *\n * If a replacement is provided, then any edges that were previously\n * pointing to the removed node will be directed to the replacement,\n * if it is valid to do so.\n */\n removeNode(node: Node, replacement?: Node) {\n this.nodes.delete(node.id)\n const nbn = this.nodesByName.get(node.name)\n // if it's the last one, just remove the set\n if (nbn?.size === 1) this.nodesByName.delete(node.name)\n else nbn?.delete(node)\n for (const r of this.resolutionsReverse.get(node) ?? new Set()) {\n this.resolutions.delete(r)\n }\n this.resolutionsReverse.delete(node)\n this.manifests.delete(node.id)\n for (const edge of node.edgesOut.values()) {\n this.edges.delete(edge)\n }\n for (const edge of node.edgesIn) {\n if (\n replacement &&\n satisfies(\n replacement.id,\n edge.spec,\n edge.from.location,\n this.projectRoot,\n this.monorepo,\n )\n ) {\n edge.to = replacement\n } else {\n edge.from.edgesOut.delete(edge.spec.name)\n this.edges.delete(edge)\n }\n }\n }\n\n toJSON() {\n return lockfileData({\n ...this.#options,\n graph: this,\n saveManifests: true,\n })\n }\n\n [kCustomInspect](_: number, options: InspectOptions) {\n const data = this.toJSON()\n return `${this[Symbol.toStringTag]} ${inspect(data, options)}`\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAInC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D,kEAAkE;AAClE,qEAAqE;AACrE,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;AAI/C,MAAM,MAAM,GAAG,CAA0B,CAAK,EAAE,EAAE,CAChD,CAAC,IAAK,IAAI,GAAG,EAAQ,CAAA;AAqBvB,MAAM,OAAO,KAAK;IAChB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,qBAAqB,CAAA;IAC9B,CAAC;IAED,QAAQ,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,CAAC;CACF","sourcesContent":["import { getId, joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport { satisfies } from '@vltpkg/satisfies'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { Manifest, DependencySaveType } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport { inspect } from 'node:util'\nimport type { InspectOptions } from 'node:util'\nimport type { Edge } from './edge.ts'\nimport { lockfileData } from './lockfile/save.ts'\nimport { Node } from './node.ts'\nimport type { NodeOptions } from './node.ts'\nimport type { GraphLike, NodeLike } from './types.ts'\nimport { resolveSaveType } from './resolve-save-type.ts'\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\n// this is always the same, but we don't hard code it as a string,\n// in case the DepID module needs to change its delimiter again ever.\nconst mainDepID = joinDepIDTuple(['file', '.'])\n\nexport type ManifestInventory = Map<DepID, Manifest>\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\nexport type GraphOptions = SpecOptions & {\n /**\n * The main importer manifest info.\n */\n mainManifest: Manifest\n /**\n * An inventory of seen manifests.\n */\n manifests?: ManifestInventory\n /**\n * A {@link Monorepo} object, for managing workspaces\n */\n monorepo?: Monorepo\n /**\n * Root of the project this graph represents\n */\n projectRoot: string\n}\n\nexport class Graph implements GraphLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Graph'\n }\n\n #options: GraphOptions\n\n #nodeOptions: NodeOptions\n\n /**\n * A {@link Monorepo} instance, used for managing workspaces.\n */\n monorepo?: Monorepo\n\n /**\n * An inventory with all manifests related to an install.\n */\n manifests: ManifestInventory\n\n /**\n * A set of all edges in this graph.\n */\n edges = new Set<Edge>()\n\n /**\n * Map registered dep ids to the node that represent them in the graph.\n */\n nodes = new Map<DepID, Node>()\n\n /**\n * Map of nodes by their name\n */\n nodesByName = new Map<string, Set<Node>>()\n\n /**\n * Cached resolutions for spec lookups\n */\n resolutions = new Map<string, Node>()\n\n /**\n * Reverse map of resolutions\n */\n resolutionsReverse = new Map<Node, Set<string>>()\n\n /**\n * A set of importer nodes in this graph.\n */\n importers = new Set<Node>()\n\n /**\n * The {@link Node} that represents the project root `package.json`.\n */\n mainImporter: Node\n\n /**\n * A set of extraneous dependencies found when building the graph.\n */\n extraneousDependencies = new Set<Edge>()\n\n /**\n * The root of the project this graph represents\n */\n projectRoot: string\n\n constructor(options: GraphOptions) {\n const { mainManifest, monorepo } = options\n this.#options = options\n this.manifests = getMap(options.manifests)\n this.projectRoot = options.projectRoot\n this.#nodeOptions = {\n ...this.#options,\n graph: this,\n }\n\n // add the project root node\n const mainImporterLocation = '.'\n const mainImporterSpec = Spec.parse(\n mainManifest.name || '(root)',\n mainImporterLocation,\n )\n const mainImporter = this.addNode(\n mainDepID,\n mainManifest,\n mainImporterSpec,\n )\n mainImporter.setImporterLocation(mainImporterLocation)\n mainImporter.mainImporter = true\n this.mainImporter = mainImporter\n this.importers.add(mainImporter)\n this.manifests.set(mainImporter.id, mainManifest)\n\n // uses the monorepo instance in order to retrieve info on\n // workspaces and create importer nodes for each of them\n this.monorepo = monorepo\n if (this.monorepo) {\n for (const ws of this.monorepo) {\n const wsNode = this.addNode(\n ws.id,\n ws.manifest,\n undefined,\n ws.name,\n )\n wsNode.setImporterLocation(`./${ws.path}`)\n if (wsNode.manifest) {\n this.manifests.set(wsNode.id, wsNode.manifest)\n }\n this.importers.add(wsNode)\n }\n }\n }\n\n /**\n * Delete all nodes that are unreachable from the importers.\n * The collection of deleted nodes is returned.\n *\n * NOTE: This can be extremely slow for large graphs, and is almost always\n * unnecessary! Only call when it is known that some unreachable nodes may\n * have been created, for example when deleting the unneeded subgraph when an\n * optional node fails to resolve/install.\n */\n gc() {\n const { nodes } = this\n this.nodes = new Map()\n const marked = new Set(this.importers)\n for (const imp of marked) {\n // don't delete the importer!\n nodes.delete(imp.id)\n this.nodes.set(imp.id, imp)\n for (const { to } of imp.edgesOut.values()) {\n if (!to || marked.has(to)) continue\n marked.add(to)\n nodes.delete(to.id)\n this.nodes.set(to.id, to)\n }\n }\n for (const node of nodes.values()) {\n this.removeNode(node)\n }\n return nodes\n }\n\n /**\n * Create a new edge between two nodes of the graph in case both exist,\n * in case the destination node does not exists, then a dangling edge,\n * pointing to nothing will be created to represent that missing dependency.\n */\n addEdge(\n type: DependencySaveType,\n spec: Spec,\n from: NodeLike,\n to?: NodeLike,\n ) {\n // fix any nameless spec\n if (spec.name === '(unknown)') {\n if (to) {\n spec.name = to.name /* c8 ignore next */ || '(unknown)'\n spec.spec = `${to.name}@${spec.bareSpec}`\n } else {\n throw error(\n 'Impossible to place a missing, nameless dependency',\n { spec },\n )\n }\n }\n const existing = from.edgesOut.get(spec.name)\n if (existing) {\n const edge = existing as Edge\n if (\n edge.type === type &&\n edge.spec.bareSpec === spec.bareSpec\n ) {\n if (to && to !== edge.to) {\n edge.to = to as Node\n edge.to.edgesIn.add(edge)\n }\n return edge\n }\n this.edges.delete(edge)\n }\n const f = from as Node\n const edgeOut = f.addEdgesTo(\n resolveSaveType(from, spec.name, type),\n spec,\n to as Node | undefined,\n )\n this.edges.add(edgeOut)\n return edgeOut\n }\n\n /**\n * Find an existing node to satisfy a dependency\n */\n findResolution(spec: Spec, fromNode: Node) {\n const f = spec.final\n // if it's a file: dep, then the fromNode location matters\n const fromPref =\n f.type === 'file' ? fromNode.location + ' : ' : ''\n const sf = fromPref + String(f)\n const cached = this.resolutions.get(sf)\n if (cached) return cached\n const nbn = this.nodesByName.get(f.name)\n if (!nbn) return undefined\n for (const node of nbn) {\n if (\n satisfies(\n node.id,\n f,\n fromNode.location,\n this.projectRoot,\n this.monorepo,\n )\n ) {\n this.resolutions.set(sf, node)\n // always set by now, because the node was added at some point\n this.resolutionsReverse.get(node)?.add(sf)\n return node\n }\n }\n }\n\n /**\n * Create a new node in the graph.\n */\n addNode(\n id?: DepID,\n manifest?: Manifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) {\n const node = new Node(\n this.#nodeOptions,\n id,\n manifest,\n spec,\n name,\n version,\n )\n this.nodes.set(node.id, node)\n const nbn = this.nodesByName.get(node.name) ?? new Set()\n nbn.add(node)\n this.nodesByName.set(node.name, nbn)\n if (spec) {\n const f = String(spec.final)\n // if it's a file: type, then that is fromNode-specific,\n // so we can't shortcut add it here.\n if (spec.final.type !== 'file') {\n this.resolutions.set(f, node)\n const rrev = this.resolutionsReverse.get(node) ?? new Set()\n rrev.add(f)\n this.resolutionsReverse.set(node, rrev)\n }\n }\n if (manifest) {\n this.manifests.set(node.id, manifest)\n }\n return node\n }\n\n /**\n * Place a new package into the graph representation, creating the new\n * edges and possibly new nodes that are to be expected when traversing\n * the graph in a top-down direction, e.g: from importers to leafs.\n *\n * For different uses that are not a direct top-down traversal of the graph\n * consider using `addNode()` and `addEdge()` instead.\n */\n placePackage(\n fromNode: Node,\n depType: DependencySaveType,\n spec: Spec,\n manifest?: Manifest,\n id?: DepID,\n ) {\n // if no manifest is available, then create an edge that has no\n // reference to any other node, representing a missing dependency\n if (!manifest && !id) {\n this.addEdge(depType, spec, fromNode)\n return\n }\n\n // flags set on the node we're about to create or find.\n const flags = {\n dev: fromNode.dev || depType === 'dev',\n optional:\n fromNode.optional ||\n depType === 'optional' ||\n depType === 'peerOptional',\n }\n\n const depId = id || (manifest && getId(spec, manifest))\n\n /* c8 ignore start - should not be possible */\n if (!depId) {\n throw error('Could not find dep id when placing package', {\n spec,\n manifest,\n })\n }\n /* c8 ignore stop */\n\n // if a node for this package is already represented by a node\n // in the graph, then just creates a new edge to that node\n const toFoundNode = this.nodes.get(depId)\n if (toFoundNode) {\n this.addEdge(depType, spec, fromNode, toFoundNode)\n // the current only stays dev/optional if this dep lets it remain so\n // if it's not already, we don't make it dev or optional.\n toFoundNode.dev &&= flags.dev\n toFoundNode.optional &&= flags.optional\n return toFoundNode\n }\n\n // creates a new node and edges to its parent\n const toNode = this.addNode(depId, manifest, spec)\n toNode.registry = spec.registry\n toNode.dev = flags.dev\n toNode.optional = flags.optional\n this.addEdge(depType, spec, fromNode, toNode)\n return toNode\n }\n\n /**\n * Removes a node and its relevant edges from the graph.\n *\n * If a replacement is provided, then any edges that were previously\n * pointing to the removed node will be directed to the replacement,\n * if it is valid to do so.\n */\n removeNode(node: Node, replacement?: Node) {\n this.nodes.delete(node.id)\n const nbn = this.nodesByName.get(node.name)\n // if it's the last one, just remove the set\n if (nbn?.size === 1) this.nodesByName.delete(node.name)\n else nbn?.delete(node)\n for (const r of this.resolutionsReverse.get(node) ?? new Set()) {\n this.resolutions.delete(r)\n }\n this.resolutionsReverse.delete(node)\n this.manifests.delete(node.id)\n for (const edge of node.edgesOut.values()) {\n this.edges.delete(edge)\n }\n for (const edge of node.edgesIn) {\n if (\n replacement &&\n satisfies(\n replacement.id,\n edge.spec,\n edge.from.location,\n this.projectRoot,\n this.monorepo,\n )\n ) {\n edge.to = replacement\n } else {\n edge.from.edgesOut.delete(edge.spec.name)\n this.edges.delete(edge)\n }\n }\n }\n\n toJSON() {\n return lockfileData({\n ...this.#options,\n graph: this,\n saveManifests: true,\n })\n }\n\n [kCustomInspect](_: number, options: InspectOptions) {\n const data = this.toJSON()\n return `${this[Symbol.toStringTag]} ${inspect(data, options)}`\n }\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const lockfile: {
|
|
|
20
20
|
load: (options: LockfileLoadOptions) => import("./graph.ts").Graph;
|
|
21
21
|
loadEdges: (graph: import("./types.ts").GraphLike, edges: import("./lockfile/types.ts").LockfileData["edges"], options: import("@vltpkg/spec").SpecOptions) => void;
|
|
22
22
|
loadNodes: (graph: import("./types.ts").GraphLike, nodes: import("./lockfile/types.ts").LockfileData["nodes"]) => void;
|
|
23
|
-
save: (options: import("./lockfile/save.ts").SaveOptions) => void;
|
|
23
|
+
save: (options: Omit<import("./lockfile/save.ts").SaveOptions, "saveManifests">) => void;
|
|
24
24
|
};
|
|
25
25
|
export type { ActualLoadOptions, LockfileLoadOptions };
|
|
26
26
|
export type { SaveOptions } from './lockfile/save.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-nodes.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,eAAO,MAAM,SAAS,UACb,SAAS,SACT,YAAY,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"load-nodes.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,eAAO,MAAM,SAAS,UACb,SAAS,SACT,YAAY,CAAC,OAAO,CAAC,SA6C7B,CAAA"}
|
|
@@ -7,7 +7,7 @@ export const loadNodes = (graph, nodes) => {
|
|
|
7
7
|
// graph and it should not create new nodes if an existing one is there
|
|
8
8
|
if (graph.nodes.has(id))
|
|
9
9
|
continue;
|
|
10
|
-
const [flags, name, integrity, resolved, location, manifest] = lockfileNode;
|
|
10
|
+
const [flags, name, integrity, resolved, location, manifest, rawManifest,] = lockfileNode;
|
|
11
11
|
const [type, , spec] = splitDepID(id);
|
|
12
12
|
// if the lockfile has manifest data then it should just use that
|
|
13
13
|
// otherwise tries to infer name / version value from the lockfile node
|
|
@@ -25,6 +25,9 @@ export const loadNodes = (graph, nodes) => {
|
|
|
25
25
|
node.setResolved();
|
|
26
26
|
if (location)
|
|
27
27
|
node.location = location;
|
|
28
|
+
if (manifest && rawManifest) {
|
|
29
|
+
node.setConfusedManifest(manifest, rawManifest);
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
};
|
|
30
33
|
//# sourceMappingURL=load-nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-nodes.js","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAKnD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAgB,EAChB,KAA4B,EAC5B,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAA4B,CAAA;IAChE,KAAK,MAAM,CAAC,EAAE,EAAE,YAAY,CAAC,IAAI,OAAO,EAAE,CAAC;QACzC,oEAAoE;QACpE,uEAAuE;QACvE,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,SAAQ;QAEjC,MAAM,
|
|
1
|
+
{"version":3,"file":"load-nodes.js","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAKnD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAgB,EAChB,KAA4B,EAC5B,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAA4B,CAAA;IAChE,KAAK,MAAM,CAAC,EAAE,EAAE,YAAY,CAAC,IAAI,OAAO,EAAE,CAAC;QACzC,oEAAoE;QACpE,uEAAuE;QACvE,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,SAAQ;QAEjC,MAAM,CACJ,KAAK,EACL,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,EACZ,GAAG,YAAY,CAAA;QAChB,MAAM,CAAC,IAAI,EAAE,AAAD,EAAG,IAAI,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;QAErC,iEAAiE;QACjE,uEAAuE;QACvE,MAAM,IAAI,GACR,QAAQ,CAAC,CAAC;YACR,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC;YAC7B,CAAC,CAAC,KAAK,CAAC,OAAO,CACX,EAAE,EACF,SAAS,EACT,SAAS,EACT,IAAI,IAAI,SAAS,EACjB,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9B,CAAC,CAAC,SAAS,CACZ,CAAA;QAEL,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAA;QACvD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,SAAS,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,SAAS,CAAA;QACrC,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,WAAW,EAAE,CAAA;QACtC,IAAI,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACtC,IAAI,QAAQ,IAAI,WAAW,EAAE,CAAC;YAC5B,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport { getBooleanFlagsFromNum } from './types.ts'\nimport type { LockfileData, LockfileNode } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { GraphLike } from '../types.ts'\n\nexport const loadNodes = (\n graph: GraphLike,\n nodes: LockfileData['nodes'],\n) => {\n const entries = Object.entries(nodes) as [DepID, LockfileNode][]\n for (const [id, lockfileNode] of entries) {\n // workspace nodes and the project root node are already part of the\n // graph and it should not create new nodes if an existing one is there\n if (graph.nodes.has(id)) continue\n\n const [\n flags,\n name,\n integrity,\n resolved,\n location,\n manifest,\n rawManifest,\n ] = lockfileNode\n const [type, , spec] = splitDepID(id)\n\n // if the lockfile has manifest data then it should just use that\n // otherwise tries to infer name / version value from the lockfile node\n const node =\n manifest ?\n graph.addNode(id, manifest)\n : graph.addNode(\n id,\n undefined,\n undefined,\n name ?? undefined,\n type === 'registry' && spec.indexOf('@') > 0 ?\n spec.split('@').slice(-1)[0]\n : undefined,\n )\n\n const { dev, optional } = getBooleanFlagsFromNum(flags)\n node.dev = dev\n node.optional = optional\n node.integrity = integrity ?? undefined\n node.resolved = resolved ?? undefined\n if (!node.resolved) node.setResolved()\n if (location) node.location = location\n if (manifest && rawManifest) {\n node.setConfusedManifest(manifest, rawManifest)\n }\n }\n}\n"]}
|
|
@@ -13,6 +13,6 @@ export type SaveOptions = SpecOptions & {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const lockfileData: ({ graph, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, registry, registries, saveManifests, "scope-registries": scopeRegistries, }: SaveOptions) => LockfileData;
|
|
15
15
|
export declare const saveData: (data: LockfileData, fileName: string, saveManifests?: boolean) => void;
|
|
16
|
-
export declare const save: (options: SaveOptions) => void;
|
|
17
|
-
export declare const saveHidden: (options: SaveOptions) => void;
|
|
16
|
+
export declare const save: (options: Omit<SaveOptions, "saveManifests">) => void;
|
|
17
|
+
export declare const saveHidden: (options: Omit<SaveOptions, "saveManifests">) => void;
|
|
18
18
|
//# sourceMappingURL=save.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAI/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,OAAO,KAAK,EACV,YAAY,EAKb,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;OAEG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAI/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,OAAO,KAAK,EACV,YAAY,EAKb,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;OAEG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAoGD,eAAO,MAAM,YAAY,sJAQtB,WAAW,KAAG,YAwChB,CAAA;AAeD,eAAO,MAAM,QAAQ,SACb,YAAY,YACR,MAAM,8BAEf,IAIF,CAAA;AAED,eAAO,MAAM,IAAI,YACN,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,KAC1C,IAKF,CAAA;AAED,eAAO,MAAM,UAAU,YACZ,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,KAC1C,IASF,CAAA"}
|
|
@@ -33,6 +33,9 @@ const formatNodes = (nodes, saveManifests, registry) => {
|
|
|
33
33
|
}
|
|
34
34
|
if (saveManifests) {
|
|
35
35
|
lockfileNode[5] = node.manifest;
|
|
36
|
+
if (node.confused) {
|
|
37
|
+
lockfileNode[6] = node.rawManifest;
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
40
|
res[node.id] = lockfileNode;
|
|
38
41
|
}
|
|
@@ -116,13 +119,13 @@ export const save = (options) => {
|
|
|
116
119
|
const { graph } = options;
|
|
117
120
|
const data = lockfileData({ ...options, saveManifests: false });
|
|
118
121
|
const fileName = resolve(graph.projectRoot, 'vlt-lock.json');
|
|
119
|
-
|
|
122
|
+
saveData(data, fileName, false);
|
|
120
123
|
};
|
|
121
124
|
export const saveHidden = (options) => {
|
|
122
125
|
const { graph } = options;
|
|
123
126
|
const data = lockfileData({ ...options, saveManifests: true });
|
|
124
127
|
const fileName = resolve(graph.projectRoot, 'node_modules/.vlt-lock.json');
|
|
125
128
|
mkdirSync(dirname(fileName), { recursive: true });
|
|
126
|
-
|
|
129
|
+
saveData(data, fileName, true);
|
|
127
130
|
};
|
|
128
131
|
//# sourceMappingURL=save.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAI5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAoB/C,MAAM,WAAW,GAAG,CAClB,KAAqB,EACrB,aAAuB,EACvB,QAAiB,EACjB,EAAE;IACF,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,GAAG,GAAW,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC7D,2DAA2D;IAC3D,MAAM,YAAY,GAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC7C,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC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;AACvC,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport {\n defaultRegistry,\n defaultRegistries,\n defaultGitHosts,\n defaultGitHostArchives,\n defaultScopeRegistries,\n} from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport type { Edge } from '../edge.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { getFlagNumFromNode } from './types.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdges,\n LockfileEdgeValue,\n LockfileNode,\n} from './types.ts'\n\nexport type SaveOptions = SpecOptions & {\n /**\n * The graph to be stored in the lockfile.\n */\n graph: Graph\n /**\n * Should it save manifest data in the lockfile?\n */\n saveManifests?: boolean\n}\n\nconst formatNodes = (\n nodes: Iterable<Node>,\n saveManifests?: boolean,\n registry?: string,\n) => {\n // we do not store importers in the lockfile, though we do store\n // their edges. when we load, we always read workspaces/main fresh.\n const arr: Node[] = [...nodes].filter(node => !node.importer)\n // nodes are sorted in order to have a deterministic result\n const orderedNodes: Node[] = arr.sort((a, b) =>\n a.id.localeCompare(b.id, 'en'),\n )\n\n const res: Record<DepID, LockfileNode> = {}\n for (const node of orderedNodes) {\n const customRegistry =\n node.resolved && registry && !node.resolved.startsWith(registry)\n const resolved = customRegistry ? node.resolved : undefined\n // if it's in a location other than the default, stash that\n const location =\n (\n node.id.startsWith('file') ||\n node.location.endsWith(\n '/node_modules/.vlt/' +\n node.id +\n '/node_modules/' +\n node.name,\n )\n ) ?\n undefined\n : node.location\n\n const flags = getFlagNumFromNode(node)\n const lockfileNode: LockfileNode = [flags, node.name]\n\n if (node.integrity) {\n lockfileNode[2] = node.integrity\n }\n\n if (resolved) {\n lockfileNode[3] = resolved\n }\n\n if (location) {\n lockfileNode[4] = location\n }\n\n if (saveManifests) {\n lockfileNode[5] = node.manifest\n }\n\n res[node.id] = lockfileNode\n }\n return res\n}\n\nconst formatEdges = (edges: Set<Edge>): LockfileEdges =>\n Object.fromEntries(\n [...edges]\n .sort(\n (a, b) =>\n /* c8 ignore start - nondeterminstic and annoying to test */\n // sort importers to the top, then alphabetically by\n // id, type, target\n Number(b.from.importer) - Number(a.from.importer) ||\n a.from.id.localeCompare(b.from.id, 'en') ||\n a.type.localeCompare(b.type, 'en') ||\n (a.to?.id ?? '').localeCompare(b.to?.id ?? ''),\n /* c8 ignore stop */\n )\n .map((edge): [LockfileEdgeKey, LockfileEdgeValue] => [\n `${edge.from.id} ${edge.spec.name}`,\n `${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,\n ]),\n )\n\nconst isRecordStringString = (\n registries: unknown,\n): registries is Record<string, string> =>\n !(!registries || typeof registries === 'string')\n\nconst removeDefaultItems = (\n defaultItems: Record<string, string>,\n items: Record<string, string>,\n) => {\n const res: Record<string, string> = {}\n for (const [key, value] of Object.entries(items)) {\n if (!defaultItems[key] || defaultItems[key] !== value) {\n res[key] = value\n }\n }\n return res\n}\n\nexport const lockfileData = ({\n graph,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n registry,\n registries,\n saveManifests,\n 'scope-registries': scopeRegistries,\n}: SaveOptions): LockfileData => {\n const cleanGitHosts =\n isRecordStringString(gitHosts) ?\n removeDefaultItems(defaultGitHosts, gitHosts)\n : undefined\n const cleanGitHostArchives =\n isRecordStringString(gitHostArchives) ?\n removeDefaultItems(defaultGitHostArchives, gitHostArchives)\n : undefined\n const cleanRegistries =\n isRecordStringString(registries) ?\n removeDefaultItems(defaultRegistries, registries)\n : undefined\n const cleanScopeRegistries =\n isRecordStringString(scopeRegistries) ?\n removeDefaultItems(defaultScopeRegistries, scopeRegistries)\n : undefined\n const hasItems = (clean: Record<string, string> | undefined) =>\n clean && Object.keys(clean).length\n return {\n options: {\n ...(hasItems(cleanScopeRegistries) ?\n { 'scope-registries': cleanScopeRegistries }\n : undefined),\n ...(registry !== undefined && registry !== defaultRegistry ?\n { registry }\n : undefined),\n ...(hasItems(registries) ?\n { registries: cleanRegistries }\n : undefined),\n ...(hasItems(cleanGitHosts) ?\n { 'git-hosts': cleanGitHosts }\n : undefined),\n ...(hasItems(cleanGitHostArchives) ?\n { 'git-host-archives': cleanGitHostArchives }\n : undefined),\n },\n nodes: formatNodes(graph.nodes.values(), saveManifests, registry),\n edges: formatEdges(graph.edges),\n }\n}\n\n// renders each node / edge as a single line entry\nconst extraFormat = (jsonString: string) => {\n const str = `${jsonString}\\n`\n const [init, ...parts] = str.split(' \"nodes\": {')\n const res = [init]\n for (const part of parts) {\n res.push(\n part.replaceAll('\\n ', '').replaceAll('\\n ]', ']'),\n )\n }\n return res.join(' \"nodes\": {')\n}\n\nexport const saveData = (\n data: LockfileData,\n fileName: string,\n saveManifests = false,\n) => {\n const json = JSON.stringify(data, null, 2)\n const content = saveManifests ? json : extraFormat(json)\n writeFileSync(fileName, content)\n}\n\nexport const save = (options: SaveOptions) => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: false })\n const fileName = resolve(graph.projectRoot, 'vlt-lock.json')\n return saveData(data, fileName, false)\n}\n\nexport const saveHidden = (options: SaveOptions) => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: true })\n const fileName = resolve(\n graph.projectRoot,\n 'node_modules/.vlt-lock.json',\n )\n mkdirSync(dirname(fileName), { recursive: true })\n return saveData(data, fileName, true)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAI5C,OAAO,EAAE,kBAAkB,EAAE,MA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AC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAA2C,EACrC,EAAE;IACR,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACzB,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;IAC9D,MAAM,QAAQ,GAAG,OAAO,CACtB,KAAK,CAAC,WAAW,EACjB,6BAA6B,CAC9B,CAAA;IACD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACjD,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAChC,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport {\n defaultRegistry,\n defaultRegistries,\n defaultGitHosts,\n defaultGitHostArchives,\n defaultScopeRegistries,\n} from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport type { Edge } from '../edge.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { getFlagNumFromNode } from './types.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdges,\n LockfileEdgeValue,\n LockfileNode,\n} from './types.ts'\n\nexport type SaveOptions = SpecOptions & {\n /**\n * The graph to be stored in the lockfile.\n */\n graph: Graph\n /**\n * Should it save manifest data in the lockfile?\n */\n saveManifests?: boolean\n}\n\nconst formatNodes = (\n nodes: Iterable<Node>,\n saveManifests?: boolean,\n registry?: string,\n) => {\n // we do not store importers in the lockfile, though we do store\n // their edges. when we load, we always read workspaces/main fresh.\n const arr: Node[] = [...nodes].filter(node => !node.importer)\n // nodes are sorted in order to have a deterministic result\n const orderedNodes: Node[] = arr.sort((a, b) =>\n a.id.localeCompare(b.id, 'en'),\n )\n\n const res: Record<DepID, LockfileNode> = {}\n for (const node of orderedNodes) {\n const customRegistry =\n node.resolved && registry && !node.resolved.startsWith(registry)\n const resolved = customRegistry ? node.resolved : undefined\n // if it's in a location other than the default, stash that\n const location =\n (\n node.id.startsWith('file') ||\n node.location.endsWith(\n '/node_modules/.vlt/' +\n node.id +\n '/node_modules/' +\n node.name,\n )\n ) ?\n undefined\n : node.location\n\n const flags = getFlagNumFromNode(node)\n const lockfileNode: LockfileNode = [flags, node.name]\n\n if (node.integrity) {\n lockfileNode[2] = node.integrity\n }\n\n if (resolved) {\n lockfileNode[3] = resolved\n }\n\n if (location) {\n lockfileNode[4] = location\n }\n\n if (saveManifests) {\n lockfileNode[5] = node.manifest\n\n if (node.confused) {\n lockfileNode[6] = node.rawManifest\n }\n }\n\n res[node.id] = lockfileNode\n }\n return res\n}\n\nconst formatEdges = (edges: Set<Edge>): LockfileEdges =>\n Object.fromEntries(\n [...edges]\n .sort(\n (a, b) =>\n /* c8 ignore start - nondeterminstic and annoying to test */\n // sort importers to the top, then alphabetically by\n // id, type, target\n Number(b.from.importer) - Number(a.from.importer) ||\n a.from.id.localeCompare(b.from.id, 'en') ||\n a.type.localeCompare(b.type, 'en') ||\n (a.to?.id ?? '').localeCompare(b.to?.id ?? ''),\n /* c8 ignore stop */\n )\n .map((edge): [LockfileEdgeKey, LockfileEdgeValue] => [\n `${edge.from.id} ${edge.spec.name}`,\n `${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,\n ]),\n )\n\nconst isRecordStringString = (\n registries: unknown,\n): registries is Record<string, string> =>\n !(!registries || typeof registries === 'string')\n\nconst removeDefaultItems = (\n defaultItems: Record<string, string>,\n items: Record<string, string>,\n) => {\n const res: Record<string, string> = {}\n for (const [key, value] of Object.entries(items)) {\n if (!defaultItems[key] || defaultItems[key] !== value) {\n res[key] = value\n }\n }\n return res\n}\n\nexport const lockfileData = ({\n graph,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n registry,\n registries,\n saveManifests,\n 'scope-registries': scopeRegistries,\n}: SaveOptions): LockfileData => {\n const cleanGitHosts =\n isRecordStringString(gitHosts) ?\n removeDefaultItems(defaultGitHosts, gitHosts)\n : undefined\n const cleanGitHostArchives =\n isRecordStringString(gitHostArchives) ?\n removeDefaultItems(defaultGitHostArchives, gitHostArchives)\n : undefined\n const cleanRegistries =\n isRecordStringString(registries) ?\n removeDefaultItems(defaultRegistries, registries)\n : undefined\n const cleanScopeRegistries =\n isRecordStringString(scopeRegistries) ?\n removeDefaultItems(defaultScopeRegistries, scopeRegistries)\n : undefined\n const hasItems = (clean: Record<string, string> | undefined) =>\n clean && Object.keys(clean).length\n return {\n options: {\n ...(hasItems(cleanScopeRegistries) ?\n { 'scope-registries': cleanScopeRegistries }\n : undefined),\n ...(registry !== undefined && registry !== defaultRegistry ?\n { registry }\n : undefined),\n ...(hasItems(registries) ?\n { registries: cleanRegistries }\n : undefined),\n ...(hasItems(cleanGitHosts) ?\n { 'git-hosts': cleanGitHosts }\n : undefined),\n ...(hasItems(cleanGitHostArchives) ?\n { 'git-host-archives': cleanGitHostArchives }\n : undefined),\n },\n nodes: formatNodes(graph.nodes.values(), saveManifests, registry),\n edges: formatEdges(graph.edges),\n }\n}\n\n// renders each node / edge as a single line entry\nconst extraFormat = (jsonString: string) => {\n const str = `${jsonString}\\n`\n const [init, ...parts] = str.split(' \"nodes\": {')\n const res = [init]\n for (const part of parts) {\n res.push(\n part.replaceAll('\\n ', '').replaceAll('\\n ]', ']'),\n )\n }\n return res.join(' \"nodes\": {')\n}\n\nexport const saveData = (\n data: LockfileData,\n fileName: string,\n saveManifests = false,\n): void => {\n const json = JSON.stringify(data, null, 2)\n const content = saveManifests ? json : extraFormat(json)\n writeFileSync(fileName, content)\n}\n\nexport const save = (\n options: Omit<SaveOptions, 'saveManifests'>,\n): void => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: false })\n const fileName = resolve(graph.projectRoot, 'vlt-lock.json')\n saveData(data, fileName, false)\n}\n\nexport const saveHidden = (\n options: Omit<SaveOptions, 'saveManifests'>,\n): void => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: true })\n const fileName = resolve(\n graph.projectRoot,\n 'node_modules/.vlt-lock.json',\n )\n mkdirSync(dirname(fileName), { recursive: true })\n saveData(data, fileName, true)\n}\n"]}
|
|
@@ -38,7 +38,8 @@ export type LockfileNode = [
|
|
|
38
38
|
integrity?: Integrity | null,
|
|
39
39
|
resolved?: string | null,
|
|
40
40
|
location?: string | null,
|
|
41
|
-
manifest?: Manifest | null
|
|
41
|
+
manifest?: Manifest | null,
|
|
42
|
+
rawManifest?: Manifest | null
|
|
42
43
|
];
|
|
43
44
|
/**
|
|
44
45
|
* Lockfile edges are stored as a record object where the key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lockfile/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,mBAAmB,EACpB,MAAM,eAAe,CAAA;AAGtB;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,WAAW,CAAA;IACpB,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAClC,KAAK,EAAE,aAAa,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,kBAIuB,CAAA;AAExB,eAAO,MAAM,sBAAsB,UAAW,iBAAiB;;;CAG7D,CAAA;AAEF,eAAO,MAAM,oBAAoB,IAAI,CAAA;AACrC,e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AC,MAAM,sBAAsB,GAAG,CAAC,KAAwB,EAAE,EAAE,CAAC,CAAC;IACnE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,mBAAmB,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,wBAAwB,CAAC;CAC/C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AACrC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAA;AACzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type {\n Integrity,\n Manifest,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport type { Graph } from '../graph.ts'\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 options: SpecOptions\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 * 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?: Manifest | 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"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lockfile/types.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAGlC,EAAE,EAAE,CACH,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,2BAA2B;IACvD,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,wBAAwB;QAC1C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,mBAAmB;YAChC,CAAC,CAAC,oBAAoB,CAAA;AAExB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAwB,EAAE,EAAE,CAAC,CAAC;IACnE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,mBAAmB,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,wBAAwB,CAAC;CAC/C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AACrC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAA;AACzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type {\n Integrity,\n Manifest,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport type { Graph } from '../graph.ts'\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 options: SpecOptions\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 * 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?: Manifest | null,\n rawManifest?: Manifest | 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/esm/node.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export declare class Node implements NodeLike {
|
|
|
34
34
|
isDev(): this is Node & {
|
|
35
35
|
dev: true;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* True if there's a manifest-confused package name.
|
|
39
|
+
*/
|
|
40
|
+
confused: boolean;
|
|
37
41
|
/**
|
|
38
42
|
* List of edges coming into this node.
|
|
39
43
|
*/
|
|
@@ -130,7 +134,17 @@ export declare class Node implements NodeLike {
|
|
|
130
134
|
* Add an edge from this node connecting it to a direct dependency.
|
|
131
135
|
*/
|
|
132
136
|
addEdgesTo(type: DependencyTypeShort, spec: Spec, node?: Node): Edge;
|
|
137
|
+
/**
|
|
138
|
+
* The raw manifest before any modifications.
|
|
139
|
+
* If not set, falls back to the current manifest.
|
|
140
|
+
*/
|
|
141
|
+
get rawManifest(): Manifest | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Sets this node as having a manifest-confused manifest.
|
|
144
|
+
*/
|
|
145
|
+
setConfusedManifest(fixed: Manifest, confused?: Manifest): void;
|
|
133
146
|
toJSON(): {
|
|
147
|
+
rawManifest?: Manifest | undefined;
|
|
134
148
|
id: DepID;
|
|
135
149
|
name: string;
|
|
136
150
|
version: string | undefined;
|
|
@@ -142,6 +156,7 @@ export declare class Node implements NodeLike {
|
|
|
142
156
|
resolved: string | undefined;
|
|
143
157
|
dev: boolean;
|
|
144
158
|
optional: boolean;
|
|
159
|
+
confused: boolean;
|
|
145
160
|
};
|
|
146
161
|
toString(): string;
|
|
147
162
|
}
|
package/dist/esm/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,OAA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MAAM;;;;;;;;;;;;;;;IAoBN,QAAQ;CAGT"}
|
package/dist/esm/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getId, hydrateTuple, splitDepID } from '@vltpkg/dep-id';
|
|
1
|
+
import { isPackageNameConfused, getId, hydrateTuple, splitDepID, } from '@vltpkg/dep-id';
|
|
2
2
|
import { typeError } from '@vltpkg/error-cause';
|
|
3
3
|
import { Edge } from "./edge.js";
|
|
4
4
|
import { stringifyNode } from "./stringify-node.js";
|
|
@@ -8,6 +8,7 @@ export class Node {
|
|
|
8
8
|
}
|
|
9
9
|
#options;
|
|
10
10
|
#location;
|
|
11
|
+
#rawManifest;
|
|
11
12
|
#optional = false;
|
|
12
13
|
/**
|
|
13
14
|
* True if a node is only reachable via optional or peerOptional edges from
|
|
@@ -57,6 +58,10 @@ export class Node {
|
|
|
57
58
|
isDev() {
|
|
58
59
|
return this.#dev;
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* True if there's a manifest-confused package name.
|
|
63
|
+
*/
|
|
64
|
+
confused = false;
|
|
60
65
|
/**
|
|
61
66
|
* List of edges coming into this node.
|
|
62
67
|
*/
|
|
@@ -179,6 +184,12 @@ export class Node {
|
|
|
179
184
|
}
|
|
180
185
|
this.graph = options.graph;
|
|
181
186
|
this.manifest = manifest;
|
|
187
|
+
if (isPackageNameConfused(spec, this.manifest?.name)) {
|
|
188
|
+
this.setConfusedManifest({
|
|
189
|
+
...manifest,
|
|
190
|
+
name: spec?.name,
|
|
191
|
+
}, manifest);
|
|
192
|
+
}
|
|
182
193
|
this.#name = name || this.manifest?.name;
|
|
183
194
|
this.version = version || this.manifest?.version;
|
|
184
195
|
if (this.version?.startsWith('v')) {
|
|
@@ -253,6 +264,22 @@ export class Node {
|
|
|
253
264
|
this.edgesOut.set(spec.name, edge);
|
|
254
265
|
return edge;
|
|
255
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* The raw manifest before any modifications.
|
|
269
|
+
* If not set, falls back to the current manifest.
|
|
270
|
+
*/
|
|
271
|
+
get rawManifest() {
|
|
272
|
+
return this.#rawManifest ?? this.manifest;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Sets this node as having a manifest-confused manifest.
|
|
276
|
+
*/
|
|
277
|
+
setConfusedManifest(fixed, confused) {
|
|
278
|
+
this.manifest = fixed;
|
|
279
|
+
this.#rawManifest = confused;
|
|
280
|
+
this.confused = true;
|
|
281
|
+
this.#name = this.manifest.name;
|
|
282
|
+
}
|
|
256
283
|
toJSON() {
|
|
257
284
|
return {
|
|
258
285
|
id: this.id,
|
|
@@ -266,6 +293,10 @@ export class Node {
|
|
|
266
293
|
resolved: this.resolved,
|
|
267
294
|
dev: this.dev,
|
|
268
295
|
optional: this.optional,
|
|
296
|
+
confused: this.confused,
|
|
297
|
+
...(this.confused ?
|
|
298
|
+
{ rawManifest: this.#rawManifest }
|
|
299
|
+
: undefined),
|
|
269
300
|
};
|
|
270
301
|
}
|
|
271
302
|
toString() {
|
package/dist/esm/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAO/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAQnD,MAAM,OAAO,IAAI;IACf,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IAED,QAAQ,CAAa;IACrB,SAAS,CAAS;IAElB,SAAS,GAAG,KAAK,CAAA;IACjB;;;;;;OAMG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IACD,IAA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,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAA;IACH,CAAC;IAED,QAAQ;QACN,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;CACF","sourcesContent":["import type { PathScurry } from 'path-scurry'\nimport { getId, hydrateTuple, splitDepID } 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 type {\n Integrity,\n Manifest,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport { Edge } from './edge.ts'\nimport type { GraphLike, NodeLike } from './types.ts'\nimport { stringifyNode } from './stringify-node.ts'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\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\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 * 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 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: GraphLike\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?: Manifest\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 * 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 * 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?: Manifest,\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\n this.manifest = manifest\n this.#name = name || this.manifest?.name\n\n this.version = version || this.manifest?.version\n if (this.version?.startsWith('v')) {\n this.version = this.version.slice(1)\n }\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 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 '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 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: this.manifest,\n projectRoot: this.projectRoot,\n integrity: this.integrity,\n resolved: this.resolved,\n dev: this.dev,\n optional: this.optional,\n }\n }\n\n toString() {\n return stringifyNode(this)\n }\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;AAO/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAQnD,MAAM,OAAO,IAAI;IACf,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IAED,QAAQ,CAAa;IACrB,SAAS,CAAS;IAClB,YAAY,CAAW;IAEvB,SAAS,GAAG,KAAK,CAAA;IACjB;;;;;;OAMG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,C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AC;IAED;;OAEG;IACH,mBAAmB,CAAC,KAAe,EAAE,QAAmB;QACtD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;QACrB,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;IACjC,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,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","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 type {\n Integrity,\n Manifest,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport { Edge } from './edge.ts'\nimport type { GraphLike, NodeLike } from './types.ts'\nimport { stringifyNode } from './stringify-node.ts'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\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?: Manifest\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 * 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 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: GraphLike\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?: Manifest\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 * 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 * 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?: Manifest,\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\n this.manifest = manifest\n\n if (isPackageNameConfused(spec, this.manifest?.name)) {\n this.setConfusedManifest(\n {\n ...manifest,\n name: spec?.name,\n },\n manifest,\n )\n }\n\n this.#name = name || this.manifest?.name\n this.version = version || this.manifest?.version\n if (this.version?.startsWith('v')) {\n this.version = this.version.slice(1)\n }\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 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 '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(): Manifest | undefined {\n return this.#rawManifest ?? this.manifest\n }\n\n /**\n * Sets this node as having a manifest-confused manifest.\n */\n setConfusedManifest(fixed: Manifest, confused?: Manifest) {\n this.manifest = fixed\n this.#rawManifest = confused\n this.confused = true\n this.#name = this.manifest.name\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: 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 ...(this.confused ?\n { rawManifest: this.#rawManifest }\n : undefined),\n }\n }\n\n toString() {\n return stringifyNode(this)\n }\n}\n"]}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -21,10 +21,12 @@ export type GraphLike = {
|
|
|
21
21
|
};
|
|
22
22
|
export type NodeLike = {
|
|
23
23
|
id: DepID;
|
|
24
|
+
confused: boolean;
|
|
24
25
|
edgesIn: Set<EdgeLike>;
|
|
25
26
|
edgesOut: Map<string, EdgeLike>;
|
|
26
27
|
location?: string;
|
|
27
28
|
manifest?: Manifest | null;
|
|
29
|
+
rawManifest?: Manifest | null;
|
|
28
30
|
name?: string | null;
|
|
29
31
|
version?: string | null;
|
|
30
32
|
integrity?: string | null;
|
|
@@ -35,8 +37,11 @@ export type NodeLike = {
|
|
|
35
37
|
projectRoot: string;
|
|
36
38
|
dev: boolean;
|
|
37
39
|
optional: boolean;
|
|
38
|
-
toJSON: () => Pick<NodeLike, 'id' | 'name' | 'version' | 'location' | 'importer' | 'manifest' | 'projectRoot' | 'integrity' | 'resolved' | 'dev' | 'optional'
|
|
40
|
+
toJSON: () => Pick<NodeLike, 'id' | 'name' | 'version' | 'location' | 'importer' | 'manifest' | 'projectRoot' | 'integrity' | 'resolved' | 'dev' | 'optional' | 'confused'> & {
|
|
41
|
+
rawManifest?: NodeLike['manifest'];
|
|
42
|
+
};
|
|
39
43
|
toString(): string;
|
|
40
44
|
setResolved(): void;
|
|
45
|
+
setConfusedManifest(fixed: Manifest, confused?: Manifest): void;
|
|
41
46
|
};
|
|
42
47
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEtD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,YAAY,CAAA;IAClB,EAAE,CAAC,EAAE,QAAQ,CAAA;IACb,IAAI,EAAE,mBAAmB,CAAA;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,YAAY,EAAE,QAAQ,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC3B,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACpB,OAAO,EA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,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;IAC1B,WAAW,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,SAAS,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,OAAO,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,MAAM,IAAI,CAChB,QAAQ,EACN,IAAI,GACJ,MAAM,GACN,SAAS,GACT,UAAU,GACV,UAAU,GACV,UAAU,GACV,aAAa,GACb,WAAW,GACX,UAAU,GACV,KAAK,GACL,UAAU,GACV,UAAU,CACb,GAAG;QACF,WAAW,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAA;KACnC,CAAA;IACD,QAAQ,IAAI,MAAM,CAAA;IAClB,WAAW,IAAI,IAAI,CAAA;IACnB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;CAChE,CAAA"}
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { Manifest, DependencyTypeShort } from '@vltpkg/types'\nimport type { Spec, SpecLikeBase } from '@vltpkg/spec'\n\nexport type EdgeLike = {\n name: string\n from: NodeLike\n spec: SpecLikeBase\n to?: NodeLike\n type: DependencyTypeShort\n optional?: boolean\n peer?: boolean\n}\n\nexport type GraphLike = {\n importers: Set<NodeLike>\n mainImporter: NodeLike\n projectRoot: string\n nodes: Map<DepID, NodeLike>\n edges: Set<EdgeLike>\n addEdge: (\n type: DependencyTypeShort,\n spec: Spec,\n from: NodeLike,\n to?: NodeLike,\n ) => EdgeLike\n addNode: (\n id?: DepID,\n manifest?: Manifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) => NodeLike\n}\n\nexport type NodeLike = {\n id: DepID\n edgesIn: Set<EdgeLike>\n edgesOut: Map<string, EdgeLike>\n location?: string\n manifest?: Manifest | null\n name?: string | null\n version?: string | null\n integrity?: string | null\n resolved?: string | null\n importer: boolean\n graph: GraphLike\n mainImporter: boolean\n projectRoot: string\n dev: boolean\n optional: boolean\n toJSON: () => Pick<\n NodeLike,\n | 'id'\n | 'name'\n | 'version'\n | 'location'\n | 'importer'\n | 'manifest'\n | 'projectRoot'\n | 'integrity'\n | 'resolved'\n | 'dev'\n | 'optional'\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { Manifest, DependencyTypeShort } from '@vltpkg/types'\nimport type { Spec, SpecLikeBase } from '@vltpkg/spec'\n\nexport type EdgeLike = {\n name: string\n from: NodeLike\n spec: SpecLikeBase\n to?: NodeLike\n type: DependencyTypeShort\n optional?: boolean\n peer?: boolean\n}\n\nexport type GraphLike = {\n importers: Set<NodeLike>\n mainImporter: NodeLike\n projectRoot: string\n nodes: Map<DepID, NodeLike>\n edges: Set<EdgeLike>\n addEdge: (\n type: DependencyTypeShort,\n spec: Spec,\n from: NodeLike,\n to?: NodeLike,\n ) => EdgeLike\n addNode: (\n id?: DepID,\n manifest?: Manifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) => NodeLike\n}\n\nexport type NodeLike = {\n id: DepID\n confused: boolean\n edgesIn: Set<EdgeLike>\n edgesOut: Map<string, EdgeLike>\n location?: string\n manifest?: Manifest | null\n rawManifest?: Manifest | null\n name?: string | null\n version?: string | null\n integrity?: string | null\n resolved?: string | null\n importer: boolean\n graph: GraphLike\n mainImporter: boolean\n projectRoot: string\n dev: boolean\n optional: boolean\n toJSON: () => Pick<\n NodeLike,\n | 'id'\n | 'name'\n | 'version'\n | 'location'\n | 'importer'\n | 'manifest'\n | 'projectRoot'\n | 'integrity'\n | 'resolved'\n | 'dev'\n | 'optional'\n | 'confused'\n > & {\n rawManifest?: NodeLike['manifest']\n }\n toString(): string\n setResolved(): void\n setConfusedManifest(fixed: Manifest, confused?: Manifest): void\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"human-readable-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAqBrD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,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;AAED,M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ACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,wBAAwB,EACjC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,UA6GjC"}
|
|
@@ -118,9 +118,11 @@ export function humanReadableOutput(options, { colors }) {
|
|
|
118
118
|
: nodeName;
|
|
119
119
|
const nextChar = isLast ? 'last-child' : 'middle-child';
|
|
120
120
|
nextItem.name =
|
|
121
|
-
nextItem.node?.
|
|
122
|
-
`${nextItem.edge?.name}
|
|
123
|
-
:
|
|
121
|
+
nextItem.node?.confused ?
|
|
122
|
+
`${nextItem.edge?.name} ${red('(confused)')}`
|
|
123
|
+
: nextItem.node?.name && nextItem.edge?.name !== nodeName ?
|
|
124
|
+
`${nextItem.edge?.name} (${toName})`
|
|
125
|
+
: `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`;
|
|
124
126
|
nextItem.padding =
|
|
125
127
|
parent.prefix.length ?
|
|
126
128
|
`${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"human-readable-output.js","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAA;AAEtD,MAAM,SAAS,GAAG,CAChB,MAA2C,EAC3C,CAAS,EACT,EAAE;IACF,kEAAkE;IAClE,OAAO,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAA;AAC5D,CAAC,CAAA;AAED,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,OAAO,CAAC;IACb,UAAU,EAAE,GAAG;IACf,IAAI,EAAE,GAAG;IACT,YAAY,EAAE,GAAG;IACjB,cAAc,EAAE,GAAG;IACnB,CAAC,E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,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAA;QACvD,MAAM,gBAAgB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAA;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACjB,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE;YACvF,CAAC,CAAC,EAAE,CAAA;IACR,CAAC,CAAA;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '../types.ts'\nimport { styleText as utilStyleText } from 'node:util'\n\nconst styleText = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => {\n // @ts-expect-error -- styleText 3rd argument is not in types/node\n return utilStyleText(format, s, { validateStream: false })\n}\n\nconst chars = new Map(\n Object.entries({\n connection: '─',\n down: '│',\n 'last-child': '└',\n 'middle-child': '├',\n t: '┬',\n }),\n)\n\nexport type TreeItem = {\n name?: string | null\n edge: EdgeLike | undefined\n node: NodeLike | undefined\n prefix: string\n padding: string\n hasSibling: boolean\n seen: boolean\n include: boolean\n parent: TreeItem | undefined\n}\n\nexport type HumanReadableOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n highlightSelection?: boolean\n}\n\nexport type EdgeMap = Map<NodeLike | undefined, TreeItem>\n\nexport type TreeMap = Map<EdgeLike | undefined, EdgeMap>\n\nconst isSelected = (\n options: HumanReadableOutputGraph,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n !!(\n (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\n )\n\n/**\n * Returns a map of tree items to be printed.\n */\nconst getTreeItems = (\n initialItems: Set<TreeItem>,\n options: HumanReadableOutputGraph,\n) => {\n const seenNodes = new Set<NodeLike>()\n const treeItems: TreeMap = new Map()\n const traverse = new Set<TreeItem>(initialItems)\n for (const item of traverse) {\n if (item.node) {\n if (seenNodes.has(item.node)) {\n item.seen = true\n continue\n }\n seenNodes.add(item.node)\n const edges = [...item.node.edgesOut.values()].sort(i =>\n Number(i.to?.importer),\n )\n for (const edge of edges) {\n const toItems: EdgeMap =\n treeItems.get(edge) ?? (new Map() as EdgeMap)\n const nextItem: TreeItem = {\n edge,\n node: edge.to,\n hasSibling: false,\n padding: '',\n prefix: '',\n seen: false,\n include: isSelected(options, edge, edge.to),\n parent: item,\n }\n toItems.set(edge.to, nextItem)\n treeItems.set(edge, toItems)\n traverse.add(nextItem)\n }\n }\n }\n for (const item of [...traverse].reverse()) {\n if (item.include && item.parent) {\n item.parent.include = true\n }\n }\n return treeItems\n}\n\n/**\n * Returns a human-readable output of the graph.\n */\nexport function humanReadableOutput(\n options: HumanReadableOutputGraph,\n { colors }: { colors?: boolean },\n) {\n const { importers } = options\n const createStyleText =\n (style: Parameters<typeof styleText>[0]) => (s: string) =>\n colors ? styleText(style, s) : s\n const dim = createStyleText('dim')\n const red = createStyleText('red')\n const reset = createStyleText('reset')\n const yellow = createStyleText('yellow')\n const initialItems = new Set<TreeItem>()\n for (const importer of importers) {\n initialItems.add({\n name: importer.name,\n edge: undefined,\n node: importer,\n prefix: '',\n padding: '',\n hasSibling: false,\n seen: false,\n include: isSelected(options, undefined, importer),\n parent: undefined,\n })\n }\n const treeItems = getTreeItems(initialItems, options)\n\n let res = ''\n const traverse = (item: TreeItem) => {\n let header = ''\n let content = ''\n\n const name = item.name\n const decoratedName =\n (\n options.highlightSelection &&\n isSelected(options, item.edge, item.node) &&\n name\n ) ?\n yellow(name)\n : name\n if (!item.node && item.include) {\n const missing =\n item.edge?.type.endsWith('ptional') ?\n dim('(missing optional)')\n : red('(missing)')\n return `${item.padding}${item.prefix}${decoratedName} ${missing}\\n`\n }\n\n header += `${item.padding}${item.prefix}${decoratedName}\\n`\n\n // seen items need not to be printed or traversed\n if (!item.seen) {\n const edges = item.node ? [...item.node.edgesOut.values()] : []\n const nextItems = edges.map(i => treeItems.get(i)?.get(i.to))\n const includedItems = nextItems.filter(i => i?.include)\n\n for (const nextItem of nextItems) {\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!nextItem) continue\n\n const parent = item\n const isLast =\n includedItems.indexOf(nextItem) === includedItems.length - 1\n\n // prefixes the node name with the registry name\n // if a custom registry name is found\n const depIdTuple =\n nextItem.node?.id && splitDepID(nextItem.node.id)\n const hasCustomReg =\n depIdTuple?.[0] === 'registry' && depIdTuple[1]\n const nodeName =\n hasCustomReg ?\n `${depIdTuple[1]}:${nextItem.node?.name}`\n : nextItem.node?.name\n\n const toName =\n nextItem.node?.version ?\n `${nodeName}@${nextItem.node.version}`\n : nodeName\n const nextChar = isLast ? 'last-child' : 'middle-child'\n\n nextItem.name =\n nextItem.node?.name && nextItem.edge?.name !== nodeName ?\n `${nextItem.edge?.name} (${toName})`\n : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`\n nextItem.padding =\n parent.prefix.length ?\n `${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `\n : ''\n nextItem.prefix = `${chars.get(nextChar)}${chars.get('connection')}${chars.get('connection')} `\n nextItem.hasSibling = !isLast\n\n content += traverse(nextItem)\n }\n }\n\n const regularConnection = `${chars.get('connection')} `\n const parentConnection = `${chars.get('t')} `\n return item.include ?\n `${content ? header.replace(regularConnection, parentConnection) : header}${content}`\n : ''\n }\n\n for (const item of initialItems) {\n res += traverse(item)\n }\n return reset(res)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"human-readable-output.js","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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AE,IAAI,CAAC,QAAQ,EAAE,CAAA;gBACtF,QAAQ,CAAC,OAAO;oBACd,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;wBACpB,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG;wBACpE,CAAC,CAAC,EAAE,CAAA;gBACN,QAAQ,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAA;gBAC/F,QAAQ,CAAC,UAAU,GAAG,CAAC,MAAM,CAAA;gBAE7B,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;QAED,MAAM,iBAAiB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAA;QACvD,MAAM,gBAAgB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAA;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACjB,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE;YACvF,CAAC,CAAC,EAAE,CAAA;IACR,CAAC,CAAA;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '../types.ts'\nimport { styleText as utilStyleText } from 'node:util'\n\nconst styleText = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => {\n // @ts-expect-error -- styleText 3rd argument is not in types/node\n return utilStyleText(format, s, { validateStream: false })\n}\n\nconst chars = new Map(\n Object.entries({\n connection: '─',\n down: '│',\n 'last-child': '└',\n 'middle-child': '├',\n t: '┬',\n }),\n)\n\nexport type TreeItem = {\n name?: string | null\n edge: EdgeLike | undefined\n node: NodeLike | undefined\n prefix: string\n padding: string\n hasSibling: boolean\n seen: boolean\n include: boolean\n parent: TreeItem | undefined\n}\n\nexport type HumanReadableOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n highlightSelection?: boolean\n}\n\nexport type EdgeMap = Map<NodeLike | undefined, TreeItem>\n\nexport type TreeMap = Map<EdgeLike | undefined, EdgeMap>\n\nconst isSelected = (\n options: HumanReadableOutputGraph,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n !!(\n (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\n )\n\n/**\n * Returns a map of tree items to be printed.\n */\nconst getTreeItems = (\n initialItems: Set<TreeItem>,\n options: HumanReadableOutputGraph,\n) => {\n const seenNodes = new Set<NodeLike>()\n const treeItems: TreeMap = new Map()\n const traverse = new Set<TreeItem>(initialItems)\n for (const item of traverse) {\n if (item.node) {\n if (seenNodes.has(item.node)) {\n item.seen = true\n continue\n }\n seenNodes.add(item.node)\n const edges = [...item.node.edgesOut.values()].sort(i =>\n Number(i.to?.importer),\n )\n for (const edge of edges) {\n const toItems: EdgeMap =\n treeItems.get(edge) ?? (new Map() as EdgeMap)\n const nextItem: TreeItem = {\n edge,\n node: edge.to,\n hasSibling: false,\n padding: '',\n prefix: '',\n seen: false,\n include: isSelected(options, edge, edge.to),\n parent: item,\n }\n toItems.set(edge.to, nextItem)\n treeItems.set(edge, toItems)\n traverse.add(nextItem)\n }\n }\n }\n for (const item of [...traverse].reverse()) {\n if (item.include && item.parent) {\n item.parent.include = true\n }\n }\n return treeItems\n}\n\n/**\n * Returns a human-readable output of the graph.\n */\nexport function humanReadableOutput(\n options: HumanReadableOutputGraph,\n { colors }: { colors?: boolean },\n) {\n const { importers } = options\n const createStyleText =\n (style: Parameters<typeof styleText>[0]) => (s: string) =>\n colors ? styleText(style, s) : s\n const dim = createStyleText('dim')\n const red = createStyleText('red')\n const reset = createStyleText('reset')\n const yellow = createStyleText('yellow')\n const initialItems = new Set<TreeItem>()\n for (const importer of importers) {\n initialItems.add({\n name: importer.name,\n edge: undefined,\n node: importer,\n prefix: '',\n padding: '',\n hasSibling: false,\n seen: false,\n include: isSelected(options, undefined, importer),\n parent: undefined,\n })\n }\n const treeItems = getTreeItems(initialItems, options)\n\n let res = ''\n const traverse = (item: TreeItem) => {\n let header = ''\n let content = ''\n\n const name = item.name\n const decoratedName =\n (\n options.highlightSelection &&\n isSelected(options, item.edge, item.node) &&\n name\n ) ?\n yellow(name)\n : name\n if (!item.node && item.include) {\n const missing =\n item.edge?.type.endsWith('ptional') ?\n dim('(missing optional)')\n : red('(missing)')\n return `${item.padding}${item.prefix}${decoratedName} ${missing}\\n`\n }\n\n header += `${item.padding}${item.prefix}${decoratedName}\\n`\n\n // seen items need not to be printed or traversed\n if (!item.seen) {\n const edges = item.node ? [...item.node.edgesOut.values()] : []\n const nextItems = edges.map(i => treeItems.get(i)?.get(i.to))\n const includedItems = nextItems.filter(i => i?.include)\n\n for (const nextItem of nextItems) {\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!nextItem) continue\n\n const parent = item\n const isLast =\n includedItems.indexOf(nextItem) === includedItems.length - 1\n\n // prefixes the node name with the registry name\n // if a custom registry name is found\n const depIdTuple =\n nextItem.node?.id && splitDepID(nextItem.node.id)\n const hasCustomReg =\n depIdTuple?.[0] === 'registry' && depIdTuple[1]\n const nodeName =\n hasCustomReg ?\n `${depIdTuple[1]}:${nextItem.node?.name}`\n : nextItem.node?.name\n\n const toName =\n nextItem.node?.version ?\n `${nodeName}@${nextItem.node.version}`\n : nodeName\n const nextChar = isLast ? 'last-child' : 'middle-child'\n\n nextItem.name =\n nextItem.node?.confused ?\n `${nextItem.edge?.name} ${red('(confused)')}`\n : nextItem.node?.name && nextItem.edge?.name !== nodeName ?\n `${nextItem.edge?.name} (${toName})`\n : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`\n nextItem.padding =\n parent.prefix.length ?\n `${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `\n : ''\n nextItem.prefix = `${chars.get(nextChar)}${chars.get('connection')}${chars.get('connection')} `\n nextItem.hasSibling = !isLast\n\n content += traverse(nextItem)\n }\n }\n\n const regularConnection = `${chars.get('connection')} `\n const parentConnection = `${chars.get('t')} `\n return item.include ?\n `${content ? header.replace(regularConnection, parentConnection) : header}${content}`\n : ''\n }\n\n for (const item of initialItems) {\n res += traverse(item)\n }\n return reset(res)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/graph",
|
|
3
3
|
"description": "A library that helps understanding & expressing what happens on an install",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-12",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -23,32 +23,32 @@
|
|
|
23
23
|
"graph-run": "^1.0.4",
|
|
24
24
|
"path-scurry": "^2.0.0",
|
|
25
25
|
"promise-call-limit": "^3.0.2",
|
|
26
|
-
"@vltpkg/cmd-shim": "0.0.0-
|
|
27
|
-
"@vltpkg/dep-id": "0.0.0-
|
|
28
|
-
"@vltpkg/
|
|
29
|
-
"@vltpkg/
|
|
30
|
-
"@vltpkg/
|
|
31
|
-
"@vltpkg/package-json": "0.0.0-
|
|
32
|
-
"@vltpkg/package-info": "0.0.0-
|
|
33
|
-
"@vltpkg/
|
|
34
|
-
"@vltpkg/
|
|
35
|
-
"@vltpkg/
|
|
36
|
-
"@vltpkg/
|
|
37
|
-
"@vltpkg/
|
|
38
|
-
"@vltpkg/
|
|
39
|
-
"@vltpkg/workspaces": "0.0.0-
|
|
26
|
+
"@vltpkg/cmd-shim": "0.0.0-12",
|
|
27
|
+
"@vltpkg/dep-id": "0.0.0-12",
|
|
28
|
+
"@vltpkg/error-cause": "0.0.0-12",
|
|
29
|
+
"@vltpkg/fast-split": "0.0.0-12",
|
|
30
|
+
"@vltpkg/output": "0.0.0-12",
|
|
31
|
+
"@vltpkg/package-json": "0.0.0-12",
|
|
32
|
+
"@vltpkg/package-info": "0.0.0-12",
|
|
33
|
+
"@vltpkg/pick-manifest": "0.0.0-12",
|
|
34
|
+
"@vltpkg/rollback-remove": "0.0.0-12",
|
|
35
|
+
"@vltpkg/run": "0.0.0-12",
|
|
36
|
+
"@vltpkg/spec": "0.0.0-12",
|
|
37
|
+
"@vltpkg/satisfies": "0.0.0-12",
|
|
38
|
+
"@vltpkg/types": "0.0.0-12",
|
|
39
|
+
"@vltpkg/workspaces": "0.0.0-12"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@eslint/js": "^9.25.
|
|
43
|
-
"@types/node": "^22.
|
|
44
|
-
"eslint": "^9.25.
|
|
42
|
+
"@eslint/js": "^9.25.1",
|
|
43
|
+
"@types/node": "^22.15.3",
|
|
44
|
+
"eslint": "^9.25.1",
|
|
45
45
|
"prettier": "^3.5.3",
|
|
46
46
|
"tap": "^21.1.0",
|
|
47
47
|
"tar": "^7.4.3",
|
|
48
48
|
"tshy": "^3.0.2",
|
|
49
|
-
"typedoc": "~0.27.
|
|
49
|
+
"typedoc": "~0.27.9",
|
|
50
50
|
"typescript": "5.7.3",
|
|
51
|
-
"typescript-eslint": "^8.
|
|
51
|
+
"typescript-eslint": "^8.31.1"
|
|
52
52
|
},
|
|
53
53
|
"license": "BSD-2-Clause-Patent",
|
|
54
54
|
"engines": {
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"snap": "tap",
|
|
87
87
|
"test": "tap",
|
|
88
88
|
"posttest": "tsc --noEmit",
|
|
89
|
+
"tshy": "tshy",
|
|
89
90
|
"typecheck": "tsc --noEmit"
|
|
90
91
|
}
|
|
91
92
|
}
|