@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.
- package/README.md +147 -37
- package/dist/bin/smoo-nx-exec.js +3 -14
- package/dist/cargo-closure-input.d.ts +13 -15
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -37
- package/dist/cargo-source-hash.d.ts +12 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +416 -32
- package/dist/cargo-workspace.d.ts +7 -7
- package/dist/cargo-workspace.js +8 -8
- package/dist/ensure-built.d.ts +6 -0
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +79 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -96
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +6 -0
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +6 -2
- package/dist/workspace-manifest.d.ts +0 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/envrc +15 -0
- package/managed/raw/git-format-staged.yml +1 -0
- package/managed/raw/tooling/direnv/developer-links.ts +43 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +5 -0
- package/managed/raw/tooling/direnv/inherited-devenv.ts +665 -0
- package/managed/raw/tooling/direnv/setup-environment.ts +123 -7
- package/nextest.toml +3 -37
- package/package.json +40 -3
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +711 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +93 -3
- package/src/bin/smoo-nx-exec.ts +3 -14
- package/src/bounded-test-policy.test.ts +0 -1
- package/src/cargo-closure-input.test.ts +313 -15
- package/src/cargo-closure-input.ts +42 -50
- package/src/cargo-resolve-cache.test.ts +975 -0
- package/src/cargo-source-hash.test.ts +17 -3
- package/src/cargo-source-hash.ts +447 -37
- package/src/cargo-workspace.ts +8 -8
- package/src/ensure-built.test.ts +122 -20
- package/src/ensure-built.ts +82 -5
- package/src/index.test.ts +203 -107
- package/src/index.ts +86 -115
- package/src/managed-assets.ts +12 -0
- package/src/managed-files/files.ts +6 -0
- package/src/manifest-hash.ts +7 -2
- package/src/nextest-partitions.test.ts +150 -0
- package/src/nx-cache-bound.test.ts +114 -0
- package/src/nx-resident-graph-workers.test.ts +121 -0
- package/src/nx-store-resolution.test.ts +98 -0
- package/src/task-history-namespace.test.ts +183 -0
- package/src/workspace-manifest.ts +0 -1
- package/test-timings.json +35 -0
- package/src/__tests__/in-process-nx-index.ts +0 -9
package/src/index.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import { chmod, mkdir, mkdtemp, readdir, readFile, rm, symlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { chmod, mkdir, mkdtemp, readdir, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
@@ -8,17 +8,25 @@ import type { CreateNodesContextV2, CreateNodesV2, TargetConfiguration } from 'n
|
|
|
8
8
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
9
9
|
import { createTargetDefaultsResults } from 'nx/src/project-graph/utils/project-configuration/target-defaults.js';
|
|
10
10
|
import { mergeTargetConfigurations } from 'nx/src/project-graph/utils/project-configuration-utils.js';
|
|
11
|
+
import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
|
|
12
|
+
import { fixtureNxEnv, stopFixtureNxDaemon } from './__tests__/fixture-nx-env.js';
|
|
11
13
|
import { BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
12
14
|
import { exceptionalTestFilter, packageNameFromCargoTestTarget } from './cargo-workspace.js';
|
|
13
15
|
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_LINT_CLIPPY_COMMAND } from './cross-check-policy.js';
|
|
14
16
|
import { createNodesV2, createNodesV2ForPlatform } from './index.js';
|
|
15
17
|
import { applyWorkspaceConfig, RELEASE_CONFIGURATION } from './workspace-config-policy.js';
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
useFixtureCargoHome();
|
|
20
|
+
|
|
21
|
+
const [, rawInferTargets] = createNodesV2;
|
|
22
|
+
const inferTargets: typeof rawInferTargets = async (files, options, context) => {
|
|
23
|
+
await prepareCargoFixture(context.workspaceRoot);
|
|
24
|
+
return rawInferTargets(files, options, context);
|
|
25
|
+
};
|
|
18
26
|
|
|
19
27
|
describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
20
28
|
it('runs Rust-only lint without ESLint and checks JavaScript when sources appear', async () => {
|
|
21
|
-
const workspace = await
|
|
29
|
+
const workspace = await createNxWorkspace();
|
|
22
30
|
const root = workspace.context.workspaceRoot;
|
|
23
31
|
const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
|
24
32
|
try {
|
|
@@ -52,12 +60,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
52
60
|
const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'rust-fixture:lint'], {
|
|
53
61
|
cwd: root,
|
|
54
62
|
env: {
|
|
55
|
-
...
|
|
63
|
+
...fixtureNxEnv(root),
|
|
56
64
|
PATH: `${join(repositoryRoot, 'node_modules/.bin')}:${process.env.PATH ?? ''}`,
|
|
57
|
-
NX_DAEMON: 'false',
|
|
58
|
-
NX_ISOLATE_PLUGINS: 'false',
|
|
59
|
-
NX_WORKSPACE_DATA_DIRECTORY: join(root, '.nx/workspace-data'),
|
|
60
|
-
NX_CACHE_DIRECTORY: join(root, '.nx/cache'),
|
|
61
65
|
RUSTC_WRAPPER: '',
|
|
62
66
|
RUSTC_WORKSPACE_WRAPPER: '',
|
|
63
67
|
},
|
|
@@ -89,12 +93,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
89
93
|
expect(overridden).toMatchObject({ exitCode: 0 });
|
|
90
94
|
expect(overridden.output).toContain('explicit-lint');
|
|
91
95
|
} finally {
|
|
92
|
-
await workspace
|
|
96
|
+
await cleanupNxWorkspace(workspace);
|
|
93
97
|
}
|
|
94
98
|
}, 120_000);
|
|
95
99
|
|
|
96
100
|
it('never restores a stale child artifact from the cached build aggregate', async () => {
|
|
97
|
-
const workspace = await
|
|
101
|
+
const workspace = await createNxWorkspace();
|
|
98
102
|
const root = workspace.context.workspaceRoot;
|
|
99
103
|
const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
|
100
104
|
try {
|
|
@@ -142,12 +146,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
142
146
|
const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'app:build'], {
|
|
143
147
|
cwd: root,
|
|
144
148
|
env: {
|
|
145
|
-
...
|
|
149
|
+
...fixtureNxEnv(root),
|
|
146
150
|
PATH: `${join(repositoryRoot, 'node_modules/.bin')}:${process.env.PATH ?? ''}`,
|
|
147
|
-
NX_DAEMON: 'false',
|
|
148
|
-
NX_ISOLATE_PLUGINS: 'false',
|
|
149
|
-
NX_WORKSPACE_DATA_DIRECTORY: join(root, '.nx/workspace-data'),
|
|
150
|
-
NX_CACHE_DIRECTORY: join(root, '.nx/cache'),
|
|
151
151
|
},
|
|
152
152
|
stdout: 'pipe',
|
|
153
153
|
stderr: 'pipe',
|
|
@@ -173,7 +173,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
173
173
|
// would have claimed on the first run.
|
|
174
174
|
expect(await artifact(), second.output).toBe('source\ntoolchain-2\n');
|
|
175
175
|
} finally {
|
|
176
|
-
await workspace
|
|
176
|
+
await cleanupNxWorkspace(workspace);
|
|
177
177
|
}
|
|
178
178
|
}, 120_000);
|
|
179
179
|
|
|
@@ -841,11 +841,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
841
841
|
expect(targets['cargo-fetch']?.options).toEqual({
|
|
842
842
|
commands: ['cargo fetch --locked'],
|
|
843
843
|
cwd: 'packages/ferris',
|
|
844
|
-
parallel: false,
|
|
845
844
|
});
|
|
846
|
-
// Every frozen cargo command carries the edge
|
|
847
|
-
//
|
|
848
|
-
// needs the locked graph downloaded whether or not the chain runs first.
|
|
845
|
+
// Every frozen cargo command carries the edge: offline cargo fails at
|
|
846
|
+
// resolution, so each one needs the locked graph downloaded before it runs.
|
|
849
847
|
for (const name of [
|
|
850
848
|
'cargo-test-compile',
|
|
851
849
|
'cargo-test-archive',
|
|
@@ -882,17 +880,18 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
882
880
|
expect(targets['cargo-test-archive']?.executor).toBe('nx:run-commands');
|
|
883
881
|
expect(targets['cargo-test-archive']?.cache).toBe(true);
|
|
884
882
|
expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/target/nextest/archive.tar.zst']);
|
|
885
|
-
expect(targets['cargo-test-archive']?.options).toMatchObject({ cwd: 'packages/ferris'
|
|
883
|
+
expect(targets['cargo-test-archive']?.options).toMatchObject({ cwd: 'packages/ferris' });
|
|
886
884
|
// nextest does not create the archive's parent directory and fails the
|
|
887
885
|
// whole build if it is missing (measured: "error writing to archive").
|
|
888
|
-
|
|
886
|
+
// The directory and the archive are ONE command, in the order the archive needs.
|
|
887
|
+
expect(targets['cargo-test-archive']?.options?.commands).toBeUndefined();
|
|
889
888
|
// `--tool-config-file`, never `--config-file`: the plugin's settings must
|
|
890
889
|
// sit UNDER the repository's `.config/nextest.toml`, which is the only
|
|
891
890
|
// place an `archive.include` for a cdylib or fixture can be declared.
|
|
892
891
|
// `$PWD` because tool config paths must be absolute and an absolute path
|
|
893
892
|
// in the command text would split one cache entry per checkout.
|
|
894
|
-
expect(String(targets['cargo-test-archive']?.options?.
|
|
895
|
-
/^cargo --frozen nextest archive --workspace --archive-file target\/nextest\/archive\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
893
|
+
expect(String(targets['cargo-test-archive']?.options?.command)).toMatch(
|
|
894
|
+
/^mkdir -p target\/nextest && cargo --frozen nextest archive --workspace --archive-file target\/nextest\/archive\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
896
895
|
);
|
|
897
896
|
expect(targets['cargo-test-archive']?.inputs).toContain('{projectRoot}/.config/nextest.toml');
|
|
898
897
|
// Tests compile the dev profile only. Nx forwards a run's configuration
|
|
@@ -956,6 +955,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
956
955
|
expect(targets.mutation?.cache).toBe(false);
|
|
957
956
|
expect(targets.mutation?.options).toMatchObject({ command: 'cargo --frozen mutants --workspace' });
|
|
958
957
|
expect(targets.bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
|
|
958
|
+
expectNoSchedulerThrottle(targets);
|
|
959
959
|
} finally {
|
|
960
960
|
await workspace.cleanup();
|
|
961
961
|
}
|
|
@@ -1040,6 +1040,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1040
1040
|
`biome check --files-ignore-unknown=true '${root}'`,
|
|
1041
1041
|
`eslint '${root}/src/index.ts'`,
|
|
1042
1042
|
]);
|
|
1043
|
+
expectNoSchedulerThrottle(mixed);
|
|
1043
1044
|
} finally {
|
|
1044
1045
|
await workspace.cleanup();
|
|
1045
1046
|
}
|
|
@@ -1070,7 +1071,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1070
1071
|
'',
|
|
1071
1072
|
].join('\n'),
|
|
1072
1073
|
);
|
|
1073
|
-
await workspace.write('Cargo.lock', 'version = 4\n');
|
|
1074
1074
|
await workspace.write(
|
|
1075
1075
|
'packages/runtime/crates/runtime-core/Cargo.toml',
|
|
1076
1076
|
'[package]\nname = "runtime-core"\n\n[package.metadata.smoothbricks.test]\nshards = 2\n',
|
|
@@ -1117,7 +1117,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1117
1117
|
expect(root['cargo-fetch']?.options).toEqual({
|
|
1118
1118
|
commands: ['cargo fetch --locked'],
|
|
1119
1119
|
cwd: '.',
|
|
1120
|
-
parallel: false,
|
|
1121
1120
|
});
|
|
1122
1121
|
expect(root['cargo-test-compile']?.options).toMatchObject({
|
|
1123
1122
|
command: 'cargo --frozen test --workspace --no-run',
|
|
@@ -1127,14 +1126,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1127
1126
|
expect(String(root['cargo-lint']?.options?.commands?.[1])).toContain('clippy --workspace');
|
|
1128
1127
|
expect(root['cargo-lint']?.options?.cwd).toBe(root['cargo-test-compile']?.options?.cwd);
|
|
1129
1128
|
expect(root['cargo-lint']?.dependsOn).toContain('cargo-fetch');
|
|
1130
|
-
expect(root['cargo-test']?.dependsOn).toHaveLength(
|
|
1129
|
+
expect(root['cargo-test']?.dependsOn).toHaveLength(6);
|
|
1131
1130
|
|
|
1132
1131
|
// Root mode: every piece of every project hangs off the one root archive,
|
|
1133
1132
|
// in any order. The crate is selected by filterset alone — `-p` would
|
|
1134
1133
|
// re-resolve features, and there is nothing left to build anyway.
|
|
1135
1134
|
expect(runtime['cargo-test-runtime-core-shard1']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1136
1135
|
expect(runtime['cargo-test-runtime-core-shard2']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1137
|
-
expect(runtime['cargo-test-runtime-core-exceptions']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1136
|
+
expect(runtime['cargo-test-runtime-core-exceptions-shard1']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1137
|
+
expect(runtime['cargo-test-runtime-core-exceptions-shard2']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1138
1138
|
expect(runtime['cargo-test-runtime-core-shard1']?.options).toMatchObject({ cwd: '.' });
|
|
1139
1139
|
// At the root the helper is the root's own `node_modules` link, no `../`.
|
|
1140
1140
|
expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toStartWith(
|
|
@@ -1147,7 +1147,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1147
1147
|
expect(runtime['cargo-test']?.dependsOn).toEqual([
|
|
1148
1148
|
'cargo-test-runtime-core-shard1',
|
|
1149
1149
|
'cargo-test-runtime-core-shard2',
|
|
1150
|
-
'cargo-test-runtime-core-exceptions',
|
|
1150
|
+
'cargo-test-runtime-core-exceptions-shard1',
|
|
1151
|
+
'cargo-test-runtime-core-exceptions-shard2',
|
|
1151
1152
|
]);
|
|
1152
1153
|
// A package owning crates validates through the root's one clippy verdict.
|
|
1153
1154
|
expect(runtime['cargo-lint']?.dependsOn).toEqual([{ projects: [rootProject], target: 'cargo-lint' }]);
|
|
@@ -1159,14 +1160,19 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1159
1160
|
expect(wasm['cargo-wasm']?.options).toMatchObject({ cwd: '.' });
|
|
1160
1161
|
// Dev by default, in the workspace's own `target/`; only the release
|
|
1161
1162
|
// configuration compiles, and binds, the release artifact.
|
|
1162
|
-
expect(wasm['cargo-wasm']?.options?.
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
])
|
|
1163
|
+
expect(wasm['cargo-wasm']?.options?.command).toBe(
|
|
1164
|
+
[
|
|
1165
|
+
'cargo --frozen build --target wasm32-unknown-unknown -p runtime-wasm',
|
|
1166
|
+
'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/debug/runtime_wasm.wasm',
|
|
1167
|
+
].join(' && '),
|
|
1168
|
+
);
|
|
1169
|
+
expect(wasm['cargo-wasm']?.options?.commands).toBeUndefined();
|
|
1170
|
+
expect(wasm['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
|
|
1171
|
+
command: [
|
|
1172
|
+
'cargo --frozen build --release --target wasm32-unknown-unknown -p runtime-wasm',
|
|
1173
|
+
'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/release/runtime_wasm.wasm',
|
|
1174
|
+
].join(' && '),
|
|
1175
|
+
});
|
|
1170
1176
|
expect(wasm['cargo-wasm']?.outputs).toEqual(['{projectRoot}/dist-wasm']);
|
|
1171
1177
|
expect(wasm['cargo-wasm']?.dependsOn).toEqual([rootFetch, '^build']);
|
|
1172
1178
|
expect(wasm.build?.dependsOn).toContainEqual(rootCompile);
|
|
@@ -1175,7 +1181,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1175
1181
|
// The crate whose project also builds the debug cdylib keeps that edge:
|
|
1176
1182
|
// its tests load the artifact `napi-debug` writes into `target/debug`.
|
|
1177
1183
|
expect(native['cargo-test-native-napi']?.dependsOn).toEqual([rootFetch, rootArchive, 'napi-debug']);
|
|
1178
|
-
|
|
1184
|
+
// The addon build consumes only its dependencies' outputs; it is not
|
|
1185
|
+
// ordered behind the test compile.
|
|
1186
|
+
expect(native['napi-debug']?.dependsOn).toEqual(['^build']);
|
|
1179
1187
|
// The addon depends on the package's napi block and the napi CLI's version,
|
|
1180
1188
|
// never on the package version or the whole lockfile: a release bumps both
|
|
1181
1189
|
// before it builds, and that must not recompile the native code.
|
|
@@ -1204,6 +1212,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1204
1212
|
});
|
|
1205
1213
|
expect(native.build?.dependsOn).toContainEqual(rootCompile);
|
|
1206
1214
|
expect(native.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
1215
|
+
for (const inferred of [root, runtime, wasm, native]) {
|
|
1216
|
+
expectNoSchedulerThrottle(inferred);
|
|
1217
|
+
}
|
|
1207
1218
|
} finally {
|
|
1208
1219
|
await workspace.cleanup();
|
|
1209
1220
|
}
|
|
@@ -1535,30 +1546,31 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1535
1546
|
inputs: expect.arrayContaining(['{projectRoot}/**/*.rs', '{projectRoot}/**/Cargo.toml']),
|
|
1536
1547
|
outputs: ['{projectRoot}/generated/wasm'],
|
|
1537
1548
|
options: {
|
|
1538
|
-
|
|
1549
|
+
command: [
|
|
1539
1550
|
'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
|
|
1540
1551
|
'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
|
|
1541
1552
|
'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
|
|
1542
|
-
],
|
|
1553
|
+
].join(' && '),
|
|
1543
1554
|
cwd: 'packages/git-do',
|
|
1544
|
-
parallel: false,
|
|
1545
1555
|
},
|
|
1546
1556
|
});
|
|
1547
1557
|
// No workspace claims the crate, so cargo's default target dir is the one
|
|
1548
1558
|
// beside its own manifest, and the release configuration reads the
|
|
1549
1559
|
// release artifact from it.
|
|
1550
|
-
expect(targets['cargo-wasm']?.
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1560
|
+
expect(targets['cargo-wasm']?.options?.commands).toBeUndefined();
|
|
1561
|
+
expect(targets['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
|
|
1562
|
+
command: [
|
|
1563
|
+
'cargo --frozen build --release --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
|
|
1564
|
+
'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
|
|
1565
|
+
'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
|
|
1566
|
+
].join(' && '),
|
|
1567
|
+
});
|
|
1555
1568
|
// A wasm-bindgen crate in a nested Cargo workspace still needs its locked
|
|
1556
1569
|
// graph downloaded, and the project root is not a member of it, so the
|
|
1557
1570
|
// fetch names the crate manifest instead of relying on cwd.
|
|
1558
1571
|
expect(targets['cargo-fetch']?.options).toEqual({
|
|
1559
1572
|
commands: ['cargo fetch --locked --manifest-path crates/git-do/Cargo.toml'],
|
|
1560
1573
|
cwd: 'packages/git-do',
|
|
1561
|
-
parallel: false,
|
|
1562
1574
|
});
|
|
1563
1575
|
expect(targets['tsc-js']?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
|
|
1564
1576
|
expect(targets.typecheck?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
|
|
@@ -1568,6 +1580,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1568
1580
|
// workspace-wide cargo-test/lint policy.
|
|
1569
1581
|
expect(targets['cargo-test']).toBeUndefined();
|
|
1570
1582
|
expect(targets['cargo-lint']).toBeUndefined();
|
|
1583
|
+
expectNoSchedulerThrottle(targets);
|
|
1571
1584
|
} finally {
|
|
1572
1585
|
await workspace.cleanup();
|
|
1573
1586
|
}
|
|
@@ -1637,9 +1650,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1637
1650
|
expect(unservedHostTargets['cargo-napi']).toMatchObject({
|
|
1638
1651
|
executor: 'nx:run-commands',
|
|
1639
1652
|
cache: true,
|
|
1640
|
-
// The dedicated host build
|
|
1641
|
-
//
|
|
1642
|
-
dependsOn: ['^build'
|
|
1653
|
+
// The dedicated host build consumes only its dependencies' outputs; it is
|
|
1654
|
+
// not ordered behind the test compile.
|
|
1655
|
+
dependsOn: ['^build'],
|
|
1643
1656
|
outputs: ['{projectRoot}/dist/native/host'],
|
|
1644
1657
|
options: {
|
|
1645
1658
|
cwd: 'packages/cowshed',
|
|
@@ -1663,10 +1676,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1663
1676
|
command: darwinArm64Build(' --release'),
|
|
1664
1677
|
});
|
|
1665
1678
|
expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
|
|
1666
|
-
// No cargo-test-compile edge here, on ANY host:
|
|
1667
|
-
// dependency closure may only reach
|
|
1668
|
-
// (`validatePlatformTargetDependencies`)
|
|
1669
|
-
// cargo's flock rather than on a graph edge.
|
|
1679
|
+
// No cargo-test-compile edge here, on ANY host: the platform build consumes
|
|
1680
|
+
// nothing from it, and a platform target's dependency closure may only reach
|
|
1681
|
+
// its own family (`validatePlatformTargetDependencies`).
|
|
1670
1682
|
expect(targets['napi-arm64-macos']?.dependsOn).toBeUndefined();
|
|
1671
1683
|
// A macOS triple never gets a cross toolchain: `usesNapiCross` is
|
|
1672
1684
|
// `family === 'linux' && target !== host`, so the family decides this one
|
|
@@ -1766,11 +1778,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1766
1778
|
.sort();
|
|
1767
1779
|
expect(hostNapiTargets.length).toBeGreaterThan(0);
|
|
1768
1780
|
expect(inferred.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'tsc-js', ...hostNapiTargets]);
|
|
1769
|
-
// Crate `cowshed-napi` names its bounded runner
|
|
1770
|
-
//
|
|
1771
|
-
//
|
|
1772
|
-
// that single edge put the whole cargo test suite inside
|
|
1773
|
-
// `nx run-many -t build`.
|
|
1781
|
+
// Crate `cowshed-napi` names its bounded runner `cargo-test-cowshed-napi`;
|
|
1782
|
+
// the retired `*-napi` output-family glob matched it on suffix alone and
|
|
1783
|
+
// put the whole cargo test suite inside `nx run-many -t build`.
|
|
1774
1784
|
expect(inferred['cargo-test-cowshed-napi']).toBeDefined();
|
|
1775
1785
|
for (const dependency of inferred.build?.dependsOn ?? []) {
|
|
1776
1786
|
expect(String(dependency).startsWith('cargo-test-')).toBe(dependency === 'cargo-test-compile');
|
|
@@ -1789,7 +1799,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1789
1799
|
expect(targets['napi-debug']).toMatchObject({
|
|
1790
1800
|
executor: 'nx:run-commands',
|
|
1791
1801
|
cache: true,
|
|
1792
|
-
dependsOn: ['^build'
|
|
1802
|
+
dependsOn: ['^build'],
|
|
1793
1803
|
outputs: ['{projectRoot}/.cache/native-debug'],
|
|
1794
1804
|
options: {
|
|
1795
1805
|
cwd: 'packages/cowshed',
|
|
@@ -1822,6 +1832,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1822
1832
|
killAfterMs: 10000,
|
|
1823
1833
|
},
|
|
1824
1834
|
});
|
|
1835
|
+
expectNoSchedulerThrottle(targets);
|
|
1825
1836
|
await workspace.write('packages/cowshed/bunfig.napi-test.toml', '[test]\n');
|
|
1826
1837
|
const targetsWithDedicatedBunfig = await inferProjectTargets(workspace, 'packages/cowshed/package.json');
|
|
1827
1838
|
expect(targetsWithDedicatedBunfig['napi-test']?.options?.command).toBe(
|
|
@@ -1885,16 +1896,18 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1885
1896
|
|
|
1886
1897
|
// Cargo writes a member's artifacts under its workspace root, not beside
|
|
1887
1898
|
// the member's manifest, so the bindgen input is read from there.
|
|
1888
|
-
expect(targets['cargo-wasm']?.options?.
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1899
|
+
expect(targets['cargo-wasm']?.options?.command).toBe(
|
|
1900
|
+
[
|
|
1901
|
+
'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/columine-wasm/Cargo.toml',
|
|
1902
|
+
'wasm-bindgen --target web --out-dir dist-wasm/web target/wasm32-unknown-unknown/debug/columine_wasm.wasm',
|
|
1903
|
+
].join(' && '),
|
|
1904
|
+
);
|
|
1892
1905
|
} finally {
|
|
1893
1906
|
await workspace.cleanup();
|
|
1894
1907
|
}
|
|
1895
1908
|
});
|
|
1896
1909
|
|
|
1897
|
-
it('
|
|
1910
|
+
it('partitions ordinary and exceptional tests into disjoint hash shards of the same declared count', async () => {
|
|
1898
1911
|
const workspace = await createWorkspace();
|
|
1899
1912
|
try {
|
|
1900
1913
|
await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
|
|
@@ -1913,8 +1926,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1913
1926
|
/--workspace-remap \. -E 'package\(small\)' --no-tests=pass --user-config-file none/,
|
|
1914
1927
|
);
|
|
1915
1928
|
// The shards partition the crate MINUS the classes nextest.toml singles
|
|
1916
|
-
// out, i of N. Those are lifted out because a test
|
|
1917
|
-
// within one nextest run, and because a test carrying a raised
|
|
1929
|
+
// out, i of N. Those are lifted out because a test carrying a raised
|
|
1918
1930
|
// slow-timeout costs what the suite does not — the compile-fail test
|
|
1919
1931
|
// rustc's a fixture for 25.6s on a cold target dir against 1.8s warm.
|
|
1920
1932
|
const exceptional = exceptionalTestFilter(fileURLToPath(new URL('../nextest.toml', import.meta.url)));
|
|
@@ -1927,30 +1939,39 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1927
1939
|
);
|
|
1928
1940
|
expect(targets[`cargo-test-big-shard${index}`]?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
|
|
1929
1941
|
}
|
|
1930
|
-
//
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1942
|
+
// Exceptional partitions are the exact complement, hashed by the same
|
|
1943
|
+
// declared count; each keeps the full bounded window.
|
|
1944
|
+
for (const index of [1, 2, 3]) {
|
|
1945
|
+
const name = `cargo-test-big-exceptions-shard${index}`;
|
|
1946
|
+
expect(targets[name]?.options?.command).toContain(
|
|
1947
|
+
`-E 'package(big) and (${exceptional})' --partition hash:${index}/3 --no-tests=pass`,
|
|
1948
|
+
);
|
|
1949
|
+
expect(targets[name]?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
|
|
1950
|
+
expect(packageNameFromCargoTestTarget(name)).toBe('big');
|
|
1951
|
+
}
|
|
1952
|
+
expect(targets['cargo-test-big-exceptions']).toBeUndefined();
|
|
1936
1953
|
// An unsharded crate needs no pin: its whole suite is already one run.
|
|
1937
1954
|
expect(targets['cargo-test-small-exceptions']).toBeUndefined();
|
|
1938
1955
|
expect(targets['cargo-test-big']).toBeUndefined();
|
|
1939
1956
|
// Every piece reaches the aggregate, and they all hang off the one
|
|
1940
1957
|
// archive: a run extracts binaries to its own temp directory and writes
|
|
1941
|
-
// nothing to cargo's
|
|
1958
|
+
// nothing to cargo's target/, so no piece waits on another.
|
|
1942
1959
|
expect(targets['cargo-test']?.dependsOn).toEqual([
|
|
1943
1960
|
'cargo-test-big-shard1',
|
|
1944
1961
|
'cargo-test-big-shard2',
|
|
1945
1962
|
'cargo-test-big-shard3',
|
|
1946
|
-
'cargo-test-big-exceptions',
|
|
1963
|
+
'cargo-test-big-exceptions-shard1',
|
|
1964
|
+
'cargo-test-big-exceptions-shard2',
|
|
1965
|
+
'cargo-test-big-exceptions-shard3',
|
|
1947
1966
|
'cargo-test-small',
|
|
1948
1967
|
]);
|
|
1949
1968
|
for (const name of [
|
|
1950
1969
|
'cargo-test-big-shard1',
|
|
1951
1970
|
'cargo-test-big-shard2',
|
|
1952
1971
|
'cargo-test-big-shard3',
|
|
1953
|
-
'cargo-test-big-exceptions',
|
|
1972
|
+
'cargo-test-big-exceptions-shard1',
|
|
1973
|
+
'cargo-test-big-exceptions-shard2',
|
|
1974
|
+
'cargo-test-big-exceptions-shard3',
|
|
1954
1975
|
'cargo-test-small',
|
|
1955
1976
|
]) {
|
|
1956
1977
|
expect(targets[name]?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
@@ -1958,7 +1979,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1958
1979
|
// Pieces of one crate share its inputs: they are one suite, split only to
|
|
1959
1980
|
// fit the bound, so any change to the crate invalidates all of them.
|
|
1960
1981
|
expect(targets['cargo-test-big-shard2']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
1961
|
-
expect(targets['cargo-test-big-exceptions']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
1982
|
+
expect(targets['cargo-test-big-exceptions-shard1']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
1983
|
+
// Exceptional pieces fan out like the ordinary ones: nothing is exclusive.
|
|
1984
|
+
expectNoSchedulerThrottle(targets);
|
|
1962
1985
|
} finally {
|
|
1963
1986
|
await workspace.cleanup();
|
|
1964
1987
|
}
|
|
@@ -2050,7 +2073,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2050
2073
|
// One added edge per target. Everything that makes each target do its job
|
|
2051
2074
|
// — executor, options, inputs, cache — must survive the declaration
|
|
2052
2075
|
// instead of being replaced wholesale by it.
|
|
2053
|
-
'cargo-test': { dependsOn: ['cargo-test-
|
|
2076
|
+
'cargo-test': { dependsOn: ['cargo-test-ferris-core', 'cargo-wasm'] },
|
|
2054
2077
|
'cargo-test-compile': { dependsOn: ['cargo-wasm'] },
|
|
2055
2078
|
'cargo-lint': { inputs: ['{projectRoot}/clippy.toml'] },
|
|
2056
2079
|
mutation: { options: { command: 'cargo mutants --in-diff' } },
|
|
@@ -2061,30 +2084,27 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2061
2084
|
'packages/ferris/package.json',
|
|
2062
2085
|
JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
|
|
2063
2086
|
);
|
|
2064
|
-
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = []\n');
|
|
2087
|
+
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/ferris-core"]\n');
|
|
2088
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
2065
2089
|
|
|
2066
2090
|
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
2067
2091
|
|
|
2068
|
-
//
|
|
2069
|
-
//
|
|
2070
|
-
|
|
2071
|
-
expect(targets['cargo-test']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
2092
|
+
// The aggregate stays a no-op that reaches bounded crate runners. A
|
|
2093
|
+
// partial declaration must keep that inferred base, not erase the chain.
|
|
2094
|
+
expect(targets['cargo-test']?.executor).toBe('nx:noop');
|
|
2095
|
+
expect(targets['cargo-test-ferris-core']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
2072
2096
|
expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
|
|
2073
2097
|
expect(targets['cargo-lint']?.options).toMatchObject({
|
|
2074
2098
|
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
2075
2099
|
});
|
|
2076
2100
|
|
|
2077
2101
|
const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
|
|
2078
|
-
expect(cargoTest?.executor).toBe('
|
|
2102
|
+
expect(cargoTest?.executor).toBe('nx:noop');
|
|
2079
2103
|
expect(cargoTest?.cache).toBe(true);
|
|
2080
|
-
expect(cargoTest?.dependsOn).toEqual(['cargo-test-
|
|
2081
|
-
expect(cargoTest?.options).
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
timeoutMs: 120000,
|
|
2085
|
-
killAfterMs: 10000,
|
|
2086
|
-
});
|
|
2087
|
-
expect(cargoTest?.inputs).toContain('{projectRoot}/**/*.rs');
|
|
2104
|
+
expect(cargoTest?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-wasm']);
|
|
2105
|
+
expect(cargoTest?.options).toBeUndefined();
|
|
2106
|
+
expect(targets['cargo-test-ferris-core']?.options?.command).toContain("-E 'package(ferris-core)'");
|
|
2107
|
+
expect(targets['cargo-test-ferris-core']?.options?.timeoutMs).toBe(120000);
|
|
2088
2108
|
|
|
2089
2109
|
const cargoTestCompile = resolveDeclaredOverInferred(targets, declared, 'cargo-test-compile');
|
|
2090
2110
|
expect(cargoTestCompile?.executor).toBe('nx:run-commands');
|
|
@@ -2119,7 +2139,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2119
2139
|
it('lets a declared dependsOn spread expand the inferred cargo chain', async () => {
|
|
2120
2140
|
const workspace = await createWorkspace();
|
|
2121
2141
|
// Additive intent has Nx's own spelling: `'...'` expands the inferred list
|
|
2122
|
-
// at the token, so an added edge keeps the cargo
|
|
2142
|
+
// at the token, so an added edge keeps the inferred cargo edges.
|
|
2123
2143
|
const declared: Record<string, TargetConfiguration> = {
|
|
2124
2144
|
'cargo-test': { dependsOn: ['...', 'cargo-wasm'] },
|
|
2125
2145
|
};
|
|
@@ -2128,15 +2148,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2128
2148
|
'packages/ferris/package.json',
|
|
2129
2149
|
JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
|
|
2130
2150
|
);
|
|
2131
|
-
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = []\n');
|
|
2151
|
+
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/ferris-core"]\n');
|
|
2152
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
2132
2153
|
|
|
2133
2154
|
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
2134
2155
|
|
|
2135
2156
|
// The spread expands exactly once, against the single inferred base this
|
|
2136
2157
|
// plugin emits — re-implementing the overlay here would double it.
|
|
2137
2158
|
const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
|
|
2138
|
-
expect(cargoTest?.dependsOn).toEqual(['cargo-
|
|
2139
|
-
expect(cargoTest?.executor).toBe('
|
|
2159
|
+
expect(cargoTest?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-wasm']);
|
|
2160
|
+
expect(cargoTest?.executor).toBe('nx:noop');
|
|
2140
2161
|
} finally {
|
|
2141
2162
|
await workspace.cleanup();
|
|
2142
2163
|
}
|
|
@@ -2275,7 +2296,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2275
2296
|
});
|
|
2276
2297
|
|
|
2277
2298
|
it('orders a three-project chain of INFERRED deploys through one run-many', async () => {
|
|
2278
|
-
const workspace = await
|
|
2299
|
+
const workspace = await createNxWorkspace();
|
|
2279
2300
|
const root = workspace.context.workspaceRoot;
|
|
2280
2301
|
const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
|
2281
2302
|
try {
|
|
@@ -2330,12 +2351,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2330
2351
|
{
|
|
2331
2352
|
cwd: root,
|
|
2332
2353
|
env: {
|
|
2333
|
-
...
|
|
2354
|
+
...fixtureNxEnv(root),
|
|
2334
2355
|
PATH: `${join(repositoryRoot, 'node_modules/.bin')}:${process.env.PATH ?? ''}`,
|
|
2335
|
-
NX_DAEMON: 'false',
|
|
2336
|
-
NX_ISOLATE_PLUGINS: 'false',
|
|
2337
|
-
NX_WORKSPACE_DATA_DIRECTORY: join(root, '.nx/workspace-data'),
|
|
2338
|
-
NX_CACHE_DIRECTORY: join(root, '.nx/cache'),
|
|
2339
2356
|
},
|
|
2340
2357
|
stdout: 'pipe',
|
|
2341
2358
|
stderr: 'pipe',
|
|
@@ -2350,7 +2367,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2350
2367
|
const order = (await readFile(join(root, 'deploy-order.txt'), 'utf8')).trim().split('\n');
|
|
2351
2368
|
expect(order).toEqual(['c', 'b', 'a']);
|
|
2352
2369
|
} finally {
|
|
2353
|
-
await workspace
|
|
2370
|
+
await cleanupNxWorkspace(workspace);
|
|
2354
2371
|
}
|
|
2355
2372
|
}, 120_000);
|
|
2356
2373
|
|
|
@@ -2386,11 +2403,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2386
2403
|
expect(archive?.options?.env).toEqual({ CARGO: 'scripts/cargo-for-nextest.sh' });
|
|
2387
2404
|
// The runner needs no driver: it never invokes cargo at all.
|
|
2388
2405
|
expect(run?.options?.env).toBeUndefined();
|
|
2389
|
-
expect(archive?.options?.commands
|
|
2406
|
+
expect(archive?.options?.commands).toBeUndefined();
|
|
2390
2407
|
// `cargo-nextest`, not `cargo nextest`: cargo overwrites CARGO for its
|
|
2391
2408
|
// subcommands, and CARGO is the only seam a cross cargo driver has.
|
|
2392
|
-
expect(String(archive?.options?.
|
|
2393
|
-
/^cargo-nextest nextest archive --workspace --target aarch64-apple-darwin --frozen --archive-file target\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
2409
|
+
expect(String(archive?.options?.command)).toMatch(
|
|
2410
|
+
/^mkdir -p target\/nextest && cargo-nextest nextest archive --workspace --target aarch64-apple-darwin --frozen --archive-file target\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
2394
2411
|
);
|
|
2395
2412
|
expect(archive?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
|
|
2396
2413
|
expect(run?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
|
|
@@ -2409,6 +2426,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2409
2426
|
expect(packageNameFromCargoTestTarget('cargo-cross-test-aarch64-apple-darwin')).toBeNull();
|
|
2410
2427
|
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core']);
|
|
2411
2428
|
expect(targets.build?.dependsOn ?? []).not.toContain('cargo-cross-test-archive-aarch64-apple-darwin');
|
|
2429
|
+
expectNoSchedulerThrottle(targets);
|
|
2412
2430
|
} finally {
|
|
2413
2431
|
await workspace.cleanup();
|
|
2414
2432
|
}
|
|
@@ -2440,8 +2458,50 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
2440
2458
|
//#endregion
|
|
2441
2459
|
});
|
|
2442
2460
|
|
|
2461
|
+
/**
|
|
2462
|
+
* Target-inference fixtures declare real Cargo workspaces. Supply their empty
|
|
2463
|
+
* Rust library and initial lock before inference, rather than relying on a
|
|
2464
|
+
* rejected Cargo query. Explicit sources and locks, including planted failures,
|
|
2465
|
+
* remain untouched.
|
|
2466
|
+
*/
|
|
2467
|
+
async function prepareCargoFixture(root: string): Promise<void> {
|
|
2468
|
+
const manifests = (await readdir(root, { recursive: true }))
|
|
2469
|
+
.filter((path) => path === 'Cargo.toml' || path.endsWith('/Cargo.toml'))
|
|
2470
|
+
.filter((path) => !path.split('/').some((part) => ['node_modules', 'target', '.nx'].includes(part)));
|
|
2471
|
+
const workspaces: string[] = [];
|
|
2472
|
+
for (const manifest of manifests) {
|
|
2473
|
+
const path = join(root, manifest);
|
|
2474
|
+
const contents = await readFile(path, 'utf8');
|
|
2475
|
+
if (/^\[package\]\s*$/m.test(contents)) {
|
|
2476
|
+
const source = join(dirname(path), 'src/lib.rs');
|
|
2477
|
+
if (!(await Bun.file(source).exists())) {
|
|
2478
|
+
await mkdir(dirname(source), { recursive: true });
|
|
2479
|
+
await writeFile(source, '// Empty Cargo fixture library.\n');
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
if (/^\[workspace\]\s*$/m.test(contents)) workspaces.push(path);
|
|
2483
|
+
}
|
|
2484
|
+
for (const manifest of workspaces) {
|
|
2485
|
+
if (await Bun.file(join(dirname(manifest), 'Cargo.lock')).exists()) continue;
|
|
2486
|
+
const child = Bun.spawn(['cargo', 'generate-lockfile', '--offline', '--manifest-path', manifest], {
|
|
2487
|
+
env: process.env,
|
|
2488
|
+
cwd: root,
|
|
2489
|
+
stdout: 'pipe',
|
|
2490
|
+
stderr: 'pipe',
|
|
2491
|
+
});
|
|
2492
|
+
const [code, stdout, stderr] = await Promise.all([
|
|
2493
|
+
child.exited,
|
|
2494
|
+
new Response(child.stdout).text(),
|
|
2495
|
+
new Response(child.stderr).text(),
|
|
2496
|
+
]);
|
|
2497
|
+
if (code !== 0) throw new Error(`Cargo fixture ${manifest} could not lock:\n${stdout}${stderr}`);
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2443
2501
|
async function createWorkspace(): Promise<WorkspaceFixture> {
|
|
2444
|
-
|
|
2502
|
+
// Canonical, because macOS puts the temp directory behind a /private symlink
|
|
2503
|
+
// and a daemon never sees an edit made under a root named through one.
|
|
2504
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-')));
|
|
2445
2505
|
|
|
2446
2506
|
return {
|
|
2447
2507
|
context: {
|
|
@@ -2459,6 +2519,27 @@ async function createWorkspace(): Promise<WorkspaceFixture> {
|
|
|
2459
2519
|
};
|
|
2460
2520
|
}
|
|
2461
2521
|
|
|
2522
|
+
/**
|
|
2523
|
+
* A workspace that runs real Nx. It gets its own Git boundary, as every other
|
|
2524
|
+
* fixture here that runs Nx does: a daemon's ignore-aware watcher drops all of
|
|
2525
|
+
* a fixture's edits when an enclosing checkout ignores the temp directory.
|
|
2526
|
+
*/
|
|
2527
|
+
async function createNxWorkspace(): Promise<WorkspaceFixture> {
|
|
2528
|
+
const workspace = await createWorkspace();
|
|
2529
|
+
const initialized = Bun.spawnSync(['git', 'init', '--quiet', workspace.context.workspaceRoot]);
|
|
2530
|
+
expect(initialized.exitCode).toBe(0);
|
|
2531
|
+
return workspace;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
/** Release the fixture's own Nx daemon through Nx before its root is deleted. */
|
|
2535
|
+
async function cleanupNxWorkspace(workspace: WorkspaceFixture): Promise<void> {
|
|
2536
|
+
try {
|
|
2537
|
+
await stopFixtureNxDaemon(workspace.context.workspaceRoot);
|
|
2538
|
+
} finally {
|
|
2539
|
+
await workspace.cleanup();
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2462
2543
|
interface WorkspaceFixture {
|
|
2463
2544
|
context: CreateNodesContextV2;
|
|
2464
2545
|
write(filePath: string, contents: string): Promise<void>;
|
|
@@ -2546,6 +2627,7 @@ async function inferProject(
|
|
|
2546
2627
|
createNodes: CreateNodesV2 = createNodesV2,
|
|
2547
2628
|
) {
|
|
2548
2629
|
const [, infer] = createNodes;
|
|
2630
|
+
await prepareCargoFixture(workspace.context.workspaceRoot);
|
|
2549
2631
|
const result = await infer([packageJsonPath], undefined, workspace.context);
|
|
2550
2632
|
return result[0]?.[1].projects?.[dirname(packageJsonPath)];
|
|
2551
2633
|
}
|
|
@@ -2561,6 +2643,7 @@ async function inferProjectWithNxJson(
|
|
|
2561
2643
|
nxJsonConfiguration: CreateNodesContextV2['nxJsonConfiguration'],
|
|
2562
2644
|
) {
|
|
2563
2645
|
const [, infer] = createNodesV2;
|
|
2646
|
+
await prepareCargoFixture(workspace.context.workspaceRoot);
|
|
2564
2647
|
const result = await infer([packageJsonPath], undefined, {
|
|
2565
2648
|
workspaceRoot: workspace.context.workspaceRoot,
|
|
2566
2649
|
nxJsonConfiguration,
|
|
@@ -2629,3 +2712,16 @@ function cargoPackageSelection(command: string): {
|
|
|
2629
2712
|
),
|
|
2630
2713
|
};
|
|
2631
2714
|
}
|
|
2715
|
+
|
|
2716
|
+
/**
|
|
2717
|
+
* Inference never throttles the scheduler: no target is exclusive and no
|
|
2718
|
+
* run-commands target is run one command at a time. A pair that really is
|
|
2719
|
+
* producer and consumer is one `&&` command; everything else is left to Nx and
|
|
2720
|
+
* to the locks Cargo owns.
|
|
2721
|
+
*/
|
|
2722
|
+
function expectNoSchedulerThrottle(targets: Record<string, TargetConfiguration>): void {
|
|
2723
|
+
for (const [name, target] of Object.entries(targets)) {
|
|
2724
|
+
expect(target.parallelism, `${name} parallelism`).toBeUndefined();
|
|
2725
|
+
expect(target.options?.parallel, `${name} options.parallel`).toBeUndefined();
|
|
2726
|
+
}
|
|
2727
|
+
}
|