@smoothbricks/nx-plugin 0.4.25 → 0.4.26
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 +144 -41
- package/dist/bin/smoo-nx-exec.js +3 -14
- package/dist/cargo-closure-input.d.ts +13 -15
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -37
- package/dist/cargo-source-hash.d.ts +12 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +416 -32
- package/dist/cargo-workspace.d.ts +7 -7
- package/dist/cargo-workspace.js +8 -8
- package/dist/ensure-built.d.ts +6 -0
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +79 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -96
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +6 -2
- package/dist/workspace-manifest.d.ts +0 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/envrc +6 -1
- package/managed/raw/tooling/direnv/developer-links.ts +43 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -0
- package/managed/raw/tooling/direnv/inherited-devenv.ts +69 -19
- package/managed/raw/tooling/direnv/setup-environment.ts +79 -2
- package/nextest.toml +3 -37
- package/package.json +2 -2
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +711 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +93 -3
- package/src/bin/smoo-nx-exec.ts +3 -14
- package/src/bounded-test-policy.test.ts +0 -1
- package/src/cargo-closure-input.test.ts +313 -15
- package/src/cargo-closure-input.ts +42 -50
- package/src/cargo-resolve-cache.test.ts +975 -0
- package/src/cargo-source-hash.test.ts +17 -3
- package/src/cargo-source-hash.ts +447 -37
- package/src/cargo-workspace.ts +8 -8
- package/src/ensure-built.test.ts +122 -20
- package/src/ensure-built.ts +82 -5
- package/src/index.test.ts +203 -107
- package/src/index.ts +86 -115
- package/src/managed-assets.ts +12 -0
- package/src/manifest-hash.ts +7 -2
- package/src/nextest-partitions.test.ts +150 -0
- package/src/nx-cache-bound.test.ts +114 -0
- package/src/nx-resident-graph-workers.test.ts +121 -0
- package/src/nx-store-resolution.test.ts +98 -0
- package/src/task-history-namespace.test.ts +183 -0
- package/src/workspace-manifest.ts +0 -1
- package/test-timings.json +30 -28
- package/src/__tests__/in-process-nx-index.ts +0 -9
package/README.md
CHANGED
|
@@ -40,10 +40,15 @@ commands, dependencies, inputs and outputs because they override source-aware in
|
|
|
40
40
|
|
|
41
41
|
The plugin's own `nx run nx-plugin:test` aggregates four bounded Bun targets. Each uses Bun's native
|
|
42
42
|
`--timings=test-timings.json --shard=N/4` partition to balance measured per-file work, while normal discovery still runs
|
|
43
|
-
every test file (including newly added files) exactly once. A failed shard fails the aggregate. The shard count
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
every test file (including newly added files) exactly once. A failed shard fails the aggregate. The shard count and
|
|
44
|
+
standard 120-second target deadline stay unchanged. Refresh the portable timing manifest from this package directory
|
|
45
|
+
with `bun test --timeout=30000 --timings=test-timings.json --update-timings`; it is scheduling data, not a test
|
|
46
|
+
allowlist.
|
|
47
|
+
|
|
48
|
+
Real Nx fixtures own their cache and workspace-data directories and stop their daemon before removing the fixture.
|
|
49
|
+
Fixtures that intentionally strip caller directory overrides declare `cacheDirectory: ".nx/cache"` in their own
|
|
50
|
+
`nx.json`; this keeps the native task database local too, rather than leaving a new `~/.nx/<repoKey>` behind. Offline,
|
|
51
|
+
path-only Cargo fixtures likewise own a temporary `CARGO_HOME`; production commands still keep the caller's Cargo home.
|
|
47
52
|
|
|
48
53
|
## Cargo Workspace Layouts
|
|
49
54
|
|
|
@@ -65,6 +70,12 @@ The plugin discovers Cargo workspaces beside Nx project manifests at any depth:
|
|
|
65
70
|
compiled a second time. Cargo's own lock serializes the invocations that share the directory. `cargo-lint-cross` keeps
|
|
66
71
|
`target/cargo-lint-cross`: a foreign triple's units are distinct anyway, and its own lock keeps the cross check from
|
|
67
72
|
queueing behind host builds.
|
|
73
|
+
- **Scheduling:** inference never throttles Nx. It sets no `parallelism: false` or `parallel: false`, no cap, and no
|
|
74
|
+
edge whose only purpose is keeping two cargo writers off one `target/`: Cargo owns that lock, and a second process
|
|
75
|
+
waits inside cargo. An edge states a real consumer — fetch before frozen cargo, the archive before the runners,
|
|
76
|
+
`napi-debug` before the tests that load its addon. A producer and its consumer inside one task are one `&&` command
|
|
77
|
+
(`mkdir` then the archive, `cargo build` then `wasm-bindgen`); independent commands (`cargo fmt` and clippy,
|
|
78
|
+
per-manifest `cargo fetch`, Biome and ESLint) stay in a `commands` list that Nx runs side by side.
|
|
68
79
|
- **Overrides:** normal Nx merging applies. Explicit `nx.targets` fields replace inferred fields, while omitted fields
|
|
69
80
|
retain their inferred base. Use `"dependsOn": ["...", "extra"]` to preserve inferred prerequisites when adding an
|
|
70
81
|
edge; replacing the array makes its author responsible for fetching before frozen Cargo commands.
|
|
@@ -110,8 +121,35 @@ in that declaration, or in the named input it uses, or a toolchain bump will not
|
|
|
110
121
|
|
|
111
122
|
Cargo keeps the caller's `CARGO_HOME`. Moving configuration into an isolated home can change relative paths or lose
|
|
112
123
|
source replacement, credentials, and toolchain settings; forwarding it with `--config` changes precedence. Registry
|
|
113
|
-
access may consequently
|
|
114
|
-
|
|
124
|
+
access may consequently wait on Cargo's package-cache lock, which Cargo arbitrates itself; Nx adds no ordering for it.
|
|
125
|
+
|
|
126
|
+
Graph inference persists locked, offline Cargo resolution in Nx's workspace-data directory. Its content key includes the
|
|
127
|
+
canonical workspace and manifest paths, the complete indexed manifest set, local path-dependency and governing
|
|
128
|
+
manifests, lockfiles, Cargo configuration (including ancestor and `CARGO_HOME` configuration), toolchain pins, the
|
|
129
|
+
resolved Cargo executable, and explicit rustup toolchain selection. Changing only Rust sources, other files, or file
|
|
130
|
+
timestamps reuses the resolved closure without starting Cargo. The configuration identity here is a local
|
|
131
|
+
resolution-cache key, not a machine-specific task input.
|
|
132
|
+
|
|
133
|
+
Concurrent graph computations share one in-flight resolution per workspace. A native Nx file lock serializes workers;
|
|
134
|
+
after acquiring it, a worker checks the persisted result again before starting Cargo. A caller with changed inputs waits
|
|
135
|
+
for the current flight and resolves the new content rather than accepting the old closure. Successful cache writes use
|
|
136
|
+
atomic rename; failed resolutions are never cached. A corrupt cache is reported and resolved again. Inputs that change
|
|
137
|
+
during resolution are retried at most three times, then refused with the cause intact. A WASM-only Nx host cannot
|
|
138
|
+
provide the native lock and receives a typed refusal rather than an unserialized fallback.
|
|
139
|
+
|
|
140
|
+
A plugin worker's normal exit, host disconnect, or handled termination kills Cargo children it still owns; on POSIX it
|
|
141
|
+
kills the whole process group, including wrapper descendants. Standalone callers also forward unhandled termination
|
|
142
|
+
signals to their owned groups. An uncatchable `SIGKILL` cannot run an exit hook; the kernel still releases its file
|
|
143
|
+
lock.
|
|
144
|
+
|
|
145
|
+
The `@smoothbricks/nx-plugin:cargo-resolve` diagnostics channel reports `{ phase: "join", manifest }` when a caller
|
|
146
|
+
joins an existing flight. With no subscribers, inference neither allocates nor publishes an event. The cache regressions
|
|
147
|
+
use this readiness signal and Cargo control-channel events to prove concurrency and child teardown without sleep-based
|
|
148
|
+
timing assumptions; their outer hang guards report still-open test spans and process/gate state.
|
|
149
|
+
|
|
150
|
+
Keep workspace-owned runtime state outside Nx's source index. In a cowshed workspace, the root `.nxignore` must include
|
|
151
|
+
`.cowshed/`: Nx's watcher reads the root ignore files, not Git's `.git/info/exclude`. Watching the daemon's own log,
|
|
152
|
+
plugin sockets or job records turns each graph computation into another file event and another graph computation.
|
|
115
153
|
|
|
116
154
|
### Cargo source runtime inputs
|
|
117
155
|
|
|
@@ -129,8 +167,8 @@ For a package-root Cargo workspace, pass its manifest relative to the Nx root:
|
|
|
129
167
|
`smoo-nx-cargo-hash packages/example/Cargo.toml`. A shared input covering several Cargo workspaces includes one runtime
|
|
130
168
|
entry per manifest.
|
|
131
169
|
|
|
132
|
-
By default, the command
|
|
133
|
-
including transitive dependencies, Rust sources, target source files, governing Cargo manifests, and Cargo
|
|
170
|
+
By default, the command uses the content-keyed `cargo metadata --locked --offline` resolution and hashes external path
|
|
171
|
+
packages, including transitive dependencies, Rust sources, target source files, governing Cargo manifests, and Cargo
|
|
134
172
|
configuration. It also covers path packages under `node_modules`, which Nx's normal file map ignores. Packages inside
|
|
135
173
|
both the Nx and Cargo workspaces are left to the plugin's inferred file inputs. Adding or moving a dependency does not
|
|
136
174
|
require maintaining a second list of source roots. The command refuses missing dependencies or an unavailable locked
|
|
@@ -155,24 +193,30 @@ it in each custom Cargo target's `inputs`, alongside `cargoToolchain`, the targe
|
|
|
155
193
|
}
|
|
156
194
|
```
|
|
157
195
|
|
|
158
|
-
Cargo decides the closure.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
196
|
+
Cargo decides the closure. Graph inference checks the content-keyed locked offline resolution of the local packages
|
|
197
|
+
under the project's root and every mutable local package they reach through normal, build or dev dependencies; an edit
|
|
198
|
+
to a workspace member outside that closure leaves the task key alone. The members Nx's file index holds become filesets:
|
|
199
|
+
each package's `.rs` files, `Cargo.toml` files and `.cargo/config[.toml]` below its directory (skipping `target/` and
|
|
200
|
+
the other directories the hash command skips), target sources outside it, its governing workspace manifest, the
|
|
201
|
+
`Cargo.toml` and `.cargo/config[.toml]` of every directory from the package up to the Nx root, and the workspace's
|
|
202
|
+
`Cargo.lock`. Nx hashes those from the file hashes it already keeps, so hashing these inputs starts no process. A graph
|
|
203
|
+
with unchanged resolution inputs starts no Cargo process either.
|
|
166
204
|
|
|
167
205
|
Members the file index cannot hold, outside the Nx workspace or under `node_modules`, are hashed by one runtime
|
|
168
|
-
`smoo-nx-cargo-hash --closure <projectRoot> <Cargo.toml>` entry, present only while such members exist.
|
|
169
|
-
|
|
206
|
+
`smoo-nx-cargo-hash --closure <projectRoot> <Cargo.toml>` entry, present only while such members exist. Its cached
|
|
207
|
+
resolution checks external manifests too, so a dependency introduced by an external manifest edit is still covered.
|
|
208
|
+
|
|
209
|
+
Cargo resolution failures (no `cargo` on PATH, a stale `Cargo.lock`, or an unavailable locked dependency) fail graph
|
|
210
|
+
inference with `CargoMetadataError`, including the manifest path and Cargo's cause. A member inside the workspace
|
|
211
|
+
missing from Nx's file index, or another closure Nx cannot express precisely, fails with `CargoClosureInputError`.
|
|
212
|
+
Neither condition falls back to a whole-workspace runtime hash or silently reuses an older closure.
|
|
170
213
|
|
|
171
|
-
|
|
172
|
-
`
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
the
|
|
214
|
+
Resolution therefore needs the packages `Cargo.lock` pins already in `CARGO_HOME`, before any task can run: the graph's
|
|
215
|
+
own `cargo-fetch` target cannot supply them. The managed shell entry (`tooling/direnv/setup-environment.ts`) runs
|
|
216
|
+
`cargo fetch --locked` for every project whose `Cargo.toml` declares `[workspace]`, once per change to that workspace's
|
|
217
|
+
`Cargo.toml`, `Cargo.lock` or `.cargo/config[.toml]`, with its stamp in `CARGO_HOME/smoo-fetched`. In CI a failed fetch
|
|
218
|
+
fails the shell; locally it prints Cargo's cause, loads the shell, and retries on the next entry, while graph inference
|
|
219
|
+
keeps refusing with that same cause.
|
|
176
220
|
|
|
177
221
|
In-workspace members follow Nx's file semantics, which differ from the command's own walk in two places: a symlinked
|
|
178
222
|
directory inside a package is not followed, and manifests and Cargo configuration above the Nx root (a
|
|
@@ -293,30 +337,32 @@ Concrete targets come from concrete files:
|
|
|
293
337
|
serves every checkout of the same commit; nextest re-points `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the
|
|
294
338
|
extracted binaries at runtime, but a test that reads them through the compile-time `env!` macro keeps the producing
|
|
295
339
|
tree's path. Per-crate runners accept an empty nextest selection because a valid workspace member may have no tests
|
|
296
|
-
and a hash partition may legitimately be empty.
|
|
297
|
-
|
|
298
|
-
also receives the cacheable `cargo-wasm` output target in its owning
|
|
340
|
+
and a hash partition may legitimately be empty. A crate in the project that builds the debug cdylib runs after
|
|
341
|
+
`napi-debug`, because its tests load that addon from `target/debug`. A crate declaring
|
|
342
|
+
`[package.metadata.smoothbricks.wasm-bindgen]` also receives the cacheable `cargo-wasm` output target in its owning
|
|
343
|
+
project.
|
|
299
344
|
- The plugin's own `nextest.toml` is passed as `--tool-config-file "smoo:$PWD/<path>"`, so it is a layer BENEATH the
|
|
300
345
|
repository's `<cargo-workspace>/.config/nextest.toml` rather than a replacement for it: a repository can raise a
|
|
301
|
-
timeout
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
346
|
+
timeout or declare `archive.include` for a cdylib or fixture the archived test binaries need, and its settings win.
|
|
347
|
+
That file is an input of both the archive and every runner, so changing it invalidates the verdicts it governs. `$PWD`
|
|
348
|
+
keeps the command text identical across checkouts while satisfying nextest's requirement that a tool config path be
|
|
349
|
+
absolute; `--user-config-file none` still holds, because a developer's `~/.config/nextest` must not decide a cached
|
|
350
|
+
verdict.
|
|
306
351
|
- A crate whose suite outgrows one bounded window declares `[package.metadata.smoothbricks.test] shards = N`, and gets
|
|
307
352
|
`cargo-test-<package>-shard1..N`, each running `--partition hash:i/N` with the full bound. nextest assigns a test to a
|
|
308
353
|
shard by hashing its name, so the shards stay an exact partition of the crate as tests and test binaries are added,
|
|
309
354
|
and a stale `N` can only make a target slow — never drop a test. Omitting the key means one target, as before.
|
|
310
|
-
- Tests that a `nextest.toml` override singles out
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
355
|
+
- Tests that a `nextest.toml` override singles out run separately in `cargo-test-<package>-exceptions-shard1..N`, using
|
|
356
|
+
the same declared partition count. Ordinary shards run the complement, so the union still covers every test exactly
|
|
357
|
+
once. The plugin's own overrides raise `slow-timeout` for compile-fail tests and for the real-APFS full-lifecycle
|
|
358
|
+
tests; lifting them out keeps their raised bound from delaying an ordinary shard, and partitioning the class keeps
|
|
359
|
+
every target inside its deadline without relaxing it. Exceptional shards are scheduled like the ordinary ones: nothing
|
|
360
|
+
is exclusive, and isolation between concurrent real-APFS fixtures is the production backend's per-image lease, not Nx
|
|
361
|
+
scheduling. The exceptional filter is derived from the overrides in `nextest.toml`, so adding an override is the whole
|
|
362
|
+
classification change. Only sharded crates need these targets; an unsharded crate already runs its whole suite in one
|
|
363
|
+
process. Empty partitions pass, including platforms where the tests are `cfg`-ed out. `nextest-partitions.test.ts`
|
|
364
|
+
executes the inferred archive and shard commands over 26 tests and asserts that the ordinary shards ran exactly the 13
|
|
365
|
+
ordinary tests once and the exceptional shards exactly the 13 exceptional ones.
|
|
320
366
|
- Canonical `napi` package metadata provides a host `cargo-napi` target and named release targets for each configured
|
|
321
367
|
triple. Linux `--use-napi-cross` targets compile C/C++ dependencies with Clang; the NAPI CLI supplies its downloaded
|
|
322
368
|
GNU sysroot and toolchain flags. This avoids the bundled GCC's unsupported diagnostics-color flag without disabling
|
|
@@ -432,6 +478,13 @@ It is deliberately not `nx run <target> && exec`:
|
|
|
432
478
|
Pass `--workspace-root <dir>` before `--` when invoking the wrapper outside the workspace. The binary path resolves
|
|
433
479
|
against the caller's current directory.
|
|
434
480
|
|
|
481
|
+
Nx state belongs to one workspace. The wrapper's own Nx is the one `NX_WORKSPACE_ROOT_PATH` names, else the nearest
|
|
482
|
+
`nx.json` above the current directory. When that is not the requested root, `NX_SOCKET_DIR`, `NX_DAEMON_SOCKET_DIR`,
|
|
483
|
+
`NX_WORKSPACE_DATA_DIRECTORY` and `NX_CACHE_DIRECTORY` are not passed on, so the root's daemon, task database and cache
|
|
484
|
+
stay its own instead of landing on the socket and database of the workspace that exported them. The managed shell and
|
|
485
|
+
Cowshed supervisor publish `NX_WORKSPACE_ROOT_PATH` beside those overrides, so a child entering a scratch root still
|
|
486
|
+
knows which workspace owns its inherited state. Without a managed owner, the wrapper derives the root from cwd.
|
|
487
|
+
|
|
435
488
|
Without `--` and a binary, the wrapper only makes the target current and exits 0, or with the failed run's status:
|
|
436
489
|
|
|
437
490
|
```bash
|
|
@@ -441,6 +494,56 @@ smoo-nx-exec my-cli:build --workspace-root "$root"
|
|
|
441
494
|
A hit prints nothing, where `nx run` would replay every task's cached log. A miss prints Nx's run of the target on
|
|
442
495
|
stderr.
|
|
443
496
|
|
|
497
|
+
## Nx 23.2.1 Runtime Patch
|
|
498
|
+
|
|
499
|
+
The repository installs Nx 23.2.1 with [`patches/nx@23.2.1.patch`](../../patches/nx@23.2.1.patch) applied, from an
|
|
500
|
+
immutable release tarball: the root `package.json` keeps `devDependencies.nx` at `23.2.1` and sets `overrides.nx` to the
|
|
501
|
+
release asset's URL, and `bun.lock` pins its sha512. `tooling/patched-nx.ts` builds the tarball reproducibly from the
|
|
502
|
+
registry tarball and the patch; the `Patched Nx` workflow publishes it once from `main`, under a tag named for the
|
|
503
|
+
uncompressed tar's sha256, and verifies the served asset on every later run. A tarball, unlike a `patchedDependencies`
|
|
504
|
+
entry, stays in Bun's read-only global store (`~/.bun/install/cache/links`), so a sandbox can run Nx without being able
|
|
505
|
+
to write it.
|
|
506
|
+
|
|
507
|
+
`@nx/js` imports `nx` (`nx/release`, `nx/src/…`) without declaring it
|
|
508
|
+
([nrwl/nx#34087](https://github.com/nrwl/nx/issues/34087)), and a global-store entry links only declared dependencies,
|
|
509
|
+
so `@nx/js` in that store cannot find Nx: its version actions, and this plugin's that extend them, would fail.
|
|
510
|
+
`patches/@nx%2Fjs@23.2.1.patch` declares the peer. Being patched, `@nx/js` installs project-local under
|
|
511
|
+
`node_modules/.bun/`, where `nx` resolves through the hoisted `node_modules/.bun/node_modules/nx` link to the same
|
|
512
|
+
tarball entry; Bun's lock still records only the registry peers, so the placement is what makes the import resolve.
|
|
513
|
+
|
|
514
|
+
The Nx patch repairs upstream Nx runtime behavior, separately from this plugin's workspace-owner checks:
|
|
515
|
+
|
|
516
|
+
- **Task history uses the client's native database connection.** Task details and history must share that connection; a
|
|
517
|
+
daemon can have frozen a different database namespace before a later client supplies workspace-data overrides. The
|
|
518
|
+
patch removes the obsolete history RPCs and retains native errors, including post-run failures. See
|
|
519
|
+
[upstream Nx #37268](https://github.com/nrwl/nx/pull/37268).
|
|
520
|
+
- **The default cache limit uses the cache's own filesystem.** It takes ten percent of `statfs(cacheDir)` capacity, or
|
|
521
|
+
its nearest existing ancestor when the directory has not been created. This avoids synchronously inventorying every
|
|
522
|
+
mounted disk. Explicit `NX_MAX_CACHE_SIZE` and `nx.json.maxCacheSize` retain their precedence; filesystem errors other
|
|
523
|
+
than a missing directory still fail the operation. See [upstream Nx #37269](https://github.com/nrwl/nx/pull/37269).
|
|
524
|
+
- **The daemon keeps graph plugin workers running.** Nx stops an isolated plugin worker after the last phase it has
|
|
525
|
+
hooks for, which for a graph-only plugin is every graph; the daemon recomputes the graph on every tracked file change,
|
|
526
|
+
so each change spawned and loaded every graph plugin's worker again (median 199 ms against 63 ms from edit to graph in
|
|
527
|
+
a one-project fixture, 0.9–1.5 s per worker under a gate's load). On the daemon a worker with graph hooks now lives as
|
|
528
|
+
long as the daemon; one-shot clients and task-only plugins keep the eager shutdown. See
|
|
529
|
+
[upstream Nx #37271](https://github.com/nrwl/nx/pull/37271).
|
|
530
|
+
- **Nx resolves typescript and release version actions from the workspace.** Nx 23.2.1 loads both with a plain `require`
|
|
531
|
+
from its own location, which in Bun's global store holds only Nx's own dependencies. There it finds no `typescript`,
|
|
532
|
+
so its dependency analysis skips every source import without a warning (this repository lost 12 of 44 graph edges),
|
|
533
|
+
and `release version` cannot resolve `@nx/js`'s version actions. The patch resolves both through `getNxRequirePaths`
|
|
534
|
+
(the workspace first), falling back to Nx's own location. See
|
|
535
|
+
[upstream Nx #37272](https://github.com/nrwl/nx/pull/37272).
|
|
536
|
+
|
|
537
|
+
Publishing or installing `@smoothbricks/nx-plugin` does **not** change a consumer's Nx. A consumer needing these repairs
|
|
538
|
+
sets the same `overrides.nx` URL in its root `package.json`, registers the same `@nx/js` patch in its
|
|
539
|
+
`patchedDependencies`, regenerates its lockfile, and proves a frozen install and its affected normal Nx gates. Do not
|
|
540
|
+
replace the registry dependency with a local link or hide a failure by resetting the database or disabling the daemon.
|
|
541
|
+
|
|
542
|
+
The patch is version-specific. A changed patch publishes a new release, and consumers move to its URL. On an Nx upgrade,
|
|
543
|
+
remove each hunk only when the installed upstream release contains that repair and the task-history namespace,
|
|
544
|
+
cache-bound, resident-worker and store-resolution regressions pass; preserve any repair not yet released. When every
|
|
545
|
+
hunk is upstream, drop the override, the patch, `tooling/patched-nx.ts` and the workflow together.
|
|
546
|
+
|
|
444
547
|
## Bun Test Tracing Generator
|
|
445
548
|
|
|
446
549
|
Configure a package for the Bun test tracing + no-emit test typechecking pattern used in this repo.
|
package/dist/bin/smoo-nx-exec.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
2
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
4
3
|
import { inspect } from 'node:util';
|
|
5
|
-
import { describeMiss, ensureBuilt, parseTargetSelector } from '../ensure-built.js';
|
|
4
|
+
import { describeMiss, ensureBuilt, findNxWorkspaceRoot, parseTargetSelector } from '../ensure-built.js';
|
|
6
5
|
const USAGE = 'usage: smoo-nx-exec <project:target[:configuration]> [--workspace-root <dir>] [-- <binary> [args...]]';
|
|
7
6
|
/** Argument and environment problems all exit 2, the shell's "usage" code. */
|
|
8
7
|
function usageError(message) {
|
|
@@ -38,17 +37,7 @@ function tokenize(args) {
|
|
|
38
37
|
return tokens;
|
|
39
38
|
}
|
|
40
39
|
function findWorkspaceRoot(from) {
|
|
41
|
-
|
|
42
|
-
for (;;) {
|
|
43
|
-
if (existsSync(join(directory, 'nx.json'))) {
|
|
44
|
-
return directory;
|
|
45
|
-
}
|
|
46
|
-
const parent = dirname(directory);
|
|
47
|
-
if (parent === directory) {
|
|
48
|
-
return usageError(`no nx.json at or above ${from}; pass --workspace-root`);
|
|
49
|
-
}
|
|
50
|
-
directory = parent;
|
|
51
|
-
}
|
|
40
|
+
return findNxWorkspaceRoot(from) ?? usageError(`no nx.json at or above ${from}; pass --workspace-root`);
|
|
52
41
|
}
|
|
53
42
|
const argv = process.argv.slice(2);
|
|
54
43
|
const separator = argv.indexOf('--');
|
|
@@ -7,22 +7,23 @@ import { type CargoResolve } from './cargo-source-hash.js';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const CARGO_CLOSURE_INPUT = "cargoClosure";
|
|
9
9
|
type Input = NonNullable<TargetConfiguration['inputs']>[number];
|
|
10
|
+
/** A closure Nx cannot express exactly is a refusal, never a broader cache key. */
|
|
11
|
+
export declare class CargoClosureInputError extends Error {
|
|
12
|
+
readonly projectRoot: string;
|
|
13
|
+
constructor(projectRoot: string, cause: unknown);
|
|
14
|
+
}
|
|
10
15
|
/**
|
|
11
16
|
* One Cargo workspace as one project-graph computation sees it. `manifest` is
|
|
12
17
|
* the workspace's root manifest relative to the Nx workspace root.
|
|
13
18
|
*/
|
|
14
|
-
export
|
|
15
|
-
readonly kind: 'resolved';
|
|
19
|
+
export interface CargoClosureSource {
|
|
16
20
|
readonly manifest: string;
|
|
17
21
|
/** The canonical Nx workspace root. */
|
|
18
22
|
readonly root: string;
|
|
19
23
|
readonly cargo: CargoResolve;
|
|
20
24
|
/** Every `Cargo.toml` in Nx's file index, relative to the workspace root. */
|
|
21
25
|
readonly indexed: ReadonlySet<string>;
|
|
22
|
-
}
|
|
23
|
-
readonly kind: 'unresolved';
|
|
24
|
-
readonly manifest: string;
|
|
25
|
-
};
|
|
26
|
+
}
|
|
26
27
|
/**
|
|
27
28
|
* Every `Cargo.toml` Nx's workspace file index holds: .gitignore and .nxignore
|
|
28
29
|
* applied, `node_modules` never entered. A package whose manifest is missing
|
|
@@ -30,11 +31,9 @@ export type CargoClosureSource = {
|
|
|
30
31
|
*/
|
|
31
32
|
export declare function indexedCargoManifests(workspaceRoot: string): Promise<ReadonlySet<string>>;
|
|
32
33
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* closure inputs, hashed at run time by the command that reports the same
|
|
37
|
-
* failure wherever a task needs it. Said once here, not once per project.
|
|
34
|
+
* Content-keyed locked offline metadata. A refusal fails graph inference:
|
|
35
|
+
* a stale closure or runtime whole-workspace fallback cannot establish the
|
|
36
|
+
* precise set of cache inputs.
|
|
38
37
|
*/
|
|
39
38
|
export declare function resolveCargoClosureSource(manifest: string, workspaceRoot: string, indexed: Promise<ReadonlySet<string>>): Promise<CargoClosureSource>;
|
|
40
39
|
/**
|
|
@@ -53,10 +52,9 @@ export declare function resolveCargoClosureSource(manifest: string, workspaceRoo
|
|
|
53
52
|
* exist. That command resolves the closure again when it runs, so a member
|
|
54
53
|
* that only an edit outside the workspace brings in is still covered.
|
|
55
54
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* the
|
|
59
|
-
* reported on stderr.
|
|
55
|
+
* An in-workspace member missing from Nx's file index is a typed refusal,
|
|
56
|
+
* never a whole-workspace runtime hash. Only outside-workspace members need
|
|
57
|
+
* the external-only runtime input.
|
|
60
58
|
*/
|
|
61
59
|
export declare function cargoClosureInputs(projectRoot: string, sources: readonly CargoClosureSource[]): Promise<Input[]>;
|
|
62
60
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cargo-closure-input.d.ts","sourceRoot":"","sources":["../src/cargo-closure-input.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"cargo-closure-input.d.ts","sourceRoot":"","sources":["../src/cargo-closure-input.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIpE,OAAO,EAEL,KAAK,YAAY,EAIlB,MAAM,wBAAwB,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAElD,KAAK,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,mFAAmF;AACnF,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,YAAY,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAS9C;CACF;AAgBD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAM/F;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GACpC,OAAO,CAAC,kBAAkB,CAAC,CAI7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,SAAS,kBAAkB,EAAE,GACrC,OAAO,CAAC,KAAK,EAAE,CAAC,CAelB"}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { realpath } from 'node:fs/promises';
|
|
2
2
|
import { isAbsolute, join, posix, relative, sep } from 'node:path';
|
|
3
|
-
import { globWithWorkspaceContext } from 'nx/src/utils/workspace-context.js';
|
|
4
|
-
import {
|
|
3
|
+
import { globWithWorkspaceContext, globWithWorkspaceContextSync } from 'nx/src/utils/workspace-context.js';
|
|
4
|
+
import { workspaceRoot as daemonWorkspaceRoot } from 'nx/src/utils/workspace-root.js';
|
|
5
|
+
import { CARGO_ANCESTOR_INPUTS, dependencyClosure, HASH_SKIPPED_DIRECTORIES, readCargoResolve, } from './cargo-source-hash.js';
|
|
5
6
|
/**
|
|
6
7
|
* The named input the plugin infers for every project with crates of a Cargo
|
|
7
8
|
* workspace under its root: the mutable sources of the Cargo-resolved
|
|
8
9
|
* dependency closure of those crates, and the lockfile that pins the rest.
|
|
9
10
|
*/
|
|
10
11
|
export const CARGO_CLOSURE_INPUT = 'cargoClosure';
|
|
12
|
+
/** A closure Nx cannot express exactly is a refusal, never a broader cache key. */
|
|
13
|
+
export class CargoClosureInputError extends Error {
|
|
14
|
+
projectRoot;
|
|
15
|
+
constructor(projectRoot, cause) {
|
|
16
|
+
super(`Cannot infer ${CARGO_CLOSURE_INPUT} for ${projectRoot}: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
17
|
+
cause,
|
|
18
|
+
});
|
|
19
|
+
this.name = 'CargoClosureInputError';
|
|
20
|
+
this.projectRoot = projectRoot;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
11
23
|
/**
|
|
12
24
|
* How a runtime input reaches the hash command. Nx runs it with `sh -c` from
|
|
13
25
|
* the workspace root and puts no `node_modules/.bin` on its PATH; a plugin Nx
|
|
@@ -26,34 +38,20 @@ const GLOB_SYNTAX = /[*?[\]{}()!,]/;
|
|
|
26
38
|
* here has no files a fileset input can hash.
|
|
27
39
|
*/
|
|
28
40
|
export async function indexedCargoManifests(workspaceRoot) {
|
|
29
|
-
|
|
41
|
+
const manifests = workspaceRoot === daemonWorkspaceRoot
|
|
42
|
+
? await globWithWorkspaceContext(workspaceRoot, ['**/Cargo.toml'])
|
|
43
|
+
: globWithWorkspaceContextSync(workspaceRoot, ['**/Cargo.toml']);
|
|
44
|
+
return new Set(manifests);
|
|
30
45
|
}
|
|
31
46
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* closure inputs, hashed at run time by the command that reports the same
|
|
36
|
-
* failure wherever a task needs it. Said once here, not once per project.
|
|
47
|
+
* Content-keyed locked offline metadata. A refusal fails graph inference:
|
|
48
|
+
* a stale closure or runtime whole-workspace fallback cannot establish the
|
|
49
|
+
* precise set of cache inputs.
|
|
37
50
|
*/
|
|
38
51
|
export async function resolveCargoClosureSource(manifest, workspaceRoot, indexed) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const [{ root, cargo }, index] = await Promise.all([
|
|
43
|
-
realpath(workspaceRoot).then(async (root) => ({
|
|
44
|
-
root,
|
|
45
|
-
cargo: await readCargoResolve(join(root, manifest), root),
|
|
46
|
-
})),
|
|
47
|
-
indexed,
|
|
48
|
-
]);
|
|
49
|
-
return { kind: 'resolved', manifest, root, cargo, indexed: index };
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
-
process.stderr.write(`@smoothbricks/nx-plugin: resolving ${manifest} failed (${message.trim().split('\n').slice(0, 3).join(' ')}); ` +
|
|
54
|
-
`every ${CARGO_CLOSURE_INPUT} under it runs smoo-nx-cargo-hash on each hash instead of reading Nx's file index.\n`);
|
|
55
|
-
return { kind: 'unresolved', manifest };
|
|
56
|
-
}
|
|
52
|
+
const [root, index] = await Promise.all([realpath(workspaceRoot), indexed]);
|
|
53
|
+
const cargo = await readCargoResolve(join(root, manifest), root, index);
|
|
54
|
+
return { manifest, root, cargo, indexed: index };
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
59
57
|
* The `cargoClosure` definition for the project at `projectRoot`: for each
|
|
@@ -71,10 +69,9 @@ export async function resolveCargoClosureSource(manifest, workspaceRoot, indexed
|
|
|
71
69
|
* exist. That command resolves the closure again when it runs, so a member
|
|
72
70
|
* that only an edit outside the workspace brings in is still covered.
|
|
73
71
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* the
|
|
77
|
-
* reported on stderr.
|
|
72
|
+
* An in-workspace member missing from Nx's file index is a typed refusal,
|
|
73
|
+
* never a whole-workspace runtime hash. Only outside-workspace members need
|
|
74
|
+
* the external-only runtime input.
|
|
78
75
|
*/
|
|
79
76
|
export async function cargoClosureInputs(projectRoot, sources) {
|
|
80
77
|
const inputs = [];
|
|
@@ -94,9 +91,6 @@ export async function cargoClosureInputs(projectRoot, sources) {
|
|
|
94
91
|
async function workspaceClosureInputs(projectRoot, source) {
|
|
95
92
|
const lock = posix.join('{workspaceRoot}', posix.dirname(source.manifest), 'Cargo.lock');
|
|
96
93
|
const closureArguments = `--closure ${shellWord(projectRoot)} ${shellWord(source.manifest)}`;
|
|
97
|
-
const runtimeHash = [lock, { runtime: `${CARGO_HASH_COMMAND} --include-workspace ${closureArguments}` }];
|
|
98
|
-
if (source.kind === 'unresolved')
|
|
99
|
-
return runtimeHash;
|
|
100
94
|
const { root, cargo, indexed } = source;
|
|
101
95
|
const packageDirectories = [];
|
|
102
96
|
const files = [];
|
|
@@ -115,7 +109,7 @@ async function workspaceClosureInputs(projectRoot, source) {
|
|
|
115
109
|
throw new Error(`the Cargo package ${directory} is not in Nx's file index (an ignored directory)`);
|
|
116
110
|
}
|
|
117
111
|
packageDirectories.push(directory);
|
|
118
|
-
for (const file of [...pkg.sources,
|
|
112
|
+
for (const file of [...pkg.sources, pkg.governingManifest]) {
|
|
119
113
|
const path = indexablePath(root, file);
|
|
120
114
|
if (path === null)
|
|
121
115
|
throw new Error(`${directory} compiles ${file}, which Nx's file index cannot hold`);
|
|
@@ -127,9 +121,7 @@ async function workspaceClosureInputs(projectRoot, source) {
|
|
|
127
121
|
throw new Error(`${unglobbable} contains glob syntax, so no fileset can name it`);
|
|
128
122
|
}
|
|
129
123
|
catch (error) {
|
|
130
|
-
|
|
131
|
-
`instead of reading Nx's file index: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
132
|
-
return runtimeHash;
|
|
124
|
+
throw new CargoClosureInputError(projectRoot, error);
|
|
133
125
|
}
|
|
134
126
|
// A package nested in another member's directory is already covered by it.
|
|
135
127
|
const directories = [...new Set(packageDirectories)]
|
|
@@ -5,6 +5,7 @@ export interface LocalCargoPackage {
|
|
|
5
5
|
readonly manifest: string;
|
|
6
6
|
/** Every target's source file: library, binaries, tests, build script. A target may live outside `directory`. */
|
|
7
7
|
readonly sources: readonly string[];
|
|
8
|
+
readonly governingManifest: string;
|
|
8
9
|
}
|
|
9
10
|
/** What locked, offline `cargo metadata` reports about one Cargo workspace's mutable packages. */
|
|
10
11
|
export interface CargoResolve {
|
|
@@ -29,15 +30,19 @@ export interface CargoPathInputsOptions {
|
|
|
29
30
|
export declare const HASH_SKIPPED_DIRECTORIES: readonly ['target', '.git', 'node_modules', '.cache', '.cowshed', '.fseventsd', '.TemporaryItems', '.Trashes', '.Spotlight-V100', '.DocumentRevisions-V100'];
|
|
30
31
|
/** Files in every ancestor of a package directory that Cargo reads while building it. */
|
|
31
32
|
export declare const CARGO_ANCESTOR_INPUTS: readonly ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
|
|
32
|
-
/**
|
|
33
|
-
export declare
|
|
33
|
+
/** A Cargo resolution refusal: no stale closure or runtime whole-workspace substitute is safe. */
|
|
34
|
+
export declare class CargoMetadataError extends Error {
|
|
35
|
+
readonly manifestPath: string;
|
|
36
|
+
constructor(manifestPath: string, cause: unknown);
|
|
37
|
+
}
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
+
* One content-keyed resolution per Cargo workspace, across concurrent graph
|
|
40
|
+
* calls and workers. Nx's kernel FileLock releases even if its worker dies;
|
|
41
|
+
* in-process callers join before taking that lock, so a synchronous lock()
|
|
42
|
+
* cannot block the continuation that owns it. A changed key queues behind
|
|
43
|
+
* the old child instead of receiving its stale answer.
|
|
39
44
|
*/
|
|
40
|
-
export declare function
|
|
45
|
+
export declare function readCargoResolve(manifestPath: string, cwd: string, indexed?: ReadonlySet<string>): Promise<CargoResolve>;
|
|
41
46
|
export declare function hashCargoPathInputs(manifestPath: string, workspaceRoot: string, options?: CargoPathInputsOptions): Promise<string>;
|
|
42
47
|
/**
|
|
43
48
|
* The ids Cargo's resolve graph reaches from the local packages under
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"AA0FA,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iHAAiH;IACjH,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,kGAAkG;AAClG,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC7C,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;CAC/D;AAED,MAAM,WAAW,sBAAsB;IACrC,oHAAoH;IACpH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA0HD,2GAA2G;AAC3G,eAAO,MAAM,wBAAwB,YACnC,QAAQ,EACR,MAAM,EACN,cAAc,EACd,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,yBAAyB,CACjB,CAAC;AACX,yFAAyF;AACzF,eAAO,MAAM,qBAAqB,YAAI,YAAY,EAAE,eAAe,EAAE,oBAAoB,CAAU,CAAC;AA6BpG,kGAAkG;AAClG,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,YAAY,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAU/C;CACF;AAiJD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAC5B,OAAO,CAAC,YAAY,CAAC,CA0DvB;AA6FD,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,MAAM,CAAC,CA0FjB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAc5G"}
|