@smoothbricks/nx-plugin 0.3.1 → 0.3.3

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/src/index.test.ts CHANGED
@@ -5,21 +5,10 @@ import { dirname, join } from 'node:path';
5
5
 
6
6
  import type { CreateNodesContextV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
7
7
  import { createNodesV2 } from './index.js';
8
+ import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
8
9
 
9
10
  const [, inferTargets] = createNodesV2;
10
- const buildOutputDependencies = [
11
- '^build',
12
- '*-js',
13
- '*-web',
14
- '*-html',
15
- '*-css',
16
- '*-ios',
17
- '*-android',
18
- '*-native',
19
- '*-napi',
20
- '*-bun',
21
- '*-wasm',
22
- ];
11
+ const buildOutputDependencies = ['^build', ...BUILD_OUTPUT_DEPENDENCIES];
23
12
 
24
13
  describe('@smoothbricks/nx-plugin inferred targets', () => {
25
14
  it('names standalone package projects from package metadata', async () => {
@@ -43,6 +32,32 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
43
32
  }
44
33
  });
45
34
 
35
+ it('skips smoo managed raw package.json sources as projects', async () => {
36
+ const workspace = await createWorkspace();
37
+ try {
38
+ await workspace.write(
39
+ 'packages/cli/managed/raw/tooling/typescript-api/package.json',
40
+ '{"name":"@smoothbricks/typescript-api","private":true}\n',
41
+ );
42
+ await workspace.write(
43
+ 'tooling/typescript-api/package.json',
44
+ '{"name":"@smoothbricks/typescript-api","private":true}\n',
45
+ );
46
+
47
+ const managed = await inferTargets(
48
+ ['packages/cli/managed/raw/tooling/typescript-api/package.json'],
49
+ undefined,
50
+ workspace.context,
51
+ );
52
+ expect(managed[0]?.[1]).toEqual({});
53
+
54
+ const live = await inferProject(workspace, 'tooling/typescript-api/package.json');
55
+ expect(live?.name).toBe('@smoothbricks/typescript-api');
56
+ } finally {
57
+ await workspace.cleanup();
58
+ }
59
+ });
60
+
46
61
  it('overrides inferred TypeScript compiler commands with ttsc', async () => {
47
62
  const workspace = await createWorkspace();
48
63
  try {
@@ -71,6 +86,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
71
86
  ...toolchainInputs,
72
87
  '{projectRoot}/tsconfig.lib.json',
73
88
  ]);
89
+ expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']);
74
90
  expect(targets.typecheck?.options).toMatchObject({
75
91
  command: 'ttsc -p tsconfig.lib.json --noEmit',
76
92
  cwd: 'packages/example',
@@ -145,66 +161,57 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
145
161
  }
146
162
  });
147
163
 
148
- it('infers zig step targets and excludes reserved non-build steps', async () => {
164
+ it('infers aggregate build for package-local output targets without owning them', async () => {
149
165
  const workspace = await createWorkspace();
150
166
  try {
151
- await workspace.write('packages/ziggy/package.json', '{"name":"ziggy"}\n');
152
167
  await workspace.write(
153
- 'packages/ziggy/build.zig',
154
- [
155
- 'pub fn build(b: *std.Build) void {',
156
- ' _ = b.step("wasm", "Build wasm");',
157
- ' _ = b.step("native", "Build native");',
158
- ' _ = b.step("test", "Run tests");',
159
- ' _ = b.step("all", "Build everything");',
160
- ' _ = b.step("clean", "Clean outputs");',
161
- ' _ = b.step("install", "Install artifacts");',
162
- '}',
163
- '',
164
- ].join('\n'),
168
+ 'packages/tsdown/package.json',
169
+ JSON.stringify({ name: 'tsdown', nx: { targets: { 'tsdown-js': { executor: 'nx:run-commands' } } } }),
165
170
  );
166
171
 
167
- const targets = await inferProjectTargets(workspace, 'packages/ziggy/package.json');
172
+ const targets = await inferProjectTargets(workspace, 'packages/tsdown/package.json');
168
173
 
169
- expect(Object.keys(targets).sort()).toEqual(['build', 'clean', 'zig-native', 'zig-wasm']);
174
+ expect(targets['tsc-js']).toBeUndefined();
175
+ expect(targets['tsdown-js']).toBeUndefined();
176
+ expect(targets.build?.executor).toBe('nx:noop');
170
177
  expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
171
- expect(targets.build?.cache).toBe(true);
172
- expect(targets['zig-wasm']?.cache).toBe(true);
173
- expect(targets['zig-native']?.cache).toBe(true);
174
- expect(targets['zig-wasm']?.options).toEqual({
175
- command: 'zig build wasm',
176
- cwd: 'packages/ziggy',
177
- });
178
- expect(targets['zig-native']?.options).toEqual({
179
- command: 'zig build native',
180
- cwd: 'packages/ziggy',
181
- });
178
+ expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
182
179
  } finally {
183
180
  await workspace.cleanup();
184
181
  }
185
182
  });
186
183
 
187
- it('infers aggregate build for package-local output targets without owning them', async () => {
184
+ it('keeps platform-only output families out of the ordinary aggregate build', async () => {
188
185
  const workspace = await createWorkspace();
189
186
  try {
190
187
  await workspace.write(
191
- 'packages/tsdown/package.json',
192
- JSON.stringify({ name: 'tsdown', nx: { targets: { 'tsdown-js': { executor: 'nx:run-commands' } } } }),
188
+ 'packages/platform/package.json',
189
+ JSON.stringify({
190
+ name: 'platform',
191
+ nx: {
192
+ targets: {
193
+ 'bundle-ios': { executor: 'nx:run-commands' },
194
+ 'bundle-macos': { executor: 'nx:run-commands' },
195
+ 'bundle-linux': { executor: 'nx:run-commands' },
196
+ },
197
+ },
198
+ }),
193
199
  );
194
200
 
195
- const targets = await inferProjectTargets(workspace, 'packages/tsdown/package.json');
201
+ const targets = await inferProjectTargets(workspace, 'packages/platform/package.json');
196
202
 
197
- expect(targets['tsc-js']).toBeUndefined();
198
- expect(targets['tsdown-js']).toBeUndefined();
199
- expect(targets.build?.executor).toBe('nx:noop');
200
- expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
203
+ expect(targets.build).toBeUndefined();
201
204
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
205
+ expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-ios');
206
+ expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-macos');
207
+ expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-linux');
202
208
  } finally {
203
209
  await workspace.cleanup();
204
210
  }
205
211
  });
206
212
 
207
- it('infers cargo workspace targets including explicitly named wasm crate builds', async () => {
213
+ //#region smoo!n/rust-output-target-inference
214
+ it('infers generic cargo workspace targets without any rust output targets', async () => {
208
215
  const workspace = await createWorkspace();
209
216
  try {
210
217
  await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
@@ -220,17 +227,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
220
227
 
221
228
  const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
222
229
 
223
- expect(Object.keys(targets).sort()).toEqual([
224
- 'bench',
225
- 'build',
226
- 'cargo-lint',
227
- 'cargo-test',
228
- 'cargo-wasm',
229
- 'clean',
230
- 'lint',
231
- 'mutation',
232
- 'test',
233
- ]);
230
+ // Even a cdylib crate named *-wasm infers no cargo-wasm: rust output
231
+ // targets are declared package-locally, never derived from crate metadata.
232
+ expect(Object.keys(targets).sort()).toEqual(['bench', 'cargo-lint', 'cargo-test', 'lint', 'mutation', 'test']);
234
233
  expect(targets['cargo-test']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
235
234
  expect(targets['cargo-test']?.options).toMatchObject({
236
235
  command: 'cargo test --workspace',
@@ -254,19 +253,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
254
253
  });
255
254
  expect(targets.mutation?.cache).toBe(false);
256
255
  expect(targets.mutation?.options).toMatchObject({ command: 'cargo mutants --workspace' });
257
- expect(targets['cargo-wasm']?.outputs).toEqual(['{projectRoot}/dist/**/*.wasm']);
258
- expect(targets['cargo-wasm']?.options).toMatchObject({
259
- commands: [
260
- 'cargo build --profile wasm-release --target wasm32-unknown-unknown -p ferris-wasm && mkdir -p dist && cp target/wasm32-unknown-unknown/wasm-release/ferris_wasm.wasm dist/ferris_wasm.wasm',
261
- ],
262
- });
263
- expect(targets['cargo-wasm']?.configurations?.development).toEqual({
264
- commands: [
265
- 'cargo build --target wasm32-unknown-unknown -p ferris-wasm && mkdir -p dist && cp target/wasm32-unknown-unknown/debug/ferris_wasm.wasm dist/ferris_wasm.wasm',
266
- ],
267
- });
268
- // cargo-wasm matches the *-wasm build-output pattern → aggregate build/clean exist
269
- expect(targets.build?.executor).toBe('nx:noop');
256
+ expect(targets.bench?.options).toMatchObject({ command: 'cargo bench --workspace' });
270
257
  } finally {
271
258
  await workspace.cleanup();
272
259
  }
@@ -293,7 +280,45 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
293
280
  }
294
281
  });
295
282
 
296
- it('lets explicit nx.targets override wasm inference and skips non-workspace Cargo.toml', async () => {
283
+ it('keeps an explicit package-local cargo-wasm target singular and feeding the aggregate build', async () => {
284
+ const workspace = await createWorkspace();
285
+ try {
286
+ await workspace.write(
287
+ 'packages/columine/package.json',
288
+ JSON.stringify({
289
+ name: 'columine',
290
+ nx: {
291
+ targets: {
292
+ 'cargo-wasm': { executor: 'nx:run-commands', outputs: ['{projectRoot}/dist/**/*.wasm'] },
293
+ },
294
+ },
295
+ }),
296
+ );
297
+ await workspace.write(
298
+ 'packages/columine/Cargo.toml',
299
+ '[workspace]\nmembers = ["crates/columine-wasm"]\n\n[profile.wasm-release]\ninherits = "release"\n',
300
+ );
301
+ await workspace.write(
302
+ 'packages/columine/crates/columine-wasm/Cargo.toml',
303
+ '[package]\nname = "columine-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n',
304
+ );
305
+
306
+ const targets = await inferProjectTargets(workspace, 'packages/columine/package.json');
307
+
308
+ // The declared target stays the only cargo-wasm: inference never emits a
309
+ // duplicate for Nx to merge, even with a cdylib *-wasm member crate present.
310
+ expect(targets['cargo-wasm']).toBeUndefined();
311
+ // Its *-wasm output-family name feeds the aggregate build and clean.
312
+ expect(buildOutputDependencies).toContain('*-wasm');
313
+ expect(targets.build?.executor).toBe('nx:noop');
314
+ expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
315
+ expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
316
+ } finally {
317
+ await workspace.cleanup();
318
+ }
319
+ });
320
+
321
+ it('lets explicit nx.targets suppress cargo inference and skips non-workspace Cargo.toml', async () => {
297
322
  const workspace = await createWorkspace();
298
323
  try {
299
324
  await workspace.write(
@@ -320,20 +345,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
320
345
  await workspace.cleanup();
321
346
  }
322
347
  });
323
-
324
- it('leaves build.zig without b.step declarations to smoo validation', async () => {
325
- const workspace = await createWorkspace();
326
- try {
327
- await workspace.write('packages/broken/package.json', '{"name":"broken"}\n');
328
- await workspace.write('packages/broken/build.zig', 'pub fn build(_: *std.Build) void {}\n');
329
-
330
- const targets = await inferProjectTargets(workspace, 'packages/broken/package.json');
331
-
332
- expect(targets).toEqual({});
333
- } finally {
334
- await workspace.cleanup();
335
- }
336
- });
348
+ //#endregion
337
349
  });
338
350
 
339
351
  async function createWorkspace(): Promise<WorkspaceFixture> {
package/src/index.ts CHANGED
@@ -5,12 +5,9 @@ import { dirname, join } from 'node:path';
5
5
  import type { CreateNodesResultV2, CreateNodesV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
6
6
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
7
7
 
8
- import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
8
+ import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
9
9
 
10
- const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
11
- const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
12
- const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
13
- const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|ios|android|native|napi|bun|wasm)$/;
10
+ const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
14
11
  const TYPESCRIPT_TOOLCHAIN_INPUTS = [
15
12
  '{workspaceRoot}/package.json',
16
13
  '{workspaceRoot}/bun.lock',
@@ -18,19 +15,17 @@ const TYPESCRIPT_TOOLCHAIN_INPUTS = [
18
15
  '{workspaceRoot}/tsconfig.base.json',
19
16
  ];
20
17
 
18
+ //#region smoo!n/rust-output-target-inference
21
19
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
22
20
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
23
- // the lint aggregate, mutation (cargo-mutants), bench, and — per cdylib member
24
- // crate whose package name ends in `-wasm` — a cargo-wasm build producing
25
- // dist/<crate>.wasm. Explicit nx.targets entries in the package.json always win
26
- // over inference.
21
+ // the lint aggregate, mutation (cargo-mutants), and bench. Rust output targets
22
+ // (cargo-wasm, cargo-napi, ...) are never inferred from crate metadata such as
23
+ // cdylib crate-types — a native N-API cdylib is not a wasm build. Packages
24
+ // declare output targets in package.json nx.targets, and those *-wasm/*-napi/
25
+ // *-native output-family names feed the aggregate build and clean targets.
26
+ // Explicit nx.targets entries always win over inference.
27
27
  const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
28
- const CARGO_MEMBERS_PATTERN = /^\s*members\s*=\s*\[([^\]]*)\]/m;
29
- const CARGO_MEMBER_ENTRY_PATTERN = /["']([^"']+)["']/g;
30
- const CARGO_PACKAGE_NAME_PATTERN = /^\s*name\s*=\s*["']([^"']+)["']/m;
31
- const CARGO_WASM_CRATE_NAME_PATTERN = /-wasm$/;
32
- const CARGO_CDYLIB_CRATE_TYPE_PATTERN = /^\s*crate-type\s*=\s*\[[^\]]*["']cdylib["']/m;
33
- const CARGO_WASM_RELEASE_PROFILE_PATTERN = /^\s*\[profile\.wasm-release\]/m;
28
+ //#endregion
34
29
  const CARGO_INPUTS = [
35
30
  '{projectRoot}/**/*.rs',
36
31
  '{projectRoot}/**/Cargo.toml',
@@ -65,6 +60,12 @@ export const createNodesV2: CreateNodesV2 = [
65
60
  await Promise.all(
66
61
  projectConfigurationFiles.map(async (packageJsonPath) => {
67
62
  try {
63
+ if (isManagedPackageJsonSource(packageJsonPath)) {
64
+ // smoo monorepo managed raw/templates are source copies, not projects.
65
+ // Dogfood trees symlink live paths here; discovering both doubles names.
66
+ results.push([packageJsonPath, {}]);
67
+ return;
68
+ }
68
69
  results.push([packageJsonPath, await createProjectTargets(packageJsonPath, context.workspaceRoot)]);
69
70
  } catch (error) {
70
71
  errors.push([packageJsonPath, error instanceof Error ? error : new Error(String(error))]);
@@ -80,6 +81,11 @@ export const createNodesV2: CreateNodesV2 = [
80
81
  },
81
82
  ];
82
83
 
84
+ function isManagedPackageJsonSource(packageJsonPath: string): boolean {
85
+ const normalized = packageJsonPath.replaceAll('\\', '/');
86
+ return normalized.includes('/managed/raw/') || normalized.includes('/managed/templates/');
87
+ }
88
+
83
89
  export default { createNodesV2 };
84
90
 
85
91
  interface PackageJson {
@@ -98,7 +104,9 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
98
104
  const targets: Record<string, TargetConfiguration> = {};
99
105
  const validationTargets: string[] = [];
100
106
  const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
101
- let hasBuildOutputTarget = hasLibTsconfig || hasPackageLocalBuildOutputTarget(packageJson);
107
+ const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
108
+ const hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
109
+ const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
102
110
 
103
111
  if (hasLibTsconfig) {
104
112
  // Official Nx target inference is disabled because its compiler surface only
@@ -107,10 +115,7 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
107
115
  executor: 'nx:run-commands',
108
116
  cache: true,
109
117
  inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
110
- outputs: [
111
- '{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}',
112
- '{projectRoot}/dist/.build.tsbuildinfo',
113
- ],
118
+ outputs: ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'],
114
119
  dependsOn: ['^tsc-js'],
115
120
  options: {
116
121
  command: 'ttsc -p tsconfig.lib.json --emit',
@@ -167,8 +172,10 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
167
172
  validationTargets.push('typecheck');
168
173
  }
169
174
 
170
- const cargo = await readCargoWorkspace(absoluteProjectRoot);
171
- if (cargo) {
175
+ // Member crates get their targets from the workspace-root package.json,
176
+ // never per-crate — one Nx project per Cargo workspace.
177
+ const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
178
+ if (existsSync(cargoTomlPath) && CARGO_WORKSPACE_PATTERN.test(await readFile(cargoTomlPath, 'utf-8'))) {
172
179
  const declared = packageJson.nx?.targets ?? {};
173
180
  if (!('cargo-test' in declared)) {
174
181
  targets['cargo-test'] = createCargoTestTarget(projectRoot);
@@ -206,63 +213,16 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
206
213
  options: { command: 'cargo bench --workspace', cwd: projectRoot },
207
214
  };
208
215
  }
209
- if (cargo.wasmCrates.length > 0 && !('cargo-wasm' in declared)) {
210
- const profile = cargo.hasWasmReleaseProfile ? 'wasm-release' : 'release';
211
- const buildAndCopy = (crate: string, profileName: string | null) => {
212
- const artifact = crate.replace(/-/g, '_');
213
- const profileFlag = profileName === null ? '' : ` --profile ${profileName}`;
214
- const outputDirectory = profileName ?? 'debug';
215
- return `cargo build${profileFlag} --target wasm32-unknown-unknown -p ${crate} && mkdir -p dist && cp target/wasm32-unknown-unknown/${outputDirectory}/${artifact}.wasm dist/${artifact}.wasm`;
216
- };
217
- targets['cargo-wasm'] = {
218
- executor: 'nx:run-commands',
219
- cache: true,
220
- inputs: CARGO_INPUTS,
221
- outputs: ['{projectRoot}/dist/**/*.wasm'],
222
- options: {
223
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, profile)),
224
- cwd: projectRoot,
225
- parallel: false,
226
- },
227
- configurations: {
228
- development: {
229
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, null)),
230
- },
231
- },
232
- };
233
- hasBuildOutputTarget = true;
234
- }
235
216
  }
236
217
 
237
- const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
238
- for (const step of zigSteps) {
239
- const targetName = `zig-${step}`;
240
- targets[targetName] = {
241
- executor: 'nx:run-commands',
242
- cache: true,
243
- inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
244
- outputs: [
245
- '{projectRoot}/dist/**/*.wasm',
246
- '{projectRoot}/dist/**/*.node',
247
- '{projectRoot}/dist/**/*.dylib',
248
- '{projectRoot}/dist/**/*.so',
249
- '{projectRoot}/dist/**/*.dll',
250
- '{projectRoot}/dist/**/*.a',
251
- ],
252
- options: {
253
- command: `zig build ${step}`,
254
- cwd: projectRoot,
255
- },
256
- };
257
- hasBuildOutputTarget = true;
258
- }
259
-
260
- if (hasBuildOutputTarget) {
218
+ if (hasOrdinaryBuildOutputTarget) {
261
219
  targets.build = {
262
220
  executor: 'nx:noop',
263
221
  cache: true,
264
222
  dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
265
223
  };
224
+ }
225
+ if (hasAnyBuildOutputTarget) {
266
226
  targets.clean = {
267
227
  executor: '@smoothbricks/nx-plugin:clean-outputs',
268
228
  cache: false,
@@ -367,85 +327,13 @@ function isRecord(value: unknown): value is Record<string, unknown> {
367
327
  return value !== null && typeof value === 'object';
368
328
  }
369
329
 
370
- function hasPackageLocalBuildOutputTarget(packageJson: PackageJson): boolean {
330
+ function classifyPackageLocalBuildOutputs(packageJson: PackageJson): { ordinary: boolean; platform: boolean } {
371
331
  const targets = packageJson.nx?.targets;
372
- if (!isRecord(targets)) {
373
- return false;
374
- }
375
-
376
- return Object.keys(targets).some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName));
377
- }
378
-
379
- interface CargoWorkspace {
380
- wasmCrates: string[];
381
- hasWasmReleaseProfile: boolean;
382
- }
383
-
384
- async function readCargoWorkspace(absoluteProjectRoot: string): Promise<CargoWorkspace | null> {
385
- const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
386
- if (!existsSync(cargoTomlPath)) {
387
- return null;
388
- }
389
-
390
- const cargoToml = await readFile(cargoTomlPath, 'utf-8');
391
- if (!CARGO_WORKSPACE_PATTERN.test(cargoToml)) {
392
- // Member crates get their targets from the workspace-root package.json,
393
- // never per-crate — one Nx project per Cargo workspace.
394
- return null;
395
- }
396
-
397
- const wasmCrates: string[] = [];
398
- const membersList = CARGO_MEMBERS_PATTERN.exec(cargoToml)?.[1] ?? '';
399
- for (const match of membersList.matchAll(CARGO_MEMBER_ENTRY_PATTERN)) {
400
- const memberTomlPath = join(absoluteProjectRoot, match[1], 'Cargo.toml');
401
- if (!existsSync(memberTomlPath)) {
402
- continue;
403
- }
404
- const memberToml = await readFile(memberTomlPath, 'utf-8');
405
- const name = CARGO_PACKAGE_NAME_PATTERN.exec(memberToml)?.[1];
406
- if (
407
- name &&
408
- CARGO_WASM_CRATE_NAME_PATTERN.test(name) &&
409
- CARGO_CDYLIB_CRATE_TYPE_PATTERN.test(memberToml) &&
410
- !wasmCrates.includes(name)
411
- ) {
412
- wasmCrates.push(name);
413
- }
414
- }
415
-
416
- return { wasmCrates, hasWasmReleaseProfile: CARGO_WASM_RELEASE_PROFILE_PATTERN.test(cargoToml) };
417
- }
418
-
419
- async function readZigSteps(absoluteProjectRoot: string, projectRoot: string): Promise<string[]> {
420
- const buildZigPath = join(absoluteProjectRoot, 'build.zig');
421
-
422
- if (!existsSync(buildZigPath)) {
423
- return [];
424
- }
425
-
426
- const buildZig = await readFile(buildZigPath, 'utf-8');
427
- const declaredSteps = Array.from(buildZig.matchAll(ZIG_STEP_PATTERN), (match) => match[1]);
428
-
429
- if (declaredSteps.length === 0) {
430
- return [];
431
- }
432
-
433
- const steps: string[] = [];
434
- for (const step of declaredSteps) {
435
- if (RESERVED_ZIG_STEPS.has(step)) {
436
- continue;
437
- }
438
-
439
- if (!VALID_ZIG_STEP_NAME.test(step)) {
440
- throw new Error(
441
- `${projectRoot}/build.zig declares unsupported Zig step "${step}"; inferred target names cannot contain ':' or other special characters`,
442
- );
443
- }
444
-
445
- if (!steps.includes(step)) {
446
- steps.push(step);
447
- }
448
- }
449
-
450
- return steps;
332
+ const targetNames = isRecord(targets) ? Object.keys(targets) : [];
333
+ return {
334
+ ordinary: targetNames.some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName)),
335
+ platform: targetNames.some((targetName) =>
336
+ PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1))),
337
+ ),
338
+ };
451
339
  }
@@ -427,30 +427,6 @@ describe('package target policy', () => {
427
427
  }
428
428
  });
429
429
 
430
- it('validates build.zig has steps', async () => {
431
- const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
432
- try {
433
- await writeJson(join(root, 'package.json'), {
434
- name: '@scope/root',
435
- private: true,
436
- workspaces: ['packages/*'],
437
- });
438
- const pkgDir = join(root, 'packages/wasm');
439
- await mkdir(pkgDir, { recursive: true });
440
- await writeJson(join(pkgDir, 'package.json'), {
441
- name: '@scope/wasm',
442
- nx: { name: 'wasm' },
443
- });
444
- // build.zig without b.step(...)
445
- await writeFile(join(pkgDir, 'build.zig'), 'const std = @import("std");\n');
446
-
447
- const issues = checkPackageTargetPolicy(root);
448
- expect(issues.some((i) => i.message.includes('build.zig must define at least one b.step'))).toBe(true);
449
- } finally {
450
- await rm(root, { recursive: true, force: true });
451
- }
452
- });
453
-
454
430
  it('requires test entrypoint when test files exist', async () => {
455
431
  const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
456
432
  try {
@@ -639,30 +615,6 @@ describe('checkPackageTargetPolicyTree', () => {
639
615
  expect(issues.some((i) => i.message.includes('lint:fix') && i.message.includes('colon target names'))).toBe(true);
640
616
  });
641
617
 
642
- it('validates build.zig has steps', () => {
643
- addProject(tree, 'wasm', 'packages/wasm');
644
- writeJsonFile(tree, 'packages/wasm/package.json', {
645
- name: '@scope/wasm',
646
- nx: { name: 'wasm' },
647
- });
648
- tree.write('packages/wasm/build.zig', 'const std = @import("std");\n');
649
-
650
- const issues = checkPackageTargetPolicyTree(tree);
651
- expect(issues.some((i) => i.message.includes('build.zig must define at least one b.step'))).toBe(true);
652
- });
653
-
654
- it('passes build.zig with valid steps', () => {
655
- addProject(tree, 'wasm', 'packages/wasm');
656
- writeJsonFile(tree, 'packages/wasm/package.json', {
657
- name: '@scope/wasm',
658
- nx: { name: 'wasm' },
659
- });
660
- tree.write('packages/wasm/build.zig', 'const step = b.step("wasm", "Build wasm");\n');
661
-
662
- const issues = checkPackageTargetPolicyTree(tree);
663
- expect(issues.filter((i) => i.message.includes('build.zig'))).toEqual([]);
664
- });
665
-
666
618
  it('requires test entrypoint when test files exist', () => {
667
619
  addProject(tree, 'lib', 'packages/lib');
668
620
  writeJsonFile(tree, 'packages/lib/package.json', {
@@ -708,6 +660,68 @@ describe('checkPackageTargetPolicyTree', () => {
708
660
  expect(buildIssues).toEqual([]);
709
661
  });
710
662
 
663
+ it('accepts platform-only target families without an ordinary build aggregate', () => {
664
+ addProject(tree, 'native', 'packages/native');
665
+ writeJsonFile(tree, 'packages/native/package.json', {
666
+ name: '@scope/native',
667
+ nx: { name: 'native' },
668
+ });
669
+ const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
670
+ [
671
+ 'native',
672
+ {
673
+ targets: new Set(['bundle-ios', 'prepare-macos', 'bundle-linux']),
674
+ targetDependencies: new Map([
675
+ ['bundle-ios', ['prepare-macos', '^build']],
676
+ ['prepare-macos', []],
677
+ ['bundle-linux', ['^build']],
678
+ ]),
679
+ },
680
+ ],
681
+ ]);
682
+
683
+ expect(checkPackageTargetPolicyTree(tree, { resolvedTargetsByProject })).toEqual([]);
684
+ });
685
+
686
+ it('rejects cross-family dependencies in resolved platform target closures', () => {
687
+ addProject(tree, 'native', 'packages/native');
688
+ writeJsonFile(tree, 'packages/native/package.json', {
689
+ name: '@scope/native',
690
+ nx: { name: 'native' },
691
+ });
692
+ const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
693
+ [
694
+ 'native',
695
+ {
696
+ targets: new Set(['bundle-ios', 'prepare-macos', 'compile-js', 'bundle-linux']),
697
+ targetDependencies: new Map([
698
+ ['bundle-ios', ['prepare-macos', '^build']],
699
+ ['prepare-macos', ['compile-js']],
700
+ ['bundle-linux', ['bundle-ios']],
701
+ ]),
702
+ },
703
+ ],
704
+ ]);
705
+
706
+ const issues = checkPackageTargetPolicyTree(tree, { resolvedTargetsByProject });
707
+
708
+ expect(
709
+ issues.some(
710
+ (issue) =>
711
+ issue.message.includes('platform target bundle-ios dependency closure') &&
712
+ issue.message.includes('non-macos sibling target compile-js'),
713
+ ),
714
+ ).toBe(true);
715
+ expect(
716
+ issues.some(
717
+ (issue) =>
718
+ issue.message.includes('platform target bundle-linux dependency closure') &&
719
+ issue.message.includes('non-linux sibling target bundle-ios'),
720
+ ),
721
+ ).toBe(true);
722
+ expect(issues.some((issue) => issue.message.includes('non-macos sibling target prepare-macos'))).toBe(false);
723
+ });
724
+
711
725
  it('rejects recursive script commands', () => {
712
726
  addProject(tree, 'app', 'packages/app');
713
727
  addProject(tree, 'lib', 'packages/lib');