@smoothbricks/nx-plugin 0.2.1 → 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/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
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
|
+
}
|