@vzn/vx 0.0.194 → 0.0.196

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vzn/vx",
3
- "version": "0.0.194",
3
+ "version": "0.0.196",
4
4
  "description": "A fast, correct task runner and build cache for JavaScript monorepos.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,10 +17,10 @@
17
17
  "node": ">=18"
18
18
  },
19
19
  "optionalDependencies": {
20
- "@vzn/vx-linux-x64": "0.0.194",
21
- "@vzn/vx-linux-arm64": "0.0.194",
22
- "@vzn/vx-darwin-x64": "0.0.194",
23
- "@vzn/vx-darwin-arm64": "0.0.194"
20
+ "@vzn/vx-linux-x64": "0.0.196",
21
+ "@vzn/vx-linux-arm64": "0.0.196",
22
+ "@vzn/vx-darwin-x64": "0.0.196",
23
+ "@vzn/vx-darwin-arm64": "0.0.196"
24
24
  },
25
25
  "dependencies": {
26
26
  "@anthropic-ai/sandbox-runtime": "^0.0.76"
@@ -88,6 +88,7 @@ export async function sweepConfigs(
88
88
  projects: readonly ProjectMeta[],
89
89
  workspaceRoot: string,
90
90
  load: CliLoadOptions = {},
91
+ tasks?: readonly string[],
91
92
  ): Promise<ConfigSweep> {
92
93
  const outputs = new Map<string, string[]>()
93
94
  const inputs = new Map<string, string[][]>()
@@ -115,8 +116,22 @@ export async function sweepConfigs(
115
116
  addTo(outputs, dir, globs)
116
117
  const workspaceInputs = new Set<string>()
117
118
  const uncached = new Set<string>()
119
+ const folded: [string, ProjectConfig][] = []
118
120
  const fold = (dir: string, config: ProjectConfig): void => {
119
- for (const task of Object.values(config.tasks ?? {})) {
121
+ folded.push([dir, config])
122
+ }
123
+ // Only the tasks the run can reach are judged: `vx watch build` over a
124
+ // turbo() package whose `lint` reads `**/*` took build's own `dist/`
125
+ // write for lint's input, and re-ran build.
126
+ const foldAll = (): void => {
127
+ const names = tasks === undefined ? null : reachableNames(folded, tasks)
128
+ for (const [dir, config] of folded) foldTasks(dir, config, names)
129
+ }
130
+ const foldTasks = (dir: string, config: ProjectConfig, names: Set<string> | null): void => {
131
+ for (const [name, task] of Object.entries(config.tasks ?? {})) {
132
+ add(dir, task.cache?.outputs?.files)
133
+ add(workspaceRoot, task.cache?.outputs?.workspaceFiles)
134
+ if (names !== null && !names.has(name)) continue
120
135
  if (task.cache === undefined && task.exec !== undefined && task.exec.persistent === undefined)
121
136
  uncached.add(dir)
122
137
  for (const g of task.cache?.inputs?.workspaceFiles ?? []) workspaceInputs.add(g)
@@ -126,8 +141,6 @@ export async function sweepConfigs(
126
141
  task.cache?.inputs?.workspaceFiles,
127
142
  task.cache?.outputs?.workspaceFiles,
128
143
  )
129
- add(dir, task.cache?.outputs?.files)
130
- add(workspaceRoot, task.cache?.outputs?.workspaceFiles)
131
144
  }
132
145
  }
133
146
  const result = (staged: Map<string, ProjectEntry> | null): ConfigSweep => ({
@@ -159,6 +172,7 @@ export async function sweepConfigs(
159
172
  }
160
173
  if (staged !== null) {
161
174
  for (const p of staged.values()) fold(p.dir, p.config)
175
+ foldAll()
162
176
  return result(staged)
163
177
  }
164
178
  await Promise.all(
@@ -171,9 +185,40 @@ export async function sweepConfigs(
171
185
  }
172
186
  }),
173
187
  )
188
+ foldAll()
174
189
  return result(null)
175
190
  }
176
191
 
192
+ /**
193
+ * The task names a run of `requested` reaches through `dependsOn`, by name
194
+ * in any project: a superset of the graph's tasks, so a file is never
195
+ * dropped that one of them reads. Null when a name pattern (`build.*`)
196
+ * makes the set unknowable without the graph: every task then counts.
197
+ */
198
+ function reachableNames(
199
+ configs: ReadonlyArray<readonly [string, ProjectConfig]>,
200
+ requested: readonly string[],
201
+ ): Set<string> | null {
202
+ const name = (spec: string): string => spec.slice(spec.indexOf('#') + 1).replace(/^\^/, '')
203
+ const names = new Set(requested.map(name))
204
+ for (let grew = true; grew;) {
205
+ grew = false
206
+ for (const [, config] of configs) {
207
+ for (const [task, def] of Object.entries(config.tasks ?? {})) {
208
+ if (!names.has(task)) continue
209
+ for (const dep of def.dependsOn ?? []) {
210
+ const n = name(dep)
211
+ if (!names.has(n)) {
212
+ names.add(n)
213
+ grew = true
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+ return [...names].some((n) => n.includes('*')) ? null : names
220
+ }
221
+
177
222
  /**
178
223
  * The directory entries under a package glob's directory that can be
179
224
  * members: directories (or links) whose name is not dotted and not
package/src/cli/watch.ts CHANGED
@@ -201,7 +201,7 @@ export async function watchCmd(args: readonly string[]): Promise<number> {
201
201
  ...(opts.cacheDir !== undefined ? { cacheDir: opts.cacheDir } : {}),
202
202
  ...(opts.frozen === true ? { frozen: true } : {}),
203
203
  }
204
- const swept = await sweepConfigs(allProjects, workspaceRoot, load)
204
+ const swept = await sweepConfigs(allProjects, workspaceRoot, load, opts.tasks)
205
205
  const watched = await watchedProjects(workspaceRoot, allProjects, scope, load, swept.staged)
206
206
  const ws = await loadCliWorkspace(workspaceRoot)
207
207
  return await runWatchLoop({
@@ -227,7 +227,7 @@ export async function watchCmd(args: readonly string[]): Promise<number> {
227
227
  rediscover: async () => {
228
228
  const workspace = await loadWorkspace(workspaceRoot)
229
229
  const all = await listProjects(workspace)
230
- const sweep = await sweepConfigs(all, workspaceRoot, load)
230
+ const sweep = await sweepConfigs(all, workspaceRoot, load, opts.tasks)
231
231
  const now = await watchedProjects(workspaceRoot, all, inScope(all), load, sweep.staged)
232
232
  return {
233
233
  projects: now,
@@ -515,6 +515,16 @@ export async function loadProjectConfigs(
515
515
  const WATCHED_BUILTINS: ReadonlyArray<readonly [string, object]> = [
516
516
  ['Object.prototype', Object.prototype],
517
517
  ['Array.prototype', Array.prototype],
518
+ // What vx itself runs on: `Bun.hash.xxHash3 = () => 7n` gave every task
519
+ // the key 00000000, and a changed command replayed the old output (D-75).
520
+ ['Bun', Bun],
521
+ ['Bun.hash', Bun.hash],
522
+ ['JSON', JSON],
523
+ ['Math', Math],
524
+ ['String.prototype', String.prototype],
525
+ ['Map.prototype', Map.prototype],
526
+ ['Set.prototype', Set.prototype],
527
+ ['Promise.prototype', Promise.prototype],
518
528
  ]
519
529
 
520
530
  type BuiltinSnapshot = ReadonlyArray<ReadonlyMap<PropertyKey, PropertyDescriptor>>
@@ -530,7 +540,7 @@ function builtinSnapshot(): BuiltinSnapshot {
530
540
  function builtinsChanged(changed: readonly string[], configPath?: string): UserError {
531
541
  const who = configPath === undefined ? 'a project config' : configPath
532
542
  return new UserError(
533
- `${who} changed ${changed.join(', ')} while it was evaluated — a config must not change the built-ins: every other config is read through them, and the cache key does not see what they add`,
543
+ `${who} changed ${changed.join(', ')} while it was evaluated — a config must not change the built-ins vx runs on: other configs are read through them and cache keys are made with them`,
534
544
  )
535
545
  }
536
546