@ruan-cat/utils 4.17.0 → 4.19.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.
@@ -134,19 +134,6 @@ declare function executePromiseTasks(config: TasksConfig,
134
134
  */
135
135
  lastParams?: any): Promise<any>;
136
136
 
137
- /**
138
- * 判断目标项目是否是 monorepo 格式的项目
139
- * @description
140
- * 判别逻辑:
141
- * 1. 目标项目同时存在 `pnpm-workspace.yaml` 文件
142
- * 2. `pnpm-workspace.yaml` 提供了有效的 packages 匹配配置
143
- * 3. 至少能匹配到一个 package.json 文件
144
- *
145
- * @returns {boolean} 是否是 monorepo 项目
146
- * @throws {Error} 当 pnpm-workspace.yaml 格式错误时抛出错误
147
- */
148
- declare function isMonorepoProject(): boolean;
149
-
150
137
  /**
151
138
  * pnpm-workspace.yaml 文件的类型声明
152
139
  * @description
@@ -184,4 +171,17 @@ type Prettify<T> = {
184
171
  */
185
172
  type ToNumberLike<T extends number> = T | `${T}`;
186
173
 
174
+ /**
175
+ * 判断目标项目是否是 monorepo 格式的项目
176
+ * @description
177
+ * 判别逻辑:
178
+ * 1. 目标项目同时存在 `pnpm-workspace.yaml` 文件
179
+ * 2. `pnpm-workspace.yaml` 提供了有效的 packages 匹配配置
180
+ * 3. 至少能匹配到一个 package.json 文件
181
+ *
182
+ * @returns {boolean} 是否是 monorepo 项目
183
+ * @throws {Error} 当 pnpm-workspace.yaml 格式错误时抛出错误
184
+ */
185
+ declare function isMonorepoProject(): boolean;
186
+
187
187
  export { type BaseTask, type Condition, type Conditions, type ParallelTasks, type PnpmWorkspace, type Prettify, type PrintListParams, type PromiseTasksConfig, type QueueTasks, type SimpleAsyncTask, type SingleTasks, type SpawnSyncSimpleParams, type Task, type TaskType, type TasksConfig, type ToNumberLike, defPrintCurrentCommand, definePromiseTasks, executePromiseTasks, generateSimpleAsyncTask, generateSpawnSync, initFlag, isConditionsEvery, isConditionsSome, isMonorepoProject, pathChange, printFormat, printList, runPromiseByConcurrency, runPromiseByQueue, taskTypes };
@@ -43,4 +43,17 @@ interface WriteYaml2mdParams<T = Record<string, any>> {
43
43
  */
44
44
  declare function writeYaml2md<T>(params: WriteYaml2mdParams<T>): void;
45
45
 
46
- export { type PackageInfo, type WriteYaml2mdParams, clean, defaultCleanTargets, getRuanCatPkgInfo, writeYaml2md };
46
+ /**
47
+ * 判断目标项目是否是 monorepo 格式的项目
48
+ * @description
49
+ * 判别逻辑:
50
+ * 1. 目标项目同时存在 `pnpm-workspace.yaml` 文件
51
+ * 2. `pnpm-workspace.yaml` 提供了有效的 packages 匹配配置
52
+ * 3. 至少能匹配到一个 package.json 文件
53
+ *
54
+ * @returns {boolean} 是否是 monorepo 项目
55
+ * @throws {Error} 当 pnpm-workspace.yaml 格式错误时抛出错误
56
+ */
57
+ declare function isMonorepoProject(): boolean;
58
+
59
+ export { type PackageInfo, type WriteYaml2mdParams, clean, defaultCleanTargets, getRuanCatPkgInfo, isMonorepoProject, writeYaml2md };
@@ -84,10 +84,10 @@ function generateSpawnSync(spawnSyncSimpleParams) {
84
84
  import { isPlainObject, isArray } from "lodash-es";
85
85
  import consola2 from "consola";
86
86
 
87
- // src/monorepo.ts
87
+ // src/monorepo/index.ts
88
88
  import { join } from "path";
89
89
  import * as fs from "fs";
90
- import { sync } from "glob";
90
+ import { globSync } from "tinyglobby";
91
91
 
92
92
  // ../../node_modules/.pnpm/js-yaml@4.1.1/node_modules/js-yaml/dist/js-yaml.mjs
93
93
  function isNothing(subject) {
@@ -2713,8 +2713,40 @@ var jsYaml = {
2713
2713
  safeDump
2714
2714
  };
2715
2715
 
2716
- // src/monorepo.ts
2716
+ // src/monorepo/index.ts
2717
2717
  import { isUndefined } from "lodash-es";
2718
+ function pathChange(path) {
2719
+ return path.replace(/\\/g, "/");
2720
+ }
2721
+ function isMonorepoProject() {
2722
+ const workspaceConfigPath = join(process.cwd(), "pnpm-workspace.yaml");
2723
+ if (!fs.existsSync(workspaceConfigPath)) {
2724
+ return false;
2725
+ }
2726
+ let workspaceConfig;
2727
+ try {
2728
+ const workspaceFile = fs.readFileSync(workspaceConfigPath, "utf8");
2729
+ workspaceConfig = load(workspaceFile);
2730
+ } catch (error) {
2731
+ throw new Error(
2732
+ `\u89E3\u6790 pnpm-workspace.yaml \u6587\u4EF6\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u683C\u5F0F\u662F\u5426\u6B63\u786E\u3002\u9519\u8BEF\u4FE1\u606F\uFF1A${error instanceof Error ? error.message : String(error)}`
2733
+ );
2734
+ }
2735
+ const pkgPatterns = workspaceConfig.packages;
2736
+ if (isUndefined(pkgPatterns) || pkgPatterns.length === 0) {
2737
+ return false;
2738
+ }
2739
+ for (const pkgPattern of pkgPatterns) {
2740
+ const matchedPath = pathChange(join(process.cwd(), pkgPattern, "package.json"));
2741
+ const matchedPaths = globSync(matchedPath, {
2742
+ ignore: ["**/node_modules/**"]
2743
+ });
2744
+ if (matchedPaths.length > 0) {
2745
+ return true;
2746
+ }
2747
+ }
2748
+ return false;
2749
+ }
2718
2750
 
2719
2751
  // src/node-esm/scripts/clean.ts
2720
2752
  var defaultCleanTargets = [
@@ -2773,6 +2805,7 @@ export {
2773
2805
  clean,
2774
2806
  defaultCleanTargets,
2775
2807
  getRuanCatPkgInfo,
2808
+ isMonorepoProject,
2776
2809
  writeYaml2md
2777
2810
  };
2778
2811
  /*! Bundled license information: