@smoothbricks/nx-plugin 0.3.4 → 0.3.6

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.
Files changed (32) hide show
  1. package/README.md +40 -8
  2. package/dist/bounded-test-policy.d.ts +4 -2
  3. package/dist/bounded-test-policy.d.ts.map +1 -1
  4. package/dist/bounded-test-policy.js +93 -15
  5. package/dist/executors/typescript-emit/executor.d.ts +17 -0
  6. package/dist/executors/typescript-emit/executor.d.ts.map +1 -0
  7. package/dist/executors/typescript-emit/executor.js +61 -0
  8. package/dist/executors/typescript-emit/schema.d.ts +5 -0
  9. package/dist/executors/typescript-emit/schema.d.ts.map +1 -0
  10. package/dist/executors/typescript-emit/schema.js +1 -0
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +280 -29
  14. package/dist/package-target-policy.d.ts +2 -0
  15. package/dist/package-target-policy.d.ts.map +1 -1
  16. package/dist/package-target-policy.js +5 -1
  17. package/dist/workspace-config-policy.d.ts.map +1 -1
  18. package/dist/workspace-config-policy.js +11 -3
  19. package/executors.json +5 -0
  20. package/package.json +4 -3
  21. package/src/bounded-test-policy.test.ts +102 -2
  22. package/src/bounded-test-policy.ts +110 -17
  23. package/src/executors/typescript-emit/executor.test.ts +98 -0
  24. package/src/executors/typescript-emit/executor.ts +94 -0
  25. package/src/executors/typescript-emit/schema.json +19 -0
  26. package/src/executors/typescript-emit/schema.ts +4 -0
  27. package/src/index.test.ts +158 -17
  28. package/src/index.ts +358 -31
  29. package/src/package-target-policy.test.ts +17 -0
  30. package/src/package-target-policy.ts +5 -1
  31. package/src/workspace-config-policy.test.ts +41 -1
  32. package/src/workspace-config-policy.ts +12 -3
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { existsSync } from 'node:fs';
2
- import { readFile } from 'node:fs/promises';
3
- import { dirname, join } from 'node:path';
2
+ import { readdir, readFile } from 'node:fs/promises';
3
+ import { dirname, join, posix } from 'node:path';
4
+ import { readJsonFile, } from 'nx/src/devkit-exports.js';
4
5
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
6
+ import { parse as parseToml } from 'smol-toml';
5
7
  import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
6
8
  const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
7
9
  const TYPESCRIPT_TOOLCHAIN_INPUTS = [
@@ -13,21 +15,65 @@ const TYPESCRIPT_TOOLCHAIN_INPUTS = [
13
15
  //#region smoo!n/rust-output-target-inference
14
16
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
15
17
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
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.
18
+ // the lint aggregate, mutation (cargo-mutants), and bench. Cargo output families
19
+ // use tool-native metadata: N-API comes from package.json napi metadata; Wasm
20
+ // comes from [package.metadata.smoothbricks.wasm-bindgen] in a crate manifest.
22
21
  const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
23
22
  //#endregion
24
23
  const CARGO_INPUTS = [
25
24
  '{projectRoot}/**/*.rs',
26
25
  '{projectRoot}/**/Cargo.toml',
27
- '{projectRoot}/Cargo.lock',
28
- '{projectRoot}/.cargo/config.toml',
29
- '!{projectRoot}/target/**',
26
+ '{projectRoot}/**/Cargo.lock',
27
+ '{projectRoot}/**/.cargo/config.toml',
28
+ '!{projectRoot}/**/target/**',
30
29
  ];
30
+ const CARGO_OUTPUT_INPUTS = [...CARGO_INPUTS, '{projectRoot}/package.json', '{workspaceRoot}/bun.lock'];
31
+ const NAPI_INPUTS = CARGO_OUTPUT_INPUTS;
32
+ const NAPI_TARGET_CONVENTIONS = {
33
+ 'aarch64-apple-darwin': {
34
+ architecture: 'arm64',
35
+ outputName: 'darwin-arm64',
36
+ targetFamily: 'macos',
37
+ useNapiCross: false,
38
+ },
39
+ 'x86_64-apple-darwin': {
40
+ architecture: 'x64',
41
+ outputName: 'darwin-x64',
42
+ targetFamily: 'macos',
43
+ useNapiCross: false,
44
+ },
45
+ 'aarch64-unknown-linux-gnu': {
46
+ architecture: 'arm64',
47
+ outputName: 'linux-arm64-gnu',
48
+ targetFamily: 'linux',
49
+ useNapiCross: true,
50
+ },
51
+ 'x86_64-unknown-linux-gnu': {
52
+ architecture: 'x64',
53
+ outputName: 'linux-x64-gnu',
54
+ targetFamily: 'linux',
55
+ useNapiCross: true,
56
+ },
57
+ };
58
+ function createCargoWasmTarget(projectRoot, config) {
59
+ const cargoTargetDirectory = posix.join(posix.dirname(config.manifestPath), 'target/cargo-wasm');
60
+ const wasmInput = `${cargoTargetDirectory}/wasm32-unknown-unknown/release/${config.libraryName}.wasm`;
61
+ return {
62
+ executor: 'nx:run-commands',
63
+ cache: true,
64
+ dependsOn: ['^build'],
65
+ inputs: CARGO_OUTPUT_INPUTS,
66
+ outputs: [`{projectRoot}/${config.outputDirectory}`],
67
+ options: {
68
+ commands: [
69
+ `cargo build --release --target wasm32-unknown-unknown --target-dir ${cargoTargetDirectory} --manifest-path ${config.manifestPath}`,
70
+ ...config.targets.map(({ bindgenTarget, outputName }) => `wasm-bindgen --target ${bindgenTarget} --out-dir ${config.outputDirectory}/${outputName} ${wasmInput}`),
71
+ ],
72
+ cwd: projectRoot,
73
+ parallel: false,
74
+ },
75
+ };
76
+ }
31
77
  function createCargoTestTarget(projectRoot) {
32
78
  return {
33
79
  executor: '@smoothbricks/nx-plugin:bounded-exec',
@@ -36,7 +82,8 @@ function createCargoTestTarget(projectRoot) {
36
82
  options: {
37
83
  command: 'cargo test --workspace',
38
84
  cwd: projectRoot,
39
- timeoutMs: 600000,
85
+ // Cold macOS Cargo workspaces can exceed ten minutes while still making progress.
86
+ timeoutMs: 1200000,
40
87
  killAfterMs: 10000,
41
88
  },
42
89
  configurations: {
@@ -80,21 +127,34 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
80
127
  const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
81
128
  const targets = {};
82
129
  const validationTargets = [];
83
- const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
130
+ const libTsconfigPath = join(absoluteProjectRoot, 'tsconfig.lib.json');
131
+ const hasLibTsconfig = existsSync(libTsconfigPath);
132
+ const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
133
+ const isCargoWorkspace = existsSync(cargoTomlPath) && CARGO_WORKSPACE_PATTERN.test(await readFile(cargoTomlPath, 'utf-8'));
134
+ const napiConfig = resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace);
135
+ const declaredTargets = packageJson.nx?.targets ?? {};
136
+ const cargoWasmConfig = await resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath);
137
+ const inferCargoWasm = cargoWasmConfig !== null && !('cargo-wasm' in declaredTargets);
84
138
  const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
85
- const hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
139
+ const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
86
140
  const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
87
141
  if (hasLibTsconfig) {
88
- // Official Nx target inference is disabled because its compiler surface only
89
- // supports tsc/tsgo. Smoo owns the complete transformer-aware ttsc targets.
142
+ // Dependency packages may publish bundled entries that raw tsc does not produce.
143
+ // Build every JavaScript output lane before resolving package exports, without pulling
144
+ // unrelated Wasm, N-API, native, or web outputs onto the compiler critical path.
145
+ //
146
+ // ttsc transforms the source program before declaration emit, so typia's
147
+ // generated implementation identifiers are not valid declaration inputs.
148
+ // The executor gives ttsc a JS-only overlay and emits declarations from the
149
+ // original project with native tsc.
90
150
  targets['tsc-js'] = {
91
- executor: 'nx:run-commands',
151
+ executor: '@smoothbricks/nx-plugin:typescript-emit',
92
152
  cache: true,
93
153
  inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
94
- outputs: ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'],
95
- dependsOn: ['^tsc-js'],
154
+ outputs: inferTypescriptOutputs(libTsconfigPath, packageJsonPath),
155
+ dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
96
156
  options: {
97
- command: 'ttsc -p tsconfig.lib.json --emit',
157
+ tsConfig: 'tsconfig.lib.json',
98
158
  cwd: projectRoot,
99
159
  },
100
160
  };
@@ -103,9 +163,9 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
103
163
  cache: true,
104
164
  inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
105
165
  outputs: [],
106
- dependsOn: ['^tsc-js'],
166
+ dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
107
167
  options: {
108
- command: 'ttsc -p tsconfig.lib.json --noEmit',
168
+ command: 'tsc -p tsconfig.lib.json --noEmit',
109
169
  cwd: projectRoot,
110
170
  },
111
171
  };
@@ -118,7 +178,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
118
178
  inputs: ['default', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.test.json'],
119
179
  dependsOn: ['typecheck'],
120
180
  options: {
121
- command: 'ttsc -p tsconfig.test.json --noEmit',
181
+ command: 'tsc -p tsconfig.test.json --noEmit',
122
182
  cwd: projectRoot,
123
183
  },
124
184
  };
@@ -126,7 +186,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
126
186
  executor: 'nx:run-commands',
127
187
  continuous: true,
128
188
  options: {
129
- command: 'ttsc -p tsconfig.test.json --noEmit --watch',
189
+ command: 'tsc -p tsconfig.test.json --noEmit --watch',
130
190
  cwd: projectRoot,
131
191
  },
132
192
  };
@@ -147,11 +207,20 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
147
207
  else if (hasLibTsconfig) {
148
208
  validationTargets.push('typecheck');
149
209
  }
210
+ if (inferCargoWasm && cargoWasmConfig) {
211
+ targets['cargo-wasm'] = createCargoWasmTarget(projectRoot, cargoWasmConfig);
212
+ }
213
+ if (napiConfig) {
214
+ Object.assign(targets, createNapiTargets(projectRoot, napiConfig));
215
+ if (!('napi-test' in (packageJson.nx?.targets ?? {})) &&
216
+ existsSync(join(absoluteProjectRoot, 'src/native.test.ts'))) {
217
+ targets['napi-test'] = createNapiTestTarget(projectRoot, existsSync(join(absoluteProjectRoot, 'bunfig.napi-test.toml')));
218
+ }
219
+ }
150
220
  // Member crates get their targets from the workspace-root package.json,
151
221
  // 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'))) {
154
- const declared = packageJson.nx?.targets ?? {};
222
+ if (isCargoWorkspace) {
223
+ const declared = declaredTargets;
155
224
  if (!('cargo-test' in declared)) {
156
225
  targets['cargo-test'] = createCargoTestTarget(projectRoot);
157
226
  }
@@ -168,7 +237,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
168
237
  };
169
238
  }
170
239
  validationTargets.push('cargo-lint');
171
- if (!('test' in declared) && typeof packageJson.scripts?.test !== 'string') {
240
+ if (!targets.test && !('test' in declared) && typeof packageJson.scripts?.test !== 'string') {
172
241
  // Execute Cargo directly: workspace targetDefaults may replace test.dependsOn.
173
242
  targets.test = createCargoTestTarget(projectRoot);
174
243
  }
@@ -204,7 +273,10 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
204
273
  }
205
274
  if (targets['typecheck-tests']) {
206
275
  if (hasLibTsconfig) {
207
- targets['typecheck-tests'].dependsOn = ['typecheck'];
276
+ // Test configs may resolve the package's own `./index.js` through dist.
277
+ // Rebuild that current-project declaration output after clean, not only
278
+ // dependency-project outputs reached through typecheck.
279
+ targets['typecheck-tests'].dependsOn = ['tsc-js', 'typecheck'];
208
280
  }
209
281
  else if (targets.build) {
210
282
  targets['typecheck-tests'].dependsOn = ['build'];
@@ -226,6 +298,184 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
226
298
  },
227
299
  };
228
300
  }
301
+ const WASM_BINDGEN_OUTPUT_NAMES = {
302
+ bundler: 'bundler',
303
+ deno: 'deno',
304
+ module: 'module',
305
+ 'no-modules': 'no-modules',
306
+ nodejs: 'node',
307
+ web: 'web',
308
+ };
309
+ async function resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath) {
310
+ const manifestPaths = ['Cargo.toml'];
311
+ const cratesDirectory = join(absoluteProjectRoot, 'crates');
312
+ if (existsSync(cratesDirectory)) {
313
+ const crateEntries = await readdir(cratesDirectory, { withFileTypes: true });
314
+ for (const entry of crateEntries.sort((left, right) => left.name.localeCompare(right.name))) {
315
+ if (entry.isDirectory()) {
316
+ const manifestPath = posix.join('crates', entry.name, 'Cargo.toml');
317
+ if (existsSync(join(absoluteProjectRoot, manifestPath))) {
318
+ manifestPaths.push(manifestPath);
319
+ }
320
+ }
321
+ }
322
+ }
323
+ const resolved = [];
324
+ for (const manifestPath of manifestPaths) {
325
+ const absoluteManifestPath = join(absoluteProjectRoot, manifestPath);
326
+ if (!existsSync(absoluteManifestPath)) {
327
+ continue;
328
+ }
329
+ const manifest = parseToml(await readFile(absoluteManifestPath, 'utf-8'));
330
+ const cargoPackage = isRecord(manifest) && isRecord(manifest.package) ? manifest.package : null;
331
+ const metadata = cargoPackage && isRecord(cargoPackage.metadata) ? cargoPackage.metadata : null;
332
+ const smoothbricks = metadata && isRecord(metadata.smoothbricks) ? metadata.smoothbricks : null;
333
+ const rawConfig = smoothbricks && isRecord(smoothbricks['wasm-bindgen']) ? smoothbricks['wasm-bindgen'] : null;
334
+ if (!rawConfig) {
335
+ continue;
336
+ }
337
+ const packageName = cargoPackage?.name;
338
+ if (typeof packageName !== 'string' || !/^[A-Za-z0-9_-]+$/.test(packageName)) {
339
+ throw new Error(`${packageJsonPath}: ${manifestPath} must declare a valid package.name for Wasm inference`);
340
+ }
341
+ const lib = isRecord(manifest) && isRecord(manifest.lib) ? manifest.lib : null;
342
+ const crateTypes = lib?.['crate-type'];
343
+ if (!Array.isArray(crateTypes) || !crateTypes.includes('cdylib')) {
344
+ throw new Error(`${packageJsonPath}: ${manifestPath} Wasm inference requires lib.crate-type to include cdylib`);
345
+ }
346
+ const rawLibraryName = lib?.name ?? packageName.replaceAll('-', '_');
347
+ if (typeof rawLibraryName !== 'string' || !/^[A-Za-z0-9_]+$/.test(rawLibraryName)) {
348
+ throw new Error(`${packageJsonPath}: ${manifestPath} must declare a valid Rust library name`);
349
+ }
350
+ const rawTargets = rawConfig.targets;
351
+ if (!Array.isArray(rawTargets) ||
352
+ rawTargets.length === 0 ||
353
+ !rawTargets.every((target) => typeof target === 'string')) {
354
+ throw new Error(`${packageJsonPath}: ${manifestPath} smoothbricks.wasm-bindgen.targets must be a non-empty string array`);
355
+ }
356
+ const bindgenTargets = [...new Set(rawTargets)];
357
+ const targets = bindgenTargets.map((bindgenTarget) => {
358
+ const outputName = WASM_BINDGEN_OUTPUT_NAMES[bindgenTarget];
359
+ if (!outputName) {
360
+ throw new Error(`${packageJsonPath}: ${manifestPath} has unsupported wasm-bindgen target ${bindgenTarget}`);
361
+ }
362
+ return { bindgenTarget, outputName };
363
+ });
364
+ const rawOutputDirectory = rawConfig['out-dir'] ?? 'dist-wasm';
365
+ if (typeof rawOutputDirectory !== 'string' || !/^[A-Za-z0-9._/-]+$/.test(rawOutputDirectory)) {
366
+ throw new Error(`${packageJsonPath}: ${manifestPath} smoothbricks.wasm-bindgen.out-dir must be a safe relative path`);
367
+ }
368
+ const outputDirectory = posix.normalize(rawOutputDirectory);
369
+ if (outputDirectory === '.' ||
370
+ outputDirectory === '..' ||
371
+ outputDirectory.startsWith('../') ||
372
+ outputDirectory.startsWith('/')) {
373
+ throw new Error(`${packageJsonPath}: ${manifestPath} smoothbricks.wasm-bindgen.out-dir must stay inside the project`);
374
+ }
375
+ resolved.push({ libraryName: rawLibraryName, manifestPath, outputDirectory, targets });
376
+ }
377
+ if (resolved.length > 1) {
378
+ throw new Error(`${packageJsonPath}: only one Cargo crate may declare smoothbricks.wasm-bindgen metadata`);
379
+ }
380
+ return resolved[0] ?? null;
381
+ }
382
+ function inferTypescriptOutputs(tsconfigPath, packageJsonPath) {
383
+ const tsconfig = readJsonFile(tsconfigPath);
384
+ const compilerOptions = isRecord(tsconfig) && isRecord(tsconfig.compilerOptions) ? tsconfig.compilerOptions : null;
385
+ const outDir = compilerOptions?.outDir;
386
+ if (typeof outDir !== 'string' || outDir.length === 0) {
387
+ return ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}', '{projectRoot}/dist/**/*.tsbuildinfo'];
388
+ }
389
+ const normalized = posix.normalize(outDir.replaceAll('\\', '/'));
390
+ if (normalized === '.' || normalized === '..' || normalized.startsWith('../') || normalized.startsWith('/')) {
391
+ throw new Error(`${packageJsonPath}: tsconfig.lib.json compilerOptions.outDir must stay inside the project`);
392
+ }
393
+ return [`{projectRoot}/${normalized}`];
394
+ }
395
+ function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace) {
396
+ if (!packageJson.napi) {
397
+ return null;
398
+ }
399
+ if (!isCargoWorkspace) {
400
+ throw new Error(`${packageJsonPath}: napi target inference requires a Cargo workspace beside package.json`);
401
+ }
402
+ const binaryName = packageJson.napi.binaryName;
403
+ if (typeof binaryName !== 'string' || !/^[A-Za-z0-9_-]+$/.test(binaryName)) {
404
+ throw new Error(`${packageJsonPath}: napi.binaryName must contain only letters, numbers, hyphens, or underscores`);
405
+ }
406
+ const rawTargets = packageJson.napi.targets;
407
+ if (!Array.isArray(rawTargets) ||
408
+ rawTargets.length === 0 ||
409
+ !rawTargets.every((target) => typeof target === 'string')) {
410
+ throw new Error(`${packageJsonPath}: napi.targets must be a non-empty array of target triples`);
411
+ }
412
+ const targets = [...new Set(rawTargets)];
413
+ for (const target of targets) {
414
+ if (!NAPI_TARGET_CONVENTIONS[target]) {
415
+ throw new Error(`${packageJsonPath}: unsupported inferred napi target ${target}`);
416
+ }
417
+ }
418
+ const cargoPackage = `${binaryName}-napi`;
419
+ const manifestPath = `crates/${cargoPackage}/Cargo.toml`;
420
+ if (!existsSync(join(absoluteProjectRoot, manifestPath))) {
421
+ throw new Error(`${packageJsonPath}: inferred N-API crate is missing at ${manifestPath}`);
422
+ }
423
+ return { binaryName, cargoPackage, manifestPath, targets };
424
+ }
425
+ function createNapiTargets(projectRoot, config) {
426
+ const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage}`;
427
+ const targets = {
428
+ 'cargo-napi': {
429
+ executor: 'nx:run-commands',
430
+ cache: true,
431
+ dependsOn: ['^build'],
432
+ inputs: NAPI_INPUTS,
433
+ outputs: ['{projectRoot}/dist/native/host'],
434
+ options: {
435
+ cwd: projectRoot,
436
+ command: `napi build --release --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir dist/native/host`,
437
+ },
438
+ },
439
+ };
440
+ for (const triple of config.targets) {
441
+ const convention = NAPI_TARGET_CONVENTIONS[triple];
442
+ if (!convention) {
443
+ throw new Error(`Missing N-API target convention for ${triple}`);
444
+ }
445
+ const targetName = `napi-${convention.architecture}-${convention.targetFamily}`;
446
+ const outputDirectory = `dist/native/${convention.outputName}`;
447
+ const crossFlag = convention.useNapiCross ? ' --use-napi-cross' : '';
448
+ targets[targetName] = {
449
+ executor: 'nx:run-commands',
450
+ cache: true,
451
+ inputs: NAPI_INPUTS,
452
+ outputs: [`{projectRoot}/${outputDirectory}`],
453
+ options: {
454
+ cwd: projectRoot,
455
+ command: `napi build --release --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputDirectory}`,
456
+ // @napi-rs recognizes Clang and supplies its downloaded GNU sysroot
457
+ // and toolchain flags. This keeps sccache enabled while avoiding the
458
+ // old bundled GCC, which rejects sccache's diagnostics-color flag.
459
+ ...(convention.useNapiCross ? { env: { TARGET_CC: 'clang', TARGET_CXX: 'clang++' } } : {}),
460
+ },
461
+ };
462
+ }
463
+ return targets;
464
+ }
465
+ function createNapiTestTarget(projectRoot, hasDedicatedBunfig) {
466
+ const configFlag = hasDedicatedBunfig ? ' --config=bunfig.napi-test.toml' : '';
467
+ return {
468
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
469
+ cache: true,
470
+ dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
471
+ options: {
472
+ command: `bun${configFlag} test --timeout=30000 src/native.test.ts`,
473
+ cwd: projectRoot,
474
+ timeoutMs: 120000,
475
+ killAfterMs: 10000,
476
+ },
477
+ };
478
+ }
229
479
  async function readPackageJson(packageJsonPath) {
230
480
  const parsed = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
231
481
  if (!isRecord(parsed)) {
@@ -234,6 +484,7 @@ async function readPackageJson(packageJsonPath) {
234
484
  const rawNx = isRecord(parsed.nx) ? parsed.nx : undefined;
235
485
  return {
236
486
  ...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
487
+ ...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
237
488
  ...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
238
489
  ...(rawNx
239
490
  ? {
@@ -3,10 +3,12 @@ import { type NxPolicyIssue } from './workspace-config-policy.js';
3
3
  export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
4
4
  export type { NxPolicyIssue };
5
5
  export interface ResolvedProjectTargets {
6
+ root?: string;
6
7
  targets: ReadonlySet<string>;
7
8
  buildDependsOn?: readonly string[];
8
9
  targetDependencies?: ReadonlyMap<string, readonly string[]>;
9
10
  targetExecutors?: ReadonlyMap<string, string>;
11
+ targetOptions?: ReadonlyMap<string, Readonly<Record<string, unknown>>>;
10
12
  targetScripts?: ReadonlyMap<string, string>;
11
13
  }
12
14
  export interface PackageTargetPolicyOptions {
@@ -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,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OA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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"}
@@ -147,7 +147,11 @@ function isBuildOutputDependencyPattern(dependency) {
147
147
  return BUILD_OUTPUT_DEPENDENCIES.some((pattern) => pattern === dependency);
148
148
  }
149
149
  function expectedTargetDependencies(targetName) {
150
- return targetName === 'preview' ? ['build'] : ['^build'];
150
+ if (targetName === 'preview')
151
+ return ['build'];
152
+ if (targetName.endsWith('-js'))
153
+ return ['^*-js'];
154
+ return ['^build'];
151
155
  }
152
156
  function applyTargetDependencyPolicy(target, targetName) {
153
157
  return setStringArrayProperty(target, 'dependsOn', expectedTargetDependencies(targetName));
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,YACpC,MAAM,EACN,OAAO,EACP,Q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AM,2BAA2B,YAAI,SAAS,CAAU,CAAC;AAChE,eAAO,MAAM,qBAAqB,0CAA4E,CAAC;AAgB/G;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CAuDrF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAa7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYxE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWhE"}
@@ -19,6 +19,7 @@ const nxJsTypescriptPlugin = '@nx/js/typescript';
19
19
  const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
20
20
  const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
21
21
  const expectedSharedGlobalsNamedInput = ['{workspaceRoot}/.github/workflows/ci.yml'];
22
+ const inferredTestTypecheckTarget = 'typecheck-tests';
22
23
  const defaultProductionNamedInput = [
23
24
  '{projectRoot}/src/**/*',
24
25
  '{projectRoot}/package.json',
@@ -43,6 +44,13 @@ export function checkWorkspaceConfig(nxJson) {
43
44
  'Nx CLI syntax already uses project:target:configuration, so smoo Nx target names must be unambiguous tool-output names.',
44
45
  });
45
46
  }
47
+ if (targetName === inferredTestTypecheckTarget) {
48
+ issues.push({
49
+ path: 'nx.json',
50
+ message: `targetDefaults.${inferredTestTypecheckTarget} must not be configured. ` +
51
+ 'Per-project inference selects current library or build outputs before test typechecking.',
52
+ });
53
+ }
46
54
  }
47
55
  }
48
56
  // Build target default
@@ -74,7 +82,7 @@ export function checkWorkspaceConfig(nxJson) {
74
82
  * Mutates in place, returns whether anything changed.
75
83
  */
76
84
  export function applyWorkspaceConfig(nxJson) {
77
- let changed = removeColonTargetDefaults(nxJson);
85
+ let changed = removeDisallowedTargetDefaults(nxJson);
78
86
  changed = applyBuildTargetDefault(nxJson) || changed;
79
87
  changed = applyCleanTargetDefault(nxJson) || changed;
80
88
  changed = applyNamedInputDefaults(nxJson) || changed;
@@ -228,14 +236,14 @@ function applyNamedInputDefaults(nxJson) {
228
236
  }
229
237
  return changed;
230
238
  }
231
- function removeColonTargetDefaults(nxJson) {
239
+ function removeDisallowedTargetDefaults(nxJson) {
232
240
  const targetDefaults = recordProperty(nxJson, 'targetDefaults');
233
241
  if (!targetDefaults) {
234
242
  return false;
235
243
  }
236
244
  let changed = false;
237
245
  for (const targetName of Object.keys(targetDefaults)) {
238
- if (targetName.includes(':')) {
246
+ if (targetName.includes(':') || targetName === inferredTestTypecheckTarget) {
239
247
  delete targetDefaults[targetName];
240
248
  changed = true;
241
249
  }
package/executors.json CHANGED
@@ -5,6 +5,11 @@
5
5
  "schema": "./src/executors/bounded-exec/schema.json",
6
6
  "description": "Run a command with bounded timeout and force-kill behavior"
7
7
  },
8
+ "typescript-emit": {
9
+ "implementation": "./dist/executors/typescript-emit/executor.js",
10
+ "schema": "./src/executors/typescript-emit/schema.json",
11
+ "description": "Emit transformed JavaScript with ttsc and declarations with native tsc"
12
+ },
8
13
  "clean-outputs": {
9
14
  "implementation": "./dist/executors/clean-outputs/executor.js",
10
15
  "schema": "./src/executors/clean-outputs/schema.json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -92,8 +92,9 @@
92
92
  "directory": "packages/nx-plugin"
93
93
  },
94
94
  "dependencies": {
95
- "@nx/js": "23.1.0",
96
- "nx": "23.1.0",
95
+ "@nx/js": "23.1.1",
96
+ "nx": "23.1.1",
97
+ "smol-toml": "^1.6.1",
97
98
  "tslib": "^2.8.1"
98
99
  }
99
100
  }