@naseej/blox 1.11.0 → 1.12.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/dist/run.js +821 -522
- package/package.json +1 -1
- package/readme.md +18 -13
package/dist/run.js
CHANGED
|
@@ -262,7 +262,7 @@ var checkForCliUpdate = async (currentVersion, argv = []) => {
|
|
|
262
262
|
};
|
|
263
263
|
|
|
264
264
|
// package.json
|
|
265
|
-
var version = "1.
|
|
265
|
+
var version = "1.12.0";
|
|
266
266
|
|
|
267
267
|
// src/migrations/index.ts
|
|
268
268
|
var import_node_path15 = __toESM(require("path"));
|
|
@@ -687,6 +687,7 @@ var v1 = {
|
|
|
687
687
|
var migrationsList = [v1];
|
|
688
688
|
|
|
689
689
|
// src/services/git.ts
|
|
690
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
690
691
|
var import_node_os = __toESM(require("os"));
|
|
691
692
|
var import_node_path13 = __toESM(require("path"));
|
|
692
693
|
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
@@ -1027,23 +1028,14 @@ var getAvailableTemplates = async () => {
|
|
|
1027
1028
|
block.source = data.baseUrl + block.source;
|
|
1028
1029
|
}
|
|
1029
1030
|
});
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
if (!block.source) {
|
|
1039
|
-
block.source = `/block-${appName}-${blockName}`;
|
|
1040
|
-
}
|
|
1041
|
-
if (block.source.startsWith("/")) {
|
|
1042
|
-
block.source = data.baseUrl + block.source;
|
|
1043
|
-
}
|
|
1044
|
-
});
|
|
1045
|
-
});
|
|
1046
|
-
const resolvedTemplate = template;
|
|
1031
|
+
const appRefs = {};
|
|
1032
|
+
for (const app of template.apps || []) {
|
|
1033
|
+
appRefs[app.name ?? app.template] = app;
|
|
1034
|
+
}
|
|
1035
|
+
const resolvedTemplate = {
|
|
1036
|
+
...template,
|
|
1037
|
+
apps: appRefs
|
|
1038
|
+
};
|
|
1047
1039
|
if (templates[templateName]) {
|
|
1048
1040
|
templates[templateName] = (0, import_merge.default)(templates[templateName], resolvedTemplate);
|
|
1049
1041
|
} else {
|
|
@@ -1052,6 +1044,28 @@ var getAvailableTemplates = async () => {
|
|
|
1052
1044
|
});
|
|
1053
1045
|
}
|
|
1054
1046
|
}
|
|
1047
|
+
for (const template of Object.values(templates)) {
|
|
1048
|
+
const refs = template.apps || {};
|
|
1049
|
+
const apps = {};
|
|
1050
|
+
for (const [key, ref] of Object.entries(refs)) {
|
|
1051
|
+
const referenced = templates[ref.template];
|
|
1052
|
+
if (!referenced) {
|
|
1053
|
+
import_prompts2.log.warn(
|
|
1054
|
+
`Application "${key}" references unknown template "${ref.template}"`
|
|
1055
|
+
);
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
apps[key] = {
|
|
1059
|
+
template: ref.template,
|
|
1060
|
+
name: ref.name,
|
|
1061
|
+
version: ref.version,
|
|
1062
|
+
description: referenced.description,
|
|
1063
|
+
tags: referenced.tags,
|
|
1064
|
+
source: referenced.source
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
template.apps = apps;
|
|
1068
|
+
}
|
|
1055
1069
|
debug({ templates });
|
|
1056
1070
|
return templates;
|
|
1057
1071
|
};
|
|
@@ -1078,21 +1092,6 @@ var getAvailableApps = async (templateInfo) => {
|
|
|
1078
1092
|
debug({ apps });
|
|
1079
1093
|
return apps;
|
|
1080
1094
|
};
|
|
1081
|
-
var getAvailableBlocksForApp = async (appKey, rootTemplateName, appTemplateInfo) => {
|
|
1082
|
-
debug(`Get available blocks for app ${appKey}`);
|
|
1083
|
-
const templates = await getAvailableTemplates();
|
|
1084
|
-
const blocks = {
|
|
1085
|
-
...templates[rootTemplateName]?.apps?.[appKey]?.blocks || {}
|
|
1086
|
-
};
|
|
1087
|
-
for (const base of appTemplateInfo.bases || []) {
|
|
1088
|
-
const baseTemplate = templates[base.name];
|
|
1089
|
-
Object.entries(baseTemplate?.apps?.[appKey]?.blocks || {}).forEach(
|
|
1090
|
-
([k, v]) => blocks[k] = v
|
|
1091
|
-
);
|
|
1092
|
-
}
|
|
1093
|
-
debug({ blocks });
|
|
1094
|
-
return blocks;
|
|
1095
|
-
};
|
|
1096
1095
|
var getAvailableVersions = async (source) => {
|
|
1097
1096
|
for (const { dir } of getConfiguredRegistryDirs()) {
|
|
1098
1097
|
const indexPath = import_node_path10.default.join(dir, "index.json");
|
|
@@ -1140,11 +1139,7 @@ var getComponentRepoUrl = async (component) => {
|
|
|
1140
1139
|
`Component missing templateDef for block source resolution: ${component.name}`
|
|
1141
1140
|
);
|
|
1142
1141
|
}
|
|
1143
|
-
const blocks =
|
|
1144
|
-
component.app,
|
|
1145
|
-
component.rootTemplateName || "",
|
|
1146
|
-
templateDef
|
|
1147
|
-
) : await getAvailableBlocks(templateDef);
|
|
1142
|
+
const blocks = await getAvailableBlocks(templateDef);
|
|
1148
1143
|
const blockSource = blocks?.[component.name]?.source;
|
|
1149
1144
|
if (!blockSource) {
|
|
1150
1145
|
throw new MissingRegistrySourceError(
|
|
@@ -1265,11 +1260,16 @@ var collectProjectComponents = (projectDirAbs, projectDirRel, app, rootTemplateN
|
|
|
1265
1260
|
}
|
|
1266
1261
|
}
|
|
1267
1262
|
};
|
|
1268
|
-
var discoverBloxComponents = (cwd) => {
|
|
1263
|
+
var discoverBloxComponents = (cwd, options = {}) => {
|
|
1269
1264
|
const components = [];
|
|
1270
1265
|
const projectDir = findProjectDir(cwd) ?? cwd;
|
|
1271
1266
|
const workspaceRoot = findWorkspaceRoot(projectDir);
|
|
1272
1267
|
const rootTemplateName = readBloxFileIfExists(workspaceRoot)?.definition?.name;
|
|
1268
|
+
if (options.scope === "project") {
|
|
1269
|
+
const app = projectDir === workspaceRoot ? void 0 : import_node_path12.default.basename(projectDir);
|
|
1270
|
+
collectProjectComponents(projectDir, ".", app, rootTemplateName, components);
|
|
1271
|
+
return components;
|
|
1272
|
+
}
|
|
1273
1273
|
collectProjectComponents(workspaceRoot, ".", void 0, rootTemplateName, components);
|
|
1274
1274
|
const appsRoot = import_node_path12.default.join(workspaceRoot, appsDir);
|
|
1275
1275
|
for (const app of listApps(workspaceRoot)) {
|
|
@@ -1318,6 +1318,9 @@ var getChangedFiles = async (fromCommit, toCommit, ignore3 = [], cwd = ".") => {
|
|
|
1318
1318
|
let output = "";
|
|
1319
1319
|
const args = [
|
|
1320
1320
|
"diff",
|
|
1321
|
+
// Rename detection (diff.renames) would list only the new path, hiding
|
|
1322
|
+
// the deletion of the old one from the updater.
|
|
1323
|
+
"--no-renames",
|
|
1321
1324
|
"--name-only",
|
|
1322
1325
|
"-z",
|
|
1323
1326
|
fromCommit,
|
|
@@ -1335,43 +1338,49 @@ var getChangedFiles = async (fromCommit, toCommit, ignore3 = [], cwd = ".") => {
|
|
|
1335
1338
|
return output.split("\0").filter(Boolean);
|
|
1336
1339
|
};
|
|
1337
1340
|
var getRemoteWorktree = async (remote, commit2) => {
|
|
1338
|
-
const
|
|
1341
|
+
const repo = process.cwd();
|
|
1342
|
+
const key = `${repo}:${remote}:${commit2}`;
|
|
1339
1343
|
if (remoteWorktrees.has(key)) {
|
|
1340
|
-
return remoteWorktrees.get(key);
|
|
1344
|
+
return remoteWorktrees.get(key).dir;
|
|
1341
1345
|
}
|
|
1342
1346
|
const tmpDir = import_node_os.default.tmpdir();
|
|
1343
|
-
const
|
|
1347
|
+
const repoSlug = import_node_crypto.default.createHash("sha1").update(repo).digest("hex").slice(0, 8);
|
|
1348
|
+
const worktreeDir = import_node_path13.default.join(tmpDir, "blox-cli-worktrees", `${remote}-${repoSlug}`, commit2);
|
|
1344
1349
|
try {
|
|
1345
|
-
await $("git", ["worktree", "prune"]);
|
|
1350
|
+
await $("git", ["worktree", "prune"], { cwd: repo });
|
|
1346
1351
|
} catch {
|
|
1347
1352
|
}
|
|
1348
1353
|
if (await import_fs_extra9.default.pathExists(worktreeDir)) {
|
|
1349
1354
|
try {
|
|
1350
|
-
await $("git", ["worktree", "remove", "--force", worktreeDir]);
|
|
1355
|
+
await $("git", ["worktree", "remove", "--force", worktreeDir], { cwd: repo });
|
|
1351
1356
|
} catch {
|
|
1352
1357
|
await import_fs_extra9.default.remove(worktreeDir);
|
|
1353
1358
|
try {
|
|
1354
|
-
await $("git", ["worktree", "prune"]);
|
|
1359
|
+
await $("git", ["worktree", "prune"], { cwd: repo });
|
|
1355
1360
|
} catch {
|
|
1356
1361
|
}
|
|
1357
1362
|
}
|
|
1358
1363
|
}
|
|
1359
|
-
await $("git", ["worktree", "add", "--detach", "--force", worktreeDir, commit2]
|
|
1360
|
-
|
|
1364
|
+
await $("git", ["worktree", "add", "--detach", "--force", worktreeDir, commit2], {
|
|
1365
|
+
cwd: repo
|
|
1366
|
+
});
|
|
1367
|
+
remoteWorktrees.set(key, { dir: worktreeDir, repo });
|
|
1361
1368
|
return worktreeDir;
|
|
1362
1369
|
};
|
|
1363
1370
|
var cleanUpWorktrees = async () => {
|
|
1364
1371
|
debug("Cleaning up worktrees...");
|
|
1365
|
-
for (const
|
|
1372
|
+
for (const { dir, repo } of remoteWorktrees.values()) {
|
|
1366
1373
|
try {
|
|
1367
|
-
await $("git", ["worktree", "remove", "--force",
|
|
1374
|
+
await $("git", ["worktree", "remove", "--force", dir], { cwd: repo });
|
|
1368
1375
|
} catch (e) {
|
|
1369
|
-
debug(`Failed to remove worktree ${
|
|
1376
|
+
debug(`Failed to remove worktree ${dir}: ${e}`);
|
|
1370
1377
|
}
|
|
1371
1378
|
}
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1379
|
+
for (const repo of new Set([...remoteWorktrees.values()].map((w) => w.repo))) {
|
|
1380
|
+
try {
|
|
1381
|
+
await $("git", ["worktree", "prune"], { cwd: repo });
|
|
1382
|
+
} catch {
|
|
1383
|
+
}
|
|
1375
1384
|
}
|
|
1376
1385
|
remoteWorktrees.clear();
|
|
1377
1386
|
};
|
|
@@ -1512,8 +1521,8 @@ var update = (shellOptions = {}) => {
|
|
|
1512
1521
|
var getLatestCommitFromRemote = async (remote, branch) => {
|
|
1513
1522
|
return getLatestCommit(`${remote}/${branch}`);
|
|
1514
1523
|
};
|
|
1515
|
-
var getLatestCommitFromPath = async (
|
|
1516
|
-
return getLatestCommit("HEAD",
|
|
1524
|
+
var getLatestCommitFromPath = async (path38) => {
|
|
1525
|
+
return getLatestCommit("HEAD", path38);
|
|
1517
1526
|
};
|
|
1518
1527
|
var getLatestCommit = async (rev, cwd = ".") => {
|
|
1519
1528
|
debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
|
|
@@ -1526,9 +1535,10 @@ var getLatestCommit = async (rev, cwd = ".") => {
|
|
|
1526
1535
|
});
|
|
1527
1536
|
return commit2.replace(/\r?\n/g, "").trim();
|
|
1528
1537
|
};
|
|
1529
|
-
var getChangesLog = async (fromCommit, toCommit) => {
|
|
1538
|
+
var getChangesLog = async (fromCommit, toCommit, cwd = ".") => {
|
|
1530
1539
|
let changes = "";
|
|
1531
1540
|
await $("git", ["log", `${fromCommit}..${toCommit}`, '--pretty=format:"%B"'], {
|
|
1541
|
+
cwd,
|
|
1532
1542
|
onStdout: (text2) => {
|
|
1533
1543
|
changes = text2;
|
|
1534
1544
|
}
|
|
@@ -1570,10 +1580,10 @@ var commit = async (msg, cwd = ".") => {
|
|
|
1570
1580
|
debug(`Git commit: ${msg}`);
|
|
1571
1581
|
await $("git", ["commit", "--no-verify", "-m", msg], { cwd });
|
|
1572
1582
|
};
|
|
1573
|
-
var rollback = async () => {
|
|
1583
|
+
var rollback = async (cwd = ".") => {
|
|
1574
1584
|
debug("Rollback");
|
|
1575
|
-
await $("git", ["add", "."]);
|
|
1576
|
-
await $("git", ["reset", "--hard"]);
|
|
1585
|
+
await $("git", ["add", "."], { cwd });
|
|
1586
|
+
await $("git", ["reset", "--hard"], { cwd });
|
|
1577
1587
|
await cleanUpWorktrees();
|
|
1578
1588
|
};
|
|
1579
1589
|
var hasUncommittedChanges = async (cwd = ".") => {
|
|
@@ -1681,11 +1691,11 @@ var createBranch = async (branch, from, cwd = ".") => {
|
|
|
1681
1691
|
var push = async (remote, branch, cwd = ".") => {
|
|
1682
1692
|
await $("git", ["push", "--progress", remote, `refs/heads/${branch}`], { cwd });
|
|
1683
1693
|
};
|
|
1684
|
-
var checkoutFile = async (
|
|
1694
|
+
var checkoutFile = async (path38, ref, cwd = ".") => {
|
|
1685
1695
|
const args = ["checkout"];
|
|
1686
1696
|
if (ref) args.push(ref);
|
|
1687
1697
|
else args.push("HEAD");
|
|
1688
|
-
args.push("--",
|
|
1698
|
+
args.push("--", path38);
|
|
1689
1699
|
await $("git", args, { cwd });
|
|
1690
1700
|
};
|
|
1691
1701
|
var pathExistsAsBlobInRev = async (rev, filePath, cwd = ".") => {
|
|
@@ -1747,10 +1757,10 @@ var cherryPick = async (commitHash, subtree, noCommit, cwd = ".") => {
|
|
|
1747
1757
|
args.push(normalizeCommitRef(commitHash));
|
|
1748
1758
|
await $("git", args, { cwd });
|
|
1749
1759
|
};
|
|
1750
|
-
var reset = async (
|
|
1760
|
+
var reset = async (path38, hard, cwd = ".") => {
|
|
1751
1761
|
const args = ["reset"];
|
|
1752
1762
|
if (hard) args.push("--hard");
|
|
1753
|
-
if (
|
|
1763
|
+
if (path38) args.push(path38);
|
|
1754
1764
|
await $("git", args, { cwd });
|
|
1755
1765
|
};
|
|
1756
1766
|
var commitAll = async (message, cwd = ".") => {
|
|
@@ -1774,7 +1784,7 @@ var getChangedFilesInCommit = async (commit2, cwd = ".") => {
|
|
|
1774
1784
|
let out = "";
|
|
1775
1785
|
await $(
|
|
1776
1786
|
"git",
|
|
1777
|
-
["diff-tree", "--no-commit-id", "--name-only", "-r", "--root", normalizeCommitRef(commit2)],
|
|
1787
|
+
["diff-tree", "--no-renames", "--no-commit-id", "--name-only", "-r", "--root", normalizeCommitRef(commit2)],
|
|
1778
1788
|
{
|
|
1779
1789
|
cwd,
|
|
1780
1790
|
onStdout: (text2) => {
|
|
@@ -1786,7 +1796,7 @@ var getChangedFilesInCommit = async (commit2, cwd = ".") => {
|
|
|
1786
1796
|
};
|
|
1787
1797
|
var getChangedFilesFromHead = async (cwd = ".") => {
|
|
1788
1798
|
let out = "";
|
|
1789
|
-
await $("git", ["diff", "--name-status", "-z", "HEAD"], {
|
|
1799
|
+
await $("git", ["diff", "--no-renames", "--name-status", "-z", "HEAD"], {
|
|
1790
1800
|
cwd,
|
|
1791
1801
|
onStdout: (text2) => {
|
|
1792
1802
|
out += text2;
|
|
@@ -2012,16 +2022,24 @@ async function migrateAll(autoCommit, rootDir = ".") {
|
|
|
2012
2022
|
}
|
|
2013
2023
|
const urlsChanged = await updateSchemaUrls(rootDir);
|
|
2014
2024
|
filesChanged = filesChanged || urlsChanged;
|
|
2015
|
-
if (autoCommit && filesChanged
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2025
|
+
if (autoCommit && filesChanged) {
|
|
2026
|
+
for (const dir of [rootDir, ...listApps(rootDir).map((app) => app.dir)]) {
|
|
2027
|
+
if (await git.hasUncommittedChanges(dir)) {
|
|
2028
|
+
import_prompts2.log.warn(fmt.yellow(`Migrations done and will be commited`));
|
|
2029
|
+
await git.add(".", dir);
|
|
2030
|
+
await git.commit("chore: migrate blox schema", dir);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2019
2033
|
}
|
|
2020
2034
|
}
|
|
2021
2035
|
|
|
2022
2036
|
// src/services/add.ts
|
|
2023
2037
|
var import_node_os2 = __toESM(require("os"));
|
|
2024
2038
|
var import_node_path18 = __toESM(require("path"));
|
|
2039
|
+
var import_fs_extra14 = __toESM(require("fs-extra"));
|
|
2040
|
+
|
|
2041
|
+
// src/services/apps.ts
|
|
2042
|
+
var import_node_path17 = __toESM(require("path"));
|
|
2025
2043
|
var import_fs_extra13 = __toESM(require("fs-extra"));
|
|
2026
2044
|
|
|
2027
2045
|
// src/services/fs.ts
|
|
@@ -2046,9 +2064,6 @@ var deletePattern = async (cwd, patterns = []) => {
|
|
|
2046
2064
|
}
|
|
2047
2065
|
};
|
|
2048
2066
|
|
|
2049
|
-
// src/services/versions/checkCompatibility.ts
|
|
2050
|
-
var import_node_path17 = __toESM(require("path"));
|
|
2051
|
-
|
|
2052
2067
|
// src/services/versions/compatibility.ts
|
|
2053
2068
|
var DEFAULT_VERSION = 0;
|
|
2054
2069
|
function normalizeVersion(version2) {
|
|
@@ -2110,7 +2125,7 @@ function ensureVersionOverlap(version2 = 0, range = 0, mismatchMessage) {
|
|
|
2110
2125
|
);
|
|
2111
2126
|
}
|
|
2112
2127
|
}
|
|
2113
|
-
async function _checkVersionsCompatibility(template, usedBlocks, basesVersion
|
|
2128
|
+
async function _checkVersionsCompatibility(template, usedBlocks, basesVersion) {
|
|
2114
2129
|
for (const templateBaseDep of template.bases || []) {
|
|
2115
2130
|
const currentVersion = basesVersion[templateBaseDep.name]?.version;
|
|
2116
2131
|
ensureVersionOverlap(
|
|
@@ -2134,7 +2149,7 @@ async function _checkVersionsCompatibility(template, usedBlocks, basesVersion, f
|
|
|
2134
2149
|
);
|
|
2135
2150
|
}
|
|
2136
2151
|
for (const blockDep of block.dependencies || []) {
|
|
2137
|
-
const blockDepDef = usedBlocks.find((b) => b.name === blockDep.name)
|
|
2152
|
+
const blockDepDef = usedBlocks.find((b) => b.name === blockDep.name);
|
|
2138
2153
|
if (!blockDepDef) {
|
|
2139
2154
|
throw new Error(
|
|
2140
2155
|
`Block "${block.name}" version: ${block.version} depends on missing block "${blockDep.name}" `
|
|
@@ -2148,14 +2163,13 @@ async function _checkVersionsCompatibility(template, usedBlocks, basesVersion, f
|
|
|
2148
2163
|
}
|
|
2149
2164
|
}
|
|
2150
2165
|
}
|
|
2151
|
-
async function checkVersionsCompatibility(projectDir = "."
|
|
2166
|
+
async function checkVersionsCompatibility(projectDir = ".") {
|
|
2152
2167
|
debug("checkVersionsCompatibility");
|
|
2153
2168
|
const template = processTemplate(getTemplateDef(projectDir));
|
|
2154
2169
|
const usedBlocks = processBlocks(getUsedBlocksDef(projectDir));
|
|
2155
2170
|
const basesVersion = processBases(getBloxFile(projectDir));
|
|
2156
2171
|
basesVersion[template.name] = { version: template.version, commit: "" };
|
|
2157
|
-
|
|
2158
|
-
await _checkVersionsCompatibility(template, usedBlocks, basesVersion, fallbackBlocks);
|
|
2172
|
+
await _checkVersionsCompatibility(template, usedBlocks, basesVersion);
|
|
2159
2173
|
}
|
|
2160
2174
|
|
|
2161
2175
|
// src/services/versions/select.ts
|
|
@@ -2195,33 +2209,119 @@ async function selectVersion(source, fromCommit) {
|
|
|
2195
2209
|
});
|
|
2196
2210
|
return versionsData[version2]?.lastCommit;
|
|
2197
2211
|
}
|
|
2212
|
+
async function resolveVersionCommit(source, version2) {
|
|
2213
|
+
const versionsData = await getAvailableVersions(source);
|
|
2214
|
+
const candidates = Object.keys(versionsData ?? {}).filter(
|
|
2215
|
+
(label2) => import_semver.default.valid(label2) && import_semver.default.major(label2) === version2
|
|
2216
|
+
);
|
|
2217
|
+
const label = candidates.sort(import_semver.default.rcompare)[0];
|
|
2218
|
+
const commit2 = label ? versionsData?.[label]?.lastCommit : void 0;
|
|
2219
|
+
if (!commit2) {
|
|
2220
|
+
throw new Error(`Version ${version2} is not available for ${source}`);
|
|
2221
|
+
}
|
|
2222
|
+
return commit2;
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
// src/services/apps.ts
|
|
2226
|
+
var hasGitRepo = (dir) => import_fs_extra13.default.existsSync(import_node_path17.default.join(dir, ".git"));
|
|
2227
|
+
var gitignorePath = (workspaceRoot) => import_node_path17.default.join(workspaceRoot, ".gitignore");
|
|
2228
|
+
var readGitignoreLines = (workspaceRoot) => {
|
|
2229
|
+
const file = gitignorePath(workspaceRoot);
|
|
2230
|
+
if (!import_fs_extra13.default.existsSync(file)) return [];
|
|
2231
|
+
return import_fs_extra13.default.readFileSync(file, "utf8").split(/\r?\n/);
|
|
2232
|
+
};
|
|
2233
|
+
var appIgnorePattern = (key) => `/${appsDir}/${key}/`;
|
|
2234
|
+
function ensureAppIgnored(workspaceRoot, key) {
|
|
2235
|
+
const lines = readGitignoreLines(workspaceRoot);
|
|
2236
|
+
const probe = normalizePath(import_node_path17.default.join(appsDir, key, "__probe__"));
|
|
2237
|
+
if (createGitignoreMatcher(lines).ignores(probe)) return;
|
|
2238
|
+
const pattern = appIgnorePattern(key);
|
|
2239
|
+
const kept = lines.filter((line, index) => line !== "" || index < lines.length - 1);
|
|
2240
|
+
import_fs_extra13.default.writeFileSync(
|
|
2241
|
+
gitignorePath(workspaceRoot),
|
|
2242
|
+
[...kept, pattern].join("\n") + "\n"
|
|
2243
|
+
);
|
|
2244
|
+
}
|
|
2245
|
+
function removeAppIgnore(workspaceRoot, key) {
|
|
2246
|
+
const file = gitignorePath(workspaceRoot);
|
|
2247
|
+
if (!import_fs_extra13.default.existsSync(file)) return;
|
|
2248
|
+
const pattern = appIgnorePattern(key);
|
|
2249
|
+
const lines = readGitignoreLines(workspaceRoot).filter(
|
|
2250
|
+
(line) => line.trim() !== pattern && line.trim() !== pattern.slice(1)
|
|
2251
|
+
);
|
|
2252
|
+
import_fs_extra13.default.writeFileSync(file, lines.join("\n"));
|
|
2253
|
+
}
|
|
2254
|
+
async function materializeApp({
|
|
2255
|
+
source,
|
|
2256
|
+
dir,
|
|
2257
|
+
branch,
|
|
2258
|
+
version: version2
|
|
2259
|
+
}) {
|
|
2260
|
+
await git.clone(source, dir, branch);
|
|
2261
|
+
let commit2 = version2 !== void 0 ? await resolveVersionCommit(source, version2) : await selectVersion(source);
|
|
2262
|
+
if (commit2) {
|
|
2263
|
+
await git.resetToCommit(commit2, dir);
|
|
2264
|
+
} else {
|
|
2265
|
+
commit2 = await git.getLatestCommitFromPath(dir);
|
|
2266
|
+
}
|
|
2267
|
+
await git.unInit(dir);
|
|
2268
|
+
await replacePlaceholders(dir, {});
|
|
2269
|
+
await migrateAll(false, dir);
|
|
2270
|
+
const definition = getTemplateDef(dir);
|
|
2271
|
+
if (!definition?.name) {
|
|
2272
|
+
throw new Error(`Missing app definition: ${import_node_path17.default.join(dir, bloxFilePath)}`);
|
|
2273
|
+
}
|
|
2274
|
+
await deletePattern(dir, definition.ignore);
|
|
2275
|
+
updateCheckpoint(definition.name, { commit: commit2, branch }, dir);
|
|
2276
|
+
await git.init(dir);
|
|
2277
|
+
return commit2;
|
|
2278
|
+
}
|
|
2279
|
+
var errorMessage = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
2280
|
+
async function materializeWorkspaceApps(workspaceRoot, registryApps) {
|
|
2281
|
+
const root = import_node_path17.default.resolve(workspaceRoot);
|
|
2282
|
+
const results = [];
|
|
2283
|
+
for (const [key, data] of Object.entries(registryApps)) {
|
|
2284
|
+
const appDir = import_node_path17.default.join(root, appsDir, key);
|
|
2285
|
+
if (import_fs_extra13.default.existsSync(appDir)) continue;
|
|
2286
|
+
try {
|
|
2287
|
+
await materializeApp({
|
|
2288
|
+
source: data.source,
|
|
2289
|
+
dir: appDir,
|
|
2290
|
+
version: data.version
|
|
2291
|
+
});
|
|
2292
|
+
results.push({ key, status: "added" });
|
|
2293
|
+
} catch (cause) {
|
|
2294
|
+
const reason = errorMessage(cause);
|
|
2295
|
+
import_prompts2.log.error(`App "${key}" failed to initialize: ${reason}`);
|
|
2296
|
+
if (await import_fs_extra13.default.pathExists(appDir)) {
|
|
2297
|
+
await import_fs_extra13.default.remove(appDir).catch(() => {
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
const keepGoing = isNonInteractive() ? true : await confirm({
|
|
2301
|
+
message: `Continue initializing the workspace without "${key}"?`,
|
|
2302
|
+
initialValue: true
|
|
2303
|
+
});
|
|
2304
|
+
if (!keepGoing) throw cause;
|
|
2305
|
+
results.push({ key, status: "failed", reason });
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
return results;
|
|
2309
|
+
}
|
|
2198
2310
|
|
|
2199
2311
|
// src/services/add.ts
|
|
2200
|
-
function createAddScope(projectDir,
|
|
2312
|
+
function createAddScope(projectDir, blocks, options = {}) {
|
|
2201
2313
|
const resolvedProject = import_node_path18.default.resolve(projectDir);
|
|
2202
2314
|
return {
|
|
2203
2315
|
projectDir: resolvedProject,
|
|
2204
2316
|
blocksRoot: import_node_path18.default.join(resolvedProject, blocksDir),
|
|
2205
|
-
workspaceRoot: import_node_path18.default.resolve(workspaceRoot),
|
|
2206
2317
|
blocks,
|
|
2207
|
-
rootBlocks: options.rootBlocks,
|
|
2208
2318
|
app: options.app
|
|
2209
2319
|
};
|
|
2210
2320
|
}
|
|
2211
|
-
function rootAddScope(scope) {
|
|
2212
|
-
return createAddScope(
|
|
2213
|
-
scope.workspaceRoot,
|
|
2214
|
-
scope.workspaceRoot,
|
|
2215
|
-
scope.rootBlocks || {},
|
|
2216
|
-
{
|
|
2217
|
-
rootBlocks: scope.rootBlocks
|
|
2218
|
-
}
|
|
2219
|
-
);
|
|
2220
|
-
}
|
|
2221
2321
|
function toAddScope(scope) {
|
|
2222
2322
|
if ("projectDir" in scope && "blocksRoot" in scope) return scope;
|
|
2223
2323
|
const cwd = import_node_path18.default.resolve(".");
|
|
2224
|
-
return createAddScope(cwd,
|
|
2324
|
+
return createAddScope(cwd, scope);
|
|
2225
2325
|
}
|
|
2226
2326
|
function recordResult(results, result) {
|
|
2227
2327
|
const index = results.findIndex(
|
|
@@ -2246,8 +2346,8 @@ function getInstalledBlockNames(blocksRoot = blocksDir) {
|
|
|
2246
2346
|
function findDependents(oldNames, ownedDir, blocksRoots) {
|
|
2247
2347
|
const dependents = [];
|
|
2248
2348
|
for (const root of blocksRoots) {
|
|
2249
|
-
if (!
|
|
2250
|
-
for (const entry of
|
|
2349
|
+
if (!import_fs_extra14.default.existsSync(root)) continue;
|
|
2350
|
+
for (const entry of import_fs_extra14.default.readdirSync(root, { withFileTypes: true })) {
|
|
2251
2351
|
if (!entry.isDirectory()) continue;
|
|
2252
2352
|
const dir = import_node_path18.default.join(root, entry.name);
|
|
2253
2353
|
if (import_node_path18.default.resolve(dir) === import_node_path18.default.resolve(ownedDir)) continue;
|
|
@@ -2260,13 +2360,7 @@ function findDependents(oldNames, ownedDir, blocksRoots) {
|
|
|
2260
2360
|
return dependents;
|
|
2261
2361
|
}
|
|
2262
2362
|
function dependentBlocksRoots(scope) {
|
|
2263
|
-
|
|
2264
|
-
return [
|
|
2265
|
-
scope.blocksRoot,
|
|
2266
|
-
...listApps(scope.workspaceRoot).map(
|
|
2267
|
-
(app) => import_node_path18.default.join(app.dir, blocksDir)
|
|
2268
|
-
)
|
|
2269
|
-
];
|
|
2363
|
+
return [scope.blocksRoot];
|
|
2270
2364
|
}
|
|
2271
2365
|
function renameDependency(dir, oldNames, newName) {
|
|
2272
2366
|
const file = getBloxFile(dir);
|
|
@@ -2275,7 +2369,7 @@ function renameDependency(dir, oldNames, newName) {
|
|
|
2275
2369
|
}
|
|
2276
2370
|
saveBloxFile(file, dir);
|
|
2277
2371
|
}
|
|
2278
|
-
function
|
|
2372
|
+
function errorMessage2(cause) {
|
|
2279
2373
|
return cause instanceof Error ? cause.message : String(cause);
|
|
2280
2374
|
}
|
|
2281
2375
|
function assertNoSymlinkParents(filename, projectDir = ".") {
|
|
@@ -2283,20 +2377,20 @@ function assertNoSymlinkParents(filename, projectDir = ".") {
|
|
|
2283
2377
|
for (let parent = import_node_path18.default.dirname(import_node_path18.default.resolve(filename)); parent !== root; parent = import_node_path18.default.dirname(parent)) {
|
|
2284
2378
|
if (parent === import_node_path18.default.dirname(parent))
|
|
2285
2379
|
throw new Error(`Path outside project: ${filename}`);
|
|
2286
|
-
if (
|
|
2380
|
+
if (import_fs_extra14.default.existsSync(parent) && import_fs_extra14.default.lstatSync(parent).isSymbolicLink()) {
|
|
2287
2381
|
throw new Error(`Symbolic link in block destination: ${filename}`);
|
|
2288
2382
|
}
|
|
2289
2383
|
}
|
|
2290
2384
|
}
|
|
2291
2385
|
async function snapshot(ownedPath, directory, entries = /* @__PURE__ */ new Map()) {
|
|
2292
|
-
for (const entry of await
|
|
2386
|
+
for (const entry of await import_fs_extra14.default.readdir(directory, { withFileTypes: true })) {
|
|
2293
2387
|
const filename = import_node_path18.default.join(directory, entry.name);
|
|
2294
2388
|
const owned = filename === ownedPath || filename.startsWith(ownedPath + import_node_path18.default.sep);
|
|
2295
2389
|
if (!owned && (entry.name === ".git" || entry.name === "node_modules"))
|
|
2296
2390
|
continue;
|
|
2297
2391
|
entries.set(filename, {
|
|
2298
2392
|
directory: entry.isDirectory(),
|
|
2299
|
-
metadata: entry.isFile() && entry.name === ".blox" ? await
|
|
2393
|
+
metadata: entry.isFile() && entry.name === ".blox" ? await import_fs_extra14.default.readFile(filename) : void 0
|
|
2300
2394
|
});
|
|
2301
2395
|
if (entry.isDirectory()) await snapshot(ownedPath, filename, entries);
|
|
2302
2396
|
}
|
|
@@ -2312,14 +2406,14 @@ async function cleanup(before, after) {
|
|
|
2312
2406
|
assertNoSymlinkParents(filename, import_node_path18.default.resolve("."));
|
|
2313
2407
|
if (!before.has(filename)) {
|
|
2314
2408
|
if (entry.directory) {
|
|
2315
|
-
await
|
|
2409
|
+
await import_fs_extra14.default.rmdir(filename);
|
|
2316
2410
|
} else {
|
|
2317
|
-
await
|
|
2411
|
+
await import_fs_extra14.default.unlink(filename);
|
|
2318
2412
|
}
|
|
2319
2413
|
} else {
|
|
2320
2414
|
const original = before.get(filename)?.metadata;
|
|
2321
|
-
if (original && !await
|
|
2322
|
-
const existing = await
|
|
2415
|
+
if (original && !await import_fs_extra14.default.pathExists(filename)) {
|
|
2416
|
+
const existing = await import_fs_extra14.default.lstat(filename).catch((cause) => {
|
|
2323
2417
|
if (cause.code !== "ENOENT") throw cause;
|
|
2324
2418
|
return void 0;
|
|
2325
2419
|
});
|
|
@@ -2328,32 +2422,21 @@ async function cleanup(before, after) {
|
|
|
2328
2422
|
`Cannot restore metadata through a symbolic link: ${filename}`
|
|
2329
2423
|
);
|
|
2330
2424
|
}
|
|
2331
|
-
await
|
|
2332
|
-
} else if (original && entry.metadata && !original.equals(entry.metadata) && (await
|
|
2333
|
-
await
|
|
2425
|
+
await import_fs_extra14.default.outputFile(filename, original);
|
|
2426
|
+
} else if (original && entry.metadata && !original.equals(entry.metadata) && (await import_fs_extra14.default.lstat(filename)).isFile() && (await import_fs_extra14.default.readFile(filename)).equals(entry.metadata)) {
|
|
2427
|
+
await import_fs_extra14.default.writeFile(filename, original);
|
|
2334
2428
|
}
|
|
2335
2429
|
}
|
|
2336
2430
|
} catch (cause) {
|
|
2337
2431
|
const code = cause.code;
|
|
2338
2432
|
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST") {
|
|
2339
|
-
failures.push(`${filename}: ${
|
|
2433
|
+
failures.push(`${filename}: ${errorMessage2(cause)}`);
|
|
2340
2434
|
}
|
|
2341
2435
|
}
|
|
2342
2436
|
}
|
|
2343
2437
|
if (failures.length)
|
|
2344
2438
|
throw new Error(`Cleanup incomplete: ${failures.join("; ")}`);
|
|
2345
2439
|
}
|
|
2346
|
-
function resolveDependencyScope(depName, scope) {
|
|
2347
|
-
if (!scope.app) return scope;
|
|
2348
|
-
if (scope.blocks[depName] || getInstalledBlockNames(scope.blocksRoot).has(depName)) {
|
|
2349
|
-
return scope;
|
|
2350
|
-
}
|
|
2351
|
-
const rootBlocksRoot = import_node_path18.default.join(scope.workspaceRoot, blocksDir);
|
|
2352
|
-
if (scope.rootBlocks?.[depName] || getInstalledBlockNames(rootBlocksRoot).has(depName)) {
|
|
2353
|
-
return rootAddScope(scope);
|
|
2354
|
-
}
|
|
2355
|
-
return scope;
|
|
2356
|
-
}
|
|
2357
2440
|
async function addBlockWithResult(block, results, branch, destination, visiting, isDependency, options, scope) {
|
|
2358
2441
|
if (visiting.has(block)) return false;
|
|
2359
2442
|
const warnings = [];
|
|
@@ -2373,7 +2456,7 @@ async function addBlockWithResult(block, results, branch, destination, visiting,
|
|
|
2373
2456
|
if (!installed && !blocks[block]) {
|
|
2374
2457
|
throw new Error(`Selected blocks not available in registries: ${block}`);
|
|
2375
2458
|
}
|
|
2376
|
-
const occupied = await
|
|
2459
|
+
const occupied = await import_fs_extra14.default.pathExists(blockPath);
|
|
2377
2460
|
if (installed && (isDependency || !occupied)) {
|
|
2378
2461
|
recordResult(results, {
|
|
2379
2462
|
block,
|
|
@@ -2418,8 +2501,8 @@ async function addBlockWithResult(block, results, branch, destination, visiting,
|
|
|
2418
2501
|
import_node_path18.default.resolve(scope.projectDir)
|
|
2419
2502
|
);
|
|
2420
2503
|
if (occupied) {
|
|
2421
|
-
backupPath = await
|
|
2422
|
-
await
|
|
2504
|
+
backupPath = await import_fs_extra14.default.mkdtemp(import_node_path18.default.join(import_node_os2.default.tmpdir(), "blox-replaced-"));
|
|
2505
|
+
await import_fs_extra14.default.move(blockPath, import_node_path18.default.join(backupPath, "block"));
|
|
2423
2506
|
}
|
|
2424
2507
|
await runTask(
|
|
2425
2508
|
{ start: `Fetching block: ${block}`, end: `Fetched block: ${block}` },
|
|
@@ -2468,7 +2551,7 @@ async function addBlockWithResult(block, results, branch, destination, visiting,
|
|
|
2468
2551
|
try {
|
|
2469
2552
|
await runLifecycleHookWithTask(blockPath, hook, `Run block ${hook}`);
|
|
2470
2553
|
} catch (cause) {
|
|
2471
|
-
const message = `${block}: ${hook} hook failed: ${
|
|
2554
|
+
const message = `${block}: ${hook} hook failed: ${errorMessage2(cause)}`;
|
|
2472
2555
|
import_prompts2.log.error(message);
|
|
2473
2556
|
const shouldContinue = isNonInteractive() ? true : await confirm({
|
|
2474
2557
|
message: `Continue adding ${block} despite the failed ${hook} hook?`,
|
|
@@ -2486,7 +2569,6 @@ async function addBlockWithResult(block, results, branch, destination, visiting,
|
|
|
2486
2569
|
import_node_path18.default.resolve(scope.projectDir)
|
|
2487
2570
|
);
|
|
2488
2571
|
for (const dependency of getBlockDef(blockPath).dependencies || []) {
|
|
2489
|
-
const depScope = resolveDependencyScope(dependency.name, scope);
|
|
2490
2572
|
await addBlockWithResult(
|
|
2491
2573
|
dependency.name,
|
|
2492
2574
|
results,
|
|
@@ -2495,10 +2577,10 @@ async function addBlockWithResult(block, results, branch, destination, visiting,
|
|
|
2495
2577
|
visiting,
|
|
2496
2578
|
true,
|
|
2497
2579
|
options,
|
|
2498
|
-
|
|
2580
|
+
scope
|
|
2499
2581
|
);
|
|
2500
2582
|
}
|
|
2501
|
-
if (backupPath) await
|
|
2583
|
+
if (backupPath) await import_fs_extra14.default.remove(backupPath);
|
|
2502
2584
|
recordResult(results, {
|
|
2503
2585
|
block,
|
|
2504
2586
|
status: warnings.length ? "warning" : "added",
|
|
@@ -2506,7 +2588,7 @@ async function addBlockWithResult(block, results, branch, destination, visiting,
|
|
|
2506
2588
|
});
|
|
2507
2589
|
return true;
|
|
2508
2590
|
} catch (cause) {
|
|
2509
|
-
let reason =
|
|
2591
|
+
let reason = errorMessage2(cause);
|
|
2510
2592
|
if (before) {
|
|
2511
2593
|
try {
|
|
2512
2594
|
await cleanup(
|
|
@@ -2517,16 +2599,16 @@ async function addBlockWithResult(block, results, branch, destination, visiting,
|
|
|
2517
2599
|
)
|
|
2518
2600
|
);
|
|
2519
2601
|
} catch (cleanupError) {
|
|
2520
|
-
reason += `; ${
|
|
2602
|
+
reason += `; ${errorMessage2(cleanupError)}`;
|
|
2521
2603
|
}
|
|
2522
2604
|
}
|
|
2523
2605
|
if (backupPath) {
|
|
2524
2606
|
try {
|
|
2525
|
-
await
|
|
2526
|
-
await
|
|
2527
|
-
await
|
|
2607
|
+
await import_fs_extra14.default.remove(blockPath);
|
|
2608
|
+
await import_fs_extra14.default.move(import_node_path18.default.join(backupPath, "block"), blockPath);
|
|
2609
|
+
await import_fs_extra14.default.remove(backupPath);
|
|
2528
2610
|
} catch (restoreError) {
|
|
2529
|
-
reason += `; failed to restore previous block (kept at ${backupPath}): ${
|
|
2611
|
+
reason += `; failed to restore previous block (kept at ${backupPath}): ${errorMessage2(restoreError)}`;
|
|
2530
2612
|
}
|
|
2531
2613
|
}
|
|
2532
2614
|
recordResult(results, { block, status: "failed", reason });
|
|
@@ -2559,7 +2641,7 @@ async function addBlocks(selected, scope, branch, destination, options = {}) {
|
|
|
2559
2641
|
async function addApp(appKey, appData, workspaceRoot, branch, options = {}) {
|
|
2560
2642
|
const result = { block: `app/${appKey}`, status: "failed" };
|
|
2561
2643
|
const root = import_node_path18.default.resolve(workspaceRoot);
|
|
2562
|
-
const appPath = import_node_path18.default.join(root, appsDir,
|
|
2644
|
+
const appPath = import_node_path18.default.join(root, appsDir, appKey);
|
|
2563
2645
|
let backupPath;
|
|
2564
2646
|
try {
|
|
2565
2647
|
const relative = import_node_path18.default.relative(
|
|
@@ -2570,8 +2652,8 @@ async function addApp(appKey, appData, workspaceRoot, branch, options = {}) {
|
|
|
2570
2652
|
throw new Error(`Invalid app destination: ${appPath}`);
|
|
2571
2653
|
}
|
|
2572
2654
|
assertNoSymlinkParents(appPath, root);
|
|
2573
|
-
if (await
|
|
2574
|
-
const isApp =
|
|
2655
|
+
if (await import_fs_extra14.default.pathExists(appPath)) {
|
|
2656
|
+
const isApp = import_fs_extra14.default.existsSync(import_node_path18.default.join(appPath, bloxFilePath));
|
|
2575
2657
|
if (isApp) {
|
|
2576
2658
|
result.status = "skipped";
|
|
2577
2659
|
result.reason = "Already installed";
|
|
@@ -2586,39 +2668,29 @@ async function addApp(appKey, appData, workspaceRoot, branch, options = {}) {
|
|
|
2586
2668
|
result.reason = isNonInteractive() ? "Destination already exists (pass --replace to overwrite)" : "Destination already exists";
|
|
2587
2669
|
return result;
|
|
2588
2670
|
}
|
|
2589
|
-
backupPath = await
|
|
2671
|
+
backupPath = await import_fs_extra14.default.mkdtemp(
|
|
2590
2672
|
import_node_path18.default.join(import_node_os2.default.tmpdir(), "blox-app-replaced-")
|
|
2591
2673
|
);
|
|
2592
|
-
await
|
|
2674
|
+
await import_fs_extra14.default.move(appPath, import_node_path18.default.join(backupPath, "app"));
|
|
2593
2675
|
}
|
|
2594
2676
|
const warnings = [];
|
|
2595
2677
|
await runTask(
|
|
2596
2678
|
{ start: `Fetching app: ${appKey}`, end: `Fetched app: ${appKey}` },
|
|
2597
2679
|
async () => {
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
}
|
|
2606
|
-
await git.unInit(appPath);
|
|
2607
|
-
await replacePlaceholders(appPath, {});
|
|
2608
|
-
await migrateAll(false, appPath);
|
|
2609
|
-
const definition = getTemplateDef(appPath);
|
|
2610
|
-
if (!definition?.name) {
|
|
2611
|
-
throw new Error(`Missing app definition: ${appPath}/${bloxFilePath}`);
|
|
2612
|
-
}
|
|
2613
|
-
await deletePattern(appPath, definition.ignore);
|
|
2614
|
-
updateCheckpoint(definition.name, { commit: commit2, branch }, appPath);
|
|
2680
|
+
await materializeApp({
|
|
2681
|
+
source: appData.source,
|
|
2682
|
+
dir: appPath,
|
|
2683
|
+
branch,
|
|
2684
|
+
version: appData.version
|
|
2685
|
+
});
|
|
2686
|
+
ensureAppIgnored(root, import_node_path18.default.basename(appPath));
|
|
2615
2687
|
}
|
|
2616
2688
|
);
|
|
2617
2689
|
for (const hook of ["init", "add"]) {
|
|
2618
2690
|
try {
|
|
2619
2691
|
await runLifecycleHookWithTask(appPath, hook, `Run app ${hook}`);
|
|
2620
2692
|
} catch (cause) {
|
|
2621
|
-
const message = `${appKey}: ${hook} hook failed: ${
|
|
2693
|
+
const message = `${appKey}: ${hook} hook failed: ${errorMessage2(cause)}`;
|
|
2622
2694
|
import_prompts2.log.error(message);
|
|
2623
2695
|
const shouldContinue = isNonInteractive() ? true : await confirm({
|
|
2624
2696
|
message: `Continue adding ${appKey} despite the failed ${hook} hook?`,
|
|
@@ -2629,25 +2701,25 @@ async function addApp(appKey, appData, workspaceRoot, branch, options = {}) {
|
|
|
2629
2701
|
import_prompts2.log.warn(`Adding ${appKey} with a warning: ${message}`);
|
|
2630
2702
|
}
|
|
2631
2703
|
}
|
|
2632
|
-
if (backupPath) await
|
|
2704
|
+
if (backupPath) await import_fs_extra14.default.remove(backupPath);
|
|
2633
2705
|
result.status = warnings.length ? "warning" : "added";
|
|
2634
2706
|
result.warnings = warnings;
|
|
2635
2707
|
return result;
|
|
2636
2708
|
} catch (cause) {
|
|
2637
|
-
let reason =
|
|
2709
|
+
let reason = errorMessage2(cause);
|
|
2638
2710
|
if (backupPath) {
|
|
2639
2711
|
try {
|
|
2640
|
-
await
|
|
2641
|
-
await
|
|
2642
|
-
await
|
|
2712
|
+
await import_fs_extra14.default.remove(appPath);
|
|
2713
|
+
await import_fs_extra14.default.move(import_node_path18.default.join(backupPath, "app"), appPath);
|
|
2714
|
+
await import_fs_extra14.default.remove(backupPath);
|
|
2643
2715
|
} catch (restoreError) {
|
|
2644
|
-
reason += `; failed to restore previous app (kept at ${backupPath}): ${
|
|
2716
|
+
reason += `; failed to restore previous app (kept at ${backupPath}): ${errorMessage2(restoreError)}`;
|
|
2645
2717
|
}
|
|
2646
|
-
} else if (await
|
|
2718
|
+
} else if (await import_fs_extra14.default.pathExists(appPath)) {
|
|
2647
2719
|
try {
|
|
2648
|
-
await
|
|
2720
|
+
await import_fs_extra14.default.remove(appPath);
|
|
2649
2721
|
} catch (removeError) {
|
|
2650
|
-
reason += `; failed to clean up ${appPath}: ${
|
|
2722
|
+
reason += `; failed to clean up ${appPath}: ${errorMessage2(removeError)}`;
|
|
2651
2723
|
}
|
|
2652
2724
|
}
|
|
2653
2725
|
result.status = "failed";
|
|
@@ -2750,7 +2822,8 @@ and can be combined with either mode.`
|
|
|
2750
2822
|
if (isNonInteractive() && !selectedBlocks?.length) {
|
|
2751
2823
|
throw new MissingArgumentsError(["blocks"]);
|
|
2752
2824
|
}
|
|
2753
|
-
|
|
2825
|
+
const context = resolveContext(".", args.app);
|
|
2826
|
+
if (await git.hasUncommittedChanges(context.projectDir)) {
|
|
2754
2827
|
if (isNonInteractive()) {
|
|
2755
2828
|
throw new CliError(
|
|
2756
2829
|
"Make sure to commit any changes first",
|
|
@@ -2761,7 +2834,6 @@ and can be combined with either mode.`
|
|
|
2761
2834
|
import_prompts2.log.warn(fmt.yellow("Make sure to commit any changes first"));
|
|
2762
2835
|
return;
|
|
2763
2836
|
}
|
|
2764
|
-
const context = resolveContext(".", args.app);
|
|
2765
2837
|
await migrateAll(false, context.workspaceRoot);
|
|
2766
2838
|
await syncRegistries();
|
|
2767
2839
|
const rootTemplateDef = getTemplateDef(context.workspaceRoot);
|
|
@@ -2770,22 +2842,12 @@ and can be combined with either mode.`
|
|
|
2770
2842
|
let availableApps = {};
|
|
2771
2843
|
if (context.app) {
|
|
2772
2844
|
const appDef = getTemplateDef(context.projectDir);
|
|
2773
|
-
const blocks = await
|
|
2774
|
-
|
|
2775
|
-
rootTemplateName,
|
|
2776
|
-
appDef
|
|
2777
|
-
);
|
|
2778
|
-
const rootBlocks = rootTemplateName ? await getAvailableBlocks(rootTemplateDef) : {};
|
|
2779
|
-
scope = createAddScope(context.projectDir, context.workspaceRoot, blocks, {
|
|
2780
|
-
rootBlocks,
|
|
2781
|
-
app: context.app
|
|
2782
|
-
});
|
|
2845
|
+
const blocks = await getAvailableBlocks(appDef);
|
|
2846
|
+
scope = createAddScope(context.projectDir, blocks, { app: context.app });
|
|
2783
2847
|
} else {
|
|
2784
2848
|
const blocks = rootTemplateName ? await getAvailableBlocks(rootTemplateDef) : {};
|
|
2785
2849
|
availableApps = rootTemplateName ? await getAvailableApps(rootTemplateDef) : {};
|
|
2786
|
-
scope = createAddScope(context.projectDir,
|
|
2787
|
-
rootBlocks: blocks
|
|
2788
|
-
});
|
|
2850
|
+
scope = createAddScope(context.projectDir, blocks);
|
|
2789
2851
|
}
|
|
2790
2852
|
const installed = getInstalledBlockNames(scope.blocksRoot);
|
|
2791
2853
|
const installedApps = new Set(listApps(context.workspaceRoot).map((app) => app.key));
|
|
@@ -2882,7 +2944,7 @@ and can be combined with either mode.`
|
|
|
2882
2944
|
if (results.some((result) => result.status === "added" || result.status === "warning")) {
|
|
2883
2945
|
await runLifecycleHookWithTask(context.projectDir, "add", "Run template add");
|
|
2884
2946
|
}
|
|
2885
|
-
await checkVersionsCompatibility(context.projectDir
|
|
2947
|
+
await checkVersionsCompatibility(context.projectDir);
|
|
2886
2948
|
} finally {
|
|
2887
2949
|
process.stdout.write(formatAddSummary(results, process.stdout.columns || 80));
|
|
2888
2950
|
}
|
|
@@ -2975,7 +3037,7 @@ function buildBranchName(commitType, title) {
|
|
|
2975
3037
|
|
|
2976
3038
|
// src/services/contribute/utils/getExcludedPrefixesForTarget.ts
|
|
2977
3039
|
var import_node_path19 = __toESM(require("path"));
|
|
2978
|
-
var
|
|
3040
|
+
var import_fs_extra15 = __toESM(require("fs-extra"));
|
|
2979
3041
|
function getExcludedPrefixesForTarget(target, cwd) {
|
|
2980
3042
|
if (target.type === ContributionTargetType.BLOCK) {
|
|
2981
3043
|
return [];
|
|
@@ -2983,12 +3045,12 @@ function getExcludedPrefixesForTarget(target, cwd) {
|
|
|
2983
3045
|
const projectDir = !target.projectDir || target.projectDir === "." ? "" : target.projectDir;
|
|
2984
3046
|
const excluded = [];
|
|
2985
3047
|
const blocksPath = import_node_path19.default.join(cwd, projectDir, blocksDir);
|
|
2986
|
-
if (
|
|
2987
|
-
const entries =
|
|
3048
|
+
if (import_fs_extra15.default.existsSync(blocksPath)) {
|
|
3049
|
+
const entries = import_fs_extra15.default.readdirSync(blocksPath, { withFileTypes: true });
|
|
2988
3050
|
for (const entry of entries) {
|
|
2989
3051
|
if (!entry.isDirectory()) continue;
|
|
2990
3052
|
const blockBloxFile = import_node_path19.default.join(blocksPath, entry.name, bloxFilePath);
|
|
2991
|
-
if (
|
|
3053
|
+
if (import_fs_extra15.default.existsSync(blockBloxFile)) {
|
|
2992
3054
|
excluded.push(
|
|
2993
3055
|
normalizePath(import_node_path19.default.join(projectDir, blocksDir, entry.name)) + "/"
|
|
2994
3056
|
);
|
|
@@ -2997,12 +3059,12 @@ function getExcludedPrefixesForTarget(target, cwd) {
|
|
|
2997
3059
|
}
|
|
2998
3060
|
if (!projectDir) {
|
|
2999
3061
|
const appsPath = import_node_path19.default.join(cwd, appsDir);
|
|
3000
|
-
if (
|
|
3001
|
-
const entries =
|
|
3062
|
+
if (import_fs_extra15.default.existsSync(appsPath)) {
|
|
3063
|
+
const entries = import_fs_extra15.default.readdirSync(appsPath, { withFileTypes: true });
|
|
3002
3064
|
for (const entry of entries) {
|
|
3003
3065
|
if (!entry.isDirectory()) continue;
|
|
3004
3066
|
const appBloxFile = import_node_path19.default.join(appsPath, entry.name, bloxFilePath);
|
|
3005
|
-
if (
|
|
3067
|
+
if (import_fs_extra15.default.existsSync(appBloxFile)) {
|
|
3006
3068
|
excluded.push(normalizePath(import_node_path19.default.join(appsDir, entry.name)) + "/");
|
|
3007
3069
|
}
|
|
3008
3070
|
}
|
|
@@ -3067,7 +3129,7 @@ var componentLabel = (component) => {
|
|
|
3067
3129
|
}
|
|
3068
3130
|
return `${component.type}/${component.name}`;
|
|
3069
3131
|
};
|
|
3070
|
-
var discoverContributionTargets = (cwd) => discoverBloxComponents(cwd).map((component) => ({
|
|
3132
|
+
var discoverContributionTargets = (cwd) => discoverBloxComponents(cwd, { scope: "project" }).map((component) => ({
|
|
3071
3133
|
...component,
|
|
3072
3134
|
label: componentLabel(component),
|
|
3073
3135
|
hint: componentHint(component)
|
|
@@ -3182,8 +3244,7 @@ async function remoteBranchExists(repoUrl, branch) {
|
|
|
3182
3244
|
}
|
|
3183
3245
|
}
|
|
3184
3246
|
|
|
3185
|
-
// src/services/contribute/
|
|
3186
|
-
var MANUAL_BRANCH_OPTION = "__manual__";
|
|
3247
|
+
// src/services/contribute/utils/assertContributeFlagsComplete.ts
|
|
3187
3248
|
function assertContributeFlagsComplete(flags) {
|
|
3188
3249
|
if (!isNonInteractive()) {
|
|
3189
3250
|
return;
|
|
@@ -3223,6 +3284,9 @@ function assertContributeFlagsComplete(flags) {
|
|
|
3223
3284
|
throw new MissingArgumentsError(missing);
|
|
3224
3285
|
}
|
|
3225
3286
|
}
|
|
3287
|
+
|
|
3288
|
+
// src/services/contribute/ContributionWorkflow.ts
|
|
3289
|
+
var MANUAL_BRANCH_OPTION = "__manual__";
|
|
3226
3290
|
var ContributionWorkflow = class {
|
|
3227
3291
|
constructor(ctx, logger, targetSelector, tmpRepo, commitSelector, commitApplier, pullRequest) {
|
|
3228
3292
|
this.ctx = ctx;
|
|
@@ -3678,7 +3742,7 @@ Expected remote ${remoteHead}, local checkpoint ${checkpoint.commit}.`
|
|
|
3678
3742
|
|
|
3679
3743
|
// src/services/contribute/services/CommitApplierService.ts
|
|
3680
3744
|
var import_node_path21 = __toESM(require("path"));
|
|
3681
|
-
var
|
|
3745
|
+
var import_fs_extra17 = __toESM(require("fs-extra"));
|
|
3682
3746
|
var import_isEqual2 = __toESM(require("lodash/isEqual"));
|
|
3683
3747
|
|
|
3684
3748
|
// src/services/breakingChange.ts
|
|
@@ -3756,7 +3820,7 @@ var detectBreakingChanges = (commits) => {
|
|
|
3756
3820
|
|
|
3757
3821
|
// src/services/ide.ts
|
|
3758
3822
|
var import_node_path20 = __toESM(require("path"));
|
|
3759
|
-
var
|
|
3823
|
+
var import_fs_extra16 = __toESM(require("fs-extra"));
|
|
3760
3824
|
var KNOWN_IDES = [
|
|
3761
3825
|
{ id: "vscode", name: "Visual Studio Code", command: "code" },
|
|
3762
3826
|
{ id: "cursor", name: "Cursor", command: "cursor" },
|
|
@@ -3771,11 +3835,11 @@ var windowsExecutableNames = (command2, pathext) => {
|
|
|
3771
3835
|
};
|
|
3772
3836
|
var isExecutableFile = async (filePath) => {
|
|
3773
3837
|
try {
|
|
3774
|
-
const stat = await
|
|
3838
|
+
const stat = await import_fs_extra16.default.stat(filePath);
|
|
3775
3839
|
if (!stat.isFile()) {
|
|
3776
3840
|
return false;
|
|
3777
3841
|
}
|
|
3778
|
-
await
|
|
3842
|
+
await import_fs_extra16.default.access(filePath, import_fs_extra16.default.constants.X_OK);
|
|
3779
3843
|
return true;
|
|
3780
3844
|
} catch {
|
|
3781
3845
|
return false;
|
|
@@ -3787,7 +3851,7 @@ var isCommandOnPath = async (command2, env = process.env, platform = process.pla
|
|
|
3787
3851
|
for (const dir of dirs) {
|
|
3788
3852
|
if (platform === "win32") {
|
|
3789
3853
|
for (const name of windowsExecutableNames(command2, env.PATHEXT)) {
|
|
3790
|
-
if (await
|
|
3854
|
+
if (await import_fs_extra16.default.pathExists(import_node_path20.default.join(dir, name))) {
|
|
3791
3855
|
return true;
|
|
3792
3856
|
}
|
|
3793
3857
|
}
|
|
@@ -3824,7 +3888,7 @@ var import_core2 = require("@clack/core");
|
|
|
3824
3888
|
|
|
3825
3889
|
// src/shared/prompts/selectWithSearch.ts
|
|
3826
3890
|
var import_core = require("@clack/core");
|
|
3827
|
-
var
|
|
3891
|
+
var import_prompts14 = require("@clack/prompts");
|
|
3828
3892
|
var SEARCH_REQUESTED = Symbol("search-requested");
|
|
3829
3893
|
function isSelectedOption(option2, selectedValues) {
|
|
3830
3894
|
return selectedValues.includes(option2.value);
|
|
@@ -3845,8 +3909,8 @@ function stateSymbol(state) {
|
|
|
3845
3909
|
}
|
|
3846
3910
|
}
|
|
3847
3911
|
function exitIfRealCancel(result) {
|
|
3848
|
-
if ((0,
|
|
3849
|
-
(0,
|
|
3912
|
+
if ((0, import_prompts14.isCancel)(result)) {
|
|
3913
|
+
(0, import_prompts14.cancel)("Canceled");
|
|
3850
3914
|
process.exit(0);
|
|
3851
3915
|
}
|
|
3852
3916
|
}
|
|
@@ -3982,6 +4046,35 @@ var showConflictSummary = (commit2, files, stillRemaining) => {
|
|
|
3982
4046
|
];
|
|
3983
4047
|
import_prompts2.log.message(["", ...drawBox(title, bodyLines), ""].join("\n"));
|
|
3984
4048
|
};
|
|
4049
|
+
var showStagedConflictMarkers = (files) => {
|
|
4050
|
+
const bodyLines = [
|
|
4051
|
+
"The following staged files contain lines",
|
|
4052
|
+
"that resemble Git conflict markers:",
|
|
4053
|
+
"",
|
|
4054
|
+
...files.map((f) => ` ${fmt.red("\u2022 " + f)}`),
|
|
4055
|
+
"",
|
|
4056
|
+
"Make sure these are intentional before",
|
|
4057
|
+
"continuing."
|
|
4058
|
+
];
|
|
4059
|
+
import_prompts2.log.message(
|
|
4060
|
+
[
|
|
4061
|
+
"",
|
|
4062
|
+
...drawBox(fmt.yellow(fmt.bold(" \u26A0 Potential conflict markers detected ")), bodyLines),
|
|
4063
|
+
""
|
|
4064
|
+
].join("\n")
|
|
4065
|
+
);
|
|
4066
|
+
};
|
|
4067
|
+
var promptStagedMarkersAction = async (files) => {
|
|
4068
|
+
showStagedConflictMarkers(files);
|
|
4069
|
+
return select({
|
|
4070
|
+
message: "What would you like to do?",
|
|
4071
|
+
options: [
|
|
4072
|
+
{ value: "resolve", label: "Keep resolving conflicts" },
|
|
4073
|
+
{ value: "continue", label: "Continue anyway" },
|
|
4074
|
+
{ value: "abort", label: "Abort contribution" }
|
|
4075
|
+
]
|
|
4076
|
+
});
|
|
4077
|
+
};
|
|
3985
4078
|
var selectIdeForConflictResolution = async (ides, tmpRepoCwd) => {
|
|
3986
4079
|
const options = [
|
|
3987
4080
|
...ides.map((ide) => ({ value: ide.id, label: ide.name })),
|
|
@@ -4067,7 +4160,7 @@ function parseJsonObject(raw) {
|
|
|
4067
4160
|
}
|
|
4068
4161
|
}
|
|
4069
4162
|
function hasGitConflictMarkers(content) {
|
|
4070
|
-
return /^(<{7}
|
|
4163
|
+
return /^(<{7}|>{7}|\|{7})/m.test(content);
|
|
4071
4164
|
}
|
|
4072
4165
|
function withGovernedKeysFrom(value, source, governedKeys) {
|
|
4073
4166
|
const result = { ...value };
|
|
@@ -4330,7 +4423,7 @@ ${e instanceof Error ? e.message : String(e)}`);
|
|
|
4330
4423
|
return false;
|
|
4331
4424
|
}
|
|
4332
4425
|
this.logger.debug("apply.commit.blox_merge_resolved", { file });
|
|
4333
|
-
await
|
|
4426
|
+
await import_fs_extra17.default.outputFile(import_node_path21.default.join(tmpRepoCwd, file), JSON.stringify(merge3.value, null, 2));
|
|
4334
4427
|
await git.add(file, tmpRepoCwd);
|
|
4335
4428
|
return true;
|
|
4336
4429
|
}
|
|
@@ -4397,7 +4490,7 @@ ${e instanceof Error ? e.message : String(e)}`);
|
|
|
4397
4490
|
return;
|
|
4398
4491
|
}
|
|
4399
4492
|
this.logger.debug("apply.commit.blox_governed_keys_restored", { file });
|
|
4400
|
-
await
|
|
4493
|
+
await import_fs_extra17.default.outputFile(import_node_path21.default.join(tmpRepoCwd, file), JSON.stringify(enforced, null, 2));
|
|
4401
4494
|
await git.add(file, tmpRepoCwd);
|
|
4402
4495
|
}
|
|
4403
4496
|
async waitUntilUserResolvesConflicts(opts, commit2, remainingCommits, conflictingFiles) {
|
|
@@ -4419,9 +4512,28 @@ ${e instanceof Error ? e.message : String(e)}`);
|
|
|
4419
4512
|
return;
|
|
4420
4513
|
}
|
|
4421
4514
|
const ides = await detectAvailableIdes();
|
|
4515
|
+
const nonBloxConflictingFiles = conflictingFiles.filter((f) => !isBloxConfigFile(f));
|
|
4516
|
+
let stagedMarkerFiles = [];
|
|
4422
4517
|
let stillRemaining = false;
|
|
4423
|
-
while (remainingConflicts.length) {
|
|
4424
|
-
|
|
4518
|
+
while (remainingConflicts.length || stagedMarkerFiles.length) {
|
|
4519
|
+
if (remainingConflicts.length) {
|
|
4520
|
+
showConflictSummary(commit2, remainingConflicts, stillRemaining);
|
|
4521
|
+
} else {
|
|
4522
|
+
const action = await promptStagedMarkersAction(stagedMarkerFiles);
|
|
4523
|
+
if (action === "continue") {
|
|
4524
|
+
this.logger.warn("commit.staged_markers_overridden", {
|
|
4525
|
+
files: stagedMarkerFiles
|
|
4526
|
+
});
|
|
4527
|
+
return;
|
|
4528
|
+
}
|
|
4529
|
+
if (action === "abort") {
|
|
4530
|
+
throw new CliError(
|
|
4531
|
+
"Contribution aborted by user.",
|
|
4532
|
+
"ABORTED",
|
|
4533
|
+
exitCodes.GENERAL
|
|
4534
|
+
);
|
|
4535
|
+
}
|
|
4536
|
+
}
|
|
4425
4537
|
if (ides.length) {
|
|
4426
4538
|
const ide = await selectIdeForConflictResolution(ides, tmpRepoCwd);
|
|
4427
4539
|
if (ide) {
|
|
@@ -4443,9 +4555,29 @@ Resolve the conflicts manually using the instructions below.`
|
|
|
4443
4555
|
message: "Press Enter once you have resolved and staged all changes to continue..."
|
|
4444
4556
|
});
|
|
4445
4557
|
remainingConflicts = await git.getUnmergedFiles(tmpRepoCwd);
|
|
4558
|
+
stagedMarkerFiles = remainingConflicts.length ? [] : await this.getStagedFilesWithConflictMarkers(
|
|
4559
|
+
nonBloxConflictingFiles,
|
|
4560
|
+
tmpRepoCwd
|
|
4561
|
+
);
|
|
4446
4562
|
stillRemaining = true;
|
|
4447
4563
|
}
|
|
4448
4564
|
}
|
|
4565
|
+
/**
|
|
4566
|
+
* Returns conflicted files whose staged resolution still contains Git
|
|
4567
|
+
* conflict markers — i.e. the user ran `git add` without removing the
|
|
4568
|
+
* <<<<<<<, =======, or >>>>>>> lines. Files staged as deletions (no
|
|
4569
|
+
* stage-0 entry) count as resolved.
|
|
4570
|
+
*/
|
|
4571
|
+
async getStagedFilesWithConflictMarkers(files, tmpRepoCwd) {
|
|
4572
|
+
const flagged = [];
|
|
4573
|
+
for (const file of files) {
|
|
4574
|
+
const staged = await git.readFileFromIndex(file, 0, tmpRepoCwd);
|
|
4575
|
+
if (staged && hasGitConflictMarkers(staged)) {
|
|
4576
|
+
flagged.push(file);
|
|
4577
|
+
}
|
|
4578
|
+
}
|
|
4579
|
+
return flagged;
|
|
4580
|
+
}
|
|
4449
4581
|
buildApplyCommitMessage(opts, commit2) {
|
|
4450
4582
|
const header = `${opts.title}${opts.commits.length > 1 ? ` (cherry-pick: ${commit2.slice(0, 7)})` : ""}`;
|
|
4451
4583
|
return buildCommitMessage({
|
|
@@ -4890,7 +5022,7 @@ var PullRequestService = class {
|
|
|
4890
5022
|
// src/services/contribute/services/TmpRepoService.ts
|
|
4891
5023
|
var import_node_os3 = require("os");
|
|
4892
5024
|
var import_node_path22 = __toESM(require("path"));
|
|
4893
|
-
var
|
|
5025
|
+
var import_fs_extra18 = __toESM(require("fs-extra"));
|
|
4894
5026
|
var TmpRepoService = class {
|
|
4895
5027
|
constructor(logger) {
|
|
4896
5028
|
this.logger = logger;
|
|
@@ -4921,7 +5053,7 @@ var TmpRepoService = class {
|
|
|
4921
5053
|
repoUrl: opts.repoUrl,
|
|
4922
5054
|
branch: opts.branch
|
|
4923
5055
|
});
|
|
4924
|
-
if (await
|
|
5056
|
+
if (await import_fs_extra18.default.pathExists(dir)) {
|
|
4925
5057
|
this.logger.debug(`${tempRepoName} reuse_tmp_local_repo`, { dir });
|
|
4926
5058
|
try {
|
|
4927
5059
|
await this.refreshExistingTmpRepo(dir, opts.branch);
|
|
@@ -4932,10 +5064,10 @@ var TmpRepoService = class {
|
|
|
4932
5064
|
dir,
|
|
4933
5065
|
message: e instanceof Error ? e.message : String(e)
|
|
4934
5066
|
});
|
|
4935
|
-
await
|
|
5067
|
+
await import_fs_extra18.default.remove(dir);
|
|
4936
5068
|
}
|
|
4937
5069
|
}
|
|
4938
|
-
await
|
|
5070
|
+
await import_fs_extra18.default.ensureDir(import_node_path22.default.dirname(dir));
|
|
4939
5071
|
await git.clone(opts.repoUrl, dir, opts.branch);
|
|
4940
5072
|
taskSpinner.stop("Prepared tmp repo");
|
|
4941
5073
|
return dir;
|
|
@@ -5004,16 +5136,16 @@ controls the output format and can be combined with either mode.`
|
|
|
5004
5136
|
initExecutionMode(flags);
|
|
5005
5137
|
try {
|
|
5006
5138
|
assertContributeFlagsComplete(flags);
|
|
5007
|
-
|
|
5139
|
+
const context = resolveContext(".", flags.app);
|
|
5140
|
+
if (await git.hasUncommittedChanges(context.projectDir)) {
|
|
5008
5141
|
throw new Error(
|
|
5009
5142
|
"Make sure to commit or stash any changes in the app repo before contributing."
|
|
5010
5143
|
);
|
|
5011
5144
|
}
|
|
5012
|
-
const context = resolveContext(".", flags.app);
|
|
5013
5145
|
await migrateAll(true, context.workspaceRoot);
|
|
5014
5146
|
await syncRegistries();
|
|
5015
5147
|
const workflow = await buildContributionWorkflow({
|
|
5016
|
-
cwd: context.
|
|
5148
|
+
cwd: context.projectDir,
|
|
5017
5149
|
force: !!flags.force
|
|
5018
5150
|
});
|
|
5019
5151
|
const results = await workflow.runFromFlags(flags);
|
|
@@ -5061,8 +5193,10 @@ mode.`
|
|
|
5061
5193
|
).action(async (args) => {
|
|
5062
5194
|
initExecutionMode(args);
|
|
5063
5195
|
const { basic, base: baseFlag } = args;
|
|
5196
|
+
let projectDir = ".";
|
|
5064
5197
|
try {
|
|
5065
5198
|
const context = resolveContext(".", args.app);
|
|
5199
|
+
projectDir = context.projectDir;
|
|
5066
5200
|
const cwd = process.cwd();
|
|
5067
5201
|
process.chdir(context.projectDir);
|
|
5068
5202
|
try {
|
|
@@ -5116,7 +5250,7 @@ mode.`
|
|
|
5116
5250
|
} catch (e) {
|
|
5117
5251
|
if (!isDebugMode() && !(e instanceof CliError)) {
|
|
5118
5252
|
import_prompts2.log.warn("Error happened, Will rollback changes");
|
|
5119
|
-
await git.rollback();
|
|
5253
|
+
await git.rollback(projectDir);
|
|
5120
5254
|
}
|
|
5121
5255
|
handleCommandError(e);
|
|
5122
5256
|
}
|
|
@@ -5124,7 +5258,7 @@ mode.`
|
|
|
5124
5258
|
|
|
5125
5259
|
// src/commands/doctor/checks/schema-validation/fix.ts
|
|
5126
5260
|
var import_node_path23 = __toESM(require("path"));
|
|
5127
|
-
var
|
|
5261
|
+
var import_fs_extra19 = __toESM(require("fs-extra"));
|
|
5128
5262
|
async function fixMetadataSchema(context, diagnostic) {
|
|
5129
5263
|
if (!diagnostic.filePath) {
|
|
5130
5264
|
return { status: "skipped", message: "Diagnostic has no associated file." };
|
|
@@ -5147,7 +5281,7 @@ async function fixMetadataSchema(context, diagnostic) {
|
|
|
5147
5281
|
async function migrateBloxFile(context, filePath) {
|
|
5148
5282
|
const dir = import_node_path23.default.dirname(import_node_path23.default.join(context.projectRoot, filePath));
|
|
5149
5283
|
const name = filePath === bloxFilePath ? "app" : import_node_path23.default.basename(dir);
|
|
5150
|
-
const current = await
|
|
5284
|
+
const current = await import_fs_extra19.default.readJson(import_node_path23.default.join(dir, bloxFilePath));
|
|
5151
5285
|
const schemaVersion = typeof current?.schemaVersion === "number" ? current.schemaVersion : 0;
|
|
5152
5286
|
if (schemaVersion >= migrationsList.length) {
|
|
5153
5287
|
return {
|
|
@@ -5165,11 +5299,11 @@ async function migrateBloxFile(context, filePath) {
|
|
|
5165
5299
|
|
|
5166
5300
|
// src/commands/doctor/checks/utils/discoverBloxFiles.ts
|
|
5167
5301
|
var import_node_path24 = __toESM(require("path"));
|
|
5168
|
-
var
|
|
5302
|
+
var import_fs_extra20 = __toESM(require("fs-extra"));
|
|
5169
5303
|
var collectProjectTargets = (projectRoot, projectDir, name, targets) => {
|
|
5170
5304
|
const projectDirRel = normalizePath(import_node_path24.default.relative(projectRoot, projectDir)) || ".";
|
|
5171
5305
|
const bloxPath = import_node_path24.default.join(projectDir, bloxFilePath);
|
|
5172
|
-
if (
|
|
5306
|
+
if (import_fs_extra20.default.existsSync(bloxPath)) {
|
|
5173
5307
|
targets.push({
|
|
5174
5308
|
filePath: normalizePath(import_node_path24.default.relative(projectRoot, bloxPath)),
|
|
5175
5309
|
absPath: bloxPath,
|
|
@@ -5179,11 +5313,11 @@ var collectProjectTargets = (projectRoot, projectDir, name, targets) => {
|
|
|
5179
5313
|
});
|
|
5180
5314
|
}
|
|
5181
5315
|
const blocksPath = import_node_path24.default.join(projectDir, blocksDir);
|
|
5182
|
-
if (!
|
|
5183
|
-
for (const entry of
|
|
5316
|
+
if (!import_fs_extra20.default.existsSync(blocksPath)) return;
|
|
5317
|
+
for (const entry of import_fs_extra20.default.readdirSync(blocksPath, { withFileTypes: true })) {
|
|
5184
5318
|
if (!entry.isDirectory()) continue;
|
|
5185
5319
|
const absPath = import_node_path24.default.join(blocksPath, entry.name, bloxFilePath);
|
|
5186
|
-
if (!
|
|
5320
|
+
if (!import_fs_extra20.default.existsSync(absPath)) continue;
|
|
5187
5321
|
targets.push({
|
|
5188
5322
|
filePath: normalizePath(import_node_path24.default.relative(projectRoot, absPath)),
|
|
5189
5323
|
absPath,
|
|
@@ -5197,8 +5331,8 @@ function discoverBloxFiles(projectRoot) {
|
|
|
5197
5331
|
const targets = [];
|
|
5198
5332
|
collectProjectTargets(projectRoot, projectRoot, "app", targets);
|
|
5199
5333
|
const appsPath = import_node_path24.default.join(projectRoot, appsDir);
|
|
5200
|
-
if (
|
|
5201
|
-
for (const entry of
|
|
5334
|
+
if (import_fs_extra20.default.existsSync(appsPath)) {
|
|
5335
|
+
for (const entry of import_fs_extra20.default.readdirSync(appsPath, { withFileTypes: true })) {
|
|
5202
5336
|
if (!entry.isDirectory()) continue;
|
|
5203
5337
|
collectProjectTargets(
|
|
5204
5338
|
projectRoot,
|
|
@@ -5225,7 +5359,7 @@ function createDiagnostic(fields) {
|
|
|
5225
5359
|
}
|
|
5226
5360
|
|
|
5227
5361
|
// src/commands/doctor/checks/schema-validation/validate.ts
|
|
5228
|
-
var
|
|
5362
|
+
var import_fs_extra21 = __toESM(require("fs-extra"));
|
|
5229
5363
|
|
|
5230
5364
|
// src/commands/doctor/checks/schema-validation/utils/validateSchemaVersion.ts
|
|
5231
5365
|
function extractSchemaVersion(raw) {
|
|
@@ -5428,7 +5562,7 @@ async function validateBloxFile(target) {
|
|
|
5428
5562
|
const base = { checkId: "schema.validation", filePath: target.filePath };
|
|
5429
5563
|
let raw;
|
|
5430
5564
|
try {
|
|
5431
|
-
raw = await
|
|
5565
|
+
raw = await import_fs_extra21.default.readJson(target.absPath);
|
|
5432
5566
|
} catch (e) {
|
|
5433
5567
|
return [
|
|
5434
5568
|
createDiagnostic({
|
|
@@ -5499,10 +5633,10 @@ var metadataSchemaCheck = {
|
|
|
5499
5633
|
};
|
|
5500
5634
|
|
|
5501
5635
|
// src/commands/doctor/checks/dependencies/utils/readBlocksMetadata.ts
|
|
5502
|
-
var
|
|
5636
|
+
var import_fs_extra22 = __toESM(require("fs-extra"));
|
|
5503
5637
|
var import_node_path25 = __toESM(require("path"));
|
|
5504
5638
|
async function readBlockMetadata(target) {
|
|
5505
|
-
const raw = await
|
|
5639
|
+
const raw = await import_fs_extra22.default.readJson(target.absPath);
|
|
5506
5640
|
const definition = raw.definition;
|
|
5507
5641
|
const dependencies = definition?.dependencies ?? [];
|
|
5508
5642
|
const templates = definition?.templates ?? [];
|
|
@@ -5523,8 +5657,8 @@ async function readBlocksMetadata(projectRoot) {
|
|
|
5523
5657
|
const blockTargets = bloxTargets.filter((t) => t.kind === "block");
|
|
5524
5658
|
const byDir = /* @__PURE__ */ new Map();
|
|
5525
5659
|
const scopes = /* @__PURE__ */ new Map();
|
|
5526
|
-
|
|
5527
|
-
|
|
5660
|
+
const allMetadata = await Promise.all(blockTargets.map(readBlockMetadata));
|
|
5661
|
+
for (const metadata of allMetadata) {
|
|
5528
5662
|
byDir.set(metadata.blockDir, metadata);
|
|
5529
5663
|
let scope = scopes.get(metadata.projectDir);
|
|
5530
5664
|
if (!scope) {
|
|
@@ -5548,12 +5682,11 @@ async function readBlocksMetadata(projectRoot) {
|
|
|
5548
5682
|
}
|
|
5549
5683
|
|
|
5550
5684
|
// src/commands/doctor/checks/dependencies/missing/utils/collectImports.ts
|
|
5551
|
-
var
|
|
5552
|
-
var import_fs_extra23 = __toESM(require("fs-extra"));
|
|
5685
|
+
var import_fs_extra24 = __toESM(require("fs-extra"));
|
|
5553
5686
|
|
|
5554
5687
|
// src/commands/doctor/checks/utils/findSourceFiles.ts
|
|
5555
5688
|
var import_node_path26 = __toESM(require("path"));
|
|
5556
|
-
var
|
|
5689
|
+
var import_fs_extra23 = __toESM(require("fs-extra"));
|
|
5557
5690
|
var SOURCE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".d.ts"];
|
|
5558
5691
|
var EXCLUDED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
5559
5692
|
"node_modules",
|
|
@@ -5570,13 +5703,13 @@ var EXCLUDED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
|
5570
5703
|
]);
|
|
5571
5704
|
async function findSourceFiles(blockDir) {
|
|
5572
5705
|
const sourceFiles = [];
|
|
5573
|
-
if (!await
|
|
5706
|
+
if (!await import_fs_extra23.default.pathExists(blockDir)) return sourceFiles;
|
|
5574
5707
|
const stack = [blockDir];
|
|
5575
5708
|
while (stack.length > 0) {
|
|
5576
5709
|
const currentDir = stack.pop();
|
|
5577
5710
|
let entries;
|
|
5578
5711
|
try {
|
|
5579
|
-
entries = await
|
|
5712
|
+
entries = await import_fs_extra23.default.readdir(currentDir, { withFileTypes: true });
|
|
5580
5713
|
} catch {
|
|
5581
5714
|
continue;
|
|
5582
5715
|
}
|
|
@@ -5609,63 +5742,69 @@ function getBlockDirFromSourceFile(projectRoot, sourceFile) {
|
|
|
5609
5742
|
|
|
5610
5743
|
// src/commands/doctor/checks/dependencies/missing/utils/parseImports.ts
|
|
5611
5744
|
var ts = __toESM(require("typescript"));
|
|
5612
|
-
function parseImports(
|
|
5613
|
-
|
|
5614
|
-
function visit(node) {
|
|
5615
|
-
if (ts.isImportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
5616
|
-
imports.push({
|
|
5617
|
-
specifier: node.moduleSpecifier.text,
|
|
5618
|
-
containingFile,
|
|
5619
|
-
importingBlock,
|
|
5620
|
-
isReExport: false
|
|
5621
|
-
});
|
|
5622
|
-
}
|
|
5623
|
-
if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
5624
|
-
imports.push({
|
|
5625
|
-
specifier: node.moduleSpecifier.text,
|
|
5626
|
-
containingFile,
|
|
5627
|
-
importingBlock,
|
|
5628
|
-
isReExport: true
|
|
5629
|
-
});
|
|
5630
|
-
}
|
|
5631
|
-
ts.forEachChild(node, visit);
|
|
5632
|
-
}
|
|
5633
|
-
visit(sourceFile);
|
|
5634
|
-
return imports;
|
|
5745
|
+
function parseImports(sourceText) {
|
|
5746
|
+
return ts.preProcessFile(sourceText, true, false).importedFiles.map((ref) => ref.fileName);
|
|
5635
5747
|
}
|
|
5636
5748
|
|
|
5637
5749
|
// src/commands/doctor/checks/dependencies/missing/utils/collectImports.ts
|
|
5638
5750
|
var sourceFileCache = /* @__PURE__ */ new Map();
|
|
5751
|
+
var FILE_READ_CONCURRENCY = 32;
|
|
5752
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
5753
|
+
const results = new Array(items.length);
|
|
5754
|
+
let next = 0;
|
|
5755
|
+
await Promise.all(
|
|
5756
|
+
Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
5757
|
+
while (next < items.length) {
|
|
5758
|
+
const index = next++;
|
|
5759
|
+
results[index] = await fn(items[index]);
|
|
5760
|
+
}
|
|
5761
|
+
})
|
|
5762
|
+
);
|
|
5763
|
+
return results;
|
|
5764
|
+
}
|
|
5639
5765
|
async function collectImports(blocks) {
|
|
5640
|
-
const
|
|
5641
|
-
|
|
5642
|
-
|
|
5766
|
+
const filesByBlock = await Promise.all(
|
|
5767
|
+
[...blocks.values()].map(async (block) => ({
|
|
5768
|
+
block,
|
|
5769
|
+
sourceFiles: await findSourceFiles(block.blockDir)
|
|
5770
|
+
}))
|
|
5771
|
+
);
|
|
5772
|
+
const targets = filesByBlock.flatMap(
|
|
5773
|
+
({ block, sourceFiles }) => sourceFiles.map((sourceFile) => ({ block, sourceFile }))
|
|
5774
|
+
);
|
|
5775
|
+
const perFileImports = await mapWithConcurrency(
|
|
5776
|
+
targets,
|
|
5777
|
+
FILE_READ_CONCURRENCY,
|
|
5778
|
+
async ({ block, sourceFile }) => {
|
|
5643
5779
|
try {
|
|
5644
|
-
let
|
|
5645
|
-
if (!
|
|
5646
|
-
const sourceText = await
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
sourceText,
|
|
5650
|
-
ts2.ScriptTarget.Latest,
|
|
5651
|
-
true,
|
|
5652
|
-
ts2.ScriptKind.TS
|
|
5653
|
-
);
|
|
5654
|
-
sourceFileCache.set(sourceFile, sourceFileAst);
|
|
5780
|
+
let specifiers = sourceFileCache.get(sourceFile);
|
|
5781
|
+
if (!specifiers) {
|
|
5782
|
+
const sourceText = await import_fs_extra24.default.readFile(sourceFile, "utf8");
|
|
5783
|
+
specifiers = sourceText.includes("import") || sourceText.includes("export") ? parseImports(sourceText) : [];
|
|
5784
|
+
sourceFileCache.set(sourceFile, specifiers);
|
|
5655
5785
|
}
|
|
5656
|
-
|
|
5786
|
+
return specifiers.map(
|
|
5787
|
+
(specifier) => ({
|
|
5788
|
+
specifier,
|
|
5789
|
+
containingFile: sourceFile,
|
|
5790
|
+
importingBlock: block
|
|
5791
|
+
})
|
|
5792
|
+
);
|
|
5657
5793
|
} catch {
|
|
5658
|
-
|
|
5794
|
+
return [];
|
|
5659
5795
|
}
|
|
5660
5796
|
}
|
|
5661
|
-
|
|
5662
|
-
return
|
|
5797
|
+
);
|
|
5798
|
+
return perFileImports.flat();
|
|
5663
5799
|
}
|
|
5664
5800
|
|
|
5801
|
+
// src/commands/doctor/checks/dependencies/missing/utils/matchDependencies.ts
|
|
5802
|
+
var import_node_path28 = __toESM(require("path"));
|
|
5803
|
+
|
|
5665
5804
|
// src/commands/doctor/checks/utils/resolveModuleName.ts
|
|
5666
5805
|
var import_node_path27 = __toESM(require("path"));
|
|
5667
|
-
var
|
|
5668
|
-
var
|
|
5806
|
+
var import_fs_extra25 = __toESM(require("fs-extra"));
|
|
5807
|
+
var ts2 = __toESM(require("typescript"));
|
|
5669
5808
|
var tsconfigCache = /* @__PURE__ */ new Map();
|
|
5670
5809
|
var compilerOptionsByDirCache = /* @__PURE__ */ new Map();
|
|
5671
5810
|
var hostCache = /* @__PURE__ */ new Map();
|
|
@@ -5681,6 +5820,16 @@ var SKIP_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
|
5681
5820
|
".next",
|
|
5682
5821
|
"out"
|
|
5683
5822
|
]);
|
|
5823
|
+
var pathExistsCache = /* @__PURE__ */ new Map();
|
|
5824
|
+
var existsCached = (filePath) => {
|
|
5825
|
+
const cached = pathExistsCache.get(filePath);
|
|
5826
|
+
if (cached !== void 0) {
|
|
5827
|
+
return cached;
|
|
5828
|
+
}
|
|
5829
|
+
const exists = import_fs_extra25.default.existsSync(filePath);
|
|
5830
|
+
pathExistsCache.set(filePath, exists);
|
|
5831
|
+
return exists;
|
|
5832
|
+
};
|
|
5684
5833
|
function parseTsconfig(configPath) {
|
|
5685
5834
|
if (tsconfigCache.has(configPath)) {
|
|
5686
5835
|
return tsconfigCache.get(configPath) ?? null;
|
|
@@ -5689,12 +5838,12 @@ function parseTsconfig(configPath) {
|
|
|
5689
5838
|
const configFileName = import_node_path27.default.basename(configPath);
|
|
5690
5839
|
let configText;
|
|
5691
5840
|
try {
|
|
5692
|
-
configText =
|
|
5841
|
+
configText = import_fs_extra25.default.readFileSync(configPath, "utf8");
|
|
5693
5842
|
} catch {
|
|
5694
5843
|
tsconfigCache.set(configPath, null);
|
|
5695
5844
|
return null;
|
|
5696
5845
|
}
|
|
5697
|
-
const parseResult =
|
|
5846
|
+
const parseResult = ts2.parseConfigFileTextToJson(configFileName, configText);
|
|
5698
5847
|
if (!parseResult.config) {
|
|
5699
5848
|
tsconfigCache.set(configPath, null);
|
|
5700
5849
|
return null;
|
|
@@ -5705,9 +5854,9 @@ function parseTsconfig(configPath) {
|
|
|
5705
5854
|
const extendedConfig = parseTsconfig(extendedPath);
|
|
5706
5855
|
if (extendedConfig) {
|
|
5707
5856
|
const mergedConfig = { ...extendedConfig.options, ...rawConfig };
|
|
5708
|
-
const mergedResult =
|
|
5857
|
+
const mergedResult = ts2.parseJsonConfigFileContent(
|
|
5709
5858
|
mergedConfig,
|
|
5710
|
-
|
|
5859
|
+
ts2.sys,
|
|
5711
5860
|
configDir,
|
|
5712
5861
|
void 0,
|
|
5713
5862
|
configFileName
|
|
@@ -5731,9 +5880,9 @@ function parseTsconfig(configPath) {
|
|
|
5731
5880
|
const rawCompilerOptions = rawConfig.compilerOptions ?? {};
|
|
5732
5881
|
const finalCompilerOptions = { ...mergedOptions, ...rawCompilerOptions };
|
|
5733
5882
|
const finalConfig = { ...rawConfig, compilerOptions: finalCompilerOptions };
|
|
5734
|
-
const mergedResult =
|
|
5883
|
+
const mergedResult = ts2.parseJsonConfigFileContent(
|
|
5735
5884
|
finalConfig,
|
|
5736
|
-
|
|
5885
|
+
ts2.sys,
|
|
5737
5886
|
configDir,
|
|
5738
5887
|
void 0,
|
|
5739
5888
|
configFileName
|
|
@@ -5741,9 +5890,9 @@ function parseTsconfig(configPath) {
|
|
|
5741
5890
|
tsconfigCache.set(configPath, mergedResult);
|
|
5742
5891
|
return mergedResult;
|
|
5743
5892
|
}
|
|
5744
|
-
const result =
|
|
5893
|
+
const result = ts2.parseJsonConfigFileContent(
|
|
5745
5894
|
rawConfig,
|
|
5746
|
-
|
|
5895
|
+
ts2.sys,
|
|
5747
5896
|
configDir,
|
|
5748
5897
|
void 0,
|
|
5749
5898
|
configFileName
|
|
@@ -5761,7 +5910,7 @@ function getCompilerOptionsForDirectory(fileDir, projectRoot) {
|
|
|
5761
5910
|
let currentDir = normalizedFileDir;
|
|
5762
5911
|
while (currentDir.startsWith(normalizedProjectRoot) && currentDir !== normalizedProjectRoot) {
|
|
5763
5912
|
const configPath = import_node_path27.default.join(currentDir, "tsconfig.json");
|
|
5764
|
-
if (
|
|
5913
|
+
if (import_fs_extra25.default.existsSync(configPath)) {
|
|
5765
5914
|
const parsed = parseTsconfig(configPath);
|
|
5766
5915
|
if (parsed?.options) {
|
|
5767
5916
|
compilerOptionsByDirCache.set(normalizedFileDir, parsed.options);
|
|
@@ -5771,7 +5920,7 @@ function getCompilerOptionsForDirectory(fileDir, projectRoot) {
|
|
|
5771
5920
|
currentDir = import_node_path27.default.dirname(currentDir);
|
|
5772
5921
|
}
|
|
5773
5922
|
const rootConfigPath = import_node_path27.default.join(normalizedProjectRoot, "tsconfig.json");
|
|
5774
|
-
if (
|
|
5923
|
+
if (import_fs_extra25.default.existsSync(rootConfigPath)) {
|
|
5775
5924
|
const parsed = parseTsconfig(rootConfigPath);
|
|
5776
5925
|
if (parsed?.options) {
|
|
5777
5926
|
compilerOptionsByDirCache.set(normalizedFileDir, parsed.options);
|
|
@@ -5779,9 +5928,9 @@ function getCompilerOptionsForDirectory(fileDir, projectRoot) {
|
|
|
5779
5928
|
}
|
|
5780
5929
|
}
|
|
5781
5930
|
const defaults = {
|
|
5782
|
-
moduleResolution:
|
|
5783
|
-
target:
|
|
5784
|
-
module:
|
|
5931
|
+
moduleResolution: ts2.ModuleResolutionKind.Node16,
|
|
5932
|
+
target: ts2.ScriptTarget.ES2020,
|
|
5933
|
+
module: ts2.ModuleKind.ESNext
|
|
5785
5934
|
};
|
|
5786
5935
|
compilerOptionsByDirCache.set(normalizedFileDir, defaults);
|
|
5787
5936
|
return defaults;
|
|
@@ -5815,13 +5964,13 @@ var CachedModuleResolutionHost = class {
|
|
|
5815
5964
|
if (cached !== void 0) {
|
|
5816
5965
|
return cached;
|
|
5817
5966
|
}
|
|
5818
|
-
const exists =
|
|
5967
|
+
const exists = import_fs_extra25.default.existsSync(fileName);
|
|
5819
5968
|
this.fileExistsCache.set(fileName, exists);
|
|
5820
5969
|
return exists;
|
|
5821
5970
|
}
|
|
5822
5971
|
readFile(fileName) {
|
|
5823
5972
|
try {
|
|
5824
|
-
return
|
|
5973
|
+
return import_fs_extra25.default.readFileSync(fileName, "utf8");
|
|
5825
5974
|
} catch {
|
|
5826
5975
|
return void 0;
|
|
5827
5976
|
}
|
|
@@ -5831,7 +5980,7 @@ var CachedModuleResolutionHost = class {
|
|
|
5831
5980
|
if (cached !== void 0) {
|
|
5832
5981
|
return cached;
|
|
5833
5982
|
}
|
|
5834
|
-
const exists =
|
|
5983
|
+
const exists = import_fs_extra25.default.existsSync(directoryName) && import_fs_extra25.default.statSync(directoryName).isDirectory();
|
|
5835
5984
|
this.directoryExistsCache.set(directoryName, exists);
|
|
5836
5985
|
return exists;
|
|
5837
5986
|
}
|
|
@@ -5841,7 +5990,7 @@ var CachedModuleResolutionHost = class {
|
|
|
5841
5990
|
return cached;
|
|
5842
5991
|
}
|
|
5843
5992
|
try {
|
|
5844
|
-
const dirs =
|
|
5993
|
+
const dirs = import_fs_extra25.default.readdirSync(directoryName, { withFileTypes: true }).filter((d) => d.isDirectory() && !SKIP_DIRECTORIES.has(d.name)).map((d) => d.name);
|
|
5845
5994
|
this.getDirectoriesCache.set(directoryName, dirs);
|
|
5846
5995
|
return dirs;
|
|
5847
5996
|
} catch {
|
|
@@ -5859,7 +6008,7 @@ var CachedModuleResolutionHost = class {
|
|
|
5859
6008
|
return cached;
|
|
5860
6009
|
}
|
|
5861
6010
|
try {
|
|
5862
|
-
const resolved =
|
|
6011
|
+
const resolved = import_fs_extra25.default.realpathSync(fileName);
|
|
5863
6012
|
this.realpathCache.set(fileName, resolved);
|
|
5864
6013
|
return resolved;
|
|
5865
6014
|
} catch {
|
|
@@ -5886,14 +6035,14 @@ function resolveRelativeImport(moduleSpecifier, containingFile, projectRoot) {
|
|
|
5886
6035
|
const extensions = [".ts", ".tsx", ".d.ts", ".js", ".jsx"];
|
|
5887
6036
|
for (const ext of extensions) {
|
|
5888
6037
|
const filePath = resolvedPath + ext;
|
|
5889
|
-
if (
|
|
6038
|
+
if (existsCached(filePath)) {
|
|
5890
6039
|
return filePath;
|
|
5891
6040
|
}
|
|
5892
6041
|
}
|
|
5893
|
-
if (
|
|
6042
|
+
if (existsCached(resolvedPath) && import_fs_extra25.default.statSync(resolvedPath).isDirectory()) {
|
|
5894
6043
|
for (const ext of extensions) {
|
|
5895
6044
|
const indexPath = import_node_path27.default.join(resolvedPath, "index" + ext);
|
|
5896
|
-
if (
|
|
6045
|
+
if (existsCached(indexPath)) {
|
|
5897
6046
|
return indexPath;
|
|
5898
6047
|
}
|
|
5899
6048
|
}
|
|
@@ -5913,7 +6062,7 @@ function resolveModuleName2(moduleSpecifier, containingFile, projectRoot) {
|
|
|
5913
6062
|
const containingDir = import_node_path27.default.dirname(containingFile);
|
|
5914
6063
|
const compilerOptions = getCompilerOptionsForDirectory(containingDir, projectRoot);
|
|
5915
6064
|
const host = getOrCreateHost(projectRoot, compilerOptions);
|
|
5916
|
-
const result =
|
|
6065
|
+
const result = ts2.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, host);
|
|
5917
6066
|
if (result.resolvedModule) {
|
|
5918
6067
|
return result.resolvedModule.resolvedFileName;
|
|
5919
6068
|
}
|
|
@@ -5925,6 +6074,45 @@ var yieldToEventLoop = () => new Promise((resolve) => setImmediate(resolve));
|
|
|
5925
6074
|
|
|
5926
6075
|
// src/commands/doctor/checks/dependencies/missing/utils/matchDependencies.ts
|
|
5927
6076
|
var blockDirCache = /* @__PURE__ */ new Map();
|
|
6077
|
+
var resolutionCache = /* @__PURE__ */ new Map();
|
|
6078
|
+
function canResolveIntoBlocks(moduleSpecifier, containingFile, projectRoot) {
|
|
6079
|
+
if (moduleSpecifier.startsWith("./") || moduleSpecifier.startsWith("../") || import_node_path28.default.isAbsolute(moduleSpecifier)) {
|
|
6080
|
+
return true;
|
|
6081
|
+
}
|
|
6082
|
+
const compilerOptions = getCompilerOptionsForDirectory(
|
|
6083
|
+
import_node_path28.default.dirname(containingFile),
|
|
6084
|
+
projectRoot
|
|
6085
|
+
);
|
|
6086
|
+
if (compilerOptions.baseUrl) {
|
|
6087
|
+
return true;
|
|
6088
|
+
}
|
|
6089
|
+
const pathPatterns = Object.keys(compilerOptions.paths ?? {});
|
|
6090
|
+
if (pathPatterns.length === 0) {
|
|
6091
|
+
return false;
|
|
6092
|
+
}
|
|
6093
|
+
return pathPatterns.some((pattern) => matchesPathsPattern(pattern, moduleSpecifier));
|
|
6094
|
+
}
|
|
6095
|
+
function matchesPathsPattern(pattern, candidate) {
|
|
6096
|
+
const starIndex = pattern.indexOf("*");
|
|
6097
|
+
if (starIndex === -1) {
|
|
6098
|
+
return pattern === candidate;
|
|
6099
|
+
}
|
|
6100
|
+
const prefix = pattern.slice(0, starIndex);
|
|
6101
|
+
const suffix = pattern.slice(starIndex + 1);
|
|
6102
|
+
return candidate.startsWith(prefix) && candidate.endsWith(suffix) && candidate.length >= prefix.length + suffix.length;
|
|
6103
|
+
}
|
|
6104
|
+
function resolveImportSpecifier(importInfo, projectRoot) {
|
|
6105
|
+
const { specifier, containingFile } = importInfo;
|
|
6106
|
+
const key = `${import_node_path28.default.dirname(containingFile)}
|
|
6107
|
+
${specifier}`;
|
|
6108
|
+
const cached = resolutionCache.get(key);
|
|
6109
|
+
if (cached !== void 0) {
|
|
6110
|
+
return cached ?? void 0;
|
|
6111
|
+
}
|
|
6112
|
+
const resolved = canResolveIntoBlocks(specifier, containingFile, projectRoot) ? resolveModuleName2(specifier, containingFile, projectRoot) ?? null : null;
|
|
6113
|
+
resolutionCache.set(key, resolved);
|
|
6114
|
+
return resolved ?? void 0;
|
|
6115
|
+
}
|
|
5928
6116
|
async function resolveImportsToBlocks(imports, allBlocks, projectRoot) {
|
|
5929
6117
|
const resolved = [];
|
|
5930
6118
|
const blocksByDir = allBlocks.byDir;
|
|
@@ -5933,11 +6121,7 @@ async function resolveImportsToBlocks(imports, allBlocks, projectRoot) {
|
|
|
5933
6121
|
if (++processed % 50 === 0) {
|
|
5934
6122
|
await yieldToEventLoop();
|
|
5935
6123
|
}
|
|
5936
|
-
const resolvedPath =
|
|
5937
|
-
importInfo.specifier,
|
|
5938
|
-
importInfo.containingFile,
|
|
5939
|
-
projectRoot
|
|
5940
|
-
);
|
|
6124
|
+
const resolvedPath = resolveImportSpecifier(importInfo, projectRoot);
|
|
5941
6125
|
if (!resolvedPath) {
|
|
5942
6126
|
continue;
|
|
5943
6127
|
}
|
|
@@ -5994,7 +6178,7 @@ function checkMissingDependencies(resolvedImports) {
|
|
|
5994
6178
|
}
|
|
5995
6179
|
|
|
5996
6180
|
// src/commands/doctor/checks/dependencies/missing/utils/reportFinding.ts
|
|
5997
|
-
var
|
|
6181
|
+
var import_node_path29 = __toESM(require("path"));
|
|
5998
6182
|
function createMissingDependencyDiagnostics(results, projectRoot) {
|
|
5999
6183
|
const diagnostics = [];
|
|
6000
6184
|
for (const result of results) {
|
|
@@ -6006,7 +6190,7 @@ function createMissingDependencyDiagnostics(results, projectRoot) {
|
|
|
6006
6190
|
title: "Missing block dependency declaration",
|
|
6007
6191
|
classification: "invalid",
|
|
6008
6192
|
message: `Block "${result.block.name}" imports "${missing.targetBlock.name}" via "${missing.importSpecifier}" but "${missing.targetBlock.name}" is not declared in definition.dependencies`,
|
|
6009
|
-
filePath: normalizePath(
|
|
6193
|
+
filePath: normalizePath(import_node_path29.default.relative(projectRoot, missing.containingFile))
|
|
6010
6194
|
})
|
|
6011
6195
|
);
|
|
6012
6196
|
}
|
|
@@ -6279,12 +6463,12 @@ function findVersionIncompatibilities(blocks, templates) {
|
|
|
6279
6463
|
}
|
|
6280
6464
|
|
|
6281
6465
|
// src/commands/doctor/checks/dependencies/dependency-version/utils/readProjectTemplate.ts
|
|
6282
|
-
var
|
|
6466
|
+
var import_fs_extra26 = __toESM(require("fs-extra"));
|
|
6283
6467
|
async function readProjectTemplates(projectRoot) {
|
|
6284
6468
|
const templates = /* @__PURE__ */ new Map();
|
|
6285
6469
|
for (const target of discoverBloxFiles(projectRoot)) {
|
|
6286
6470
|
if (target.kind !== "template") continue;
|
|
6287
|
-
const raw = await
|
|
6471
|
+
const raw = await import_fs_extra26.default.readJson(target.absPath);
|
|
6288
6472
|
const definition = raw.definition;
|
|
6289
6473
|
const checkpoints = raw.checkpoints ?? {};
|
|
6290
6474
|
templates.set(target.projectDir, {
|
|
@@ -6359,7 +6543,7 @@ var dependenciesChecks = [
|
|
|
6359
6543
|
];
|
|
6360
6544
|
|
|
6361
6545
|
// src/commands/doctor/checks/updates/available-updates.ts
|
|
6362
|
-
var
|
|
6546
|
+
var import_node_path30 = __toESM(require("path"));
|
|
6363
6547
|
var CHECK_ID = "updates.availability";
|
|
6364
6548
|
var availableUpdatesCheck = {
|
|
6365
6549
|
id: CHECK_ID,
|
|
@@ -6398,7 +6582,7 @@ Remote commit: ${remoteCommit.slice(0, 7)}`,
|
|
|
6398
6582
|
}
|
|
6399
6583
|
function bloxFilePathFor(component) {
|
|
6400
6584
|
if (component.type === "block" /* BLOCK */) {
|
|
6401
|
-
return normalizePath(
|
|
6585
|
+
return normalizePath(import_node_path30.default.join(blocksDir, component.dir, bloxFilePath));
|
|
6402
6586
|
}
|
|
6403
6587
|
return bloxFilePath;
|
|
6404
6588
|
}
|
|
@@ -6645,13 +6829,13 @@ function printSummary(report) {
|
|
|
6645
6829
|
}
|
|
6646
6830
|
|
|
6647
6831
|
// src/commands/doctor/runner.ts
|
|
6648
|
-
var
|
|
6832
|
+
var errorMessage3 = (e) => e instanceof Error ? e.message : String(e);
|
|
6649
6833
|
async function executeCheck(check, context, checkErrors, taskText) {
|
|
6650
6834
|
try {
|
|
6651
6835
|
const diagnostics = await runTask(taskText, () => check.run(context));
|
|
6652
6836
|
return diagnostics.map((d) => ({ ...d, checkName: check.name }));
|
|
6653
6837
|
} catch (e) {
|
|
6654
|
-
checkErrors.push({ checkId: check.id, message:
|
|
6838
|
+
checkErrors.push({ checkId: check.id, message: errorMessage3(e) });
|
|
6655
6839
|
return [];
|
|
6656
6840
|
}
|
|
6657
6841
|
}
|
|
@@ -6682,7 +6866,7 @@ async function runDoctor(checks, context) {
|
|
|
6682
6866
|
try {
|
|
6683
6867
|
result = await check.fix(context, diagnostic);
|
|
6684
6868
|
} catch (e) {
|
|
6685
|
-
result = { status: "failed", message:
|
|
6869
|
+
result = { status: "failed", message: errorMessage3(e) };
|
|
6686
6870
|
}
|
|
6687
6871
|
repairs.push({ checkId: check.id, diagnosticId: diagnostic.id, result });
|
|
6688
6872
|
if (result.status !== "skipped") {
|
|
@@ -6747,8 +6931,9 @@ either mode.`
|
|
|
6747
6931
|
});
|
|
6748
6932
|
|
|
6749
6933
|
// src/commands/init/index.ts
|
|
6750
|
-
var
|
|
6751
|
-
var
|
|
6934
|
+
var import_node_path31 = __toESM(require("path"));
|
|
6935
|
+
var import_fs_extra27 = __toESM(require("fs-extra"));
|
|
6936
|
+
var isValidName = (value) => !!value && value !== "." && value !== ".." && value === import_node_path31.default.basename(value);
|
|
6752
6937
|
var init2 = addExecutionOptions(
|
|
6753
6938
|
command("init").description("Init new app").alias("i").option("-n, --name <name>", "App name").option("-t, --template <template>", "Template to use").option("--branch <name>", "branch name").addHelpText(
|
|
6754
6939
|
"after",
|
|
@@ -6771,7 +6956,19 @@ be combined with either mode.`
|
|
|
6771
6956
|
requireArgs(args, ["name", "template"]);
|
|
6772
6957
|
}
|
|
6773
6958
|
if (!name) {
|
|
6774
|
-
name = await text({
|
|
6959
|
+
name = await text({
|
|
6960
|
+
message: "Select app name",
|
|
6961
|
+
validate: (value) => isValidName(value?.trim()) ? void 0 : "Enter a valid app name"
|
|
6962
|
+
});
|
|
6963
|
+
}
|
|
6964
|
+
name = name?.trim();
|
|
6965
|
+
if (!isValidName(name)) {
|
|
6966
|
+
throw new CliError(
|
|
6967
|
+
`Invalid app name: ${JSON.stringify(name)}`,
|
|
6968
|
+
"INVALID_NAME",
|
|
6969
|
+
exitCodes.USAGE,
|
|
6970
|
+
"Provide a simple directory name for the app."
|
|
6971
|
+
);
|
|
6775
6972
|
}
|
|
6776
6973
|
await syncRegistries();
|
|
6777
6974
|
const templates = await getAvailableTemplates();
|
|
@@ -6796,7 +6993,7 @@ be combined with either mode.`
|
|
|
6796
6993
|
const task = spinner();
|
|
6797
6994
|
task.start(`Fetch template`);
|
|
6798
6995
|
const templateSource = templates[template]?.source || "";
|
|
6799
|
-
createdDir = !
|
|
6996
|
+
createdDir = !import_fs_extra27.default.existsSync(name);
|
|
6800
6997
|
await git.clone(templateSource, name, branch);
|
|
6801
6998
|
let commit2 = await selectVersion(templateSource);
|
|
6802
6999
|
if (commit2) {
|
|
@@ -6810,22 +7007,56 @@ be combined with either mode.`
|
|
|
6810
7007
|
await deletePattern(name, def.ignore);
|
|
6811
7008
|
await replacePlaceholders(name, { app: { name } });
|
|
6812
7009
|
updateCheckpoint(def.name, { commit: commit2, branch }, name);
|
|
7010
|
+
const root = import_node_path31.default.resolve(name);
|
|
7011
|
+
for (const app of listApps(root)) {
|
|
7012
|
+
if (!hasGitRepo(app.dir)) {
|
|
7013
|
+
await git.init(app.dir);
|
|
7014
|
+
}
|
|
7015
|
+
}
|
|
7016
|
+
const appResults = await materializeWorkspaceApps(root, await getAvailableApps(def));
|
|
7017
|
+
for (const app of listApps(root)) {
|
|
7018
|
+
ensureAppIgnored(root, app.key);
|
|
7019
|
+
}
|
|
6813
7020
|
await git.init(name);
|
|
6814
7021
|
task.stop(`App initialized in ${name}`);
|
|
6815
7022
|
await runLifecycleHookWithTask(name || "", "init", "Run template init");
|
|
7023
|
+
const warnings = [];
|
|
6816
7024
|
for (const app of listApps(name)) {
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
7025
|
+
try {
|
|
7026
|
+
await runLifecycleHookWithTask(
|
|
7027
|
+
import_node_path31.default.join(name, "apps", app.key),
|
|
7028
|
+
"init",
|
|
7029
|
+
`Run app init: ${app.key}`
|
|
7030
|
+
);
|
|
7031
|
+
} catch (cause) {
|
|
7032
|
+
const message = `${app.key}: init hook failed: ${cause instanceof Error ? cause.message : String(cause)}`;
|
|
7033
|
+
import_prompts2.log.error(message);
|
|
7034
|
+
const keepGoing = isNonInteractive() ? true : await confirm({
|
|
7035
|
+
message: `Continue initializing ${app.key} despite the failed init hook?`,
|
|
7036
|
+
initialValue: true
|
|
7037
|
+
});
|
|
7038
|
+
if (!keepGoing) throw cause;
|
|
7039
|
+
warnings.push(message);
|
|
7040
|
+
}
|
|
7041
|
+
}
|
|
7042
|
+
const failedApps = appResults.filter((app) => app.status === "failed");
|
|
7043
|
+
if (failedApps.length) {
|
|
7044
|
+
process.exitCode = 1;
|
|
7045
|
+
import_prompts2.log.warn(
|
|
7046
|
+
fmt.yellow(
|
|
7047
|
+
`${failedApps.length} app(s) failed to initialize \u2014 retry with: blox add ${failedApps.map((app) => `app/${app.key}`).join(" ")}`
|
|
7048
|
+
)
|
|
6821
7049
|
);
|
|
6822
7050
|
}
|
|
7051
|
+
for (const warning of warnings) {
|
|
7052
|
+
import_prompts2.log.warn(fmt.yellow(warning));
|
|
7053
|
+
}
|
|
6823
7054
|
if (isJsonMode()) {
|
|
6824
|
-
printJsonResult({ name, template, branch, commit: commit2 });
|
|
7055
|
+
printJsonResult({ name, template, branch, commit: commit2, apps: appResults, warnings });
|
|
6825
7056
|
}
|
|
6826
7057
|
} catch (e) {
|
|
6827
|
-
if (createdDir && name &&
|
|
6828
|
-
await
|
|
7058
|
+
if (createdDir && name && import_fs_extra27.default.existsSync(name)) {
|
|
7059
|
+
await import_fs_extra27.default.remove(name);
|
|
6829
7060
|
}
|
|
6830
7061
|
handleCommandError(e);
|
|
6831
7062
|
}
|
|
@@ -6842,54 +7073,58 @@ Non-interactive usage:
|
|
|
6842
7073
|
)
|
|
6843
7074
|
).action(async (args) => {
|
|
6844
7075
|
initExecutionMode(args);
|
|
7076
|
+
let workspaceRoot = ".";
|
|
6845
7077
|
try {
|
|
6846
|
-
|
|
7078
|
+
workspaceRoot = resolveContext(".").workspaceRoot;
|
|
7079
|
+
await migrateAll(false, workspaceRoot);
|
|
6847
7080
|
if (isJsonMode()) {
|
|
6848
7081
|
printJsonResult({ migrated: true });
|
|
6849
7082
|
}
|
|
6850
7083
|
} catch (e) {
|
|
6851
7084
|
if (!isDebugMode()) {
|
|
6852
7085
|
import_prompts2.log.warn("Error happened, Will rollback changes");
|
|
6853
|
-
|
|
7086
|
+
for (const dir of [
|
|
7087
|
+
workspaceRoot,
|
|
7088
|
+
...listApps(workspaceRoot).map((app) => app.dir)
|
|
7089
|
+
]) {
|
|
7090
|
+
try {
|
|
7091
|
+
await git.rollback(dir);
|
|
7092
|
+
} catch {
|
|
7093
|
+
}
|
|
7094
|
+
}
|
|
6854
7095
|
}
|
|
6855
7096
|
handleCommandError(e);
|
|
6856
7097
|
}
|
|
6857
7098
|
});
|
|
6858
7099
|
|
|
6859
7100
|
// src/commands/remove/index.ts
|
|
6860
|
-
var
|
|
6861
|
-
var
|
|
7101
|
+
var import_node_path32 = __toESM(require("path"));
|
|
7102
|
+
var import_fs_extra28 = __toESM(require("fs-extra"));
|
|
6862
7103
|
function listInstalledBlockRelPaths(blocksRoot, projectDir) {
|
|
6863
|
-
if (!
|
|
7104
|
+
if (!import_fs_extra28.default.existsSync(blocksRoot)) {
|
|
6864
7105
|
return [];
|
|
6865
7106
|
}
|
|
6866
7107
|
const paths2 = [];
|
|
6867
|
-
for (const entry of
|
|
7108
|
+
for (const entry of import_fs_extra28.default.readdirSync(blocksRoot, { withFileTypes: true })) {
|
|
6868
7109
|
if (!entry.isDirectory()) {
|
|
6869
7110
|
continue;
|
|
6870
7111
|
}
|
|
6871
|
-
const abs =
|
|
7112
|
+
const abs = import_node_path32.default.join(blocksRoot, entry.name);
|
|
6872
7113
|
if (!isBlockDirectory(abs)) {
|
|
6873
7114
|
continue;
|
|
6874
7115
|
}
|
|
6875
|
-
paths2.push(
|
|
7116
|
+
paths2.push(import_node_path32.default.relative(projectDir, abs));
|
|
6876
7117
|
}
|
|
6877
7118
|
return paths2;
|
|
6878
7119
|
}
|
|
6879
7120
|
function dependentBlocksRoots2(context) {
|
|
6880
|
-
|
|
6881
|
-
if (!context.app) {
|
|
6882
|
-
for (const app of listApps(context.workspaceRoot)) {
|
|
6883
|
-
roots.push(import_node_path31.default.join(app.dir, blocksDir));
|
|
6884
|
-
}
|
|
6885
|
-
}
|
|
6886
|
-
return roots;
|
|
7121
|
+
return [import_node_path32.default.join(context.projectDir, blocksDir)];
|
|
6887
7122
|
}
|
|
6888
7123
|
function getInstalledSelectOptions(context) {
|
|
6889
|
-
const blocksRoot =
|
|
7124
|
+
const blocksRoot = import_node_path32.default.join(context.projectDir, blocksDir);
|
|
6890
7125
|
const options = listInstalledBlockRelPaths(blocksRoot, context.projectDir).map((rel) => {
|
|
6891
|
-
const folder =
|
|
6892
|
-
const def = getBlockDef(
|
|
7126
|
+
const folder = import_node_path32.default.basename(rel);
|
|
7127
|
+
const def = getBlockDef(import_node_path32.default.join(context.projectDir, rel));
|
|
6893
7128
|
const label = def?.name && def.name !== folder ? `${def.name} (${folder})` : folder;
|
|
6894
7129
|
return { value: `block/${folder}`, label: `block/${label}`, hint: def?.name };
|
|
6895
7130
|
});
|
|
@@ -6902,10 +7137,10 @@ function getInstalledSelectOptions(context) {
|
|
|
6902
7137
|
}
|
|
6903
7138
|
function assertNoDependents(blockPathAbs, targetBlockName, roots) {
|
|
6904
7139
|
for (const root of roots) {
|
|
6905
|
-
if (!
|
|
6906
|
-
for (const entry of
|
|
7140
|
+
if (!import_fs_extra28.default.existsSync(root)) continue;
|
|
7141
|
+
for (const entry of import_fs_extra28.default.readdirSync(root, { withFileTypes: true })) {
|
|
6907
7142
|
if (!entry.isDirectory()) continue;
|
|
6908
|
-
const abs =
|
|
7143
|
+
const abs = import_node_path32.default.join(root, entry.name);
|
|
6909
7144
|
if (abs === blockPathAbs) continue;
|
|
6910
7145
|
const def = getBlockDef(abs);
|
|
6911
7146
|
for (const dep of def.dependencies || []) {
|
|
@@ -6919,19 +7154,19 @@ function assertNoDependents(blockPathAbs, targetBlockName, roots) {
|
|
|
6919
7154
|
}
|
|
6920
7155
|
}
|
|
6921
7156
|
function assertUnderBlocksRoot(blockPathAbs, blocksRootAbs) {
|
|
6922
|
-
const rel =
|
|
6923
|
-
if (!rel || rel.startsWith("..") ||
|
|
7157
|
+
const rel = import_node_path32.default.relative(blocksRootAbs, blockPathAbs);
|
|
7158
|
+
if (!rel || rel.startsWith("..") || import_node_path32.default.isAbsolute(rel)) {
|
|
6924
7159
|
throw new Error("Block path escapes the blocks directory");
|
|
6925
7160
|
}
|
|
6926
7161
|
}
|
|
6927
7162
|
async function removeBlock(block, blocks, context, force = false) {
|
|
6928
7163
|
const reg = blocks[block];
|
|
6929
7164
|
const destination = reg ? reg.destination ?? block : block;
|
|
6930
|
-
const blocksRoot =
|
|
6931
|
-
const blockPathAbs =
|
|
7165
|
+
const blocksRoot = import_node_path32.default.join(context.projectDir, blocksDir);
|
|
7166
|
+
const blockPathAbs = import_node_path32.default.resolve(blocksRoot, destination);
|
|
6932
7167
|
assertUnderBlocksRoot(blockPathAbs, blocksRoot);
|
|
6933
|
-
if (!
|
|
6934
|
-
throw new Error(`Block is not installed at ${
|
|
7168
|
+
if (!import_fs_extra28.default.existsSync(blockPathAbs) || !isBlockDirectory(blockPathAbs)) {
|
|
7169
|
+
throw new Error(`Block is not installed at ${import_node_path32.default.relative(process.cwd(), blockPathAbs)}`);
|
|
6935
7170
|
}
|
|
6936
7171
|
const targetDef = getBlockDef(blockPathAbs);
|
|
6937
7172
|
if (!targetDef?.name) {
|
|
@@ -6943,19 +7178,28 @@ async function removeBlock(block, blocks, context, force = false) {
|
|
|
6943
7178
|
await runLifecycleHookWithTask(blockPathAbs, "remove", "Run block remove");
|
|
6944
7179
|
await runTask("Remove block files", async () => {
|
|
6945
7180
|
assertUnderBlocksRoot(blockPathAbs, blocksRoot);
|
|
6946
|
-
await
|
|
7181
|
+
await import_fs_extra28.default.remove(blockPathAbs);
|
|
6947
7182
|
});
|
|
6948
7183
|
return true;
|
|
6949
7184
|
}
|
|
6950
|
-
async function removeApp(appKey, context) {
|
|
6951
|
-
const appPath =
|
|
6952
|
-
if (!
|
|
6953
|
-
throw new Error(`Application is not installed at ${
|
|
7185
|
+
async function removeApp(appKey, context, dirtyApps) {
|
|
7186
|
+
const appPath = import_node_path32.default.join(context.workspaceRoot, appsDir, appKey);
|
|
7187
|
+
if (!import_fs_extra28.default.existsSync(import_node_path32.default.join(appPath, ".blox"))) {
|
|
7188
|
+
throw new Error(`Application is not installed at ${import_node_path32.default.relative(process.cwd(), appPath)}`);
|
|
7189
|
+
}
|
|
7190
|
+
if (dirtyApps.has(appKey)) {
|
|
7191
|
+
throw new CliError(
|
|
7192
|
+
`Application "${appKey}" has uncommitted changes`,
|
|
7193
|
+
"DIRTY_WORKING_TREE",
|
|
7194
|
+
exitCodes.GENERAL,
|
|
7195
|
+
"Commit or stash the changes inside the application repository first"
|
|
7196
|
+
);
|
|
6954
7197
|
}
|
|
6955
7198
|
await runLifecycleHookWithTask(appPath, "remove", "Run app remove");
|
|
6956
7199
|
await runTask("Remove app files", async () => {
|
|
6957
|
-
await
|
|
7200
|
+
await import_fs_extra28.default.remove(appPath);
|
|
6958
7201
|
});
|
|
7202
|
+
removeAppIgnore(context.workspaceRoot, appKey);
|
|
6959
7203
|
return true;
|
|
6960
7204
|
}
|
|
6961
7205
|
var remove = addExecutionOptions(
|
|
@@ -6980,8 +7224,11 @@ combined with either mode.`
|
|
|
6980
7224
|
).action(async (selectedBlocks, args) => {
|
|
6981
7225
|
initExecutionMode(args);
|
|
6982
7226
|
const { force } = args;
|
|
7227
|
+
let projectDir = ".";
|
|
6983
7228
|
try {
|
|
6984
|
-
|
|
7229
|
+
const context = resolveContext(".", args.app);
|
|
7230
|
+
projectDir = context.projectDir;
|
|
7231
|
+
if (await git.hasUncommittedChanges(context.projectDir)) {
|
|
6985
7232
|
if (isNonInteractive()) {
|
|
6986
7233
|
throw new CliError(
|
|
6987
7234
|
"Make sure to commit any changes first",
|
|
@@ -6992,12 +7239,14 @@ combined with either mode.`
|
|
|
6992
7239
|
import_prompts2.log.warn(fmt.yellow("Make sure to commit any changes first"));
|
|
6993
7240
|
return;
|
|
6994
7241
|
}
|
|
6995
|
-
const
|
|
7242
|
+
const dirtyApps = /* @__PURE__ */ new Set();
|
|
7243
|
+
for (const app of listApps(context.workspaceRoot)) {
|
|
7244
|
+
if (await git.hasUncommittedChanges(app.dir)) dirtyApps.add(app.key);
|
|
7245
|
+
}
|
|
6996
7246
|
await migrateAll(false, context.workspaceRoot);
|
|
6997
7247
|
await syncRegistries();
|
|
6998
7248
|
const templateDef = getTemplateDef(context.projectDir);
|
|
6999
|
-
const
|
|
7000
|
-
const blocks = context.app ? await getAvailableBlocksForApp(context.app, rootTemplateName, templateDef) : await getAvailableBlocks(templateDef);
|
|
7249
|
+
const blocks = await getAvailableBlocks(templateDef);
|
|
7001
7250
|
let componentsToRemove = Array.isArray(selectedBlocks) ? selectedBlocks : [];
|
|
7002
7251
|
if (!componentsToRemove.length) {
|
|
7003
7252
|
const options = getInstalledSelectOptions(context);
|
|
@@ -7040,16 +7289,16 @@ combined with either mode.`
|
|
|
7040
7289
|
exitCodes.USAGE
|
|
7041
7290
|
);
|
|
7042
7291
|
}
|
|
7043
|
-
if (await removeApp(ref.name, context)) {
|
|
7292
|
+
if (await removeApp(ref.name, context, dirtyApps)) {
|
|
7044
7293
|
removed.push(arg);
|
|
7045
7294
|
}
|
|
7046
7295
|
continue;
|
|
7047
7296
|
}
|
|
7048
7297
|
if (!ref.type && installedApps.has(ref.name)) {
|
|
7049
|
-
const blocksRoot =
|
|
7050
|
-
const isBlock =
|
|
7298
|
+
const blocksRoot = import_node_path32.default.join(context.projectDir, blocksDir);
|
|
7299
|
+
const isBlock = import_fs_extra28.default.existsSync(import_node_path32.default.join(blocksRoot, ref.name));
|
|
7051
7300
|
if (!isBlock) {
|
|
7052
|
-
if (await removeApp(ref.name, context)) {
|
|
7301
|
+
if (await removeApp(ref.name, context, dirtyApps)) {
|
|
7053
7302
|
removed.push(arg);
|
|
7054
7303
|
}
|
|
7055
7304
|
continue;
|
|
@@ -7064,7 +7313,7 @@ combined with either mode.`
|
|
|
7064
7313
|
await runLifecycleHookWithTask(context.projectDir, "remove", "Run template remove");
|
|
7065
7314
|
}
|
|
7066
7315
|
if (!force) {
|
|
7067
|
-
await checkVersionsCompatibility(context.projectDir
|
|
7316
|
+
await checkVersionsCompatibility(context.projectDir);
|
|
7068
7317
|
}
|
|
7069
7318
|
if (isJsonMode()) {
|
|
7070
7319
|
printJsonResult({ removed });
|
|
@@ -7072,25 +7321,25 @@ combined with either mode.`
|
|
|
7072
7321
|
} catch (e) {
|
|
7073
7322
|
if (!isDebugMode() && !(e instanceof CliError)) {
|
|
7074
7323
|
import_prompts2.log.warn("Error happened, Will rollback changes");
|
|
7075
|
-
await git.rollback();
|
|
7324
|
+
await git.rollback(projectDir);
|
|
7076
7325
|
}
|
|
7077
7326
|
handleCommandError(e);
|
|
7078
7327
|
}
|
|
7079
7328
|
});
|
|
7080
7329
|
|
|
7081
7330
|
// src/commands/skills/index.ts
|
|
7082
|
-
var
|
|
7331
|
+
var import_node_crypto2 = require("crypto");
|
|
7083
7332
|
var import_node_os4 = __toESM(require("os"));
|
|
7084
|
-
var
|
|
7333
|
+
var import_node_path34 = __toESM(require("path"));
|
|
7085
7334
|
var import_cross_spawn2 = __toESM(require("cross-spawn"));
|
|
7086
|
-
var
|
|
7335
|
+
var import_fs_extra30 = __toESM(require("fs-extra"));
|
|
7087
7336
|
|
|
7088
7337
|
// src/commands/skills/constants.ts
|
|
7089
7338
|
var SKILLS_REPO_URL = "https://github.com/Naseej-its/blox.git";
|
|
7090
7339
|
|
|
7091
7340
|
// src/commands/skills/utils/cliCompatibility.ts
|
|
7092
|
-
var
|
|
7093
|
-
var
|
|
7341
|
+
var import_node_path33 = __toESM(require("path"));
|
|
7342
|
+
var import_fs_extra29 = __toESM(require("fs-extra"));
|
|
7094
7343
|
var import_semver2 = __toESM(require("semver"));
|
|
7095
7344
|
var SKILLS_CLI_COMPATIBILITY_COMMANDS = ["add", "update"];
|
|
7096
7345
|
function getSkillscommandIndex(args, subcommand) {
|
|
@@ -7114,18 +7363,18 @@ function getAddCommandIndex(args) {
|
|
|
7114
7363
|
return getSkillscommandIndex(args, "add");
|
|
7115
7364
|
}
|
|
7116
7365
|
async function loadSkillsData(cloneRoot) {
|
|
7117
|
-
const skillsDir =
|
|
7118
|
-
if (!await
|
|
7366
|
+
const skillsDir = import_node_path33.default.join(cloneRoot, "skills");
|
|
7367
|
+
if (!await import_fs_extra29.default.pathExists(skillsDir)) {
|
|
7119
7368
|
return [];
|
|
7120
7369
|
}
|
|
7121
|
-
const entries = await
|
|
7370
|
+
const entries = await import_fs_extra29.default.readdir(skillsDir, { withFileTypes: true });
|
|
7122
7371
|
const manifests = await Promise.all(
|
|
7123
7372
|
entries.filter((entry) => entry.isDirectory()).map(async (entry) => {
|
|
7124
|
-
const filePath =
|
|
7125
|
-
if (!await
|
|
7373
|
+
const filePath = import_node_path33.default.join(skillsDir, entry.name, "skill.json");
|
|
7374
|
+
if (!await import_fs_extra29.default.pathExists(filePath)) {
|
|
7126
7375
|
return null;
|
|
7127
7376
|
}
|
|
7128
|
-
const raw = await
|
|
7377
|
+
const raw = await import_fs_extra29.default.readJson(filePath);
|
|
7129
7378
|
const range = raw.cliCompatibility?.trim();
|
|
7130
7379
|
if (!range) {
|
|
7131
7380
|
return null;
|
|
@@ -7177,8 +7426,8 @@ async function runSkills() {
|
|
|
7177
7426
|
const idx = process.argv.indexOf("skills");
|
|
7178
7427
|
const args = idx === -1 ? [] : process.argv.slice(idx + 1);
|
|
7179
7428
|
if (needsCliCompatibilityCheck(args)) {
|
|
7180
|
-
const tempDir =
|
|
7181
|
-
await
|
|
7429
|
+
const tempDir = import_node_path34.default.join(import_node_os4.default.tmpdir(), `blox-skills-compat-${(0, import_node_crypto2.randomUUID)()}`);
|
|
7430
|
+
await import_fs_extra30.default.mkdir(tempDir);
|
|
7182
7431
|
try {
|
|
7183
7432
|
await git.clone(SKILLS_REPO_URL, tempDir);
|
|
7184
7433
|
const skills2 = await loadSkillsData(tempDir);
|
|
@@ -7196,7 +7445,7 @@ async function runSkills() {
|
|
|
7196
7445
|
}
|
|
7197
7446
|
} finally {
|
|
7198
7447
|
try {
|
|
7199
|
-
await
|
|
7448
|
+
await import_fs_extra30.default.remove(tempDir);
|
|
7200
7449
|
} catch {
|
|
7201
7450
|
debug(`Failed to cleanup temp dir: ${tempDir}`);
|
|
7202
7451
|
}
|
|
@@ -7229,15 +7478,15 @@ function runSkillsCommand(args, cwd) {
|
|
|
7229
7478
|
}
|
|
7230
7479
|
|
|
7231
7480
|
// src/commands/update/index.ts
|
|
7232
|
-
var
|
|
7481
|
+
var import_prompts27 = require("@clack/prompts");
|
|
7233
7482
|
|
|
7234
7483
|
// src/commands/update/utils.ts
|
|
7235
|
-
var
|
|
7236
|
-
var
|
|
7484
|
+
var import_node_path37 = __toESM(require("path"));
|
|
7485
|
+
var import_fs_extra32 = __toESM(require("fs-extra"));
|
|
7237
7486
|
|
|
7238
7487
|
// src/services/updater/index.ts
|
|
7239
|
-
var
|
|
7240
|
-
var
|
|
7488
|
+
var import_node_path36 = __toESM(require("path"));
|
|
7489
|
+
var import_fs_extra31 = __toESM(require("fs-extra"));
|
|
7241
7490
|
var import_klaw3 = __toESM(require("klaw"));
|
|
7242
7491
|
|
|
7243
7492
|
// src/services/updater/utils/formaters.ts
|
|
@@ -7324,6 +7573,23 @@ async function confirmBreakingChanges(name, fromCommit, toCommit, opts = {}) {
|
|
|
7324
7573
|
return run;
|
|
7325
7574
|
}
|
|
7326
7575
|
|
|
7576
|
+
// src/services/updater/utils/pruneEmptyDirs.ts
|
|
7577
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
7578
|
+
var import_node_path35 = __toESM(require("path"));
|
|
7579
|
+
var pruneEmptyDirs = async (startDir, stopDir) => {
|
|
7580
|
+
const root = import_node_path35.default.resolve(stopDir);
|
|
7581
|
+
let current = import_node_path35.default.resolve(startDir);
|
|
7582
|
+
while (current !== root && current.startsWith(root + import_node_path35.default.sep)) {
|
|
7583
|
+
try {
|
|
7584
|
+
if ((await import_promises.default.readdir(current)).length > 0) return;
|
|
7585
|
+
await import_promises.default.rmdir(current);
|
|
7586
|
+
} catch {
|
|
7587
|
+
return;
|
|
7588
|
+
}
|
|
7589
|
+
current = import_node_path35.default.dirname(current);
|
|
7590
|
+
}
|
|
7591
|
+
};
|
|
7592
|
+
|
|
7327
7593
|
// src/services/updater/index.ts
|
|
7328
7594
|
async function updateFromRemote({
|
|
7329
7595
|
name,
|
|
@@ -7375,9 +7641,9 @@ async function updateFromRemote({
|
|
|
7375
7641
|
const remoteIgnore = remoteBloxFile.definition?.ignore || [];
|
|
7376
7642
|
const projectIgnore = bloxFile.project?.ignore || [];
|
|
7377
7643
|
ignore3.push(...remoteIgnore, ...projectIgnore, bloxFilePath, `**/${bloxFilePath}`);
|
|
7378
|
-
const gitIgnorePath =
|
|
7379
|
-
if (await
|
|
7380
|
-
const gitIgnoreContent = await
|
|
7644
|
+
const gitIgnorePath = import_node_path36.default.join(dir, ".gitignore");
|
|
7645
|
+
if (await import_fs_extra31.default.pathExists(gitIgnorePath)) {
|
|
7646
|
+
const gitIgnoreContent = await import_fs_extra31.default.readFile(gitIgnorePath, "utf8");
|
|
7381
7647
|
const gitIgnorePatterns = gitIgnoreContent.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
7382
7648
|
ignore3.push(...gitIgnorePatterns);
|
|
7383
7649
|
debug(`Added ${gitIgnorePatterns.length} patterns from .gitignore`);
|
|
@@ -7389,14 +7655,14 @@ async function updateFromRemote({
|
|
|
7389
7655
|
if (hard) {
|
|
7390
7656
|
const getAllFiles = async (d) => {
|
|
7391
7657
|
const files = [];
|
|
7392
|
-
if (await
|
|
7658
|
+
if (await import_fs_extra31.default.pathExists(d)) {
|
|
7393
7659
|
for await (const file of (0, import_klaw3.default)(d)) {
|
|
7394
7660
|
if (file.path.includes("/.git/") || file.path.endsWith("/.git") || file.path.includes("\\.git\\") || file.path.endsWith("\\.git"))
|
|
7395
7661
|
continue;
|
|
7396
7662
|
if (file.path.includes("/node_modules/") || file.path.includes("\\node_modules\\"))
|
|
7397
7663
|
continue;
|
|
7398
7664
|
if (file.stats.isFile()) {
|
|
7399
|
-
files.push(
|
|
7665
|
+
files.push(import_node_path36.default.relative(d, file.path));
|
|
7400
7666
|
}
|
|
7401
7667
|
}
|
|
7402
7668
|
}
|
|
@@ -7415,23 +7681,23 @@ async function updateFromRemote({
|
|
|
7415
7681
|
for (const file of filesToProcess) {
|
|
7416
7682
|
if (file === ".git" || file.startsWith(".git/") || file.startsWith(".git\\")) continue;
|
|
7417
7683
|
if (ignoredMatcher.ignores(toIgnorePath(file))) continue;
|
|
7418
|
-
const localPath =
|
|
7419
|
-
const basePath =
|
|
7420
|
-
const remotePath =
|
|
7421
|
-
const existsLocal = await
|
|
7422
|
-
const existsBase = await
|
|
7423
|
-
const existsRemote = await
|
|
7424
|
-
const ext =
|
|
7684
|
+
const localPath = import_node_path36.default.join(dir, file);
|
|
7685
|
+
const basePath = import_node_path36.default.join(baseDir, file);
|
|
7686
|
+
const remotePath = import_node_path36.default.join(remoteDir, file);
|
|
7687
|
+
const existsLocal = await import_fs_extra31.default.pathExists(localPath);
|
|
7688
|
+
const existsBase = await import_fs_extra31.default.pathExists(basePath);
|
|
7689
|
+
const existsRemote = await import_fs_extra31.default.pathExists(remotePath);
|
|
7690
|
+
const ext = import_node_path36.default.extname(file);
|
|
7425
7691
|
const isBinary = isBinaryFile(ext);
|
|
7426
7692
|
if (existsRemote) {
|
|
7427
|
-
await
|
|
7693
|
+
await import_fs_extra31.default.ensureDir(import_node_path36.default.dirname(localPath));
|
|
7428
7694
|
}
|
|
7429
7695
|
if (hard) {
|
|
7430
7696
|
if (existsRemote) {
|
|
7431
|
-
await
|
|
7697
|
+
await import_fs_extra31.default.copy(remotePath, localPath, { overwrite: true });
|
|
7432
7698
|
debug(`Hard update: Overwrote ${file}`);
|
|
7433
7699
|
} else if (existsLocal) {
|
|
7434
|
-
await
|
|
7700
|
+
await import_fs_extra31.default.remove(localPath);
|
|
7435
7701
|
debug(`Hard update: Removed ${file}`);
|
|
7436
7702
|
}
|
|
7437
7703
|
continue;
|
|
@@ -7440,29 +7706,30 @@ async function updateFromRemote({
|
|
|
7440
7706
|
if (existsLocal) {
|
|
7441
7707
|
if (isBinary) {
|
|
7442
7708
|
debug(`Binary collision: ${file}, overwriting.`);
|
|
7443
|
-
await
|
|
7709
|
+
await import_fs_extra31.default.copy(remotePath, localPath, { overwrite: true });
|
|
7444
7710
|
logWarningSection(`Overwrote binary file collision: ${file}`);
|
|
7445
7711
|
} else {
|
|
7446
|
-
const emptyBase =
|
|
7447
|
-
await
|
|
7712
|
+
const emptyBase = import_node_path36.default.join(baseDir, `${file}.empty`);
|
|
7713
|
+
await import_fs_extra31.default.ensureFile(emptyBase);
|
|
7448
7714
|
const result = await git.mergeFile(localPath, emptyBase, remotePath);
|
|
7449
7715
|
if (!result) {
|
|
7450
7716
|
hasConflicts2 = true;
|
|
7451
7717
|
conflictFiles.push(file);
|
|
7452
7718
|
}
|
|
7453
|
-
await
|
|
7719
|
+
await import_fs_extra31.default.remove(emptyBase);
|
|
7454
7720
|
}
|
|
7455
7721
|
} else {
|
|
7456
|
-
await
|
|
7722
|
+
await import_fs_extra31.default.copy(remotePath, localPath);
|
|
7457
7723
|
}
|
|
7458
7724
|
continue;
|
|
7459
7725
|
}
|
|
7460
7726
|
if (existsBase && !existsRemote) {
|
|
7461
7727
|
if (existsLocal) {
|
|
7462
|
-
const localBuffer = await
|
|
7463
|
-
const baseBuffer = await
|
|
7728
|
+
const localBuffer = await import_fs_extra31.default.readFile(localPath);
|
|
7729
|
+
const baseBuffer = await import_fs_extra31.default.readFile(basePath);
|
|
7464
7730
|
if (localBuffer.equals(baseBuffer)) {
|
|
7465
|
-
await
|
|
7731
|
+
await import_fs_extra31.default.remove(localPath);
|
|
7732
|
+
await pruneEmptyDirs(import_node_path36.default.dirname(localPath), dir);
|
|
7466
7733
|
} else {
|
|
7467
7734
|
logWarningSection(
|
|
7468
7735
|
`File ${file} was deleted in remote but modified locally. Kept local version.`
|
|
@@ -7473,7 +7740,7 @@ async function updateFromRemote({
|
|
|
7473
7740
|
}
|
|
7474
7741
|
if (existsBase && existsRemote) {
|
|
7475
7742
|
if (!existsLocal) {
|
|
7476
|
-
await
|
|
7743
|
+
await import_fs_extra31.default.copy(remotePath, localPath);
|
|
7477
7744
|
logWarningSection(
|
|
7478
7745
|
`File restored: ${file}`,
|
|
7479
7746
|
`This file was deleted locally but updated in the remote block.
|
|
@@ -7482,7 +7749,7 @@ It has been recreated to apply upstream changes.`
|
|
|
7482
7749
|
continue;
|
|
7483
7750
|
}
|
|
7484
7751
|
if (isBinary) {
|
|
7485
|
-
await
|
|
7752
|
+
await import_fs_extra31.default.copy(remotePath, localPath, { overwrite: true });
|
|
7486
7753
|
logWarningSection(`Updated binary file: ${file} (overwritten)`);
|
|
7487
7754
|
} else {
|
|
7488
7755
|
const result = await git.mergeFile(localPath, basePath, remotePath);
|
|
@@ -7497,7 +7764,7 @@ It has been recreated to apply upstream changes.`
|
|
|
7497
7764
|
logWarningSection(
|
|
7498
7765
|
`Conflicts detected in "${name}":`,
|
|
7499
7766
|
conflictFiles.map((file) => {
|
|
7500
|
-
const absolutePath = normalizePath(
|
|
7767
|
+
const absolutePath = normalizePath(import_node_path36.default.resolve(dir, file));
|
|
7501
7768
|
return `${fmt.red(absolutePath)} (${file})`;
|
|
7502
7769
|
}).join("\n")
|
|
7503
7770
|
);
|
|
@@ -7528,6 +7795,31 @@ ${conflictFiles.map((f) => `- ${f}`).join("\n")}`,
|
|
|
7528
7795
|
}
|
|
7529
7796
|
|
|
7530
7797
|
// src/commands/update/utils.ts
|
|
7798
|
+
function reportUpdateSummary(summary, mode) {
|
|
7799
|
+
const failedScopes = (summary.scopes ?? []).filter((scope) => scope.error);
|
|
7800
|
+
const failed = summary.failedBlocks.length > 0 || failedScopes.length > 0;
|
|
7801
|
+
if (mode.json) {
|
|
7802
|
+
if (failed) {
|
|
7803
|
+
printJsonError({
|
|
7804
|
+
code: summary.failedBlocks.length ? "BLOCK_UPDATE_FAILED" : "UPDATE_FAILED",
|
|
7805
|
+
message: [
|
|
7806
|
+
...summary.failedBlocks.map(
|
|
7807
|
+
(failure) => `${failure.block}: ${failure.error}`
|
|
7808
|
+
),
|
|
7809
|
+
...failedScopes.map((scope) => `${scope.scope}: ${scope.error}`)
|
|
7810
|
+
].join("; "),
|
|
7811
|
+
details: { ...summary },
|
|
7812
|
+
exitCode: exitCodes.GENERAL
|
|
7813
|
+
});
|
|
7814
|
+
} else {
|
|
7815
|
+
printJsonResult(summary);
|
|
7816
|
+
}
|
|
7817
|
+
return;
|
|
7818
|
+
}
|
|
7819
|
+
if (failed && mode.nonInteractive) {
|
|
7820
|
+
process.exitCode = exitCodes.GENERAL;
|
|
7821
|
+
}
|
|
7822
|
+
}
|
|
7531
7823
|
var isRecoverableBlockUpdateError = (error2) => {
|
|
7532
7824
|
if (!(error2 instanceof Error)) return false;
|
|
7533
7825
|
if (!error2.message.startsWith('Command "git fetch ')) return false;
|
|
@@ -7545,14 +7837,6 @@ async function confirmContinueWhenMissing(itemType, name) {
|
|
|
7545
7837
|
initialValue: true
|
|
7546
7838
|
});
|
|
7547
7839
|
}
|
|
7548
|
-
var listVendoredBlocks = (projectDir) => {
|
|
7549
|
-
const blocksRoot = import_node_path35.default.join(projectDir, blocksDir);
|
|
7550
|
-
if (!import_fs_extra31.default.existsSync(blocksRoot)) return [];
|
|
7551
|
-
return import_fs_extra31.default.readdirSync(blocksRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => ({
|
|
7552
|
-
dir: entry.name,
|
|
7553
|
-
name: getBloxFile(import_node_path35.default.join(blocksRoot, entry.name)).definition?.name
|
|
7554
|
-
})).filter((block) => !!block.name);
|
|
7555
|
-
};
|
|
7556
7840
|
var repinVendoredUnit = async (unit, toAppCommit) => {
|
|
7557
7841
|
if (!unit.source) return "missing";
|
|
7558
7842
|
await git.updateRemote(unit.remote, unit.source);
|
|
@@ -7570,52 +7854,26 @@ var repinVendoredUnit = async (unit, toAppCommit) => {
|
|
|
7570
7854
|
);
|
|
7571
7855
|
return false;
|
|
7572
7856
|
};
|
|
7573
|
-
var vendoredUnits =
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
}));
|
|
7580
|
-
const workspaceRoot = process.cwd();
|
|
7581
|
-
if (findWorkspaceRoot(workspaceRoot) !== workspaceRoot) return units;
|
|
7582
|
-
const availableApps = await getAvailableApps(templateDef);
|
|
7583
|
-
for (const app of listApps(workspaceRoot)) {
|
|
7584
|
-
const appDir = import_node_path35.default.relative(workspaceRoot, app.dir);
|
|
7585
|
-
units.push({
|
|
7586
|
-
name: app.def.name,
|
|
7587
|
-
dir: appDir,
|
|
7588
|
-
remote: `${appsDir}/${app.key}`,
|
|
7589
|
-
source: availableApps[app.key]?.source
|
|
7590
|
-
});
|
|
7591
|
-
const appBlocks = await getAvailableBlocksForApp(
|
|
7592
|
-
app.key,
|
|
7593
|
-
templateDef.name,
|
|
7594
|
-
app.def
|
|
7595
|
-
);
|
|
7596
|
-
for (const block of listVendoredBlocks(app.dir)) {
|
|
7597
|
-
units.push({
|
|
7598
|
-
name: block.name,
|
|
7599
|
-
dir: import_node_path35.default.join(appDir, blocksDir, block.dir),
|
|
7600
|
-
remote: `${appsDir}/${app.key}/${blocksDir}/${block.dir}`,
|
|
7601
|
-
source: appBlocks[block.name]?.source
|
|
7602
|
-
});
|
|
7603
|
-
}
|
|
7604
|
-
}
|
|
7605
|
-
return units;
|
|
7606
|
-
};
|
|
7857
|
+
var vendoredUnits = (usedBlocks, availableBlocks) => usedBlocks.map((block) => ({
|
|
7858
|
+
name: block.name,
|
|
7859
|
+
dir: getBlockPath(block.name),
|
|
7860
|
+
remote: block.name,
|
|
7861
|
+
source: availableBlocks[block.name]?.source
|
|
7862
|
+
}));
|
|
7607
7863
|
async function updateApp({
|
|
7608
7864
|
templateDef,
|
|
7609
7865
|
templates,
|
|
7610
7866
|
usedBlocks,
|
|
7611
7867
|
availableBlocks,
|
|
7868
|
+
appKey,
|
|
7612
7869
|
ignore: ignore3,
|
|
7613
7870
|
hard = false,
|
|
7614
7871
|
allowBreaking = false
|
|
7615
7872
|
}) {
|
|
7616
7873
|
let updated = false;
|
|
7617
7874
|
let shouldContinue = true;
|
|
7618
|
-
|
|
7875
|
+
const label = appKey ? ` App: ${appKey}` : " App";
|
|
7876
|
+
await runTask({ start: `Update${label}`, end: `Updated${label}` }, async () => {
|
|
7619
7877
|
const template = templates[templateDef.name];
|
|
7620
7878
|
if (!template) {
|
|
7621
7879
|
shouldContinue = await confirmContinueWhenMissing(
|
|
@@ -7634,11 +7892,7 @@ async function updateApp({
|
|
|
7634
7892
|
if (!toAppCommit) return;
|
|
7635
7893
|
updated = true;
|
|
7636
7894
|
if (!templateDef.bases?.length) return;
|
|
7637
|
-
for (const unit of
|
|
7638
|
-
usedBlocks,
|
|
7639
|
-
availableBlocks,
|
|
7640
|
-
templateDef
|
|
7641
|
-
)) {
|
|
7895
|
+
for (const unit of vendoredUnits(usedBlocks, availableBlocks)) {
|
|
7642
7896
|
const result = await repinVendoredUnit(unit, toAppCommit);
|
|
7643
7897
|
if (result === "missing") {
|
|
7644
7898
|
shouldContinue = await confirmContinueWhenMissing(
|
|
@@ -7804,14 +8058,23 @@ async function getCurrentCheckpoints(workspaceRoot = ".") {
|
|
|
7804
8058
|
}
|
|
7805
8059
|
return checkpoints;
|
|
7806
8060
|
}
|
|
7807
|
-
async function printChangeLog(startCheckpoints, endCheckpoints) {
|
|
8061
|
+
async function printChangeLog(startCheckpoints, endCheckpoints, workspaceRoot = ".") {
|
|
7808
8062
|
const allChanges = [];
|
|
8063
|
+
const repoDirFor = (name) => {
|
|
8064
|
+
const appKey = name.split("/")[0] ?? "";
|
|
8065
|
+
const appDir = import_node_path37.default.join(workspaceRoot, appsDir, appKey);
|
|
8066
|
+
return name.includes("/") && import_fs_extra32.default.existsSync(import_node_path37.default.join(appDir, bloxFilePath)) ? appDir : workspaceRoot;
|
|
8067
|
+
};
|
|
7809
8068
|
for (const name of Object.keys(startCheckpoints)) {
|
|
7810
8069
|
const fromCommit = startCheckpoints[name]?.commit;
|
|
7811
8070
|
const toCommit = endCheckpoints[name]?.commit;
|
|
7812
8071
|
if (!fromCommit || !toCommit) continue;
|
|
7813
8072
|
if (fromCommit === toCommit) continue;
|
|
7814
|
-
const changes = await git.getChangesLog(
|
|
8073
|
+
const changes = await git.getChangesLog(
|
|
8074
|
+
fromCommit,
|
|
8075
|
+
toCommit,
|
|
8076
|
+
repoDirFor(name)
|
|
8077
|
+
);
|
|
7815
8078
|
if (changes.trim() !== "") {
|
|
7816
8079
|
allChanges.push(`${fmt.bold(fmt.bgYellowBright(name))}:
|
|
7817
8080
|
|
|
@@ -7837,22 +8100,14 @@ async function runScopeUpdate(args, ignoresByName, rootTemplateName, appKey) {
|
|
|
7837
8100
|
const templates = await getAvailableTemplates();
|
|
7838
8101
|
const usedBlocks = getUsedBlocksDef();
|
|
7839
8102
|
let availableBlocks;
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
templateDef
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
const appEntry = templates[rootTemplateName]?.apps?.[appKey];
|
|
7848
|
-
if (appEntry?.source) {
|
|
7849
|
-
templates[templateDef.name] = {
|
|
7850
|
-
...appEntry
|
|
7851
|
-
};
|
|
7852
|
-
}
|
|
8103
|
+
availableBlocks = await getAvailableBlocks(templateDef);
|
|
8104
|
+
if (appKey && !templates[templateDef.name]?.source) {
|
|
8105
|
+
const appEntry = templates[rootTemplateName]?.apps?.[appKey];
|
|
8106
|
+
if (appEntry?.source) {
|
|
8107
|
+
templates[templateDef.name] = {
|
|
8108
|
+
...appEntry
|
|
8109
|
+
};
|
|
7853
8110
|
}
|
|
7854
|
-
} else {
|
|
7855
|
-
availableBlocks = await getAvailableBlocks(templateDef);
|
|
7856
8111
|
}
|
|
7857
8112
|
let hasUpdate = false;
|
|
7858
8113
|
let shouldContinue = true;
|
|
@@ -7863,6 +8118,7 @@ async function runScopeUpdate(args, ignoresByName, rootTemplateName, appKey) {
|
|
|
7863
8118
|
templates,
|
|
7864
8119
|
usedBlocks,
|
|
7865
8120
|
availableBlocks,
|
|
8121
|
+
appKey,
|
|
7866
8122
|
ignore: ignoresByName[templateDef.name],
|
|
7867
8123
|
hard: args.hard,
|
|
7868
8124
|
allowBreaking: args.allowBreaking
|
|
@@ -7887,7 +8143,7 @@ async function runScopeUpdate(args, ignoresByName, rootTemplateName, appKey) {
|
|
|
7887
8143
|
);
|
|
7888
8144
|
for (const block of missingBlocks) {
|
|
7889
8145
|
if (isNonInteractive()) {
|
|
7890
|
-
|
|
8146
|
+
import_prompts27.log.warn(
|
|
7891
8147
|
`${block.name} does not exist in registries. Continuing with remaining parts.`
|
|
7892
8148
|
);
|
|
7893
8149
|
continue;
|
|
@@ -7921,19 +8177,24 @@ async function runScopeUpdate(args, ignoresByName, rootTemplateName, appKey) {
|
|
|
7921
8177
|
);
|
|
7922
8178
|
hasUpdate = hasUpdate || blockResults.some((result) => result.updated);
|
|
7923
8179
|
const failed = blockResults.filter((result) => result.error);
|
|
7924
|
-
failedBlocks.push(
|
|
8180
|
+
failedBlocks.push(
|
|
8181
|
+
...failed.map((result) => ({
|
|
8182
|
+
block: result.block,
|
|
8183
|
+
error: getErrorMessage(result.error)
|
|
8184
|
+
}))
|
|
8185
|
+
);
|
|
7925
8186
|
if (failed.length) {
|
|
7926
|
-
|
|
8187
|
+
import_prompts27.log.warn(
|
|
7927
8188
|
fmt.yellow(
|
|
7928
8189
|
`${failedBlocks.length} block update${failedBlocks.length === 1 ? "" : "s"} failed.`
|
|
7929
8190
|
)
|
|
7930
8191
|
);
|
|
7931
8192
|
for (const result of failed) {
|
|
7932
|
-
|
|
8193
|
+
import_prompts27.log.error(
|
|
7933
8194
|
fmt.red(`${result.block}: ${getErrorMessage(result.error)}`)
|
|
7934
8195
|
);
|
|
7935
8196
|
}
|
|
7936
|
-
|
|
8197
|
+
import_prompts27.log.warn(
|
|
7937
8198
|
"Fix the errors above and rerun the update for the failed blocks."
|
|
7938
8199
|
);
|
|
7939
8200
|
}
|
|
@@ -7975,12 +8236,15 @@ async function runScopeUpdate(args, ignoresByName, rootTemplateName, appKey) {
|
|
|
7975
8236
|
);
|
|
7976
8237
|
for (const result of blockResults) {
|
|
7977
8238
|
if (result.error) {
|
|
7978
|
-
failedBlocks.push(
|
|
7979
|
-
|
|
8239
|
+
failedBlocks.push({
|
|
8240
|
+
block: result.block,
|
|
8241
|
+
error: getErrorMessage(result.error)
|
|
8242
|
+
});
|
|
8243
|
+
import_prompts27.log.error(fmt.red(`${result.block}: ${getErrorMessage(result.error)}`));
|
|
7980
8244
|
}
|
|
7981
8245
|
}
|
|
7982
8246
|
if (blockResults.some((result) => result.error)) {
|
|
7983
|
-
|
|
8247
|
+
import_prompts27.log.warn(
|
|
7984
8248
|
"Fix the errors above and rerun the update for the failed blocks."
|
|
7985
8249
|
);
|
|
7986
8250
|
}
|
|
@@ -7992,7 +8256,7 @@ async function runScopeUpdate(args, ignoresByName, rootTemplateName, appKey) {
|
|
|
7992
8256
|
}
|
|
7993
8257
|
}
|
|
7994
8258
|
if (!shouldContinue) {
|
|
7995
|
-
|
|
8259
|
+
import_prompts27.log.warn(fmt.yellow("Stopped updating remaining parts by user choice"));
|
|
7996
8260
|
}
|
|
7997
8261
|
if (hasUpdate) {
|
|
7998
8262
|
await runLifecycleHookWithTask(".", "update", "Run template update");
|
|
@@ -8033,19 +8297,6 @@ directory to limit the update to that application.`
|
|
|
8033
8297
|
)
|
|
8034
8298
|
).action(async (args) => {
|
|
8035
8299
|
initExecutionMode(args);
|
|
8036
|
-
if (await git.hasUncommittedChanges()) {
|
|
8037
|
-
if (isNonInteractive()) {
|
|
8038
|
-
handleCommandError(
|
|
8039
|
-
new CliError(
|
|
8040
|
-
"Make sure to commit any changes first",
|
|
8041
|
-
"DIRTY_WORKING_TREE",
|
|
8042
|
-
exitCodes.GENERAL
|
|
8043
|
-
)
|
|
8044
|
-
);
|
|
8045
|
-
}
|
|
8046
|
-
import_prompts26.log.warn(fmt.yellow("Make sure to commit any changes first"));
|
|
8047
|
-
return;
|
|
8048
|
-
}
|
|
8049
8300
|
const ignoresByName = {};
|
|
8050
8301
|
for (const ignore3 of args.ignore || []) {
|
|
8051
8302
|
const [repo, pattern] = ignore3.split(":");
|
|
@@ -8060,6 +8311,7 @@ directory to limit the update to that application.`
|
|
|
8060
8311
|
}
|
|
8061
8312
|
ignoresByName[repo].push(pattern);
|
|
8062
8313
|
}
|
|
8314
|
+
const touchedScopes = [];
|
|
8063
8315
|
try {
|
|
8064
8316
|
const context = resolveContext(".", args.app);
|
|
8065
8317
|
const scoped = args.app || context.app;
|
|
@@ -8070,6 +8322,20 @@ directory to limit the update to that application.`
|
|
|
8070
8322
|
app: app.key
|
|
8071
8323
|
}))
|
|
8072
8324
|
];
|
|
8325
|
+
const dirtyScopes = [];
|
|
8326
|
+
for (const scope of scopes) {
|
|
8327
|
+
if (await git.hasUncommittedChanges(scope.dir)) {
|
|
8328
|
+
dirtyScopes.push(scope.app ?? "workspace root");
|
|
8329
|
+
}
|
|
8330
|
+
}
|
|
8331
|
+
if (dirtyScopes.length) {
|
|
8332
|
+
const message = `Make sure to commit any changes first: ${dirtyScopes.join(", ")}`;
|
|
8333
|
+
if (isNonInteractive()) {
|
|
8334
|
+
throw new CliError(message, "DIRTY_WORKING_TREE", exitCodes.GENERAL);
|
|
8335
|
+
}
|
|
8336
|
+
import_prompts27.log.warn(fmt.yellow(message));
|
|
8337
|
+
return;
|
|
8338
|
+
}
|
|
8073
8339
|
const rootTemplateName = getTemplateDef(context.workspaceRoot).name;
|
|
8074
8340
|
await migrateAll(true, context.workspaceRoot);
|
|
8075
8341
|
await syncRegistries();
|
|
@@ -8077,39 +8343,72 @@ directory to limit the update to that application.`
|
|
|
8077
8343
|
let hasUpdate = false;
|
|
8078
8344
|
let stoppedEarly = false;
|
|
8079
8345
|
const failedBlocks = [];
|
|
8346
|
+
const scopeResults = [];
|
|
8080
8347
|
const cwd = process.cwd();
|
|
8081
8348
|
try {
|
|
8082
8349
|
for (const scope of scopes) {
|
|
8083
8350
|
process.chdir(scope.dir);
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8351
|
+
touchedScopes.push(scope.dir);
|
|
8352
|
+
try {
|
|
8353
|
+
const result = await runScopeUpdate(
|
|
8354
|
+
args,
|
|
8355
|
+
ignoresByName,
|
|
8356
|
+
rootTemplateName,
|
|
8357
|
+
scope.app
|
|
8358
|
+
);
|
|
8359
|
+
hasUpdate = hasUpdate || result.updated;
|
|
8360
|
+
stoppedEarly = stoppedEarly || result.stoppedEarly;
|
|
8361
|
+
failedBlocks.push(...result.failedBlocks);
|
|
8362
|
+
scopeResults.push({ scope: scope.app ?? "(root)", ...result });
|
|
8363
|
+
} catch (scopeError) {
|
|
8364
|
+
if (scopeError instanceof CliError) throw scopeError;
|
|
8365
|
+
const message = scopeError instanceof Error ? scopeError.message : String(scopeError);
|
|
8366
|
+
try {
|
|
8367
|
+
await git.rollback(scope.dir);
|
|
8368
|
+
} catch (rollbackError) {
|
|
8369
|
+
import_prompts27.log.warn(
|
|
8370
|
+
fmt.yellow(`Rollback failed for ${scope.dir}: ${rollbackError}`)
|
|
8371
|
+
);
|
|
8372
|
+
}
|
|
8373
|
+
scopeResults.push({
|
|
8374
|
+
scope: scope.app ?? "(root)",
|
|
8375
|
+
updated: false,
|
|
8376
|
+
stoppedEarly: false,
|
|
8377
|
+
failedBlocks: [],
|
|
8378
|
+
error: message
|
|
8379
|
+
});
|
|
8380
|
+
import_prompts27.log.error(fmt.red(`${scope.app ?? "workspace root"}: ${message}`));
|
|
8381
|
+
}
|
|
8093
8382
|
}
|
|
8094
8383
|
} finally {
|
|
8095
8384
|
process.chdir(cwd);
|
|
8096
8385
|
}
|
|
8097
8386
|
const endCheckpoints = await getCurrentCheckpoints(context.workspaceRoot);
|
|
8098
|
-
await printChangeLog(startCheckpoints, endCheckpoints);
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
if (failedBlocks.length && isNonInteractive()) {
|
|
8107
|
-
process.exitCode = exitCodes.GENERAL;
|
|
8387
|
+
await printChangeLog(startCheckpoints, endCheckpoints, context.workspaceRoot);
|
|
8388
|
+
const failedScopes = scopeResults.filter((result) => result.error);
|
|
8389
|
+
if (failedScopes.length) {
|
|
8390
|
+
import_prompts27.log.warn(
|
|
8391
|
+
fmt.yellow(
|
|
8392
|
+
`${failedScopes.length} scope(s) failed to update: ${failedScopes.map((result) => result.scope).join(", ")}`
|
|
8393
|
+
)
|
|
8394
|
+
);
|
|
8108
8395
|
}
|
|
8396
|
+
reportUpdateSummary(
|
|
8397
|
+
{ updated: hasUpdate, stoppedEarly, failedBlocks, scopes: scopeResults },
|
|
8398
|
+
{ json: isJsonMode(), nonInteractive: isNonInteractive() }
|
|
8399
|
+
);
|
|
8109
8400
|
} catch (e) {
|
|
8110
|
-
if (!isDebugMode()) {
|
|
8111
|
-
|
|
8112
|
-
|
|
8401
|
+
if (!isDebugMode() && !(e instanceof CliError)) {
|
|
8402
|
+
import_prompts27.log.warn("Error happened, Will rollback changes");
|
|
8403
|
+
for (const dir of new Set(touchedScopes)) {
|
|
8404
|
+
try {
|
|
8405
|
+
await git.rollback(dir);
|
|
8406
|
+
} catch {
|
|
8407
|
+
}
|
|
8408
|
+
}
|
|
8409
|
+
if (!touchedScopes.length) {
|
|
8410
|
+
await git.rollback();
|
|
8411
|
+
}
|
|
8113
8412
|
}
|
|
8114
8413
|
handleCommandError(e);
|
|
8115
8414
|
} finally {
|