@smoothbricks/nx-plugin 0.4.24 → 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.
Files changed (58) hide show
  1. package/README.md +147 -37
  2. package/dist/bin/smoo-nx-exec.js +3 -14
  3. package/dist/cargo-closure-input.d.ts +13 -15
  4. package/dist/cargo-closure-input.d.ts.map +1 -1
  5. package/dist/cargo-closure-input.js +29 -37
  6. package/dist/cargo-source-hash.d.ts +12 -7
  7. package/dist/cargo-source-hash.d.ts.map +1 -1
  8. package/dist/cargo-source-hash.js +416 -32
  9. package/dist/cargo-workspace.d.ts +7 -7
  10. package/dist/cargo-workspace.js +8 -8
  11. package/dist/ensure-built.d.ts +6 -0
  12. package/dist/ensure-built.d.ts.map +1 -1
  13. package/dist/ensure-built.js +79 -6
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +69 -96
  16. package/dist/managed-assets.d.ts +6 -0
  17. package/dist/managed-assets.d.ts.map +1 -1
  18. package/dist/managed-files/files.d.ts.map +1 -1
  19. package/dist/managed-files/files.js +6 -0
  20. package/dist/manifest-hash.d.ts.map +1 -1
  21. package/dist/manifest-hash.js +6 -2
  22. package/dist/workspace-manifest.d.ts +0 -1
  23. package/dist/workspace-manifest.d.ts.map +1 -1
  24. package/managed/raw/envrc +15 -0
  25. package/managed/raw/git-format-staged.yml +1 -0
  26. package/managed/raw/tooling/direnv/developer-links.ts +43 -11
  27. package/managed/raw/tooling/direnv/devenv.smoo.nix +5 -0
  28. package/managed/raw/tooling/direnv/inherited-devenv.ts +665 -0
  29. package/managed/raw/tooling/direnv/setup-environment.ts +123 -7
  30. package/nextest.toml +3 -37
  31. package/package.json +40 -3
  32. package/src/__tests__/counted-cargo-process.ts +286 -0
  33. package/src/__tests__/counted-cargo.ts +711 -0
  34. package/src/__tests__/fixture-cargo-home.ts +36 -0
  35. package/src/__tests__/fixture-nx-env.ts +93 -3
  36. package/src/bin/smoo-nx-exec.ts +3 -14
  37. package/src/bounded-test-policy.test.ts +0 -1
  38. package/src/cargo-closure-input.test.ts +313 -15
  39. package/src/cargo-closure-input.ts +42 -50
  40. package/src/cargo-resolve-cache.test.ts +975 -0
  41. package/src/cargo-source-hash.test.ts +17 -3
  42. package/src/cargo-source-hash.ts +447 -37
  43. package/src/cargo-workspace.ts +8 -8
  44. package/src/ensure-built.test.ts +122 -20
  45. package/src/ensure-built.ts +82 -5
  46. package/src/index.test.ts +203 -107
  47. package/src/index.ts +86 -115
  48. package/src/managed-assets.ts +12 -0
  49. package/src/managed-files/files.ts +6 -0
  50. package/src/manifest-hash.ts +7 -2
  51. package/src/nextest-partitions.test.ts +150 -0
  52. package/src/nx-cache-bound.test.ts +114 -0
  53. package/src/nx-resident-graph-workers.test.ts +121 -0
  54. package/src/nx-store-resolution.test.ts +98 -0
  55. package/src/task-history-namespace.test.ts +183 -0
  56. package/src/workspace-manifest.ts +0 -1
  57. package/test-timings.json +35 -0
  58. package/src/__tests__/in-process-nx-index.ts +0 -9
@@ -28,6 +28,16 @@
28
28
  * before the install, with a warning, so that install puts the lockfile's
29
29
  * version in its place.
30
30
  *
31
+ * An install that exists to replace links says which: `{ relink }` names the
32
+ * packages (`name` or `@scope/name`) it is meant to relink, in the root's
33
+ * tree and in every member's. When the install resolves, what it left at
34
+ * those names stays (a `bun link` run against providers a developer
35
+ * registered anew) and every other developer link is put back as before.
36
+ * When it rejects, every link is put back, the named ones included, so a
37
+ * failed relink changes nothing. A named package with no developer link when
38
+ * the install starts has nothing to put back, and a named link that dangled
39
+ * is removed first, as for any install.
40
+ *
31
41
  * Like secret-references.ts, this is a managed raw script: shell entry imports
32
42
  * it before anything is installed, and `smoo monorepo update` loads the copy
33
43
  * the nx-plugin ships. Because both use the one implementation, the shell and
@@ -42,9 +52,11 @@ import {
42
52
  readFileSync,
43
53
  readlinkSync,
44
54
  rmSync,
55
+ statSync,
45
56
  symlinkSync,
46
57
  } from 'node:fs';
47
58
  import path from 'node:path';
59
+ import type { KeepDeveloperLinksOptions } from '@smoothbricks/nx-plugin/managed-assets';
48
60
 
49
61
  interface DeveloperLink {
50
62
  /** Where the link is, relative to the project root. */
@@ -60,24 +72,40 @@ interface DeveloperLinks {
60
72
  }
61
73
 
62
74
  /**
63
- * Runs `install` with every developer link under `root` kept. The links in
64
- * place when it starts are exactly the links in place when it settles,
65
- * whether it resolved or rejected, less those that already dangled. It then
66
- * names them as `reportDeveloperLinks` does.
75
+ * Runs `install` while preserving the developer links captured under `root`.
76
+ * On rejection every captured live link is restored, less links that already
77
+ * dangled; a resolved install keeps its selected `relink` replacements.
78
+ * This is not a transaction over new entries created by the install. Relink
79
+ * intent reports the actual final link state on either outcome.
67
80
  */
68
- export async function keepDeveloperLinks<T>(root: string, install: () => Promise<T>): Promise<T> {
81
+ export async function keepDeveloperLinks<T>(
82
+ root: string,
83
+ install: () => Promise<T>,
84
+ options?: KeepDeveloperLinksOptions,
85
+ ): Promise<T> {
69
86
  const { live, dangling } = findDeveloperLinks(root);
70
87
  for (const link of dangling) {
71
88
  rmSync(path.join(root, link.path), { force: true });
72
89
  console.error(`! removed developer link ${link.path}: its target ${resolvedTarget(root, link)} no longer exists`);
73
90
  }
91
+ // Only an install that resolved leaves the links it was meant to replace as
92
+ // it made them; a rejected one puts every captured live link back.
93
+ let replaced: readonly string[] | undefined;
74
94
  try {
75
- return await install();
95
+ const result = await install();
96
+ replaced = options?.relink;
97
+ return result;
76
98
  } finally {
77
99
  for (const link of live) {
78
- restoreLink(root, link);
100
+ if (!replaced?.length || !replaced.includes(packageName(link))) {
101
+ restoreLink(root, link);
102
+ }
103
+ }
104
+ if (options !== undefined) {
105
+ reportDeveloperLinks(root);
106
+ } else {
107
+ describeDeveloperLinks(root, live);
79
108
  }
80
- describeDeveloperLinks(root, live);
81
109
  }
82
110
  }
83
111
 
@@ -93,6 +121,11 @@ export function reportDeveloperLinks(root: string): void {
93
121
  describeDeveloperLinks(root, findDeveloperLinks(root).live);
94
122
  }
95
123
 
124
+ /** The package a link stands for in its tree: `name` or `@scope/name`. */
125
+ function packageName(link: DeveloperLink): string {
126
+ return link.path.slice(link.path.lastIndexOf('node_modules/') + 'node_modules/'.length);
127
+ }
128
+
96
129
  /** A package linked from many members is named once, with its count. */
97
130
  function describeDeveloperLinks(root: string, links: readonly DeveloperLink[]): void {
98
131
  if (links.length === 0) {
@@ -100,8 +133,7 @@ function describeDeveloperLinks(root: string, links: readonly DeveloperLink[]):
100
133
  }
101
134
  const counts = new Map<string, number>();
102
135
  for (const link of links) {
103
- const name = link.path.slice(link.path.lastIndexOf('node_modules/') + 'node_modules/'.length);
104
- const named = `${name} -> ${resolvedTarget(root, link)}`;
136
+ const named = `${packageName(link)} -> ${resolvedTarget(root, link)}`;
105
137
  counts.set(named, (counts.get(named) ?? 0) + 1);
106
138
  }
107
139
  const entries = [...counts].map(([named, count]) => (count === 1 ? named : `${named} (${count} links)`));
@@ -117,7 +149,7 @@ function findDeveloperLinks(root: string): DeveloperLinks {
117
149
  const target = resolvedTarget(root, link);
118
150
  const relative = path.relative(root, target);
119
151
  if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
120
- (existsSync(target) ? live : dangling).push(link);
152
+ (statSync(target, { throwIfNoEntry: false }) === undefined ? dangling : live).push(link);
121
153
  }
122
154
  }
123
155
  }
@@ -386,6 +386,10 @@ in {
386
386
  # a subprocess of either), and one socket dir for two workspaces makes the
387
387
  # daemon refuse whichever came second ("received a message from a
388
388
  # different workspace"). Nobody supplies this deliberately.
389
+ #
390
+ # In a cowshed sandbox an inherited private .devenv can supply the
391
+ # evaluated shell after its inputs and task graph are checked. The merged
392
+ # hook still runs only when direnv imports the workspace's own export.
389
393
  (lib.mkBefore ''
390
394
  cd "$DEVENV_ROOT/../.."
391
395
  export PATH="$("$PWD/tooling/direnv/repo-path")"
@@ -416,6 +420,7 @@ in {
416
420
  # workspace"), which reads as a hung Nx in a workspace that did nothing
417
421
  # wrong. Nx's own diagnostic names this exact cause.
418
422
  nx_workspace_root="$(cd "$DEVENV_ROOT/../.." >/dev/null 2>&1 && pwd || printf '%s' "$PWD")"
423
+ export NX_WORKSPACE_ROOT_PATH="$nx_workspace_root"
419
424
  export NX_SOCKET_DIR="$DEVENV_RUNTIME/nx-$(printf '%s' "$nx_workspace_root" | cksum | cut -d' ' -f1)"
420
425
  mkdir -p "$NX_SOCKET_DIR"
421
426
  ${lib.optionalString pkgs.stdenv.isDarwin ''