@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.
- package/README.md +66 -2
- package/dist/generators/bun-test-tracing/generator.d.ts +10 -0
- package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -0
- package/dist/generators/bun-test-tracing/generator.js +246 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +126 -0
- package/generators.json +9 -0
- package/loader.js +16 -0
- package/package.json +55 -4
- package/src/generators/bun-test-tracing/generator.test.ts +219 -0
- package/src/generators/bun-test-tracing/generator.ts +347 -0
- package/src/generators/bun-test-tracing/schema.d.ts +8 -0
- package/src/generators/bun-test-tracing/schema.json +28 -0
- package/src/index.test.ts +133 -0
- package/src/index.ts +151 -0
- package/src/test-suite-tracer.ts +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import type { CreateNodesContextV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
|
|
7
|
+
import { createNodesV2 } from './index.js';
|
|
8
|
+
|
|
9
|
+
const [, inferTargets] = createNodesV2;
|
|
10
|
+
|
|
11
|
+
describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
12
|
+
it('infers validation and aggregate build targets without owning TypeScript lib build', async () => {
|
|
13
|
+
const workspace = await createWorkspace();
|
|
14
|
+
try {
|
|
15
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
16
|
+
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
17
|
+
await workspace.write('packages/example/tsconfig.test.json', '{}\n');
|
|
18
|
+
|
|
19
|
+
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
20
|
+
|
|
21
|
+
expect(targets['tsc-js']).toBeUndefined();
|
|
22
|
+
expect(targets.build).toEqual({
|
|
23
|
+
executor: 'nx:noop',
|
|
24
|
+
cache: true,
|
|
25
|
+
dependsOn: ['^build', 'tsc-js'],
|
|
26
|
+
});
|
|
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'],
|
|
35
|
+
});
|
|
36
|
+
expect(targets.lint).toEqual({
|
|
37
|
+
executor: 'nx:noop',
|
|
38
|
+
cache: true,
|
|
39
|
+
dependsOn: ['typecheck-tests'],
|
|
40
|
+
});
|
|
41
|
+
} finally {
|
|
42
|
+
await workspace.cleanup();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('infers zig step targets and excludes reserved non-build steps', async () => {
|
|
47
|
+
const workspace = await createWorkspace();
|
|
48
|
+
try {
|
|
49
|
+
await workspace.write('packages/ziggy/package.json', '{"name":"ziggy"}\n');
|
|
50
|
+
await workspace.write(
|
|
51
|
+
'packages/ziggy/build.zig',
|
|
52
|
+
[
|
|
53
|
+
'pub fn build(b: *std.Build) void {',
|
|
54
|
+
' _ = b.step("wasm", "Build wasm");',
|
|
55
|
+
' _ = b.step("native", "Build native");',
|
|
56
|
+
' _ = b.step("test", "Run tests");',
|
|
57
|
+
' _ = b.step("all", "Build everything");',
|
|
58
|
+
' _ = b.step("clean", "Clean outputs");',
|
|
59
|
+
' _ = b.step("install", "Install artifacts");',
|
|
60
|
+
'}',
|
|
61
|
+
'',
|
|
62
|
+
].join('\n'),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const targets = await inferProjectTargets(workspace, 'packages/ziggy/package.json');
|
|
66
|
+
|
|
67
|
+
expect(Object.keys(targets).sort()).toEqual(['build', 'zig-native', 'zig-wasm']);
|
|
68
|
+
expect(targets.build?.dependsOn).toEqual(['^build', 'zig-wasm', 'zig-native']);
|
|
69
|
+
expect(targets.build?.cache).toBe(true);
|
|
70
|
+
expect(targets['zig-wasm']?.cache).toBe(true);
|
|
71
|
+
expect(targets['zig-native']?.cache).toBe(true);
|
|
72
|
+
expect(targets['zig-wasm']?.options).toEqual({
|
|
73
|
+
command: 'zig build wasm',
|
|
74
|
+
cwd: 'packages/ziggy',
|
|
75
|
+
});
|
|
76
|
+
expect(targets['zig-native']?.options).toEqual({
|
|
77
|
+
command: 'zig build native',
|
|
78
|
+
cwd: 'packages/ziggy',
|
|
79
|
+
});
|
|
80
|
+
} finally {
|
|
81
|
+
await workspace.cleanup();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('leaves build.zig without b.step declarations to smoo validation', async () => {
|
|
86
|
+
const workspace = await createWorkspace();
|
|
87
|
+
try {
|
|
88
|
+
await workspace.write('packages/broken/package.json', '{"name":"broken"}\n');
|
|
89
|
+
await workspace.write('packages/broken/build.zig', 'pub fn build(_: *std.Build) void {}\n');
|
|
90
|
+
|
|
91
|
+
const targets = await inferProjectTargets(workspace, 'packages/broken/package.json');
|
|
92
|
+
|
|
93
|
+
expect(targets).toEqual({});
|
|
94
|
+
} finally {
|
|
95
|
+
await workspace.cleanup();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
async function createWorkspace(): Promise<WorkspaceFixture> {
|
|
101
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-'));
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
context: {
|
|
105
|
+
workspaceRoot: root,
|
|
106
|
+
nxJsonConfiguration: {},
|
|
107
|
+
},
|
|
108
|
+
async write(filePath: string, contents: string): Promise<void> {
|
|
109
|
+
const absolutePath = join(root, filePath);
|
|
110
|
+
await mkdir(dirname(absolutePath), { recursive: true });
|
|
111
|
+
await writeFile(absolutePath, contents);
|
|
112
|
+
},
|
|
113
|
+
async cleanup(): Promise<void> {
|
|
114
|
+
await rm(root, { recursive: true, force: true });
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
interface WorkspaceFixture {
|
|
120
|
+
context: CreateNodesContextV2;
|
|
121
|
+
write(filePath: string, contents: string): Promise<void>;
|
|
122
|
+
cleanup(): Promise<void>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function inferProjectTargets(
|
|
126
|
+
workspace: WorkspaceFixture,
|
|
127
|
+
packageJsonPath: string,
|
|
128
|
+
): Promise<Record<string, TargetConfiguration>> {
|
|
129
|
+
const result = await inferTargets([packageJsonPath], undefined, workspace.context);
|
|
130
|
+
const projectRoot = dirname(packageJsonPath);
|
|
131
|
+
|
|
132
|
+
return result[0]?.[1].projects?.[projectRoot]?.targets ?? {};
|
|
133
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import type { CreateNodesResultV2, CreateNodesV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
|
|
6
|
+
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
7
|
+
|
|
8
|
+
const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
|
|
9
|
+
const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
|
|
10
|
+
const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
|
|
11
|
+
|
|
12
|
+
export const createNodesV2: CreateNodesV2 = [
|
|
13
|
+
'**/package.json',
|
|
14
|
+
async (projectConfigurationFiles, _options, context) => {
|
|
15
|
+
const results: CreateNodesResultV2 = [];
|
|
16
|
+
const errors: Array<[file: string | null, error: Error]> = [];
|
|
17
|
+
|
|
18
|
+
await Promise.all(
|
|
19
|
+
projectConfigurationFiles.map(async (packageJsonPath) => {
|
|
20
|
+
try {
|
|
21
|
+
results.push([packageJsonPath, await createProjectTargets(packageJsonPath, context.workspaceRoot)]);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
errors.push([packageJsonPath, error instanceof Error ? error : new Error(String(error))]);
|
|
24
|
+
}
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (errors.length > 0) {
|
|
29
|
+
throw new AggregateCreateNodesError(errors, results);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return results;
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export default { createNodesV2 };
|
|
37
|
+
|
|
38
|
+
async function createProjectTargets(packageJsonPath: string, workspaceRoot: string) {
|
|
39
|
+
const projectRoot = dirname(packageJsonPath);
|
|
40
|
+
const absoluteProjectRoot = join(workspaceRoot, projectRoot);
|
|
41
|
+
const targets: Record<string, TargetConfiguration> = {};
|
|
42
|
+
const buildComponents: string[] = [];
|
|
43
|
+
const validationTargets: string[] = [];
|
|
44
|
+
const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
|
|
45
|
+
|
|
46
|
+
if (hasLibTsconfig) {
|
|
47
|
+
buildComponents.push('tsc-js');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const hasTestTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.test.json'));
|
|
51
|
+
if (hasTestTsconfig) {
|
|
52
|
+
targets['typecheck-tests'] = {
|
|
53
|
+
executor: 'nx:run-commands',
|
|
54
|
+
cache: true,
|
|
55
|
+
options: {
|
|
56
|
+
command: 'tsc --noEmit -p tsconfig.test.json',
|
|
57
|
+
cwd: projectRoot,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
validationTargets.push('typecheck-tests');
|
|
61
|
+
} else if (hasLibTsconfig) {
|
|
62
|
+
validationTargets.push('typecheck');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
|
|
66
|
+
for (const step of zigSteps) {
|
|
67
|
+
const targetName = `zig-${step}`;
|
|
68
|
+
targets[targetName] = {
|
|
69
|
+
executor: 'nx:run-commands',
|
|
70
|
+
cache: true,
|
|
71
|
+
inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
|
|
72
|
+
outputs: [
|
|
73
|
+
'{projectRoot}/dist/**/*.wasm',
|
|
74
|
+
'{projectRoot}/dist/**/*.node',
|
|
75
|
+
'{projectRoot}/dist/**/*.dylib',
|
|
76
|
+
'{projectRoot}/dist/**/*.so',
|
|
77
|
+
'{projectRoot}/dist/**/*.dll',
|
|
78
|
+
'{projectRoot}/dist/**/*.a',
|
|
79
|
+
],
|
|
80
|
+
options: {
|
|
81
|
+
command: `zig build ${step}`,
|
|
82
|
+
cwd: projectRoot,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
buildComponents.push(targetName);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (buildComponents.length > 0) {
|
|
89
|
+
targets.build = {
|
|
90
|
+
executor: 'nx:noop',
|
|
91
|
+
cache: true,
|
|
92
|
+
dependsOn: ['^build', ...buildComponents],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (targets['typecheck-tests']) {
|
|
97
|
+
if (hasLibTsconfig) {
|
|
98
|
+
targets['typecheck-tests'].dependsOn = ['typecheck'];
|
|
99
|
+
} else if (targets.build) {
|
|
100
|
+
targets['typecheck-tests'].dependsOn = ['build'];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (validationTargets.length > 0) {
|
|
105
|
+
targets.lint = {
|
|
106
|
+
executor: 'nx:noop',
|
|
107
|
+
cache: true,
|
|
108
|
+
dependsOn: validationTargets,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
projects: {
|
|
114
|
+
[projectRoot]: { targets },
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function readZigSteps(absoluteProjectRoot: string, projectRoot: string): Promise<string[]> {
|
|
120
|
+
const buildZigPath = join(absoluteProjectRoot, 'build.zig');
|
|
121
|
+
|
|
122
|
+
if (!existsSync(buildZigPath)) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const buildZig = await readFile(buildZigPath, 'utf-8');
|
|
127
|
+
const declaredSteps = Array.from(buildZig.matchAll(ZIG_STEP_PATTERN), (match) => match[1]);
|
|
128
|
+
|
|
129
|
+
if (declaredSteps.length === 0) {
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const steps: string[] = [];
|
|
134
|
+
for (const step of declaredSteps) {
|
|
135
|
+
if (RESERVED_ZIG_STEPS.has(step)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!VALID_ZIG_STEP_NAME.test(step)) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
`${projectRoot}/build.zig declares unsupported Zig step "${step}"; inferred target names cannot contain ':' or other special characters`,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!steps.includes(step)) {
|
|
146
|
+
steps.push(step);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return steps;
|
|
151
|
+
}
|
|
File without changes
|