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