@smoothbricks/nx-plugin 0.3.0 → 0.3.2

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.
@@ -6,13 +6,15 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
6
6
  '*-web',
7
7
  '*-html',
8
8
  '*-css',
9
- '*-ios',
10
9
  '*-android',
11
10
  '*-native',
12
11
  '*-napi',
13
12
  '*-bun',
14
13
  '*-wasm',
15
14
  ];
15
+ export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'];
16
+ export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'];
17
+ export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS];
16
18
  const nxJsTypescriptPlugin = '@nx/js/typescript';
17
19
  const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
18
20
  const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
@@ -51,19 +53,11 @@ export function checkWorkspaceConfig(nxJson) {
51
53
  validateNamedInputDefaults(nxJson, 'nx.json', issues);
52
54
  // Plugin configuration
53
55
  const plugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
54
- const nxJsPlugin = plugins.find(isNxJsTypescriptPlugin);
55
- if (!nxJsPlugin) {
56
+ if (plugins.some(isNxJsTypescriptPlugin)) {
56
57
  issues.push({
57
58
  path: 'nx.json',
58
- message: `plugins must configure ${nxJsTypescriptPlugin}. ` +
59
- 'Official Nx owns TypeScript library inference; smoo configures it so tsconfig.lib.json produces tsc-js and leaves build available as an aggregate target.',
60
- });
61
- }
62
- else if (nxJsBuildTargetName(nxJsPlugin) !== 'tsc-js') {
63
- issues.push({
64
- path: 'nx.json',
65
- message: `${nxJsTypescriptPlugin} build.targetName must be tsc-js. ` +
66
- 'TypeScript library output is a concrete tool-output target; build is reserved for aggregate targets that depend on concrete build work.',
59
+ message: `plugins must not configure ${nxJsTypescriptPlugin}. ` +
60
+ 'Smoo owns transformer-aware TypeScript targets; Nx native inference only supports tsc/tsgo.',
67
61
  });
68
62
  }
69
63
  if (!plugins.includes(smoothBricksNxPlugin) && !plugins.some(isSmoothBricksNxPluginRecord)) {
@@ -85,7 +79,8 @@ export function applyWorkspaceConfig(nxJson) {
85
79
  changed = applyCleanTargetDefault(nxJson) || changed;
86
80
  changed = applyNamedInputDefaults(nxJson) || changed;
87
81
  const currentPlugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
88
- const nextPlugins = upsertNxPlugin(upsertNxPlugin(currentPlugins, expectedNxJsTypescriptPlugin()), smoothBricksNxPlugin);
82
+ const pluginsWithoutNxTypeScript = currentPlugins.filter((plugin) => !isNxJsTypescriptPlugin(plugin));
83
+ const nextPlugins = upsertNxPlugin(pluginsWithoutNxTypeScript, smoothBricksNxPlugin);
89
84
  if (JSON.stringify(currentPlugins) !== JSON.stringify(nextPlugins)) {
90
85
  nxJson.plugins = nextPlugins;
91
86
  changed = true;
@@ -150,7 +145,7 @@ export function applyWorkspaceConfigPolicy(root) {
150
145
  function validateBuildTargetDefault(nxJson, nxJsonPath, issues) {
151
146
  const targetDefaults = recordProperty(nxJson, 'targetDefaults');
152
147
  const build = targetDefaults ? recordProperty(targetDefaults, 'build') : null;
153
- if (!build || build.cache !== true) {
148
+ if (build?.cache !== true) {
154
149
  issues.push({ path: nxJsonPath, message: 'targetDefaults.build.cache must be true' });
155
150
  }
156
151
  const outputs = build?.outputs;
@@ -164,7 +159,7 @@ function validateCleanTargetDefault(nxJson, nxJsonPath, issues) {
164
159
  if (!clean || clean.executor !== cleanOutputsExecutor) {
165
160
  issues.push({ path: nxJsonPath, message: `targetDefaults.clean.executor must be ${cleanOutputsExecutor}` });
166
161
  }
167
- if (!clean || clean.cache !== false) {
162
+ if (clean?.cache !== false) {
168
163
  issues.push({ path: nxJsonPath, message: 'targetDefaults.clean.cache must be false' });
169
164
  }
170
165
  }
@@ -263,20 +258,6 @@ function isPreciseProductionNamedInput(production) {
263
258
  }
264
259
  return hasPositiveProjectInput;
265
260
  }
266
- function expectedNxJsTypescriptPlugin() {
267
- return {
268
- plugin: nxJsTypescriptPlugin,
269
- options: {
270
- typecheck: { targetName: 'typecheck' },
271
- build: {
272
- targetName: 'tsc-js',
273
- configName: 'tsconfig.lib.json',
274
- buildDepsName: 'build-deps',
275
- watchDepsName: 'watch-deps',
276
- },
277
- },
278
- };
279
- }
280
261
  function upsertNxPlugin(plugins, plugin) {
281
262
  const pluginName = typeof plugin === 'string' ? plugin : stringProperty(plugin, 'plugin');
282
263
  const next = plugins.filter((entry) => nxPluginName(entry) !== pluginName);
@@ -290,16 +271,11 @@ function nxPluginName(value) {
290
271
  return isRecord(value) ? stringProperty(value, 'plugin') : null;
291
272
  }
292
273
  function isNxJsTypescriptPlugin(value) {
293
- return isRecord(value) && stringProperty(value, 'plugin') === nxJsTypescriptPlugin;
274
+ return (value === nxJsTypescriptPlugin || (isRecord(value) && stringProperty(value, 'plugin') === nxJsTypescriptPlugin));
294
275
  }
295
276
  function isSmoothBricksNxPluginRecord(value) {
296
277
  return isRecord(value) && stringProperty(value, 'plugin') === smoothBricksNxPlugin;
297
278
  }
298
- function nxJsBuildTargetName(plugin) {
299
- const options = recordProperty(plugin, 'options');
300
- const build = options ? recordProperty(options, 'build') : null;
301
- return build ? stringProperty(build, 'targetName') : null;
302
- }
303
279
  function readJsonObject(path) {
304
280
  if (!existsSync(path)) {
305
281
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -92,8 +92,8 @@
92
92
  "directory": "packages/nx-plugin"
93
93
  },
94
94
  "dependencies": {
95
- "@nx/js": "22.7.1",
96
- "nx": "22.7.1",
95
+ "@nx/js": "23.1.0",
96
+ "nx": "23.1.0",
97
97
  "tslib": "^2.8.1"
98
98
  }
99
99
  }
@@ -41,7 +41,11 @@ export function applyBoundedTestTargetPolicy(
41
41
  options: ApplyBoundedTestTargetPolicyOptions,
42
42
  ): void {
43
43
  const command = resolveTestCommand(packageJson, options.defaultCommand ?? 'bun test', options.projectJson);
44
- const targetOwner = options.projectJson ?? (packageJson.nx ??= {});
44
+ let targetOwner = options.projectJson;
45
+ if (!targetOwner) {
46
+ packageJson.nx ??= {};
47
+ targetOwner = packageJson.nx;
48
+ }
45
49
 
46
50
  targetOwner.targets ??= {};
47
51
 
@@ -251,7 +255,22 @@ function listWorkspacePackageJsonPaths(root: string): string[] {
251
255
  }
252
256
 
253
257
  function readPackageJson(path: string): BoundedTestPolicyPackageJson {
254
- return JSON.parse(readFileSync(path, 'utf8')) as BoundedTestPolicyPackageJson;
258
+ const parsed = readJsonObject(path);
259
+ const nx = isRecord(parsed.nx) ? parsed.nx : undefined;
260
+ const normalizedNx = nx
261
+ ? {
262
+ ...nx,
263
+ name: typeof nx.name === 'string' ? nx.name : undefined,
264
+ targets: readTargets(nx.targets),
265
+ }
266
+ : undefined;
267
+ return {
268
+ ...parsed,
269
+ name: typeof parsed.name === 'string' ? parsed.name : undefined,
270
+ workspaces: parsed.workspaces,
271
+ scripts: isRecord(parsed.scripts) ? parsed.scripts : undefined,
272
+ nx: normalizedNx,
273
+ };
255
274
  }
256
275
 
257
276
  function writePackageJson(path: string, packageJson: BoundedTestPolicyPackageJson): void {
@@ -259,7 +278,31 @@ function writePackageJson(path: string, packageJson: BoundedTestPolicyPackageJso
259
278
  }
260
279
 
261
280
  function readProjectJson(path: string): BoundedTestPolicyProjectJson {
262
- return JSON.parse(readFileSync(path, 'utf8')) as BoundedTestPolicyProjectJson;
281
+ const parsed = readJsonObject(path);
282
+ return {
283
+ ...parsed,
284
+ name: typeof parsed.name === 'string' ? parsed.name : undefined,
285
+ targets: readTargets(parsed.targets),
286
+ };
287
+ }
288
+
289
+ function readJsonObject(path: string): Record<string, unknown> {
290
+ const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'));
291
+ if (!isRecord(parsed)) {
292
+ throw new Error(`${path} must contain a JSON object`);
293
+ }
294
+ return parsed;
295
+ }
296
+
297
+ function readTargets(value: unknown): Record<string, Record<string, unknown>> | undefined {
298
+ if (!isRecord(value)) {
299
+ return undefined;
300
+ }
301
+ const targets: Record<string, Record<string, unknown>> = {};
302
+ for (const [name, target] of Object.entries(value)) {
303
+ targets[name] = isRecord(target) ? target : {};
304
+ }
305
+ return targets;
263
306
  }
264
307
 
265
308
  function writeProjectJson(path: string, projectJson: BoundedTestPolicyProjectJson): void {
@@ -140,14 +140,18 @@ function buildPackageJson(
140
140
  packageJson.license = 'MIT';
141
141
  packageJson.publishConfig = { access: 'public' };
142
142
  const rootRepository = rootPkg.repository;
143
- if (rootRepository && typeof rootRepository === 'object') {
143
+ if (isRecord(rootRepository)) {
144
144
  packageJson.repository = {
145
- type: (rootRepository as Record<string, unknown>).type ?? 'git',
146
- url: (rootRepository as Record<string, unknown>).url,
145
+ type: rootRepository.type ?? 'git',
146
+ url: rootRepository.url,
147
147
  directory: projectRoot,
148
148
  };
149
149
  }
150
- (packageJson.nx as Record<string, unknown>).tags = ['npm:public'];
150
+ const nx = packageJson.nx;
151
+ if (!isRecord(nx)) {
152
+ throw new Error('generated package.json nx configuration must be an object');
153
+ }
154
+ nx.tags = ['npm:public'];
151
155
  } else {
152
156
  packageJson.private = true;
153
157
  }
@@ -160,13 +164,25 @@ function writeZigFiles(tree: Tree, schema: CreatePackageGeneratorSchema, project
160
164
  const packageJson = readJson<Record<string, unknown>>(tree, `${projectRoot}/package.json`);
161
165
 
162
166
  // Add wasm export and remove development condition
163
- const exports = packageJson.exports as Record<string, unknown>;
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
+ }
164
172
  exports['./wasm'] = `./dist/${schema.name}.wasm`;
165
- const dotExport = exports['.'] as Record<string, unknown>;
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
+ }
166
178
  delete dotExport.development;
167
179
 
168
180
  // Add build scripts
169
- const scripts = packageJson.scripts as Record<string, string>;
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
+ }
170
186
  scripts['build:zig'] = `nx run ${schema.name}:zig-wasm`;
171
187
  scripts['build:ts'] = `nx run ${schema.name}:tsc-js`;
172
188
  scripts.build = 'bun run build:ts && bun run build:zig';
@@ -178,7 +194,11 @@ function writeZigFiles(tree: Tree, schema: CreatePackageGeneratorSchema, project
178
194
 
179
195
  // Modify tsconfig.lib.json for ts-zig
180
196
  const tsconfigLib = readJson<Record<string, unknown>>(tree, `${projectRoot}/tsconfig.lib.json`);
181
- const libCompilerOptions = tsconfigLib.compilerOptions as Record<string, unknown>;
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
+ }
182
202
  libCompilerOptions.lib = ['es2022', 'webworker'];
183
203
  libCompilerOptions.declaration = true;
184
204
  libCompilerOptions.sourceMap = true;
@@ -187,7 +207,11 @@ function writeZigFiles(tree: Tree, schema: CreatePackageGeneratorSchema, project
187
207
 
188
208
  // Modify tsconfig.test.json for ts-zig
189
209
  const tsconfigTest = readJson<Record<string, unknown>>(tree, `${projectRoot}/tsconfig.test.json`);
190
- const testCompilerOptions = tsconfigTest.compilerOptions as Record<string, unknown>;
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
+ }
191
215
  testCompilerOptions.lib = ['es2022', 'webworker'];
192
216
  writeJson(tree, `${projectRoot}/tsconfig.test.json`, tsconfigTest);
193
217
 
@@ -249,3 +273,7 @@ pub fn build(b: *std.Build) void {
249
273
  `,
250
274
  );
251
275
  }
276
+
277
+ function isRecord(value: unknown): value is Record<string, unknown> {
278
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
279
+ }
@@ -40,7 +40,7 @@ export default async function generator(tree: Tree, schema: MakePublicGeneratorS
40
40
  };
41
41
  }
42
42
 
43
- const nx = (pkg.nx ?? {}) as Record<string, unknown>;
43
+ const nx = isRecord(pkg.nx) ? pkg.nx : {};
44
44
  const tags = Array.isArray(nx.tags) ? [...nx.tags] : [];
45
45
  if (!tags.includes('npm:public')) {
46
46
  tags.push('npm:public');
@@ -56,6 +56,10 @@ export default async function generator(tree: Tree, schema: MakePublicGeneratorS
56
56
  });
57
57
  }
58
58
 
59
+ function isRecord(value: unknown): value is Record<string, unknown> {
60
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
61
+ }
62
+
59
63
  function resolveProject(tree: Tree, projectInput: string): { name: string; root: string } {
60
64
  const normalizedInput = normalizeLookupValue(projectInput);
61
65
 
package/src/index.test.ts CHANGED
@@ -5,21 +5,10 @@ import { dirname, join } from 'node:path';
5
5
 
6
6
  import type { CreateNodesContextV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
7
7
  import { createNodesV2 } from './index.js';
8
+ import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
8
9
 
9
10
  const [, inferTargets] = createNodesV2;
10
- const buildOutputDependencies = [
11
- '^build',
12
- '*-js',
13
- '*-web',
14
- '*-html',
15
- '*-css',
16
- '*-ios',
17
- '*-android',
18
- '*-native',
19
- '*-napi',
20
- '*-bun',
21
- '*-wasm',
22
- ];
11
+ const buildOutputDependencies = ['^build', ...BUILD_OUTPUT_DEPENDENCIES];
23
12
 
24
13
  describe('@smoothbricks/nx-plugin inferred targets', () => {
25
14
  it('names standalone package projects from package metadata', async () => {
@@ -43,7 +32,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
43
32
  }
44
33
  });
45
34
 
46
- it('infers validation and aggregate build targets without owning TypeScript lib build', async () => {
35
+ it('overrides inferred TypeScript compiler commands with ttsc', async () => {
47
36
  const workspace = await createWorkspace();
48
37
  try {
49
38
  await workspace.write(
@@ -55,7 +44,33 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
55
44
 
56
45
  const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
57
46
 
58
- expect(targets['tsc-js']).toBeUndefined();
47
+ expect(targets['tsc-js']?.options).toMatchObject({
48
+ command: 'ttsc -p tsconfig.lib.json --emit',
49
+ cwd: 'packages/example',
50
+ });
51
+ const toolchainInputs = [
52
+ '{workspaceRoot}/package.json',
53
+ '{workspaceRoot}/bun.lock',
54
+ '{workspaceRoot}/patches/**/*',
55
+ '{workspaceRoot}/tsconfig.base.json',
56
+ ];
57
+ expect(targets['tsc-js']?.inputs).toEqual([
58
+ 'production',
59
+ '^production',
60
+ ...toolchainInputs,
61
+ '{projectRoot}/tsconfig.lib.json',
62
+ ]);
63
+ expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']);
64
+ expect(targets.typecheck?.options).toMatchObject({
65
+ command: 'ttsc -p tsconfig.lib.json --noEmit',
66
+ cwd: 'packages/example',
67
+ });
68
+ expect(targets.typecheck?.inputs).toEqual([
69
+ 'production',
70
+ '^production',
71
+ ...toolchainInputs,
72
+ '{projectRoot}/tsconfig.lib.json',
73
+ ]);
59
74
  expect(targets.build?.executor).toBe('nx:noop');
60
75
  expect(targets.build?.cache).toBe(true);
61
76
  expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
@@ -66,14 +81,20 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
66
81
  expect(targets['typecheck-tests']?.cache).toBe(true);
67
82
  expect(targets['typecheck-tests']?.dependsOn).toEqual(['typecheck']);
68
83
  expect(targets['typecheck-tests']?.options).toMatchObject({
69
- command: 'tsc --noEmit -p tsconfig.test.json',
84
+ command: 'ttsc -p tsconfig.test.json --noEmit',
70
85
  cwd: 'packages/example',
71
86
  });
87
+ expect(targets['typecheck-tests']?.inputs).toEqual([
88
+ 'default',
89
+ '^production',
90
+ ...toolchainInputs,
91
+ '{projectRoot}/tsconfig.test.json',
92
+ ]);
72
93
 
73
94
  expect(targets['typecheck-tests:watch']?.executor).toBe('nx:run-commands');
74
95
  expect(targets['typecheck-tests:watch']?.continuous).toBe(true);
75
96
  expect(targets['typecheck-tests:watch']?.options).toMatchObject({
76
- command: 'tsc --noEmit -p tsconfig.test.json --watch',
97
+ command: 'ttsc -p tsconfig.test.json --noEmit --watch',
77
98
  cwd: 'packages/example',
78
99
  });
79
100
 
@@ -85,7 +106,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
85
106
  cwd: 'packages/example',
86
107
  });
87
108
 
88
- expect(targets.lint?.executor).toBe('nx:noop');
109
+ expect(targets.lint?.executor).toBeUndefined();
89
110
  expect(targets.lint?.cache).toBe(true);
90
111
  expect(targets.lint?.dependsOn).toEqual(['typecheck-tests']);
91
112
  } finally {
@@ -140,6 +161,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
140
161
  expect(targets.build?.cache).toBe(true);
141
162
  expect(targets['zig-wasm']?.cache).toBe(true);
142
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}']);
143
166
  expect(targets['zig-wasm']?.options).toEqual({
144
167
  command: 'zig build wasm',
145
168
  cwd: 'packages/ziggy',
@@ -173,6 +196,35 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
173
196
  }
174
197
  });
175
198
 
199
+ it('keeps platform-only output families out of the ordinary aggregate build', async () => {
200
+ const workspace = await createWorkspace();
201
+ try {
202
+ await workspace.write(
203
+ 'packages/platform/package.json',
204
+ JSON.stringify({
205
+ name: 'platform',
206
+ nx: {
207
+ targets: {
208
+ 'bundle-ios': { executor: 'nx:run-commands' },
209
+ 'bundle-macos': { executor: 'nx:run-commands' },
210
+ 'bundle-linux': { executor: 'nx:run-commands' },
211
+ },
212
+ },
213
+ }),
214
+ );
215
+
216
+ const targets = await inferProjectTargets(workspace, 'packages/platform/package.json');
217
+
218
+ expect(targets.build).toBeUndefined();
219
+ expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
220
+ expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-ios');
221
+ expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-macos');
222
+ expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-linux');
223
+ } finally {
224
+ await workspace.cleanup();
225
+ }
226
+ });
227
+
176
228
  it('infers cargo workspace targets including explicitly named wasm crate builds', async () => {
177
229
  const workspace = await createWorkspace();
178
230
  try {
package/src/index.ts CHANGED
@@ -5,12 +5,21 @@ import { dirname, join } from 'node:path';
5
5
  import type { CreateNodesResultV2, CreateNodesV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
6
6
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
7
7
 
8
- import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
8
+ import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
9
9
 
10
10
  const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
11
11
  const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
12
12
  const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
13
- const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|ios|android|native|napi|bun|wasm)$/;
13
+ 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
+ const TYPESCRIPT_TOOLCHAIN_INPUTS = [
18
+ '{workspaceRoot}/package.json',
19
+ '{workspaceRoot}/bun.lock',
20
+ '{workspaceRoot}/patches/**/*',
21
+ '{workspaceRoot}/tsconfig.base.json',
22
+ ];
14
23
 
15
24
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
16
25
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
@@ -92,15 +101,46 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
92
101
  const targets: Record<string, TargetConfiguration> = {};
93
102
  const validationTargets: string[] = [];
94
103
  const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
95
- let hasBuildOutputTarget = hasLibTsconfig || hasPackageLocalBuildOutputTarget(packageJson);
104
+ const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
105
+ let hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
106
+ let hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
107
+
108
+ if (hasLibTsconfig) {
109
+ // Official Nx target inference is disabled because its compiler surface only
110
+ // supports tsc/tsgo. Smoo owns the complete transformer-aware ttsc targets.
111
+ targets['tsc-js'] = {
112
+ executor: 'nx:run-commands',
113
+ cache: true,
114
+ inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
115
+ outputs: ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'],
116
+ dependsOn: ['^tsc-js'],
117
+ options: {
118
+ command: 'ttsc -p tsconfig.lib.json --emit',
119
+ cwd: projectRoot,
120
+ },
121
+ };
122
+ targets.typecheck = {
123
+ executor: 'nx:run-commands',
124
+ cache: true,
125
+ inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
126
+ outputs: [],
127
+ dependsOn: ['^tsc-js'],
128
+ options: {
129
+ command: 'ttsc -p tsconfig.lib.json --noEmit',
130
+ cwd: projectRoot,
131
+ },
132
+ };
133
+ }
96
134
 
97
135
  const hasTestTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.test.json'));
98
136
  if (hasTestTsconfig) {
99
137
  targets['typecheck-tests'] = {
100
138
  executor: 'nx:run-commands',
101
139
  cache: true,
140
+ inputs: ['default', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.test.json'],
141
+ dependsOn: ['typecheck'],
102
142
  options: {
103
- command: 'tsc --noEmit -p tsconfig.test.json',
143
+ command: 'ttsc -p tsconfig.test.json --noEmit',
104
144
  cwd: projectRoot,
105
145
  },
106
146
  };
@@ -108,7 +148,7 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
108
148
  executor: 'nx:run-commands',
109
149
  continuous: true,
110
150
  options: {
111
- command: 'tsc --noEmit -p tsconfig.test.json --watch',
151
+ command: 'ttsc -p tsconfig.test.json --noEmit --watch',
112
152
  cwd: projectRoot,
113
153
  },
114
154
  };
@@ -192,7 +232,8 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
192
232
  },
193
233
  },
194
234
  };
195
- hasBuildOutputTarget = true;
235
+ hasOrdinaryBuildOutputTarget = true;
236
+ hasAnyBuildOutputTarget = true;
196
237
  }
197
238
  }
198
239
 
@@ -203,28 +244,24 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
203
244
  executor: 'nx:run-commands',
204
245
  cache: true,
205
246
  inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
206
- outputs: [
207
- '{projectRoot}/dist/**/*.wasm',
208
- '{projectRoot}/dist/**/*.node',
209
- '{projectRoot}/dist/**/*.dylib',
210
- '{projectRoot}/dist/**/*.so',
211
- '{projectRoot}/dist/**/*.dll',
212
- '{projectRoot}/dist/**/*.a',
213
- ],
247
+ outputs: zigOutputsForStep(step),
214
248
  options: {
215
249
  command: `zig build ${step}`,
216
250
  cwd: projectRoot,
217
251
  },
218
252
  };
219
- hasBuildOutputTarget = true;
253
+ hasOrdinaryBuildOutputTarget = true;
254
+ hasAnyBuildOutputTarget = true;
220
255
  }
221
256
 
222
- if (hasBuildOutputTarget) {
257
+ if (hasOrdinaryBuildOutputTarget) {
223
258
  targets.build = {
224
259
  executor: 'nx:noop',
225
260
  cache: true,
226
261
  dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
227
262
  };
263
+ }
264
+ if (hasAnyBuildOutputTarget) {
228
265
  targets.clean = {
229
266
  executor: '@smoothbricks/nx-plugin:clean-outputs',
230
267
  cache: false,
@@ -241,7 +278,6 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
241
278
 
242
279
  if (validationTargets.length > 0) {
243
280
  targets.lint = {
244
- executor: 'nx:noop',
245
281
  cache: true,
246
282
  dependsOn: validationTargets,
247
283
  };
@@ -260,7 +296,23 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
260
296
  }
261
297
 
262
298
  async function readPackageJson(packageJsonPath: string): Promise<PackageJson> {
263
- return JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
299
+ const parsed: unknown = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
300
+ if (!isRecord(parsed)) {
301
+ throw new Error(`${packageJsonPath} must contain a JSON object`);
302
+ }
303
+ const rawNx = isRecord(parsed.nx) ? parsed.nx : undefined;
304
+ return {
305
+ ...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
306
+ ...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
307
+ ...(rawNx
308
+ ? {
309
+ nx: {
310
+ ...(typeof rawNx.name === 'string' ? { name: rawNx.name } : {}),
311
+ ...(isRecord(rawNx.targets) ? { targets: rawNx.targets } : {}),
312
+ },
313
+ }
314
+ : {}),
315
+ };
264
316
  }
265
317
 
266
318
  function inferTestWatchCommand(packageJson: PackageJson): string | null {
@@ -314,13 +366,25 @@ function isRecord(value: unknown): value is Record<string, unknown> {
314
366
  return value !== null && typeof value === 'object';
315
367
  }
316
368
 
317
- function hasPackageLocalBuildOutputTarget(packageJson: PackageJson): boolean {
369
+ function classifyPackageLocalBuildOutputs(packageJson: PackageJson): { ordinary: boolean; platform: boolean } {
318
370
  const targets = packageJson.nx?.targets;
319
- if (!isRecord(targets)) {
320
- return false;
321
- }
371
+ const targetNames = isRecord(targets) ? Object.keys(targets) : [];
372
+ return {
373
+ ordinary: targetNames.some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName)),
374
+ platform: targetNames.some((targetName) =>
375
+ PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1))),
376
+ ),
377
+ };
378
+ }
322
379
 
323
- return Object.keys(targets).some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName));
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;
324
388
  }
325
389
 
326
390
  interface CargoWorkspace {