@smoothbricks/nx-plugin 0.2.1 → 0.2.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/dist/bounded-test-policy.d.ts +2 -0
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +29 -0
- package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -1
- package/dist/generators/bun-test-tracing/generator.js +18 -22
- package/dist/release-config-policy.d.ts.map +1 -1
- package/dist/release-config-policy.js +4 -0
- package/dist/version-actions.cjs +39 -7
- package/dist/version-actions.d.cts.map +1 -1
- package/package.json +2 -2
- package/src/bounded-test-policy.test.ts +24 -7
- package/src/bounded-test-policy.ts +36 -0
- package/src/bun-bootstrap.test.ts +2 -0
- package/src/generators/bounded-test-targets/generator.test.ts +7 -3
- package/src/generators/bun-test-tracing/generator.test.ts +12 -5
- package/src/generators/bun-test-tracing/generator.ts +18 -27
- package/src/release-config-policy.test.ts +3 -0
- package/src/release-config-policy.ts +4 -0
- package/src/version-actions.cts +49 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const BOUNDED_TEST_EXECUTOR = "@smoothbricks/nx-plugin:bounded-exec";
|
|
2
2
|
export declare const BOUNDED_TEST_TIMEOUT_MS = 120000;
|
|
3
3
|
export declare const BOUNDED_TEST_KILL_AFTER_MS = 10000;
|
|
4
|
+
export declare const BOUNDED_TEST_PER_TEST_TIMEOUT_MS = 30000;
|
|
4
5
|
export interface BoundedTestPolicyPackageJson {
|
|
5
6
|
name?: string;
|
|
6
7
|
workspaces?: unknown;
|
|
@@ -29,4 +30,5 @@ export declare function checkWorkspaceBoundedTestTargetPolicy(root: string): Bou
|
|
|
29
30
|
export declare function checkBoundedTestTargetPolicy(packageJson: BoundedTestPolicyPackageJson, options: ApplyBoundedTestTargetPolicyOptions): boolean;
|
|
30
31
|
export declare function boundedTestScriptAlias(projectName: string): string;
|
|
31
32
|
export declare function resolveTestCommand(packageJson: BoundedTestPolicyPackageJson, defaultCommand?: string, projectJson?: BoundedTestPolicyProjectJson): string;
|
|
33
|
+
export declare function ensureBunTestTimeoutFlag(command: string, timeoutMs?: number): string;
|
|
32
34
|
//# sourceMappingURL=bounded-test-policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-test-policy.d.ts","sourceRoot":"","sources":["../src/bounded-test-policy.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAC/C,eAAO,MAAM,0BAA0B,QAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"bounded-test-policy.d.ts","sourceRoot":"","sources":["../src/bounded-test-policy.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAC/C,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAKjD,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACnD,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mCAAmC;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,OAAO,EAAE,mCAAmC,GAC3C,IAAI,CAmBN;AAED,wBAAgB,qCAAqC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CA0B3E;AAED,wBAAgB,qCAAqC,CAAC,IAAI,EAAE,MAAM,GAAG,sBAAsB,EAAE,CAyB5F;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,OAAO,EAAE,mCAAmC,GAC3C,OAAO,CAmBT;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,4BAA4B,EACzC,cAAc,SAAa,EAC3B,WAAW,CAAC,EAAE,4BAA4B,GACzC,MAAM,CAER;AA+CD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAmC,GAAG,MAAM,CAa9G"}
|
|
@@ -3,6 +3,11 @@ import { dirname, join } from 'node:path';
|
|
|
3
3
|
export const BOUNDED_TEST_EXECUTOR = '@smoothbricks/nx-plugin:bounded-exec';
|
|
4
4
|
export const BOUNDED_TEST_TIMEOUT_MS = 120_000;
|
|
5
5
|
export const BOUNDED_TEST_KILL_AFTER_MS = 10_000;
|
|
6
|
+
// Per-test timeout passed to `bun test --timeout=<ms>`. Bun's default is
|
|
7
|
+
// 5000ms which is too tight for git-fixture tests on slower CI runners
|
|
8
|
+
// (Actions). The bunfig.toml `[test] timeout` key is silently ignored by
|
|
9
|
+
// Bun — the only working surfaces are this CLI flag and `setDefaultTimeout()`.
|
|
10
|
+
export const BOUNDED_TEST_PER_TEST_TIMEOUT_MS = 30_000;
|
|
6
11
|
export function applyBoundedTestTargetPolicy(packageJson, options) {
|
|
7
12
|
const command = resolveTestCommand(packageJson, options.defaultCommand ?? 'bun test', options.projectJson);
|
|
8
13
|
const targetOwner = options.projectJson ?? (packageJson.nx ??= {});
|
|
@@ -83,6 +88,7 @@ export function checkBoundedTestTargetPolicy(packageJson, options) {
|
|
|
83
88
|
typeof targetOptions.command !== 'string' ||
|
|
84
89
|
targetOptions.command.length === 0 ||
|
|
85
90
|
isPackageTestScriptRunnerCommand(targetOptions.command) ||
|
|
91
|
+
targetOptions.command !== ensureBunTestTimeoutFlag(targetOptions.command) ||
|
|
86
92
|
targetOptions.cwd !== '{projectRoot}' ||
|
|
87
93
|
targetOptions.timeoutMs !== BOUNDED_TEST_TIMEOUT_MS ||
|
|
88
94
|
targetOptions.killAfterMs !== BOUNDED_TEST_KILL_AFTER_MS) {
|
|
@@ -94,6 +100,9 @@ export function boundedTestScriptAlias(projectName) {
|
|
|
94
100
|
return `nx run ${projectName}:test --outputStyle=stream`;
|
|
95
101
|
}
|
|
96
102
|
export function resolveTestCommand(packageJson, defaultCommand = 'bun test', projectJson) {
|
|
103
|
+
return ensureBunTestTimeoutFlag(resolveRawTestCommand(packageJson, defaultCommand, projectJson));
|
|
104
|
+
}
|
|
105
|
+
function resolveRawTestCommand(packageJson, defaultCommand, projectJson) {
|
|
97
106
|
const commandFromProjectTarget = resolveTargetCommand(projectJson?.targets?.test);
|
|
98
107
|
if (commandFromProjectTarget) {
|
|
99
108
|
return commandFromProjectTarget;
|
|
@@ -120,6 +129,26 @@ function resolveTargetCommand(existingTarget) {
|
|
|
120
129
|
}
|
|
121
130
|
return null;
|
|
122
131
|
}
|
|
132
|
+
const BUN_TEST_PREFIX = /^bun\s+test(?=\s|$)/;
|
|
133
|
+
const EXISTING_BUN_TIMEOUT = /(^|\s)--timeout(?:=|\s+)(\S+)/;
|
|
134
|
+
// Bun's `[test] timeout` bunfig key is silently ignored — only the CLI flag
|
|
135
|
+
// and `setDefaultTimeout()` actually take effect. Normalize every `bun test`
|
|
136
|
+
// command so the policy enforces the workspace per-test timeout in the one
|
|
137
|
+
// place where Bun will honor it.
|
|
138
|
+
export function ensureBunTestTimeoutFlag(command, timeoutMs = BOUNDED_TEST_PER_TEST_TIMEOUT_MS) {
|
|
139
|
+
if (!BUN_TEST_PREFIX.test(command)) {
|
|
140
|
+
return command;
|
|
141
|
+
}
|
|
142
|
+
const flag = `--timeout=${timeoutMs}`;
|
|
143
|
+
const existing = EXISTING_BUN_TIMEOUT.exec(command);
|
|
144
|
+
if (!existing) {
|
|
145
|
+
return command.replace(BUN_TEST_PREFIX, `bun test ${flag}`);
|
|
146
|
+
}
|
|
147
|
+
if (existing[2] === String(timeoutMs)) {
|
|
148
|
+
return command;
|
|
149
|
+
}
|
|
150
|
+
return command.replace(EXISTING_BUN_TIMEOUT, `${existing[1]}${flag}`);
|
|
151
|
+
}
|
|
123
152
|
function isPackageTestScriptRunnerCommand(command) {
|
|
124
153
|
return /^(?:bun\s+run|npm(?:\s+run)?|pnpm(?:\s+run)?|yarn(?:\s+run)?)\s+test(?:\s|$)/.test(command.trim());
|
|
125
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/bun-test-tracing/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,IAAI,EAEV,MAAM,0BAA0B,CAAC;AAIlC,UAAU,6BAA6B;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/bun-test-tracing/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,IAAI,EAEV,MAAM,0BAA0B,CAAC;AAIlC,UAAU,6BAA6B;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAgCD,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBxG"}
|
|
@@ -9,7 +9,6 @@ const DEFAULT_TEST_INCLUDES = [
|
|
|
9
9
|
'src/test-suite-tracer.ts',
|
|
10
10
|
];
|
|
11
11
|
const COPIED_COMPILER_OPTIONS = ['baseUrl', 'module', 'moduleResolution', 'jsx', 'lib'];
|
|
12
|
-
const DEFAULT_BUN_TEST_TIMEOUT_MS = 30_000;
|
|
13
12
|
export default async function generator(tree, schema) {
|
|
14
13
|
const options = normalizeOptions(schema);
|
|
15
14
|
const resolved = resolveProject(tree, options.project);
|
|
@@ -77,39 +76,36 @@ function writeBunfig(tree, projectRoot) {
|
|
|
77
76
|
const bunfigPath = joinPathFragments(projectRoot, 'bunfig.toml');
|
|
78
77
|
const preloadEntries = '"@smoothbricks/lmao/bun/preload", "@smoothbricks/lmao/bun/trace-preload"';
|
|
79
78
|
if (!tree.exists(bunfigPath)) {
|
|
80
|
-
tree.write(bunfigPath, `[test]\
|
|
79
|
+
tree.write(bunfigPath, `[test]\npreload = [${preloadEntries}]\n`);
|
|
81
80
|
return;
|
|
82
81
|
}
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
// Bun silently ignores `[test] timeout` in bunfig.toml — only the `--timeout`
|
|
83
|
+
// CLI flag and `setDefaultTimeout()` actually take effect. Strip any stale
|
|
84
|
+
// `timeout = N` lines so the file isn't lying about what's enforced; the real
|
|
85
|
+
// per-test timeout is wired into `bun test --timeout=N` by the bounded-test
|
|
86
|
+
// policy (see BOUNDED_TEST_PER_TEST_TIMEOUT_MS).
|
|
87
|
+
const current = stripBunTestTimeoutLine(tree.read(bunfigPath, 'utf-8') ?? '');
|
|
85
88
|
// Already has the package specifier preloads
|
|
86
|
-
if (
|
|
87
|
-
if (
|
|
88
|
-
tree.write(bunfigPath,
|
|
89
|
+
if (current.includes('@smoothbricks/lmao/bun/preload')) {
|
|
90
|
+
if (current !== (tree.read(bunfigPath, 'utf-8') ?? '')) {
|
|
91
|
+
tree.write(bunfigPath, current);
|
|
89
92
|
}
|
|
90
93
|
return;
|
|
91
94
|
}
|
|
92
95
|
// Replace old patterns with the package specifier preloads
|
|
93
|
-
if (
|
|
94
|
-
tree.write(bunfigPath,
|
|
96
|
+
if (current.includes('preload = [')) {
|
|
97
|
+
tree.write(bunfigPath, current.replace(/preload\s*=\s*\[.*?\]/s, `preload = [${preloadEntries}]`));
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
97
|
-
if (next.includes('[test]')) {
|
|
98
|
-
tree.write(bunfigPath, next.replace('[test]', `[test]\npreload = [${preloadEntries}]`));
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const suffix = next.endsWith('\n') ? '' : '\n';
|
|
102
|
-
tree.write(bunfigPath, `${next}${suffix}[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\npreload = [${preloadEntries}]\n`);
|
|
103
|
-
}
|
|
104
|
-
function ensureBunTestTimeout(current) {
|
|
105
|
-
if (/(^|\n)\s*timeout\s*=/.test(current)) {
|
|
106
|
-
return current;
|
|
107
|
-
}
|
|
108
100
|
if (current.includes('[test]')) {
|
|
109
|
-
|
|
101
|
+
tree.write(bunfigPath, current.replace('[test]', `[test]\npreload = [${preloadEntries}]`));
|
|
102
|
+
return;
|
|
110
103
|
}
|
|
111
104
|
const suffix = current.endsWith('\n') ? '' : '\n';
|
|
112
|
-
|
|
105
|
+
tree.write(bunfigPath, `${current}${suffix}[test]\npreload = [${preloadEntries}]\n`);
|
|
106
|
+
}
|
|
107
|
+
function stripBunTestTimeoutLine(current) {
|
|
108
|
+
return current.replace(/^\s*timeout\s*=.*\n?/gm, '');
|
|
113
109
|
}
|
|
114
110
|
function renderSuiteTracer(options) {
|
|
115
111
|
return [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"release-config-policy.d.ts","sourceRoot":"","sources":["../src/release-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AACjF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"release-config-policy.d.ts","sourceRoot":"","sources":["../src/release-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AACjF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CAuFnF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAuC3E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKlE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYtE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW9D"}
|
|
@@ -55,6 +55,9 @@ export function checkReleaseConfig(nxJson) {
|
|
|
55
55
|
if (!changelog) {
|
|
56
56
|
issues.push({ path: 'nx.json', message: 'release.changelog config is missing' });
|
|
57
57
|
}
|
|
58
|
+
if (changelog && changelog.automaticFromRef !== true) {
|
|
59
|
+
issues.push({ path: 'nx.json', message: 'release.changelog.automaticFromRef must be true' });
|
|
60
|
+
}
|
|
58
61
|
if (changelog && changelog.workspaceChangelog !== false) {
|
|
59
62
|
issues.push({ path: 'nx.json', message: 'release.changelog.workspaceChangelog must be false' });
|
|
60
63
|
}
|
|
@@ -103,6 +106,7 @@ export function applyReleaseConfig(nxJson) {
|
|
|
103
106
|
const releaseTag = getOrCreateRecord(release, 'releaseTag');
|
|
104
107
|
changed = setStringProperty(releaseTag, 'pattern', SMOO_NX_RELEASE_TAG_PATTERN) || changed;
|
|
105
108
|
const changelog = getOrCreateRecord(release, 'changelog');
|
|
109
|
+
changed = setBooleanProperty(changelog, 'automaticFromRef', true) || changed;
|
|
106
110
|
changed = setBooleanProperty(changelog, 'workspaceChangelog', false) || changed;
|
|
107
111
|
const projectChangelogs = getOrCreateRecord(changelog, 'projectChangelogs');
|
|
108
112
|
changed = setBooleanProperty(projectChangelogs, 'createRelease', false) || changed;
|
package/dist/version-actions.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const node_child_process_1 = require("node:child_process");
|
|
2
3
|
const node_fs_1 = require("node:fs");
|
|
3
4
|
const node_path_1 = require("node:path");
|
|
4
5
|
const nxJsVersionActions = require('@nx/js/src/release/version-actions');
|
|
@@ -32,6 +33,12 @@ function syncBunLockfileVersions(root) {
|
|
|
32
33
|
let lockfile = (0, node_fs_1.readFileSync)(lockfilePath, 'utf8');
|
|
33
34
|
let updated = 0;
|
|
34
35
|
for (const pkg of packages) {
|
|
36
|
+
// If the package.json version is a prerelease (e.g. 0.2.2-next.0) it may
|
|
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;
|
|
35
42
|
const relativePath = pkg.path.replaceAll('\\', '/');
|
|
36
43
|
const escaped = escapeRegex(relativePath);
|
|
37
44
|
const pattern = new RegExp(`("${escaped}":\\s*\\{[^}]*"version":\\s*")([^"]+)(")`);
|
|
@@ -41,12 +48,12 @@ function syncBunLockfileVersions(root) {
|
|
|
41
48
|
continue;
|
|
42
49
|
}
|
|
43
50
|
const lockVersion = match[2];
|
|
44
|
-
if (lockVersion ===
|
|
45
|
-
console.log(`ok: ${relativePath} = ${
|
|
51
|
+
if (lockVersion === targetVersion) {
|
|
52
|
+
console.log(`ok: ${relativePath} = ${targetVersion}`);
|
|
46
53
|
continue;
|
|
47
54
|
}
|
|
48
|
-
lockfile = lockfile.replace(pattern, `$1${
|
|
49
|
-
console.log(`fix: ${relativePath}: ${lockVersion} -> ${pkg.version}`);
|
|
55
|
+
lockfile = lockfile.replace(pattern, `$1${targetVersion}$3`);
|
|
56
|
+
console.log(`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : ''}`);
|
|
50
57
|
updated++;
|
|
51
58
|
}
|
|
52
59
|
if (updated > 0) {
|
|
@@ -66,13 +73,38 @@ function workspacePackages(root) {
|
|
|
66
73
|
return null;
|
|
67
74
|
}
|
|
68
75
|
const json = JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, 'utf8'));
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
if (typeof json.name !== 'string' || typeof json.version !== 'string')
|
|
77
|
+
return null;
|
|
78
|
+
const nx = json.nx != null && typeof json.nx === 'object' ? json.nx : null;
|
|
79
|
+
const projectName = (nx ? (typeof nx.name === 'string' ? nx.name : null) : null) ?? json.name;
|
|
80
|
+
return { path, name: json.name, projectName, version: json.version };
|
|
72
81
|
})
|
|
73
82
|
.filter((pkg) => pkg !== null);
|
|
74
83
|
}
|
|
75
84
|
function escapeRegex(value) {
|
|
76
85
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
77
86
|
}
|
|
87
|
+
function latestStableTagVersion(root, projectName) {
|
|
88
|
+
try {
|
|
89
|
+
const output = (0, node_child_process_1.execSync)(`git tag --list '${projectName}@*' --sort=-v:refname`, {
|
|
90
|
+
cwd: root,
|
|
91
|
+
encoding: 'utf8',
|
|
92
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
93
|
+
});
|
|
94
|
+
const prefix = `${projectName}@`;
|
|
95
|
+
for (const line of output.split('\n')) {
|
|
96
|
+
const tag = line.trim();
|
|
97
|
+
if (!tag.startsWith(prefix))
|
|
98
|
+
continue;
|
|
99
|
+
const version = tag.slice(prefix.length);
|
|
100
|
+
if (version && !version.includes('-')) {
|
|
101
|
+
return version;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
78
110
|
module.exports = baseVersionActions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"
|
|
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;AA0B5E,SAAS,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoothbricks/nx-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"test": {
|
|
62
62
|
"executor": "@smoothbricks/nx-plugin:bounded-exec",
|
|
63
63
|
"options": {
|
|
64
|
-
"command": "bun test",
|
|
64
|
+
"command": "bun test --timeout=30000",
|
|
65
65
|
"cwd": "{projectRoot}",
|
|
66
66
|
"timeoutMs": 120000,
|
|
67
67
|
"killAfterMs": 1e4
|
|
@@ -8,15 +8,19 @@ import {
|
|
|
8
8
|
applyWorkspaceBoundedTestTargetPolicy,
|
|
9
9
|
BOUNDED_TEST_EXECUTOR,
|
|
10
10
|
BOUNDED_TEST_KILL_AFTER_MS,
|
|
11
|
+
BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
|
|
11
12
|
BOUNDED_TEST_TIMEOUT_MS,
|
|
12
13
|
type BoundedTestPolicyPackageJson,
|
|
13
14
|
type BoundedTestPolicyProjectJson,
|
|
14
15
|
boundedTestScriptAlias,
|
|
15
16
|
checkBoundedTestTargetPolicy,
|
|
16
17
|
checkWorkspaceBoundedTestTargetPolicy,
|
|
18
|
+
ensureBunTestTimeoutFlag,
|
|
17
19
|
resolveTestCommand,
|
|
18
20
|
} from './bounded-test-policy.js';
|
|
19
21
|
|
|
22
|
+
const TIMEOUT_FLAG = `--timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`;
|
|
23
|
+
|
|
20
24
|
describe('bounded test target policy', () => {
|
|
21
25
|
it('preserves an existing nx:run-commands test command', () => {
|
|
22
26
|
const packageJson: BoundedTestPolicyPackageJson = {
|
|
@@ -38,7 +42,7 @@ describe('bounded test target policy', () => {
|
|
|
38
42
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
39
43
|
dependsOn: ['typecheck-tests'],
|
|
40
44
|
options: {
|
|
41
|
-
command:
|
|
45
|
+
command: `bun test ${TIMEOUT_FLAG} --coverage`,
|
|
42
46
|
cwd: '{projectRoot}',
|
|
43
47
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
44
48
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -57,7 +61,7 @@ describe('bounded test target policy', () => {
|
|
|
57
61
|
expect(packageJson.nx?.targets?.test).toEqual({
|
|
58
62
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
59
63
|
options: {
|
|
60
|
-
command:
|
|
64
|
+
command: `bun test ${TIMEOUT_FLAG} --pass-with-no-tests`,
|
|
61
65
|
cwd: '{projectRoot}',
|
|
62
66
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
63
67
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -94,7 +98,7 @@ describe('bounded test target policy', () => {
|
|
|
94
98
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
95
99
|
dependsOn: ['typecheck-tests'],
|
|
96
100
|
options: {
|
|
97
|
-
command:
|
|
101
|
+
command: `bun test ${TIMEOUT_FLAG} --project-target`,
|
|
98
102
|
cwd: '{projectRoot}',
|
|
99
103
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
100
104
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -120,7 +124,7 @@ describe('bounded test target policy', () => {
|
|
|
120
124
|
expect(projectJson.targets?.test).toEqual({
|
|
121
125
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
122
126
|
options: {
|
|
123
|
-
command:
|
|
127
|
+
command: `bun test ${TIMEOUT_FLAG} --script`,
|
|
124
128
|
cwd: '{projectRoot}',
|
|
125
129
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
126
130
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -157,7 +161,20 @@ describe('bounded test target policy', () => {
|
|
|
157
161
|
scripts: { test: boundedTestScriptAlias('example') },
|
|
158
162
|
};
|
|
159
163
|
|
|
160
|
-
expect(resolveTestCommand(packageJson)).toBe(
|
|
164
|
+
expect(resolveTestCommand(packageJson)).toBe(`bun test ${TIMEOUT_FLAG}`);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('idempotently appends --timeout to bare bun test commands', () => {
|
|
168
|
+
expect(ensureBunTestTimeoutFlag('bun test')).toBe(`bun test ${TIMEOUT_FLAG}`);
|
|
169
|
+
expect(ensureBunTestTimeoutFlag('bun test --pass-with-no-tests')).toBe(
|
|
170
|
+
`bun test ${TIMEOUT_FLAG} --pass-with-no-tests`,
|
|
171
|
+
);
|
|
172
|
+
expect(ensureBunTestTimeoutFlag(`bun test ${TIMEOUT_FLAG}`)).toBe(`bun test ${TIMEOUT_FLAG}`);
|
|
173
|
+
expect(ensureBunTestTimeoutFlag('bun test --timeout=10')).toBe(`bun test ${TIMEOUT_FLAG}`);
|
|
174
|
+
expect(ensureBunTestTimeoutFlag('bun test --timeout 10 --bail')).toBe(`bun test ${TIMEOUT_FLAG} --bail`);
|
|
175
|
+
// Non-bun-test commands are left alone (vitest, custom runners, etc.).
|
|
176
|
+
expect(ensureBunTestTimeoutFlag('vitest run')).toBe('vitest run');
|
|
177
|
+
expect(ensureBunTestTimeoutFlag('bun run test')).toBe('bun run test');
|
|
161
178
|
});
|
|
162
179
|
|
|
163
180
|
it('checks and fixes workspace package test targets', async () => {
|
|
@@ -188,7 +205,7 @@ describe('bounded test target policy', () => {
|
|
|
188
205
|
expect(app.nx.targets.test).toEqual({
|
|
189
206
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
190
207
|
options: {
|
|
191
|
-
command:
|
|
208
|
+
command: `bun test ${TIMEOUT_FLAG} --pass-with-no-tests`,
|
|
192
209
|
cwd: '{projectRoot}',
|
|
193
210
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
194
211
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -238,7 +255,7 @@ describe('bounded test target policy', () => {
|
|
|
238
255
|
expect(appProject.targets.test).toEqual({
|
|
239
256
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
240
257
|
options: {
|
|
241
|
-
command:
|
|
258
|
+
command: `bun test ${TIMEOUT_FLAG} --project`,
|
|
242
259
|
cwd: '{projectRoot}',
|
|
243
260
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
244
261
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -4,6 +4,11 @@ import { dirname, join } from 'node:path';
|
|
|
4
4
|
export const BOUNDED_TEST_EXECUTOR = '@smoothbricks/nx-plugin:bounded-exec';
|
|
5
5
|
export const BOUNDED_TEST_TIMEOUT_MS = 120_000;
|
|
6
6
|
export const BOUNDED_TEST_KILL_AFTER_MS = 10_000;
|
|
7
|
+
// Per-test timeout passed to `bun test --timeout=<ms>`. Bun's default is
|
|
8
|
+
// 5000ms which is too tight for git-fixture tests on slower CI runners
|
|
9
|
+
// (Actions). The bunfig.toml `[test] timeout` key is silently ignored by
|
|
10
|
+
// Bun — the only working surfaces are this CLI flag and `setDefaultTimeout()`.
|
|
11
|
+
export const BOUNDED_TEST_PER_TEST_TIMEOUT_MS = 30_000;
|
|
7
12
|
|
|
8
13
|
export interface BoundedTestPolicyPackageJson {
|
|
9
14
|
name?: string;
|
|
@@ -124,6 +129,7 @@ export function checkBoundedTestTargetPolicy(
|
|
|
124
129
|
typeof targetOptions.command !== 'string' ||
|
|
125
130
|
targetOptions.command.length === 0 ||
|
|
126
131
|
isPackageTestScriptRunnerCommand(targetOptions.command) ||
|
|
132
|
+
targetOptions.command !== ensureBunTestTimeoutFlag(targetOptions.command) ||
|
|
127
133
|
targetOptions.cwd !== '{projectRoot}' ||
|
|
128
134
|
targetOptions.timeoutMs !== BOUNDED_TEST_TIMEOUT_MS ||
|
|
129
135
|
targetOptions.killAfterMs !== BOUNDED_TEST_KILL_AFTER_MS
|
|
@@ -141,6 +147,14 @@ export function resolveTestCommand(
|
|
|
141
147
|
packageJson: BoundedTestPolicyPackageJson,
|
|
142
148
|
defaultCommand = 'bun test',
|
|
143
149
|
projectJson?: BoundedTestPolicyProjectJson,
|
|
150
|
+
): string {
|
|
151
|
+
return ensureBunTestTimeoutFlag(resolveRawTestCommand(packageJson, defaultCommand, projectJson));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function resolveRawTestCommand(
|
|
155
|
+
packageJson: BoundedTestPolicyPackageJson,
|
|
156
|
+
defaultCommand: string,
|
|
157
|
+
projectJson: BoundedTestPolicyProjectJson | undefined,
|
|
144
158
|
): string {
|
|
145
159
|
const commandFromProjectTarget = resolveTargetCommand(projectJson?.targets?.test);
|
|
146
160
|
if (commandFromProjectTarget) {
|
|
@@ -175,6 +189,28 @@ function resolveTargetCommand(existingTarget: unknown): string | null {
|
|
|
175
189
|
return null;
|
|
176
190
|
}
|
|
177
191
|
|
|
192
|
+
const BUN_TEST_PREFIX = /^bun\s+test(?=\s|$)/;
|
|
193
|
+
const EXISTING_BUN_TIMEOUT = /(^|\s)--timeout(?:=|\s+)(\S+)/;
|
|
194
|
+
|
|
195
|
+
// Bun's `[test] timeout` bunfig key is silently ignored — only the CLI flag
|
|
196
|
+
// and `setDefaultTimeout()` actually take effect. Normalize every `bun test`
|
|
197
|
+
// command so the policy enforces the workspace per-test timeout in the one
|
|
198
|
+
// place where Bun will honor it.
|
|
199
|
+
export function ensureBunTestTimeoutFlag(command: string, timeoutMs = BOUNDED_TEST_PER_TEST_TIMEOUT_MS): string {
|
|
200
|
+
if (!BUN_TEST_PREFIX.test(command)) {
|
|
201
|
+
return command;
|
|
202
|
+
}
|
|
203
|
+
const flag = `--timeout=${timeoutMs}`;
|
|
204
|
+
const existing = EXISTING_BUN_TIMEOUT.exec(command);
|
|
205
|
+
if (!existing) {
|
|
206
|
+
return command.replace(BUN_TEST_PREFIX, `bun test ${flag}`);
|
|
207
|
+
}
|
|
208
|
+
if (existing[2] === String(timeoutMs)) {
|
|
209
|
+
return command;
|
|
210
|
+
}
|
|
211
|
+
return command.replace(EXISTING_BUN_TIMEOUT, `${existing[1]}${flag}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
178
214
|
function isPackageTestScriptRunnerCommand(command: string): boolean {
|
|
179
215
|
return /^(?:bun\s+run|npm(?:\s+run)?|pnpm(?:\s+run)?|yarn(?:\s+run)?)\s+test(?:\s|$)/.test(command.trim());
|
|
180
216
|
}
|
|
@@ -15,9 +15,11 @@ describe('Bun bootstrap imports', () => {
|
|
|
15
15
|
expect(typeof policy.checkBoundedTestTargetPolicy).toBe('function');
|
|
16
16
|
expect(typeof policy.boundedTestScriptAlias).toBe('function');
|
|
17
17
|
expect(typeof policy.resolveTestCommand).toBe('function');
|
|
18
|
+
expect(typeof policy.ensureBunTestTimeoutFlag).toBe('function');
|
|
18
19
|
expect(typeof policy.BOUNDED_TEST_EXECUTOR).toBe('string');
|
|
19
20
|
expect(typeof policy.BOUNDED_TEST_TIMEOUT_MS).toBe('number');
|
|
20
21
|
expect(typeof policy.BOUNDED_TEST_KILL_AFTER_MS).toBe('number');
|
|
22
|
+
expect(typeof policy.BOUNDED_TEST_PER_TEST_TIMEOUT_MS).toBe('number');
|
|
21
23
|
});
|
|
22
24
|
|
|
23
25
|
it('imports workspace-config-policy', async () => {
|
|
@@ -5,8 +5,12 @@ import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
|
|
|
5
5
|
import {
|
|
6
6
|
BOUNDED_TEST_EXECUTOR,
|
|
7
7
|
BOUNDED_TEST_KILL_AFTER_MS,
|
|
8
|
+
BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
|
|
8
9
|
BOUNDED_TEST_TIMEOUT_MS,
|
|
9
10
|
} from '../../bounded-test-policy.js';
|
|
11
|
+
|
|
12
|
+
const TIMEOUT_FLAG = `--timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`;
|
|
13
|
+
|
|
10
14
|
import generator from './generator.js';
|
|
11
15
|
|
|
12
16
|
describe('bounded-test-targets generator', () => {
|
|
@@ -41,7 +45,7 @@ describe('bounded-test-targets generator', () => {
|
|
|
41
45
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
42
46
|
dependsOn: ['typecheck-tests', '^build'],
|
|
43
47
|
options: {
|
|
44
|
-
command:
|
|
48
|
+
command: `bun test ${TIMEOUT_FLAG} --target`,
|
|
45
49
|
cwd: '{projectRoot}',
|
|
46
50
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
47
51
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -64,7 +68,7 @@ describe('bounded-test-targets generator', () => {
|
|
|
64
68
|
expect(packageJson.nx?.targets?.test).toEqual({
|
|
65
69
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
66
70
|
options: {
|
|
67
|
-
command:
|
|
71
|
+
command: `bun test ${TIMEOUT_FLAG} --script`,
|
|
68
72
|
cwd: '{projectRoot}',
|
|
69
73
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
70
74
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -110,7 +114,7 @@ describe('bounded-test-targets generator', () => {
|
|
|
110
114
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
111
115
|
dependsOn: ['typecheck-tests'],
|
|
112
116
|
options: {
|
|
113
|
-
command:
|
|
117
|
+
command: `bun test ${TIMEOUT_FLAG} --project-target`,
|
|
114
118
|
cwd: '{projectRoot}',
|
|
115
119
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
116
120
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -2,7 +2,11 @@ import { beforeEach, describe, expect, it } from 'bun:test';
|
|
|
2
2
|
import { addProjectConfiguration, readJson, type Tree } from 'nx/src/devkit-exports.js';
|
|
3
3
|
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
BOUNDED_TEST_KILL_AFTER_MS,
|
|
7
|
+
BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
|
|
8
|
+
BOUNDED_TEST_TIMEOUT_MS,
|
|
9
|
+
} from '../../bounded-test-policy.js';
|
|
6
10
|
import generator from './generator.js';
|
|
7
11
|
|
|
8
12
|
function referencePaths(references: Array<{ path: string }> | undefined): string[] {
|
|
@@ -57,7 +61,8 @@ describe('bun-test-tracing generator', () => {
|
|
|
57
61
|
expect(tree.read('packages/example/bunfig.toml', 'utf-8')).toContain(
|
|
58
62
|
'preload = ["@smoothbricks/lmao/bun/preload", "@smoothbricks/lmao/bun/trace-preload"]',
|
|
59
63
|
);
|
|
60
|
-
|
|
64
|
+
// Bun ignores `[test] timeout` in bunfig — per-test timeout lives on the bun CLI flag.
|
|
65
|
+
expect(tree.read('packages/example/bunfig.toml', 'utf-8')).not.toContain('timeout =');
|
|
61
66
|
|
|
62
67
|
const tracerFile = tree.read('packages/example/src/test-suite-tracer.ts', 'utf-8');
|
|
63
68
|
expect(tracerFile).toContain("import { opContext } from '@smoothbricks/lmao';");
|
|
@@ -72,7 +77,7 @@ describe('bun-test-tracing generator', () => {
|
|
|
72
77
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
73
78
|
dependsOn: ['typecheck-tests', '^build'],
|
|
74
79
|
options: {
|
|
75
|
-
command:
|
|
80
|
+
command: `bun test --timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`,
|
|
76
81
|
cwd: '{projectRoot}',
|
|
77
82
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
78
83
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -142,7 +147,7 @@ describe('bun-test-tracing generator', () => {
|
|
|
142
147
|
|
|
143
148
|
const bunfig = tree.read('packages/example/bunfig.toml', 'utf-8') ?? '';
|
|
144
149
|
expect(bunfig).toContain('[test]');
|
|
145
|
-
expect(bunfig).toContain('timeout =
|
|
150
|
+
expect(bunfig).not.toContain('timeout =');
|
|
146
151
|
expect(bunfig).toContain('preload');
|
|
147
152
|
});
|
|
148
153
|
|
|
@@ -193,7 +198,9 @@ describe('bun-test-tracing generator', () => {
|
|
|
193
198
|
});
|
|
194
199
|
|
|
195
200
|
const bunfig = tree.read('packages/example/bunfig.toml', 'utf-8') ?? '';
|
|
196
|
-
|
|
201
|
+
// Stale `[test] timeout` lines are stripped — Bun ignores them and they
|
|
202
|
+
// mislead readers about what's actually enforced.
|
|
203
|
+
expect(bunfig).not.toContain('timeout =');
|
|
197
204
|
expect(bunfig).toContain('@smoothbricks/lmao/bun/preload');
|
|
198
205
|
expect(bunfig).toContain('@smoothbricks/lmao/bun/trace-preload');
|
|
199
206
|
|
|
@@ -47,7 +47,6 @@ const DEFAULT_TEST_INCLUDES = [
|
|
|
47
47
|
];
|
|
48
48
|
|
|
49
49
|
const COPIED_COMPILER_OPTIONS = ['baseUrl', 'module', 'moduleResolution', 'jsx', 'lib'];
|
|
50
|
-
const DEFAULT_BUN_TEST_TIMEOUT_MS = 30_000;
|
|
51
50
|
|
|
52
51
|
export default async function generator(tree: Tree, schema: BunTestTracingGeneratorSchema): Promise<void> {
|
|
53
52
|
const options = normalizeOptions(schema);
|
|
@@ -135,50 +134,42 @@ function writeBunfig(tree: Tree, projectRoot: string): void {
|
|
|
135
134
|
const preloadEntries = '"@smoothbricks/lmao/bun/preload", "@smoothbricks/lmao/bun/trace-preload"';
|
|
136
135
|
|
|
137
136
|
if (!tree.exists(bunfigPath)) {
|
|
138
|
-
tree.write(bunfigPath, `[test]\
|
|
137
|
+
tree.write(bunfigPath, `[test]\npreload = [${preloadEntries}]\n`);
|
|
139
138
|
return;
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
// Bun silently ignores `[test] timeout` in bunfig.toml — only the `--timeout`
|
|
142
|
+
// CLI flag and `setDefaultTimeout()` actually take effect. Strip any stale
|
|
143
|
+
// `timeout = N` lines so the file isn't lying about what's enforced; the real
|
|
144
|
+
// per-test timeout is wired into `bun test --timeout=N` by the bounded-test
|
|
145
|
+
// policy (see BOUNDED_TEST_PER_TEST_TIMEOUT_MS).
|
|
146
|
+
const current = stripBunTestTimeoutLine(tree.read(bunfigPath, 'utf-8') ?? '');
|
|
144
147
|
|
|
145
148
|
// Already has the package specifier preloads
|
|
146
|
-
if (
|
|
147
|
-
if (
|
|
148
|
-
tree.write(bunfigPath,
|
|
149
|
+
if (current.includes('@smoothbricks/lmao/bun/preload')) {
|
|
150
|
+
if (current !== (tree.read(bunfigPath, 'utf-8') ?? '')) {
|
|
151
|
+
tree.write(bunfigPath, current);
|
|
149
152
|
}
|
|
150
153
|
return;
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
// Replace old patterns with the package specifier preloads
|
|
154
|
-
if (
|
|
155
|
-
tree.write(bunfigPath,
|
|
157
|
+
if (current.includes('preload = [')) {
|
|
158
|
+
tree.write(bunfigPath, current.replace(/preload\s*=\s*\[.*?\]/s, `preload = [${preloadEntries}]`));
|
|
156
159
|
return;
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
if (
|
|
160
|
-
tree.write(bunfigPath,
|
|
162
|
+
if (current.includes('[test]')) {
|
|
163
|
+
tree.write(bunfigPath, current.replace('[test]', `[test]\npreload = [${preloadEntries}]`));
|
|
161
164
|
return;
|
|
162
165
|
}
|
|
163
166
|
|
|
164
|
-
const suffix =
|
|
165
|
-
tree.write(
|
|
166
|
-
bunfigPath,
|
|
167
|
-
`${next}${suffix}[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\npreload = [${preloadEntries}]\n`,
|
|
168
|
-
);
|
|
167
|
+
const suffix = current.endsWith('\n') ? '' : '\n';
|
|
168
|
+
tree.write(bunfigPath, `${current}${suffix}[test]\npreload = [${preloadEntries}]\n`);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
return current;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (current.includes('[test]')) {
|
|
177
|
-
return current.replace('[test]', `[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const suffix = current.endsWith('\n') ? '' : '\n';
|
|
181
|
-
return `${current}${suffix}[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\n`;
|
|
171
|
+
function stripBunTestTimeoutLine(current: string): string {
|
|
172
|
+
return current.replace(/^\s*timeout\s*=.*\n?/gm, '');
|
|
182
173
|
}
|
|
183
174
|
|
|
184
175
|
function renderSuiteTracer(options: Required<BunTestTracingGeneratorSchema>): string {
|
|
@@ -35,6 +35,7 @@ function validReleaseNxJson(): Record<string, unknown> {
|
|
|
35
35
|
pattern: SMOO_NX_RELEASE_TAG_PATTERN,
|
|
36
36
|
},
|
|
37
37
|
changelog: {
|
|
38
|
+
automaticFromRef: true,
|
|
38
39
|
workspaceChangelog: false,
|
|
39
40
|
projectChangelogs: {
|
|
40
41
|
createRelease: false,
|
|
@@ -104,6 +105,7 @@ describe('pure core: checkReleaseConfig', () => {
|
|
|
104
105
|
'release.version.preVersionCommand must not be defined; smoo builds npm-missing packages before publish',
|
|
105
106
|
);
|
|
106
107
|
expect(messages).toContainEqual(`release.releaseTag.pattern must be ${SMOO_NX_RELEASE_TAG_PATTERN}`);
|
|
108
|
+
expect(messages).toContainEqual('release.changelog.automaticFromRef must be true');
|
|
107
109
|
expect(messages).toContainEqual('release.changelog.workspaceChangelog must be false');
|
|
108
110
|
expect(messages).toContainEqual('release.changelog.projectChangelogs.createRelease must be false');
|
|
109
111
|
expect(messages).toContainEqual('release.changelog.projectChangelogs.file must be false');
|
|
@@ -131,6 +133,7 @@ describe('pure core: applyReleaseConfig', () => {
|
|
|
131
133
|
const releaseTag = release.releaseTag as Record<string, unknown>;
|
|
132
134
|
expect(releaseTag.pattern).toBe(SMOO_NX_RELEASE_TAG_PATTERN);
|
|
133
135
|
const changelog = release.changelog as Record<string, unknown>;
|
|
136
|
+
expect(changelog.automaticFromRef).toBe(true);
|
|
134
137
|
expect(changelog.workspaceChangelog).toBe(false);
|
|
135
138
|
const projectChangelogs = changelog.projectChangelogs as Record<string, unknown>;
|
|
136
139
|
expect(projectChangelogs.createRelease).toBe(false);
|
|
@@ -65,6 +65,9 @@ export function checkReleaseConfig(nxJson: Record<string, unknown>): NxPolicyIss
|
|
|
65
65
|
if (!changelog) {
|
|
66
66
|
issues.push({ path: 'nx.json', message: 'release.changelog config is missing' });
|
|
67
67
|
}
|
|
68
|
+
if (changelog && changelog.automaticFromRef !== true) {
|
|
69
|
+
issues.push({ path: 'nx.json', message: 'release.changelog.automaticFromRef must be true' });
|
|
70
|
+
}
|
|
68
71
|
if (changelog && changelog.workspaceChangelog !== false) {
|
|
69
72
|
issues.push({ path: 'nx.json', message: 'release.changelog.workspaceChangelog must be false' });
|
|
70
73
|
}
|
|
@@ -122,6 +125,7 @@ export function applyReleaseConfig(nxJson: Record<string, unknown>): boolean {
|
|
|
122
125
|
changed = setStringProperty(releaseTag, 'pattern', SMOO_NX_RELEASE_TAG_PATTERN) || changed;
|
|
123
126
|
|
|
124
127
|
const changelog = getOrCreateRecord(release, 'changelog');
|
|
128
|
+
changed = setBooleanProperty(changelog, 'automaticFromRef', true) || changed;
|
|
125
129
|
changed = setBooleanProperty(changelog, 'workspaceChangelog', false) || changed;
|
|
126
130
|
|
|
127
131
|
const projectChangelogs = getOrCreateRecord(changelog, 'projectChangelogs');
|
package/src/version-actions.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
1
2
|
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import type { AfterAllProjectsVersioned, VersionActions } from 'nx/release';
|
|
@@ -45,6 +46,13 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
45
46
|
let lockfile = readFileSync(lockfilePath, 'utf8');
|
|
46
47
|
let updated = 0;
|
|
47
48
|
for (const pkg of packages) {
|
|
49
|
+
// If the package.json version is a prerelease (e.g. 0.2.2-next.0) it may
|
|
50
|
+
// never have been published. Use the latest stable git tag version so
|
|
51
|
+
// that `bun pm pack` writes an installable dependency range for consumers.
|
|
52
|
+
const targetVersion = pkg.version.includes('-')
|
|
53
|
+
? (latestStableTagVersion(root, pkg.projectName) ?? pkg.version)
|
|
54
|
+
: pkg.version;
|
|
55
|
+
|
|
48
56
|
const relativePath = pkg.path.replaceAll('\\', '/');
|
|
49
57
|
const escaped = escapeRegex(relativePath);
|
|
50
58
|
const pattern = new RegExp(`("${escaped}":\\s*\\{[^}]*"version":\\s*")([^"]+)(")`);
|
|
@@ -54,12 +62,14 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
54
62
|
continue;
|
|
55
63
|
}
|
|
56
64
|
const lockVersion = match[2];
|
|
57
|
-
if (lockVersion ===
|
|
58
|
-
console.log(`ok: ${relativePath} = ${
|
|
65
|
+
if (lockVersion === targetVersion) {
|
|
66
|
+
console.log(`ok: ${relativePath} = ${targetVersion}`);
|
|
59
67
|
continue;
|
|
60
68
|
}
|
|
61
|
-
lockfile = lockfile.replace(pattern, `$1${
|
|
62
|
-
console.log(
|
|
69
|
+
lockfile = lockfile.replace(pattern, `$1${targetVersion}$3`);
|
|
70
|
+
console.log(
|
|
71
|
+
`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : ''}`
|
|
72
|
+
);
|
|
63
73
|
updated++;
|
|
64
74
|
}
|
|
65
75
|
if (updated > 0) {
|
|
@@ -71,7 +81,14 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
71
81
|
return updated;
|
|
72
82
|
}
|
|
73
83
|
|
|
74
|
-
|
|
84
|
+
interface WorkspacePackage {
|
|
85
|
+
path: string;
|
|
86
|
+
name: string;
|
|
87
|
+
projectName: string;
|
|
88
|
+
version: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function workspacePackages(root: string): WorkspacePackage[] {
|
|
75
92
|
const packagesRoot = join(root, 'packages');
|
|
76
93
|
return readdirSync(packagesRoot, { withFileTypes: true })
|
|
77
94
|
.filter((entry) => entry.isDirectory())
|
|
@@ -82,13 +99,36 @@ function workspacePackages(root: string): Array<{ path: string; name: string; ve
|
|
|
82
99
|
return null;
|
|
83
100
|
}
|
|
84
101
|
const json = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as Record<string, unknown>;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
if (typeof json.name !== 'string' || typeof json.version !== 'string') return null;
|
|
103
|
+
const nx = json.nx != null && typeof json.nx === 'object' ? (json.nx as Record<string, unknown>) : null;
|
|
104
|
+
const projectName = (nx ? (typeof nx.name === 'string' ? nx.name : null) : null) ?? json.name;
|
|
105
|
+
return { path, name: json.name, projectName, version: json.version };
|
|
88
106
|
})
|
|
89
|
-
.filter((pkg): pkg is
|
|
107
|
+
.filter((pkg): pkg is WorkspacePackage => pkg !== null);
|
|
90
108
|
}
|
|
91
109
|
|
|
92
110
|
function escapeRegex(value: string): string {
|
|
93
111
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
94
112
|
}
|
|
113
|
+
|
|
114
|
+
function latestStableTagVersion(root: string, projectName: string): string | null {
|
|
115
|
+
try {
|
|
116
|
+
const output = execSync(`git tag --list '${projectName}@*' --sort=-v:refname`, {
|
|
117
|
+
cwd: root,
|
|
118
|
+
encoding: 'utf8',
|
|
119
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
120
|
+
});
|
|
121
|
+
const prefix = `${projectName}@`;
|
|
122
|
+
for (const line of output.split('\n')) {
|
|
123
|
+
const tag = line.trim();
|
|
124
|
+
if (!tag.startsWith(prefix)) continue;
|
|
125
|
+
const version = tag.slice(prefix.length);
|
|
126
|
+
if (version && !version.includes('-')) {
|
|
127
|
+
return version;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
} catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|