@smoothbricks/nx-plugin 0.0.0-bootstrap.0 → 0.1.0

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.
@@ -0,0 +1,219 @@
1
+ import { beforeEach, 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 referencePaths(references: Array<{ path: string }> | undefined): string[] {
8
+ return (references ?? []).map((ref) => ref.path);
9
+ }
10
+
11
+ function readStringArray(value: unknown): string[] {
12
+ if (Array.isArray(value)) {
13
+ return value.filter((item): item is string => typeof item === 'string');
14
+ }
15
+ return [];
16
+ }
17
+
18
+ describe('bun-test-tracing generator', () => {
19
+ let tree: Tree;
20
+
21
+ beforeEach(() => {
22
+ tree = createTreeWithEmptyWorkspace();
23
+ });
24
+
25
+ it('should generate files and update configs for a project', async () => {
26
+ addWorkspacePackage(tree, '@smoothbricks/lmao', 'packages/lmao');
27
+ addWorkspacePackage(tree, 'example', 'packages/example');
28
+
29
+ writeJsonFile(tree, 'packages/example/package.json', {
30
+ name: '@scope/example',
31
+ type: 'module',
32
+ dependencies: {
33
+ '@smoothbricks/lmao': 'workspace:*',
34
+ },
35
+ });
36
+ writeJsonFile(tree, 'packages/example/tsconfig.json', {
37
+ extends: '../../tsconfig.base.json',
38
+ files: [],
39
+ include: [],
40
+ references: [{ path: './tsconfig.lib.json' }],
41
+ });
42
+ writeJsonFile(tree, 'packages/example/tsconfig.lib.json', {
43
+ extends: '../../tsconfig.base.json',
44
+ compilerOptions: {
45
+ baseUrl: '.',
46
+ rootDir: 'src',
47
+ },
48
+ include: ['src/**/*.ts'],
49
+ });
50
+
51
+ await generator(tree, {
52
+ project: 'example',
53
+ opContextModule: '@smoothbricks/lmao',
54
+ });
55
+
56
+ expect(tree.read('packages/example/bunfig.toml', 'utf-8')).toContain(
57
+ 'preload = ["@smoothbricks/lmao/bun/preload", "@smoothbricks/lmao/bun/trace-preload"]',
58
+ );
59
+ expect(tree.read('packages/example/bunfig.toml', 'utf-8')).toContain('timeout = 30000');
60
+
61
+ const tracerFile = tree.read('packages/example/src/test-suite-tracer.ts', 'utf-8');
62
+ expect(tracerFile).toContain("import { opContext } from '@smoothbricks/lmao';");
63
+ expect(tracerFile).toContain("import { defineTestTracer } from '@smoothbricks/lmao/testing/bun';");
64
+ expect(tracerFile).toContain(
65
+ 'export const { useTestSpan, opContext, extraTestColumns } = defineTestTracer(opContext);',
66
+ );
67
+
68
+ const packageJson = readJson(tree, 'packages/example/package.json');
69
+ expect(packageJson.scripts?.test).toBe('bun test');
70
+ expect(
71
+ packageJson.dependencies?.['@smoothbricks/lmao'] ?? packageJson.devDependencies?.['@smoothbricks/lmao'],
72
+ ).toBe('workspace:*');
73
+
74
+ const tsconfigTest = readJson(tree, 'packages/example/tsconfig.test.json') as {
75
+ extends?: string;
76
+ compilerOptions?: {
77
+ types?: string[];
78
+ composite?: boolean;
79
+ declaration?: boolean;
80
+ declarationMap?: boolean;
81
+ emitDeclarationOnly?: boolean;
82
+ noEmit?: boolean;
83
+ outDir?: string;
84
+ tsBuildInfoFile?: string;
85
+ };
86
+ include?: string[];
87
+ references?: Array<{ path: string }>;
88
+ };
89
+ expect(tsconfigTest.extends).toBe('../../tsconfig.base.json');
90
+ expect(tsconfigTest.compilerOptions?.types).toEqual(['bun']);
91
+ expect(tsconfigTest.compilerOptions?.composite).toBe(false);
92
+ expect(tsconfigTest.compilerOptions?.declaration).toBe(false);
93
+ expect(tsconfigTest.compilerOptions?.declarationMap).toBe(false);
94
+ expect(tsconfigTest.compilerOptions?.emitDeclarationOnly).toBe(false);
95
+ expect(tsconfigTest.compilerOptions?.noEmit).toBe(true);
96
+ expect(tsconfigTest.compilerOptions?.outDir).toBeUndefined();
97
+ expect(tsconfigTest.compilerOptions?.tsBuildInfoFile).toBeUndefined();
98
+ expect(tsconfigTest.include).toContain('src/test-suite-tracer.ts');
99
+ expect(referencePaths(tsconfigTest.references)).toContain('./tsconfig.lib.json');
100
+
101
+ const projectTsconfig = readJson(tree, 'packages/example/tsconfig.json') as {
102
+ references?: Array<{ path: string }>;
103
+ };
104
+ expect(referencePaths(projectTsconfig.references)).not.toContain('./tsconfig.test.json');
105
+ });
106
+
107
+ it('should add bunfig.toml if missing', async () => {
108
+ addWorkspacePackage(tree, '@smoothbricks/lmao', 'packages/lmao');
109
+ addWorkspacePackage(tree, 'example', 'packages/example');
110
+
111
+ writeJsonFile(tree, 'packages/example/package.json', {
112
+ name: '@scope/example',
113
+ type: 'module',
114
+ });
115
+ writeJsonFile(tree, 'packages/example/tsconfig.json', {
116
+ extends: '../../tsconfig.base.json',
117
+ files: [],
118
+ include: [],
119
+ references: [{ path: './tsconfig.lib.json' }],
120
+ });
121
+ writeJsonFile(tree, 'packages/example/tsconfig.lib.json', {
122
+ extends: '../../tsconfig.base.json',
123
+ compilerOptions: { baseUrl: '.', rootDir: 'src' },
124
+ include: ['src/**/*.ts'],
125
+ });
126
+
127
+ await generator(tree, {
128
+ project: 'example',
129
+ opContextModule: '@smoothbricks/lmao',
130
+ });
131
+
132
+ const bunfig = tree.read('packages/example/bunfig.toml', 'utf-8') ?? '';
133
+ expect(bunfig).toContain('[test]');
134
+ expect(bunfig).toContain('timeout = 30000');
135
+ expect(bunfig).toContain('preload');
136
+ });
137
+
138
+ it('should update existing bunfig.toml without duplicating preload', async () => {
139
+ addWorkspacePackage(tree, '@smoothbricks/lmao', 'packages/lmao');
140
+ addWorkspacePackage(tree, 'example', 'packages/example');
141
+
142
+ writeJsonFile(tree, 'packages/example/package.json', {
143
+ name: '@scope/example',
144
+ type: 'module',
145
+ scripts: { test: 'bun test' },
146
+ dependencies: {
147
+ '@smoothbricks/lmao': 'workspace:*',
148
+ },
149
+ nx: {
150
+ targets: {
151
+ lint: {},
152
+ },
153
+ },
154
+ });
155
+ writeJsonFile(tree, 'packages/example/tsconfig.json', {
156
+ extends: '../../tsconfig.base.json',
157
+ compilerOptions: {
158
+ rootDir: 'src',
159
+ },
160
+ include: ['src/**/*'],
161
+ references: [{ path: './tsconfig.lib.json' }],
162
+ });
163
+ writeJsonFile(tree, 'packages/example/tsconfig.lib.json', {
164
+ extends: './tsconfig.json',
165
+ compilerOptions: { baseUrl: '.', rootDir: 'src' },
166
+ });
167
+ tree.write('packages/example/bunfig.toml', '[test]\ntimeout = 10\npreload = ["./custom.ts"]\n');
168
+
169
+ await generator(tree, {
170
+ project: 'example',
171
+ opContextModule: '@smoothbricks/lmao',
172
+ });
173
+
174
+ const bunfig = tree.read('packages/example/bunfig.toml', 'utf-8') ?? '';
175
+ expect(bunfig).toContain('timeout = 10');
176
+ expect(bunfig).toContain('@smoothbricks/lmao/bun/preload');
177
+ expect(bunfig).toContain('@smoothbricks/lmao/bun/trace-preload');
178
+
179
+ const tsconfigTest = readJson(tree, 'packages/example/tsconfig.test.json') as {
180
+ extends?: string;
181
+ compilerOptions?: {
182
+ types?: string[];
183
+ composite?: boolean;
184
+ declaration?: boolean;
185
+ declarationMap?: boolean;
186
+ emitDeclarationOnly?: boolean;
187
+ noEmit?: boolean;
188
+ outDir?: string;
189
+ };
190
+ include?: string[];
191
+ references?: Array<{ path: string }>;
192
+ };
193
+ expect(tsconfigTest.extends).toBe('./tsconfig.json');
194
+ expect(readStringArray(tsconfigTest.compilerOptions?.types)).toEqual(['bun']);
195
+ expect(tsconfigTest.compilerOptions?.composite).toBe(false);
196
+ expect(tsconfigTest.compilerOptions?.declaration).toBe(false);
197
+ expect(tsconfigTest.compilerOptions?.declarationMap).toBe(false);
198
+ expect(tsconfigTest.compilerOptions?.emitDeclarationOnly).toBe(false);
199
+ expect(tsconfigTest.compilerOptions?.noEmit).toBe(true);
200
+ expect(tsconfigTest.compilerOptions?.outDir).toBeUndefined();
201
+ expect(tsconfigTest.include).toContain('src/test-suite-tracer.ts');
202
+ expect(referencePaths(tsconfigTest.references)).toContain('./tsconfig.lib.json');
203
+ });
204
+ });
205
+
206
+ function addWorkspacePackage(tree: Tree, name: string, root: string): void {
207
+ addProjectConfiguration(tree, name, {
208
+ root,
209
+ sourceRoot: `${root}/src`,
210
+ projectType: 'library',
211
+ targets: {},
212
+ });
213
+ writeJsonFile(tree, `${root}/package.json`, { name, type: 'module' });
214
+ writeJsonFile(tree, `${root}/tsconfig.lib.json`, { extends: '../../tsconfig.base.json' });
215
+ }
216
+
217
+ function writeJsonFile(tree: Tree, filePath: string, value: unknown): void {
218
+ tree.write(filePath, `${JSON.stringify(value, null, 2)}\n`);
219
+ }
@@ -0,0 +1,347 @@
1
+ import { posix as path } from 'node:path';
2
+ import {
3
+ getProjects,
4
+ joinPathFragments,
5
+ normalizePath,
6
+ type ProjectConfiguration,
7
+ readJson,
8
+ type Tree,
9
+ updateJson,
10
+ } from 'nx/src/devkit-exports.js';
11
+
12
+ interface BunTestTracingGeneratorSchema {
13
+ project: string;
14
+ opContextModule: string;
15
+ opContextExport?: string;
16
+ tracerModule?: string;
17
+ }
18
+
19
+ type JsonObject = Record<string, unknown>;
20
+
21
+ interface PackageJson extends JsonObject {
22
+ name?: string;
23
+ scripts?: Record<string, string>;
24
+ nx?: {
25
+ targets?: Record<string, JsonObject>;
26
+ };
27
+ dependencies?: Record<string, string>;
28
+ devDependencies?: Record<string, string>;
29
+ }
30
+
31
+ interface TsConfigJson extends JsonObject {
32
+ extends?: string;
33
+ files?: string[];
34
+ include?: string[];
35
+ references?: Array<{ path: string }>;
36
+ compilerOptions?: Record<string, unknown>;
37
+ }
38
+
39
+ const DEFAULT_TEST_INCLUDES = [
40
+ 'src/**/*.test.ts',
41
+ 'src/**/*.spec.ts',
42
+ 'src/**/__tests__/**/*.ts',
43
+ 'src/**/__tests__/**/*.tsx',
44
+ 'src/test-suite-tracer.ts',
45
+ ];
46
+
47
+ const COPIED_COMPILER_OPTIONS = ['baseUrl', 'module', 'moduleResolution', 'jsx', 'lib'];
48
+ const DEFAULT_BUN_TEST_TIMEOUT_MS = 30_000;
49
+
50
+ export default async function generator(tree: Tree, schema: BunTestTracingGeneratorSchema): Promise<void> {
51
+ const options = normalizeOptions(schema);
52
+ const resolved = resolveProject(tree, options.project);
53
+ const packageJsonPath = joinPathFragments(resolved.root, 'package.json');
54
+ const tsconfigPath = joinPathFragments(resolved.root, 'tsconfig.json');
55
+ const libTsconfigPath = joinPathFragments(resolved.root, 'tsconfig.lib.json');
56
+
57
+ if (!tree.exists(packageJsonPath)) {
58
+ throw new Error(`Project ${resolved.name} is missing ${packageJsonPath}`);
59
+ }
60
+
61
+ if (!tree.exists(tsconfigPath)) {
62
+ throw new Error(`Project ${resolved.name} is missing ${tsconfigPath}`);
63
+ }
64
+
65
+ if (!tree.exists(libTsconfigPath)) {
66
+ throw new Error(`Project ${resolved.name} is missing ${libTsconfigPath}`);
67
+ }
68
+
69
+ updatePackageJson(tree, packageJsonPath);
70
+ writeBunfig(tree, resolved.root);
71
+ tree.write(joinPathFragments(resolved.root, 'src/test-suite-tracer.ts'), renderSuiteTracer(options));
72
+ updateTsconfigTest(tree, resolved.root, packageJsonPath, tsconfigPath, libTsconfigPath);
73
+ }
74
+
75
+ function normalizeOptions(schema: BunTestTracingGeneratorSchema): Required<BunTestTracingGeneratorSchema> {
76
+ return {
77
+ project: schema.project,
78
+ opContextModule: schema.opContextModule,
79
+ opContextExport: schema.opContextExport ?? 'opContext',
80
+ tracerModule: schema.tracerModule ?? '@smoothbricks/lmao/testing/bun',
81
+ };
82
+ }
83
+
84
+ function resolveProject(tree: Tree, projectInput: string): { name: string; root: string } {
85
+ const normalizedInput = normalizeLookupValue(projectInput);
86
+
87
+ for (const [name, config] of getProjects(tree)) {
88
+ if (normalizeLookupValue(name) === normalizedInput || normalizeLookupValue(config.root) === normalizedInput) {
89
+ return { name, root: config.root };
90
+ }
91
+
92
+ const packageJsonPath = joinPathFragments(config.root, 'package.json');
93
+ if (!tree.exists(packageJsonPath)) {
94
+ continue;
95
+ }
96
+
97
+ const packageJson = readJson<PackageJson>(tree, packageJsonPath);
98
+ if (packageJson.name && normalizeLookupValue(packageJson.name) === normalizedInput) {
99
+ return { name, root: config.root };
100
+ }
101
+ }
102
+
103
+ throw new Error(`Could not resolve project ${projectInput}`);
104
+ }
105
+
106
+ function normalizeLookupValue(value: string): string {
107
+ return value.replace(/^\.\//, '').replace(/\\/g, '/');
108
+ }
109
+
110
+ function updatePackageJson(tree: Tree, packageJsonPath: string): void {
111
+ updateJson<PackageJson>(tree, packageJsonPath, (packageJson: PackageJson) => {
112
+ packageJson.scripts ??= {};
113
+ packageJson.scripts.test ??= 'bun test';
114
+
115
+ packageJson.nx ??= {};
116
+ packageJson.nx.targets ??= {};
117
+ packageJson.nx.targets.lint ??= {};
118
+
119
+ const hasLmaoDependency = Boolean(
120
+ packageJson.dependencies?.['@smoothbricks/lmao'] || packageJson.devDependencies?.['@smoothbricks/lmao'],
121
+ );
122
+
123
+ if (!hasLmaoDependency) {
124
+ packageJson.devDependencies ??= {};
125
+ packageJson.devDependencies['@smoothbricks/lmao'] = 'workspace:*';
126
+ }
127
+
128
+ return packageJson;
129
+ });
130
+ }
131
+
132
+ function writeBunfig(tree: Tree, projectRoot: string): void {
133
+ const bunfigPath = joinPathFragments(projectRoot, 'bunfig.toml');
134
+ const preloadEntries = '"@smoothbricks/lmao/bun/preload", "@smoothbricks/lmao/bun/trace-preload"';
135
+
136
+ if (!tree.exists(bunfigPath)) {
137
+ tree.write(bunfigPath, `[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\npreload = [${preloadEntries}]\n`);
138
+ return;
139
+ }
140
+
141
+ const current = tree.read(bunfigPath, 'utf-8') ?? '';
142
+ const next = ensureBunTestTimeout(current);
143
+
144
+ // Already has the package specifier preloads
145
+ if (next.includes('@smoothbricks/lmao/bun/preload')) {
146
+ if (next !== current) {
147
+ tree.write(bunfigPath, next);
148
+ }
149
+ return;
150
+ }
151
+
152
+ // Replace old patterns with the package specifier preloads
153
+ if (next.includes('preload = [')) {
154
+ tree.write(bunfigPath, next.replace(/preload\s*=\s*\[.*?\]/s, `preload = [${preloadEntries}]`));
155
+ return;
156
+ }
157
+
158
+ if (next.includes('[test]')) {
159
+ tree.write(bunfigPath, next.replace('[test]', `[test]\npreload = [${preloadEntries}]`));
160
+ return;
161
+ }
162
+
163
+ const suffix = next.endsWith('\n') ? '' : '\n';
164
+ tree.write(
165
+ bunfigPath,
166
+ `${next}${suffix}[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\npreload = [${preloadEntries}]\n`,
167
+ );
168
+ }
169
+
170
+ function ensureBunTestTimeout(current: string): string {
171
+ if (/(^|\n)\s*timeout\s*=/.test(current)) {
172
+ return current;
173
+ }
174
+
175
+ if (current.includes('[test]')) {
176
+ return current.replace('[test]', `[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}`);
177
+ }
178
+
179
+ const suffix = current.endsWith('\n') ? '' : '\n';
180
+ return `${current}${suffix}[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\n`;
181
+ }
182
+
183
+ function renderSuiteTracer(options: Required<BunTestTracingGeneratorSchema>): string {
184
+ return [
185
+ `import { ${options.opContextExport} } from '${options.opContextModule}';`,
186
+ `import { defineTestTracer } from '${options.tracerModule}';`,
187
+ '',
188
+ `export const { useTestSpan, opContext, extraTestColumns } = defineTestTracer(${options.opContextExport});`,
189
+ '',
190
+ ].join('\n');
191
+ }
192
+
193
+ function updateTsconfigTest(
194
+ tree: Tree,
195
+ projectRoot: string,
196
+ packageJsonPath: string,
197
+ tsconfigPath: string,
198
+ libTsconfigPath: string,
199
+ ): void {
200
+ const tsconfigTestPath = joinPathFragments(projectRoot, 'tsconfig.test.json');
201
+ const packageJson = readJson<PackageJson>(tree, packageJsonPath);
202
+ const projectTsconfig = readJson<TsConfigJson>(tree, tsconfigPath);
203
+ const libTsconfig = readJson<TsConfigJson>(tree, libTsconfigPath);
204
+ const extendsPath = chooseTsconfigTestExtends(projectTsconfig, libTsconfig);
205
+ const copiedCompilerOptions = getCopiedCompilerOptions(libTsconfig);
206
+ const referencePaths = collectReferencePaths(tree, projectRoot, packageJson);
207
+
208
+ if (!tree.exists(tsconfigTestPath)) {
209
+ const compilerOptions: Record<string, unknown> = {
210
+ ...copiedCompilerOptions,
211
+ types: mergeStringArray([], ['bun']),
212
+ composite: false,
213
+ declaration: false,
214
+ declarationMap: false,
215
+ emitDeclarationOnly: false,
216
+ noEmit: true,
217
+ };
218
+
219
+ const tsconfigTest: TsConfigJson = {
220
+ extends: extendsPath,
221
+ compilerOptions,
222
+ include: [...DEFAULT_TEST_INCLUDES],
223
+ references: referencePaths.map((refPath) => ({ path: refPath })),
224
+ };
225
+
226
+ tree.write(tsconfigTestPath, `${JSON.stringify(tsconfigTest, null, 2)}\n`);
227
+ return;
228
+ }
229
+
230
+ updateJson<TsConfigJson>(tree, tsconfigTestPath, (tsconfigTest: TsConfigJson) => {
231
+ tsconfigTest.extends ??= extendsPath;
232
+ tsconfigTest.compilerOptions = {
233
+ ...copiedCompilerOptions,
234
+ ...tsconfigTest.compilerOptions,
235
+ types: mergeStringArray(readStringArray(tsconfigTest.compilerOptions?.types), ['bun']),
236
+ composite: false,
237
+ declaration: false,
238
+ declarationMap: false,
239
+ emitDeclarationOnly: false,
240
+ noEmit: true,
241
+ };
242
+ delete tsconfigTest.compilerOptions.outDir;
243
+ delete tsconfigTest.compilerOptions.tsBuildInfoFile;
244
+ tsconfigTest.include = mergeStringArray(tsconfigTest.include, DEFAULT_TEST_INCLUDES);
245
+ tsconfigTest.references = mergeReferences(tsconfigTest.references, referencePaths);
246
+ return tsconfigTest;
247
+ });
248
+ }
249
+
250
+ function chooseTsconfigTestExtends(projectTsconfig: TsConfigJson, libTsconfig: TsConfigJson): string {
251
+ return isWrapperTsconfig(projectTsconfig) ? (libTsconfig.extends ?? '../../tsconfig.base.json') : './tsconfig.json';
252
+ }
253
+
254
+ function isWrapperTsconfig(tsconfig: TsConfigJson): boolean {
255
+ const includeLength = Array.isArray(tsconfig.include) ? tsconfig.include.length : 0;
256
+ const filesLength = Array.isArray(tsconfig.files) ? tsconfig.files.length : 0;
257
+ const compilerOptionKeys = Object.keys(tsconfig.compilerOptions ?? {});
258
+ return includeLength === 0 && filesLength === 0 && compilerOptionKeys.length === 0;
259
+ }
260
+
261
+ function getCopiedCompilerOptions(libTsconfig: TsConfigJson): Record<string, unknown> {
262
+ const result: Record<string, unknown> = {};
263
+ const compilerOptions = libTsconfig.compilerOptions ?? {};
264
+
265
+ for (const key of COPIED_COMPILER_OPTIONS) {
266
+ if (key in compilerOptions) {
267
+ result[key] = compilerOptions[key];
268
+ }
269
+ }
270
+
271
+ return result;
272
+ }
273
+
274
+ function collectReferencePaths(tree: Tree, projectRoot: string, packageJson: PackageJson): string[] {
275
+ const referencePaths = ['./tsconfig.lib.json'];
276
+ const workspacePackages = buildWorkspacePackageMap(tree);
277
+ const dependencyNames = new Set<string>([
278
+ ...Object.keys(packageJson.dependencies ?? {}),
279
+ ...Object.keys(packageJson.devDependencies ?? {}),
280
+ ]);
281
+
282
+ dependencyNames.add('@smoothbricks/lmao');
283
+
284
+ for (const dependencyName of dependencyNames) {
285
+ const dependencyProject = workspacePackages.get(dependencyName);
286
+ if (!dependencyProject) {
287
+ continue;
288
+ }
289
+
290
+ const dependencyTsconfig = joinPathFragments(dependencyProject.root, 'tsconfig.lib.json');
291
+ if (!tree.exists(dependencyTsconfig)) {
292
+ continue;
293
+ }
294
+
295
+ const relativePath = normalizePath(path.relative(projectRoot, dependencyTsconfig));
296
+ if (!referencePaths.includes(relativePath)) {
297
+ referencePaths.push(relativePath);
298
+ }
299
+ }
300
+
301
+ return referencePaths;
302
+ }
303
+
304
+ function buildWorkspacePackageMap(tree: Tree): Map<string, ProjectConfiguration> {
305
+ const packageMap = new Map<string, ProjectConfiguration>();
306
+
307
+ for (const [, config] of getProjects(tree)) {
308
+ const packageJsonPath = joinPathFragments(config.root, 'package.json');
309
+ if (!tree.exists(packageJsonPath)) {
310
+ continue;
311
+ }
312
+
313
+ const packageJson = readJson<PackageJson>(tree, packageJsonPath);
314
+ if (packageJson.name) {
315
+ packageMap.set(packageJson.name, config);
316
+ }
317
+ }
318
+
319
+ return packageMap;
320
+ }
321
+
322
+ function mergeStringArray(a: string[] | undefined, b: string[]): string[] {
323
+ const aArray = a ?? [];
324
+ const set = new Set([...aArray, ...b]);
325
+ return Array.from(set);
326
+ }
327
+
328
+ function readStringArray(value: unknown): string[] {
329
+ if (Array.isArray(value)) {
330
+ return value.filter((item): item is string => typeof item === 'string');
331
+ }
332
+ return [];
333
+ }
334
+
335
+ function mergeReferences(existing: Array<{ path: string }> | undefined, newPaths: string[]): Array<{ path: string }> {
336
+ const existingPaths = existing ?? [];
337
+ const existingSet = new Set(existingPaths.map((ref) => ref.path));
338
+
339
+ const merged = [...existingPaths];
340
+ for (const path of newPaths) {
341
+ if (!existingSet.has(path)) {
342
+ merged.push({ path });
343
+ }
344
+ }
345
+
346
+ return merged;
347
+ }
@@ -0,0 +1,8 @@
1
+ export interface BunTestTracingGeneratorSchema {
2
+ project: string;
3
+ opContextModule: string;
4
+ opContextExport?: string;
5
+ spanContextModule: string;
6
+ spanContextExport?: string;
7
+ tracerModule?: string;
8
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "title": "Configure Bun test tracing",
5
+ "description": "Configure a workspace package for the standard Bun test tracing + dist-test TypeScript setup",
6
+ "type": "object",
7
+ "properties": {
8
+ "project": {
9
+ "type": "string",
10
+ "description": "Nx project name, package name, or project root to configure"
11
+ },
12
+ "opContextModule": {
13
+ "type": "string",
14
+ "description": "Module specifier that exports the package op context"
15
+ },
16
+ "opContextExport": {
17
+ "type": "string",
18
+ "description": "Named export for the package op context",
19
+ "default": "opContext"
20
+ },
21
+ "tracerModule": {
22
+ "type": "string",
23
+ "description": "Module specifier for defineTestTracer",
24
+ "default": "@smoothbricks/lmao/testing/bun"
25
+ }
26
+ },
27
+ "required": ["project", "opContextModule"]
28
+ }