@smoothbricks/nx-plugin 0.2.0 → 0.2.2
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 +1 -1
- package/dist/bounded-test-policy.js +1 -1
- package/dist/generators/create-package/generator.js +1 -1
- package/dist/package-target-policy.d.ts +1 -1
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +14 -7
- 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 +6 -6
- package/src/bounded-test-policy.ts +1 -1
- package/src/generators/bounded-test-targets/generator.test.ts +3 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/create-package/generator.test.ts +1 -1
- package/src/generators/create-package/generator.ts +1 -1
- package/src/package-target-policy.test.ts +14 -7
- package/src/package-target-policy.ts +20 -7
- package/src/version-actions.cts +49 -9
package/README.md
CHANGED
|
@@ -91,4 +91,4 @@ The generator rewrites `package.json` so `nx.targets.test` uses:
|
|
|
91
91
|
- `cwd: "{projectRoot}"`
|
|
92
92
|
- `timeoutMs: 600000`
|
|
93
93
|
- `killAfterMs: 10000`
|
|
94
|
-
- package script alias `nx run <project>:test --
|
|
94
|
+
- package script alias `nx run <project>:test --outputStyle=stream`
|
|
@@ -91,7 +91,7 @@ export function checkBoundedTestTargetPolicy(packageJson, options) {
|
|
|
91
91
|
return packageJson.scripts?.test === boundedTestScriptAlias(options.projectName);
|
|
92
92
|
}
|
|
93
93
|
export function boundedTestScriptAlias(projectName) {
|
|
94
|
-
return `nx run ${projectName}:test --
|
|
94
|
+
return `nx run ${projectName}:test --outputStyle=stream`;
|
|
95
95
|
}
|
|
96
96
|
export function resolveTestCommand(packageJson, defaultCommand = 'bun test', projectJson) {
|
|
97
97
|
const commandFromProjectTarget = resolveTargetCommand(projectJson?.targets?.test);
|
|
@@ -84,7 +84,7 @@ function buildPackageJson(schema, packageName, projectRoot, rootPkg) {
|
|
|
84
84
|
},
|
|
85
85
|
files: ['dist', 'src', '!**/*.tsbuildinfo'],
|
|
86
86
|
scripts: {
|
|
87
|
-
test: `nx run ${schema.name}:test --
|
|
87
|
+
test: `nx run ${schema.name}:test --outputStyle=stream`,
|
|
88
88
|
},
|
|
89
89
|
dependencies: {
|
|
90
90
|
tslib: '^2.8.1',
|
|
@@ -10,7 +10,7 @@ export interface PackageTargetPolicyOptions {
|
|
|
10
10
|
}
|
|
11
11
|
export declare const BUILD_OUTPUT_DEPENDENCIES: string[];
|
|
12
12
|
export declare function packageNxProjectName(pkg: Record<string, unknown>): string | null;
|
|
13
|
-
export declare function nxRunAlias(projectName: string, targetName: string, continuous: boolean): string;
|
|
13
|
+
export declare function nxRunAlias(projectName: string, targetName: string, continuous: boolean, command?: string | null): string;
|
|
14
14
|
/**
|
|
15
15
|
* Check package target policy using an Nx Tree.
|
|
16
16
|
* Uses `getProjects()` for project discovery instead of manual filesystem walking.
|
|
@@ -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,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,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;CACpC;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AAED,eAAO,MAAM,yBAAyB,UAWrC,CAAC;AA0HF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA0ID,wBAAgB,UAAU,
|
|
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,8BAA8B,CAAC;AAElE,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;CACpC;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AAED,eAAO,MAAM,yBAAyB,UAWrC,CAAC;AA0HF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA0ID,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;AA8jBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAqBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA4B1G;AAiID,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,CAqBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA4BxG"}
|
|
@@ -211,13 +211,19 @@ function parseNxRunAlias(command) {
|
|
|
211
211
|
}
|
|
212
212
|
return { projectName: match[1], targetName: match[2] };
|
|
213
213
|
}
|
|
214
|
-
export function nxRunAlias(projectName, targetName, continuous) {
|
|
214
|
+
export function nxRunAlias(projectName, targetName, continuous, command) {
|
|
215
215
|
if (targetName === 'test') {
|
|
216
216
|
return boundedTestScriptAlias(projectName);
|
|
217
217
|
}
|
|
218
|
-
const flags = continuous
|
|
218
|
+
const flags = continuous ? ` --outputStyle=${nxRunOutputStyle(command)}` : '';
|
|
219
219
|
return `nx run ${projectName}:${targetName}${flags}`;
|
|
220
220
|
}
|
|
221
|
+
function nxRunOutputStyle(command) {
|
|
222
|
+
if (command && /(?:^|\s)(?:astro|vite)\s+dev(?:\s|$)/.test(command)) {
|
|
223
|
+
return 'dynamic-legacy';
|
|
224
|
+
}
|
|
225
|
+
return 'stream';
|
|
226
|
+
}
|
|
221
227
|
function isContinuousTarget(targetName, command) {
|
|
222
228
|
return (/(?:^|:|-)(?:dev|serve|preview|watch)(?:$|:|-)/.test(targetName) ||
|
|
223
229
|
/(?:^|\s)(?:dev|serve|preview|--watch|-w)(?:\s|$)/.test(command));
|
|
@@ -536,7 +542,11 @@ function validatePackageScriptPolicy(pkg, packagePath, workspaceNames, options =
|
|
|
536
542
|
});
|
|
537
543
|
continue;
|
|
538
544
|
}
|
|
539
|
-
const
|
|
545
|
+
const target = targets ? recordProperty(targets, rewrite.targetName) : null;
|
|
546
|
+
const targetOptions = target ? recordProperty(target, 'options') : null;
|
|
547
|
+
const command = targetOptions ? stringProperty(targetOptions, 'command') : null;
|
|
548
|
+
const rewriteCommand = 'command' in rewrite ? rewrite.command : null;
|
|
549
|
+
const expectedAlias = nxRunAlias(projectName, rewrite.targetName, rewrite.continuous, command ?? rewriteCommand);
|
|
540
550
|
if (rawCommand !== expectedAlias) {
|
|
541
551
|
issues.push({
|
|
542
552
|
path: packagePath,
|
|
@@ -544,7 +554,6 @@ function validatePackageScriptPolicy(pkg, packagePath, workspaceNames, options =
|
|
|
544
554
|
});
|
|
545
555
|
continue;
|
|
546
556
|
}
|
|
547
|
-
const target = targets ? recordProperty(targets, rewrite.targetName) : null;
|
|
548
557
|
if (!target &&
|
|
549
558
|
rewrite.targetName !== scriptName &&
|
|
550
559
|
targetExistsInResolvedProject(rewrite.targetName, options.resolvedTargets)) {
|
|
@@ -556,8 +565,6 @@ function validatePackageScriptPolicy(pkg, packagePath, workspaceNames, options =
|
|
|
556
565
|
if (rewrite.targetName === 'test') {
|
|
557
566
|
continue;
|
|
558
567
|
}
|
|
559
|
-
const targetOptions = target ? recordProperty(target, 'options') : null;
|
|
560
|
-
const command = targetOptions ? stringProperty(targetOptions, 'command') : null;
|
|
561
568
|
if (!target || stringProperty(target, 'executor') !== 'nx:run-commands' || !targetOptions || !command) {
|
|
562
569
|
issues.push({
|
|
563
570
|
path: packagePath,
|
|
@@ -830,7 +837,7 @@ function applyPackageScriptPolicyForPkg(pkg, _packagePath, workspaceNames, optio
|
|
|
830
837
|
continue;
|
|
831
838
|
}
|
|
832
839
|
const targetName = rewrite.targetName;
|
|
833
|
-
const alias = nxRunAlias(projectName, targetName, rewrite.continuous);
|
|
840
|
+
const alias = nxRunAlias(projectName, targetName, rewrite.continuous, rewrite.command);
|
|
834
841
|
if (targetName === 'test') {
|
|
835
842
|
continue;
|
|
836
843
|
}
|
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.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"generators": "./generators.json",
|
|
54
54
|
"executors": "./executors.json",
|
|
55
55
|
"scripts": {
|
|
56
|
-
"test": "nx run nx-plugin:test --
|
|
56
|
+
"test": "nx run nx-plugin:test --outputStyle=stream"
|
|
57
57
|
},
|
|
58
58
|
"nx": {
|
|
59
59
|
"targets": {
|
|
@@ -44,7 +44,7 @@ describe('bounded test target policy', () => {
|
|
|
44
44
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
45
45
|
},
|
|
46
46
|
});
|
|
47
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
47
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it('uses a direct test script when no target command exists', () => {
|
|
@@ -63,7 +63,7 @@ describe('bounded test target policy', () => {
|
|
|
63
63
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
64
64
|
},
|
|
65
65
|
});
|
|
66
|
-
expect(packageJson.scripts?.test).toBe('nx run @scope/example:test --
|
|
66
|
+
expect(packageJson.scripts?.test).toBe('nx run @scope/example:test --outputStyle=stream');
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it('normalizes project.json targets while reading package test scripts', () => {
|
|
@@ -104,7 +104,7 @@ describe('bounded test target policy', () => {
|
|
|
104
104
|
executor: 'nx:run-commands',
|
|
105
105
|
options: { command: 'bun test --package-target' },
|
|
106
106
|
});
|
|
107
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
107
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it('creates project.json test targets from package test scripts', () => {
|
|
@@ -127,7 +127,7 @@ describe('bounded test target policy', () => {
|
|
|
127
127
|
},
|
|
128
128
|
});
|
|
129
129
|
expect(packageJson.nx).toBeUndefined();
|
|
130
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
130
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
it('requires bounded targets in project.json when project config exists', () => {
|
|
@@ -184,7 +184,7 @@ describe('bounded test target policy', () => {
|
|
|
184
184
|
expect(applyWorkspaceBoundedTestTargetPolicy(root)).toBe(true);
|
|
185
185
|
|
|
186
186
|
const app = JSON.parse(await readFile(join(root, 'packages/app/package.json'), 'utf8'));
|
|
187
|
-
expect(app.scripts.test).toBe('nx run app:test --
|
|
187
|
+
expect(app.scripts.test).toBe('nx run app:test --outputStyle=stream');
|
|
188
188
|
expect(app.nx.targets.test).toEqual({
|
|
189
189
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
190
190
|
options: {
|
|
@@ -233,7 +233,7 @@ describe('bounded test target policy', () => {
|
|
|
233
233
|
|
|
234
234
|
const appPackage = JSON.parse(await readFile(join(root, 'packages/app/package.json'), 'utf8'));
|
|
235
235
|
const appProject = JSON.parse(await readFile(join(root, 'packages/app/project.json'), 'utf8'));
|
|
236
|
-
expect(appPackage.scripts.test).toBe('nx run app:test --
|
|
236
|
+
expect(appPackage.scripts.test).toBe('nx run app:test --outputStyle=stream');
|
|
237
237
|
expect(appPackage.nx).toBeUndefined();
|
|
238
238
|
expect(appProject.targets.test).toEqual({
|
|
239
239
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
@@ -134,7 +134,7 @@ export function checkBoundedTestTargetPolicy(
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
export function boundedTestScriptAlias(projectName: string): string {
|
|
137
|
-
return `nx run ${projectName}:test --
|
|
137
|
+
return `nx run ${projectName}:test --outputStyle=stream`;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
export function resolveTestCommand(
|
|
@@ -36,7 +36,7 @@ describe('bounded-test-targets generator', () => {
|
|
|
36
36
|
await generator(tree, { project: '@scope/example' });
|
|
37
37
|
|
|
38
38
|
const packageJson = readJson(tree, 'packages/example/package.json');
|
|
39
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
39
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
40
40
|
expect(packageJson.nx?.targets?.test).toEqual({
|
|
41
41
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
42
42
|
dependsOn: ['typecheck-tests', '^build'],
|
|
@@ -60,7 +60,7 @@ describe('bounded-test-targets generator', () => {
|
|
|
60
60
|
await generator(tree, { project: 'packages/example' });
|
|
61
61
|
|
|
62
62
|
const packageJson = readJson(tree, 'packages/example/package.json');
|
|
63
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
63
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
64
64
|
expect(packageJson.nx?.targets?.test).toEqual({
|
|
65
65
|
executor: BOUNDED_TEST_EXECUTOR,
|
|
66
66
|
options: {
|
|
@@ -101,7 +101,7 @@ describe('bounded-test-targets generator', () => {
|
|
|
101
101
|
|
|
102
102
|
const packageJson = readJson(tree, 'packages/example/package.json');
|
|
103
103
|
const projectJson = readJson(tree, 'packages/example/project.json');
|
|
104
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
104
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
105
105
|
expect(packageJson.nx?.targets?.test).toEqual({
|
|
106
106
|
executor: 'nx:run-commands',
|
|
107
107
|
options: { command: 'bun test --package-target' },
|
|
@@ -67,7 +67,7 @@ describe('bun-test-tracing generator', () => {
|
|
|
67
67
|
);
|
|
68
68
|
|
|
69
69
|
const packageJson = readJson(tree, 'packages/example/package.json');
|
|
70
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
70
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
71
71
|
expect(packageJson.nx?.targets?.test).toEqual({
|
|
72
72
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
73
73
|
dependsOn: ['typecheck-tests', '^build'],
|
|
@@ -198,7 +198,7 @@ describe('bun-test-tracing generator', () => {
|
|
|
198
198
|
expect(bunfig).toContain('@smoothbricks/lmao/bun/trace-preload');
|
|
199
199
|
|
|
200
200
|
const packageJson = readJson(tree, 'packages/example/package.json');
|
|
201
|
-
expect(packageJson.scripts?.test).toBe('nx run example:test --
|
|
201
|
+
expect(packageJson.scripts?.test).toBe('nx run example:test --outputStyle=stream');
|
|
202
202
|
|
|
203
203
|
const tsconfigTest = readJson(tree, 'packages/example/tsconfig.test.json') as {
|
|
204
204
|
extends?: string;
|
|
@@ -50,7 +50,7 @@ describe('create-package generator', () => {
|
|
|
50
50
|
});
|
|
51
51
|
expect(pkg.dependencies).toEqual({ tslib: '^2.8.1' });
|
|
52
52
|
expect(pkg.devDependencies).toEqual({ '@smoothbricks/validation': 'workspace:*' });
|
|
53
|
-
expect(pkg.scripts?.test).toBe('nx run duration:test --
|
|
53
|
+
expect(pkg.scripts?.test).toBe('nx run duration:test --outputStyle=stream');
|
|
54
54
|
expect(pkg.nx?.name).toBe('duration');
|
|
55
55
|
expect(pkg.nx?.targets?.lint).toEqual({});
|
|
56
56
|
expect(pkg.nx?.targets?.test?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
@@ -111,7 +111,7 @@ function buildPackageJson(
|
|
|
111
111
|
},
|
|
112
112
|
files: ['dist', 'src', '!**/*.tsbuildinfo'],
|
|
113
113
|
scripts: {
|
|
114
|
-
test: `nx run ${schema.name}:test --
|
|
114
|
+
test: `nx run ${schema.name}:test --outputStyle=stream`,
|
|
115
115
|
},
|
|
116
116
|
dependencies: {
|
|
117
117
|
tslib: '^2.8.1',
|
|
@@ -209,8 +209,8 @@ describe('package target policy', () => {
|
|
|
209
209
|
expect(applyPackageTargetPolicy(root)).toBe(true);
|
|
210
210
|
|
|
211
211
|
const web = JSON.parse(await readFile(join(root, 'packages/web/package.json'), 'utf8'));
|
|
212
|
-
// dev
|
|
213
|
-
expect(web.scripts.dev).toBe('nx run web:dev --
|
|
212
|
+
// Vite/Astro dev servers render best with dynamic legacy output.
|
|
213
|
+
expect(web.scripts.dev).toBe('nx run web:dev --outputStyle=dynamic-legacy');
|
|
214
214
|
// build script should become an Nx alias without streaming flags
|
|
215
215
|
expect(web.scripts.build).toBe('nx run web:build');
|
|
216
216
|
// nx.targets.dev should be created with continuous flag
|
|
@@ -237,7 +237,7 @@ describe('package target policy', () => {
|
|
|
237
237
|
name: '@scope/app',
|
|
238
238
|
dependencies: { '@scope/lib': 'workspace:*' },
|
|
239
239
|
scripts: {
|
|
240
|
-
dev: 'nx run app:dev --
|
|
240
|
+
dev: 'nx run app:dev --outputStyle=stream',
|
|
241
241
|
},
|
|
242
242
|
nx: {
|
|
243
243
|
name: 'app',
|
|
@@ -415,7 +415,14 @@ describe('per-package applyPackageTargets', () => {
|
|
|
415
415
|
|
|
416
416
|
describe('nxRunAlias', () => {
|
|
417
417
|
it('generates streaming flags for continuous targets', () => {
|
|
418
|
-
expect(nxRunAlias('app', 'dev', true)).toBe('nx run app:dev --
|
|
418
|
+
expect(nxRunAlias('app', 'dev', true)).toBe('nx run app:dev --outputStyle=stream');
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it('uses dynamic legacy output for Astro and Vite dev targets', () => {
|
|
422
|
+
expect(nxRunAlias('app', 'dev', true, 'astro dev')).toBe('nx run app:dev --outputStyle=dynamic-legacy');
|
|
423
|
+
expect(nxRunAlias('app', 'serve', true, 'vite dev --host 0.0.0.0')).toBe(
|
|
424
|
+
'nx run app:serve --outputStyle=dynamic-legacy',
|
|
425
|
+
);
|
|
419
426
|
});
|
|
420
427
|
|
|
421
428
|
it('generates plain alias for non-continuous targets', () => {
|
|
@@ -423,7 +430,7 @@ describe('nxRunAlias', () => {
|
|
|
423
430
|
});
|
|
424
431
|
|
|
425
432
|
it('delegates test targets to boundedTestScriptAlias', () => {
|
|
426
|
-
expect(nxRunAlias('app', 'test', false)).toBe('nx run app:test --
|
|
433
|
+
expect(nxRunAlias('app', 'test', false)).toBe('nx run app:test --outputStyle=stream');
|
|
427
434
|
});
|
|
428
435
|
});
|
|
429
436
|
|
|
@@ -569,7 +576,7 @@ describe('checkPackageTargetPolicyTree', () => {
|
|
|
569
576
|
name: '@scope/app',
|
|
570
577
|
dependencies: { '@scope/lib': 'workspace:*' },
|
|
571
578
|
scripts: {
|
|
572
|
-
dev: 'nx run app:dev --
|
|
579
|
+
dev: 'nx run app:dev --outputStyle=stream',
|
|
573
580
|
},
|
|
574
581
|
nx: {
|
|
575
582
|
name: 'app',
|
|
@@ -723,7 +730,7 @@ describe('applyPackageTargetPolicyTree', () => {
|
|
|
723
730
|
expect(applyPackageTargetPolicyTree(tree)).toBe(true);
|
|
724
731
|
|
|
725
732
|
const web = readJson(tree, 'packages/web/package.json');
|
|
726
|
-
expect(web.scripts.dev).toBe('nx run web:dev --
|
|
733
|
+
expect(web.scripts.dev).toBe('nx run web:dev --outputStyle=dynamic-legacy');
|
|
727
734
|
expect(web.scripts.build).toBe('nx run web:build');
|
|
728
735
|
expect(web.nx.targets.dev.continuous).toBe(true);
|
|
729
736
|
expect(web.nx.targets.dev.executor).toBe('nx:run-commands');
|
|
@@ -291,14 +291,26 @@ function parseNxRunAlias(command: string): { projectName: string; targetName: st
|
|
|
291
291
|
return { projectName: match[1], targetName: match[2] };
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
export function nxRunAlias(
|
|
294
|
+
export function nxRunAlias(
|
|
295
|
+
projectName: string,
|
|
296
|
+
targetName: string,
|
|
297
|
+
continuous: boolean,
|
|
298
|
+
command?: string | null,
|
|
299
|
+
): string {
|
|
295
300
|
if (targetName === 'test') {
|
|
296
301
|
return boundedTestScriptAlias(projectName);
|
|
297
302
|
}
|
|
298
|
-
const flags = continuous
|
|
303
|
+
const flags = continuous ? ` --outputStyle=${nxRunOutputStyle(command)}` : '';
|
|
299
304
|
return `nx run ${projectName}:${targetName}${flags}`;
|
|
300
305
|
}
|
|
301
306
|
|
|
307
|
+
function nxRunOutputStyle(command?: string | null): 'stream' | 'dynamic-legacy' {
|
|
308
|
+
if (command && /(?:^|\s)(?:astro|vite)\s+dev(?:\s|$)/.test(command)) {
|
|
309
|
+
return 'dynamic-legacy';
|
|
310
|
+
}
|
|
311
|
+
return 'stream';
|
|
312
|
+
}
|
|
313
|
+
|
|
302
314
|
function isContinuousTarget(targetName: string, command: string): boolean {
|
|
303
315
|
return (
|
|
304
316
|
/(?:^|:|-)(?:dev|serve|preview|watch)(?:$|:|-)/.test(targetName) ||
|
|
@@ -677,7 +689,11 @@ function validatePackageScriptPolicy(
|
|
|
677
689
|
});
|
|
678
690
|
continue;
|
|
679
691
|
}
|
|
680
|
-
const
|
|
692
|
+
const target = targets ? recordProperty(targets, rewrite.targetName) : null;
|
|
693
|
+
const targetOptions = target ? recordProperty(target, 'options') : null;
|
|
694
|
+
const command = targetOptions ? stringProperty(targetOptions, 'command') : null;
|
|
695
|
+
const rewriteCommand = 'command' in rewrite ? rewrite.command : null;
|
|
696
|
+
const expectedAlias = nxRunAlias(projectName, rewrite.targetName, rewrite.continuous, command ?? rewriteCommand);
|
|
681
697
|
if (rawCommand !== expectedAlias) {
|
|
682
698
|
issues.push({
|
|
683
699
|
path: packagePath,
|
|
@@ -685,7 +701,6 @@ function validatePackageScriptPolicy(
|
|
|
685
701
|
});
|
|
686
702
|
continue;
|
|
687
703
|
}
|
|
688
|
-
const target = targets ? recordProperty(targets, rewrite.targetName) : null;
|
|
689
704
|
if (
|
|
690
705
|
!target &&
|
|
691
706
|
rewrite.targetName !== scriptName &&
|
|
@@ -699,8 +714,6 @@ function validatePackageScriptPolicy(
|
|
|
699
714
|
if (rewrite.targetName === 'test') {
|
|
700
715
|
continue;
|
|
701
716
|
}
|
|
702
|
-
const targetOptions = target ? recordProperty(target, 'options') : null;
|
|
703
|
-
const command = targetOptions ? stringProperty(targetOptions, 'command') : null;
|
|
704
717
|
if (!target || stringProperty(target, 'executor') !== 'nx:run-commands' || !targetOptions || !command) {
|
|
705
718
|
issues.push({
|
|
706
719
|
path: packagePath,
|
|
@@ -1005,7 +1018,7 @@ function applyPackageScriptPolicyForPkg(
|
|
|
1005
1018
|
continue;
|
|
1006
1019
|
}
|
|
1007
1020
|
const targetName = rewrite.targetName;
|
|
1008
|
-
const alias = nxRunAlias(projectName, targetName, rewrite.continuous);
|
|
1021
|
+
const alias = nxRunAlias(projectName, targetName, rewrite.continuous, rewrite.command);
|
|
1009
1022
|
if (targetName === 'test') {
|
|
1010
1023
|
continue;
|
|
1011
1024
|
}
|
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
|
+
}
|