@smoothbricks/nx-plugin 0.4.21 → 0.4.23

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 (64) hide show
  1. package/README.md +95 -18
  2. package/dist/bin/smoo-nx-cargo-hash.js +32 -6
  3. package/dist/bin/smoo-nx-exec.js +35 -11
  4. package/dist/cargo-closure-input.d.ts +63 -0
  5. package/dist/cargo-closure-input.d.ts.map +1 -0
  6. package/dist/cargo-closure-input.js +197 -0
  7. package/dist/cargo-source-hash.d.ts +46 -2
  8. package/dist/cargo-source-hash.d.ts.map +1 -1
  9. package/dist/cargo-source-hash.js +238 -114
  10. package/dist/cross-check-policy.d.ts +14 -0
  11. package/dist/cross-check-policy.d.ts.map +1 -1
  12. package/dist/cross-check-policy.js +15 -1
  13. package/dist/ensure-built.d.ts +3 -2
  14. package/dist/ensure-built.d.ts.map +1 -1
  15. package/dist/ensure-built.js +33 -56
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +112 -76
  18. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  19. package/dist/managed-files/ci-workflow.js +12 -15
  20. package/dist/managed-files/files.d.ts.map +1 -1
  21. package/dist/managed-files/files.js +10 -0
  22. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  23. package/dist/managed-files/publish-workflow.js +12 -6
  24. package/dist/manifest-hash.d.ts.map +1 -1
  25. package/dist/manifest-hash.js +24 -30
  26. package/dist/package-target-policy.js +1 -1
  27. package/dist/platform-targets.d.ts +7 -0
  28. package/dist/platform-targets.d.ts.map +1 -1
  29. package/dist/platform-targets.js +7 -0
  30. package/dist/workspace-config-policy.d.ts +1 -1
  31. package/dist/workspace-config-policy.d.ts.map +1 -1
  32. package/dist/workspace-config-policy.js +1 -1
  33. package/managed/raw/envrc +38 -1
  34. package/managed/raw/tooling/direnv/developer-links.ts +201 -0
  35. package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
  36. package/managed/raw/tooling/direnv/secret-references.ts +3 -1
  37. package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
  38. package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
  39. package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
  40. package/managed/templates/github/workflows/managed-files.yml +4 -3
  41. package/nextest.toml +5 -5
  42. package/package.json +2 -2
  43. package/src/__tests__/fixture-nx-env.ts +31 -0
  44. package/src/__tests__/in-process-nx-index.ts +9 -0
  45. package/src/bin/smoo-nx-cargo-hash.ts +29 -9
  46. package/src/bin/smoo-nx-exec.ts +40 -11
  47. package/src/cargo-closure-input.test.ts +184 -0
  48. package/src/cargo-closure-input.ts +247 -0
  49. package/src/cargo-source-hash.test.ts +104 -10
  50. package/src/cargo-source-hash.ts +290 -37
  51. package/src/cross-check-policy.ts +15 -3
  52. package/src/ensure-built.test.ts +65 -5
  53. package/src/ensure-built.ts +40 -85
  54. package/src/index.test.ts +94 -53
  55. package/src/index.ts +164 -84
  56. package/src/managed-files/ci-workflow.ts +12 -15
  57. package/src/managed-files/files.ts +10 -0
  58. package/src/managed-files/generator.test.ts +29 -0
  59. package/src/managed-files/publish-workflow.ts +17 -6
  60. package/src/manifest-hash.test.ts +21 -1
  61. package/src/manifest-hash.ts +26 -29
  62. package/src/package-target-policy.ts +1 -1
  63. package/src/platform-targets.ts +8 -0
  64. package/src/workspace-config-policy.ts +6 -1
@@ -13,6 +13,7 @@
13
13
  # Every explanation lives out here in Nix comments. Hook bodies are exported as
14
14
  # shell text, so a comment inside one becomes part of an environment variable.
15
15
  {
16
+ config,
16
17
  inputs,
17
18
  lib,
18
19
  pkgs,
@@ -29,12 +30,29 @@
29
30
  rev = "56ab4af42157";
30
31
  hash = "sha256-ebjX+1+9axEqsnZXCRZSumA38gPNdmoz98tMt2oftN4=";
31
32
  };
33
+
34
+ # A repository that enables uv under languages.python gets its uv workspace
35
+ # synced and activated by this contract (enterShell item 5), never by
36
+ # devenv's own python tasks.
37
+ python = config.languages.python;
38
+ uvProject = python.enable && python.uv.enable;
32
39
  in {
33
40
  env = lib.mkMerge [
34
41
  {
35
42
  # Nx otherwise defaults to three workers. Scale to the cores available in each
36
43
  # developer shell or CI runner; explicit --parallel flags still take precedence.
37
44
  NX_PARALLEL = "100%";
45
+ # Every Nx daemon, when it starts, installs nx@latest from the registry
46
+ # into a temporary directory to ask the newest release whether to prompt
47
+ # for Nx Console and whether AI agent configuration is outdated, and
48
+ # `nx configure-ai-agents` and `nx init` do the same. NX_USE_LOCAL answers
49
+ # from the installed nx, so starting Nx installs nothing from the registry.
50
+ # (A daemon still runs `git ls-remote` against GitHub's
51
+ # nrwl/nx-ai-agents-config when an agent has both rules and Nx's MCP
52
+ # configured; a cowshed sandbox runs Nx without a daemon.) It also makes
53
+ # `nx migrate` run with the installed CLI instead of the newest one;
54
+ # `NX_USE_LOCAL=false nx migrate` restores that for the one command.
55
+ NX_USE_LOCAL = "true";
38
56
  TTSC_TYPESCRIPT_GO_DIR = "${typescriptGo}";
39
57
  }
40
58
  # Playwright's downloaded Ubuntu browser has no runtime closure on NixOS
@@ -255,6 +273,16 @@ in {
255
273
  ]
256
274
  ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [pkgs.chromium];
257
275
 
276
+ # devenv wraps the Python interpreter to find native libraries in
277
+ # `languages.python.libraries`, whose default is this checkout's
278
+ # `.devenv/profile`. That path then lands in the interpreter's store path, the
279
+ # profile that holds it and the uv environment built with it, so every clone
280
+ # evaluates and builds its own interpreter and profile on first entry, and its
281
+ # copied uv environment names another checkout's interpreter. Cleared, the
282
+ # interpreter is one store path in every checkout. devenv still adds the C++
283
+ # runtime; a wheel that needs another library names that library here.
284
+ languages.python.libraries = lib.mkIf uvProject (lib.mkDefault []);
285
+
258
286
  enterShell = lib.mkMerge [
259
287
  # Prologue, in order:
260
288
  #
@@ -264,47 +292,35 @@ in {
264
292
  # use, so a hook and a shell resolve one binary the same way.
265
293
  # 3. ttsc drives the native TypeScript 7 binary while Nx imports the TypeScript
266
294
  # 6 API, so the two must be named separately.
267
- # 4. On a cowshed host, Go and ttsc caches point at the shared store, so every
268
- # workspace reads one warm cache instead of growing its own copy inside its
269
- # image. Without one, ttsc stays in-tree for the CI cache action while Go
270
- # keeps its normal per-user defaults. Both Go caches are content-addressed,
271
- # so sharing them needs no patch — unlike Rust, Go keys on content and flags
272
- # rather than on where the files live. An inherited value always wins so CI
273
- # can place any of these caches itself. GOFLAGS carries -trimpath because it
274
- # is Go's stable way to keep absolute build paths out of the artifact, and
275
- # unlike Rust's trim-paths it costs no cache reuse.
276
- #
277
- # ttsc's plugin builds use the Go it bundles rather than ours, so the
278
- # repository's own Go work and ttsc's plugin builds are two toolchains by
279
- # construction. Placing both caches in the shared store is what keeps that
280
- # from costing a rebuild per workspace.
295
+ # 4. Go and ttsc caches: tooling/direnv/shared-caches.sh places them under
296
+ # the machine's shared caches root when it exists and states why.
297
+ # 5. The shared setup-environment.ts bootstraps repository dependencies. It
298
+ # runs `bun install` — and, for a uv project, `uv sync` — only when that
299
+ # installer's inputs changed since its last successful run, so an
300
+ # unchanged checkout enters in the time it takes to hash a lockfile. It
301
+ # records those inputs, and the managed .envrc watches them, so a shell
302
+ # that direnv keeps loaded re-enters exactly when one of them changes.
281
303
  #
282
- # TTSC_GO_CACHE_DIR and GOCACHE stay separate for ownership, not
283
- # correctness: both caches are content-addressed, so one directory would
284
- # compile the same bytes to the same entries. What sharing loses is an
285
- # owner. ttsc reclaims a Go build cache only when it resolved that
286
- # directory itself — `ttsc clean` takes the cache whose source is
287
- # TTSC_GO_CACHE_DIR and never one whose source is a user GOCACHE, which it
288
- # treats as someone else's property. Pointing ttsc at GOCACHE therefore
289
- # produced a directory ttsc filled and no repository verb could empty,
290
- # measured at 35G here. A dedicated directory gives ttsc's half back to
291
- # `ttsc clean` and leaves GOCACHE holding only Go work this repository does
292
- # itself, which is one module.
304
+ # The uv project environment is devenv's UV_PROJECT_ENVIRONMENT, synced
305
+ # with the interpreter devenv would use and activated here after the
306
+ # sync. It lives under this checkout and names no path of it: uv creates
307
+ # it relocatable, setup-environment.ts rewrites the editable installs of
308
+ # workspace members relative to it, and the interpreter is the same
309
+ # store path everywhere (languages.python.libraries above). A
310
+ # copy-on-write clone copies it along with everything else, installed.
311
+ # devenv's own virtualenv and uv sync tasks are refused below: they
312
+ # activate the environment from its own activation script — which in a
313
+ # clone names the original checkout — before this prologue runs, and key
314
+ # their skip on pyproject.toml alone.
293
315
  #
294
- # That buys ownership, not automatic GC: ttsc prunes opportunistically only
295
- # when it owns the whole cache root, which requires TTSC_CACHE_DIR unset,
296
- # and a pinned shared root is the point of the block below. The trade is
297
- # deliberate — one warm cache every workspace shares, reclaimed by an
298
- # explicit verb, over per-workspace caches that self-trim. Go's own build
299
- # cache trimming belongs to the go command and still applies to both.
300
- # 5. The shared setup-environment.ts bootstraps repository dependencies; a
301
- # failure aborts shell entry instead of yielding a half-working shell.
302
- # Repo-owned enterShell bodies merge after this prologue.
303
- # 6. Shell entry resolves the `shell` group of `smoo.secrets` and nothing
304
- # else. Shell entry happens on every direnv reload and every
305
- # `devenv shell -- <command>`, and a provider command that runs then is a
306
- # credential prompt on every one of them (1Password authorises per
307
- # requesting process lineage, and this one is new each time). A
316
+ # A local install failure is reported and the shell still loads, so the
317
+ # tools to repair it stay available; CI fails. Repo-owned enterShell
318
+ # bodies merge after this prologue.
319
+ # 6. Shell entry resolves the `shell` group of `smoo.secrets`, only when it
320
+ # installs, and nothing else. Shell entry happens on every direnv reload
321
+ # and every `devenv shell -- <command>`, and a provider command that runs
322
+ # then is a credential prompt on every one of them (1Password authorises
323
+ # per requesting process lineage, and this one is new each time). A
308
324
  # credential only one deliberate command needs belongs to that command:
309
325
  # `smoo secrets run <group> <command...>`. The full statement, and the
310
326
  # derivation below, live in tooling/direnv/secret-references.ts.
@@ -383,19 +399,15 @@ in {
383
399
  export TMPDIR="''${TMPDIR:-/tmp}"
384
400
  fi
385
401
  export TTSC_TSGO_BINARY="$PWD/node_modules/@typescript/native/bin/tsc"
386
- if [ -d "$HOME/.cowshed/caches" ]; then
387
- export TTSC_CACHE_DIR="''${TTSC_CACHE_DIR:-$HOME/.cowshed/caches/ttsc}"
388
- export GOCACHE="''${GOCACHE:-$HOME/.cowshed/caches/go/build}"
389
- export GOMODCACHE="''${GOMODCACHE:-$HOME/.cowshed/caches/go/mod}"
390
- mkdir -p "$GOCACHE" "$GOMODCACHE"
391
- else
392
- export TTSC_CACHE_DIR="''${TTSC_CACHE_DIR:-$PWD/.cache/ttsc}"
393
- fi
394
- export TTSC_GO_CACHE_DIR="''${TTSC_GO_CACHE_DIR:-$TTSC_CACHE_DIR/go-build}"
395
- mkdir -p "$TTSC_CACHE_DIR" "$TTSC_GO_CACHE_DIR"
396
- export GOFLAGS="''${GOFLAGS:--trimpath}"
402
+ . "$DEVENV_ROOT/shared-caches.sh" /private/cowshed/caches
397
403
  unset GOROOT
398
- bun "$DEVENV_ROOT/setup-environment.ts" || exit $?
404
+ bun "$DEVENV_ROOT/setup-environment.ts"${lib.optionalString uvProject " --python ${python.package.interpreter}"} || exit $?
405
+ ${lib.optionalString uvProject ''
406
+ if [ -f pyproject.toml ]; then
407
+ export VIRTUAL_ENV="$UV_PROJECT_ENVIRONMENT"
408
+ export PATH="$VIRTUAL_ENV/bin:$PATH"
409
+ fi
410
+ ''}
399
411
  # One socket dir per Nx workspace. DEVENV_RUNTIME is keyed to the devenv
400
412
  # ROOT, so every workspace sharing one devenv - a sibling repository, a
401
413
  # copy-on-write clone, a scratch workspace created inside this shell -
@@ -432,4 +444,16 @@ in {
432
444
  fi
433
445
  '')
434
446
  ];
447
+
448
+ assertions = [
449
+ {
450
+ assertion = !(uvProject && (python.venv.enable || python.uv.sync.enable));
451
+ message = ''
452
+ devenv.smoo.nix syncs and activates the uv project environment itself (enterShell item 5).
453
+ Set languages.python.venv.enable and languages.python.uv.sync.enable to false in devenv.nix:
454
+ devenv's tasks activate the environment from its own activation script, which in a
455
+ copy-on-write clone names the original checkout, and skip the sync while uv.lock changes.
456
+ '';
457
+ }
458
+ ];
435
459
  }
@@ -393,7 +393,9 @@ async function routeSecret(
393
393
  }
394
394
  const requested = group === context.group;
395
395
  if (requested || context.dependsOn.includes(group)) {
396
- if (isNonemptyEnvValue(env.CI)) {
396
+ // A CI runner (GitHub or Forgejo Actions, which sets GITHUB_ACTIONS too), never
397
+ // `CI`: agent harnesses set CI=true on every command they run.
398
+ if (env.GITHUB_ACTIONS === 'true') {
397
399
  return {
398
400
  name,
399
401
  group,