@vltpkg/graph 0.0.0-9 → 1.0.0-rc.2
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 +136 -1
- package/dist/esm/actual/load.d.ts +49 -3
- package/dist/esm/actual/load.d.ts.map +1 -1
- package/dist/esm/actual/load.js +130 -73
- package/dist/esm/actual/load.js.map +1 -1
- package/dist/esm/browser.d.ts +8 -4
- package/dist/esm/browser.d.ts.map +1 -1
- package/dist/esm/browser.js +6 -2
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/build.d.ts +29 -0
- package/dist/esm/build.d.ts.map +1 -0
- package/dist/esm/build.js +79 -0
- package/dist/esm/build.js.map +1 -0
- package/dist/esm/dependencies.d.ts +10 -3
- package/dist/esm/dependencies.d.ts.map +1 -1
- package/dist/esm/dependencies.js +63 -0
- package/dist/esm/dependencies.js.map +1 -1
- package/dist/esm/diff.d.ts +67 -0
- package/dist/esm/diff.d.ts.map +1 -1
- package/dist/esm/diff.js +25 -0
- package/dist/esm/diff.js.map +1 -1
- package/dist/esm/edge.d.ts +7 -2
- package/dist/esm/edge.d.ts.map +1 -1
- package/dist/esm/edge.js +8 -0
- package/dist/esm/edge.js.map +1 -1
- package/dist/esm/graph.d.ts +20 -10
- package/dist/esm/graph.d.ts.map +1 -1
- package/dist/esm/graph.js +124 -21
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/ideal/add-nodes.d.ts +17 -2
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/add-nodes.js +9 -2
- package/dist/esm/ideal/add-nodes.js.map +1 -1
- package/dist/esm/ideal/append-nodes.d.ts +11 -1
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/append-nodes.js +177 -31
- package/dist/esm/ideal/append-nodes.js.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +9 -5
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
- package/dist/esm/ideal/build.d.ts +9 -0
- package/dist/esm/ideal/build.d.ts.map +1 -1
- package/dist/esm/ideal/build.js +4 -1
- package/dist/esm/ideal/build.js.map +1 -1
- package/dist/esm/ideal/get-importer-specs.d.ts +3 -2
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
- package/dist/esm/ideal/get-importer-specs.js +7 -5
- package/dist/esm/ideal/get-importer-specs.js.map +1 -1
- package/dist/esm/index.d.ts +8 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install.d.ts +8 -3
- package/dist/esm/install.d.ts.map +1 -1
- package/dist/esm/install.js +167 -20
- package/dist/esm/install.js.map +1 -1
- package/dist/esm/lockfile/load-edges.d.ts +8 -1
- package/dist/esm/lockfile/load-edges.d.ts.map +1 -1
- package/dist/esm/lockfile/load-edges.js +79 -15
- package/dist/esm/lockfile/load-edges.js.map +1 -1
- package/dist/esm/lockfile/load-nodes.d.ts +3 -2
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
- package/dist/esm/lockfile/load-nodes.js +77 -12
- package/dist/esm/lockfile/load-nodes.js.map +1 -1
- package/dist/esm/lockfile/load.d.ts +22 -5
- package/dist/esm/lockfile/load.d.ts.map +1 -1
- package/dist/esm/lockfile/load.js +55 -22
- package/dist/esm/lockfile/load.js.map +1 -1
- package/dist/esm/lockfile/save.d.ts +16 -3
- package/dist/esm/lockfile/save.d.ts.map +1 -1
- package/dist/esm/lockfile/save.js +61 -16
- package/dist/esm/lockfile/save.js.map +1 -1
- package/dist/esm/lockfile/types.d.ts +34 -4
- package/dist/esm/lockfile/types.d.ts.map +1 -1
- package/dist/esm/lockfile/types.js +31 -0
- package/dist/esm/lockfile/types.js.map +1 -1
- package/dist/esm/modifiers.d.ts +189 -0
- package/dist/esm/modifiers.d.ts.map +1 -0
- package/dist/esm/modifiers.js +330 -0
- package/dist/esm/modifiers.js.map +1 -0
- package/dist/esm/node.d.ts +77 -6
- package/dist/esm/node.d.ts.map +1 -1
- package/dist/esm/node.js +98 -5
- package/dist/esm/node.js.map +1 -1
- package/dist/esm/reify/add-edge.d.ts +1 -2
- package/dist/esm/reify/add-edge.d.ts.map +1 -1
- package/dist/esm/reify/add-edge.js +29 -18
- package/dist/esm/reify/add-edge.js.map +1 -1
- package/dist/esm/reify/add-edges.d.ts +1 -2
- package/dist/esm/reify/add-edges.d.ts.map +1 -1
- package/dist/esm/reify/add-edges.js +2 -3
- package/dist/esm/reify/add-edges.js.map +1 -1
- package/dist/esm/reify/add-nodes.d.ts.map +1 -1
- package/dist/esm/reify/add-nodes.js +4 -27
- package/dist/esm/reify/add-nodes.js.map +1 -1
- package/dist/esm/reify/bin-chmod.d.ts +11 -0
- package/dist/esm/reify/bin-chmod.d.ts.map +1 -0
- package/dist/esm/reify/bin-chmod.js +39 -0
- package/dist/esm/reify/bin-chmod.js.map +1 -0
- package/dist/esm/reify/build.d.ts +10 -1
- package/dist/esm/reify/build.d.ts.map +1 -1
- package/dist/esm/reify/build.js +36 -23
- package/dist/esm/reify/build.js.map +1 -1
- package/dist/esm/reify/calculate-save-value.d.ts +3 -0
- package/dist/esm/reify/calculate-save-value.d.ts.map +1 -0
- package/dist/esm/reify/calculate-save-value.js +45 -0
- package/dist/esm/reify/calculate-save-value.js.map +1 -0
- package/dist/esm/reify/check-needed-build.d.ts +25 -0
- package/dist/esm/reify/check-needed-build.d.ts.map +1 -0
- package/dist/esm/reify/check-needed-build.js +50 -0
- package/dist/esm/reify/check-needed-build.js.map +1 -0
- package/dist/esm/reify/delete-edge.d.ts.map +1 -1
- package/dist/esm/reify/delete-edge.js +3 -4
- package/dist/esm/reify/delete-edge.js.map +1 -1
- package/dist/esm/reify/extract-node.d.ts +24 -0
- package/dist/esm/reify/extract-node.d.ts.map +1 -0
- package/dist/esm/reify/extract-node.js +76 -0
- package/dist/esm/reify/extract-node.js.map +1 -0
- package/dist/esm/reify/index.d.ts +18 -1
- package/dist/esm/reify/index.d.ts.map +1 -1
- package/dist/esm/reify/index.js +84 -14
- package/dist/esm/reify/index.js.map +1 -1
- package/dist/esm/reify/internal-hoist.d.ts +9 -0
- package/dist/esm/reify/internal-hoist.d.ts.map +1 -0
- package/dist/esm/reify/internal-hoist.js +134 -0
- package/dist/esm/reify/internal-hoist.js.map +1 -0
- package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -1
- package/dist/esm/reify/update-importers-package-json.js +15 -9
- package/dist/esm/reify/update-importers-package-json.js.map +1 -1
- package/dist/esm/remove-optional-subgraph.js +1 -1
- package/dist/esm/remove-optional-subgraph.js.map +1 -1
- package/dist/esm/resolve-save-type.d.ts +1 -2
- package/dist/esm/resolve-save-type.d.ts.map +1 -1
- package/dist/esm/resolve-save-type.js.map +1 -1
- package/dist/esm/stringify-node.d.ts +1 -1
- package/dist/esm/stringify-node.d.ts.map +1 -1
- package/dist/esm/stringify-node.js.map +1 -1
- package/dist/esm/transfer-data/load.d.ts +44 -0
- package/dist/esm/transfer-data/load.d.ts.map +1 -0
- package/dist/esm/transfer-data/load.js +176 -0
- package/dist/esm/transfer-data/load.js.map +1 -0
- package/dist/esm/uninstall.d.ts +5 -4
- package/dist/esm/uninstall.d.ts.map +1 -1
- package/dist/esm/uninstall.js +51 -19
- package/dist/esm/uninstall.js.map +1 -1
- package/dist/esm/update.d.ts +13 -0
- package/dist/esm/update.d.ts.map +1 -0
- package/dist/esm/update.js +63 -0
- package/dist/esm/update.js.map +1 -0
- package/dist/esm/virtual-root.d.ts +16 -0
- package/dist/esm/virtual-root.d.ts.map +1 -0
- package/dist/esm/virtual-root.js +79 -0
- package/dist/esm/virtual-root.js.map +1 -0
- package/dist/esm/visualization/human-readable-output.d.ts +4 -5
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
- package/dist/esm/visualization/human-readable-output.js +41 -18
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/dist/esm/visualization/json-output.d.ts +7 -3
- package/dist/esm/visualization/json-output.d.ts.map +1 -1
- package/dist/esm/visualization/json-output.js +35 -12
- package/dist/esm/visualization/json-output.js.map +1 -1
- package/dist/esm/visualization/mermaid-output.d.ts +7 -1
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
- package/dist/esm/visualization/mermaid-output.js +64 -9
- package/dist/esm/visualization/mermaid-output.js.map +1 -1
- package/dist/esm/visualization/object-like-output.d.ts +1 -1
- package/dist/esm/visualization/object-like-output.d.ts.map +1 -1
- package/dist/esm/visualization/object-like-output.js.map +1 -1
- package/package.json +30 -24
- package/dist/esm/reify/bin-paths.d.ts +0 -4
- package/dist/esm/reify/bin-paths.d.ts.map +0 -1
- package/dist/esm/reify/bin-paths.js +0 -23
- package/dist/esm/reify/bin-paths.js.map +0 -1
- package/dist/esm/types.d.ts +0 -42
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
|
@@ -1,39 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { platformCheck } from '@vltpkg/pick-manifest';
|
|
3
|
-
import { optionalFail } from "./optional-fail.js";
|
|
1
|
+
import { extractNode } from "./extract-node.js";
|
|
4
2
|
export const addNodes = (diff, scurry, remover, options, packageInfo) => {
|
|
5
3
|
const actions = [];
|
|
6
4
|
// fetch and extract all the nodes, removing any in the way
|
|
7
5
|
for (const node of diff.nodes.add) {
|
|
8
|
-
/* c8 ignore next - all nodes have manifests by this point */
|
|
9
|
-
const { manifest = {} } = node;
|
|
10
6
|
// if it's not in the store, we don't have to extract it, because
|
|
11
7
|
// we're just linking to a location that already exists.
|
|
12
8
|
if (!node.inVltStore())
|
|
13
9
|
continue;
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
const from = scurry.resolve('');
|
|
17
|
-
const spec = hydrate(node.id, manifest.name, options);
|
|
18
|
-
const onErr = optionalFail(diff, node);
|
|
19
|
-
const { integrity, resolved } = node;
|
|
20
|
-
// if it's optional, and we know it isn't for this platform, or it's
|
|
21
|
-
// deprecated, don't install it. if it's not optional, try our best.
|
|
22
|
-
if (onErr &&
|
|
23
|
-
(manifest.deprecated ||
|
|
24
|
-
!platformCheck(manifest, process.version, process.platform, process.arch))) {
|
|
25
|
-
onErr();
|
|
10
|
+
// skip nodes that have already been extracted
|
|
11
|
+
if (node.extracted)
|
|
26
12
|
continue;
|
|
27
|
-
|
|
28
|
-
actions.push(() => remover.rm(target).then(() => onErr ?
|
|
29
|
-
packageInfo
|
|
30
|
-
.extract(spec, target, { from, integrity, resolved })
|
|
31
|
-
.then(x => x, onErr)
|
|
32
|
-
: packageInfo.extract(spec, target, {
|
|
33
|
-
from,
|
|
34
|
-
integrity,
|
|
35
|
-
resolved,
|
|
36
|
-
})));
|
|
13
|
+
actions.push(() => extractNode(node, scurry, remover, options, packageInfo, diff));
|
|
37
14
|
}
|
|
38
15
|
return actions;
|
|
39
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-nodes.js","sourceRoot":"","sources":["../../../src/reify/add-nodes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add-nodes.js","sourceRoot":"","sources":["../../../src/reify/add-nodes.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAU,EACV,MAAkB,EAClB,OAAuB,EACvB,OAAoB,EACpB,WAA8B,EACF,EAAE;IAC9B,MAAM,OAAO,GAA+B,EAAE,CAAA;IAC9C,2DAA2D;IAC3D,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAClC,iEAAiE;QACjE,wDAAwD;QACxD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAAE,SAAQ;QAEhC,8CAA8C;QAC9C,IAAI,IAAI,CAAC,SAAS;YAAE,SAAQ;QAE5B,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAChB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAC/D,CAAA;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { PathScurry } from 'path-scurry'\nimport type { Diff } from '../diff.ts'\nimport { extractNode } from './extract-node.ts'\n\nexport const addNodes = (\n diff: Diff,\n scurry: PathScurry,\n remover: RollbackRemove,\n options: SpecOptions,\n packageInfo: PackageInfoClient,\n): (() => Promise<unknown>)[] => {\n const actions: (() => Promise<unknown>)[] = []\n // fetch and extract all the nodes, removing any in the way\n for (const node of diff.nodes.add) {\n // if it's not in the store, we don't have to extract it, because\n // we're just linking to a location that already exists.\n if (!node.inVltStore()) continue\n\n // skip nodes that have already been extracted\n if (node.extracted) continue\n\n actions.push(() =>\n extractNode(node, scurry, remover, options, packageInfo, diff),\n )\n }\n return actions\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PathScurry } from 'path-scurry';
|
|
2
|
+
import type { Node } from '../node.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Make all the packages' bins executable.
|
|
5
|
+
*/
|
|
6
|
+
export declare const binChmodAll: (nodes: Iterable<Node>, scurry: PathScurry) => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Make all the package's bins executable.
|
|
9
|
+
*/
|
|
10
|
+
export declare const binChmod: (node: Node, scurry: PathScurry) => Promise<void>;
|
|
11
|
+
//# sourceMappingURL=bin-chmod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin-chmod.d.ts","sourceRoot":"","sources":["../../../src/reify/bin-chmod.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC;;GAEG;AACH,eAAO,MAAM,WAAW,UACf,QAAQ,CAAC,IAAI,CAAC,UACb,UAAU,KACjB,OAAO,CAAC,IAAI,CAMd,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,SACb,IAAI,UACF,UAAU,KACjB,OAAO,CAAC,IAAI,CAad,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { statSync, existsSync } from 'node:fs';
|
|
2
|
+
import { chmod } from 'node:fs/promises';
|
|
3
|
+
/**
|
|
4
|
+
* Make all the packages' bins executable.
|
|
5
|
+
*/
|
|
6
|
+
export const binChmodAll = async (nodes, scurry) => {
|
|
7
|
+
const chmods = [];
|
|
8
|
+
for (const node of nodes) {
|
|
9
|
+
chmods.push(binChmod(node, scurry));
|
|
10
|
+
}
|
|
11
|
+
await Promise.all(chmods);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Make all the package's bins executable.
|
|
15
|
+
*/
|
|
16
|
+
export const binChmod = async (node, scurry) => {
|
|
17
|
+
const chmods = [];
|
|
18
|
+
if (!node.bins)
|
|
19
|
+
return;
|
|
20
|
+
for (const bin of Object.values(node.bins)) {
|
|
21
|
+
const path = scurry.resolve(`${node.resolvedLocation(scurry)}/${bin}`);
|
|
22
|
+
// only try to make executable if the file exists
|
|
23
|
+
if (existsSync(path)) {
|
|
24
|
+
chmods.push(makeExecutable(path));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
await Promise.all(chmods);
|
|
28
|
+
};
|
|
29
|
+
// 0 is "not yet set"
|
|
30
|
+
// This is defined by doing `0o111 | <mode>` so that systems
|
|
31
|
+
// that create files group-writable result in 0o775 instead of 0o755
|
|
32
|
+
let execMode = 0;
|
|
33
|
+
const makeExecutable = async (path) => {
|
|
34
|
+
if (!execMode) {
|
|
35
|
+
execMode = (statSync(path).mode & 0o777) | 0o111;
|
|
36
|
+
}
|
|
37
|
+
await chmod(path, execMode);
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=bin-chmod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin-chmod.js","sourceRoot":"","sources":["../../../src/reify/bin-chmod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAIxC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,KAAqB,EACrB,MAAkB,EACH,EAAE;IACjB,MAAM,MAAM,GAAoB,EAAE,CAAA;IAClC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;IACrC,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,IAAU,EACV,MAAkB,EACH,EAAE;IACjB,MAAM,MAAM,GAAoB,EAAE,CAAA;IAClC,IAAI,CAAC,IAAI,CAAC,IAAI;QAAE,OAAM;IACtB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CACzB,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,CAC1C,CAAA;QACD,iDAAiD;QACjD,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED,qBAAqB;AACrB,4DAA4D;AAC5D,oEAAoE;AACpE,IAAI,QAAQ,GAAG,CAAC,CAAA;AAChB,MAAM,cAAc,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAA;IAClD,CAAC;IACD,MAAM,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["import { statSync, existsSync } from 'node:fs'\nimport { chmod } from 'node:fs/promises'\nimport type { PathScurry } from 'path-scurry'\nimport type { Node } from '../node.ts'\n\n/**\n * Make all the packages' bins executable.\n */\nexport const binChmodAll = async (\n nodes: Iterable<Node>,\n scurry: PathScurry,\n): Promise<void> => {\n const chmods: Promise<void>[] = []\n for (const node of nodes) {\n chmods.push(binChmod(node, scurry))\n }\n await Promise.all(chmods)\n}\n\n/**\n * Make all the package's bins executable.\n */\nexport const binChmod = async (\n node: Node,\n scurry: PathScurry,\n): Promise<void> => {\n const chmods: Promise<void>[] = []\n if (!node.bins) return\n for (const bin of Object.values(node.bins)) {\n const path = scurry.resolve(\n `${node.resolvedLocation(scurry)}/${bin}`,\n )\n // only try to make executable if the file exists\n if (existsSync(path)) {\n chmods.push(makeExecutable(path))\n }\n }\n await Promise.all(chmods)\n}\n\n// 0 is \"not yet set\"\n// This is defined by doing `0o111 | <mode>` so that systems\n// that create files group-writable result in 0o775 instead of 0o755\nlet execMode = 0\nconst makeExecutable = async (path: string) => {\n if (!execMode) {\n execMode = (statSync(path).mode & 0o777) | 0o111\n }\n await chmod(path, execMode)\n}\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { PackageJson } from '@vltpkg/package-json';
|
|
2
2
|
import type { PathScurry } from 'path-scurry';
|
|
3
|
+
import type { DepID } from '@vltpkg/dep-id';
|
|
3
4
|
import type { Diff } from '../diff.ts';
|
|
4
|
-
|
|
5
|
+
import type { Node } from '../node.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Returns an object mapping registries to the names of the packages built.
|
|
8
|
+
*/
|
|
9
|
+
export type BuildResult = {
|
|
10
|
+
success: Node[];
|
|
11
|
+
failure: Node[];
|
|
12
|
+
};
|
|
13
|
+
export declare const build: (diff: Diff, packageJson: PackageJson, scurry: PathScurry, allowScriptsNodes: Set<DepID>) => Promise<BuildResult>;
|
|
5
14
|
//# sourceMappingURL=build.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAKtC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,IAAI,EAAE,CAAA;IACf,OAAO,EAAE,IAAI,EAAE,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,KAAK,SACV,IAAI,eACG,WAAW,UAChB,UAAU,qBACC,GAAG,CAAC,KAAK,CAAC,KAC5B,OAAO,CAAC,WAAW,CA6DrB,CAAA"}
|
package/dist/esm/reify/build.js
CHANGED
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
// at the end, we get back to the importers, and run their prepare
|
|
3
3
|
// script as well as install script.
|
|
4
4
|
import { run } from '@vltpkg/run';
|
|
5
|
-
import { statSync } from 'node:fs';
|
|
6
|
-
import { chmod } from 'node:fs/promises';
|
|
7
5
|
import { graphRun } from 'graph-run';
|
|
8
6
|
import { nonEmptyList } from "../non-empty-list.js";
|
|
9
|
-
import { binPaths } from "./bin-paths.js";
|
|
10
7
|
import { optionalFail } from "./optional-fail.js";
|
|
11
|
-
|
|
8
|
+
import { binChmod } from "./bin-chmod.js";
|
|
9
|
+
export const build = async (diff, packageJson, scurry, allowScriptsNodes) => {
|
|
12
10
|
const graph = diff.to;
|
|
13
11
|
const nodes = nonEmptyList([...graph.importers]);
|
|
12
|
+
const res = { success: [], failure: [] };
|
|
13
|
+
// determine if scripts should run - check if node is in allowed set
|
|
14
|
+
const shouldRunScripts = (node) => allowScriptsNodes.has(node.id);
|
|
14
15
|
/* c8 ignore next - all graphs have at least one importer */
|
|
15
16
|
if (!nodes)
|
|
16
|
-
return;
|
|
17
|
+
return res;
|
|
17
18
|
await graphRun({
|
|
18
19
|
graph: nodes,
|
|
19
20
|
visit: async (node, signal, path) => {
|
|
@@ -23,9 +24,31 @@ export const build = async (diff, packageJson, scurry) => {
|
|
|
23
24
|
// most recent build.
|
|
24
25
|
// For now, just always build all importers, because we don't
|
|
25
26
|
// track all that other stuff.
|
|
26
|
-
if (!node.importer &&
|
|
27
|
+
if (!node.importer &&
|
|
28
|
+
(!diff.nodes.add.has(node) || !shouldRunScripts(node)))
|
|
27
29
|
return;
|
|
28
|
-
|
|
30
|
+
try {
|
|
31
|
+
await visit(packageJson, scurry, node, signal, path);
|
|
32
|
+
if (!node.importer) {
|
|
33
|
+
node.buildState = 'built';
|
|
34
|
+
res.success.push(node);
|
|
35
|
+
}
|
|
36
|
+
/* c8 ignore start - windows on CI is missing those tests */
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
// Check if this is an optional failure that was handled
|
|
40
|
+
if (node.optional) {
|
|
41
|
+
node.buildState = 'failed';
|
|
42
|
+
res.failure.push(node);
|
|
43
|
+
// Let optionalFail handle the error
|
|
44
|
+
await Promise.reject(err).catch(optionalFail(diff, node));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Re-throw non-optional failures
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/* c8 ignore stop */
|
|
29
52
|
},
|
|
30
53
|
getDeps: node => {
|
|
31
54
|
const deps = [];
|
|
@@ -37,8 +60,13 @@ export const build = async (diff, packageJson, scurry) => {
|
|
|
37
60
|
return deps;
|
|
38
61
|
},
|
|
39
62
|
});
|
|
63
|
+
return res;
|
|
40
64
|
};
|
|
41
65
|
const visit = async (packageJson, scurry, node, signal, _path) => {
|
|
66
|
+
// at this point we might have to read the manifest from disk if it's
|
|
67
|
+
// currently nullish, that could happen in a scenario where the ideal
|
|
68
|
+
// graph is from a lockfile and there's no actual graph available
|
|
69
|
+
// to hydrate the manifest data from.
|
|
42
70
|
node.manifest ??= packageJson.read(node.resolvedLocation(scurry));
|
|
43
71
|
const { manifest } = node;
|
|
44
72
|
const { scripts = {} } = manifest;
|
|
@@ -70,21 +98,6 @@ const visit = async (packageJson, scurry, node, signal, _path) => {
|
|
|
70
98
|
manifest,
|
|
71
99
|
});
|
|
72
100
|
}
|
|
73
|
-
|
|
74
|
-
for (const bin of Object.values(binPaths(manifest))) {
|
|
75
|
-
const path = scurry.resolve(`${node.resolvedLocation(scurry)}/${bin}`);
|
|
76
|
-
chmods.push(makeExecutable(path));
|
|
77
|
-
}
|
|
78
|
-
await Promise.all(chmods);
|
|
79
|
-
};
|
|
80
|
-
// 0 is "not yet set"
|
|
81
|
-
// This is defined by doing `0o111 | <mode>` so that systems
|
|
82
|
-
// that create files group-writable result in 0o775 instead of 0o755
|
|
83
|
-
let execMode = 0;
|
|
84
|
-
const makeExecutable = async (path) => {
|
|
85
|
-
if (!execMode) {
|
|
86
|
-
execMode = (statSync(path).mode & 0o777) | 0o111;
|
|
87
|
-
}
|
|
88
|
-
await chmod(path, execMode);
|
|
101
|
+
await binChmod(node, scurry);
|
|
89
102
|
};
|
|
90
103
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAClE,oCAAoC;AAGpC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAClE,oCAAoC;AAGpC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAKpC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAUzC,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,IAAU,EACV,WAAwB,EACxB,MAAkB,EAClB,iBAA6B,EACP,EAAE;IACxB,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAA;IACrB,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAA;IAChD,MAAM,GAAG,GAAgB,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;IAErD,oEAAoE;IACpE,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAW,EAAE,CAC/C,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEhC,4DAA4D;IAC5D,IAAI,C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AAQ,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAClE,MAAM,UAAU,GACd,CAAC,CAAC,CAAC,OAAO,IAAI,UAAU,IAAI,WAAW,CAAC,IAAI,QAAQ,CAAA;IAEtD,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,GAAG,CAAC;YACR,MAAM;YACN,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,WAAW;YACX,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;YAClC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC9B,CAAC,CAAA","sourcesContent":["// walk the graph of added nodes, building and chmoding their bins\n// at the end, we get back to the importers, and run their prepare\n// script as well as install script.\n\nimport type { PackageJson } from '@vltpkg/package-json'\nimport { run } from '@vltpkg/run'\nimport { graphRun } from 'graph-run'\nimport type { PathScurry } from 'path-scurry'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\nimport { nonEmptyList } from '../non-empty-list.ts'\nimport { optionalFail } from './optional-fail.ts'\nimport { binChmod } from './bin-chmod.ts'\n\n/**\n * Returns an object mapping registries to the names of the packages built.\n */\nexport type BuildResult = {\n success: Node[]\n failure: Node[]\n}\n\nexport const build = async (\n diff: Diff,\n packageJson: PackageJson,\n scurry: PathScurry,\n allowScriptsNodes: Set<DepID>,\n): Promise<BuildResult> => {\n const graph = diff.to\n const nodes = nonEmptyList([...graph.importers])\n const res: BuildResult = { success: [], failure: [] }\n\n // determine if scripts should run - check if node is in allowed set\n const shouldRunScripts = (node: Node): boolean =>\n allowScriptsNodes.has(node.id)\n\n /* c8 ignore next - all graphs have at least one importer */\n if (!nodes) return res\n\n await graphRun<Node, unknown>({\n graph: nodes,\n visit: async (node: Node, signal, path) => {\n // if it's not an importer or an added node, nothing to do.\n // TODO: only build importers if it has changed deps, there's never\n // been a previous build, or it contains something newer than the\n // most recent build.\n // For now, just always build all importers, because we don't\n // track all that other stuff.\n\n if (\n !node.importer &&\n (!diff.nodes.add.has(node) || !shouldRunScripts(node))\n )\n return\n\n try {\n await visit(packageJson, scurry, node, signal, path)\n if (!node.importer) {\n node.buildState = 'built'\n res.success.push(node)\n }\n /* c8 ignore start - windows on CI is missing those tests */\n } catch (err) {\n // Check if this is an optional failure that was handled\n if (node.optional) {\n node.buildState = 'failed'\n res.failure.push(node)\n // Let optionalFail handle the error\n await Promise.reject(err).catch(optionalFail(diff, node))\n } else {\n // Re-throw non-optional failures\n throw err\n }\n }\n /* c8 ignore stop */\n },\n\n getDeps: node => {\n const deps: Node[] = []\n for (const { to } of node.edgesOut.values()) {\n /* c8 ignore next - vanishingly unlikely in practice */\n if (to) deps.push(to)\n }\n return deps\n },\n })\n\n return res\n}\n\nconst visit = async (\n packageJson: PackageJson,\n scurry: PathScurry,\n node: Node,\n signal: AbortSignal,\n _path: Node[],\n): Promise<void> => {\n // at this point we might have to read the manifest from disk if it's\n // currently nullish, that could happen in a scenario where the ideal\n // graph is from a lockfile and there's no actual graph available\n // to hydrate the manifest data from.\n node.manifest ??= packageJson.read(node.resolvedLocation(scurry))\n const { manifest } = node\n const { scripts = {} } = manifest\n\n const {\n install,\n preinstall,\n postinstall,\n prepare,\n preprepare,\n postprepare,\n } = scripts\n\n // if it has install script, run it\n const runInstall = !!(install || preinstall || postinstall)\n if (runInstall) {\n await run({\n signal,\n arg0: 'install',\n ignoreMissing: true,\n packageJson,\n cwd: node.resolvedLocation(scurry),\n projectRoot: node.projectRoot,\n manifest,\n })\n }\n\n // if it's an importer or git, run prepare\n const prepable =\n node.id.startsWith('git') || node.importer || !node.inVltStore()\n const runPrepare =\n !!(prepare || preprepare || postprepare) && prepable\n\n if (runPrepare) {\n await run({\n signal,\n arg0: 'prepare',\n ignoreMissing: true,\n packageJson,\n cwd: node.resolvedLocation(scurry),\n projectRoot: node.projectRoot,\n manifest,\n })\n }\n\n await binChmod(node, scurry)\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-save-value.d.ts","sourceRoot":"","sources":["../../../src/reify/calculate-save-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGxC,eAAO,MAAM,kBAAkB,aACnB,MAAM,QACV,IAAI,YACA,MAAM,GAAG,SAAS,eACf,MAAM,GAAG,SAAS,KAC9B,MAoDF,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const SAVE_PREFIX = '^';
|
|
2
|
+
export const calculateSaveValue = (nodeType, spec, existing, nodeVersion) => {
|
|
3
|
+
if (
|
|
4
|
+
// if not from the registry, save whatever we requested
|
|
5
|
+
nodeType === 'registry' &&
|
|
6
|
+
// if we installed exactly what we already wanted, leave it untouched
|
|
7
|
+
spec.bareSpec !== existing &&
|
|
8
|
+
// if we installed a specific version, keep that specific version.
|
|
9
|
+
!spec.final.range?.isSingle) {
|
|
10
|
+
// if we had a single version, and got that version, then
|
|
11
|
+
// leave it as-is.
|
|
12
|
+
if (existing && existing === nodeVersion) {
|
|
13
|
+
// depend on 1.2.3, got 1.2.3, keep unchanged
|
|
14
|
+
return existing;
|
|
15
|
+
}
|
|
16
|
+
else if (existing && !spec.bareSpec) {
|
|
17
|
+
// if we had `"express": "5.1"` and did `vlt i express`,
|
|
18
|
+
// then leave it as-is, because we just installed our pj dep
|
|
19
|
+
return existing;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const finalRange = (spec.final.semver && spec.final.bareSpec) ||
|
|
23
|
+
`${SAVE_PREFIX}${nodeVersion}`;
|
|
24
|
+
// didn't have dep previously, or depended on a different thing
|
|
25
|
+
// than what was requested. Update with the ^ range based on
|
|
26
|
+
// the node that landed in the graph, but preserve alias prefix
|
|
27
|
+
if (spec.subspec && spec.final.namedRegistry) {
|
|
28
|
+
return `${spec.final.namedRegistry}:${spec.final.name}@${finalRange}`;
|
|
29
|
+
}
|
|
30
|
+
if (spec.final.namedJsrRegistry) {
|
|
31
|
+
// if we were given an alternative name, preserve that
|
|
32
|
+
// do this with a regexp because the Spec objects get a little
|
|
33
|
+
// weird here, and the string is relatively straightforward.
|
|
34
|
+
return spec.bareSpec
|
|
35
|
+
.replace(new RegExp(`^(?:.*?@)?${spec.final.namedJsrRegistry}:(@[^/]+/[^@]+)(@.*?)?$`), `${spec.final.namedJsrRegistry}:$1@${finalRange}`)
|
|
36
|
+
.replace(
|
|
37
|
+
// otherwise, swap out the final version for the save range
|
|
38
|
+
new RegExp(`^(?:.*?@)?${spec.final.namedJsrRegistry}:([^@].*?)?$`), `${spec.final.namedJsrRegistry}:${finalRange}`);
|
|
39
|
+
}
|
|
40
|
+
return finalRange;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return spec.bareSpec;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=calculate-save-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-save-value.js","sourceRoot":"","sources":["../../../src/reify/calculate-save-value.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,GAAG,GAAG,CAAA;AAEvB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,QAAgB,EAChB,IAAU,EACV,QAA4B,EAC5B,WAA+B,EACvB,EAAE;IACV;IACE,uDAAuD;IACvD,QAAQ,KAAK,UAAU;QACvB,qEAAqE;QACrE,IAAI,CAAC,QAAQ,KAAK,QAAQ;QAC1B,kEAAkE;QAClE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAC3B,CAAC;QACD,yDAAyD;QACzD,kBAAkB;QAClB,IAAI,QAAQ,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;YACzC,6CAA6C;YAC7C,OAAO,QAAQ,CAAA;QACjB,CAAC;aAAM,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACtC,wDAAwD;YACxD,4DAA4D;YAC5D,OAAO,QAAQ,CAAA;QACjB,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,GACd,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;gBAC1C,GAAG,WAAW,GAAG,WAAW,EAAE,CAAA;YAChC,+DAA+D;YAC/D,4DAA4D;YAC5D,+DAA+D;YAC/D,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;gBAC7C,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,UAAU,EAAE,CAAA;YACvE,CAAC;YAED,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;gBAChC,sDAAsD;gBACtD,8DAA8D;gBAC9D,4DAA4D;gBAC5D,OAAO,IAAI,CAAC,QAAQ;qBACjB,OAAO,CACN,IAAI,MAAM,CACR,aAAa,IAAI,CAAC,KAAK,CAAC,gBAAgB,yBAAyB,CAClE,EACD,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,OAAO,UAAU,EAAE,CAClD;qBACA,OAAO;gBACN,2DAA2D;gBAC3D,IAAI,MAAM,CACR,aAAa,IAAI,CAAC,KAAK,CAAC,gBAAgB,cAAc,CACvD,EACD,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAAI,UAAU,EAAE,CAC/C,CAAA;YACL,CAAC;YACD,OAAO,UAAU,CAAA;QACnB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import type { Spec } from '@vltpkg/spec'\nconst SAVE_PREFIX = '^'\n\nexport const calculateSaveValue = (\n nodeType: string,\n spec: Spec,\n existing: string | undefined,\n nodeVersion: string | undefined,\n): string => {\n if (\n // if not from the registry, save whatever we requested\n nodeType === 'registry' &&\n // if we installed exactly what we already wanted, leave it untouched\n spec.bareSpec !== existing &&\n // if we installed a specific version, keep that specific version.\n !spec.final.range?.isSingle\n ) {\n // if we had a single version, and got that version, then\n // leave it as-is.\n if (existing && existing === nodeVersion) {\n // depend on 1.2.3, got 1.2.3, keep unchanged\n return existing\n } else if (existing && !spec.bareSpec) {\n // if we had `\"express\": \"5.1\"` and did `vlt i express`,\n // then leave it as-is, because we just installed our pj dep\n return existing\n } else {\n const finalRange =\n (spec.final.semver && spec.final.bareSpec) ||\n `${SAVE_PREFIX}${nodeVersion}`\n // didn't have dep previously, or depended on a different thing\n // than what was requested. Update with the ^ range based on\n // the node that landed in the graph, but preserve alias prefix\n if (spec.subspec && spec.final.namedRegistry) {\n return `${spec.final.namedRegistry}:${spec.final.name}@${finalRange}`\n }\n\n if (spec.final.namedJsrRegistry) {\n // if we were given an alternative name, preserve that\n // do this with a regexp because the Spec objects get a little\n // weird here, and the string is relatively straightforward.\n return spec.bareSpec\n .replace(\n new RegExp(\n `^(?:.*?@)?${spec.final.namedJsrRegistry}:(@[^/]+/[^@]+)(@.*?)?$`,\n ),\n `${spec.final.namedJsrRegistry}:$1@${finalRange}`,\n )\n .replace(\n // otherwise, swap out the final version for the save range\n new RegExp(\n `^(?:.*?@)?${spec.final.namedJsrRegistry}:([^@].*?)?$`,\n ),\n `${spec.final.namedJsrRegistry}:${finalRange}`,\n )\n }\n return finalRange\n }\n }\n return spec.bareSpec\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Diff } from '../diff.ts';
|
|
2
|
+
import type { Node } from '../node.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Build data containing the queue of DepIDs that need building
|
|
5
|
+
*/
|
|
6
|
+
export type BuildData = {
|
|
7
|
+
needsBuildNodes: Node[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Options for checking needed build data
|
|
11
|
+
*/
|
|
12
|
+
export type CheckNeededBuildOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The diff object containing nodes to process
|
|
15
|
+
*/
|
|
16
|
+
diff: Diff;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Check which nodes need to be built and set buildState accordingly
|
|
20
|
+
* Marks nodes with buildState = 'needed' for those that require
|
|
21
|
+
* install lifecycle scripts as part of `vlt build`
|
|
22
|
+
* @returns {BuildData} The BuildData object containing Node objects that need building
|
|
23
|
+
*/
|
|
24
|
+
export declare const checkNeededBuild: (options: CheckNeededBuildOptions) => BuildData;
|
|
25
|
+
//# sourceMappingURL=check-needed-build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-needed-build.d.ts","sourceRoot":"","sources":["../../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,eAAe,EAAE,IAAI,EAAE,CAAA;CACxB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAuCD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAClB,uBAAuB,KAC/B,SAgBF,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a node needs to be built based on the conditions from build.ts:
|
|
3
|
+
* 1. Has install lifecycle scripts (install, preinstall, postinstall)
|
|
4
|
+
* 2. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)
|
|
5
|
+
* 3. Has binary files that need to be linked
|
|
6
|
+
*/
|
|
7
|
+
const nodeNeedsBuild = (node) => {
|
|
8
|
+
// If the node has already been built during reify, no need to build again
|
|
9
|
+
if (node.built)
|
|
10
|
+
return false;
|
|
11
|
+
const { manifest } = node;
|
|
12
|
+
/* c8 ignore next */
|
|
13
|
+
if (!manifest)
|
|
14
|
+
return false;
|
|
15
|
+
const { scripts = {} } = manifest;
|
|
16
|
+
// Check for install lifecycle scripts
|
|
17
|
+
const runInstall = !!(scripts.install ||
|
|
18
|
+
scripts.preinstall ||
|
|
19
|
+
scripts.postinstall);
|
|
20
|
+
if (runInstall)
|
|
21
|
+
return true;
|
|
22
|
+
// Check for prepare scripts on importers or git dependencies
|
|
23
|
+
const prepable = node.id.startsWith('git') || node.importer || !node.inVltStore();
|
|
24
|
+
const runPrepare = !!((scripts.prepare || scripts.preprepare || scripts.postprepare)
|
|
25
|
+
/* c8 ignore next 2 */
|
|
26
|
+
) && prepable;
|
|
27
|
+
if (runPrepare)
|
|
28
|
+
return true;
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Check which nodes need to be built and set buildState accordingly
|
|
33
|
+
* Marks nodes with buildState = 'needed' for those that require
|
|
34
|
+
* install lifecycle scripts as part of `vlt build`
|
|
35
|
+
* @returns {BuildData} The BuildData object containing Node objects that need building
|
|
36
|
+
*/
|
|
37
|
+
export const checkNeededBuild = (options) => {
|
|
38
|
+
const { diff } = options;
|
|
39
|
+
// Filter nodes to only include those that actually need to be built
|
|
40
|
+
const nodesToBuild = [...diff.nodes.add].filter(nodeNeedsBuild);
|
|
41
|
+
// Set buildState = 'needed' on all nodes that require building
|
|
42
|
+
for (const node of nodesToBuild) {
|
|
43
|
+
node.buildState = 'needed';
|
|
44
|
+
}
|
|
45
|
+
const buildData = {
|
|
46
|
+
needsBuildNodes: nodesToBuild,
|
|
47
|
+
};
|
|
48
|
+
return buildData;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=check-needed-build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-needed-build.js","sourceRoot":"","sources":["../../../src/reify/check-needed-build.ts"],"names":[],"mappings":"AAoBA;;;;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A;IAC5B,CAAC;IAED,MAAM,SAAS,GAAc;QAC3B,eAAe,EAAE,YAAY;KAC9B,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA","sourcesContent":["import type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\n\n/**\n * Build data containing the queue of DepIDs that need building\n */\nexport type BuildData = {\n needsBuildNodes: Node[]\n}\n\n/**\n * Options for checking needed build data\n */\nexport type CheckNeededBuildOptions = {\n /**\n * The diff object containing nodes to process\n */\n diff: Diff\n}\n\n/**\n * Checks if a node needs to be built based on the conditions from build.ts:\n * 1. Has install lifecycle scripts (install, preinstall, postinstall)\n * 2. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)\n * 3. Has binary files that need to be linked\n */\nconst nodeNeedsBuild = (node: Node): boolean => {\n // If the node has already been built during reify, no need to build again\n if (node.built) return false\n\n const { manifest } = node\n /* c8 ignore next */\n if (!manifest) return false\n\n const { scripts = {} } = manifest\n\n // Check for install lifecycle scripts\n const runInstall = !!(\n scripts.install ||\n scripts.preinstall ||\n scripts.postinstall\n )\n if (runInstall) return true\n\n // Check for prepare scripts on importers or git dependencies\n const prepable =\n node.id.startsWith('git') || node.importer || !node.inVltStore()\n const runPrepare =\n !!(\n (scripts.prepare || scripts.preprepare || scripts.postprepare)\n /* c8 ignore next 2 */\n ) && prepable\n if (runPrepare) return true\n\n return false\n}\n\n/**\n * Check which nodes need to be built and set buildState accordingly\n * Marks nodes with buildState = 'needed' for those that require\n * install lifecycle scripts as part of `vlt build`\n * @returns {BuildData} The BuildData object containing Node objects that need building\n */\nexport const checkNeededBuild = (\n options: CheckNeededBuildOptions,\n): BuildData => {\n const { diff } = options\n\n // Filter nodes to only include those that actually need to be built\n const nodesToBuild = [...diff.nodes.add].filter(nodeNeedsBuild)\n\n // Set buildState = 'needed' on all nodes that require building\n for (const node of nodesToBuild) {\n node.buildState = 'needed'\n }\n\n const buildData: BuildData = {\n needsBuildNodes: nodesToBuild,\n }\n\n return buildData\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-edge.d.ts","sourceRoot":"","sources":["../../../src/reify/delete-edge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"delete-edge.d.ts","sourceRoot":"","sources":["../../../src/reify/delete-edge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAgBtC,eAAO,MAAM,UAAU,SACf,IAAI,UACF,UAAU,WACT,cAAc,kBAmBxB,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { binPaths } from "./bin-paths.js";
|
|
2
1
|
const rmBinPosix = (remover, bin) => {
|
|
3
2
|
return [remover.rm(bin)];
|
|
4
3
|
};
|
|
@@ -17,9 +16,9 @@ export const deleteEdge = async (edge, scurry, remover) => {
|
|
|
17
16
|
const binRoot = scurry.cwd.resolve(`${nm}/.bin`);
|
|
18
17
|
const promises = [];
|
|
19
18
|
promises.push(remover.rm(path));
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
for (const key of Object.keys(
|
|
19
|
+
const bins = to?.bins;
|
|
20
|
+
if (bins) {
|
|
21
|
+
for (const key of Object.keys(bins)) {
|
|
23
22
|
const bin = binRoot.resolve(key).fullpath();
|
|
24
23
|
promises.push(...rmBin(remover, bin));
|
|
25
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-edge.js","sourceRoot":"","sources":["../../../src/reify/delete-edge.ts"],"names":[],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,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,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 type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport type { PathScurry } from 'path-scurry'\nimport type { Edge } from '../edge.ts'\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 + '.ps1'),\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(scurry)\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 bins = to?.bins\n if (bins) {\n for (const key of Object.keys(bins)) {\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,24 @@
|
|
|
1
|
+
import type { PackageInfoClient } from '@vltpkg/package-info';
|
|
2
|
+
import type { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
3
|
+
import type { SpecOptions } from '@vltpkg/spec';
|
|
4
|
+
import type { PathScurry } from 'path-scurry';
|
|
5
|
+
import type { Diff } from '../diff.ts';
|
|
6
|
+
import type { Node } from '../node.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Result of the extraction operation.
|
|
9
|
+
* Either the extracted package data or an error if extraction failed.
|
|
10
|
+
*/
|
|
11
|
+
export type ExtractResult = {
|
|
12
|
+
success: true;
|
|
13
|
+
node: Node;
|
|
14
|
+
} | {
|
|
15
|
+
success: false;
|
|
16
|
+
node: Node;
|
|
17
|
+
error: unknown;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Extract a single node to the file system.
|
|
21
|
+
* Returns a promise that resolves when the extraction is complete.
|
|
22
|
+
*/
|
|
23
|
+
export declare const extractNode: (node: Node, scurry: PathScurry, remover: RollbackRemove, options: SpecOptions, packageInfo: PackageInfoClient, diff?: Diff) => Promise<ExtractResult>;
|
|
24
|
+
//# sourceMappingURL=extract-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-node.d.ts","sourceRoot":"","sources":["../../../src/reify/extract-node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAItC;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB;IACE,OAAO,EAAE,IAAI,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;CACX,GACD;IACE,OAAO,EAAE,KAAK,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAgBL;;;GAGG;AACH,eAAO,MAAM,WAAW,SAChB,IAAI,UACF,UAAU,WACT,cAAc,WACd,WAAW,eACP,iBAAiB,SACvB,IAAI,KACV,OAAO,CAAC,aAAa,CAkEvB,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { hydrate } from '@vltpkg/dep-id';
|
|
2
|
+
import { platformCheck } from '@vltpkg/pick-manifest';
|
|
3
|
+
import { optionalFail } from "./optional-fail.js";
|
|
4
|
+
import { removeOptionalSubgraph } from "../remove-optional-subgraph.js";
|
|
5
|
+
/**
|
|
6
|
+
* Returns a function that handles removing
|
|
7
|
+
* a failed optional node from its graph.
|
|
8
|
+
* Returns undefined for non-optional nodes when no diff is provided.
|
|
9
|
+
*/
|
|
10
|
+
const getOptionalFailedNodeRemover = (node, diff) => {
|
|
11
|
+
return (diff ? optionalFail(diff, node)
|
|
12
|
+
: node.isOptional() ?
|
|
13
|
+
() => removeOptionalSubgraph(node.graph, node)
|
|
14
|
+
: undefined);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Extract a single node to the file system.
|
|
18
|
+
* Returns a promise that resolves when the extraction is complete.
|
|
19
|
+
*/
|
|
20
|
+
export const extractNode = async (node, scurry, remover, options, packageInfo, diff) => {
|
|
21
|
+
node.extracted = true;
|
|
22
|
+
const { manifest = {} } = node;
|
|
23
|
+
const target = node.resolvedLocation(scurry);
|
|
24
|
+
const from = scurry.resolve('');
|
|
25
|
+
const spec = hydrate(node.id, node.name, options);
|
|
26
|
+
const removeOptionalFailedNode = getOptionalFailedNodeRemover(node, diff);
|
|
27
|
+
const { integrity, resolved } = node;
|
|
28
|
+
// Use platform data from node if available (from lockfile), otherwise fall back to manifest
|
|
29
|
+
const platformData = node.platform ?? manifest;
|
|
30
|
+
// Check if we should skip this node due to platform incompatibility or deprecation
|
|
31
|
+
if (removeOptionalFailedNode &&
|
|
32
|
+
(manifest.deprecated ||
|
|
33
|
+
!platformCheck(platformData, process.version, process.platform, process.arch))) {
|
|
34
|
+
removeOptionalFailedNode();
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
node,
|
|
38
|
+
error: new Error('Platform check failed or package deprecated'),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
await remover.rm(target);
|
|
43
|
+
if (removeOptionalFailedNode) {
|
|
44
|
+
try {
|
|
45
|
+
await packageInfo.extract(spec, target, {
|
|
46
|
+
from,
|
|
47
|
+
integrity,
|
|
48
|
+
resolved,
|
|
49
|
+
});
|
|
50
|
+
return { success: true, node };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
removeOptionalFailedNode();
|
|
54
|
+
return { success: false, node, error };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
await packageInfo.extract(spec, target, {
|
|
59
|
+
from,
|
|
60
|
+
integrity,
|
|
61
|
+
resolved,
|
|
62
|
+
});
|
|
63
|
+
return { success: true, node };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
/* c8 ignore start */
|
|
68
|
+
if (removeOptionalFailedNode) {
|
|
69
|
+
removeOptionalFailedNode();
|
|
70
|
+
return { success: false, node, error };
|
|
71
|
+
}
|
|
72
|
+
/* c8 ignore stop */
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=extract-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-node.js","sourceRoot":"","sources":["../../../src/reify/extract-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAMrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAiBvE;;;;GAIG;AACH,MAAM,4BAA4B,GAAG,CAAC,IAAU,EAAE,IAAW,EAAE,EAAE;IAC/D,OAAO,CACL,IAAI,CAAC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CAA6C,CAAC;SAChE,CAAA;IACH,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;QAExB,IAAI,wBAAwB,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE;oBACtC,IAAI;oBACJ,SAAS;oBACT,QAAQ;iBACT,CAAC,CAAA;gBACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;YAChC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,wBAAwB,EAAE,CAAA;gBAC1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;YACxC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE;gBACtC,IAAI;gBACJ,SAAS;gBACT,QAAQ;aACT,CAAC,CAAA;YACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAChC,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qBAAqB;QACrB,IAAI,wBAAwB,EAAE,CAAC;YAC7B,wBAAwB,EAAE,CAAA;YAC1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;QACxC,CAAC;QACD,oBAAoB;QACpB,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { hydrate } from '@vltpkg/dep-id'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { platformCheck } from '@vltpkg/pick-manifest'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { PathScurry } from 'path-scurry'\nimport type { Diff } from '../diff.ts'\nimport type { Node } from '../node.ts'\nimport { optionalFail } from './optional-fail.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\n\n/**\n * Result of the extraction operation.\n * Either the extracted package data or an error if extraction failed.\n */\nexport type ExtractResult =\n | {\n success: true\n node: Node\n }\n | {\n success: false\n node: Node\n error: unknown\n }\n\n/**\n * Returns a function that handles removing\n * a failed optional node from its graph.\n * Returns undefined for non-optional nodes when no diff is provided.\n */\nconst getOptionalFailedNodeRemover = (node: Node, diff?: Diff) => {\n return (\n diff ? optionalFail(diff, node)\n : node.isOptional() ?\n () => removeOptionalSubgraph(node.graph, node)\n : undefined\n )\n}\n\n/**\n * Extract a single node to the file system.\n * Returns a promise that resolves when the extraction is complete.\n */\nexport const extractNode = async (\n node: Node,\n scurry: PathScurry,\n remover: RollbackRemove,\n options: SpecOptions,\n packageInfo: PackageInfoClient,\n diff?: Diff,\n): Promise<ExtractResult> => {\n node.extracted = true\n const { manifest = {} } = node\n const target = node.resolvedLocation(scurry)\n const from = scurry.resolve('')\n const spec = hydrate(node.id, node.name, options)\n const removeOptionalFailedNode = getOptionalFailedNodeRemover(\n node,\n diff,\n )\n const { integrity, resolved } = node\n\n // Use platform data from node if available (from lockfile), otherwise fall back to manifest\n const platformData = node.platform ?? manifest\n\n // Check if we should skip this node due to platform incompatibility or deprecation\n if (\n removeOptionalFailedNode &&\n (manifest.deprecated ||\n !platformCheck(\n platformData,\n process.version,\n process.platform,\n process.arch,\n ))\n ) {\n removeOptionalFailedNode()\n return {\n success: false,\n node,\n error: new Error('Platform check failed or package deprecated'),\n }\n }\n\n try {\n await remover.rm(target)\n\n if (removeOptionalFailedNode) {\n try {\n await packageInfo.extract(spec, target, {\n from,\n integrity,\n resolved,\n })\n return { success: true, node }\n } catch (error) {\n removeOptionalFailedNode()\n return { success: false, node, error }\n }\n } else {\n await packageInfo.extract(spec, target, {\n from,\n integrity,\n resolved,\n })\n return { success: true, node }\n }\n } catch (error) {\n /* c8 ignore start */\n if (removeOptionalFailedNode) {\n removeOptionalFailedNode()\n return { success: false, node, error }\n }\n /* c8 ignore stop */\n throw error\n }\n}\n"]}
|