@smoothbricks/nx-plugin 0.1.0 → 0.2.1

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 (74) hide show
  1. package/README.md +35 -8
  2. package/dist/bounded-test-policy.d.ts +32 -0
  3. package/dist/bounded-test-policy.d.ts.map +1 -0
  4. package/dist/bounded-test-policy.js +184 -0
  5. package/dist/executors/bounded-exec/executor.d.ts +15 -0
  6. package/dist/executors/bounded-exec/executor.d.ts.map +1 -0
  7. package/dist/executors/bounded-exec/executor.js +179 -0
  8. package/dist/executors/bounded-exec/schema.d.ts +11 -0
  9. package/dist/executors/bounded-exec/schema.d.ts.map +1 -0
  10. package/dist/executors/bounded-exec/schema.js +1 -0
  11. package/dist/generators/bounded-test-targets/generator.d.ts +7 -0
  12. package/dist/generators/bounded-test-targets/generator.d.ts.map +1 -0
  13. package/dist/generators/bounded-test-targets/generator.js +40 -0
  14. package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -1
  15. package/dist/generators/bun-test-tracing/generator.js +5 -4
  16. package/dist/generators/create-package/generator.d.ts +4 -0
  17. package/dist/generators/create-package/generator.d.ts.map +1 -0
  18. package/dist/generators/create-package/generator.js +204 -0
  19. package/dist/generators/make-public/generator.d.ts +4 -0
  20. package/dist/generators/make-public/generator.d.ts.map +1 -0
  21. package/dist/generators/make-public/generator.js +55 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +78 -7
  24. package/dist/package-target-policy.d.ts +31 -0
  25. package/dist/package-target-policy.d.ts.map +1 -0
  26. package/dist/package-target-policy.js +937 -0
  27. package/dist/release-config-policy.d.ts +32 -0
  28. package/dist/release-config-policy.d.ts.map +1 -0
  29. package/dist/release-config-policy.js +225 -0
  30. package/dist/typecheck-test-policy.d.ts +56 -0
  31. package/dist/typecheck-test-policy.d.ts.map +1 -0
  32. package/dist/typecheck-test-policy.js +640 -0
  33. package/dist/version-actions.cjs +78 -0
  34. package/dist/version-actions.d.cts +6 -0
  35. package/dist/version-actions.d.cts.map +1 -0
  36. package/dist/workspace-config-policy.d.ts +33 -0
  37. package/dist/workspace-config-policy.d.ts.map +1 -0
  38. package/dist/workspace-config-policy.js +334 -0
  39. package/executors.json +9 -0
  40. package/generators.json +15 -0
  41. package/package.json +45 -11
  42. package/src/bounded-test-policy.test.ts +257 -0
  43. package/src/bounded-test-policy.ts +257 -0
  44. package/src/bun-bootstrap.test.ts +52 -0
  45. package/src/executors/bounded-exec/executor.test.ts +258 -0
  46. package/src/executors/bounded-exec/executor.ts +228 -0
  47. package/src/executors/bounded-exec/schema.json +68 -0
  48. package/src/executors/bounded-exec/schema.ts +10 -0
  49. package/src/generators/bounded-test-targets/generator.test.ts +136 -0
  50. package/src/generators/bounded-test-targets/generator.ts +67 -0
  51. package/src/generators/bounded-test-targets/schema.d.ts +3 -0
  52. package/src/generators/bounded-test-targets/schema.json +14 -0
  53. package/src/generators/bun-test-tracing/generator.test.ts +25 -1
  54. package/src/generators/bun-test-tracing/generator.ts +6 -5
  55. package/src/generators/create-package/generator.test.ts +206 -0
  56. package/src/generators/create-package/generator.ts +251 -0
  57. package/src/generators/create-package/schema.d.ts +5 -0
  58. package/src/generators/create-package/schema.json +24 -0
  59. package/src/generators/make-public/generator.test.ts +137 -0
  60. package/src/generators/make-public/generator.ts +83 -0
  61. package/src/generators/make-public/schema.d.ts +3 -0
  62. package/src/generators/make-public/schema.json +13 -0
  63. package/src/index.test.ts +85 -18
  64. package/src/index.ts +99 -8
  65. package/src/package-target-policy.test.ts +785 -0
  66. package/src/package-target-policy.ts +1140 -0
  67. package/src/release-config-policy.test.ts +280 -0
  68. package/src/release-config-policy.ts +258 -0
  69. package/src/typecheck-test-policy.test.ts +797 -0
  70. package/src/typecheck-test-policy.ts +752 -0
  71. package/src/version-actions.cts +94 -0
  72. package/src/workspace-config-policy.test.ts +376 -0
  73. package/src/workspace-config-policy.ts +390 -0
  74. package/src/test-suite-tracer.ts +0 -0
@@ -0,0 +1,137 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { addProjectConfiguration, readJson, type Tree } from 'nx/src/devkit-exports.js';
3
+ import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
4
+
5
+ import generator from './generator.js';
6
+
7
+ function setupTree(): Tree {
8
+ const tree = createTreeWithEmptyWorkspace();
9
+ tree.write(
10
+ 'package.json',
11
+ JSON.stringify(
12
+ {
13
+ name: '@smoothbricks/codebase',
14
+ license: 'MIT',
15
+ repository: { type: 'git', url: 'git+https://github.com/smoothbricks/codebase.git' },
16
+ workspaces: ['packages/*'],
17
+ },
18
+ null,
19
+ 2,
20
+ ),
21
+ );
22
+ return tree;
23
+ }
24
+
25
+ function addPackage(tree: Tree, name: string, root: string, extra: Record<string, unknown> = {}): void {
26
+ addProjectConfiguration(tree, name, { root, targets: {} });
27
+ if (tree.exists(`${root}/project.json`)) tree.delete(`${root}/project.json`);
28
+ tree.write(
29
+ `${root}/package.json`,
30
+ JSON.stringify(
31
+ {
32
+ name: `@smoothbricks/${name}`,
33
+ version: '0.0.0',
34
+ private: true,
35
+ nx: { name },
36
+ ...extra,
37
+ },
38
+ null,
39
+ 2,
40
+ ),
41
+ );
42
+ }
43
+
44
+ describe('make-public generator', () => {
45
+ it('promotes private package to public', async () => {
46
+ const tree = setupTree();
47
+ addPackage(tree, 'my-lib', 'packages/my-lib');
48
+
49
+ await generator(tree, { project: 'my-lib' });
50
+
51
+ const pkg = readJson(tree, 'packages/my-lib/package.json');
52
+ expect(pkg.private).toBeUndefined();
53
+ expect(pkg.license).toBe('MIT');
54
+ expect(pkg.publishConfig).toEqual({ access: 'public' });
55
+ expect(pkg.repository).toEqual({
56
+ type: 'git',
57
+ url: 'git+https://github.com/smoothbricks/codebase.git',
58
+ directory: 'packages/my-lib',
59
+ });
60
+ expect(pkg.nx.tags).toContain('npm:public');
61
+ expect(pkg.version).toBe('0.1.0');
62
+ });
63
+
64
+ it('preserves existing license', async () => {
65
+ const tree = setupTree();
66
+ addPackage(tree, 'my-lib', 'packages/my-lib', { license: 'Apache-2.0' });
67
+
68
+ await generator(tree, { project: 'my-lib' });
69
+
70
+ const pkg = readJson(tree, 'packages/my-lib/package.json');
71
+ expect(pkg.license).toBe('Apache-2.0');
72
+ });
73
+
74
+ it('does not duplicate npm:public tag', async () => {
75
+ const tree = setupTree();
76
+ addPackage(tree, 'my-lib', 'packages/my-lib', { nx: { name: 'my-lib', tags: ['npm:public'] } });
77
+
78
+ await generator(tree, { project: 'my-lib' });
79
+
80
+ const pkg = readJson(tree, 'packages/my-lib/package.json');
81
+ const publicTags = pkg.nx.tags.filter((t: string) => t === 'npm:public');
82
+ expect(publicTags).toHaveLength(1);
83
+ });
84
+
85
+ it('preserves version above 0.0.0', async () => {
86
+ const tree = setupTree();
87
+ addPackage(tree, 'my-lib', 'packages/my-lib', { version: '1.2.3' });
88
+
89
+ await generator(tree, { project: 'my-lib' });
90
+
91
+ const pkg = readJson(tree, 'packages/my-lib/package.json');
92
+ expect(pkg.version).toBe('1.2.3');
93
+ });
94
+
95
+ it('resolves by project name, package name, and root', async () => {
96
+ const tree = setupTree();
97
+ addPackage(tree, 'my-lib', 'packages/my-lib');
98
+
99
+ // By project name
100
+ await generator(tree, { project: 'my-lib' });
101
+ expect(readJson(tree, 'packages/my-lib/package.json').private).toBeUndefined();
102
+
103
+ // Reset private for next lookup test
104
+ tree.write(
105
+ 'packages/my-lib/package.json',
106
+ JSON.stringify(
107
+ { name: '@smoothbricks/my-lib', version: '0.0.0', private: true, nx: { name: 'my-lib' } },
108
+ null,
109
+ 2,
110
+ ),
111
+ );
112
+
113
+ // By package name
114
+ await generator(tree, { project: '@smoothbricks/my-lib' });
115
+ expect(readJson(tree, 'packages/my-lib/package.json').private).toBeUndefined();
116
+
117
+ // Reset private for next lookup test
118
+ tree.write(
119
+ 'packages/my-lib/package.json',
120
+ JSON.stringify(
121
+ { name: '@smoothbricks/my-lib', version: '0.0.0', private: true, nx: { name: 'my-lib' } },
122
+ null,
123
+ 2,
124
+ ),
125
+ );
126
+
127
+ // By root path
128
+ await generator(tree, { project: 'packages/my-lib' });
129
+ expect(readJson(tree, 'packages/my-lib/package.json').private).toBeUndefined();
130
+ });
131
+
132
+ it('throws for unknown project', async () => {
133
+ const tree = setupTree();
134
+
135
+ expect(generator(tree, { project: 'nonexistent' })).rejects.toThrow('Could not resolve project nonexistent');
136
+ });
137
+ });
@@ -0,0 +1,83 @@
1
+ // Promote a private package to npm publication. Invoked by `smoo g make-public <name>`.
2
+ // CLI wiring: packages/cli/src/generate/index.ts (variant registry)
3
+ import {
4
+ getProjects,
5
+ joinPathFragments,
6
+ normalizePath,
7
+ readJson,
8
+ type Tree,
9
+ updateJson,
10
+ } from 'nx/src/devkit-exports.js';
11
+
12
+ import type { MakePublicGeneratorSchema } from './schema.js';
13
+
14
+ export default async function generator(tree: Tree, schema: MakePublicGeneratorSchema): Promise<void> {
15
+ const resolved = resolveProject(tree, schema.project);
16
+ const packageJsonPath = joinPathFragments(resolved.root, 'package.json');
17
+
18
+ if (!tree.exists(packageJsonPath)) {
19
+ throw new Error(`Project ${resolved.name} is missing ${packageJsonPath}`);
20
+ }
21
+
22
+ const rootPkg = readJson<{ name?: string; license?: string; repository?: Record<string, unknown> }>(
23
+ tree,
24
+ 'package.json',
25
+ );
26
+
27
+ updateJson(tree, packageJsonPath, (pkg: Record<string, unknown>) => {
28
+ delete pkg.private;
29
+
30
+ if (!pkg.license && rootPkg.license) {
31
+ pkg.license = rootPkg.license;
32
+ }
33
+
34
+ pkg.publishConfig = { access: 'public' };
35
+
36
+ if (rootPkg.repository) {
37
+ pkg.repository = {
38
+ ...(typeof rootPkg.repository === 'object' ? rootPkg.repository : {}),
39
+ directory: resolved.root,
40
+ };
41
+ }
42
+
43
+ const nx = (pkg.nx ?? {}) as Record<string, unknown>;
44
+ const tags = Array.isArray(nx.tags) ? [...nx.tags] : [];
45
+ if (!tags.includes('npm:public')) {
46
+ tags.push('npm:public');
47
+ }
48
+ nx.tags = tags;
49
+ pkg.nx = nx;
50
+
51
+ if (pkg.version === '0.0.0') {
52
+ pkg.version = '0.1.0';
53
+ }
54
+
55
+ return pkg;
56
+ });
57
+ }
58
+
59
+ function resolveProject(tree: Tree, projectInput: string): { name: string; root: string } {
60
+ const normalizedInput = normalizeLookupValue(projectInput);
61
+
62
+ for (const [name, config] of getProjects(tree)) {
63
+ if (normalizeLookupValue(name) === normalizedInput || normalizeLookupValue(config.root) === normalizedInput) {
64
+ return { name, root: config.root };
65
+ }
66
+
67
+ const packageJsonPath = joinPathFragments(config.root, 'package.json');
68
+ if (!tree.exists(packageJsonPath)) {
69
+ continue;
70
+ }
71
+
72
+ const packageJson = readJson<{ name?: string }>(tree, packageJsonPath);
73
+ if (packageJson.name && normalizeLookupValue(packageJson.name) === normalizedInput) {
74
+ return { name, root: config.root };
75
+ }
76
+ }
77
+
78
+ throw new Error(`Could not resolve project ${projectInput}`);
79
+ }
80
+
81
+ function normalizeLookupValue(value: string): string {
82
+ return normalizePath(value.replace(/^\.\//, ''));
83
+ }
@@ -0,0 +1,3 @@
1
+ export interface MakePublicGeneratorSchema {
2
+ project: string;
3
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "id": "MakePublic",
4
+ "title": "Promote a private package to public npm publication",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": {
8
+ "type": "string",
9
+ "description": "Nx project name, package name, or project root to promote."
10
+ }
11
+ },
12
+ "required": ["project"]
13
+ }
package/src/index.test.ts CHANGED
@@ -7,36 +7,84 @@ import type { CreateNodesContextV2, TargetConfiguration } from 'nx/src/devkit-ex
7
7
  import { createNodesV2 } from './index.js';
8
8
 
9
9
  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
+ ];
10
23
 
11
24
  describe('@smoothbricks/nx-plugin inferred targets', () => {
12
25
  it('infers validation and aggregate build targets without owning TypeScript lib build', async () => {
13
26
  const workspace = await createWorkspace();
14
27
  try {
15
- await workspace.write('packages/example/package.json', '{"name":"example"}\n');
28
+ await workspace.write(
29
+ 'packages/example/package.json',
30
+ '{"name":"example","scripts":{"test":"bun test --pass-with-no-tests"}}\n',
31
+ );
16
32
  await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
17
33
  await workspace.write('packages/example/tsconfig.test.json', '{}\n');
18
34
 
19
35
  const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
20
36
 
21
37
  expect(targets['tsc-js']).toBeUndefined();
22
- expect(targets.build).toEqual({
23
- executor: 'nx:noop',
24
- cache: true,
25
- dependsOn: ['^build', 'tsc-js'],
38
+ expect(targets.build?.executor).toBe('nx:noop');
39
+ expect(targets.build?.cache).toBe(true);
40
+ expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
41
+
42
+ expect(targets['typecheck-tests']?.executor).toBe('nx:run-commands');
43
+ expect(targets['typecheck-tests']?.cache).toBe(true);
44
+ expect(targets['typecheck-tests']?.dependsOn).toEqual(['typecheck']);
45
+ expect(targets['typecheck-tests']?.options).toMatchObject({
46
+ command: 'tsc --noEmit -p tsconfig.test.json',
47
+ cwd: 'packages/example',
48
+ });
49
+
50
+ expect(targets['typecheck-tests:watch']?.executor).toBe('nx:run-commands');
51
+ expect(targets['typecheck-tests:watch']?.continuous).toBe(true);
52
+ expect(targets['typecheck-tests:watch']?.options).toMatchObject({
53
+ command: 'tsc --noEmit -p tsconfig.test.json --watch',
54
+ cwd: 'packages/example',
26
55
  });
27
- expect(targets['typecheck-tests']).toEqual({
28
- executor: 'nx:run-commands',
29
- cache: true,
30
- options: {
31
- command: 'tsc --noEmit -p tsconfig.test.json',
32
- cwd: 'packages/example',
33
- },
34
- dependsOn: ['typecheck'],
56
+
57
+ expect(targets['test:watch']?.executor).toBe('nx:run-commands');
58
+ expect(targets['test:watch']?.continuous).toBe(true);
59
+ expect(targets['test:watch']?.dependsOn).toEqual(['typecheck-tests']);
60
+ expect(targets['test:watch']?.options).toMatchObject({
61
+ command: 'bun test --watch --pass-with-no-tests',
62
+ cwd: 'packages/example',
35
63
  });
36
- expect(targets.lint).toEqual({
37
- executor: 'nx:noop',
38
- cache: true,
39
- dependsOn: ['typecheck-tests'],
64
+
65
+ expect(targets.lint?.executor).toBe('nx:noop');
66
+ expect(targets.lint?.cache).toBe(true);
67
+ expect(targets.lint?.dependsOn).toEqual(['typecheck-tests']);
68
+ } finally {
69
+ await workspace.cleanup();
70
+ }
71
+ });
72
+
73
+ it('infers vitest watch targets from explicit test commands', async () => {
74
+ const workspace = await createWorkspace();
75
+ try {
76
+ await workspace.write(
77
+ 'packages/example/package.json',
78
+ '{"name":"example","scripts":{"test":"vitest run --coverage"}}\n',
79
+ );
80
+ await workspace.write('packages/example/tsconfig.test.json', '{}\n');
81
+
82
+ const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
83
+
84
+ expect(targets['test:watch']?.continuous).toBe(true);
85
+ expect(targets['test:watch']?.options).toMatchObject({
86
+ command: 'vitest --coverage',
87
+ cwd: 'packages/example',
40
88
  });
41
89
  } finally {
42
90
  await workspace.cleanup();
@@ -65,7 +113,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
65
113
  const targets = await inferProjectTargets(workspace, 'packages/ziggy/package.json');
66
114
 
67
115
  expect(Object.keys(targets).sort()).toEqual(['build', 'zig-native', 'zig-wasm']);
68
- expect(targets.build?.dependsOn).toEqual(['^build', 'zig-wasm', 'zig-native']);
116
+ expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
69
117
  expect(targets.build?.cache).toBe(true);
70
118
  expect(targets['zig-wasm']?.cache).toBe(true);
71
119
  expect(targets['zig-native']?.cache).toBe(true);
@@ -82,6 +130,25 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
82
130
  }
83
131
  });
84
132
 
133
+ it('infers aggregate build for package-local output targets without owning them', async () => {
134
+ const workspace = await createWorkspace();
135
+ try {
136
+ await workspace.write(
137
+ 'packages/tsdown/package.json',
138
+ JSON.stringify({ name: 'tsdown', nx: { targets: { 'tsdown-js': { executor: 'nx:run-commands' } } } }),
139
+ );
140
+
141
+ const targets = await inferProjectTargets(workspace, 'packages/tsdown/package.json');
142
+
143
+ expect(targets['tsc-js']).toBeUndefined();
144
+ expect(targets['tsdown-js']).toBeUndefined();
145
+ expect(targets.build?.executor).toBe('nx:noop');
146
+ expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
147
+ } finally {
148
+ await workspace.cleanup();
149
+ }
150
+ });
151
+
85
152
  it('leaves build.zig without b.step declarations to smoo validation', async () => {
86
153
  const workspace = await createWorkspace();
87
154
  try {
package/src/index.ts CHANGED
@@ -5,9 +5,12 @@ 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';
9
+
8
10
  const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
9
11
  const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
10
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)$/;
11
14
 
12
15
  export const createNodesV2: CreateNodesV2 = [
13
16
  '**/package.json',
@@ -35,17 +38,21 @@ export const createNodesV2: CreateNodesV2 = [
35
38
 
36
39
  export default { createNodesV2 };
37
40
 
41
+ interface PackageJson {
42
+ scripts?: Record<string, unknown>;
43
+ nx?: {
44
+ targets?: Record<string, unknown>;
45
+ };
46
+ }
47
+
38
48
  async function createProjectTargets(packageJsonPath: string, workspaceRoot: string) {
39
49
  const projectRoot = dirname(packageJsonPath);
40
50
  const absoluteProjectRoot = join(workspaceRoot, projectRoot);
51
+ const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
41
52
  const targets: Record<string, TargetConfiguration> = {};
42
- const buildComponents: string[] = [];
43
53
  const validationTargets: string[] = [];
44
54
  const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
45
-
46
- if (hasLibTsconfig) {
47
- buildComponents.push('tsc-js');
48
- }
55
+ let hasBuildOutputTarget = hasLibTsconfig || hasPackageLocalBuildOutputTarget(packageJson);
49
56
 
50
57
  const hasTestTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.test.json'));
51
58
  if (hasTestTsconfig) {
@@ -57,6 +64,26 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
57
64
  cwd: projectRoot,
58
65
  },
59
66
  };
67
+ targets['typecheck-tests:watch'] = {
68
+ executor: 'nx:run-commands',
69
+ continuous: true,
70
+ options: {
71
+ command: 'tsc --noEmit -p tsconfig.test.json --watch',
72
+ cwd: projectRoot,
73
+ },
74
+ };
75
+ const inferredTestWatchCommand = inferTestWatchCommand(packageJson);
76
+ if (inferredTestWatchCommand) {
77
+ targets['test:watch'] = {
78
+ executor: 'nx:run-commands',
79
+ continuous: true,
80
+ dependsOn: ['typecheck-tests'],
81
+ options: {
82
+ command: inferredTestWatchCommand,
83
+ cwd: projectRoot,
84
+ },
85
+ };
86
+ }
60
87
  validationTargets.push('typecheck-tests');
61
88
  } else if (hasLibTsconfig) {
62
89
  validationTargets.push('typecheck');
@@ -82,14 +109,14 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
82
109
  cwd: projectRoot,
83
110
  },
84
111
  };
85
- buildComponents.push(targetName);
112
+ hasBuildOutputTarget = true;
86
113
  }
87
114
 
88
- if (buildComponents.length > 0) {
115
+ if (hasBuildOutputTarget) {
89
116
  targets.build = {
90
117
  executor: 'nx:noop',
91
118
  cache: true,
92
- dependsOn: ['^build', ...buildComponents],
119
+ dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
93
120
  };
94
121
  }
95
122
 
@@ -116,6 +143,70 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
116
143
  };
117
144
  }
118
145
 
146
+ async function readPackageJson(packageJsonPath: string): Promise<PackageJson> {
147
+ return JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
148
+ }
149
+
150
+ function inferTestWatchCommand(packageJson: PackageJson): string | null {
151
+ const scriptCommand = packageJson.scripts?.test;
152
+ if (typeof scriptCommand === 'string') {
153
+ const watchCommand = watchCommandFromTestCommand(scriptCommand);
154
+ if (watchCommand) {
155
+ return watchCommand;
156
+ }
157
+ }
158
+
159
+ const target = packageJson.nx?.targets?.test;
160
+ if (!isRecord(target)) {
161
+ return null;
162
+ }
163
+
164
+ const options = target.options;
165
+ if (!isRecord(options) || typeof options.command !== 'string') {
166
+ return null;
167
+ }
168
+
169
+ return watchCommandFromTestCommand(options.command);
170
+ }
171
+
172
+ function watchCommandFromTestCommand(command: string): string | null {
173
+ const parsed = parseEnvPrefixedCommand(command);
174
+ const trimmed = parsed.command.trim();
175
+
176
+ if (/^bun\s+test(?:\s|$)/.test(trimmed)) {
177
+ const suffix = trimmed.slice(trimmed.indexOf('test') + 'test'.length).trim();
178
+ return `${parsed.envPrefix}bun test --watch${suffix ? ` ${suffix}` : ''}`;
179
+ }
180
+
181
+ if (/^vitest(?:\s+run|\s+--run)?(?:\s|$)/.test(trimmed)) {
182
+ const suffix = trimmed.replace(/^vitest(?:\s+run|\s+--run)?/, '').trim();
183
+ return `${parsed.envPrefix}vitest${suffix ? ` ${suffix}` : ''}`;
184
+ }
185
+
186
+ return null;
187
+ }
188
+
189
+ function parseEnvPrefixedCommand(command: string): { command: string; envPrefix: string } {
190
+ const match = /^(?:\s*[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S+)\s+)+/.exec(command);
191
+ if (!match?.[0]) {
192
+ return { command, envPrefix: '' };
193
+ }
194
+ return { command: command.slice(match[0].length), envPrefix: match[0] };
195
+ }
196
+
197
+ function isRecord(value: unknown): value is Record<string, unknown> {
198
+ return value !== null && typeof value === 'object';
199
+ }
200
+
201
+ function hasPackageLocalBuildOutputTarget(packageJson: PackageJson): boolean {
202
+ const targets = packageJson.nx?.targets;
203
+ if (!isRecord(targets)) {
204
+ return false;
205
+ }
206
+
207
+ return Object.keys(targets).some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName));
208
+ }
209
+
119
210
  async function readZigSteps(absoluteProjectRoot: string, projectRoot: string): Promise<string[]> {
120
211
  const buildZigPath = join(absoluteProjectRoot, 'build.zig');
121
212