@smoothbricks/nx-plugin 0.0.0-bootstrap.0 → 0.2.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 +93 -2
- package/dist/bounded-test-policy.d.ts +32 -0
- package/dist/bounded-test-policy.d.ts.map +1 -0
- package/dist/bounded-test-policy.js +184 -0
- package/dist/executors/bounded-exec/executor.d.ts +15 -0
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -0
- package/dist/executors/bounded-exec/executor.js +179 -0
- package/dist/executors/bounded-exec/schema.d.ts +11 -0
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -0
- package/dist/executors/bounded-exec/schema.js +1 -0
- package/dist/generators/bounded-test-targets/generator.d.ts +7 -0
- package/dist/generators/bounded-test-targets/generator.d.ts.map +1 -0
- package/dist/generators/bounded-test-targets/generator.js +40 -0
- 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 +247 -0
- package/dist/generators/create-package/generator.d.ts +4 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -0
- package/dist/generators/create-package/generator.js +204 -0
- package/dist/generators/make-public/generator.d.ts +4 -0
- package/dist/generators/make-public/generator.d.ts.map +1 -0
- package/dist/generators/make-public/generator.js +55 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +197 -0
- package/dist/package-target-policy.d.ts +31 -0
- package/dist/package-target-policy.d.ts.map +1 -0
- package/dist/package-target-policy.js +930 -0
- package/dist/release-config-policy.d.ts +32 -0
- package/dist/release-config-policy.d.ts.map +1 -0
- package/dist/release-config-policy.js +225 -0
- package/dist/typecheck-test-policy.d.ts +56 -0
- package/dist/typecheck-test-policy.d.ts.map +1 -0
- package/dist/typecheck-test-policy.js +640 -0
- package/dist/version-actions.cjs +78 -0
- package/dist/version-actions.d.cts +6 -0
- package/dist/version-actions.d.cts.map +1 -0
- package/dist/workspace-config-policy.d.ts +33 -0
- package/dist/workspace-config-policy.d.ts.map +1 -0
- package/dist/workspace-config-policy.js +334 -0
- package/executors.json +9 -0
- package/generators.json +24 -0
- package/loader.js +16 -0
- package/package.json +89 -4
- package/src/bounded-test-policy.test.ts +257 -0
- package/src/bounded-test-policy.ts +257 -0
- package/src/bun-bootstrap.test.ts +52 -0
- package/src/executors/bounded-exec/executor.test.ts +258 -0
- package/src/executors/bounded-exec/executor.ts +228 -0
- package/src/executors/bounded-exec/schema.json +68 -0
- package/src/executors/bounded-exec/schema.ts +10 -0
- package/src/generators/bounded-test-targets/generator.test.ts +136 -0
- package/src/generators/bounded-test-targets/generator.ts +67 -0
- package/src/generators/bounded-test-targets/schema.d.ts +3 -0
- package/src/generators/bounded-test-targets/schema.json +14 -0
- package/src/generators/bun-test-tracing/generator.test.ts +243 -0
- package/src/generators/bun-test-tracing/generator.ts +348 -0
- package/src/generators/bun-test-tracing/schema.d.ts +8 -0
- package/src/generators/bun-test-tracing/schema.json +28 -0
- package/src/generators/create-package/generator.test.ts +206 -0
- package/src/generators/create-package/generator.ts +251 -0
- package/src/generators/create-package/schema.d.ts +5 -0
- package/src/generators/create-package/schema.json +24 -0
- package/src/generators/make-public/generator.test.ts +137 -0
- package/src/generators/make-public/generator.ts +83 -0
- package/src/generators/make-public/schema.d.ts +3 -0
- package/src/generators/make-public/schema.json +13 -0
- package/src/index.test.ts +200 -0
- package/src/index.ts +242 -0
- package/src/package-target-policy.test.ts +778 -0
- package/src/package-target-policy.ts +1127 -0
- package/src/release-config-policy.test.ts +280 -0
- package/src/release-config-policy.ts +258 -0
- package/src/typecheck-test-policy.test.ts +797 -0
- package/src/typecheck-test-policy.ts +752 -0
- package/src/version-actions.cts +94 -0
- package/src/workspace-config-policy.test.ts +376 -0
- package/src/workspace-config-policy.ts +390 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
5
|
+
import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
|
|
6
|
+
const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
|
|
7
|
+
const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
|
|
8
|
+
const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
|
|
9
|
+
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|ios|android|native|napi|bun|wasm)$/;
|
|
10
|
+
export const createNodesV2 = [
|
|
11
|
+
'**/package.json',
|
|
12
|
+
async (projectConfigurationFiles, _options, context) => {
|
|
13
|
+
const results = [];
|
|
14
|
+
const errors = [];
|
|
15
|
+
await Promise.all(projectConfigurationFiles.map(async (packageJsonPath) => {
|
|
16
|
+
try {
|
|
17
|
+
results.push([packageJsonPath, await createProjectTargets(packageJsonPath, context.workspaceRoot)]);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
errors.push([packageJsonPath, error instanceof Error ? error : new Error(String(error))]);
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
if (errors.length > 0) {
|
|
24
|
+
throw new AggregateCreateNodesError(errors, results);
|
|
25
|
+
}
|
|
26
|
+
return results;
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
export default { createNodesV2 };
|
|
30
|
+
async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
31
|
+
const projectRoot = dirname(packageJsonPath);
|
|
32
|
+
const absoluteProjectRoot = join(workspaceRoot, projectRoot);
|
|
33
|
+
const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
|
|
34
|
+
const targets = {};
|
|
35
|
+
const validationTargets = [];
|
|
36
|
+
const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
|
|
37
|
+
let hasBuildOutputTarget = hasLibTsconfig || hasPackageLocalBuildOutputTarget(packageJson);
|
|
38
|
+
const hasTestTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.test.json'));
|
|
39
|
+
if (hasTestTsconfig) {
|
|
40
|
+
targets['typecheck-tests'] = {
|
|
41
|
+
executor: 'nx:run-commands',
|
|
42
|
+
cache: true,
|
|
43
|
+
options: {
|
|
44
|
+
command: 'tsc --noEmit -p tsconfig.test.json',
|
|
45
|
+
cwd: projectRoot,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
targets['typecheck-tests:watch'] = {
|
|
49
|
+
executor: 'nx:run-commands',
|
|
50
|
+
continuous: true,
|
|
51
|
+
options: {
|
|
52
|
+
command: 'tsc --noEmit -p tsconfig.test.json --watch',
|
|
53
|
+
cwd: projectRoot,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const inferredTestWatchCommand = inferTestWatchCommand(packageJson);
|
|
57
|
+
if (inferredTestWatchCommand) {
|
|
58
|
+
targets['test:watch'] = {
|
|
59
|
+
executor: 'nx:run-commands',
|
|
60
|
+
continuous: true,
|
|
61
|
+
dependsOn: ['typecheck-tests'],
|
|
62
|
+
options: {
|
|
63
|
+
command: inferredTestWatchCommand,
|
|
64
|
+
cwd: projectRoot,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
validationTargets.push('typecheck-tests');
|
|
69
|
+
}
|
|
70
|
+
else if (hasLibTsconfig) {
|
|
71
|
+
validationTargets.push('typecheck');
|
|
72
|
+
}
|
|
73
|
+
const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
|
|
74
|
+
for (const step of zigSteps) {
|
|
75
|
+
const targetName = `zig-${step}`;
|
|
76
|
+
targets[targetName] = {
|
|
77
|
+
executor: 'nx:run-commands',
|
|
78
|
+
cache: true,
|
|
79
|
+
inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
|
|
80
|
+
outputs: [
|
|
81
|
+
'{projectRoot}/dist/**/*.wasm',
|
|
82
|
+
'{projectRoot}/dist/**/*.node',
|
|
83
|
+
'{projectRoot}/dist/**/*.dylib',
|
|
84
|
+
'{projectRoot}/dist/**/*.so',
|
|
85
|
+
'{projectRoot}/dist/**/*.dll',
|
|
86
|
+
'{projectRoot}/dist/**/*.a',
|
|
87
|
+
],
|
|
88
|
+
options: {
|
|
89
|
+
command: `zig build ${step}`,
|
|
90
|
+
cwd: projectRoot,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
hasBuildOutputTarget = true;
|
|
94
|
+
}
|
|
95
|
+
if (hasBuildOutputTarget) {
|
|
96
|
+
targets.build = {
|
|
97
|
+
executor: 'nx:noop',
|
|
98
|
+
cache: true,
|
|
99
|
+
dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (targets['typecheck-tests']) {
|
|
103
|
+
if (hasLibTsconfig) {
|
|
104
|
+
targets['typecheck-tests'].dependsOn = ['typecheck'];
|
|
105
|
+
}
|
|
106
|
+
else if (targets.build) {
|
|
107
|
+
targets['typecheck-tests'].dependsOn = ['build'];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (validationTargets.length > 0) {
|
|
111
|
+
targets.lint = {
|
|
112
|
+
executor: 'nx:noop',
|
|
113
|
+
cache: true,
|
|
114
|
+
dependsOn: validationTargets,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
projects: {
|
|
119
|
+
[projectRoot]: { targets },
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async function readPackageJson(packageJsonPath) {
|
|
124
|
+
return JSON.parse(await readFile(packageJsonPath, 'utf-8'));
|
|
125
|
+
}
|
|
126
|
+
function inferTestWatchCommand(packageJson) {
|
|
127
|
+
const scriptCommand = packageJson.scripts?.test;
|
|
128
|
+
if (typeof scriptCommand === 'string') {
|
|
129
|
+
const watchCommand = watchCommandFromTestCommand(scriptCommand);
|
|
130
|
+
if (watchCommand) {
|
|
131
|
+
return watchCommand;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const target = packageJson.nx?.targets?.test;
|
|
135
|
+
if (!isRecord(target)) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const options = target.options;
|
|
139
|
+
if (!isRecord(options) || typeof options.command !== 'string') {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return watchCommandFromTestCommand(options.command);
|
|
143
|
+
}
|
|
144
|
+
function watchCommandFromTestCommand(command) {
|
|
145
|
+
const parsed = parseEnvPrefixedCommand(command);
|
|
146
|
+
const trimmed = parsed.command.trim();
|
|
147
|
+
if (/^bun\s+test(?:\s|$)/.test(trimmed)) {
|
|
148
|
+
const suffix = trimmed.slice(trimmed.indexOf('test') + 'test'.length).trim();
|
|
149
|
+
return `${parsed.envPrefix}bun test --watch${suffix ? ` ${suffix}` : ''}`;
|
|
150
|
+
}
|
|
151
|
+
if (/^vitest(?:\s+run|\s+--run)?(?:\s|$)/.test(trimmed)) {
|
|
152
|
+
const suffix = trimmed.replace(/^vitest(?:\s+run|\s+--run)?/, '').trim();
|
|
153
|
+
return `${parsed.envPrefix}vitest${suffix ? ` ${suffix}` : ''}`;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
function parseEnvPrefixedCommand(command) {
|
|
158
|
+
const match = /^(?:\s*[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S+)\s+)+/.exec(command);
|
|
159
|
+
if (!match?.[0]) {
|
|
160
|
+
return { command, envPrefix: '' };
|
|
161
|
+
}
|
|
162
|
+
return { command: command.slice(match[0].length), envPrefix: match[0] };
|
|
163
|
+
}
|
|
164
|
+
function isRecord(value) {
|
|
165
|
+
return value !== null && typeof value === 'object';
|
|
166
|
+
}
|
|
167
|
+
function hasPackageLocalBuildOutputTarget(packageJson) {
|
|
168
|
+
const targets = packageJson.nx?.targets;
|
|
169
|
+
if (!isRecord(targets)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
return Object.keys(targets).some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName));
|
|
173
|
+
}
|
|
174
|
+
async function readZigSteps(absoluteProjectRoot, projectRoot) {
|
|
175
|
+
const buildZigPath = join(absoluteProjectRoot, 'build.zig');
|
|
176
|
+
if (!existsSync(buildZigPath)) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
const buildZig = await readFile(buildZigPath, 'utf-8');
|
|
180
|
+
const declaredSteps = Array.from(buildZig.matchAll(ZIG_STEP_PATTERN), (match) => match[1]);
|
|
181
|
+
if (declaredSteps.length === 0) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
const steps = [];
|
|
185
|
+
for (const step of declaredSteps) {
|
|
186
|
+
if (RESERVED_ZIG_STEPS.has(step)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (!VALID_ZIG_STEP_NAME.test(step)) {
|
|
190
|
+
throw new Error(`${projectRoot}/build.zig declares unsupported Zig step "${step}"; inferred target names cannot contain ':' or other special characters`);
|
|
191
|
+
}
|
|
192
|
+
if (!steps.includes(step)) {
|
|
193
|
+
steps.push(step);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return steps;
|
|
197
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Tree } from 'nx/src/devkit-exports.js';
|
|
2
|
+
import type { NxPolicyIssue } from './workspace-config-policy.js';
|
|
3
|
+
export type { NxPolicyIssue };
|
|
4
|
+
export interface ResolvedProjectTargets {
|
|
5
|
+
targets: ReadonlySet<string>;
|
|
6
|
+
buildDependsOn?: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export interface PackageTargetPolicyOptions {
|
|
9
|
+
resolvedTargetsByProject?: ReadonlyMap<string, ReadonlySet<string> | ResolvedProjectTargets>;
|
|
10
|
+
}
|
|
11
|
+
export declare const BUILD_OUTPUT_DEPENDENCIES: string[];
|
|
12
|
+
export declare function packageNxProjectName(pkg: Record<string, unknown>): string | null;
|
|
13
|
+
export declare function nxRunAlias(projectName: string, targetName: string, continuous: boolean): string;
|
|
14
|
+
/**
|
|
15
|
+
* Check package target policy using an Nx Tree.
|
|
16
|
+
* Uses `getProjects()` for project discovery instead of manual filesystem walking.
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkPackageTargetPolicyTree(tree: Tree, options?: PackageTargetPolicyOptions): NxPolicyIssue[];
|
|
19
|
+
/**
|
|
20
|
+
* Apply package target policy using an Nx Tree.
|
|
21
|
+
* Uses `getProjects()` for project discovery and `updateJson()` for writes.
|
|
22
|
+
* Returns whether anything changed.
|
|
23
|
+
*/
|
|
24
|
+
export declare function applyPackageTargetPolicyTree(tree: Tree, options?: PackageTargetPolicyOptions): boolean;
|
|
25
|
+
export declare function checkPackageTargets(pkg: Record<string, unknown>, packagePath: string, resolvedTargets?: ReadonlySet<string>): NxPolicyIssue[];
|
|
26
|
+
export declare function applyPackageTargets(pkg: Record<string, unknown>, packagePath: string, workspaceNames: ReadonlySet<string>, options?: {
|
|
27
|
+
resolvedTargets?: ReadonlySet<string>;
|
|
28
|
+
}): boolean;
|
|
29
|
+
export declare function checkPackageTargetPolicy(root: string, options?: PackageTargetPolicyOptions): NxPolicyIssue[];
|
|
30
|
+
export declare function applyPackageTargetPolicy(root: string, options?: PackageTargetPolicyOptions): boolean;
|
|
31
|
+
//# sourceMappingURL=package-target-policy.d.ts.map
|
|
@@ -0,0 +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,KAAK,EAAE,aAAa,EAAE,MAAM,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