@icebreakers/monorepo 0.6.4 → 0.6.6

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.
@@ -0,0 +1,959 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
10
+ var __commonJS = (cb, mod) => function __require() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+
30
+ // ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.3.1_postcss@8.4.47_tsx@4.19.1_typescript@5.6.3_yaml@2.5.1/node_modules/tsup/assets/esm_shims.js
31
+ var init_esm_shims = __esm({
32
+ "../../node_modules/.pnpm/tsup@8.3.0_jiti@2.3.1_postcss@8.4.47_tsx@4.19.1_typescript@5.6.3_yaml@2.5.1/node_modules/tsup/assets/esm_shims.js"() {
33
+ "use strict";
34
+ }
35
+ });
36
+
37
+ // ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
38
+ var require_isobject = __commonJS({
39
+ "../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
40
+ "use strict";
41
+ init_esm_shims();
42
+ module.exports = function isObject(val) {
43
+ return val != null && typeof val === "object" && Array.isArray(val) === false;
44
+ };
45
+ }
46
+ });
47
+
48
+ // ../../node_modules/.pnpm/get-value@3.0.1/node_modules/get-value/index.js
49
+ var require_get_value = __commonJS({
50
+ "../../node_modules/.pnpm/get-value@3.0.1/node_modules/get-value/index.js"(exports, module) {
51
+ "use strict";
52
+ init_esm_shims();
53
+ var isObject = require_isobject();
54
+ module.exports = function(target, path8, options) {
55
+ if (!isObject(options)) {
56
+ options = { default: options };
57
+ }
58
+ if (!isValidObject(target)) {
59
+ return typeof options.default !== "undefined" ? options.default : target;
60
+ }
61
+ if (typeof path8 === "number") {
62
+ path8 = String(path8);
63
+ }
64
+ const isArray = Array.isArray(path8);
65
+ const isString = typeof path8 === "string";
66
+ const splitChar = options.separator || ".";
67
+ const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
68
+ if (!isString && !isArray) {
69
+ return target;
70
+ }
71
+ if (isString && path8 in target) {
72
+ return isValid(path8, target, options) ? target[path8] : options.default;
73
+ }
74
+ let segs = isArray ? path8 : split(path8, splitChar, options);
75
+ let len = segs.length;
76
+ let idx = 0;
77
+ do {
78
+ let prop = segs[idx];
79
+ if (typeof prop === "number") {
80
+ prop = String(prop);
81
+ }
82
+ while (prop && prop.slice(-1) === "\\") {
83
+ prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
84
+ }
85
+ if (prop in target) {
86
+ if (!isValid(prop, target, options)) {
87
+ return options.default;
88
+ }
89
+ target = target[prop];
90
+ } else {
91
+ let hasProp = false;
92
+ let n = idx + 1;
93
+ while (n < len) {
94
+ prop = join([prop, segs[n++]], joinChar, options);
95
+ if (hasProp = prop in target) {
96
+ if (!isValid(prop, target, options)) {
97
+ return options.default;
98
+ }
99
+ target = target[prop];
100
+ idx = n - 1;
101
+ break;
102
+ }
103
+ }
104
+ if (!hasProp) {
105
+ return options.default;
106
+ }
107
+ }
108
+ } while (++idx < len && isValidObject(target));
109
+ if (idx === len) {
110
+ return target;
111
+ }
112
+ return options.default;
113
+ };
114
+ function join(segs, joinChar, options) {
115
+ if (typeof options.join === "function") {
116
+ return options.join(segs);
117
+ }
118
+ return segs[0] + joinChar + segs[1];
119
+ }
120
+ function split(path8, splitChar, options) {
121
+ if (typeof options.split === "function") {
122
+ return options.split(path8);
123
+ }
124
+ return path8.split(splitChar);
125
+ }
126
+ function isValid(key, target, options) {
127
+ if (typeof options.isValid === "function") {
128
+ return options.isValid(key, target);
129
+ }
130
+ return true;
131
+ }
132
+ function isValidObject(val) {
133
+ return isObject(val) || Array.isArray(val) || typeof val === "function";
134
+ }
135
+ }
136
+ });
137
+
138
+ // ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
139
+ var require_is_primitive = __commonJS({
140
+ "../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports, module) {
141
+ "use strict";
142
+ init_esm_shims();
143
+ module.exports = function isPrimitive(val) {
144
+ if (typeof val === "object") {
145
+ return val === null;
146
+ }
147
+ return typeof val !== "function";
148
+ };
149
+ }
150
+ });
151
+
152
+ // ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
153
+ var require_is_plain_object = __commonJS({
154
+ "../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports, module) {
155
+ "use strict";
156
+ init_esm_shims();
157
+ var isObject = require_isobject();
158
+ function isObjectObject(o) {
159
+ return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
160
+ }
161
+ module.exports = function isPlainObject2(o) {
162
+ var ctor, prot;
163
+ if (isObjectObject(o) === false) return false;
164
+ ctor = o.constructor;
165
+ if (typeof ctor !== "function") return false;
166
+ prot = ctor.prototype;
167
+ if (isObjectObject(prot) === false) return false;
168
+ if (prot.hasOwnProperty("isPrototypeOf") === false) {
169
+ return false;
170
+ }
171
+ return true;
172
+ };
173
+ }
174
+ });
175
+
176
+ // ../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js
177
+ var require_set_value = __commonJS({
178
+ "../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js"(exports, module) {
179
+ "use strict";
180
+ init_esm_shims();
181
+ var { deleteProperty } = Reflect;
182
+ var isPrimitive = require_is_primitive();
183
+ var isPlainObject2 = require_is_plain_object();
184
+ var isObject = (value) => {
185
+ return typeof value === "object" && value !== null || typeof value === "function";
186
+ };
187
+ var isUnsafeKey = (key) => {
188
+ return key === "__proto__" || key === "constructor" || key === "prototype";
189
+ };
190
+ var validateKey = (key) => {
191
+ if (!isPrimitive(key)) {
192
+ throw new TypeError("Object keys must be strings or symbols");
193
+ }
194
+ if (isUnsafeKey(key)) {
195
+ throw new Error(`Cannot set unsafe key: "${key}"`);
196
+ }
197
+ };
198
+ var toStringKey = (input) => {
199
+ return Array.isArray(input) ? input.flat().map(String).join(",") : input;
200
+ };
201
+ var createMemoKey = (input, options) => {
202
+ if (typeof input !== "string" || !options) return input;
203
+ let key = input + ";";
204
+ if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
205
+ if (options.separator !== void 0) key += `separator=${options.separator};`;
206
+ if (options.split !== void 0) key += `split=${options.split};`;
207
+ if (options.merge !== void 0) key += `merge=${options.merge};`;
208
+ if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
209
+ return key;
210
+ };
211
+ var memoize = (input, options, fn) => {
212
+ const key = toStringKey(options ? createMemoKey(input, options) : input);
213
+ validateKey(key);
214
+ const value = setValue.cache.get(key) || fn();
215
+ setValue.cache.set(key, value);
216
+ return value;
217
+ };
218
+ var splitString = (input, options = {}) => {
219
+ const sep = options.separator || ".";
220
+ const preserve = sep === "/" ? false : options.preservePaths;
221
+ if (typeof input === "string" && preserve !== false && /\//.test(input)) {
222
+ return [input];
223
+ }
224
+ const parts = [];
225
+ let part = "";
226
+ const push = (part2) => {
227
+ let number;
228
+ if (part2.trim() !== "" && Number.isInteger(number = Number(part2))) {
229
+ parts.push(number);
230
+ } else {
231
+ parts.push(part2);
232
+ }
233
+ };
234
+ for (let i = 0; i < input.length; i++) {
235
+ const value = input[i];
236
+ if (value === "\\") {
237
+ part += input[++i];
238
+ continue;
239
+ }
240
+ if (value === sep) {
241
+ push(part);
242
+ part = "";
243
+ continue;
244
+ }
245
+ part += value;
246
+ }
247
+ if (part) {
248
+ push(part);
249
+ }
250
+ return parts;
251
+ };
252
+ var split = (input, options) => {
253
+ if (options && typeof options.split === "function") return options.split(input);
254
+ if (typeof input === "symbol") return [input];
255
+ if (Array.isArray(input)) return input;
256
+ return memoize(input, options, () => splitString(input, options));
257
+ };
258
+ var assignProp = (obj, prop, value, options) => {
259
+ validateKey(prop);
260
+ if (value === void 0) {
261
+ deleteProperty(obj, prop);
262
+ } else if (options && options.merge) {
263
+ const merge = options.merge === "function" ? options.merge : Object.assign;
264
+ if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
265
+ obj[prop] = merge(obj[prop], value);
266
+ } else {
267
+ obj[prop] = value;
268
+ }
269
+ } else {
270
+ obj[prop] = value;
271
+ }
272
+ return obj;
273
+ };
274
+ var setValue = (target, path8, value, options) => {
275
+ if (!path8 || !isObject(target)) return target;
276
+ const keys = split(path8, options);
277
+ let obj = target;
278
+ for (let i = 0; i < keys.length; i++) {
279
+ const key = keys[i];
280
+ const next = keys[i + 1];
281
+ validateKey(key);
282
+ if (next === void 0) {
283
+ assignProp(obj, key, value, options);
284
+ break;
285
+ }
286
+ if (typeof next === "number" && !Array.isArray(obj[key])) {
287
+ obj = obj[key] = [];
288
+ continue;
289
+ }
290
+ if (!isObject(obj[key])) {
291
+ obj[key] = {};
292
+ }
293
+ obj = obj[key];
294
+ }
295
+ return target;
296
+ };
297
+ setValue.split = split;
298
+ setValue.cache = /* @__PURE__ */ new Map();
299
+ setValue.clear = () => {
300
+ setValue.cache = /* @__PURE__ */ new Map();
301
+ };
302
+ module.exports = setValue;
303
+ }
304
+ });
305
+
306
+ // src/monorepo/git.ts
307
+ init_esm_shims();
308
+ var import_get_value = __toESM(require_get_value(), 1);
309
+ import gitUrlParse from "git-url-parse";
310
+ import { simpleGit } from "simple-git";
311
+ var GitClient = class {
312
+ client;
313
+ #config;
314
+ constructor(options = {}) {
315
+ this.client = simpleGit(options);
316
+ }
317
+ listConfig() {
318
+ return this.client.listConfig();
319
+ }
320
+ async init() {
321
+ const listConfig = await this.listConfig();
322
+ this.#config = listConfig.all;
323
+ return this.#config;
324
+ }
325
+ async getConfig() {
326
+ if (this.#config) {
327
+ return this.#config;
328
+ } else {
329
+ return await this.init();
330
+ }
331
+ }
332
+ async getGitUrl() {
333
+ const config = await this.getConfig();
334
+ const x = (0, import_get_value.default)(config, "remote.origin.url");
335
+ if (x) {
336
+ return gitUrlParse(x);
337
+ }
338
+ }
339
+ async getRepoName() {
340
+ const url = await this.getGitUrl();
341
+ if (url) {
342
+ return `${url.owner}/${url.name}`;
343
+ }
344
+ }
345
+ async getUser() {
346
+ const config = await this.getConfig();
347
+ const name2 = (0, import_get_value.default)(config, "user.name");
348
+ const email = (0, import_get_value.default)(config, "user.email");
349
+ return {
350
+ name: name2,
351
+ email
352
+ };
353
+ }
354
+ };
355
+
356
+ // src/utils/md5.ts
357
+ init_esm_shims();
358
+ import crypto from "node:crypto";
359
+ function getFileHash(data) {
360
+ const hashSum = crypto.createHash("md5");
361
+ hashSum.update(data);
362
+ return hashSum.digest("hex");
363
+ }
364
+ function isFileChanged(src, dest) {
365
+ try {
366
+ const currentHash = getFileHash(src);
367
+ const previousHash = getFileHash(dest);
368
+ return currentHash !== previousHash;
369
+ } catch (err) {
370
+ console.error("Error calculating file hash:", err);
371
+ return false;
372
+ }
373
+ }
374
+
375
+ // src/utils/regexp.ts
376
+ init_esm_shims();
377
+ function escapeStringRegexp(str) {
378
+ return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
379
+ }
380
+ function isMatch(str, arr) {
381
+ for (const reg of arr) {
382
+ if (reg.test(str)) {
383
+ return true;
384
+ }
385
+ }
386
+ return false;
387
+ }
388
+
389
+ // src/lib.ts
390
+ init_esm_shims();
391
+ var import_get_value2 = __toESM(require_get_value(), 1);
392
+ var import_set_value = __toESM(require_set_value(), 1);
393
+ import process from "node:process";
394
+ import { fileURLToPath } from "node:url";
395
+ import checkbox from "@inquirer/checkbox";
396
+ import confirm from "@inquirer/confirm";
397
+ import fs from "fs-extra";
398
+ import klaw from "klaw";
399
+ import PQueue from "p-queue";
400
+ import path from "pathe";
401
+ import pc from "picocolors";
402
+
403
+ // src/constants.ts
404
+ init_esm_shims();
405
+
406
+ // package.json
407
+ var name = "@icebreakers/monorepo";
408
+ var version = "0.6.6";
409
+
410
+ // src/logger.ts
411
+ init_esm_shims();
412
+ import { createConsola } from "consola";
413
+ var logger = createConsola();
414
+
415
+ // src/scripts.ts
416
+ init_esm_shims();
417
+ var scripts = {
418
+ "script:init": "monorepo init",
419
+ "script:sync": "monorepo sync",
420
+ "script:clean": "monorepo clean",
421
+ "script:mirror": "monorepo mirror"
422
+ };
423
+ var scriptsEntries = Object.entries(scripts);
424
+
425
+ // src/targets.ts
426
+ init_esm_shims();
427
+ function getAssetTargets(raw) {
428
+ const list = [
429
+ ".changeset",
430
+ ".husky",
431
+ ".vscode",
432
+ ".editorconfig",
433
+ ".gitattributes",
434
+ ".gitignore",
435
+ ".npmrc",
436
+ "commitlint.config.ts",
437
+ "eslint.config.js",
438
+ "lint-staged.config.js",
439
+ "stylelint.config.js",
440
+ "package.json",
441
+ // pnpm
442
+ "pnpm-workspace.yaml",
443
+ // base tsconfig
444
+ "tsconfig.json",
445
+ // turbo
446
+ "turbo.json",
447
+ // vitest
448
+ "vitest.workspace.ts",
449
+ // #region docker
450
+ "Dockerfile",
451
+ ".dockerignore"
452
+ // #endregion
453
+ ];
454
+ if (!raw) {
455
+ list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
456
+ }
457
+ return list;
458
+ }
459
+
460
+ // src/lib.ts
461
+ var queue = new PQueue({ concurrency: 1 });
462
+ var __filename2 = fileURLToPath(import.meta.url);
463
+ var __dirname2 = path.dirname(__filename2);
464
+ var assetsDir = path.join(__dirname2, "../assets");
465
+ var templatesDir = path.join(__dirname2, "../templates");
466
+ var cwd = process.cwd();
467
+ function isWorkspace(version2) {
468
+ if (typeof version2 === "string") {
469
+ return version2.startsWith("workspace:");
470
+ }
471
+ return false;
472
+ }
473
+ function setPkgJson(sourcePkgJson, targetPkgJson) {
474
+ const packageManager = (0, import_get_value2.default)(sourcePkgJson, "packageManager", { default: "" });
475
+ const deps = (0, import_get_value2.default)(sourcePkgJson, "dependencies", { default: {} });
476
+ const devDeps = (0, import_get_value2.default)(sourcePkgJson, "devDependencies", { default: {} });
477
+ const targetDeps = (0, import_get_value2.default)(targetPkgJson, "dependencies", { default: {} });
478
+ const targetDevDeps = (0, import_get_value2.default)(targetPkgJson, "devDependencies", { default: {} });
479
+ (0, import_set_value.default)(targetPkgJson, "packageManager", packageManager);
480
+ Object.entries(deps).forEach((x) => {
481
+ if (!isWorkspace(targetDeps[x[0]])) {
482
+ (0, import_set_value.default)(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
483
+ }
484
+ });
485
+ Object.entries(devDeps).forEach((x) => {
486
+ if (x[0] === name) {
487
+ (0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
488
+ } else {
489
+ if (!isWorkspace(targetDevDeps[x[0]])) {
490
+ (0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
491
+ }
492
+ }
493
+ });
494
+ for (const [k, v] of scriptsEntries) {
495
+ (0, import_set_value.default)(targetPkgJson, `scripts.${k}`, v);
496
+ }
497
+ }
498
+ function confirmOverwrite(filename) {
499
+ return confirm({ message: `${pc.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
500
+ }
501
+ async function upgradeMonorepo(opts) {
502
+ const { outDir = "", raw, interactive } = opts;
503
+ const absOutDir = path.isAbsolute(outDir) ? outDir : path.join(cwd, outDir);
504
+ const gitClient = new GitClient({
505
+ baseDir: cwd
506
+ });
507
+ const repoName = await gitClient.getRepoName();
508
+ let targets = getAssetTargets(raw);
509
+ if (interactive) {
510
+ targets = await checkbox({
511
+ message: "\u9009\u62E9\u4F60\u9700\u8981\u7684\u6587\u4EF6",
512
+ choices: targets.map((x) => {
513
+ return {
514
+ value: x,
515
+ checked: true
516
+ };
517
+ })
518
+ });
519
+ }
520
+ const regexpArr = targets.map((x) => {
521
+ return new RegExp(`^${escapeStringRegexp(x)}`);
522
+ });
523
+ for await (const file of klaw(assetsDir, {
524
+ filter(p) {
525
+ const str = path.relative(assetsDir, p);
526
+ return isMatch(str, regexpArr);
527
+ }
528
+ })) {
529
+ await queue.add(async () => {
530
+ if (file.stats.isFile()) {
531
+ const relPath = path.relative(assetsDir, file.path);
532
+ const targetPath = path.resolve(absOutDir, relPath);
533
+ const targetIsExisted = await fs.exists(targetPath);
534
+ async function overwriteOrCopy(target) {
535
+ let isOverwrite = true;
536
+ if (targetIsExisted) {
537
+ const src = await fs.readFile(file.path);
538
+ const dest = target ?? await fs.readFile(targetPath);
539
+ if (await isFileChanged(src, dest)) {
540
+ isOverwrite = await confirmOverwrite(relPath);
541
+ }
542
+ }
543
+ return isOverwrite;
544
+ }
545
+ if (relPath === "package.json") {
546
+ const sourcePath = file.path;
547
+ if (targetIsExisted) {
548
+ const sourcePkgJson = await fs.readJson(sourcePath);
549
+ const targetPkgJson = await fs.readJson(targetPath);
550
+ setPkgJson(sourcePkgJson, targetPkgJson);
551
+ const data = JSON.stringify(targetPkgJson, void 0, 2);
552
+ await fs.writeFile(targetPath, `${data}
553
+ `, "utf8");
554
+ logger.success(targetPath);
555
+ }
556
+ } else if (relPath === ".changeset/config.json" && repoName) {
557
+ const changesetJson = await fs.readJson(file.path);
558
+ (0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
559
+ const data = JSON.stringify(changesetJson, void 0, 2);
560
+ if (await overwriteOrCopy(data)) {
561
+ await fs.ensureDir(path.dirname(targetPath));
562
+ await fs.writeFile(targetPath, `${data}
563
+ `, "utf8");
564
+ logger.success(targetPath);
565
+ }
566
+ } else {
567
+ if (await overwriteOrCopy()) {
568
+ await fs.copy(
569
+ file.path,
570
+ targetPath
571
+ );
572
+ logger.success(targetPath);
573
+ }
574
+ }
575
+ }
576
+ });
577
+ }
578
+ }
579
+ async function createNewProject(name2) {
580
+ const defaultTemplate = "bar";
581
+ const targetTemplate = name2 ?? defaultTemplate;
582
+ await fs.copy(path.join(templatesDir, defaultTemplate), path.join(cwd, targetTemplate));
583
+ logger.success(`${targetTemplate} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01`);
584
+ }
585
+
586
+ // src/monorepo/binaryMirror.ts
587
+ init_esm_shims();
588
+ import { parse, stringify } from "comment-json";
589
+ import fs2 from "fs-extra";
590
+ import path2 from "pathe";
591
+
592
+ // src/monorepo/mirror/sources.ts
593
+ init_esm_shims();
594
+ var chinaMirrorsEnvs = {
595
+ COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
596
+ EDGEDRIVER_CDNURL: "https://npmmirror.com/mirrors/edgedriver",
597
+ NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
598
+ NVM_NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
599
+ PHANTOMJS_CDNURL: "https://cdn.npmmirror.com/binaries/phantomjs",
600
+ CHROMEDRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/chromedriver",
601
+ OPERADRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/operadriver",
602
+ CYPRESS_DOWNLOAD_PATH_TEMPLATE: "https://cdn.npmmirror.com/binaries/cypress/${version}/${platform}-${arch}/cypress.zip",
603
+ ELECTRON_MIRROR: "https://cdn.npmmirror.com/binaries/electron/",
604
+ ELECTRON_BUILDER_BINARIES_MIRROR: "https://cdn.npmmirror.com/binaries/electron-builder-binaries/",
605
+ SASS_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-sass",
606
+ SWC_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-swc",
607
+ NWJS_URLBASE: "https://cdn.npmmirror.com/binaries/nwjs/v",
608
+ PUPPETEER_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
609
+ PUPPETEER_DOWNLOAD_BASE_URL: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
610
+ PLAYWRIGHT_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/playwright",
611
+ SENTRYCLI_CDNURL: "https://cdn.npmmirror.com/binaries/sentry-cli",
612
+ SAUCECTL_INSTALL_BINARY_MIRROR: "https://cdn.npmmirror.com/binaries/saucectl",
613
+ RE2_DOWNLOAD_MIRROR: "https://cdn.npmmirror.com/binaries/node-re2",
614
+ RE2_DOWNLOAD_SKIP_PATH: "true",
615
+ PRISMA_ENGINES_MIRROR: "https://cdn.npmmirror.com/binaries/prisma",
616
+ npm_config_better_sqlite3_binary_host: "https://cdn.npmmirror.com/binaries/better-sqlite3",
617
+ npm_config_keytar_binary_host: "https://cdn.npmmirror.com/binaries/keytar",
618
+ npm_config_sharp_binary_host: "https://cdn.npmmirror.com/binaries/sharp",
619
+ npm_config_sharp_libvips_binary_host: "https://cdn.npmmirror.com/binaries/sharp-libvips",
620
+ npm_config_robotjs_binary_host: "https://cdn.npmmirror.com/binaries/robotjs"
621
+ };
622
+
623
+ // src/monorepo/mirror/utils.ts
624
+ init_esm_shims();
625
+ var import_set_value2 = __toESM(require_set_value(), 1);
626
+ function setMirror(obj) {
627
+ const platforms = ["linux", "windows", "osx"];
628
+ const prefix = "terminal.integrated.env";
629
+ if (typeof obj === "object" && obj) {
630
+ for (const platform of platforms) {
631
+ (0, import_set_value2.default)(obj, [prefix, platform].join(".").replaceAll(".", "\\."), chinaMirrorsEnvs);
632
+ }
633
+ }
634
+ }
635
+
636
+ // src/monorepo/binaryMirror.ts
637
+ async function setVscodeBinaryMirror(cwd2) {
638
+ const targetJsonPath = path2.resolve(cwd2, ".vscode/settings.json");
639
+ await fs2.ensureFile(targetJsonPath);
640
+ const json = parse(await fs2.readFile(targetJsonPath, "utf8"), void 0, false);
641
+ json && typeof json === "object" && setMirror(json);
642
+ await fs2.writeFile(targetJsonPath, `${stringify(json, void 0, 2)}
643
+ `, "utf8");
644
+ }
645
+
646
+ // src/monorepo/clean.ts
647
+ init_esm_shims();
648
+ import fs3 from "fs-extra";
649
+ import path3 from "pathe";
650
+ var dirs = [
651
+ "packages/monorepo",
652
+ "packages/foo",
653
+ // 'apps/cli',
654
+ // 'apps/website',
655
+ "apps"
656
+ ];
657
+ async function cleanProjects(cwd2) {
658
+ for (const dir of dirs.map((x) => {
659
+ return path3.resolve(cwd2, x);
660
+ })) {
661
+ await fs3.remove(dir);
662
+ }
663
+ }
664
+
665
+ // src/monorepo/workspace.ts
666
+ init_esm_shims();
667
+ import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
668
+
669
+ // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
670
+ init_esm_shims();
671
+ function isPlainObject(value) {
672
+ if (value === null || typeof value !== "object") {
673
+ return false;
674
+ }
675
+ const prototype = Object.getPrototypeOf(value);
676
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
677
+ return false;
678
+ }
679
+ if (Symbol.iterator in value) {
680
+ return false;
681
+ }
682
+ if (Symbol.toStringTag in value) {
683
+ return Object.prototype.toString.call(value) === "[object Module]";
684
+ }
685
+ return true;
686
+ }
687
+ function _defu(baseObject, defaults, namespace = ".", merger) {
688
+ if (!isPlainObject(defaults)) {
689
+ return _defu(baseObject, {}, namespace, merger);
690
+ }
691
+ const object = Object.assign({}, defaults);
692
+ for (const key in baseObject) {
693
+ if (key === "__proto__" || key === "constructor") {
694
+ continue;
695
+ }
696
+ const value = baseObject[key];
697
+ if (value === null || value === void 0) {
698
+ continue;
699
+ }
700
+ if (merger && merger(object, key, value, namespace)) {
701
+ continue;
702
+ }
703
+ if (Array.isArray(value) && Array.isArray(object[key])) {
704
+ object[key] = [...value, ...object[key]];
705
+ } else if (isPlainObject(value) && isPlainObject(object[key])) {
706
+ object[key] = _defu(
707
+ value,
708
+ object[key],
709
+ (namespace ? `${namespace}.` : "") + key.toString(),
710
+ merger
711
+ );
712
+ } else {
713
+ object[key] = value;
714
+ }
715
+ }
716
+ return object;
717
+ }
718
+ function createDefu(merger) {
719
+ return (...arguments_) => (
720
+ // eslint-disable-next-line unicorn/no-array-reduce
721
+ arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
722
+ );
723
+ }
724
+ var defu = createDefu();
725
+ var defuFn = createDefu((object, key, currentValue) => {
726
+ if (object[key] !== void 0 && typeof currentValue === "function") {
727
+ object[key] = currentValue(object[key]);
728
+ return true;
729
+ }
730
+ });
731
+ var defuArrayFn = createDefu((object, key, currentValue) => {
732
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
733
+ object[key] = currentValue(object[key]);
734
+ return true;
735
+ }
736
+ });
737
+
738
+ // src/monorepo/workspace.ts
739
+ import path4 from "pathe";
740
+ async function getWorkspacePackages(cwd2, options) {
741
+ const posixCwd = path4.normalize(cwd2);
742
+ const { ignoreRootPackage, ignorePrivatePackage } = defu(options, {
743
+ ignoreRootPackage: true,
744
+ ignorePrivatePackage: true
745
+ });
746
+ const packages = await findWorkspacePackages(cwd2);
747
+ let pkgs = packages.filter((x) => {
748
+ if (ignorePrivatePackage && x.manifest.private) {
749
+ return false;
750
+ }
751
+ return true;
752
+ }).map((project) => {
753
+ const pkgJsonPath = path4.resolve(project.rootDir, "package.json");
754
+ return {
755
+ ...project,
756
+ pkgJsonPath
757
+ };
758
+ });
759
+ if (ignoreRootPackage) {
760
+ pkgs = pkgs.filter((x) => {
761
+ return path4.normalize(
762
+ x.rootDir
763
+ ) !== posixCwd;
764
+ });
765
+ }
766
+ return pkgs;
767
+ }
768
+
769
+ // src/monorepo/init.ts
770
+ init_esm_shims();
771
+
772
+ // src/monorepo/context.ts
773
+ init_esm_shims();
774
+ import path5 from "pathe";
775
+ import "@pnpm/types";
776
+ async function createContext(cwd2) {
777
+ const git = new GitClient();
778
+ const workspaceFilepath = path5.resolve(cwd2, "pnpm-workspace.yaml");
779
+ const projects = await getWorkspacePackages(cwd2);
780
+ return {
781
+ cwd: cwd2,
782
+ git,
783
+ workspaceFilepath,
784
+ projects
785
+ };
786
+ }
787
+
788
+ // src/monorepo/setPkgJson.ts
789
+ init_esm_shims();
790
+ var import_set_value3 = __toESM(require_set_value(), 1);
791
+ import fs4 from "fs-extra";
792
+ import path6 from "pathe";
793
+ async function setPkgJson_default(ctx) {
794
+ const { git, projects, cwd: cwd2, workspaceFilepath } = ctx;
795
+ const gitUrl = await git.getGitUrl();
796
+ const gitUser = await git.getUser();
797
+ if (gitUrl && await fs4.exists(workspaceFilepath)) {
798
+ for (const project of projects) {
799
+ const pkgJson = project.manifest;
800
+ const directory = path6.relative(cwd2, project.rootDir);
801
+ (0, import_set_value3.default)(pkgJson, "bugs.url", `https://github.com/${gitUrl.full_name}/issues`);
802
+ const repository = {
803
+ type: "git",
804
+ url: `git+https://github.com/${gitUrl.full_name}.git`
805
+ };
806
+ if (directory) {
807
+ repository.directory = directory;
808
+ }
809
+ (0, import_set_value3.default)(pkgJson, "repository", repository);
810
+ if (gitUser) {
811
+ (0, import_set_value3.default)(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
812
+ }
813
+ await fs4.writeJSON(project.pkgJsonPath, pkgJson, {
814
+ spaces: 2
815
+ });
816
+ }
817
+ }
818
+ }
819
+
820
+ // src/monorepo/setReadme.ts
821
+ init_esm_shims();
822
+ import fs5 from "fs-extra";
823
+ import path7 from "pathe";
824
+ async function getRows(ctx) {
825
+ const { projects, git, cwd: cwd2 } = ctx;
826
+ const gitUrl = await git.getGitUrl();
827
+ const gitUser = await git.getUser();
828
+ const rows = [];
829
+ if (gitUrl) {
830
+ rows.push(`# ${gitUrl.name}
831
+ `);
832
+ }
833
+ rows.push("## Projects\n");
834
+ for (const project of projects) {
835
+ const p = path7.relative(cwd2, project.rootDirRealPath);
836
+ p && rows.push(`- [${project.manifest.name}](${p}) ${project.manifest.description ? `- ${project.manifest.description}` : ""}`);
837
+ }
838
+ if (gitUrl) {
839
+ rows.push("\n## Contributing\n");
840
+ rows.push("Contributions Welcome! You can contribute in the following ways.");
841
+ rows.push("");
842
+ rows.push("- Create an Issue - Propose a new feature. Report a bug.");
843
+ rows.push("- Pull Request - Fix a bug and typo. Refactor the code.");
844
+ rows.push("- Create third-party middleware - Instruct below.");
845
+ rows.push("- Share - Share your thoughts on the Blog, X, and others.");
846
+ rows.push(`- Make your application - Please try to use ${gitUrl.name}.`);
847
+ rows.push("");
848
+ rows.push("For more details, see [CONTRIBUTING.md](CONTRIBUTING.md).");
849
+ rows.push("\n## Contributors\n");
850
+ rows.push(`Thanks to [all contributors](https://github.com/${gitUrl.full_name}/graphs/contributors)!`);
851
+ }
852
+ rows.push("\n## Authors\n");
853
+ rows.push(`${gitUser.name} <${gitUser.email}>`);
854
+ rows.push("\n## License\n");
855
+ rows.push("Distributed under the MIT License. See [LICENSE](LICENSE) for more information.");
856
+ return rows;
857
+ }
858
+ async function setReadme_default(ctx) {
859
+ const rows = await getRows(ctx);
860
+ await fs5.writeFile(path7.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
861
+ `);
862
+ }
863
+
864
+ // src/monorepo/init.ts
865
+ async function init(cwd2) {
866
+ const ctx = await createContext(cwd2);
867
+ await setPkgJson_default(ctx);
868
+ await setReadme_default(ctx);
869
+ }
870
+
871
+ // src/monorepo/sync.ts
872
+ init_esm_shims();
873
+ import os from "node:os";
874
+ import { execa } from "execa";
875
+ import PQueue2 from "p-queue";
876
+ import pc2 from "picocolors";
877
+ async function syncNpmMirror(cwd2) {
878
+ const packages = await getWorkspacePackages(cwd2);
879
+ const set4 = new Set(packages.map((x) => x.manifest.name));
880
+ logger.info(`[\u5373\u5C06\u540C\u6B65\u7684\u5305]:
881
+ ${Array.from(set4).map((x) => `- ${pc2.green(x)}`).join("\n")}
882
+ `);
883
+ const concurrency = Math.max(os.cpus().length, 1);
884
+ const queue2 = new PQueue2({ concurrency });
885
+ for (const pkgName of set4) {
886
+ if (pkgName) {
887
+ await queue2.add(async () => {
888
+ return execa({
889
+ stdout: ["pipe", "inherit"]
890
+ })`cnpm sync ${pkgName}`;
891
+ });
892
+ }
893
+ }
894
+ }
895
+
896
+ // src/monorepo/index.ts
897
+ init_esm_shims();
898
+
899
+ export {
900
+ name,
901
+ version,
902
+ init_esm_shims,
903
+ logger,
904
+ GitClient,
905
+ getFileHash,
906
+ isFileChanged,
907
+ escapeStringRegexp,
908
+ isMatch,
909
+ setPkgJson,
910
+ upgradeMonorepo,
911
+ createNewProject,
912
+ setVscodeBinaryMirror,
913
+ cleanProjects,
914
+ getWorkspacePackages,
915
+ init,
916
+ syncNpmMirror
917
+ };
918
+ /*! Bundled license information:
919
+
920
+ isobject/index.js:
921
+ (*!
922
+ * isobject <https://github.com/jonschlinkert/isobject>
923
+ *
924
+ * Copyright (c) 2014-2017, Jon Schlinkert.
925
+ * Released under the MIT License.
926
+ *)
927
+
928
+ get-value/index.js:
929
+ (*!
930
+ * get-value <https://github.com/jonschlinkert/get-value>
931
+ *
932
+ * Copyright (c) 2014-2018, Jon Schlinkert.
933
+ * Released under the MIT License.
934
+ *)
935
+
936
+ is-primitive/index.js:
937
+ (*!
938
+ * is-primitive <https://github.com/jonschlinkert/is-primitive>
939
+ *
940
+ * Copyright (c) 2014-present, Jon Schlinkert.
941
+ * Released under the MIT License.
942
+ *)
943
+
944
+ is-plain-object/index.js:
945
+ (*!
946
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
947
+ *
948
+ * Copyright (c) 2014-2017, Jon Schlinkert.
949
+ * Released under the MIT License.
950
+ *)
951
+
952
+ set-value/index.js:
953
+ (*!
954
+ * set-value <https://github.com/jonschlinkert/set-value>
955
+ *
956
+ * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
957
+ * Released under the MIT License.
958
+ *)
959
+ */