@icebreakers/monorepo 2.2.0 → 3.0.1

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.cjs CHANGED
@@ -1,1583 +1,43 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __commonJS = (cb, mod) => function __require() {
12
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
- };
14
- var __export = (target, all) => {
15
- for (var name2 in all)
16
- __defProp(target, name2, { get: all[name2], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
- // If the importer is in node compatibility mode or this is not an ESM
28
- // file that has been converted to a CommonJS file using a Babel-
29
- // compatible transform (i.e. "__esModule" has not been set), then set
30
- // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
33
- ));
34
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
-
36
- // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.52.12_@types+node@24.10.1__jiti@2.6.1_postcss@8.5_f48fe4e18fc17d0faecb4c10461dc770/node_modules/tsup/assets/cjs_shims.js
37
- var getImportMetaUrl, importMetaUrl;
38
- var init_cjs_shims = __esm({
39
- "../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.52.12_@types+node@24.10.1__jiti@2.6.1_postcss@8.5_f48fe4e18fc17d0faecb4c10461dc770/node_modules/tsup/assets/cjs_shims.js"() {
40
- "use strict";
41
- getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
42
- importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
43
- }
44
- });
45
-
46
- // ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
47
- var require_is_primitive = __commonJS({
48
- "../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports2, module2) {
49
- "use strict";
50
- init_cjs_shims();
51
- module2.exports = function isPrimitive(val) {
52
- if (typeof val === "object") {
53
- return val === null;
54
- }
55
- return typeof val !== "function";
56
- };
57
- }
58
- });
59
-
60
- // ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
61
- var require_isobject = __commonJS({
62
- "../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports2, module2) {
63
- "use strict";
64
- init_cjs_shims();
65
- module2.exports = function isObject2(val) {
66
- return val != null && typeof val === "object" && Array.isArray(val) === false;
67
- };
68
- }
69
- });
70
-
71
- // ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
72
- var require_is_plain_object = __commonJS({
73
- "../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports2, module2) {
74
- "use strict";
75
- init_cjs_shims();
76
- var isObject2 = require_isobject();
77
- function isObjectObject(o) {
78
- return isObject2(o) === true && Object.prototype.toString.call(o) === "[object Object]";
79
- }
80
- module2.exports = function isPlainObject2(o) {
81
- var ctor, prot;
82
- if (isObjectObject(o) === false) return false;
83
- ctor = o.constructor;
84
- if (typeof ctor !== "function") return false;
85
- prot = ctor.prototype;
86
- if (isObjectObject(prot) === false) return false;
87
- if (prot.hasOwnProperty("isPrototypeOf") === false) {
88
- return false;
89
- }
90
- return true;
91
- };
92
- }
93
- });
94
-
95
- // ../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js
96
- var require_set_value = __commonJS({
97
- "../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js"(exports2, module2) {
98
- "use strict";
99
- init_cjs_shims();
100
- var { deleteProperty } = Reflect;
101
- var isPrimitive = require_is_primitive();
102
- var isPlainObject2 = require_is_plain_object();
103
- var isObject2 = (value) => {
104
- return typeof value === "object" && value !== null || typeof value === "function";
105
- };
106
- var isUnsafeKey = (key) => {
107
- return key === "__proto__" || key === "constructor" || key === "prototype";
108
- };
109
- var validateKey = (key) => {
110
- if (!isPrimitive(key)) {
111
- throw new TypeError("Object keys must be strings or symbols");
112
- }
113
- if (isUnsafeKey(key)) {
114
- throw new Error(`Cannot set unsafe key: "${key}"`);
115
- }
116
- };
117
- var toStringKey = (input) => {
118
- return Array.isArray(input) ? input.flat().map(String).join(",") : input;
119
- };
120
- var createMemoKey = (input, options) => {
121
- if (typeof input !== "string" || !options) return input;
122
- let key = input + ";";
123
- if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
124
- if (options.separator !== void 0) key += `separator=${options.separator};`;
125
- if (options.split !== void 0) key += `split=${options.split};`;
126
- if (options.merge !== void 0) key += `merge=${options.merge};`;
127
- if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
128
- return key;
129
- };
130
- var memoize = (input, options, fn) => {
131
- const key = toStringKey(options ? createMemoKey(input, options) : input);
132
- validateKey(key);
133
- const value = setValue.cache.get(key) || fn();
134
- setValue.cache.set(key, value);
135
- return value;
136
- };
137
- var splitString = (input, options = {}) => {
138
- const sep = options.separator || ".";
139
- const preserve = sep === "/" ? false : options.preservePaths;
140
- if (typeof input === "string" && preserve !== false && /\//.test(input)) {
141
- return [input];
142
- }
143
- const parts = [];
144
- let part = "";
145
- const push = (part2) => {
146
- let number;
147
- if (part2.trim() !== "" && Number.isInteger(number = Number(part2))) {
148
- parts.push(number);
149
- } else {
150
- parts.push(part2);
151
- }
152
- };
153
- for (let i = 0; i < input.length; i++) {
154
- const value = input[i];
155
- if (value === "\\") {
156
- part += input[++i];
157
- continue;
158
- }
159
- if (value === sep) {
160
- push(part);
161
- part = "";
162
- continue;
163
- }
164
- part += value;
165
- }
166
- if (part) {
167
- push(part);
168
- }
169
- return parts;
170
- };
171
- var split2 = (input, options) => {
172
- if (options && typeof options.split === "function") return options.split(input);
173
- if (typeof input === "symbol") return [input];
174
- if (Array.isArray(input)) return input;
175
- return memoize(input, options, () => splitString(input, options));
176
- };
177
- var assignProp = (obj, prop, value, options) => {
178
- validateKey(prop);
179
- if (value === void 0) {
180
- deleteProperty(obj, prop);
181
- } else if (options && options.merge) {
182
- const merge = options.merge === "function" ? options.merge : Object.assign;
183
- if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
184
- obj[prop] = merge(obj[prop], value);
185
- } else {
186
- obj[prop] = value;
187
- }
188
- } else {
189
- obj[prop] = value;
190
- }
191
- return obj;
192
- };
193
- var setValue = (target, path13, value, options) => {
194
- if (!path13 || !isObject2(target)) return target;
195
- const keys = split2(path13, options);
196
- let obj = target;
197
- for (let i = 0; i < keys.length; i++) {
198
- const key = keys[i];
199
- const next = keys[i + 1];
200
- validateKey(key);
201
- if (next === void 0) {
202
- assignProp(obj, key, value, options);
203
- break;
204
- }
205
- if (typeof next === "number" && !Array.isArray(obj[key])) {
206
- obj = obj[key] = [];
207
- continue;
208
- }
209
- if (!isObject2(obj[key])) {
210
- obj[key] = {};
211
- }
212
- obj = obj[key];
213
- }
214
- return target;
215
- };
216
- setValue.split = split2;
217
- setValue.cache = /* @__PURE__ */ new Map();
218
- setValue.clear = () => {
219
- setValue.cache = /* @__PURE__ */ new Map();
220
- };
221
- module2.exports = setValue;
222
- }
223
- });
224
-
225
- // src/index.ts
226
- var index_exports = {};
227
- __export(index_exports, {
228
- GitClient: () => GitClient,
229
- assetsDir: () => assetsDir,
230
- cleanProjects: () => cleanProjects,
231
- createContext: () => createContext,
232
- createNewProject: () => createNewProject,
233
- defineMonorepoConfig: () => defineMonorepoConfig,
234
- escapeStringRegexp: () => escapeStringRegexp,
235
- getCreateChoices: () => getCreateChoices,
236
- getFileHash: () => getFileHash,
237
- getTemplateMap: () => getTemplateMap,
238
- getWorkspaceData: () => getWorkspaceData,
239
- getWorkspacePackages: () => getWorkspacePackages,
240
- init: () => init,
241
- isFileChanged: () => isFileChanged,
242
- isGitignoreFile: () => isGitignoreFile,
243
- isIgnorableFsError: () => isIgnorableFsError,
244
- isMatch: () => isMatch,
245
- loadMonorepoConfig: () => loadMonorepoConfig,
246
- logger: () => logger,
247
- name: () => name,
248
- packageDir: () => packageDir,
249
- resolveCommandConfig: () => resolveCommandConfig,
250
- rootDir: () => rootDir,
251
- setVscodeBinaryMirror: () => setVscodeBinaryMirror,
252
- syncNpmMirror: () => syncNpmMirror,
253
- templateMap: () => templateMap,
254
- templatesDir: () => templatesDir,
255
- toPublishGitignorePath: () => toPublishGitignorePath,
256
- toWorkspaceGitignorePath: () => toWorkspaceGitignorePath,
257
- upgradeMonorepo: () => upgradeMonorepo,
258
- version: () => version
259
- });
260
- module.exports = __toCommonJS(index_exports);
261
- init_cjs_shims();
262
-
263
- // src/commands/index.ts
264
- init_cjs_shims();
265
-
266
- // src/core/git.ts
267
- init_cjs_shims();
268
-
269
- // ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
270
- init_cjs_shims();
271
- var __defProp2 = Object.defineProperty;
272
- var __name = (target, value) => __defProp2(target, "name", { value, configurable: true });
273
- var isObject = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
274
- var join = /* @__PURE__ */ __name((segs, joinChar, options) => {
275
- if (typeof options.join === "function") {
276
- return options.join(segs);
277
- }
278
- return segs[0] + joinChar + segs[1];
279
- }, "join");
280
- var split = /* @__PURE__ */ __name((path13, splitChar, options) => {
281
- if (typeof options.split === "function") {
282
- return options.split(path13);
283
- }
284
- return path13.split(splitChar);
285
- }, "split");
286
- var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
287
- if (typeof (options == null ? void 0 : options.isValid) === "function") {
288
- return options.isValid(key, target);
289
- }
290
- return true;
291
- }, "isValid");
292
- var isValidObject = /* @__PURE__ */ __name((v) => {
293
- return isObject(v) || typeof v === "function";
294
- }, "isValidObject");
295
- var getValue = /* @__PURE__ */ __name((target, path13, options = {}) => {
296
- if (!isObject(options)) {
297
- options = { default: options };
298
- }
299
- if (!isValidObject(target)) {
300
- return typeof options.default !== "undefined" ? options.default : target;
301
- }
302
- if (typeof path13 === "number") {
303
- path13 = String(path13);
304
- }
305
- const pathIsArray = Array.isArray(path13);
306
- const pathIsString = typeof path13 === "string";
307
- const splitChar = options.separator || ".";
308
- const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
309
- if (!pathIsString && !pathIsArray) {
310
- return target;
311
- }
312
- if (target[path13] !== void 0) {
313
- return isValid(path13, target, options) ? target[path13] : options.default;
314
- }
315
- const segs = pathIsArray ? path13 : split(path13, splitChar, options);
316
- const len = segs.length;
317
- let idx = 0;
318
- do {
319
- let prop = segs[idx];
320
- if (typeof prop !== "string") {
321
- prop = String(prop);
322
- }
323
- while (prop && prop.slice(-1) === "\\") {
324
- prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
325
- }
326
- if (target[prop] !== void 0) {
327
- if (!isValid(prop, target, options)) {
328
- return options.default;
329
- }
330
- target = target[prop];
331
- } else {
332
- let hasProp = false;
333
- let n = idx + 1;
334
- while (n < len) {
335
- prop = join([prop, segs[n++]], joinChar, options);
336
- if (hasProp = target[prop] !== void 0) {
337
- if (!isValid(prop, target, options)) {
338
- return options.default;
339
- }
340
- target = target[prop];
341
- idx = n - 1;
342
- break;
343
- }
344
- }
345
- if (!hasProp) {
346
- return options.default;
347
- }
348
- }
349
- } while (++idx < len && isValidObject(target));
350
- if (idx === len) {
351
- return target;
352
- }
353
- return options.default;
354
- }, "getValue");
355
- var index_default = getValue;
356
-
357
- // src/core/git.ts
358
- var import_git_url_parse = __toESM(require("git-url-parse"), 1);
359
- var import_simple_git = require("simple-git");
360
- var GitClient = class {
361
- client;
362
- #config;
363
- constructor(options = {}) {
364
- this.client = (0, import_simple_git.simpleGit)(options);
365
- }
366
- /**
367
- * 读取 Git 的 config 列表,原样返回 simple-git 的结果。
368
- */
369
- listConfig() {
370
- return this.client.listConfig();
371
- }
372
- /**
373
- * 初始化配置缓存,避免多次访问 Git 产生的性能损耗。
374
- */
375
- async init() {
376
- const listConfig = await this.listConfig();
377
- this.#config = listConfig.all;
378
- return this.#config;
379
- }
380
- /**
381
- * 获取缓存的配置,若未初始化则自动触发 init。
382
- */
383
- async getConfig() {
384
- if (this.#config) {
385
- return this.#config;
386
- } else {
387
- return await this.init();
388
- }
389
- }
390
- /**
391
- * 解析 remote.origin.url,返回 git-url-parse 的结构,便于获取仓库元信息。
392
- */
393
- async getGitUrl() {
394
- const config = await this.getConfig();
395
- const x = index_default(config, "remote.origin.url");
396
- if (x) {
397
- return (0, import_git_url_parse.default)(x);
398
- }
399
- }
400
- /**
401
- * 组合 owner/name,生成常用的仓库名表达。
402
- */
403
- async getRepoName() {
404
- const url = await this.getGitUrl();
405
- if (url) {
406
- return `${url.owner}/${url.name}`;
407
- }
408
- }
409
- /**
410
- * 从 Git 配置中提取用户信息,用于填充 package.json author 字段。
411
- */
412
- async getUser() {
413
- const config = await this.getConfig();
414
- const name2 = index_default(config, "user.name");
415
- const email = index_default(config, "user.email");
416
- return {
417
- name: name2,
418
- email
419
- };
420
- }
421
- /**
422
- * 获取当前仓库的顶层目录路径。
423
- */
424
- async getRepoRoot() {
425
- try {
426
- const root = await this.client.revparse(["--show-toplevel"]);
427
- return typeof root === "string" ? root.trim() : void 0;
428
- } catch {
429
- return void 0;
430
- }
431
- }
432
- };
433
-
434
- // src/core/workspace.ts
435
- init_cjs_shims();
436
- var import_find_workspace_dir = require("@pnpm/find-workspace-dir");
437
- var import_workspace = require("@pnpm/workspace.find-packages");
438
- var import_workspace2 = require("@pnpm/workspace.read-manifest");
439
-
440
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
441
- init_cjs_shims();
442
- function isPlainObject(value) {
443
- if (value === null || typeof value !== "object") {
444
- return false;
445
- }
446
- const prototype = Object.getPrototypeOf(value);
447
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
448
- return false;
449
- }
450
- if (Symbol.iterator in value) {
451
- return false;
452
- }
453
- if (Symbol.toStringTag in value) {
454
- return Object.prototype.toString.call(value) === "[object Module]";
455
- }
456
- return true;
457
- }
458
- function _defu(baseObject, defaults, namespace = ".", merger) {
459
- if (!isPlainObject(defaults)) {
460
- return _defu(baseObject, {}, namespace, merger);
461
- }
462
- const object = Object.assign({}, defaults);
463
- for (const key in baseObject) {
464
- if (key === "__proto__" || key === "constructor") {
465
- continue;
466
- }
467
- const value = baseObject[key];
468
- if (value === null || value === void 0) {
469
- continue;
470
- }
471
- if (merger && merger(object, key, value, namespace)) {
472
- continue;
473
- }
474
- if (Array.isArray(value) && Array.isArray(object[key])) {
475
- object[key] = [...value, ...object[key]];
476
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
477
- object[key] = _defu(
478
- value,
479
- object[key],
480
- (namespace ? `${namespace}.` : "") + key.toString(),
481
- merger
482
- );
483
- } else {
484
- object[key] = value;
485
- }
486
- }
487
- return object;
488
- }
489
- function createDefu(merger) {
490
- return (...arguments_) => (
491
- // eslint-disable-next-line unicorn/no-array-reduce
492
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
493
- );
494
- }
495
- var defu = createDefu();
496
- var defuFn = createDefu((object, key, currentValue) => {
497
- if (object[key] !== void 0 && typeof currentValue === "function") {
498
- object[key] = currentValue(object[key]);
499
- return true;
500
- }
501
- });
502
- var defuArrayFn = createDefu((object, key, currentValue) => {
503
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
504
- object[key] = currentValue(object[key]);
505
- return true;
506
- }
507
- });
508
-
509
- // src/core/workspace.ts
510
- var import_pathe = __toESM(require("pathe"), 1);
511
- async function getWorkspacePackages(workspaceDir, options) {
512
- const { ignoreRootPackage, ignorePrivatePackage, patterns } = defu(options, {
513
- ignoreRootPackage: true,
514
- ignorePrivatePackage: true
515
- });
516
- const manifest = await (0, import_workspace2.readWorkspaceManifest)(workspaceDir);
517
- const packages = await (0, import_workspace.findWorkspacePackages)(workspaceDir, {
518
- patterns: patterns ?? (manifest == null ? void 0 : manifest.packages)
519
- });
520
- let pkgs = packages.filter((x) => {
521
- if (ignorePrivatePackage && x.manifest.private) {
522
- return false;
523
- }
524
- return true;
525
- }).map((project) => {
526
- const pkgJsonPath = import_pathe.default.resolve(project.rootDir, "package.json");
527
- return {
528
- ...project,
529
- pkgJsonPath
530
- };
531
- });
532
- if (ignoreRootPackage) {
533
- pkgs = pkgs.filter((x) => {
534
- return x.rootDir !== workspaceDir;
535
- });
536
- }
537
- return pkgs;
538
- }
539
- async function getWorkspaceData(cwd, options) {
540
- const workspaceDir = await (0, import_find_workspace_dir.findWorkspaceDir)(cwd) ?? cwd;
541
- const packages = await getWorkspacePackages(workspaceDir, options);
542
- return {
543
- cwd,
544
- workspaceDir,
545
- packages
546
- };
547
- }
548
-
549
- // src/commands/clean.ts
550
- init_cjs_shims();
551
- var import_checkbox = __toESM(require("@inquirer/checkbox"), 1);
552
- var import_fs_extra = __toESM(require("fs-extra"), 1);
553
- var import_pathe3 = __toESM(require("pathe"), 1);
554
- var import_set_value = __toESM(require_set_value(), 1);
555
-
556
- // src/core/config.ts
557
- init_cjs_shims();
558
- var import_c12 = require("c12");
559
- var import_pathe2 = __toESM(require("pathe"), 1);
560
- var cache = /* @__PURE__ */ new Map();
561
- async function loadConfigInternal(cwd) {
562
- const { config, configFile } = await (0, import_c12.loadConfig)({
563
- name: "monorepo",
564
- cwd,
565
- // configFile: ['monorepo.config'],
566
- rcFile: false,
567
- defaults: {},
568
- globalRc: false,
569
- packageJson: false
570
- });
571
- return {
572
- file: configFile ? import_pathe2.default.resolve(configFile) : null,
573
- config: config ?? {}
574
- };
575
- }
576
- function defineMonorepoConfig(config) {
577
- return config;
578
- }
579
- async function loadMonorepoConfig(cwd) {
580
- const key = import_pathe2.default.resolve(cwd);
581
- if (!cache.has(key)) {
582
- cache.set(key, loadConfigInternal(key));
583
- }
584
- const { config } = await cache.get(key);
585
- return config;
586
- }
587
- async function resolveCommandConfig(name2, cwd) {
588
- const config = await loadMonorepoConfig(cwd);
589
- const commands = config.commands ?? {};
590
- const commandConfig = commands[name2];
591
- return commandConfig ?? {};
592
- }
593
-
594
- // src/commands/clean.ts
595
- async function cleanProjects(cwd) {
596
- const cleanConfig = await resolveCommandConfig("clean", cwd);
597
- const workspaceOptions = (cleanConfig == null ? void 0 : cleanConfig.includePrivate) ? { ignorePrivatePackage: false } : void 0;
598
- const { packages, workspaceDir } = await getWorkspaceData(cwd, workspaceOptions);
599
- const filteredPackages = packages.filter((pkg) => {
600
- var _a;
601
- const name3 = pkg.manifest.name ?? "";
602
- if (!name3) {
603
- return true;
604
- }
605
- if (!((_a = cleanConfig == null ? void 0 : cleanConfig.ignorePackages) == null ? void 0 : _a.length)) {
606
- return true;
607
- }
608
- return !cleanConfig.ignorePackages.includes(name3);
609
- });
610
- let cleanDirs = [];
611
- if (cleanConfig == null ? void 0 : cleanConfig.autoConfirm) {
612
- cleanDirs = filteredPackages.map((pkg) => pkg.rootDir);
613
- } else {
614
- cleanDirs = await (0, import_checkbox.default)({
615
- message: "\u8BF7\u9009\u62E9\u9700\u8981\u6E05\u7406\u7684\u76EE\u5F55",
616
- choices: filteredPackages.map((x) => {
617
- return {
618
- name: import_pathe3.default.relative(workspaceDir, x.rootDir),
619
- value: x.rootDir,
620
- checked: true,
621
- description: x.manifest.name
622
- };
623
- })
624
- });
625
- }
626
- const candidates = Array.from(new Set(cleanDirs.filter(Boolean)));
627
- await Promise.all(candidates.map(async (dir) => {
628
- if (await import_fs_extra.default.pathExists(dir)) {
629
- await import_fs_extra.default.remove(dir);
630
- }
631
- }));
632
- const name2 = import_pathe3.default.resolve(workspaceDir, "package.json");
633
- const pkgJson = await import_fs_extra.default.readJson(name2);
634
- (0, import_set_value.default)(pkgJson, "devDependencies.@icebreakers/monorepo", (cleanConfig == null ? void 0 : cleanConfig.pinnedVersion) ?? "latest", { preservePaths: false });
635
- await import_fs_extra.default.outputJson(name2, pkgJson, {
636
- spaces: 2
637
- });
638
- }
639
-
640
- // src/commands/create.ts
641
- init_cjs_shims();
642
- var import_node_process = __toESM(require("process"), 1);
643
- var import_fs_extra2 = __toESM(require("fs-extra"), 1);
644
- var import_pathe4 = __toESM(require("pathe"), 1);
645
- var import_picocolors = __toESM(require("picocolors"), 1);
646
- var import_set_value2 = __toESM(require_set_value(), 1);
647
-
648
- // src/constants.ts
649
- init_cjs_shims();
650
- var import_node_path = __toESM(require("path"), 1);
651
- var import_node_url = require("url");
652
-
653
- // package.json
654
- var name = "@icebreakers/monorepo";
655
- var version = "2.2.0";
656
-
657
- // src/constants.ts
658
- var packageJsonPath = (0, import_node_url.fileURLToPath)(new URL("../package.json", importMetaUrl));
659
- var packageDir = import_node_path.default.dirname(packageJsonPath);
660
- var templatesDir = import_node_path.default.join(packageDir, "templates");
661
- var assetsDir = import_node_path.default.join(packageDir, "assets");
662
- var rootDir = import_node_path.default.resolve(packageDir, "..", "..");
663
-
664
- // src/core/logger.ts
665
- init_cjs_shims();
666
- var import_consola = require("consola");
667
- var logger = (0, import_consola.createConsola)();
668
-
669
- // src/utils/fs.ts
670
- init_cjs_shims();
671
- function isIgnorableFsError(error) {
672
- if (!error) {
673
- return false;
674
- }
675
- const code = error.code;
676
- return code === "ENOENT" || code === "EBUSY" || code === "EEXIST";
677
- }
678
-
679
- // src/utils/gitignore.ts
680
- init_cjs_shims();
681
- var publishBasename = "gitignore";
682
- var workspaceBasename = ".gitignore";
683
- function detectSeparator(input) {
684
- if (input.includes("\\") && !input.includes("/")) {
685
- return "\\";
686
- }
687
- return "/";
688
- }
689
- function replaceBasename(input, from, to) {
690
- if (!input) {
691
- return input;
692
- }
693
- const separator = detectSeparator(input);
694
- const normalized = input.replace(/[\\/]/g, separator);
695
- const hasTrailingSeparator = normalized.endsWith(separator);
696
- const segments = normalized.split(separator);
697
- if (hasTrailingSeparator && segments[segments.length - 1] === "") {
698
- segments.pop();
699
- }
700
- const lastIndex = segments.length - 1;
701
- if (lastIndex >= 0 && segments[lastIndex] === from) {
702
- segments[lastIndex] = to;
703
- const rebuilt = segments.join(separator);
704
- return hasTrailingSeparator ? `${rebuilt}${separator}` : rebuilt;
705
- }
706
- return input;
707
- }
708
- function toPublishGitignorePath(input) {
709
- return replaceBasename(input, workspaceBasename, publishBasename);
710
- }
711
- function toWorkspaceGitignorePath(input) {
712
- return replaceBasename(input, publishBasename, workspaceBasename);
713
- }
714
- function isGitignoreFile(name2) {
715
- return toPublishGitignorePath(name2) !== name2 || toWorkspaceGitignorePath(name2) !== name2;
716
- }
717
-
718
- // src/utils/hash.ts
719
- init_cjs_shims();
720
- var import_node_crypto = __toESM(require("crypto"), 1);
721
- function getFileHash(data) {
722
- const hashSum = import_node_crypto.default.createHash("md5");
723
- hashSum.update(data);
724
- return hashSum.digest("hex");
725
- }
726
- function isFileChanged(src, dest) {
727
- try {
728
- const currentHash = getFileHash(src);
729
- const previousHash = getFileHash(dest);
730
- return currentHash !== previousHash;
731
- } catch (err) {
732
- logger.error("Error calculating file hash:", err);
733
- return false;
734
- }
735
- }
736
-
737
- // src/utils/regexp.ts
738
- init_cjs_shims();
739
- function escapeStringRegexp(str) {
740
- return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
741
- }
742
- function isMatch(str, arr) {
743
- for (const reg of arr) {
744
- if (reg.test(str)) {
745
- return true;
746
- }
747
- }
748
- return false;
749
- }
750
-
751
- // src/commands/create.ts
752
- var templateMap = {
753
- "tsup": "packages/tsup-template",
754
- "tsdown": "packages/tsdown-template",
755
- "unbuild": "packages/unbuild-template",
756
- "vue-lib": "packages/vue-lib-template",
757
- "hono-server": "apps/server",
758
- "vue-hono": "apps/client",
759
- "vitepress": "apps/website",
760
- "cli": "apps/cli"
761
- };
762
- var defaultTemplate = "unbuild";
763
- var baseChoices = [
764
- { name: "unbuild \u6253\u5305", value: "unbuild" },
765
- { name: "tsup \u6253\u5305", value: "tsup" },
766
- { name: "tsdown \u6253\u5305", value: "tsdown" },
767
- { name: "vue \u7EC4\u4EF6", value: "vue-lib" },
768
- { name: "vue hono \u5168\u6808", value: "vue-hono" },
769
- { name: "hono \u6A21\u677F", value: "hono-server" },
770
- { name: "vitepress \u6587\u6863", value: "vitepress" },
771
- { name: "cli \u6A21\u677F", value: "cli" }
772
- ];
773
- function getCreateChoices(choices) {
774
- if (choices == null ? void 0 : choices.length) {
775
- return choices;
776
- }
777
- return [...baseChoices];
778
- }
779
- function getTemplateMap(extra) {
780
- const base = { ...templateMap };
781
- if (extra && Object.keys(extra).length) {
782
- Object.assign(base, extra);
783
- }
784
- return base;
785
- }
786
- async function applyGitMetadata(pkgJson, repoDir, targetDir) {
787
- try {
788
- const git = new GitClient({ baseDir: repoDir });
789
- const repoName = await git.getRepoName();
790
- if (!repoName) {
791
- return;
792
- }
793
- (0, import_set_value2.default)(pkgJson, ["bugs", "url"], `https://github.com/${repoName}/issues`);
794
- const repository = {
795
- type: "git",
796
- url: `git+https://github.com/${repoName}.git`
797
- };
798
- const repoRoot = await git.getRepoRoot();
799
- const directoryBase = repoRoot ?? repoDir;
800
- const relative = import_pathe4.default.relative(directoryBase, targetDir);
801
- if (relative && relative !== ".") {
802
- repository.directory = relative.split(import_pathe4.default.sep).join("/");
803
- }
804
- (0, import_set_value2.default)(pkgJson, "repository", repository);
805
- const gitUser = await git.getUser();
806
- if ((gitUser == null ? void 0 : gitUser.name) && (gitUser == null ? void 0 : gitUser.email)) {
807
- (0, import_set_value2.default)(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
808
- }
809
- } catch {
810
- }
811
- }
812
- async function createNewProject(options) {
813
- const cwd = (options == null ? void 0 : options.cwd) ?? import_node_process.default.cwd();
814
- const createConfig = await resolveCommandConfig("create", cwd);
815
- const renameJson = (options == null ? void 0 : options.renameJson) ?? (createConfig == null ? void 0 : createConfig.renameJson) ?? false;
816
- const rawName = (options == null ? void 0 : options.name) ?? (createConfig == null ? void 0 : createConfig.name);
817
- const name2 = typeof rawName === "string" ? rawName.trim() : void 0;
818
- const requestedTemplate = (options == null ? void 0 : options.type) ?? (createConfig == null ? void 0 : createConfig.type) ?? (createConfig == null ? void 0 : createConfig.defaultTemplate) ?? defaultTemplate;
819
- const templateDefinitions = getTemplateMap(createConfig == null ? void 0 : createConfig.templateMap);
820
- const templatesRoot = (createConfig == null ? void 0 : createConfig.templatesDir) ? import_pathe4.default.resolve(cwd, createConfig.templatesDir) : templatesDir;
821
- const fallbackTemplate = (createConfig == null ? void 0 : createConfig.defaultTemplate) ?? defaultTemplate;
822
- const bundlerName = typeof requestedTemplate === "string" && templateDefinitions[requestedTemplate] ? requestedTemplate : fallbackTemplate;
823
- const sourceRelative = templateDefinitions[bundlerName];
824
- if (!sourceRelative) {
825
- throw new Error(`\u672A\u627E\u5230\u540D\u4E3A ${bundlerName} \u7684\u6A21\u677F\uFF0C\u8BF7\u68C0\u67E5 monorepo.config.ts`);
826
- }
827
- const from = import_pathe4.default.join(templatesRoot, sourceRelative);
828
- const targetName = name2 && name2.length > 0 ? name2 : sourceRelative;
829
- const to = import_pathe4.default.join(cwd, targetName);
830
- if (await import_fs_extra2.default.pathExists(to)) {
831
- throw new Error(`${import_picocolors.default.red("\u76EE\u6807\u76EE\u5F55\u5DF2\u5B58\u5728")}: ${import_pathe4.default.relative(cwd, to)}`);
832
- }
833
- await import_fs_extra2.default.ensureDir(to);
834
- const filelist = await import_fs_extra2.default.readdir(from);
835
- const shouldSkip = (src) => import_pathe4.default.basename(src) === ".DS_Store";
836
- const copyTasks = filelist.filter((filename) => filename !== "package.json").map(async (filename) => {
837
- const sourcePath = import_pathe4.default.resolve(from, filename);
838
- const targetPath = import_pathe4.default.resolve(to, toWorkspaceGitignorePath(filename));
839
- await import_fs_extra2.default.copy(sourcePath, targetPath, {
840
- filter(src) {
841
- if (shouldSkip(src)) {
842
- return false;
843
- }
844
- return true;
845
- }
846
- });
847
- });
848
- await Promise.all(copyTasks);
849
- if (filelist.includes("package.json")) {
850
- const sourceJsonPath = import_pathe4.default.resolve(from, "package.json");
851
- const sourceJson = await import_fs_extra2.default.readJson(sourceJsonPath);
852
- (0, import_set_value2.default)(sourceJson, "version", "0.0.0");
853
- const packageName = (name2 == null ? void 0 : name2.startsWith("@")) ? name2 : import_pathe4.default.basename(targetName);
854
- (0, import_set_value2.default)(sourceJson, "name", packageName);
855
- await applyGitMetadata(sourceJson, cwd, to);
856
- await import_fs_extra2.default.outputJson(
857
- import_pathe4.default.resolve(
858
- to,
859
- renameJson ? "package.mock.json" : "package.json"
860
- ),
861
- sourceJson,
862
- { spaces: 2 }
863
- );
864
- }
865
- logger.success(`${import_picocolors.default.bgGreenBright(import_picocolors.default.white(`[${bundlerName}]`))} ${targetName} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01`);
866
- }
867
-
868
- // src/commands/init/index.ts
869
- init_cjs_shims();
870
-
871
- // src/core/context.ts
872
- init_cjs_shims();
873
- var import_pathe5 = __toESM(require("pathe"), 1);
874
- var import_types = require("@pnpm/types");
875
- async function createContext(cwd) {
876
- const { packages, workspaceDir } = await getWorkspaceData(cwd);
877
- const git = new GitClient({
878
- baseDir: workspaceDir
879
- });
880
- const workspaceFilepath = import_pathe5.default.resolve(workspaceDir, "pnpm-workspace.yaml");
881
- const gitUrl = await git.getGitUrl();
882
- const gitUser = await git.getUser();
883
- const config = await loadMonorepoConfig(workspaceDir);
884
- return {
885
- cwd,
886
- git,
887
- gitUrl,
888
- gitUser,
889
- workspaceDir,
890
- workspaceFilepath,
891
- packages,
892
- config
893
- };
894
- }
895
-
896
- // src/commands/init/setChangeset.ts
897
- init_cjs_shims();
898
- var import_fs_extra3 = __toESM(require("fs-extra"), 1);
899
- var import_pathe6 = __toESM(require("pathe"), 1);
900
- var import_set_value3 = __toESM(require_set_value(), 1);
901
- async function setChangeset_default(ctx) {
902
- const { gitUrl, workspaceFilepath } = ctx;
903
- if (gitUrl && await import_fs_extra3.default.exists(workspaceFilepath)) {
904
- const changesetConfigPath = import_pathe6.default.resolve(import_pathe6.default.dirname(workspaceFilepath), ".changeset/config.json");
905
- if (await import_fs_extra3.default.exists(changesetConfigPath)) {
906
- const changesetConfig = await import_fs_extra3.default.readJson(
907
- changesetConfigPath
908
- );
909
- if (gitUrl.full_name) {
910
- (0, import_set_value3.default)(changesetConfig, "changelog.1.repo", gitUrl.full_name);
911
- await import_fs_extra3.default.outputJson(changesetConfigPath, changesetConfig, { spaces: 2 });
912
- }
913
- }
914
- }
915
- }
916
-
917
- // src/commands/init/setPkgJson.ts
918
- init_cjs_shims();
919
- var import_fs_extra4 = __toESM(require("fs-extra"), 1);
920
- var import_pathe7 = __toESM(require("pathe"), 1);
921
- var import_set_value4 = __toESM(require_set_value(), 1);
922
- async function setPkgJson_default(ctx) {
923
- const { gitUrl, gitUser, packages, cwd, workspaceFilepath } = ctx;
924
- const workspaceExists = await import_fs_extra4.default.pathExists(workspaceFilepath);
925
- if (gitUrl && workspaceExists) {
926
- await Promise.all(packages.map(async (pkg) => {
927
- if (!await import_fs_extra4.default.pathExists(pkg.pkgJsonPath)) {
928
- return;
929
- }
930
- const pkgJson = JSON.parse(JSON.stringify(pkg.manifest));
931
- const directory = import_pathe7.default.relative(cwd, pkg.rootDir);
932
- (0, import_set_value4.default)(pkgJson, ["bugs", "url"], `https://github.com/${gitUrl.full_name}/issues`);
933
- const repository = {
934
- type: "git",
935
- url: `git+https://github.com/${gitUrl.full_name}.git`
936
- };
937
- if (directory) {
938
- repository.directory = directory;
939
- }
940
- (0, import_set_value4.default)(pkgJson, "repository", repository);
941
- if ((gitUser == null ? void 0 : gitUser.name) && (gitUser == null ? void 0 : gitUser.email)) {
942
- (0, import_set_value4.default)(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
943
- }
944
- const nextContent = `${JSON.stringify(pkgJson, void 0, 2)}
945
- `;
946
- const prevContent = await import_fs_extra4.default.readFile(pkg.pkgJsonPath, "utf8");
947
- if (prevContent !== nextContent) {
948
- await import_fs_extra4.default.writeFile(pkg.pkgJsonPath, nextContent, "utf8");
949
- }
950
- }));
951
- }
952
- }
953
-
954
- // src/commands/init/setReadme.ts
955
- init_cjs_shims();
956
- var import_fs_extra5 = __toESM(require("fs-extra"), 1);
957
- var import_pathe8 = __toESM(require("pathe"), 1);
958
- async function getRows(ctx) {
959
- const { packages, gitUrl, gitUser, cwd } = ctx;
960
- const rows = [];
961
- if (gitUrl) {
962
- rows.push(`# ${gitUrl.name}
963
- `);
964
- }
965
- rows.push("## Packages\n");
966
- const sortedPackages = [...packages].sort((a, b) => {
967
- const left = a.manifest.name ?? "";
968
- const right = b.manifest.name ?? "";
969
- return left.localeCompare(right);
970
- });
971
- for (const pkg of sortedPackages) {
972
- const p = import_pathe8.default.relative(cwd, pkg.rootDirRealPath);
973
- if (p) {
974
- const description = pkg.manifest.description ? `- ${pkg.manifest.description}` : "";
975
- rows.push(`- [${pkg.manifest.name}](${p}) ${description}`);
976
- }
977
- }
978
- if (gitUrl) {
979
- rows.push("\n## Contributing\n");
980
- rows.push("Contributions Welcome! You can contribute in the following ways.");
981
- rows.push("");
982
- rows.push("- Create an Issue - Propose a new feature. Report a bug.");
983
- rows.push("- Pull Request - Fix a bug and typo. Refactor the code.");
984
- rows.push("- Create third-party middleware - Instruct below.");
985
- rows.push("- Share - Share your thoughts on the Blog, X, and others.");
986
- rows.push(`- Make your application - Please try to use ${gitUrl.name}.`);
987
- rows.push("");
988
- rows.push("For more details, see [CONTRIBUTING.md](CONTRIBUTING.md).");
989
- rows.push("\n## Contributors\n");
990
- rows.push(`Thanks to [all contributors](https://github.com/${gitUrl.full_name}/graphs/contributors)!`);
991
- }
992
- rows.push("\n## Authors\n");
993
- if ((gitUser == null ? void 0 : gitUser.name) && (gitUser == null ? void 0 : gitUser.email)) {
994
- rows.push(`${gitUser.name} <${gitUser.email}>`);
995
- }
996
- rows.push("\n## License\n");
997
- rows.push("Distributed under the MIT License. See [LICENSE](LICENSE) for more information.");
998
- return rows;
999
- }
1000
- async function setReadme_default(ctx) {
1001
- const rows = await getRows(ctx);
1002
- await import_fs_extra5.default.writeFile(import_pathe8.default.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
1003
- `);
1004
- }
1005
-
1006
- // src/commands/init/index.ts
1007
- async function init(cwd) {
1008
- var _a;
1009
- const ctx = await createContext(cwd);
1010
- const initConfig = ((_a = ctx.config.commands) == null ? void 0 : _a.init) ?? {};
1011
- if (!initConfig.skipChangeset) {
1012
- await setChangeset_default(ctx);
1013
- }
1014
- if (!initConfig.skipPkgJson) {
1015
- await setPkgJson_default(ctx);
1016
- }
1017
- if (!initConfig.skipReadme) {
1018
- await setReadme_default(ctx);
1019
- }
1020
- }
1021
-
1022
- // src/commands/mirror/binaryMirror.ts
1023
- init_cjs_shims();
1024
- var import_comment_json = require("comment-json");
1025
- var import_fs_extra6 = __toESM(require("fs-extra"), 1);
1026
- var import_pathe9 = __toESM(require("pathe"), 1);
1027
-
1028
- // src/commands/mirror/sources.ts
1029
- init_cjs_shims();
1030
- var chinaMirrorsEnvs = {
1031
- COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
1032
- EDGEDRIVER_CDNURL: "https://npmmirror.com/mirrors/edgedriver",
1033
- NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
1034
- NVM_NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
1035
- PHANTOMJS_CDNURL: "https://cdn.npmmirror.com/binaries/phantomjs",
1036
- CHROMEDRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/chromedriver",
1037
- OPERADRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/operadriver",
1038
- CYPRESS_DOWNLOAD_PATH_TEMPLATE: "https://cdn.npmmirror.com/binaries/cypress/${version}/${platform}-${arch}/cypress.zip",
1039
- ELECTRON_MIRROR: "https://cdn.npmmirror.com/binaries/electron/",
1040
- ELECTRON_BUILDER_BINARIES_MIRROR: "https://cdn.npmmirror.com/binaries/electron-builder-binaries/",
1041
- SASS_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-sass",
1042
- SWC_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-swc",
1043
- NWJS_URLBASE: "https://cdn.npmmirror.com/binaries/nwjs/v",
1044
- PUPPETEER_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
1045
- PUPPETEER_DOWNLOAD_BASE_URL: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
1046
- PLAYWRIGHT_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/playwright",
1047
- SENTRYCLI_CDNURL: "https://cdn.npmmirror.com/binaries/sentry-cli",
1048
- SAUCECTL_INSTALL_BINARY_MIRROR: "https://cdn.npmmirror.com/binaries/saucectl",
1049
- RE2_DOWNLOAD_MIRROR: "https://cdn.npmmirror.com/binaries/node-re2",
1050
- RE2_DOWNLOAD_SKIP_PATH: "true",
1051
- PRISMA_ENGINES_MIRROR: "https://cdn.npmmirror.com/binaries/prisma",
1052
- npm_config_better_sqlite3_binary_host: "https://cdn.npmmirror.com/binaries/better-sqlite3",
1053
- npm_config_keytar_binary_host: "https://cdn.npmmirror.com/binaries/keytar",
1054
- npm_config_sharp_binary_host: "https://cdn.npmmirror.com/binaries/sharp",
1055
- npm_config_sharp_libvips_binary_host: "https://cdn.npmmirror.com/binaries/sharp-libvips",
1056
- npm_config_robotjs_binary_host: "https://cdn.npmmirror.com/binaries/robotjs"
1057
- };
1058
-
1059
- // src/commands/mirror/utils.ts
1060
- init_cjs_shims();
1061
- var import_set_value5 = __toESM(require_set_value(), 1);
1062
- function setMirror(obj, envs = chinaMirrorsEnvs) {
1063
- const platforms = ["linux", "windows", "osx"];
1064
- const prefix = "terminal.integrated.env";
1065
- if (typeof obj === "object" && obj) {
1066
- for (const platform of platforms) {
1067
- (0, import_set_value5.default)(obj, [prefix, platform].join(".").replaceAll(".", "\\."), envs);
1068
- }
1069
- }
1070
- }
1071
-
1072
- // src/commands/mirror/binaryMirror.ts
1073
- async function setVscodeBinaryMirror(cwd) {
1074
- const mirrorConfig = await resolveCommandConfig("mirror", cwd);
1075
- const targetJsonPath = import_pathe9.default.resolve(cwd, ".vscode/settings.json");
1076
- await import_fs_extra6.default.ensureFile(targetJsonPath);
1077
- const json = (0, import_comment_json.parse)(await import_fs_extra6.default.readFile(targetJsonPath, "utf8"), void 0, false);
1078
- const env = (mirrorConfig == null ? void 0 : mirrorConfig.env) ? { ...chinaMirrorsEnvs, ...mirrorConfig.env } : chinaMirrorsEnvs;
1079
- json && typeof json === "object" && setMirror(json, env);
1080
- await import_fs_extra6.default.writeFile(targetJsonPath, `${(0, import_comment_json.stringify)(json, void 0, 2)}
1081
- `, "utf8");
1082
- }
1083
-
1084
- // src/commands/sync.ts
1085
- init_cjs_shims();
1086
- var import_node_os = __toESM(require("os"), 1);
1087
- var import_execa = require("execa");
1088
- var import_p_queue = __toESM(require("p-queue"), 1);
1089
- var import_pathe10 = __toESM(require("pathe"), 1);
1090
- var import_picocolors2 = __toESM(require("picocolors"), 1);
1091
- function renderCommand(template, pkgName) {
1092
- return template.replaceAll("{name}", pkgName);
1093
- }
1094
- async function syncNpmMirror(cwd, options) {
1095
- const syncConfig = await resolveCommandConfig("sync", cwd);
1096
- const {
1097
- concurrency: configConcurrency,
1098
- command: configCommand,
1099
- packages: packageFilter,
1100
- ...workspaceOverrides
1101
- } = syncConfig ?? {};
1102
- const workspaceOptions = {
1103
- ...workspaceOverrides,
1104
- ...options ?? {}
1105
- };
1106
- const { packages, workspaceDir } = await getWorkspaceData(cwd, workspaceOptions);
1107
- logger.info(`[\u5F53\u524D\u5DE5\u4F5C\u533ARepo]:
1108
- ${packages.map((x) => `- ${import_picocolors2.default.green(x.manifest.name)} : ${import_pathe10.default.relative(workspaceDir, x.rootDir)}`).join("\n")}
1109
- `);
1110
- const set7 = new Set(packages.map((x) => x.manifest.name));
1111
- if (packageFilter == null ? void 0 : packageFilter.length) {
1112
- for (const name2 of Array.from(set7)) {
1113
- if (!name2 || !packageFilter.includes(name2)) {
1114
- set7.delete(name2);
1115
- }
1116
- }
1117
- }
1118
- logger.info(`[\u5373\u5C06\u540C\u6B65\u7684\u5305]:
1119
- ${Array.from(set7).map((x) => `- ${import_picocolors2.default.green(x ?? "")}`).join("\n")}
1120
- `);
1121
- const concurrency = configConcurrency ?? Math.max(import_node_os.default.cpus().length, 1);
1122
- const queue = new import_p_queue.default({ concurrency });
1123
- const template = configCommand ?? "cnpm sync {name}";
1124
- const tasks = [];
1125
- for (const pkgName of set7) {
1126
- if (!pkgName) {
1127
- continue;
1128
- }
1129
- tasks.push(queue.add(async () => {
1130
- const command = renderCommand(template, pkgName);
1131
- return (0, import_execa.execaCommand)(command, {
1132
- stdio: "inherit"
1133
- });
1134
- }));
1135
- }
1136
- await Promise.all(tasks);
1137
- }
1138
-
1139
- // src/commands/upgrade/index.ts
1140
- init_cjs_shims();
1141
- var import_node_process2 = __toESM(require("process"), 1);
1142
- var import_checkbox3 = __toESM(require("@inquirer/checkbox"), 1);
1143
- var import_fs_extra8 = __toESM(require("fs-extra"), 1);
1144
- var import_klaw = __toESM(require("klaw"), 1);
1145
- var import_pathe11 = __toESM(require("pathe"), 1);
1146
- var import_set_value6 = __toESM(require_set_value(), 1);
1147
-
1148
- // src/commands/upgrade/overwrite.ts
1149
- init_cjs_shims();
1150
- var import_node_buffer = require("buffer");
1151
- var import_checkbox2 = __toESM(require("@inquirer/checkbox"), 1);
1152
- var import_fs_extra7 = __toESM(require("fs-extra"), 1);
1153
- var import_picocolors3 = __toESM(require("picocolors"), 1);
1154
- function asBuffer(data) {
1155
- return typeof data === "string" ? import_node_buffer.Buffer.from(data) : data;
1156
- }
1157
- async function evaluateWriteIntent(targetPath, options) {
1158
- const { skipOverwrite, source } = options;
1159
- const exists = await import_fs_extra7.default.pathExists(targetPath);
1160
- if (!exists) {
1161
- return {
1162
- type: "write",
1163
- reason: "missing"
1164
- };
1165
- }
1166
- if (skipOverwrite) {
1167
- return {
1168
- type: "skip",
1169
- reason: "skipOverwrite"
1170
- };
1171
- }
1172
- const src = asBuffer(source);
1173
- let destSize = 0;
1174
- try {
1175
- const stat = await import_fs_extra7.default.stat(targetPath);
1176
- destSize = stat.size;
1177
- } catch {
1178
- return {
1179
- type: "write",
1180
- reason: "missing"
1181
- };
1182
- }
1183
- if (destSize !== src.length) {
1184
- return {
1185
- type: "prompt",
1186
- reason: "changed"
1187
- };
1188
- }
1189
- const dest = await import_fs_extra7.default.readFile(targetPath);
1190
- if (!isFileChanged(src, dest)) {
1191
- return {
1192
- type: "skip",
1193
- reason: "identical"
1194
- };
1195
- }
1196
- return {
1197
- type: "prompt",
1198
- reason: "changed"
1199
- };
1200
- }
1201
- async function scheduleOverwrite(intent, options) {
1202
- const { relPath, targetPath, action, pending } = options;
1203
- if (intent.type === "write") {
1204
- await action();
1205
- return;
1206
- }
1207
- if (intent.type === "prompt") {
1208
- pending.push({
1209
- relPath,
1210
- targetPath,
1211
- action
1212
- });
1213
- }
1214
- }
1215
- async function flushPendingOverwrites(pending) {
1216
- if (!pending.length) {
1217
- return;
1218
- }
1219
- const selected = await (0, import_checkbox2.default)({
1220
- message: "\u68C0\u6D4B\u5230\u4EE5\u4E0B\u6587\u4EF6\u5185\u5BB9\u4E0E\u5F53\u524D\u4ED3\u5E93\u4E0D\u540C\uFF0C\u9009\u62E9\u9700\u8981\u8986\u76D6\u7684\u6587\u4EF6",
1221
- choices: pending.map((item) => ({
1222
- name: import_picocolors3.default.greenBright(item.relPath),
1223
- value: item.targetPath,
1224
- checked: false
1225
- })),
1226
- loop: false
1227
- });
1228
- const selectedSet = new Set(selected);
1229
- for (const item of pending) {
1230
- if (selectedSet.has(item.targetPath)) {
1231
- await item.action();
1232
- }
1233
- }
1234
- }
1235
-
1236
- // src/commands/upgrade/pkg-json.ts
1237
- init_cjs_shims();
1238
- var import_semver = require("semver");
1239
-
1240
- // src/commands/upgrade/scripts.ts
1241
- init_cjs_shims();
1242
- var scripts = {
1243
- "script:init": "monorepo init",
1244
- "script:sync": "monorepo sync",
1245
- "script:clean": "monorepo clean",
1246
- "script:mirror": "monorepo mirror",
1247
- "commitlint": "commitlint --edit"
1248
- };
1249
- var scriptsEntries = Object.entries(scripts);
1250
-
1251
- // src/commands/upgrade/pkg-json.ts
1252
- var NON_OVERRIDABLE_PREFIXES = ["workspace:", "catalog:"];
1253
- function parseVersion(input) {
1254
- if (typeof input !== "string" || input.trim().length === 0) {
1255
- return null;
1256
- }
1257
- try {
1258
- return (0, import_semver.minVersion)(input) ?? (0, import_semver.coerce)(input);
1259
- } catch {
1260
- return null;
1261
- }
1262
- }
1263
- function hasNonOverridablePrefix(version2) {
1264
- if (typeof version2 !== "string") {
1265
- return false;
1266
- }
1267
- return NON_OVERRIDABLE_PREFIXES.some((prefix) => version2.startsWith(prefix));
1268
- }
1269
- function shouldAssignVersion(currentVersion, nextVersion) {
1270
- if (typeof currentVersion !== "string" || currentVersion.trim().length === 0) {
1271
- return true;
1272
- }
1273
- if (currentVersion === nextVersion) {
1274
- return false;
1275
- }
1276
- const current = parseVersion(currentVersion);
1277
- const next = parseVersion(nextVersion);
1278
- if (!current || !next) {
1279
- return true;
1280
- }
1281
- return !(0, import_semver.gte)(current, next);
1282
- }
1283
- function setPkgJson(sourcePkgJson, targetPkgJson, options) {
1284
- const packageManager = sourcePkgJson.packageManager ?? "";
1285
- const sourceDeps = sourcePkgJson.dependencies ?? {};
1286
- const sourceDevDeps = sourcePkgJson.devDependencies ?? {};
1287
- const targetDeps = { ...targetPkgJson.dependencies ?? {} };
1288
- const targetDevDeps = { ...targetPkgJson.devDependencies ?? {} };
1289
- if (packageManager) {
1290
- targetPkgJson.packageManager = packageManager;
1291
- }
1292
- for (const [depName, depVersion] of Object.entries(sourceDeps)) {
1293
- if (typeof depVersion !== "string") {
1294
- continue;
1295
- }
1296
- const targetVersion = targetDeps[depName];
1297
- if (hasNonOverridablePrefix(targetVersion)) {
1298
- continue;
1299
- }
1300
- if (shouldAssignVersion(targetVersion, depVersion)) {
1301
- targetDeps[depName] = depVersion;
1302
- }
1303
- }
1304
- if (Object.keys(targetDeps).length) {
1305
- targetPkgJson.dependencies = targetDeps;
1306
- }
1307
- for (const [depName, depVersion] of Object.entries(sourceDevDeps)) {
1308
- if (typeof depVersion !== "string") {
1309
- continue;
1310
- }
1311
- if (depName === name) {
1312
- const nextVersion = `^${version}`;
1313
- const targetVersion = targetDevDeps[depName];
1314
- if (!hasNonOverridablePrefix(targetVersion) && shouldAssignVersion(targetVersion, nextVersion)) {
1315
- targetDevDeps[depName] = nextVersion;
1316
- }
1317
- } else {
1318
- const targetVersion = targetDevDeps[depName];
1319
- if (hasNonOverridablePrefix(targetVersion)) {
1320
- continue;
1321
- }
1322
- if (shouldAssignVersion(targetVersion, depVersion)) {
1323
- targetDevDeps[depName] = depVersion;
1324
- }
1325
- }
1326
- }
1327
- if (Object.keys(targetDevDeps).length) {
1328
- targetPkgJson.devDependencies = targetDevDeps;
1329
- }
1330
- const scriptPairs = (options == null ? void 0 : options.scripts) ? Object.entries(options.scripts) : scriptsEntries;
1331
- if (scriptPairs.length) {
1332
- const scripts2 = { ...targetPkgJson.scripts ?? {} };
1333
- for (const [scriptName, scriptCmd] of scriptPairs) {
1334
- scripts2[scriptName] = scriptCmd;
1335
- }
1336
- targetPkgJson.scripts = scripts2;
1337
- }
1338
- }
1339
-
1340
- // src/commands/upgrade/targets.ts
1341
- init_cjs_shims();
1342
- function getAssetTargets(core) {
1343
- const list = [
1344
- ".changeset",
1345
- ".husky",
1346
- ".vscode",
1347
- ".editorconfig",
1348
- ".gitattributes",
1349
- ".gitignore",
1350
- ".npmrc",
1351
- "commitlint.config.ts",
1352
- "eslint.config.js",
1353
- "lint-staged.config.js",
1354
- "stylelint.config.js",
1355
- "monorepo.config.ts",
1356
- "package.json",
1357
- // pnpm
1358
- "pnpm-workspace.yaml",
1359
- // base tsconfig
1360
- "tsconfig.json",
1361
- // turbo
1362
- "turbo.json",
1363
- // vitest
1364
- "vitest.config.ts",
1365
- // 'vitest.workspace.ts',
1366
- // #region docker
1367
- "Dockerfile",
1368
- ".dockerignore"
1369
- // #endregion
1370
- ];
1371
- if (!core) {
1372
- list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
1373
- }
1374
- return list;
1375
- }
1376
-
1377
- // src/commands/upgrade/index.ts
1378
- async function upgradeMonorepo(opts) {
1379
- const cwd = opts.cwd ?? import_node_process2.default.cwd();
1380
- const upgradeConfig = await resolveCommandConfig("upgrade", cwd);
1381
- const merged = {
1382
- cwd,
1383
- outDir: "",
1384
- ...upgradeConfig ?? {},
1385
- ...opts
1386
- };
1387
- const outDir = merged.outDir ?? "";
1388
- const absOutDir = import_pathe11.default.isAbsolute(outDir) ? outDir : import_pathe11.default.join(cwd, outDir);
1389
- const gitClient = new GitClient({
1390
- baseDir: cwd
1391
- });
1392
- const repoName = await gitClient.getRepoName();
1393
- const useCoreAssets = merged.core ?? false;
1394
- merged.core = useCoreAssets;
1395
- const baseTargets = getAssetTargets(useCoreAssets);
1396
- const configTargets = (upgradeConfig == null ? void 0 : upgradeConfig.targets) ?? [];
1397
- const mergeTargets = upgradeConfig == null ? void 0 : upgradeConfig.mergeTargets;
1398
- let targets = configTargets.length ? mergeTargets === false ? [...configTargets] : Array.from(/* @__PURE__ */ new Set([...baseTargets, ...configTargets])) : baseTargets;
1399
- if (merged.interactive) {
1400
- targets = await (0, import_checkbox3.default)({
1401
- message: "\u9009\u62E9\u4F60\u9700\u8981\u7684\u6587\u4EF6",
1402
- choices: targets.map((x) => {
1403
- return {
1404
- value: x,
1405
- checked: true
1406
- };
1407
- })
1408
- });
1409
- }
1410
- const regexpArr = targets.map((x) => {
1411
- return new RegExp(`^${escapeStringRegexp(x)}`);
1412
- });
1413
- const skipChangesetMarkdown = (upgradeConfig == null ? void 0 : upgradeConfig.skipChangesetMarkdown) ?? true;
1414
- const scriptOverrides = upgradeConfig == null ? void 0 : upgradeConfig.scripts;
1415
- const skipOverwrite = merged.skipOverwrite;
1416
- const pendingOverwrites = [];
1417
- for await (const file of (0, import_klaw.default)(assetsDir, {
1418
- filter(p) {
1419
- const rel = toWorkspaceGitignorePath(import_pathe11.default.relative(assetsDir, p));
1420
- return isMatch(rel, regexpArr);
1421
- }
1422
- })) {
1423
- if (!file.stats.isFile()) {
1424
- continue;
1425
- }
1426
- const relPath = toWorkspaceGitignorePath(import_pathe11.default.relative(assetsDir, file.path));
1427
- if (skipChangesetMarkdown && relPath.startsWith(".changeset/") && relPath.endsWith(".md")) {
1428
- continue;
1429
- }
1430
- const targetPath = import_pathe11.default.resolve(absOutDir, relPath);
1431
- try {
1432
- if (relPath === "package.json") {
1433
- if (!await import_fs_extra8.default.pathExists(targetPath)) {
1434
- continue;
1435
- }
1436
- const sourcePkgJson = await import_fs_extra8.default.readJson(file.path);
1437
- const targetPkgJson = await import_fs_extra8.default.readJson(targetPath);
1438
- setPkgJson(sourcePkgJson, targetPkgJson, { scripts: scriptOverrides });
1439
- const data = `${JSON.stringify(targetPkgJson, void 0, 2)}
1440
- `;
1441
- const intent2 = await evaluateWriteIntent(targetPath, { skipOverwrite, source: data });
1442
- const action2 = async () => {
1443
- await import_fs_extra8.default.outputFile(targetPath, data, "utf8");
1444
- logger.success(targetPath);
1445
- };
1446
- await scheduleOverwrite(intent2, {
1447
- relPath,
1448
- targetPath,
1449
- action: action2,
1450
- pending: pendingOverwrites
1451
- });
1452
- continue;
1453
- }
1454
- if (relPath === ".changeset/config.json" && repoName) {
1455
- const changesetJson = await import_fs_extra8.default.readJson(file.path);
1456
- (0, import_set_value6.default)(changesetJson, "changelog.1.repo", repoName);
1457
- const data = `${JSON.stringify(changesetJson, void 0, 2)}
1458
- `;
1459
- const intent2 = await evaluateWriteIntent(targetPath, { skipOverwrite, source: data });
1460
- const action2 = async () => {
1461
- await import_fs_extra8.default.outputFile(targetPath, data, "utf8");
1462
- logger.success(targetPath);
1463
- };
1464
- await scheduleOverwrite(intent2, {
1465
- relPath,
1466
- targetPath,
1467
- action: action2,
1468
- pending: pendingOverwrites
1469
- });
1470
- continue;
1471
- }
1472
- if (relPath === "LICENSE") {
1473
- const source2 = await import_fs_extra8.default.readFile(file.path);
1474
- const intent2 = await evaluateWriteIntent(targetPath, { skipOverwrite: true, source: source2 });
1475
- const action2 = async () => {
1476
- await import_fs_extra8.default.outputFile(targetPath, source2);
1477
- logger.success(targetPath);
1478
- };
1479
- await scheduleOverwrite(intent2, {
1480
- relPath,
1481
- targetPath,
1482
- action: action2,
1483
- pending: pendingOverwrites
1484
- });
1485
- continue;
1486
- }
1487
- const source = await import_fs_extra8.default.readFile(file.path);
1488
- const intent = await evaluateWriteIntent(targetPath, { skipOverwrite, source });
1489
- const action = async () => {
1490
- await import_fs_extra8.default.outputFile(targetPath, source);
1491
- logger.success(targetPath);
1492
- };
1493
- await scheduleOverwrite(intent, {
1494
- relPath,
1495
- targetPath,
1496
- action,
1497
- pending: pendingOverwrites
1498
- });
1499
- } catch (error) {
1500
- if (isIgnorableFsError(error)) {
1501
- continue;
1502
- }
1503
- throw error;
1504
- }
1505
- }
1506
- await flushPendingOverwrites(pendingOverwrites);
1507
- }
1508
- // Annotate the CommonJS export names for ESM import in node:
1509
- 0 && (module.exports = {
1510
- GitClient,
1511
- assetsDir,
1512
- cleanProjects,
1513
- createContext,
1514
- createNewProject,
1515
- defineMonorepoConfig,
1516
- escapeStringRegexp,
1517
- getCreateChoices,
1518
- getFileHash,
1519
- getTemplateMap,
1520
- getWorkspaceData,
1521
- getWorkspacePackages,
1522
- init,
1523
- isFileChanged,
1524
- isGitignoreFile,
1525
- isIgnorableFsError,
1526
- isMatch,
1527
- loadMonorepoConfig,
1528
- logger,
1529
- name,
1530
- packageDir,
1531
- resolveCommandConfig,
1532
- rootDir,
1533
- setVscodeBinaryMirror,
1534
- syncNpmMirror,
1535
- templateMap,
1536
- templatesDir,
1537
- toPublishGitignorePath,
1538
- toWorkspaceGitignorePath,
1539
- upgradeMonorepo,
1540
- version
1541
- });
1542
- /*! Bundled license information:
1543
-
1544
- is-primitive/index.js:
1545
- (*!
1546
- * is-primitive <https://github.com/jonschlinkert/is-primitive>
1547
- *
1548
- * Copyright (c) 2014-present, Jon Schlinkert.
1549
- * Released under the MIT License.
1550
- *)
1551
-
1552
- isobject/index.js:
1553
- (*!
1554
- * isobject <https://github.com/jonschlinkert/isobject>
1555
- *
1556
- * Copyright (c) 2014-2017, Jon Schlinkert.
1557
- * Released under the MIT License.
1558
- *)
1559
-
1560
- is-plain-object/index.js:
1561
- (*!
1562
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
1563
- *
1564
- * Copyright (c) 2014-2017, Jon Schlinkert.
1565
- * Released under the MIT License.
1566
- *)
1567
-
1568
- set-value/index.js:
1569
- (*!
1570
- * set-value <https://github.com/jonschlinkert/set-value>
1571
- *
1572
- * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
1573
- * Released under the MIT License.
1574
- *)
1575
-
1576
- get-value/dist/index.mjs:
1577
- (*!
1578
- * get-value <https://github.com/jonschlinkert/get-value>
1579
- *
1580
- * Copyright (c) 2014-present, Jon Schlinkert.
1581
- * Released under the MIT License.
1582
- *)
1583
- */
1
+ const require_upgrade = require('./upgrade-C7eRZs41.cjs');
2
+
3
+ exports.GitClient = require_upgrade.GitClient;
4
+ exports.assetsDir = require_upgrade.assetsDir;
5
+ exports.cleanProjects = require_upgrade.cleanProjects;
6
+ exports.createContext = require_upgrade.createContext;
7
+ exports.createNewProject = require_upgrade.createNewProject;
8
+ exports.defineMonorepoConfig = require_upgrade.defineMonorepoConfig;
9
+ exports.escapeStringRegexp = require_upgrade.escapeStringRegexp;
10
+ exports.getCreateChoices = require_upgrade.getCreateChoices;
11
+ exports.getFileHash = require_upgrade.getFileHash;
12
+ exports.getTemplateMap = require_upgrade.getTemplateMap;
13
+ exports.getWorkspaceData = require_upgrade.getWorkspaceData;
14
+ exports.getWorkspacePackages = require_upgrade.getWorkspacePackages;
15
+ exports.init = require_upgrade.init;
16
+ exports.isFileChanged = require_upgrade.isFileChanged;
17
+ exports.isGitignoreFile = require_upgrade.isGitignoreFile;
18
+ exports.isIgnorableFsError = require_upgrade.isIgnorableFsError;
19
+ exports.isMatch = require_upgrade.isMatch;
20
+ exports.loadMonorepoConfig = require_upgrade.loadMonorepoConfig;
21
+ exports.logger = require_upgrade.logger;
22
+ Object.defineProperty(exports, 'name', {
23
+ enumerable: true,
24
+ get: function () {
25
+ return require_upgrade.name;
26
+ }
27
+ });
28
+ exports.packageDir = require_upgrade.packageDir;
29
+ exports.resolveCommandConfig = require_upgrade.resolveCommandConfig;
30
+ exports.rootDir = require_upgrade.rootDir;
31
+ exports.setVscodeBinaryMirror = require_upgrade.setVscodeBinaryMirror;
32
+ exports.syncNpmMirror = require_upgrade.syncNpmMirror;
33
+ exports.templateMap = require_upgrade.templateMap;
34
+ exports.templatesDir = require_upgrade.templatesDir;
35
+ exports.toPublishGitignorePath = require_upgrade.toPublishGitignorePath;
36
+ exports.toWorkspaceGitignorePath = require_upgrade.toWorkspaceGitignorePath;
37
+ exports.upgradeMonorepo = require_upgrade.upgradeMonorepo;
38
+ Object.defineProperty(exports, 'version', {
39
+ enumerable: true,
40
+ get: function () {
41
+ return require_upgrade.version;
42
+ }
43
+ });