@vltpkg/graph 1.0.0-rc.8 → 1.0.0-rc.9
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.d.ts.map +1 -1
- package/dist/esm/graph.js +13 -1
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/reify/update-importers-package-json.js +1 -1
- package/dist/esm/reify/update-importers-package-json.js.map +1 -1
- package/dist/esm/stringify-node.d.ts.map +1 -1
- package/dist/esm/stringify-node.js +10 -1
- package/dist/esm/stringify-node.js.map +1 -1
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
- package/dist/esm/visualization/human-readable-output.js +7 -2
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/package.json +21 -21
package/dist/esm/graph.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/graph.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/graph.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,EAAc,IAAI,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,KAAK,E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AAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,SAAK;IAyBrD;;OAEG;IACH,OAAO,CACL,EAAE,CAAC,EAAE,KAAK,EACV,QAAQ,CAAC,EAAE,kBAAkB,EAC7B,IAAI,CAAC,EAAE,IAAI,EACX,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM;IA2BlB;;;;;;;OAOG;IACH,YAAY,CACV,QAAQ,EAAE,IAAI,EACd,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,IAAI,EACV,QAAQ,CAAC,EAAE,kBAAkB,EAC7B,EAAE,CAAC,EAAE,KAAK,EACV,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,GAAG,SAAS;IAuFnB;;;;;;;;;OASG;IACH,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,OAAO;IAmC9D;;OAEG;IACH,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,SAAK;IAmB3C;;;OAGG;IACH,UAAU;IAiBV,MAAM;IAQN,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc;CAIpD"}
|
package/dist/esm/graph.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getId, joinDepIDTuple, splitExtra } from '@vltpkg/dep-id';
|
|
2
2
|
import { error } from '@vltpkg/error-cause';
|
|
3
3
|
import { satisfies } from '@vltpkg/satisfies';
|
|
4
|
-
import { Spec } from '@vltpkg/spec';
|
|
4
|
+
import { getOptions, Spec } from '@vltpkg/spec';
|
|
5
5
|
import { inspect } from 'node:util';
|
|
6
6
|
import { lockfileData } from "./lockfile/save.js";
|
|
7
7
|
import { Edge } from "./edge.js";
|
|
@@ -93,10 +93,22 @@ export class Graph {
|
|
|
93
93
|
constructor(options) {
|
|
94
94
|
const { mainManifest, monorepo } = options;
|
|
95
95
|
this.#options = options;
|
|
96
|
+
// hydrate spec options to their full contents, including defaults
|
|
97
|
+
const specOptions = getOptions({
|
|
98
|
+
registry: options.registry,
|
|
99
|
+
registries: options.registries,
|
|
100
|
+
'git-hosts': options['git-hosts'],
|
|
101
|
+
'git-host-archives': options['git-host-archives'],
|
|
102
|
+
'scope-registries': options['scope-registries'],
|
|
103
|
+
'jsr-registries': options['jsr-registries'],
|
|
104
|
+
catalog: options.catalog,
|
|
105
|
+
catalogs: options.catalogs,
|
|
106
|
+
});
|
|
96
107
|
this.manifests = getMap(options.manifests);
|
|
97
108
|
this.projectRoot = options.projectRoot;
|
|
98
109
|
this.#nodeOptions = {
|
|
99
110
|
...this.#options,
|
|
111
|
+
...specOptions,
|
|
100
112
|
graph: this,
|
|
101
113
|
};
|
|
102
114
|
// add the project root node
|
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,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AASnC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAGxD,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAE7B,kEAAkE;AAClE,qEAAqE;AACr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AK,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,iEAAiE;YACjE,oEAAoE;YACpE,kEAAkE;YAClE,IAAI,IAAI,CAAC,QAAQ;gBAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;YAEvC,oCAAoC;YACpC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;YACrB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;QACtB,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, splitExtra } 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 {\n GraphLike,\n NodeLike,\n NormalizedManifest,\n DependencySaveType,\n} from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport { inspect } from 'node:util'\nimport type { InspectOptions } from 'node:util'\nimport { lockfileData } from './lockfile/save.ts'\nimport { Edge } from './edge.ts'\nimport { Node } from './node.ts'\nimport type { NodeOptions } from './node.ts'\nimport { resolveSaveType } from './resolve-save-type.ts'\nimport type { PeerContext } from './ideal/types.ts'\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nconst cacheKeySeparator = '│'\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, NormalizedManifest>\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\n/**\n * Get a cache key for a resolution based on the\n * spec, location and query modifier.\n */\nconst getResolutionCacheKey = (\n spec: Spec,\n location: string,\n extra: string,\n): string => {\n const f = spec.final\n // if it's a file: dep, then the fromNode location matters\n const fromPrefix = f.type === 'file' ? location + ' : ' : ''\n // the unique key should also precise what is the type of the spec,\n // and in the case of a registry, what registry it is from.\n const typePrecisionKey =\n f.registry ?\n `${cacheKeySeparator}registry` +\n `${cacheKeySeparator}${f.registry}`\n : f.gitRemote ?\n `${cacheKeySeparator}git` + `${cacheKeySeparator}${f.gitRemote}`\n : `${cacheKeySeparator}${f.type}`\n const modifierSuffix = `${cacheKeySeparator}${extra}`\n return fromPrefix + String(f) + typePrecisionKey + modifierSuffix\n}\n\nexport type GraphOptions = SpecOptions & {\n /**\n * The main importer manifest info.\n */\n mainManifest: NormalizedManifest\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 /**\n * The peer context sets used to resolve peer dependencies within this graph.\n */\n peerContexts: PeerContext[]\n\n /**\n * Tracks the current peer context index.\n */\n currentPeerContextIndex = 0\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.mainImporter.workspaces = new Map()\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 // creates a virtual edge to connect the workspaces to the root node\n const edge = new Edge(\n 'prod',\n Spec.parse(wsNode.name, 'workspace:*', this.#options),\n this.mainImporter,\n wsNode,\n )\n this.mainImporter.workspaces.set(wsNode.name, edge)\n }\n }\n\n // initializes the peer context set collection\n const initialPeerContext: PeerContext = new Map()\n initialPeerContext.index = this.currentPeerContextIndex\n this.peerContexts = [initialPeerContext]\n }\n\n /**\n * Get the next peer context index.\n */\n nextPeerContextIndex() {\n return ++this.currentPeerContextIndex\n }\n\n /**\n * Delete all nodes and edges 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.edges.clear()\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 edge of imp.edgesOut.values()) {\n this.edges.add(edge)\n const { to } = edge\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 // removes this edge from its destination edgesIn ref\n edge.to?.edgesIn.delete(edge)\n // now swap the destination to the new one\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, extra = '') {\n const f = spec.final\n const sf = getResolutionCacheKey(f, fromNode.location, extra)\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?: NormalizedManifest,\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\n // ensure the nodes by name set is always sorted, this will help\n // keeping a deterministic graph resolution when reusing nodes\n const newByNameSet = new Set(\n [...nbn].sort((a, b) => a.id.localeCompare(b.id)),\n )\n this.nodesByName.set(node.name, newByNameSet)\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?: NormalizedManifest,\n id?: DepID,\n extra?: string,\n ): Node | undefined {\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, extra))\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.detached = false\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 // split extra into modifier and peerSetHash\n if (extra) {\n const { modifier, peerSetHash } = splitExtra(extra)\n toNode.modifier = modifier\n toNode.peerSetHash = peerSetHash\n }\n\n // add extra manifest info if available\n if (manifest) {\n const { bin, engines, os, cpu } = manifest\n // add platform info if available\n if (engines || os || cpu) {\n const platform: NodeLike['platform'] = {}\n if (engines) platform.engines = engines\n if (os) platform.os = os\n if (cpu) platform.cpu = cpu\n toNode.platform = platform\n }\n // add bin info if available\n if (bin) {\n toNode.bins = bin\n }\n }\n toNode.maybeSetConfusedManifest(spec, manifest)\n\n this.addEdge(depType, spec, fromNode, toNode)\n\n // populate resolution cache if applicable\n const f = getResolutionCacheKey(\n spec.final,\n fromNode.location,\n extra || '',\n )\n this.resolutions.set(f, toNode)\n const rrev = this.resolutionsReverse.get(toNode) ?? new Set()\n rrev.add(f)\n this.resolutionsReverse.set(toNode, rrev)\n\n return toNode\n }\n\n /**\n * Removes a node and its relevant edges from the graph.\n *\n * Use the `keepEdges` option to keep the edges that were pointing to\n * this node and only removes their `to` property value.\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, keepEdges?: boolean) {\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 if (keepEdges) {\n edge.to = undefined\n } else {\n edge.from.edgesOut.delete(edge.spec.name)\n this.edges.delete(edge)\n }\n }\n }\n\n /**\n * Removes the resolved node of a given edge.\n */\n removeEdgeResolution(edge: Edge, extra = '') {\n const node = edge.to\n const resolutionKey = getResolutionCacheKey(\n edge.spec,\n edge.from.location,\n extra,\n )\n if (node) {\n edge.to = undefined\n this.resolutions.delete(resolutionKey)\n this.resolutionsReverse.get(node)?.delete(resolutionKey)\n this.nodesByName.delete(node.name)\n node.edgesIn.delete(edge)\n if (node.edgesIn.size === 0) {\n this.nodes.delete(node.id)\n }\n }\n }\n\n /**\n * Remove all edges from the graph while preserving nodes and resolution caches.\n * This allows the graph to be reconstructed efficiently using the existing nodes.\n */\n resetEdges() {\n // Clear the global edges set\n this.edges.clear()\n\n // Clear all node edge relationships\n for (const node of this.nodes.values()) {\n // marking nodes as detached needs to be restricted to only those\n // that had a manifest, otherwise we'd be skipping fetching manifest\n // for nodes we don't have a manifest during the ideal build phase\n if (node.manifest) node.detached = true\n\n // detaches all edges from this node\n node.edgesOut.clear()\n node.edgesIn.clear()\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":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AAQ,GAAG,IAAI,CAAA;YAEvC,oCAAoC;YACpC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;YACrB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;QACtB,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, splitExtra } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport { satisfies } from '@vltpkg/satisfies'\nimport { getOptions, Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type {\n GraphLike,\n NodeLike,\n NormalizedManifest,\n DependencySaveType,\n} from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport { inspect } from 'node:util'\nimport type { InspectOptions } from 'node:util'\nimport { lockfileData } from './lockfile/save.ts'\nimport { Edge } from './edge.ts'\nimport { Node } from './node.ts'\nimport type { NodeOptions } from './node.ts'\nimport { resolveSaveType } from './resolve-save-type.ts'\nimport type { PeerContext } from './ideal/types.ts'\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nconst cacheKeySeparator = '│'\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, NormalizedManifest>\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\n/**\n * Get a cache key for a resolution based on the\n * spec, location and query modifier.\n */\nconst getResolutionCacheKey = (\n spec: Spec,\n location: string,\n extra: string,\n): string => {\n const f = spec.final\n // if it's a file: dep, then the fromNode location matters\n const fromPrefix = f.type === 'file' ? location + ' : ' : ''\n // the unique key should also precise what is the type of the spec,\n // and in the case of a registry, what registry it is from.\n const typePrecisionKey =\n f.registry ?\n `${cacheKeySeparator}registry` +\n `${cacheKeySeparator}${f.registry}`\n : f.gitRemote ?\n `${cacheKeySeparator}git` + `${cacheKeySeparator}${f.gitRemote}`\n : `${cacheKeySeparator}${f.type}`\n const modifierSuffix = `${cacheKeySeparator}${extra}`\n return fromPrefix + String(f) + typePrecisionKey + modifierSuffix\n}\n\nexport type GraphOptions = SpecOptions & {\n /**\n * The main importer manifest info.\n */\n mainManifest: NormalizedManifest\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 /**\n * The peer context sets used to resolve peer dependencies within this graph.\n */\n peerContexts: PeerContext[]\n\n /**\n * Tracks the current peer context index.\n */\n currentPeerContextIndex = 0\n\n constructor(options: GraphOptions) {\n const { mainManifest, monorepo } = options\n this.#options = options\n // hydrate spec options to their full contents, including defaults\n const specOptions = getOptions({\n registry: options.registry,\n registries: options.registries,\n 'git-hosts': options['git-hosts'],\n 'git-host-archives': options['git-host-archives'],\n 'scope-registries': options['scope-registries'],\n 'jsr-registries': options['jsr-registries'],\n catalog: options.catalog,\n catalogs: options.catalogs,\n })\n this.manifests = getMap(options.manifests)\n this.projectRoot = options.projectRoot\n this.#nodeOptions = {\n ...this.#options,\n ...specOptions,\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.mainImporter.workspaces = new Map()\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 // creates a virtual edge to connect the workspaces to the root node\n const edge = new Edge(\n 'prod',\n Spec.parse(wsNode.name, 'workspace:*', this.#options),\n this.mainImporter,\n wsNode,\n )\n this.mainImporter.workspaces.set(wsNode.name, edge)\n }\n }\n\n // initializes the peer context set collection\n const initialPeerContext: PeerContext = new Map()\n initialPeerContext.index = this.currentPeerContextIndex\n this.peerContexts = [initialPeerContext]\n }\n\n /**\n * Get the next peer context index.\n */\n nextPeerContextIndex() {\n return ++this.currentPeerContextIndex\n }\n\n /**\n * Delete all nodes and edges 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.edges.clear()\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 edge of imp.edgesOut.values()) {\n this.edges.add(edge)\n const { to } = edge\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 // removes this edge from its destination edgesIn ref\n edge.to?.edgesIn.delete(edge)\n // now swap the destination to the new one\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, extra = '') {\n const f = spec.final\n const sf = getResolutionCacheKey(f, fromNode.location, extra)\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?: NormalizedManifest,\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\n // ensure the nodes by name set is always sorted, this will help\n // keeping a deterministic graph resolution when reusing nodes\n const newByNameSet = new Set(\n [...nbn].sort((a, b) => a.id.localeCompare(b.id)),\n )\n this.nodesByName.set(node.name, newByNameSet)\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?: NormalizedManifest,\n id?: DepID,\n extra?: string,\n ): Node | undefined {\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, extra))\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.detached = false\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 // split extra into modifier and peerSetHash\n if (extra) {\n const { modifier, peerSetHash } = splitExtra(extra)\n toNode.modifier = modifier\n toNode.peerSetHash = peerSetHash\n }\n\n // add extra manifest info if available\n if (manifest) {\n const { bin, engines, os, cpu } = manifest\n // add platform info if available\n if (engines || os || cpu) {\n const platform: NodeLike['platform'] = {}\n if (engines) platform.engines = engines\n if (os) platform.os = os\n if (cpu) platform.cpu = cpu\n toNode.platform = platform\n }\n // add bin info if available\n if (bin) {\n toNode.bins = bin\n }\n }\n toNode.maybeSetConfusedManifest(spec, manifest)\n\n this.addEdge(depType, spec, fromNode, toNode)\n\n // populate resolution cache if applicable\n const f = getResolutionCacheKey(\n spec.final,\n fromNode.location,\n extra || '',\n )\n this.resolutions.set(f, toNode)\n const rrev = this.resolutionsReverse.get(toNode) ?? new Set()\n rrev.add(f)\n this.resolutionsReverse.set(toNode, rrev)\n\n return toNode\n }\n\n /**\n * Removes a node and its relevant edges from the graph.\n *\n * Use the `keepEdges` option to keep the edges that were pointing to\n * this node and only removes their `to` property value.\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, keepEdges?: boolean) {\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 if (keepEdges) {\n edge.to = undefined\n } else {\n edge.from.edgesOut.delete(edge.spec.name)\n this.edges.delete(edge)\n }\n }\n }\n\n /**\n * Removes the resolved node of a given edge.\n */\n removeEdgeResolution(edge: Edge, extra = '') {\n const node = edge.to\n const resolutionKey = getResolutionCacheKey(\n edge.spec,\n edge.from.location,\n extra,\n )\n if (node) {\n edge.to = undefined\n this.resolutions.delete(resolutionKey)\n this.resolutionsReverse.get(node)?.delete(resolutionKey)\n this.nodesByName.delete(node.name)\n node.edgesIn.delete(edge)\n if (node.edgesIn.size === 0) {\n this.nodes.delete(node.id)\n }\n }\n }\n\n /**\n * Remove all edges from the graph while preserving nodes and resolution caches.\n * This allows the graph to be reconstructed efficiently using the existing nodes.\n */\n resetEdges() {\n // Clear the global edges set\n this.edges.clear()\n\n // Clear all node edge relationships\n for (const node of this.nodes.values()) {\n // marking nodes as detached needs to be restricted to only those\n // that had a manifest, otherwise we'd be skipping fetching manifest\n // for nodes we don't have a manifest during the ideal build phase\n if (node.manifest) node.detached = true\n\n // detaches all edges from this node\n node.edgesOut.clear()\n node.edgesIn.clear()\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"]}
|
|
@@ -86,7 +86,7 @@ const addOrRemoveDeps = (nodeId, graph, addOrRemove) => {
|
|
|
86
86
|
// If the manifest does not contain anything, then update it.
|
|
87
87
|
// Only for registry dependencies
|
|
88
88
|
const existing = dependencies[name];
|
|
89
|
-
const saveValue = calculateSaveValue(nodeType, dep.spec, existing,
|
|
89
|
+
const saveValue = calculateSaveValue(nodeType, dep.spec, existing, n.version);
|
|
90
90
|
dependencies[name] = saveValue;
|
|
91
91
|
manifestChanged = manifestChanged || saveValue !== existing;
|
|
92
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-importers-package-json.js","sourceRoot":"","sources":["../../../src/reify/update-importers-package-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAO3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAOnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,MAAM,WAAW,GAAG,IAAI,GAAG,CAA0C;IACnE,CAAC,MAAM,EAAE,cAAc,CAAC;IACxB,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAC1B,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAC5B,CAAC,cAAc,EAAE,kBAAkB,CAAC;IACpC,CAAC,UAAU,EAAE,sBAAsB,CAAC;CACrC,CAAC,CAAA;AA8BF,MAAM,eAAe,GAAG,CACtB,MAAa,EACb,KAAY,EACZ,WAEkC,EACF,EAAE;IAClC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,yB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iB,EAAE,CAAC;YACzC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { splitDepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type {\n DependencyTypeLong,\n DependencyTypeShort,\n NormalizedManifest,\n} from '@vltpkg/types'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport { resolveSaveType } from '../resolve-save-type.ts'\nimport { calculateSaveValue } from './calculate-save-value.ts'\n\nconst depTypesMap = new Map<DependencyTypeShort, DependencyTypeLong>([\n ['prod', 'dependencies'],\n ['dev', 'devDependencies'],\n ['peer', 'peerDependencies'],\n ['peerOptional', 'peerDependencies'],\n ['optional', 'optionalDependencies'],\n])\n\nexport type UpdatePackageJsonOptions = {\n /**\n * A `Map` in which keys are {@link DepID} linking to another `Map` in which\n * keys are the dependency names and values are {@link Dependency}. This\n * structure represents dependencies that need to be added to the importer\n * represented by {@link DepID}.\n */\n add?: AddImportersDependenciesMap\n /**\n * A `Map` object representing nodes to be removed from the ideal graph.\n * Each {@link DepID} key represents an importer node and the `Set` of\n * dependency names to be removed from its dependency list.\n */\n remove?: RemoveImportersDependenciesMap\n /**\n * The {@link Graph} instance that contain the importer nodes to which\n * the manifest data (and it's corresponding `package.json` file) are\n * going to be updated.\n */\n graph: Graph\n /**\n * An instance of {@link PackageJson} to use when writing updated manifest\n * data to `package.json` files. It's necessary that this is the same\n * instance used to load these `package.json` files previously.\n */\n packageJson: PackageJson\n}\n\nconst addOrRemoveDeps = (\n nodeId: DepID,\n graph: Graph,\n addOrRemove?:\n | AddImportersDependenciesMap\n | RemoveImportersDependenciesMap,\n): NormalizedManifest | undefined => {\n const node = graph.nodes.get(nodeId)\n if (!node) {\n throw error('Failed to retrieve node', {\n found: nodeId,\n })\n }\n const manifest = node.manifest\n if (!manifest) {\n throw error('Could not find manifest data for node', {\n found: nodeId,\n })\n }\n const deps = addOrRemove?.get(nodeId)\n /* c8 ignore start -- impossible but TS doesn't know that */\n if (!deps) {\n throw error('Failed to retrieve added deps info', {\n manifest,\n })\n }\n let manifestChanged = false\n /* c8 ignore stop */\n for (const deleteNameOrAddItem of deps) {\n if (typeof deleteNameOrAddItem === 'string') {\n const name = deleteNameOrAddItem\n for (const depType of longDependencyTypes) {\n if (manifest[depType]?.[name]) {\n delete manifest[depType][name]\n manifestChanged = true\n }\n }\n if (manifest.peerDependenciesMeta?.[name]) {\n delete manifest.peerDependenciesMeta[name]\n manifestChanged = true\n }\n } else {\n const [name, dep] = deleteNameOrAddItem\n // peerOptional also needs to add peerDependenciesMeta entry\n const depTypeShort = resolveSaveType(node, name, dep.type)\n const depType = depTypesMap.get(depTypeShort)\n if (!depType) {\n throw error('Failed to retrieve dependency type', {\n validOptions: [...depTypesMap.keys()],\n found: dep.type,\n })\n }\n const n = node.edgesOut.get(name)?.to\n if (!n) {\n throw error('Dependency node could not be found')\n }\n const [nodeType] = splitDepID(n.id)\n\n for (const dtype of longDependencyTypes) {\n if (dtype === depType || !manifest[dtype]) continue\n delete manifest[dtype][name]\n }\n if (depTypeShort === 'peerOptional') {\n manifest.peerDependenciesMeta ??= {}\n manifest.peerDependenciesMeta[name] = { optional: true }\n } else if (manifest.peerDependenciesMeta?.[name]) {\n delete manifest.peerDependenciesMeta[name]\n }\n\n const dependencies =\n manifest[depType] ?? (manifest[depType] = {})\n // check to see if we need to save a different version\n // - If you install a single specific version, that is deliberate,\n // we save that exact version, no matter what.\n // - If the requested spec matches the manifest, make no change\n // If the requested spec had no bareSpec, and the manifest has\n // a dependency entry, make no change.\n // If the requested spec has a bareSpec that did NOT match the manifest,\n // then update it.\n // If the manifest does not contain anything, then update it.\n // Only for registry dependencies\n const existing = dependencies[name]\n const saveValue = calculateSaveValue(\n nodeType,\n dep.spec,\n existing,\n node.version,\n )\n dependencies[name] = saveValue\n manifestChanged = manifestChanged || saveValue !== existing\n }\n }\n return manifestChanged ? manifest : undefined\n}\n\n/**\n * Updates nodes of a provided {@link Graph} accordingly to the\n * provided add or remove arguments.\n */\nexport const updatePackageJson = ({\n add,\n graph,\n packageJson,\n remove,\n}: UpdatePackageJsonOptions) => {\n const manifestsToUpdate = new Set<NormalizedManifest>()\n const operations = new Set([add, remove])\n\n for (const operation of operations) {\n if (operation) {\n // These node ids are from either importer nodes or dependencies\n // that are nested folders from which the user can also add new\n // dependencies to\n for (const nodeId of operation.keys()) {\n const manifest = addOrRemoveDeps(nodeId, graph, operation)\n if (manifest) {\n manifestsToUpdate.add(manifest)\n }\n }\n }\n }\n\n const commit = () => {\n for (const manifest of manifestsToUpdate) {\n packageJson.save(manifest)\n }\n }\n\n return commit\n}\n"]}
|
|
1
|
+
{"version":3,"file":"update-importers-package-json.js","sourceRoot":"","sources":["../../../src/reify/update-importers-package-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAO3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAOnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,MAAM,WAAW,GAAG,IAAI,GAAG,CAA0C;IACnE,CAAC,MAAM,EAAE,cAAc,CAAC;IACxB,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAC1B,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAC5B,CAAC,cAAc,EAAE,kBAAkB,CAAC;IACpC,CAAC,UAAU,EAAE,sBAAsB,CAAC;CACrC,CAAC,CAAA;AA8BF,MAAM,eAAe,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AAI,QAAQ,EAAE,CAAC;oBACb,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;YACzC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { splitDepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type {\n DependencyTypeLong,\n DependencyTypeShort,\n NormalizedManifest,\n} from '@vltpkg/types'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport { resolveSaveType } from '../resolve-save-type.ts'\nimport { calculateSaveValue } from './calculate-save-value.ts'\n\nconst depTypesMap = new Map<DependencyTypeShort, DependencyTypeLong>([\n ['prod', 'dependencies'],\n ['dev', 'devDependencies'],\n ['peer', 'peerDependencies'],\n ['peerOptional', 'peerDependencies'],\n ['optional', 'optionalDependencies'],\n])\n\nexport type UpdatePackageJsonOptions = {\n /**\n * A `Map` in which keys are {@link DepID} linking to another `Map` in which\n * keys are the dependency names and values are {@link Dependency}. This\n * structure represents dependencies that need to be added to the importer\n * represented by {@link DepID}.\n */\n add?: AddImportersDependenciesMap\n /**\n * A `Map` object representing nodes to be removed from the ideal graph.\n * Each {@link DepID} key represents an importer node and the `Set` of\n * dependency names to be removed from its dependency list.\n */\n remove?: RemoveImportersDependenciesMap\n /**\n * The {@link Graph} instance that contain the importer nodes to which\n * the manifest data (and it's corresponding `package.json` file) are\n * going to be updated.\n */\n graph: Graph\n /**\n * An instance of {@link PackageJson} to use when writing updated manifest\n * data to `package.json` files. It's necessary that this is the same\n * instance used to load these `package.json` files previously.\n */\n packageJson: PackageJson\n}\n\nconst addOrRemoveDeps = (\n nodeId: DepID,\n graph: Graph,\n addOrRemove?:\n | AddImportersDependenciesMap\n | RemoveImportersDependenciesMap,\n): NormalizedManifest | undefined => {\n const node = graph.nodes.get(nodeId)\n if (!node) {\n throw error('Failed to retrieve node', {\n found: nodeId,\n })\n }\n const manifest = node.manifest\n if (!manifest) {\n throw error('Could not find manifest data for node', {\n found: nodeId,\n })\n }\n const deps = addOrRemove?.get(nodeId)\n /* c8 ignore start -- impossible but TS doesn't know that */\n if (!deps) {\n throw error('Failed to retrieve added deps info', {\n manifest,\n })\n }\n let manifestChanged = false\n /* c8 ignore stop */\n for (const deleteNameOrAddItem of deps) {\n if (typeof deleteNameOrAddItem === 'string') {\n const name = deleteNameOrAddItem\n for (const depType of longDependencyTypes) {\n if (manifest[depType]?.[name]) {\n delete manifest[depType][name]\n manifestChanged = true\n }\n }\n if (manifest.peerDependenciesMeta?.[name]) {\n delete manifest.peerDependenciesMeta[name]\n manifestChanged = true\n }\n } else {\n const [name, dep] = deleteNameOrAddItem\n // peerOptional also needs to add peerDependenciesMeta entry\n const depTypeShort = resolveSaveType(node, name, dep.type)\n const depType = depTypesMap.get(depTypeShort)\n if (!depType) {\n throw error('Failed to retrieve dependency type', {\n validOptions: [...depTypesMap.keys()],\n found: dep.type,\n })\n }\n const n = node.edgesOut.get(name)?.to\n if (!n) {\n throw error('Dependency node could not be found')\n }\n const [nodeType] = splitDepID(n.id)\n\n for (const dtype of longDependencyTypes) {\n if (dtype === depType || !manifest[dtype]) continue\n delete manifest[dtype][name]\n }\n if (depTypeShort === 'peerOptional') {\n manifest.peerDependenciesMeta ??= {}\n manifest.peerDependenciesMeta[name] = { optional: true }\n } else if (manifest.peerDependenciesMeta?.[name]) {\n delete manifest.peerDependenciesMeta[name]\n }\n\n const dependencies =\n manifest[depType] ?? (manifest[depType] = {})\n // check to see if we need to save a different version\n // - If you install a single specific version, that is deliberate,\n // we save that exact version, no matter what.\n // - If the requested spec matches the manifest, make no change\n // If the requested spec had no bareSpec, and the manifest has\n // a dependency entry, make no change.\n // If the requested spec has a bareSpec that did NOT match the manifest,\n // then update it.\n // If the manifest does not contain anything, then update it.\n // Only for registry dependencies\n const existing = dependencies[name]\n const saveValue = calculateSaveValue(\n nodeType,\n dep.spec,\n existing,\n n.version,\n )\n dependencies[name] = saveValue\n manifestChanged = manifestChanged || saveValue !== existing\n }\n }\n return manifestChanged ? manifest : undefined\n}\n\n/**\n * Updates nodes of a provided {@link Graph} accordingly to the\n * provided add or remove arguments.\n */\nexport const updatePackageJson = ({\n add,\n graph,\n packageJson,\n remove,\n}: UpdatePackageJsonOptions) => {\n const manifestsToUpdate = new Set<NormalizedManifest>()\n const operations = new Set([add, remove])\n\n for (const operation of operations) {\n if (operation) {\n // These node ids are from either importer nodes or dependencies\n // that are nested folders from which the user can also add new\n // dependencies to\n for (const nodeId of operation.keys()) {\n const manifest = addOrRemoveDeps(nodeId, graph, operation)\n if (manifest) {\n manifestsToUpdate.add(manifest)\n }\n }\n }\n }\n\n const commit = () => {\n for (const manifest of manifestsToUpdate) {\n packageJson.save(manifest)\n }\n }\n\n return commit\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-node.d.ts","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stringify-node.d.ts","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,eAAO,MAAM,aAAa,UAAW,QAAQ,WA0B5C,CAAA"}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { splitDepID } from '@vltpkg/dep-id/browser';
|
|
2
|
+
import { defaultRegistryName } from '@vltpkg/spec/browser';
|
|
2
3
|
export const stringifyNode = (node) => {
|
|
3
4
|
if (!node)
|
|
4
5
|
return '';
|
|
5
6
|
const version = node.version ? `@${node.version}` : '';
|
|
6
7
|
const [type, ref, nameVersion] = splitDepID(node.id);
|
|
7
8
|
if (type === 'registry') {
|
|
8
|
-
|
|
9
|
+
let prefix = `${defaultRegistryName}:`;
|
|
10
|
+
if (ref) {
|
|
11
|
+
if (/^https?:\/\//.test(ref)) {
|
|
12
|
+
prefix = `registry:${ref}#`;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
prefix = `${ref}:`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
9
18
|
return `${prefix}${nameVersion}`;
|
|
10
19
|
}
|
|
11
20
|
else if (type === 'workspace') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-node.js","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"stringify-node.js","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG1D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAe,EAAE,EAAE;IAC/C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACtD,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEpD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,IAAI,MAAM,GAAG,GAAG,mBAAmB,GAAG,CAAA;QACtC,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC7B,MAAM,GAAG,YAAY,GAAG,GAAG,CAAA;YAC7B,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,GAAG,GAAG,GAAG,CAAA;YACpB,CAAC;QACH,CAAC;QACD,OAAO,GAAG,MAAM,GAAG,WAAW,EAAE,CAAA;IAClC,CAAC;SAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,aAAa,IAAI,CAAC,IAAI,EAAE,CAAA;IACjC,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QAChD,OAAO,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,yEAAyE;QACzE,MAAM,WAAW,GACf,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACxD,OAAO,GAAG,IAAI,IAAI,GAAG,IAAI,WAAW,EAAE,CAAA;IACxC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport { defaultRegistryName } from '@vltpkg/spec/browser'\nimport type { NodeLike } from '@vltpkg/types'\n\nexport const stringifyNode = (node?: NodeLike) => {\n if (!node) return ''\n const version = node.version ? `@${node.version}` : ''\n const [type, ref, nameVersion] = splitDepID(node.id)\n\n if (type === 'registry') {\n let prefix = `${defaultRegistryName}:`\n if (ref) {\n if (/^https?:\\/\\//.test(ref)) {\n prefix = `registry:${ref}#`\n } else {\n prefix = `${ref}:`\n }\n }\n return `${prefix}${nameVersion}`\n } else if (type === 'workspace') {\n return `workspace:${node.name}`\n } else if (type === 'file' && node.mainImporter) {\n return `root:${node.name}`\n } else {\n // node.name getter will return the id if the package has no name\n // property so here we check for that in order to return `type(ref)` only\n const nameVersion =\n node.name !== node.id ? `:${node.name}${version}` : ''\n return `${type}(${ref})${nameVersion}`\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"human-readable-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"human-readable-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAkBvD,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,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAA;AAEzD,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,OAAO,CAAC,CAAA;AAoExD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,wBAAwB,EACjC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,UA4HjC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defaultRegistryName } from '@vltpkg/spec';
|
|
1
2
|
import { splitDepID } from '@vltpkg/dep-id';
|
|
2
3
|
import { styleText as utilStyleText } from 'node:util';
|
|
3
4
|
const styleText = (format, s) => utilStyleText(format, s, { validateStream: false });
|
|
@@ -119,7 +120,9 @@ export function humanReadableOutput(options, { colors }) {
|
|
|
119
120
|
// prefixes the node name with the registry name
|
|
120
121
|
// if a custom registry name is found
|
|
121
122
|
const depIdTuple = nextItem.node?.id && splitDepID(nextItem.node.id);
|
|
122
|
-
const hasCustomReg = depIdTuple?.[0] === 'registry' &&
|
|
123
|
+
const hasCustomReg = depIdTuple?.[0] === 'registry' &&
|
|
124
|
+
depIdTuple[1] &&
|
|
125
|
+
depIdTuple[1] !== defaultRegistryName;
|
|
123
126
|
const nodeName = hasCustomReg ?
|
|
124
127
|
`${depIdTuple[1]}:${nextItem.node?.name}`
|
|
125
128
|
: nextItem.node?.name;
|
|
@@ -127,7 +130,9 @@ export function humanReadableOutput(options, { colors }) {
|
|
|
127
130
|
`${nodeName}@${nextItem.node.version}`
|
|
128
131
|
: nodeName;
|
|
129
132
|
const nextChar = isLast ? 'last-child' : 'middle-child';
|
|
130
|
-
const aliasedPackage =
|
|
133
|
+
const aliasedPackage = hasCustomReg ||
|
|
134
|
+
(nextItem.node?.name &&
|
|
135
|
+
nextItem.edge?.name !== nextItem.node.name);
|
|
131
136
|
nextItem.name =
|
|
132
137
|
nextItem.node?.confused ?
|
|
133
138
|
`${nextItem.edge?.name} ${red('(confused)')}`
|
|
@@ -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,MAA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C,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 '@vltpkg/types'\nimport { styleText as utilStyleText } from 'node:util'\n\nconst styleText = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => utilStyleText(format, s, { validateStream: false })\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 (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\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()]\n const workspaces =\n item.node.workspaces ? [...item.node.workspaces.values()] : []\n const allEdges = [...edges, ...workspaces].sort((a, b) =>\n a.name.localeCompare(b.name, 'en'),\n )\n\n // keeps track of seen edge names to avoid duplicating printed\n // items when a workspace is also a regular dependency of the root\n const seenEdgeName = new Set<string>()\n for (const edge of allEdges) {\n if (seenEdgeName.has(edge.name)) {\n continue\n }\n seenEdgeName.add(edge.name)\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 workspaces =\n item.node?.workspaces ?\n [...item.node.workspaces.values()]\n : []\n const allEdges = [...edges, ...workspaces].sort((a, b) =>\n a.name.localeCompare(b.name, 'en'),\n )\n const nextItems = allEdges.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 const aliasedPackage =\n nextItem.node?.name && nextItem.edge?.name !== nodeName\n nextItem.name =\n nextItem.node?.confused ?\n `${nextItem.edge?.name} ${red('(confused)')}`\n : nextItem.edge?.spec.overridden ?\n /* c8 ignore next */\n `${nextItem.edge.name}@${nextItem.node?.version || nextItem.edge.spec.bareSpec}${aliasedPackage ? ` (${toName})` : ''} ${yellow('(overridden)')}`\n : aliasedPackage ? `${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,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,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,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE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G,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 { defaultRegistryName } from '@vltpkg/spec'\nimport { splitDepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\nimport { styleText as utilStyleText } from 'node:util'\n\nconst styleText = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => utilStyleText(format, s, { validateStream: false })\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 (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\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()]\n const workspaces =\n item.node.workspaces ? [...item.node.workspaces.values()] : []\n const allEdges = [...edges, ...workspaces].sort((a, b) =>\n a.name.localeCompare(b.name, 'en'),\n )\n\n // keeps track of seen edge names to avoid duplicating printed\n // items when a workspace is also a regular dependency of the root\n const seenEdgeName = new Set<string>()\n for (const edge of allEdges) {\n if (seenEdgeName.has(edge.name)) {\n continue\n }\n seenEdgeName.add(edge.name)\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 workspaces =\n item.node?.workspaces ?\n [...item.node.workspaces.values()]\n : []\n const allEdges = [...edges, ...workspaces].sort((a, b) =>\n a.name.localeCompare(b.name, 'en'),\n )\n const nextItems = allEdges.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' &&\n depIdTuple[1] &&\n depIdTuple[1] !== defaultRegistryName\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 const aliasedPackage =\n hasCustomReg ||\n (nextItem.node?.name &&\n nextItem.edge?.name !== nextItem.node.name)\n nextItem.name =\n nextItem.node?.confused ?\n `${nextItem.edge?.name} ${red('(confused)')}`\n : nextItem.edge?.spec.overridden ?\n /* c8 ignore next */\n `${nextItem.edge.name}@${nextItem.node?.version || nextItem.edge.spec.bareSpec}${aliasedPackage ? ` (${toName})` : ''} ${yellow('(overridden)')}`\n : aliasedPackage ? `${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": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.9",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -24,25 +24,25 @@
|
|
|
24
24
|
"graph-run": "^1.1.0",
|
|
25
25
|
"path-scurry": "^2.0.0",
|
|
26
26
|
"promise-call-limit": "^3.0.2",
|
|
27
|
-
"@vltpkg/cmd-shim": "1.0.0-rc.
|
|
28
|
-
"@vltpkg/
|
|
29
|
-
"@vltpkg/
|
|
30
|
-
"@vltpkg/error-cause": "1.0.0-rc.
|
|
31
|
-
"@vltpkg/
|
|
32
|
-
"@vltpkg/
|
|
33
|
-
"@vltpkg/
|
|
34
|
-
"@vltpkg/package-
|
|
35
|
-
"@vltpkg/
|
|
36
|
-
"@vltpkg/pick-manifest": "1.0.0-rc.
|
|
37
|
-
"@vltpkg/query": "1.0.0-rc.
|
|
38
|
-
"@vltpkg/
|
|
39
|
-
"@vltpkg/
|
|
40
|
-
"@vltpkg/
|
|
41
|
-
"@vltpkg/spec": "1.0.0-rc.
|
|
42
|
-
"@vltpkg/
|
|
43
|
-
"@vltpkg/types": "1.0.0-rc.
|
|
44
|
-
"@vltpkg/vlt-json": "1.0.0-rc.
|
|
45
|
-
"@vltpkg/workspaces": "1.0.0-rc.
|
|
27
|
+
"@vltpkg/cmd-shim": "1.0.0-rc.9",
|
|
28
|
+
"@vltpkg/dss-breadcrumb": "1.0.0-rc.9",
|
|
29
|
+
"@vltpkg/dep-id": "1.0.0-rc.9",
|
|
30
|
+
"@vltpkg/error-cause": "1.0.0-rc.9",
|
|
31
|
+
"@vltpkg/fast-split": "1.0.0-rc.9",
|
|
32
|
+
"@vltpkg/init": "1.0.0-rc.9",
|
|
33
|
+
"@vltpkg/package-info": "1.0.0-rc.9",
|
|
34
|
+
"@vltpkg/package-json": "1.0.0-rc.9",
|
|
35
|
+
"@vltpkg/output": "1.0.0-rc.9",
|
|
36
|
+
"@vltpkg/pick-manifest": "1.0.0-rc.9",
|
|
37
|
+
"@vltpkg/query": "1.0.0-rc.9",
|
|
38
|
+
"@vltpkg/satisfies": "1.0.0-rc.9",
|
|
39
|
+
"@vltpkg/rollback-remove": "1.0.0-rc.9",
|
|
40
|
+
"@vltpkg/security-archive": "1.0.0-rc.9",
|
|
41
|
+
"@vltpkg/spec": "1.0.0-rc.9",
|
|
42
|
+
"@vltpkg/run": "1.0.0-rc.9",
|
|
43
|
+
"@vltpkg/types": "1.0.0-rc.9",
|
|
44
|
+
"@vltpkg/vlt-json": "1.0.0-rc.9",
|
|
45
|
+
"@vltpkg/workspaces": "1.0.0-rc.9"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@eslint/js": "^9.34.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"typedoc": "~0.27.9",
|
|
56
56
|
"typescript": "5.7.3",
|
|
57
57
|
"typescript-eslint": "^8.40.0",
|
|
58
|
-
"@vltpkg/vlt-json": "1.0.0-rc.
|
|
58
|
+
"@vltpkg/vlt-json": "1.0.0-rc.9"
|
|
59
59
|
},
|
|
60
60
|
"license": "BSD-2-Clause-Patent",
|
|
61
61
|
"engines": {
|