@smoothbricks/nx-plugin 0.3.2 → 0.3.3
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 +7 -12
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +1 -100
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -125
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +0 -30
- package/dist/version-actions.cjs +39 -35
- package/dist/version-actions.d.cts.map +1 -1
- package/generators.json +1 -1
- package/package.json +1 -1
- package/src/generators/create-package/generator.test.ts +0 -71
- package/src/generators/create-package/generator.ts +1 -121
- package/src/generators/create-package/schema.d.ts +1 -1
- package/src/generators/create-package/schema.json +1 -1
- package/src/index.test.ts +72 -81
- package/src/index.ts +25 -148
- package/src/package-target-policy.test.ts +0 -48
- package/src/package-target-policy.ts +0 -32
- package/src/version-actions.cts +39 -37
package/README.md
CHANGED
|
@@ -11,12 +11,12 @@ target `tsc-js`; this plugin must not duplicate or rename that target.
|
|
|
11
11
|
|
|
12
12
|
- `typecheck-tests` and `typecheck-tests:watch` from `tsconfig.test.json`
|
|
13
13
|
- `test:watch` from explicit `test` commands for Bun and Vitest packages
|
|
14
|
-
-
|
|
14
|
+
- Cargo workspace targets from a neighboring workspace-root `Cargo.toml`
|
|
15
15
|
- aggregate `build` and `lint` targets
|
|
16
16
|
|
|
17
17
|
## Nx Target Naming
|
|
18
18
|
|
|
19
|
-
Target names are `{tool}-{output}` names. Use names like `tsc-js`, `tsdown-js`, and `
|
|
19
|
+
Target names are `{tool}-{output}` names. Use names like `tsc-js`, `tsdown-js`, and `cargo-wasm`; `build` and `lint` are
|
|
20
20
|
aggregates.
|
|
21
21
|
|
|
22
22
|
Concrete targets come from concrete files:
|
|
@@ -25,19 +25,17 @@ Concrete targets come from concrete files:
|
|
|
25
25
|
- `typecheck-tests:watch` is inferred from `tsconfig.test.json` and runs the same typecheck in watch mode.
|
|
26
26
|
- `test:watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
|
|
27
27
|
the corresponding watch command and makes it depend on `typecheck-tests`.
|
|
28
|
-
-
|
|
28
|
+
- A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`; workspaces with
|
|
29
|
+
`cdylib` member crates also receive the cacheable `cargo-wasm` output target.
|
|
29
30
|
- `build` is inferred only when the project has at least one concrete build target to run, such as `tsc-js` from the
|
|
30
|
-
official TypeScript plugin, a package-local target like `tsdown-js`, or
|
|
31
|
-
|
|
31
|
+
official TypeScript plugin, a package-local target like `tsdown-js`, or `cargo-wasm` from this plugin. It depends on
|
|
32
|
+
output-family wildcard targets: `*-js`, `*-web`, `*-html`, `*-css`, `*-ios`, `*-android`, `*-native`, `*-napi`,
|
|
32
33
|
`*-bun`, and `*-wasm`.
|
|
33
34
|
|
|
34
|
-
This is why Zig appears in the convention: the plugin is not guessing from arbitrary Zig source. SmoothBricks requires
|
|
35
|
-
`build.zig` to expose named build steps so Nx can create cacheable, addressable targets from those steps.
|
|
36
|
-
|
|
37
35
|
Do not use colon-style Nx target names such as `build:wasm` or `lint:fix`. Nx CLI syntax already uses colons for
|
|
38
36
|
`project:target:configuration`, so colon target names are hard to read, easy to confuse with configurations, and awkward
|
|
39
37
|
to expose through package scripts. Package scripts may still use names like `build:wasm`; they should delegate to a real
|
|
40
|
-
target such as `nx run pkg:
|
|
38
|
+
target such as `nx run pkg:cargo-wasm`.
|
|
41
39
|
|
|
42
40
|
There is no Nx `lint:fix` target; repository formatting is handled by the root `lint:fix` script.
|
|
43
41
|
|
|
@@ -49,9 +47,6 @@ mode. Smoo validation creates/requires this config for test runners that do not
|
|
|
49
47
|
against, but the package root `tsconfig.json` should not reference `./tsconfig.test.json`. Nx runs test typechecking
|
|
50
48
|
through the inferred `typecheck-tests` target, not through `tsc --build`.
|
|
51
49
|
|
|
52
|
-
Zig targets are inferred only when `build.zig` declares at least one `b.step(...)`. Each step becomes a `zig-*` target,
|
|
53
|
-
so a package `build.zig` must have at least one step.
|
|
54
|
-
|
|
55
50
|
## Bun Test Tracing Generator
|
|
56
51
|
|
|
57
52
|
Configure a package for the Bun test tracing + no-emit test typechecking pattern used in this repo.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/create-package/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/create-package/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAWvG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Scaffold a new workspace package. Invoked by `smoo g ts-lib
|
|
1
|
+
// Scaffold a new TypeScript workspace package. Invoked by `smoo g ts-lib <name>`.
|
|
2
2
|
// CLI wiring: packages/cli/src/generate/index.ts (variant registry)
|
|
3
3
|
import { readJson, writeJson } from 'nx/src/devkit-exports.js';
|
|
4
4
|
export default async function generator(tree, schema) {
|
|
@@ -10,9 +10,6 @@ export default async function generator(tree, schema) {
|
|
|
10
10
|
throw new Error(`Package already exists at ${projectRoot}`);
|
|
11
11
|
}
|
|
12
12
|
writeCommonFiles(tree, schema, packageName, projectRoot, rootPkg);
|
|
13
|
-
if (schema.variant === 'ts-zig') {
|
|
14
|
-
writeZigFiles(tree, schema, projectRoot);
|
|
15
|
-
}
|
|
16
13
|
}
|
|
17
14
|
function extractScope(name) {
|
|
18
15
|
if (!name)
|
|
@@ -130,102 +127,6 @@ function buildPackageJson(schema, packageName, projectRoot, rootPkg) {
|
|
|
130
127
|
}
|
|
131
128
|
return packageJson;
|
|
132
129
|
}
|
|
133
|
-
function writeZigFiles(tree, schema, projectRoot) {
|
|
134
|
-
// Modify package.json for ts-zig variant
|
|
135
|
-
const packageJson = readJson(tree, `${projectRoot}/package.json`);
|
|
136
|
-
// Add wasm export and remove development condition
|
|
137
|
-
const exports = packageJson.exports;
|
|
138
|
-
if (!isRecord(exports)) {
|
|
139
|
-
// invariant throw: writeCommonFiles always emits an object-valued exports map.
|
|
140
|
-
throw new Error('generated package.json exports must be an object');
|
|
141
|
-
}
|
|
142
|
-
exports['./wasm'] = `./dist/${schema.name}.wasm`;
|
|
143
|
-
const dotExport = exports['.'];
|
|
144
|
-
if (!isRecord(dotExport)) {
|
|
145
|
-
// invariant throw: writeCommonFiles always emits an object-valued "." export.
|
|
146
|
-
throw new Error('generated package.json "." export must be an object');
|
|
147
|
-
}
|
|
148
|
-
delete dotExport.development;
|
|
149
|
-
// Add build scripts
|
|
150
|
-
const scripts = packageJson.scripts;
|
|
151
|
-
if (!isRecord(scripts)) {
|
|
152
|
-
// invariant throw: writeCommonFiles always emits an object-valued scripts map.
|
|
153
|
-
throw new Error('generated package.json scripts must be an object');
|
|
154
|
-
}
|
|
155
|
-
scripts['build:zig'] = `nx run ${schema.name}:zig-wasm`;
|
|
156
|
-
scripts['build:ts'] = `nx run ${schema.name}:tsc-js`;
|
|
157
|
-
scripts.build = 'bun run build:ts && bun run build:zig';
|
|
158
|
-
// Change files for zig packages (no src published)
|
|
159
|
-
packageJson.files = ['dist'];
|
|
160
|
-
writeJson(tree, `${projectRoot}/package.json`, packageJson);
|
|
161
|
-
// Modify tsconfig.lib.json for ts-zig
|
|
162
|
-
const tsconfigLib = readJson(tree, `${projectRoot}/tsconfig.lib.json`);
|
|
163
|
-
const libCompilerOptions = tsconfigLib.compilerOptions;
|
|
164
|
-
if (!isRecord(libCompilerOptions)) {
|
|
165
|
-
// invariant throw: writeCommonFiles always emits compilerOptions for library builds.
|
|
166
|
-
throw new Error('generated tsconfig.lib.json compilerOptions must be an object');
|
|
167
|
-
}
|
|
168
|
-
libCompilerOptions.lib = ['es2022', 'webworker'];
|
|
169
|
-
libCompilerOptions.declaration = true;
|
|
170
|
-
libCompilerOptions.sourceMap = true;
|
|
171
|
-
libCompilerOptions.skipLibCheck = true;
|
|
172
|
-
writeJson(tree, `${projectRoot}/tsconfig.lib.json`, tsconfigLib);
|
|
173
|
-
// Modify tsconfig.test.json for ts-zig
|
|
174
|
-
const tsconfigTest = readJson(tree, `${projectRoot}/tsconfig.test.json`);
|
|
175
|
-
const testCompilerOptions = tsconfigTest.compilerOptions;
|
|
176
|
-
if (!isRecord(testCompilerOptions)) {
|
|
177
|
-
// invariant throw: writeCommonFiles always emits compilerOptions for test builds.
|
|
178
|
-
throw new Error('generated tsconfig.test.json compilerOptions must be an object');
|
|
179
|
-
}
|
|
180
|
-
testCompilerOptions.lib = ['es2022', 'webworker'];
|
|
181
|
-
writeJson(tree, `${projectRoot}/tsconfig.test.json`, tsconfigTest);
|
|
182
|
-
// Write build.zig
|
|
183
|
-
tree.write(`${projectRoot}/build.zig`, `const std = @import("std");
|
|
184
|
-
|
|
185
|
-
pub fn build(b: *std.Build) void {
|
|
186
|
-
const optimize = b.standardOptimizeOption(.{});
|
|
187
|
-
|
|
188
|
-
const wasm_step = b.step("wasm", "Build WASM artifact");
|
|
189
|
-
|
|
190
|
-
const wasm_target = b.resolveTargetQuery(.{
|
|
191
|
-
.cpu_arch = .wasm32,
|
|
192
|
-
.os_tag = .freestanding,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const lib = b.addExecutable(.{
|
|
196
|
-
.name = "${schema.name}",
|
|
197
|
-
.root_source_file = b.path("src/${schema.name}.zig"),
|
|
198
|
-
.target = wasm_target,
|
|
199
|
-
.optimize = optimize,
|
|
200
|
-
});
|
|
201
|
-
lib.entry = .disabled;
|
|
202
|
-
lib.rdynamic = true;
|
|
203
|
-
|
|
204
|
-
const install = b.addInstallArtifact(lib, .{
|
|
205
|
-
.dest_dir = .{ .override = .{ .custom = "../dist" } },
|
|
206
|
-
});
|
|
207
|
-
wasm_step.dependOn(&install.step);
|
|
208
|
-
}
|
|
209
|
-
`);
|
|
210
|
-
// Write build.zig.zon
|
|
211
|
-
tree.write(`${projectRoot}/build.zig.zon`, `.{
|
|
212
|
-
.name = .${schema.name},
|
|
213
|
-
.version = "0.0.0",
|
|
214
|
-
.minimum_zig_version = "0.14.0",
|
|
215
|
-
.dependencies = .{},
|
|
216
|
-
.paths = .{
|
|
217
|
-
"build.zig",
|
|
218
|
-
"build.zig.zon",
|
|
219
|
-
"src",
|
|
220
|
-
},
|
|
221
|
-
}
|
|
222
|
-
`);
|
|
223
|
-
// Write src/<name>.zig
|
|
224
|
-
tree.write(`${projectRoot}/src/${schema.name}.zig`, `export fn add(a: i32, b: i32) i32 {
|
|
225
|
-
return a + b;
|
|
226
|
-
}
|
|
227
|
-
`);
|
|
228
|
-
}
|
|
229
130
|
function isRecord(value) {
|
|
230
131
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
231
132
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAiDxG,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,32 +3,24 @@ import { readFile } from 'node:fs/promises';
|
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
5
5
|
import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } 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
6
|
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
10
|
-
const ZIG_WASM_OUTPUTS = ['{projectRoot}/dist/**/*.wasm'];
|
|
11
|
-
const ZIG_NATIVE_OUTPUTS = ['{projectRoot}/dist/**/*.{node,dylib,so,dll,a}'];
|
|
12
|
-
const ZIG_GENERIC_OUTPUTS = ['{projectRoot}/dist/**/*.{wasm,node,dylib,so,dll,a}'];
|
|
13
7
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
14
8
|
'{workspaceRoot}/package.json',
|
|
15
9
|
'{workspaceRoot}/bun.lock',
|
|
16
10
|
'{workspaceRoot}/patches/**/*',
|
|
17
11
|
'{workspaceRoot}/tsconfig.base.json',
|
|
18
12
|
];
|
|
13
|
+
//#region smoo!n/rust-output-target-inference
|
|
19
14
|
// Cargo workspace inference: a package.json sitting next to a Cargo.toml that
|
|
20
15
|
// declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
|
|
21
|
-
// the lint aggregate, mutation (cargo-mutants),
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
16
|
+
// the lint aggregate, mutation (cargo-mutants), and bench. Rust output targets
|
|
17
|
+
// (cargo-wasm, cargo-napi, ...) are never inferred from crate metadata such as
|
|
18
|
+
// cdylib crate-types — a native N-API cdylib is not a wasm build. Packages
|
|
19
|
+
// declare output targets in package.json nx.targets, and those *-wasm/*-napi/
|
|
20
|
+
// *-native output-family names feed the aggregate build and clean targets.
|
|
21
|
+
// Explicit nx.targets entries always win over inference.
|
|
25
22
|
const CARGO_WORKSPACE_PATTERN = /^\s*\[workspace\]/m;
|
|
26
|
-
|
|
27
|
-
const CARGO_MEMBER_ENTRY_PATTERN = /["']([^"']+)["']/g;
|
|
28
|
-
const CARGO_PACKAGE_NAME_PATTERN = /^\s*name\s*=\s*["']([^"']+)["']/m;
|
|
29
|
-
const CARGO_WASM_CRATE_NAME_PATTERN = /-wasm$/;
|
|
30
|
-
const CARGO_CDYLIB_CRATE_TYPE_PATTERN = /^\s*crate-type\s*=\s*\[[^\]]*["']cdylib["']/m;
|
|
31
|
-
const CARGO_WASM_RELEASE_PROFILE_PATTERN = /^\s*\[profile\.wasm-release\]/m;
|
|
23
|
+
//#endregion
|
|
32
24
|
const CARGO_INPUTS = [
|
|
33
25
|
'{projectRoot}/**/*.rs',
|
|
34
26
|
'{projectRoot}/**/Cargo.toml',
|
|
@@ -59,6 +51,12 @@ export const createNodesV2 = [
|
|
|
59
51
|
const errors = [];
|
|
60
52
|
await Promise.all(projectConfigurationFiles.map(async (packageJsonPath) => {
|
|
61
53
|
try {
|
|
54
|
+
if (isManagedPackageJsonSource(packageJsonPath)) {
|
|
55
|
+
// smoo monorepo managed raw/templates are source copies, not projects.
|
|
56
|
+
// Dogfood trees symlink live paths here; discovering both doubles names.
|
|
57
|
+
results.push([packageJsonPath, {}]);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
62
60
|
results.push([packageJsonPath, await createProjectTargets(packageJsonPath, context.workspaceRoot)]);
|
|
63
61
|
}
|
|
64
62
|
catch (error) {
|
|
@@ -71,6 +69,10 @@ export const createNodesV2 = [
|
|
|
71
69
|
return results;
|
|
72
70
|
},
|
|
73
71
|
];
|
|
72
|
+
function isManagedPackageJsonSource(packageJsonPath) {
|
|
73
|
+
const normalized = packageJsonPath.replaceAll('\\', '/');
|
|
74
|
+
return normalized.includes('/managed/raw/') || normalized.includes('/managed/templates/');
|
|
75
|
+
}
|
|
74
76
|
export default { createNodesV2 };
|
|
75
77
|
async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
76
78
|
const projectRoot = dirname(packageJsonPath);
|
|
@@ -80,8 +82,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
80
82
|
const validationTargets = [];
|
|
81
83
|
const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
|
|
82
84
|
const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
const hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
|
|
86
|
+
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
85
87
|
if (hasLibTsconfig) {
|
|
86
88
|
// Official Nx target inference is disabled because its compiler surface only
|
|
87
89
|
// supports tsc/tsgo. Smoo owns the complete transformer-aware ttsc targets.
|
|
@@ -145,8 +147,10 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
145
147
|
else if (hasLibTsconfig) {
|
|
146
148
|
validationTargets.push('typecheck');
|
|
147
149
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
// Member crates get their targets from the workspace-root package.json,
|
|
151
|
+
// never per-crate — one Nx project per Cargo workspace.
|
|
152
|
+
const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
|
|
153
|
+
if (existsSync(cargoTomlPath) && CARGO_WORKSPACE_PATTERN.test(await readFile(cargoTomlPath, 'utf-8'))) {
|
|
150
154
|
const declared = packageJson.nx?.targets ?? {};
|
|
151
155
|
if (!('cargo-test' in declared)) {
|
|
152
156
|
targets['cargo-test'] = createCargoTestTarget(projectRoot);
|
|
@@ -184,49 +188,6 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
184
188
|
options: { command: 'cargo bench --workspace', cwd: projectRoot },
|
|
185
189
|
};
|
|
186
190
|
}
|
|
187
|
-
if (cargo.wasmCrates.length > 0 && !('cargo-wasm' in declared)) {
|
|
188
|
-
const profile = cargo.hasWasmReleaseProfile ? 'wasm-release' : 'release';
|
|
189
|
-
const buildAndCopy = (crate, profileName) => {
|
|
190
|
-
const artifact = crate.replace(/-/g, '_');
|
|
191
|
-
const profileFlag = profileName === null ? '' : ` --profile ${profileName}`;
|
|
192
|
-
const outputDirectory = profileName ?? 'debug';
|
|
193
|
-
return `cargo build${profileFlag} --target wasm32-unknown-unknown -p ${crate} && mkdir -p dist && cp target/wasm32-unknown-unknown/${outputDirectory}/${artifact}.wasm dist/${artifact}.wasm`;
|
|
194
|
-
};
|
|
195
|
-
targets['cargo-wasm'] = {
|
|
196
|
-
executor: 'nx:run-commands',
|
|
197
|
-
cache: true,
|
|
198
|
-
inputs: CARGO_INPUTS,
|
|
199
|
-
outputs: ['{projectRoot}/dist/**/*.wasm'],
|
|
200
|
-
options: {
|
|
201
|
-
commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, profile)),
|
|
202
|
-
cwd: projectRoot,
|
|
203
|
-
parallel: false,
|
|
204
|
-
},
|
|
205
|
-
configurations: {
|
|
206
|
-
development: {
|
|
207
|
-
commands: cargo.wasmCrates.map((crate) => buildAndCopy(crate, null)),
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
hasOrdinaryBuildOutputTarget = true;
|
|
212
|
-
hasAnyBuildOutputTarget = true;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
|
|
216
|
-
for (const step of zigSteps) {
|
|
217
|
-
const targetName = `zig-${step}`;
|
|
218
|
-
targets[targetName] = {
|
|
219
|
-
executor: 'nx:run-commands',
|
|
220
|
-
cache: true,
|
|
221
|
-
inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
|
|
222
|
-
outputs: zigOutputsForStep(step),
|
|
223
|
-
options: {
|
|
224
|
-
command: `zig build ${step}`,
|
|
225
|
-
cwd: projectRoot,
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
hasOrdinaryBuildOutputTarget = true;
|
|
229
|
-
hasAnyBuildOutputTarget = true;
|
|
230
191
|
}
|
|
231
192
|
if (hasOrdinaryBuildOutputTarget) {
|
|
232
193
|
targets.build = {
|
|
@@ -333,65 +294,3 @@ function classifyPackageLocalBuildOutputs(packageJson) {
|
|
|
333
294
|
platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
|
|
334
295
|
};
|
|
335
296
|
}
|
|
336
|
-
function zigOutputsForStep(step) {
|
|
337
|
-
if (step.endsWith('wasm')) {
|
|
338
|
-
return ZIG_WASM_OUTPUTS;
|
|
339
|
-
}
|
|
340
|
-
if (step.endsWith('native')) {
|
|
341
|
-
return ZIG_NATIVE_OUTPUTS;
|
|
342
|
-
}
|
|
343
|
-
return ZIG_GENERIC_OUTPUTS;
|
|
344
|
-
}
|
|
345
|
-
async function readCargoWorkspace(absoluteProjectRoot) {
|
|
346
|
-
const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
|
|
347
|
-
if (!existsSync(cargoTomlPath)) {
|
|
348
|
-
return null;
|
|
349
|
-
}
|
|
350
|
-
const cargoToml = await readFile(cargoTomlPath, 'utf-8');
|
|
351
|
-
if (!CARGO_WORKSPACE_PATTERN.test(cargoToml)) {
|
|
352
|
-
// Member crates get their targets from the workspace-root package.json,
|
|
353
|
-
// never per-crate — one Nx project per Cargo workspace.
|
|
354
|
-
return null;
|
|
355
|
-
}
|
|
356
|
-
const wasmCrates = [];
|
|
357
|
-
const membersList = CARGO_MEMBERS_PATTERN.exec(cargoToml)?.[1] ?? '';
|
|
358
|
-
for (const match of membersList.matchAll(CARGO_MEMBER_ENTRY_PATTERN)) {
|
|
359
|
-
const memberTomlPath = join(absoluteProjectRoot, match[1], 'Cargo.toml');
|
|
360
|
-
if (!existsSync(memberTomlPath)) {
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
363
|
-
const memberToml = await readFile(memberTomlPath, 'utf-8');
|
|
364
|
-
const name = CARGO_PACKAGE_NAME_PATTERN.exec(memberToml)?.[1];
|
|
365
|
-
if (name &&
|
|
366
|
-
CARGO_WASM_CRATE_NAME_PATTERN.test(name) &&
|
|
367
|
-
CARGO_CDYLIB_CRATE_TYPE_PATTERN.test(memberToml) &&
|
|
368
|
-
!wasmCrates.includes(name)) {
|
|
369
|
-
wasmCrates.push(name);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return { wasmCrates, hasWasmReleaseProfile: CARGO_WASM_RELEASE_PROFILE_PATTERN.test(cargoToml) };
|
|
373
|
-
}
|
|
374
|
-
async function readZigSteps(absoluteProjectRoot, projectRoot) {
|
|
375
|
-
const buildZigPath = join(absoluteProjectRoot, 'build.zig');
|
|
376
|
-
if (!existsSync(buildZigPath)) {
|
|
377
|
-
return [];
|
|
378
|
-
}
|
|
379
|
-
const buildZig = await readFile(buildZigPath, 'utf-8');
|
|
380
|
-
const declaredSteps = Array.from(buildZig.matchAll(ZIG_STEP_PATTERN), (match) => match[1]);
|
|
381
|
-
if (declaredSteps.length === 0) {
|
|
382
|
-
return [];
|
|
383
|
-
}
|
|
384
|
-
const steps = [];
|
|
385
|
-
for (const step of declaredSteps) {
|
|
386
|
-
if (RESERVED_ZIG_STEPS.has(step)) {
|
|
387
|
-
continue;
|
|
388
|
-
}
|
|
389
|
-
if (!VALID_ZIG_STEP_NAME.test(step)) {
|
|
390
|
-
throw new Error(`${projectRoot}/build.zig declares unsupported Zig step "${step}"; inferred target names cannot contain ':' or other special characters`);
|
|
391
|
-
}
|
|
392
|
-
if (!steps.includes(step)) {
|
|
393
|
-
steps.push(step);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return steps;
|
|
397
|
-
}
|
|
@@ -1 +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,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA2JD,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;
|
|
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,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA2JD,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;AAynBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAoBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA4B1G;AAoJD,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACpC,aAAa,EAAE,CAEjB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GACtD,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAmBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA6BxG"}
|
|
@@ -240,7 +240,6 @@ function isSafeNxScriptCommand(command) {
|
|
|
240
240
|
/^tsdown(?:\s|$)/.test(trimmed) ||
|
|
241
241
|
/^vite\s+(?:build|dev|preview)(?:\s|$)/.test(trimmed) ||
|
|
242
242
|
/^astro\s+(?:build|dev|preview|check)(?:\s|$)/.test(trimmed) ||
|
|
243
|
-
/^zig\s+build(?:\s|$)/.test(trimmed) ||
|
|
244
243
|
/^bun\s+[./\w-]*build[\w.-]*\.ts(?:\s|$)/.test(trimmed) ||
|
|
245
244
|
/(?:^|\s)(?:bench|benchmark)(?:\s|$)/.test(trimmed) ||
|
|
246
245
|
/^wrangler\s+build(?:\s|$)/.test(trimmed));
|
|
@@ -300,10 +299,6 @@ function targetNameForCommand(command) {
|
|
|
300
299
|
if (/^tsdown(?:\s|$)/.test(trimmed)) {
|
|
301
300
|
return 'tsdown-js';
|
|
302
301
|
}
|
|
303
|
-
const zigStep = /^zig\s+build\s+([A-Za-z0-9_-]+)(?:\s|$)/.exec(trimmed)?.[1];
|
|
304
|
-
if (zigStep) {
|
|
305
|
-
return `zig-${zigStep}`;
|
|
306
|
-
}
|
|
307
302
|
if (/^wrangler\s+build(?:\s|$)/.test(trimmed)) {
|
|
308
303
|
return 'build';
|
|
309
304
|
}
|
|
@@ -438,18 +433,6 @@ function directoryContainsTestFiles(path) {
|
|
|
438
433
|
}
|
|
439
434
|
return false;
|
|
440
435
|
}
|
|
441
|
-
function validateBuildZigPolicy(root, packagePath) {
|
|
442
|
-
const path = join(root, packagePath, 'build.zig');
|
|
443
|
-
if (!existsSync(path)) {
|
|
444
|
-
return [];
|
|
445
|
-
}
|
|
446
|
-
if (/\bb\.step\s*\(/.test(readFileSync(path, 'utf8'))) {
|
|
447
|
-
return [];
|
|
448
|
-
}
|
|
449
|
-
return [
|
|
450
|
-
{ path: join(root, packagePath), message: `${packagePath}/build.zig must define at least one b.step(...) target` },
|
|
451
|
-
];
|
|
452
|
-
}
|
|
453
436
|
function validateExplicitNxTargets(pkg, packagePath, resolvedProject) {
|
|
454
437
|
const issues = validatePlatformTargetDependencies(packagePath, resolvedProject);
|
|
455
438
|
const nx = recordProperty(pkg, 'nx');
|
|
@@ -757,17 +740,6 @@ function directoryContainsTestFilesTree(tree, path) {
|
|
|
757
740
|
}
|
|
758
741
|
return false;
|
|
759
742
|
}
|
|
760
|
-
function validateBuildZigPolicyTree(tree, packagePath) {
|
|
761
|
-
const path = `${packagePath}/build.zig`;
|
|
762
|
-
if (!tree.exists(path)) {
|
|
763
|
-
return [];
|
|
764
|
-
}
|
|
765
|
-
const content = tree.read(path, 'utf-8');
|
|
766
|
-
if (content && /\bb\.step\s*\(/.test(content)) {
|
|
767
|
-
return [];
|
|
768
|
-
}
|
|
769
|
-
return [{ path: packagePath, message: `${packagePath}/build.zig must define at least one b.step(...) target` }];
|
|
770
|
-
}
|
|
771
743
|
function validateTestEntrypointPresenceTree(tree, packagePath, pkg) {
|
|
772
744
|
if (packagePath === '.') {
|
|
773
745
|
return [];
|
|
@@ -795,7 +767,6 @@ export function checkPackageTargetPolicyTree(tree, options = {}) {
|
|
|
795
767
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
796
768
|
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
797
769
|
issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
|
|
798
|
-
issues.push(...validateBuildZigPolicyTree(tree, packagePath));
|
|
799
770
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
|
|
800
771
|
}
|
|
801
772
|
return issues;
|
|
@@ -979,7 +950,6 @@ export function checkPackageTargetPolicy(root, options = {}) {
|
|
|
979
950
|
const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
|
|
980
951
|
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
981
952
|
issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
|
|
982
|
-
issues.push(...validateBuildZigPolicy(root, packagePath));
|
|
983
953
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
|
|
984
954
|
}
|
|
985
955
|
return issues;
|
package/dist/version-actions.cjs
CHANGED
|
@@ -11,10 +11,12 @@ const afterAllProjectsVersioned = async (cwd, options) => {
|
|
|
11
11
|
// - https://github.com/oven-sh/bun/issues/18906
|
|
12
12
|
// - https://github.com/oven-sh/bun/issues/20477
|
|
13
13
|
// - https://github.com/oven-sh/bun/issues/20829
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
|
|
14
|
+
//
|
|
15
|
+
// After version bumps, rewrite bun.lock for pack/publish:
|
|
16
|
+
// - stable package.json versions stay as-is
|
|
17
|
+
// - unpublished package.json prereleases (prepare-next) map to last stable tag
|
|
18
|
+
// so a releasing package does not embed unpublishable -next deps via workspace:*
|
|
19
|
+
const updated = syncBunLockfileVersionsForPublish(cwd);
|
|
18
20
|
if (updated === 0) {
|
|
19
21
|
return result;
|
|
20
22
|
}
|
|
@@ -24,7 +26,7 @@ const afterAllProjectsVersioned = async (cwd, options) => {
|
|
|
24
26
|
};
|
|
25
27
|
};
|
|
26
28
|
baseVersionActions.afterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
27
|
-
function
|
|
29
|
+
function syncBunLockfileVersionsForPublish(root) {
|
|
28
30
|
const lockfilePath = (0, node_path_1.join)(root, 'bun.lock');
|
|
29
31
|
if (!(0, node_fs_1.existsSync)(lockfilePath)) {
|
|
30
32
|
throw new Error('bun.lock not found');
|
|
@@ -33,12 +35,7 @@ function syncBunLockfileVersions(root) {
|
|
|
33
35
|
let lockfile = (0, node_fs_1.readFileSync)(lockfilePath, 'utf8');
|
|
34
36
|
let updated = 0;
|
|
35
37
|
for (const pkg of packages) {
|
|
36
|
-
|
|
37
|
-
// never have been published. Use the latest stable git tag version so
|
|
38
|
-
// that `bun pm pack` writes an installable dependency range for consumers.
|
|
39
|
-
const targetVersion = pkg.version.includes('-')
|
|
40
|
-
? (latestStableTagVersion(root, pkg.projectName) ?? pkg.version)
|
|
41
|
-
: pkg.version;
|
|
38
|
+
const targetVersion = publishLockfileVersion(root, pkg.projectName, pkg.version);
|
|
42
39
|
const relativePath = pkg.path.replaceAll('\\', '/');
|
|
43
40
|
const escaped = escapeRegex(relativePath);
|
|
44
41
|
const pattern = new RegExp(`("${escaped}":\\s*\\{[^}]*"version":\\s*")([^"]+)(")`);
|
|
@@ -53,7 +50,8 @@ function syncBunLockfileVersions(root) {
|
|
|
53
50
|
continue;
|
|
54
51
|
}
|
|
55
52
|
lockfile = lockfile.replace(pattern, `$1${targetVersion}$3`);
|
|
56
|
-
|
|
53
|
+
const suffix = targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : '';
|
|
54
|
+
console.log(`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${suffix}`);
|
|
57
55
|
updated++;
|
|
58
56
|
}
|
|
59
57
|
if (updated > 0) {
|
|
@@ -62,6 +60,35 @@ function syncBunLockfileVersions(root) {
|
|
|
62
60
|
console.log(updated > 0 ? `Updated ${updated} workspace version(s) in bun.lock` : 'All workspace versions already in sync.');
|
|
63
61
|
return updated;
|
|
64
62
|
}
|
|
63
|
+
function publishLockfileVersion(root, projectName, packageVersion) {
|
|
64
|
+
if (!packageVersion.includes('-')) {
|
|
65
|
+
return packageVersion;
|
|
66
|
+
}
|
|
67
|
+
return latestStableTagVersion(root, projectName) ?? packageVersion;
|
|
68
|
+
}
|
|
69
|
+
function latestStableTagVersion(root, projectName) {
|
|
70
|
+
try {
|
|
71
|
+
const output = (0, node_child_process_1.execSync)(`git tag --list '${projectName}@*' --sort=-v:refname`, {
|
|
72
|
+
cwd: root,
|
|
73
|
+
encoding: 'utf8',
|
|
74
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
75
|
+
});
|
|
76
|
+
const prefix = `${projectName}@`;
|
|
77
|
+
for (const line of output.split('\n')) {
|
|
78
|
+
const tag = line.trim();
|
|
79
|
+
if (!tag.startsWith(prefix))
|
|
80
|
+
continue;
|
|
81
|
+
const version = tag.slice(prefix.length);
|
|
82
|
+
if (version && !version.includes('-')) {
|
|
83
|
+
return version;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
65
92
|
function workspacePackages(root) {
|
|
66
93
|
const packagesRoot = (0, node_path_1.join)(root, 'packages');
|
|
67
94
|
return (0, node_fs_1.readdirSync)(packagesRoot, { withFileTypes: true })
|
|
@@ -89,27 +116,4 @@ function isRecord(value) {
|
|
|
89
116
|
function escapeRegex(value) {
|
|
90
117
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
91
118
|
}
|
|
92
|
-
function latestStableTagVersion(root, projectName) {
|
|
93
|
-
try {
|
|
94
|
-
const output = (0, node_child_process_1.execSync)(`git tag --list '${projectName}@*' --sort=-v:refname`, {
|
|
95
|
-
cwd: root,
|
|
96
|
-
encoding: 'utf8',
|
|
97
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
98
|
-
});
|
|
99
|
-
const prefix = `${projectName}@`;
|
|
100
|
-
for (const line of output.split('\n')) {
|
|
101
|
-
const tag = line.trim();
|
|
102
|
-
if (!tag.startsWith(prefix))
|
|
103
|
-
continue;
|
|
104
|
-
const version = tag.slice(prefix.length);
|
|
105
|
-
if (version && !version.includes('-')) {
|
|
106
|
-
return version;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
119
|
module.exports = baseVersionActions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQ5E,QAAA,MAAM,kBAAkB;+BALyC,yBAAyB;CAKf,CAAC;
|
|
1
|
+
{"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQ5E,QAAA,MAAM,kBAAkB;+BALyC,yBAAyB;CAKf,CAAC;SA4BnE,kBAAkB"}
|
package/generators.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"create-package": {
|
|
14
14
|
"factory": "./dist/generators/create-package/generator.js",
|
|
15
15
|
"schema": "./src/generators/create-package/schema.json",
|
|
16
|
-
"description": "Scaffold a new workspace package
|
|
16
|
+
"description": "Scaffold a new TypeScript workspace package"
|
|
17
17
|
},
|
|
18
18
|
"make-public": {
|
|
19
19
|
"factory": "./dist/generators/make-public/generator.js",
|