@ruan-cat/utils 4.22.0 → 4.24.0

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.
@@ -1,7 +1,7 @@
1
1
  // src/node-esm/ruan-cat-pkg-info.ts
2
2
  import { spawnSync } from "child_process";
3
3
  async function getRuanCatPkgInfo() {
4
- return new Promise((resolve2, reject) => {
4
+ return new Promise((resolve3, reject) => {
5
5
  const result = spawnSync("pnpm", ["s", "@ruan-cat/*", "--registry", "https://registry.npmmirror.com/", "--json"], {
6
6
  encoding: "utf-8"
7
7
  });
@@ -23,7 +23,7 @@ async function getRuanCatPkgInfo() {
23
23
  url: `https://npm.im/${pkg.name}`
24
24
  })
25
25
  );
26
- resolve2(res);
26
+ resolve3(res);
27
27
  });
28
28
  }
29
29
 
@@ -33,8 +33,8 @@ import { spawnSync as spawnSync2 } from "child_process";
33
33
  // src/simple-promise-tools.ts
34
34
  function generateSimpleAsyncTask(func) {
35
35
  return function(...args) {
36
- return new Promise((resolve2, reject) => {
37
- resolve2(func(...args));
36
+ return new Promise((resolve3, reject) => {
37
+ resolve3(func(...args));
38
38
  });
39
39
  };
40
40
  }
@@ -2956,43 +2956,293 @@ if (isRunningAsCli()) {
2956
2956
  }
2957
2957
  }
2958
2958
 
2959
+ // src/node-esm/scripts/relizy-runner/index.ts
2960
+ import { execFileSync, spawnSync as spawnSync3 } from "child_process";
2961
+ import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "fs";
2962
+ import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
2963
+ import process2 from "process";
2964
+ import { fileURLToPath as fileURLToPath2 } from "url";
2965
+ import consola4 from "consola";
2966
+ import { parsePnpmWorkspaceYaml } from "pnpm-workspace-yaml";
2967
+ var WINDOWS_GNU_COMMANDS = ["grep", "head", "sed"];
2968
+ function getWorkspacePackages(workspaceRoot) {
2969
+ const root = workspaceRoot ?? process2.cwd();
2970
+ const yamlPath = resolve2(root, "pnpm-workspace.yaml");
2971
+ if (!existsSync3(yamlPath)) {
2972
+ consola4.error("release:relizy\uFF1A\u672A\u5728\u5F53\u524D\u76EE\u5F55\u627E\u5230 pnpm-workspace.yaml\uFF0C\u8BF7\u4ECE\u4ED3\u5E93\u6839\u76EE\u5F55\u6267\u884C\u3002");
2973
+ return [];
2974
+ }
2975
+ const globs = parsePnpmWorkspaceYaml(readFileSync2(yamlPath, "utf8")).toJSON().packages ?? [];
2976
+ const packages = [];
2977
+ for (const pattern of globs) {
2978
+ const parts = pattern.split("/");
2979
+ if (parts.length !== 2 || parts[1] !== "*") {
2980
+ continue;
2981
+ }
2982
+ const dir = resolve2(root, parts[0]);
2983
+ if (!existsSync3(dir)) {
2984
+ continue;
2985
+ }
2986
+ const discovered = readdirSync2(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join2(dir, entry.name, "package.json")).filter((pkgPath) => existsSync3(pkgPath)).map((pkgPath) => {
2987
+ const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
2988
+ return { name: pkg.name, version: pkg.version };
2989
+ }).filter((pkg) => typeof pkg.name === "string" && typeof pkg.version === "string");
2990
+ packages.push(...discovered);
2991
+ }
2992
+ return packages;
2993
+ }
2994
+ function runLookup(command, args, env = process2.env) {
2995
+ return spawnSync3(command, args, {
2996
+ cwd: process2.cwd(),
2997
+ env,
2998
+ encoding: "utf8",
2999
+ stdio: "pipe"
3000
+ });
3001
+ }
3002
+ function hasExecutable(command, env = process2.env) {
3003
+ const lookupCommand = process2.platform === "win32" ? "where" : "which";
3004
+ return runLookup(lookupCommand, [command], env).status === 0;
3005
+ }
3006
+ function listExecutableMatches(command) {
3007
+ const lookupCommand = process2.platform === "win32" ? "where" : "which";
3008
+ const result = runLookup(lookupCommand, [command]);
3009
+ if (result.status !== 0) {
3010
+ return [];
3011
+ }
3012
+ return result.stdout.split(/\r?\n/u).map((line) => line.trim()).filter(Boolean);
3013
+ }
3014
+ function resolveGitUsrBinPath() {
3015
+ if (process2.platform !== "win32") {
3016
+ return null;
3017
+ }
3018
+ const candidates = /* @__PURE__ */ new Set();
3019
+ for (const executablePath of [...listExecutableMatches("bash"), ...listExecutableMatches("git")]) {
3020
+ const executableDir = dirname2(executablePath);
3021
+ candidates.add(resolve2(executableDir, "..", "usr", "bin"));
3022
+ candidates.add(resolve2(executableDir, "usr", "bin"));
3023
+ }
3024
+ for (const candidate of candidates) {
3025
+ const hasAllCommands = WINDOWS_GNU_COMMANDS.every((command) => existsSync3(join2(candidate, `${command}.exe`)));
3026
+ if (hasAllCommands) {
3027
+ return candidate;
3028
+ }
3029
+ }
3030
+ return null;
3031
+ }
3032
+ function ensureRelizyShellEnv() {
3033
+ if (process2.platform !== "win32") {
3034
+ return { ...process2.env };
3035
+ }
3036
+ if (WINDOWS_GNU_COMMANDS.every((command) => hasExecutable(command))) {
3037
+ return { ...process2.env };
3038
+ }
3039
+ const gitUsrBinPath = resolveGitUsrBinPath();
3040
+ if (!gitUsrBinPath) {
3041
+ consola4.error("[release:relizy] \u5728 Windows \u4E0A\u672A\u627E\u5230 relizy \u6240\u9700\u7684 GNU \u5DE5\u5177\uFF08grep / head / sed\uFF09\u3002");
3042
+ consola4.error("\u8BF7\u5148\u5B89\u88C5 Git for Windows\uFF0C\u6216\u5C06\u5176\u5B89\u88C5\u76EE\u5F55\u4E0B\u7684 usr\\bin \u52A0\u5165 PATH\u3002");
3043
+ process2.exit(1);
3044
+ }
3045
+ const env = {
3046
+ ...process2.env,
3047
+ PATH: `${gitUsrBinPath};${process2.env.PATH ?? ""}`
3048
+ };
3049
+ if (!WINDOWS_GNU_COMMANDS.every((command) => hasExecutable(command, env))) {
3050
+ consola4.error("[release:relizy] \u5DF2\u5B9A\u4F4D\u5230 Git for Windows\uFF0C\u4F46 grep / head / sed \u4ECD\u4E0D\u53EF\u7528\u3002");
3051
+ consola4.error(`\u8BF7\u68C0\u67E5 PATH\uFF0C\u6216\u624B\u52A8\u786E\u8BA4\u8BE5\u76EE\u5F55\u662F\u5426\u5B58\u5728\u6240\u9700\u53EF\u6267\u884C\u6587\u4EF6\uFF1A${gitUsrBinPath}`);
3052
+ process2.exit(1);
3053
+ }
3054
+ consola4.info(`[release:relizy] Windows \u4E0B\u5DF2\u8865\u9F50 GNU \u5DE5\u5177\u8DEF\u5F84\uFF1A${gitUsrBinPath}`);
3055
+ return env;
3056
+ }
3057
+ function getPackageTags(packageName, env) {
3058
+ const stdout = execFileSync("git", ["tag", "--list", `${packageName}@*`], {
3059
+ cwd: process2.cwd(),
3060
+ env,
3061
+ encoding: "utf8"
3062
+ });
3063
+ return stdout.split(/\r?\n/u).map((line) => line.trim()).filter(Boolean);
3064
+ }
3065
+ function shouldCheckIndependentBootstrap(relizyArgs) {
3066
+ const [command] = relizyArgs;
3067
+ return command === "release" || command === "bump";
3068
+ }
3069
+ var RELIZY_SUBCOMMANDS_WITH_YES_PRESET = /* @__PURE__ */ new Set(["release", "bump"]);
3070
+ function prepareRelizySpawnArgs(relizyArgs) {
3071
+ const optOutYes = relizyArgs.includes("--no-yes");
3072
+ const forward = relizyArgs.filter((arg) => arg !== "--no-yes");
3073
+ const [command] = forward;
3074
+ const shouldInjectYes = !optOutYes && command !== void 0 && RELIZY_SUBCOMMANDS_WITH_YES_PRESET.has(command) && !forward.includes("--yes");
3075
+ return shouldInjectYes ? [...forward, "--yes"] : forward;
3076
+ }
3077
+ function getPackagesMissingBootstrapTags(env) {
3078
+ return getWorkspacePackages().filter((pkg) => getPackageTags(pkg.name, env).length === 0);
3079
+ }
3080
+ function buildBootstrapInstructions(missingPackages) {
3081
+ const tagCommands = missingPackages.map((pkg) => `git tag "${pkg.name}@${pkg.version}"`);
3082
+ const pushArgs = missingPackages.map((pkg) => `"${pkg.name}@${pkg.version}"`).join(" ");
3083
+ return [
3084
+ "[release:relizy] \u68C0\u6D4B\u5230\u672C\u4ED3\u5E93\u5C1A\u672A\u4E3A\u4EE5\u4E0B\u5305\u5EFA\u7ACB\u57FA\u7EBF tag\uFF08independent \u6A21\u5F0F\u9996\u6B21\u53D1\u7248\u524D\u9700\u8981\uFF09\uFF1A",
3085
+ ...missingPackages.map((pkg) => `- ${pkg.name}@${pkg.version}`),
3086
+ "",
3087
+ "\u8BF7\u6309\u5F53\u524D package.json \u7248\u672C\u521B\u5EFA\u57FA\u7EBF tag\uFF0C\u5E76\u63A8\u9001\u5230\u8FDC\u7AEF\uFF1A",
3088
+ ...tagCommands,
3089
+ `git push origin ${pushArgs}`
3090
+ ].join("\n");
3091
+ }
3092
+ function printBootstrapInstructions(missingPackages) {
3093
+ consola4.error(buildBootstrapInstructions(missingPackages));
3094
+ }
3095
+ function getRelizyRunnerHelpText() {
3096
+ return [
3097
+ "relizy-runner <relizy \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570>",
3098
+ "",
3099
+ "\u5728 relizy \u6267\u884C\u524D\u8865\u9F50 Windows GNU \u5DE5\u5177\u8DEF\u5F84\uFF0C\u5E76\u5728\u9996\u6B21 independent \u53D1\u7248\u524D",
3100
+ "\u6821\u9A8C\u57FA\u7EBF tag\u3002\u4E0D\u6539\u53D8 relizy \u81EA\u8EAB\u7684\u53D1\u7248\u4E0E\u7248\u672C\u8BA1\u7B97\u903B\u8F91\u3002",
3101
+ "",
3102
+ "\u7528\u6CD5\uFF1A",
3103
+ " relizy-runner release --no-publish --no-provider-release",
3104
+ " relizy-runner changelog --dry-run",
3105
+ " relizy-runner bump",
3106
+ "",
3107
+ "runner \u884C\u4E3A\uFF1A\u5BF9 release / bump \u9ED8\u8BA4\u5728\u672B\u5C3E\u8FFD\u52A0 --yes\uFF08\u8DF3\u8FC7\u4E0A\u6E38\u786E\u8BA4\uFF09\uFF1B",
3108
+ " \u9700\u8981\u4EA4\u4E92\u786E\u8BA4\u65F6\u8BF7\u52A0\u4E0A --no-yes\uFF08\u4EC5 runner \u8BC6\u522B\uFF0C\u4E0D\u4F20\u7ED9 relizy\uFF09\u3002",
3109
+ "",
3110
+ "\u5E38\u7528\u53C2\u6570\uFF08\u8282\u9009\uFF0C\u7531 relizy \u5904\u7406\uFF1B\u9664 --no-yes \u5916 runner \u4EC5\u900F\u4F20\uFF09\uFF1A",
3111
+ " --dry-run \u9884\u89C8\uFF0C\u4E0D\u5199\u6587\u4EF6\u3001\u4E0D\u6253 tag\u3001\u4E0D\u63D0\u4EA4",
3112
+ " --no-push \u4E0D push \u5230\u8FDC\u7AEF",
3113
+ " --no-publish \u4E0D\u6267\u884C npm publish",
3114
+ " --no-provider-release \u4E0D\u5728 GitHub/GitLab \u521B\u5EFA Release",
3115
+ " --no-commit \u4E0D\u521B\u5EFA\u63D0\u4EA4\u4E0E tag",
3116
+ " --no-changelog \u4E0D\u751F\u6210 changelog \u6587\u4EF6",
3117
+ " --no-verify \u63D0\u4EA4\u65F6\u8DF3\u8FC7 git hooks",
3118
+ " --yes \u8DF3\u8FC7 relizy \u7684\u786E\u8BA4\u63D0\u793A\uFF08release/bump \u4E0B runner \u4E5F\u4F1A\u81EA\u52A8\u8FFD\u52A0\uFF09",
3119
+ "",
3120
+ "\u4EE5\u4E0A\u4EC5\u4E3A\u5E38\u7528\u53C2\u6570\u8282\u9009\uFF0C\u5B8C\u6574\u53C2\u6570\u8BF7\u67E5\u9605 relizy \u5305\u81EA\u8EAB\u6587\u6863\uFF1A",
3121
+ " npx relizy --help",
3122
+ " npx relizy release --help",
3123
+ " npx relizy changelog --help",
3124
+ "",
3125
+ "\u793A\u4F8B\uFF1A",
3126
+ " npx relizy-runner release --no-publish --no-provider-release",
3127
+ " npx ruan-cat-utils relizy-runner release --dry-run",
3128
+ "",
3129
+ "\u9009\u9879\uFF1A",
3130
+ " --no-yes \u5173\u95ED release/bump \u7684\u81EA\u52A8 --yes\uFF0C\u6062\u590D relizy \u4EA4\u4E92\u786E\u8BA4",
3131
+ " -h, --help \u67E5\u770B\u5E2E\u52A9\u4FE1\u606F"
3132
+ ].join("\n");
3133
+ }
3134
+ function resolveRelizyEntrypoint() {
3135
+ return resolve2(process2.cwd(), "node_modules", "relizy", "bin", "relizy.mjs");
3136
+ }
3137
+ function runRelizyRunner(relizyArgs) {
3138
+ if (relizyArgs.length === 0) {
3139
+ consola4.error("\u7528\u6CD5\uFF1Arelizy-runner <relizy \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570>");
3140
+ consola4.error("\u793A\u4F8B\uFF1Arelizy-runner release --no-publish --no-provider-release");
3141
+ return 1;
3142
+ }
3143
+ const spawnArgs = prepareRelizySpawnArgs(relizyArgs);
3144
+ consola4.start(`[release:relizy] \u6267\u884C\u547D\u4EE4\uFF1Arelizy ${spawnArgs.join(" ")}`);
3145
+ const env = ensureRelizyShellEnv();
3146
+ if (shouldCheckIndependentBootstrap(spawnArgs)) {
3147
+ consola4.info("[release:relizy] \u68C0\u67E5 independent \u57FA\u7EBF tag...");
3148
+ const missingPackages = getPackagesMissingBootstrapTags(env);
3149
+ if (missingPackages.length > 0) {
3150
+ printBootstrapInstructions(missingPackages);
3151
+ return 1;
3152
+ }
3153
+ consola4.success("[release:relizy] \u57FA\u7EBF tag \u68C0\u67E5\u901A\u8FC7\u3002");
3154
+ }
3155
+ const relizyEntrypoint = resolveRelizyEntrypoint();
3156
+ if (!existsSync3(relizyEntrypoint)) {
3157
+ consola4.error("\u672A\u5728 node_modules \u4E2D\u627E\u5230 relizy \u547D\u4EE4\u884C\u5165\u53E3\uFF0C\u8BF7\u5148\u6267\u884C pnpm install\u3002");
3158
+ return 1;
3159
+ }
3160
+ consola4.info(`[release:relizy] \u8C03\u7528 relizy \u5165\u53E3\uFF1A${relizyEntrypoint}`);
3161
+ const result = spawnSync3(process2.execPath, [relizyEntrypoint, ...spawnArgs], {
3162
+ cwd: process2.cwd(),
3163
+ env,
3164
+ stdio: "inherit"
3165
+ });
3166
+ if (result.status === 0) {
3167
+ consola4.success("[release:relizy] relizy \u6267\u884C\u5B8C\u6BD5\u3002");
3168
+ } else {
3169
+ consola4.error(`[release:relizy] relizy \u4EE5\u9000\u51FA\u7801 ${result.status} \u7ED3\u675F\u3002`);
3170
+ }
3171
+ return result.status ?? 1;
3172
+ }
3173
+ function parseRelizyRunnerCliArgs(args) {
3174
+ if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
3175
+ return { help: true, relizyArgs: [] };
3176
+ }
3177
+ return { help: false, relizyArgs: args };
3178
+ }
3179
+ function runRelizyRunnerCli(args = process2.argv.slice(2)) {
3180
+ const parsed = parseRelizyRunnerCliArgs(args);
3181
+ if (parsed.help) {
3182
+ console.log(getRelizyRunnerHelpText());
3183
+ return;
3184
+ }
3185
+ const exitCode = runRelizyRunner(parsed.relizyArgs);
3186
+ process2.exitCode = exitCode;
3187
+ }
3188
+ function isRunningAsCli2() {
3189
+ const currentFilePath = fileURLToPath2(import.meta.url);
3190
+ const entryPath = process2.argv[1];
3191
+ if (!entryPath) {
3192
+ return false;
3193
+ }
3194
+ return resolve2(entryPath) === currentFilePath;
3195
+ }
3196
+ if (isRunningAsCli2()) {
3197
+ runRelizyRunnerCli();
3198
+ }
3199
+
2959
3200
  // src/node-esm/yaml-to-md.ts
2960
- import { readFileSync as readFileSync2, writeFileSync } from "fs";
2961
- import { consola as consola4 } from "consola";
3201
+ import { readFileSync as readFileSync3, writeFileSync } from "fs";
3202
+ import { consola as consola5 } from "consola";
2962
3203
  import { isUndefined as isUndefined2 } from "lodash-es";
2963
3204
  function writeYaml2md(params) {
2964
- consola4.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
3205
+ consola5.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
2965
3206
  const { mdPath, data } = params;
2966
3207
  if (isUndefined2(mdPath)) {
2967
- consola4.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
3208
+ consola5.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2968
3209
  process.exit(1);
2969
3210
  }
2970
3211
  try {
2971
- readFileSync2(mdPath, "utf-8");
3212
+ readFileSync3(mdPath, "utf-8");
2972
3213
  } catch (error) {
2973
- consola4.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
3214
+ consola5.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2974
3215
  process.exit(1);
2975
3216
  }
2976
- const mdContent = readFileSync2(mdPath, "utf-8");
3217
+ const mdContent = readFileSync3(mdPath, "utf-8");
2977
3218
  const yamlContent = jsYaml.dump(data);
2978
3219
  const newContent = `---
2979
3220
  ${yamlContent}---
2980
3221
 
2981
3222
  ${mdContent}`;
2982
3223
  writeFileSync(mdPath, newContent, "utf-8");
2983
- consola4.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
3224
+ consola5.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2984
3225
  }
2985
3226
  export {
3227
+ buildBootstrapInstructions,
2986
3228
  clean,
2987
3229
  defaultCleanTargets,
3230
+ ensureRelizyShellEnv,
2988
3231
  findMonorepoRoot,
2989
3232
  getMoveVercelOutputToRootHelpText,
3233
+ getRelizyRunnerHelpText,
2990
3234
  getRuanCatPkgInfo,
3235
+ getWorkspacePackages,
2991
3236
  isMonorepoProject,
2992
3237
  moveVercelOutputToRoot,
2993
3238
  parseMoveVercelOutputToRootCliArgs,
3239
+ parseRelizyRunnerCliArgs,
3240
+ prepareRelizySpawnArgs,
2994
3241
  resolveMoveVercelOutputToRootOptions,
2995
3242
  runMoveVercelOutputToRootCli,
3243
+ runRelizyRunner,
3244
+ runRelizyRunnerCli,
3245
+ shouldCheckIndependentBootstrap,
2996
3246
  writeYaml2md
2997
3247
  };
2998
3248
  /*! Bundled license information: