@smoothbricks/nx-plugin 0.3.2 → 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.
@@ -124,77 +124,6 @@ describe('create-package generator', () => {
124
124
  });
125
125
  });
126
126
 
127
- describe('ts-zig variant', () => {
128
- it('creates zig scaffold on top of ts-lib', async () => {
129
- const tree = setupTree();
130
- await generator(tree, { name: 'columine', variant: 'ts-zig' });
131
-
132
- // Zig files exist
133
- expect(tree.exists('packages/columine/build.zig')).toBe(true);
134
- expect(tree.exists('packages/columine/build.zig.zon')).toBe(true);
135
- expect(tree.exists('packages/columine/src/columine.zig')).toBe(true);
136
-
137
- // build.zig contains wasm step
138
- const buildZig = tree.read('packages/columine/build.zig', 'utf-8') ?? '';
139
- expect(buildZig).toContain('b.step("wasm", "Build WASM artifact")');
140
- expect(buildZig).toContain('.name = "columine"');
141
- expect(buildZig).toContain('b.path("src/columine.zig")');
142
-
143
- // build.zig.zon
144
- const buildZigZon = tree.read('packages/columine/build.zig.zon', 'utf-8') ?? '';
145
- expect(buildZigZon).toContain('.name = .columine');
146
-
147
- // src/<name>.zig
148
- const zigSrc = tree.read('packages/columine/src/columine.zig', 'utf-8') ?? '';
149
- expect(zigSrc).toContain('export fn add');
150
-
151
- // package.json has wasm export and build scripts
152
- const pkg = readJson(tree, 'packages/columine/package.json');
153
- expect(pkg.exports['./wasm']).toBe('./dist/columine.wasm');
154
- expect(pkg.exports['.'].development).toBeUndefined();
155
- expect(pkg.scripts['build:zig']).toBe('nx run columine:zig-wasm');
156
- expect(pkg.scripts['build:ts']).toBe('nx run columine:tsc-js');
157
- expect(pkg.scripts.build).toBe('bun run build:ts && bun run build:zig');
158
- expect(pkg.files).toEqual(['dist']);
159
-
160
- // tsconfig.lib.json has webworker lib
161
- const tsconfigLib = readJson(tree, 'packages/columine/tsconfig.lib.json');
162
- expect(tsconfigLib.compilerOptions.lib).toEqual(['es2022', 'webworker']);
163
- expect(tsconfigLib.compilerOptions.declaration).toBe(true);
164
- expect(tsconfigLib.compilerOptions.sourceMap).toBe(true);
165
-
166
- // tsconfig.test.json has webworker lib
167
- const tsconfigTest = readJson(tree, 'packages/columine/tsconfig.test.json');
168
- expect(tsconfigTest.compilerOptions.lib).toEqual(['es2022', 'webworker']);
169
- });
170
-
171
- it('combines zig and publication metadata when public', async () => {
172
- const tree = setupTree();
173
- await generator(tree, { name: 'zigpub', variant: 'ts-zig', public: true });
174
-
175
- const pkg = readJson(tree, 'packages/zigpub/package.json');
176
-
177
- // Has zig files
178
- expect(tree.exists('packages/zigpub/build.zig')).toBe(true);
179
- expect(tree.exists('packages/zigpub/build.zig.zon')).toBe(true);
180
- expect(tree.exists('packages/zigpub/src/zigpub.zig')).toBe(true);
181
-
182
- // Has publication metadata
183
- expect(pkg.private).toBeUndefined();
184
- expect(pkg.license).toBe('MIT');
185
- expect(pkg.publishConfig).toEqual({ access: 'public' });
186
- expect(pkg.repository).toEqual({
187
- type: 'git',
188
- url: 'git+https://github.com/smoothbricks/codebase.git',
189
- directory: 'packages/zigpub',
190
- });
191
- expect(pkg.nx?.tags).toEqual(['npm:public']);
192
-
193
- // Has wasm export
194
- expect(pkg.exports['./wasm']).toBe('./dist/zigpub.wasm');
195
- });
196
- });
197
-
198
127
  it('rejects existing package', async () => {
199
128
  const tree = setupTree();
200
129
  tree.write('packages/existing/package.json', '{}');
@@ -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, type Tree, writeJson } from 'nx/src/devkit-exports.js';
4
4
 
@@ -15,10 +15,6 @@ export default async function generator(tree: Tree, schema: CreatePackageGenerat
15
15
  }
16
16
 
17
17
  writeCommonFiles(tree, schema, packageName, projectRoot, rootPkg);
18
-
19
- if (schema.variant === 'ts-zig') {
20
- writeZigFiles(tree, schema, projectRoot);
21
- }
22
18
  }
23
19
 
24
20
  function extractScope(name: string | undefined): string | null {
@@ -158,122 +154,6 @@ function buildPackageJson(
158
154
 
159
155
  return packageJson;
160
156
  }
161
-
162
- function writeZigFiles(tree: Tree, schema: CreatePackageGeneratorSchema, projectRoot: string): void {
163
- // Modify package.json for ts-zig variant
164
- const packageJson = readJson<Record<string, unknown>>(tree, `${projectRoot}/package.json`);
165
-
166
- // Add wasm export and remove development condition
167
- const exports = packageJson.exports;
168
- if (!isRecord(exports)) {
169
- // invariant throw: writeCommonFiles always emits an object-valued exports map.
170
- throw new Error('generated package.json exports must be an object');
171
- }
172
- exports['./wasm'] = `./dist/${schema.name}.wasm`;
173
- const dotExport = exports['.'];
174
- if (!isRecord(dotExport)) {
175
- // invariant throw: writeCommonFiles always emits an object-valued "." export.
176
- throw new Error('generated package.json "." export must be an object');
177
- }
178
- delete dotExport.development;
179
-
180
- // Add build scripts
181
- const scripts = packageJson.scripts;
182
- if (!isRecord(scripts)) {
183
- // invariant throw: writeCommonFiles always emits an object-valued scripts map.
184
- throw new Error('generated package.json scripts must be an object');
185
- }
186
- scripts['build:zig'] = `nx run ${schema.name}:zig-wasm`;
187
- scripts['build:ts'] = `nx run ${schema.name}:tsc-js`;
188
- scripts.build = 'bun run build:ts && bun run build:zig';
189
-
190
- // Change files for zig packages (no src published)
191
- packageJson.files = ['dist'];
192
-
193
- writeJson(tree, `${projectRoot}/package.json`, packageJson);
194
-
195
- // Modify tsconfig.lib.json for ts-zig
196
- const tsconfigLib = readJson<Record<string, unknown>>(tree, `${projectRoot}/tsconfig.lib.json`);
197
- const libCompilerOptions = tsconfigLib.compilerOptions;
198
- if (!isRecord(libCompilerOptions)) {
199
- // invariant throw: writeCommonFiles always emits compilerOptions for library builds.
200
- throw new Error('generated tsconfig.lib.json compilerOptions must be an object');
201
- }
202
- libCompilerOptions.lib = ['es2022', 'webworker'];
203
- libCompilerOptions.declaration = true;
204
- libCompilerOptions.sourceMap = true;
205
- libCompilerOptions.skipLibCheck = true;
206
- writeJson(tree, `${projectRoot}/tsconfig.lib.json`, tsconfigLib);
207
-
208
- // Modify tsconfig.test.json for ts-zig
209
- const tsconfigTest = readJson<Record<string, unknown>>(tree, `${projectRoot}/tsconfig.test.json`);
210
- const testCompilerOptions = tsconfigTest.compilerOptions;
211
- if (!isRecord(testCompilerOptions)) {
212
- // invariant throw: writeCommonFiles always emits compilerOptions for test builds.
213
- throw new Error('generated tsconfig.test.json compilerOptions must be an object');
214
- }
215
- testCompilerOptions.lib = ['es2022', 'webworker'];
216
- writeJson(tree, `${projectRoot}/tsconfig.test.json`, tsconfigTest);
217
-
218
- // Write build.zig
219
- tree.write(
220
- `${projectRoot}/build.zig`,
221
- `const std = @import("std");
222
-
223
- pub fn build(b: *std.Build) void {
224
- const optimize = b.standardOptimizeOption(.{});
225
-
226
- const wasm_step = b.step("wasm", "Build WASM artifact");
227
-
228
- const wasm_target = b.resolveTargetQuery(.{
229
- .cpu_arch = .wasm32,
230
- .os_tag = .freestanding,
231
- });
232
-
233
- const lib = b.addExecutable(.{
234
- .name = "${schema.name}",
235
- .root_source_file = b.path("src/${schema.name}.zig"),
236
- .target = wasm_target,
237
- .optimize = optimize,
238
- });
239
- lib.entry = .disabled;
240
- lib.rdynamic = true;
241
-
242
- const install = b.addInstallArtifact(lib, .{
243
- .dest_dir = .{ .override = .{ .custom = "../dist" } },
244
- });
245
- wasm_step.dependOn(&install.step);
246
- }
247
- `,
248
- );
249
-
250
- // Write build.zig.zon
251
- tree.write(
252
- `${projectRoot}/build.zig.zon`,
253
- `.{
254
- .name = .${schema.name},
255
- .version = "0.0.0",
256
- .minimum_zig_version = "0.14.0",
257
- .dependencies = .{},
258
- .paths = .{
259
- "build.zig",
260
- "build.zig.zon",
261
- "src",
262
- },
263
- }
264
- `,
265
- );
266
-
267
- // Write src/<name>.zig
268
- tree.write(
269
- `${projectRoot}/src/${schema.name}.zig`,
270
- `export fn add(a: i32, b: i32) i32 {
271
- return a + b;
272
- }
273
- `,
274
- );
275
- }
276
-
277
157
  function isRecord(value: unknown): value is Record<string, unknown> {
278
158
  return value !== null && typeof value === 'object' && !Array.isArray(value);
279
159
  }
@@ -1,5 +1,5 @@
1
1
  export interface CreatePackageGeneratorSchema {
2
2
  name: string;
3
- variant: 'ts-lib' | 'ts-zig';
3
+ variant: 'ts-lib';
4
4
  public?: boolean;
5
5
  }
@@ -11,7 +11,7 @@
11
11
  "variant": {
12
12
  "type": "string",
13
13
  "description": "Package variant to scaffold.",
14
- "enum": ["ts-lib", "ts-zig"],
14
+ "enum": ["ts-lib"],
15
15
  "default": "ts-lib"
16
16
  },
17
17
  "public": {
package/src/index.test.ts CHANGED
@@ -32,6 +32,32 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
32
32
  }
33
33
  });
34
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
+
35
61
  it('overrides inferred TypeScript compiler commands with ttsc', async () => {
36
62
  const workspace = await createWorkspace();
37
63
  try {
@@ -135,47 +161,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
135
161
  }
136
162
  });
137
163
 
138
- it('infers zig step targets and excludes reserved non-build steps', async () => {
139
- const workspace = await createWorkspace();
140
- try {
141
- await workspace.write('packages/ziggy/package.json', '{"name":"ziggy"}\n');
142
- await workspace.write(
143
- 'packages/ziggy/build.zig',
144
- [
145
- 'pub fn build(b: *std.Build) void {',
146
- ' _ = b.step("wasm", "Build wasm");',
147
- ' _ = b.step("native", "Build native");',
148
- ' _ = b.step("test", "Run tests");',
149
- ' _ = b.step("all", "Build everything");',
150
- ' _ = b.step("clean", "Clean outputs");',
151
- ' _ = b.step("install", "Install artifacts");',
152
- '}',
153
- '',
154
- ].join('\n'),
155
- );
156
-
157
- const targets = await inferProjectTargets(workspace, 'packages/ziggy/package.json');
158
-
159
- expect(Object.keys(targets).sort()).toEqual(['build', 'clean', 'zig-native', 'zig-wasm']);
160
- expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
161
- expect(targets.build?.cache).toBe(true);
162
- expect(targets['zig-wasm']?.cache).toBe(true);
163
- expect(targets['zig-native']?.cache).toBe(true);
164
- expect(targets['zig-wasm']?.outputs).toEqual(['{projectRoot}/dist/**/*.wasm']);
165
- expect(targets['zig-native']?.outputs).toEqual(['{projectRoot}/dist/**/*.{node,dylib,so,dll,a}']);
166
- expect(targets['zig-wasm']?.options).toEqual({
167
- command: 'zig build wasm',
168
- cwd: 'packages/ziggy',
169
- });
170
- expect(targets['zig-native']?.options).toEqual({
171
- command: 'zig build native',
172
- cwd: 'packages/ziggy',
173
- });
174
- } finally {
175
- await workspace.cleanup();
176
- }
177
- });
178
-
179
164
  it('infers aggregate build for package-local output targets without owning them', async () => {
180
165
  const workspace = await createWorkspace();
181
166
  try {
@@ -225,7 +210,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
225
210
  }
226
211
  });
227
212
 
228
- 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 () => {
229
215
  const workspace = await createWorkspace();
230
216
  try {
231
217
  await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
@@ -241,17 +227,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
241
227
 
242
228
  const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
243
229
 
244
- expect(Object.keys(targets).sort()).toEqual([
245
- 'bench',
246
- 'build',
247
- 'cargo-lint',
248
- 'cargo-test',
249
- 'cargo-wasm',
250
- 'clean',
251
- 'lint',
252
- 'mutation',
253
- 'test',
254
- ]);
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']);
255
233
  expect(targets['cargo-test']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
256
234
  expect(targets['cargo-test']?.options).toMatchObject({
257
235
  command: 'cargo test --workspace',
@@ -275,19 +253,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
275
253
  });
276
254
  expect(targets.mutation?.cache).toBe(false);
277
255
  expect(targets.mutation?.options).toMatchObject({ command: 'cargo mutants --workspace' });
278
- expect(targets['cargo-wasm']?.outputs).toEqual(['{projectRoot}/dist/**/*.wasm']);
279
- expect(targets['cargo-wasm']?.options).toMatchObject({
280
- commands: [
281
- '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',
282
- ],
283
- });
284
- expect(targets['cargo-wasm']?.configurations?.development).toEqual({
285
- commands: [
286
- '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',
287
- ],
288
- });
289
- // cargo-wasm matches the *-wasm build-output pattern → aggregate build/clean exist
290
- expect(targets.build?.executor).toBe('nx:noop');
256
+ expect(targets.bench?.options).toMatchObject({ command: 'cargo bench --workspace' });
291
257
  } finally {
292
258
  await workspace.cleanup();
293
259
  }
@@ -314,7 +280,45 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
314
280
  }
315
281
  });
316
282
 
317
- 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 () => {
318
322
  const workspace = await createWorkspace();
319
323
  try {
320
324
  await workspace.write(
@@ -341,20 +345,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
341
345
  await workspace.cleanup();
342
346
  }
343
347
  });
344
-
345
- it('leaves build.zig without b.step declarations to smoo validation', async () => {
346
- const workspace = await createWorkspace();
347
- try {
348
- await workspace.write('packages/broken/package.json', '{"name":"broken"}\n');
349
- await workspace.write('packages/broken/build.zig', 'pub fn build(_: *std.Build) void {}\n');
350
-
351
- const targets = await inferProjectTargets(workspace, 'packages/broken/package.json');
352
-
353
- expect(targets).toEqual({});
354
- } finally {
355
- await workspace.cleanup();
356
- }
357
- });
348
+ //#endregion
358
349
  });
359
350
 
360
351
  async function createWorkspace(): Promise<WorkspaceFixture> {
package/src/index.ts CHANGED
@@ -7,13 +7,7 @@ import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
7
7
 
8
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
10
  const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
14
- const ZIG_WASM_OUTPUTS = ['{projectRoot}/dist/**/*.wasm'];
15
- const ZIG_NATIVE_OUTPUTS = ['{projectRoot}/dist/**/*.{node,dylib,so,dll,a}'];
16
- const ZIG_GENERIC_OUTPUTS = ['{projectRoot}/dist/**/*.{wasm,node,dylib,so,dll,a}'];
17
11
  const TYPESCRIPT_TOOLCHAIN_INPUTS = [
18
12
  '{workspaceRoot}/package.json',
19
13
  '{workspaceRoot}/bun.lock',
@@ -21,19 +15,17 @@ const TYPESCRIPT_TOOLCHAIN_INPUTS = [
21
15
  '{workspaceRoot}/tsconfig.base.json',
22
16
  ];
23
17
 
18
+ //#region smoo!n/rust-output-target-inference
24
19
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
25
20
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
26
- // the lint aggregate, mutation (cargo-mutants), bench, and — per cdylib member
27
- // crate whose package name ends in `-wasm` — a cargo-wasm build producing
28
- // dist/<crate>.wasm. Explicit nx.targets entries in the package.json always win
29
- // 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.
30
27
  const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
31
- const CARGO_MEMBERS_PATTERN = /^\s*members\s*=\s*\[([^\]]*)\]/m;
32
- const CARGO_MEMBER_ENTRY_PATTERN = /["']([^"']+)["']/g;
33
- const CARGO_PACKAGE_NAME_PATTERN = /^\s*name\s*=\s*["']([^"']+)["']/m;
34
- const CARGO_WASM_CRATE_NAME_PATTERN = /-wasm$/;
35
- const CARGO_CDYLIB_CRATE_TYPE_PATTERN = /^\s*crate-type\s*=\s*\[[^\]]*["']cdylib["']/m;
36
- const CARGO_WASM_RELEASE_PROFILE_PATTERN = /^\s*\[profile\.wasm-release\]/m;
28
+ //#endregion
37
29
  const CARGO_INPUTS = [
38
30
  '{projectRoot}/**/*.rs',
39
31
  '{projectRoot}/**/Cargo.toml',
@@ -68,6 +60,12 @@ export const createNodesV2: CreateNodesV2 = [
68
60
  await Promise.all(
69
61
  projectConfigurationFiles.map(async (packageJsonPath) => {
70
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
+ }
71
69
  results.push([packageJsonPath, await createProjectTargets(packageJsonPath, context.workspaceRoot)]);
72
70
  } catch (error) {
73
71
  errors.push([packageJsonPath, error instanceof Error ? error : new Error(String(error))]);
@@ -83,6 +81,11 @@ export const createNodesV2: CreateNodesV2 = [
83
81
  },
84
82
  ];
85
83
 
84
+ function isManagedPackageJsonSource(packageJsonPath: string): boolean {
85
+ const normalized = packageJsonPath.replaceAll('\\', '/');
86
+ return normalized.includes('/managed/raw/') || normalized.includes('/managed/templates/');
87
+ }
88
+
86
89
  export default { createNodesV2 };
87
90
 
88
91
  interface PackageJson {
@@ -102,8 +105,8 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
102
105
  const validationTargets: string[] = [];
103
106
  const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
104
107
  const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
105
- let hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
106
- let hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
108
+ const hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
109
+ const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
107
110
 
108
111
  if (hasLibTsconfig) {
109
112
  // Official Nx target inference is disabled because its compiler surface only
@@ -169,8 +172,10 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
169
172
  validationTargets.push('typecheck');
170
173
  }
171
174
 
172
- const cargo = await readCargoWorkspace(absoluteProjectRoot);
173
- 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'))) {
174
179
  const declared = packageJson.nx?.targets ?? {};
175
180
  if (!('cargo-test' in declared)) {
176
181
  targets['cargo-test'] = createCargoTestTarget(projectRoot);
@@ -208,50 +213,6 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
208
213
  options: { command: 'cargo bench --workspace', cwd: projectRoot },
209
214
  };
210
215
  }
211
- if (cargo.wasmCrates.length > 0 && !('cargo-wasm' in declared)) {
212
- const profile = cargo.hasWasmReleaseProfile ? 'wasm-release' : 'release';
213
- const buildAndCopy = (crate: string, profileName: string | null) => {
214
- const artifact = crate.replace(/-/g, '_');
215
- const profileFlag = profileName === null ? '' : ` --profile ${profileName}`;
216
- const outputDirectory = profileName ?? 'debug';
217
- return `cargo build${profileFlag} --target wasm32-unknown-unknown -p ${crate} && mkdir -p dist && cp target/wasm32-unknown-unknown/${outputDirectory}/${artifact}.wasm dist/${artifact}.wasm`;
218
- };
219
- targets['cargo-wasm'] = {
220
- executor: 'nx:run-commands',
221
- cache: true,
222
- inputs: CARGO_INPUTS,
223
- outputs: ['{projectRoot}/dist/**/*.wasm'],
224
- options: {
225
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, profile)),
226
- cwd: projectRoot,
227
- parallel: false,
228
- },
229
- configurations: {
230
- development: {
231
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, null)),
232
- },
233
- },
234
- };
235
- hasOrdinaryBuildOutputTarget = true;
236
- hasAnyBuildOutputTarget = true;
237
- }
238
- }
239
-
240
- const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
241
- for (const step of zigSteps) {
242
- const targetName = `zig-${step}`;
243
- targets[targetName] = {
244
- executor: 'nx:run-commands',
245
- cache: true,
246
- inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
247
- outputs: zigOutputsForStep(step),
248
- options: {
249
- command: `zig build ${step}`,
250
- cwd: projectRoot,
251
- },
252
- };
253
- hasOrdinaryBuildOutputTarget = true;
254
- hasAnyBuildOutputTarget = true;
255
216
  }
256
217
 
257
218
  if (hasOrdinaryBuildOutputTarget) {
@@ -376,87 +337,3 @@ function classifyPackageLocalBuildOutputs(packageJson: PackageJson): { ordinary:
376
337
  ),
377
338
  };
378
339
  }
379
-
380
- function zigOutputsForStep(step: string): string[] {
381
- if (step.endsWith('wasm')) {
382
- return ZIG_WASM_OUTPUTS;
383
- }
384
- if (step.endsWith('native')) {
385
- return ZIG_NATIVE_OUTPUTS;
386
- }
387
- return ZIG_GENERIC_OUTPUTS;
388
- }
389
-
390
- interface CargoWorkspace {
391
- wasmCrates: string[];
392
- hasWasmReleaseProfile: boolean;
393
- }
394
-
395
- async function readCargoWorkspace(absoluteProjectRoot: string): Promise<CargoWorkspace | null> {
396
- const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
397
- if (!existsSync(cargoTomlPath)) {
398
- return null;
399
- }
400
-
401
- const cargoToml = await readFile(cargoTomlPath, 'utf-8');
402
- if (!CARGO_WORKSPACE_PATTERN.test(cargoToml)) {
403
- // Member crates get their targets from the workspace-root package.json,
404
- // never per-crate — one Nx project per Cargo workspace.
405
- return null;
406
- }
407
-
408
- const wasmCrates: string[] = [];
409
- const membersList = CARGO_MEMBERS_PATTERN.exec(cargoToml)?.[1] ?? '';
410
- for (const match of membersList.matchAll(CARGO_MEMBER_ENTRY_PATTERN)) {
411
- const memberTomlPath = join(absoluteProjectRoot, match[1], 'Cargo.toml');
412
- if (!existsSync(memberTomlPath)) {
413
- continue;
414
- }
415
- const memberToml = await readFile(memberTomlPath, 'utf-8');
416
- const name = CARGO_PACKAGE_NAME_PATTERN.exec(memberToml)?.[1];
417
- if (
418
- name &&
419
- CARGO_WASM_CRATE_NAME_PATTERN.test(name) &&
420
- CARGO_CDYLIB_CRATE_TYPE_PATTERN.test(memberToml) &&
421
- !wasmCrates.includes(name)
422
- ) {
423
- wasmCrates.push(name);
424
- }
425
- }
426
-
427
- return { wasmCrates, hasWasmReleaseProfile: CARGO_WASM_RELEASE_PROFILE_PATTERN.test(cargoToml) };
428
- }
429
-
430
- async function readZigSteps(absoluteProjectRoot: string, projectRoot: string): Promise<string[]> {
431
- const buildZigPath = join(absoluteProjectRoot, 'build.zig');
432
-
433
- if (!existsSync(buildZigPath)) {
434
- return [];
435
- }
436
-
437
- const buildZig = await readFile(buildZigPath, 'utf-8');
438
- const declaredSteps = Array.from(buildZig.matchAll(ZIG_STEP_PATTERN), (match) => match[1]);
439
-
440
- if (declaredSteps.length === 0) {
441
- return [];
442
- }
443
-
444
- const steps: string[] = [];
445
- for (const step of declaredSteps) {
446
- if (RESERVED_ZIG_STEPS.has(step)) {
447
- continue;
448
- }
449
-
450
- if (!VALID_ZIG_STEP_NAME.test(step)) {
451
- throw new Error(
452
- `${projectRoot}/build.zig declares unsupported Zig step "${step}"; inferred target names cannot contain ':' or other special characters`,
453
- );
454
- }
455
-
456
- if (!steps.includes(step)) {
457
- steps.push(step);
458
- }
459
- }
460
-
461
- return steps;
462
- }