@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
@@ -2,8 +2,9 @@ import { describe, expect, it } from 'bun:test';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { mkdir, mkdtemp, rename, rm, writeFile } from 'node:fs/promises';
4
4
  import { tmpdir } from 'node:os';
5
- import { dirname, join } from 'node:path';
5
+ import { dirname, join, posix } from 'node:path';
6
6
 
7
+ import { resetWorkspaceContext, updateFilesInContext } from 'nx/src/utils/workspace-context.js';
7
8
  import { hashVersionlessCrateManifests, updateVersionlessCrateManifest } from './manifest-hash.js';
8
9
 
9
10
  const CRATE_MANIFEST = `[package]
@@ -141,6 +142,20 @@ describe('versionless crate manifest hashing', () => {
141
142
  });
142
143
  });
143
144
 
145
+ it('hashes only the manifests Nx indexes, never ones under ignored build output', async () => {
146
+ await withProject(async (project) => {
147
+ const baseline = await hashVersionlessCrateManifests(project.root, project.workspaceRoot);
148
+ // A build that copies crates into ignored output (a vendored dist, a
149
+ // cache restore) must neither move the digest nor be read at all: a
150
+ // restore may delete that tree while the digest is computed.
151
+ await project.write('.gitignore', 'generated/\n');
152
+ await project.write('generated/crate/Cargo.toml', CRATE_MANIFEST.replace('1.0.200', '9.9.9'));
153
+ project.refreshIndex();
154
+
155
+ expect(await hashVersionlessCrateManifests(project.root, project.workspaceRoot)).toBe(baseline);
156
+ });
157
+ });
158
+
144
159
  it('hashes a manifest it cannot read instead of dropping it', async () => {
145
160
  await withProject(async (project) => {
146
161
  await project.write('crates/core/Cargo.toml', 'this is not toml [[[');
@@ -169,6 +184,8 @@ interface ProjectFixture {
169
184
  root: string;
170
185
  write(path: string, contents: string): Promise<void>;
171
186
  move(from: string, to: string): Promise<void>;
187
+ /** Rebuild Nx's file index for the fixture, as a fresh Nx process would. */
188
+ refreshIndex(): void;
172
189
  }
173
190
 
174
191
  async function withProject(body: (project: ProjectFixture) => Promise<void>): Promise<void> {
@@ -191,7 +208,10 @@ async function withProject(body: (project: ProjectFixture) => Promise<void>): Pr
191
208
  const target = join(workspaceRoot, root, to);
192
209
  await mkdir(dirname(target), { recursive: true });
193
210
  await rename(join(workspaceRoot, root, from), target);
211
+ // What Nx's file watcher reports to the index for a move.
212
+ updateFilesInContext(workspaceRoot, [posix.join(root, to)], [posix.join(root, from)]);
194
213
  },
214
+ refreshIndex: resetWorkspaceContext,
195
215
  });
196
216
  } finally {
197
217
  await rm(workspaceRoot, { recursive: true, force: true });
@@ -1,8 +1,8 @@
1
1
  import { createHash, type Hash } from 'node:crypto';
2
- import { readdir, readFile } from 'node:fs/promises';
3
- import { join, sep } from 'node:path';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { join, posix } from 'node:path';
4
4
 
5
- import { isNonSourceDirectory } from './source-directories.js';
5
+ import { globWithWorkspaceContext } from 'nx/src/utils/workspace-context.js';
6
6
 
7
7
  /**
8
8
  * A release rewrites `version` in every manifest it publishes. Those manifests
@@ -150,41 +150,38 @@ export function updateVersionlessCrateManifest(hash: Hash, manifest: Buffer): vo
150
150
  * answer: the dependency the digest describes really did change.
151
151
  */
152
152
  export async function hashVersionlessCrateManifests(projectRoot: string, workspaceRoot: string): Promise<string> {
153
- const root = join(workspaceRoot, projectRoot);
154
- const paths: string[] = [];
155
- await collectCrateManifests(root, '', paths);
156
- paths.sort();
157
- const manifests = await Promise.all(paths.map((path) => readFile(join(root, path))));
153
+ const manifests = await Promise.all(
154
+ (await listCrateManifests(projectRoot, workspaceRoot)).map(async (path) => ({
155
+ path,
156
+ bytes: await readFile(join(workspaceRoot, projectRoot, path)),
157
+ })),
158
+ );
158
159
  const hash = createHash('sha256');
159
160
  hash.update(DIGEST_TAG);
160
161
  hash.update(SEPARATOR);
161
- for (let index = 0; index < paths.length; index++) {
162
- hash.update(paths[index] as string);
162
+ for (const { path, bytes } of manifests) {
163
+ hash.update(path);
163
164
  hash.update(SEPARATOR);
164
- updateVersionlessCrateManifest(hash, manifests[index] as Buffer);
165
+ updateVersionlessCrateManifest(hash, bytes);
165
166
  hash.update(SEPARATOR);
166
167
  }
167
168
  return hash.digest('hex');
168
169
  }
169
170
 
170
- /** Collects manifest paths relative to the project root, `/`-separated so the digest is platform-independent. */
171
- async function collectCrateManifests(directory: string, prefix: string, found: string[]): Promise<void> {
172
- // No `catch`: an unreadable directory would otherwise hash as an empty
173
- // manifest set, which is the silent-staleness failure this module exists to
174
- // avoid. The caller degrades to the raw manifests instead. Symlinked
175
- // directories are not entries `isDirectory` reports, so the walk cannot loop
176
- // and matches what Nx keeps in its file map.
177
- for (const entry of await readdir(directory, { withFileTypes: true })) {
178
- if (entry.isDirectory()) {
179
- // The exclusions every source walk in this plugin uses, so the digest
180
- // covers the same files Nx keeps in its file map.
181
- if (!isNonSourceDirectory(entry.name)) {
182
- await collectCrateManifests(`${directory}${sep}${entry.name}`, `${prefix}${entry.name}/`, found);
183
- }
184
- } else if (entry.name === CARGO_MANIFEST) {
185
- found.push(`${prefix}${entry.name}`);
186
- }
187
- }
171
+ /**
172
+ * Crate manifest paths relative to the project root, `/`-separated and sorted,
173
+ * so the digest is platform-independent. They come from Nx's own workspace
174
+ * file index — exactly the files the project's `Cargo.toml` exclusion removes
175
+ * from its filesets, with `.gitignore` applied — rather than from a walk of
176
+ * the tree: a walk reads ignored build output, which an Nx cache restore can
177
+ * delete while it is being read. No `catch`: a listing or read that fails
178
+ * would otherwise hash as a smaller manifest set, the silent staleness this
179
+ * module exists to avoid; the caller degrades to the raw manifests instead.
180
+ */
181
+ async function listCrateManifests(projectRoot: string, workspaceRoot: string): Promise<string[]> {
182
+ const prefix = projectRoot === '.' ? '' : `${posix.normalize(projectRoot)}/`;
183
+ const files = await globWithWorkspaceContext(workspaceRoot, [`${prefix}**/${CARGO_MANIFEST}`]);
184
+ return files.map((file) => file.slice(prefix.length)).sort();
188
185
  }
189
186
 
190
187
  /** `from` is just past the `[`. */
@@ -327,7 +327,7 @@ function isRedundantBuildDeclaration(build: Record<string, unknown>, resolvedTar
327
327
  * Deliberately NOT decided against the resolved project graph. Nx replaces a
328
328
  * named property of an inferred target with the declared one, so the resolved
329
329
  * `build.dependsOn` IS the declaration: comparing them answered "redundant"
330
- * for every noop aggregate anyone ever wrote. AxE's `containium` lost seven
330
+ * for every noop aggregate anyone ever wrote. A downstream runtime host lost seven
331
331
  * edges that way — four of them targets no inference can reach — and a clean
332
332
  * checkout then built it without its producers. The question this has to
333
333
  * answer is what inference yields WITHOUT the declaration, so the test is
@@ -2,3 +2,11 @@
2
2
  export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'] as const;
3
3
  export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'] as const;
4
4
  export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS] as const;
5
+
6
+ /**
7
+ * The Nx configuration that builds what ships. A cargo build target's default
8
+ * options compile cargo's `dev` profile, which every local build, test and
9
+ * gate shares; this configuration adds `--release`. Only release tooling
10
+ * selects it, so a shipped artifact is the only thing compiled twice.
11
+ */
12
+ export const RELEASE_CONFIGURATION = 'production';
@@ -24,7 +24,12 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
24
24
  '*-wasm',
25
25
  ] as const;
26
26
 
27
- export { LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, PLATFORM_TARGET_GLOBS } from './platform-targets.js';
27
+ export {
28
+ LINUX_PLATFORM_TARGET_GLOBS,
29
+ MACOS_PLATFORM_TARGET_GLOBS,
30
+ PLATFORM_TARGET_GLOBS,
31
+ RELEASE_CONFIGURATION,
32
+ } from './platform-targets.js';
28
33
 
29
34
  const buildOutputTargetSuffixes = BUILD_OUTPUT_DEPENDENCIES.map((glob) => glob.slice(1));
30
35