@smoothbricks/nx-plugin 0.3.2 → 0.3.4

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;AAyDxG,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
@@ -3,32 +3,24 @@ 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
5
  import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } 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
6
  const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
10
- const ZIG_WASM_OUTPUTS = ['{projectRoot}/dist/**/*.wasm'];
11
- const ZIG_NATIVE_OUTPUTS = ['{projectRoot}/dist/**/*.{node,dylib,so,dll,a}'];
12
- const ZIG_GENERIC_OUTPUTS = ['{projectRoot}/dist/**/*.{wasm,node,dylib,so,dll,a}'];
13
7
  const TYPESCRIPT_TOOLCHAIN_INPUTS = [
14
8
  '{workspaceRoot}/package.json',
15
9
  '{workspaceRoot}/bun.lock',
16
10
  '{workspaceRoot}/patches/**/*',
17
11
  '{workspaceRoot}/tsconfig.base.json',
18
12
  ];
13
+ //#region smoo!n/rust-output-target-inference
19
14
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
20
15
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
21
- // the lint aggregate, mutation (cargo-mutants), bench, and — per cdylib member
22
- // crate whose package name ends in `-wasm` — a cargo-wasm build producing
23
- // dist/<crate>.wasm. Explicit nx.targets entries in the package.json always win
24
- // 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.
25
22
  const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
26
- const CARGO_MEMBERS_PATTERN = /^\s*members\s*=\s*\[([^\]]*)\]/m;
27
- const CARGO_MEMBER_ENTRY_PATTERN = /["']([^"']+)["']/g;
28
- const CARGO_PACKAGE_NAME_PATTERN = /^\s*name\s*=\s*["']([^"']+)["']/m;
29
- const CARGO_WASM_CRATE_NAME_PATTERN = /-wasm$/;
30
- const CARGO_CDYLIB_CRATE_TYPE_PATTERN = /^\s*crate-type\s*=\s*\[[^\]]*["']cdylib["']/m;
31
- const CARGO_WASM_RELEASE_PROFILE_PATTERN = /^\s*\[profile\.wasm-release\]/m;
23
+ //#endregion
32
24
  const CARGO_INPUTS = [
33
25
  '{projectRoot}/**/*.rs',
34
26
  '{projectRoot}/**/Cargo.toml',
@@ -59,6 +51,12 @@ export const createNodesV2 = [
59
51
  const errors = [];
60
52
  await Promise.all(projectConfigurationFiles.map(async (packageJsonPath) => {
61
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
+ }
62
60
  results.push([packageJsonPath, await createProjectTargets(packageJsonPath, context.workspaceRoot)]);
63
61
  }
64
62
  catch (error) {
@@ -71,6 +69,10 @@ export const createNodesV2 = [
71
69
  return results;
72
70
  },
73
71
  ];
72
+ function isManagedPackageJsonSource(packageJsonPath) {
73
+ const normalized = packageJsonPath.replaceAll('\\', '/');
74
+ return normalized.includes('/managed/raw/') || normalized.includes('/managed/templates/');
75
+ }
74
76
  export default { createNodesV2 };
75
77
  async function createProjectTargets(packageJsonPath, workspaceRoot) {
76
78
  const projectRoot = dirname(packageJsonPath);
@@ -80,8 +82,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
80
82
  const validationTargets = [];
81
83
  const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
82
84
  const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
83
- let hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
84
- let hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
85
+ const hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
86
+ const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
85
87
  if (hasLibTsconfig) {
86
88
  // Official Nx target inference is disabled because its compiler surface only
87
89
  // supports tsc/tsgo. Smoo owns the complete transformer-aware ttsc targets.
@@ -145,8 +147,10 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
145
147
  else if (hasLibTsconfig) {
146
148
  validationTargets.push('typecheck');
147
149
  }
148
- const cargo = await readCargoWorkspace(absoluteProjectRoot);
149
- 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'))) {
150
154
  const declared = packageJson.nx?.targets ?? {};
151
155
  if (!('cargo-test' in declared)) {
152
156
  targets['cargo-test'] = createCargoTestTarget(projectRoot);
@@ -184,49 +188,6 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
184
188
  options: { command: 'cargo bench --workspace', cwd: projectRoot },
185
189
  };
186
190
  }
187
- if (cargo.wasmCrates.length > 0 && !('cargo-wasm' in declared)) {
188
- const profile = cargo.hasWasmReleaseProfile ? 'wasm-release' : 'release';
189
- const buildAndCopy = (crate, profileName) => {
190
- const artifact = crate.replace(/-/g, '_');
191
- const profileFlag = profileName === null ? '' : ` --profile ${profileName}`;
192
- const outputDirectory = profileName ?? 'debug';
193
- return `cargo build${profileFlag} --target wasm32-unknown-unknown -p ${crate} && mkdir -p dist && cp target/wasm32-unknown-unknown/${outputDirectory}/${artifact}.wasm dist/${artifact}.wasm`;
194
- };
195
- targets['cargo-wasm'] = {
196
- executor: 'nx:run-commands',
197
- cache: true,
198
- inputs: CARGO_INPUTS,
199
- outputs: ['{projectRoot}/dist/**/*.wasm'],
200
- options: {
201
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, profile)),
202
- cwd: projectRoot,
203
- parallel: false,
204
- },
205
- configurations: {
206
- development: {
207
- commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, null)),
208
- },
209
- },
210
- };
211
- hasOrdinaryBuildOutputTarget = true;
212
- hasAnyBuildOutputTarget = true;
213
- }
214
- }
215
- const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
216
- for (const step of zigSteps) {
217
- const targetName = `zig-${step}`;
218
- targets[targetName] = {
219
- executor: 'nx:run-commands',
220
- cache: true,
221
- inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
222
- outputs: zigOutputsForStep(step),
223
- options: {
224
- command: `zig build ${step}`,
225
- cwd: projectRoot,
226
- },
227
- };
228
- hasOrdinaryBuildOutputTarget = true;
229
- hasAnyBuildOutputTarget = true;
230
191
  }
231
192
  if (hasOrdinaryBuildOutputTarget) {
232
193
  targets.build = {
@@ -333,65 +294,3 @@ function classifyPackageLocalBuildOutputs(packageJson) {
333
294
  platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
334
295
  };
335
296
  }
336
- function zigOutputsForStep(step) {
337
- if (step.endsWith('wasm')) {
338
- return ZIG_WASM_OUTPUTS;
339
- }
340
- if (step.endsWith('native')) {
341
- return ZIG_NATIVE_OUTPUTS;
342
- }
343
- return ZIG_GENERIC_OUTPUTS;
344
- }
345
- async function readCargoWorkspace(absoluteProjectRoot) {
346
- const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
347
- if (!existsSync(cargoTomlPath)) {
348
- return null;
349
- }
350
- const cargoToml = await readFile(cargoTomlPath, 'utf-8');
351
- if (!CARGO_WORKSPACE_PATTERN.test(cargoToml)) {
352
- // Member crates get their targets from the workspace-root package.json,
353
- // never per-crate — one Nx project per Cargo workspace.
354
- return null;
355
- }
356
- const wasmCrates = [];
357
- const membersList = CARGO_MEMBERS_PATTERN.exec(cargoToml)?.[1] ?? '';
358
- for (const match of membersList.matchAll(CARGO_MEMBER_ENTRY_PATTERN)) {
359
- const memberTomlPath = join(absoluteProjectRoot, match[1], 'Cargo.toml');
360
- if (!existsSync(memberTomlPath)) {
361
- continue;
362
- }
363
- const memberToml = await readFile(memberTomlPath, 'utf-8');
364
- const name = CARGO_PACKAGE_NAME_PATTERN.exec(memberToml)?.[1];
365
- if (name &&
366
- CARGO_WASM_CRATE_NAME_PATTERN.test(name) &&
367
- CARGO_CDYLIB_CRATE_TYPE_PATTERN.test(memberToml) &&
368
- !wasmCrates.includes(name)) {
369
- wasmCrates.push(name);
370
- }
371
- }
372
- return { wasmCrates, hasWasmReleaseProfile: CARGO_WASM_RELEASE_PROFILE_PATTERN.test(cargoToml) };
373
- }
374
- async function readZigSteps(absoluteProjectRoot, projectRoot) {
375
- const buildZigPath = join(absoluteProjectRoot, 'build.zig');
376
- if (!existsSync(buildZigPath)) {
377
- return [];
378
- }
379
- const buildZig = await readFile(buildZigPath, 'utf-8');
380
- const declaredSteps = Array.from(buildZig.matchAll(ZIG_STEP_PATTERN), (match) => match[1]);
381
- if (declaredSteps.length === 0) {
382
- return [];
383
- }
384
- const steps = [];
385
- for (const step of declaredSteps) {
386
- if (RESERVED_ZIG_STEPS.has(step)) {
387
- continue;
388
- }
389
- if (!VALID_ZIG_STEP_NAME.test(step)) {
390
- throw new Error(`${projectRoot}/build.zig declares unsupported Zig step "${step}"; inferred target names cannot contain ':' or other special characters`);
391
- }
392
- if (!steps.includes(step)) {
393
- steps.push(step);
394
- }
395
- }
396
- return steps;
397
- }
@@ -1 +1 @@
1
- {"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAGxF,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAA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F;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"}
@@ -240,7 +240,6 @@ function isSafeNxScriptCommand(command) {
240
240
  /^tsdown(?:\s|$)/.test(trimmed) ||
241
241
  /^vite\s+(?:build|dev|preview)(?:\s|$)/.test(trimmed) ||
242
242
  /^astro\s+(?:build|dev|preview|check)(?:\s|$)/.test(trimmed) ||
243
- /^zig\s+build(?:\s|$)/.test(trimmed) ||
244
243
  /^bun\s+[./\w-]*build[\w.-]*\.ts(?:\s|$)/.test(trimmed) ||
245
244
  /(?:^|\s)(?:bench|benchmark)(?:\s|$)/.test(trimmed) ||
246
245
  /^wrangler\s+build(?:\s|$)/.test(trimmed));
@@ -300,10 +299,6 @@ function targetNameForCommand(command) {
300
299
  if (/^tsdown(?:\s|$)/.test(trimmed)) {
301
300
  return 'tsdown-js';
302
301
  }
303
- const zigStep = /^zig\s+build\s+([A-Za-z0-9_-]+)(?:\s|$)/.exec(trimmed)?.[1];
304
- if (zigStep) {
305
- return `zig-${zigStep}`;
306
- }
307
302
  if (/^wrangler\s+build(?:\s|$)/.test(trimmed)) {
308
303
  return 'build';
309
304
  }
@@ -438,18 +433,6 @@ function directoryContainsTestFiles(path) {
438
433
  }
439
434
  return false;
440
435
  }
441
- function validateBuildZigPolicy(root, packagePath) {
442
- const path = join(root, packagePath, 'build.zig');
443
- if (!existsSync(path)) {
444
- return [];
445
- }
446
- if (/\bb\.step\s*\(/.test(readFileSync(path, 'utf8'))) {
447
- return [];
448
- }
449
- return [
450
- { path: join(root, packagePath), message: `${packagePath}/build.zig must define at least one b.step(...) target` },
451
- ];
452
- }
453
436
  function validateExplicitNxTargets(pkg, packagePath, resolvedProject) {
454
437
  const issues = validatePlatformTargetDependencies(packagePath, resolvedProject);
455
438
  const nx = recordProperty(pkg, 'nx');
@@ -757,17 +740,6 @@ function directoryContainsTestFilesTree(tree, path) {
757
740
  }
758
741
  return false;
759
742
  }
760
- function validateBuildZigPolicyTree(tree, packagePath) {
761
- const path = `${packagePath}/build.zig`;
762
- if (!tree.exists(path)) {
763
- return [];
764
- }
765
- const content = tree.read(path, 'utf-8');
766
- if (content && /\bb\.step\s*\(/.test(content)) {
767
- return [];
768
- }
769
- return [{ path: packagePath, message: `${packagePath}/build.zig must define at least one b.step(...) target` }];
770
- }
771
743
  function validateTestEntrypointPresenceTree(tree, packagePath, pkg) {
772
744
  if (packagePath === '.') {
773
745
  return [];
@@ -795,7 +767,6 @@ export function checkPackageTargetPolicyTree(tree, options = {}) {
795
767
  const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
796
768
  issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
797
769
  issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
798
- issues.push(...validateBuildZigPolicyTree(tree, packagePath));
799
770
  issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
800
771
  }
801
772
  return issues;
@@ -979,7 +950,6 @@ export function checkPackageTargetPolicy(root, options = {}) {
979
950
  const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
980
951
  issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
981
952
  issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
982
- issues.push(...validateBuildZigPolicy(root, packagePath));
983
953
  issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
984
954
  }
985
955
  return issues;
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- const node_child_process_1 = require("node:child_process");
3
2
  const node_fs_1 = require("node:fs");
4
3
  const node_path_1 = require("node:path");
5
4
  const nxJsVersionActions = require('@nx/js/src/release/version-actions');
@@ -11,10 +10,16 @@ const afterAllProjectsVersioned = async (cwd, options) => {
11
10
  // - https://github.com/oven-sh/bun/issues/18906
12
11
  // - https://github.com/oven-sh/bun/issues/20477
13
12
  // - https://github.com/oven-sh/bun/issues/20829
14
- // Nx runs `bun install --lockfile-only`, but Bun currently leaves workspace
15
- // versions stale in bun.lock. `bun pm pack` then rewrites `workspace:*` using
16
- // those stale lockfile versions instead of the current package.json versions.
17
- const updated = syncBunLockfileVersions(cwd);
13
+ //
14
+ // After ANY version bump (release or prepare-next), bun.lock workspace versions
15
+ // must match package.json exactly — including unpublished -next. Day-to-day CI
16
+ // and frozen installs require that invariant.
17
+ //
18
+ // Publish-time pack rewrites (-next → last stable tag) happen only in
19
+ // `smoo release publish` around `bun pm pack`, never here. Doing publish-mode
20
+ // rewrite on prepare-next is what left lock at 0.x.y while package.json said
21
+ // 0.x.y-next.0 and blew up monorepo validate / packed-package-manifest.
22
+ const updated = syncBunLockfileVersionsToPackageJson(cwd);
18
23
  if (updated === 0) {
19
24
  return result;
20
25
  }
@@ -24,7 +29,7 @@ const afterAllProjectsVersioned = async (cwd, options) => {
24
29
  };
25
30
  };
26
31
  baseVersionActions.afterAllProjectsVersioned = afterAllProjectsVersioned;
27
- function syncBunLockfileVersions(root) {
32
+ function syncBunLockfileVersionsToPackageJson(root) {
28
33
  const lockfilePath = (0, node_path_1.join)(root, 'bun.lock');
29
34
  if (!(0, node_fs_1.existsSync)(lockfilePath)) {
30
35
  throw new Error('bun.lock not found');
@@ -33,12 +38,8 @@ function syncBunLockfileVersions(root) {
33
38
  let lockfile = (0, node_fs_1.readFileSync)(lockfilePath, 'utf8');
34
39
  let updated = 0;
35
40
  for (const pkg of packages) {
36
- // If the package.json version is a prerelease (e.g. 0.2.2-next.0) it may
37
- // never have been published. Use the latest stable git tag version so
38
- // that `bun pm pack` writes an installable dependency range for consumers.
39
- const targetVersion = pkg.version.includes('-')
40
- ? (latestStableTagVersion(root, pkg.projectName) ?? pkg.version)
41
- : pkg.version;
41
+ // Install/CI invariant: lockfile version ≡ package.json version (including -next).
42
+ const targetVersion = pkg.version;
42
43
  const relativePath = pkg.path.replaceAll('\\', '/');
43
44
  const escaped = escapeRegex(relativePath);
44
45
  const pattern = new RegExp(`("${escaped}":\\s*\\{[^}]*"version":\\s*")([^"]+)(")`);
@@ -53,7 +54,7 @@ function syncBunLockfileVersions(root) {
53
54
  continue;
54
55
  }
55
56
  lockfile = lockfile.replace(pattern, `$1${targetVersion}$3`);
56
- console.log(`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : ''}`);
57
+ console.log(`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}`);
57
58
  updated++;
58
59
  }
59
60
  if (updated > 0) {
@@ -89,27 +90,4 @@ function isRecord(value) {
89
90
  function escapeRegex(value) {
90
91
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
91
92
  }
92
- function latestStableTagVersion(root, projectName) {
93
- try {
94
- const output = (0, node_child_process_1.execSync)(`git tag --list '${projectName}@*' --sort=-v:refname`, {
95
- cwd: root,
96
- encoding: 'utf8',
97
- stdio: ['pipe', 'pipe', 'pipe'],
98
- });
99
- const prefix = `${projectName}@`;
100
- for (const line of output.split('\n')) {
101
- const tag = line.trim();
102
- if (!tag.startsWith(prefix))
103
- continue;
104
- const version = tag.slice(prefix.length);
105
- if (version && !version.includes('-')) {
106
- return version;
107
- }
108
- }
109
- return null;
110
- }
111
- catch {
112
- return null;
113
- }
114
- }
115
93
  module.exports = baseVersionActions;
@@ -1 +1 @@
1
- {"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQ5E,QAAA,MAAM,kBAAkB;+BALyC,yBAAyB;CAKf,CAAC;SA0BnE,kBAAkB"}
1
+ {"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQ5E,QAAA,MAAM,kBAAkB;+BALyC,yBAAyB;CAKf,CAAC;SAgCnE,kBAAkB"}
package/generators.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "create-package": {
14
14
  "factory": "./dist/generators/create-package/generator.js",
15
15
  "schema": "./src/generators/create-package/schema.json",
16
- "description": "Scaffold a new workspace package (ts-lib or ts-zig)"
16
+ "description": "Scaffold a new TypeScript workspace package"
17
17
  },
18
18
  "make-public": {
19
19
  "factory": "./dist/generators/make-public/generator.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -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', '{}');