@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/README.md CHANGED
@@ -11,12 +11,12 @@ target `tsc-js`; this plugin must not duplicate or rename that target.
11
11
 
12
12
  - `typecheck-tests` and `typecheck-tests:watch` from `tsconfig.test.json`
13
13
  - `test:watch` from explicit `test` commands for Bun and Vitest packages
14
- - `zig-*` targets from `build.zig` steps such as `zig-wasm`
14
+ - Cargo workspace targets from a neighboring workspace-root `Cargo.toml`
15
15
  - aggregate `build` and `lint` targets
16
16
 
17
17
  ## Nx Target Naming
18
18
 
19
- Target names are `{tool}-{output}` names. Use names like `tsc-js`, `tsdown-js`, and `zig-wasm`; `build` and `lint` are
19
+ Target names are `{tool}-{output}` names. Use names like `tsc-js`, `tsdown-js`, and `cargo-wasm`; `build` and `lint` are
20
20
  aggregates.
21
21
 
22
22
  Concrete targets come from concrete files:
@@ -25,19 +25,17 @@ Concrete targets come from concrete files:
25
25
  - `typecheck-tests:watch` is inferred from `tsconfig.test.json` and runs the same typecheck in watch mode.
26
26
  - `test:watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
27
27
  the corresponding watch command and makes it depend on `typecheck-tests`.
28
- - `zig-*` is inferred from `build.zig`; each explicit `b.step("name", ...)` becomes `zig-name`.
28
+ - A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`; workspaces with
29
+ `cdylib` member crates also receive the cacheable `cargo-wasm` output target.
29
30
  - `build` is inferred only when the project has at least one concrete build target to run, such as `tsc-js` from the
30
- official TypeScript plugin, a package-local target like `tsdown-js`, or a `zig-*` target from this plugin. It depends
31
- on output-family wildcard targets: `*-js`, `*-web`, `*-html`, `*-css`, `*-ios`, `*-android`, `*-native`, `*-napi`,
31
+ official TypeScript plugin, a package-local target like `tsdown-js`, or `cargo-wasm` from this plugin. It depends on
32
+ output-family wildcard targets: `*-js`, `*-web`, `*-html`, `*-css`, `*-ios`, `*-android`, `*-native`, `*-napi`,
32
33
  `*-bun`, and `*-wasm`.
33
34
 
34
- This is why Zig appears in the convention: the plugin is not guessing from arbitrary Zig source. SmoothBricks requires
35
- `build.zig` to expose named build steps so Nx can create cacheable, addressable targets from those steps.
36
-
37
35
  Do not use colon-style Nx target names such as `build:wasm` or `lint:fix`. Nx CLI syntax already uses colons for
38
36
  `project:target:configuration`, so colon target names are hard to read, easy to confuse with configurations, and awkward
39
37
  to expose through package scripts. Package scripts may still use names like `build:wasm`; they should delegate to a real
40
- target such as `nx run pkg:zig-wasm`.
38
+ target such as `nx run pkg:cargo-wasm`.
41
39
 
42
40
  There is no Nx `lint:fix` target; repository formatting is handled by the root `lint:fix` script.
43
41
 
@@ -49,9 +47,6 @@ mode. Smoo validation creates/requires this config for test runners that do not
49
47
  against, but the package root `tsconfig.json` should not reference `./tsconfig.test.json`. Nx runs test typechecking
50
48
  through the inferred `typecheck-tests` target, not through `tsc --build`.
51
49
 
52
- Zig targets are inferred only when `build.zig` declares at least one `b.step(...)`. Each step becomes a `zig-*` target,
53
- so a package `build.zig` must have at least one step.
54
-
55
50
  ## Bun Test Tracing Generator
56
51
 
57
52
  Configure a package for the Bun test tracing + no-emit test typechecking pattern used in this repo.
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/create-package/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAevG"}
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/create-package/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAWvG"}
@@ -1,4 +1,4 @@
1
- // Scaffold a new workspace package. Invoked by `smoo g ts-lib|ts-zig <name>`.
1
+ // Scaffold a new TypeScript workspace package. Invoked by `smoo g ts-lib <name>`.
2
2
  // CLI wiring: packages/cli/src/generate/index.ts (variant registry)
3
3
  import { readJson, writeJson } from 'nx/src/devkit-exports.js';
4
4
  export default async function generator(tree, schema) {
@@ -10,9 +10,6 @@ export default async function generator(tree, schema) {
10
10
  throw new Error(`Package already exists at ${projectRoot}`);
11
11
  }
12
12
  writeCommonFiles(tree, schema, packageName, projectRoot, rootPkg);
13
- if (schema.variant === 'ts-zig') {
14
- writeZigFiles(tree, schema, projectRoot);
15
- }
16
13
  }
17
14
  function extractScope(name) {
18
15
  if (!name)
@@ -130,102 +127,6 @@ function buildPackageJson(schema, packageName, projectRoot, rootPkg) {
130
127
  }
131
128
  return packageJson;
132
129
  }
133
- function writeZigFiles(tree, schema, projectRoot) {
134
- // Modify package.json for ts-zig variant
135
- const packageJson = readJson(tree, `${projectRoot}/package.json`);
136
- // Add wasm export and remove development condition
137
- const exports = packageJson.exports;
138
- if (!isRecord(exports)) {
139
- // invariant throw: writeCommonFiles always emits an object-valued exports map.
140
- throw new Error('generated package.json exports must be an object');
141
- }
142
- exports['./wasm'] = `./dist/${schema.name}.wasm`;
143
- const dotExport = exports['.'];
144
- if (!isRecord(dotExport)) {
145
- // invariant throw: writeCommonFiles always emits an object-valued "." export.
146
- throw new Error('generated package.json "." export must be an object');
147
- }
148
- delete dotExport.development;
149
- // Add build scripts
150
- const scripts = packageJson.scripts;
151
- if (!isRecord(scripts)) {
152
- // invariant throw: writeCommonFiles always emits an object-valued scripts map.
153
- throw new Error('generated package.json scripts must be an object');
154
- }
155
- scripts['build:zig'] = `nx run ${schema.name}:zig-wasm`;
156
- scripts['build:ts'] = `nx run ${schema.name}:tsc-js`;
157
- scripts.build = 'bun run build:ts && bun run build:zig';
158
- // Change files for zig packages (no src published)
159
- packageJson.files = ['dist'];
160
- writeJson(tree, `${projectRoot}/package.json`, packageJson);
161
- // Modify tsconfig.lib.json for ts-zig
162
- const tsconfigLib = readJson(tree, `${projectRoot}/tsconfig.lib.json`);
163
- const libCompilerOptions = tsconfigLib.compilerOptions;
164
- if (!isRecord(libCompilerOptions)) {
165
- // invariant throw: writeCommonFiles always emits compilerOptions for library builds.
166
- throw new Error('generated tsconfig.lib.json compilerOptions must be an object');
167
- }
168
- libCompilerOptions.lib = ['es2022', 'webworker'];
169
- libCompilerOptions.declaration = true;
170
- libCompilerOptions.sourceMap = true;
171
- libCompilerOptions.skipLibCheck = true;
172
- writeJson(tree, `${projectRoot}/tsconfig.lib.json`, tsconfigLib);
173
- // Modify tsconfig.test.json for ts-zig
174
- const tsconfigTest = readJson(tree, `${projectRoot}/tsconfig.test.json`);
175
- const testCompilerOptions = tsconfigTest.compilerOptions;
176
- if (!isRecord(testCompilerOptions)) {
177
- // invariant throw: writeCommonFiles always emits compilerOptions for test builds.
178
- throw new Error('generated tsconfig.test.json compilerOptions must be an object');
179
- }
180
- testCompilerOptions.lib = ['es2022', 'webworker'];
181
- writeJson(tree, `${projectRoot}/tsconfig.test.json`, tsconfigTest);
182
- // Write build.zig
183
- tree.write(`${projectRoot}/build.zig`, `const std = @import("std");
184
-
185
- pub fn build(b: *std.Build) void {
186
- const optimize = b.standardOptimizeOption(.{});
187
-
188
- const wasm_step = b.step("wasm", "Build WASM artifact");
189
-
190
- const wasm_target = b.resolveTargetQuery(.{
191
- .cpu_arch = .wasm32,
192
- .os_tag = .freestanding,
193
- });
194
-
195
- const lib = b.addExecutable(.{
196
- .name = "${schema.name}",
197
- .root_source_file = b.path("src/${schema.name}.zig"),
198
- .target = wasm_target,
199
- .optimize = optimize,
200
- });
201
- lib.entry = .disabled;
202
- lib.rdynamic = true;
203
-
204
- const install = b.addInstallArtifact(lib, .{
205
- .dest_dir = .{ .override = .{ .custom = "../dist" } },
206
- });
207
- wasm_step.dependOn(&install.step);
208
- }
209
- `);
210
- // Write build.zig.zon
211
- tree.write(`${projectRoot}/build.zig.zon`, `.{
212
- .name = .${schema.name},
213
- .version = "0.0.0",
214
- .minimum_zig_version = "0.14.0",
215
- .dependencies = .{},
216
- .paths = .{
217
- "build.zig",
218
- "build.zig.zon",
219
- "src",
220
- },
221
- }
222
- `);
223
- // Write src/<name>.zig
224
- tree.write(`${projectRoot}/src/${schema.name}.zig`, `export fn add(a: i32, b: i32) i32 {
225
- return a + b;
226
- }
227
- `);
228
- }
229
130
  function isRecord(value) {
230
131
  return value !== null && typeof value === 'object' && !Array.isArray(value);
231
132
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAsDxG,eAAO,MAAM,aAAa,EAAE,aAsB3B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAiDxG,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAC"}
package/dist/index.js CHANGED
@@ -2,30 +2,25 @@ import { existsSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
5
- import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
6
- const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
7
- const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
8
- const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
9
- const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|ios|android|native|napi|bun|wasm)$/;
5
+ import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
6
+ const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
10
7
  const TYPESCRIPT_TOOLCHAIN_INPUTS = [
11
8
  '{workspaceRoot}/package.json',
12
9
  '{workspaceRoot}/bun.lock',
13
10
  '{workspaceRoot}/patches/**/*',
14
11
  '{workspaceRoot}/tsconfig.base.json',
15
12
  ];
13
+ //#region smoo!n/rust-output-target-inference
16
14
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
17
15
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
18
- // the lint aggregate, mutation (cargo-mutants), bench, and — per cdylib member
19
- // crate whose package name ends in `-wasm` — a cargo-wasm build producing
20
- // dist/<crate>.wasm. Explicit nx.targets entries in the package.json always win
21
- // over inference.
16
+ // the lint aggregate, mutation (cargo-mutants), and bench. Rust output targets
17
+ // (cargo-wasm, cargo-napi, ...) are never inferred from crate metadata such as
18
+ // cdylib crate-types — a native N-API cdylib is not a wasm build. Packages
19
+ // declare output targets in package.json nx.targets, and those *-wasm/*-napi/
20
+ // *-native output-family names feed the aggregate build and clean targets.
21
+ // Explicit nx.targets entries always win over inference.
22
22
  const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
23
- const CARGO_MEMBERS_PATTERN = /^\s*members\s*=\s*\[([^\]]*)\]/m;
24
- const CARGO_MEMBER_ENTRY_PATTERN = /["']([^"']+)["']/g;
25
- const CARGO_PACKAGE_NAME_PATTERN = /^\s*name\s*=\s*["']([^"']+)["']/m;
26
- const CARGO_WASM_CRATE_NAME_PATTERN = /-wasm$/;
27
- const CARGO_CDYLIB_CRATE_TYPE_PATTERN = /^\s*crate-type\s*=\s*\[[^\]]*["']cdylib["']/m;
28
- const CARGO_WASM_RELEASE_PROFILE_PATTERN = /^\s*\[profile\.wasm-release\]/m;
23
+ //#endregion
29
24
  const CARGO_INPUTS = [
30
25
  '{projectRoot}/**/*.rs',
31
26
  '{projectRoot}/**/Cargo.toml',
@@ -56,6 +51,12 @@ export const createNodesV2 = [
56
51
  const errors = [];
57
52
  await Promise.all(projectConfigurationFiles.map(async (packageJsonPath) => {
58
53
  try {
54
+ if (isManagedPackageJsonSource(packageJsonPath)) {
55
+ // smoo monorepo managed raw/templates are source copies, not projects.
56
+ // Dogfood trees symlink live paths here; discovering both doubles names.
57
+ results.push([packageJsonPath, {}]);
58
+ return;
59
+ }
59
60
  results.push([packageJsonPath, await createProjectTargets(packageJsonPath, context.workspaceRoot)]);
60
61
  }
61
62
  catch (error) {
@@ -68,6 +69,10 @@ export const createNodesV2 = [
68
69
  return results;
69
70
  },
70
71
  ];
72
+ function isManagedPackageJsonSource(packageJsonPath) {
73
+ const normalized = packageJsonPath.replaceAll('\\', '/');
74
+ return normalized.includes('/managed/raw/') || normalized.includes('/managed/templates/');
75
+ }
71
76
  export default { createNodesV2 };
72
77
  async function createProjectTargets(packageJsonPath, workspaceRoot) {
73
78
  const projectRoot = dirname(packageJsonPath);
@@ -76,7 +81,9 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
76
81
  const targets = {};
77
82
  const validationTargets = [];
78
83
  const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
79
- let hasBuildOutputTarget = hasLibTsconfig || hasPackageLocalBuildOutputTarget(packageJson);
84
+ const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
85
+ const hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
86
+ const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
80
87
  if (hasLibTsconfig) {
81
88
  // Official Nx target inference is disabled because its compiler surface only
82
89
  // supports tsc/tsgo. Smoo owns the complete transformer-aware ttsc targets.
@@ -84,10 +91,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
84
91
  executor: 'nx:run-commands',
85
92
  cache: true,
86
93
  inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
87
- outputs: [
88
- '{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}',
89
- '{projectRoot}/dist/.build.tsbuildinfo',
90
- ],
94
+ outputs: ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'],
91
95
  dependsOn: ['^tsc-js'],
92
96
  options: {
93
97
  command: 'ttsc -p tsconfig.lib.json --emit',
@@ -143,8 +147,10 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
143
147
  else if (hasLibTsconfig) {
144
148
  validationTargets.push('typecheck');
145
149
  }
146
- const cargo = await readCargoWorkspace(absoluteProjectRoot);
147
- if (cargo) {
150
+ // Member crates get their targets from the workspace-root package.json,
151
+ // never per-crate — one Nx project per Cargo workspace.
152
+ const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
153
+ if (existsSync(cargoTomlPath) && CARGO_WORKSPACE_PATTERN.test(await readFile(cargoTomlPath, 'utf-8'))) {
148
154
  const declared = packageJson.nx?.targets ?? {};
149
155
  if (!('cargo-test' in declared)) {
150
156
  targets['cargo-test'] = createCargoTestTarget(projectRoot);
@@ -182,61 +188,15 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
182
188
  options: { command: 'cargo bench --workspace', cwd: projectRoot },
183
189
  };
184
190
  }
185
- if (cargo.wasmCrates.length > 0 && !('cargo-wasm' in declared)) {
186
- const profile = cargo.hasWasmReleaseProfile ? 'wasm-release' : 'release';
187
- const buildAndCopy = (crate, profileName) => {
188
- const artifact = crate.replace(/-/g, '_');
189
- const profileFlag = profileName === null ? '' : ` --profile ${profileName}`;
190
- const outputDirectory = profileName ?? 'debug';
191
- return `cargo build${profileFlag} --target wasm32-unknown-unknown -p ${crate} && mkdir -p dist && cp target/wasm32-unknown-unknown/${outputDirectory}/${artifact}.wasm dist/${artifact}.wasm`;
192
- };
193
- targets['cargo-wasm'] = {
194
- executor: 'nx:run-commands',
195
- cache: true,
196
- inputs: CARGO_INPUTS,
197
- outputs: ['{projectRoot}/dist/**/*.wasm'],
198
- options: {
199
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, profile)),
200
- cwd: projectRoot,
201
- parallel: false,
202
- },
203
- configurations: {
204
- development: {
205
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, null)),
206
- },
207
- },
208
- };
209
- hasBuildOutputTarget = true;
210
- }
211
- }
212
- const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
213
- for (const step of zigSteps) {
214
- const targetName = `zig-${step}`;
215
- targets[targetName] = {
216
- executor: 'nx:run-commands',
217
- cache: true,
218
- inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
219
- outputs: [
220
- '{projectRoot}/dist/**/*.wasm',
221
- '{projectRoot}/dist/**/*.node',
222
- '{projectRoot}/dist/**/*.dylib',
223
- '{projectRoot}/dist/**/*.so',
224
- '{projectRoot}/dist/**/*.dll',
225
- '{projectRoot}/dist/**/*.a',
226
- ],
227
- options: {
228
- command: `zig build ${step}`,
229
- cwd: projectRoot,
230
- },
231
- };
232
- hasBuildOutputTarget = true;
233
191
  }
234
- if (hasBuildOutputTarget) {
192
+ if (hasOrdinaryBuildOutputTarget) {
235
193
  targets.build = {
236
194
  executor: 'nx:noop',
237
195
  cache: true,
238
196
  dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
239
197
  };
198
+ }
199
+ if (hasAnyBuildOutputTarget) {
240
200
  targets.clean = {
241
201
  executor: '@smoothbricks/nx-plugin:clean-outputs',
242
202
  cache: false,
@@ -326,63 +286,11 @@ function parseEnvPrefixedCommand(command) {
326
286
  function isRecord(value) {
327
287
  return value !== null && typeof value === 'object';
328
288
  }
329
- function hasPackageLocalBuildOutputTarget(packageJson) {
289
+ function classifyPackageLocalBuildOutputs(packageJson) {
330
290
  const targets = packageJson.nx?.targets;
331
- if (!isRecord(targets)) {
332
- return false;
333
- }
334
- return Object.keys(targets).some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName));
335
- }
336
- async function readCargoWorkspace(absoluteProjectRoot) {
337
- const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
338
- if (!existsSync(cargoTomlPath)) {
339
- return null;
340
- }
341
- const cargoToml = await readFile(cargoTomlPath, 'utf-8');
342
- if (!CARGO_WORKSPACE_PATTERN.test(cargoToml)) {
343
- // Member crates get their targets from the workspace-root package.json,
344
- // never per-crate — one Nx project per Cargo workspace.
345
- return null;
346
- }
347
- const wasmCrates = [];
348
- const membersList = CARGO_MEMBERS_PATTERN.exec(cargoToml)?.[1] ?? '';
349
- for (const match of membersList.matchAll(CARGO_MEMBER_ENTRY_PATTERN)) {
350
- const memberTomlPath = join(absoluteProjectRoot, match[1], 'Cargo.toml');
351
- if (!existsSync(memberTomlPath)) {
352
- continue;
353
- }
354
- const memberToml = await readFile(memberTomlPath, 'utf-8');
355
- const name = CARGO_PACKAGE_NAME_PATTERN.exec(memberToml)?.[1];
356
- if (name &&
357
- CARGO_WASM_CRATE_NAME_PATTERN.test(name) &&
358
- CARGO_CDYLIB_CRATE_TYPE_PATTERN.test(memberToml) &&
359
- !wasmCrates.includes(name)) {
360
- wasmCrates.push(name);
361
- }
362
- }
363
- return { wasmCrates, hasWasmReleaseProfile: CARGO_WASM_RELEASE_PROFILE_PATTERN.test(cargoToml) };
364
- }
365
- async function readZigSteps(absoluteProjectRoot, projectRoot) {
366
- const buildZigPath = join(absoluteProjectRoot, 'build.zig');
367
- if (!existsSync(buildZigPath)) {
368
- return [];
369
- }
370
- const buildZig = await readFile(buildZigPath, 'utf-8');
371
- const declaredSteps = Array.from(buildZig.matchAll(ZIG_STEP_PATTERN), (match) => match[1]);
372
- if (declaredSteps.length === 0) {
373
- return [];
374
- }
375
- const steps = [];
376
- for (const step of declaredSteps) {
377
- if (RESERVED_ZIG_STEPS.has(step)) {
378
- continue;
379
- }
380
- if (!VALID_ZIG_STEP_NAME.test(step)) {
381
- throw new Error(`${projectRoot}/build.zig declares unsupported Zig step "${step}"; inferred target names cannot contain ':' or other special characters`);
382
- }
383
- if (!steps.includes(step)) {
384
- steps.push(step);
385
- }
386
- }
387
- return steps;
291
+ const targetNames = isRecord(targets) ? Object.keys(targets) : [];
292
+ return {
293
+ ordinary: targetNames.some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName)),
294
+ platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
295
+ };
388
296
  }
@@ -1,16 +1,17 @@
1
1
  import { type Tree } from 'nx/src/devkit-exports.js';
2
- import type { NxPolicyIssue } from './workspace-config-policy.js';
2
+ import { type NxPolicyIssue } from './workspace-config-policy.js';
3
+ export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
3
4
  export type { NxPolicyIssue };
4
5
  export interface ResolvedProjectTargets {
5
6
  targets: ReadonlySet<string>;
6
7
  buildDependsOn?: readonly string[];
8
+ targetDependencies?: ReadonlyMap<string, readonly string[]>;
7
9
  targetExecutors?: ReadonlyMap<string, string>;
8
10
  targetScripts?: ReadonlyMap<string, string>;
9
11
  }
10
12
  export interface PackageTargetPolicyOptions {
11
13
  resolvedTargetsByProject?: ReadonlyMap<string, ReadonlySet<string> | ResolvedProjectTargets>;
12
14
  }
13
- export declare const BUILD_OUTPUT_DEPENDENCIES: string[];
14
15
  export declare function packageNxProjectName(pkg: Record<string, unknown>): string | null;
15
16
  export declare function nxRunAlias(projectName: string, targetName: string, continuous: boolean, command?: string | null): string;
16
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","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GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA2JD,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;AAynBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAoBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA4B1G;AAoJD,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACpC,aAAa,EAAE,CAEjB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GACtD,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAmBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA6BxG"}
@@ -2,18 +2,8 @@ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { getProjects, readJson, updateJson } from 'nx/src/devkit-exports.js';
4
4
  import { boundedTestScriptAlias } from './bounded-test-policy.js';
5
- export const BUILD_OUTPUT_DEPENDENCIES = [
6
- '*-js',
7
- '*-web',
8
- '*-html',
9
- '*-css',
10
- '*-ios',
11
- '*-android',
12
- '*-native',
13
- '*-napi',
14
- '*-bun',
15
- '*-wasm',
16
- ];
5
+ import { BUILD_OUTPUT_DEPENDENCIES, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
6
+ export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
17
7
  const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
18
8
  function isRecord(value) {
19
9
  return value !== null && typeof value === 'object' && !Array.isArray(value);
@@ -154,7 +144,7 @@ function targetExistsInResolvedProject(targetName, resolvedTargets) {
154
144
  return resolvedProjectTargetNames(resolvedTargets)?.has(targetName) === true;
155
145
  }
156
146
  function isBuildOutputDependencyPattern(dependency) {
157
- return BUILD_OUTPUT_DEPENDENCIES.includes(dependency);
147
+ return BUILD_OUTPUT_DEPENDENCIES.some((pattern) => pattern === dependency);
158
148
  }
159
149
  function expectedTargetDependencies(targetName) {
160
150
  return targetName === 'preview' ? ['build'] : ['^build'];
@@ -250,7 +240,6 @@ function isSafeNxScriptCommand(command) {
250
240
  /^tsdown(?:\s|$)/.test(trimmed) ||
251
241
  /^vite\s+(?:build|dev|preview)(?:\s|$)/.test(trimmed) ||
252
242
  /^astro\s+(?:build|dev|preview|check)(?:\s|$)/.test(trimmed) ||
253
- /^zig\s+build(?:\s|$)/.test(trimmed) ||
254
243
  /^bun\s+[./\w-]*build[\w.-]*\.ts(?:\s|$)/.test(trimmed) ||
255
244
  /(?:^|\s)(?:bench|benchmark)(?:\s|$)/.test(trimmed) ||
256
245
  /^wrangler\s+build(?:\s|$)/.test(trimmed));
@@ -310,10 +299,6 @@ function targetNameForCommand(command) {
310
299
  if (/^tsdown(?:\s|$)/.test(trimmed)) {
311
300
  return 'tsdown-js';
312
301
  }
313
- const zigStep = /^zig\s+build\s+([A-Za-z0-9_-]+)(?:\s|$)/.exec(trimmed)?.[1];
314
- if (zigStep) {
315
- return `zig-${zigStep}`;
316
- }
317
302
  if (/^wrangler\s+build(?:\s|$)/.test(trimmed)) {
318
303
  return 'build';
319
304
  }
@@ -448,25 +433,13 @@ function directoryContainsTestFiles(path) {
448
433
  }
449
434
  return false;
450
435
  }
451
- function validateBuildZigPolicy(root, packagePath) {
452
- const path = join(root, packagePath, 'build.zig');
453
- if (!existsSync(path)) {
454
- return [];
455
- }
456
- if (/\bb\.step\s*\(/.test(readFileSync(path, 'utf8'))) {
457
- return [];
458
- }
459
- return [
460
- { path: join(root, packagePath), message: `${packagePath}/build.zig must define at least one b.step(...) target` },
461
- ];
462
- }
463
- function validateExplicitNxTargets(pkg, packagePath, resolvedTargets) {
436
+ function validateExplicitNxTargets(pkg, packagePath, resolvedProject) {
437
+ const issues = validatePlatformTargetDependencies(packagePath, resolvedProject);
464
438
  const nx = recordProperty(pkg, 'nx');
465
439
  const targets = nx ? recordProperty(nx, 'targets') : null;
466
440
  if (!targets) {
467
- return [];
441
+ return issues;
468
442
  }
469
- const issues = [];
470
443
  for (const [targetName, rawTarget] of Object.entries(targets)) {
471
444
  if (targetName.includes(':')) {
472
445
  issues.push({
@@ -478,7 +451,61 @@ function validateExplicitNxTargets(pkg, packagePath, resolvedTargets) {
478
451
  if (!isRecord(rawTarget)) {
479
452
  continue;
480
453
  }
481
- issues.push(...validateTargetDependencies(rawTarget, `${packagePath}: nx.targets.${targetName}`, resolvedTargets));
454
+ issues.push(...validateTargetDependencies(rawTarget, `${packagePath}: nx.targets.${targetName}`, resolvedProjectTargetNames(resolvedProject)));
455
+ }
456
+ return issues;
457
+ }
458
+ function platformTargetFamily(targetName) {
459
+ if (MACOS_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
460
+ return 'macos';
461
+ }
462
+ if (LINUX_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
463
+ return 'linux';
464
+ }
465
+ return null;
466
+ }
467
+ function matchingResolvedTargets(dependency, targets) {
468
+ if (!dependency.startsWith('*')) {
469
+ return targets.has(dependency) ? [dependency] : [];
470
+ }
471
+ const suffix = dependency.slice(1);
472
+ return [...targets].filter((targetName) => targetName.endsWith(suffix));
473
+ }
474
+ function validatePlatformTargetDependencies(packagePath, resolvedProject) {
475
+ if (!isResolvedProjectTargets(resolvedProject) || !resolvedProject.targetDependencies) {
476
+ return [];
477
+ }
478
+ const issues = [];
479
+ for (const platformTarget of resolvedProject.targets) {
480
+ const family = platformTargetFamily(platformTarget);
481
+ if (!family) {
482
+ continue;
483
+ }
484
+ const visited = new Set();
485
+ const pending = [platformTarget];
486
+ while (pending.length > 0) {
487
+ const targetName = pending.pop();
488
+ if (!targetName || visited.has(targetName)) {
489
+ continue;
490
+ }
491
+ visited.add(targetName);
492
+ for (const dependency of resolvedProject.targetDependencies.get(targetName) ?? []) {
493
+ if (dependency.startsWith('^')) {
494
+ continue;
495
+ }
496
+ for (const resolvedDependency of matchingResolvedTargets(dependency, resolvedProject.targets)) {
497
+ if (platformTargetFamily(resolvedDependency) !== family) {
498
+ issues.push({
499
+ path: packagePath,
500
+ message: `${packagePath}: platform target ${platformTarget} dependency closure references ` +
501
+ `non-${family} sibling target ${resolvedDependency} via ${targetName}`,
502
+ });
503
+ continue;
504
+ }
505
+ pending.push(resolvedDependency);
506
+ }
507
+ }
508
+ }
482
509
  }
483
510
  return issues;
484
511
  }
@@ -713,17 +740,6 @@ function directoryContainsTestFilesTree(tree, path) {
713
740
  }
714
741
  return false;
715
742
  }
716
- function validateBuildZigPolicyTree(tree, packagePath) {
717
- const path = `${packagePath}/build.zig`;
718
- if (!tree.exists(path)) {
719
- return [];
720
- }
721
- const content = tree.read(path, 'utf-8');
722
- if (content && /\bb\.step\s*\(/.test(content)) {
723
- return [];
724
- }
725
- return [{ path: packagePath, message: `${packagePath}/build.zig must define at least one b.step(...) target` }];
726
- }
727
743
  function validateTestEntrypointPresenceTree(tree, packagePath, pkg) {
728
744
  if (packagePath === '.') {
729
745
  return [];
@@ -749,9 +765,8 @@ export function checkPackageTargetPolicyTree(tree, options = {}) {
749
765
  const packagePath = config.root;
750
766
  const resolvedProject = options.resolvedTargetsByProject?.get(projectName);
751
767
  const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
752
- issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedTargets));
768
+ issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
753
769
  issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
754
- issues.push(...validateBuildZigPolicyTree(tree, packagePath));
755
770
  issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
756
771
  }
757
772
  return issues;
@@ -933,10 +948,8 @@ export function checkPackageTargetPolicy(root, options = {}) {
933
948
  const packagePath = packagePathFromJsonPath(root, packageJsonPath);
934
949
  const projectName = packageNxProjectName(pkg);
935
950
  const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
936
- const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
937
- issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedTargets));
951
+ issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
938
952
  issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
939
- issues.push(...validateBuildZigPolicy(root, packagePath));
940
953
  issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
941
954
  }
942
955
  return issues;