@vzn/vx-migrate 0.0.0 → 0.0.485

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.
@@ -0,0 +1,54 @@
1
+ // What the written configs leave to vx.workspace.ts, said once by both
2
+ // migrators: the adoption plugin `vx init` declared still reads the old
3
+ // tool's file every run, and the old tool keyed each package on its own
4
+ // lockfile entries where core keys every task on the whole lockfile.
5
+ // Without a lockfile plugin a dependency bump re-ran every task (hey-api:
6
+ // a `pnpm-lock.yaml` edit re-keyed all 42 builds, none with `pnpm()`).
7
+
8
+ import { existsSync, readdirSync } from 'node:fs'
9
+ import path from 'node:path'
10
+
11
+ /** Each lockfile and the `@vzn/vx-lockfile` plugin that claims it. */
12
+ const LOCKFILES: ReadonlyArray<readonly [file: string, plugin: string]> = [
13
+ ['pnpm-lock.yaml', 'pnpm'],
14
+ ['bun.lock', 'bun'],
15
+ ['bun.lockb', 'bun'],
16
+ ['package-lock.json', 'npm'],
17
+ ['npm-shrinkwrap.json', 'npm'],
18
+ ['yarn.lock', 'yarn'],
19
+ ]
20
+
21
+ export interface AdoptedTool {
22
+ /** The adoption plugin `vx init` declares: `turbo`, `nx`. */
23
+ readonly plugin: string
24
+ /** The file it reads every run: `turbo.json`, `nx.json`. */
25
+ readonly config: string
26
+ /** How the tool keys a package on the lockfile, as the note's opening. */
27
+ readonly keys: (lockfile: string) => string
28
+ /** What `vx run` replaces, in the note: `turbo`, `nx`. */
29
+ readonly runner: string
30
+ }
31
+
32
+ export async function adoptedToolNotes(root: string, tool: AdoptedTool): Promise<string[]> {
33
+ const notes: string[] = []
34
+ let declared = ''
35
+ for (const name of readdirSync(root)) {
36
+ if (!/^vx\.workspace\.(ts|mts|js|mjs|cts|cjs)$/.test(name)) continue
37
+ declared = await Bun.file(path.join(root, name)).text()
38
+ if (new RegExp(`\\b${tool.plugin}\\s*\\(`).test(declared))
39
+ notes.push(
40
+ `${name} still declares ${tool.plugin}(), which reads ${tool.config} every run and fills any task ` +
41
+ 'a vx.config does not declare; the configs written here declare them all. Once ' +
42
+ `\`vx run\` does what ${tool.runner} did, remove ${tool.plugin}() (and its import), then ${tool.config}`,
43
+ )
44
+ break
45
+ }
46
+ const lock = LOCKFILES.find(([file]) => existsSync(path.join(root, file)))
47
+ if (lock !== undefined && !declared.includes('@vzn/vx-lockfile'))
48
+ notes.push(
49
+ `${tool.keys(lock[0])}; vx keys every task on the whole ` +
50
+ `file, so a dependency bump re-runs them all. Declare ${lock[1]}() from @vzn/vx-lockfile ` +
51
+ "in vx.workspace.ts to key each task on its package's dependency closure",
52
+ )
53
+ return notes
54
+ }