@vltpkg/graph 1.4.0 → 1.5.0
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 +59 -3
- package/dist/actual/load.js +24 -12
- package/dist/build.js +30 -5
- package/dist/dependencies.d.ts +11 -0
- package/dist/dependencies.js +47 -7
- package/dist/filter-nodes-by-query.d.ts +39 -0
- package/dist/filter-nodes-by-query.js +100 -0
- package/dist/ideal/append-nodes.js +11 -6
- package/dist/ideal/get-importer-specs.js +17 -7
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/install.d.ts +23 -8
- package/dist/install.js +24 -1
- package/dist/lockfile/load-edges.js +10 -2
- package/dist/reify/build.d.ts +7 -0
- package/dist/reify/check-needed-build.d.ts +5 -0
- package/dist/reify/check-needed-build.js +13 -0
- package/dist/reify/index.js +4 -38
- package/dist/reify/update-importers-package-json.js +5 -9
- package/dist/skills/dirs.d.ts +58 -0
- package/dist/skills/dirs.js +211 -0
- package/dist/skills/discover.d.ts +73 -0
- package/dist/skills/discover.js +234 -0
- package/dist/skills/gitignore.d.ts +13 -0
- package/dist/skills/gitignore.js +53 -0
- package/dist/skills/index.d.ts +123 -0
- package/dist/skills/index.js +225 -0
- package/dist/skills/lazy.d.ts +8 -0
- package/dist/skills/lazy.js +8 -0
- package/dist/skills/mask.d.ts +26 -0
- package/dist/skills/mask.js +43 -0
- package/dist/skills/mounts.d.ts +64 -0
- package/dist/skills/mounts.js +136 -0
- package/dist/uninstall.d.ts +24 -7
- package/dist/uninstall.js +24 -1
- package/dist/update.d.ts +24 -4
- package/dist/update.js +24 -1
- package/dist/visualization/mermaid-output.d.ts +8 -0
- package/dist/visualization/mermaid-output.js +25 -8
- package/package.json +21 -21
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { QueryPartIds } from '../filter-nodes-by-query.ts';
|
|
2
|
+
import type { Skill } from './discover.ts';
|
|
3
|
+
/**
|
|
4
|
+
* A `:skill()` pattern that matched no skill of its selector's
|
|
5
|
+
* packages.
|
|
6
|
+
*/
|
|
7
|
+
export type UnmatchedPattern = {
|
|
8
|
+
pattern: string;
|
|
9
|
+
/** skills those packages ship, sorted; unset: no package selected */
|
|
10
|
+
skills?: string[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Whole-name, case-insensitive; `*` = any run of characters (incl.
|
|
14
|
+
* none).
|
|
15
|
+
*/
|
|
16
|
+
export declare const globRegExp: (pattern: string) => RegExp;
|
|
17
|
+
/**
|
|
18
|
+
* Apply an `allow-skills` mask. A skill is picked when some part matched
|
|
19
|
+
* its package (any version) and has no patterns, or one of its patterns
|
|
20
|
+
* matches the skill (parts are a union). Also returns the patterns that
|
|
21
|
+
* matched nothing.
|
|
22
|
+
*/
|
|
23
|
+
export declare const maskSkills: (skills: Skill[], parts: QueryPartIds[]) => {
|
|
24
|
+
skills: Skill[];
|
|
25
|
+
unmatched: UnmatchedPattern[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { packageKey } from "./mounts.js";
|
|
2
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3
|
+
/**
|
|
4
|
+
* Whole-name, case-insensitive; `*` = any run of characters (incl.
|
|
5
|
+
* none).
|
|
6
|
+
*/
|
|
7
|
+
export const globRegExp = (pattern) => new RegExp(`^${pattern.split('*').map(escape).join('.*')}$`, 'i');
|
|
8
|
+
const matches = (re, s) => re.test(s.skill) ||
|
|
9
|
+
(!!s.frontmatterName && re.test(s.frontmatterName));
|
|
10
|
+
/**
|
|
11
|
+
* Apply an `allow-skills` mask. A skill is picked when some part matched
|
|
12
|
+
* its package (any version) and has no patterns, or one of its patterns
|
|
13
|
+
* matches the skill (parts are a union). Also returns the patterns that
|
|
14
|
+
* matched nothing.
|
|
15
|
+
*/
|
|
16
|
+
export const maskSkills = (skills, parts) => {
|
|
17
|
+
const compiled = parts.map(p => ({
|
|
18
|
+
keys: new Set([...p.ids].map(packageKey)),
|
|
19
|
+
patterns: p.patterns?.map(pattern => ({
|
|
20
|
+
pattern,
|
|
21
|
+
re: globRegExp(pattern),
|
|
22
|
+
})),
|
|
23
|
+
}));
|
|
24
|
+
const picked = skills.filter(s => compiled.some(p => p.keys.has(packageKey(s.id)) &&
|
|
25
|
+
(!p.patterns || p.patterns.some(({ re }) => matches(re, s)))));
|
|
26
|
+
const unmatched = [];
|
|
27
|
+
for (const p of compiled) {
|
|
28
|
+
if (!p.patterns)
|
|
29
|
+
continue;
|
|
30
|
+
const own = skills.filter(s => p.keys.has(packageKey(s.id)));
|
|
31
|
+
for (const { pattern, re } of p.patterns) {
|
|
32
|
+
if (own.some(s => matches(re, s)))
|
|
33
|
+
continue;
|
|
34
|
+
unmatched.push({
|
|
35
|
+
pattern,
|
|
36
|
+
...(p.keys.size > 0 && {
|
|
37
|
+
skills: [...new Set(own.map(s => s.skill))].sort((a, b) => a.localeCompare(b, 'en')),
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { skills: picked, unmatched };
|
|
43
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Stats } from 'node:fs';
|
|
2
|
+
import type { DepID } from '@vltpkg/dep-id';
|
|
3
|
+
import type { SkillsDir } from './dirs.ts';
|
|
4
|
+
import type { Skill } from './discover.ts';
|
|
5
|
+
/**
|
|
6
|
+
* A vlt link in an agent skills dir.
|
|
7
|
+
*/
|
|
8
|
+
export type SkillMount = {
|
|
9
|
+
/** the dir holding the link */
|
|
10
|
+
dir: SkillsDir;
|
|
11
|
+
/** entry name */
|
|
12
|
+
name: string;
|
|
13
|
+
/** `<dir>/<name>`, `/`-separated, relative to projectRoot */
|
|
14
|
+
mount: string;
|
|
15
|
+
/** absolute link path, in the real dir */
|
|
16
|
+
link: string;
|
|
17
|
+
/** absolute resolved link target */
|
|
18
|
+
target: string;
|
|
19
|
+
/** DepID of the store dir the link points into */
|
|
20
|
+
owner?: DepID;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Outcome of mounting a single skill.
|
|
24
|
+
*/
|
|
25
|
+
export type MountResult = 'linked' | 'unchanged' | 'conflict';
|
|
26
|
+
/** `lstat`, undefined when missing or unreadable (eg, ENOTDIR) */
|
|
27
|
+
export declare const lstat: (path: string) => Stats | undefined;
|
|
28
|
+
/** Resolved path, lowercased on win32. */
|
|
29
|
+
export declare const norm: (p: string) => string;
|
|
30
|
+
/** realpath, else the resolved path when missing. */
|
|
31
|
+
export declare const realOr: (p: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Same real path? Case-insensitive on win32.
|
|
34
|
+
*/
|
|
35
|
+
export declare const samePath: (a: string, b: string) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The target of `link` if it is a symlink (or junction) pointing into
|
|
38
|
+
* a `node_modules/.vlt` store, otherwise undefined. Any store, not just
|
|
39
|
+
* the project's: win32 junctions are absolute, so they point to the old
|
|
40
|
+
* store after the project is moved or copied.
|
|
41
|
+
*/
|
|
42
|
+
export declare const mountTarget: (link: string) => string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The DepID of the last `node_modules/.vlt/<DepID>` segment of a raw
|
|
45
|
+
* link target, if valid.
|
|
46
|
+
*/
|
|
47
|
+
export declare const ownerOf: (target: string) => DepID | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* One key per package: registry + name, else the DepID w/o its extra.
|
|
50
|
+
*/
|
|
51
|
+
export declare const packageKey: (id: DepID) => string;
|
|
52
|
+
/**
|
|
53
|
+
* All vlt links in the given dirs. Anything else is ignored.
|
|
54
|
+
*/
|
|
55
|
+
export declare const readMounts: (scan: SkillsDir[]) => SkillMount[];
|
|
56
|
+
/**
|
|
57
|
+
* Link a skill at `<dir>/<skill>`. Never touches anything not managed by
|
|
58
|
+
* vlt: returns `'conflict'` instead.
|
|
59
|
+
*/
|
|
60
|
+
export declare const mountSkill: (skill: Pick<Skill, "skill" | "path">, dir: SkillsDir) => MountResult;
|
|
61
|
+
/**
|
|
62
|
+
* Remove a vlt link. Its dir is kept.
|
|
63
|
+
*/
|
|
64
|
+
export declare const unmountSkill: (m: SkillMount) => void;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { lstatSync, readdirSync, readlinkSync, realpathSync, unlinkSync, } from 'node:fs';
|
|
2
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { baseDepID, isDepID, joinDepIDTuple, splitDepID, } from '@vltpkg/dep-id';
|
|
4
|
+
import { symlinkSyncMkdirp } from "../reify/symlink-sync.js";
|
|
5
|
+
/** `lstat`, undefined when missing or unreadable (eg, ENOTDIR) */
|
|
6
|
+
export const lstat = (path) => {
|
|
7
|
+
try {
|
|
8
|
+
return lstatSync(path, { throwIfNoEntry: false });
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Resolved path, lowercased on win32. */
|
|
15
|
+
export const norm = (p) => {
|
|
16
|
+
const r = resolve(p);
|
|
17
|
+
return process.platform === 'win32' ? r.toLowerCase() : r;
|
|
18
|
+
};
|
|
19
|
+
/** realpath, else the resolved path when missing. */
|
|
20
|
+
export const realOr = (p) => {
|
|
21
|
+
try {
|
|
22
|
+
return realpathSync(p);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return resolve(p);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Same real path? Case-insensitive on win32.
|
|
30
|
+
*/
|
|
31
|
+
export const samePath = (a, b) => norm(realOr(a)) === norm(realOr(b));
|
|
32
|
+
const storeSeg = `${sep}node_modules${sep}.vlt${sep}`;
|
|
33
|
+
/**
|
|
34
|
+
* The target of `link` if it is a symlink (or junction) pointing into
|
|
35
|
+
* a `node_modules/.vlt` store, otherwise undefined. Any store, not just
|
|
36
|
+
* the project's: win32 junctions are absolute, so they point to the old
|
|
37
|
+
* store after the project is moved or copied.
|
|
38
|
+
*/
|
|
39
|
+
export const mountTarget = (link) => {
|
|
40
|
+
if (!lstat(link)?.isSymbolicLink())
|
|
41
|
+
return undefined;
|
|
42
|
+
let raw = readlinkSync(link);
|
|
43
|
+
if (raw.startsWith('\\\\?\\'))
|
|
44
|
+
raw = raw.slice(4);
|
|
45
|
+
const target = resolve(dirname(link), raw);
|
|
46
|
+
return norm(target).includes(storeSeg) ? target : undefined;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The DepID of the last `node_modules/.vlt/<DepID>` segment of a raw
|
|
50
|
+
* link target, if valid.
|
|
51
|
+
*/
|
|
52
|
+
export const ownerOf = (target) => {
|
|
53
|
+
const parts = target.split(sep);
|
|
54
|
+
const seg = (i) => process.platform === 'win32' ? parts[i]?.toLowerCase() : parts[i];
|
|
55
|
+
for (let i = parts.length - 3; i >= 0; i--) {
|
|
56
|
+
if (seg(i) === 'node_modules' && seg(i + 1) === '.vlt') {
|
|
57
|
+
const id = parts[i + 2];
|
|
58
|
+
return isDepID(id) ? id : undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* One key per package: registry + name, else the DepID w/o its extra.
|
|
65
|
+
*/
|
|
66
|
+
export const packageKey = (id) => {
|
|
67
|
+
const t = splitDepID(id);
|
|
68
|
+
if (t[0] !== 'registry')
|
|
69
|
+
return baseDepID(id);
|
|
70
|
+
const spec = t[2];
|
|
71
|
+
const at = spec.lastIndexOf('@');
|
|
72
|
+
return joinDepIDTuple([
|
|
73
|
+
'registry',
|
|
74
|
+
t[1],
|
|
75
|
+
at > 0 ? spec.slice(0, at) : spec,
|
|
76
|
+
]);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* All vlt links in the given dirs. Anything else is ignored.
|
|
80
|
+
*/
|
|
81
|
+
export const readMounts = (scan) => {
|
|
82
|
+
const mounts = [];
|
|
83
|
+
for (const dir of scan) {
|
|
84
|
+
let entries;
|
|
85
|
+
try {
|
|
86
|
+
entries = readdirSync(dir.real);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
for (const name of entries) {
|
|
92
|
+
const link = join(dir.real, name);
|
|
93
|
+
const target = mountTarget(link);
|
|
94
|
+
if (target) {
|
|
95
|
+
mounts.push({
|
|
96
|
+
dir,
|
|
97
|
+
name,
|
|
98
|
+
mount: `${dir.dir}/${name}`,
|
|
99
|
+
link,
|
|
100
|
+
target,
|
|
101
|
+
owner: ownerOf(target),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return mounts.sort((a, b) => a.mount.localeCompare(b.mount, 'en'));
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Link a skill at `<dir>/<skill>`. Never touches anything not managed by
|
|
110
|
+
* vlt: returns `'conflict'` instead.
|
|
111
|
+
*/
|
|
112
|
+
export const mountSkill = (skill, dir) => {
|
|
113
|
+
const link = join(dir.real, skill.skill);
|
|
114
|
+
if (lstat(link)) {
|
|
115
|
+
const target = mountTarget(link);
|
|
116
|
+
if (!target)
|
|
117
|
+
return 'conflict';
|
|
118
|
+
if (samePath(target, skill.path))
|
|
119
|
+
return 'unchanged';
|
|
120
|
+
unlinkSync(link);
|
|
121
|
+
}
|
|
122
|
+
// junctions need no admin rights, but want an absolute target
|
|
123
|
+
if (process.platform === 'win32') {
|
|
124
|
+
symlinkSyncMkdirp(skill.path, link, 'junction');
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
symlinkSyncMkdirp(relative(dir.real, skill.path), link, 'dir');
|
|
128
|
+
}
|
|
129
|
+
return 'linked';
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Remove a vlt link. Its dir is kept.
|
|
133
|
+
*/
|
|
134
|
+
export const unmountSkill = (m) => {
|
|
135
|
+
unlinkSync(m.link);
|
|
136
|
+
};
|
package/dist/uninstall.d.ts
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import type { PackageInfoClient } from '@vltpkg/package-info';
|
|
2
2
|
import type { LoadOptions } from './actual/load.ts';
|
|
3
3
|
import type { RemoveImportersDependenciesMap } from './dependencies.ts';
|
|
4
|
+
import type { ReifyResult } from './reify/index.ts';
|
|
5
|
+
import type { Graph } from './graph.ts';
|
|
6
|
+
import type { LinkSkillsResult } from './skills/index.ts';
|
|
4
7
|
export type UninstallOptions = LoadOptions & {
|
|
5
8
|
packageInfo: PackageInfoClient;
|
|
6
9
|
allowScripts: string;
|
|
10
|
+
/**
|
|
11
|
+
* DSS query: packages whose agent skills get linked into the
|
|
12
|
+
* project's agent skill dirs after uninstall. Selectors may end with
|
|
13
|
+
* `:skill()`. Unset or `:not(*)`: none.
|
|
14
|
+
*/
|
|
15
|
+
allowSkills?: string;
|
|
16
|
+
/**
|
|
17
|
+
* agent skill dirs, relative to projectRoot. Unset: detect; `[]`:
|
|
18
|
+
* none
|
|
19
|
+
*/
|
|
20
|
+
skillsDirs?: string[];
|
|
7
21
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
graph:
|
|
13
|
-
diff
|
|
14
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Result of {@link uninstall}.
|
|
24
|
+
*/
|
|
25
|
+
export type UninstallResult = {
|
|
26
|
+
graph: Graph;
|
|
27
|
+
diff?: ReifyResult;
|
|
28
|
+
/** skill links added or removed, if any */
|
|
29
|
+
skills?: LinkSkillsResult;
|
|
30
|
+
};
|
|
31
|
+
export declare const uninstall: (options: UninstallOptions, remove?: RemoveImportersDependenciesMap) => Promise<UninstallResult>;
|
package/dist/uninstall.js
CHANGED
|
@@ -8,7 +8,19 @@ import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
|
8
8
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
9
9
|
import { existsSync, rmSync } from 'node:fs';
|
|
10
10
|
import { resolve } from 'node:path';
|
|
11
|
+
import { assertQuery } from "./filter-nodes-by-query.js";
|
|
12
|
+
import { assertSkillsDirs } from "./skills/dirs.js";
|
|
11
13
|
export const uninstall = async (options, remove) => {
|
|
14
|
+
// unset or `:not(*)`: no skills work at all, the skills code never
|
|
15
|
+
// loads
|
|
16
|
+
const allowSkills = options.allowSkills === ':not(*)' ?
|
|
17
|
+
undefined
|
|
18
|
+
: options.allowSkills;
|
|
19
|
+
// fail before uninstalling, not after
|
|
20
|
+
if (allowSkills) {
|
|
21
|
+
await assertQuery(allowSkills, 'allow-skills', ['skill']);
|
|
22
|
+
assertSkillsDirs(options.projectRoot, options.skillsDirs);
|
|
23
|
+
}
|
|
12
24
|
const mainManifest = options.packageJson.read(options.projectRoot);
|
|
13
25
|
const modifiers = GraphModifier.maybeLoad(options);
|
|
14
26
|
const remover = new RollbackRemove();
|
|
@@ -17,6 +29,7 @@ export const uninstall = async (options, remove) => {
|
|
|
17
29
|
packageJson: options.packageJson,
|
|
18
30
|
scurry: options.scurry,
|
|
19
31
|
});
|
|
32
|
+
let result;
|
|
20
33
|
try {
|
|
21
34
|
// Load the actual graph before building the ideal graph so that
|
|
22
35
|
// manifest data from installed packages can be used to hydrate
|
|
@@ -71,7 +84,7 @@ export const uninstall = async (options, remove) => {
|
|
|
71
84
|
modifiers,
|
|
72
85
|
remover,
|
|
73
86
|
});
|
|
74
|
-
|
|
87
|
+
result = { graph, diff };
|
|
75
88
|
/* c8 ignore start */
|
|
76
89
|
}
|
|
77
90
|
catch (err) {
|
|
@@ -87,4 +100,14 @@ export const uninstall = async (options, remove) => {
|
|
|
87
100
|
throw err;
|
|
88
101
|
}
|
|
89
102
|
/* c8 ignore stop */
|
|
103
|
+
// after the try: a link failure must not roll back the uninstall
|
|
104
|
+
if (!allowSkills)
|
|
105
|
+
return result;
|
|
106
|
+
const { linkSkills } = await import("./skills/index.js");
|
|
107
|
+
result.skills = await linkSkills({
|
|
108
|
+
...options,
|
|
109
|
+
graph: result.graph,
|
|
110
|
+
target: allowSkills,
|
|
111
|
+
});
|
|
112
|
+
return result;
|
|
90
113
|
};
|
package/dist/update.d.ts
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import type { PackageInfoClient } from '@vltpkg/package-info';
|
|
2
2
|
import type { LoadOptions } from './actual/load.ts';
|
|
3
3
|
import { Graph } from './graph.ts';
|
|
4
|
+
import type { DepID } from '@vltpkg/dep-id';
|
|
5
|
+
import type { Diff } from './diff.ts';
|
|
6
|
+
import type { LinkSkillsResult } from './skills/index.ts';
|
|
4
7
|
export type UpdateOptions = LoadOptions & {
|
|
5
8
|
packageInfo: PackageInfoClient;
|
|
6
9
|
allowScripts: string;
|
|
10
|
+
/**
|
|
11
|
+
* DSS query: packages whose agent skills get linked into the
|
|
12
|
+
* project's agent skill dirs after update. Selectors may end with
|
|
13
|
+
* `:skill()`. Unset or `:not(*)`: none.
|
|
14
|
+
*/
|
|
15
|
+
allowSkills?: string;
|
|
16
|
+
/**
|
|
17
|
+
* agent skill dirs, relative to projectRoot. Unset: detect; `[]`:
|
|
18
|
+
* none
|
|
19
|
+
*/
|
|
20
|
+
skillsDirs?: string[];
|
|
7
21
|
};
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Result of {@link update}.
|
|
24
|
+
*/
|
|
25
|
+
export type UpdateResult = {
|
|
26
|
+
buildQueue?: DepID[];
|
|
10
27
|
graph: Graph;
|
|
11
|
-
diff
|
|
12
|
-
|
|
28
|
+
diff?: Diff;
|
|
29
|
+
/** skill links added or removed, if any */
|
|
30
|
+
skills?: LinkSkillsResult;
|
|
31
|
+
};
|
|
32
|
+
export declare const update: (options: UpdateOptions) => Promise<UpdateResult>;
|
package/dist/update.js
CHANGED
|
@@ -12,6 +12,8 @@ import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
|
12
12
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
13
13
|
import { existsSync, rmSync } from 'node:fs';
|
|
14
14
|
import { resolve } from 'node:path';
|
|
15
|
+
import { assertQuery } from "./filter-nodes-by-query.js";
|
|
16
|
+
import { assertSkillsDirs } from "./skills/dirs.js";
|
|
15
17
|
/**
|
|
16
18
|
* Graph to update from. `-w` filtered: the lockfile (else installed)
|
|
17
19
|
* graph minus the selected workspaces' deps, so only those re-resolve
|
|
@@ -45,6 +47,16 @@ const startingGraph = (options, monorepo) => {
|
|
|
45
47
|
return graph;
|
|
46
48
|
};
|
|
47
49
|
export const update = async (options) => {
|
|
50
|
+
// unset or `:not(*)`: no skills work at all, the skills code never
|
|
51
|
+
// loads
|
|
52
|
+
const allowSkills = options.allowSkills === ':not(*)' ?
|
|
53
|
+
undefined
|
|
54
|
+
: options.allowSkills;
|
|
55
|
+
// fail before updating, not after
|
|
56
|
+
if (allowSkills) {
|
|
57
|
+
await assertQuery(allowSkills, 'allow-skills', ['skill']);
|
|
58
|
+
assertSkillsDirs(options.projectRoot, options.skillsDirs);
|
|
59
|
+
}
|
|
48
60
|
let mainManifest = undefined;
|
|
49
61
|
try {
|
|
50
62
|
mainManifest = options.packageJson.read(options.projectRoot);
|
|
@@ -66,6 +78,7 @@ export const update = async (options) => {
|
|
|
66
78
|
packageJson: options.packageJson,
|
|
67
79
|
scurry: options.scurry,
|
|
68
80
|
});
|
|
81
|
+
let result;
|
|
69
82
|
try {
|
|
70
83
|
const done = graphStep('build');
|
|
71
84
|
const graph = await buildIdealFromStartingGraph({
|
|
@@ -94,7 +107,7 @@ export const update = async (options) => {
|
|
|
94
107
|
remover,
|
|
95
108
|
update: true,
|
|
96
109
|
});
|
|
97
|
-
|
|
110
|
+
result = { buildQueue, graph, diff };
|
|
98
111
|
/* c8 ignore start */
|
|
99
112
|
}
|
|
100
113
|
catch (err) {
|
|
@@ -110,4 +123,14 @@ export const update = async (options) => {
|
|
|
110
123
|
throw err;
|
|
111
124
|
}
|
|
112
125
|
/* c8 ignore stop */
|
|
126
|
+
// after the try: a link failure must not roll back the update
|
|
127
|
+
if (!allowSkills)
|
|
128
|
+
return result;
|
|
129
|
+
const { linkSkills } = await import("./skills/index.js");
|
|
130
|
+
result.skills = await linkSkills({
|
|
131
|
+
...options,
|
|
132
|
+
graph: result.graph,
|
|
133
|
+
target: allowSkills,
|
|
134
|
+
});
|
|
135
|
+
return result;
|
|
113
136
|
};
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import type { DepID } from '@vltpkg/dep-id';
|
|
1
2
|
import type { EdgeLike, NodeLike } from '@vltpkg/types';
|
|
3
|
+
/** A leaf drawn under a graph node: node label, optional edge label. */
|
|
4
|
+
export type MermaidChild = {
|
|
5
|
+
label: string;
|
|
6
|
+
edge?: string;
|
|
7
|
+
};
|
|
2
8
|
export type MermaidOutputGraph = {
|
|
3
9
|
edges: EdgeLike[];
|
|
4
10
|
importers: Set<NodeLike>;
|
|
5
11
|
nodes: NodeLike[];
|
|
6
12
|
highlightSelection?: boolean;
|
|
13
|
+
/** leaves to draw under included nodes (class `b`), eg: skills */
|
|
14
|
+
children?: Map<DepID, MermaidChild[]>;
|
|
7
15
|
};
|
|
8
16
|
/**
|
|
9
17
|
* Generates a short identifier for a given index following the pattern:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Edge } from "../edge.js";
|
|
2
2
|
import { Node } from "../node.js";
|
|
3
3
|
let missingCount = 0;
|
|
4
|
+
const escapeLabel = (s) => s.replaceAll('"', '#quot;').replaceAll('@', '#64;');
|
|
4
5
|
const isSelected = (options, edge, node) => (!node || options.nodes.includes(node)) &&
|
|
5
6
|
/* c8 ignore next */ (!edge || options.edges.includes(edge));
|
|
6
7
|
/**
|
|
@@ -72,7 +73,7 @@ const nodeRef = (node, labeledNodes, depIdMapping, options) => {
|
|
|
72
73
|
labeledNodes.add(node.id);
|
|
73
74
|
return `${shortId}("${String(node).replaceAll('@', '#64;')}")${selectedClass}`;
|
|
74
75
|
};
|
|
75
|
-
function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, node, isImporter = false) {
|
|
76
|
+
function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, leaves, node, isImporter = false) {
|
|
76
77
|
if (seenNodes.has(node.id) || !includedItems.get(node)) {
|
|
77
78
|
return '';
|
|
78
79
|
}
|
|
@@ -87,8 +88,10 @@ function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options
|
|
|
87
88
|
...node.edgesOut.values(),
|
|
88
89
|
...(node.workspaces?.values() ?? []),
|
|
89
90
|
];
|
|
90
|
-
const edges =
|
|
91
|
-
.
|
|
91
|
+
const edges = [
|
|
92
|
+
leaves.get(node.id),
|
|
93
|
+
...allEdges.map(e => parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options, leaves, e)),
|
|
94
|
+
]
|
|
92
95
|
.filter(Boolean)
|
|
93
96
|
.join('\n');
|
|
94
97
|
// Only render node standalone for importers, others are rendered as part of edges
|
|
@@ -98,7 +101,7 @@ function parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options
|
|
|
98
101
|
}
|
|
99
102
|
return edges;
|
|
100
103
|
}
|
|
101
|
-
function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options, edge) {
|
|
104
|
+
function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options, leaves, edge) {
|
|
102
105
|
if (!includedItems.get(edge)) {
|
|
103
106
|
return '';
|
|
104
107
|
}
|
|
@@ -112,14 +115,14 @@ function parseEdge(seenNodes, labeledNodes, includedItems, depIdMapping, options
|
|
|
112
115
|
// Label the target node first so that if it's referenced again later in the graph,
|
|
113
116
|
// it will use the short identifier instead of repeating the full label.
|
|
114
117
|
const toRef = nodeRef(edge.to, labeledNodes, depIdMapping, options);
|
|
115
|
-
const childEdges = parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, edge.to);
|
|
118
|
+
const childEdges = parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, leaves, edge.to);
|
|
116
119
|
return edgeResult + toRef + (childEdges ? '\n' + childEdges : '');
|
|
117
120
|
}
|
|
118
121
|
/**
|
|
119
122
|
* Returns a mermaid string representation of the graph.
|
|
120
123
|
*/
|
|
121
124
|
export function mermaidOutput(options) {
|
|
122
|
-
const { edges, importers, nodes, highlightSelection } = options;
|
|
125
|
+
const { edges, importers, nodes, highlightSelection, children } = options;
|
|
123
126
|
const seen = new Set();
|
|
124
127
|
const includedItems = new Map();
|
|
125
128
|
const traverse = new Set([...importers].map(i => ({ self: i, parent: undefined })));
|
|
@@ -157,14 +160,28 @@ export function mermaidOutput(options) {
|
|
|
157
160
|
}
|
|
158
161
|
// Create DepID to short identifier mapping
|
|
159
162
|
const depIdMapping = createDepIdMapping(importers);
|
|
163
|
+
// leaf lines per node, ids after the graph's
|
|
164
|
+
const leaves = new Map();
|
|
165
|
+
let leafIndex = depIdMapping.size;
|
|
166
|
+
for (const [id, items] of children ?? []) {
|
|
167
|
+
const from = depIdMapping.get(id);
|
|
168
|
+
if (!from || !items.length)
|
|
169
|
+
continue;
|
|
170
|
+
leaves.set(id, items
|
|
171
|
+
.map(({ label, edge }) => `${from} -->${edge === undefined ? '' : `|"${escapeLabel(edge)}"|`} ${generateShortId(leafIndex++)}("${escapeLabel(label)}"):::b`)
|
|
172
|
+
.join('\n'));
|
|
173
|
+
}
|
|
160
174
|
// Track nodes that have had their label printed (shared across all importers)
|
|
161
175
|
const labeledNodes = new Set();
|
|
162
176
|
// Track nodes that have been processed (shared across all importers to avoid duplicates)
|
|
163
177
|
const seenNodes = new Set();
|
|
164
178
|
const graphOutput = [...importers]
|
|
165
|
-
.map(i => parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, i, true))
|
|
179
|
+
.map(i => parseNode(seenNodes, labeledNodes, includedItems, depIdMapping, options, leaves, i, true))
|
|
166
180
|
.filter(Boolean)
|
|
167
181
|
.join('\n');
|
|
168
|
-
const styleDefinition = highlightSelection ?
|
|
182
|
+
const styleDefinition = (highlightSelection ?
|
|
183
|
+
'\nclassDef a fill:gold,color:#242424'
|
|
184
|
+
: '') +
|
|
185
|
+
(leaves.size ? '\nclassDef b fill:turquoise,color:#242424' : '');
|
|
169
186
|
return 'flowchart TD\n' + graphOutput + styleDefinition;
|
|
170
187
|
}
|
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.
|
|
4
|
+
"version": "1.5.0",
|
|
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.
|
|
17
|
-
"@vltpkg/dep-id": "1.
|
|
18
|
-
"@vltpkg/dss-breadcrumb": "1.
|
|
19
|
-
"@vltpkg/error-cause": "1.
|
|
20
|
-
"@vltpkg/fast-split": "1.
|
|
21
|
-
"@vltpkg/graph-run": "1.
|
|
22
|
-
"@vltpkg/init": "1.
|
|
23
|
-
"@vltpkg/output": "1.
|
|
24
|
-
"@vltpkg/package-info": "1.
|
|
25
|
-
"@vltpkg/package-json": "1.
|
|
26
|
-
"@vltpkg/pick-manifest": "1.
|
|
27
|
-
"@vltpkg/query": "1.
|
|
28
|
-
"@vltpkg/rollback-remove": "1.
|
|
29
|
-
"@vltpkg/run": "1.
|
|
30
|
-
"@vltpkg/satisfies": "1.
|
|
31
|
-
"@vltpkg/security-archive": "1.
|
|
32
|
-
"@vltpkg/spec": "1.
|
|
33
|
-
"@vltpkg/types": "1.
|
|
34
|
-
"@vltpkg/vlt-json": "1.
|
|
35
|
-
"@vltpkg/workspaces": "1.
|
|
16
|
+
"@vltpkg/cmd-shim": "1.5.0",
|
|
17
|
+
"@vltpkg/dep-id": "1.5.0",
|
|
18
|
+
"@vltpkg/dss-breadcrumb": "1.5.0",
|
|
19
|
+
"@vltpkg/error-cause": "1.5.0",
|
|
20
|
+
"@vltpkg/fast-split": "1.5.0",
|
|
21
|
+
"@vltpkg/graph-run": "1.5.0",
|
|
22
|
+
"@vltpkg/init": "1.5.0",
|
|
23
|
+
"@vltpkg/output": "1.5.0",
|
|
24
|
+
"@vltpkg/package-info": "1.5.0",
|
|
25
|
+
"@vltpkg/package-json": "1.5.0",
|
|
26
|
+
"@vltpkg/pick-manifest": "1.5.0",
|
|
27
|
+
"@vltpkg/query": "1.5.0",
|
|
28
|
+
"@vltpkg/rollback-remove": "1.5.0",
|
|
29
|
+
"@vltpkg/run": "1.5.0",
|
|
30
|
+
"@vltpkg/satisfies": "1.5.0",
|
|
31
|
+
"@vltpkg/security-archive": "1.5.0",
|
|
32
|
+
"@vltpkg/spec": "1.5.0",
|
|
33
|
+
"@vltpkg/types": "1.5.0",
|
|
34
|
+
"@vltpkg/vlt-json": "1.5.0",
|
|
35
|
+
"@vltpkg/workspaces": "1.5.0",
|
|
36
36
|
"path-scurry": "^2.0.1",
|
|
37
37
|
"promise-call-limit": "^3.0.2"
|
|
38
38
|
},
|