@anvil-works/anvil-cli 0.8.0-dev.1 → 0.8.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/README.md +3 -3
- package/dist/CLILogger.d.ts.map +1 -1
- package/dist/SavePathRouter.d.ts +4 -2
- package/dist/SavePathRouter.d.ts.map +1 -1
- package/dist/WatchSession.d.ts +5 -2
- package/dist/WatchSession.d.ts.map +1 -1
- package/dist/api.d.ts +5 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/appRoot.d.ts +11 -0
- package/dist/appRoot.d.ts.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +18815 -17933
- package/dist/cliProgram.d.ts +4 -0
- package/dist/cliProgram.d.ts.map +1 -0
- package/dist/cliReporting.d.ts +4 -0
- package/dist/cliReporting.d.ts.map +1 -0
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/deps.d.ts.map +1 -1
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/secret.d.ts.map +1 -1
- package/dist/commands/test.d.ts +0 -11
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/validate.d.ts +11 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/index.js +443 -317
- package/dist/logger.d.ts +2 -2
- package/dist/program.d.ts +2 -9
- package/dist/program.d.ts.map +1 -1
- package/dist/programBase.d.ts +5 -0
- package/dist/programBase.d.ts.map +1 -0
- package/dist/reporting.d.ts +24 -0
- package/dist/reporting.d.ts.map +1 -0
- package/dist/serviceSources.d.ts.map +1 -1
- package/dist/services/db.d.ts.map +1 -1
- package/dist/services/deps.d.ts +4 -24
- package/dist/services/deps.d.ts.map +1 -1
- package/dist/services/depsCache.d.ts +25 -0
- package/dist/services/depsCache.d.ts.map +1 -0
- package/dist/services/git.d.ts +5 -2
- package/dist/services/git.d.ts.map +1 -1
- package/dist/services/validation.d.ts +2 -1
- package/dist/services/validation.d.ts.map +1 -1
- package/dist/validatePython.d.ts +5 -5
- package/dist/validatePython.d.ts.map +1 -1
- package/dist/validateThemeCss.d.ts +4 -0
- package/dist/validateThemeCss.d.ts.map +1 -0
- package/dist/validators.d.ts +2 -2
- package/dist/validators.d.ts.map +1 -1
- package/dist/watch/ConflictResolver.d.ts +5 -4
- package/dist/watch/ConflictResolver.d.ts.map +1 -1
- package/dist/watch/FileWatcher.d.ts +3 -1
- package/dist/watch/FileWatcher.d.ts.map +1 -1
- package/dist/watch/SaveProcessor.d.ts +5 -2
- package/dist/watch/SaveProcessor.d.ts.map +1 -1
- package/dist/watch/SyncManager.d.ts +3 -1
- package/dist/watch/SyncManager.d.ts.map +1 -1
- package/dist/watch/WebSocketClient.d.ts +3 -0
- package/dist/watch/WebSocketClient.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -6705,6 +6705,10 @@ var __webpack_modules__ = {
|
|
|
6705
6705
|
"use strict";
|
|
6706
6706
|
module.exports = require("fs");
|
|
6707
6707
|
},
|
|
6708
|
+
ora (module) {
|
|
6709
|
+
"use strict";
|
|
6710
|
+
module.exports = require("ora");
|
|
6711
|
+
},
|
|
6708
6712
|
os (module) {
|
|
6709
6713
|
"use strict";
|
|
6710
6714
|
module.exports = require("os");
|
|
@@ -7516,20 +7520,20 @@ var __webpack_exports__ = {};
|
|
|
7516
7520
|
var anvil_api_namespaceObject = {};
|
|
7517
7521
|
__webpack_require__.r(anvil_api_namespaceObject);
|
|
7518
7522
|
__webpack_require__.d(anvil_api_namespaceObject, {
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7523
|
+
createAnvilApp: ()=>createAnvilApp,
|
|
7524
|
+
detectAppIdsByCommitLookup: ()=>anvil_api_detectAppIdsByCommitLookup,
|
|
7525
|
+
detectAppIdsFromAllRemotes: ()=>anvil_api_detectAppIdsFromAllRemotes,
|
|
7526
|
+
filterCandidates: ()=>anvil_api_filterCandidates,
|
|
7527
|
+
formatCandidateLabel: ()=>anvil_api_formatCandidateLabel,
|
|
7528
|
+
getGitFetchUrl: ()=>anvil_api_getGitFetchUrl,
|
|
7529
|
+
getGitPushUrl: ()=>anvil_api_getGitPushUrl,
|
|
7530
|
+
getLatestVersion: ()=>getLatestVersion,
|
|
7531
|
+
getWebSocketUrl: ()=>getWebSocketUrl,
|
|
7532
|
+
listAppsForCheckout: ()=>listAppsForCheckout,
|
|
7533
|
+
lookupByCommit: ()=>lookupByCommit,
|
|
7534
|
+
lookupRemoteInfoForAppId: ()=>anvil_api_lookupRemoteInfoForAppId,
|
|
7535
|
+
saveUpdates: ()=>saveUpdates,
|
|
7536
|
+
validateAppId: ()=>anvil_api_validateAppId
|
|
7533
7537
|
});
|
|
7534
7538
|
var validators_namespaceObject = {};
|
|
7535
7539
|
__webpack_require__.r(validators_namespaceObject);
|
|
@@ -7563,8 +7567,7 @@ var __webpack_exports__ = {};
|
|
|
7563
7567
|
KV: ()=>sanitizeDirectoryName,
|
|
7564
7568
|
Bc: ()=>validateCheckoutDestination
|
|
7565
7569
|
});
|
|
7566
|
-
const
|
|
7567
|
-
var external_chalk_default = /*#__PURE__*/ __webpack_require__.n(external_chalk_namespaceObject);
|
|
7570
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
7568
7571
|
const external_path_namespaceObject = require("path");
|
|
7569
7572
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
7570
7573
|
const external_node_buffer_namespaceObject = require("node:buffer");
|
|
@@ -11642,7 +11645,8 @@ var __webpack_exports__ = {};
|
|
|
11642
11645
|
return !!this.data.unique_ids[entityType]?.[name];
|
|
11643
11646
|
}
|
|
11644
11647
|
}
|
|
11645
|
-
const
|
|
11648
|
+
const external_chalk_namespaceObject = require("chalk");
|
|
11649
|
+
var external_chalk_default = /*#__PURE__*/ __webpack_require__.n(external_chalk_namespaceObject);
|
|
11646
11650
|
const external_node_process_namespaceObject = require("node:process");
|
|
11647
11651
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
11648
11652
|
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
@@ -12050,7 +12054,7 @@ var __webpack_exports__ = {};
|
|
|
12050
12054
|
}
|
|
12051
12055
|
const interceptor = new Interceptor();
|
|
12052
12056
|
const whenExit = interceptor.register;
|
|
12053
|
-
const
|
|
12057
|
+
const dist_node = whenExit;
|
|
12054
12058
|
const temp_Temp = {
|
|
12055
12059
|
store: {},
|
|
12056
12060
|
create: (filePath)=>{
|
|
@@ -12093,7 +12097,7 @@ var __webpack_exports__ = {};
|
|
|
12093
12097
|
return `${filePath.slice(0, -basename.length)}${truncable[1]}${truncable[2].slice(0, -truncationLength)}${truncable[3]}`;
|
|
12094
12098
|
}
|
|
12095
12099
|
};
|
|
12096
|
-
|
|
12100
|
+
dist_node(temp_Temp.purgeSyncAll);
|
|
12097
12101
|
const temp = temp_Temp;
|
|
12098
12102
|
function writeFileSync(filePath, data, options = constants_DEFAULT_WRITE_OPTIONS) {
|
|
12099
12103
|
if (lang_isString(options)) return writeFileSync(filePath, data, {
|
|
@@ -13614,6 +13618,18 @@ var __webpack_exports__ = {};
|
|
|
13614
13618
|
return "An unknown error occurred";
|
|
13615
13619
|
}
|
|
13616
13620
|
}
|
|
13621
|
+
const reporting_silentLogger = {
|
|
13622
|
+
debug () {},
|
|
13623
|
+
verbose () {},
|
|
13624
|
+
info () {},
|
|
13625
|
+
warn () {},
|
|
13626
|
+
error () {}
|
|
13627
|
+
};
|
|
13628
|
+
const silentProgress = {
|
|
13629
|
+
start () {},
|
|
13630
|
+
update () {},
|
|
13631
|
+
end () {}
|
|
13632
|
+
};
|
|
13617
13633
|
const external_module_namespaceObject = require("module");
|
|
13618
13634
|
const requireFromHere = (0, external_module_namespaceObject.createRequire)(__filename);
|
|
13619
13635
|
const GIT_CREDENTIAL_HELPER_FILENAME = "anvil-credential-helper.cjs";
|
|
@@ -14319,6 +14335,7 @@ Promise.resolve()
|
|
|
14319
14335
|
return WANT_NOT_VALID_RE.test(error.message || "");
|
|
14320
14336
|
}
|
|
14321
14337
|
class git_GitService extends Emitter {
|
|
14338
|
+
logger;
|
|
14322
14339
|
git;
|
|
14323
14340
|
repoPath;
|
|
14324
14341
|
static INDEX_LOCK_RETRY_DELAYS_MS = [
|
|
@@ -14327,8 +14344,10 @@ Promise.resolve()
|
|
|
14327
14344
|
100,
|
|
14328
14345
|
200
|
|
14329
14346
|
];
|
|
14330
|
-
constructor(repoPath){
|
|
14331
|
-
|
|
14347
|
+
constructor(repoPath, options = {}){
|
|
14348
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
14349
|
+
super((event, error)=>logger.error(`Error in event handler for '${event}': ${error}`));
|
|
14350
|
+
this.logger = logger;
|
|
14332
14351
|
this.repoPath = external_path_default().resolve(repoPath);
|
|
14333
14352
|
this.git = esm_default(this.repoPath);
|
|
14334
14353
|
}
|
|
@@ -14483,8 +14502,16 @@ Promise.resolve()
|
|
|
14483
14502
|
if ((511 & stat.mode) !== (511 & mode)) await external_fs_.promises.chmod(filePath, mode);
|
|
14484
14503
|
}
|
|
14485
14504
|
async hasUncommittedChanges() {
|
|
14486
|
-
|
|
14487
|
-
|
|
14505
|
+
try {
|
|
14506
|
+
const status = await this.git.raw([
|
|
14507
|
+
"--no-optional-locks",
|
|
14508
|
+
"status",
|
|
14509
|
+
"--porcelain"
|
|
14510
|
+
]);
|
|
14511
|
+
return status.trim().length > 0;
|
|
14512
|
+
} catch (e) {
|
|
14513
|
+
throw errors_createGitError.commandFailed("status", e.message);
|
|
14514
|
+
}
|
|
14488
14515
|
}
|
|
14489
14516
|
async fetch(url, refSpec) {
|
|
14490
14517
|
let attempt = 0;
|
|
@@ -14513,7 +14540,7 @@ Promise.resolve()
|
|
|
14513
14540
|
delayMs: FETCH_RETRY_DELAY_MS,
|
|
14514
14541
|
error: err.message
|
|
14515
14542
|
});
|
|
14516
|
-
|
|
14543
|
+
this.logger.verbose(`git fetch race (attempt ${attempt}, sleeping ${FETCH_RETRY_DELAY_MS}ms): ${err.message}`);
|
|
14517
14544
|
await (0, promises_namespaceObject.setTimeout)(FETCH_RETRY_DELAY_MS);
|
|
14518
14545
|
}
|
|
14519
14546
|
}
|
|
@@ -15070,6 +15097,29 @@ Promise.resolve()
|
|
|
15070
15097
|
}
|
|
15071
15098
|
const external_fs_promises_namespaceObject = require("fs/promises");
|
|
15072
15099
|
var external_fs_promises_default = /*#__PURE__*/ __webpack_require__.n(external_fs_promises_namespaceObject);
|
|
15100
|
+
function http_formatHttpError(prefix, status, body) {
|
|
15101
|
+
if (!body) return `${prefix}: ${status}`;
|
|
15102
|
+
try {
|
|
15103
|
+
const parsed = JSON.parse(body);
|
|
15104
|
+
if ("string" == typeof parsed.error && parsed.error.trim()) return `${prefix}: ${parsed.error} (${status})`;
|
|
15105
|
+
} catch {}
|
|
15106
|
+
return `${prefix}: ${status} ${body}`;
|
|
15107
|
+
}
|
|
15108
|
+
const ANVIL_GITIGNORE_ENTRY = "/.anvil/";
|
|
15109
|
+
async function ensureProjectGitignoreIgnoresAnvilDir(projectRoot) {
|
|
15110
|
+
const rootGitignorePath = external_path_default().join(projectRoot, ".gitignore");
|
|
15111
|
+
try {
|
|
15112
|
+
const existing = await external_fs_.promises.readFile(rootGitignorePath, "utf8");
|
|
15113
|
+
if (existing.includes(ANVIL_GITIGNORE_ENTRY)) return false;
|
|
15114
|
+
const prefix = existing.endsWith("\n") || 0 === existing.length ? "" : "\n";
|
|
15115
|
+
await external_fs_.promises.writeFile(rootGitignorePath, `${existing}${prefix}${ANVIL_GITIGNORE_ENTRY}\n`, "utf8");
|
|
15116
|
+
return true;
|
|
15117
|
+
} catch (error) {
|
|
15118
|
+
if ("ENOENT" !== error.code) throw error;
|
|
15119
|
+
await external_fs_.promises.writeFile(rootGitignorePath, `${ANVIL_GITIGNORE_ENTRY}\n`, "utf8");
|
|
15120
|
+
return true;
|
|
15121
|
+
}
|
|
15122
|
+
}
|
|
15073
15123
|
function normalizeLineEndings(content) {
|
|
15074
15124
|
return content.replace(/\r\n/g, "\n");
|
|
15075
15125
|
}
|
|
@@ -15114,32 +15164,67 @@ Promise.resolve()
|
|
|
15114
15164
|
html: htmlContent
|
|
15115
15165
|
};
|
|
15116
15166
|
}
|
|
15117
|
-
|
|
15118
|
-
|
|
15167
|
+
const ANVIL_DEPS_DIR = ".anvil/deps";
|
|
15168
|
+
const ANVIL_DEPS_MANIFEST = "manifest.json";
|
|
15169
|
+
const DEPS_MANIFEST_VERSION = 3;
|
|
15170
|
+
function depsCache_depsDir(projectRoot) {
|
|
15171
|
+
return external_path_default().join(projectRoot, ANVIL_DEPS_DIR);
|
|
15172
|
+
}
|
|
15173
|
+
function depsManifestPath(projectRoot) {
|
|
15174
|
+
return external_path_default().join(depsCache_depsDir(projectRoot), ANVIL_DEPS_MANIFEST);
|
|
15175
|
+
}
|
|
15176
|
+
function isResolvedDependencyManifestEntry(value) {
|
|
15177
|
+
if (!value || "object" != typeof value) return false;
|
|
15178
|
+
const entry = value;
|
|
15179
|
+
return "string" == typeof entry.app_id && entry.app_id.length > 0 && "string" == typeof entry.commit_id && entry.commit_id.length > 0 && (void 0 === entry.branch || "string" == typeof entry.branch);
|
|
15180
|
+
}
|
|
15181
|
+
function isCachedDependencyManifestEntry(value) {
|
|
15182
|
+
if (!isResolvedDependencyManifestEntry(value)) return false;
|
|
15183
|
+
const entry = value;
|
|
15184
|
+
return "string" == typeof entry.package_name && entry.package_name.length > 0;
|
|
15185
|
+
}
|
|
15186
|
+
function isDepsCacheManifest(value) {
|
|
15187
|
+
if (!value || "object" != typeof value) return false;
|
|
15188
|
+
const manifest = value;
|
|
15189
|
+
return manifest.version === DEPS_MANIFEST_VERSION && "boolean" == typeof manifest.includeDocs && (null === manifest.source_dependencies || Array.isArray(manifest.source_dependencies)) && Array.isArray(manifest.resolved_dependencies) && manifest.resolved_dependencies.every(isResolvedDependencyManifestEntry) && Array.isArray(manifest.cached_dependencies) && manifest.cached_dependencies.every(isCachedDependencyManifestEntry);
|
|
15190
|
+
}
|
|
15191
|
+
async function readDepsCacheManifest(projectRoot) {
|
|
15119
15192
|
try {
|
|
15120
|
-
const
|
|
15121
|
-
|
|
15122
|
-
|
|
15123
|
-
|
|
15193
|
+
const raw = await external_fs_promises_default().readFile(depsManifestPath(projectRoot), "utf-8");
|
|
15194
|
+
const parsed = JSON.parse(raw);
|
|
15195
|
+
return isDepsCacheManifest(parsed) ? parsed : void 0;
|
|
15196
|
+
} catch {
|
|
15197
|
+
return;
|
|
15198
|
+
}
|
|
15124
15199
|
}
|
|
15125
|
-
|
|
15126
|
-
|
|
15127
|
-
|
|
15200
|
+
function normalizeAnvilYamlDependenciesFromContent(content) {
|
|
15201
|
+
const parsed = external_js_yaml_default().load(content);
|
|
15202
|
+
if (!parsed || "object" != typeof parsed || !Array.isArray(parsed.dependencies)) return [];
|
|
15203
|
+
return normalizeAnvilYamlDependenciesValue(parsed.dependencies);
|
|
15204
|
+
}
|
|
15205
|
+
function normalizeAnvilYamlDependenciesValue(value) {
|
|
15206
|
+
if (!Array.isArray(value)) return [];
|
|
15207
|
+
return value.map(normalizeForComparison);
|
|
15208
|
+
}
|
|
15209
|
+
async function readAnvilYamlDependencies(projectRoot) {
|
|
15128
15210
|
try {
|
|
15129
|
-
const
|
|
15130
|
-
|
|
15131
|
-
|
|
15132
|
-
|
|
15133
|
-
return true;
|
|
15134
|
-
} catch (error) {
|
|
15135
|
-
if ("ENOENT" !== error.code) throw error;
|
|
15136
|
-
await external_fs_.promises.writeFile(rootGitignorePath, `${ANVIL_GITIGNORE_ENTRY}\n`, "utf8");
|
|
15137
|
-
return true;
|
|
15211
|
+
const content = await external_fs_promises_default().readFile(external_path_default().join(projectRoot, "anvil.yaml"), "utf-8");
|
|
15212
|
+
return normalizeAnvilYamlDependenciesFromContent(content);
|
|
15213
|
+
} catch {
|
|
15214
|
+
return [];
|
|
15138
15215
|
}
|
|
15139
15216
|
}
|
|
15140
|
-
|
|
15141
|
-
|
|
15142
|
-
|
|
15217
|
+
function anvilYamlDependenciesEqual(left, right) {
|
|
15218
|
+
return deepEqual(left, right);
|
|
15219
|
+
}
|
|
15220
|
+
function normalizeForComparison(value) {
|
|
15221
|
+
if (Array.isArray(value)) return value.map(normalizeForComparison);
|
|
15222
|
+
if (value && "object" == typeof value) return Object.fromEntries(Object.entries(value).sort(([left], [right])=>left.localeCompare(right)).map(([key, entryValue])=>[
|
|
15223
|
+
key,
|
|
15224
|
+
normalizeForComparison(entryValue)
|
|
15225
|
+
]));
|
|
15226
|
+
return value;
|
|
15227
|
+
}
|
|
15143
15228
|
async function fetchAllDependencies(appId, anvilUrl, options = {}) {
|
|
15144
15229
|
const { commit, includeDocs = true, knownDependencies = [] } = options;
|
|
15145
15230
|
anvilUrl ??= await auth_resolveAuthAnvilUrl();
|
|
@@ -15167,7 +15252,9 @@ Promise.resolve()
|
|
|
15167
15252
|
auth_setRepoContext(projectRoot);
|
|
15168
15253
|
anvilUrl ??= await auth_resolveAuthAnvilUrl();
|
|
15169
15254
|
const includeDocs = options.includeDocs ?? true;
|
|
15170
|
-
const git = new git_GitService(projectRoot
|
|
15255
|
+
const git = new git_GitService(projectRoot, {
|
|
15256
|
+
logger: options.logger
|
|
15257
|
+
});
|
|
15171
15258
|
const commit = options.commit ?? await git.getCommitId();
|
|
15172
15259
|
const sourceYaml = await git.show(`${commit}:anvil.yaml`).catch((error)=>{
|
|
15173
15260
|
if (options.commit) return null;
|
|
@@ -15198,36 +15285,6 @@ Promise.resolve()
|
|
|
15198
15285
|
addedGitignoreEntry
|
|
15199
15286
|
};
|
|
15200
15287
|
}
|
|
15201
|
-
function depsDir(projectRoot) {
|
|
15202
|
-
return external_path_default().join(projectRoot, ANVIL_DEPS_DIR);
|
|
15203
|
-
}
|
|
15204
|
-
function depsManifestPath(projectRoot) {
|
|
15205
|
-
return external_path_default().join(depsDir(projectRoot), ANVIL_DEPS_MANIFEST);
|
|
15206
|
-
}
|
|
15207
|
-
function isResolvedDependencyManifestEntry(value) {
|
|
15208
|
-
if (!value || "object" != typeof value) return false;
|
|
15209
|
-
const entry = value;
|
|
15210
|
-
return "string" == typeof entry.app_id && entry.app_id.length > 0 && "string" == typeof entry.commit_id && entry.commit_id.length > 0 && (void 0 === entry.branch || "string" == typeof entry.branch);
|
|
15211
|
-
}
|
|
15212
|
-
function isCachedDependencyManifestEntry(value) {
|
|
15213
|
-
if (!isResolvedDependencyManifestEntry(value)) return false;
|
|
15214
|
-
const entry = value;
|
|
15215
|
-
return "string" == typeof entry.package_name && entry.package_name.length > 0;
|
|
15216
|
-
}
|
|
15217
|
-
function isDepsCacheManifest(value) {
|
|
15218
|
-
if (!value || "object" != typeof value) return false;
|
|
15219
|
-
const manifest = value;
|
|
15220
|
-
return manifest.version === DEPS_MANIFEST_VERSION && "boolean" == typeof manifest.includeDocs && (null === manifest.source_dependencies || Array.isArray(manifest.source_dependencies)) && Array.isArray(manifest.resolved_dependencies) && manifest.resolved_dependencies.every(isResolvedDependencyManifestEntry) && Array.isArray(manifest.cached_dependencies) && manifest.cached_dependencies.every(isCachedDependencyManifestEntry);
|
|
15221
|
-
}
|
|
15222
|
-
async function readDepsCacheManifest(projectRoot) {
|
|
15223
|
-
try {
|
|
15224
|
-
const raw = await external_fs_promises_default().readFile(depsManifestPath(projectRoot), "utf-8");
|
|
15225
|
-
const parsed = JSON.parse(raw);
|
|
15226
|
-
return isDepsCacheManifest(parsed) ? parsed : void 0;
|
|
15227
|
-
} catch {
|
|
15228
|
-
return;
|
|
15229
|
-
}
|
|
15230
|
-
}
|
|
15231
15288
|
async function getKnownDependenciesForCache(projectRoot, includeDocs) {
|
|
15232
15289
|
const manifest = await readDepsCacheManifest(projectRoot);
|
|
15233
15290
|
if (!manifest || manifest.includeDocs !== includeDocs) return [];
|
|
@@ -15253,34 +15310,6 @@ Promise.resolve()
|
|
|
15253
15310
|
];
|
|
15254
15311
|
});
|
|
15255
15312
|
}
|
|
15256
|
-
function normalizeAnvilYamlDependenciesFromContent(content) {
|
|
15257
|
-
const parsed = external_js_yaml_default().load(content);
|
|
15258
|
-
if (!parsed || "object" != typeof parsed || !Array.isArray(parsed.dependencies)) return [];
|
|
15259
|
-
return normalizeAnvilYamlDependenciesValue(parsed.dependencies);
|
|
15260
|
-
}
|
|
15261
|
-
function normalizeAnvilYamlDependenciesValue(value) {
|
|
15262
|
-
if (!Array.isArray(value)) return [];
|
|
15263
|
-
return value.map(normalizeForComparison);
|
|
15264
|
-
}
|
|
15265
|
-
async function readAnvilYamlDependencies(projectRoot) {
|
|
15266
|
-
try {
|
|
15267
|
-
const content = await external_fs_promises_default().readFile(external_path_default().join(projectRoot, "anvil.yaml"), "utf-8");
|
|
15268
|
-
return normalizeAnvilYamlDependenciesFromContent(content);
|
|
15269
|
-
} catch {
|
|
15270
|
-
return [];
|
|
15271
|
-
}
|
|
15272
|
-
}
|
|
15273
|
-
function anvilYamlDependenciesEqual(left, right) {
|
|
15274
|
-
return deepEqual(left, right);
|
|
15275
|
-
}
|
|
15276
|
-
function normalizeForComparison(value) {
|
|
15277
|
-
if (Array.isArray(value)) return value.map(normalizeForComparison);
|
|
15278
|
-
if (value && "object" == typeof value) return Object.fromEntries(Object.entries(value).sort(([left], [right])=>left.localeCompare(right)).map(([key, entryValue])=>[
|
|
15279
|
-
key,
|
|
15280
|
-
normalizeForComparison(entryValue)
|
|
15281
|
-
]));
|
|
15282
|
-
return value;
|
|
15283
|
-
}
|
|
15284
15313
|
function cachedManifestEntry(dep, packageName) {
|
|
15285
15314
|
return {
|
|
15286
15315
|
app_id: dep.app_id,
|
|
@@ -15302,7 +15331,7 @@ Promise.resolve()
|
|
|
15302
15331
|
return external_path_default().join(...parts);
|
|
15303
15332
|
}
|
|
15304
15333
|
async function writeDepToCache(projectRoot, dep) {
|
|
15305
|
-
const depDir = external_path_default().join(projectRoot,
|
|
15334
|
+
const depDir = external_path_default().join(depsCache_depsDir(projectRoot), dep.package_name);
|
|
15306
15335
|
await external_fs_promises_default().rm(depDir, {
|
|
15307
15336
|
recursive: true,
|
|
15308
15337
|
force: true
|
|
@@ -15386,7 +15415,7 @@ Promise.resolve()
|
|
|
15386
15415
|
if (!canReuseExistingCache) await clearDepsCache(projectRoot);
|
|
15387
15416
|
const previousCached = canReuseExistingCache ? manifest.cached_dependencies : [];
|
|
15388
15417
|
const resolvedAppIds = new Set(response.resolved_dependencies.map((dep)=>dep.app_id));
|
|
15389
|
-
for (const dep of previousCached)if (!resolvedAppIds.has(dep.app_id)) await external_fs_promises_default().rm(external_path_default().join(projectRoot,
|
|
15418
|
+
for (const dep of previousCached)if (!resolvedAppIds.has(dep.app_id)) await external_fs_promises_default().rm(external_path_default().join(depsCache_depsDir(projectRoot), dep.package_name), {
|
|
15390
15419
|
recursive: true,
|
|
15391
15420
|
force: true
|
|
15392
15421
|
});
|
|
@@ -15413,13 +15442,13 @@ Promise.resolve()
|
|
|
15413
15442
|
resolved_dependencies: response.resolved_dependencies,
|
|
15414
15443
|
cached_dependencies: cachedDependencies
|
|
15415
15444
|
};
|
|
15416
|
-
await external_fs_promises_default().mkdir(
|
|
15445
|
+
await external_fs_promises_default().mkdir(depsCache_depsDir(projectRoot), {
|
|
15417
15446
|
recursive: true
|
|
15418
15447
|
});
|
|
15419
15448
|
await external_fs_promises_default().writeFile(depsManifestPath(projectRoot), `${JSON.stringify(newManifest, null, 2)}\n`);
|
|
15420
15449
|
}
|
|
15421
15450
|
async function clearDepsCache(projectRoot) {
|
|
15422
|
-
await external_fs_promises_default().rm(
|
|
15451
|
+
await external_fs_promises_default().rm(depsCache_depsDir(projectRoot), {
|
|
15423
15452
|
recursive: true,
|
|
15424
15453
|
force: true
|
|
15425
15454
|
});
|
|
@@ -15427,6 +15456,7 @@ Promise.resolve()
|
|
|
15427
15456
|
const external_chokidar_namespaceObject = require("chokidar");
|
|
15428
15457
|
var external_chokidar_default = /*#__PURE__*/ __webpack_require__.n(external_chokidar_namespaceObject);
|
|
15429
15458
|
class FileWatcher extends Emitter {
|
|
15459
|
+
logger;
|
|
15430
15460
|
repoPath;
|
|
15431
15461
|
gitDir;
|
|
15432
15462
|
stagedOnly;
|
|
@@ -15436,7 +15466,9 @@ Promise.resolve()
|
|
|
15436
15466
|
currentBranch = "";
|
|
15437
15467
|
sessionId;
|
|
15438
15468
|
constructor(options){
|
|
15439
|
-
|
|
15469
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
15470
|
+
super((event, error)=>logger.error(`Error in event handler for '${event}': ${error}`));
|
|
15471
|
+
this.logger = logger;
|
|
15440
15472
|
this.repoPath = external_path_default().resolve(options.repoPath);
|
|
15441
15473
|
this.gitDir = options.gitDir;
|
|
15442
15474
|
this.stagedOnly = options.stagedOnly ?? false;
|
|
@@ -15445,14 +15477,14 @@ Promise.resolve()
|
|
|
15445
15477
|
}
|
|
15446
15478
|
async start(currentBranch) {
|
|
15447
15479
|
this.currentBranch = currentBranch;
|
|
15448
|
-
|
|
15480
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, "Starting watchers..."));
|
|
15449
15481
|
this.startHeadWatcher();
|
|
15450
15482
|
if (this.stagedOnly) this.startIndexWatcher();
|
|
15451
15483
|
else this.startFileWatcher();
|
|
15452
15484
|
}
|
|
15453
15485
|
startHeadWatcher() {
|
|
15454
15486
|
const headPath = external_path_default().join(this.gitDir, "HEAD");
|
|
15455
|
-
|
|
15487
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, `Setting up HEAD watcher: ${headPath}`));
|
|
15456
15488
|
this.headWatcher = external_chokidar_default().watch(headPath, {
|
|
15457
15489
|
persistent: true,
|
|
15458
15490
|
ignoreInitial: true,
|
|
@@ -15465,13 +15497,13 @@ Promise.resolve()
|
|
|
15465
15497
|
if (newBranch !== this.currentBranch) {
|
|
15466
15498
|
const oldBranch = this.currentBranch;
|
|
15467
15499
|
this.currentBranch = newBranch;
|
|
15468
|
-
|
|
15500
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, `Branch changed: ${oldBranch} -> ${newBranch}`));
|
|
15469
15501
|
this.emit("branch-change", {
|
|
15470
15502
|
newBranch
|
|
15471
15503
|
});
|
|
15472
15504
|
}
|
|
15473
15505
|
} catch (error) {
|
|
15474
|
-
|
|
15506
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, `Error getting current branch: ${error.message}`));
|
|
15475
15507
|
}
|
|
15476
15508
|
});
|
|
15477
15509
|
this.headWatcher.on("error", (err)=>{
|
|
@@ -15483,9 +15515,9 @@ Promise.resolve()
|
|
|
15483
15515
|
}
|
|
15484
15516
|
startIndexWatcher() {
|
|
15485
15517
|
const indexPath = external_path_default().join(this.gitDir, "index");
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
if (!external_fs_.existsSync(indexPath)) return void
|
|
15518
|
+
this.logger.verbose(`Setting up watcher for: ${indexPath}`);
|
|
15519
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, `Setting up index watcher (staged-only mode): ${indexPath}`));
|
|
15520
|
+
if (!external_fs_.existsSync(indexPath)) return void this.logger.error(`ERROR: Git index file not found at ${indexPath}`);
|
|
15489
15521
|
this.fileWatcher = external_chokidar_default().watch(indexPath, {
|
|
15490
15522
|
persistent: true,
|
|
15491
15523
|
ignoreInitial: true,
|
|
@@ -15493,23 +15525,23 @@ Promise.resolve()
|
|
|
15493
15525
|
interval: 100
|
|
15494
15526
|
});
|
|
15495
15527
|
this.fileWatcher.on("ready", ()=>{
|
|
15496
|
-
|
|
15528
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, "Staged-only watcher ready"));
|
|
15497
15529
|
});
|
|
15498
15530
|
this.fileWatcher.on("change", async ()=>{
|
|
15499
|
-
|
|
15531
|
+
this.logger.verbose("Git index changed (staging event detected)");
|
|
15500
15532
|
this.emit("index-change", void 0);
|
|
15501
15533
|
});
|
|
15502
15534
|
this.fileWatcher.on("error", (err)=>{
|
|
15503
15535
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
15504
|
-
|
|
15536
|
+
this.logger.error(`Watcher error: ${error}`);
|
|
15505
15537
|
this.emit("error", {
|
|
15506
15538
|
error
|
|
15507
15539
|
});
|
|
15508
15540
|
});
|
|
15509
|
-
|
|
15541
|
+
this.logger.info("Watching for staged changes. Press Ctrl-C to exit.");
|
|
15510
15542
|
}
|
|
15511
15543
|
startFileWatcher() {
|
|
15512
|
-
|
|
15544
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, `Setting up file watcher (normal mode): ${this.repoPath}`));
|
|
15513
15545
|
this.fileWatcher = external_chokidar_default().watch(this.repoPath, {
|
|
15514
15546
|
ignored: [
|
|
15515
15547
|
/(^|[\/\\])\../,
|
|
@@ -15534,12 +15566,12 @@ Promise.resolve()
|
|
|
15534
15566
|
});
|
|
15535
15567
|
this.fileWatcher.on("error", (err)=>{
|
|
15536
15568
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
15537
|
-
|
|
15569
|
+
this.logger.error(`Watcher error: ${error}`);
|
|
15538
15570
|
this.emit("error", {
|
|
15539
15571
|
error
|
|
15540
15572
|
});
|
|
15541
15573
|
});
|
|
15542
|
-
|
|
15574
|
+
this.logger.info("Watching for changes. Press Ctrl-C to exit.");
|
|
15543
15575
|
}
|
|
15544
15576
|
getCurrentWatchedBranch() {
|
|
15545
15577
|
return this.currentBranch;
|
|
@@ -15548,23 +15580,24 @@ Promise.resolve()
|
|
|
15548
15580
|
this.currentBranch = branch;
|
|
15549
15581
|
}
|
|
15550
15582
|
cleanup() {
|
|
15551
|
-
|
|
15583
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, "Cleaning up watchers..."));
|
|
15552
15584
|
if (this.headWatcher) {
|
|
15553
|
-
|
|
15585
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, "Closing HEAD watcher"));
|
|
15554
15586
|
this.headWatcher.close();
|
|
15555
15587
|
this.headWatcher = null;
|
|
15556
15588
|
}
|
|
15557
15589
|
if (this.fileWatcher) {
|
|
15558
|
-
|
|
15590
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, "Closing file watcher"));
|
|
15559
15591
|
this.fileWatcher.close();
|
|
15560
15592
|
this.fileWatcher = null;
|
|
15561
15593
|
}
|
|
15562
|
-
|
|
15594
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[FileWatcher ${this.sessionId}]`, "Watcher cleanup complete"));
|
|
15563
15595
|
}
|
|
15564
15596
|
}
|
|
15565
15597
|
const external_ws_namespaceObject = require("ws");
|
|
15566
15598
|
var external_ws_default = /*#__PURE__*/ __webpack_require__.n(external_ws_namespaceObject);
|
|
15567
15599
|
class WebSocketClient extends Emitter {
|
|
15600
|
+
logger;
|
|
15568
15601
|
ws = null;
|
|
15569
15602
|
appId;
|
|
15570
15603
|
anvilUrl;
|
|
@@ -15593,7 +15626,9 @@ Promise.resolve()
|
|
|
15593
15626
|
HEARTBEAT_INTERVAL_MS = 30000;
|
|
15594
15627
|
HEARTBEAT_TIMEOUT_MS = 10000;
|
|
15595
15628
|
constructor(options){
|
|
15596
|
-
|
|
15629
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
15630
|
+
super((event, error)=>logger.error(`Error in event handler for '${event}': ${error}`));
|
|
15631
|
+
this.logger = logger;
|
|
15597
15632
|
this.appId = options.appId;
|
|
15598
15633
|
this.anvilUrl = options.anvilUrl;
|
|
15599
15634
|
this.authToken = options.authToken;
|
|
@@ -15609,24 +15644,24 @@ Promise.resolve()
|
|
|
15609
15644
|
async connect() {
|
|
15610
15645
|
this.isClosing = false;
|
|
15611
15646
|
this.connectAttempts++;
|
|
15612
|
-
if (this.ws?.readyState === external_ws_default().OPEN) return void
|
|
15647
|
+
if (this.ws?.readyState === external_ws_default().OPEN) return void this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, "WebSocket already open, skipping connection"));
|
|
15613
15648
|
if (this.ws) {
|
|
15614
|
-
|
|
15649
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, "Closing existing WebSocket before reconnecting"));
|
|
15615
15650
|
this.teardownSocket();
|
|
15616
15651
|
}
|
|
15617
15652
|
this.authToken = await auth_getValidAuthToken(this.anvilUrl, this.username);
|
|
15618
15653
|
const wsUrl = getWebSocketUrl(this.appId, this.authToken, this.anvilUrl);
|
|
15619
|
-
|
|
15620
|
-
|
|
15654
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, `Connecting to: ${wsUrl.replace(this.authToken, "[TOKEN]")}`));
|
|
15655
|
+
this.logger.verbose(`WebSocket connecting to ${this.getConnectionTarget(wsUrl)} (app ${this.appId}, branch ${this.currentBranch}, session ${this.sessionId}, connect attempt ${this.connectAttempts})`);
|
|
15621
15656
|
this.ws = new (external_ws_default())(wsUrl);
|
|
15622
15657
|
this.ws.on("open", ()=>{
|
|
15623
|
-
|
|
15624
|
-
|
|
15658
|
+
this.logger.verbose("🔌 Connected to Anvil WebSocket");
|
|
15659
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, "WebSocket opened"));
|
|
15625
15660
|
this.reconnectAttempts = 0;
|
|
15626
15661
|
this.reconnectDelayMs = this.RECONNECT_DELAY_BASE_MS;
|
|
15627
15662
|
this.startHeartbeat();
|
|
15628
15663
|
const subscribeMsg = this.buildSubscribeMessage(this.currentBranch);
|
|
15629
|
-
|
|
15664
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, `Subscribing: ${JSON.stringify(subscribeMsg)}`));
|
|
15630
15665
|
this.ws?.send(JSON.stringify(subscribeMsg));
|
|
15631
15666
|
this.watchedPrimaryBranch = this.currentBranch;
|
|
15632
15667
|
this.activeDependencySubscriptions.clear();
|
|
@@ -15636,7 +15671,7 @@ Promise.resolve()
|
|
|
15636
15671
|
this.ws.on("unexpected-response", (request, response)=>{
|
|
15637
15672
|
const summary = this.summarizeUnexpectedResponse(response, wsUrl);
|
|
15638
15673
|
this.lastDisconnectSummary = summary;
|
|
15639
|
-
|
|
15674
|
+
this.logger.error(summary);
|
|
15640
15675
|
response.resume();
|
|
15641
15676
|
request.destroy();
|
|
15642
15677
|
if (this.isClosing) return;
|
|
@@ -15652,23 +15687,23 @@ Promise.resolve()
|
|
|
15652
15687
|
this.markSocketResponsive();
|
|
15653
15688
|
try {
|
|
15654
15689
|
const msg = JSON.parse(data.toString());
|
|
15655
|
-
|
|
15690
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, `Message: ${JSON.stringify(msg)}`));
|
|
15656
15691
|
this.handleDependencySubscriptionReply(msg);
|
|
15657
15692
|
this.handleMessage(msg);
|
|
15658
15693
|
} catch (error) {
|
|
15659
|
-
|
|
15694
|
+
this.logger.error(`Failed to parse WebSocket message: ${error.message}`);
|
|
15660
15695
|
}
|
|
15661
15696
|
});
|
|
15662
15697
|
this.ws.on("pong", ()=>{
|
|
15663
15698
|
this.markSocketResponsive();
|
|
15664
15699
|
});
|
|
15665
15700
|
this.ws.on("close", (code, reason)=>{
|
|
15666
|
-
|
|
15701
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, `Closed: code=${code}, reason=${reason.toString()}`));
|
|
15667
15702
|
this.stopHeartbeat();
|
|
15668
15703
|
this.ws = null;
|
|
15669
15704
|
if (1008 === code || reason.toString().includes("unauthenticated")) {
|
|
15670
|
-
|
|
15671
|
-
|
|
15705
|
+
this.logger.warn(" WebSocket authentication failed - changes from the Anvil Editor won't be detected");
|
|
15706
|
+
this.logger.verbose(" Local changes will still sync to Anvil, but editor changes won't appear locally");
|
|
15672
15707
|
this.emit("auth-failed", void 0);
|
|
15673
15708
|
return;
|
|
15674
15709
|
}
|
|
@@ -15681,13 +15716,13 @@ Promise.resolve()
|
|
|
15681
15716
|
this.scheduleReconnect();
|
|
15682
15717
|
});
|
|
15683
15718
|
this.ws.on("error", (error)=>{
|
|
15684
|
-
|
|
15719
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, `Error: ${error.message}`));
|
|
15685
15720
|
if (this.isClosing) return;
|
|
15686
15721
|
if (error.message.includes("Unexpected server response")) return;
|
|
15687
|
-
if (error.message.includes("502"))
|
|
15722
|
+
if (error.message.includes("502")) this.logger.error(`WebSocket connection failed (502 Bad Gateway) - the server could not open the live update connection (${this.getConnectionContext()})`);
|
|
15688
15723
|
else {
|
|
15689
15724
|
const details = this.getConnectionContext();
|
|
15690
|
-
|
|
15725
|
+
this.logger.error(`WebSocket error: ${error.message} (${details})`);
|
|
15691
15726
|
}
|
|
15692
15727
|
this.lastDisconnectSummary = `WebSocket error: ${error.message}`;
|
|
15693
15728
|
this.emit("error", {
|
|
@@ -15701,7 +15736,7 @@ Promise.resolve()
|
|
|
15701
15736
|
});
|
|
15702
15737
|
if ("REPO_UPDATE" === msg.event) {
|
|
15703
15738
|
const { ref_update, commit } = msg;
|
|
15704
|
-
if (!ref_update) return void
|
|
15739
|
+
if (!ref_update) return void this.logger.debug("Ignoring REPO_UPDATE with no ref_update");
|
|
15705
15740
|
const { ref } = ref_update;
|
|
15706
15741
|
const commitHash = "string" == typeof commit ? commit : commit?.v;
|
|
15707
15742
|
const appId = this.getMessageAppId(msg);
|
|
@@ -15712,7 +15747,7 @@ Promise.resolve()
|
|
|
15712
15747
|
saveSeq: ref_update?.["save-seq"]
|
|
15713
15748
|
});
|
|
15714
15749
|
} else if ("REPO_INVALIDATE" === msg.event) {
|
|
15715
|
-
|
|
15750
|
+
this.logger.warn(" Repository invalidated, refreshing...");
|
|
15716
15751
|
this.emit("repo-invalidate", void 0);
|
|
15717
15752
|
} else if ("ENV_UPDATE" === msg.event) this.emit("env-update", normalizeEnvironmentBinding(msg));
|
|
15718
15753
|
}
|
|
@@ -15747,7 +15782,7 @@ Promise.resolve()
|
|
|
15747
15782
|
close() {
|
|
15748
15783
|
this.isClosing = true;
|
|
15749
15784
|
if (this.reconnectTimer) {
|
|
15750
|
-
|
|
15785
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, "Clearing reconnect timer"));
|
|
15751
15786
|
clearTimeout(this.reconnectTimer);
|
|
15752
15787
|
this.reconnectTimer = null;
|
|
15753
15788
|
}
|
|
@@ -15775,7 +15810,7 @@ Promise.resolve()
|
|
|
15775
15810
|
if (this.reconnectTimer || this.isClosing) return;
|
|
15776
15811
|
this.reconnectAttempts++;
|
|
15777
15812
|
const delayMs = this.reconnectDelayMs;
|
|
15778
|
-
|
|
15813
|
+
this.logger.verbose(`WebSocket disconnected (${this.lastDisconnectSummary ?? "unknown cause"}), reconnecting in ${Math.round(delayMs / 1000)}s (${this.getConnectionContext()}, next connect attempt ${this.connectAttempts + 1})...`);
|
|
15779
15814
|
this.reconnectTimer = setTimeout(()=>{
|
|
15780
15815
|
this.reconnectTimer = null;
|
|
15781
15816
|
this.connect().catch((error)=>{
|
|
@@ -15819,8 +15854,8 @@ Promise.resolve()
|
|
|
15819
15854
|
app: subscription.appId,
|
|
15820
15855
|
only_branch: subscription.branch
|
|
15821
15856
|
};
|
|
15822
|
-
|
|
15823
|
-
|
|
15857
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, `Subscribing dependency: ${JSON.stringify(subscribeMsg)}`));
|
|
15858
|
+
this.logger.verbose(`Watching dependency ${subscription.packageName ?? subscription.appId} (${subscription.appId}, branch ${subscription.branch})`);
|
|
15824
15859
|
this.ws.send(JSON.stringify(subscribeMsg));
|
|
15825
15860
|
}
|
|
15826
15861
|
}
|
|
@@ -15831,7 +15866,7 @@ Promise.resolve()
|
|
|
15831
15866
|
this.pendingDependencySubscriptionById.delete(msg.id);
|
|
15832
15867
|
if (!msg.error) return;
|
|
15833
15868
|
this.activeDependencySubscriptions.delete(this.dependencySubscriptionKey(subscription));
|
|
15834
|
-
|
|
15869
|
+
this.logger.warn(`Could not watch dependency ${subscription.packageName ?? subscription.appId} (${subscription.appId}, branch ${subscription.branch}): ${this.formatDependencySubscriptionError(msg.error)}`);
|
|
15835
15870
|
}
|
|
15836
15871
|
formatDependencySubscriptionError(error) {
|
|
15837
15872
|
if ("string" == typeof error) return error;
|
|
@@ -15860,7 +15895,7 @@ Promise.resolve()
|
|
|
15860
15895
|
const unwatchedAppIds = new Set();
|
|
15861
15896
|
for (const subscription of subscriptions)if (!unwatchedAppIds.has(subscription.appId)) {
|
|
15862
15897
|
unwatchedAppIds.add(subscription.appId);
|
|
15863
|
-
|
|
15898
|
+
this.logger.verbose(`Stopped watching dependency ${subscription.packageName ?? subscription.appId} (${subscription.appId})`);
|
|
15864
15899
|
this.ws.send(JSON.stringify(this.buildUnsubscribeMessage(subscription.appId)));
|
|
15865
15900
|
}
|
|
15866
15901
|
for (const subscription of subscriptions)this.activeDependencySubscriptions.delete(this.dependencySubscriptionKey(subscription));
|
|
@@ -15911,12 +15946,12 @@ Promise.resolve()
|
|
|
15911
15946
|
try {
|
|
15912
15947
|
ws.ping();
|
|
15913
15948
|
} catch (error) {
|
|
15914
|
-
|
|
15949
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, `Failed to send ping: ${error.message}`));
|
|
15915
15950
|
ws.terminate();
|
|
15916
15951
|
return;
|
|
15917
15952
|
}
|
|
15918
15953
|
this.pongTimeoutTimer = setTimeout(()=>{
|
|
15919
|
-
|
|
15954
|
+
this.logger.warn(" WebSocket heartbeat timed out - reconnecting");
|
|
15920
15955
|
ws.terminate();
|
|
15921
15956
|
}, this.HEARTBEAT_TIMEOUT_MS);
|
|
15922
15957
|
}, this.HEARTBEAT_INTERVAL_MS);
|
|
@@ -15943,7 +15978,7 @@ Promise.resolve()
|
|
|
15943
15978
|
this.ws = null;
|
|
15944
15979
|
if (!socket) return;
|
|
15945
15980
|
try {
|
|
15946
|
-
|
|
15981
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, "Closing WebSocket"));
|
|
15947
15982
|
if (socket.readyState === external_ws_default().CONNECTING) {
|
|
15948
15983
|
socket.once("error", ()=>{});
|
|
15949
15984
|
socket.terminate();
|
|
@@ -15951,7 +15986,7 @@ Promise.resolve()
|
|
|
15951
15986
|
}
|
|
15952
15987
|
if (socket.readyState === external_ws_default().OPEN) return void socket.close();
|
|
15953
15988
|
} catch (e) {
|
|
15954
|
-
|
|
15989
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[WebSocket ${this.sessionId}]`, "Error closing WebSocket (ignoring):", e));
|
|
15955
15990
|
}
|
|
15956
15991
|
}
|
|
15957
15992
|
dependencySubscriptionKey(subscription) {
|
|
@@ -15977,12 +16012,13 @@ Promise.resolve()
|
|
|
15977
16012
|
}
|
|
15978
16013
|
return deduped;
|
|
15979
16014
|
}
|
|
15980
|
-
async function detectRemoteChanges(gitService, oldCommitId, newCommitId) {
|
|
16015
|
+
async function detectRemoteChanges(gitService, oldCommitId, newCommitId, options = {}) {
|
|
16016
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
15981
16017
|
try {
|
|
15982
16018
|
const files = await gitService.diffNames(oldCommitId, newCommitId);
|
|
15983
16019
|
return new Set(files);
|
|
15984
16020
|
} catch (e) {
|
|
15985
|
-
|
|
16021
|
+
logger.debug(`Git diff error: ${errors_getErrorMessage(e)}`);
|
|
15986
16022
|
return new Set();
|
|
15987
16023
|
}
|
|
15988
16024
|
}
|
|
@@ -16007,17 +16043,18 @@ Promise.resolve()
|
|
|
16007
16043
|
remoteOnlyChanges
|
|
16008
16044
|
};
|
|
16009
16045
|
}
|
|
16010
|
-
async function acceptRemoteChanges(gitService, remoteOnlyChanges) {
|
|
16046
|
+
async function acceptRemoteChanges(gitService, remoteOnlyChanges, options = {}) {
|
|
16047
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
16011
16048
|
if (remoteOnlyChanges.length > 0) {
|
|
16012
|
-
|
|
16049
|
+
logger.verbose(`Accepting ${remoteOnlyChanges.length} remote-only change(s)...`);
|
|
16013
16050
|
for (const file of remoteOnlyChanges)try {
|
|
16014
16051
|
await gitService.checkout([
|
|
16015
16052
|
file
|
|
16016
16053
|
]);
|
|
16017
|
-
|
|
16054
|
+
logger.verbose(` ✓ Accepted remote: ${file}`);
|
|
16018
16055
|
} catch (e) {
|
|
16019
16056
|
const errorMsg = errors_getErrorMessage(e);
|
|
16020
|
-
if (errorMsg.includes("pathspec") && errorMsg.includes("did not match any file"))
|
|
16057
|
+
if (errorMsg.includes("pathspec") && errorMsg.includes("did not match any file")) logger.warn(` Skipping ${file}: file not found in git repository`);
|
|
16021
16058
|
else throw new Error(errorMsg);
|
|
16022
16059
|
}
|
|
16023
16060
|
}
|
|
@@ -16063,17 +16100,19 @@ Promise.resolve()
|
|
|
16063
16100
|
...renameChanges
|
|
16064
16101
|
];
|
|
16065
16102
|
}
|
|
16066
|
-
function logConflictResolution(result) {
|
|
16103
|
+
function logConflictResolution(result, options = {}) {
|
|
16104
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
16067
16105
|
if (result.conflicts.length > 0) {
|
|
16068
|
-
|
|
16069
|
-
result.conflicts.forEach((c)=>
|
|
16106
|
+
logger.warn(` ${result.conflicts.length} file(s) changed both locally and remotely - keeping your local changes:`);
|
|
16107
|
+
result.conflicts.forEach((c)=>logger.info(` ${c.path}`));
|
|
16070
16108
|
}
|
|
16071
16109
|
if (result.localOnlyChanges.length > 0) {
|
|
16072
|
-
|
|
16073
|
-
result.localOnlyChanges.forEach((c)=>
|
|
16110
|
+
logger.info(`📝 ${result.localOnlyChanges.length} local change(s) preserved:`);
|
|
16111
|
+
result.localOnlyChanges.forEach((c)=>logger.verbose(` ${c.path}`));
|
|
16074
16112
|
}
|
|
16075
16113
|
}
|
|
16076
16114
|
async function deleteFilesRemovedOnAnvil(gitService, unstagedFiles, remotelyChangedFiles, options = {}) {
|
|
16115
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
16077
16116
|
const filesToRemove = [];
|
|
16078
16117
|
const localChangesToPreserve = options.localChangesToPreserve ?? new Set();
|
|
16079
16118
|
for (const file of unstagedFiles)if (!localChangesToPreserve.has(file)) {
|
|
@@ -16093,7 +16132,7 @@ Promise.resolve()
|
|
|
16093
16132
|
if (filesToRemove.length > 0) try {
|
|
16094
16133
|
await gitService.clean(filesToRemove);
|
|
16095
16134
|
filesToRemove.forEach((file)=>{
|
|
16096
|
-
|
|
16135
|
+
logger.verbose(` Deleted file removed on Anvil: ${file}`);
|
|
16097
16136
|
});
|
|
16098
16137
|
await gitService.removeEmptyDirectories(filesToRemove);
|
|
16099
16138
|
} catch (e) {}
|
|
@@ -16540,6 +16579,28 @@ Promise.resolve()
|
|
|
16540
16579
|
}));
|
|
16541
16580
|
return issues;
|
|
16542
16581
|
}
|
|
16582
|
+
function findAnvilAppRoot(filePath) {
|
|
16583
|
+
const existingPath = external_path_default().resolve(filePath);
|
|
16584
|
+
if (!external_fs_.existsSync(existingPath)) return null;
|
|
16585
|
+
let currentDir = external_fs_.statSync(existingPath).isDirectory() ? existingPath : external_path_default().dirname(existingPath);
|
|
16586
|
+
const candidates = [];
|
|
16587
|
+
while(true){
|
|
16588
|
+
if (external_fs_.existsSync(external_path_default().join(currentDir, "anvil.yaml"))) candidates.push(currentDir);
|
|
16589
|
+
const parentDir = external_path_default().dirname(currentDir);
|
|
16590
|
+
if (parentDir === currentDir) break;
|
|
16591
|
+
currentDir = parentDir;
|
|
16592
|
+
}
|
|
16593
|
+
return candidates.find((candidate)=>!candidates.some((outerCandidate)=>{
|
|
16594
|
+
if (candidate === outerCandidate) return false;
|
|
16595
|
+
return [
|
|
16596
|
+
"client_code",
|
|
16597
|
+
"server_code"
|
|
16598
|
+
].some((codeDir)=>{
|
|
16599
|
+
const relativePath = external_path_default().relative(external_path_default().join(outerCandidate, codeDir), candidate);
|
|
16600
|
+
return !external_path_default().isAbsolute(relativePath) && ".." !== relativePath && !relativePath.startsWith(`..${external_path_default().sep}`);
|
|
16601
|
+
});
|
|
16602
|
+
})) ?? null;
|
|
16603
|
+
}
|
|
16543
16604
|
const KNOWN_RUNTIME_SERVICE_SOURCES = new Set([
|
|
16544
16605
|
"/runtime/services/tables.yml",
|
|
16545
16606
|
"/runtime/services/google.yml",
|
|
@@ -16552,7 +16613,8 @@ Promise.resolve()
|
|
|
16552
16613
|
"/runtime/services/anvil/saml.yml",
|
|
16553
16614
|
"/runtime/services/anvil/microsoft.yml",
|
|
16554
16615
|
"/runtime/services/anvil/email.yml",
|
|
16555
|
-
"/runtime/services/anvil/files.yml"
|
|
16616
|
+
"/runtime/services/anvil/files.yml",
|
|
16617
|
+
"/runtime/services/anvil/tests.yml"
|
|
16556
16618
|
]);
|
|
16557
16619
|
const FRONTMATTER_ALLOWED_KEYS = new Set([
|
|
16558
16620
|
"custom_component",
|
|
@@ -16913,6 +16975,38 @@ print(json.dumps({"issues": issues}))
|
|
|
16913
16975
|
ok: true
|
|
16914
16976
|
};
|
|
16915
16977
|
}
|
|
16978
|
+
const css_namespaceObject = require("@lezer/css");
|
|
16979
|
+
function validateThemeCss(source) {
|
|
16980
|
+
if (!/anvil-dropzone/i.test(source)) return [];
|
|
16981
|
+
const warnings = [];
|
|
16982
|
+
let line = 1;
|
|
16983
|
+
let lineStart = 0;
|
|
16984
|
+
let nextLineBreak = source.indexOf("\n");
|
|
16985
|
+
css_namespaceObject.parser.parse(source).iterate({
|
|
16986
|
+
enter (node) {
|
|
16987
|
+
if ("SelectorQuery" === node.name) return false;
|
|
16988
|
+
if ("TagName" !== node.name || node.node.parent?.name !== "TagSelector" || "anvil-dropzone" !== source.slice(node.from, node.to).toLowerCase()) return;
|
|
16989
|
+
while(-1 !== nextLineBreak && nextLineBreak < node.from){
|
|
16990
|
+
line += 1;
|
|
16991
|
+
lineStart = nextLineBreak + 1;
|
|
16992
|
+
nextLineBreak = source.indexOf("\n", lineStart);
|
|
16993
|
+
}
|
|
16994
|
+
const column = node.from - lineStart + 1;
|
|
16995
|
+
warnings.push({
|
|
16996
|
+
path: "anvil-dropzone",
|
|
16997
|
+
code: "anvil-dropzone-selector",
|
|
16998
|
+
message: "HtmlComponent no longer renders anvil-dropzone elements. Target a component class or its surrounding element instead.",
|
|
16999
|
+
line,
|
|
17000
|
+
column,
|
|
17001
|
+
endLine: line,
|
|
17002
|
+
endColumn: column + node.to - node.from,
|
|
17003
|
+
offset: node.from,
|
|
17004
|
+
endOffset: node.to
|
|
17005
|
+
});
|
|
17006
|
+
}
|
|
17007
|
+
});
|
|
17008
|
+
return warnings;
|
|
17009
|
+
}
|
|
16916
17010
|
const validators_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
16917
17011
|
const DB_ACCESS_LEVELS = new Set([
|
|
16918
17012
|
"none",
|
|
@@ -17316,6 +17410,10 @@ print(json.dumps({"issues": issues}))
|
|
|
17316
17410
|
}
|
|
17317
17411
|
function inferValidationTarget(filePath) {
|
|
17318
17412
|
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
17413
|
+
if (/(^|\/)theme\/assets\/.+\.css$/i.test(normalizedPath)) {
|
|
17414
|
+
const appRoot = findAnvilAppRoot(filePath);
|
|
17415
|
+
if (!appRoot || external_path_default().relative(appRoot, filePath).replace(/\\/g, "/").startsWith("theme/assets/")) return "css";
|
|
17416
|
+
}
|
|
17319
17417
|
if ("anvil.yaml" === normalizedPath || normalizedPath.endsWith("/anvil.yaml")) return "anvil.yaml";
|
|
17320
17418
|
const clientCodePrefix = "client_code/";
|
|
17321
17419
|
if (normalizedPath.startsWith(clientCodePrefix) || normalizedPath.includes(`/${clientCodePrefix}`)) {
|
|
@@ -17337,28 +17435,6 @@ print(json.dumps({"issues": issues}))
|
|
|
17337
17435
|
const absolutePath = external_path_default().resolve(filePath);
|
|
17338
17436
|
return external_fs_.existsSync(absolutePath) ? absolutePath : null;
|
|
17339
17437
|
}
|
|
17340
|
-
function findAnvilAppRoot(filePath) {
|
|
17341
|
-
const existingPath = resolveExistingPath(filePath);
|
|
17342
|
-
if (!existingPath) return null;
|
|
17343
|
-
let currentDir = external_fs_.statSync(existingPath).isDirectory() ? existingPath : external_path_default().dirname(existingPath);
|
|
17344
|
-
const candidates = [];
|
|
17345
|
-
while(true){
|
|
17346
|
-
if (external_fs_.existsSync(external_path_default().join(currentDir, "anvil.yaml"))) candidates.push(currentDir);
|
|
17347
|
-
const parentDir = external_path_default().dirname(currentDir);
|
|
17348
|
-
if (parentDir === currentDir) break;
|
|
17349
|
-
currentDir = parentDir;
|
|
17350
|
-
}
|
|
17351
|
-
return candidates.find((candidate)=>!candidates.some((outerCandidate)=>{
|
|
17352
|
-
if (candidate === outerCandidate) return false;
|
|
17353
|
-
return [
|
|
17354
|
-
"client_code",
|
|
17355
|
-
"server_code"
|
|
17356
|
-
].some((codeDir)=>{
|
|
17357
|
-
const relativePath = external_path_default().relative(external_path_default().join(outerCandidate, codeDir), candidate);
|
|
17358
|
-
return !external_path_default().isAbsolute(relativePath) && ".." !== relativePath && !relativePath.startsWith(`..${external_path_default().sep}`);
|
|
17359
|
-
});
|
|
17360
|
-
})) ?? null;
|
|
17361
|
-
}
|
|
17362
17438
|
function validatePath(filePath, fileContent, options = {}) {
|
|
17363
17439
|
const target = inferValidationTarget(filePath);
|
|
17364
17440
|
const existingPath = resolveExistingPath(filePath);
|
|
@@ -17374,6 +17450,7 @@ print(json.dumps({"issues": issues}))
|
|
|
17374
17450
|
}
|
|
17375
17451
|
]
|
|
17376
17452
|
};
|
|
17453
|
+
if ("css" === target) return validPathResult(target, validateThemeCss(fileContent));
|
|
17377
17454
|
if ("anvil.yaml" === target) {
|
|
17378
17455
|
if (existingPath && appRoot && external_path_default().resolve(existingPath) !== external_path_default().join(appRoot, "anvil.yaml")) return {
|
|
17379
17456
|
ok: false,
|
|
@@ -17473,7 +17550,7 @@ print(json.dumps({"issues": issues}))
|
|
|
17473
17550
|
issues: [
|
|
17474
17551
|
{
|
|
17475
17552
|
path: "",
|
|
17476
|
-
message: "supported paths are anvil.yaml, client_code/**/form_template.yaml, client_code/**/*.yaml, client_code/**/*.html, client_code/**/*.py, and
|
|
17553
|
+
message: "supported paths are anvil.yaml, client_code/**/form_template.yaml, client_code/**/*.yaml, client_code/**/*.html, client_code/**/*.py, server_code/**/*.py, and theme/assets/**/*.css"
|
|
17477
17554
|
}
|
|
17478
17555
|
]
|
|
17479
17556
|
};
|
|
@@ -17715,7 +17792,8 @@ print(json.dumps({"issues": issues}))
|
|
|
17715
17792
|
content: null
|
|
17716
17793
|
};
|
|
17717
17794
|
}
|
|
17718
|
-
function deduplicateFormChanges(changes) {
|
|
17795
|
+
function deduplicateFormChanges(changes, options = {}) {
|
|
17796
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
17719
17797
|
const filtered = [];
|
|
17720
17798
|
const seenCodeFiles = new Set();
|
|
17721
17799
|
for (const change of changes)if ("rename" === change.type || "add" === change.type) {
|
|
@@ -17745,7 +17823,7 @@ print(json.dumps({"issues": issues}))
|
|
|
17745
17823
|
hasCorrespondingCode &&= seenCodeFiles.has(correspondingFromCodePath);
|
|
17746
17824
|
}
|
|
17747
17825
|
if (hasCorrespondingCode) {
|
|
17748
|
-
|
|
17826
|
+
logger.verbose(` Skipping form template ${change.type}: ${change.path} (handled by code file)`);
|
|
17749
17827
|
continue;
|
|
17750
17828
|
}
|
|
17751
17829
|
if ("rename" === change.type && change.from) filtered.push({
|
|
@@ -17760,8 +17838,9 @@ print(json.dumps({"issues": issues}))
|
|
|
17760
17838
|
return filtered;
|
|
17761
17839
|
}
|
|
17762
17840
|
async function routeFileChange(change, context) {
|
|
17841
|
+
const logger = context.logger ?? reporting_silentLogger;
|
|
17763
17842
|
const { relativePath, changeType, fromPath } = change;
|
|
17764
|
-
|
|
17843
|
+
logger.verbose(`Routing ${changeType}: ${relativePath}${fromPath ? ` (from: ${fromPath})` : ""}`);
|
|
17765
17844
|
if (isGitRelatedFile(relativePath)) return {
|
|
17766
17845
|
type: "ignore",
|
|
17767
17846
|
reason: "Git internal file"
|
|
@@ -17825,10 +17904,11 @@ print(json.dumps({"issues": issues}))
|
|
|
17825
17904
|
}
|
|
17826
17905
|
];
|
|
17827
17906
|
async function handleRename(rename, context) {
|
|
17907
|
+
const logger = context.logger ?? reporting_silentLogger;
|
|
17828
17908
|
const { fromPath, toPath } = rename;
|
|
17829
17909
|
const validation = await validateRename(fromPath, toPath, context);
|
|
17830
17910
|
if (!validation.valid) {
|
|
17831
|
-
|
|
17911
|
+
logger.verbose(`Rename invalid (${validation.reason}), falling back to unlink + add`);
|
|
17832
17912
|
const unlinkResult = await routeFileChange({
|
|
17833
17913
|
relativePath: fromPath,
|
|
17834
17914
|
changeType: "unlink"
|
|
@@ -18057,6 +18137,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18057
18137
|
};
|
|
18058
18138
|
}
|
|
18059
18139
|
async function handleDirectoryRenaming(rename, context) {
|
|
18140
|
+
const logger = context.logger ?? reporting_silentLogger;
|
|
18060
18141
|
const { repoPath } = context;
|
|
18061
18142
|
const { originalParts, pythonifiedParts, baseDir } = rename;
|
|
18062
18143
|
const needsRename = originalParts.some((part, idx)=>part !== pythonifiedParts[idx]);
|
|
@@ -18066,7 +18147,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18066
18147
|
for(let i = 0; i < originalParts.length - 1; i++)if (originalParts[i] !== pythonifiedParts[i]) {
|
|
18067
18148
|
const oldDirPath = external_path_default().join(repoPath, baseDir, ...originalParts.slice(0, i + 1));
|
|
18068
18149
|
const newDirPath = external_path_default().join(repoPath, baseDir, ...pythonifiedParts.slice(0, i + 1));
|
|
18069
|
-
|
|
18150
|
+
logger.verbose(`Renaming directory ${external_path_default().relative(repoPath, oldDirPath)} → ${external_path_default().relative(repoPath, newDirPath)} (pythonifying)`);
|
|
18070
18151
|
await external_fs_.promises.rename(oldDirPath, newDirPath);
|
|
18071
18152
|
return {
|
|
18072
18153
|
type: "ignore",
|
|
@@ -18077,6 +18158,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18077
18158
|
return null;
|
|
18078
18159
|
}
|
|
18079
18160
|
async function renameIfNeeded(rename, context) {
|
|
18161
|
+
const logger = context.logger ?? reporting_silentLogger;
|
|
18080
18162
|
const { repoPath } = context;
|
|
18081
18163
|
const { relativePath, originalNameOrParts, baseDir } = rename;
|
|
18082
18164
|
let pythonifiedName;
|
|
@@ -18100,7 +18182,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18100
18182
|
if (needsRename) {
|
|
18101
18183
|
const oldPath = external_path_default().join(repoPath, relativePath);
|
|
18102
18184
|
const newPath = external_path_default().join(repoPath, newRelativePath);
|
|
18103
|
-
|
|
18185
|
+
logger.verbose(`Renaming ${relativePath} → ${newRelativePath} (pythonifying)`);
|
|
18104
18186
|
await external_fs_.promises.rename(oldPath, newPath);
|
|
18105
18187
|
ignoreResult = {
|
|
18106
18188
|
type: "ignore",
|
|
@@ -18252,6 +18334,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18252
18334
|
});
|
|
18253
18335
|
}
|
|
18254
18336
|
async function buildFormTemplateData(relativePath, templateInfo, context, missingCodeBehavior = "error") {
|
|
18337
|
+
const logger = context.logger ?? reporting_silentLogger;
|
|
18255
18338
|
const { repoPath, stagedOnly = false } = context;
|
|
18256
18339
|
const { kind } = templateInfo;
|
|
18257
18340
|
const loadResult = await loadFormTemplateData(relativePath, templateInfo, context);
|
|
@@ -18274,7 +18357,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18274
18357
|
const knownForm = context.editorYaml.hasId("forms", className);
|
|
18275
18358
|
if ("defer" === missingCodeBehavior || knownForm) {
|
|
18276
18359
|
const action = knownForm ? `not saving existing form ${className}` : `deferring form ${className}`;
|
|
18277
|
-
|
|
18360
|
+
logger.warn(`Form template ${relativePath} has no code file ${codeRelativePath} yet; ${action}.`);
|
|
18278
18361
|
return {
|
|
18279
18362
|
formData: {},
|
|
18280
18363
|
className: "",
|
|
@@ -18285,7 +18368,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18285
18368
|
};
|
|
18286
18369
|
}
|
|
18287
18370
|
codeContent = "";
|
|
18288
|
-
|
|
18371
|
+
logger.warn(`Form template ${relativePath} has no code file ${codeRelativePath} yet; creating ${className} with empty code.`);
|
|
18289
18372
|
}
|
|
18290
18373
|
const formData = (0, form_template_parser_namespaceObject.buildFormTemplateSavePayload)(loadResult.source, {
|
|
18291
18374
|
className,
|
|
@@ -18447,7 +18530,8 @@ print(json.dumps({"issues": issues}))
|
|
|
18447
18530
|
reason: "No matching deletion route"
|
|
18448
18531
|
};
|
|
18449
18532
|
}
|
|
18450
|
-
async function getAnvilYamlChanges(repoPath, previousYaml) {
|
|
18533
|
+
async function getAnvilYamlChanges(repoPath, previousYaml, options = {}) {
|
|
18534
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
18451
18535
|
const anvilYamlPath = external_path_default().join(repoPath, "anvil.yaml");
|
|
18452
18536
|
let yamlContent;
|
|
18453
18537
|
let parsedYaml;
|
|
@@ -18459,8 +18543,8 @@ print(json.dumps({"issues": issues}))
|
|
|
18459
18543
|
try {
|
|
18460
18544
|
parsedYaml = external_js_yaml_default().load(yamlContent, {
|
|
18461
18545
|
onWarning: (warning)=>{
|
|
18462
|
-
|
|
18463
|
-
if (warning.mark)
|
|
18546
|
+
logger.warn(` YAML warning in anvil.yaml: ${warning.message}`);
|
|
18547
|
+
if (warning.mark) logger.verbose(` Line ${warning.mark.line + 1}, column ${warning.mark.column + 1}`);
|
|
18464
18548
|
}
|
|
18465
18549
|
});
|
|
18466
18550
|
} catch (error) {
|
|
@@ -18652,6 +18736,8 @@ print(json.dumps({"issues": issues}))
|
|
|
18652
18736
|
}
|
|
18653
18737
|
}
|
|
18654
18738
|
class SaveProcessor extends Emitter {
|
|
18739
|
+
logger;
|
|
18740
|
+
progress;
|
|
18655
18741
|
hasPendingChanges = false;
|
|
18656
18742
|
debounceTimer = null;
|
|
18657
18743
|
saveLoopPromise = null;
|
|
@@ -18662,7 +18748,10 @@ print(json.dumps({"issues": issues}))
|
|
|
18662
18748
|
syncCallback = null;
|
|
18663
18749
|
postSaveCallback = null;
|
|
18664
18750
|
constructor(config){
|
|
18665
|
-
|
|
18751
|
+
const logger = config.logger ?? reporting_silentLogger;
|
|
18752
|
+
super((event, error)=>logger.error(`Error in event handler for '${event}': ${error}`));
|
|
18753
|
+
this.logger = logger;
|
|
18754
|
+
this.progress = config.progress ?? silentProgress;
|
|
18666
18755
|
this.config = config;
|
|
18667
18756
|
}
|
|
18668
18757
|
setSyncCallback(callback) {
|
|
@@ -18676,11 +18765,11 @@ print(json.dumps({"issues": issues}))
|
|
|
18676
18765
|
const isFirstChange = !this.hasPendingChanges;
|
|
18677
18766
|
this.hasPendingChanges = true;
|
|
18678
18767
|
if (this.debounceTimer) clearTimeout(this.debounceTimer);
|
|
18679
|
-
if (isFirstChange)
|
|
18768
|
+
if (isFirstChange) this.progress.start("sync", "Change detected");
|
|
18680
18769
|
this.debounceTimer = setTimeout(()=>{
|
|
18681
18770
|
this.debounceTimer = null;
|
|
18682
18771
|
this.processSaveBatchWithEvents().catch((error)=>{
|
|
18683
|
-
|
|
18772
|
+
this.logger.error(`Save failed: ${errors_getErrorMessage(error)}`);
|
|
18684
18773
|
});
|
|
18685
18774
|
}, this.SAVE_DEBOUNCE_MS);
|
|
18686
18775
|
}
|
|
@@ -18703,7 +18792,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18703
18792
|
}
|
|
18704
18793
|
cleanup() {
|
|
18705
18794
|
if (this.hasPendingChanges) {
|
|
18706
|
-
|
|
18795
|
+
this.progress.end("sync");
|
|
18707
18796
|
this.hasPendingChanges = false;
|
|
18708
18797
|
}
|
|
18709
18798
|
if (this.debounceTimer) {
|
|
@@ -18725,8 +18814,8 @@ print(json.dumps({"issues": issues}))
|
|
|
18725
18814
|
}
|
|
18726
18815
|
async processOneSaveBatchWithEvents() {
|
|
18727
18816
|
if (this.config.isCleanedUp()) return;
|
|
18728
|
-
|
|
18729
|
-
if (!this.hasPendingChanges) return void
|
|
18817
|
+
this.progress.update("sync", "Processing");
|
|
18818
|
+
if (!this.hasPendingChanges) return void this.progress.end("sync");
|
|
18730
18819
|
let fileCount = 0;
|
|
18731
18820
|
try {
|
|
18732
18821
|
const status = await this.config.gitService.getStatus();
|
|
@@ -18748,7 +18837,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18748
18837
|
});
|
|
18749
18838
|
let finalMessage;
|
|
18750
18839
|
finalMessage = result.skipped ? void 0 : await this.getSuccessMessage();
|
|
18751
|
-
|
|
18840
|
+
this.progress.end("sync", finalMessage);
|
|
18752
18841
|
} catch (e) {
|
|
18753
18842
|
const diagnostic = createWatchDiagnostic(e, {
|
|
18754
18843
|
branch: this.config.getCurrentBranch(),
|
|
@@ -18763,7 +18852,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18763
18852
|
newCommitId: this.config.getCommitId(),
|
|
18764
18853
|
fileCount
|
|
18765
18854
|
});
|
|
18766
|
-
|
|
18855
|
+
this.progress.end("sync", "Failed");
|
|
18767
18856
|
throw e;
|
|
18768
18857
|
}
|
|
18769
18858
|
}
|
|
@@ -18785,7 +18874,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18785
18874
|
reason: "No pending changes"
|
|
18786
18875
|
};
|
|
18787
18876
|
this.hasPendingChanges = false;
|
|
18788
|
-
|
|
18877
|
+
this.logger.verbose(`\n📦 Processing batched file changes...`);
|
|
18789
18878
|
if (!this.config.isSettlePeriodOver()) return {
|
|
18790
18879
|
skipped: true,
|
|
18791
18880
|
reason: `Waiting (${this.config.getRemainingSettleTime()}s settle period)`
|
|
@@ -18796,34 +18885,34 @@ print(json.dumps({"issues": issues}))
|
|
|
18796
18885
|
try {
|
|
18797
18886
|
status = await this.config.gitService.getStatus();
|
|
18798
18887
|
} catch (e) {
|
|
18799
|
-
|
|
18888
|
+
this.logger.error(`Error reading git status: ${errors_getErrorMessage(e)}`);
|
|
18800
18889
|
throw e;
|
|
18801
18890
|
}
|
|
18802
18891
|
let allChanges;
|
|
18803
18892
|
if (this.config.stagedOnly) {
|
|
18804
18893
|
allChanges = await this.getStagedChanges();
|
|
18805
18894
|
if (0 === allChanges.length) {
|
|
18806
|
-
|
|
18895
|
+
this.logger.verbose("No staged changes found");
|
|
18807
18896
|
return {
|
|
18808
18897
|
skipped: true,
|
|
18809
18898
|
reason: "No staged changes"
|
|
18810
18899
|
};
|
|
18811
18900
|
}
|
|
18812
|
-
|
|
18901
|
+
this.logger.verbose(`Found ${allChanges.length} staged change(s):`);
|
|
18813
18902
|
} else {
|
|
18814
18903
|
allChanges = await this.getUnstagedChanges(status);
|
|
18815
18904
|
if (0 === allChanges.length) {
|
|
18816
|
-
|
|
18905
|
+
this.logger.verbose("No unstaged changes found");
|
|
18817
18906
|
return {
|
|
18818
18907
|
skipped: true,
|
|
18819
18908
|
reason: "No unstaged changes"
|
|
18820
18909
|
};
|
|
18821
18910
|
}
|
|
18822
|
-
|
|
18911
|
+
this.logger.verbose(`Found ${allChanges.length} unstaged change(s):`);
|
|
18823
18912
|
}
|
|
18824
18913
|
allChanges.forEach((c)=>{
|
|
18825
|
-
if ("rename" === c.type)
|
|
18826
|
-
else
|
|
18914
|
+
if ("rename" === c.type) this.logger.verbose(` ${c.type}: ${c.from} → ${c.path}`);
|
|
18915
|
+
else this.logger.verbose(` ${c.type}: ${c.path}`);
|
|
18827
18916
|
});
|
|
18828
18917
|
return this.processBatchedChanges(allChanges);
|
|
18829
18918
|
}
|
|
@@ -18831,7 +18920,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18831
18920
|
try {
|
|
18832
18921
|
return await getStagedFileChanges(this.config.gitService.getGit(), this.config.gitService);
|
|
18833
18922
|
} catch (e) {
|
|
18834
|
-
|
|
18923
|
+
this.logger.error(`Error getting staged changes: ${errors_getErrorMessage(e)}`);
|
|
18835
18924
|
return [];
|
|
18836
18925
|
}
|
|
18837
18926
|
}
|
|
@@ -18892,7 +18981,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18892
18981
|
const hash = external_crypto_namespaceObject.createHash("sha256").update(content).digest("hex");
|
|
18893
18982
|
newFileHashes.set(newPath, hash);
|
|
18894
18983
|
} catch (error) {
|
|
18895
|
-
|
|
18984
|
+
this.logger.debug(`Could not read new file: ${newPath}`);
|
|
18896
18985
|
}
|
|
18897
18986
|
for (const [deletedPath, deletedHash] of deletedFileHashes.entries())for (const [newPath, newHash] of newFileHashes.entries())if (deletedHash === newHash && !matchedNewFiles.has(newPath)) {
|
|
18898
18987
|
renames.push({
|
|
@@ -18928,16 +19017,20 @@ print(json.dumps({"issues": issues}))
|
|
|
18928
19017
|
const saveArray = [];
|
|
18929
19018
|
const originalFilePaths = [];
|
|
18930
19019
|
let anvilYamlDependenciesChanged = false;
|
|
18931
|
-
const deduplicatedChanges = deduplicateFormChanges(changes
|
|
19020
|
+
const deduplicatedChanges = deduplicateFormChanges(changes, {
|
|
19021
|
+
logger: this.logger
|
|
19022
|
+
});
|
|
18932
19023
|
for (const change of deduplicatedChanges){
|
|
18933
19024
|
if ("anvil.yaml" === change.path) {
|
|
18934
19025
|
const previousAnvilYaml = await this.getHeadAnvilYaml();
|
|
18935
|
-
const anvilChanges = await getAnvilYamlChanges(this.config.repoPath, previousAnvilYaml
|
|
19026
|
+
const anvilChanges = await getAnvilYamlChanges(this.config.repoPath, previousAnvilYaml, {
|
|
19027
|
+
logger: this.logger
|
|
19028
|
+
});
|
|
18936
19029
|
const previousDependencies = normalizeAnvilYamlDependenciesValue(previousAnvilYaml?.dependencies);
|
|
18937
19030
|
const currentDependencies = await readAnvilYamlDependencies(this.config.repoPath);
|
|
18938
19031
|
if (!anvilYamlDependenciesEqual(previousDependencies, currentDependencies)) anvilYamlDependenciesChanged = true;
|
|
18939
19032
|
if (0 === anvilChanges.length) {
|
|
18940
|
-
|
|
19033
|
+
this.logger.verbose(" Ignoring anvil.yaml: No changes detected");
|
|
18941
19034
|
continue;
|
|
18942
19035
|
}
|
|
18943
19036
|
for (const { key, value } of anvilChanges){
|
|
@@ -18947,7 +19040,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18947
19040
|
],
|
|
18948
19041
|
value
|
|
18949
19042
|
]);
|
|
18950
|
-
|
|
19043
|
+
this.logger.verbose(` ✓ anvil.yaml[${key}] → [["${key}"], ...]`);
|
|
18951
19044
|
}
|
|
18952
19045
|
originalFilePaths.push(change.path);
|
|
18953
19046
|
continue;
|
|
@@ -18957,6 +19050,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18957
19050
|
changeType: change.type,
|
|
18958
19051
|
fromPath: change.from
|
|
18959
19052
|
}, {
|
|
19053
|
+
logger: this.logger,
|
|
18960
19054
|
repoPath: this.config.repoPath,
|
|
18961
19055
|
editorYaml: this.config.editorYaml,
|
|
18962
19056
|
stagedOnly: this.config.stagedOnly
|
|
@@ -18966,7 +19060,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18966
19060
|
];
|
|
18967
19061
|
for (const result of results){
|
|
18968
19062
|
if ("ignore" === result.type) {
|
|
18969
|
-
|
|
19063
|
+
this.logger.verbose(` Ignoring ${change.path}: ${result.reason}`);
|
|
18970
19064
|
continue;
|
|
18971
19065
|
}
|
|
18972
19066
|
const { savePath, content } = result;
|
|
@@ -18979,7 +19073,7 @@ print(json.dumps({"issues": issues}))
|
|
|
18979
19073
|
}
|
|
18980
19074
|
}
|
|
18981
19075
|
if (0 === saveArray.length) {
|
|
18982
|
-
|
|
19076
|
+
this.logger.verbose("No savable changes");
|
|
18983
19077
|
return {
|
|
18984
19078
|
skipped: true,
|
|
18985
19079
|
reason: "No savable changes"
|
|
@@ -19003,25 +19097,25 @@ print(json.dumps({"issues": issues}))
|
|
|
19003
19097
|
contentToLog = JSON.stringify(tempContent, null, 2);
|
|
19004
19098
|
}
|
|
19005
19099
|
const changeDesc = "rename" === change.type && change.from ? `${change.from} → ${change.path}` : change.path;
|
|
19006
|
-
|
|
19100
|
+
this.logger.verbose(` ✓ ${changeDesc} → ${JSON.stringify(savePath)} → ${contentToLog}`);
|
|
19007
19101
|
}
|
|
19008
19102
|
async sendSavesToAnvil(saveArray, originalFilePaths = [], retryCount = 0) {
|
|
19009
19103
|
const fileCount = saveArray.length;
|
|
19010
19104
|
const message = 1 === fileCount ? "Syncing to Anvil" : `Syncing ${fileCount} changes to Anvil`;
|
|
19011
|
-
|
|
19105
|
+
this.progress.update("sync", message);
|
|
19012
19106
|
const payload = {
|
|
19013
19107
|
edit_session: this.config.editSession,
|
|
19014
19108
|
save_sequence: this.saveSequence++,
|
|
19015
19109
|
version: this.config.getCommitId(),
|
|
19016
19110
|
updates: saveArray
|
|
19017
19111
|
};
|
|
19018
|
-
|
|
19112
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)("PAYLOAD:", JSON.stringify(this.sanitizePayload(payload), null, 2)));
|
|
19019
19113
|
const currentBranch = this.config.getCurrentBranch();
|
|
19020
19114
|
try {
|
|
19021
19115
|
const branchFromGit = await this.config.gitService.getCurrentBranch();
|
|
19022
19116
|
if (branchFromGit !== currentBranch) {
|
|
19023
19117
|
const reason = `Branch ${branchFromGit} not validated`;
|
|
19024
|
-
|
|
19118
|
+
this.logger.error(`Cannot sync - ${reason}`);
|
|
19025
19119
|
const error = createSaveError.validationFailed(reason, branchFromGit);
|
|
19026
19120
|
this.emit("validation-failed", {
|
|
19027
19121
|
reason,
|
|
@@ -19035,7 +19129,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19035
19129
|
} catch (e) {
|
|
19036
19130
|
if ("save_validation_failed" === e.type) throw e;
|
|
19037
19131
|
const reason = "Branch unknown not validated";
|
|
19038
|
-
|
|
19132
|
+
this.logger.error(`Cannot sync - ${reason}`);
|
|
19039
19133
|
const error = createSaveError.validationFailed(reason, "unknown");
|
|
19040
19134
|
this.emit("validation-failed", {
|
|
19041
19135
|
reason,
|
|
@@ -19057,15 +19151,15 @@ print(json.dumps({"issues": issues}))
|
|
|
19057
19151
|
body: JSON.stringify(payload)
|
|
19058
19152
|
});
|
|
19059
19153
|
const json_resp = await resp.json();
|
|
19060
|
-
|
|
19154
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)("JSON RESPONSE:", JSON.stringify(json_resp, null, 2)));
|
|
19061
19155
|
if (401 === resp.status || 403 === resp.status) this.handleAuthError(resp.status, json_resp);
|
|
19062
19156
|
if (409 === resp.status) {
|
|
19063
|
-
|
|
19157
|
+
this.progress.update("sync", "Conflict - retrying");
|
|
19064
19158
|
await this.handleConflict(json_resp, originalFilePaths, retryCount);
|
|
19065
19159
|
return;
|
|
19066
19160
|
}
|
|
19067
19161
|
if (200 === resp.status) return void await this.handleSuccess(json_resp, originalFilePaths);
|
|
19068
|
-
|
|
19162
|
+
this.logger.error(`Unexpected response status: ${resp.status}`);
|
|
19069
19163
|
throw {
|
|
19070
19164
|
type: "server_error",
|
|
19071
19165
|
status: resp.status,
|
|
@@ -19101,15 +19195,15 @@ print(json.dumps({"issues": issues}))
|
|
|
19101
19195
|
handleAuthError(status, json_resp) {
|
|
19102
19196
|
const errorMsg = json_resp.error || "unauthorized";
|
|
19103
19197
|
const detailedMsg = `Authentication failed (${status}): ${errorMsg}`;
|
|
19104
|
-
if (403 === status)
|
|
19105
|
-
else
|
|
19198
|
+
if (403 === status) this.logger.error(`${detailedMsg}\n This may indicate:\n - The OAuth token doesn't have permission to write to app ${this.config.appId}\n - The app belongs to a different user or organization\n - The OAuth token is missing required scopes (apps:write)`);
|
|
19199
|
+
else this.logger.error(detailedMsg);
|
|
19106
19200
|
throw createAuthError.invalid(detailedMsg);
|
|
19107
19201
|
}
|
|
19108
19202
|
async handleConflict(json_resp, originalFilePaths, retryCount) {
|
|
19109
19203
|
const conflict = this.getConflictDiagnosticInfo(json_resp);
|
|
19110
19204
|
if (retryCount >= this.MAX_RETRIES) {
|
|
19111
|
-
|
|
19112
|
-
|
|
19205
|
+
this.logger.error(`Save failed after ${this.MAX_RETRIES} retries due to version conflicts.`);
|
|
19206
|
+
this.logger.warn("This usually means someone else is editing the app at the same time.");
|
|
19113
19207
|
const error = createSaveError.maxRetriesExceeded(this.MAX_RETRIES);
|
|
19114
19208
|
this.emit("max-retries-exceeded", {
|
|
19115
19209
|
retries: this.MAX_RETRIES,
|
|
@@ -19122,10 +19216,10 @@ print(json.dumps({"issues": issues}))
|
|
|
19122
19216
|
});
|
|
19123
19217
|
throw error;
|
|
19124
19218
|
}
|
|
19125
|
-
if (json_resp.overtaken)
|
|
19126
|
-
else if (json_resp.latest_version)
|
|
19219
|
+
if (json_resp.overtaken) this.logger.warn(`${conflict.reason}, fetching latest and retrying (attempt ${retryCount + 1}/${this.MAX_RETRIES})`);
|
|
19220
|
+
else if (json_resp.latest_version) this.logger.warn(`Version conflict detected, syncing to ${json_resp.latest_version.substring(0, 8)} and retrying (attempt ${retryCount + 1}/${this.MAX_RETRIES})`);
|
|
19127
19221
|
else {
|
|
19128
|
-
|
|
19222
|
+
this.logger.error("Save failed with 409 but no conflict info provided");
|
|
19129
19223
|
throw createSaveError.conflict();
|
|
19130
19224
|
}
|
|
19131
19225
|
this.emit("sync-conflict", {
|
|
@@ -19143,7 +19237,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19143
19237
|
})
|
|
19144
19238
|
});
|
|
19145
19239
|
if (!this.syncCallback) throw createSaveError.noSyncCallback();
|
|
19146
|
-
|
|
19240
|
+
this.progress.update("sync", "Syncing back");
|
|
19147
19241
|
const syncResult = await this.syncCallback(new Set(originalFilePaths));
|
|
19148
19242
|
const { localOnlyChanges, conflicts } = syncResult;
|
|
19149
19243
|
const changesToSave = [
|
|
@@ -19177,13 +19271,13 @@ print(json.dumps({"issues": issues}))
|
|
|
19177
19271
|
branch: this.config.getCurrentBranch()
|
|
19178
19272
|
});
|
|
19179
19273
|
if (this.postSaveCallback) {
|
|
19180
|
-
|
|
19274
|
+
this.progress.update("sync", "Syncing back");
|
|
19181
19275
|
await this.postSaveCallback(new Set(originalFilePaths));
|
|
19182
19276
|
}
|
|
19183
19277
|
if (this.config.getCommitId() === commitIdBeforePostSaveSync) this.config.setCommitId(version);
|
|
19184
19278
|
}
|
|
19185
19279
|
async rerouteChanges(changes) {
|
|
19186
|
-
|
|
19280
|
+
this.logger.verbose(`Re-routing ${changes.length} local change(s)...`);
|
|
19187
19281
|
const newSaveArray = [];
|
|
19188
19282
|
const newFilePaths = [];
|
|
19189
19283
|
for (const change of changes){
|
|
@@ -19192,6 +19286,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19192
19286
|
changeType: change.type,
|
|
19193
19287
|
fromPath: change.from
|
|
19194
19288
|
}, {
|
|
19289
|
+
logger: this.logger,
|
|
19195
19290
|
repoPath: this.config.repoPath,
|
|
19196
19291
|
editorYaml: this.config.editorYaml,
|
|
19197
19292
|
stagedOnly: this.config.stagedOnly
|
|
@@ -19201,7 +19296,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19201
19296
|
];
|
|
19202
19297
|
for (const result of results){
|
|
19203
19298
|
if ("ignore" === result.type) {
|
|
19204
|
-
|
|
19299
|
+
this.logger.verbose(` Ignoring ${change.path}: ${result.reason}`);
|
|
19205
19300
|
continue;
|
|
19206
19301
|
}
|
|
19207
19302
|
newSaveArray.push([
|
|
@@ -19210,7 +19305,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19210
19305
|
]);
|
|
19211
19306
|
newFilePaths.push(change.path);
|
|
19212
19307
|
const changeDesc = "rename" === change.type && change.from ? `${change.from} → ${change.path}` : change.path;
|
|
19213
|
-
|
|
19308
|
+
this.logger.verbose(` ✓ ${changeDesc} → ${JSON.stringify(result.savePath)}`);
|
|
19214
19309
|
}
|
|
19215
19310
|
}
|
|
19216
19311
|
return {
|
|
@@ -19233,10 +19328,13 @@ print(json.dumps({"issues": issues}))
|
|
|
19233
19328
|
return normalized;
|
|
19234
19329
|
}
|
|
19235
19330
|
class SyncManager extends Emitter {
|
|
19331
|
+
logger;
|
|
19236
19332
|
config;
|
|
19237
19333
|
syncQueue = Promise.resolve();
|
|
19238
19334
|
constructor(config){
|
|
19239
|
-
|
|
19335
|
+
const logger = config.logger ?? reporting_silentLogger;
|
|
19336
|
+
super((event, error)=>logger.error(`Error in event handler for '${event}': ${error}`));
|
|
19337
|
+
this.logger = logger;
|
|
19240
19338
|
this.config = config;
|
|
19241
19339
|
}
|
|
19242
19340
|
async syncRemoteChanges(knownLocalChanges) {
|
|
@@ -19266,19 +19364,25 @@ print(json.dumps({"issues": issues}))
|
|
|
19266
19364
|
};
|
|
19267
19365
|
const newCommitId = await this.config.gitService.getCommitId();
|
|
19268
19366
|
this.config.setCommitId(newCommitId);
|
|
19269
|
-
const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId
|
|
19367
|
+
const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId, {
|
|
19368
|
+
logger: this.logger
|
|
19369
|
+
});
|
|
19270
19370
|
const statusAfter = await this.config.gitService.getStatus();
|
|
19271
19371
|
const newChanges = extractChangesFromStatus(statusAfter);
|
|
19272
19372
|
if (0 === newChanges.length) {
|
|
19273
|
-
|
|
19373
|
+
this.logger.verbose(" No local changes - working directory is clean");
|
|
19274
19374
|
return {
|
|
19275
19375
|
localOnlyChanges: [],
|
|
19276
19376
|
conflicts: []
|
|
19277
19377
|
};
|
|
19278
19378
|
}
|
|
19279
19379
|
const result = categorizeChanges(newChanges, locallyChangedFiles, remoteChangedFiles);
|
|
19280
|
-
await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges
|
|
19281
|
-
|
|
19380
|
+
await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges, {
|
|
19381
|
+
logger: this.logger
|
|
19382
|
+
});
|
|
19383
|
+
logConflictResolution(result, {
|
|
19384
|
+
logger: this.logger
|
|
19385
|
+
});
|
|
19282
19386
|
return {
|
|
19283
19387
|
localOnlyChanges: result.localOnlyChanges,
|
|
19284
19388
|
conflicts: result.conflicts
|
|
@@ -19337,13 +19441,16 @@ print(json.dumps({"issues": issues}))
|
|
|
19337
19441
|
async deleteFilesRemovedOnAnvilLocally(oldCommitId, newCommitId, localChangesToPreserve) {
|
|
19338
19442
|
try {
|
|
19339
19443
|
const status = await this.config.gitService.getStatus();
|
|
19340
|
-
const remotelyChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId
|
|
19444
|
+
const remotelyChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId, {
|
|
19445
|
+
logger: this.logger
|
|
19446
|
+
});
|
|
19341
19447
|
await deleteFilesRemovedOnAnvil(this.config.gitService, status.notAdded, remotelyChangedFiles, {
|
|
19448
|
+
logger: this.logger,
|
|
19342
19449
|
oldCommitId,
|
|
19343
19450
|
localChangesToPreserve
|
|
19344
19451
|
});
|
|
19345
19452
|
} catch (e) {
|
|
19346
|
-
|
|
19453
|
+
this.logger.verbose(` Failed to check git status: ${errors_getErrorMessage(e)}`);
|
|
19347
19454
|
}
|
|
19348
19455
|
}
|
|
19349
19456
|
async discardFormattingOnlyYamlChanges() {
|
|
@@ -19351,7 +19458,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19351
19458
|
try {
|
|
19352
19459
|
status = await this.config.gitService.getStatus();
|
|
19353
19460
|
} catch (e) {
|
|
19354
|
-
|
|
19461
|
+
this.logger.verbose(` Failed to check git status: ${errors_getErrorMessage(e)}`);
|
|
19355
19462
|
return;
|
|
19356
19463
|
}
|
|
19357
19464
|
const serverCreatedFiles = [
|
|
@@ -19363,7 +19470,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19363
19470
|
await this.config.gitService.checkout([
|
|
19364
19471
|
yamlFile
|
|
19365
19472
|
]);
|
|
19366
|
-
|
|
19473
|
+
this.logger.verbose(` Accepted server-created file: ${yamlFile}`);
|
|
19367
19474
|
}
|
|
19368
19475
|
const serverConvertedFormTemplates = status.deleted.filter((f)=>{
|
|
19369
19476
|
const norm = f.replace(/\\/g, "/");
|
|
@@ -19376,7 +19483,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19376
19483
|
await this.config.gitService.checkout([
|
|
19377
19484
|
htmlFile
|
|
19378
19485
|
]);
|
|
19379
|
-
|
|
19486
|
+
this.logger.verbose(` Accepted HTML form template: ${htmlFile}`);
|
|
19380
19487
|
}
|
|
19381
19488
|
const yamlFiles = status.modified.filter((f)=>f.endsWith(".yaml") || f.endsWith(".yml"));
|
|
19382
19489
|
for (const yamlFile of yamlFiles)try {
|
|
@@ -19393,13 +19500,13 @@ print(json.dumps({"issues": issues}))
|
|
|
19393
19500
|
const workingForCompare = stripNonSemanticYamlFields(yamlFile, workingParsed);
|
|
19394
19501
|
const headForCompare = stripNonSemanticYamlFields(yamlFile, headParsed);
|
|
19395
19502
|
if (deepEqual(workingForCompare, headForCompare)) {
|
|
19396
|
-
|
|
19503
|
+
this.logger.verbose(` Discarding formatting-only change: ${yamlFile}`);
|
|
19397
19504
|
await this.config.gitService.checkout([
|
|
19398
19505
|
yamlFile
|
|
19399
19506
|
]);
|
|
19400
19507
|
}
|
|
19401
19508
|
} catch (error) {
|
|
19402
|
-
|
|
19509
|
+
this.logger.verbose(` Keeping ${yamlFile} (couldn't verify if formatting-only)`);
|
|
19403
19510
|
}
|
|
19404
19511
|
const htmlFiles = status.modified.filter((f)=>{
|
|
19405
19512
|
const norm = f.replace(/\\/g, "/");
|
|
@@ -19417,18 +19524,20 @@ print(json.dumps({"issues": issues}))
|
|
|
19417
19524
|
const working = parseHtmlWithFrontmatter(workingContent);
|
|
19418
19525
|
const head = parseHtmlWithFrontmatter(headContent);
|
|
19419
19526
|
if (deepEqual(working.frontmatter, head.frontmatter) && working.html === head.html) {
|
|
19420
|
-
|
|
19527
|
+
this.logger.verbose(` Discarding formatting-only change: ${htmlFile}`);
|
|
19421
19528
|
await this.config.gitService.checkout([
|
|
19422
19529
|
htmlFile
|
|
19423
19530
|
]);
|
|
19424
19531
|
}
|
|
19425
19532
|
} catch (error) {
|
|
19426
|
-
|
|
19533
|
+
this.logger.verbose(` Keeping ${htmlFile} (couldn't verify if frontmatter-only change)`);
|
|
19427
19534
|
}
|
|
19428
19535
|
}
|
|
19429
19536
|
}
|
|
19430
19537
|
class WatchSession_WatchSession extends Emitter {
|
|
19431
19538
|
sessionId;
|
|
19539
|
+
logger;
|
|
19540
|
+
progress;
|
|
19432
19541
|
repoPath;
|
|
19433
19542
|
appId;
|
|
19434
19543
|
anvilUrl;
|
|
@@ -19464,7 +19573,10 @@ print(json.dumps({"issues": issues}))
|
|
|
19464
19573
|
LOCAL_CHANGE_POLL_MS = 2000;
|
|
19465
19574
|
stagedOnly;
|
|
19466
19575
|
constructor(repoPath, appId, options){
|
|
19467
|
-
|
|
19576
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
19577
|
+
super((event, error)=>logger.error(`Error in event handler for '${event}': ${error}`));
|
|
19578
|
+
this.logger = logger;
|
|
19579
|
+
this.progress = options.progress ?? silentProgress;
|
|
19468
19580
|
this.sessionId = Math.random().toString(36).substring(2, 10);
|
|
19469
19581
|
this.repoPath = external_path_default().resolve(repoPath);
|
|
19470
19582
|
this.appId = appId;
|
|
@@ -19479,22 +19591,22 @@ print(json.dumps({"issues": issues}))
|
|
|
19479
19591
|
this.envBranchChangeMode = options.envBranchChangeMode ?? "manual";
|
|
19480
19592
|
this.dependencyWatchEnabled = options.dependencyWatch ?? true;
|
|
19481
19593
|
this.editSession = "anvil-sync-" + Math.random().toString(36).substring(2, 15);
|
|
19482
|
-
this.gitService = new git_GitService(this.repoPath
|
|
19594
|
+
this.gitService = new git_GitService(this.repoPath, {
|
|
19595
|
+
logger: this.logger
|
|
19596
|
+
});
|
|
19483
19597
|
this.gitService.on("fetch-retry", (data)=>this.emit("fetch-retry", data));
|
|
19484
19598
|
this.gitService.on("fetch-retry-resolved", (data)=>this.emit("fetch-retry-resolved", data));
|
|
19485
19599
|
this.editorYaml = new EditorYamlManager(this.repoPath);
|
|
19486
|
-
|
|
19600
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[Session ${this.sessionId}]`, `Created for app ${appId} on branch ${options.currentBranch}`));
|
|
19487
19601
|
}
|
|
19488
19602
|
getBranchName() {
|
|
19489
19603
|
return this.currentBranch;
|
|
19490
19604
|
}
|
|
19491
19605
|
pauseForUserInput() {
|
|
19492
19606
|
this.isPausedForUserInput = true;
|
|
19493
|
-
logger_logger.pause();
|
|
19494
19607
|
}
|
|
19495
19608
|
resumeAfterUserInput() {
|
|
19496
19609
|
this.isPausedForUserInput = false;
|
|
19497
|
-
logger_logger.resume();
|
|
19498
19610
|
}
|
|
19499
19611
|
async initialize() {
|
|
19500
19612
|
await this.editorYaml.load();
|
|
@@ -19503,13 +19615,14 @@ print(json.dumps({"issues": issues}))
|
|
|
19503
19615
|
try {
|
|
19504
19616
|
await this.connectWebSocket();
|
|
19505
19617
|
} catch (error) {
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19618
|
+
this.logger.warn(" WebSocket connection unavailable - changes from the Anvil Editor won't be detected");
|
|
19619
|
+
this.logger.verbose(" Local changes will still sync to Anvil, but editor changes won't appear locally");
|
|
19620
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)("WebSocket init error:", error.message));
|
|
19509
19621
|
}
|
|
19510
19622
|
}
|
|
19511
19623
|
initializeProcessors() {
|
|
19512
19624
|
this.syncManager = new SyncManager({
|
|
19625
|
+
logger: this.logger,
|
|
19513
19626
|
repoPath: this.repoPath,
|
|
19514
19627
|
appId: this.appId,
|
|
19515
19628
|
anvilUrl: this.anvilUrl,
|
|
@@ -19529,6 +19642,8 @@ print(json.dumps({"issues": issues}))
|
|
|
19529
19642
|
}
|
|
19530
19643
|
});
|
|
19531
19644
|
this.saveProcessor = new SaveProcessor({
|
|
19645
|
+
logger: this.logger,
|
|
19646
|
+
progress: this.progress,
|
|
19532
19647
|
repoPath: this.repoPath,
|
|
19533
19648
|
appId: this.appId,
|
|
19534
19649
|
anvilUrl: this.anvilUrl,
|
|
@@ -19574,6 +19689,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19574
19689
|
}
|
|
19575
19690
|
async connectWebSocket() {
|
|
19576
19691
|
this.wsClient = new WebSocketClient({
|
|
19692
|
+
logger: this.logger,
|
|
19577
19693
|
appId: this.appId,
|
|
19578
19694
|
anvilUrl: this.anvilUrl,
|
|
19579
19695
|
authToken: this.authToken,
|
|
@@ -19592,23 +19708,23 @@ print(json.dumps({"issues": issues}))
|
|
|
19592
19708
|
});
|
|
19593
19709
|
this.wsClient.on("repo-update", async ({ appId, ref, commitHash, saveSeq })=>{
|
|
19594
19710
|
if (appId !== this.appId) return void await this.handleDependencyRepoUpdate(appId, ref, commitHash);
|
|
19595
|
-
if (saveSeq?.session === this.editSession) return void
|
|
19711
|
+
if (saveSeq?.session === this.editSession) return void this.logger.debug("Ignoring update from our own session");
|
|
19596
19712
|
const branchName = ref.replace(/^refs\/heads\//, "");
|
|
19597
|
-
if (branchName !== this.currentBranch) return void
|
|
19598
|
-
|
|
19713
|
+
if (branchName !== this.currentBranch) return void this.logger.debug(`Ignoring update to different branch: ${branchName} (current: ${this.currentBranch})`);
|
|
19714
|
+
this.logger.warn(`Remote changes detected on branch ${this.currentBranch}`);
|
|
19599
19715
|
this.emit("remote-update", {
|
|
19600
19716
|
branch: this.currentBranch,
|
|
19601
19717
|
commitHash
|
|
19602
19718
|
});
|
|
19603
|
-
|
|
19719
|
+
this.progress.start("remote-sync", "Syncing from Anvil");
|
|
19604
19720
|
try {
|
|
19605
19721
|
await this.syncRemoteChanges();
|
|
19606
19722
|
const message = await this.getSuccessMessage();
|
|
19607
|
-
|
|
19723
|
+
this.progress.end("remote-sync", message);
|
|
19608
19724
|
} catch (e) {
|
|
19609
|
-
|
|
19725
|
+
this.progress.end("remote-sync", "Sync failed");
|
|
19610
19726
|
this.emitRemoteSyncFailed(e, this.currentBranch, commitHash);
|
|
19611
|
-
|
|
19727
|
+
this.logger.error(`Failed to sync remote changes: ${errors_getErrorMessage(e)}`);
|
|
19612
19728
|
}
|
|
19613
19729
|
});
|
|
19614
19730
|
await this.wsClient.connect();
|
|
@@ -19617,8 +19733,8 @@ print(json.dumps({"issues": issues}))
|
|
|
19617
19733
|
if (!this.dependencyWatchEnabled) return;
|
|
19618
19734
|
const branchName = ref.replace(/^refs\/heads\//, "");
|
|
19619
19735
|
const subscription = this.wsClient?.getDependencySubscriptions().find((candidate)=>candidate.appId === appId && candidate.branch === branchName);
|
|
19620
|
-
if (!subscription) return void
|
|
19621
|
-
|
|
19736
|
+
if (!subscription) return void this.logger.debug(`Ignoring update for unwatched dependency app ${appId} on ${branchName}`);
|
|
19737
|
+
this.logger.verbose(`Dependency update detected: ${subscription.packageName ?? appId} (${branchName}, ${commitHash.substring(0, 8)})`);
|
|
19622
19738
|
await this.queueDependencyRefresh(`dependency ${appId} updated`);
|
|
19623
19739
|
}
|
|
19624
19740
|
async queueDependencyRefresh(reason) {
|
|
@@ -19639,20 +19755,21 @@ print(json.dumps({"issues": issues}))
|
|
|
19639
19755
|
}
|
|
19640
19756
|
async refreshDependencies(reason) {
|
|
19641
19757
|
if (!this.dependencyWatchEnabled || this.isCleanedUp) return;
|
|
19642
|
-
|
|
19758
|
+
this.progress.start("dependency-refresh", "startup" === reason ? "Fetching dependencies" : "Refreshing dependencies");
|
|
19643
19759
|
try {
|
|
19644
19760
|
const previousSubscriptions = this.wsClient?.getDependencySubscriptions() ?? [];
|
|
19645
19761
|
const { response, addedGitignoreEntry } = await refreshDependencyCache(this.repoPath, this.appId, this.anvilUrl, {
|
|
19762
|
+
logger: this.logger,
|
|
19646
19763
|
username: this.username,
|
|
19647
19764
|
includeDocs: true
|
|
19648
19765
|
});
|
|
19649
|
-
if (addedGitignoreEntry)
|
|
19766
|
+
if (addedGitignoreEntry) this.logger.info("Added /.anvil/ to .gitignore");
|
|
19650
19767
|
const nextSubscriptions = await this.getDependencyWatchSubscriptions();
|
|
19651
19768
|
this.reconcileDependencySubscriptions(previousSubscriptions, nextSubscriptions);
|
|
19652
|
-
|
|
19769
|
+
this.progress.end("dependency-refresh", response.dependencies.length ? `Fetched ${response.dependencies.length} dependencies` : "Dependencies already up to date");
|
|
19653
19770
|
} catch (error) {
|
|
19654
|
-
|
|
19655
|
-
|
|
19771
|
+
this.progress.end("dependency-refresh", "Failed");
|
|
19772
|
+
this.logger.warn(`Failed to refresh dependencies: ${errors_getErrorMessage(error)}`);
|
|
19656
19773
|
}
|
|
19657
19774
|
}
|
|
19658
19775
|
async getDependencyWatchSubscriptions() {
|
|
@@ -19709,7 +19826,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19709
19826
|
"-fd"
|
|
19710
19827
|
]);
|
|
19711
19828
|
}
|
|
19712
|
-
|
|
19829
|
+
this.logger.verbose(`Environment branch ${"snapshot" === source ? "snapshot" : "update"}: ${this.currentBranch} -> ${targetBranch}`);
|
|
19713
19830
|
this.authToken = await auth_getValidAuthToken(this.anvilUrl, this.username);
|
|
19714
19831
|
this.wsClient?.updateAuthToken?.(this.authToken);
|
|
19715
19832
|
const fetchUrl = anvil_api_getGitFetchUrl(this.appId, this.authToken, this.gitUrl);
|
|
@@ -19809,7 +19926,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19809
19926
|
}
|
|
19810
19927
|
cleanup() {
|
|
19811
19928
|
this.isCleanedUp = true;
|
|
19812
|
-
|
|
19929
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[Session ${this.sessionId}]`, "Cleaning up..."));
|
|
19813
19930
|
this.saveProcessor?.cleanup();
|
|
19814
19931
|
if (this.wsClient) {
|
|
19815
19932
|
this.wsClient.close();
|
|
@@ -19823,12 +19940,13 @@ print(json.dumps({"issues": issues}))
|
|
|
19823
19940
|
clearInterval(this.localChangePollTimer);
|
|
19824
19941
|
this.localChangePollTimer = null;
|
|
19825
19942
|
}
|
|
19826
|
-
|
|
19943
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[Session ${this.sessionId}]`, "Cleanup complete"));
|
|
19827
19944
|
}
|
|
19828
19945
|
async startWatching() {
|
|
19829
|
-
|
|
19946
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[Session ${this.sessionId}]`, "Starting watchers..."));
|
|
19830
19947
|
const gitDir = await this.gitService.getGitDir();
|
|
19831
19948
|
this.fileWatcher = new FileWatcher({
|
|
19949
|
+
logger: this.logger,
|
|
19832
19950
|
repoPath: this.repoPath,
|
|
19833
19951
|
gitDir,
|
|
19834
19952
|
stagedOnly: this.stagedOnly,
|
|
@@ -19844,7 +19962,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19844
19962
|
try {
|
|
19845
19963
|
await this.handleFileChange(event, filePath, relativePath);
|
|
19846
19964
|
} catch (error) {
|
|
19847
|
-
|
|
19965
|
+
this.logger.error(`Error handling file change for ${relativePath}: ${error.message}`);
|
|
19848
19966
|
}
|
|
19849
19967
|
});
|
|
19850
19968
|
await this.fileWatcher.start(this.currentBranch);
|
|
@@ -19853,9 +19971,9 @@ print(json.dumps({"issues": issues}))
|
|
|
19853
19971
|
await new Promise(()=>{});
|
|
19854
19972
|
}
|
|
19855
19973
|
handleFileWatcherBranchChange(newBranch) {
|
|
19856
|
-
if (this.isSwitchingForEnvironment && newBranch === this.environmentSwitchTargetBranch) return void
|
|
19974
|
+
if (this.isSwitchingForEnvironment && newBranch === this.environmentSwitchTargetBranch) return void this.logger.debug(`Ignoring FileWatcher branch-change during environment switch: ${newBranch}`);
|
|
19857
19975
|
const oldBranch = this.currentBranch;
|
|
19858
|
-
|
|
19976
|
+
this.logger.verbose(" Pausing sync for 2 seconds to allow branch to settle...");
|
|
19859
19977
|
this.currentBranch = newBranch;
|
|
19860
19978
|
this.lastBranchChangeTime = Date.now();
|
|
19861
19979
|
this.wsClient?.updateBranch(newBranch);
|
|
@@ -19881,7 +19999,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19881
19999
|
const status = await this.gitService.getStatus();
|
|
19882
20000
|
this.lastLocalStatusFingerprint = this.getLocalStatusFingerprint(status);
|
|
19883
20001
|
} catch (error) {
|
|
19884
|
-
|
|
20002
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[Session ${this.sessionId}]`, `Failed to initialize local change fingerprint: ${error.message}`));
|
|
19885
20003
|
}
|
|
19886
20004
|
}
|
|
19887
20005
|
startLocalChangeFallbackPolling() {
|
|
@@ -19903,12 +20021,12 @@ print(json.dumps({"issues": issues}))
|
|
|
19903
20021
|
if (fingerprint !== this.lastLocalStatusFingerprint) {
|
|
19904
20022
|
this.lastLocalStatusFingerprint = fingerprint;
|
|
19905
20023
|
if (fingerprint) {
|
|
19906
|
-
|
|
20024
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[Session ${this.sessionId}]`, "Detected local change via fallback status poll"));
|
|
19907
20025
|
this.saveProcessor?.queueSave();
|
|
19908
20026
|
}
|
|
19909
20027
|
}
|
|
19910
20028
|
} catch (error) {
|
|
19911
|
-
|
|
20029
|
+
this.logger.debug((0, external_node_util_namespaceObject.format)(`[Session ${this.sessionId}]`, `Fallback status poll failed: ${error.message}`));
|
|
19912
20030
|
} finally{
|
|
19913
20031
|
this.isPollingLocalChanges = false;
|
|
19914
20032
|
}
|
|
@@ -19937,11 +20055,11 @@ print(json.dumps({"issues": issues}))
|
|
|
19937
20055
|
}
|
|
19938
20056
|
async handleFileChange(event, filePath, relativePath) {
|
|
19939
20057
|
if (this.isCleanedUp || this.isPausedForUserInput) return;
|
|
19940
|
-
|
|
20058
|
+
this.logger.verbose("File changed: " + relativePath);
|
|
19941
20059
|
if (!this.isSettlePeriodOver()) return;
|
|
19942
20060
|
if (relativePath.startsWith("server_code/") || relativePath.startsWith("client_code/")) {
|
|
19943
20061
|
const didRename = await this.handlePythonification(filePath, relativePath);
|
|
19944
|
-
if (didRename) return void
|
|
20062
|
+
if (didRename) return void this.logger.verbose(" Pythonified - waiting for new watch event");
|
|
19945
20063
|
}
|
|
19946
20064
|
this.saveProcessor?.queueSave();
|
|
19947
20065
|
}
|
|
@@ -19980,7 +20098,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19980
20098
|
const pythonified = pythonifyName(dirName);
|
|
19981
20099
|
if (dirName !== pythonified) {
|
|
19982
20100
|
const newPath = external_path_default().join(external_path_default().dirname(absolutePath), pythonified);
|
|
19983
|
-
|
|
20101
|
+
this.logger.verbose(`Renaming directory: ${relativePath} → ${external_path_default().relative(this.repoPath, newPath)}`);
|
|
19984
20102
|
await external_fs_.promises.rename(absolutePath, newPath);
|
|
19985
20103
|
return true;
|
|
19986
20104
|
}
|
|
@@ -19992,7 +20110,7 @@ print(json.dumps({"issues": issues}))
|
|
|
19992
20110
|
const pythonified = pythonifyName(fileName);
|
|
19993
20111
|
if (fileName !== pythonified) {
|
|
19994
20112
|
const newPath = external_path_default().join(external_path_default().dirname(absolutePath), pythonified + ".py");
|
|
19995
|
-
|
|
20113
|
+
this.logger.verbose(`Renaming file: ${relativePath} → ${external_path_default().relative(this.repoPath, newPath)}`);
|
|
19996
20114
|
await external_fs_.promises.rename(absolutePath, newPath);
|
|
19997
20115
|
return true;
|
|
19998
20116
|
}
|
|
@@ -20024,8 +20142,9 @@ print(json.dumps({"issues": issues}))
|
|
|
20024
20142
|
};
|
|
20025
20143
|
}
|
|
20026
20144
|
async function validation_validateBranchSyncStatus(git, branchName, options) {
|
|
20145
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
20027
20146
|
const { appId, anvilUrl, gitUrl = anvilUrl, username } = options;
|
|
20028
|
-
|
|
20147
|
+
logger.verbose("Checking branch sync status...");
|
|
20029
20148
|
let authToken;
|
|
20030
20149
|
try {
|
|
20031
20150
|
authToken = await auth_getValidAuthToken(anvilUrl, username);
|
|
@@ -20036,14 +20155,16 @@ print(json.dumps({"issues": issues}))
|
|
|
20036
20155
|
return await validateViaGitFetch(git, branchName, {
|
|
20037
20156
|
appId,
|
|
20038
20157
|
gitUrl,
|
|
20039
|
-
authToken
|
|
20158
|
+
authToken,
|
|
20159
|
+
logger
|
|
20040
20160
|
});
|
|
20041
20161
|
} catch (e) {
|
|
20042
|
-
|
|
20162
|
+
logger.verbose("Git fetch failed, trying server validation...");
|
|
20043
20163
|
return validateViaAnvilServer(git, branchName, options);
|
|
20044
20164
|
}
|
|
20045
20165
|
}
|
|
20046
20166
|
async function validateViaGitFetch(git, branchName, options) {
|
|
20167
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
20047
20168
|
const { appId, gitUrl, authToken } = options;
|
|
20048
20169
|
const baseUrl = new URL(gitUrl);
|
|
20049
20170
|
const encodedToken = encodeURIComponent(authToken);
|
|
@@ -20055,7 +20176,7 @@ print(json.dumps({"issues": issues}))
|
|
|
20055
20176
|
const host = baseUrl.hostname + (baseUrl.port ? `:${baseUrl.port}` : "");
|
|
20056
20177
|
const httpUrl = `${baseUrl.protocol}//git:${encodedToken}@${host}${gitPath}?${searchParams.toString()}`;
|
|
20057
20178
|
try {
|
|
20058
|
-
|
|
20179
|
+
logger.verbose("Fetching latest from Anvil...");
|
|
20059
20180
|
const tempRef = `anvil-sync-temp-${Date.now()}`;
|
|
20060
20181
|
await git.fetch([
|
|
20061
20182
|
httpUrl,
|
|
@@ -20099,15 +20220,16 @@ print(json.dumps({"issues": issues}))
|
|
|
20099
20220
|
upstreamRef: branchName,
|
|
20100
20221
|
diverged: false
|
|
20101
20222
|
};
|
|
20102
|
-
|
|
20223
|
+
logger.verbose(`✔ Branch '${branchName}' is up-to-date with Anvil.`);
|
|
20103
20224
|
return null;
|
|
20104
20225
|
} catch (e) {
|
|
20105
20226
|
throw errors_createGitError.fetchFailed(e.message);
|
|
20106
20227
|
}
|
|
20107
20228
|
}
|
|
20108
20229
|
async function validateViaAnvilServer(git, branchName, options) {
|
|
20230
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
20109
20231
|
const { appId, anvilUrl, username } = options;
|
|
20110
|
-
|
|
20232
|
+
logger.verbose("Validating sync status with Anvil server...");
|
|
20111
20233
|
const authToken = await auth_getValidAuthToken(anvilUrl, username);
|
|
20112
20234
|
let commitId;
|
|
20113
20235
|
try {
|
|
@@ -20133,8 +20255,8 @@ print(json.dumps({"issues": issues}))
|
|
|
20133
20255
|
const data = await resp.json();
|
|
20134
20256
|
const matchingApp = data.apps?.find((app)=>app.app_id === appId);
|
|
20135
20257
|
if (matchingApp) {
|
|
20136
|
-
|
|
20137
|
-
|
|
20258
|
+
logger.info(`Anvil server recognizes commit ${commitId.substring(0, 8)} for app ${appId}`);
|
|
20259
|
+
logger.verbose(" You appear to be in sync with Anvil server");
|
|
20138
20260
|
return null;
|
|
20139
20261
|
}
|
|
20140
20262
|
const allBranches = data.apps?.flatMap((app)=>app.branches || []) || [];
|
|
@@ -20409,8 +20531,6 @@ print(json.dumps({"issues": issues}))
|
|
|
20409
20531
|
}
|
|
20410
20532
|
};
|
|
20411
20533
|
}
|
|
20412
|
-
require("inquirer");
|
|
20413
|
-
require("ora");
|
|
20414
20534
|
class CreateCheckoutError extends Error {
|
|
20415
20535
|
created;
|
|
20416
20536
|
constructor(message, created, options){
|
|
@@ -21220,6 +21340,8 @@ print(json.dumps({"issues": issues}))
|
|
|
21220
21340
|
"HEAD"
|
|
21221
21341
|
])).trim();
|
|
21222
21342
|
const session = new WatchSession_WatchSession(repoPath, appId, {
|
|
21343
|
+
logger: options.logger,
|
|
21344
|
+
progress: options.progress,
|
|
21223
21345
|
anvilUrl,
|
|
21224
21346
|
gitUrl,
|
|
21225
21347
|
authToken,
|
|
@@ -21240,6 +21362,7 @@ print(json.dumps({"issues": issues}))
|
|
|
21240
21362
|
}
|
|
21241
21363
|
}
|
|
21242
21364
|
async function src_api_watch(repoPath, appId, options = {}) {
|
|
21365
|
+
const logger = options.logger ?? reporting_silentLogger;
|
|
21243
21366
|
repoPath = external_path_default().resolve(repoPath);
|
|
21244
21367
|
auth_setRepoContext(repoPath);
|
|
21245
21368
|
const anvilUrl = options.anvilUrl ?? await auth_resolveAuthAnvilUrl();
|
|
@@ -21301,13 +21424,14 @@ print(json.dumps({"issues": issues}))
|
|
|
21301
21424
|
"HEAD"
|
|
21302
21425
|
])).trim();
|
|
21303
21426
|
} else throw errors_createGitError.commandFailed("revparse", `Environment ${environment.envPid} is on branch '${environmentBranch}', but the local checkout is on '${currentBranch}'.`);
|
|
21304
|
-
|
|
21305
|
-
|
|
21427
|
+
logger.verbose("Current branch: " + currentBranch);
|
|
21428
|
+
logger.verbose("Current commit ID: " + commitId);
|
|
21306
21429
|
const syncStatus = await validation_validateBranchSyncStatus(git, currentBranch, {
|
|
21307
21430
|
appId,
|
|
21308
21431
|
anvilUrl,
|
|
21309
21432
|
gitUrl,
|
|
21310
|
-
username
|
|
21433
|
+
username,
|
|
21434
|
+
logger
|
|
21311
21435
|
});
|
|
21312
21436
|
let hasUncommittedChanges = false;
|
|
21313
21437
|
try {
|
|
@@ -21316,8 +21440,10 @@ print(json.dumps({"issues": issues}))
|
|
|
21316
21440
|
} catch (e) {
|
|
21317
21441
|
throw errors_createGitError.commandFailed("status", e.message);
|
|
21318
21442
|
}
|
|
21319
|
-
|
|
21443
|
+
logger.verbose("Has uncommitted changes: " + hasUncommittedChanges);
|
|
21320
21444
|
const session = new WatchSession_WatchSession(repoPath, appId, {
|
|
21445
|
+
logger: options.logger,
|
|
21446
|
+
progress: options.progress,
|
|
21321
21447
|
anvilUrl,
|
|
21322
21448
|
gitUrl,
|
|
21323
21449
|
authToken,
|
|
@@ -21330,22 +21456,22 @@ print(json.dumps({"issues": issues}))
|
|
|
21330
21456
|
dependencyWatch: options.dependencyWatch ?? true
|
|
21331
21457
|
});
|
|
21332
21458
|
session.on("branch-changed", (data)=>{
|
|
21333
|
-
|
|
21459
|
+
logger.debug((0, external_node_util_namespaceObject.format)("Event: branch-changed", data));
|
|
21334
21460
|
});
|
|
21335
21461
|
session.on("sync-conflict", (data)=>{
|
|
21336
|
-
|
|
21462
|
+
logger.debug((0, external_node_util_namespaceObject.format)("Event: sync-conflict", data));
|
|
21337
21463
|
});
|
|
21338
21464
|
session.on("remote-update", (data)=>{
|
|
21339
|
-
|
|
21465
|
+
logger.debug((0, external_node_util_namespaceObject.format)("Event: remote-update", data));
|
|
21340
21466
|
});
|
|
21341
21467
|
session.on("validation-failed", (data)=>{
|
|
21342
|
-
|
|
21468
|
+
logger.debug((0, external_node_util_namespaceObject.format)("Event: validation-failed", data));
|
|
21343
21469
|
});
|
|
21344
21470
|
session.on("save-complete", (data)=>{
|
|
21345
|
-
|
|
21471
|
+
logger.debug((0, external_node_util_namespaceObject.format)("Event: save-complete", data));
|
|
21346
21472
|
});
|
|
21347
21473
|
session.on("save-started", (data)=>{
|
|
21348
|
-
|
|
21474
|
+
logger.debug((0, external_node_util_namespaceObject.format)("Event: save-started", data));
|
|
21349
21475
|
});
|
|
21350
21476
|
try {
|
|
21351
21477
|
await session.initialize();
|