@vltpkg/graph 1.0.0-rc.13 → 1.0.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -22
- package/dist/actual/load.d.ts.map +1 -1
- package/dist/actual/load.js +3 -2
- package/dist/actual/load.js.map +1 -1
- package/dist/diff.d.ts +2 -0
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +5 -1
- package/dist/diff.js.map +1 -1
- package/dist/fixup-added-names.d.ts +4 -1
- package/dist/fixup-added-names.d.ts.map +1 -1
- package/dist/fixup-added-names.js +16 -0
- package/dist/fixup-added-names.js.map +1 -1
- package/dist/graph.d.ts +7 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +17 -2
- package/dist/graph.js.map +1 -1
- package/dist/ideal/append-nodes.d.ts +14 -2
- package/dist/ideal/append-nodes.d.ts.map +1 -1
- package/dist/ideal/append-nodes.js +188 -57
- package/dist/ideal/append-nodes.js.map +1 -1
- package/dist/ideal/build.d.ts.map +1 -1
- package/dist/ideal/build.js +11 -1
- package/dist/ideal/build.js.map +1 -1
- package/dist/ideal/peers.d.ts +90 -6
- package/dist/ideal/peers.d.ts.map +1 -1
- package/dist/ideal/peers.js +387 -131
- package/dist/ideal/peers.js.map +1 -1
- package/dist/ideal/refresh-ideal-graph.d.ts +0 -4
- package/dist/ideal/refresh-ideal-graph.d.ts.map +1 -1
- package/dist/ideal/refresh-ideal-graph.js +8 -24
- package/dist/ideal/refresh-ideal-graph.js.map +1 -1
- package/dist/ideal/sorting.d.ts +46 -0
- package/dist/ideal/sorting.d.ts.map +1 -0
- package/dist/ideal/sorting.js +71 -0
- package/dist/ideal/sorting.js.map +1 -0
- package/dist/ideal/types.d.ts +2 -6
- package/dist/ideal/types.d.ts.map +1 -1
- package/dist/ideal/types.js.map +1 -1
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +12 -0
- package/dist/install.js.map +1 -1
- package/dist/lockfile/load.d.ts.map +1 -1
- package/dist/lockfile/load.js +21 -0
- package/dist/lockfile/load.js.map +1 -1
- package/dist/lockfile/save.d.ts.map +1 -1
- package/dist/lockfile/save.js +2 -2
- package/dist/lockfile/save.js.map +1 -1
- package/dist/lockfile/types.d.ts +7 -0
- package/dist/lockfile/types.d.ts.map +1 -1
- package/dist/lockfile/types.js +6 -0
- package/dist/lockfile/types.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js.map +1 -1
- package/dist/reify/extract-node.d.ts.map +1 -1
- package/dist/reify/extract-node.js.map +1 -1
- package/dist/reify/index.d.ts +1 -0
- package/dist/reify/index.d.ts.map +1 -1
- package/dist/reify/index.js +2 -1
- package/dist/reify/index.js.map +1 -1
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +1 -0
- package/dist/update.js.map +1 -1
- package/dist/visualization/mermaid-output.d.ts +2 -1
- package/dist/visualization/mermaid-output.d.ts.map +1 -1
- package/dist/visualization/mermaid-output.js +28 -16
- package/dist/visualization/mermaid-output.js.map +1 -1
- package/package.json +22 -22
- package/dist/ideal/get-ordered-dependencies.d.ts +0 -10
- package/dist/ideal/get-ordered-dependencies.d.ts.map +0 -1
- package/dist/ideal/get-ordered-dependencies.js +0 -42
- package/dist/ideal/get-ordered-dependencies.js.map +0 -1
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,YAA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@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { checkNeededBuild } from './check-needed-build.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport type { NodeLike } from '@vltpkg/types'\nimport { binChmodAll } from './bin-chmod.ts'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n/**\n * Filter nodes using a DSS query string\n */\nconst filterNodesByQuery = async (\n graph: Graph,\n allowScriptsQuery?: string,\n): Promise<Set<DepID>> => {\n // shortcut no packages included\n if (\n allowScriptsQuery === ':not(*)' /* c8 ignore next */ ||\n !allowScriptsQuery\n ) {\n return new Set()\n }\n // shortcut all packages included\n if (allowScriptsQuery === '*') {\n return new Set(graph.nodes.keys())\n }\n /* c8 ignore start */\n const securityArchive =\n Query.hasSecuritySelectors(allowScriptsQuery) ?\n await SecurityArchive.start({\n nodes: [...graph.nodes.values()],\n })\n : undefined\n /* c8 ignore stop */\n\n const edges = graph.edges\n const nodes = new Set<NodeLike>(graph.nodes.values())\n const importers = graph.importers\n\n const query = new Query({\n edges,\n nodes,\n importers,\n securityArchive,\n })\n\n const { nodes: resultNodes } = await query.search(\n allowScriptsQuery,\n {\n signal: new AbortController().signal,\n },\n )\n\n return new Set(resultNodes.map(node => node.id))\n}\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n allowScripts: string\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n remover: RollbackRemove\n}\n\nexport type ReifyResult = {\n /**\n * The diff object that was used to reify the project.\n */\n diff: Diff\n /**\n * Optional queue of DepIDs that requires building (running lifecycle scripts\n * and binary linking) after the reification is complete.\n */\n buildQueue?: DepID[]\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (\n options: ReifyOptions,\n): Promise<ReifyResult> => {\n const done = graphStep('reify')\n\n const { graph, scurry, remover } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const noModifiedDependencies =\n !options.add?.modifiedDependencies &&\n !options.remove?.modifiedDependencies\n const skipOptionalOnly = noModifiedDependencies && diff.optionalOnly\n const res: ReifyResult = { diff }\n if (!diff.hasChanges() || skipOptionalOnly) {\n // nothing to do, so just return the diff\n done()\n return res\n }\n\n let success = false\n try {\n const { buildQueue } = await reify_(options, diff, remover)\n remover.confirm()\n success = true\n res.buildQueue = buildQueue\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return res\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n): Promise<Omit<ReifyResult, 'diff'>> => {\n const res: Omit<ReifyResult, 'diff'> = {}\n const {\n add,\n remove,\n packageInfo,\n packageJson,\n scurry,\n allowScripts,\n } = options\n const saveImportersPackageJson =\n /* c8 ignore next */\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions = addEdges(diff, scurry, remover)\n if (edgeActions.length) await callLimit(edgeActions, { limit })\n\n await internalHoist(diff.to, options, remover)\n\n // looks up all nodes setting buildState = 'needed'\n // on nodes that require building\n checkNeededBuild({ diff, scurry, packageJson })\n\n // Filter nodes allowed to run scripts if allowScripts query is provided\n const allowScriptsNodes = await filterNodesByQuery(\n diff.to,\n allowScripts,\n )\n\n // ensure that all added bins are chmod +x\n await binChmodAll(diff.nodes.add, scurry)\n\n // run install lifecycle scripts and link any binary files\n await build(diff, packageJson, scurry, allowScriptsNodes)\n\n // set the buildQueue on the result object containing\n // an array with all the ids of nodes that need building\n res.buildQueue = [...diff.nodes.add]\n .filter(node => node.buildState === 'needed')\n .map(node => node.id)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n // TODO: add tests to cover this\n /* c8 ignore start */\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n /* c8 ignore stop */\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n\n // returns the result object\n return res\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAKtD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;A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,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 update?: boolean\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 skippable = skipOptionalOnly && !options.update\n const res: ReifyResult = { diff }\n if (!diff.hasChanges() || skippable) {\n // nothing to do, so just return the diff\n done()\n return res\n }\n\n let success = false\n try {\n const { buildQueue } = await reify_(options, diff, remover)\n remover.confirm()\n success = true\n res.buildQueue = buildQueue\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return res\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n): Promise<Omit<ReifyResult, 'diff'>> => {\n const res: Omit<ReifyResult, 'diff'> = {}\n const {\n add,\n remove,\n packageInfo,\n packageJson,\n scurry,\n allowScripts,\n } = options\n const saveImportersPackageJson =\n /* c8 ignore next */\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions = addEdges(diff, scurry, remover)\n if (edgeActions.length) await callLimit(edgeActions, { limit })\n\n await internalHoist(diff.to, options, remover)\n\n // looks up all nodes setting buildState = 'needed'\n // on nodes that require building\n checkNeededBuild({ diff, scurry, packageJson })\n\n // Filter nodes allowed to run scripts if allowScripts query is provided\n const allowScriptsNodes = await filterNodesByQuery(\n diff.to,\n allowScripts,\n )\n\n // ensure that all added bins are chmod +x\n await binChmodAll(diff.nodes.add, scurry)\n\n // run install lifecycle scripts and link any binary files\n await build(diff, packageJson, scurry, allowScriptsNodes)\n\n // set the buildQueue on the result object containing\n // an array with all the ids of nodes that need building\n res.buildQueue = [...diff.nodes.add]\n .filter(node => node.buildState === 'needed')\n .map(node => node.id)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n // TODO: add tests to cover this\n /* c8 ignore start */\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n /* c8 ignore stop */\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n\n // returns the result object\n return res\n}\n"]}
|
package/dist/update.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAMlC,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACxC,WAAW,EAAE,iBAAiB,CAAA;IAC9B,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,MAAM,YAAmB,aAAa;;;;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAMlC,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACxC,WAAW,EAAE,iBAAiB,CAAA;IAC9B,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,MAAM,YAAmB,aAAa;;;;EAiElD,CAAA"}
|
package/dist/update.js
CHANGED
package/dist/update.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAA;AACxF,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAIvC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAOnC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IACrD,IAAI,YAAY,GAAmC,SAAS,CAAA;IAC5D,IAAI,CAAC;QACH,YAAY,GAAG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AoC;QACpC,IAAI,CAAC;YACH,MAAM,cAAc,GAAG,OAAO,CAC5B,OAAO,CAAC,WAAW,EACnB,6BAA6B,CAC9B,CAAA;YACD,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;gBAC/B,MAAM,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YACzC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QACV,MAAM,GAAG,CAAA;IACX,CAAC;IACD,oBAAoB;AACtB,CAAC,CAAA","sourcesContent":["import { load as actualLoad } from './actual/load.ts'\nimport { buildIdealFromStartingGraph } from './ideal/build-ideal-from-starting-graph.ts'\nimport { reify } from './reify/index.ts'\nimport { GraphModifier } from './modifiers.ts'\nimport { init } from '@vltpkg/init'\nimport { asError } from '@vltpkg/types'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { LoadOptions } from './actual/load.ts'\nimport { Graph } from './graph.ts'\nimport { graphStep } from '@vltpkg/output'\nimport { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { existsSync, rmSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nexport type UpdateOptions = LoadOptions & {\n packageInfo: PackageInfoClient\n allowScripts: string\n}\n\nexport const update = async (options: UpdateOptions) => {\n let mainManifest: NormalizedManifest | undefined = undefined\n try {\n mainManifest = options.packageJson.read(options.projectRoot)\n } catch (err) {\n if (asError(err).message === 'Could not read package.json file') {\n await init({ cwd: options.projectRoot })\n mainManifest = options.packageJson.read(options.projectRoot, {\n reload: true,\n })\n } else {\n throw err\n }\n }\n\n const modifiers = GraphModifier.maybeLoad(options)\n const remover = new RollbackRemove()\n\n try {\n const done = graphStep('build')\n const graph = await buildIdealFromStartingGraph({\n ...options,\n add: Object.assign(new Map(), { modifiedDependencies: false }),\n remove: Object.assign(new Map(), {\n modifiedDependencies: false,\n }),\n graph: new Graph({ ...options, mainManifest }),\n modifiers,\n remover,\n })\n done()\n\n const act = actualLoad({\n ...options,\n mainManifest,\n loadManifests: true,\n })\n\n const { buildQueue, diff } = await reify({\n ...options,\n actual: act,\n graph,\n loadManifests: true,\n modifiers,\n remover,\n update: true,\n })\n\n return { buildQueue, graph, diff }\n /* c8 ignore start */\n } catch (err) {\n await remover.rollback().catch(() => {})\n // Remove hidden lockfile on failure\n try {\n const hiddenLockfile = resolve(\n options.projectRoot,\n 'node_modules/.vlt-lock.json',\n )\n if (existsSync(hiddenLockfile)) {\n rmSync(hiddenLockfile, { force: true })\n }\n } catch {}\n throw err\n }\n /* c8 ignore stop */\n}\n"]}
|
|
@@ -3,6 +3,7 @@ export type MermaidOutputGraph = {
|
|
|
3
3
|
edges: EdgeLike[];
|
|
4
4
|
importers: Set<NodeLike>;
|
|
5
5
|
nodes: NodeLike[];
|
|
6
|
+
highlightSelection?: boolean;
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
8
9
|
* Generates a short identifier for a given index following the pattern:
|
|
@@ -13,5 +14,5 @@ export declare function generateShortId(index: number): string;
|
|
|
13
14
|
/**
|
|
14
15
|
* Returns a mermaid string representation of the graph.
|
|
15
16
|
*/
|
|
16
|
-
export declare function mermaidOutput(
|
|
17
|
+
export declare function mermaidOutput(options: MermaidOutputGraph): string;
|
|
17
18
|
//# sourceMappingURL=mermaid-output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid-output.d.ts","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"mermaid-output.d.ts","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAiBD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA0BrD;AA8ID;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,kBAAkB,UA8ExD"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Edge } from "../edge.js";
|
|
2
2
|
import { Node } from "../node.js";
|
|
3
3
|
let missingCount = 0;
|
|
4
|
+
const isSelected = (options, edge, node) => (!node || options.nodes.includes(node)) &&
|
|
5
|
+
/* c8 ignore next */ (!edge || options.edges.includes(edge));
|
|
4
6
|
/**
|
|
5
7
|
* Generates a short identifier for a given index following the pattern:
|
|
6
8
|
* 0 -> a, 1 -> b, ..., 25 -> z, 26 -> A, ..., 51 -> Z, 52 -> aa, 53 -> ab, etc.
|
|
@@ -58,29 +60,35 @@ function createDepIdMapping(importers) {
|
|
|
58
60
|
* been labeled. This tracking is shared across multiple importers to prevent duplicate
|
|
59
61
|
* labels in the output.
|
|
60
62
|
*/
|
|
61
|
-
const nodeRef = (node, labeledNodes, depIdMapping) => {
|
|
63
|
+
const nodeRef = (node, labeledNodes, depIdMapping, options) => {
|
|
62
64
|
const shortId = depIdMapping.get(node.id) /* c8 ignore next - should not be possible */ ?? '';
|
|
65
|
+
const selectedClass = (options.highlightSelection &&
|
|
66
|
+
isSelected(options, undefined, node)) ?
|
|
67
|
+
':::selected'
|
|
68
|
+
: '';
|
|
63
69
|
if (labeledNodes.has(node.id)) {
|
|
64
|
-
return shortId;
|
|
70
|
+
return shortId + selectedClass;
|
|
65
71
|
}
|
|
66
72
|
labeledNodes.add(node.id);
|
|
67
|
-
return `${shortId}("${String(node).replaceAll('@', '#64;')}")`;
|
|
73
|
+
return `${shortId}("${String(node).replaceAll('@', '#64;')}")${selectedClass}`;
|
|
68
74
|
};
|
|
69
|
-
function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, node, isImporter = false) {
|
|
75
|
+
function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, node, isImporter = false) {
|
|
70
76
|
if (seenNodes.has(node.id) || !includedItems.get(node)) {
|
|
71
77
|
return '';
|
|
72
78
|
}
|
|
73
79
|
seenNodes.add(node.id);
|
|
74
80
|
// For importers, render the node label first as a standalone line before processing edges,
|
|
75
81
|
// since they appear at the top of the graph. Non-importer nodes are labeled inline as part of edge definitions.
|
|
76
|
-
const nodeLabel = isImporter ?
|
|
82
|
+
const nodeLabel = isImporter ?
|
|
83
|
+
nodeRef(node, labeledNodes, depIdMapping, options)
|
|
84
|
+
: '';
|
|
77
85
|
// Include both regular edges and workspace edges (if any)
|
|
78
86
|
const allEdges = [
|
|
79
87
|
...node.edgesOut.values(),
|
|
80
88
|
...(node.workspaces?.values() ?? []),
|
|
81
89
|
];
|
|
82
90
|
const edges = allEdges
|
|
83
|
-
.map(e => parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, e))
|
|
91
|
+
.map(e => parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options, e))
|
|
84
92
|
.filter(Boolean)
|
|
85
93
|
.join('\n');
|
|
86
94
|
// Only render node standalone for importers, others are rendered as part of edges
|
|
@@ -90,12 +98,12 @@ function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, node, i
|
|
|
90
98
|
}
|
|
91
99
|
return edges;
|
|
92
100
|
}
|
|
93
|
-
function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, edge) {
|
|
101
|
+
function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options, edge) {
|
|
94
102
|
if (!includedItems.get(edge)) {
|
|
95
103
|
return '';
|
|
96
104
|
}
|
|
97
105
|
const edgeType = edge.type === 'prod' ? '' : ` (${edge.type})`;
|
|
98
|
-
const edgeResult = nodeRef(edge.from, labeledNodes, depIdMapping) +
|
|
106
|
+
const edgeResult = nodeRef(edge.from, labeledNodes, depIdMapping, options) +
|
|
99
107
|
` -->|"${String(edge.spec).replaceAll('@', '#64;')}${edgeType}"| `;
|
|
100
108
|
const missingLabel = edge.type.endsWith('ptional') ? 'Missing Optional' : 'Missing';
|
|
101
109
|
if (!edge.to) {
|
|
@@ -103,14 +111,15 @@ function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, edge) {
|
|
|
103
111
|
}
|
|
104
112
|
// Label the target node first so that if it's referenced again later in the graph,
|
|
105
113
|
// it will use the short identifier instead of repeating the full label.
|
|
106
|
-
const toRef = nodeRef(edge.to, labeledNodes, depIdMapping);
|
|
107
|
-
const childEdges = parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, edge.to);
|
|
114
|
+
const toRef = nodeRef(edge.to, labeledNodes, depIdMapping, options);
|
|
115
|
+
const childEdges = parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, edge.to);
|
|
108
116
|
return edgeResult + toRef + (childEdges ? '\n' + childEdges : '');
|
|
109
117
|
}
|
|
110
118
|
/**
|
|
111
119
|
* Returns a mermaid string representation of the graph.
|
|
112
120
|
*/
|
|
113
|
-
export function mermaidOutput(
|
|
121
|
+
export function mermaidOutput(options) {
|
|
122
|
+
const { edges, importers, nodes, highlightSelection } = options;
|
|
114
123
|
const seen = new Set();
|
|
115
124
|
const includedItems = new Map();
|
|
116
125
|
const traverse = new Set([...importers].map(i => ({ self: i, parent: undefined })));
|
|
@@ -155,10 +164,13 @@ export function mermaidOutput({ edges, importers, nodes, }) {
|
|
|
155
164
|
const labeledNodes = new Set();
|
|
156
165
|
// Track nodes that have been processed (shared across all importers to avoid duplicates)
|
|
157
166
|
const seenNodes = new Set();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
const graphOutput = [...importers]
|
|
168
|
+
.map(i => parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, i, true))
|
|
169
|
+
.filter(Boolean)
|
|
170
|
+
.join('\n');
|
|
171
|
+
const styleDefinition = highlightSelection ?
|
|
172
|
+
'\nclassDef selected fill:gold,color:#242424'
|
|
173
|
+
: '';
|
|
174
|
+
return 'flowchart TD\n' + graphOutput + styleDefinition;
|
|
163
175
|
}
|
|
164
176
|
//# sourceMappingURL=mermaid-output.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid-output.js","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAcjC,IAAI,YAAY,GAAG,CAAC,CAAA;AAEpB;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,IAAI,GAAG,EAAE,CAAA;IAEf,yDAAyD;IACzD,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE;QAC5C,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;YACf,aAAa;YACb,OAAO,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,CAAC,CAAA;QACxC,CAAC;aAAM,CAAC;YACN,cAAc;YACd,OAAO,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC,CAAA;IAED,+BAA+B;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,GAAG,GAAG,KAAK,GAAG,CAAC,CAAA,CAAC,wCAAwC;IAE5D,OAAO,GAAG,GAAG,CAAC,EAAE,CAAC;QACf,GAAG,E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ID } from '@vltpkg/dep-id'\nimport { Edge } from '../edge.ts'\nimport { Node } from '../node.ts'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\n\nexport type MermaidOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n}\n\ntype TraverseItem = {\n self: EdgeLike | NodeLike\n parent: EdgeLike | NodeLike | undefined\n}\n\nlet missingCount = 0\n\n/**\n * Generates a short identifier for a given index following the pattern:\n * 0 -> a, 1 -> b, ..., 25 -> z, 26 -> A, ..., 51 -> Z, 52 -> aa, 53 -> ab, etc.\n * This implements a bijective base-52 numbering system where a-z = 0-25, A-Z = 26-51\n */\nexport function generateShortId(index: number): string {\n const base = 52\n\n // Helper function to convert a digit (0-51) to character\n const digitToChar = (digit: number): string => {\n if (digit < 26) {\n // a-z (0-25)\n return String.fromCharCode(97 + digit)\n } else {\n // A-Z (26-51)\n return String.fromCharCode(65 + (digit - 26))\n }\n }\n\n // Bijective base-52 conversion\n let result = ''\n let num = index + 1 // Convert to 1-based for bijective base\n\n while (num > 0) {\n num-- // Adjust for 0-based indexing in each position\n const remainder = num % base\n result = digitToChar(remainder) + result\n num = Math.floor(num / base)\n }\n\n return result\n}\n\n/**\n * Creates a mapping from DepID to short identifier\n */\nfunction createDepIdMapping(\n importers: Set<NodeLike>,\n): Map<DepID, string> {\n const mapping = new Map<DepID, string>()\n const uniqueDepIds = new Set<DepID>()\n\n // Collect all unique DepIDs from nodes & importers\n const [importer] = importers\n if (importer) {\n for (const node of importer.graph.nodes.values()) {\n uniqueDepIds.add(node.id)\n }\n }\n\n // Create mapping for each unique DepID\n let index = 0\n for (const depId of uniqueDepIds) {\n mapping.set(depId, generateShortId(index++))\n }\n\n return mapping\n}\n\n/**\n * Returns a node reference: on the first occurrence of a node, returns the full label;\n * on subsequent occurrences, returns just the shortId.\n *\n * Note: Mutates the `labeledNodes` set as a side effect to track which nodes have already\n * been labeled. This tracking is shared across multiple importers to prevent duplicate\n * labels in the output.\n */\nconst nodeRef = (\n node: NodeLike,\n labeledNodes: Set<DepID>,\n depIdMapping: Map<DepID, string>,\n): string => {\n const shortId =\n depIdMapping.get(\n node.id,\n ) /* c8 ignore next - should not be possible */ ?? ''\n if (labeledNodes.has(node.id)) {\n return shortId\n }\n labeledNodes.add(node.id)\n return `${shortId}(\"${String(node).replaceAll('@', '#64;')}\")`\n}\n\nfunction parseNode(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n node: NodeLike,\n isImporter = false,\n) {\n if (seenNodes.has(node.id) || !includedItems.get(node)) {\n return ''\n }\n seenNodes.add(node.id)\n // For importers, render the node label first as a standalone line before processing edges,\n // since they appear at the top of the graph. Non-importer nodes are labeled inline as part of edge definitions.\n const nodeLabel =\n isImporter ? nodeRef(node, labeledNodes, depIdMapping) : ''\n // Include both regular edges and workspace edges (if any)\n const allEdges = [\n ...node.edgesOut.values(),\n ...(node.workspaces?.values() ?? []),\n ]\n const edges: string = allEdges\n .map(e =>\n parseEdge(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n e,\n ),\n )\n .filter(Boolean)\n .join('\\n')\n // Only render node standalone for importers, others are rendered as part of edges\n if (isImporter) {\n /* c8 ignore next */\n return `${nodeLabel}${edges.length ? '\\n' : ''}${edges}`\n }\n return edges\n}\n\nfunction parseEdge(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n edge: EdgeLike,\n) {\n if (!includedItems.get(edge)) {\n return ''\n }\n\n const edgeType = edge.type === 'prod' ? '' : ` (${edge.type})`\n const edgeResult =\n nodeRef(edge.from, labeledNodes, depIdMapping) +\n ` -->|\"${String(edge.spec).replaceAll('@', '#64;')}${edgeType}\"| `\n\n const missingLabel =\n edge.type.endsWith('ptional') ? 'Missing Optional' : 'Missing'\n if (!edge.to) {\n return edgeResult + `missing-${missingCount++}(${missingLabel})`\n }\n\n // Label the target node first so that if it's referenced again later in the graph,\n // it will use the short identifier instead of repeating the full label.\n const toRef = nodeRef(edge.to, labeledNodes, depIdMapping)\n const childEdges = parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n edge.to,\n )\n return edgeResult + toRef + (childEdges ? '\\n' + childEdges : '')\n}\n\n/**\n * Returns a mermaid string representation of the graph.\n */\nexport function mermaidOutput({\n edges,\n importers,\n nodes,\n}: MermaidOutputGraph) {\n const seen = new Set<EdgeLike | NodeLike>()\n const includedItems = new Map<EdgeLike | NodeLike, boolean>()\n const traverse = new Set<TraverseItem>(\n [...importers].map(i => ({ self: i, parent: undefined })),\n )\n\n for (const item of traverse) {\n if (seen.has(item.self)) continue\n seen.add(item.self)\n\n if (item.self instanceof Edge) {\n // Workspace edges are stored in mainImporter.workspaces and not in graph.edges,\n // so we need to check for workspace spec type to always include them\n if (\n edges.includes(item.self) ||\n item.self.spec.type === 'workspace'\n ) {\n includedItems.set(item.self, true)\n }\n if (item.self.to) {\n traverse.add({ self: item.self.to, parent: item.self })\n }\n }\n\n if (item.self instanceof Node) {\n if (nodes.includes(item.self)) {\n includedItems.set(item.self, true)\n }\n for (const edge of item.self.edgesOut.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n // Also traverse workspace edges (only mainImporter has these)\n if (item.self.workspaces) {\n for (const edge of item.self.workspaces.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n }\n }\n }\n\n for (const item of [...traverse].reverse()) {\n if (includedItems.has(item.self) && item.parent) {\n includedItems.set(item.parent, true)\n }\n }\n\n // Create DepID to short identifier mapping\n const depIdMapping = createDepIdMapping(importers)\n\n // Track nodes that have had their label printed (shared across all importers)\n const labeledNodes = new Set<DepID>()\n\n // Track nodes that have been processed (shared across all importers to avoid duplicates)\n const seenNodes = new Set<DepID>()\n\n return (\n 'flowchart TD\\n' +\n [...importers]\n .map(i =>\n parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n i,\n true, // isImporter\n ),\n )\n .filter(Boolean)\n .join('\\n')\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mermaid-output.js","sourceRoot":"","sources":["../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAejC,IAAI,YAAY,GAAG,CAAC,CAAA;AAEpB,MAAM,UAAU,GAAG,CACjB,OAA2B,EAC3B,IAAe,EACf,IAAe,EACf,EAAE,CACF,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvC,oBAAoB,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;AAE9D;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,IAAI,GAAG,EAAE,CAAA;IAEf,yDAAyD;IACzD,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE;QAC5C,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;YACf,aAAa;YACb,OAAO,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,CAAC,CAAA;QACxC,CAAC;aAAM,CAAC;YACN,cAAc;YACd,OAAO,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC,CAAA;IAED,+BAA+B;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,GAAG,GAAG,KAAK,GAAG,CAAC,CAAA,CAAC,wCAAwC;IAE5D,OAAO,GAAG,GAAG,CAAC,EAAE,CAAC;QACf,GAAG,EAAE,CAAA,CAAC,+CAA+C;QACrD,MAAM,SAAS,GAAG,GAAG,GAAG,IAAI,CAAA;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WAAW,GAAG,CAAC,GAAG,SAAS,CAAC;SAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,CACP,SAAS,CACP,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,OAAO,EACP,CAAC,EACD,IAAI,CACL,CACF;SACA,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,eAAe,GACnB,kBAAkB,CAAC,CAAC;QAClB,6CAA6C;QAC/C,CAAC,CAAC,EAAE,CAAA;IAEN,OAAO,gBAAgB,GAAG,WAAW,GAAG,eAAe,CAAA;AACzD,CAAC","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { Edge } from '../edge.ts'\nimport { Node } from '../node.ts'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\n\nexport type MermaidOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n highlightSelection?: boolean\n}\n\ntype TraverseItem = {\n self: EdgeLike | NodeLike\n parent: EdgeLike | NodeLike | undefined\n}\n\nlet missingCount = 0\n\nconst isSelected = (\n options: MermaidOutputGraph,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n (!node || options.nodes.includes(node)) &&\n /* c8 ignore next */ (!edge || options.edges.includes(edge))\n\n/**\n * Generates a short identifier for a given index following the pattern:\n * 0 -> a, 1 -> b, ..., 25 -> z, 26 -> A, ..., 51 -> Z, 52 -> aa, 53 -> ab, etc.\n * This implements a bijective base-52 numbering system where a-z = 0-25, A-Z = 26-51\n */\nexport function generateShortId(index: number): string {\n const base = 52\n\n // Helper function to convert a digit (0-51) to character\n const digitToChar = (digit: number): string => {\n if (digit < 26) {\n // a-z (0-25)\n return String.fromCharCode(97 + digit)\n } else {\n // A-Z (26-51)\n return String.fromCharCode(65 + (digit - 26))\n }\n }\n\n // Bijective base-52 conversion\n let result = ''\n let num = index + 1 // Convert to 1-based for bijective base\n\n while (num > 0) {\n num-- // Adjust for 0-based indexing in each position\n const remainder = num % base\n result = digitToChar(remainder) + result\n num = Math.floor(num / base)\n }\n\n return result\n}\n\n/**\n * Creates a mapping from DepID to short identifier\n */\nfunction createDepIdMapping(\n importers: Set<NodeLike>,\n): Map<DepID, string> {\n const mapping = new Map<DepID, string>()\n const uniqueDepIds = new Set<DepID>()\n\n // Collect all unique DepIDs from nodes & importers\n const [importer] = importers\n if (importer) {\n for (const node of importer.graph.nodes.values()) {\n uniqueDepIds.add(node.id)\n }\n }\n\n // Create mapping for each unique DepID\n let index = 0\n for (const depId of uniqueDepIds) {\n mapping.set(depId, generateShortId(index++))\n }\n\n return mapping\n}\n\n/**\n * Returns a node reference: on the first occurrence of a node, returns the full label;\n * on subsequent occurrences, returns just the shortId.\n *\n * Note: Mutates the `labeledNodes` set as a side effect to track which nodes have already\n * been labeled. This tracking is shared across multiple importers to prevent duplicate\n * labels in the output.\n */\nconst nodeRef = (\n node: NodeLike,\n labeledNodes: Set<DepID>,\n depIdMapping: Map<DepID, string>,\n options: MermaidOutputGraph,\n): string => {\n const shortId =\n depIdMapping.get(\n node.id,\n ) /* c8 ignore next - should not be possible */ ?? ''\n const selectedClass =\n (\n options.highlightSelection &&\n isSelected(options, undefined, node)\n ) ?\n ':::selected'\n : ''\n if (labeledNodes.has(node.id)) {\n return shortId + selectedClass\n }\n labeledNodes.add(node.id)\n return `${shortId}(\"${String(node).replaceAll('@', '#64;')}\")${selectedClass}`\n}\n\nfunction parseNode(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n options: MermaidOutputGraph,\n node: NodeLike,\n isImporter = false,\n) {\n if (seenNodes.has(node.id) || !includedItems.get(node)) {\n return ''\n }\n seenNodes.add(node.id)\n // For importers, render the node label first as a standalone line before processing edges,\n // since they appear at the top of the graph. Non-importer nodes are labeled inline as part of edge definitions.\n const nodeLabel =\n isImporter ?\n nodeRef(node, labeledNodes, depIdMapping, options)\n : ''\n // Include both regular edges and workspace edges (if any)\n const allEdges = [\n ...node.edgesOut.values(),\n ...(node.workspaces?.values() ?? []),\n ]\n const edges: string = allEdges\n .map(e =>\n parseEdge(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n options,\n e,\n ),\n )\n .filter(Boolean)\n .join('\\n')\n // Only render node standalone for importers, others are rendered as part of edges\n if (isImporter) {\n /* c8 ignore next */\n return `${nodeLabel}${edges.length ? '\\n' : ''}${edges}`\n }\n return edges\n}\n\nfunction parseEdge(\n seenNodes: Set<DepID>,\n labeledNodes: Set<DepID>,\n includedItems: Map<EdgeLike | NodeLike, boolean>,\n depIdMapping: Map<DepID, string>,\n options: MermaidOutputGraph,\n edge: EdgeLike,\n) {\n if (!includedItems.get(edge)) {\n return ''\n }\n\n const edgeType = edge.type === 'prod' ? '' : ` (${edge.type})`\n const edgeResult =\n nodeRef(edge.from, labeledNodes, depIdMapping, options) +\n ` -->|\"${String(edge.spec).replaceAll('@', '#64;')}${edgeType}\"| `\n\n const missingLabel =\n edge.type.endsWith('ptional') ? 'Missing Optional' : 'Missing'\n if (!edge.to) {\n return edgeResult + `missing-${missingCount++}(${missingLabel})`\n }\n\n // Label the target node first so that if it's referenced again later in the graph,\n // it will use the short identifier instead of repeating the full label.\n const toRef = nodeRef(edge.to, labeledNodes, depIdMapping, options)\n const childEdges = parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n options,\n edge.to,\n )\n return edgeResult + toRef + (childEdges ? '\\n' + childEdges : '')\n}\n\n/**\n * Returns a mermaid string representation of the graph.\n */\nexport function mermaidOutput(options: MermaidOutputGraph) {\n const { edges, importers, nodes, highlightSelection } = options\n const seen = new Set<EdgeLike | NodeLike>()\n const includedItems = new Map<EdgeLike | NodeLike, boolean>()\n const traverse = new Set<TraverseItem>(\n [...importers].map(i => ({ self: i, parent: undefined })),\n )\n\n for (const item of traverse) {\n if (seen.has(item.self)) continue\n seen.add(item.self)\n\n if (item.self instanceof Edge) {\n // Workspace edges are stored in mainImporter.workspaces and not in graph.edges,\n // so we need to check for workspace spec type to always include them\n if (\n edges.includes(item.self) ||\n item.self.spec.type === 'workspace'\n ) {\n includedItems.set(item.self, true)\n }\n if (item.self.to) {\n traverse.add({ self: item.self.to, parent: item.self })\n }\n }\n\n if (item.self instanceof Node) {\n if (nodes.includes(item.self)) {\n includedItems.set(item.self, true)\n }\n for (const edge of item.self.edgesOut.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n // Also traverse workspace edges (only mainImporter has these)\n if (item.self.workspaces) {\n for (const edge of item.self.workspaces.values()) {\n traverse.add({ self: edge, parent: item.self })\n }\n }\n }\n }\n\n for (const item of [...traverse].reverse()) {\n if (includedItems.has(item.self) && item.parent) {\n includedItems.set(item.parent, true)\n }\n }\n\n // Create DepID to short identifier mapping\n const depIdMapping = createDepIdMapping(importers)\n\n // Track nodes that have had their label printed (shared across all importers)\n const labeledNodes = new Set<DepID>()\n\n // Track nodes that have been processed (shared across all importers to avoid duplicates)\n const seenNodes = new Set<DepID>()\n\n const graphOutput = [...importers]\n .map(i =>\n parseNode(\n seenNodes,\n labeledNodes,\n includedItems,\n depIdMapping,\n options,\n i,\n true, // isImporter\n ),\n )\n .filter(Boolean)\n .join('\\n')\n\n const styleDefinition =\n highlightSelection ?\n '\\nclassDef selected fill:gold,color:#242424'\n : ''\n\n return 'flowchart TD\\n' + graphOutput + styleDefinition\n}\n"]}
|
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.15",
|
|
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/
|
|
17
|
-
"@vltpkg/
|
|
18
|
-
"@vltpkg/
|
|
19
|
-
"@vltpkg/graph-run": "1.0.0-rc.
|
|
20
|
-
"@vltpkg/
|
|
21
|
-
"@vltpkg/
|
|
22
|
-
"@vltpkg/package-info": "1.0.0-rc.
|
|
23
|
-
"@vltpkg/package-json": "1.0.0-rc.
|
|
24
|
-
"@vltpkg/pick-manifest": "1.0.0-rc.
|
|
25
|
-
"@vltpkg/
|
|
26
|
-
"@vltpkg/
|
|
27
|
-
"@vltpkg/run": "1.0.0-rc.
|
|
28
|
-
"@vltpkg/satisfies": "1.0.0-rc.
|
|
29
|
-
"@vltpkg/security-archive": "1.0.0-rc.
|
|
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.15",
|
|
15
|
+
"@vltpkg/dep-id": "1.0.0-rc.15",
|
|
16
|
+
"@vltpkg/dss-breadcrumb": "1.0.0-rc.15",
|
|
17
|
+
"@vltpkg/error-cause": "1.0.0-rc.15",
|
|
18
|
+
"@vltpkg/fast-split": "1.0.0-rc.15",
|
|
19
|
+
"@vltpkg/graph-run": "1.0.0-rc.15",
|
|
20
|
+
"@vltpkg/init": "1.0.0-rc.15",
|
|
21
|
+
"@vltpkg/output": "1.0.0-rc.15",
|
|
22
|
+
"@vltpkg/package-info": "1.0.0-rc.15",
|
|
23
|
+
"@vltpkg/package-json": "1.0.0-rc.15",
|
|
24
|
+
"@vltpkg/pick-manifest": "1.0.0-rc.15",
|
|
25
|
+
"@vltpkg/query": "1.0.0-rc.15",
|
|
26
|
+
"@vltpkg/rollback-remove": "1.0.0-rc.15",
|
|
27
|
+
"@vltpkg/run": "1.0.0-rc.15",
|
|
28
|
+
"@vltpkg/satisfies": "1.0.0-rc.15",
|
|
29
|
+
"@vltpkg/security-archive": "1.0.0-rc.15",
|
|
30
|
+
"@vltpkg/spec": "1.0.0-rc.15",
|
|
31
|
+
"@vltpkg/types": "1.0.0-rc.15",
|
|
32
|
+
"@vltpkg/vlt-json": "1.0.0-rc.15",
|
|
33
|
+
"@vltpkg/workspaces": "1.0.0-rc.15"
|
|
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.15"
|
|
46
46
|
},
|
|
47
47
|
"license": "BSD-2-Clause-Patent",
|
|
48
48
|
"engines": {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Node } from '../node.ts';
|
|
2
|
-
import type { Dependency } from '../dependencies.ts';
|
|
3
|
-
import type { BuildIdealAddOptions, BuildIdealRemoveOptions } from './types.ts';
|
|
4
|
-
/**
|
|
5
|
-
* Computes the ordered list of dependencies for an given node,
|
|
6
|
-
* taking into account additions and removals.
|
|
7
|
-
*/
|
|
8
|
-
export declare const getNodeOrderedDependencies: (fromNode: Node, options?: BuildIdealAddOptions & BuildIdealRemoveOptions) => Dependency[];
|
|
9
|
-
export declare const getOrderedDependencies: (deps: Dependency[]) => Dependency[];
|
|
10
|
-
//# sourceMappingURL=get-ordered-dependencies.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-ordered-dependencies.d.ts","sourceRoot":"","sources":["../../src/ideal/get-ordered-dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EACV,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAEnB;;;GAGG;AACH,eAAO,MAAM,0BAA0B,aAC3B,IAAI,YACJ,oBAAoB,GAAG,uBAAuB,KACvD,UAAU,EAyBZ,CAAA;AAED,eAAO,MAAM,sBAAsB,SAC3B,UAAU,EAAE,KACjB,UAAU,EAiBZ,CAAA"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Computes the ordered list of dependencies for an given node,
|
|
3
|
-
* taking into account additions and removals.
|
|
4
|
-
*/
|
|
5
|
-
export const getNodeOrderedDependencies = (fromNode, options) => {
|
|
6
|
-
// using a map here instead of an array helps us get simpler
|
|
7
|
-
// deduplication while iterating through all the items at hand:
|
|
8
|
-
// existing dependencies in the graph, dependencies to be added, etc.
|
|
9
|
-
const deps = new Map();
|
|
10
|
-
for (const [name, { spec, type }] of fromNode.edgesOut.entries()) {
|
|
11
|
-
deps.set(name, { spec, type });
|
|
12
|
-
}
|
|
13
|
-
// next iterate through the list of dependencies to be added
|
|
14
|
-
const addedDeps = options?.add.get(fromNode.id);
|
|
15
|
-
if (addedDeps) {
|
|
16
|
-
for (const [name, { spec, type }] of addedDeps.entries()) {
|
|
17
|
-
deps.set(name, { spec, type });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// finally iterate through the list of dependencies to be removed
|
|
21
|
-
const removedDeps = options?.remove.get(fromNode.id);
|
|
22
|
-
if (removedDeps) {
|
|
23
|
-
for (const name of removedDeps) {
|
|
24
|
-
deps.delete(name);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// now turn the map into a sorted array
|
|
28
|
-
return getOrderedDependencies([...deps.values()]);
|
|
29
|
-
};
|
|
30
|
-
export const getOrderedDependencies = (deps) => {
|
|
31
|
-
const orderedDeps = [...deps].sort(({ spec: aSpec, type: aType }, { spec: bSpec, type: bType }) => {
|
|
32
|
-
const aIsPeer = aType === 'peer' || aType === 'peerOptional' ? 1 : 0;
|
|
33
|
-
const bIsPeer = bType === 'peer' || bType === 'peerOptional' ? 1 : 0;
|
|
34
|
-
// regular dependencies first, peer dependencies last
|
|
35
|
-
if (aIsPeer !== bIsPeer) {
|
|
36
|
-
return aIsPeer - bIsPeer;
|
|
37
|
-
}
|
|
38
|
-
return aSpec.name.localeCompare(bSpec.name, 'en');
|
|
39
|
-
});
|
|
40
|
-
return orderedDeps;
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=get-ordered-dependencies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-ordered-dependencies.js","sourceRoot":"","sources":["../../src/ideal/get-ordered-dependencies.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,QAAc,EACd,OAAwD,EAC1C,EAAE;IAChB,4DAA4D;IAC5D,+DAA+D;IAC/D,qEAAqE;IACrE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC1C,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QACjE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IAChC,CAAC;IACD,4DAA4D;IAC5D,MAAM,SAAS,GAAG,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC/C,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,C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,CAAA","sourcesContent":["import type { Node } from '../node.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type {\n BuildIdealAddOptions,\n BuildIdealRemoveOptions,\n} from './types.ts'\n\n/**\n * Computes the ordered list of dependencies for an given node,\n * taking into account additions and removals.\n */\nexport const getNodeOrderedDependencies = (\n fromNode: Node,\n options?: BuildIdealAddOptions & BuildIdealRemoveOptions,\n): Dependency[] => {\n // using a map here instead of an array helps us get simpler\n // deduplication while iterating through all the items at hand:\n // existing dependencies in the graph, dependencies to be added, etc.\n const deps = new Map<string, Dependency>()\n for (const [name, { spec, type }] of fromNode.edgesOut.entries()) {\n deps.set(name, { spec, type })\n }\n // next iterate through the list of dependencies to be added\n const addedDeps = options?.add.get(fromNode.id)\n if (addedDeps) {\n for (const [name, { spec, type }] of addedDeps.entries()) {\n deps.set(name, { spec, type })\n }\n }\n // finally iterate through the list of dependencies to be removed\n const removedDeps = options?.remove.get(fromNode.id)\n if (removedDeps) {\n for (const name of removedDeps) {\n deps.delete(name)\n }\n }\n\n // now turn the map into a sorted array\n return getOrderedDependencies([...deps.values()])\n}\n\nexport const getOrderedDependencies = (\n deps: Dependency[],\n): Dependency[] => {\n const orderedDeps = [...deps].sort(\n ({ spec: aSpec, type: aType }, { spec: bSpec, type: bType }) => {\n const aIsPeer =\n aType === 'peer' || aType === 'peerOptional' ? 1 : 0\n const bIsPeer =\n bType === 'peer' || bType === 'peerOptional' ? 1 : 0\n\n // regular dependencies first, peer dependencies last\n if (aIsPeer !== bIsPeer) {\n return aIsPeer - bIsPeer\n }\n\n return aSpec.name.localeCompare(bSpec.name, 'en')\n },\n )\n return orderedDeps\n}\n"]}
|