@vltpkg/graph 1.0.0-rc.11 → 1.0.0-rc.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ideal/peers.d.ts.map +1 -1
- package/dist/ideal/peers.js +23 -2
- package/dist/ideal/peers.js.map +1 -1
- package/dist/reify/build.d.ts.map +1 -1
- package/dist/reify/build.js +11 -2
- package/dist/reify/build.js.map +1 -1
- package/dist/reify/check-needed-build.d.ts +5 -0
- package/dist/reify/check-needed-build.d.ts.map +1 -1
- package/dist/reify/check-needed-build.js +16 -5
- package/dist/reify/check-needed-build.js.map +1 -1
- package/dist/reify/index.js +1 -1
- package/dist/reify/index.js.map +1 -1
- package/package.json +22 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peers.d.ts","sourceRoot":"","sources":["../../src/ideal/peers.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC;;GAEG;AACH,eAAO,MAAM,uBAAuB,gBACrB,WAAW,GAAG,SAAS,KACnC,MAAM,GAAG,SAKX,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,SACtB,IAAI,SACH,gBAAgB,KACtB,OAkBF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4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E,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC;;GAEG;AACH,eAAO,MAAM,uBAAuB,gBACrB,WAAW,GAAG,SAAS,KACnC,MAAM,GAAG,SAKX,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,SACtB,IAAI,SACH,gBAAgB,KACtB,OAkBF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4B,YAC9B,qBAAqB,EAAE,KAC/B,qBAAqB,EAUpB,CAAA;AAQJ,eAAO,MAAM,yBAAyB,gBACvB,WAAW,WACf,qBAAqB,EAAE,KAC/B,OAgBF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,gBACrB,WAAW,WACf,qBAAqB,EAAE,YACtB,IAAI,aACH,QAAQ,KAClB,OAsEF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,UACnB,KAAK,eACC,WAAW,WACf,qBAAqB,EAAE,KAC/B,WAqCF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,gBAChB,WAAW,YACd,QAAQ,YACR,IAAI,WACL,WAAW;;;CA4CrB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,gBACd,WAAW,YACd,UAAU,EAAE,gBACR,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,SAChD,KAAK,QACN,IAAI,YACA,IAAI,QACR,IAAI,QACJ,kBAAkB,iBACT,qBAAqB,EAAE;IAEtC;;OAEG;;;;;;IA2CH;;;OAGG;;CAyEH,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,UAC1B,KAAK,sBACQ,sBAAsB,EAAE,SAiE7C,CAAA"}
|
package/dist/ideal/peers.js
CHANGED
|
@@ -265,7 +265,22 @@ export const endPeerPlacement = (peerContext, nextDeps, nextPeerDeps, graph, spe
|
|
|
265
265
|
for (const nextDep of nextPeerDeps.values()) {
|
|
266
266
|
const { spec, type } = nextDep;
|
|
267
267
|
if (type === 'peer' || type === 'peerOptional') {
|
|
268
|
-
//
|
|
268
|
+
// FIRST: Check if there's a sibling dependency from the parent
|
|
269
|
+
// that specifies this same package. Sibling deps take priority
|
|
270
|
+
// because they represent the workspace's direct dependency,
|
|
271
|
+
// which should be preferred over versions from other workspaces
|
|
272
|
+
// that may have been added to the peer context earlier.
|
|
273
|
+
const siblingEntry = queuedEntries.find(e => (e.target?.name ?? e.spec.final.name) === spec.final.name);
|
|
274
|
+
if (siblingEntry?.target &&
|
|
275
|
+
!node.edgesOut.has(spec.final.name) &&
|
|
276
|
+
satisfies(siblingEntry.target.id, spec, fromNode.location, fromNode.projectRoot, graph.monorepo)) {
|
|
277
|
+
// The sibling's resolved target satisfies the peer spec,
|
|
278
|
+
// use it directly - this prioritizes the workspace's own
|
|
279
|
+
// direct dependency over versions from other workspaces
|
|
280
|
+
graph.addEdge(type, spec, node, siblingEntry.target);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
// THEN: Try to retrieve an entry for that peer dep from
|
|
269
284
|
// the current peer context set
|
|
270
285
|
const entry = peerContext.get(spec.final.name);
|
|
271
286
|
if (!node.edgesOut.has(spec.final.name) &&
|
|
@@ -280,8 +295,14 @@ export const endPeerPlacement = (peerContext, nextDeps, nextPeerDeps, graph, spe
|
|
|
280
295
|
// just create a dangling edge
|
|
281
296
|
graph.addEdge(type, spec, node);
|
|
282
297
|
}
|
|
298
|
+
else if (siblingEntry &&
|
|
299
|
+
siblingEntry.spec.bareSpec !== spec.bareSpec) {
|
|
300
|
+
// Sibling has a more specific spec for this package,
|
|
301
|
+
// use it when resolving to ensure we get the right version
|
|
302
|
+
nextDeps.push({ ...nextDep, spec: siblingEntry.spec });
|
|
303
|
+
}
|
|
283
304
|
else {
|
|
284
|
-
// could not satisfy from peer context, add to next deps
|
|
305
|
+
// could not satisfy from peer context or sibling, add to next deps
|
|
285
306
|
nextDeps.push(nextDep);
|
|
286
307
|
}
|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W,GAAG,WAAW,CAAA;gBAClC,SAAQ;YACV,CAAC;YACD,QAAQ,CAAC,WAAW,GAAG,eAAe,CACpC,KAAK,EACL,QAAQ,CAAC,WAAW,EACpB,WAAW,CACZ,CAAA;YACD,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAA;QACpC,CAAC;QACD,4CAA4C;QAC5C,8BAA8B;QAC9B,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;YACvC,QAAQ,CAAC,aAAa,CAAC,eAAe,EAAE,CAAA;YACxC,QAAQ,CAAC,IAAI,GAAG,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["// helpers for managing peer dependency resolution\n// during the ideal graph building process.\n\nimport { intersects } from '@vltpkg/semver'\nimport { satisfies } from '@vltpkg/satisfies'\nimport { getDependencies } from '../dependencies.ts'\nimport { getOrderedDependencies } from './get-ordered-dependencies.ts'\nimport type {\n ProcessPlacementResultEntry,\n PeerContext,\n PeerContextEntry,\n PeerContextEntryInput,\n ProcessPlacementResult,\n} from './types.ts'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type { DependencySaveType, Manifest } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\n\n/**\n * Retrieve a unique hash value for a given peer context set.\n */\nexport const retrievePeerContextHash = (\n peerContext: PeerContext | undefined,\n): string | undefined => {\n // skips creating the initial peer context ref\n if (!peerContext?.index) return undefined\n\n return `ṗ:${peerContext.index}`\n}\n\n/**\n * Checks if a given spec is compatible with the specs already\n * assigned to a peer context entry.\n *\n * Returns true if compatible, false otherwise.\n */\nexport const incompatibleSpecs = (\n spec: Spec,\n entry: PeerContextEntry,\n): boolean => {\n if (entry.specs.size > 0) {\n for (const s of entry.specs) {\n if (\n // only able to check range intersections for registry types\n (spec.type === 'registry' &&\n (!spec.range ||\n !s.range ||\n !intersects(spec.range, s.range))) ||\n // also support types other than registry in case\n // they use the very same bareSpec value\n (spec.type !== 'registry' && spec.bareSpec !== s.bareSpec)\n ) {\n return true\n }\n }\n }\n return false\n}\n\n/**\n * Sort peer context entry inputs for deterministic processing.\n * Orders: non-peer dependencies first, then peer dependencies, alphabetically by name.\n */\nexport const getOrderedPeerContextEntries = (\n entries: PeerContextEntryInput[],\n): PeerContextEntryInput[] =>\n [...entries].sort((a, b) => {\n const aIsPeer =\n a.type === 'peer' || a.type === 'peerOptional' ? 1 : 0\n const bIsPeer =\n b.type === 'peer' || b.type === 'peerOptional' ? 1 : 0\n if (aIsPeer !== bIsPeer) return aIsPeer - bIsPeer\n const aName = a.target?.name ?? a.spec.name\n const bName = b.target?.name ?? b.spec.name\n return aName.localeCompare(bName, 'en')\n })\n\n/*\n * Checks if there are any conflicting versions for a given dependency\n * to be added to a peer context set which will require forking.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const checkEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): boolean => {\n // check on compatibility of new entries\n for (const { spec, target } of entries) {\n const name = target?.name ?? spec.final.name\n\n // skip any inactive entry\n const entry = peerContext.get(name)\n if (!entry?.active) continue\n\n // validate if the provided spec is compatible with existing specs\n if (incompatibleSpecs(spec, entry)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Add or update dependencies in a given peer context making sure to check\n * for compatibility with existing dependencies already resolved by a given\n * peer context set. Extra info such as a target or dependent nodes is\n * optional.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const addEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n fromNode: Node,\n monorepo?: Monorepo,\n): boolean => {\n // pre check to see if any of the new entries to be added to the\n // provided peer context set conflicts with existing ones\n // if that's already the case we can skip processing them and\n // will return that a fork is needed right away\n if (checkEntriesToPeerContext(peerContext, entries)) return true\n\n // iterate on every entry to be added to the peer context set\n for (const { dependent, spec, target, type } of entries) {\n const name = target?.name ?? spec.final.name\n\n // if there's no existing entry, create one\n let entry = peerContext.get(name)\n if (!entry) {\n entry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents: new Set(),\n }\n peerContext.set(name, entry)\n if (dependent) entry.contextDependents.add(dependent)\n continue\n }\n\n // perform an extra check that confirms the new spec does not\n // conflicts with existing specs in this entry, this handles the\n // case of adding sibling deps that conflicts with one another\n if (incompatibleSpecs(spec, entry)) return true\n\n if (\n target &&\n [...entry.specs].every(s =>\n satisfies(\n target.id,\n s,\n fromNode.location,\n fromNode.projectRoot,\n monorepo,\n ),\n )\n ) {\n if (\n target.id !== entry.target?.id &&\n target.version !== entry.target?.version\n ) {\n // we have a compatible entry that has a new, compatible target\n // so we need to update all dependents to point to the new target\n for (const dependents of entry.contextDependents) {\n const edge = dependents.edgesOut.get(name)\n if (edge?.to && edge.to !== target) {\n edge.to.edgesIn.delete(edge)\n edge.to = target\n target.edgesIn.add(edge)\n }\n }\n entry.target = target\n }\n\n // otherwise sets the value in case it was nullish\n entry.target ??= target\n }\n\n // update specs and dependents values\n entry.specs.add(spec)\n if (dependent) entry.contextDependents.add(dependent)\n }\n\n return false\n}\n\n/**\n * Create and returns a forked copy of a given peer context set.\n */\nexport const forkPeerContext = (\n graph: Graph,\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): PeerContext => {\n // create a new peer context set\n const nextPeerContext: PeerContext = new Map()\n nextPeerContext.index = graph.nextPeerContextIndex()\n // register it in the graph\n graph.peerContexts[nextPeerContext.index] = nextPeerContext\n\n // copy existing entries marking them as inactive, it's also important\n // to note that specs and contextDependents are new objects so that changes\n // to those in the new context do not affect the previous one\n for (const [name, entry] of peerContext.entries()) {\n nextPeerContext.set(name, {\n active: false,\n specs: new Set(entry.specs),\n target: undefined,\n type: entry.type,\n contextDependents: new Set(entry.contextDependents),\n })\n }\n\n // add the new entries to this peer context set, marking them as active\n // these are the entries that were incompatible with the previous context set\n for (const entry of entries) {\n const { dependent, spec, target, type } = entry\n const name = target?.name /* c8 ignore next */ ?? spec.final.name\n const newEntry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents:\n dependent ? new Set([dependent]) : new Set<Node>(),\n }\n nextPeerContext.set(name, newEntry)\n }\n\n return nextPeerContext\n}\n\n/**\n * Starts the peer dependency placement process\n * for a given node being processed and placed.\n */\nexport const startPeerPlacement = (\n peerContext: PeerContext,\n manifest: Manifest,\n fromNode: Node,\n options: SpecOptions,\n) => {\n // queue entries so that they can be added at the end of the placement\n // process, use a map to ensure deduplication between read json dep\n // values and the resolved edges in the graph\n const queueMap = new Map<string, PeerContextEntryInput>()\n let peerSetHash: string | undefined\n\n if (\n manifest.peerDependencies &&\n Object.keys(manifest.peerDependencies).length > 0\n ) {\n // generates a peer context set hash for nodes that\n // have peer dependencies to be resolved\n peerSetHash = retrievePeerContextHash(peerContext)\n\n // get any potential sibling dependency from the\n // parent node that might have not been parsed yet\n const siblingDeps = getDependencies(fromNode, {\n ...options,\n registry: fromNode.registry,\n })\n for (const [depName, dep] of siblingDeps) {\n queueMap.set(depName, dep)\n }\n\n // collect the already parsed nodes and add those to the\n // list of entries to be added to the peer context set\n for (const edge of fromNode.edgesOut.values()) {\n queueMap.set(edge.name, {\n spec: edge.spec,\n target: edge.to,\n type: edge.type,\n })\n }\n }\n\n return {\n peerSetHash,\n // Sort queuedEntries for deterministic order\n queuedEntries: getOrderedPeerContextEntries([\n ...queueMap.values(),\n ]),\n }\n}\n\n/**\n * Ends the peer dependency placement process, returning the functions that\n * are going to be used to update the peer context set, forking when needed\n * and resolving peer dependencies if possible.\n */\nexport const endPeerPlacement = (\n peerContext: PeerContext,\n nextDeps: Dependency[],\n nextPeerDeps: Map<string, Dependency> & { id?: number },\n graph: Graph,\n spec: Spec,\n fromNode: Node,\n node: Node,\n type: DependencySaveType,\n queuedEntries: PeerContextEntryInput[],\n) => ({\n /**\n * Add the new entries to the current peer context set.\n */\n putEntries: () => {\n // keep track of whether we need to fork the current peer context set\n let needsToForkPeerContext = false\n // add queued entries from this node parents along\n // with a self-ref to the current peer context set\n const prevEntries = [\n ...queuedEntries,\n /* ref itself */ {\n spec,\n target: node,\n type,\n },\n ]\n addEntriesToPeerContext(\n peerContext,\n prevEntries,\n fromNode,\n graph.monorepo,\n )\n\n // add this node's direct dependencies next\n const nextEntries = [\n ...nextDeps.map(dep => ({ ...dep, dependent: node })),\n ...[...nextPeerDeps.values()].map(dep => ({\n ...dep,\n dependent: node,\n })),\n ]\n if (nextEntries.length > 0) {\n needsToForkPeerContext = addEntriesToPeerContext(\n peerContext,\n nextEntries,\n node,\n graph.monorepo,\n )\n }\n\n // returns all entries that need to be added to a forked\n // context or undefined if the current context was updated directly\n return needsToForkPeerContext ? nextEntries : undefined\n },\n\n /**\n * Try to resolve peer dependencies using already seen target\n * values from the current peer context set.\n */\n resolvePeerDeps: () => {\n // iterate on the set of peer dependencies of the current node\n // and try to resolve them from the existing peer context set,\n // when possible, add them as edges in the graph right away, if not,\n // then we move them back to the `nextDeps` list for processing\n // along with the rest of the regular dependencies\n for (const nextDep of nextPeerDeps.values()) {\n const { spec, type } = nextDep\n if (type === 'peer' || type === 'peerOptional') {\n // try to retrieve an entry for that peer dep from\n // the current peer context set\n const entry = peerContext.get(spec.final.name)\n if (\n !node.edgesOut.has(spec.final.name) &&\n entry?.target &&\n satisfies(\n entry.target.id,\n spec,\n fromNode.location,\n fromNode.projectRoot,\n graph.monorepo,\n )\n ) {\n // entry satisfied, create edge in the graph\n graph.addEdge(type, spec, node, entry.target)\n entry.specs.add(spec.final)\n } else if (type === 'peerOptional') {\n // skip unsatisfied peerOptional dependencies,\n // just create a dangling edge\n graph.addEdge(type, spec, node)\n } else {\n // could not satisfy from peer context, add to next deps\n nextDeps.push(nextDep)\n }\n }\n }\n },\n})\n\n/**\n * Given an array of processed results for the current level dependencies\n * being placed in the currently building ideal graph, traverse its direct\n * dependencies and track peer dependencies in their appropriate peer context\n * sets, forking as needed and resolving peer dependencies using suitable\n * nodes already present in the graph if possible.\n */\nexport const postPlacementPeerCheck = (\n graph: Graph,\n sortedLevelResults: ProcessPlacementResult[],\n) => {\n // Update peer contexts in a sorted manner after processing all nodes\n // at a given level to ensure deterministic behavior when it comes to\n // forking new peer contexts\n for (const childDepsToProcess of sortedLevelResults) {\n // Sort childDepsToProcess deterministically by node.id\n const sortedChildDeps = [...childDepsToProcess].sort((a, b) =>\n a.node.id.localeCompare(b.node.id, 'en'),\n )\n\n const needsForking = new Map<\n ProcessPlacementResultEntry,\n {\n dependent: Node\n spec: Spec\n type: DependencySaveType\n }[]\n >()\n // first iterate on all child deps, adding entries to the current\n // context and collect the information on which ones need forking\n for (const childDep of sortedChildDeps) {\n const needsFork = childDep.updateContext.putEntries()\n if (needsFork) {\n needsForking.set(childDep, needsFork)\n }\n }\n\n // Sort needsForking entries before iterating (Map iteration order = insertion order)\n const sortedNeedsForkingEntries = [\n ...needsForking.entries(),\n ].sort(([a], [b]) => a.node.id.localeCompare(b.node.id, 'en'))\n\n // then iterate again, forking contexts as needed but also try to\n // reuse the context of the previous sibling if possible\n let prevContext\n for (const [childDep, nextEntries] of sortedNeedsForkingEntries) {\n if (\n prevContext &&\n !checkEntriesToPeerContext(prevContext, nextEntries)\n ) {\n // the context of the previous sibling can be reused\n addEntriesToPeerContext(\n prevContext,\n nextEntries,\n childDep.node,\n graph.monorepo,\n )\n childDep.peerContext = prevContext\n continue\n }\n childDep.peerContext = forkPeerContext(\n graph,\n childDep.peerContext,\n nextEntries,\n )\n prevContext = childDep.peerContext\n }\n // try to resolve peer dependencies now that\n // the context is fully set up\n for (const childDep of sortedChildDeps) {\n childDep.updateContext.resolvePeerDeps()\n childDep.deps = getOrderedDependencies(childDep.deps)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"peers.js","sourceRoot":"","sources":["../../src/ideal/peers.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,2CAA2C;AAE3C,OAAO,EAAE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ourcesContent":["// helpers for managing peer dependency resolution\n// during the ideal graph building process.\n\nimport { intersects } from '@vltpkg/semver'\nimport { satisfies } from '@vltpkg/satisfies'\nimport { getDependencies } from '../dependencies.ts'\nimport { getOrderedDependencies } from './get-ordered-dependencies.ts'\nimport type {\n ProcessPlacementResultEntry,\n PeerContext,\n PeerContextEntry,\n PeerContextEntryInput,\n ProcessPlacementResult,\n} from './types.ts'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type { DependencySaveType, Manifest } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\n\n/**\n * Retrieve a unique hash value for a given peer context set.\n */\nexport const retrievePeerContextHash = (\n peerContext: PeerContext | undefined,\n): string | undefined => {\n // skips creating the initial peer context ref\n if (!peerContext?.index) return undefined\n\n return `ṗ:${peerContext.index}`\n}\n\n/**\n * Checks if a given spec is compatible with the specs already\n * assigned to a peer context entry.\n *\n * Returns true if compatible, false otherwise.\n */\nexport const incompatibleSpecs = (\n spec: Spec,\n entry: PeerContextEntry,\n): boolean => {\n if (entry.specs.size > 0) {\n for (const s of entry.specs) {\n if (\n // only able to check range intersections for registry types\n (spec.type === 'registry' &&\n (!spec.range ||\n !s.range ||\n !intersects(spec.range, s.range))) ||\n // also support types other than registry in case\n // they use the very same bareSpec value\n (spec.type !== 'registry' && spec.bareSpec !== s.bareSpec)\n ) {\n return true\n }\n }\n }\n return false\n}\n\n/**\n * Sort peer context entry inputs for deterministic processing.\n * Orders: non-peer dependencies first, then peer dependencies, alphabetically by name.\n */\nexport const getOrderedPeerContextEntries = (\n entries: PeerContextEntryInput[],\n): PeerContextEntryInput[] =>\n [...entries].sort((a, b) => {\n const aIsPeer =\n a.type === 'peer' || a.type === 'peerOptional' ? 1 : 0\n const bIsPeer =\n b.type === 'peer' || b.type === 'peerOptional' ? 1 : 0\n if (aIsPeer !== bIsPeer) return aIsPeer - bIsPeer\n const aName = a.target?.name ?? a.spec.name\n const bName = b.target?.name ?? b.spec.name\n return aName.localeCompare(bName, 'en')\n })\n\n/*\n * Checks if there are any conflicting versions for a given dependency\n * to be added to a peer context set which will require forking.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const checkEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): boolean => {\n // check on compatibility of new entries\n for (const { spec, target } of entries) {\n const name = target?.name ?? spec.final.name\n\n // skip any inactive entry\n const entry = peerContext.get(name)\n if (!entry?.active) continue\n\n // validate if the provided spec is compatible with existing specs\n if (incompatibleSpecs(spec, entry)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Add or update dependencies in a given peer context making sure to check\n * for compatibility with existing dependencies already resolved by a given\n * peer context set. Extra info such as a target or dependent nodes is\n * optional.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const addEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n fromNode: Node,\n monorepo?: Monorepo,\n): boolean => {\n // pre check to see if any of the new entries to be added to the\n // provided peer context set conflicts with existing ones\n // if that's already the case we can skip processing them and\n // will return that a fork is needed right away\n if (checkEntriesToPeerContext(peerContext, entries)) return true\n\n // iterate on every entry to be added to the peer context set\n for (const { dependent, spec, target, type } of entries) {\n const name = target?.name ?? spec.final.name\n\n // if there's no existing entry, create one\n let entry = peerContext.get(name)\n if (!entry) {\n entry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents: new Set(),\n }\n peerContext.set(name, entry)\n if (dependent) entry.contextDependents.add(dependent)\n continue\n }\n\n // perform an extra check that confirms the new spec does not\n // conflicts with existing specs in this entry, this handles the\n // case of adding sibling deps that conflicts with one another\n if (incompatibleSpecs(spec, entry)) return true\n\n if (\n target &&\n [...entry.specs].every(s =>\n satisfies(\n target.id,\n s,\n fromNode.location,\n fromNode.projectRoot,\n monorepo,\n ),\n )\n ) {\n if (\n target.id !== entry.target?.id &&\n target.version !== entry.target?.version\n ) {\n // we have a compatible entry that has a new, compatible target\n // so we need to update all dependents to point to the new target\n for (const dependents of entry.contextDependents) {\n const edge = dependents.edgesOut.get(name)\n if (edge?.to && edge.to !== target) {\n edge.to.edgesIn.delete(edge)\n edge.to = target\n target.edgesIn.add(edge)\n }\n }\n entry.target = target\n }\n\n // otherwise sets the value in case it was nullish\n entry.target ??= target\n }\n\n // update specs and dependents values\n entry.specs.add(spec)\n if (dependent) entry.contextDependents.add(dependent)\n }\n\n return false\n}\n\n/**\n * Create and returns a forked copy of a given peer context set.\n */\nexport const forkPeerContext = (\n graph: Graph,\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): PeerContext => {\n // create a new peer context set\n const nextPeerContext: PeerContext = new Map()\n nextPeerContext.index = graph.nextPeerContextIndex()\n // register it in the graph\n graph.peerContexts[nextPeerContext.index] = nextPeerContext\n\n // copy existing entries marking them as inactive, it's also important\n // to note that specs and contextDependents are new objects so that changes\n // to those in the new context do not affect the previous one\n for (const [name, entry] of peerContext.entries()) {\n nextPeerContext.set(name, {\n active: false,\n specs: new Set(entry.specs),\n target: undefined,\n type: entry.type,\n contextDependents: new Set(entry.contextDependents),\n })\n }\n\n // add the new entries to this peer context set, marking them as active\n // these are the entries that were incompatible with the previous context set\n for (const entry of entries) {\n const { dependent, spec, target, type } = entry\n const name = target?.name /* c8 ignore next */ ?? spec.final.name\n const newEntry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents:\n dependent ? new Set([dependent]) : new Set<Node>(),\n }\n nextPeerContext.set(name, newEntry)\n }\n\n return nextPeerContext\n}\n\n/**\n * Starts the peer dependency placement process\n * for a given node being processed and placed.\n */\nexport const startPeerPlacement = (\n peerContext: PeerContext,\n manifest: Manifest,\n fromNode: Node,\n options: SpecOptions,\n) => {\n // queue entries so that they can be added at the end of the placement\n // process, use a map to ensure deduplication between read json dep\n // values and the resolved edges in the graph\n const queueMap = new Map<string, PeerContextEntryInput>()\n let peerSetHash: string | undefined\n\n if (\n manifest.peerDependencies &&\n Object.keys(manifest.peerDependencies).length > 0\n ) {\n // generates a peer context set hash for nodes that\n // have peer dependencies to be resolved\n peerSetHash = retrievePeerContextHash(peerContext)\n\n // get any potential sibling dependency from the\n // parent node that might have not been parsed yet\n const siblingDeps = getDependencies(fromNode, {\n ...options,\n registry: fromNode.registry,\n })\n for (const [depName, dep] of siblingDeps) {\n queueMap.set(depName, dep)\n }\n\n // collect the already parsed nodes and add those to the\n // list of entries to be added to the peer context set\n for (const edge of fromNode.edgesOut.values()) {\n queueMap.set(edge.name, {\n spec: edge.spec,\n target: edge.to,\n type: edge.type,\n })\n }\n }\n\n return {\n peerSetHash,\n // Sort queuedEntries for deterministic order\n queuedEntries: getOrderedPeerContextEntries([\n ...queueMap.values(),\n ]),\n }\n}\n\n/**\n * Ends the peer dependency placement process, returning the functions that\n * are going to be used to update the peer context set, forking when needed\n * and resolving peer dependencies if possible.\n */\nexport const endPeerPlacement = (\n peerContext: PeerContext,\n nextDeps: Dependency[],\n nextPeerDeps: Map<string, Dependency> & { id?: number },\n graph: Graph,\n spec: Spec,\n fromNode: Node,\n node: Node,\n type: DependencySaveType,\n queuedEntries: PeerContextEntryInput[],\n) => ({\n /**\n * Add the new entries to the current peer context set.\n */\n putEntries: () => {\n // keep track of whether we need to fork the current peer context set\n let needsToForkPeerContext = false\n // add queued entries from this node parents along\n // with a self-ref to the current peer context set\n const prevEntries = [\n ...queuedEntries,\n /* ref itself */ {\n spec,\n target: node,\n type,\n },\n ]\n addEntriesToPeerContext(\n peerContext,\n prevEntries,\n fromNode,\n graph.monorepo,\n )\n\n // add this node's direct dependencies next\n const nextEntries = [\n ...nextDeps.map(dep => ({ ...dep, dependent: node })),\n ...[...nextPeerDeps.values()].map(dep => ({\n ...dep,\n dependent: node,\n })),\n ]\n if (nextEntries.length > 0) {\n needsToForkPeerContext = addEntriesToPeerContext(\n peerContext,\n nextEntries,\n node,\n graph.monorepo,\n )\n }\n\n // returns all entries that need to be added to a forked\n // context or undefined if the current context was updated directly\n return needsToForkPeerContext ? nextEntries : undefined\n },\n\n /**\n * Try to resolve peer dependencies using already seen target\n * values from the current peer context set.\n */\n resolvePeerDeps: () => {\n // iterate on the set of peer dependencies of the current node\n // and try to resolve them from the existing peer context set,\n // when possible, add them as edges in the graph right away, if not,\n // then we move them back to the `nextDeps` list for processing\n // along with the rest of the regular dependencies\n for (const nextDep of nextPeerDeps.values()) {\n const { spec, type } = nextDep\n if (type === 'peer' || type === 'peerOptional') {\n // FIRST: Check if there's a sibling dependency from the parent\n // that specifies this same package. Sibling deps take priority\n // because they represent the workspace's direct dependency,\n // which should be preferred over versions from other workspaces\n // that may have been added to the peer context earlier.\n const siblingEntry = queuedEntries.find(\n e =>\n (e.target?.name ?? e.spec.final.name) === spec.final.name,\n )\n\n if (\n siblingEntry?.target &&\n !node.edgesOut.has(spec.final.name) &&\n satisfies(\n siblingEntry.target.id,\n spec,\n fromNode.location,\n fromNode.projectRoot,\n graph.monorepo,\n )\n ) {\n // The sibling's resolved target satisfies the peer spec,\n // use it directly - this prioritizes the workspace's own\n // direct dependency over versions from other workspaces\n graph.addEdge(type, spec, node, siblingEntry.target)\n continue\n }\n\n // THEN: Try to retrieve an entry for that peer dep from\n // the current peer context set\n const entry = peerContext.get(spec.final.name)\n if (\n !node.edgesOut.has(spec.final.name) &&\n entry?.target &&\n satisfies(\n entry.target.id,\n spec,\n fromNode.location,\n fromNode.projectRoot,\n graph.monorepo,\n )\n ) {\n // entry satisfied, create edge in the graph\n graph.addEdge(type, spec, node, entry.target)\n entry.specs.add(spec.final)\n } else if (type === 'peerOptional') {\n // skip unsatisfied peerOptional dependencies,\n // just create a dangling edge\n graph.addEdge(type, spec, node)\n } else if (\n siblingEntry &&\n siblingEntry.spec.bareSpec !== spec.bareSpec\n ) {\n // Sibling has a more specific spec for this package,\n // use it when resolving to ensure we get the right version\n nextDeps.push({ ...nextDep, spec: siblingEntry.spec })\n } else {\n // could not satisfy from peer context or sibling, add to next deps\n nextDeps.push(nextDep)\n }\n }\n }\n },\n})\n\n/**\n * Given an array of processed results for the current level dependencies\n * being placed in the currently building ideal graph, traverse its direct\n * dependencies and track peer dependencies in their appropriate peer context\n * sets, forking as needed and resolving peer dependencies using suitable\n * nodes already present in the graph if possible.\n */\nexport const postPlacementPeerCheck = (\n graph: Graph,\n sortedLevelResults: ProcessPlacementResult[],\n) => {\n // Update peer contexts in a sorted manner after processing all nodes\n // at a given level to ensure deterministic behavior when it comes to\n // forking new peer contexts\n for (const childDepsToProcess of sortedLevelResults) {\n // Sort childDepsToProcess deterministically by node.id\n const sortedChildDeps = [...childDepsToProcess].sort((a, b) =>\n a.node.id.localeCompare(b.node.id, 'en'),\n )\n\n const needsForking = new Map<\n ProcessPlacementResultEntry,\n {\n dependent: Node\n spec: Spec\n type: DependencySaveType\n }[]\n >()\n // first iterate on all child deps, adding entries to the current\n // context and collect the information on which ones need forking\n for (const childDep of sortedChildDeps) {\n const needsFork = childDep.updateContext.putEntries()\n if (needsFork) {\n needsForking.set(childDep, needsFork)\n }\n }\n\n // Sort needsForking entries before iterating (Map iteration order = insertion order)\n const sortedNeedsForkingEntries = [\n ...needsForking.entries(),\n ].sort(([a], [b]) => a.node.id.localeCompare(b.node.id, 'en'))\n\n // then iterate again, forking contexts as needed but also try to\n // reuse the context of the previous sibling if possible\n let prevContext\n for (const [childDep, nextEntries] of sortedNeedsForkingEntries) {\n if (\n prevContext &&\n !checkEntriesToPeerContext(prevContext, nextEntries)\n ) {\n // the context of the previous sibling can be reused\n addEntriesToPeerContext(\n prevContext,\n nextEntries,\n childDep.node,\n graph.monorepo,\n )\n childDep.peerContext = prevContext\n continue\n }\n childDep.peerContext = forkPeerContext(\n graph,\n childDep.peerContext,\n nextEntries,\n )\n prevContext = childDep.peerContext\n }\n // try to resolve peer dependencies now that\n // the context is fully set up\n for (const childDep of sortedChildDeps) {\n childDep.updateContext.resolvePeerDeps()\n childDep.deps = getOrderedDependencies(childDep.deps)\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/reify/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/reify/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAKtC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,IAAI,EAAE,CAAA;IACf,OAAO,EAAE,IAAI,EAAE,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,KAAK,SACV,IAAI,eACG,WAAW,UAChB,UAAU,qBACC,GAAG,CAAC,KAAK,CAAC,KAC5B,OAAO,CAAC,WAAW,CA6DrB,CAAA"}
|
package/dist/reify/build.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// walk the graph of added nodes, building and chmoding their bins
|
|
2
2
|
// at the end, we get back to the importers, and run their prepare
|
|
3
3
|
// script as well as install script.
|
|
4
|
+
import { join } from 'node:path';
|
|
4
5
|
import { run } from '@vltpkg/run';
|
|
5
6
|
import { graphRun } from '@vltpkg/graph-run';
|
|
6
7
|
import { nonEmptyList } from "../non-empty-list.js";
|
|
@@ -71,8 +72,16 @@ const visit = async (packageJson, scurry, node, signal, _path) => {
|
|
|
71
72
|
const { manifest } = node;
|
|
72
73
|
const { scripts = {} } = manifest;
|
|
73
74
|
const { install, preinstall, postinstall, prepare, preprepare, postprepare, } = scripts;
|
|
74
|
-
//
|
|
75
|
-
|
|
75
|
+
// Check for binding.gyp file (npm's implicit install detection)
|
|
76
|
+
// "If there is a binding.gyp file in the root of your package and you
|
|
77
|
+
// haven't defined your own install or preinstall scripts, npm will default
|
|
78
|
+
// the install command to compile using node-gyp via node-gyp rebuild"
|
|
79
|
+
const hasBindingGyp = scurry
|
|
80
|
+
.lstatSync(join(node.resolvedLocation(scurry), 'binding.gyp'))
|
|
81
|
+
?.isFile() ?? false;
|
|
82
|
+
const hasImplicitInstall = hasBindingGyp && !install && !preinstall;
|
|
83
|
+
// if it has install script or binding.gyp (implicit install), run it
|
|
84
|
+
const runInstall = !!(install || preinstall || postinstall) || hasImplicitInstall;
|
|
76
85
|
if (runInstall) {
|
|
77
86
|
await run({
|
|
78
87
|
signal,
|
package/dist/reify/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/reify/build.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAClE,oCAAoC;
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/reify/build.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAClE,oCAAoC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAK5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAUzC,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,IAAU,EACV,WAAwB,EACxB,MAAkB,EAClB,iBAA6B,EACP,EAAE;IACxB,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAA;IACrB,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAA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,IAAI,KAAK,CAAA;IACvB,MAAM,kBAAkB,GAAG,aAAa,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,CAAA;IAEnE,qEAAqE;IACrE,MAAM,UAAU,GACd,CAAC,CAAC,CAAC,OAAO,IAAI,UAAU,IAAI,WAAW,CAAC,IAAI,kBAAkB,CAAA;IAChE,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,GAAG,CAAC;YACR,MAAM;YACN,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,WAAW;YACX,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;YAClC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,0CAA0C;IAC1C,MAAM,QAAQ,GACZ,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAClE,MAAM,UAAU,GACd,CAAC,CAAC,CAAC,OAAO,IAAI,UAAU,IAAI,WAAW,CAAC,IAAI,QAAQ,CAAA;IAEtD,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,GAAG,CAAC;YACR,MAAM;YACN,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,WAAW;YACX,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;YAClC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC9B,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 { join } from 'node:path'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport { run } from '@vltpkg/run'\nimport { graphRun } from '@vltpkg/graph-run'\nimport type { PathScurry } from 'path-scurry'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\nimport { nonEmptyList } from '../non-empty-list.ts'\nimport { optionalFail } from './optional-fail.ts'\nimport { binChmod } from './bin-chmod.ts'\n\n/**\n * Returns an object mapping registries to the names of the packages built.\n */\nexport type BuildResult = {\n success: Node[]\n failure: Node[]\n}\n\nexport const build = async (\n diff: Diff,\n packageJson: PackageJson,\n scurry: PathScurry,\n allowScriptsNodes: Set<DepID>,\n): Promise<BuildResult> => {\n const graph = diff.to\n const nodes = nonEmptyList([...graph.importers])\n const res: BuildResult = { success: [], failure: [] }\n\n // determine if scripts should run - check if node is in allowed set\n const shouldRunScripts = (node: Node): boolean =>\n allowScriptsNodes.has(node.id)\n\n /* c8 ignore next - all graphs have at least one importer */\n if (!nodes) return res\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\n if (\n !node.importer &&\n (!diff.nodes.add.has(node) || !shouldRunScripts(node))\n )\n return\n\n try {\n await visit(packageJson, scurry, node, signal, path)\n if (!node.importer) {\n node.buildState = 'built'\n res.success.push(node)\n }\n /* c8 ignore start - windows on CI is missing those tests */\n } catch (err) {\n // Check if this is an optional failure that was handled\n if (node.optional) {\n node.buildState = 'failed'\n res.failure.push(node)\n // Let optionalFail handle the error\n await Promise.reject(err).catch(optionalFail(diff, node))\n } else {\n // Re-throw non-optional failures\n throw err\n }\n }\n /* c8 ignore stop */\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 return res\n}\n\nconst visit = async (\n packageJson: PackageJson,\n scurry: PathScurry,\n node: Node,\n signal: AbortSignal,\n _path: Node[],\n): Promise<void> => {\n // at this point we might have to read the manifest from disk if it's\n // currently nullish, that could happen in a scenario where the ideal\n // graph is from a lockfile and there's no actual graph available\n // to hydrate the manifest data from.\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 // Check for binding.gyp file (npm's implicit install detection)\n // \"If there is a binding.gyp file in the root of your package and you\n // haven't defined your own install or preinstall scripts, npm will default\n // the install command to compile using node-gyp via node-gyp rebuild\"\n const hasBindingGyp =\n scurry\n .lstatSync(join(node.resolvedLocation(scurry), 'binding.gyp'))\n ?.isFile() ?? false\n const hasImplicitInstall = hasBindingGyp && !install && !preinstall\n\n // if it has install script or binding.gyp (implicit install), run it\n const runInstall =\n !!(install || preinstall || postinstall) || hasImplicitInstall\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 await binChmod(node, scurry)\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PathScurry } from 'path-scurry';
|
|
1
2
|
import type { Diff } from '../diff.ts';
|
|
2
3
|
import type { Node } from '../node.ts';
|
|
3
4
|
/**
|
|
@@ -14,6 +15,10 @@ export type CheckNeededBuildOptions = {
|
|
|
14
15
|
* The diff object containing nodes to process
|
|
15
16
|
*/
|
|
16
17
|
diff: Diff;
|
|
18
|
+
/**
|
|
19
|
+
* PathScurry instance for filesystem access
|
|
20
|
+
*/
|
|
21
|
+
scurry: PathScurry;
|
|
17
22
|
};
|
|
18
23
|
/**
|
|
19
24
|
* Check which nodes need to be built and set buildState accordingly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-needed-build.d.ts","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"check-needed-build.d.ts","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGtC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,eAAe,EAAE,IAAI,EAAE,CAAA;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IACV;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAmDD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAClB,uBAAuB,KAC/B,SAkBF,CAAA"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
1
2
|
/**
|
|
2
3
|
* Checks if a node needs to be built based on the conditions from build.ts:
|
|
3
4
|
* 1. Has install lifecycle scripts (install, preinstall, postinstall)
|
|
4
|
-
* 2.
|
|
5
|
-
* 3.
|
|
5
|
+
* 2. Has binding.gyp file with no install/preinstall scripts (implicit install)
|
|
6
|
+
* 3. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)
|
|
7
|
+
* 4. Has binary files that need to be linked
|
|
6
8
|
*/
|
|
7
|
-
const nodeNeedsBuild = (node) => {
|
|
9
|
+
const nodeNeedsBuild = (node, scurry) => {
|
|
8
10
|
// If the node has already been built during reify, no need to build again
|
|
9
11
|
if (node.built)
|
|
10
12
|
return false;
|
|
@@ -19,6 +21,15 @@ const nodeNeedsBuild = (node) => {
|
|
|
19
21
|
scripts.postinstall);
|
|
20
22
|
if (runInstall)
|
|
21
23
|
return true;
|
|
24
|
+
// Check for binding.gyp file (npm's implicit install detection)
|
|
25
|
+
// "If there is a binding.gyp file in the root of your package and you
|
|
26
|
+
// haven't defined your own install or preinstall scripts, npm will default
|
|
27
|
+
// the install command to compile using node-gyp via node-gyp rebuild"
|
|
28
|
+
const hasBindingGyp = scurry
|
|
29
|
+
.lstatSync(join(node.resolvedLocation(scurry), 'binding.gyp'))
|
|
30
|
+
?.isFile() ?? false;
|
|
31
|
+
if (hasBindingGyp && !scripts.install && !scripts.preinstall)
|
|
32
|
+
return true;
|
|
22
33
|
// Check for prepare scripts on importers or git dependencies
|
|
23
34
|
const prepable = node.id.startsWith('git') || node.importer || !node.inVltStore();
|
|
24
35
|
const runPrepare = !!((scripts.prepare || scripts.preprepare || scripts.postprepare)
|
|
@@ -35,9 +46,9 @@ const nodeNeedsBuild = (node) => {
|
|
|
35
46
|
* @returns {BuildData} The BuildData object containing Node objects that need building
|
|
36
47
|
*/
|
|
37
48
|
export const checkNeededBuild = (options) => {
|
|
38
|
-
const { diff } = options;
|
|
49
|
+
const { diff, scurry } = options;
|
|
39
50
|
// Filter nodes to only include those that actually need to be built
|
|
40
|
-
const nodesToBuild = [...diff.nodes.add].filter(nodeNeedsBuild);
|
|
51
|
+
const nodesToBuild = [...diff.nodes.add].filter(node => nodeNeedsBuild(node, scurry));
|
|
41
52
|
// Set buildState = 'needed' on all nodes that require building
|
|
42
53
|
for (const node of nodesToBuild) {
|
|
43
54
|
node.buildState = 'needed';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-needed-build.js","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"check-needed-build.js","sourceRoot":"","sources":["../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAuBhC;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,CAAC,IAAU,EAAE,MAAkB,EAAW,EAAE;IACjE,0EAA0E;IAC1E,IAAI,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAE5B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;IACzB,oBAAoB;IACpB,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAA;IAE3B,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAA;IAEjC,sCAAsC;IACtC,MAAM,UAAU,GAAG,CAAC,CAAC,CACnB,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,UAAU;QAClB,OAAO,CAAC,WAAW,CACpB,CAAA;IACD,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAE3B,gEAAgE;IAChE,sEAAsE;IACtE,2EAA2E;IAC3E,sEAAsE;IACtE,MAAM,aAAa,GACjB,MAAM;SACH,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,CAAC;QAC9D,EAAE,MAAM,EAAE,IAAI,KAAK,CAAA;IACvB,IAAI,aAAa,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU;QAC1D,OAAO,IAAI,CAAA;IAEb,6DAA6D;IAC7D,MAAM,QAAQ,GACZ,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAClE,MAAM,UAAU,GACd,CAAC,CAAC,CACA,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;IAC9D,sBAAsB;KACvB,IAAI,QAAQ,CAAA;IACf,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAE3B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAAgC,EACrB,EAAE;IACb,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAEhC,oEAAoE;IACpE,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CACrD,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAC7B,CAAA;IAED,+DAA+D;IAC/D,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAA;IAC5B,CAAC;IAED,MAAM,SAAS,GAAc;QAC3B,eAAe,EAAE,YAAY;KAC9B,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA","sourcesContent":["import type { PathScurry } from 'path-scurry'\nimport type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\nimport { join } from 'node:path'\n\n/**\n * Build data containing the queue of DepIDs that need building\n */\nexport type BuildData = {\n needsBuildNodes: Node[]\n}\n\n/**\n * Options for checking needed build data\n */\nexport type CheckNeededBuildOptions = {\n /**\n * The diff object containing nodes to process\n */\n diff: Diff\n /**\n * PathScurry instance for filesystem access\n */\n scurry: PathScurry\n}\n\n/**\n * Checks if a node needs to be built based on the conditions from build.ts:\n * 1. Has install lifecycle scripts (install, preinstall, postinstall)\n * 2. Has binding.gyp file with no install/preinstall scripts (implicit install)\n * 3. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)\n * 4. Has binary files that need to be linked\n */\nconst nodeNeedsBuild = (node: Node, scurry: PathScurry): boolean => {\n // If the node has already been built during reify, no need to build again\n if (node.built) return false\n\n const { manifest } = node\n /* c8 ignore next */\n if (!manifest) return false\n\n const { scripts = {} } = manifest\n\n // Check for install lifecycle scripts\n const runInstall = !!(\n scripts.install ||\n scripts.preinstall ||\n scripts.postinstall\n )\n if (runInstall) return true\n\n // Check for binding.gyp file (npm's implicit install detection)\n // \"If there is a binding.gyp file in the root of your package and you\n // haven't defined your own install or preinstall scripts, npm will default\n // the install command to compile using node-gyp via node-gyp rebuild\"\n const hasBindingGyp =\n scurry\n .lstatSync(join(node.resolvedLocation(scurry), 'binding.gyp'))\n ?.isFile() ?? false\n if (hasBindingGyp && !scripts.install && !scripts.preinstall)\n return true\n\n // Check for prepare scripts on importers or git dependencies\n const prepable =\n node.id.startsWith('git') || node.importer || !node.inVltStore()\n const runPrepare =\n !!(\n (scripts.prepare || scripts.preprepare || scripts.postprepare)\n /* c8 ignore next 2 */\n ) && prepable\n if (runPrepare) return true\n\n return false\n}\n\n/**\n * Check which nodes need to be built and set buildState accordingly\n * Marks nodes with buildState = 'needed' for those that require\n * install lifecycle scripts as part of `vlt build`\n * @returns {BuildData} The BuildData object containing Node objects that need building\n */\nexport const checkNeededBuild = (\n options: CheckNeededBuildOptions,\n): BuildData => {\n const { diff, scurry } = options\n\n // Filter nodes to only include those that actually need to be built\n const nodesToBuild = [...diff.nodes.add].filter(node =>\n nodeNeedsBuild(node, scurry),\n )\n\n // Set buildState = 'needed' on all nodes that require building\n for (const node of nodesToBuild) {\n node.buildState = 'needed'\n }\n\n const buildData: BuildData = {\n needsBuildNodes: nodesToBuild,\n }\n\n return buildData\n}\n"]}
|
package/dist/reify/index.js
CHANGED
|
@@ -119,7 +119,7 @@ const reify_ = async (options, diff, remover) => {
|
|
|
119
119
|
await internalHoist(diff.to, options, remover);
|
|
120
120
|
// looks up all nodes setting buildState = 'needed'
|
|
121
121
|
// on nodes that require building
|
|
122
|
-
checkNeededBuild({ diff });
|
|
122
|
+
checkNeededBuild({ diff, scurry });
|
|
123
123
|
// Filter nodes allowed to run scripts if allowScripts query is provided
|
|
124
124
|
const allowScriptsNodes = await filterNodesByQuery(diff.to, allowScripts);
|
|
125
125
|
// ensure that all added bins are chmod +x
|
package/dist/reify/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAKtD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,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AAI,SAAS,CAAC,MAAM;QAAE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IAElD,6DAA6D;IAC7D,wBAAwB,EAAE,EAAE,CAAA;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;IAExD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,YAAY,CACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAC7C,CAAA;IACH,CAAC;IAED,4BAA4B;IAC5B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { graphStep } from '@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { checkNeededBuild } from './check-needed-build.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport type { NodeLike } from '@vltpkg/types'\nimport { binChmodAll } from './bin-chmod.ts'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n/**\n * Filter nodes using a DSS query string\n */\nconst filterNodesByQuery = async (\n graph: Graph,\n allowScriptsQuery?: string,\n): Promise<Set<DepID>> => {\n // shortcut no packages included\n if (\n allowScriptsQuery === ':not(*)' /* c8 ignore next */ ||\n !allowScriptsQuery\n ) {\n return new Set()\n }\n // shortcut all packages included\n if (allowScriptsQuery === '*') {\n return new Set(graph.nodes.keys())\n }\n /* c8 ignore start */\n const securityArchive =\n Query.hasSecuritySelectors(allowScriptsQuery) ?\n await SecurityArchive.start({\n nodes: [...graph.nodes.values()],\n })\n : undefined\n /* c8 ignore stop */\n\n const edges = graph.edges\n const nodes = new Set<NodeLike>(graph.nodes.values())\n const importers = graph.importers\n\n const query = new Query({\n edges,\n nodes,\n importers,\n securityArchive,\n })\n\n const { nodes: resultNodes } = await query.search(\n allowScriptsQuery,\n {\n signal: new AbortController().signal,\n },\n )\n\n return new Set(resultNodes.map(node => node.id))\n}\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n allowScripts: string\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n remover: RollbackRemove\n}\n\nexport type ReifyResult = {\n /**\n * The diff object that was used to reify the project.\n */\n diff: Diff\n /**\n * Optional queue of DepIDs that requires building (running lifecycle scripts\n * and binary linking) after the reification is complete.\n */\n buildQueue?: DepID[]\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (\n options: ReifyOptions,\n): Promise<ReifyResult> => {\n const done = graphStep('reify')\n\n const { graph, scurry, remover } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const noModifiedDependencies =\n !options.add?.modifiedDependencies &&\n !options.remove?.modifiedDependencies\n const skipOptionalOnly = noModifiedDependencies && diff.optionalOnly\n const res: ReifyResult = { diff }\n if (!diff.hasChanges() || skipOptionalOnly) {\n // nothing to do, so just return the diff\n done()\n return res\n }\n\n let success = false\n try {\n const { buildQueue } = await reify_(options, diff, remover)\n remover.confirm()\n success = true\n res.buildQueue = buildQueue\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return res\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n): Promise<Omit<ReifyResult, 'diff'>> => {\n const res: Omit<ReifyResult, 'diff'> = {}\n const {\n add,\n remove,\n packageInfo,\n packageJson,\n scurry,\n allowScripts,\n } = options\n const saveImportersPackageJson =\n /* c8 ignore next */\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions = addEdges(diff, scurry, remover)\n if (edgeActions.length) await callLimit(edgeActions, { limit })\n\n await internalHoist(diff.to, options, remover)\n\n // looks up all nodes setting buildState = 'needed'\n // on nodes that require building\n checkNeededBuild({ diff })\n\n // Filter nodes allowed to run scripts if allowScripts query is provided\n const allowScriptsNodes = await filterNodesByQuery(\n diff.to,\n allowScripts,\n )\n\n // ensure that all added bins are chmod +x\n await binChmodAll(diff.nodes.add, scurry)\n\n // run install lifecycle scripts and link any binary files\n await build(diff, packageJson, scurry, allowScriptsNodes)\n\n // set the buildQueue on the result object containing\n // an array with all the ids of nodes that need building\n res.buildQueue = [...diff.nodes.add]\n .filter(node => node.buildState === 'needed')\n .map(node => node.id)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n // TODO: add tests to cover this\n /* c8 ignore start */\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n /* c8 ignore stop */\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n\n // returns the result object\n return res\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAKtD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,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D;IACzD,gCAAgC;IAChC,qBAAqB;IACrB,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;IACD,oBAAoB;IACpB,UAAU,CAAC,OAAO,CAAC,CAAA;IAEnB,iCAAiC;IACjC,MAAM,SAAS,GAAuB,WAAW,CAC/C,IAAI,EACJ,OAAO,EACP,MAAM,CACP,CAAA;IACD,IAAI,SAAS,CAAC,MAAM;QAAE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IAElD,6DAA6D;IAC7D,wBAAwB,EAAE,EAAE,CAAA;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;IAExD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,YAAY,CACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAC7C,CAAA;IACH,CAAC;IAED,4BAA4B;IAC5B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { graphStep } from '@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { checkNeededBuild } from './check-needed-build.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport type { NodeLike } from '@vltpkg/types'\nimport { binChmodAll } from './bin-chmod.ts'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n/**\n * Filter nodes using a DSS query string\n */\nconst filterNodesByQuery = async (\n graph: Graph,\n allowScriptsQuery?: string,\n): Promise<Set<DepID>> => {\n // shortcut no packages included\n if (\n allowScriptsQuery === ':not(*)' /* c8 ignore next */ ||\n !allowScriptsQuery\n ) {\n return new Set()\n }\n // shortcut all packages included\n if (allowScriptsQuery === '*') {\n return new Set(graph.nodes.keys())\n }\n /* c8 ignore start */\n const securityArchive =\n Query.hasSecuritySelectors(allowScriptsQuery) ?\n await SecurityArchive.start({\n nodes: [...graph.nodes.values()],\n })\n : undefined\n /* c8 ignore stop */\n\n const edges = graph.edges\n const nodes = new Set<NodeLike>(graph.nodes.values())\n const importers = graph.importers\n\n const query = new Query({\n edges,\n nodes,\n importers,\n securityArchive,\n })\n\n const { nodes: resultNodes } = await query.search(\n allowScriptsQuery,\n {\n signal: new AbortController().signal,\n },\n )\n\n return new Set(resultNodes.map(node => node.id))\n}\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n allowScripts: string\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n remover: RollbackRemove\n}\n\nexport type ReifyResult = {\n /**\n * The diff object that was used to reify the project.\n */\n diff: Diff\n /**\n * Optional queue of DepIDs that requires building (running lifecycle scripts\n * and binary linking) after the reification is complete.\n */\n buildQueue?: DepID[]\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (\n options: ReifyOptions,\n): Promise<ReifyResult> => {\n const done = graphStep('reify')\n\n const { graph, scurry, remover } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const noModifiedDependencies =\n !options.add?.modifiedDependencies &&\n !options.remove?.modifiedDependencies\n const skipOptionalOnly = noModifiedDependencies && diff.optionalOnly\n const res: ReifyResult = { diff }\n if (!diff.hasChanges() || skipOptionalOnly) {\n // nothing to do, so just return the diff\n done()\n return res\n }\n\n let success = false\n try {\n const { buildQueue } = await reify_(options, diff, remover)\n remover.confirm()\n success = true\n res.buildQueue = buildQueue\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return res\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n): Promise<Omit<ReifyResult, 'diff'>> => {\n const res: Omit<ReifyResult, 'diff'> = {}\n const {\n add,\n remove,\n packageInfo,\n packageJson,\n scurry,\n allowScripts,\n } = options\n const saveImportersPackageJson =\n /* c8 ignore next */\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions = addEdges(diff, scurry, remover)\n if (edgeActions.length) await callLimit(edgeActions, { limit })\n\n await internalHoist(diff.to, options, remover)\n\n // looks up all nodes setting buildState = 'needed'\n // on nodes that require building\n checkNeededBuild({ diff, scurry })\n\n // Filter nodes allowed to run scripts if allowScripts query is provided\n const allowScriptsNodes = await filterNodesByQuery(\n diff.to,\n allowScripts,\n )\n\n // ensure that all added bins are chmod +x\n await binChmodAll(diff.nodes.add, scurry)\n\n // run install lifecycle scripts and link any binary files\n await build(diff, packageJson, scurry, allowScriptsNodes)\n\n // set the buildQueue on the result object containing\n // an array with all the ids of nodes that need building\n res.buildQueue = [...diff.nodes.add]\n .filter(node => node.buildState === 'needed')\n .map(node => node.id)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n // TODO: add tests to cover this\n /* c8 ignore start */\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n /* c8 ignore stop */\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n\n // returns the result object\n return res\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/graph",
|
|
3
3
|
"description": "A library that helps understanding & expressing what happens on an install",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.12",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -11,26 +11,26 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"path-scurry": "^2.0.1",
|
|
13
13
|
"promise-call-limit": "^3.0.2",
|
|
14
|
-
"@vltpkg/cmd-shim": "1.0.0-rc.
|
|
15
|
-
"@vltpkg/dep-id": "1.0.0-rc.
|
|
16
|
-
"@vltpkg/error-cause": "1.0.0-rc.
|
|
17
|
-
"@vltpkg/dss-breadcrumb": "1.0.0-rc.
|
|
18
|
-
"@vltpkg/fast-split": "1.0.0-rc.
|
|
19
|
-
"@vltpkg/graph-run": "1.0.0-rc.
|
|
20
|
-
"@vltpkg/
|
|
21
|
-
"@vltpkg/
|
|
22
|
-
"@vltpkg/package-info": "1.0.0-rc.
|
|
23
|
-
"@vltpkg/
|
|
24
|
-
"@vltpkg/
|
|
25
|
-
"@vltpkg/
|
|
26
|
-
"@vltpkg/rollback-remove": "1.0.0-rc.
|
|
27
|
-
"@vltpkg/
|
|
28
|
-
"@vltpkg/
|
|
29
|
-
"@vltpkg/
|
|
30
|
-
"@vltpkg/spec": "1.0.0-rc.
|
|
31
|
-
"@vltpkg/types": "1.0.0-rc.
|
|
32
|
-
"@vltpkg/vlt-json": "1.0.0-rc.
|
|
33
|
-
"@vltpkg/workspaces": "1.0.0-rc.
|
|
14
|
+
"@vltpkg/cmd-shim": "1.0.0-rc.12",
|
|
15
|
+
"@vltpkg/dep-id": "1.0.0-rc.12",
|
|
16
|
+
"@vltpkg/error-cause": "1.0.0-rc.12",
|
|
17
|
+
"@vltpkg/dss-breadcrumb": "1.0.0-rc.12",
|
|
18
|
+
"@vltpkg/fast-split": "1.0.0-rc.12",
|
|
19
|
+
"@vltpkg/graph-run": "1.0.0-rc.12",
|
|
20
|
+
"@vltpkg/output": "1.0.0-rc.12",
|
|
21
|
+
"@vltpkg/init": "1.0.0-rc.12",
|
|
22
|
+
"@vltpkg/package-info": "1.0.0-rc.12",
|
|
23
|
+
"@vltpkg/pick-manifest": "1.0.0-rc.12",
|
|
24
|
+
"@vltpkg/query": "1.0.0-rc.12",
|
|
25
|
+
"@vltpkg/package-json": "1.0.0-rc.12",
|
|
26
|
+
"@vltpkg/rollback-remove": "1.0.0-rc.12",
|
|
27
|
+
"@vltpkg/run": "1.0.0-rc.12",
|
|
28
|
+
"@vltpkg/security-archive": "1.0.0-rc.12",
|
|
29
|
+
"@vltpkg/satisfies": "1.0.0-rc.12",
|
|
30
|
+
"@vltpkg/spec": "1.0.0-rc.12",
|
|
31
|
+
"@vltpkg/types": "1.0.0-rc.12",
|
|
32
|
+
"@vltpkg/vlt-json": "1.0.0-rc.12",
|
|
33
|
+
"@vltpkg/workspaces": "1.0.0-rc.12"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@eslint/js": "^9.39.1",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"typedoc": "~0.27.9",
|
|
43
43
|
"typescript": "5.7.3",
|
|
44
44
|
"typescript-eslint": "^8.49.0",
|
|
45
|
-
"@vltpkg/vlt-json": "1.0.0-rc.
|
|
45
|
+
"@vltpkg/vlt-json": "1.0.0-rc.12"
|
|
46
46
|
},
|
|
47
47
|
"license": "BSD-2-Clause-Patent",
|
|
48
48
|
"engines": {
|