@vltpkg/graph 0.0.0-15 → 0.0.0-17
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/actual/load.d.ts +26 -2
- package/dist/esm/actual/load.d.ts.map +1 -1
- package/dist/esm/actual/load.js +97 -69
- package/dist/esm/actual/load.js.map +1 -1
- package/dist/esm/dependencies.d.ts +10 -2
- package/dist/esm/dependencies.d.ts.map +1 -1
- package/dist/esm/dependencies.js +63 -0
- package/dist/esm/dependencies.js.map +1 -1
- package/dist/esm/graph.d.ts +5 -1
- package/dist/esm/graph.d.ts.map +1 -1
- package/dist/esm/graph.js +30 -4
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/ideal/add-nodes.d.ts +3 -0
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/add-nodes.js.map +1 -1
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/append-nodes.js +5 -2
- package/dist/esm/ideal/append-nodes.js.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts +0 -2
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +0 -3
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
- package/dist/esm/ideal/build.d.ts +0 -5
- package/dist/esm/ideal/build.d.ts.map +1 -1
- package/dist/esm/ideal/build.js +2 -0
- package/dist/esm/ideal/build.js.map +1 -1
- package/dist/esm/ideal/get-importer-specs.d.ts +1 -6
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
- package/dist/esm/ideal/get-importer-specs.js +1 -9
- package/dist/esm/ideal/get-importer-specs.js.map +1 -1
- package/dist/esm/install.d.ts.map +1 -1
- package/dist/esm/install.js +19 -1
- package/dist/esm/install.js.map +1 -1
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
- package/dist/esm/lockfile/load-nodes.js +10 -3
- package/dist/esm/lockfile/load-nodes.js.map +1 -1
- package/dist/esm/lockfile/load.d.ts +12 -3
- package/dist/esm/lockfile/load.d.ts.map +1 -1
- package/dist/esm/lockfile/load.js +14 -4
- package/dist/esm/lockfile/load.js.map +1 -1
- package/dist/esm/lockfile/save.d.ts +6 -1
- package/dist/esm/lockfile/save.d.ts.map +1 -1
- package/dist/esm/lockfile/save.js +7 -1
- package/dist/esm/lockfile/save.js.map +1 -1
- package/dist/esm/lockfile/types.d.ts +3 -1
- package/dist/esm/lockfile/types.d.ts.map +1 -1
- package/dist/esm/lockfile/types.js.map +1 -1
- package/dist/esm/modifiers.d.ts +7 -17
- package/dist/esm/modifiers.d.ts.map +1 -1
- package/dist/esm/modifiers.js +16 -28
- package/dist/esm/modifiers.js.map +1 -1
- package/dist/esm/node.d.ts +6 -0
- package/dist/esm/node.d.ts.map +1 -1
- package/dist/esm/node.js +26 -7
- package/dist/esm/node.js.map +1 -1
- package/dist/esm/reify/build.js +5 -2
- package/dist/esm/reify/build.js.map +1 -1
- package/dist/esm/reify/index.d.ts +2 -0
- package/dist/esm/reify/index.d.ts.map +1 -1
- package/dist/esm/reify/index.js +5 -0
- package/dist/esm/reify/index.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/types.d.ts +4 -0
- 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 +6 -3
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/dist/esm/visualization/json-output.d.ts +4 -0
- package/dist/esm/visualization/json-output.d.ts.map +1 -1
- package/dist/esm/visualization/json-output.js +2 -0
- package/dist/esm/visualization/json-output.js.map +1 -1
- package/dist/esm/visualization/mermaid-output.d.ts +6 -0
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
- package/dist/esm/visualization/mermaid-output.js +64 -9
- package/dist/esm/visualization/mermaid-output.js.map +1 -1
- package/package.json +20 -19
- package/dist/esm/ideal/check-nodes.d.ts +0 -33
- package/dist/esm/ideal/check-nodes.d.ts.map +0 -1
- package/dist/esm/ideal/check-nodes.js +0 -42
- package/dist/esm/ideal/check-nodes.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifiers.js","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,GAChB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAyFvC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,aAAa;IACxB,yCAAyC;IACzC,OAAO,CAA4B;IACnC,kDAAkD;IAClD,UAAU,GAAG,IAAI,GAAG,EAAiB,CAAA;IACrC,uDAAuD;IACvD,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAA;IAC7C,uDAAuD;IACvD,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAA;IAC7C;;;;OAIG;IACH,eAAe,GAAG,IAAI,GAAG,EAA8B,CAAA;IACvD;;;;;;;OAOG;IACH,cAAc,GAAG,IAAI,GAAG,EAGrB,CAAA;IACH;;OAEG;IACH,eAAe,GAAG,IAAI,GAAG,EAAuB,CAAA;IAEhD,YAAY,OAAoB;QAC9B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACpB,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACR,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,OAAO,CAAA;QACrC,OAAO,CAAC,IAAI,CAAC,O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,CACtB,CAAA;YACH,CAAC;YACD,kCAAkC;YAClC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,OAAoB;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAA;QAC1D,IAAI,CAAC,MAAM;YAAE,OAAM;QACnB,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,OAAoB;QAC9B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import {\n parseBreadcrumb,\n specificitySort,\n} from '@vltpkg/dss-breadcrumb'\nimport { error } from '@vltpkg/error-cause'\nimport { Spec } from '@vltpkg/spec'\nimport { asManifest, assertRecordStringString } from '@vltpkg/types'\nimport { load } from '@vltpkg/vlt-json'\nimport type {\n ModifierBreadcrumb,\n ModifierInteractiveBreadcrumb,\n} from '@vltpkg/dss-breadcrumb'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { Manifest } from '@vltpkg/types'\nimport type { Edge } from './edge.ts'\nimport type { Node } from './node.ts'\nimport type { Dependency } from './dependencies.ts'\n\n/**\n * Loaded modifiers configuration as described in the `vlt.json` file.\n */\nexport type GraphModifierLoadedConfig = {\n modifiers: GraphModifierConfigObject\n}\n\n/**\n * Type definition for the modifiers configuration object\n */\n// TODO: subtype string into a more specific type for Queries\nexport type GraphModifierConfigObject = Record<string, string>\n\n/**\n * Info needed to define a graph modifier.\n */\nexport type BaseModifierEntry = {\n type: 'edge' | 'node'\n query: string\n breadcrumb: ModifierBreadcrumb\n value: string | Manifest\n refs: Set<{\n name: string\n from: Node\n }>\n}\n\n/**\n * Extra info to define specifically a graph edge modifier.\n */\nexport type EdgeModifierEntry = BaseModifierEntry & {\n type: 'edge'\n spec: Spec\n value: string\n}\n\n/**\n * Extra info to define the graph node modifier.\n */\nexport type NodeModifierEntry = BaseModifierEntry & {\n type: 'node'\n manifest: Manifest\n}\n\n/**\n * A graph modifier entry, which can be either an edge or a node modifier.\n */\nexport type ModifierEntry = EdgeModifierEntry | NodeModifierEntry\n\n/**\n * An object to track modifiers that have matched an initial part of the\n * breadcrumb. It holds pointers to both nodes and edges matched in the\n * current traversed graph on top of the modifier info and the breadcrumb\n * state that is used to track the current state of the parsing.\n */\nexport type ModifierActiveEntry = {\n /**\n * The modifier this active entry is working with.\n */\n modifier: ModifierEntry\n /**\n * The breadcrumb that is used to track the current state of the parsing.\n */\n interactiveBreadcrumb: ModifierInteractiveBreadcrumb\n /**\n * The first node to be affected by this modifier.\n */\n originalFrom: Node\n /**\n * The original edge that is being replaced with this entry.\n */\n originalEdge?: Edge\n /**\n * The modified edge that is being used to replace the original edge.\n */\n modifiedEdge?: Edge\n}\n\n/**\n * Class representing loaded modifiers configuration for a project.\n *\n * Instances of this class can be used as a helper to modify the graph\n * during the graph build ideal traversal time.\n *\n * ```\n * const modifier = new GraphModifier(options)\n * modifier.load(options)\n * ```\n *\n * The `tryImporter` method can be used to register the initial importer\n * node along with any modifier that includes an importer selector, e.g:\n * `modifier.tryImporter(graph.mainImporter)`\n *\n * When traversing the graph, use the `tryNewDependency` method to check\n * if a given dependency name to the current traversed node has matching\n * registered modifiers, e.g:\n * `const entries = modifier.tryNewDependency(fromNode, depName)`\n *\n * Use `updateActiveEntry` to update a given active modifier entry state\n * with the current node of the graph being traversed. e.g:\n * ```\n * for (const entry of entries)\n * modifier.updateActiveEntry(fromNode, entry)\n * ```\n */\nexport class GraphModifier {\n /** The loaded modifiers configuration */\n #config?: GraphModifierConfigObject\n /** A set of all modifiers loaded from vlt.json */\n #modifiers = new Set<ModifierEntry>()\n /** A set of all edge modifiers loaded from vlt.json */\n #edgeModifiers = new Set<EdgeModifierEntry>()\n /** A set of all node modifiers loaded from vlt.json */\n #nodeModifiers = new Set<NodeModifierEntry>()\n /**\n * A map of initial entries, keyed by the name of the first breadcrumb\n * item to its modifier entry. Useful for checking for non-importer\n * starting breadcrumbs, e.g: `#a > #b`\n */\n #initialEntries = new Map<string, Set<ModifierEntry>>()\n /**\n * A multi-level map of active entries, keyed by:\n * - modifiers\n * - edge name\n * - from node\n * that allows for retrieving seen {@link ModifierActiveEntry} instances\n * in constant time.\n */\n #activeEntries = new Map<\n ModifierEntry,\n Map<string, Map<Node, ModifierActiveEntry>>\n >()\n /**\n * A set of currently active modifiers, which are being parsed.\n */\n activeModifiers = new Set<ModifierActiveEntry>()\n\n constructor(options: SpecOptions) {\n this.load(options)\n }\n\n /**\n * Load the modifiers definitions from vlt.json,\n * converting the result into a GraphModifierConfigObject\n */\n get config(): GraphModifierConfigObject {\n if (this.#config) return this.#config\n return (this.#config =\n load('modifiers', assertRecordStringString) ?? {})\n }\n\n /**\n * Loads the modifiers defined in `vlt.json` into memory.\n */\n load(options: SpecOptions) {\n for (const [key, value] of Object.entries(this.config)) {\n const breadcrumb = parseBreadcrumb(key)\n /* c8 ignore start - should not be possible */\n if (!breadcrumb.last.name) {\n throw error('Could not find name in breadcrumb', {\n found: key,\n })\n }\n /* c8 ignore stop */\n let mod: ModifierEntry\n if (typeof value === 'string') {\n mod = {\n breadcrumb,\n query: key,\n refs: new Set(),\n spec: Spec.parse(breadcrumb.last.name, value, options),\n type: 'edge',\n value,\n } satisfies EdgeModifierEntry\n this.#edgeModifiers.add(mod)\n /* c8 ignore start - TODO */\n } else {\n const manifest = asManifest(value)\n mod = {\n breadcrumb,\n query: key,\n manifest,\n refs: new Set(),\n type: 'node',\n value: manifest,\n } satisfies NodeModifierEntry\n this.#nodeModifiers.add(mod)\n }\n /* c8 ignore end */\n this.#modifiers.add(mod)\n // if the breadcrumb starts with an id, then add it to the\n // map of initial entries, so that we can use it to match\n if (breadcrumb.first.name) {\n const initialSet =\n this.#initialEntries.get(breadcrumb.first.name) ?? new Set()\n initialSet.add(mod)\n this.#initialEntries.set(breadcrumb.first.name, initialSet)\n }\n }\n }\n\n /**\n * Check if a given importer dependency name has potentially a registered\n * modifier. In case of an ambiguous modifier, the method will always\n * return `true`, it only returns `false` in the case that only fully\n * qualified modifiers are registered and none are targeting the given\n * top-level dependency name.\n *\n * This method is useful to help avoiding traversing the sub graph of\n * a direct dependency when we know that it's impossible to ever match\n * beforehand.\n */\n maybeHasModifier(depName: string): boolean {\n for (const mod of this.#modifiers) {\n const matchingName =\n mod.breadcrumb.first.importer &&\n mod.breadcrumb.first.next?.name === depName\n const rootlessBreadcrumb = !mod.breadcrumb.first.importer\n if (rootlessBreadcrumb || matchingName) {\n return true\n }\n }\n return false\n }\n\n /**\n * Try matching the provided node against the top-level selectors. In case\n * a match is found it will also register the active entry modifier and\n * update the active entry to the current importer node.\n */\n tryImporter(importer: Node) {\n for (const modifier of this.#modifiers) {\n // if the first item in the breadcrumb is an importer and it matches\n // any of the valid top-level selectors, then register the modifier\n const { first } = modifier.breadcrumb\n const matchRoot =\n first.value === ':root' && importer.mainImporter\n const matchWorkspace =\n first.value === ':workspace' && importer.importer\n const matchAny =\n first.value === ':project' || matchRoot || matchWorkspace\n if (first.importer && matchAny) {\n const active = this.newModifier(importer, modifier)\n const single = active.modifier.breadcrumb.single\n // only the importers will update the active entry right after\n // registering it since tryImporter doesn't try to match from\n // active dependencies\n if (!single) {\n this.updateActiveEntry(importer, active)\n }\n }\n }\n }\n\n /**\n * Try matching the provided node and dependency name to the current\n * active parsing modifier entries along with possible starting-level\n * modifiers.\n *\n * Any entries in which the breachcrumb have already reached its last\n * element will be prioritized, along with checking for specificity,\n * the complete entry with the highest specificity will be returned or just\n * the entry with the highest specificity if no complete entry is found.\n * Returns `undefined` if no matching entry is found.\n *\n * This method works with the assumption that it's going to be called\n * during a graph traversal, such that any ascendent has been checked\n * and the active modifier entry state has been updated in the previous\n * iteration.\n */\n tryNewDependency(\n from: Node,\n name: string,\n ): ModifierActiveEntry | undefined {\n // here we use a map instead of a set so that we can associate each\n // modifier active entry with its breadcrumb so that it's easier to\n // pick the correct entry when we sort breadcrbumbs by specificity\n const all = new Map<\n ModifierBreadcrumb | undefined,\n ModifierActiveEntry\n >()\n for (const modifier of this.#modifiers) {\n // if an active entry is found then returns that\n const entry = this.#activeEntries\n .get(modifier)\n ?.get(name)\n ?.get(from)\n if (entry) {\n all.set(entry.modifier.breadcrumb, entry)\n }\n }\n // matches the name against the initial entries, this will make it so\n // that modifier queries that start with a name (e.g: #a > #b) can\n // match at any point of the graph traversal\n const initialSet =\n this.#initialEntries.get(name) ?? new Set<ModifierEntry>()\n for (const initial of initialSet) {\n const initialEntry =\n /* c8 ignore next - difficult to test branch */\n this.#activeEntries.get(initial)?.get(name)?.get(from) ??\n this.newModifier(from, initial)\n all.set(initialEntry.modifier.breadcrumb, initialEntry)\n }\n // selects the active entry that should apply to this dependency,\n // any active entry that is done parsing has the priority, if we\n // find multiple entries then we use css specificity to pick a winner\n // if we have multiple matches but no active entry is complete, then\n // we pick the one with the highest specificity breadcrumb\n const arr = [...all.values()]\n const completeEntries = arr.filter(\n active =>\n active.interactiveBreadcrumb.current ===\n active.modifier.breadcrumb.last,\n )\n // deregister completed entries\n for (const entry of completeEntries) {\n this.deregisterModifier(entry.modifier)\n }\n // returns the highest specificity entry from either the complete entries\n // if any were found or from any of the entries if available, otherwise\n // it will return undefined as no entry is found in the `all` map\n const entries = completeEntries.length ? completeEntries : arr\n return all.get(\n specificitySort(entries.map(i => i.modifier.breadcrumb))[0],\n )\n }\n\n /**\n * Returns the set of {@link ModifierActiveEntry} instances that matches\n * the provided {@link Dependency} specs for a given node.\n *\n * This method is mostly a helper to {@link GraphModifier.tryNewDependency}\n * that handles the registered modifiers traversal lookup.\n */\n tryDependencies(\n from: Node,\n dependencies: Dependency[],\n ): Map<string, ModifierActiveEntry> {\n const modifierRefs = new Map<string, ModifierActiveEntry>()\n for (const { spec } of dependencies) {\n const active = this.tryNewDependency(from, spec.name)\n if (active) {\n modifierRefs.set(spec.name, active)\n }\n }\n return modifierRefs\n }\n\n /**\n * Updates an active entry state keeping track of items in the multi-level\n * active entries map. If the current breadcrumb state shows there's no more\n * items left, then we deregister the modifier.\n */\n updateActiveEntry(from: Node, active: ModifierActiveEntry): void {\n const { modifier } = active\n const interactiveBreadcrumb = active.interactiveBreadcrumb.next()\n const name = interactiveBreadcrumb.current?.name\n\n // if there's no name, or we're done parsing then we\n // deregister the modifier instead of updating the entry\n if (interactiveBreadcrumb.done || !name) {\n this.deregisterModifier(modifier)\n return\n }\n\n // register the active modifier\n this.activeModifiers.add(active)\n active.modifier.refs.add({ from, name })\n\n // optionally read or create the nested maps\n const nameMap =\n this.#activeEntries.get(modifier) ??\n new Map<string, Map<Node, ModifierActiveEntry>>()\n this.#activeEntries.set(modifier, nameMap)\n const nodeMap =\n nameMap.get(name) ?? new Map<Node, ModifierActiveEntry>()\n nameMap.set(name, nodeMap)\n\n // sets the active entry in the map\n nodeMap.set(from, active)\n }\n\n /**\n * Creates a new active modifier.\n */\n newModifier(\n from: Node,\n modifier: ModifierEntry,\n ): ModifierActiveEntry {\n return {\n modifier,\n interactiveBreadcrumb: modifier.breadcrumb.interactive(),\n originalFrom: from,\n }\n }\n\n /**\n * Removes a previously registered modifier from the active entries.\n */\n deregisterModifier(modifier: ModifierEntry): void {\n for (const { from, name } of modifier.refs) {\n const nodeMap = this.#activeEntries.get(modifier)?.get(name)\n if (nodeMap) {\n // if an entry is found, we remove it from the active set\n const entry = nodeMap.get(from)\n if (entry) {\n this.activeModifiers.delete(entry)\n }\n // then we remove the entry from the map\n nodeMap.delete(from)\n // if the map is empty, we remove it from the active entries map\n if (!nodeMap.size) {\n this.#activeEntries.get(modifier)?.delete(name)\n }\n }\n }\n }\n\n /**\n * Operates in previously registered nodes and edges in order to put\n * back in place any of the original edges that were referenced to in\n * active (ongoing) breadcrumb parsing entries that were never completed.\n *\n * This method can be used to easily rollback any pending operations\n * once the graph traversal is done.\n */\n rollbackActiveEntries(): void {\n for (const modifier of this.activeModifiers) {\n // if the modifier has an original edge, we can put it back in place\n if (modifier.originalEdge) {\n modifier.originalFrom.edgesOut.set(\n modifier.originalEdge.spec.name,\n modifier.originalEdge,\n )\n }\n // then we deregister the modifier\n this.deregisterModifier(modifier.modifier)\n }\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Returns undefined if the project does not have a vlt.json file,\n * otherwise returns the loaded Modifiers instance.\n */\n static maybeLoad(options: SpecOptions) {\n const config = load('modifiers', assertRecordStringString)\n if (!config) return\n return new GraphModifier(options)\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Throws if called on a directory that does not have a vlt.json file.\n */\n static load(options: SpecOptions) {\n return new GraphModifier(options)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"modifiers.js","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,GAChB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAyFvC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,aAAa;IACxB,yCAAyC;IACzC,OAAO,CAA4B;IACnC,kDAAkD;IAClD,UAAU,GAAG,IAAI,GAAG,EAAiB,CAAA;IACrC,uDAAuD;IACvD,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAA;IAC7C,uDAAuD;IACvD,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAA;IAC7C;;;;OAIG;IACH,eAAe,GAAG,IAAI,GAAG,EAA8B,CAAA;IACvD;;;;;;;OAOG;IACH,cAAc,GAAG,IAAI,GAAG,EAGrB,CAAA;IACH;;OAEG;IACH,eAAe,GAAG,IAAI,G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ChC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAC/B,QAAQ,CAAC,YAAY,CACtB,CAAA;YACH,CAAC;YACD,kCAAkC;YAClC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,OAAoB;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAA;QAC1D,IAAI,CAAC,MAAM;YAAE,OAAM;QACnB,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,OAAoB;QAC9B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import {\n parseBreadcrumb,\n specificitySort,\n} from '@vltpkg/dss-breadcrumb'\nimport { error } from '@vltpkg/error-cause'\nimport { Spec } from '@vltpkg/spec'\nimport { asManifest, assertRecordStringString } from '@vltpkg/types'\nimport { load } from '@vltpkg/vlt-json'\nimport type {\n ModifierBreadcrumb,\n ModifierInteractiveBreadcrumb,\n} from '@vltpkg/dss-breadcrumb'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { Manifest } from '@vltpkg/types'\nimport type { Edge } from './edge.ts'\nimport type { Node } from './node.ts'\nimport type { Dependency } from './dependencies.ts'\n\n/**\n * Loaded modifiers configuration as described in the `vlt.json` file.\n */\nexport type GraphModifierLoadedConfig = {\n modifiers: GraphModifierConfigObject\n}\n\n/**\n * Type definition for the modifiers configuration object\n */\n// TODO: subtype string into a more specific type for Queries\nexport type GraphModifierConfigObject = Record<string, string>\n\n/**\n * Info needed to define a graph modifier.\n */\nexport type BaseModifierEntry = {\n type: 'edge' | 'node'\n query: string\n breadcrumb: ModifierBreadcrumb\n value: string | Manifest\n refs: Set<{\n name: string\n from: Node\n }>\n}\n\n/**\n * Extra info to define specifically a graph edge modifier.\n */\nexport type EdgeModifierEntry = BaseModifierEntry & {\n type: 'edge'\n spec: Spec\n value: string\n}\n\n/**\n * Extra info to define the graph node modifier.\n */\nexport type NodeModifierEntry = BaseModifierEntry & {\n type: 'node'\n manifest: Manifest\n}\n\n/**\n * A graph modifier entry, which can be either an edge or a node modifier.\n */\nexport type ModifierEntry = EdgeModifierEntry | NodeModifierEntry\n\n/**\n * An object to track modifiers that have matched an initial part of the\n * breadcrumb. It holds pointers to both nodes and edges matched in the\n * current traversed graph on top of the modifier info and the breadcrumb\n * state that is used to track the current state of the parsing.\n */\nexport type ModifierActiveEntry = {\n /**\n * The modifier this active entry is working with.\n */\n modifier: ModifierEntry\n /**\n * The breadcrumb that is used to track the current state of the parsing.\n */\n interactiveBreadcrumb: ModifierInteractiveBreadcrumb\n /**\n * The first node to be affected by this modifier.\n */\n originalFrom: Node\n /**\n * The original edge that is being replaced with this entry.\n */\n originalEdge?: Edge\n /**\n * The modified edge that is being used to replace the original edge.\n */\n modifiedEdge?: Edge\n}\n\n/**\n * Class representing loaded modifiers configuration for a project.\n *\n * Instances of this class can be used as a helper to modify the graph\n * during the graph build ideal traversal time.\n *\n * ```\n * const modifier = new GraphModifier(options)\n * modifier.load(options)\n * ```\n *\n * The `tryImporter` method can be used to register the initial importer\n * node along with any modifier that includes an importer selector, e.g:\n * `modifier.tryImporter(graph.mainImporter)`\n *\n * When traversing the graph, use the `tryNewDependency` method to check\n * if a given dependency spec to the current traversed node has matching\n * registered modifiers, e.g:\n * `const entries = modifier.tryNewDependency(fromNode, depSpec)`\n *\n * Use `updateActiveEntry` to update a given active modifier entry state\n * with the current node of the graph being traversed. e.g:\n * ```\n * for (const entry of entries)\n * modifier.updateActiveEntry(fromNode, entry)\n * ```\n */\nexport class GraphModifier {\n /** The loaded modifiers configuration */\n #config?: GraphModifierConfigObject\n /** A set of all modifiers loaded from vlt.json */\n #modifiers = new Set<ModifierEntry>()\n /** A set of all edge modifiers loaded from vlt.json */\n #edgeModifiers = new Set<EdgeModifierEntry>()\n /** A set of all node modifiers loaded from vlt.json */\n #nodeModifiers = new Set<NodeModifierEntry>()\n /**\n * A map of initial entries, keyed by the name of the first breadcrumb\n * item to its modifier entry. Useful for checking for non-importer\n * starting breadcrumbs, e.g: `#a > #b`\n */\n #initialEntries = new Map<string, Set<ModifierEntry>>()\n /**\n * A multi-level map of active entries, keyed by:\n * - modifiers\n * - edge name\n * - from node\n * that allows for retrieving seen {@link ModifierActiveEntry} instances\n * in constant time.\n */\n #activeEntries = new Map<\n ModifierEntry,\n Map<string, Map<Node, ModifierActiveEntry>>\n >()\n /**\n * A set of currently active modifiers, which are being parsed.\n */\n activeModifiers = new Set<ModifierActiveEntry>()\n /** A set of all modifier string values loaded from vlt.json */\n modifierNames = new Set<string>()\n\n constructor(options: SpecOptions) {\n this.load(options)\n }\n\n /**\n * Load the modifiers definitions from vlt.json,\n * converting the result into a GraphModifierConfigObject\n */\n get config(): GraphModifierConfigObject {\n if (this.#config) return this.#config\n return (this.#config =\n load('modifiers', assertRecordStringString) ?? {})\n }\n\n /**\n * Loads the modifiers defined in `vlt.json` into memory.\n */\n load(options: SpecOptions) {\n for (const [key, value] of Object.entries(this.config)) {\n this.modifierNames.add(key)\n const breadcrumb = parseBreadcrumb(key)\n /* c8 ignore start - should not be possible */\n if (!breadcrumb.last.name) {\n throw error('Could not find name in breadcrumb', {\n found: key,\n })\n }\n /* c8 ignore stop */\n let mod: ModifierEntry\n if (typeof value === 'string') {\n mod = {\n breadcrumb,\n query: key,\n refs: new Set(),\n spec: Spec.parse(breadcrumb.last.name, value, options),\n type: 'edge',\n value,\n } satisfies EdgeModifierEntry\n this.#edgeModifiers.add(mod)\n /* c8 ignore start - TODO */\n } else {\n const manifest = asManifest(value)\n mod = {\n breadcrumb,\n query: key,\n manifest,\n refs: new Set(),\n type: 'node',\n value: manifest,\n } satisfies NodeModifierEntry\n this.#nodeModifiers.add(mod)\n }\n /* c8 ignore end */\n this.#modifiers.add(mod)\n // if the breadcrumb starts with an id, then add it to the\n // map of initial entries, so that we can use it to match\n if (breadcrumb.first.name) {\n const initialSet =\n this.#initialEntries.get(breadcrumb.first.name) ?? new Set()\n initialSet.add(mod)\n this.#initialEntries.set(breadcrumb.first.name, initialSet)\n }\n }\n }\n\n /**\n * Try matching the provided node against the top-level selectors. In case\n * a match is found it will also register the active entry modifier and\n * update the active entry to the current importer node.\n */\n tryImporter(importer: Node) {\n for (const modifier of this.#modifiers) {\n // if the first item in the breadcrumb is an importer and it matches\n // any of the valid top-level selectors, then register the modifier\n const { first } = modifier.breadcrumb\n const matchRoot =\n first.value === ':root' && importer.mainImporter\n const matchWorkspace =\n first.value === ':workspace' && importer.importer\n const matchAny =\n first.value === ':project' || matchRoot || matchWorkspace\n if (first.importer && matchAny) {\n const active = this.newModifier(importer, modifier)\n const single = active.modifier.breadcrumb.single\n // only the importers will update the active entry right after\n // registering it since tryImporter doesn't try to match from\n // active dependencies\n if (!single) {\n this.updateActiveEntry(importer, active)\n }\n }\n }\n }\n\n /**\n * Try matching the provided node and spec to the current\n * active parsing modifier entries along with possible starting-level\n * modifiers.\n *\n * Any entries in which the breachcrumb have already reached its last\n * element will be prioritized, along with checking for specificity,\n * the complete entry with the highest specificity will be returned or just\n * the entry with the highest specificity if no complete entry is found.\n * Returns `undefined` if no matching entry is found.\n *\n * This method works with the assumption that it's going to be called\n * during a graph traversal, such that any ascendent has been checked\n * and the active modifier entry state has been updated in the previous\n * iteration.\n */\n tryNewDependency(\n from: Node,\n spec: Spec,\n ): ModifierActiveEntry | undefined {\n const { name, semver } = spec\n // here we use a map instead of a set so that we can associate each\n // modifier active entry with its breadcrumb so that it's easier to\n // pick the correct entry when we sort breadcrbumbs by specificity\n const all = new Map<\n ModifierBreadcrumb | undefined,\n ModifierActiveEntry\n >()\n for (const modifier of this.#modifiers) {\n // if an active entry is found then returns that\n const entry = this.#activeEntries\n .get(modifier)\n ?.get(name)\n ?.get(from)\n if (entry) {\n all.set(entry.modifier.breadcrumb, entry)\n }\n }\n // matches the name against the initial entries, this will make it so\n // that modifier queries that start with a name (e.g: #a > #b) can\n // match at any point of the graph traversal\n const initialSet =\n this.#initialEntries.get(name) ?? new Set<ModifierEntry>()\n for (const initial of initialSet) {\n const initialEntry =\n /* c8 ignore next - difficult to test branch */\n this.#activeEntries.get(initial)?.get(name)?.get(from) ??\n this.newModifier(from, initial)\n all.set(initialEntry.modifier.breadcrumb, initialEntry)\n }\n // selects the active entry that should apply to this dependency,\n // any active entry that is done parsing has the priority, if we\n // find multiple entries then we use css specificity to pick a winner\n // if we have multiple matches but no active entry is complete, then\n // we pick the one with the highest specificity breadcrumb\n const arr = [...all.values()]\n const completeEntries = arr.filter(\n active =>\n active.interactiveBreadcrumb.current ===\n active.modifier.breadcrumb.last,\n )\n // deregister completed entries\n for (const entry of completeEntries) {\n this.deregisterModifier(entry.modifier)\n }\n // returns the highest specificity entry from either the complete entries\n // if any were found or from any of the entries if available, otherwise\n // it will return undefined as no entry is found in the `all` map\n const entries = completeEntries.length ? completeEntries : arr\n return all.get(\n specificitySort(\n entries\n // here we filter out any entries that do not match the\n // pseudo selector comparators used in the breadcrumb item\n .filter(i =>\n i.interactiveBreadcrumb.current?.comparator({\n semver,\n }),\n )\n .map(i => i.modifier.breadcrumb),\n )[0],\n )\n }\n\n /**\n * Returns the set of {@link ModifierActiveEntry} instances that matches\n * the provided {@link Dependency} specs for a given node.\n *\n * This method is mostly a helper to {@link GraphModifier.tryNewDependency}\n * that handles the registered modifiers traversal lookup.\n */\n tryDependencies(\n from: Node,\n dependencies: Dependency[] | Edge[],\n ): Map<string, ModifierActiveEntry> {\n const modifierRefs = new Map<string, ModifierActiveEntry>()\n for (const { spec } of dependencies) {\n const active = this.tryNewDependency(from, spec)\n if (active) {\n modifierRefs.set(spec.name, active)\n }\n }\n return modifierRefs\n }\n\n /**\n * Updates an active entry state keeping track of items in the multi-level\n * active entries map. If the current breadcrumb state shows there's no more\n * items left, then we deregister the modifier.\n */\n updateActiveEntry(from: Node, active: ModifierActiveEntry): void {\n const { modifier } = active\n const interactiveBreadcrumb = active.interactiveBreadcrumb.next()\n const name = interactiveBreadcrumb.current?.name\n\n // if there's no name, or we're done parsing then we\n // deregister the modifier instead of updating the entry\n if (interactiveBreadcrumb.done || !name) {\n this.deregisterModifier(modifier)\n return\n }\n\n // register the active modifier\n this.activeModifiers.add(active)\n active.modifier.refs.add({ from, name })\n\n // optionally read or create the nested maps\n const nameMap =\n this.#activeEntries.get(modifier) ??\n new Map<string, Map<Node, ModifierActiveEntry>>()\n this.#activeEntries.set(modifier, nameMap)\n const nodeMap =\n nameMap.get(name) ?? new Map<Node, ModifierActiveEntry>()\n nameMap.set(name, nodeMap)\n\n // sets the active entry in the map\n nodeMap.set(from, active)\n }\n\n /**\n * Creates a new active modifier.\n */\n newModifier(\n from: Node,\n modifier: ModifierEntry,\n ): ModifierActiveEntry {\n return {\n modifier,\n interactiveBreadcrumb: modifier.breadcrumb.interactive(),\n originalFrom: from,\n }\n }\n\n /**\n * Removes a previously registered modifier from the active entries.\n */\n deregisterModifier(modifier: ModifierEntry): void {\n for (const { from, name } of modifier.refs) {\n const nodeMap = this.#activeEntries.get(modifier)?.get(name)\n if (nodeMap) {\n // if an entry is found, we remove it from the active set\n const entry = nodeMap.get(from)\n if (entry) {\n this.activeModifiers.delete(entry)\n }\n // then we remove the entry from the map\n nodeMap.delete(from)\n // if the map is empty, we remove it from the active entries map\n if (!nodeMap.size) {\n this.#activeEntries.get(modifier)?.delete(name)\n }\n }\n }\n }\n\n /**\n * Operates in previously registered nodes and edges in order to put\n * back in place any of the original edges that were referenced to in\n * active (ongoing) breadcrumb parsing entries that were never completed.\n *\n * This method can be used to easily rollback any pending operations\n * once the graph traversal is done.\n */\n rollbackActiveEntries(): void {\n for (const modifier of this.activeModifiers) {\n // if the modifier has an original edge, we can put it back in place\n if (modifier.originalEdge) {\n modifier.originalFrom.edgesOut.set(\n modifier.originalEdge.spec.name,\n modifier.originalEdge,\n )\n }\n // then we deregister the modifier\n this.deregisterModifier(modifier.modifier)\n }\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Returns undefined if the project does not have a vlt.json file,\n * otherwise returns the loaded Modifiers instance.\n */\n static maybeLoad(options: SpecOptions) {\n const config = load('modifiers', assertRecordStringString)\n if (!config) return\n return new GraphModifier(options)\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Throws if called on a directory that does not have a vlt.json file.\n */\n static load(options: SpecOptions) {\n return new GraphModifier(options)\n }\n}\n"]}
|
package/dist/esm/node.d.ts
CHANGED
|
@@ -149,6 +149,10 @@ export declare class Node implements NodeLike {
|
|
|
149
149
|
* Sets this node as having a manifest-confused manifest.
|
|
150
150
|
*/
|
|
151
151
|
setConfusedManifest(fixed: Manifest, confused?: Manifest): void;
|
|
152
|
+
/**
|
|
153
|
+
* Sets this node as having a manifest-confused manifest.
|
|
154
|
+
*/
|
|
155
|
+
maybeSetConfusedManifest(spec: Spec, confused?: Manifest): void;
|
|
152
156
|
toJSON(): {
|
|
153
157
|
rawManifest?: Manifest | undefined;
|
|
154
158
|
id: DepID;
|
|
@@ -167,4 +171,6 @@ export declare class Node implements NodeLike {
|
|
|
167
171
|
};
|
|
168
172
|
toString(): string;
|
|
169
173
|
}
|
|
174
|
+
export declare const isNode: (value: unknown) => value is Node;
|
|
175
|
+
export declare const asNode: (value: unknown) => Node;
|
|
170
176
|
//# sourceMappingURL=node.d.ts.map
|
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,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAO7C,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EACV,SAAS,EAC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CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAOxD;;OAEG;IACH,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAYxD,MAAM;;;;;;;;;;;;;;;;IAqBN,QAAQ;CAGT;AAED,eAAO,MAAM,MAAM,UAAW,OAAO,KAAG,KAAK,IAAI,IAQhD,CAAA;AAED,eAAO,MAAM,MAAM,UAAW,OAAO,KAAG,IAKvC,CAAA"}
|
package/dist/esm/node.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isPackageNameConfused, getId, hydrateTuple, splitDepID, } from '@vltpkg/dep-id';
|
|
2
2
|
import { typeError } from '@vltpkg/error-cause';
|
|
3
|
+
import { normalizeManifest } from '@vltpkg/types';
|
|
3
4
|
import { Edge } from "./edge.js";
|
|
4
5
|
import { stringifyNode } from "./stringify-node.js";
|
|
5
6
|
export class Node {
|
|
@@ -189,13 +190,7 @@ export class Node {
|
|
|
189
190
|
this.id = getId(spec, manifest);
|
|
190
191
|
}
|
|
191
192
|
this.graph = options.graph;
|
|
192
|
-
this.manifest = manifest;
|
|
193
|
-
if (isPackageNameConfused(spec, this.manifest?.name)) {
|
|
194
|
-
this.setConfusedManifest({
|
|
195
|
-
...manifest,
|
|
196
|
-
name: spec?.name,
|
|
197
|
-
}, manifest);
|
|
198
|
-
}
|
|
193
|
+
this.manifest = manifest && normalizeManifest(manifest);
|
|
199
194
|
this.#name = name || this.manifest?.name;
|
|
200
195
|
this.version = version || this.manifest?.version;
|
|
201
196
|
if (this.version?.startsWith('v')) {
|
|
@@ -286,6 +281,17 @@ export class Node {
|
|
|
286
281
|
this.confused = true;
|
|
287
282
|
this.#name = this.manifest.name;
|
|
288
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Sets this node as having a manifest-confused manifest.
|
|
286
|
+
*/
|
|
287
|
+
maybeSetConfusedManifest(spec, confused) {
|
|
288
|
+
if (isPackageNameConfused(spec, this.manifest?.name)) {
|
|
289
|
+
this.setConfusedManifest({
|
|
290
|
+
...this.manifest,
|
|
291
|
+
name: spec.name,
|
|
292
|
+
}, confused);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
289
295
|
toJSON() {
|
|
290
296
|
return {
|
|
291
297
|
id: this.id,
|
|
@@ -310,4 +316,17 @@ export class Node {
|
|
|
310
316
|
return stringifyNode(this);
|
|
311
317
|
}
|
|
312
318
|
}
|
|
319
|
+
export const isNode = (value) => {
|
|
320
|
+
return (typeof value === 'object' &&
|
|
321
|
+
value != null &&
|
|
322
|
+
'id' in value &&
|
|
323
|
+
'manifest' in value &&
|
|
324
|
+
value[Symbol.toStringTag] === '@vltpkg/graph.Node');
|
|
325
|
+
};
|
|
326
|
+
export const asNode = (value) => {
|
|
327
|
+
if (!isNode(value)) {
|
|
328
|
+
throw typeError('Expected a node', { found: value });
|
|
329
|
+
}
|
|
330
|
+
return value;
|
|
331
|
+
};
|
|
313
332
|
//# sourceMappingURL=node.js.map
|
package/dist/esm/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AASnD,MAAM,OAAO,IAAI;IACf,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IAED,QAAQ,CAAa;IACrB,SAAS,CAAS;IAClB,YAAY,CAAW;IAEvB,SAAS,GAAG,KAAK,CAAA;IACjB;;;;;;OAMG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,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Y,IAAI,IAAI,CAAC,QAAQ,CAAA;IAC3C,CAAC;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,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'\nimport type { GraphModifier } from './modifiers.ts'\n\nexport type NodeOptions = SpecOptions & {\n projectRoot: string\n graph: GraphLike\n}\n\nexport class Node implements NodeLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Node'\n }\n\n #options: SpecOptions\n #location?: string\n #rawManifest?: 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 * If this node has been modified as part of applying a {@link GraphModifier}\n * then this field will contain the modifier query that was applied.\n * Otherwise, it will be `undefined`.\n */\n modifier: string | undefined\n\n /**\n * The name of the package represented by this node, this is usually\n * equivalent to `manifest.name` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package names instead.\n */\n #name?: string\n get name() {\n if (this.#name) return this.#name\n this.#name = this.id\n return this.#name\n }\n\n /**\n * The version of the package represented by this node, this is usually\n * equivalent to `manifest.version` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package versions instead.\n */\n version?: string\n\n /**\n * An address {@link PackageInfoClient} may use to extract this package.\n */\n resolved?: string\n\n /**\n * 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 modifier: this.modifier,\n ...(this.confused ?\n { rawManifest: this.#rawManifest }\n : undefined),\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,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WA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;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;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE;IACtD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,IAAI,IAAI;QACb,IAAI,IAAI,KAAK;QACb,UAAU,IAAI,KAAK;QAClB,KAAc,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,oBAAoB,CAC7D,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAQ,EAAE;IAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,SAAS,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACtD,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import type { PathScurry } from 'path-scurry'\nimport {\n isPackageNameConfused,\n getId,\n hydrateTuple,\n splitDepID,\n} from '@vltpkg/dep-id'\nimport type { DepID, DepIDTuple } from '@vltpkg/dep-id'\nimport { typeError } from '@vltpkg/error-cause'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type {\n Integrity,\n Manifest,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport { normalizeManifest } 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'\nimport type { GraphModifier } from './modifiers.ts'\n\nexport type NodeOptions = SpecOptions & {\n projectRoot: string\n graph: GraphLike\n}\n\nexport class Node implements NodeLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Node'\n }\n\n #options: SpecOptions\n #location?: string\n #rawManifest?: 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 * If this node has been modified as part of applying a {@link GraphModifier}\n * then this field will contain the modifier query that was applied.\n * Otherwise, it will be `undefined`.\n */\n modifier: string | undefined\n\n /**\n * The name of the package represented by this node, this is usually\n * equivalent to `manifest.name` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package names instead.\n */\n #name?: string\n get name() {\n if (this.#name) return this.#name\n this.#name = this.id\n return this.#name\n }\n\n /**\n * The version of the package represented by this node, this is usually\n * equivalent to `manifest.version` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package versions instead.\n */\n version?: string\n\n /**\n * An address {@link PackageInfoClient} may use to extract this package.\n */\n resolved?: string\n\n /**\n * 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 && normalizeManifest(manifest)\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 /**\n * Sets this node as having a manifest-confused manifest.\n */\n maybeSetConfusedManifest(spec: Spec, confused?: Manifest) {\n if (isPackageNameConfused(spec, this.manifest?.name)) {\n this.setConfusedManifest(\n {\n ...this.manifest,\n name: spec.name,\n },\n confused,\n )\n }\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n version: this.version,\n location: this.location,\n importer: this.importer,\n manifest: this.manifest,\n projectRoot: this.projectRoot,\n integrity: this.integrity,\n resolved: this.resolved,\n dev: this.dev,\n optional: this.optional,\n confused: this.confused,\n modifier: this.modifier,\n ...(this.confused ?\n { rawManifest: this.#rawManifest }\n : undefined),\n }\n }\n\n toString() {\n return stringifyNode(this)\n }\n}\n\nexport const isNode = (value: unknown): value is Node => {\n return (\n typeof value === 'object' &&\n value != null &&\n 'id' in value &&\n 'manifest' in value &&\n (value as Node)[Symbol.toStringTag] === '@vltpkg/graph.Node'\n )\n}\n\nexport const asNode = (value: unknown): Node => {\n if (!isNode(value)) {\n throw typeError('Expected a node', { found: value })\n }\n return value\n}\n"]}
|
package/dist/esm/reify/build.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// at the end, we get back to the importers, and run their prepare
|
|
3
3
|
// script as well as install script.
|
|
4
4
|
import { run } from '@vltpkg/run';
|
|
5
|
-
import { statSync } from 'node:fs';
|
|
5
|
+
import { statSync, existsSync } from 'node:fs';
|
|
6
6
|
import { chmod } from 'node:fs/promises';
|
|
7
7
|
import { graphRun } from 'graph-run';
|
|
8
8
|
import { nonEmptyList } from "../non-empty-list.js";
|
|
@@ -73,7 +73,10 @@ const visit = async (packageJson, scurry, node, signal, _path) => {
|
|
|
73
73
|
const chmods = [];
|
|
74
74
|
for (const bin of Object.values(binPaths(manifest))) {
|
|
75
75
|
const path = scurry.resolve(`${node.resolvedLocation(scurry)}/${bin}`);
|
|
76
|
-
|
|
76
|
+
// only try to make executable if the file exists
|
|
77
|
+
if (existsSync(path)) {
|
|
78
|
+
chmods.push(makeExecutable(path));
|
|
79
|
+
}
|
|
77
80
|
}
|
|
78
81
|
await Promise.all(chmods);
|
|
79
82
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAClE,oCAAoC;AAGpC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAClE,oCAAoC;AAGpC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAIpC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,IAAU,EACV,WAAwB,EACxB,MAAkB,EAClB,EAAE;IACF,MAAM,KAAK,GAAG,IAAI,CA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,CAAC,OAAO,CACzB,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,CAC1C,CAAA;QACD,iDAAiD;QACjD,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED,qBAAqB;AACrB,4DAA4D;AAC5D,oEAAoE;AACpE,IAAI,QAAQ,GAAG,CAAC,CAAA;AAChB,MAAM,cAAc,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAA;IAClD,CAAC;IACD,MAAM,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["// walk the graph of added nodes, building and chmoding their bins\n// at the end, we get back to the importers, and run their prepare\n// script as well as install script.\n\nimport type { PackageJson } from '@vltpkg/package-json'\nimport { run } from '@vltpkg/run'\nimport { statSync, existsSync } from 'node:fs'\nimport { chmod } from 'node:fs/promises'\nimport { graphRun } from 'graph-run'\nimport type { PathScurry } from 'path-scurry'\nimport type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\nimport { nonEmptyList } from '../non-empty-list.ts'\nimport { binPaths } from './bin-paths.ts'\nimport { optionalFail } from './optional-fail.ts'\n\nexport const build = async (\n diff: Diff,\n packageJson: PackageJson,\n scurry: PathScurry,\n) => {\n const graph = diff.to\n const nodes = nonEmptyList([...graph.importers])\n /* c8 ignore next - all graphs have at least one importer */\n if (!nodes) return\n\n await graphRun<Node, unknown>({\n graph: nodes,\n visit: async (node: Node, signal, path) => {\n // if it's not an importer or an added node, nothing to do.\n // TODO: only build importers if it has changed deps, there's never\n // been a previous build, or it contains something newer than the\n // most recent build.\n // For now, just always build all importers, because we don't\n // track all that other stuff.\n if (!node.importer && !diff.nodes.add.has(node)) return\n\n await visit(packageJson, scurry, node, signal, path).then(\n x => x,\n optionalFail(diff, node),\n )\n },\n\n getDeps: node => {\n const deps: Node[] = []\n for (const { to } of node.edgesOut.values()) {\n /* c8 ignore next - vanishingly unlikely in practice */\n if (to) deps.push(to)\n }\n return deps\n },\n })\n}\n\nconst visit = async (\n packageJson: PackageJson,\n scurry: PathScurry,\n node: Node,\n signal: AbortSignal,\n _path: Node[],\n): Promise<void> => {\n node.manifest ??= packageJson.read(node.resolvedLocation(scurry))\n const { manifest } = node\n const { scripts = {} } = manifest\n\n const {\n install,\n preinstall,\n postinstall,\n prepare,\n preprepare,\n postprepare,\n } = scripts\n\n // if it has install script, run it\n const runInstall = !!(install || preinstall || postinstall)\n if (runInstall) {\n await run({\n signal,\n arg0: 'install',\n ignoreMissing: true,\n packageJson,\n cwd: node.resolvedLocation(scurry),\n projectRoot: node.projectRoot,\n manifest,\n })\n }\n\n // if it's an importer or git, run prepare\n const prepable =\n node.id.startsWith('git') || node.importer || !node.inVltStore()\n const runPrepare =\n !!(prepare || preprepare || postprepare) && prepable\n\n if (runPrepare) {\n await run({\n signal,\n arg0: 'prepare',\n ignoreMissing: true,\n packageJson,\n cwd: node.resolvedLocation(scurry),\n projectRoot: node.projectRoot,\n manifest,\n })\n }\n\n const chmods: Promise<unknown>[] = []\n for (const bin of Object.values(binPaths(manifest))) {\n const path = scurry.resolve(\n `${node.resolvedLocation(scurry)}/${bin}`,\n )\n // only try to make executable if the file exists\n if (existsSync(path)) {\n chmods.push(makeExecutable(path))\n }\n }\n await Promise.all(chmods)\n}\n\n// 0 is \"not yet set\"\n// This is defined by doing `0o111 | <mode>` so that systems\n// that create files group-writable result in 0o775 instead of 0o755\nlet execMode = 0\nconst makeExecutable = async (path: string) => {\n if (!execMode) {\n execMode = (statSync(path).mode & 0o777) | 0o111\n }\n await chmod(path, execMode)\n}\n"]}
|
|
@@ -3,12 +3,14 @@ import type { LoadOptions } from '../actual/load.ts';
|
|
|
3
3
|
import type { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '../dependencies.ts';
|
|
4
4
|
import { Diff } from '../diff.ts';
|
|
5
5
|
import type { Graph } from '../graph.ts';
|
|
6
|
+
import type { GraphModifier } from '../modifiers.ts';
|
|
6
7
|
export type ReifyOptions = LoadOptions & {
|
|
7
8
|
add?: AddImportersDependenciesMap;
|
|
8
9
|
remove?: RemoveImportersDependenciesMap;
|
|
9
10
|
graph: Graph;
|
|
10
11
|
actual?: Graph;
|
|
11
12
|
packageInfo: PackageInfoClient;
|
|
13
|
+
modifiers?: GraphModifier;
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
16
|
* Make the current project match the supplied graph.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reify/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAI7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EACV,2BAA2B,EAC3B,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reify/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAI7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EACV,2BAA2B,EAC3B,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAqBpD,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACvC,GAAG,CAAC,EAAE,2BAA2B,CAAA;IACjC,MAAM,CAAC,EAAE,8BAA8B,CAAA;IACvC,KAAK,EAAE,KAAK,CAAA;IACZ,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,WAAW,EAAE,iBAAiB,CAAA;IAC9B,SAAS,CAAC,EAAE,aAAa,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,YAAmB,YAAY,kBA8BhD,CAAA"}
|
package/dist/esm/reify/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { deleteNodes } from "./delete-nodes.js";
|
|
|
14
14
|
import { internalHoist } from "./internal-hoist.js";
|
|
15
15
|
import { rollback } from "./rollback.js";
|
|
16
16
|
import { updatePackageJson } from "./update-importers-package-json.js";
|
|
17
|
+
import { copyFileSync } from 'node:fs';
|
|
17
18
|
const limit = Math.max(availableParallelism() - 1, 1) * 8;
|
|
18
19
|
/**
|
|
19
20
|
* Make the current project match the supplied graph.
|
|
@@ -89,5 +90,9 @@ const reify_ = async (options, diff, remover) => {
|
|
|
89
90
|
saveImportersPackageJson?.();
|
|
90
91
|
// write the ideal graph data to the lockfile
|
|
91
92
|
saveData(lfData, scurry.resolve('vlt-lock.json'), false);
|
|
93
|
+
// update the store config reference if a config file was used
|
|
94
|
+
if (scurry.lstatSync('vlt.json')) {
|
|
95
|
+
copyFileSync(scurry.resolve('vlt.json'), scurry.resolve('node_modules/.vlt/vlt.json'));
|
|
96
|
+
}
|
|
92
97
|
};
|
|
93
98
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reify/index.ts"],"names":[],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K,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;IACD,UAAU,CAAC,OAAO,CAAC,CAAA;IAEnB,iCAAiC;IACjC,MAAM,SAAS,GAAuB,WAAW,CAC/C,IAAI,EACJ,OAAO,EACP,MAAM,CACP,CAAA;IACD,IAAI,SAAS,CAAC,MAAM;QAAE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IAElD,6DAA6D;IAC7D,wBAAwB,EAAE,EAAE,CAAA;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;IAExD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,YAAY,CACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAC7C,CAAA;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { graphStep } from '@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport { lockfile } from '../index.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (options: ReifyOptions) => {\n const done = graphStep('reify')\n\n const { graph, scurry } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const remover = new RollbackRemove()\n let success = false\n try {\n await reify_(options, diff, remover)\n remover.confirm()\n success = true\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return diff\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n) => {\n const { add, remove, packageInfo, packageJson, scurry } = options\n const saveImportersPackageJson =\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions: Promise<unknown>[] = addEdges(\n diff,\n packageJson,\n scurry,\n remover,\n )\n if (edgeActions.length) await Promise.all(edgeActions)\n\n await internalHoist(diff.to, options, remover)\n\n // run lifecycles and chmod bins\n await build(diff, packageJson, scurry)\n\n // save the lockfile\n lockfile.save(options)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n}\n"]}
|
|
@@ -88,7 +88,7 @@ const addOrRemoveDeps = (importerId, graph, addOrRemove) => {
|
|
|
88
88
|
const existing = dependencies[name];
|
|
89
89
|
const saveValue = calculateSaveValue(nodeType, dep.spec, existing, node.version);
|
|
90
90
|
dependencies[name] = saveValue;
|
|
91
|
-
manifestChanged = saveValue !== existing;
|
|
91
|
+
manifestChanged = manifestChanged || saveValue !== existing;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
return manifestChanged ? manifest : undefined;
|
|
@@ -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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AAiB,GAAG,IAAI,GAAG,EAAY,CAAA;IAC7C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;IAEzC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,EAAE,CAAC;YACd,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC1C,MAAM,QAAQ,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;gBAC9D,IAAI,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 Manifest,\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 importerId: DepID,\n graph: Graph,\n addOrRemove?:\n | AddImportersDependenciesMap\n | RemoveImportersDependenciesMap,\n): Manifest | undefined => {\n const importer = graph.nodes.get(importerId)\n if (!importer) {\n throw error('Failed to retrieve importer node', {\n found: importerId,\n })\n }\n const manifest = importer.manifest\n if (!manifest) {\n throw error('Could not find manifest data for node', {\n found: importerId,\n })\n }\n const deps = addOrRemove?.get(importerId)\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(importer, 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 node = importer.edgesOut.get(name)?.to\n if (!node) {\n throw error('Dependency node could not be found')\n }\n const [nodeType] = splitDepID(node.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 = saveValue !== existing\n }\n }\n return manifestChanged ? manifest : undefined\n}\n\n/**\n * Updates the importers 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<Manifest>()\n const operations = new Set([add, remove])\n\n for (const operation of operations) {\n if (operation) {\n for (const importerId of operation.keys()) {\n const manifest = addOrRemoveDeps(importerId, 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,OA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G,CAAC,EAChC,GAAG,EACH,KAAK,EACL,WAAW,EACX,MAAM,GACmB,EAAE,EAAE;IAC7B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAY,CAAA;IAC7C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;IAEzC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,EAAE,CAAC;YACd,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC1C,MAAM,QAAQ,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;gBAC9D,IAAI,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 Manifest,\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 importerId: DepID,\n graph: Graph,\n addOrRemove?:\n | AddImportersDependenciesMap\n | RemoveImportersDependenciesMap,\n): Manifest | undefined => {\n const importer = graph.nodes.get(importerId)\n if (!importer) {\n throw error('Failed to retrieve importer node', {\n found: importerId,\n })\n }\n const manifest = importer.manifest\n if (!manifest) {\n throw error('Could not find manifest data for node', {\n found: importerId,\n })\n }\n const deps = addOrRemove?.get(importerId)\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(importer, 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 node = importer.edgesOut.get(name)?.to\n if (!node) {\n throw error('Dependency node could not be found')\n }\n const [nodeType] = splitDepID(node.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 the importers 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<Manifest>()\n const operations = new Set([add, remove])\n\n for (const operation of operations) {\n if (operation) {\n for (const importerId of operation.keys()) {\n const manifest = addOrRemoveDeps(importerId, 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"]}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type GraphLike = {
|
|
|
15
15
|
mainImporter: NodeLike;
|
|
16
16
|
projectRoot: string;
|
|
17
17
|
nodes: Map<DepID, NodeLike>;
|
|
18
|
+
nodesByName: Map<string, Set<NodeLike>>;
|
|
18
19
|
edges: Set<EdgeLike>;
|
|
19
20
|
addEdge: (type: DependencyTypeShort, spec: Spec, from: NodeLike, to?: NodeLike) => EdgeLike;
|
|
20
21
|
addNode: (id?: DepID, manifest?: Manifest, spec?: Spec, name?: string, version?: string) => NodeLike;
|
|
@@ -37,11 +38,14 @@ export type NodeLike = {
|
|
|
37
38
|
projectRoot: string;
|
|
38
39
|
dev: boolean;
|
|
39
40
|
optional: boolean;
|
|
41
|
+
modifier?: string | undefined;
|
|
42
|
+
registry?: string;
|
|
40
43
|
toJSON: () => Pick<NodeLike, 'id' | 'name' | 'version' | 'location' | 'importer' | 'manifest' | 'projectRoot' | 'integrity' | 'resolved' | 'dev' | 'optional' | 'confused'> & {
|
|
41
44
|
rawManifest?: NodeLike['manifest'];
|
|
42
45
|
};
|
|
43
46
|
toString(): string;
|
|
44
47
|
setResolved(): void;
|
|
45
48
|
setConfusedManifest(fixed: Manifest, confused?: Manifest): void;
|
|
49
|
+
maybeSetConfusedManifest(spec: Spec, confused?: Manifest): void;
|
|
46
50
|
};
|
|
47
51
|
//# 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,CA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E,SAAS,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,OAAO,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,CAAC,EAAE,MAAM,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;IAC/D,wBAAwB,CAAC,IAAI,EAAE,IAAI,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 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
|
+
{"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 nodesByName: Map<string, Set<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 modifier?: string | undefined\n registry?: string\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 maybeSetConfusedManifest(spec: Spec, 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;AAkBrD,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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BAAwB,EACjC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,UAiHjC"}
|
|
@@ -114,12 +114,15 @@ export function humanReadableOutput(options, { colors }) {
|
|
|
114
114
|
`${nodeName}@${nextItem.node.version}`
|
|
115
115
|
: nodeName;
|
|
116
116
|
const nextChar = isLast ? 'last-child' : 'middle-child';
|
|
117
|
+
const aliasedPackage = nextItem.node?.name && nextItem.edge?.name !== nodeName;
|
|
117
118
|
nextItem.name =
|
|
118
119
|
nextItem.node?.confused ?
|
|
119
120
|
`${nextItem.edge?.name} ${red('(confused)')}`
|
|
120
|
-
: nextItem.
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
: nextItem.edge?.spec.overridden ?
|
|
122
|
+
/* c8 ignore next */
|
|
123
|
+
`${nextItem.edge.name}@${nextItem.node?.version || nextItem.edge.spec.bareSpec}${aliasedPackage ? ` (${toName})` : ''} ${yellow('(overridden)')}`
|
|
124
|
+
: aliasedPackage ? `${nextItem.edge?.name} (${toName})`
|
|
125
|
+
: `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`;
|
|
123
126
|
nextItem.padding =
|
|
124
127
|
parent.prefix.length ?
|
|
125
128
|
`${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `
|