@soybeanjs/cli 1.7.1 → 1.7.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/index.d.ts +1 -1
- package/dist/index.js +69 -8
- package/package.json +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface CliOption {
|
|
|
18
18
|
/**
|
|
19
19
|
* Npm-check-updates command args
|
|
20
20
|
*
|
|
21
|
-
|
|
21
|
+
* If not set, soybean-cli will resolve workspace package.json files automatically and fall back to package.json in single-package repos.
|
|
22
22
|
*/
|
|
23
23
|
ncuCommandArgs: string[];
|
|
24
24
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cac } from "cac";
|
|
3
|
-
import path from "node:path";
|
|
3
|
+
import path, { join, posix } from "node:path";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import enquirer from "enquirer";
|
|
6
6
|
import { bgRed, green, red, yellow } from "kolorist";
|
|
7
7
|
import { rimraf } from "rimraf";
|
|
8
|
-
import {
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import process$1 from "node:process";
|
|
10
|
+
import { glob } from "tinyglobby";
|
|
11
|
+
import { join as join$1 } from "path";
|
|
9
12
|
import { existsSync } from "fs";
|
|
10
13
|
import { generateChangelog, generateTotalChangelog } from "@soybeanjs/changelog";
|
|
11
14
|
import { versionBump } from "bumpp";
|
|
12
|
-
import process$1 from "node:process";
|
|
13
15
|
import { loadConfig } from "c12";
|
|
14
16
|
|
|
15
17
|
//#region package.json
|
|
16
|
-
var version = "1.7.
|
|
18
|
+
var version = "1.7.2";
|
|
17
19
|
|
|
18
20
|
//#endregion
|
|
19
21
|
//#region src/shared/index.ts
|
|
@@ -160,14 +162,73 @@ async function cleanup(paths) {
|
|
|
160
162
|
|
|
161
163
|
//#endregion
|
|
162
164
|
//#region src/command/ncu.ts
|
|
163
|
-
async function ncu(args = [
|
|
164
|
-
await execCommand("pnpm", ["npm-check-updates", ...args], { stdio: "inherit" });
|
|
165
|
+
async function ncu(args = []) {
|
|
166
|
+
await execCommand("pnpm", ["npm-check-updates", ...args.length ? args : await resolveDefaultNcuArgs()], { stdio: "inherit" });
|
|
167
|
+
}
|
|
168
|
+
function parsePnpmWorkspacePackages(content) {
|
|
169
|
+
const lines = content.split(/\r?\n/u);
|
|
170
|
+
const packages = [];
|
|
171
|
+
let inPackages = false;
|
|
172
|
+
for (const line of lines) {
|
|
173
|
+
const trimmedLine = line.trim();
|
|
174
|
+
if (!inPackages) {
|
|
175
|
+
if (trimmedLine === "packages:") inPackages = true;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (!trimmedLine || trimmedLine.startsWith("#")) continue;
|
|
179
|
+
if (/^\S/u.test(line)) break;
|
|
180
|
+
const match = line.match(/^\s*-\s*['"]?(.+?)['"]?\s*$/u);
|
|
181
|
+
if (match?.[1]) packages.push(match[1]);
|
|
182
|
+
}
|
|
183
|
+
return packages;
|
|
184
|
+
}
|
|
185
|
+
function resolveWorkspacePatterns(packageJson, pnpmWorkspaceContent) {
|
|
186
|
+
const workspaces = Array.isArray(packageJson?.workspaces) ? packageJson.workspaces : packageJson?.workspaces?.packages ?? [];
|
|
187
|
+
const pnpmWorkspacePackages = pnpmWorkspaceContent ? parsePnpmWorkspacePackages(pnpmWorkspaceContent) : [];
|
|
188
|
+
return [...new Set([...workspaces, ...pnpmWorkspacePackages])];
|
|
189
|
+
}
|
|
190
|
+
function toPackageFilePattern(pattern) {
|
|
191
|
+
const normalizedPattern = pattern.trim();
|
|
192
|
+
if (!normalizedPattern) return "";
|
|
193
|
+
const isNegated = normalizedPattern.startsWith("!");
|
|
194
|
+
const cleanPattern = (isNegated ? normalizedPattern.slice(1) : normalizedPattern).replace(/\/$/u, "");
|
|
195
|
+
const packageFilePattern = cleanPattern.endsWith("package.json") ? cleanPattern : posix.join(cleanPattern, "package.json");
|
|
196
|
+
return isNegated ? `!${packageFilePattern}` : packageFilePattern;
|
|
197
|
+
}
|
|
198
|
+
async function resolveDefaultNcuArgs(cwd = process$1.cwd()) {
|
|
199
|
+
const [packageJsonContent, pnpmWorkspaceContent] = await Promise.all([readFile(join(cwd, "package.json"), "utf8").catch(() => null), readFile(join(cwd, "pnpm-workspace.yaml"), "utf8").catch(() => null)]);
|
|
200
|
+
const workspacePatterns = resolveWorkspacePatterns(packageJsonContent ? JSON.parse(packageJsonContent) : null, pnpmWorkspaceContent).map(toPackageFilePattern).filter(Boolean);
|
|
201
|
+
if (!workspacePatterns.length) return [
|
|
202
|
+
"-u",
|
|
203
|
+
"--packageFile",
|
|
204
|
+
"package.json"
|
|
205
|
+
];
|
|
206
|
+
const packageFiles = await glob(["package.json", ...workspacePatterns], {
|
|
207
|
+
cwd,
|
|
208
|
+
followSymbolicLinks: false,
|
|
209
|
+
onlyFiles: true
|
|
210
|
+
});
|
|
211
|
+
const uniquePackageFiles = [...new Set(packageFiles)].sort((left, right) => {
|
|
212
|
+
if (left === "package.json") return -1;
|
|
213
|
+
if (right === "package.json") return 1;
|
|
214
|
+
return left.localeCompare(right);
|
|
215
|
+
});
|
|
216
|
+
if (!uniquePackageFiles.length) return [
|
|
217
|
+
"-u",
|
|
218
|
+
"--packageFile",
|
|
219
|
+
"package.json"
|
|
220
|
+
];
|
|
221
|
+
return [
|
|
222
|
+
"-u",
|
|
223
|
+
"--packageFile",
|
|
224
|
+
`{${uniquePackageFiles.join(",")}}`
|
|
225
|
+
];
|
|
165
226
|
}
|
|
166
227
|
|
|
167
228
|
//#endregion
|
|
168
229
|
//#region src/command/changelog.ts
|
|
169
230
|
async function genChangelog(options, total = false) {
|
|
170
|
-
const hasChangelog = existsSync(join(process.cwd(), "CHANGELOG.md"));
|
|
231
|
+
const hasChangelog = existsSync(join$1(process.cwd(), "CHANGELOG.md"));
|
|
171
232
|
if (total) await generateTotalChangelog(options);
|
|
172
233
|
else await generateChangelog(options);
|
|
173
234
|
if (!hasChangelog) await execCommand("git", ["add", "CHANGELOG.md"]);
|
|
@@ -198,7 +259,7 @@ const defaultOptions = {
|
|
|
198
259
|
"**/node_modules",
|
|
199
260
|
"!node_modules/**"
|
|
200
261
|
],
|
|
201
|
-
ncuCommandArgs: [
|
|
262
|
+
ncuCommandArgs: [],
|
|
202
263
|
changelogOptions: {},
|
|
203
264
|
gitCommitVerifyIgnores: [
|
|
204
265
|
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soybeanjs/cli",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "SoybeanJS's command line tools",
|
|
5
5
|
"homepage": "https://github.com/soybeanjs/cli",
|
|
6
6
|
"bugs": {
|
|
@@ -39,33 +39,33 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@soybeanjs/changelog": "^0.4.5",
|
|
41
41
|
"bumpp": "^11.0.1",
|
|
42
|
-
"c12": "^3.3.
|
|
42
|
+
"c12": "^3.3.4",
|
|
43
43
|
"cac": "^7.0.0",
|
|
44
44
|
"consola": "^3.4.2",
|
|
45
45
|
"enquirer": "^2.4.1",
|
|
46
46
|
"execa": "^9.6.1",
|
|
47
47
|
"kolorist": "^1.8.0",
|
|
48
|
-
"npm-check-updates": "^
|
|
48
|
+
"npm-check-updates": "^22.0.1",
|
|
49
49
|
"rimraf": "^6.1.3",
|
|
50
|
-
"tinyglobby": "^0.2.
|
|
50
|
+
"tinyglobby": "^0.2.16"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@soybeanjs/cli": "link:",
|
|
54
|
-
"@types/node": "^25.
|
|
54
|
+
"@types/node": "^25.6.0",
|
|
55
55
|
"lint-staged": "^16.4.0",
|
|
56
|
-
"oxfmt": "^0.
|
|
57
|
-
"oxlint": "^1.
|
|
56
|
+
"oxfmt": "^0.46.0",
|
|
57
|
+
"oxlint": "^1.61.0",
|
|
58
58
|
"simple-git-hooks": "^2.13.1",
|
|
59
|
-
"tsdown": "^0.21.
|
|
59
|
+
"tsdown": "^0.21.10",
|
|
60
60
|
"tsx": "^4.21.0",
|
|
61
|
-
"typescript": "^
|
|
61
|
+
"typescript": "^6.0.3"
|
|
62
62
|
},
|
|
63
63
|
"simple-git-hooks": {
|
|
64
64
|
"commit-msg": "pnpm soy git-commit-verify",
|
|
65
65
|
"pre-commit": "pnpm typecheck && pnpm lint-staged"
|
|
66
66
|
},
|
|
67
67
|
"lint-staged": {
|
|
68
|
-
"*": "oxlint --fix && oxfmt"
|
|
68
|
+
"*": "oxlint . --fix && oxfmt"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "tsdown",
|