@smoothbricks/nx-plugin 0.4.22 → 0.4.24

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 (72) hide show
  1. package/README.md +93 -33
  2. package/dist/bin/smoo-nx-exec.js +35 -11
  3. package/dist/bin/smoo-nx-nextest-extract.d.ts +3 -0
  4. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-nextest-extract.js +41 -0
  6. package/dist/cargo-closure-input.d.ts +63 -0
  7. package/dist/cargo-closure-input.d.ts.map +1 -0
  8. package/dist/cargo-closure-input.js +197 -0
  9. package/dist/cargo-source-hash.d.ts +37 -0
  10. package/dist/cargo-source-hash.d.ts.map +1 -1
  11. package/dist/cargo-source-hash.js +108 -190
  12. package/dist/cross-check-policy.d.ts +14 -0
  13. package/dist/cross-check-policy.d.ts.map +1 -1
  14. package/dist/cross-check-policy.js +15 -1
  15. package/dist/ensure-built.d.ts +3 -2
  16. package/dist/ensure-built.d.ts.map +1 -1
  17. package/dist/ensure-built.js +33 -56
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +152 -91
  20. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  21. package/dist/managed-files/ci-workflow.js +12 -15
  22. package/dist/managed-files/files.d.ts.map +1 -1
  23. package/dist/managed-files/files.js +10 -0
  24. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  25. package/dist/managed-files/publish-workflow.js +12 -6
  26. package/dist/manifest-hash.d.ts.map +1 -1
  27. package/dist/manifest-hash.js +24 -30
  28. package/dist/nextest-extraction.d.ts +101 -0
  29. package/dist/nextest-extraction.d.ts.map +1 -0
  30. package/dist/nextest-extraction.js +268 -0
  31. package/dist/package-target-policy.js +1 -1
  32. package/dist/platform-targets.d.ts +7 -0
  33. package/dist/platform-targets.d.ts.map +1 -1
  34. package/dist/platform-targets.js +7 -0
  35. package/dist/workspace-config-policy.d.ts +1 -1
  36. package/dist/workspace-config-policy.d.ts.map +1 -1
  37. package/dist/workspace-config-policy.js +1 -1
  38. package/managed/raw/envrc +38 -1
  39. package/managed/raw/tooling/direnv/developer-links.ts +201 -0
  40. package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
  41. package/managed/raw/tooling/direnv/secret-references.ts +3 -1
  42. package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
  43. package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
  44. package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
  45. package/managed/templates/github/workflows/managed-files.yml +4 -3
  46. package/nextest.toml +5 -5
  47. package/package.json +4 -3
  48. package/src/__tests__/fixture-nx-env.ts +31 -0
  49. package/src/__tests__/in-process-nx-index.ts +9 -0
  50. package/src/bin/smoo-nx-exec.ts +40 -11
  51. package/src/bin/smoo-nx-nextest-extract.ts +43 -0
  52. package/src/bounded-test-policy.test.ts +4 -1
  53. package/src/cargo-closure-input.test.ts +184 -0
  54. package/src/cargo-closure-input.ts +247 -0
  55. package/src/cargo-source-hash.test.ts +8 -9
  56. package/src/cargo-source-hash.ts +146 -47
  57. package/src/cross-check-policy.ts +15 -3
  58. package/src/ensure-built.test.ts +65 -5
  59. package/src/ensure-built.ts +40 -85
  60. package/src/index.test.ts +222 -75
  61. package/src/index.ts +213 -101
  62. package/src/managed-files/ci-workflow.ts +12 -15
  63. package/src/managed-files/files.ts +10 -0
  64. package/src/managed-files/generator.test.ts +29 -0
  65. package/src/managed-files/publish-workflow.ts +17 -6
  66. package/src/manifest-hash.test.ts +21 -1
  67. package/src/manifest-hash.ts +26 -29
  68. package/src/nextest-extraction.test.ts +74 -0
  69. package/src/nextest-extraction.ts +329 -0
  70. package/src/package-target-policy.ts +1 -1
  71. package/src/platform-targets.ts +8 -0
  72. package/src/workspace-config-policy.ts +6 -1
@@ -92,7 +92,7 @@ export function unvouched(entries, verdicts) {
92
92
  * on every invocation. So it never spawns the `nx` CLI: a native filesystem
93
93
  * snapshot refreshes the daemon's inputs, the task hashes and on-disk output
94
94
  * verification are daemon round-trips, and the cache lookup is a local SQLite
95
- * read. Nx's task runner is only invoked once something needs running.
95
+ * read. Only a miss starts the workspace's `nx` CLI, to run the target.
96
96
  *
97
97
  * With the daemon disabled there is no probe to make — hashing would have to
98
98
  * build the project graph in this process, and no service holds the recorded
@@ -141,7 +141,7 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
141
141
  // this explicit fallback path, which also lets a deliberately minimal
142
142
  // checkout-local CLI stand in for Nx.
143
143
  if (process.env.NX_DAEMON === 'false') {
144
- return runViaCli(workspaceRoot, selector);
144
+ return runViaCli(workspaceRoot, selector, { kind: 'no-daemon', taskId: selectorTaskId(selector) });
145
145
  }
146
146
  // Nx rejects daemon access when the client package's version differs from
147
147
  // the workspace's running daemon. Resolve every runtime module from the
@@ -151,7 +151,7 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
151
151
  bindWorkspaceRoot(workspaceRoot, requireNx);
152
152
  const { daemonClient } = requireNx('nx/src/daemon/client/client');
153
153
  if (!daemonClient.enabled()) {
154
- return runViaCli(workspaceRoot, selector);
154
+ return runViaCli(workspaceRoot, selector, { kind: 'no-daemon', taskId: selectorTaskId(selector) });
155
155
  }
156
156
  // An outer Nx task exports its own cache-bypass setting to the process it
157
157
  // launches. That setting describes the outer task, not the nested target:
@@ -199,32 +199,34 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
199
199
  });
200
200
  performance.mark('ensureBuilt:probe:start');
201
201
  let reason;
202
- const selectorTaskId = selector.configuration === undefined
203
- ? `${selector.project}:${selector.target}`
204
- : `${selector.project}:${selector.target}:${selector.configuration}`;
205
202
  if (process.env.NX_SKIP_NX_CACHE === 'true' || process.env.NX_DISABLE_NX_CACHE === 'true') {
206
- reason = { kind: 'cache-disabled', taskId: selectorTaskId };
203
+ reason = { kind: 'cache-disabled', taskId: selectorTaskId(selector) };
207
204
  }
208
205
  else if (inputsChanged) {
209
- reason = { kind: 'stale-inputs', taskId: selectorTaskId };
206
+ reason = { kind: 'stale-inputs', taskId: selectorTaskId(selector) };
210
207
  }
211
208
  else {
212
209
  reason = await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
213
210
  }
214
211
  performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
215
- const outcome = reason === null
216
- ? { result: HIT, taskResults: NO_TASK_RESULTS }
217
- : await runTarget(nxJson, nxArgs, overrides, selector, reason, requireNx);
212
+ // The CLI runs the hooks around its own run, under its own id. This process
213
+ // ran none of the tasks, so it reports none for the id it opened.
214
+ const result = reason === null ? HIT : await runViaCli(workspaceRoot, selector, reason);
218
215
  await hooks.runPostTasksExecution({
219
216
  id: runId,
220
- taskResults: outcome.taskResults,
217
+ taskResults: NO_TASK_RESULTS,
221
218
  workspaceRoot,
222
219
  nxJsonConfiguration: nxJson,
223
220
  argv: process.argv,
224
221
  startTime,
225
222
  endTime: Date.now(),
226
223
  });
227
- return outcome.result;
224
+ return result;
225
+ }
226
+ function selectorTaskId(selector) {
227
+ return selector.configuration === undefined
228
+ ? `${selector.project}:${selector.target}`
229
+ : `${selector.project}:${selector.target}:${selector.configuration}`;
228
230
  }
229
231
  /**
230
232
  * Nx computes `workspaceRoot` once, at module load, from
@@ -576,56 +578,31 @@ function firstMovedClaim(observed) {
576
578
  function isSystemError(error) {
577
579
  return error instanceof Error && 'code' in error && typeof error.code === 'string';
578
580
  }
579
- async function runTarget(nxJson, nxArgs, overrides, selector, reason, requireNx) {
580
- const { runCommandForTasks } = requireNx('nx/src/tasks-runner/run-command');
581
- const { createProjectGraphAsync } = requireNx('nx/src/project-graph/project-graph');
582
- const { signalToCode } = requireNx('nx/src/utils/exit-codes');
583
- // `runCommandForTasks` derives its own task graph and hashes, so the probe's
584
- // work is not reusable. That duplication is one daemon round-trip on a path
585
- // that is about to run a build.
586
- const projectGraph = await createProjectGraphAsync();
587
- const { taskResults, completed } = await runCommandForTasks([requireProject(projectGraph, selector.project)], projectGraph, { nxJson }, nxArgs, overrides, selector.project, {}, { excludeTaskDependencies: false, loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false' });
588
- if (!completed) {
589
- // Nx's own encoding of an interrupted run: `runCommand` reports
590
- // `signalToCode('SIGINT')` here. The runner does not surface which signal
591
- // actually arrived, so there is none to forward — only the code Nx's CLI
592
- // would have exited with.
593
- return {
594
- result: { disposition: 'failed', reason, exitCode: signalToCode('SIGINT'), signal: null },
595
- taskResults,
596
- };
597
- }
598
- for (const taskResult of Object.values(taskResults)) {
599
- if (taskResult.status === 'failure' || taskResult.status === 'skipped') {
600
- return { result: { disposition: 'failed', reason, exitCode: 1, signal: null }, taskResults };
601
- }
602
- }
603
- return { result: { disposition: 'built', reason }, taskResults };
604
- }
605
581
  /**
606
- * The daemon-disabled path: hand the target to the workspace's own `nx`, with
607
- * stdio inherited.
582
+ * Run the target through the workspace's own `nx`, the invocation whose hashes
583
+ * the probe reproduces, with the child's stdout on this process's stderr.
608
584
  *
609
- * Inheriting rather than piping is the point. The wrapper this facility
585
+ * A child, because Nx does not only write through `process.stdout`: its Rust
586
+ * pseudo-terminal and the forked executors it starts with inherited stdio
587
+ * write task output straight to file descriptor 1, and Node cannot point that
588
+ * descriptor elsewhere in its own process. In a child it is simply stderr, so
589
+ * the stdout of a wrapper that goes on to exec a binary carries nothing but
590
+ * that binary's output (`<cli> list | jq` reads only data).
591
+ *
592
+ * Inheriting rather than piping is the other half. The wrapper this facility
610
593
  * replaces piped Nx's output so it could read a cache marker out of the log and
611
594
  * stay silent on a hit — a text heuristic over ANSI-coloured, format-unstable
612
- * output. Without a daemon there is nothing to be silent about: no cheap probe
613
- * exists, so the run is unconditional, the output is the run's own, and the
614
- * child's exit status is forwarded verbatim.
595
+ * output. The probe already decided this is no hit, so the output is the run's
596
+ * own, and the child's exit status is forwarded verbatim.
615
597
  */
616
- async function runViaCli(workspaceRoot, selector) {
598
+ async function runViaCli(workspaceRoot, selector, reason) {
617
599
  const nxCli = join(workspaceRoot, 'node_modules', '.bin', 'nx');
618
600
  if (!existsSync(nxCli)) {
619
- throw new Error(`ensureBuilt: the Nx daemon is disabled and ${nxCli} does not exist`);
620
- }
621
- const reason = { kind: 'no-daemon', taskId: `${selector.project}:${selector.target}` };
622
- const targetSpec = selector.configuration
623
- ? `${selector.project}:${selector.target}:${selector.configuration}`
624
- : `${selector.project}:${selector.target}`;
625
- const signalToCode = nxSignalToCode;
626
- const child = spawn(nxCli, ['run', targetSpec, '--outputStyle=stream'], {
601
+ throw new Error(`ensureBuilt: ${describeMiss(reason)}, and ${nxCli} does not exist`);
602
+ }
603
+ const child = spawn(nxCli, ['run', selectorTaskId(selector), '--outputStyle=stream'], {
627
604
  cwd: workspaceRoot,
628
- stdio: 'inherit',
605
+ stdio: ['inherit', 2, 'inherit'],
629
606
  });
630
607
  // `Promise.withResolvers` would read better but needs lib es2024; this
631
608
  // package inherits lib es2022 from tsconfig.base.json.
@@ -633,7 +610,7 @@ async function runViaCli(workspaceRoot, selector) {
633
610
  child.once('error', reject);
634
611
  child.once('exit', (code, signal) => settle({ code, signal }));
635
612
  });
636
- return cliExitOutcome(reason, exit, signalToCode);
613
+ return cliExitOutcome(reason, exit, nxSignalToCode);
637
614
  }
638
615
  function nxSignalToCode(signal) {
639
616
  switch (signal) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAKL,yBAAyB,EAa1B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAqQlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG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