@smoothbricks/nx-plugin 0.7.12 → 0.7.13

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.
Files changed (89) hide show
  1. package/README.md +78 -24
  2. package/dist/.build-inputs.json +20 -12
  3. package/dist/built-output-packages.d.ts +27 -0
  4. package/dist/built-output-packages.d.ts.map +1 -0
  5. package/dist/built-output-packages.js +97 -0
  6. package/dist/cross-check-policy.d.ts +13 -1
  7. package/dist/cross-check-policy.d.ts.map +1 -1
  8. package/dist/cross-check-policy.js +13 -1
  9. package/dist/executors/bounded-exec/admission-queue.d.ts +68 -0
  10. package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -0
  11. package/dist/executors/bounded-exec/admission-queue.js +131 -0
  12. package/dist/executors/bounded-exec/cpu-grant.d.ts +14 -0
  13. package/dist/executors/bounded-exec/cpu-grant.d.ts.map +1 -0
  14. package/dist/executors/bounded-exec/cpu-grant.js +18 -0
  15. package/dist/executors/bounded-exec/cpu-pool.d.ts +1 -14
  16. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  17. package/dist/executors/bounded-exec/cpu-pool.js +2 -49
  18. package/dist/executors/bounded-exec/executor.d.ts +5 -12
  19. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  20. package/dist/executors/bounded-exec/executor.js +51 -154
  21. package/dist/executors/bounded-exec/memory-retry.d.ts +39 -0
  22. package/dist/executors/bounded-exec/memory-retry.d.ts.map +1 -0
  23. package/dist/executors/bounded-exec/memory-retry.js +33 -0
  24. package/dist/executors/bounded-exec/parent-grant.d.ts +43 -0
  25. package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -0
  26. package/dist/executors/bounded-exec/parent-grant.js +37 -0
  27. package/dist/executors/bounded-exec/peak-charge.d.ts +17 -0
  28. package/dist/executors/bounded-exec/peak-charge.d.ts.map +1 -0
  29. package/dist/executors/bounded-exec/peak-charge.js +20 -0
  30. package/dist/executors/bounded-exec/pool-environment.d.ts +25 -0
  31. package/dist/executors/bounded-exec/pool-environment.d.ts.map +1 -0
  32. package/dist/executors/bounded-exec/pool-environment.js +34 -0
  33. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  34. package/dist/executors/bounded-exec/run-cpu-pool.js +1 -1
  35. package/dist/executors/bounded-exec/verdict.d.ts +3 -18
  36. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  37. package/dist/executors/bounded-exec/verdict.js +4 -25
  38. package/dist/index.d.ts +4 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +62 -21
  41. package/dist/managed-files/ci-workflow.d.ts +29 -5
  42. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  43. package/dist/managed-files/ci-workflow.js +111 -16
  44. package/dist/managed-files/context.d.ts.map +1 -1
  45. package/dist/managed-files/context.js +1 -0
  46. package/dist/managed-files/files.d.ts +3 -1
  47. package/dist/managed-files/files.d.ts.map +1 -1
  48. package/dist/managed-files/files.js +2 -0
  49. package/dist/managed-files/publish-workflow.d.ts +6 -1
  50. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  51. package/dist/managed-files/publish-workflow.js +16 -11
  52. package/dist/owned-installation.d.ts.map +1 -1
  53. package/dist/owned-installation.js +48 -14
  54. package/dist/typecheck-route.d.ts +28 -0
  55. package/dist/typecheck-route.d.ts.map +1 -0
  56. package/dist/typecheck-route.js +109 -0
  57. package/dist/workspace-manifest.d.ts +50 -5
  58. package/dist/workspace-manifest.d.ts.map +1 -1
  59. package/executors.json +10 -0
  60. package/managed/raw/patches/ttsc@0.34.1.patch +93 -8
  61. package/managed/raw/tooling/direnv/apple-developer.sh +8 -1
  62. package/managed/raw/tooling/direnv/compiler-variables.sh +1 -1
  63. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +4 -2
  64. package/managed/raw/tooling/direnv/secret-references.ts +19 -5
  65. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -10
  66. package/managed/templates/github/actions/forgejo-artifact.cjs +9 -9
  67. package/managed/templates/github/actions/setup-devenv/action.yml +53 -0
  68. package/package.json +2 -2
  69. package/src/built-output-packages.ts +125 -0
  70. package/src/cross-check-policy.ts +14 -1
  71. package/src/executors/bounded-exec/admission-queue.ts +163 -0
  72. package/src/executors/bounded-exec/cpu-grant.ts +32 -0
  73. package/src/executors/bounded-exec/cpu-pool.ts +2 -33
  74. package/src/executors/bounded-exec/executor.ts +60 -201
  75. package/src/executors/bounded-exec/memory-retry.ts +63 -0
  76. package/src/executors/bounded-exec/parent-grant.ts +75 -0
  77. package/src/executors/bounded-exec/peak-charge.ts +25 -0
  78. package/src/executors/bounded-exec/pool-environment.ts +45 -0
  79. package/src/executors/bounded-exec/run-cpu-pool.ts +2 -1
  80. package/src/executors/bounded-exec/verdict.ts +7 -35
  81. package/src/index.ts +70 -21
  82. package/src/managed-files/ci-workflow.ts +143 -16
  83. package/src/managed-files/context.ts +1 -0
  84. package/src/managed-files/files.ts +5 -0
  85. package/src/managed-files/publish-workflow.ts +26 -10
  86. package/src/owned-installation.ts +63 -14
  87. package/src/typecheck-route.ts +64 -0
  88. package/src/workspace-manifest.ts +56 -5
  89. package/test-timings.json +141 -139
@@ -93,10 +93,19 @@ index 3793b3a406c2bf2643567a755d34e66a26eac5c8..3c690ac3d9a99be7914ad9aed76e5890
93
93
 
94
94
  // writePluginEmitOutput writes one artifact of the hand-assembled emit, passing
95
95
  diff --git a/driver/plugins.go b/driver/plugins.go
96
- index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119bae676c4a 100644
96
+ index 1778e250d80d1316e108f1f36b6e1a38724922d5..2964783d058000080d987044e1fe1db581bde3d2 100644
97
97
  --- a/driver/plugins.go
98
98
  +++ b/driver/plugins.go
99
- @@ -169,6 +169,7 @@ type PluginContext struct {
99
+ @@ -8,6 +8,8 @@ import (
100
+ "sort"
101
+ "strings"
102
+ "sync"
103
+ +
104
+ + "github.com/microsoft/typescript-go/shim/ast"
105
+ )
106
+
107
+ // LinkedPluginsEnv is the environment variable ttsc sets to pass the JSON
108
+ @@ -169,6 +171,7 @@ type PluginContext struct {
100
109
  reportFileDependencyRejected func(string)
101
110
  reportFileComplete func(string)
102
111
  reportEveryFileComplete func()
@@ -104,7 +113,7 @@ index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119b
104
113
  }
105
114
 
106
115
  // ReportObservationIncomplete declares that this hook's input population could
107
- @@ -195,6 +196,24 @@ func (ctx PluginContext) ReportObservationIncomplete() {
116
+ @@ -195,6 +198,24 @@ func (ctx PluginContext) ReportObservationIncomplete() {
108
117
  }
109
118
  }
110
119
 
@@ -129,7 +138,29 @@ index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119b
129
138
  // ReportHostInputHash declares the exact file state consumed by a native
130
139
  // plugin. hash is a lowercase SHA-256 digest for an observed file and nil for
131
140
  // a missing candidate. Conflicting observations are retained as host inputs
132
- @@ -511,6 +530,7 @@ type linkedPluginState struct {
141
+ @@ -506,11 +527,29 @@ type EmitTransformPlugin interface {
142
+ EmitTransform(PluginContext) (PluginTransform, error)
143
+ }
144
+
145
+ +// DiagnosticPlugin is a linked plugin whose ProgramPlugin lowers a construct
146
+ +// the stock checker refuses, a dialect its compiles admit: a source spelling
147
+ +// the plugin rewrites before emit or a transform's output, which TypeScript has
148
+ +// no grammar for. The checker judges the parse tree before any ProgramPlugin
149
+ +// applies, so its refusal of such a construct names nothing the output holds,
150
+ +// and every lane that gates on the program's diagnostics (check, emit, a
151
+ +// transform) would refuse the dialect it was built to compile.
152
+ +// LoweredDiagnostics names those refusals among the diagnostics it is given;
153
+ +// the driver drops exactly the ones it names that it gave, and reports every
154
+ +// other diagnostic as it would without the plugin.
155
+ +type DiagnosticPlugin interface {
156
+ + // LoweredDiagnostics returns the diagnostics, among those given, whose cause
157
+ + // this plugin's ProgramPlugin removes. It reads the parse tree the checker
158
+ + // judged, before any ProgramPlugin applies.
159
+ + LoweredDiagnostics(*Program, PluginContext, []*ast.Diagnostic) []*ast.Diagnostic
160
+ +}
161
+ +
162
+ type linkedPluginState struct {
163
+ cwd string
133
164
  declarations *pluginFileDeclarations
134
165
  entries []PluginEntry
135
166
  inputs *pluginHostInputScopes
@@ -137,7 +168,7 @@ index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119b
137
168
  tsconfig string
138
169
  }
139
170
 
140
- @@ -800,6 +820,7 @@ func loadLinkedPluginState(cwd, tsconfigPath string) (linkedPluginState, error)
171
+ @@ -800,6 +839,7 @@ func loadLinkedPluginState(cwd, tsconfigPath string) (linkedPluginState, error)
141
172
  cwd: cwd,
142
173
  declarations: newPluginFileDeclarations(),
143
174
  inputs: newPluginHostInputScopes(),
@@ -145,7 +176,7 @@ index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119b
145
176
  tsconfig: tsconfigPath,
146
177
  }, nil
147
178
  }
148
- @@ -812,6 +833,7 @@ func loadLinkedPluginState(cwd, tsconfigPath string) (linkedPluginState, error)
179
+ @@ -812,6 +852,7 @@ func loadLinkedPluginState(cwd, tsconfigPath string) (linkedPluginState, error)
149
180
  declarations: newPluginFileDeclarations(),
150
181
  entries: entries,
151
182
  inputs: newPluginHostInputScopes(),
@@ -153,7 +184,50 @@ index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119b
153
184
  tsconfig: tsconfigPath,
154
185
  }, nil
155
186
  }
156
- @@ -931,7 +953,43 @@ func (state linkedPluginState) contextAt(index int, entry PluginEntry) PluginCon
187
+ @@ -896,6 +937,42 @@ func (state linkedPluginState) emitTransforms() ([]PluginTransform, error) {
188
+ return out, nil
189
+ }
190
+
191
+ +// dropLoweredDiagnostics removes from in every diagnostic a registered
192
+ +// DiagnosticPlugin names as lowered. Each plugin is asked, in registration
193
+ +// order, about what the plugins before it kept; a diagnostic it names that it
194
+ +// was not given is ignored, so a plugin can only withdraw a diagnostic, never
195
+ +// add one. An entry with no registration is skipped here: apply reports it.
196
+ +func (state linkedPluginState) dropLoweredDiagnostics(prog *Program, in []*ast.Diagnostic) []*ast.Diagnostic {
197
+ + for index, entry := range state.entries {
198
+ + if len(in) == 0 {
199
+ + return in
200
+ + }
201
+ + plugin, ok := registeredPlugin(index)
202
+ + if !ok {
203
+ + continue
204
+ + }
205
+ + judge, ok := plugin.(DiagnosticPlugin)
206
+ + if !ok {
207
+ + continue
208
+ + }
209
+ + lowered := map[*ast.Diagnostic]struct{}{}
210
+ + for _, diagnostic := range judge.LoweredDiagnostics(prog, state.contextAt(index, entry), in) {
211
+ + lowered[diagnostic] = struct{}{}
212
+ + }
213
+ + if len(lowered) == 0 {
214
+ + continue
215
+ + }
216
+ + kept := make([]*ast.Diagnostic, 0, len(in))
217
+ + for _, diagnostic := range in {
218
+ + if _, drop := lowered[diagnostic]; !drop {
219
+ + kept = append(kept, diagnostic)
220
+ + }
221
+ + }
222
+ + in = kept
223
+ + }
224
+ + return in
225
+ +}
226
+ +
227
+ // registeredPlugin returns the plugin registered at position index, or
228
+ // (nil, false) when the index is out of range. Registration order matches
229
+ // the order of linked Go init() calls.
230
+ @@ -931,7 +1008,43 @@ func (state linkedPluginState) contextAt(index int, entry PluginEntry) PluginCon
157
231
  reportFileDependencyRejected: declaration.rejectDependency,
158
232
  reportFileComplete: declaration.addComplete,
159
233
  reportEveryFileComplete: declaration.completeEveryFile,
@@ -198,7 +272,7 @@ index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119b
198
272
 
199
273
  // hostInputs returns the exact native configuration inputs reported in this
200
274
  diff --git a/driver/program.go b/driver/program.go
201
- index f6ee81fb1af41deea022b92e838a7c4665eb9778..112faf913ce38b1f4624b38db37839370b9c5e8b 100644
275
+ index f6ee81fb1af41deea022b92e838a7c4665eb9778..6dc6b4d77b7cde5051782478cdc527a1e9c29c7f 100644
202
276
  --- a/driver/program.go
203
277
  +++ b/driver/program.go
204
278
  @@ -738,6 +738,12 @@ func forceEmit(parsed *tsoptions.ParsedCommandLine) {
@@ -214,6 +288,17 @@ index f6ee81fb1af41deea022b92e838a7c4665eb9778..112faf913ce38b1f4624b38db3783937
214
288
  }
215
289
 
216
290
  // forceNoEmit sets noEmit so the program type-checks without writing files.
291
+ @@ -1124,6 +1130,10 @@ func (p *Program) diagnostics(files []*ast.SourceFile) []Diagnostic {
292
+ }
293
+ }
294
+ raw = filterDiagnostics(raw)
295
+ + // A linked DiagnosticPlugin withdraws the checker's refusals of the dialect
296
+ + // its ProgramPlugin lowers. It asks about the tree the checker judged, which
297
+ + // the hooks have not mutated yet on every lane that gates on diagnostics.
298
+ + raw = p.plugins.dropLoweredDiagnostics(p, raw)
299
+ // filterDiagnostics runs first because it resolves a node from the position
300
+ // tsgo recorded, which only makes sense against the tree tsgo parsed. The
301
+ // preamble correction happens inside convertProgramDiagnostics, once the
217
302
  diff --git a/driver/rewrite.go b/driver/rewrite.go
218
303
  index 79be74d24e879da216ad680d23ecfeb5f11a29db..6db9dddba05bd50e13ed92535ca442c3a4f0b28a 100644
219
304
  --- a/driver/rewrite.go
@@ -16,6 +16,13 @@
16
16
  # xcodebuild reads, which is why they go rather than being pointed somewhere
17
17
  # else.
18
18
  #
19
+ # AR/RANLIB go with them. An outer stdenv exports AR=ar and RANLIB=ranlib,
20
+ # which resolve on PATH into the store; cc-rs runs them for every build script
21
+ # and the cargo targets key on their store objects (nx-plugin's cargo toolchain
22
+ # input). A shell that kept them keyed every cargo task differently from the
23
+ # land gate, whose cleared environment never had them, and missed the gate's
24
+ # cache entries for the same tree.
25
+ #
19
26
  # The Apple SDK is the same boundary, and dropping CC/CXX alone does not hold
20
27
  # it. An outer nix stdenv exports SDKROOT and DEVELOPER_DIR pointing at
21
28
  # nixpkgs' RECONSTRUCTED apple-sdk, so Xcode's own clang goes on to compile
@@ -49,7 +56,7 @@
49
56
  # so under direnv the dropped directory comes back behind /usr/bin, where its
50
57
  # xcrun is never the one that answers.
51
58
  smoo_apple_store="$1"
52
- unset CC CXX
59
+ unset CC CXX AR RANLIB
53
60
  case "${SDKROOT:-}" in
54
61
  "$smoo_apple_store"/*)
55
62
  echo "devenv: dropping nix-store SDKROOT ($SDKROOT); Xcode holds the licensed macOS SDK" >&2
@@ -20,7 +20,7 @@
20
20
  # direnv sources after this shell.
21
21
  #
22
22
  # The generic tool names stay where they are: on Linux the stdenv sets CC, CXX,
23
- # AR and RANLIB, and on Darwin apple-developer.sh drops CC and CXX.
23
+ # AR and RANLIB, and on Darwin apple-developer.sh drops CC, CXX, AR and RANLIB.
24
24
  smoo_compiler_declared=" $* "
25
25
  for smoo_compiler_name in ${!CC_@} ${!CXX_@} ${!AR_@} ${!RANLIB_@} ${!CFLAGS@} ${!CXXFLAGS@} ${!ARFLAGS@} ${!RANLIBFLAGS@} ${!HOST_@} ${!TARGET_@}; do
26
26
  # A target names a lowercase architecture; CC_ENABLE_DEBUG_OUTPUT and its
@@ -17,8 +17,10 @@ ttsc_cache_dir_default="${TTSC_CACHE_DIR:-$repo_root/.cache/ttsc-plugins}"
17
17
  # locked to, so this installs the commit devenv.lock's `devenv` node names and
18
18
  # nothing here restates it. `smoo monorepo check` holds that node to a release:
19
19
  # it must name its remote and a commit that one of that remote's tags from
20
- # v2.0.4 on names, which `git ls-remote` answers on every run. devenv.yaml
21
- # declares such a lock as `github:cachix/devenv/v2.3.1?dir=src/modules`.
20
+ # v2.0.4 on names. `git ls-remote` answers that once per locked commit, when
21
+ # `smoo devenv update` or `smoo monorepo update` writes the answer to
22
+ # tooling/direnv/devenv-release.json; `check` only verifies that record, offline.
23
+ # devenv.yaml declares such a lock as `github:cachix/devenv/v2.3.1?dir=src/modules`.
22
24
  # devenv.cachix.org has pinned the aarch64-darwin, aarch64-linux and
23
25
  # x86_64-linux builds of every release from v2.0.4 on for good, so on those
24
26
  # three systems the install substitutes rather than compiles. From v2.2 on
@@ -290,10 +290,12 @@ function parseSecretSpec(name: string, spec: unknown): SecretSpec {
290
290
  * The declared remote cache as a local shell needs it. `internalServer` is
291
291
  * deliberately absent: it is the address a managed runner reaches inside its
292
292
  * own network, and a shell that loads this file is by definition outside it,
293
- * so a developer machine always takes the public `server`.
293
+ * so a developer machine always takes the public origin: `server`, or the
294
+ * value of the variable `serverVariable` names, which a public repository
295
+ * declares so its cache address is never committed.
294
296
  */
295
297
  export interface RemoteCacheSpec {
296
- readonly server: string;
298
+ readonly origin: { readonly server: string } | { readonly serverVariable: string };
297
299
  /** Variable holding the cache token: an ambient value, or a `smoo.secrets` entry in group `nx-cache`. */
298
300
  readonly tokenSecret: string;
299
301
  }
@@ -310,23 +312,35 @@ export function parseSmooRemoteCache(packageJson: unknown): RemoteCacheSpec | nu
310
312
  const remoteCache = smoo.remoteCache;
311
313
  if (remoteCache === undefined) return null;
312
314
  if (!isRecord(remoteCache)) {
313
- throw new Error('smoo.remoteCache must be an object with { server, tokenSecret }');
315
+ throw new Error('smoo.remoteCache must be an object with { server or serverVariable, tokenSecret }');
314
316
  }
315
317
  const server = remoteCache.server;
318
+ const serverVariable = remoteCache.serverVariable;
316
319
  const tokenSecret = remoteCache.tokenSecret;
320
+ if (server !== undefined && serverVariable !== undefined) {
321
+ throw new Error('smoo.remoteCache names its public origin twice; declare server or serverVariable, not both');
322
+ }
317
323
  // A trailing slash is refused rather than trimmed: Nx appends
318
324
  // `/v1/cache/<hash>`, so the doubled slash is a route that answers 404
319
325
  // forever, and silently repairing the manifest here would leave managed CI
320
326
  // — which reads the same field — disagreeing with this shell.
321
- if (typeof server !== 'string' || server.length === 0 || server.endsWith('/')) {
327
+ let origin: RemoteCacheSpec['origin'];
328
+ if (serverVariable !== undefined) {
329
+ if (typeof serverVariable !== 'string' || !ENV_NAME.test(serverVariable)) {
330
+ throw new Error('smoo.remoteCache.serverVariable must name the variable holding the public origin');
331
+ }
332
+ origin = { serverVariable };
333
+ } else if (typeof server !== 'string' || server.length === 0 || server.endsWith('/')) {
322
334
  throw new Error(
323
335
  'smoo.remoteCache.server must be an origin with no trailing slash, e.g. https://nx-cache.example.net',
324
336
  );
337
+ } else {
338
+ origin = { server };
325
339
  }
326
340
  if (typeof tokenSecret !== 'string' || !ENV_NAME.test(tokenSecret)) {
327
341
  throw new Error('smoo.remoteCache.tokenSecret must name the environment variable holding the cache token');
328
342
  }
329
- return { server, tokenSecret };
343
+ return { origin, tokenSecret };
330
344
  }
331
345
 
332
346
  /** Every `${VAR}` referenced from `.npmrc` text; an absent file contributes nothing. */
@@ -17,15 +17,21 @@
17
17
  # ran, builds them. A refusal names the one command that fixes it; any other
18
18
  # failure is said as that, never as a cache miss.
19
19
  #
20
- # Nx runs in this checkout's environment, `direnv exec <checkout>`, which is the
21
- # environment the land gate runs in, never in the environment of whatever shell
22
- # ran `git push`. devenv declares this checkout's tooling and the environment it
23
- # builds with (the macOS SDK it links against among it), and tasks key on that
24
- # environment as well as on the tree: a push from a shell carrying another
25
- # directory's devenv keyed the gate's tasks on that shell's SDKROOT and
26
- # DEVELOPER_DIR, missed every one of them, and then built them against the wrong
27
- # SDK. Under the checkout's environment the keys are the gate's, and a dependency
28
- # that does miss builds the way the gate builds it.
20
+ # Nx runs in the environment the land gate runs in, never in the environment of
21
+ # whatever shell ran `git push`: cowshed clears a declared command's environment,
22
+ # keeping HOME, USER, LOGNAME, TERM, LANG and SSH_AUTH_SOCK and a PATH, and enters
23
+ # the checkout's devenv over it (specs/cowshed/02_workspaces.md, "The declared
24
+ # commands' environment"). The probe does the same: `env -i` with those
25
+ # variables and repo-path's PATH, then `direnv exec <checkout>`. devenv declares
26
+ # this checkout's tooling and the environment it builds with, and tasks key on
27
+ # that environment as well as on the tree. `direnv exec` alone only lays the
28
+ # checkout's variables over the caller's: a variable the checkout does not
29
+ # declare passes through. A push from a shell carrying another directory's
30
+ # devenv keyed the gate's tasks on that shell's SDKROOT and DEVELOPER_DIR; one
31
+ # from an agent shell carrying AR=ar and RANLIB=ranlib keyed every cargo task's
32
+ # toolchain input on them, so the probe missed the entry the gate wrote for the
33
+ # same tree. Under the gate's environment the keys are the gate's, and a
34
+ # dependency that does miss builds the way the gate builds it.
29
35
  #
30
36
  # Why the cross target never compiles here. Every checkout shell carries zig,
31
37
  # cargo-zigbuild and the Linux rust-std the cross clippy needs, so a miss would
@@ -95,7 +101,11 @@ cross_gate() {
95
101
  output=$(mktemp "${TMPDIR:-/tmp}/pre-push-cross.XXXXXX") || return 1
96
102
  trap 'rm -f "$output"' EXIT
97
103
  set -o pipefail
98
- SMOO_CROSS_LINT_REPLAY_ONLY=1 direnv exec "$PWD" nx run-many -t cargo-lint-cross --output-style=static 2>&1 | tee "$output"
104
+ pure=(PATH="$PATH" SMOO_CROSS_LINT_REPLAY_ONLY=1)
105
+ for name in HOME USER LOGNAME TERM LANG SSH_AUTH_SOCK; do
106
+ [ -z "${!name+set}" ] || pure+=("$name=${!name}")
107
+ done
108
+ env -i "${pure[@]}" direnv exec "$PWD" nx run-many -t cargo-lint-cross --output-style=static 2>&1 | tee "$output"
99
109
  status=$?
100
110
  [ "$status" -eq 0 ] && return 0
101
111
 
@@ -17,13 +17,13 @@ const { join } = require('node:path');
17
17
  const GIT_ENVIRONMENT_THAT_REDIRECTS_THE_REPOSITORY = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE'];
18
18
 
19
19
  function fail(message, status = 1) {
20
- process.stderr.write('forgejo-artifact: ' + message + '\n');
20
+ process.stderr.write(`forgejo-artifact: ${message}\n`);
21
21
  process.exitCode = status;
22
22
  }
23
23
  function describeExit(result) {
24
- if (result.error) return 'could not start: ' + result.error.message;
25
- if (result.signal) return 'was killed by signal ' + result.signal;
26
- return 'exited with status ' + result.status;
24
+ if (result.error) return `could not start: ${result.error.message}`;
25
+ if (result.signal) return `was killed by signal ${result.signal}`;
26
+ return `exited with status ${result.status}`;
27
27
  }
28
28
 
29
29
  function gitEnvironment() {
@@ -40,7 +40,7 @@ function git(directory, args, captureStdout = false) {
40
40
  stdio: ['ignore', captureStdout ? 'pipe' : 'inherit', 'inherit'],
41
41
  });
42
42
  if (result.error || result.status !== 0) {
43
- fail('git ' + args.join(' ') + ' ' + describeExit(result));
43
+ fail(`git ${args.join(' ')} ${describeExit(result)}`);
44
44
  return null;
45
45
  }
46
46
  return captureStdout ? result.stdout : '';
@@ -58,7 +58,7 @@ function checkout(directory, pin) {
58
58
  if (revision === null) return false;
59
59
  const head = revision.trim();
60
60
  if (head !== pin.commit) {
61
- fail('checked out HEAD ' + head + ' is not the pinned commit ' + pin.commit);
61
+ fail(`checked out HEAD ${head} is not the pinned commit ${pin.commit}`);
62
62
  return false;
63
63
  }
64
64
  return true;
@@ -69,7 +69,7 @@ function run(pin) {
69
69
  process.exitCode = 0;
70
70
  const runnerTemp = process.env.RUNNER_TEMP;
71
71
  if (!runnerTemp) {
72
- fail('RUNNER_TEMP is not set, so there is nowhere private to fetch ' + pin.repository);
72
+ fail(`RUNNER_TEMP is not set, so there is nowhere private to fetch ${pin.repository}`);
73
73
  return;
74
74
  }
75
75
  let directory;
@@ -79,7 +79,7 @@ function run(pin) {
79
79
  const result = spawnSync(process.execPath, [join(directory, pin.entry)], { stdio: 'inherit' });
80
80
  if (result.error || result.status !== 0) {
81
81
  fail(
82
- pin.repository + '@' + pin.commit + ' ' + pin.entry + ' ' + describeExit(result),
82
+ `${pin.repository}@${pin.commit} ${pin.entry} ${describeExit(result)}`,
83
83
  result.error || result.status === null ? 1 : result.status,
84
84
  );
85
85
  }
@@ -90,7 +90,7 @@ function run(pin) {
90
90
  try {
91
91
  rmSync(directory, { recursive: true, force: true });
92
92
  } catch (error) {
93
- fail('could not remove ' + directory + ': ' + String(error), process.exitCode || 1);
93
+ fail(`could not remove ${directory}: ${String(error)}`, process.exitCode || 1);
94
94
  }
95
95
  }
96
96
  }
@@ -235,6 +235,34 @@ runs:
235
235
  echo "devenv state: $root (workspace at $GITHUB_WORKSPACE)"
236
236
  fi
237
237
 
238
+ # Host runners keep the Cargo target directory on the shared bind as well, so a job reuses every unit its scope's
239
+ # last job compiled instead of building the dependency graph again. The scope is the Nx cache's (workflow, pull
240
+ # request or ref, job, platform): a publish and a CI run never share a mutable target, and two runs of one scope
241
+ # that overlap take turns on Cargo's own build-directory lock. The bind lands on the workspace path tasks see
242
+ # (DEVENV_WORKDIR, set above), not the checkout under it: a bind of the checkout carries no submount, so a target
243
+ # bound beneath it would be invisible at the stable path. A fresh checkout gives every source a new mtime, which
244
+ # Cargo's mtime freshness reads as changed, so a reused target is judged by file checksums instead
245
+ # (CARGO_UNSTABLE_CHECKSUM_FRESHNESS, a nightly key the managed toolchain carries). A refused bind leaves the job
246
+ # its checkout's own target/, built cold.
247
+ - name: 📂 Locate the Cargo target on the shared bind
248
+ if: steps.runner-kind.outputs.host == 'true' && hashFiles('Cargo.lock') != ''
249
+ shell: bash
250
+ env:
251
+ CARGO_TARGET_BIND: /var/cache/ci/cargo-target
252
+ CARGO_TARGET_REPO: ${{ github.repository }}
253
+ CARGO_TARGET_LANE: ${{ github.workflow }}
254
+ SCOPE_REF: ${{ github.event.pull_request.number || github.ref }}
255
+ run: |
256
+ lane=$(printf '%s' "$CARGO_TARGET_LANE" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-')
257
+ scope=$(printf '%s\0%s\0%s\0%s\0%s' "$GITHUB_WORKFLOW" "$SCOPE_REF" "$GITHUB_JOB" "$RUNNER_OS" "$RUNNER_ARCH" | git hash-object --stdin)
258
+ root="$CARGO_TARGET_BIND/$CARGO_TARGET_REPO/${lane:-default}/$scope"
259
+ target="$DEVENV_WORKDIR/target"
260
+ if mkdir -p "$root" "$target" && sudo mount --bind "$root" "$target"; then
261
+ echo "CARGO_UNSTABLE_CHECKSUM_FRESHNESS=true" >> "$GITHUB_ENV"
262
+ echo "cargo target: $root (bound at $target)"
263
+ else
264
+ echo "::warning::cargo target bind refused; this job builds $target from cold"
265
+ fi
238
266
  - name: 📂 Devenv runs in the checkout
239
267
  if: steps.runner-kind.outputs.host != 'true'
240
268
  shell: bash
@@ -412,3 +440,28 @@ runs:
412
440
  env:
413
441
  SMOO_ROOT_BUILD_INPUTS: ${{ steps.runner-kind.outputs.host != 'true' }}
414
442
  run: ./github-actions-bootstrap.sh build-shell
443
+
444
+ # smoo.mbxRemote: the job env names the mbx remote cache, and Cargo reaches it only through mbx's Cargo shim, so the
445
+ # shim goes first on PATH for every later step. mbx setup runs under a scratch HOME, where Linux's XDG_DATA_HOME and
446
+ # macOS's Application Support name the same directory, so it writes none of the runner's editor or mise
447
+ # configuration and the shim's path is known rather than parsed from its output. The shim records the shell's mbx.
448
+ - name: 🦀 Route Cargo through mbx
449
+ if: env.MBX_REMOTE_URL != '' && hashFiles('Cargo.lock') != ''
450
+ shell: bash
451
+ run: |
452
+ if ! mbx=$(command -v mbx); then
453
+ echo "::error::smoo.mbxRemote is declared but the devenv shell provides no mbx; add mbx to tooling/direnv/devenv.nix"
454
+ exit 1
455
+ fi
456
+ home="$RUNNER_TEMP/mbx-setup"
457
+ data="$home/Library/Application Support"
458
+ mkdir -p "$data"
459
+ HOME="$home" XDG_DATA_HOME="$data" XDG_CONFIG_HOME="$home/config" XDG_CACHE_HOME="$home/cache" \
460
+ MBX_CACHE_DIR="$home/cache/mbx" "$mbx" setup --yes
461
+ shim="$data/mbx/bin"
462
+ if [ ! -x "$shim/cargo" ]; then
463
+ echo "::error::$mbx setup --yes wrote no Cargo shim at $shim/cargo"
464
+ exit 1
465
+ fi
466
+ echo "$shim" >> "$GITHUB_PATH"
467
+ echo "Cargo runs through mbx ($mbx), remote $MBX_REMOTE_URL, namespace $MBX_REMOTE_NAMESPACE"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.7.12",
3
+ "version": "0.7.13",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -656,7 +656,7 @@
656
656
  "@nx/js": "24.0.3",
657
657
  "@smoothbricks/build-inputs": "0.0.3",
658
658
  "@smoothbricks/cargo-retain": "0.0.2",
659
- "@smoothbricks/cowshed": "0.4.8",
659
+ "@smoothbricks/cowshed": "0.4.9",
660
660
  "@smoothbricks/nextest-extract": "0.0.2",
661
661
  "jsonc-parser": "^3.3.1",
662
662
  "minimatch": "10.2.5",
@@ -0,0 +1,125 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import type {
5
+ CreateDependenciesContext,
6
+ CreateNodesContextV2,
7
+ ProjectGraphExternalNode,
8
+ RawProjectGraphDependency,
9
+ } from 'nx/src/devkit-exports.js';
10
+ import { hashArray } from 'nx/src/hasher/file-hasher.js';
11
+ import { readBunLockFile } from 'nx/src/plugins/js/lock-file/bun-parser.js';
12
+ import { getLockFileDependencies, getLockFileName, getLockFileNodes } from 'nx/src/plugins/js/lock-file/lock-file.js';
13
+ import { jsPluginConfig } from 'nx/src/plugins/js/utils/config.js';
14
+ import { detectPackageManager, type PackageManager } from 'nx/src/utils/package-manager.js';
15
+ import { nxVersion } from 'nx/src/utils/versions.js';
16
+
17
+ import { isRecord } from './type-guards.js';
18
+
19
+ /**
20
+ * Built-output packages: lockfile package nodes that carry no version identity for the packages a workspace keys by
21
+ * what its tasks run.
22
+ *
23
+ * Nx keys a task on an npm package through the package's external node, hashing the integrity the lockfile records for
24
+ * it (`hash_external`). A `^` input adds the node of every package a dependency project declares or imports, from any
25
+ * of its files, so a version bump of one package re-keys every task whose dependency closure reaches an importer of it.
26
+ * That is wrong for a package the workspace already keys by its bytes where a task runs them, as a consumer keys the Nx
27
+ * plugin per executor and module closure. The plugin's `builtOutputPackages` option names such packages.
28
+ *
29
+ * The workspace turns Nx's own lockfile analysis off (`pluginsConfig["@nx/js"].analyzeLockfile: false`): Nx merges its
30
+ * default plugin's nodes after every configured plugin's, so they would replace these. This plugin then publishes the
31
+ * nodes and package edges Nx's own parser makes (`getLockFileNodes`, `getLockFileDependencies`), every node of a named
32
+ * package with a `data.hash` that names the package alone. Only that hash differs from Nx's graph: names, versions and
33
+ * edges stay, so a task that reaches a named package still keys each of its dependencies by its own integrity.
34
+ */
35
+
36
+ /** The `data.hash` of a named package's nodes: the package's name, the one identity Nx's graph keys it by. */
37
+ export function builtOutputHash(packageName: string): string {
38
+ return `built-output:${packageName}`;
39
+ }
40
+
41
+ /** One read of the lockfile and Nx's parse of it. */
42
+ interface LockfileRead {
43
+ readonly packageManager: PackageManager;
44
+ readonly lockFile: string;
45
+ readonly contents: string;
46
+ readonly hash: string;
47
+ readonly nodes: Record<string, ProjectGraphExternalNode>;
48
+ readonly keyMap: Map<string, unknown>;
49
+ }
50
+
51
+ /**
52
+ * The read whose nodes createNodes published last. An install can rewrite the lockfile between the two hooks, so
53
+ * createDependencies links the nodes the graph holds, as Nx's own lockfile plugin does.
54
+ */
55
+ let published: LockfileRead | undefined;
56
+
57
+ /** The packages the option names, or null when it names none. */
58
+ function namedPackages(options: unknown): ReadonlySet<string> | null {
59
+ if (!isRecord(options) || options.builtOutputPackages === undefined) return null;
60
+ const names: unknown = options.builtOutputPackages;
61
+ if (!Array.isArray(names) || !names.every((name): name is string => typeof name === 'string' && name.length > 0)) {
62
+ throw new Error('builtOutputPackages must be a list of package names');
63
+ }
64
+ return names.length === 0 ? null : new Set(names);
65
+ }
66
+
67
+ /** The workspace's lockfile, as Nx's own lockfile plugin reads it, and Nx's parse of it. */
68
+ function readLockfile(context: CreateNodesContextV2): LockfileRead {
69
+ const packageManager = detectPackageManager(context.workspaceRoot);
70
+ const lockFile = getLockFileName(packageManager);
71
+ const path = join(context.workspaceRoot, lockFile);
72
+ if (!existsSync(path)) throw new Error(`builtOutputPackages names packages, but ${path} does not exist`);
73
+ const contents = packageManager === 'bun' ? readBunLockFile(path) : readFileSync(path, 'utf-8');
74
+ const hash = hashArray([nxVersion, contents]);
75
+ if (published?.hash === hash) return published;
76
+ const { nodes, keyMap } = getLockFileNodes(packageManager, lockFile, contents, hash, context);
77
+ return { packageManager, lockFile, contents, hash, nodes, keyMap };
78
+ }
79
+
80
+ /**
81
+ * The lockfile's package nodes, each of a named package hashed by {@link builtOutputHash}; none when the option names
82
+ * no package. Refuses while Nx's own nodes would replace them, and for a named package the lockfile installs nowhere.
83
+ */
84
+ export function builtOutputLockfileNodes(
85
+ options: unknown,
86
+ context: CreateNodesContextV2,
87
+ ): Record<string, ProjectGraphExternalNode> {
88
+ const packages = namedPackages(options);
89
+ if (packages === null) return {};
90
+ if (jsPluginConfig(context.nxJsonConfiguration).analyzeLockfile) {
91
+ throw new Error(
92
+ `builtOutputPackages (${[...packages].join(', ')}) needs nx.json pluginsConfig["@nx/js"].analyzeLockfile ` +
93
+ "set to false: Nx merges its own lockfile nodes after this plugin's, and they would key each of these " +
94
+ 'packages by its version',
95
+ );
96
+ }
97
+ const read = readLockfile(context);
98
+ published = read;
99
+ const nodes: Record<string, ProjectGraphExternalNode> = {};
100
+ const found = new Set<string>();
101
+ for (const [name, node] of Object.entries(read.nodes)) {
102
+ const packageName = node.data.packageName;
103
+ if (!packages.has(packageName)) {
104
+ nodes[name] = node;
105
+ continue;
106
+ }
107
+ found.add(packageName);
108
+ nodes[name] = { ...node, data: { ...node.data, hash: builtOutputHash(packageName) } };
109
+ }
110
+ const absent = [...packages].filter((name) => !found.has(name));
111
+ if (absent.length > 0) {
112
+ throw new Error(`builtOutputPackages names ${absent.join(', ')}, which ${read.lockFile} installs nowhere`);
113
+ }
114
+ return nodes;
115
+ }
116
+
117
+ /** The package edges Nx's parser reads from the lockfile whose nodes the graph holds; none when no package is named. */
118
+ export function builtOutputLockfileDependencies(
119
+ options: unknown,
120
+ context: CreateDependenciesContext,
121
+ ): RawProjectGraphDependency[] {
122
+ if (namedPackages(options) === null) return [];
123
+ const read = published ?? readLockfile(context);
124
+ return getLockFileDependencies(read.packageManager, read.lockFile, read.contents, read.hash, context, read.keyMap);
125
+ }
@@ -191,17 +191,30 @@ export const CARGO_LINT_CLIPPY_COMMAND = cargoFrozen(
191
191
  /** Root `package.json` script name, in the repo's `verb:qualifier` style. */
192
192
  export const CROSS_CHECK_SCRIPT_NAME = 'check:linux';
193
193
 
194
+ /**
195
+ * The caller variables a declared command keeps: cowshed clears the environment of every command a land runs, its
196
+ * gate and its push among them, and passes these on when the caller has them, with a `PATH`
197
+ * (specs/cowshed/02_workspaces.md, "The declared commands' environment"). The managed pre-push hook spells the same
198
+ * list in shell, and a test holds the two equal.
199
+ */
200
+ export const DECLARED_COMMAND_IDENTITY = ['HOME', 'USER', 'LOGNAME', 'TERM', 'LANG', 'SSH_AUTH_SOCK'] as const;
201
+
194
202
  /**
195
203
  * The developer entry point: one command on macOS that reports what CI's Linux
196
204
  * job would. A plain Nx run, because every managed devenv shell carries the
197
205
  * cross toolchain; the land gate's Nx graph holds the same target.
198
206
  *
207
+ * It runs from the environment the land gate and the pre-push probe run in: the identity variables and `PATH` alone,
208
+ * with the checkout's devenv entered over them. Run in the caller's shell, it keyed every cargo task on whatever that
209
+ * shell carried and the checkout does not declare (an `AR=ar` from a parent directory's devenv moved the toolchain
210
+ * input), so its verdict was one the probe never asks for.
211
+ *
199
212
  * Deliberately NOT `--quiet`. The pre-push gate is a probe: it consults the Nx
200
213
  * cache and refuses a push that has no hit, never starting a compile of its own.
201
214
  * The clippy behind this script is unbounded, so a silent terminal is
202
215
  * indistinguishable from a hang.
203
216
  */
204
- export const CROSS_CHECK_SCRIPT_COMMAND = `nx run-many -t ${CARGO_CROSS_LINT_TARGET}`;
217
+ export const CROSS_CHECK_SCRIPT_COMMAND = `env -i ${DECLARED_COMMAND_IDENTITY.map((name) => `${name}="$${name}"`).join(' ')} PATH="$PATH" direnv exec "$PWD" nx run-many -t ${CARGO_CROSS_LINT_TARGET}`;
205
218
 
206
219
  /**
207
220
  * A cross-built test archive and the target that EXECUTES it, per foreign