@vltpkg/graph 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ideal/append-nodes.d.ts +1 -1
- package/dist/ideal/append-nodes.js +9 -12
- package/dist/ideal/build.js +4 -0
- package/dist/ideal/prefetch-resolve.d.ts +15 -0
- package/dist/ideal/prefetch-resolve.js +75 -0
- package/dist/reify/build.js +9 -5
- package/dist/reify/extract-node.js +0 -8
- package/dist/reify/unshare.d.ts +7 -0
- package/dist/reify/unshare.js +59 -0
- package/package.json +21 -21
|
@@ -18,7 +18,7 @@ import type { ExplicitAddMap, TransientAddMap, TransientRemoveMap } from './type
|
|
|
18
18
|
*
|
|
19
19
|
* 1. Process all deps at the current level in parallel
|
|
20
20
|
* 2. After each level, run `postPlacementPeerCheck` to handle peer contexts
|
|
21
|
-
* 3. Collect child deps for the next level
|
|
21
|
+
* 3. Collect child deps for the next level, each node once
|
|
22
22
|
* 4. Repeat until no more deps to process
|
|
23
23
|
*
|
|
24
24
|
* **Peer Context Isolation**: Each workspace importer gets its own peer context
|
|
@@ -621,7 +621,7 @@ const processPlacementTasks = async (graph, options, placementTasks, add, modifi
|
|
|
621
621
|
*
|
|
622
622
|
* 1. Process all deps at the current level in parallel
|
|
623
623
|
* 2. After each level, run `postPlacementPeerCheck` to handle peer contexts
|
|
624
|
-
* 3. Collect child deps for the next level
|
|
624
|
+
* 3. Collect child deps for the next level, each node once
|
|
625
625
|
* 4. Repeat until no more deps to process
|
|
626
626
|
*
|
|
627
627
|
* **Peer Context Isolation**: Each workspace importer gets its own peer context
|
|
@@ -680,8 +680,6 @@ export const appendNodes = async (packageInfo, graph, fromNode, deps, scurry, op
|
|
|
680
680
|
// Fetch all manifests at this level in parallel without mutating the graph.
|
|
681
681
|
// This phase is read-only to avoid race conditions from network timing.
|
|
682
682
|
const fetchResults = await Promise.all(currentLevelDeps.map(async ({ node, deps: nodeDeps, modifierRefs: nodeModifierRefs, peerContext, depth, }) => {
|
|
683
|
-
// Cycle prevention: mark as seen when starting to process
|
|
684
|
-
seen.add(node.id);
|
|
685
683
|
// Fetch manifests and collect tasks (no graph mutations)
|
|
686
684
|
const result = await fetchManifestsForDeps(packageInfo, graph, node,
|
|
687
685
|
// Sort by name for deterministic ordering (reproducible builds)
|
|
@@ -740,17 +738,16 @@ export const appendNodes = async (packageInfo, graph, fromNode, deps, scurry, op
|
|
|
740
738
|
// ============================================================
|
|
741
739
|
// STEP 3: COLLECT CHILD DEPS FOR NEXT LEVEL
|
|
742
740
|
// ============================================================
|
|
741
|
+
/* c8 ignore next */
|
|
742
|
+
const nextDepth = (currentLevelDeps[0]?.depth ?? 0) + 1;
|
|
743
743
|
for (const childDepsToProcess of levelResults) {
|
|
744
744
|
for (const childDep of childDepsToProcess) {
|
|
745
|
-
//
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
depth: currentDepth + 1,
|
|
752
|
-
});
|
|
753
|
-
}
|
|
745
|
+
// seen at enqueue: skips cycles and same-level duplicates
|
|
746
|
+
// (first in sorted order wins)
|
|
747
|
+
if (seen.has(childDep.node.id))
|
|
748
|
+
continue;
|
|
749
|
+
seen.add(childDep.node.id);
|
|
750
|
+
nextLevelDeps.push({ ...childDep, depth: nextDepth });
|
|
754
751
|
}
|
|
755
752
|
}
|
|
756
753
|
// Advance to next BFS level
|
package/dist/ideal/build.js
CHANGED
|
@@ -3,6 +3,7 @@ import { graphStep } from '@vltpkg/output';
|
|
|
3
3
|
import { load as loadActual } from "../actual/load.js";
|
|
4
4
|
import { load as loadVirtual } from "../lockfile/load.js";
|
|
5
5
|
import { buildIdealFromStartingGraph } from "./build-ideal-from-starting-graph.js";
|
|
6
|
+
import { prefetchResolve } from "./prefetch-resolve.js";
|
|
6
7
|
import { isPathSecurityError } from "../path-security-error.js";
|
|
7
8
|
import { splitDepID } from '@vltpkg/dep-id';
|
|
8
9
|
const getMap = (m) => m ?? new Map();
|
|
@@ -60,6 +61,9 @@ export const build = async (options) => {
|
|
|
60
61
|
monorepo,
|
|
61
62
|
});
|
|
62
63
|
}
|
|
64
|
+
// Start resolving the importers' dependencies server-side, one request
|
|
65
|
+
// to the default registry. manifest() picks the answers up as they land.
|
|
66
|
+
prefetchResolve(graph, packageInfo, options);
|
|
63
67
|
const res = await buildIdealFromStartingGraph({
|
|
64
68
|
...options,
|
|
65
69
|
scurry,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PackageInfoClient } from '@vltpkg/package-info';
|
|
2
|
+
import type { SpecOptions } from '@vltpkg/spec';
|
|
3
|
+
import type { Graph } from '../graph.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Start a server-side resolve for the importers' dependencies, one request
|
|
6
|
+
* to the default registry, without waiting for it: the request overlaps
|
|
7
|
+
* whatever the build does before it asks for its first manifest.
|
|
8
|
+
*
|
|
9
|
+
* Fails soft in every direction: a registry that does not serve the
|
|
10
|
+
* endpoint, a request that errors, and a spec it does not resolve all
|
|
11
|
+
* leave the per-name path to handle it, exactly as before.
|
|
12
|
+
*/
|
|
13
|
+
export declare const prefetchResolve: (graph: Graph, packageInfo: PackageInfoClient, options: SpecOptions & {
|
|
14
|
+
modifiers?: unknown;
|
|
15
|
+
}) => number;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { detectLibc } from '@vltpkg/pick-manifest';
|
|
2
|
+
/**
|
|
3
|
+
* Start a server-side resolve for the importers' dependencies, one request
|
|
4
|
+
* to the default registry, without waiting for it: the request overlaps
|
|
5
|
+
* whatever the build does before it asks for its first manifest.
|
|
6
|
+
*
|
|
7
|
+
* Fails soft in every direction: a registry that does not serve the
|
|
8
|
+
* endpoint, a request that errors, and a spec it does not resolve all
|
|
9
|
+
* leave the per-name path to handle it, exactly as before.
|
|
10
|
+
*/
|
|
11
|
+
export const prefetchResolve = (graph, packageInfo, options) => {
|
|
12
|
+
// a modifier can swap any spec mid-graph, taking the server's whole
|
|
13
|
+
// closure off the client's real one; those installs resolve locally
|
|
14
|
+
if (options.modifiers)
|
|
15
|
+
return 0;
|
|
16
|
+
const registry = options.registry;
|
|
17
|
+
if (!registry)
|
|
18
|
+
return 0;
|
|
19
|
+
const scopes = Object.keys(options['scoped-registries'] ?? {});
|
|
20
|
+
// a name under a scoped registry is that registry's; it is not sent to
|
|
21
|
+
// this one at all, and `stop` keeps the server from walking into it
|
|
22
|
+
const scoped = (name) => scopes.some(scope => name.startsWith(`${scope}/`));
|
|
23
|
+
const roots = [];
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
for (const importer of graph.importers) {
|
|
26
|
+
const manifest = importer.manifest;
|
|
27
|
+
if (!manifest)
|
|
28
|
+
continue;
|
|
29
|
+
for (const field of [
|
|
30
|
+
'dependencies',
|
|
31
|
+
'devDependencies',
|
|
32
|
+
'optionalDependencies',
|
|
33
|
+
]) {
|
|
34
|
+
const deps = manifest[field];
|
|
35
|
+
if (!deps)
|
|
36
|
+
continue;
|
|
37
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
38
|
+
if (typeof spec !== 'string')
|
|
39
|
+
continue;
|
|
40
|
+
// protocols, workspace and file specs are the client's to resolve
|
|
41
|
+
if (spec.includes(':') || scoped(name))
|
|
42
|
+
continue;
|
|
43
|
+
const key = `${name}@${spec}`;
|
|
44
|
+
if (seen.has(key))
|
|
45
|
+
continue;
|
|
46
|
+
seen.add(key);
|
|
47
|
+
roots.push({ name, spec });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!roots.length)
|
|
52
|
+
return 0;
|
|
53
|
+
const have = [];
|
|
54
|
+
for (const node of graph.nodes.values()) {
|
|
55
|
+
if (node.manifest &&
|
|
56
|
+
node.name &&
|
|
57
|
+
node.version &&
|
|
58
|
+
!scoped(node.name)) {
|
|
59
|
+
have.push(`${node.name}@${node.version}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
packageInfo.prefetchResolve(registry, {
|
|
63
|
+
roots,
|
|
64
|
+
have,
|
|
65
|
+
...(scopes.length ? { stop: { scopes } } : {}),
|
|
66
|
+
platform: {
|
|
67
|
+
os: process.platform,
|
|
68
|
+
cpu: process.arch,
|
|
69
|
+
node: process.versions.node,
|
|
70
|
+
// undefined never serializes, so no libc means the field is absent
|
|
71
|
+
libc: detectLibc(),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
return roots.length;
|
|
75
|
+
};
|
package/dist/reify/build.js
CHANGED
|
@@ -8,6 +8,7 @@ import { optionalFail } from "./optional-fail.js";
|
|
|
8
8
|
import { binChmod } from "./bin-chmod.js";
|
|
9
9
|
import { hasBindingGyp } from "./binding-gyp.js";
|
|
10
10
|
import { scriptsManifest } from "./scripts-manifest.js";
|
|
11
|
+
import { unshare } from "./unshare.js";
|
|
11
12
|
export const build = async (diff, packageJson, scurry, allowScriptsNodes) => {
|
|
12
13
|
const graph = diff.to;
|
|
13
14
|
const nodes = nonEmptyList([...graph.importers]);
|
|
@@ -81,27 +82,30 @@ const visit = async (packageJson, scurry, node, signal, _path) => {
|
|
|
81
82
|
const hasImplicitInstall = hasBindingGyp(node, scurry) && !install && !preinstall;
|
|
82
83
|
// if it has install script or binding.gyp (implicit install), run it
|
|
83
84
|
const runInstall = !!(install || preinstall || postinstall) || hasImplicitInstall;
|
|
85
|
+
// if it's an importer or git, run prepare
|
|
86
|
+
const prepable = node.id.startsWith('git') || node.importer || !node.inVltStore();
|
|
87
|
+
const runPrepare = !!(prepare || preprepare || postprepare) && prepable;
|
|
88
|
+
// store links share inodes with the global store
|
|
89
|
+
if ((runInstall || runPrepare) && node.inVltStore())
|
|
90
|
+
await unshare(dir);
|
|
84
91
|
if (runInstall) {
|
|
85
92
|
await run({
|
|
86
93
|
signal,
|
|
87
94
|
arg0: 'install',
|
|
88
95
|
ignoreMissing: true,
|
|
89
96
|
packageJson,
|
|
90
|
-
cwd:
|
|
97
|
+
cwd: dir,
|
|
91
98
|
projectRoot: node.projectRoot,
|
|
92
99
|
manifest,
|
|
93
100
|
});
|
|
94
101
|
}
|
|
95
|
-
// if it's an importer or git, run prepare
|
|
96
|
-
const prepable = node.id.startsWith('git') || node.importer || !node.inVltStore();
|
|
97
|
-
const runPrepare = !!(prepare || preprepare || postprepare) && prepable;
|
|
98
102
|
if (runPrepare) {
|
|
99
103
|
await run({
|
|
100
104
|
signal,
|
|
101
105
|
arg0: 'prepare',
|
|
102
106
|
ignoreMissing: true,
|
|
103
107
|
packageJson,
|
|
104
|
-
cwd:
|
|
108
|
+
cwd: dir,
|
|
105
109
|
projectRoot: node.projectRoot,
|
|
106
110
|
manifest,
|
|
107
111
|
});
|
|
@@ -20,7 +20,6 @@ const getOptionalFailedNodeRemover = (node, diff) => {
|
|
|
20
20
|
*/
|
|
21
21
|
export const extractNode = async (node, scurry, remover, options, packageInfo, diff) => {
|
|
22
22
|
node.extracted = true;
|
|
23
|
-
const { manifest = {} } = node;
|
|
24
23
|
const target = node.resolvedLocation(scurry);
|
|
25
24
|
const from = scurry.resolve('');
|
|
26
25
|
const spec = hydrate(node.id, node.name, options);
|
|
@@ -35,18 +34,11 @@ export const extractNode = async (node, scurry, remover, options, packageInfo, d
|
|
|
35
34
|
error: new Error('Platform check failed or package deprecated'),
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
|
-
// the registry manifest can declare install scripts that the
|
|
39
|
-
// tarball's package.json, read by the global store, lacks
|
|
40
|
-
const { scripts, hasInstallScript } = manifest;
|
|
41
37
|
const extractOptions = {
|
|
42
38
|
from,
|
|
43
39
|
integrity,
|
|
44
40
|
resolved,
|
|
45
41
|
fromLockfile: node.resolvedFromLockfile,
|
|
46
|
-
installScripts: !!(hasInstallScript ||
|
|
47
|
-
scripts?.install ||
|
|
48
|
-
scripts?.preinstall ||
|
|
49
|
-
scripts?.postinstall),
|
|
50
42
|
};
|
|
51
43
|
const extracted = (r) => {
|
|
52
44
|
// Store computed integrity for git/remote deps
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace every file of `dir` that is hardlinked (e.g. from the global
|
|
3
|
+
* store) by a private copy, so a script run in it cannot write into
|
|
4
|
+
* the store. package.json goes last: a private package.json means
|
|
5
|
+
* nothing is shared, which the global store link keeps true.
|
|
6
|
+
*/
|
|
7
|
+
export declare const unshare: (dir: string) => Promise<void>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { lstatSync, readdirSync, rmSync } from 'node:fs';
|
|
3
|
+
import { chmod, readFile, rename, rm, writeFile, } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { callLimit } from 'promise-call-limit';
|
|
6
|
+
const TMP = '.vlt-unshare-';
|
|
7
|
+
const own = async (p, mode, tmp) => {
|
|
8
|
+
const body = await readFile(p);
|
|
9
|
+
try {
|
|
10
|
+
await writeFile(tmp, body, { mode: mode & 0o777, flag: 'wx' });
|
|
11
|
+
// same modes as a copy from the store
|
|
12
|
+
if (mode & 0o111)
|
|
13
|
+
await chmod(tmp, mode & 0o777);
|
|
14
|
+
// atomic: p is never missing
|
|
15
|
+
await rename(tmp, p);
|
|
16
|
+
}
|
|
17
|
+
catch (er) {
|
|
18
|
+
await rm(tmp, { force: true });
|
|
19
|
+
throw er;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Replace every file of `dir` that is hardlinked (e.g. from the global
|
|
24
|
+
* store) by a private copy, so a script run in it cannot write into
|
|
25
|
+
* the store. package.json goes last: a private package.json means
|
|
26
|
+
* nothing is shared, which the global store link keeps true.
|
|
27
|
+
*/
|
|
28
|
+
export const unshare = async (dir) => {
|
|
29
|
+
const pjPath = join(dir, 'package.json');
|
|
30
|
+
const pj = lstatSync(pjPath, { throwIfNoEntry: false });
|
|
31
|
+
if (!pj || pj.nlink < 2)
|
|
32
|
+
return;
|
|
33
|
+
// random per call: never clashes with another run's tmp
|
|
34
|
+
const tag = `${TMP}${randomBytes(4).toString('hex')}-`;
|
|
35
|
+
let n = 0;
|
|
36
|
+
const shared = [];
|
|
37
|
+
// by hand: a recursive readdir follows dir symlinks
|
|
38
|
+
const walk = (d) => {
|
|
39
|
+
for (const ent of readdirSync(d, { withFileTypes: true })) {
|
|
40
|
+
const p = join(d, ent.name);
|
|
41
|
+
if (ent.isDirectory())
|
|
42
|
+
walk(p);
|
|
43
|
+
else if (ent.isFile() && p !== pjPath) {
|
|
44
|
+
const { mode, nlink } = lstatSync(p);
|
|
45
|
+
if (nlink > 1) {
|
|
46
|
+
const tmp = join(d, `${tag}${n++}`);
|
|
47
|
+
shared.push(() => own(p, mode, tmp));
|
|
48
|
+
}
|
|
49
|
+
else if (ent.name.startsWith(TMP)) {
|
|
50
|
+
// a killed run's tmp copy
|
|
51
|
+
rmSync(p);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
walk(dir);
|
|
57
|
+
await callLimit(shared, { limit: 16, rejectLate: true });
|
|
58
|
+
await own(pjPath, pj.mode, join(dir, `${tag}${n}`));
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/graph",
|
|
3
3
|
"description": "A library that helps understanding & expressing what happens on an install",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,26 +13,26 @@
|
|
|
13
13
|
"url": "http://vlt.sh"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vltpkg/cmd-shim": "1.3.
|
|
17
|
-
"@vltpkg/dep-id": "1.3.
|
|
18
|
-
"@vltpkg/dss-breadcrumb": "1.3.
|
|
19
|
-
"@vltpkg/error-cause": "1.3.
|
|
20
|
-
"@vltpkg/fast-split": "1.3.
|
|
21
|
-
"@vltpkg/graph-run": "1.3.
|
|
22
|
-
"@vltpkg/init": "1.3.
|
|
23
|
-
"@vltpkg/output": "1.3.
|
|
24
|
-
"@vltpkg/package-info": "1.3.
|
|
25
|
-
"@vltpkg/package-json": "1.3.
|
|
26
|
-
"@vltpkg/pick-manifest": "1.3.
|
|
27
|
-
"@vltpkg/query": "1.3.
|
|
28
|
-
"@vltpkg/rollback-remove": "1.3.
|
|
29
|
-
"@vltpkg/run": "1.3.
|
|
30
|
-
"@vltpkg/satisfies": "1.3.
|
|
31
|
-
"@vltpkg/security-archive": "1.3.
|
|
32
|
-
"@vltpkg/spec": "1.3.
|
|
33
|
-
"@vltpkg/types": "1.3.
|
|
34
|
-
"@vltpkg/vlt-json": "1.3.
|
|
35
|
-
"@vltpkg/workspaces": "1.3.
|
|
16
|
+
"@vltpkg/cmd-shim": "1.3.4",
|
|
17
|
+
"@vltpkg/dep-id": "1.3.4",
|
|
18
|
+
"@vltpkg/dss-breadcrumb": "1.3.4",
|
|
19
|
+
"@vltpkg/error-cause": "1.3.4",
|
|
20
|
+
"@vltpkg/fast-split": "1.3.4",
|
|
21
|
+
"@vltpkg/graph-run": "1.3.4",
|
|
22
|
+
"@vltpkg/init": "1.3.4",
|
|
23
|
+
"@vltpkg/output": "1.3.4",
|
|
24
|
+
"@vltpkg/package-info": "1.3.4",
|
|
25
|
+
"@vltpkg/package-json": "1.3.4",
|
|
26
|
+
"@vltpkg/pick-manifest": "1.3.4",
|
|
27
|
+
"@vltpkg/query": "1.3.4",
|
|
28
|
+
"@vltpkg/rollback-remove": "1.3.4",
|
|
29
|
+
"@vltpkg/run": "1.3.4",
|
|
30
|
+
"@vltpkg/satisfies": "1.3.4",
|
|
31
|
+
"@vltpkg/security-archive": "1.3.4",
|
|
32
|
+
"@vltpkg/spec": "1.3.4",
|
|
33
|
+
"@vltpkg/types": "1.3.4",
|
|
34
|
+
"@vltpkg/vlt-json": "1.3.4",
|
|
35
|
+
"@vltpkg/workspaces": "1.3.4",
|
|
36
36
|
"path-scurry": "^2.0.1",
|
|
37
37
|
"promise-call-limit": "^3.0.2"
|
|
38
38
|
},
|