@vltpkg/graph 0.0.0-0.1730239248325
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/LICENSE +15 -0
- package/README.md +33 -0
- package/dist/esm/actual/load.d.ts +54 -0
- package/dist/esm/actual/load.d.ts.map +1 -0
- package/dist/esm/actual/load.js +243 -0
- package/dist/esm/actual/load.js.map +1 -0
- package/dist/esm/browser.d.ts +9 -0
- package/dist/esm/browser.d.ts.map +1 -0
- package/dist/esm/browser.js +11 -0
- package/dist/esm/browser.js.map +1 -0
- package/dist/esm/dependencies.d.ts +69 -0
- package/dist/esm/dependencies.d.ts.map +1 -0
- package/dist/esm/dependencies.js +71 -0
- package/dist/esm/dependencies.js.map +1 -0
- package/dist/esm/diff.d.ts +49 -0
- package/dist/esm/diff.d.ts.map +1 -0
- package/dist/esm/diff.js +123 -0
- package/dist/esm/diff.js.map +1 -0
- package/dist/esm/edge.d.ts +41 -0
- package/dist/esm/edge.d.ts.map +1 -0
- package/dist/esm/edge.js +66 -0
- package/dist/esm/edge.js.map +1 -0
- package/dist/esm/graph.d.ts +123 -0
- package/dist/esm/graph.d.ts.map +1 -0
- package/dist/esm/graph.js +301 -0
- package/dist/esm/graph.js.map +1 -0
- package/dist/esm/ideal/add-nodes.d.ts +19 -0
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/add-nodes.js +28 -0
- package/dist/esm/ideal/add-nodes.js.map +1 -0
- package/dist/esm/ideal/append-nodes.d.ts +9 -0
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/append-nodes.js +121 -0
- package/dist/esm/ideal/append-nodes.js.map +1 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts +15 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +28 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -0
- package/dist/esm/ideal/build.d.ts +32 -0
- package/dist/esm/ideal/build.d.ts.map +1 -0
- package/dist/esm/ideal/build.js +42 -0
- package/dist/esm/ideal/build.js.map +1 -0
- package/dist/esm/ideal/get-importer-specs.d.ts +13 -0
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -0
- package/dist/esm/ideal/get-importer-specs.js +76 -0
- package/dist/esm/ideal/get-importer-specs.js.map +1 -0
- package/dist/esm/ideal/remove-nodes.d.ts +7 -0
- package/dist/esm/ideal/remove-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/remove-nodes.js +19 -0
- package/dist/esm/ideal/remove-nodes.js.map +1 -0
- package/dist/esm/ideal/remove-satisfied-specs.d.ts +8 -0
- package/dist/esm/ideal/remove-satisfied-specs.d.ts.map +1 -0
- package/dist/esm/ideal/remove-satisfied-specs.js +35 -0
- package/dist/esm/ideal/remove-satisfied-specs.js.map +1 -0
- package/dist/esm/ideal/types.d.ts +35 -0
- package/dist/esm/ideal/types.d.ts.map +1 -0
- package/dist/esm/ideal/types.js +2 -0
- package/dist/esm/ideal/types.js.map +1 -0
- package/dist/esm/index.d.ts +31 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lockfile/load-edges.d.ts +5 -0
- package/dist/esm/lockfile/load-edges.d.ts.map +1 -0
- package/dist/esm/lockfile/load-edges.js +40 -0
- package/dist/esm/lockfile/load-edges.js.map +1 -0
- package/dist/esm/lockfile/load-nodes.d.ts +4 -0
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -0
- package/dist/esm/lockfile/load-nodes.js +28 -0
- package/dist/esm/lockfile/load-nodes.js.map +1 -0
- package/dist/esm/lockfile/load.d.ts +33 -0
- package/dist/esm/lockfile/load.d.ts.map +1 -0
- package/dist/esm/lockfile/load.js +53 -0
- package/dist/esm/lockfile/load.js.map +1 -0
- package/dist/esm/lockfile/save.d.ts +18 -0
- package/dist/esm/lockfile/save.d.ts.map +1 -0
- package/dist/esm/lockfile/save.js +128 -0
- package/dist/esm/lockfile/save.js.map +1 -0
- package/dist/esm/lockfile/types.d.ts +60 -0
- package/dist/esm/lockfile/types.d.ts.map +1 -0
- package/dist/esm/lockfile/types.js +13 -0
- package/dist/esm/lockfile/types.js.map +1 -0
- package/dist/esm/node.d.ts +144 -0
- package/dist/esm/node.d.ts.map +1 -0
- package/dist/esm/node.js +266 -0
- package/dist/esm/node.js.map +1 -0
- package/dist/esm/non-empty-list.d.ts +3 -0
- package/dist/esm/non-empty-list.d.ts.map +1 -0
- package/dist/esm/non-empty-list.js +3 -0
- package/dist/esm/non-empty-list.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/reify/add-edge.d.ts +11 -0
- package/dist/esm/reify/add-edge.d.ts.map +1 -0
- package/dist/esm/reify/add-edge.js +43 -0
- package/dist/esm/reify/add-edge.js.map +1 -0
- package/dist/esm/reify/add-edges.d.ts +6 -0
- package/dist/esm/reify/add-edges.d.ts.map +1 -0
- package/dist/esm/reify/add-edges.js +13 -0
- package/dist/esm/reify/add-edges.js.map +1 -0
- package/dist/esm/reify/add-nodes.d.ts +7 -0
- package/dist/esm/reify/add-nodes.d.ts.map +1 -0
- package/dist/esm/reify/add-nodes.js +37 -0
- package/dist/esm/reify/add-nodes.js.map +1 -0
- package/dist/esm/reify/bin-paths.d.ts +4 -0
- package/dist/esm/reify/bin-paths.d.ts.map +1 -0
- package/dist/esm/reify/bin-paths.js +23 -0
- package/dist/esm/reify/bin-paths.js.map +1 -0
- package/dist/esm/reify/build.d.ts +5 -0
- package/dist/esm/reify/build.d.ts.map +1 -0
- package/dist/esm/reify/build.js +90 -0
- package/dist/esm/reify/build.js.map +1 -0
- package/dist/esm/reify/delete-edge.d.ts +5 -0
- package/dist/esm/reify/delete-edge.d.ts.map +1 -0
- package/dist/esm/reify/delete-edge.js +29 -0
- package/dist/esm/reify/delete-edge.js.map +1 -0
- package/dist/esm/reify/delete-edges.d.ts +5 -0
- package/dist/esm/reify/delete-edges.d.ts.map +1 -0
- package/dist/esm/reify/delete-edges.js +14 -0
- package/dist/esm/reify/delete-edges.js.map +1 -0
- package/dist/esm/reify/delete-nodes.d.ts +5 -0
- package/dist/esm/reify/delete-nodes.d.ts.map +1 -0
- package/dist/esm/reify/delete-nodes.js +12 -0
- package/dist/esm/reify/delete-nodes.js.map +1 -0
- package/dist/esm/reify/index.d.ts +16 -0
- package/dist/esm/reify/index.d.ts.map +1 -0
- package/dist/esm/reify/index.js +85 -0
- package/dist/esm/reify/index.js.map +1 -0
- package/dist/esm/reify/optional-fail.d.ts +16 -0
- package/dist/esm/reify/optional-fail.d.ts.map +1 -0
- package/dist/esm/reify/optional-fail.js +16 -0
- package/dist/esm/reify/optional-fail.js.map +1 -0
- package/dist/esm/reify/rollback.d.ts +5 -0
- package/dist/esm/reify/rollback.d.ts.map +1 -0
- package/dist/esm/reify/rollback.js +24 -0
- package/dist/esm/reify/rollback.js.map +1 -0
- package/dist/esm/reify/update-importers-package-json.d.ts +36 -0
- package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -0
- package/dist/esm/reify/update-importers-package-json.js +95 -0
- package/dist/esm/reify/update-importers-package-json.js.map +1 -0
- package/dist/esm/remove-optional-subgraph.d.ts +34 -0
- package/dist/esm/remove-optional-subgraph.d.ts.map +1 -0
- package/dist/esm/remove-optional-subgraph.js +48 -0
- package/dist/esm/remove-optional-subgraph.js.map +1 -0
- package/dist/esm/stringify-node.d.ts +3 -0
- package/dist/esm/stringify-node.d.ts.map +1 -0
- package/dist/esm/stringify-node.js +24 -0
- package/dist/esm/stringify-node.js.map +1 -0
- package/dist/esm/types.d.ts +39 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/visualization/human-readable-output.d.ts +25 -0
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -0
- package/dist/esm/visualization/human-readable-output.js +132 -0
- package/dist/esm/visualization/human-readable-output.js.map +1 -0
- package/dist/esm/visualization/json-output.d.ts +37 -0
- package/dist/esm/visualization/json-output.d.ts.map +1 -0
- package/dist/esm/visualization/json-output.js +28 -0
- package/dist/esm/visualization/json-output.js.map +1 -0
- package/dist/esm/visualization/mermaid-output.d.ts +11 -0
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -0
- package/dist/esm/visualization/mermaid-output.js +68 -0
- package/dist/esm/visualization/mermaid-output.js.map +1 -0
- package/dist/esm/visualization/object-like-output.d.ts +3 -0
- package/dist/esm/visualization/object-like-output.d.ts.map +1 -0
- package/dist/esm/visualization/object-like-output.js +49 -0
- package/dist/esm/visualization/object-like-output.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import { PathScurry } from 'path-scurry';
|
|
3
|
+
import { Edge } from '../edge.js';
|
|
4
|
+
export declare const deleteEdge: (edge: Edge, scurry: PathScurry, remover: RollbackRemove) => Promise<void>;
|
|
5
|
+
//# sourceMappingURL=delete-edge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-edge.d.ts","sourceRoot":"","sources":["../../../src/reify/delete-edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAiBjC,eAAO,MAAM,UAAU,SACf,IAAI,UACF,UAAU,WACT,cAAc,kBAmBxB,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { binPaths } from './bin-paths.js';
|
|
2
|
+
const rmBinPosix = (remover, bin) => {
|
|
3
|
+
return [remover.rm(bin)];
|
|
4
|
+
};
|
|
5
|
+
const rmBinWin32 = (remover, bin) => {
|
|
6
|
+
return [
|
|
7
|
+
remover.rm(bin),
|
|
8
|
+
remover.rm(bin + '.cmd'),
|
|
9
|
+
remover.rm(bin + '.pwsh'),
|
|
10
|
+
];
|
|
11
|
+
};
|
|
12
|
+
const rmBin = process.platform === 'win32' ? rmBinWin32 : rmBinPosix;
|
|
13
|
+
export const deleteEdge = async (edge, scurry, remover) => {
|
|
14
|
+
const { spec: { name }, to, } = edge;
|
|
15
|
+
const nm = edge.from.nodeModules;
|
|
16
|
+
const path = scurry.resolve(nm, name);
|
|
17
|
+
const binRoot = scurry.cwd.resolve(`${nm}/.bin`);
|
|
18
|
+
const promises = [];
|
|
19
|
+
promises.push(remover.rm(path));
|
|
20
|
+
const manifest = to?.manifest;
|
|
21
|
+
if (manifest) {
|
|
22
|
+
for (const key of Object.keys(binPaths(manifest))) {
|
|
23
|
+
const bin = binRoot.resolve(key).fullpath();
|
|
24
|
+
promises.push(...rmBin(remover, bin));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
await Promise.all(promises);
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=delete-edge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-edge.js","sourceRoot":"","sources":["../../../src/reify/delete-edge.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,UAAU,GAAG,CAAC,OAAuB,EAAE,GAAW,EAAE,EAAE;IAC1D,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;AAC1B,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,OAAuB,EAAE,GAAW,EAAE,EAAE;IAC1D,OAAO;QACL,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC;QACf,OAAO,CAAC,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC;QACxB,OAAO,CAAC,EAAE,CAAC,GAAG,GAAG,OAAO,CAAC;KAC1B,CAAA;AACH,CAAC,CAAA;AAED,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAA;AAEpE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,IAAU,EACV,MAAkB,EAClB,OAAuB,EACvB,EAAE;IACF,MAAM,EACJ,IAAI,EAAE,EAAE,IAAI,EAAE,EACd,EAAE,GACH,GAAG,IAAI,CAAA;IACR,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAA;IAChC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAChD,MAAM,QAAQ,GAAuB,EAAE,CAAA;IACvC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IAC/B,MAAM,QAAQ,GAAG,EAAE,EAAE,QAAQ,CAAA;IAC7B,IAAI,QAAQ,EAAE,CAAC;QACb,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAA;YAC3C,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["import { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { PathScurry } from 'path-scurry'\nimport { Edge } from '../edge.js'\nimport { binPaths } from './bin-paths.js'\n\nconst rmBinPosix = (remover: RollbackRemove, bin: string) => {\n return [remover.rm(bin)]\n}\n\nconst rmBinWin32 = (remover: RollbackRemove, bin: string) => {\n return [\n remover.rm(bin),\n remover.rm(bin + '.cmd'),\n remover.rm(bin + '.pwsh'),\n ]\n}\n\nconst rmBin = process.platform === 'win32' ? rmBinWin32 : rmBinPosix\n\nexport const deleteEdge = async (\n edge: Edge,\n scurry: PathScurry,\n remover: RollbackRemove,\n) => {\n const {\n spec: { name },\n to,\n } = edge\n const nm = edge.from.nodeModules\n const path = scurry.resolve(nm, name)\n const binRoot = scurry.cwd.resolve(`${nm}/.bin`)\n const promises: Promise<unknown>[] = []\n promises.push(remover.rm(path))\n const manifest = to?.manifest\n if (manifest) {\n for (const key of Object.keys(binPaths(manifest))) {\n const bin = binRoot.resolve(key).fullpath()\n promises.push(...rmBin(remover, bin))\n }\n }\n await Promise.all(promises)\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import { PathScurry } from 'path-scurry';
|
|
3
|
+
import { Diff } from '../diff.js';
|
|
4
|
+
export declare const deleteEdges: (diff: Diff, scurry: PathScurry, remover: RollbackRemove) => (() => Promise<unknown>)[];
|
|
5
|
+
//# sourceMappingURL=delete-edges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-edges.d.ts","sourceRoot":"","sources":["../../../src/reify/delete-edges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,eAAO,MAAM,WAAW,SAChB,IAAI,UACF,UAAU,WACT,cAAc,KACtB,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,EAW1B,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { deleteEdge } from './delete-edge.js';
|
|
2
|
+
export const deleteEdges = (diff, scurry, remover) => {
|
|
3
|
+
const promises = [];
|
|
4
|
+
for (const edge of diff.edges.delete) {
|
|
5
|
+
// if the edge.from is a deleted node in the store, no need
|
|
6
|
+
// the entire dir will be removed in a later step.
|
|
7
|
+
if (diff.nodes.delete.has(edge.from) && edge.from.inVltStore()) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
promises.push(() => deleteEdge(edge, scurry, remover));
|
|
11
|
+
}
|
|
12
|
+
return promises;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=delete-edges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-edges.js","sourceRoot":"","sources":["../../../src/reify/delete-edges.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAU,EACV,MAAkB,EAClB,OAAuB,EACK,EAAE;IAC9B,MAAM,QAAQ,GAA+B,EAAE,CAAA;IAC/C,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACrC,2DAA2D;QAC3D,kDAAkD;QAClD,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YAC/D,SAAQ;QACV,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { PathScurry } from 'path-scurry'\nimport { Diff } from '../diff.js'\nimport { deleteEdge } from './delete-edge.js'\n\nexport const deleteEdges = (\n diff: Diff,\n scurry: PathScurry,\n remover: RollbackRemove,\n): (() => Promise<unknown>)[] => {\n const promises: (() => Promise<unknown>)[] = []\n for (const edge of diff.edges.delete) {\n // if the edge.from is a deleted node in the store, no need\n // the entire dir will be removed in a later step.\n if (diff.nodes.delete.has(edge.from) && edge.from.inVltStore()) {\n continue\n }\n promises.push(() => deleteEdge(edge, scurry, remover))\n }\n return promises\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import { PathScurry } from 'path-scurry';
|
|
3
|
+
import { Diff } from '../diff.js';
|
|
4
|
+
export declare const deleteNodes: (diff: Diff, remover: RollbackRemove, scurry: PathScurry) => Promise<unknown>[];
|
|
5
|
+
//# sourceMappingURL=delete-nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-nodes.d.ts","sourceRoot":"","sources":["../../../src/reify/delete-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,eAAO,MAAM,WAAW,SAChB,IAAI,WACD,cAAc,UACf,UAAU,KACjB,OAAO,CAAC,OAAO,CAAC,EASlB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const deleteNodes = (diff, remover, scurry) => {
|
|
2
|
+
const store = scurry.resolve('node_modules/.vlt');
|
|
3
|
+
const rmActions = [];
|
|
4
|
+
for (const node of diff.nodes.delete) {
|
|
5
|
+
// do not delete workspaces or link targets
|
|
6
|
+
if (!node.inVltStore())
|
|
7
|
+
continue;
|
|
8
|
+
rmActions.push(remover.rm(scurry.resolve(store, node.id)));
|
|
9
|
+
}
|
|
10
|
+
return rmActions;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=delete-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-nodes.js","sourceRoot":"","sources":["../../../src/reify/delete-nodes.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAU,EACV,OAAuB,EACvB,MAAkB,EACE,EAAE;IACtB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IACjD,MAAM,SAAS,GAAuB,EAAE,CAAA;IACxC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACrC,2CAA2C;QAC3C,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAAE,SAAQ;QAChC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA","sourcesContent":["import { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { PathScurry } from 'path-scurry'\nimport { Diff } from '../diff.js'\n\nexport const deleteNodes = (\n diff: Diff,\n remover: RollbackRemove,\n scurry: PathScurry,\n): Promise<unknown>[] => {\n const store = scurry.resolve('node_modules/.vlt')\n const rmActions: Promise<unknown>[] = []\n for (const node of diff.nodes.delete) {\n // do not delete workspaces or link targets\n if (!node.inVltStore()) continue\n rmActions.push(remover.rm(scurry.resolve(store, node.id)))\n }\n return rmActions\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PackageInfoClient } from '@vltpkg/package-info';
|
|
2
|
+
import { LoadOptions } from '../actual/load.js';
|
|
3
|
+
import { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '../dependencies.js';
|
|
4
|
+
import { Graph } from '../graph.js';
|
|
5
|
+
export type ReifyOptions = LoadOptions & {
|
|
6
|
+
add?: AddImportersDependenciesMap;
|
|
7
|
+
remove?: RemoveImportersDependenciesMap;
|
|
8
|
+
graph: Graph;
|
|
9
|
+
actual?: Graph;
|
|
10
|
+
packageInfo: PackageInfoClient;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Make the current project match the supplied graph.
|
|
14
|
+
*/
|
|
15
|
+
export declare const reify: (options: ReifyOptions) => Promise<void>;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAIxD,OAAO,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAoBnC,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACvC,GAAG,CAAC,EAAE,2BAA2B,CAAA;IACjC,MAAM,CAAC,EAAE,8BAA8B,CAAA;IACvC,KAAK,EAAE,KAAK,CAAA;IACZ,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,YAAmB,YAAY,kBAwBhD,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import { availableParallelism } from 'node:os';
|
|
3
|
+
import { callLimit } from 'promise-call-limit';
|
|
4
|
+
import { load as loadActual } from '../actual/load.js';
|
|
5
|
+
import { Diff } from '../diff.js';
|
|
6
|
+
import { lockfile } from '../index.js';
|
|
7
|
+
import { lockfileData, saveData, saveHidden, } from '../lockfile/save.js';
|
|
8
|
+
import { addEdges } from './add-edges.js';
|
|
9
|
+
import { addNodes } from './add-nodes.js';
|
|
10
|
+
import { build } from './build.js';
|
|
11
|
+
import { deleteEdges } from './delete-edges.js';
|
|
12
|
+
import { deleteNodes } from './delete-nodes.js';
|
|
13
|
+
import { rollback } from './rollback.js';
|
|
14
|
+
import { updatePackageJson } from './update-importers-package-json.js';
|
|
15
|
+
const limit = Math.max(availableParallelism() - 1, 1) * 8;
|
|
16
|
+
/**
|
|
17
|
+
* Make the current project match the supplied graph.
|
|
18
|
+
*/
|
|
19
|
+
export const reify = async (options) => {
|
|
20
|
+
const { graph, scurry } = options;
|
|
21
|
+
const actual = options.actual ??
|
|
22
|
+
loadActual({
|
|
23
|
+
...options,
|
|
24
|
+
loadManifests: true,
|
|
25
|
+
});
|
|
26
|
+
const diff = new Diff(actual, graph);
|
|
27
|
+
const remover = new RollbackRemove();
|
|
28
|
+
let success = false;
|
|
29
|
+
try {
|
|
30
|
+
await reify_(options, diff, remover);
|
|
31
|
+
remover.confirm();
|
|
32
|
+
success = true;
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
/* c8 ignore start */
|
|
36
|
+
if (!success) {
|
|
37
|
+
await rollback(remover, diff, scurry).catch(() => { });
|
|
38
|
+
}
|
|
39
|
+
/* c8 ignore stop */
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const reify_ = async (options, diff, remover) => {
|
|
43
|
+
const { packageInfo, packageJson, scurry } = options;
|
|
44
|
+
const saveImportersPackageJson = updatePackageJson({
|
|
45
|
+
add: options.add,
|
|
46
|
+
remove: options.remove,
|
|
47
|
+
graph: options.graph,
|
|
48
|
+
packageJson,
|
|
49
|
+
});
|
|
50
|
+
// before anything else happens, grab the ideal tree as it was resolved
|
|
51
|
+
// so that we can store it in the lockfile. We do this here so that
|
|
52
|
+
// any failed/removed optional deps are not reflected in the lockfile
|
|
53
|
+
// data as it is saved.
|
|
54
|
+
const lfData = lockfileData(options);
|
|
55
|
+
const actions = addNodes(diff, scurry, remover, options, packageInfo).concat(deleteEdges(diff, scurry, remover));
|
|
56
|
+
// need to wait, so that the nodes exist to link to
|
|
57
|
+
if (actions.length)
|
|
58
|
+
await callLimit(actions, { limit });
|
|
59
|
+
// create all node_modules symlinks, and link bins to nm/.bin
|
|
60
|
+
const edgeActions = addEdges(diff, packageJson, scurry, remover);
|
|
61
|
+
if (edgeActions.length)
|
|
62
|
+
await Promise.all(edgeActions);
|
|
63
|
+
// run lifecycles and chmod bins
|
|
64
|
+
await build(diff, packageJson, scurry);
|
|
65
|
+
// save the lockfile
|
|
66
|
+
lockfile.save(options);
|
|
67
|
+
// if we had to change the actual graph along the way,
|
|
68
|
+
// make sure we do not leave behind any unreachable nodes
|
|
69
|
+
if (diff.hadOptionalFailures) {
|
|
70
|
+
for (const node of options.graph.gc().values()) {
|
|
71
|
+
diff.nodes.add.delete(node);
|
|
72
|
+
diff.nodes.delete.add(node);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
saveHidden(options);
|
|
76
|
+
// delete garbage from the store.
|
|
77
|
+
const rmActions = deleteNodes(diff, remover, scurry);
|
|
78
|
+
if (rmActions.length)
|
|
79
|
+
await Promise.all(rmActions);
|
|
80
|
+
// updates package.json files if anything was added / removed
|
|
81
|
+
saveImportersPackageJson();
|
|
82
|
+
// write the ideal graph data to the lockfile
|
|
83
|
+
saveData(lfData, scurry.resolve('vlt-lock.json'), false);
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reify/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAe,MAAM,mBAAmB,CAAA;AAKnE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,OAAO,EAA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,yDAAyD;IACzD,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,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,CAAA;IAE1B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;AAC1D,CAAC,CAAA","sourcesContent":["import { PackageInfoClient } from '@vltpkg/package-info'\nimport { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport { load as loadActual, LoadOptions } from '../actual/load.js'\nimport {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.js'\nimport { Diff } from '../diff.js'\nimport { Graph } from '../graph.js'\nimport { lockfile } from '../index.js'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.js'\nimport { addEdges } from './add-edges.js'\nimport { addNodes } from './add-nodes.js'\nimport { build } from './build.js'\nimport { deleteEdges } from './delete-edges.js'\nimport { deleteNodes } from './delete-nodes.js'\nimport { rollback } from './rollback.js'\nimport { updatePackageJson } from './update-importers-package-json.js'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (options: ReifyOptions) => {\n const { graph, scurry } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const remover = new RollbackRemove()\n let success = false\n try {\n await reify_(options, diff, remover)\n remover.confirm()\n success = true\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n) => {\n const { packageInfo, packageJson, scurry } = options\n const saveImportersPackageJson = updatePackageJson({\n add: options.add,\n remove: options.remove,\n graph: options.graph,\n packageJson,\n })\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions: Promise<unknown>[] = addEdges(\n diff,\n packageJson,\n scurry,\n remover,\n )\n if (edgeActions.length) await Promise.all(edgeActions)\n\n // run lifecycles and chmod bins\n await build(diff, packageJson, scurry)\n\n // save the lockfile\n lockfile.save(options)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Diff } from '../diff.js';
|
|
2
|
+
import { Node } from '../node.js';
|
|
3
|
+
/**
|
|
4
|
+
* If the node is optional, then returns an error handler that removes
|
|
5
|
+
* the node and its connected optional subgraph, by moving them into the
|
|
6
|
+
* "deleted" portion of the Diff object.
|
|
7
|
+
* Otherwise, it returns `undefined` so that the promise will simply reject.
|
|
8
|
+
*/
|
|
9
|
+
export declare function optionalFail(diff: Diff, node: Node & {
|
|
10
|
+
optional: true;
|
|
11
|
+
}): () => void;
|
|
12
|
+
export declare function optionalFail(diff: Diff, node: Node & {
|
|
13
|
+
optional: false;
|
|
14
|
+
}): undefined;
|
|
15
|
+
export declare function optionalFail(diff: Diff, node: Node): (() => void) | undefined;
|
|
16
|
+
//# sourceMappingURL=optional-fail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional-fail.d.ts","sourceRoot":"","sources":["../../../src/reify/optional-fail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAC9B,MAAM,IAAI,CAAA;AACb,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,IAAI,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAA;CAAE,GAC/B,SAAS,CAAA;AACZ,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,IAAI,GACT,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { removeOptionalSubgraph } from '../remove-optional-subgraph.js';
|
|
2
|
+
export function optionalFail(diff, node) {
|
|
3
|
+
return node.isOptional() ? () => del(diff, node) : undefined;
|
|
4
|
+
}
|
|
5
|
+
const del = (diff, node) => {
|
|
6
|
+
diff.hadOptionalFailures = true;
|
|
7
|
+
for (const del of removeOptionalSubgraph(diff.to, node)) {
|
|
8
|
+
// add it to the set of nodes being deleted
|
|
9
|
+
diff.nodes.delete.add(del);
|
|
10
|
+
// delete it from the set of nodes being added
|
|
11
|
+
diff.nodes.add.delete(del);
|
|
12
|
+
}
|
|
13
|
+
diff.nodes.add.delete(node);
|
|
14
|
+
diff.nodes.delete.add(node);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=optional-fail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional-fail.js","sourceRoot":"","sources":["../../../src/reify/optional-fail.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAoBvE,MAAM,UAAU,YAAY,CAC1B,IAAU,EACV,IAAU;IAEV,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC9D,CAAC;AAED,MAAM,GAAG,GAAG,CAAC,IAAU,EAAE,IAA+B,EAAE,EAAE;IAC1D,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAA;IAC/B,KAAK,MAAM,GAAG,IAAI,sBAAsB,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC;QACxD,2CAA2C;QAC3C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC1B,8CAA8C;QAC9C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["import { Diff } from '../diff.js'\nimport { Node } from '../node.js'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.js'\n\n/**\n * If the node is optional, then returns an error handler that removes\n * the node and its connected optional subgraph, by moving them into the\n * \"deleted\" portion of the Diff object.\n * Otherwise, it returns `undefined` so that the promise will simply reject.\n */\nexport function optionalFail(\n diff: Diff,\n node: Node & { optional: true },\n): () => void\nexport function optionalFail(\n diff: Diff,\n node: Node & { optional: false },\n): undefined\nexport function optionalFail(\n diff: Diff,\n node: Node,\n): (() => void) | undefined\nexport function optionalFail(\n diff: Diff,\n node: Node,\n): (() => void) | undefined {\n return node.isOptional() ? () => del(diff, node) : undefined\n}\n\nconst del = (diff: Diff, node: Node & { optional: true }) => {\n diff.hadOptionalFailures = true\n for (const del of removeOptionalSubgraph(diff.to, node)) {\n // add it to the set of nodes being deleted\n diff.nodes.delete.add(del)\n // delete it from the set of nodes being added\n diff.nodes.add.delete(del)\n }\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import { PathScurry } from 'path-scurry';
|
|
3
|
+
import { Diff } from '../diff.js';
|
|
4
|
+
export declare const rollback: (remover: RollbackRemove, diff: Diff, scurry: PathScurry) => Promise<void>;
|
|
5
|
+
//# sourceMappingURL=rollback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollback.d.ts","sourceRoot":"","sources":["../../../src/reify/rollback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,eAAO,MAAM,QAAQ,YACV,cAAc,QACjB,IAAI,UACF,UAAU,kBAwBnB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import { deleteEdge } from './delete-edge.js';
|
|
3
|
+
export const rollback = async (remover, diff, scurry) => {
|
|
4
|
+
const promises = [];
|
|
5
|
+
const store = scurry.resolve('node_modules/.vlt');
|
|
6
|
+
// remove everything the diff tried to add
|
|
7
|
+
const backRoller = new RollbackRemove();
|
|
8
|
+
for (const node of diff.nodes.add) {
|
|
9
|
+
if (!node.inVltStore())
|
|
10
|
+
continue;
|
|
11
|
+
const path = scurry.resolve(store, node.id);
|
|
12
|
+
/* c8 ignore next */
|
|
13
|
+
promises.push(backRoller.rm(path).catch(() => { }));
|
|
14
|
+
}
|
|
15
|
+
for (const edge of diff.edges.add) {
|
|
16
|
+
promises.push(deleteEdge(edge, scurry, backRoller));
|
|
17
|
+
}
|
|
18
|
+
/* c8 ignore next */
|
|
19
|
+
await Promise.all(promises).catch(() => { });
|
|
20
|
+
backRoller.confirm();
|
|
21
|
+
/* c8 ignore next */
|
|
22
|
+
await remover.rollback().catch(() => { });
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=rollback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollback.js","sourceRoot":"","sources":["../../../src/reify/rollback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,OAAuB,EACvB,IAAU,EACV,MAAkB,EAClB,EAAE;IACF,MAAM,QAAQ,GAAuB,EAAE,CAAA;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAEjD,0CAA0C;IAC1C,MAAM,UAAU,GAAG,IAAI,cAAc,EAAE,CAAA;IACvC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAAE,SAAQ;QAChC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;QAC3C,oBAAoB;QACpB,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAA;IACpD,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAClC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;IACrD,CAAC;IAED,oBAAoB;IACpB,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IAE3C,UAAU,CAAC,OAAO,EAAE,CAAA;IAEpB,oBAAoB;IACpB,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;AAC1C,CAAC,CAAA","sourcesContent":["import { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { PathScurry } from 'path-scurry'\nimport { Diff } from '../diff.js'\nimport { deleteEdge } from './delete-edge.js'\n\nexport const rollback = async (\n remover: RollbackRemove,\n diff: Diff,\n scurry: PathScurry,\n) => {\n const promises: Promise<unknown>[] = []\n const store = scurry.resolve('node_modules/.vlt')\n\n // remove everything the diff tried to add\n const backRoller = new RollbackRemove()\n for (const node of diff.nodes.add) {\n if (!node.inVltStore()) continue\n const path = scurry.resolve(store, node.id)\n /* c8 ignore next */\n promises.push(backRoller.rm(path).catch(() => {}))\n }\n for (const edge of diff.edges.add) {\n promises.push(deleteEdge(edge, scurry, backRoller))\n }\n\n /* c8 ignore next */\n await Promise.all(promises).catch(() => {})\n\n backRoller.confirm()\n\n /* c8 ignore next */\n await remover.rollback().catch(() => {})\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { PackageJson } from '@vltpkg/package-json';
|
|
2
|
+
import { Graph } from '../graph.js';
|
|
3
|
+
import { type AddImportersDependenciesMap, type RemoveImportersDependenciesMap } from '../dependencies.js';
|
|
4
|
+
export type UpdatePackageJsonOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* A `Map` in which keys are {@link DepID} linking to another `Map` in which
|
|
7
|
+
* keys are the dependency names and values are {@link Dependency}. This
|
|
8
|
+
* structure represents dependencies that need to be added to the importer
|
|
9
|
+
* represented by {@link DepID}.
|
|
10
|
+
*/
|
|
11
|
+
add?: AddImportersDependenciesMap;
|
|
12
|
+
/**
|
|
13
|
+
* A `Map` object representing nodes to be removed from the ideal graph.
|
|
14
|
+
* Each {@link DepID} key represents an importer node and the `Set` of
|
|
15
|
+
* dependency names to be removed from its dependency list.
|
|
16
|
+
*/
|
|
17
|
+
remove?: RemoveImportersDependenciesMap;
|
|
18
|
+
/**
|
|
19
|
+
* The {@link Graph} instance that contain the importer nodes to which
|
|
20
|
+
* the manifest data (and it's corresponding `package.json` file) are
|
|
21
|
+
* going to be updated.
|
|
22
|
+
*/
|
|
23
|
+
graph: Graph;
|
|
24
|
+
/**
|
|
25
|
+
* An instance of {@link PackageJson} to use when writing updated manifest
|
|
26
|
+
* data to `package.json` files. It's necessary that this is the same
|
|
27
|
+
* instance used to load these `package.json` files previously.
|
|
28
|
+
*/
|
|
29
|
+
packageJson: PackageJson;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Updates the importers of a provided {@link Graph} accordingly to the
|
|
33
|
+
* provided add or remove arguments.
|
|
34
|
+
*/
|
|
35
|
+
export declare const updatePackageJson: ({ add, graph, packageJson, remove, }: UpdatePackageJsonOptions) => () => void;
|
|
36
|
+
//# sourceMappingURL=update-importers-package-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-importers-package-json.d.ts","sourceRoot":"","sources":["../../../src/reify/update-importers-package-json.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EAIpC,MAAM,oBAAoB,CAAA;AAY3B,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,2BAA2B,CAAA;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,8BAA8B,CAAA;IACvC;;;;OAIG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ;;;;OAIG;IACH,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAsED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,yCAK3B,wBAAwB,eAsB1B,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { splitDepID } from '@vltpkg/dep-id';
|
|
2
|
+
import { error } from '@vltpkg/error-cause';
|
|
3
|
+
import { longDependencyTypes, } from '../dependencies.js';
|
|
4
|
+
const SAVE_PREFIX = '^';
|
|
5
|
+
const depTypesMap = new Map([
|
|
6
|
+
['prod', 'dependencies'],
|
|
7
|
+
['dev', 'devDependencies'],
|
|
8
|
+
['peer', 'peerDependencies'],
|
|
9
|
+
['peerOptional', 'peerDependencies'],
|
|
10
|
+
['optional', 'optionalDependencies'],
|
|
11
|
+
]);
|
|
12
|
+
const addOrRemoveDeps = (importerId, graph, addOrRemove) => {
|
|
13
|
+
const importer = graph.nodes.get(importerId);
|
|
14
|
+
if (!importer) {
|
|
15
|
+
throw error('Failed to retrieve importer node', {
|
|
16
|
+
found: importerId,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const manifest = importer.manifest;
|
|
20
|
+
if (!manifest) {
|
|
21
|
+
throw error('Could not find manifest data for node', {
|
|
22
|
+
found: importerId,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const deps = addOrRemove?.get(importerId);
|
|
26
|
+
/* c8 ignore start -- impossible but TS doesn't know that */
|
|
27
|
+
if (!deps) {
|
|
28
|
+
throw error('Failed to retrieve added deps info', {
|
|
29
|
+
manifest,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
let manifestChanged = false;
|
|
33
|
+
/* c8 ignore stop */
|
|
34
|
+
for (const deleteNameOrAddItem of deps) {
|
|
35
|
+
if (typeof deleteNameOrAddItem === 'string') {
|
|
36
|
+
const name = deleteNameOrAddItem;
|
|
37
|
+
// TODO: needs to also remove any possible peerDependenciesMeta
|
|
38
|
+
for (const depType of longDependencyTypes) {
|
|
39
|
+
if (manifest[depType]?.[name]) {
|
|
40
|
+
delete manifest[depType][name];
|
|
41
|
+
manifestChanged = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const [name, dep] = deleteNameOrAddItem;
|
|
47
|
+
// TODO: peerOptional also needs to add peerDependenciesMeta entry
|
|
48
|
+
const depType = depTypesMap.get(dep.type);
|
|
49
|
+
if (!depType) {
|
|
50
|
+
throw error('Failed to retrieve dependency type', {
|
|
51
|
+
validOptions: [...depTypesMap.keys()],
|
|
52
|
+
found: dep.type,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const node = importer.edgesOut.get(name)?.to;
|
|
56
|
+
if (!node) {
|
|
57
|
+
throw error('Dependency node could not be found');
|
|
58
|
+
}
|
|
59
|
+
const [nodeType] = splitDepID(node.id);
|
|
60
|
+
const dependencies = manifest[depType] ?? (manifest[depType] = {});
|
|
61
|
+
dependencies[name] =
|
|
62
|
+
(nodeType === 'registry' &&
|
|
63
|
+
(!dep.spec.semver || dep.spec.range?.isSingle)) ?
|
|
64
|
+
`${SAVE_PREFIX}${node.version}`
|
|
65
|
+
: dep.spec.bareSpec;
|
|
66
|
+
manifestChanged = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return manifestChanged ? manifest : undefined;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Updates the importers of a provided {@link Graph} accordingly to the
|
|
73
|
+
* provided add or remove arguments.
|
|
74
|
+
*/
|
|
75
|
+
export const updatePackageJson = ({ add, graph, packageJson, remove, }) => {
|
|
76
|
+
const manifestsToUpdate = new Set();
|
|
77
|
+
const operations = new Set([add, remove]);
|
|
78
|
+
for (const operation of operations) {
|
|
79
|
+
if (operation) {
|
|
80
|
+
for (const importerId of operation.keys()) {
|
|
81
|
+
const manifest = addOrRemoveDeps(importerId, graph, operation);
|
|
82
|
+
if (manifest) {
|
|
83
|
+
manifestsToUpdate.add(manifest);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const commit = () => {
|
|
89
|
+
for (const manifest of manifestsToUpdate) {
|
|
90
|
+
packageJson.save(manifest);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return commit;
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=update-importers-package-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-importers-package-json.js","sourceRoot":"","sources":["../../../src/reify/update-importers-package-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;A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,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAA;YACrB,eAAe,GAAG,IAAI,CAAA;QACxB,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAA;AAC/C,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,GAAG,EACH,KAAK,EACL,WAAW,EACX,MAAM,GACmB,EAAE,EAAE;IAC7B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAY,CAAA;IAC7C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;IAEzC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,EAAE,CAAC;YACd,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC1C,MAAM,QAAQ,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;gBAC9D,IAAI,QAAQ,EAAE,CAAC;oBACb,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;YACzC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { type DepID, splitDepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type { Manifest } from '@vltpkg/types'\nimport { Graph } from '../graph.js'\nimport {\n type AddImportersDependenciesMap,\n type RemoveImportersDependenciesMap,\n type DependencyTypeLong,\n type DependencyTypeShort,\n longDependencyTypes,\n} from '../dependencies.js'\n\nconst SAVE_PREFIX = '^'\n\nconst depTypesMap = new Map<DependencyTypeShort, DependencyTypeLong>([\n ['prod', 'dependencies'],\n ['dev', 'devDependencies'],\n ['peer', 'peerDependencies'],\n ['peerOptional', 'peerDependencies'],\n ['optional', 'optionalDependencies'],\n])\n\nexport type UpdatePackageJsonOptions = {\n /**\n * A `Map` in which keys are {@link DepID} linking to another `Map` in which\n * keys are the dependency names and values are {@link Dependency}. This\n * structure represents dependencies that need to be added to the importer\n * represented by {@link DepID}.\n */\n add?: AddImportersDependenciesMap\n /**\n * A `Map` object representing nodes to be removed from the ideal graph.\n * Each {@link DepID} key represents an importer node and the `Set` of\n * dependency names to be removed from its dependency list.\n */\n remove?: RemoveImportersDependenciesMap\n /**\n * The {@link Graph} instance that contain the importer nodes to which\n * the manifest data (and it's corresponding `package.json` file) are\n * going to be updated.\n */\n graph: Graph\n /**\n * An instance of {@link PackageJson} to use when writing updated manifest\n * data to `package.json` files. It's necessary that this is the same\n * instance used to load these `package.json` files previously.\n */\n packageJson: PackageJson\n}\n\nconst addOrRemoveDeps = (\n importerId: DepID,\n graph: Graph,\n addOrRemove?:\n | AddImportersDependenciesMap\n | RemoveImportersDependenciesMap,\n): Manifest | undefined => {\n const importer = graph.nodes.get(importerId)\n if (!importer) {\n throw error('Failed to retrieve importer node', {\n found: importerId,\n })\n }\n const manifest = importer.manifest\n if (!manifest) {\n throw error('Could not find manifest data for node', {\n found: importerId,\n })\n }\n const deps = addOrRemove?.get(importerId)\n /* c8 ignore start -- impossible but TS doesn't know that */\n if (!deps) {\n throw error('Failed to retrieve added deps info', {\n manifest,\n })\n }\n let manifestChanged = false\n /* c8 ignore stop */\n for (const deleteNameOrAddItem of deps) {\n if (typeof deleteNameOrAddItem === 'string') {\n const name = deleteNameOrAddItem\n // TODO: needs to also remove any possible peerDependenciesMeta\n for (const depType of longDependencyTypes) {\n if (manifest[depType]?.[name]) {\n delete manifest[depType][name]\n manifestChanged = true\n }\n }\n } else {\n const [name, dep] = deleteNameOrAddItem\n // TODO: peerOptional also needs to add peerDependenciesMeta entry\n const depType = depTypesMap.get(dep.type)\n if (!depType) {\n throw error('Failed to retrieve dependency type', {\n validOptions: [...depTypesMap.keys()],\n found: dep.type,\n })\n }\n const node = importer.edgesOut.get(name)?.to\n if (!node) {\n throw error('Dependency node could not be found')\n }\n const [nodeType] = splitDepID(node.id)\n const dependencies =\n manifest[depType] ?? (manifest[depType] = {})\n dependencies[name] =\n (\n nodeType === 'registry' &&\n (!dep.spec.semver || dep.spec.range?.isSingle)\n ) ?\n `${SAVE_PREFIX}${node.version}`\n : dep.spec.bareSpec\n manifestChanged = true\n }\n }\n return manifestChanged ? manifest : undefined\n}\n\n/**\n * Updates the importers of a provided {@link Graph} accordingly to the\n * provided add or remove arguments.\n */\nexport const updatePackageJson = ({\n add,\n graph,\n packageJson,\n remove,\n}: UpdatePackageJsonOptions) => {\n const manifestsToUpdate = new Set<Manifest>()\n const operations = new Set([add, remove])\n\n for (const operation of operations) {\n if (operation) {\n for (const importerId of operation.keys()) {\n const manifest = addOrRemoveDeps(importerId, graph, operation)\n if (manifest) {\n manifestsToUpdate.add(manifest)\n }\n }\n }\n }\n\n const commit = () => {\n for (const manifest of manifestsToUpdate) {\n packageJson.save(manifest)\n }\n }\n\n return commit\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Graph } from './graph.js';
|
|
2
|
+
import { Node } from './node.js';
|
|
3
|
+
/**
|
|
4
|
+
* Remove the affected optional nodes starting from a given optional node
|
|
5
|
+
* that failed to resolve/install.
|
|
6
|
+
*
|
|
7
|
+
* Removing these dependents will frequently leave optional *dependencies*
|
|
8
|
+
* behind that are made unreachable from any project importer. For performance
|
|
9
|
+
* reasons, `graph.gc()` is not called automatically by this method, since
|
|
10
|
+
* multiple optional subgraphs may need to be removed in a single operation,
|
|
11
|
+
* and the mark-and-sweep garbage collection (a) can be excessively expensive,
|
|
12
|
+
* and (b) may need to communicate the set of garbage-collected nodes
|
|
13
|
+
* for cleanup (as in the case of optional node build failures during
|
|
14
|
+
* reification).
|
|
15
|
+
*/
|
|
16
|
+
export declare const removeOptionalSubgraph: (graph: Graph, startingNode: Node & {
|
|
17
|
+
optional: true;
|
|
18
|
+
}) => Set<Node>;
|
|
19
|
+
/**
|
|
20
|
+
* Given a starting node, this generator will walk back from the optional node
|
|
21
|
+
* to all of its optional dependents, emitting each one, and skipping any
|
|
22
|
+
* cycles.
|
|
23
|
+
*
|
|
24
|
+
* Note that when these are removed, it may create unreachable nodes in the
|
|
25
|
+
* graph! Be sure to call `graph.gc()` if these are removed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function findOptionalSubgraph(node: Node & {
|
|
28
|
+
optional: true;
|
|
29
|
+
}, seen?: Set<Node & {
|
|
30
|
+
optional: true;
|
|
31
|
+
}>): Generator<Node & {
|
|
32
|
+
optional: true;
|
|
33
|
+
}, void>;
|
|
34
|
+
//# sourceMappingURL=remove-optional-subgraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-optional-subgraph.d.ts","sourceRoot":"","sources":["../../src/remove-optional-subgraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,UAC1B,KAAK,gBACE,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,cAQxC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAiB,oBAAoB,CACnC,IAAI,EAAE,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,EAC/B,IAAI;cAA8B,IAAI;EAAK,GAC1C,SAAS,CAAC,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,EAAE,IAAI,CAAC,CAiB5C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove the affected optional nodes starting from a given optional node
|
|
3
|
+
* that failed to resolve/install.
|
|
4
|
+
*
|
|
5
|
+
* Removing these dependents will frequently leave optional *dependencies*
|
|
6
|
+
* behind that are made unreachable from any project importer. For performance
|
|
7
|
+
* reasons, `graph.gc()` is not called automatically by this method, since
|
|
8
|
+
* multiple optional subgraphs may need to be removed in a single operation,
|
|
9
|
+
* and the mark-and-sweep garbage collection (a) can be excessively expensive,
|
|
10
|
+
* and (b) may need to communicate the set of garbage-collected nodes
|
|
11
|
+
* for cleanup (as in the case of optional node build failures during
|
|
12
|
+
* reification).
|
|
13
|
+
*/
|
|
14
|
+
export const removeOptionalSubgraph = (graph, startingNode) => {
|
|
15
|
+
const removed = new Set();
|
|
16
|
+
for (const node of findOptionalSubgraph(startingNode)) {
|
|
17
|
+
graph.removeNode(node);
|
|
18
|
+
removed.add(node);
|
|
19
|
+
}
|
|
20
|
+
return removed;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Given a starting node, this generator will walk back from the optional node
|
|
24
|
+
* to all of its optional dependents, emitting each one, and skipping any
|
|
25
|
+
* cycles.
|
|
26
|
+
*
|
|
27
|
+
* Note that when these are removed, it may create unreachable nodes in the
|
|
28
|
+
* graph! Be sure to call `graph.gc()` if these are removed.
|
|
29
|
+
*/
|
|
30
|
+
export function* findOptionalSubgraph(node, seen = new Set()) {
|
|
31
|
+
// already visited, prevent looping
|
|
32
|
+
if (seen.has(node))
|
|
33
|
+
return;
|
|
34
|
+
// the node itself is part of the subgraph, of course
|
|
35
|
+
seen.add(node);
|
|
36
|
+
yield node;
|
|
37
|
+
// and any of its dependents that are also optional
|
|
38
|
+
for (const { from, optional } of node.edgesIn) {
|
|
39
|
+
// if it's an optional *edge*, we don't need to remove it, because it
|
|
40
|
+
// doesn't need the node anyway. But if the node is optional and the
|
|
41
|
+
// dep isn't, then we do need to remove it.
|
|
42
|
+
if (from.isOptional() && !optional) {
|
|
43
|
+
for (const dep of findOptionalSubgraph(from, seen))
|
|
44
|
+
yield dep;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=remove-optional-subgraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-optional-subgraph.js","sourceRoot":"","sources":["../../src/remove-optional-subgraph.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,KAAY,EACZ,YAAuC,EACvC,EAAE;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAQ,CAAA;IAC/B,KAAK,MAAM,IAAI,IAAI,oBAAoB,CAAC,YAAY,CAAC,EAAE,CAAC;QACtD,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACnB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,oBAAoB,CACnC,IAA+B,EAC/B,OAAO,IAAI,GAAG,EAA6B;IAE3C,mCAAmC;IACnC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAM;IAE1B,qDAAqD;IACrD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACd,MAAM,IAAI,CAAA;IAEV,mDAAmD;IACnD,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9C,qEAAqE;QACrE,oEAAoE;QACpE,2CAA2C;QAC3C,IAAI,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,KAAK,MAAM,GAAG,IAAI,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC;gBAAE,MAAM,GAAG,CAAA;QAC/D,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { Graph } from './graph.js'\nimport { Node } from './node.js'\n\n/**\n * Remove the affected optional nodes starting from a given optional node\n * that failed to resolve/install.\n *\n * Removing these dependents will frequently leave optional *dependencies*\n * behind that are made unreachable from any project importer. For performance\n * reasons, `graph.gc()` is not called automatically by this method, since\n * multiple optional subgraphs may need to be removed in a single operation,\n * and the mark-and-sweep garbage collection (a) can be excessively expensive,\n * and (b) may need to communicate the set of garbage-collected nodes\n * for cleanup (as in the case of optional node build failures during\n * reification).\n */\nexport const removeOptionalSubgraph = (\n graph: Graph,\n startingNode: Node & { optional: true },\n) => {\n const removed = new Set<Node>()\n for (const node of findOptionalSubgraph(startingNode)) {\n graph.removeNode(node)\n removed.add(node)\n }\n return removed\n}\n\n/**\n * Given a starting node, this generator will walk back from the optional node\n * to all of its optional dependents, emitting each one, and skipping any\n * cycles.\n *\n * Note that when these are removed, it may create unreachable nodes in the\n * graph! Be sure to call `graph.gc()` if these are removed.\n */\nexport function* findOptionalSubgraph(\n node: Node & { optional: true },\n seen = new Set<Node & { optional: true }>(),\n): Generator<Node & { optional: true }, void> {\n // already visited, prevent looping\n if (seen.has(node)) return\n\n // the node itself is part of the subgraph, of course\n seen.add(node)\n yield node\n\n // and any of its dependents that are also optional\n for (const { from, optional } of node.edgesIn) {\n // if it's an optional *edge*, we don't need to remove it, because it\n // doesn't need the node anyway. But if the node is optional and the\n // dep isn't, then we do need to remove it.\n if (from.isOptional() && !optional) {\n for (const dep of findOptionalSubgraph(from, seen)) yield dep\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify-node.d.ts","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,eAAO,MAAM,aAAa,UAAW,QAAQ,WAmB5C,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { splitDepID } from '@vltpkg/dep-id/browser';
|
|
2
|
+
export const stringifyNode = (node) => {
|
|
3
|
+
if (!node)
|
|
4
|
+
return '';
|
|
5
|
+
const version = node.version ? `@${node.version}` : '';
|
|
6
|
+
const [type, ref, nameVersion] = splitDepID(node.id);
|
|
7
|
+
if (type === 'registry') {
|
|
8
|
+
const prefix = ref ? `${ref}:` : 'npm:';
|
|
9
|
+
return `${prefix}${nameVersion}`;
|
|
10
|
+
}
|
|
11
|
+
else if (type === 'workspace') {
|
|
12
|
+
return `workspace:${node.name}`;
|
|
13
|
+
}
|
|
14
|
+
else if (type === 'file' && node.mainImporter) {
|
|
15
|
+
return `root:${node.name}`;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
// node.name getter will return the id if the package has no name
|
|
19
|
+
// property so here we check for that in order to return `type(ref)` only
|
|
20
|
+
const nameVersion = node.name !== node.id ? `:${node.name}${version}` : '';
|
|
21
|
+
return `${type}(${ref})${nameVersion}`;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=stringify-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify-node.js","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAGnD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAe,EAAE,EAAE;IAC/C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACtD,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEpD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;QACvC,OAAO,GAAG,MAAM,GAAG,WAAW,EAAE,CAAA;IAClC,CAAC;SAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,aAAa,IAAI,CAAC,IAAI,EAAE,CAAA;IACjC,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QAChD,OAAO,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,yEAAyE;QACzE,MAAM,WAAW,GACf,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACxD,OAAO,GAAG,IAAI,IAAI,GAAG,IAAI,WAAW,EAAE,CAAA;IACxC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport { NodeLike } from './types.js'\n\nexport const stringifyNode = (node?: NodeLike) => {\n if (!node) return ''\n const version = node.version ? `@${node.version}` : ''\n const [type, ref, nameVersion] = splitDepID(node.id)\n\n if (type === 'registry') {\n const prefix = ref ? `${ref}:` : 'npm:'\n return `${prefix}${nameVersion}`\n } else if (type === 'workspace') {\n return `workspace:${node.name}`\n } else if (type === 'file' && node.mainImporter) {\n return `root:${node.name}`\n } else {\n // node.name getter will return the id if the package has no name\n // property so here we check for that in order to return `type(ref)` only\n const nameVersion =\n node.name !== node.id ? `:${node.name}${version}` : ''\n return `${type}(${ref})${nameVersion}`\n }\n}\n"]}
|