@ruan-cat/utils 4.22.0 → 4.23.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,278 @@ 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
+ function getPackagesMissingBootstrapTags(env) {
3070
+ return getWorkspacePackages().filter((pkg) => getPackageTags(pkg.name, env).length === 0);
3071
+ }
3072
+ function buildBootstrapInstructions(missingPackages) {
3073
+ const tagCommands = missingPackages.map((pkg) => `git tag "${pkg.name}@${pkg.version}"`);
3074
+ const pushArgs = missingPackages.map((pkg) => `"${pkg.name}@${pkg.version}"`).join(" ");
3075
+ return [
3076
+ "[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",
3077
+ ...missingPackages.map((pkg) => `- ${pkg.name}@${pkg.version}`),
3078
+ "",
3079
+ "\u8BF7\u6309\u5F53\u524D package.json \u7248\u672C\u521B\u5EFA\u57FA\u7EBF tag\uFF0C\u5E76\u63A8\u9001\u5230\u8FDC\u7AEF\uFF1A",
3080
+ ...tagCommands,
3081
+ `git push origin ${pushArgs}`
3082
+ ].join("\n");
3083
+ }
3084
+ function printBootstrapInstructions(missingPackages) {
3085
+ consola4.error(buildBootstrapInstructions(missingPackages));
3086
+ }
3087
+ function getRelizyRunnerHelpText() {
3088
+ return [
3089
+ "relizy-runner <relizy \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570>",
3090
+ "",
3091
+ "\u5728 relizy \u6267\u884C\u524D\u8865\u9F50 Windows GNU \u5DE5\u5177\u8DEF\u5F84\uFF0C\u5E76\u5728\u9996\u6B21 independent \u53D1\u7248\u524D",
3092
+ "\u6821\u9A8C\u57FA\u7EBF tag\u3002\u4E0D\u6539\u53D8 relizy \u81EA\u8EAB\u7684\u53D1\u7248\u4E0E\u7248\u672C\u8BA1\u7B97\u903B\u8F91\u3002",
3093
+ "",
3094
+ "\u7528\u6CD5\uFF1A",
3095
+ " relizy-runner release --no-publish --no-provider-release",
3096
+ " relizy-runner changelog --dry-run",
3097
+ " relizy-runner bump",
3098
+ "",
3099
+ "\u5E38\u7528\u53C2\u6570\uFF08\u8282\u9009\uFF0C\u7531 relizy \u5904\u7406\uFF0Crunner \u4EC5\u900F\u4F20\uFF09\uFF1A",
3100
+ " --dry-run \u9884\u89C8\uFF0C\u4E0D\u5199\u6587\u4EF6\u3001\u4E0D\u6253 tag\u3001\u4E0D\u63D0\u4EA4",
3101
+ " --no-push \u4E0D push \u5230\u8FDC\u7AEF",
3102
+ " --no-publish \u4E0D\u6267\u884C npm publish",
3103
+ " --no-provider-release \u4E0D\u5728 GitHub/GitLab \u521B\u5EFA Release",
3104
+ " --no-commit \u4E0D\u521B\u5EFA\u63D0\u4EA4\u4E0E tag",
3105
+ " --no-changelog \u4E0D\u751F\u6210 changelog \u6587\u4EF6",
3106
+ " --no-verify \u63D0\u4EA4\u65F6\u8DF3\u8FC7 git hooks",
3107
+ "",
3108
+ "\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",
3109
+ " npx relizy --help",
3110
+ " npx relizy release --help",
3111
+ " npx relizy changelog --help",
3112
+ "",
3113
+ "\u793A\u4F8B\uFF1A",
3114
+ " npx relizy-runner release --no-publish --no-provider-release",
3115
+ " npx ruan-cat-utils relizy-runner release --dry-run",
3116
+ "",
3117
+ "\u9009\u9879\uFF1A",
3118
+ " -h, --help \u67E5\u770B\u5E2E\u52A9\u4FE1\u606F"
3119
+ ].join("\n");
3120
+ }
3121
+ function resolveRelizyEntrypoint() {
3122
+ return resolve2(process2.cwd(), "node_modules", "relizy", "bin", "relizy.mjs");
3123
+ }
3124
+ function runRelizyRunner(relizyArgs) {
3125
+ if (relizyArgs.length === 0) {
3126
+ consola4.error("\u7528\u6CD5\uFF1Arelizy-runner <relizy \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570>");
3127
+ consola4.error("\u793A\u4F8B\uFF1Arelizy-runner release --no-publish --no-provider-release");
3128
+ return 1;
3129
+ }
3130
+ consola4.start(`[release:relizy] \u6267\u884C\u547D\u4EE4\uFF1Arelizy ${relizyArgs.join(" ")}`);
3131
+ const env = ensureRelizyShellEnv();
3132
+ if (shouldCheckIndependentBootstrap(relizyArgs)) {
3133
+ consola4.info("[release:relizy] \u68C0\u67E5 independent \u57FA\u7EBF tag...");
3134
+ const missingPackages = getPackagesMissingBootstrapTags(env);
3135
+ if (missingPackages.length > 0) {
3136
+ printBootstrapInstructions(missingPackages);
3137
+ return 1;
3138
+ }
3139
+ consola4.success("[release:relizy] \u57FA\u7EBF tag \u68C0\u67E5\u901A\u8FC7\u3002");
3140
+ }
3141
+ const relizyEntrypoint = resolveRelizyEntrypoint();
3142
+ if (!existsSync3(relizyEntrypoint)) {
3143
+ consola4.error("\u672A\u5728 node_modules \u4E2D\u627E\u5230 relizy \u547D\u4EE4\u884C\u5165\u53E3\uFF0C\u8BF7\u5148\u6267\u884C pnpm install\u3002");
3144
+ return 1;
3145
+ }
3146
+ consola4.info(`[release:relizy] \u8C03\u7528 relizy \u5165\u53E3\uFF1A${relizyEntrypoint}`);
3147
+ const result = spawnSync3(process2.execPath, [relizyEntrypoint, ...relizyArgs], {
3148
+ cwd: process2.cwd(),
3149
+ env,
3150
+ stdio: "inherit"
3151
+ });
3152
+ if (result.status === 0) {
3153
+ consola4.success("[release:relizy] relizy \u6267\u884C\u5B8C\u6BD5\u3002");
3154
+ } else {
3155
+ consola4.error(`[release:relizy] relizy \u4EE5\u9000\u51FA\u7801 ${result.status} \u7ED3\u675F\u3002`);
3156
+ }
3157
+ return result.status ?? 1;
3158
+ }
3159
+ function parseRelizyRunnerCliArgs(args) {
3160
+ if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
3161
+ return { help: true, relizyArgs: [] };
3162
+ }
3163
+ return { help: false, relizyArgs: args };
3164
+ }
3165
+ function runRelizyRunnerCli(args = process2.argv.slice(2)) {
3166
+ const parsed = parseRelizyRunnerCliArgs(args);
3167
+ if (parsed.help) {
3168
+ console.log(getRelizyRunnerHelpText());
3169
+ return;
3170
+ }
3171
+ const exitCode = runRelizyRunner(parsed.relizyArgs);
3172
+ process2.exitCode = exitCode;
3173
+ }
3174
+ function isRunningAsCli2() {
3175
+ const currentFilePath = fileURLToPath2(import.meta.url);
3176
+ const entryPath = process2.argv[1];
3177
+ if (!entryPath) {
3178
+ return false;
3179
+ }
3180
+ return resolve2(entryPath) === currentFilePath;
3181
+ }
3182
+ if (isRunningAsCli2()) {
3183
+ runRelizyRunnerCli();
3184
+ }
3185
+
2959
3186
  // src/node-esm/yaml-to-md.ts
2960
- import { readFileSync as readFileSync2, writeFileSync } from "fs";
2961
- import { consola as consola4 } from "consola";
3187
+ import { readFileSync as readFileSync3, writeFileSync } from "fs";
3188
+ import { consola as consola5 } from "consola";
2962
3189
  import { isUndefined as isUndefined2 } from "lodash-es";
2963
3190
  function writeYaml2md(params) {
2964
- consola4.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
3191
+ consola5.info(` \u5F53\u524D\u8FD0\u884C\u7684\u5730\u5740\u4E3A\uFF1A ${process.cwd()} `);
2965
3192
  const { mdPath, data } = params;
2966
3193
  if (isUndefined2(mdPath)) {
2967
- consola4.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
3194
+ consola5.error(" \u8BF7\u63D0\u4F9Bmd\u6587\u4EF6\u7684\u5730\u5740 ");
2968
3195
  process.exit(1);
2969
3196
  }
2970
3197
  try {
2971
- readFileSync2(mdPath, "utf-8");
3198
+ readFileSync3(mdPath, "utf-8");
2972
3199
  } catch (error) {
2973
- consola4.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
3200
+ consola5.error(` \u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728 `);
2974
3201
  process.exit(1);
2975
3202
  }
2976
- const mdContent = readFileSync2(mdPath, "utf-8");
3203
+ const mdContent = readFileSync3(mdPath, "utf-8");
2977
3204
  const yamlContent = jsYaml.dump(data);
2978
3205
  const newContent = `---
2979
3206
  ${yamlContent}---
2980
3207
 
2981
3208
  ${mdContent}`;
2982
3209
  writeFileSync(mdPath, newContent, "utf-8");
2983
- consola4.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
3210
+ consola5.success(` \u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath} `);
2984
3211
  }
2985
3212
  export {
3213
+ buildBootstrapInstructions,
2986
3214
  clean,
2987
3215
  defaultCleanTargets,
3216
+ ensureRelizyShellEnv,
2988
3217
  findMonorepoRoot,
2989
3218
  getMoveVercelOutputToRootHelpText,
3219
+ getRelizyRunnerHelpText,
2990
3220
  getRuanCatPkgInfo,
3221
+ getWorkspacePackages,
2991
3222
  isMonorepoProject,
2992
3223
  moveVercelOutputToRoot,
2993
3224
  parseMoveVercelOutputToRootCliArgs,
3225
+ parseRelizyRunnerCliArgs,
2994
3226
  resolveMoveVercelOutputToRootOptions,
2995
3227
  runMoveVercelOutputToRootCli,
3228
+ runRelizyRunner,
3229
+ runRelizyRunnerCli,
3230
+ shouldCheckIndependentBootstrap,
2996
3231
  writeYaml2md
2997
3232
  };
2998
3233
  /*! Bundled license information: