@icebreakers/monorepo 2.0.8 → 2.0.10

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 CHANGED
@@ -605,7 +605,7 @@ var import_node_url = require("url");
605
605
 
606
606
  // package.json
607
607
  var name = "@icebreakers/monorepo";
608
- var version = "2.0.8";
608
+ var version = "2.0.10";
609
609
 
610
610
  // src/constants.ts
611
611
  var packageJsonPath = (0, import_node_url.fileURLToPath)(new URL("../package.json", importMetaUrl));
@@ -980,14 +980,11 @@ ${Array.from(set7).map((x) => `- ${import_picocolors2.default.green(x ?? "")}`).
980
980
 
981
981
  // src/commands/upgrade/index.ts
982
982
  init_cjs_shims();
983
- var import_node_buffer = require("buffer");
984
983
  var import_node_process2 = __toESM(require("process"), 1);
985
- var import_checkbox2 = __toESM(require("@inquirer/checkbox"), 1);
986
- var import_confirm = __toESM(require("@inquirer/confirm"), 1);
987
- var import_fs_extra7 = __toESM(require("fs-extra"), 1);
984
+ var import_checkbox3 = __toESM(require("@inquirer/checkbox"), 1);
985
+ var import_fs_extra8 = __toESM(require("fs-extra"), 1);
988
986
  var import_klaw = __toESM(require("klaw"), 1);
989
987
  var import_pathe11 = __toESM(require("pathe"), 1);
990
- var import_picocolors3 = __toESM(require("picocolors"), 1);
991
988
  var import_set_value6 = __toESM(require_set_value(), 1);
992
989
 
993
990
  // src/utils/fs.ts
@@ -1033,6 +1030,98 @@ function isMatch(str, arr) {
1033
1030
  return false;
1034
1031
  }
1035
1032
 
1033
+ // src/commands/upgrade/overwrite.ts
1034
+ init_cjs_shims();
1035
+ var import_node_buffer = require("buffer");
1036
+ var import_checkbox2 = __toESM(require("@inquirer/checkbox"), 1);
1037
+ var import_fs_extra7 = __toESM(require("fs-extra"), 1);
1038
+ var import_picocolors3 = __toESM(require("picocolors"), 1);
1039
+ function asBuffer(data) {
1040
+ return typeof data === "string" ? import_node_buffer.Buffer.from(data) : data;
1041
+ }
1042
+ async function evaluateWriteIntent(targetPath, options) {
1043
+ const { skipOverwrite, source } = options;
1044
+ const exists = await import_fs_extra7.default.pathExists(targetPath);
1045
+ if (!exists) {
1046
+ return {
1047
+ type: "write",
1048
+ reason: "missing"
1049
+ };
1050
+ }
1051
+ if (skipOverwrite) {
1052
+ return {
1053
+ type: "skip",
1054
+ reason: "skipOverwrite"
1055
+ };
1056
+ }
1057
+ const src = asBuffer(source);
1058
+ let destSize = 0;
1059
+ try {
1060
+ const stat = await import_fs_extra7.default.stat(targetPath);
1061
+ destSize = stat.size;
1062
+ } catch {
1063
+ return {
1064
+ type: "write",
1065
+ reason: "missing"
1066
+ };
1067
+ }
1068
+ if (destSize !== src.length) {
1069
+ return {
1070
+ type: "prompt",
1071
+ reason: "changed"
1072
+ };
1073
+ }
1074
+ const dest = await import_fs_extra7.default.readFile(targetPath);
1075
+ if (!isFileChanged(src, dest)) {
1076
+ return {
1077
+ type: "skip",
1078
+ reason: "identical"
1079
+ };
1080
+ }
1081
+ return {
1082
+ type: "prompt",
1083
+ reason: "changed"
1084
+ };
1085
+ }
1086
+ async function scheduleOverwrite(intent, options) {
1087
+ const { relPath, targetPath, action, pending } = options;
1088
+ if (intent.type === "write") {
1089
+ await action();
1090
+ return;
1091
+ }
1092
+ if (intent.type === "prompt") {
1093
+ pending.push({
1094
+ relPath,
1095
+ targetPath,
1096
+ action
1097
+ });
1098
+ }
1099
+ }
1100
+ async function flushPendingOverwrites(pending) {
1101
+ if (!pending.length) {
1102
+ return;
1103
+ }
1104
+ const selected = await (0, import_checkbox2.default)({
1105
+ 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",
1106
+ choices: pending.map((item) => ({
1107
+ name: import_picocolors3.default.greenBright(item.relPath),
1108
+ value: item.targetPath,
1109
+ checked: false
1110
+ })),
1111
+ loop: false
1112
+ });
1113
+ const selectedSet = new Set(selected);
1114
+ for (const item of pending) {
1115
+ if (selectedSet.has(item.targetPath)) {
1116
+ await item.action();
1117
+ }
1118
+ }
1119
+ }
1120
+
1121
+ // src/commands/upgrade/pkg-json.ts
1122
+ init_cjs_shims();
1123
+ var import_semver = require("semver");
1124
+
1036
1125
  // src/commands/upgrade/scripts.ts
1037
1126
  init_cjs_shims();
1038
1127
  var scripts = {
@@ -1044,6 +1133,90 @@ var scripts = {
1044
1133
  };
1045
1134
  var scriptsEntries = Object.entries(scripts);
1046
1135
 
1136
+ // src/commands/upgrade/pkg-json.ts
1137
+ function isWorkspace(version2) {
1138
+ if (typeof version2 === "string") {
1139
+ return version2.startsWith("workspace:");
1140
+ }
1141
+ return false;
1142
+ }
1143
+ function parseVersion(input2) {
1144
+ if (typeof input2 !== "string" || input2.trim().length === 0) {
1145
+ return null;
1146
+ }
1147
+ return (0, import_semver.minVersion)(input2) ?? (0, import_semver.coerce)(input2);
1148
+ }
1149
+ function shouldAssignVersion(currentVersion, nextVersion) {
1150
+ if (typeof currentVersion !== "string" || currentVersion.trim().length === 0) {
1151
+ return true;
1152
+ }
1153
+ if (currentVersion === nextVersion) {
1154
+ return false;
1155
+ }
1156
+ const current = parseVersion(currentVersion);
1157
+ const next = parseVersion(nextVersion);
1158
+ if (!current || !next) {
1159
+ return true;
1160
+ }
1161
+ return !(0, import_semver.gte)(current, next);
1162
+ }
1163
+ function setPkgJson(sourcePkgJson, targetPkgJson, options) {
1164
+ const packageManager = sourcePkgJson.packageManager ?? "";
1165
+ const sourceDeps = sourcePkgJson.dependencies ?? {};
1166
+ const sourceDevDeps = sourcePkgJson.devDependencies ?? {};
1167
+ const targetDeps = { ...targetPkgJson.dependencies ?? {} };
1168
+ const targetDevDeps = { ...targetPkgJson.devDependencies ?? {} };
1169
+ if (packageManager) {
1170
+ targetPkgJson.packageManager = packageManager;
1171
+ }
1172
+ for (const [depName, depVersion] of Object.entries(sourceDeps)) {
1173
+ if (typeof depVersion !== "string") {
1174
+ continue;
1175
+ }
1176
+ const targetVersion = targetDeps[depName];
1177
+ if (isWorkspace(targetVersion)) {
1178
+ continue;
1179
+ }
1180
+ if (shouldAssignVersion(targetVersion, depVersion)) {
1181
+ targetDeps[depName] = depVersion;
1182
+ }
1183
+ }
1184
+ if (Object.keys(targetDeps).length) {
1185
+ targetPkgJson.dependencies = targetDeps;
1186
+ }
1187
+ for (const [depName, depVersion] of Object.entries(sourceDevDeps)) {
1188
+ if (typeof depVersion !== "string") {
1189
+ continue;
1190
+ }
1191
+ if (depName === name) {
1192
+ const nextVersion = `^${version}`;
1193
+ const targetVersion = targetDevDeps[depName];
1194
+ if (!isWorkspace(targetVersion) && shouldAssignVersion(targetVersion, nextVersion)) {
1195
+ targetDevDeps[depName] = nextVersion;
1196
+ }
1197
+ } else {
1198
+ const targetVersion = targetDevDeps[depName];
1199
+ if (isWorkspace(targetVersion)) {
1200
+ continue;
1201
+ }
1202
+ if (shouldAssignVersion(targetVersion, depVersion)) {
1203
+ targetDevDeps[depName] = depVersion;
1204
+ }
1205
+ }
1206
+ }
1207
+ if (Object.keys(targetDevDeps).length) {
1208
+ targetPkgJson.devDependencies = targetDevDeps;
1209
+ }
1210
+ const scriptPairs = (options == null ? void 0 : options.scripts) ? Object.entries(options.scripts) : scriptsEntries;
1211
+ if (scriptPairs.length) {
1212
+ const scripts2 = { ...targetPkgJson.scripts ?? {} };
1213
+ for (const [scriptName, scriptCmd] of scriptPairs) {
1214
+ scripts2[scriptName] = scriptCmd;
1215
+ }
1216
+ targetPkgJson.scripts = scripts2;
1217
+ }
1218
+ }
1219
+
1047
1220
  // src/commands/upgrade/targets.ts
1048
1221
  init_cjs_shims();
1049
1222
  function getAssetTargets(raw) {
@@ -1082,80 +1255,6 @@ function getAssetTargets(raw) {
1082
1255
  }
1083
1256
 
1084
1257
  // src/commands/upgrade/index.ts
1085
- function isWorkspace(version2) {
1086
- if (typeof version2 === "string") {
1087
- return version2.startsWith("workspace:");
1088
- }
1089
- return false;
1090
- }
1091
- function setPkgJson(sourcePkgJson, targetPkgJson, options) {
1092
- const packageManager = index_default(sourcePkgJson, "packageManager", { default: "" });
1093
- const sourceDeps = index_default(sourcePkgJson, "dependencies", { default: {} });
1094
- const sourceDevDeps = index_default(sourcePkgJson, "devDependencies", { default: {} });
1095
- const targetDeps = { ...index_default(targetPkgJson, "dependencies", { default: {} }) };
1096
- const targetDevDeps = { ...index_default(targetPkgJson, "devDependencies", { default: {} }) };
1097
- if (packageManager) {
1098
- targetPkgJson.packageManager = packageManager;
1099
- }
1100
- for (const [depName, depVersion] of Object.entries(sourceDeps)) {
1101
- if (!isWorkspace(targetDeps[depName])) {
1102
- targetDeps[depName] = depVersion;
1103
- }
1104
- }
1105
- if (Object.keys(targetDeps).length) {
1106
- targetPkgJson.dependencies = targetDeps;
1107
- }
1108
- for (const [depName, depVersion] of Object.entries(sourceDevDeps)) {
1109
- if (depName === name) {
1110
- targetDevDeps[depName] = `^${version}`;
1111
- } else if (!isWorkspace(targetDevDeps[depName])) {
1112
- targetDevDeps[depName] = depVersion;
1113
- }
1114
- }
1115
- if (Object.keys(targetDevDeps).length) {
1116
- targetPkgJson.devDependencies = targetDevDeps;
1117
- }
1118
- const scriptPairs = (options == null ? void 0 : options.scripts) ? Object.entries(options.scripts) : scriptsEntries;
1119
- if (scriptPairs.length) {
1120
- const scripts2 = { ...targetPkgJson.scripts ?? {} };
1121
- for (const [scriptName, scriptCmd] of scriptPairs) {
1122
- scripts2[scriptName] = scriptCmd;
1123
- }
1124
- targetPkgJson.scripts = scripts2;
1125
- }
1126
- }
1127
- function confirmOverwrite(filename) {
1128
- return (0, import_confirm.default)({ message: `${import_picocolors3.default.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: true });
1129
- }
1130
- function asBuffer(data) {
1131
- return typeof data === "string" ? import_node_buffer.Buffer.from(data) : data;
1132
- }
1133
- async function shouldWriteFile(targetPath, options) {
1134
- const { skipOverwrite, source, promptLabel } = options;
1135
- const exists = await import_fs_extra7.default.pathExists(targetPath);
1136
- if (!exists) {
1137
- return true;
1138
- }
1139
- if (skipOverwrite) {
1140
- return false;
1141
- }
1142
- const src = asBuffer(source);
1143
- let destSize = 0;
1144
- try {
1145
- const stat = await import_fs_extra7.default.stat(targetPath);
1146
- destSize = stat.size;
1147
- } catch {
1148
- return true;
1149
- }
1150
- if (destSize !== src.length) {
1151
- return confirmOverwrite(promptLabel);
1152
- }
1153
- const dest = await import_fs_extra7.default.readFile(targetPath);
1154
- if (!isFileChanged(src, dest)) {
1155
- return false;
1156
- }
1157
- return confirmOverwrite(promptLabel);
1158
- }
1159
1258
  async function upgradeMonorepo(opts) {
1160
1259
  const cwd2 = opts.cwd ?? import_node_process2.default.cwd();
1161
1260
  const upgradeConfig = await resolveCommandConfig("upgrade", cwd2);
@@ -1176,7 +1275,7 @@ async function upgradeMonorepo(opts) {
1176
1275
  const mergeTargets = upgradeConfig == null ? void 0 : upgradeConfig.mergeTargets;
1177
1276
  let targets = configTargets.length ? mergeTargets === false ? [...configTargets] : Array.from(/* @__PURE__ */ new Set([...baseTargets, ...configTargets])) : baseTargets;
1178
1277
  if (merged.interactive) {
1179
- targets = await (0, import_checkbox2.default)({
1278
+ targets = await (0, import_checkbox3.default)({
1180
1279
  message: "\u9009\u62E9\u4F60\u9700\u8981\u7684\u6587\u4EF6",
1181
1280
  choices: targets.map((x) => {
1182
1281
  return {
@@ -1192,6 +1291,7 @@ async function upgradeMonorepo(opts) {
1192
1291
  const skipChangesetMarkdown = (upgradeConfig == null ? void 0 : upgradeConfig.skipChangesetMarkdown) ?? true;
1193
1292
  const scriptOverrides = upgradeConfig == null ? void 0 : upgradeConfig.scripts;
1194
1293
  const skipOverwrite = merged.skipOverwrite;
1294
+ const pendingOverwrites = [];
1195
1295
  for await (const file of (0, import_klaw.default)(assetsDir, {
1196
1296
  filter(p) {
1197
1297
  const str = import_pathe11.default.relative(assetsDir, p);
@@ -1211,43 +1311,72 @@ async function upgradeMonorepo(opts) {
1211
1311
  const targetPath = import_pathe11.default.resolve(absOutDir, relPath);
1212
1312
  try {
1213
1313
  if (relPath === "package.json") {
1214
- if (!await import_fs_extra7.default.pathExists(targetPath)) {
1314
+ if (!await import_fs_extra8.default.pathExists(targetPath)) {
1215
1315
  continue;
1216
1316
  }
1217
- const sourcePkgJson = await import_fs_extra7.default.readJson(file.path);
1218
- const targetPkgJson = await import_fs_extra7.default.readJson(targetPath);
1317
+ const sourcePkgJson = await import_fs_extra8.default.readJson(file.path);
1318
+ const targetPkgJson = await import_fs_extra8.default.readJson(targetPath);
1219
1319
  setPkgJson(sourcePkgJson, targetPkgJson, { scripts: scriptOverrides });
1220
1320
  const data = `${JSON.stringify(targetPkgJson, void 0, 2)}
1221
1321
  `;
1222
- if (await shouldWriteFile(targetPath, { skipOverwrite, source: data, promptLabel: relPath })) {
1223
- await import_fs_extra7.default.outputFile(targetPath, data, "utf8");
1322
+ const intent2 = await evaluateWriteIntent(targetPath, { skipOverwrite, source: data });
1323
+ const action2 = async () => {
1324
+ await import_fs_extra8.default.outputFile(targetPath, data, "utf8");
1224
1325
  logger.success(targetPath);
1225
- }
1326
+ };
1327
+ await scheduleOverwrite(intent2, {
1328
+ relPath,
1329
+ targetPath,
1330
+ action: action2,
1331
+ pending: pendingOverwrites
1332
+ });
1226
1333
  continue;
1227
1334
  }
1228
1335
  if (relPath === ".changeset/config.json" && repoName) {
1229
- const changesetJson = await import_fs_extra7.default.readJson(file.path);
1336
+ const changesetJson = await import_fs_extra8.default.readJson(file.path);
1230
1337
  (0, import_set_value6.default)(changesetJson, "changelog.1.repo", repoName);
1231
1338
  const data = `${JSON.stringify(changesetJson, void 0, 2)}
1232
1339
  `;
1233
- if (await shouldWriteFile(targetPath, { skipOverwrite, source: data, promptLabel: relPath })) {
1234
- await import_fs_extra7.default.outputFile(targetPath, data, "utf8");
1340
+ const intent2 = await evaluateWriteIntent(targetPath, { skipOverwrite, source: data });
1341
+ const action2 = async () => {
1342
+ await import_fs_extra8.default.outputFile(targetPath, data, "utf8");
1235
1343
  logger.success(targetPath);
1236
- }
1344
+ };
1345
+ await scheduleOverwrite(intent2, {
1346
+ relPath,
1347
+ targetPath,
1348
+ action: action2,
1349
+ pending: pendingOverwrites
1350
+ });
1237
1351
  continue;
1238
1352
  }
1239
1353
  if (relPath === "LICENSE") {
1240
- const source = await import_fs_extra7.default.readFile(file.path);
1241
- if (await shouldWriteFile(targetPath, { skipOverwrite: true, source, promptLabel: relPath })) {
1242
- await import_fs_extra7.default.copy(file.path, targetPath);
1354
+ const source2 = await import_fs_extra8.default.readFile(file.path);
1355
+ const intent2 = await evaluateWriteIntent(targetPath, { skipOverwrite: true, source: source2 });
1356
+ const action2 = async () => {
1357
+ await import_fs_extra8.default.outputFile(targetPath, source2);
1243
1358
  logger.success(targetPath);
1244
- }
1359
+ };
1360
+ await scheduleOverwrite(intent2, {
1361
+ relPath,
1362
+ targetPath,
1363
+ action: action2,
1364
+ pending: pendingOverwrites
1365
+ });
1245
1366
  continue;
1246
1367
  }
1247
- if (await shouldWriteFile(targetPath, { skipOverwrite, source: await import_fs_extra7.default.readFile(file.path), promptLabel: relPath })) {
1248
- await import_fs_extra7.default.copy(file.path, targetPath);
1368
+ const source = await import_fs_extra8.default.readFile(file.path);
1369
+ const intent = await evaluateWriteIntent(targetPath, { skipOverwrite, source });
1370
+ const action = async () => {
1371
+ await import_fs_extra8.default.outputFile(targetPath, source);
1249
1372
  logger.success(targetPath);
1250
- }
1373
+ };
1374
+ await scheduleOverwrite(intent, {
1375
+ relPath,
1376
+ targetPath,
1377
+ action,
1378
+ pending: pendingOverwrites
1379
+ });
1251
1380
  } catch (error) {
1252
1381
  if (isIgnorableFsError(error)) {
1253
1382
  continue;
@@ -1255,6 +1384,7 @@ async function upgradeMonorepo(opts) {
1255
1384
  throw error;
1256
1385
  }
1257
1386
  }
1387
+ await flushPendingOverwrites(pendingOverwrites);
1258
1388
  }
1259
1389
 
1260
1390
  // src/cli/program.ts
package/dist/cli.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  syncNpmMirror,
13
13
  upgradeMonorepo,
14
14
  version
15
- } from "./chunk-4R64J5LE.js";
15
+ } from "./chunk-3TJYHDE6.js";
16
16
 
17
17
  // src/cli.ts
18
18
  init_esm_shims();