@icebreakers/monorepo 3.2.3 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +301 -1
- package/dist/index.d.mts +301 -1
- package/dist/index.mjs +1 -1
- package/dist/{upgrade-vYYDUbQa.cjs → upgrade-8GwhbF6K.cjs} +65 -65
- package/dist/{upgrade-B_Pvjblg.mjs → upgrade-CVZ1525B.mjs} +85 -85
- package/package.json +4 -4
|
@@ -72,9 +72,9 @@ var join = /* @__PURE__ */ __name((segs, joinChar, options) => {
|
|
|
72
72
|
if (typeof options.join === "function") return options.join(segs);
|
|
73
73
|
return segs[0] + joinChar + segs[1];
|
|
74
74
|
}, "join");
|
|
75
|
-
var split = /* @__PURE__ */ __name((path
|
|
76
|
-
if (typeof options.split === "function") return options.split(path
|
|
77
|
-
return path
|
|
75
|
+
var split = /* @__PURE__ */ __name((path, splitChar, options) => {
|
|
76
|
+
if (typeof options.split === "function") return options.split(path);
|
|
77
|
+
return path.split(splitChar);
|
|
78
78
|
}, "split");
|
|
79
79
|
var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
|
|
80
80
|
if (typeof options?.isValid === "function") return options.isValid(key, target);
|
|
@@ -83,17 +83,17 @@ var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
|
|
|
83
83
|
var isValidObject = /* @__PURE__ */ __name((v) => {
|
|
84
84
|
return isObject(v) || typeof v === "function";
|
|
85
85
|
}, "isValidObject");
|
|
86
|
-
var index_default = /* @__PURE__ */ __name((target, path
|
|
86
|
+
var index_default = /* @__PURE__ */ __name((target, path, options = {}) => {
|
|
87
87
|
if (!isObject(options)) options = { default: options };
|
|
88
88
|
if (!isValidObject(target)) return typeof options.default !== "undefined" ? options.default : target;
|
|
89
|
-
if (typeof path
|
|
90
|
-
const pathIsArray = Array.isArray(path
|
|
91
|
-
const pathIsString = typeof path
|
|
89
|
+
if (typeof path === "number") path = String(path);
|
|
90
|
+
const pathIsArray = Array.isArray(path);
|
|
91
|
+
const pathIsString = typeof path === "string";
|
|
92
92
|
const splitChar = options.separator || ".";
|
|
93
93
|
const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
|
|
94
94
|
if (!pathIsString && !pathIsArray) return target;
|
|
95
|
-
if (target[path
|
|
96
|
-
const segs = pathIsArray ? path
|
|
95
|
+
if (target[path] !== void 0) return isValid(path, target, options) ? target[path] : options.default;
|
|
96
|
+
const segs = pathIsArray ? path : split(path, splitChar, options);
|
|
97
97
|
const len = segs.length;
|
|
98
98
|
let idx = 0;
|
|
99
99
|
do {
|
|
@@ -378,7 +378,7 @@ var require_is_primitive = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
378
378
|
* Released under the MIT License.
|
|
379
379
|
*/
|
|
380
380
|
var require_isobject = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
381
|
-
module.exports = function isObject
|
|
381
|
+
module.exports = function isObject(val) {
|
|
382
382
|
return val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
383
383
|
};
|
|
384
384
|
}));
|
|
@@ -396,7 +396,7 @@ var require_is_plain_object = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
396
396
|
function isObjectObject(o) {
|
|
397
397
|
return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
|
|
398
398
|
}
|
|
399
|
-
module.exports = function isPlainObject
|
|
399
|
+
module.exports = function isPlainObject(o) {
|
|
400
400
|
var ctor, prot;
|
|
401
401
|
if (isObjectObject(o) === false) return false;
|
|
402
402
|
ctor = o.constructor;
|
|
@@ -456,10 +456,10 @@ var require_set_value = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
456
456
|
if (typeof input === "string" && preserve !== false && /\//.test(input)) return [input];
|
|
457
457
|
const parts = [];
|
|
458
458
|
let part = "";
|
|
459
|
-
const push = (part
|
|
459
|
+
const push = (part) => {
|
|
460
460
|
let number;
|
|
461
|
-
if (part
|
|
462
|
-
else parts.push(part
|
|
461
|
+
if (part.trim() !== "" && Number.isInteger(number = Number(part))) parts.push(number);
|
|
462
|
+
else parts.push(part);
|
|
463
463
|
};
|
|
464
464
|
for (let i = 0; i < input.length; i++) {
|
|
465
465
|
const value = input[i];
|
|
@@ -493,9 +493,9 @@ var require_set_value = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
493
493
|
} else obj[prop] = value;
|
|
494
494
|
return obj;
|
|
495
495
|
};
|
|
496
|
-
const setValue = (target, path
|
|
497
|
-
if (!path
|
|
498
|
-
const keys = split(path
|
|
496
|
+
const setValue = (target, path, value, options) => {
|
|
497
|
+
if (!path || !isObject(target)) return target;
|
|
498
|
+
const keys = split(path, options);
|
|
499
499
|
let obj = target;
|
|
500
500
|
for (let i = 0; i < keys.length; i++) {
|
|
501
501
|
const key = keys[i];
|
|
@@ -563,14 +563,14 @@ async function loadMonorepoConfig(cwd) {
|
|
|
563
563
|
/**
|
|
564
564
|
* 获取命令对应的合并配置,若未配置则返回空对象,保证调用端逻辑简单。
|
|
565
565
|
*/
|
|
566
|
-
async function resolveCommandConfig(name
|
|
567
|
-
return ((await loadMonorepoConfig(cwd)).commands ?? {})[name
|
|
566
|
+
async function resolveCommandConfig(name, cwd) {
|
|
567
|
+
return ((await loadMonorepoConfig(cwd)).commands ?? {})[name] ?? {};
|
|
568
568
|
}
|
|
569
569
|
|
|
570
570
|
//#endregion
|
|
571
571
|
//#region package.json
|
|
572
572
|
var name = "@icebreakers/monorepo";
|
|
573
|
-
var version = "3.2.
|
|
573
|
+
var version = "3.2.5";
|
|
574
574
|
|
|
575
575
|
//#endregion
|
|
576
576
|
//#region src/constants.ts
|
|
@@ -652,10 +652,10 @@ async function cleanProjects(cwd, overrides) {
|
|
|
652
652
|
const cleanConfig = mergeCleanConfig(await resolveCommandConfig("clean", cwd), overrides);
|
|
653
653
|
const { packages, workspaceDir } = await getWorkspaceData(cwd, cleanConfig?.includePrivate ?? true ? { ignorePrivatePackage: false } : void 0);
|
|
654
654
|
const filteredPackages = packages.filter((pkg) => {
|
|
655
|
-
const name
|
|
656
|
-
if (!name
|
|
655
|
+
const name = pkg.manifest.name ?? "";
|
|
656
|
+
if (!name) return true;
|
|
657
657
|
if (!cleanConfig?.ignorePackages?.length) return true;
|
|
658
|
-
return !cleanConfig.ignorePackages.includes(name
|
|
658
|
+
return !cleanConfig.ignorePackages.includes(name);
|
|
659
659
|
});
|
|
660
660
|
let cleanDirs = [];
|
|
661
661
|
if (cleanConfig?.autoConfirm) cleanDirs = filteredPackages.map((pkg) => pkg.rootDir);
|
|
@@ -675,20 +675,20 @@ async function cleanProjects(cwd, overrides) {
|
|
|
675
675
|
});
|
|
676
676
|
const readmeZh = pathe.default.resolve(workspaceDir, "README.zh-CN.md");
|
|
677
677
|
const qoderDir = pathe.default.resolve(workspaceDir, ".qoder");
|
|
678
|
-
const skillTargets
|
|
678
|
+
const skillTargets = Object.values(getSkillTargetPaths());
|
|
679
679
|
const candidates = Array.from(new Set([
|
|
680
680
|
...cleanDirs.filter(Boolean),
|
|
681
681
|
readmeZh,
|
|
682
682
|
qoderDir,
|
|
683
|
-
...skillTargets
|
|
683
|
+
...skillTargets
|
|
684
684
|
]));
|
|
685
685
|
await Promise.all(candidates.map(async (dir) => {
|
|
686
686
|
if (await fs_extra.default.pathExists(dir)) await fs_extra.default.remove(dir);
|
|
687
687
|
}));
|
|
688
|
-
const name
|
|
689
|
-
const pkgJson = await fs_extra.default.readJson(name
|
|
688
|
+
const name = pathe.default.resolve(workspaceDir, "package.json");
|
|
689
|
+
const pkgJson = await fs_extra.default.readJson(name);
|
|
690
690
|
(0, import_set_value.default)(pkgJson, "devDependencies.@icebreakers/monorepo", cleanConfig?.pinnedVersion ?? "latest", { preservePaths: false });
|
|
691
|
-
await fs_extra.default.outputJson(name
|
|
691
|
+
await fs_extra.default.outputJson(name, pkgJson, { spaces: 2 });
|
|
692
692
|
}
|
|
693
693
|
|
|
694
694
|
//#endregion
|
|
@@ -816,7 +816,7 @@ async function createNewProject(options) {
|
|
|
816
816
|
const createConfig = await resolveCommandConfig("create", cwd);
|
|
817
817
|
const renameJson = options?.renameJson ?? createConfig?.renameJson ?? false;
|
|
818
818
|
const rawName = options?.name ?? createConfig?.name;
|
|
819
|
-
const name
|
|
819
|
+
const name = typeof rawName === "string" ? rawName.trim() : void 0;
|
|
820
820
|
const requestedTemplate = options?.type ?? createConfig?.type ?? createConfig?.defaultTemplate ?? defaultTemplate;
|
|
821
821
|
const templateDefinitions = getTemplateMap(createConfig?.templateMap);
|
|
822
822
|
const templatesRoot = createConfig?.templatesDir ? pathe.default.resolve(cwd, createConfig.templatesDir) : _icebreakers_monorepo_templates.templatesDir;
|
|
@@ -825,7 +825,7 @@ async function createNewProject(options) {
|
|
|
825
825
|
const templateDefinition = templateDefinitions[bundlerName];
|
|
826
826
|
if (!templateDefinition) throw new Error(`未找到名为 ${bundlerName} 的模板,请检查 monorepo.config.ts`);
|
|
827
827
|
const from = pathe.default.join(templatesRoot, templateDefinition.source);
|
|
828
|
-
const targetName = name
|
|
828
|
+
const targetName = name && name.length > 0 ? name : templateDefinition.target;
|
|
829
829
|
const to = pathe.default.join(cwd, targetName);
|
|
830
830
|
if (await fs_extra.default.pathExists(to)) throw new Error(`${picocolors.default.red("目标目录已存在")}: ${pathe.default.relative(cwd, to)}`);
|
|
831
831
|
await fs_extra.default.ensureDir(to);
|
|
@@ -839,7 +839,7 @@ async function createNewProject(options) {
|
|
|
839
839
|
if (hasPackageJson) {
|
|
840
840
|
const sourceJson = await fs_extra.default.readJson(sourceJsonPath);
|
|
841
841
|
(0, import_set_value.default)(sourceJson, "version", "0.0.0");
|
|
842
|
-
(0, import_set_value.default)(sourceJson, "name", name
|
|
842
|
+
(0, import_set_value.default)(sourceJson, "name", name?.startsWith("@") ? name : pathe.default.basename(targetName));
|
|
843
843
|
await applyGitMetadata(sourceJson, cwd, to);
|
|
844
844
|
await fs_extra.default.outputJson(pathe.default.resolve(to, renameJson ? "package.mock.json" : "package.json"), sourceJson, { spaces: 2 });
|
|
845
845
|
}
|
|
@@ -1154,15 +1154,15 @@ async function syncNpmMirror(cwd, options) {
|
|
|
1154
1154
|
...options ?? {}
|
|
1155
1155
|
});
|
|
1156
1156
|
logger.info(`[当前工作区Repo]:\n${packages.map((x) => `- ${picocolors.default.green(x.manifest.name)} : ${pathe.default.relative(workspaceDir, x.rootDir)}`).join("\n")}\n`);
|
|
1157
|
-
const set
|
|
1157
|
+
const set = new Set(packages.map((x) => x.manifest.name));
|
|
1158
1158
|
if (packageFilter?.length) {
|
|
1159
|
-
for (const name
|
|
1159
|
+
for (const name of Array.from(set)) if (!name || !packageFilter.includes(name)) set.delete(name);
|
|
1160
1160
|
}
|
|
1161
|
-
logger.info(`[即将同步的包]:\n${Array.from(set
|
|
1161
|
+
logger.info(`[即将同步的包]:\n${Array.from(set).map((x) => `- ${picocolors.default.green(x ?? "")}`).join("\n")}\n`);
|
|
1162
1162
|
const queue = new p_queue.default({ concurrency: configConcurrency ?? Math.max(node_os.default.cpus().length, 1) });
|
|
1163
1163
|
const template = configCommand ?? "cnpm sync {name}";
|
|
1164
1164
|
const tasks = [];
|
|
1165
|
-
for (const pkgName of set
|
|
1165
|
+
for (const pkgName of set) {
|
|
1166
1166
|
if (!pkgName) continue;
|
|
1167
1167
|
tasks.push(queue.add(async () => {
|
|
1168
1168
|
return (0, _icebreakers_monorepo_templates.execaCommand)(renderCommand(template, pkgName), { stdio: "inherit" });
|
|
@@ -1261,9 +1261,9 @@ function parseVersion(input) {
|
|
|
1261
1261
|
return null;
|
|
1262
1262
|
}
|
|
1263
1263
|
}
|
|
1264
|
-
function hasNonOverridablePrefix(version
|
|
1265
|
-
if (typeof version
|
|
1266
|
-
return NON_OVERRIDABLE_PREFIXES.some((prefix) => version
|
|
1264
|
+
function hasNonOverridablePrefix(version) {
|
|
1265
|
+
if (typeof version !== "string") return false;
|
|
1266
|
+
return NON_OVERRIDABLE_PREFIXES.some((prefix) => version.startsWith(prefix));
|
|
1267
1267
|
}
|
|
1268
1268
|
function shouldAssignVersion(currentVersion, nextVersion) {
|
|
1269
1269
|
if (typeof currentVersion !== "string" || currentVersion.trim().length === 0) return true;
|
|
@@ -1308,9 +1308,9 @@ function setPkgJson(sourcePkgJson, targetPkgJson, options) {
|
|
|
1308
1308
|
if (Object.keys(targetDevDeps).length) targetPkgJson.devDependencies = targetDevDeps;
|
|
1309
1309
|
const scriptPairs = options?.scripts ? Object.entries(options.scripts) : scriptsEntries;
|
|
1310
1310
|
if (scriptPairs.length) {
|
|
1311
|
-
const scripts
|
|
1312
|
-
for (const [scriptName, scriptCmd] of scriptPairs) scripts
|
|
1313
|
-
targetPkgJson.scripts = scripts
|
|
1311
|
+
const scripts = { ...targetPkgJson.scripts ?? {} };
|
|
1312
|
+
for (const [scriptName, scriptCmd] of scriptPairs) scripts[scriptName] = scriptCmd;
|
|
1313
|
+
targetPkgJson.scripts = scripts;
|
|
1314
1314
|
}
|
|
1315
1315
|
}
|
|
1316
1316
|
|
|
@@ -1403,7 +1403,7 @@ async function upgradeMonorepo(opts) {
|
|
|
1403
1403
|
})
|
|
1404
1404
|
});
|
|
1405
1405
|
const regexpArr = targets.map((x) => {
|
|
1406
|
-
return
|
|
1406
|
+
return new RegExp(`^${escapeStringRegexp(x)}`);
|
|
1407
1407
|
});
|
|
1408
1408
|
const skipChangesetMarkdown = upgradeConfig?.skipChangesetMarkdown ?? true;
|
|
1409
1409
|
const scriptOverrides = upgradeConfig?.scripts;
|
|
@@ -1429,15 +1429,15 @@ async function upgradeMonorepo(opts) {
|
|
|
1429
1429
|
const targetPkgJson = await fs_extra.default.readJson(targetPath);
|
|
1430
1430
|
setPkgJson(sourcePkgJson, targetPkgJson, scriptOverrides ? { scripts: scriptOverrides } : void 0);
|
|
1431
1431
|
const data = `${JSON.stringify(targetPkgJson, void 0, 2)}\n`;
|
|
1432
|
-
const intent
|
|
1433
|
-
const action
|
|
1432
|
+
const intent = await evaluateWriteIntent(targetPath, buildWriteIntentOptions(data));
|
|
1433
|
+
const action = async () => {
|
|
1434
1434
|
await fs_extra.default.outputFile(targetPath, data, "utf8");
|
|
1435
1435
|
logger.success(targetPath);
|
|
1436
1436
|
};
|
|
1437
|
-
await scheduleOverwrite(intent
|
|
1437
|
+
await scheduleOverwrite(intent, {
|
|
1438
1438
|
relPath,
|
|
1439
1439
|
targetPath,
|
|
1440
|
-
action
|
|
1440
|
+
action,
|
|
1441
1441
|
pending: pendingOverwrites
|
|
1442
1442
|
});
|
|
1443
1443
|
continue;
|
|
@@ -1448,15 +1448,15 @@ async function upgradeMonorepo(opts) {
|
|
|
1448
1448
|
const targetManifest = exists ? normalizeWorkspaceManifest(yaml.default.parse(await fs_extra.default.readFile(targetPath, "utf8"))) : normalizeWorkspaceManifest({});
|
|
1449
1449
|
const mergedManifest = exists ? mergeWorkspaceManifest(sourceManifest, targetManifest) : sourceManifest;
|
|
1450
1450
|
const data = yaml.default.stringify(mergedManifest, { singleQuote: true });
|
|
1451
|
-
const intent
|
|
1452
|
-
const action
|
|
1451
|
+
const intent = await evaluateWriteIntent(targetPath, buildWriteIntentOptions(data));
|
|
1452
|
+
const action = async () => {
|
|
1453
1453
|
await fs_extra.default.outputFile(targetPath, data, "utf8");
|
|
1454
1454
|
logger.success(targetPath);
|
|
1455
1455
|
};
|
|
1456
|
-
await scheduleOverwrite(intent
|
|
1456
|
+
await scheduleOverwrite(intent, {
|
|
1457
1457
|
relPath,
|
|
1458
1458
|
targetPath,
|
|
1459
|
-
action
|
|
1459
|
+
action,
|
|
1460
1460
|
pending: pendingOverwrites
|
|
1461
1461
|
});
|
|
1462
1462
|
continue;
|
|
@@ -1465,48 +1465,48 @@ async function upgradeMonorepo(opts) {
|
|
|
1465
1465
|
const changesetJson = await fs_extra.default.readJson(file.path);
|
|
1466
1466
|
(0, import_set_value.default)(changesetJson, "changelog.1.repo", repoName);
|
|
1467
1467
|
const data = `${JSON.stringify(changesetJson, void 0, 2)}\n`;
|
|
1468
|
-
const intent
|
|
1469
|
-
const action
|
|
1468
|
+
const intent = await evaluateWriteIntent(targetPath, buildWriteIntentOptions(data));
|
|
1469
|
+
const action = async () => {
|
|
1470
1470
|
await fs_extra.default.outputFile(targetPath, data, "utf8");
|
|
1471
1471
|
logger.success(targetPath);
|
|
1472
1472
|
};
|
|
1473
|
-
await scheduleOverwrite(intent
|
|
1473
|
+
await scheduleOverwrite(intent, {
|
|
1474
1474
|
relPath,
|
|
1475
1475
|
targetPath,
|
|
1476
|
-
action
|
|
1476
|
+
action,
|
|
1477
1477
|
pending: pendingOverwrites
|
|
1478
1478
|
});
|
|
1479
1479
|
continue;
|
|
1480
1480
|
}
|
|
1481
1481
|
if (relPath === "LICENSE") {
|
|
1482
|
-
const source
|
|
1483
|
-
const intent
|
|
1482
|
+
const source = await fs_extra.default.readFile(file.path);
|
|
1483
|
+
const intent = await evaluateWriteIntent(targetPath, {
|
|
1484
1484
|
skipOverwrite: true,
|
|
1485
|
-
source
|
|
1485
|
+
source
|
|
1486
1486
|
});
|
|
1487
|
-
const action
|
|
1488
|
-
await fs_extra.default.outputFile(targetPath, source
|
|
1487
|
+
const action = async () => {
|
|
1488
|
+
await fs_extra.default.outputFile(targetPath, source);
|
|
1489
1489
|
logger.success(targetPath);
|
|
1490
1490
|
};
|
|
1491
|
-
await scheduleOverwrite(intent
|
|
1491
|
+
await scheduleOverwrite(intent, {
|
|
1492
1492
|
relPath,
|
|
1493
1493
|
targetPath,
|
|
1494
|
-
action
|
|
1494
|
+
action,
|
|
1495
1495
|
pending: pendingOverwrites
|
|
1496
1496
|
});
|
|
1497
1497
|
continue;
|
|
1498
1498
|
}
|
|
1499
1499
|
if (relPath === ".github/ISSUE_TEMPLATE/config.yml") {
|
|
1500
1500
|
const data = updateIssueTemplateConfig(await fs_extra.default.readFile(file.path, "utf8"), repoName);
|
|
1501
|
-
const intent
|
|
1502
|
-
const action
|
|
1501
|
+
const intent = await evaluateWriteIntent(targetPath, buildWriteIntentOptions(data));
|
|
1502
|
+
const action = async () => {
|
|
1503
1503
|
await fs_extra.default.outputFile(targetPath, data);
|
|
1504
1504
|
logger.success(targetPath);
|
|
1505
1505
|
};
|
|
1506
|
-
await scheduleOverwrite(intent
|
|
1506
|
+
await scheduleOverwrite(intent, {
|
|
1507
1507
|
relPath,
|
|
1508
1508
|
targetPath,
|
|
1509
|
-
action
|
|
1509
|
+
action,
|
|
1510
1510
|
pending: pendingOverwrites
|
|
1511
1511
|
});
|
|
1512
1512
|
continue;
|