@soybeanjs/cli 1.7.0 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 SoybeanJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ interface CliOption {
18
18
  /**
19
19
  * Npm-check-updates command args
20
20
  *
21
- * @default ['--deep', '-u']
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 { join } from "path";
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.0";
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 = ["--deep", "-u"]) {
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: ["--deep", "-u"],
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.0",
3
+ "version": "1.7.2",
4
4
  "description": "SoybeanJS's command line tools",
5
5
  "homepage": "https://github.com/soybeanjs/cli",
6
6
  "bugs": {
@@ -37,35 +37,35 @@
37
37
  "registry": "https://registry.npmjs.org/"
38
38
  },
39
39
  "dependencies": {
40
- "@soybeanjs/changelog": "^0.4.4",
40
+ "@soybeanjs/changelog": "^0.4.5",
41
41
  "bumpp": "^11.0.1",
42
- "c12": "^3.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": "^19.6.5",
48
+ "npm-check-updates": "^22.0.1",
49
49
  "rimraf": "^6.1.3",
50
- "tinyglobby": "^0.2.15"
50
+ "tinyglobby": "^0.2.16"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@soybeanjs/cli": "link:",
54
- "@types/node": "^25.5.0",
54
+ "@types/node": "^25.6.0",
55
55
  "lint-staged": "^16.4.0",
56
- "oxfmt": "^0.41.0",
57
- "oxlint": "^1.56.0",
56
+ "oxfmt": "^0.46.0",
57
+ "oxlint": "^1.61.0",
58
58
  "simple-git-hooks": "^2.13.1",
59
- "tsdown": "^0.21.4",
59
+ "tsdown": "^0.21.10",
60
60
  "tsx": "^4.21.0",
61
- "typescript": "^5.9.3"
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",