@icebreakers/monorepo 0.6.1 → 0.6.3
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/package.json +5 -5
- package/dist/{chunk-R6F2U4ML.js → chunk-36LZD73K.js} +37 -25
- package/dist/cli.cjs +123 -35
- package/dist/cli.js +88 -12
- package/dist/index.cjs +48 -35
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/package.json +1 -1
package/assets/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"version": "0.0.0",
|
|
5
5
|
"private": true,
|
|
6
|
-
"packageManager": "pnpm@9.12.
|
|
6
|
+
"packageManager": "pnpm@9.12.1",
|
|
7
7
|
"author": "ice breaker <1324318532@qq.com>",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@commitlint/config-conventional": "^19.5.0",
|
|
39
39
|
"@commitlint/prompt-cli": "^19.5.0",
|
|
40
40
|
"@commitlint/types": "^19.5.0",
|
|
41
|
-
"@icebreakers/eslint-config": "^0.
|
|
41
|
+
"@icebreakers/eslint-config": "^0.6.0",
|
|
42
42
|
"@icebreakers/monorepo": "workspace:*",
|
|
43
43
|
"@icebreakers/stylelint-config": "^0.1.1",
|
|
44
44
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/lodash": "^4.17.10",
|
|
47
47
|
"@types/lodash-es": "^4.17.12",
|
|
48
48
|
"@types/micromatch": "^4.0.9",
|
|
49
|
-
"@types/node": "^22.7.
|
|
49
|
+
"@types/node": "^22.7.5",
|
|
50
50
|
"@vitest/coverage-v8": "~2.0.5",
|
|
51
51
|
"ci-info": "^4.0.0",
|
|
52
52
|
"cross-env": "^7.0.3",
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
"micromatch": "^4.0.8",
|
|
62
62
|
"only-allow": "^1.2.1",
|
|
63
63
|
"pathe": "^1.1.2",
|
|
64
|
-
"pkg-types": "^1.2.
|
|
64
|
+
"pkg-types": "^1.2.1",
|
|
65
65
|
"rimraf": "^6.0.1",
|
|
66
66
|
"tslib": "^2.7.0",
|
|
67
67
|
"tsup": "^8.3.0",
|
|
68
68
|
"tsx": "^4.19.1",
|
|
69
69
|
"turbo": "^2.1.3",
|
|
70
|
-
"typescript": "^5.6.
|
|
70
|
+
"typescript": "^5.6.3",
|
|
71
71
|
"unbuild": "^2.0.0",
|
|
72
72
|
"vitest": "~2.0.5",
|
|
73
73
|
"yaml": "^2.5.1"
|
|
@@ -13,30 +13,12 @@ import set from "set-value";
|
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var name = "@icebreakers/monorepo";
|
|
16
|
-
var version = "0.6.
|
|
16
|
+
var version = "0.6.3";
|
|
17
17
|
|
|
18
18
|
// src/logger.ts
|
|
19
19
|
import { createConsola } from "consola";
|
|
20
20
|
var logger = createConsola();
|
|
21
21
|
|
|
22
|
-
// src/md5.ts
|
|
23
|
-
import crypto from "node:crypto";
|
|
24
|
-
function getFileHash(data) {
|
|
25
|
-
const hashSum = crypto.createHash("md5");
|
|
26
|
-
hashSum.update(data);
|
|
27
|
-
return hashSum.digest("hex");
|
|
28
|
-
}
|
|
29
|
-
function isFileChanged(src, dest) {
|
|
30
|
-
try {
|
|
31
|
-
const currentHash = getFileHash(src);
|
|
32
|
-
const previousHash = getFileHash(dest);
|
|
33
|
-
return currentHash !== previousHash;
|
|
34
|
-
} catch (err) {
|
|
35
|
-
console.error("Error calculating file hash:", err);
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
22
|
// src/monorepo/git.ts
|
|
41
23
|
import get from "get-value";
|
|
42
24
|
import gitUrlParse from "git-url-parse";
|
|
@@ -129,7 +111,25 @@ function getAssetTargets(raw) {
|
|
|
129
111
|
return list;
|
|
130
112
|
}
|
|
131
113
|
|
|
132
|
-
// src/utils.ts
|
|
114
|
+
// src/utils/md5.ts
|
|
115
|
+
import crypto from "node:crypto";
|
|
116
|
+
function getFileHash(data) {
|
|
117
|
+
const hashSum = crypto.createHash("md5");
|
|
118
|
+
hashSum.update(data);
|
|
119
|
+
return hashSum.digest("hex");
|
|
120
|
+
}
|
|
121
|
+
function isFileChanged(src, dest) {
|
|
122
|
+
try {
|
|
123
|
+
const currentHash = getFileHash(src);
|
|
124
|
+
const previousHash = getFileHash(dest);
|
|
125
|
+
return currentHash !== previousHash;
|
|
126
|
+
} catch (err) {
|
|
127
|
+
console.error("Error calculating file hash:", err);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/utils/regexp.ts
|
|
133
133
|
function escapeStringRegexp(str) {
|
|
134
134
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
135
135
|
}
|
|
@@ -149,19 +149,31 @@ var __dirname2 = path.dirname(__filename2);
|
|
|
149
149
|
var assetsDir = path.join(__dirname2, "../assets");
|
|
150
150
|
var templatesDir = path.join(__dirname2, "../templates");
|
|
151
151
|
var cwd = process.cwd();
|
|
152
|
+
function isWorkspace(version2) {
|
|
153
|
+
if (typeof version2 === "string") {
|
|
154
|
+
return version2.startsWith("workspace:");
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
152
158
|
function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
153
159
|
const packageManager = get2(sourcePkgJson, "packageManager", { default: "" });
|
|
154
160
|
const deps = get2(sourcePkgJson, "dependencies", { default: {} });
|
|
155
161
|
const devDeps = get2(sourcePkgJson, "devDependencies", { default: {} });
|
|
162
|
+
const targetDeps = get2(targetPkgJson, "dependencies", { default: {} });
|
|
163
|
+
const targetDevDeps = get2(targetPkgJson, "devDependencies", { default: {} });
|
|
156
164
|
set(targetPkgJson, "packageManager", packageManager);
|
|
157
165
|
Object.entries(deps).forEach((x) => {
|
|
158
|
-
|
|
166
|
+
if (!isWorkspace(targetDeps[x[0]])) {
|
|
167
|
+
set(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
168
|
+
}
|
|
159
169
|
});
|
|
160
170
|
Object.entries(devDeps).forEach((x) => {
|
|
161
|
-
if (x[0] ===
|
|
171
|
+
if (x[0] === name) {
|
|
162
172
|
set(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
|
|
163
173
|
} else {
|
|
164
|
-
|
|
174
|
+
if (!isWorkspace(targetDevDeps[x[0]])) {
|
|
175
|
+
set(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
176
|
+
}
|
|
165
177
|
}
|
|
166
178
|
});
|
|
167
179
|
for (const [k, v] of scriptsEntries) {
|
|
@@ -171,7 +183,7 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
|
171
183
|
function confirmOverwrite(filename) {
|
|
172
184
|
return confirm({ message: `${pc.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
|
|
173
185
|
}
|
|
174
|
-
async function
|
|
186
|
+
async function upgradeMonorepo(opts) {
|
|
175
187
|
const { outDir = "", raw, interactive } = opts;
|
|
176
188
|
const absOutDir = path.isAbsolute(outDir) ? outDir : path.join(cwd, outDir);
|
|
177
189
|
const gitClient = new GitClient({
|
|
@@ -262,6 +274,6 @@ export {
|
|
|
262
274
|
logger,
|
|
263
275
|
GitClient,
|
|
264
276
|
setPkgJson,
|
|
265
|
-
|
|
277
|
+
upgradeMonorepo,
|
|
266
278
|
createNewProject
|
|
267
279
|
};
|
package/dist/cli.cjs
CHANGED
|
@@ -22,7 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
|
|
25
|
-
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.3.1_postcss@8.4.47_tsx@4.19.1_typescript@5.6.
|
|
25
|
+
// ../../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/cjs_shims.js
|
|
26
26
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
27
27
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ var import_commander = require("commander");
|
|
|
32
32
|
|
|
33
33
|
// package.json
|
|
34
34
|
var name = "@icebreakers/monorepo";
|
|
35
|
-
var version = "0.6.
|
|
35
|
+
var version = "0.6.3";
|
|
36
36
|
|
|
37
37
|
// src/lib.ts
|
|
38
38
|
var import_node_process = __toESM(require("process"), 1);
|
|
@@ -51,24 +51,6 @@ var import_set_value = __toESM(require("set-value"), 1);
|
|
|
51
51
|
var import_consola = require("consola");
|
|
52
52
|
var logger = (0, import_consola.createConsola)();
|
|
53
53
|
|
|
54
|
-
// src/md5.ts
|
|
55
|
-
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
56
|
-
function getFileHash(data) {
|
|
57
|
-
const hashSum = import_node_crypto.default.createHash("md5");
|
|
58
|
-
hashSum.update(data);
|
|
59
|
-
return hashSum.digest("hex");
|
|
60
|
-
}
|
|
61
|
-
function isFileChanged(src, dest) {
|
|
62
|
-
try {
|
|
63
|
-
const currentHash = getFileHash(src);
|
|
64
|
-
const previousHash = getFileHash(dest);
|
|
65
|
-
return currentHash !== previousHash;
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.error("Error calculating file hash:", err);
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
54
|
// src/monorepo/git.ts
|
|
73
55
|
var import_get_value = __toESM(require("get-value"), 1);
|
|
74
56
|
var import_git_url_parse = __toESM(require("git-url-parse"), 1);
|
|
@@ -161,7 +143,25 @@ function getAssetTargets(raw) {
|
|
|
161
143
|
return list;
|
|
162
144
|
}
|
|
163
145
|
|
|
164
|
-
// src/utils.ts
|
|
146
|
+
// src/utils/md5.ts
|
|
147
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
148
|
+
function getFileHash(data) {
|
|
149
|
+
const hashSum = import_node_crypto.default.createHash("md5");
|
|
150
|
+
hashSum.update(data);
|
|
151
|
+
return hashSum.digest("hex");
|
|
152
|
+
}
|
|
153
|
+
function isFileChanged(src, dest) {
|
|
154
|
+
try {
|
|
155
|
+
const currentHash = getFileHash(src);
|
|
156
|
+
const previousHash = getFileHash(dest);
|
|
157
|
+
return currentHash !== previousHash;
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.error("Error calculating file hash:", err);
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/utils/regexp.ts
|
|
165
165
|
function escapeStringRegexp(str) {
|
|
166
166
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
167
167
|
}
|
|
@@ -181,19 +181,31 @@ var __dirname = import_pathe.default.dirname(__filename2);
|
|
|
181
181
|
var assetsDir = import_pathe.default.join(__dirname, "../assets");
|
|
182
182
|
var templatesDir = import_pathe.default.join(__dirname, "../templates");
|
|
183
183
|
var cwd = import_node_process.default.cwd();
|
|
184
|
+
function isWorkspace(version2) {
|
|
185
|
+
if (typeof version2 === "string") {
|
|
186
|
+
return version2.startsWith("workspace:");
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
184
190
|
function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
185
191
|
const packageManager = (0, import_get_value2.default)(sourcePkgJson, "packageManager", { default: "" });
|
|
186
192
|
const deps = (0, import_get_value2.default)(sourcePkgJson, "dependencies", { default: {} });
|
|
187
193
|
const devDeps = (0, import_get_value2.default)(sourcePkgJson, "devDependencies", { default: {} });
|
|
194
|
+
const targetDeps = (0, import_get_value2.default)(targetPkgJson, "dependencies", { default: {} });
|
|
195
|
+
const targetDevDeps = (0, import_get_value2.default)(targetPkgJson, "devDependencies", { default: {} });
|
|
188
196
|
(0, import_set_value.default)(targetPkgJson, "packageManager", packageManager);
|
|
189
197
|
Object.entries(deps).forEach((x) => {
|
|
190
|
-
|
|
198
|
+
if (!isWorkspace(targetDeps[x[0]])) {
|
|
199
|
+
(0, import_set_value.default)(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
200
|
+
}
|
|
191
201
|
});
|
|
192
202
|
Object.entries(devDeps).forEach((x) => {
|
|
193
|
-
if (x[0] ===
|
|
203
|
+
if (x[0] === name) {
|
|
194
204
|
(0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
|
|
195
205
|
} else {
|
|
196
|
-
|
|
206
|
+
if (!isWorkspace(targetDevDeps[x[0]])) {
|
|
207
|
+
(0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
208
|
+
}
|
|
197
209
|
}
|
|
198
210
|
});
|
|
199
211
|
for (const [k, v] of scriptsEntries) {
|
|
@@ -203,7 +215,7 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
|
203
215
|
function confirmOverwrite(filename) {
|
|
204
216
|
return (0, import_confirm.default)({ message: `${import_picocolors.default.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
|
|
205
217
|
}
|
|
206
|
-
async function
|
|
218
|
+
async function upgradeMonorepo(opts) {
|
|
207
219
|
const { outDir = "", raw, interactive } = opts;
|
|
208
220
|
const absOutDir = import_pathe.default.isAbsolute(outDir) ? outDir : import_pathe.default.join(cwd, outDir);
|
|
209
221
|
const gitClient = new GitClient({
|
|
@@ -293,9 +305,6 @@ var import_comment_json = require("comment-json");
|
|
|
293
305
|
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
294
306
|
var import_pathe2 = __toESM(require("pathe"), 1);
|
|
295
307
|
|
|
296
|
-
// src/monorepo/mirror/utils.ts
|
|
297
|
-
var import_set_value2 = __toESM(require("set-value"), 1);
|
|
298
|
-
|
|
299
308
|
// src/monorepo/mirror/sources.ts
|
|
300
309
|
var chinaMirrorsEnvs = {
|
|
301
310
|
COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
|
|
@@ -327,6 +336,7 @@ var chinaMirrorsEnvs = {
|
|
|
327
336
|
};
|
|
328
337
|
|
|
329
338
|
// src/monorepo/mirror/utils.ts
|
|
339
|
+
var import_set_value2 = __toESM(require("set-value"), 1);
|
|
330
340
|
function setMirror(obj) {
|
|
331
341
|
const platforms = ["linux", "windows", "osx"];
|
|
332
342
|
const prefix = "terminal.integrated.env";
|
|
@@ -368,20 +378,98 @@ var import_pathe5 = __toESM(require("pathe"), 1);
|
|
|
368
378
|
|
|
369
379
|
// src/monorepo/utils.ts
|
|
370
380
|
var import_workspace = require("@pnpm/workspace.find-packages");
|
|
381
|
+
|
|
382
|
+
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
383
|
+
function isPlainObject(value) {
|
|
384
|
+
if (value === null || typeof value !== "object") {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
const prototype = Object.getPrototypeOf(value);
|
|
388
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
if (Symbol.iterator in value) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
if (Symbol.toStringTag in value) {
|
|
395
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
396
|
+
}
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
400
|
+
if (!isPlainObject(defaults)) {
|
|
401
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
402
|
+
}
|
|
403
|
+
const object = Object.assign({}, defaults);
|
|
404
|
+
for (const key in baseObject) {
|
|
405
|
+
if (key === "__proto__" || key === "constructor") {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const value = baseObject[key];
|
|
409
|
+
if (value === null || value === void 0) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
416
|
+
object[key] = [...value, ...object[key]];
|
|
417
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
418
|
+
object[key] = _defu(
|
|
419
|
+
value,
|
|
420
|
+
object[key],
|
|
421
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
422
|
+
merger
|
|
423
|
+
);
|
|
424
|
+
} else {
|
|
425
|
+
object[key] = value;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return object;
|
|
429
|
+
}
|
|
430
|
+
function createDefu(merger) {
|
|
431
|
+
return (...arguments_) => (
|
|
432
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
433
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
var defu = createDefu();
|
|
437
|
+
var defuFn = createDefu((object, key, currentValue) => {
|
|
438
|
+
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
439
|
+
object[key] = currentValue(object[key]);
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
444
|
+
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
445
|
+
object[key] = currentValue(object[key]);
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// src/monorepo/utils.ts
|
|
371
451
|
var import_pathe4 = __toESM(require("pathe"), 1);
|
|
372
|
-
async function getWorkspacePackages(cwd3) {
|
|
452
|
+
async function getWorkspacePackages(cwd3, options) {
|
|
453
|
+
const posixCwd = import_pathe4.default.normalize(cwd3);
|
|
454
|
+
const { ignoreRootPackage } = defu(options, {
|
|
455
|
+
ignoreRootPackage: true
|
|
456
|
+
});
|
|
373
457
|
const packages = await (0, import_workspace.findWorkspacePackages)(cwd3);
|
|
374
|
-
|
|
458
|
+
let pkgs = packages.map((project) => {
|
|
375
459
|
const pkgJsonPath = import_pathe4.default.resolve(project.rootDir, "package.json");
|
|
376
460
|
return {
|
|
377
461
|
...project,
|
|
378
462
|
pkgJsonPath
|
|
379
463
|
};
|
|
380
|
-
}))).filter((x) => {
|
|
381
|
-
return x.status === "fulfilled";
|
|
382
|
-
}).map((x) => {
|
|
383
|
-
return x.value;
|
|
384
464
|
});
|
|
465
|
+
if (ignoreRootPackage) {
|
|
466
|
+
pkgs = pkgs.filter((x) => {
|
|
467
|
+
return import_pathe4.default.normalize(
|
|
468
|
+
x.rootDir
|
|
469
|
+
) !== posixCwd;
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return pkgs;
|
|
385
473
|
}
|
|
386
474
|
|
|
387
475
|
// src/monorepo/context.ts
|
|
@@ -496,7 +584,7 @@ async function syncNpmMirror(cwd3) {
|
|
|
496
584
|
var cwd2 = import_node_process2.default.cwd();
|
|
497
585
|
import_commander.program.name(name).version(version);
|
|
498
586
|
import_commander.program.option("-i,--interactive").option("--raw", "raw mode").option("--outDir <dir>", "Output directory").action(async (opts) => {
|
|
499
|
-
await
|
|
587
|
+
await upgradeMonorepo(opts);
|
|
500
588
|
logger.success("upgrade @icebreakers/monorepo ok!");
|
|
501
589
|
});
|
|
502
590
|
import_commander.program.command("init").action(async () => {
|
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
GitClient,
|
|
3
3
|
createNewProject,
|
|
4
4
|
logger,
|
|
5
|
-
main,
|
|
6
5
|
name,
|
|
6
|
+
upgradeMonorepo,
|
|
7
7
|
version
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-36LZD73K.js";
|
|
9
9
|
|
|
10
10
|
// src/program.ts
|
|
11
11
|
import process from "node:process";
|
|
@@ -16,9 +16,6 @@ import { parse, stringify } from "comment-json";
|
|
|
16
16
|
import fs from "fs-extra";
|
|
17
17
|
import path from "pathe";
|
|
18
18
|
|
|
19
|
-
// src/monorepo/mirror/utils.ts
|
|
20
|
-
import set from "set-value";
|
|
21
|
-
|
|
22
19
|
// src/monorepo/mirror/sources.ts
|
|
23
20
|
var chinaMirrorsEnvs = {
|
|
24
21
|
COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
|
|
@@ -50,6 +47,7 @@ var chinaMirrorsEnvs = {
|
|
|
50
47
|
};
|
|
51
48
|
|
|
52
49
|
// src/monorepo/mirror/utils.ts
|
|
50
|
+
import set from "set-value";
|
|
53
51
|
function setMirror(obj) {
|
|
54
52
|
const platforms = ["linux", "windows", "osx"];
|
|
55
53
|
const prefix = "terminal.integrated.env";
|
|
@@ -91,20 +89,98 @@ import path4 from "pathe";
|
|
|
91
89
|
|
|
92
90
|
// src/monorepo/utils.ts
|
|
93
91
|
import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
|
|
92
|
+
|
|
93
|
+
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
94
|
+
function isPlainObject(value) {
|
|
95
|
+
if (value === null || typeof value !== "object") {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const prototype = Object.getPrototypeOf(value);
|
|
99
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (Symbol.iterator in value) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (Symbol.toStringTag in value) {
|
|
106
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
111
|
+
if (!isPlainObject(defaults)) {
|
|
112
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
113
|
+
}
|
|
114
|
+
const object = Object.assign({}, defaults);
|
|
115
|
+
for (const key in baseObject) {
|
|
116
|
+
if (key === "__proto__" || key === "constructor") {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const value = baseObject[key];
|
|
120
|
+
if (value === null || value === void 0) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
127
|
+
object[key] = [...value, ...object[key]];
|
|
128
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
129
|
+
object[key] = _defu(
|
|
130
|
+
value,
|
|
131
|
+
object[key],
|
|
132
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
133
|
+
merger
|
|
134
|
+
);
|
|
135
|
+
} else {
|
|
136
|
+
object[key] = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return object;
|
|
140
|
+
}
|
|
141
|
+
function createDefu(merger) {
|
|
142
|
+
return (...arguments_) => (
|
|
143
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
144
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
var defu = createDefu();
|
|
148
|
+
var defuFn = createDefu((object, key, currentValue) => {
|
|
149
|
+
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
150
|
+
object[key] = currentValue(object[key]);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
155
|
+
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
156
|
+
object[key] = currentValue(object[key]);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// src/monorepo/utils.ts
|
|
94
162
|
import path3 from "pathe";
|
|
95
|
-
async function getWorkspacePackages(cwd2) {
|
|
163
|
+
async function getWorkspacePackages(cwd2, options) {
|
|
164
|
+
const posixCwd = path3.normalize(cwd2);
|
|
165
|
+
const { ignoreRootPackage } = defu(options, {
|
|
166
|
+
ignoreRootPackage: true
|
|
167
|
+
});
|
|
96
168
|
const packages = await findWorkspacePackages(cwd2);
|
|
97
|
-
|
|
169
|
+
let pkgs = packages.map((project) => {
|
|
98
170
|
const pkgJsonPath = path3.resolve(project.rootDir, "package.json");
|
|
99
171
|
return {
|
|
100
172
|
...project,
|
|
101
173
|
pkgJsonPath
|
|
102
174
|
};
|
|
103
|
-
}))).filter((x) => {
|
|
104
|
-
return x.status === "fulfilled";
|
|
105
|
-
}).map((x) => {
|
|
106
|
-
return x.value;
|
|
107
175
|
});
|
|
176
|
+
if (ignoreRootPackage) {
|
|
177
|
+
pkgs = pkgs.filter((x) => {
|
|
178
|
+
return path3.normalize(
|
|
179
|
+
x.rootDir
|
|
180
|
+
) !== posixCwd;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return pkgs;
|
|
108
184
|
}
|
|
109
185
|
|
|
110
186
|
// src/monorepo/context.ts
|
|
@@ -219,7 +295,7 @@ async function syncNpmMirror(cwd2) {
|
|
|
219
295
|
var cwd = process.cwd();
|
|
220
296
|
program.name(name).version(version);
|
|
221
297
|
program.option("-i,--interactive").option("--raw", "raw mode").option("--outDir <dir>", "Output directory").action(async (opts) => {
|
|
222
|
-
await
|
|
298
|
+
await upgradeMonorepo(opts);
|
|
223
299
|
logger.success("upgrade @icebreakers/monorepo ok!");
|
|
224
300
|
});
|
|
225
301
|
program.command("init").action(async () => {
|
package/dist/index.cjs
CHANGED
|
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -31,12 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
createNewProject: () => createNewProject,
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
setPkgJson: () => setPkgJson,
|
|
35
|
+
upgradeMonorepo: () => upgradeMonorepo
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
|
|
39
|
-
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.3.1_postcss@8.4.47_tsx@4.19.1_typescript@5.6.
|
|
39
|
+
// ../../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/cjs_shims.js
|
|
40
40
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
41
41
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
42
42
|
|
|
@@ -54,30 +54,13 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
54
54
|
var import_set_value = __toESM(require("set-value"), 1);
|
|
55
55
|
|
|
56
56
|
// package.json
|
|
57
|
-
var
|
|
57
|
+
var name = "@icebreakers/monorepo";
|
|
58
|
+
var version = "0.6.3";
|
|
58
59
|
|
|
59
60
|
// src/logger.ts
|
|
60
61
|
var import_consola = require("consola");
|
|
61
62
|
var logger = (0, import_consola.createConsola)();
|
|
62
63
|
|
|
63
|
-
// src/md5.ts
|
|
64
|
-
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
65
|
-
function getFileHash(data) {
|
|
66
|
-
const hashSum = import_node_crypto.default.createHash("md5");
|
|
67
|
-
hashSum.update(data);
|
|
68
|
-
return hashSum.digest("hex");
|
|
69
|
-
}
|
|
70
|
-
function isFileChanged(src, dest) {
|
|
71
|
-
try {
|
|
72
|
-
const currentHash = getFileHash(src);
|
|
73
|
-
const previousHash = getFileHash(dest);
|
|
74
|
-
return currentHash !== previousHash;
|
|
75
|
-
} catch (err) {
|
|
76
|
-
console.error("Error calculating file hash:", err);
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
64
|
// src/monorepo/git.ts
|
|
82
65
|
var import_get_value = __toESM(require("get-value"), 1);
|
|
83
66
|
var import_git_url_parse = __toESM(require("git-url-parse"), 1);
|
|
@@ -118,10 +101,10 @@ var GitClient = class {
|
|
|
118
101
|
}
|
|
119
102
|
async getUser() {
|
|
120
103
|
const config = await this.getConfig();
|
|
121
|
-
const
|
|
104
|
+
const name2 = (0, import_get_value.default)(config, "user.name");
|
|
122
105
|
const email = (0, import_get_value.default)(config, "user.email");
|
|
123
106
|
return {
|
|
124
|
-
name,
|
|
107
|
+
name: name2,
|
|
125
108
|
email
|
|
126
109
|
};
|
|
127
110
|
}
|
|
@@ -170,7 +153,25 @@ function getAssetTargets(raw) {
|
|
|
170
153
|
return list;
|
|
171
154
|
}
|
|
172
155
|
|
|
173
|
-
// src/utils.ts
|
|
156
|
+
// src/utils/md5.ts
|
|
157
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
158
|
+
function getFileHash(data) {
|
|
159
|
+
const hashSum = import_node_crypto.default.createHash("md5");
|
|
160
|
+
hashSum.update(data);
|
|
161
|
+
return hashSum.digest("hex");
|
|
162
|
+
}
|
|
163
|
+
function isFileChanged(src, dest) {
|
|
164
|
+
try {
|
|
165
|
+
const currentHash = getFileHash(src);
|
|
166
|
+
const previousHash = getFileHash(dest);
|
|
167
|
+
return currentHash !== previousHash;
|
|
168
|
+
} catch (err) {
|
|
169
|
+
console.error("Error calculating file hash:", err);
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/utils/regexp.ts
|
|
174
175
|
function escapeStringRegexp(str) {
|
|
175
176
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
176
177
|
}
|
|
@@ -190,19 +191,31 @@ var __dirname = import_pathe.default.dirname(__filename2);
|
|
|
190
191
|
var assetsDir = import_pathe.default.join(__dirname, "../assets");
|
|
191
192
|
var templatesDir = import_pathe.default.join(__dirname, "../templates");
|
|
192
193
|
var cwd = import_node_process.default.cwd();
|
|
194
|
+
function isWorkspace(version2) {
|
|
195
|
+
if (typeof version2 === "string") {
|
|
196
|
+
return version2.startsWith("workspace:");
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
193
200
|
function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
194
201
|
const packageManager = (0, import_get_value2.default)(sourcePkgJson, "packageManager", { default: "" });
|
|
195
202
|
const deps = (0, import_get_value2.default)(sourcePkgJson, "dependencies", { default: {} });
|
|
196
203
|
const devDeps = (0, import_get_value2.default)(sourcePkgJson, "devDependencies", { default: {} });
|
|
204
|
+
const targetDeps = (0, import_get_value2.default)(targetPkgJson, "dependencies", { default: {} });
|
|
205
|
+
const targetDevDeps = (0, import_get_value2.default)(targetPkgJson, "devDependencies", { default: {} });
|
|
197
206
|
(0, import_set_value.default)(targetPkgJson, "packageManager", packageManager);
|
|
198
207
|
Object.entries(deps).forEach((x) => {
|
|
199
|
-
|
|
208
|
+
if (!isWorkspace(targetDeps[x[0]])) {
|
|
209
|
+
(0, import_set_value.default)(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
210
|
+
}
|
|
200
211
|
});
|
|
201
212
|
Object.entries(devDeps).forEach((x) => {
|
|
202
|
-
if (x[0] ===
|
|
213
|
+
if (x[0] === name) {
|
|
203
214
|
(0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
|
|
204
215
|
} else {
|
|
205
|
-
|
|
216
|
+
if (!isWorkspace(targetDevDeps[x[0]])) {
|
|
217
|
+
(0, import_set_value.default)(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
|
|
218
|
+
}
|
|
206
219
|
}
|
|
207
220
|
});
|
|
208
221
|
for (const [k, v] of scriptsEntries) {
|
|
@@ -212,7 +225,7 @@ function setPkgJson(sourcePkgJson, targetPkgJson) {
|
|
|
212
225
|
function confirmOverwrite(filename) {
|
|
213
226
|
return (0, import_confirm.default)({ message: `${import_picocolors.default.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
|
|
214
227
|
}
|
|
215
|
-
async function
|
|
228
|
+
async function upgradeMonorepo(opts) {
|
|
216
229
|
const { outDir = "", raw, interactive } = opts;
|
|
217
230
|
const absOutDir = import_pathe.default.isAbsolute(outDir) ? outDir : import_pathe.default.join(cwd, outDir);
|
|
218
231
|
const gitClient = new GitClient({
|
|
@@ -290,15 +303,15 @@ async function main(opts) {
|
|
|
290
303
|
});
|
|
291
304
|
}
|
|
292
305
|
}
|
|
293
|
-
async function createNewProject(
|
|
306
|
+
async function createNewProject(name2) {
|
|
294
307
|
const defaultTemplate = "bar";
|
|
295
|
-
const targetTemplate =
|
|
308
|
+
const targetTemplate = name2 ?? defaultTemplate;
|
|
296
309
|
await import_fs_extra.default.copy(import_pathe.default.join(templatesDir, defaultTemplate), import_pathe.default.join(cwd, targetTemplate));
|
|
297
310
|
logger.success(`${targetTemplate} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01`);
|
|
298
311
|
}
|
|
299
312
|
// Annotate the CommonJS export names for ESM import in node:
|
|
300
313
|
0 && (module.exports = {
|
|
301
314
|
createNewProject,
|
|
302
|
-
|
|
303
|
-
|
|
315
|
+
setPkgJson,
|
|
316
|
+
upgradeMonorepo
|
|
304
317
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ interface CliOpts {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
declare function setPkgJson(sourcePkgJson: PackageJson, targetPkgJson: PackageJson): void;
|
|
10
|
-
declare function
|
|
10
|
+
declare function upgradeMonorepo(opts: CliOpts): Promise<void>;
|
|
11
11
|
declare function createNewProject(name?: string): Promise<void>;
|
|
12
12
|
|
|
13
|
-
export { createNewProject,
|
|
13
|
+
export { createNewProject, setPkgJson, upgradeMonorepo };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ interface CliOpts {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
declare function setPkgJson(sourcePkgJson: PackageJson, targetPkgJson: PackageJson): void;
|
|
10
|
-
declare function
|
|
10
|
+
declare function upgradeMonorepo(opts: CliOpts): Promise<void>;
|
|
11
11
|
declare function createNewProject(name?: string): Promise<void>;
|
|
12
12
|
|
|
13
|
-
export { createNewProject,
|
|
13
|
+
export { createNewProject, setPkgJson, upgradeMonorepo };
|
package/dist/index.js
CHANGED