@smoothbricks/nx-plugin 0.4.22 → 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.
- package/README.md +77 -21
- package/dist/bin/smoo-nx-exec.js +35 -11
- package/dist/cargo-closure-input.d.ts +63 -0
- package/dist/cargo-closure-input.d.ts.map +1 -0
- package/dist/cargo-closure-input.js +197 -0
- package/dist/cargo-source-hash.d.ts +37 -0
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +108 -190
- package/dist/cross-check-policy.d.ts +14 -0
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +15 -1
- package/dist/ensure-built.d.ts +3 -2
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +33 -56
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -76
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +12 -15
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +10 -0
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +12 -6
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +24 -30
- package/dist/package-target-policy.js +1 -1
- package/dist/platform-targets.d.ts +7 -0
- package/dist/platform-targets.d.ts.map +1 -1
- package/dist/platform-targets.js +7 -0
- package/dist/workspace-config-policy.d.ts +1 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +1 -1
- package/managed/raw/envrc +38 -1
- package/managed/raw/tooling/direnv/developer-links.ts +201 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
- package/managed/raw/tooling/direnv/secret-references.ts +3 -1
- package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
- package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
- package/managed/templates/github/workflows/managed-files.yml +4 -3
- package/nextest.toml +5 -5
- package/package.json +2 -2
- package/src/__tests__/fixture-nx-env.ts +31 -0
- package/src/__tests__/in-process-nx-index.ts +9 -0
- package/src/bin/smoo-nx-exec.ts +40 -11
- package/src/cargo-closure-input.test.ts +184 -0
- package/src/cargo-closure-input.ts +247 -0
- package/src/cargo-source-hash.test.ts +8 -9
- package/src/cargo-source-hash.ts +146 -47
- package/src/cross-check-policy.ts +15 -3
- package/src/ensure-built.test.ts +65 -5
- package/src/ensure-built.ts +40 -85
- package/src/index.test.ts +94 -53
- package/src/index.ts +164 -84
- package/src/managed-files/ci-workflow.ts +12 -15
- package/src/managed-files/files.ts +10 -0
- package/src/managed-files/generator.test.ts +29 -0
- package/src/managed-files/publish-workflow.ts +17 -6
- package/src/manifest-hash.test.ts +21 -1
- package/src/manifest-hash.ts +26 -29
- package/src/package-target-policy.ts +1 -1
- package/src/platform-targets.ts +8 -0
- 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 });
|
package/src/manifest-hash.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createHash, type Hash } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { join,
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { join, posix } from 'node:path';
|
|
4
4
|
|
|
5
|
-
import {
|
|
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
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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 (
|
|
162
|
-
hash.update(
|
|
162
|
+
for (const { path, bytes } of manifests) {
|
|
163
|
+
hash.update(path);
|
|
163
164
|
hash.update(SEPARATOR);
|
|
164
|
-
updateVersionlessCrateManifest(hash,
|
|
165
|
+
updateVersionlessCrateManifest(hash, bytes);
|
|
165
166
|
hash.update(SEPARATOR);
|
|
166
167
|
}
|
|
167
168
|
return hash.digest('hex');
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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.
|
|
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
|
package/src/platform-targets.ts
CHANGED
|
@@ -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 {
|
|
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
|
|