@gadicc/loom 1.35.1 → 1.35.2
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 +36 -18
- package/esm/src/cli/legacyManagedOutputs.d.ts +33 -0
- package/esm/src/cli/legacyManagedOutputs.d.ts.map +1 -0
- package/esm/src/cli/legacyManagedOutputs.js +260 -0
- package/esm/src/cli/managedFiles.d.ts +131 -0
- package/esm/src/cli/managedFiles.d.ts.map +1 -0
- package/esm/src/cli/managedFiles.js +524 -0
- package/esm/src/cli/mod.d.ts +14 -0
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +618 -168
- package/esm/src/cli/projectTooling.d.ts +8 -0
- package/esm/src/cli/projectTooling.d.ts.map +1 -1
- package/esm/src/cli/projectTooling.js +47 -0
- package/package.json +2 -2
- package/script/src/cli/legacyManagedOutputs.d.ts +33 -0
- package/script/src/cli/legacyManagedOutputs.d.ts.map +1 -0
- package/script/src/cli/legacyManagedOutputs.js +266 -0
- package/script/src/cli/managedFiles.d.ts +131 -0
- package/script/src/cli/managedFiles.d.ts.map +1 -0
- package/script/src/cli/managedFiles.js +536 -0
- package/script/src/cli/mod.d.ts +14 -0
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +617 -167
- package/script/src/cli/projectTooling.d.ts +8 -0
- package/script/src/cli/projectTooling.d.ts.map +1 -1
- package/script/src/cli/projectTooling.js +49 -0
- package/skills/loom/SKILL.md +15 -1
- package/skills/loom-db/SKILL.md +4 -1
- package/skills/loom-db/references/db-stack.md +4 -1
package/script/src/cli/mod.js
CHANGED
|
@@ -86,6 +86,8 @@ const releaseConfig_js_1 = require("./releaseConfig.js");
|
|
|
86
86
|
const releaseCredentials_js_1 = require("./releaseCredentials.js");
|
|
87
87
|
const releaseTrustCommand_js_1 = require("./releaseTrustCommand.js");
|
|
88
88
|
const localDb_js_1 = require("./localDb.js");
|
|
89
|
+
const managedFiles_js_1 = require("./managedFiles.js");
|
|
90
|
+
const legacyManagedOutputs_js_1 = require("./legacyManagedOutputs.js");
|
|
89
91
|
const betterAuth_js_1 = require("../apiKeys/betterAuth.js");
|
|
90
92
|
const retention_js_1 = require("../apiKeys/retention.js");
|
|
91
93
|
const projectSkills_js_1 = require("./projectSkills.js");
|
|
@@ -390,6 +392,62 @@ async function writeTextIfChanged(path, text) {
|
|
|
390
392
|
await (0, promises_1.writeFile)(path, text, "utf8");
|
|
391
393
|
return true;
|
|
392
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Writes loom.json when its data changed, ignoring key order. An existing
|
|
397
|
+
* file is patched member by member, so the consumer's formatting and key
|
|
398
|
+
* order survive and a formatter such as Biome has nothing to change; only a
|
|
399
|
+
* new file is written whole.
|
|
400
|
+
*/
|
|
401
|
+
async function writeManifestIfChanged(cwd, manifest) {
|
|
402
|
+
const path = (0, node_path_1.join)(cwd, "loom.json");
|
|
403
|
+
const currentText = await readTextIfExists(path);
|
|
404
|
+
if (currentText === null) {
|
|
405
|
+
await (0, promises_1.writeFile)(path, stringifyJson(manifest), "utf8");
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
if ((0, projectTooling_js_1.jsonValuesEqual)(parseJson(currentText, "loom.json"), manifest)) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
await (0, promises_1.writeFile)(path, (0, projectTooling_js_1.patchJsonText)(currentText, manifest), "utf8");
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
function recordedManagedFileHash(feature, relativePath) {
|
|
415
|
+
return feature?.managedFiles?.[relativePath];
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Notes one managed-file sync in `records`: Loom's hash when the file now
|
|
419
|
+
* holds or matches Loom output, otherwise the previous record, so the file is
|
|
420
|
+
* recognised again if its local edits are reverted.
|
|
421
|
+
*/
|
|
422
|
+
function recordManagedFileSync(records, feature, relativePath, result) {
|
|
423
|
+
const hash = result.hash ?? recordedManagedFileHash(feature, relativePath);
|
|
424
|
+
if (hash)
|
|
425
|
+
records[relativePath] = hash;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Reports a managed file Loom left alone because it has local edits, naming
|
|
429
|
+
* the file, the difference and how to resolve it.
|
|
430
|
+
*/
|
|
431
|
+
function formatPreservedManagedFileNote(relativePath, difference, resolution) {
|
|
432
|
+
return `Preserved local edits in Loom-managed ${relativePath}${difference ? ` (${difference})` : ""}; Loom did not update it. ${resolution}`;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Replaces a feature's managed-file or managed-task record with what this
|
|
436
|
+
* sync manages, sorted so loom.json stays stable. Entries Loom no longer
|
|
437
|
+
* manages drop out.
|
|
438
|
+
*/
|
|
439
|
+
function setManagedRecords(feature, key, records) {
|
|
440
|
+
const entries = Object.entries(records).sort(([left], [right]) => left.localeCompare(right));
|
|
441
|
+
if (entries.length) {
|
|
442
|
+
feature[key] = Object.fromEntries(entries);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
delete feature[key];
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function setManagedFileRecords(feature, records) {
|
|
449
|
+
setManagedRecords(feature, "managedFiles", records);
|
|
450
|
+
}
|
|
393
451
|
async function defaultCommandRunner(command, args, options) {
|
|
394
452
|
return await new Promise((resolvePromise) => {
|
|
395
453
|
const inherit = options.stdio === "inherit" ||
|
|
@@ -578,7 +636,7 @@ function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
|
578
636
|
return (scriptName === "job" || scriptCommand.includes("jobDirect.ts")) &&
|
|
579
637
|
!scriptUsesLoomEnvRunner(scriptCommand);
|
|
580
638
|
}
|
|
581
|
-
async function checkEnvRunnerAdoption(cwd, manifest) {
|
|
639
|
+
async function checkEnvRunnerAdoption(cwd, manifest, framework) {
|
|
582
640
|
const issues = [];
|
|
583
641
|
const suggestions = new Set();
|
|
584
642
|
const activeDb = manifest.features.db?.status === "active";
|
|
@@ -595,23 +653,53 @@ async function checkEnvRunnerAdoption(cwd, manifest) {
|
|
|
595
653
|
}
|
|
596
654
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
597
655
|
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
656
|
+
// `loom add` refreshes only tasks whose value is provably Loom's; an edited
|
|
657
|
+
// task has to be moved onto `loom env` by hand.
|
|
658
|
+
const loomTasks = new Map();
|
|
659
|
+
if (activeDb) {
|
|
660
|
+
const dbConfig = mergeDbConfig(framework, manifest.features.db.config);
|
|
661
|
+
for (const task of getDbManagedTasks(dbConfig, tooling)) {
|
|
662
|
+
loomTasks.set(task.name, [manifest.features.db, task]);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (activeJobs) {
|
|
666
|
+
const jobsConfig = mergeJobsConfig(framework, manifest.features.jobs.config);
|
|
667
|
+
for (const task of getJobsManagedTasks(jobsConfig)) {
|
|
668
|
+
loomTasks.set(task.name, [manifest.features.jobs, task]);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
const loomRefreshes = (name, definition) => {
|
|
672
|
+
const entry = loomTasks.get(name);
|
|
673
|
+
if (!entry)
|
|
674
|
+
return false;
|
|
675
|
+
const [feature, task] = entry;
|
|
676
|
+
return (0, managedFiles_js_1.classifyManagedTask)(definition, task.definition, {
|
|
677
|
+
knownValues: task.knownValues,
|
|
678
|
+
recordedHash: feature.managedTasks?.[name],
|
|
679
|
+
}).state !== "customized";
|
|
680
|
+
};
|
|
681
|
+
const handEditSuggestion = (name) => `Loom does not overwrite edited tasks: change ${name} in ${taskStore.config} to run its command through \`loom env -- <command>\`.`;
|
|
598
682
|
for (const [scriptName, definition] of Object.entries(taskStore.definitions)) {
|
|
599
683
|
const scriptCommand = (0, projectTooling_js_1.getTaskCommand)(definition);
|
|
600
684
|
if (activeDb && dbScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
601
685
|
issues.push(taskStore.config === "package.json"
|
|
602
686
|
? `DB package.json script bypasses the Loom env runner: ${scriptName}`
|
|
603
687
|
: `DB task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
604
|
-
suggestions.add(
|
|
605
|
-
?
|
|
606
|
-
:
|
|
688
|
+
suggestions.add(!loomRefreshes(scriptName, definition)
|
|
689
|
+
? handEditSuggestion(scriptName)
|
|
690
|
+
: taskStore.config === "package.json"
|
|
691
|
+
? "Run `loom add db` to refresh DB package scripts."
|
|
692
|
+
: "Run `loom add db` to refresh DB tasks.");
|
|
607
693
|
}
|
|
608
694
|
if (activeJobs && jobsScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
609
695
|
issues.push(taskStore.config === "package.json"
|
|
610
696
|
? `Jobs package.json script bypasses the Loom env runner: ${scriptName}`
|
|
611
697
|
: `Jobs task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
612
|
-
suggestions.add(
|
|
613
|
-
?
|
|
614
|
-
:
|
|
698
|
+
suggestions.add(!loomRefreshes(scriptName, definition)
|
|
699
|
+
? handEditSuggestion(scriptName)
|
|
700
|
+
: taskStore.config === "package.json"
|
|
701
|
+
? "Run `loom add jobs` to refresh jobs package scripts."
|
|
702
|
+
: "Run `loom add jobs` to refresh jobs tasks.");
|
|
615
703
|
}
|
|
616
704
|
}
|
|
617
705
|
return {
|
|
@@ -1145,25 +1233,89 @@ function ensurePackageJsonDependency(packageJson, versionRange = exports.DEFAULT
|
|
|
1145
1233
|
async function getProjectTooling(cwd, manifest) {
|
|
1146
1234
|
return await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest.project?.tooling);
|
|
1147
1235
|
}
|
|
1148
|
-
|
|
1236
|
+
function formatTaskValue(definition) {
|
|
1237
|
+
return `\`${typeof definition === "string" ? definition : JSON.stringify(definition)}\``;
|
|
1238
|
+
}
|
|
1239
|
+
/** Shows a kept task's local value next to Loom's value. */
|
|
1240
|
+
function formatCustomizedTaskValues({ current, task }) {
|
|
1241
|
+
return `(local: ${formatTaskValue(current)}; Loom: ${formatTaskValue(task.definition)})`;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Creates missing Loom-owned tasks and updates those whose value is provably
|
|
1245
|
+
* Loom's (recorded hash, current value or a known earlier value), through
|
|
1246
|
+
* localized edits of the config `project.tooling` records. Edited tasks are
|
|
1247
|
+
* left alone and returned so the caller can report them.
|
|
1248
|
+
*/
|
|
1249
|
+
async function syncManagedTasks(cwd, manifest, feature, tasks) {
|
|
1149
1250
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
1150
1251
|
const changedKeys = [];
|
|
1151
|
-
|
|
1152
|
-
|
|
1252
|
+
const customized = [];
|
|
1253
|
+
const records = {};
|
|
1254
|
+
for (const task of tasks) {
|
|
1255
|
+
const store = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
1256
|
+
const current = store.definitions[task.name];
|
|
1257
|
+
const classification = (0, managedFiles_js_1.classifyManagedTask)(current, task.definition, {
|
|
1258
|
+
knownValues: task.knownValues,
|
|
1259
|
+
recordedHash: feature?.managedTasks?.[task.name],
|
|
1260
|
+
});
|
|
1261
|
+
if (classification.state === "customized") {
|
|
1262
|
+
customized.push({ current, task });
|
|
1263
|
+
const previous = feature?.managedTasks?.[task.name];
|
|
1264
|
+
if (previous)
|
|
1265
|
+
records[task.name] = previous;
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
records[task.name] = classification.expectedHash;
|
|
1269
|
+
// A value that matches apart from whitespace keeps the app's spelling.
|
|
1270
|
+
if (classification.state === "current")
|
|
1271
|
+
continue;
|
|
1272
|
+
const result = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, {
|
|
1273
|
+
definition: task.definition,
|
|
1274
|
+
name: task.name,
|
|
1275
|
+
});
|
|
1153
1276
|
if (result.changed)
|
|
1154
|
-
changedKeys.push(name);
|
|
1277
|
+
changedKeys.push(task.name);
|
|
1155
1278
|
}
|
|
1156
|
-
return { changedKeys, config: tooling.tasks.config,
|
|
1279
|
+
return { changedKeys, config: tooling.tasks.config, customized, records };
|
|
1157
1280
|
}
|
|
1158
|
-
|
|
1281
|
+
/**
|
|
1282
|
+
* Compares Loom-owned tasks with Loom's values without writing: `mismatches`
|
|
1283
|
+
* are missing tasks or unedited older Loom values that `loom add` updates;
|
|
1284
|
+
* `customized` tasks have edits Loom will not overwrite.
|
|
1285
|
+
*/
|
|
1286
|
+
async function checkManagedTasks(cwd, manifest, feature, tasks) {
|
|
1159
1287
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
1160
1288
|
const store = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
store
|
|
1165
|
-
|
|
1166
|
-
|
|
1289
|
+
const mismatches = [];
|
|
1290
|
+
const customized = [];
|
|
1291
|
+
for (const task of tasks) {
|
|
1292
|
+
const current = store.definitions[task.name];
|
|
1293
|
+
const { state } = (0, managedFiles_js_1.classifyManagedTask)(current, task.definition, {
|
|
1294
|
+
knownValues: task.knownValues,
|
|
1295
|
+
recordedHash: feature?.managedTasks?.[task.name],
|
|
1296
|
+
});
|
|
1297
|
+
if (state === "customized") {
|
|
1298
|
+
customized.push({ current, task });
|
|
1299
|
+
}
|
|
1300
|
+
else if (state !== "current") {
|
|
1301
|
+
mismatches.push(task.name);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
return { config: tooling.tasks.config, customized, mismatches, store };
|
|
1305
|
+
}
|
|
1306
|
+
/** Notes for Loom-owned tasks that `loom init` or `loom add` left alone. */
|
|
1307
|
+
function formatPreservedTaskNotes(sync, featureKey) {
|
|
1308
|
+
return sync.customized.map((customized) => `Preserved local edits in Loom-managed task ${customized.task.name} in ${sync.config} ${formatCustomizedTaskValues(customized)}; Loom did not update it. To restore Loom's value, delete the task and rerun \`loom add ${featureKey}\`.`);
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* `loom check` warnings for Loom-owned tasks with local edits, naming each
|
|
1312
|
+
* task and showing both values.
|
|
1313
|
+
*/
|
|
1314
|
+
function addCustomizedTaskWarnings(check, featureKey, warnings, suggestions) {
|
|
1315
|
+
for (const customized of check.customized) {
|
|
1316
|
+
warnings.push(`Loom-managed task ${customized.task.name} in ${check.config} has local edits that Loom will not overwrite ${formatCustomizedTaskValues(customized)}`);
|
|
1317
|
+
suggestions.add(`To restore Loom's value for an edited ${featureKey} task, delete the task and rerun \`loom add ${featureKey}\`.`);
|
|
1318
|
+
}
|
|
1167
1319
|
}
|
|
1168
1320
|
function buildManifest(cwd, packageJson, framework, existingManifest, tooling) {
|
|
1169
1321
|
return {
|
|
@@ -1509,6 +1661,14 @@ function getDbExpectedScripts(config, tooling) {
|
|
|
1509
1661
|
"schema:gen": "loom db schema-gen",
|
|
1510
1662
|
};
|
|
1511
1663
|
}
|
|
1664
|
+
function getDbManagedTasks(config, tooling) {
|
|
1665
|
+
const legacy = (0, legacyManagedOutputs_js_1.legacyDbTaskValues)(config.modules.drizzleConfig);
|
|
1666
|
+
return Object.entries(getDbExpectedScripts(config, tooling)).map(([name, definition]) => ({
|
|
1667
|
+
definition,
|
|
1668
|
+
knownValues: legacy[name] ?? [],
|
|
1669
|
+
name,
|
|
1670
|
+
}));
|
|
1671
|
+
}
|
|
1512
1672
|
function mergeDbConfig(framework, featureConfig) {
|
|
1513
1673
|
const defaults = getDbConfig(framework);
|
|
1514
1674
|
return {
|
|
@@ -3167,6 +3327,15 @@ function compareParsedVersions(left, right) {
|
|
|
3167
3327
|
}
|
|
3168
3328
|
return left.prerelease.localeCompare(right.prerelease);
|
|
3169
3329
|
}
|
|
3330
|
+
/**
|
|
3331
|
+
* Whether `version` is a newer release than the exact pin `pinned`. Pin
|
|
3332
|
+
* advice must never suggest moving an app back to an older Loom.
|
|
3333
|
+
*/
|
|
3334
|
+
function isNewerLoomVersion(version, pinned) {
|
|
3335
|
+
const candidate = parseSemverTag(version);
|
|
3336
|
+
const pin = parseSemverTag(pinned);
|
|
3337
|
+
return !!candidate && !!pin && compareParsedVersions(candidate, pin) > 0;
|
|
3338
|
+
}
|
|
3170
3339
|
async function findPublishedLoomPublicationForCommit(sourceRoot, sourceCommit, commandRunner, env, preferredSpec,
|
|
3171
3340
|
/** Names the commit in refusals, such as "Loom commit abc, which built X,". */
|
|
3172
3341
|
subject) {
|
|
@@ -4073,8 +4242,17 @@ async function usePublishedDevPackageLocked(cwd, options) {
|
|
|
4073
4242
|
lockfileText,
|
|
4074
4243
|
preferredSpec: publishedSpec,
|
|
4075
4244
|
});
|
|
4076
|
-
publishedSpec = proof.publication.version;
|
|
4077
4245
|
notes.push(proof.note);
|
|
4246
|
+
// Never move an exact pin back: a checkout without the newest tags names
|
|
4247
|
+
// the oldest release it knows that covers the build, and a newer pin
|
|
4248
|
+
// (Loom releases only from main) covers it too.
|
|
4249
|
+
if (isExactSemverVersion(publishedSpec) &&
|
|
4250
|
+
isNewerLoomVersion(publishedSpec, proof.publication.version)) {
|
|
4251
|
+
notes.push(`The pinned ${exports.LOOM_DEPENDENCY}@${publishedSpec} is newer than ${proof.publication.version}, so the pin stays at ${publishedSpec}.`);
|
|
4252
|
+
}
|
|
4253
|
+
else {
|
|
4254
|
+
publishedSpec = proof.publication.version;
|
|
4255
|
+
}
|
|
4078
4256
|
}
|
|
4079
4257
|
const changedFiles = [];
|
|
4080
4258
|
let catalogChanged = false;
|
|
@@ -4657,7 +4835,7 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
4657
4835
|
await exists(devState.sourceRoot)) {
|
|
4658
4836
|
const publication = await resolveLoomCommitPublication(devState.sourceRoot, devState.sourceCommit, options.commandRunner, options.env, dependency);
|
|
4659
4837
|
if (publication.status === "published" &&
|
|
4660
|
-
publication.version
|
|
4838
|
+
isNewerLoomVersion(publication.version, dependency)) {
|
|
4661
4839
|
warnings.push(`This app was last synced against Loom commit ${shortCommit}; ${publication.reason === "package-equivalent"
|
|
4662
4840
|
? `package-relevant files match ${exports.LOOM_DEPENDENCY}@${publication.version}`
|
|
4663
4841
|
: `it is published as ${exports.LOOM_DEPENDENCY}@${publication.version}`}, but ${pinLocation} is pinned to ${dependency}.`);
|
|
@@ -4691,9 +4869,17 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
4691
4869
|
addReleaseCheckMessage(issues, warnings, recordGatesRelease, `This app was last synced against Loom commit ${shortCommit}, but no published Loom version contains that commit or matches its package-relevant files.`);
|
|
4692
4870
|
suggestions.add("Publish Loom first, fetch tags, then rerun `loom dev published`.");
|
|
4693
4871
|
break;
|
|
4694
|
-
case "published":
|
|
4695
|
-
|
|
4696
|
-
|
|
4872
|
+
case "published": {
|
|
4873
|
+
// Advice only ever moves the pin forward. A checkout without the
|
|
4874
|
+
// newest tags reports the oldest release it knows that contains
|
|
4875
|
+
// the commit; an exact pin newer than that covers it too.
|
|
4876
|
+
const pinCovers = !!dependency &&
|
|
4877
|
+
isExactSemverVersion(dependency) &&
|
|
4878
|
+
!isNewerLoomVersion(publication.version, dependency);
|
|
4879
|
+
const coveringVersion = pinCovers && dependency
|
|
4880
|
+
? dependency
|
|
4881
|
+
: publication.version;
|
|
4882
|
+
if (dependency && isExactSemverVersion(dependency) && !pinCovers) {
|
|
4697
4883
|
const publicationDescription = publication.reason ===
|
|
4698
4884
|
"package-equivalent"
|
|
4699
4885
|
? `package-relevant files match ${exports.LOOM_DEPENDENCY}@${publication.version}`
|
|
@@ -4708,16 +4894,20 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
4708
4894
|
"package-equivalent"
|
|
4709
4895
|
? `has no package-relevant changes after ${publication.tag}, so ${exports.LOOM_DEPENDENCY}@${publication.version} covers it`
|
|
4710
4896
|
: `is published as ${exports.LOOM_DEPENDENCY}@${publication.version}`;
|
|
4711
|
-
|
|
4897
|
+
const newerPin = coveringVersion !== publication.version
|
|
4898
|
+
? ` (the pinned ${coveringVersion} is newer)`
|
|
4899
|
+
: "";
|
|
4900
|
+
warnings.push(`The synced Loom commit ${shortCommit} ${publicationDescription}${newerPin}; refresh the lockfile away from ${localLockfileResolution}.`);
|
|
4712
4901
|
suggestions.add(pnpmOverrideActive
|
|
4713
4902
|
? "Run `loom dev published`, which pins the covering version, then run `pnpm install`."
|
|
4714
|
-
: catalogName && dependency ===
|
|
4903
|
+
: catalogName && dependency === coveringVersion
|
|
4715
4904
|
// pnpm keeps a local resolution while the catalog version
|
|
4716
4905
|
// it was linked under is unchanged.
|
|
4717
4906
|
? "Restore pnpm-lock.yaml from git and run `pnpm install`."
|
|
4718
|
-
: pinSuggestion(
|
|
4907
|
+
: pinSuggestion(coveringVersion));
|
|
4719
4908
|
}
|
|
4720
4909
|
break;
|
|
4910
|
+
}
|
|
4721
4911
|
}
|
|
4722
4912
|
}
|
|
4723
4913
|
}
|
|
@@ -5796,9 +5986,16 @@ function getJobsExpectedScripts(config) {
|
|
|
5796
5986
|
job: `TSX_TSCONFIG=./${JOBS_SCRIPTS_TSCONFIG_PATH} loom env -- node --conditions=react-server --import tsx ${config.directRunner.scriptPath}`,
|
|
5797
5987
|
};
|
|
5798
5988
|
}
|
|
5799
|
-
function
|
|
5989
|
+
function getJobsManagedTasks(config) {
|
|
5990
|
+
const legacy = (0, legacyManagedOutputs_js_1.legacyJobsTaskValues)(JOBS_SCRIPTS_TSCONFIG_PATH, config.directRunner.scriptPath);
|
|
5991
|
+
return Object.entries(getJobsExpectedScripts(config)).map(([name, definition]) => ({ definition, knownValues: legacy[name] ?? [], name }));
|
|
5992
|
+
}
|
|
5993
|
+
function getJobsDirectRunnerCatalogImportPath(config, framework) {
|
|
5800
5994
|
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
5801
|
-
|
|
5995
|
+
return toRelativeImportPath(config.directRunner.scriptPath, `${jobsRoot}/index.ts`);
|
|
5996
|
+
}
|
|
5997
|
+
function jobsDirectRunnerTemplate(config, framework) {
|
|
5998
|
+
const catalogImportPath = getJobsDirectRunnerCatalogImportPath(config, framework);
|
|
5802
5999
|
return `import {
|
|
5803
6000
|
createJobCatalogFromSource,
|
|
5804
6001
|
createJobExecution,
|
|
@@ -5928,24 +6125,64 @@ function jobsThinRouteTemplate(source) {
|
|
|
5928
6125
|
export const maxDuration = ${DEFAULT_JOBS_MAX_DURATION_SECONDS};
|
|
5929
6126
|
`;
|
|
5930
6127
|
}
|
|
5931
|
-
function
|
|
5932
|
-
if (!config.staticRoutes) {
|
|
5933
|
-
throw new Error("Static jobs route config is required");
|
|
5934
|
-
}
|
|
6128
|
+
function renderJobsStaticRoute(values) {
|
|
5935
6129
|
return `${LOOM_MANAGED_STATIC_JOB_ROUTE_MARKER}
|
|
5936
6130
|
// Generated by \`loom add jobs\` from loom.json. Do not edit directly.
|
|
5937
6131
|
|
|
5938
|
-
import { ${
|
|
5939
|
-
import * as job from "${moduleSpecifier}";
|
|
6132
|
+
import { ${values.handlerFactoryExport} } from "${values.routeModuleSpecifier}";
|
|
6133
|
+
import * as job from "${values.moduleSpecifier}";
|
|
5940
6134
|
|
|
5941
6135
|
// Next.js route segment config must be a direct, statically analyzable export.
|
|
5942
|
-
export const maxDuration = ${maxDuration};
|
|
6136
|
+
export const maxDuration = ${values.maxDuration};
|
|
5943
6137
|
|
|
5944
|
-
const handler = ${
|
|
6138
|
+
const handler = ${values.handlerFactoryExport}(job);
|
|
5945
6139
|
|
|
5946
6140
|
export { handler as GET, handler as POST };
|
|
5947
6141
|
`;
|
|
5948
6142
|
}
|
|
6143
|
+
function jobsStaticRouteTemplate(config, moduleSpecifier, maxDuration) {
|
|
6144
|
+
if (!config.staticRoutes) {
|
|
6145
|
+
throw new Error("Static jobs route config is required");
|
|
6146
|
+
}
|
|
6147
|
+
return renderJobsStaticRoute({
|
|
6148
|
+
handlerFactoryExport: config.staticRoutes.handlerFactoryExport,
|
|
6149
|
+
maxDuration,
|
|
6150
|
+
moduleSpecifier,
|
|
6151
|
+
routeModuleSpecifier: toAliasImportPath(config.modules.routeModule),
|
|
6152
|
+
});
|
|
6153
|
+
}
|
|
6154
|
+
/**
|
|
6155
|
+
* Whether a marked static job route is exactly Loom's template for the
|
|
6156
|
+
* configured handler factory and route module, with any job module and
|
|
6157
|
+
* `maxDuration`. Those two values come from loom.json, so such a route is
|
|
6158
|
+
* stale Loom output that Loom may update or remove. A different factory or
|
|
6159
|
+
* route module (an audited wrapper, say), or any other edit, makes the file
|
|
6160
|
+
* the app's. This only covers routes from before Loom recorded their hashes.
|
|
6161
|
+
*/
|
|
6162
|
+
function isLoomJobsStaticRoute(text, config) {
|
|
6163
|
+
if (!config.staticRoutes)
|
|
6164
|
+
return false;
|
|
6165
|
+
if (!text.startsWith(LOOM_MANAGED_STATIC_JOB_ROUTE_MARKER))
|
|
6166
|
+
return false;
|
|
6167
|
+
const job = text.match(/import\s*\*\s*as\s+job\s+from\s*["']([^"']+)["']/);
|
|
6168
|
+
const maxDuration = text.match(/export\s+const\s+maxDuration\s*=\s*(\d+)/);
|
|
6169
|
+
if (!job || !maxDuration)
|
|
6170
|
+
return false;
|
|
6171
|
+
return (0, managedFiles_js_1.hashManagedFileText)(text) ===
|
|
6172
|
+
(0, managedFiles_js_1.hashManagedFileText)(renderJobsStaticRoute({
|
|
6173
|
+
handlerFactoryExport: config.staticRoutes.handlerFactoryExport,
|
|
6174
|
+
maxDuration: Number(maxDuration[1]),
|
|
6175
|
+
moduleSpecifier: job[1],
|
|
6176
|
+
routeModuleSpecifier: toAliasImportPath(config.modules.routeModule),
|
|
6177
|
+
}));
|
|
6178
|
+
}
|
|
6179
|
+
function jobsStaticRouteProof(config, feature, relativePath) {
|
|
6180
|
+
return {
|
|
6181
|
+
isLoomOutput: (text) => isLoomJobsStaticRoute(text, config),
|
|
6182
|
+
recordedHash: recordedManagedFileHash(feature, relativePath),
|
|
6183
|
+
};
|
|
6184
|
+
}
|
|
6185
|
+
const JOBS_STATIC_ROUTE_EDIT_RESOLUTION = `Move app-specific route code out of the generated file, then delete it and rerun \`loom add jobs\`; or remove its \`${LOOM_MANAGED_STATIC_JOB_ROUTE_MARKER}\` marker line to keep it as an app-owned route.`;
|
|
5949
6186
|
function assertPositiveJobsMaxDuration(value, label) {
|
|
5950
6187
|
if (!Number.isInteger(value) || value <= 0) {
|
|
5951
6188
|
throw new Error(`${label} must be a positive integer`);
|
|
@@ -6013,11 +6250,12 @@ async function findManagedJobsStaticRoutePaths(cwd, config) {
|
|
|
6013
6250
|
}
|
|
6014
6251
|
return managedPaths;
|
|
6015
6252
|
}
|
|
6016
|
-
async function syncJobsStaticRoutes(cwd, config) {
|
|
6253
|
+
async function syncJobsStaticRoutes(cwd, config, feature) {
|
|
6017
6254
|
const changedFiles = [];
|
|
6018
6255
|
const notes = [];
|
|
6256
|
+
const records = {};
|
|
6019
6257
|
if (!config.staticRoutes)
|
|
6020
|
-
return { changedFiles, notes };
|
|
6258
|
+
return { changedFiles, notes, records };
|
|
6021
6259
|
const plans = getJobsStaticRoutePlans(cwd, config);
|
|
6022
6260
|
const expectedPaths = new Set(plans.map((plan) => plan.path));
|
|
6023
6261
|
for (const plan of plans) {
|
|
@@ -6027,21 +6265,33 @@ async function syncJobsStaticRoutes(cwd, config) {
|
|
|
6027
6265
|
notes.push(`Preserved unmanaged jobs static route file: ${plan.relativePath}`);
|
|
6028
6266
|
continue;
|
|
6029
6267
|
}
|
|
6030
|
-
|
|
6268
|
+
const result = await (0, managedFiles_js_1.syncManagedFile)(plan.path, plan.text, jobsStaticRouteProof(config, feature, plan.relativePath));
|
|
6269
|
+
recordManagedFileSync(records, feature, plan.relativePath, result);
|
|
6270
|
+
if (result.state === "created" || result.state === "updated") {
|
|
6031
6271
|
changedFiles.push(plan.relativePath);
|
|
6032
6272
|
}
|
|
6273
|
+
else if (result.state === "customized") {
|
|
6274
|
+
notes.push(formatPreservedManagedFileNote(plan.relativePath, result.difference, JOBS_STATIC_ROUTE_EDIT_RESOLUTION));
|
|
6275
|
+
}
|
|
6033
6276
|
}
|
|
6034
6277
|
for (const routePath of await findManagedJobsStaticRoutePaths(cwd, config)) {
|
|
6035
6278
|
if (expectedPaths.has(routePath))
|
|
6036
6279
|
continue;
|
|
6037
|
-
|
|
6280
|
+
const relativePath = (0, node_path_1.relative)(cwd, routePath).replaceAll("\\", "/");
|
|
6281
|
+
const removal = await (0, managedFiles_js_1.removeManagedFile)(routePath, jobsStaticRouteProof(config, feature, relativePath));
|
|
6282
|
+
if (removal === "customized") {
|
|
6283
|
+
notes.push(`Preserved local edits in ${relativePath}, a generated jobs static route that loom.json no longer declares. Delete it yourself if the job is gone, or remove its \`${LOOM_MANAGED_STATIC_JOB_ROUTE_MARKER}\` marker line to keep it as an app-owned route.`);
|
|
6284
|
+
continue;
|
|
6285
|
+
}
|
|
6286
|
+
if (removal !== "removed")
|
|
6287
|
+
continue;
|
|
6038
6288
|
const routeDirectory = (0, node_path_1.dirname)(routePath);
|
|
6039
6289
|
if ((await (0, promises_1.readdir)(routeDirectory)).length === 0) {
|
|
6040
6290
|
await (0, promises_1.rm)(routeDirectory, { recursive: true });
|
|
6041
6291
|
}
|
|
6042
|
-
changedFiles.push(
|
|
6292
|
+
changedFiles.push(relativePath);
|
|
6043
6293
|
}
|
|
6044
|
-
return { changedFiles, notes };
|
|
6294
|
+
return { changedFiles, notes, records };
|
|
6045
6295
|
}
|
|
6046
6296
|
function pwaSerwistConfigTemplate(config) {
|
|
6047
6297
|
return `import { serwist } from "@serwist/next/config";
|
|
@@ -6096,6 +6346,7 @@ function pwaLifecyclePropLines(config) {
|
|
|
6096
6346
|
: ` updateCheckIntervalMs={${formatTsNumberLiteral(config.updateCheckIntervalMs)}}`,
|
|
6097
6347
|
].filter((line) => line !== null);
|
|
6098
6348
|
}
|
|
6349
|
+
const PWA_CUSTOMIZED_PROVIDER_RESOLUTION = "To keep it app-owned, set `features.pwa.config.provider.managed` to `false` in loom.json (`loom check` still validates its PWA wiring); to restore Loom's provider, delete it and rerun `loom init`.";
|
|
6099
6350
|
function pwaClientProviderTemplate(config) {
|
|
6100
6351
|
const lifecyclePropLines = pwaLifecyclePropLines(config);
|
|
6101
6352
|
const headlessLifecycle = lifecyclePropLines.length
|
|
@@ -6220,6 +6471,57 @@ afterAll(closeMemoryPglite);
|
|
|
6220
6471
|
export const { client, db, tableLoader } = harness;
|
|
6221
6472
|
`;
|
|
6222
6473
|
}
|
|
6474
|
+
function getDbManagedFiles(config, testRunner, tooling) {
|
|
6475
|
+
const schemaImportPath = toRelativeImportPath(config.modules.pgliteHarnessModule, (0, node_path_1.join)(config.dirs.schemaDir, "index.ts"));
|
|
6476
|
+
return [
|
|
6477
|
+
{
|
|
6478
|
+
knownOutputs: [],
|
|
6479
|
+
mismatch: "DB neon module does not match the Loom-managed wrapper",
|
|
6480
|
+
relativePath: config.modules.neonModule,
|
|
6481
|
+
text: dbNeonTemplate(),
|
|
6482
|
+
},
|
|
6483
|
+
{
|
|
6484
|
+
knownOutputs: [],
|
|
6485
|
+
mismatch: "DB neonFull module does not match the Loom-managed wrapper",
|
|
6486
|
+
relativePath: config.modules.neonFullModule,
|
|
6487
|
+
text: dbNeonFullTemplate(),
|
|
6488
|
+
},
|
|
6489
|
+
{
|
|
6490
|
+
knownOutputs: [],
|
|
6491
|
+
mismatch: "Drizzle config does not match the Loom-managed wrapper",
|
|
6492
|
+
relativePath: config.modules.drizzleConfig,
|
|
6493
|
+
text: dbDrizzleConfigTemplate(config),
|
|
6494
|
+
},
|
|
6495
|
+
{
|
|
6496
|
+
knownOutputs: [
|
|
6497
|
+
// With Deno tasks the harness follows whether the `test` task runs
|
|
6498
|
+
// vitest, which can change, so either runner's harness may be what
|
|
6499
|
+
// Loom wrote. Other runners only ever got the vitest harness.
|
|
6500
|
+
...(tooling.tasks.runner === "deno"
|
|
6501
|
+
? [
|
|
6502
|
+
dbPgliteHarnessTemplate(config, testRunner === "deno" ? "vitest" : "deno"),
|
|
6503
|
+
]
|
|
6504
|
+
: []),
|
|
6505
|
+
...(0, legacyManagedOutputs_js_1.legacyDbPgliteHarnessOutputs)(schemaImportPath, config.dirs.fixtureDir),
|
|
6506
|
+
],
|
|
6507
|
+
mismatch: "PGlite test harness does not match the Loom-managed wrapper",
|
|
6508
|
+
relativePath: config.modules.pgliteHarnessModule,
|
|
6509
|
+
text: dbPgliteHarnessTemplate(config, testRunner),
|
|
6510
|
+
},
|
|
6511
|
+
{
|
|
6512
|
+
knownOutputs: [],
|
|
6513
|
+
mismatch: "DB scripts tsconfig does not match the Loom-managed template",
|
|
6514
|
+
relativePath: config.modules.scriptsTsconfig,
|
|
6515
|
+
text: dbScriptsTsconfigTemplate(),
|
|
6516
|
+
},
|
|
6517
|
+
{
|
|
6518
|
+
knownOutputs: [],
|
|
6519
|
+
mismatch: "Valibot refinements common module does not match the Loom-managed wrapper",
|
|
6520
|
+
relativePath: config.modules.refinementsCommonModule,
|
|
6521
|
+
text: dbRefinementsCommonTemplate(),
|
|
6522
|
+
},
|
|
6523
|
+
];
|
|
6524
|
+
}
|
|
6223
6525
|
async function getDbTestRunner(cwd, tooling) {
|
|
6224
6526
|
if (tooling.tasks.runner !== "deno")
|
|
6225
6527
|
return "vitest";
|
|
@@ -6537,6 +6839,29 @@ function isGeneratedFilesStorageStub(text) {
|
|
|
6537
6839
|
"storageNotConfigured();",
|
|
6538
6840
|
].every((part) => text.includes(part));
|
|
6539
6841
|
}
|
|
6842
|
+
/**
|
|
6843
|
+
* Installs the S3 storage adapter in place of the generated not-configured
|
|
6844
|
+
* stub, but only while the stub is exactly Loom's scaffold: an edited stub is
|
|
6845
|
+
* the app's and stays.
|
|
6846
|
+
*/
|
|
6847
|
+
async function replaceFilesStorageStub(storagePath, relativePath) {
|
|
6848
|
+
const stub = filesStorageTemplate();
|
|
6849
|
+
const result = await (0, managedFiles_js_1.syncManagedFile)(storagePath, filesS3StorageTemplate(), {
|
|
6850
|
+
knownOutputs: [stub],
|
|
6851
|
+
});
|
|
6852
|
+
if (result.state !== "customized") {
|
|
6853
|
+
return {
|
|
6854
|
+
changed: result.state === "created" || result.state === "updated",
|
|
6855
|
+
note: null,
|
|
6856
|
+
};
|
|
6857
|
+
}
|
|
6858
|
+
// The edits that matter are the app's changes to Loom's stub.
|
|
6859
|
+
const currentText = await readTextIfExists(storagePath) ?? "";
|
|
6860
|
+
return {
|
|
6861
|
+
changed: false,
|
|
6862
|
+
note: formatPreservedManagedFileNote(relativePath, (0, managedFiles_js_1.describeManagedFileDifference)(currentText, stub), "Wire it to the canonical FILES_S3_* variables yourself, or delete it and rerun this command to install Loom's S3 storage adapter."),
|
|
6863
|
+
};
|
|
6864
|
+
}
|
|
6540
6865
|
function filesRouteTemplate(config) {
|
|
6541
6866
|
return `import { createFilesRouteHandlers } from "@gadicc/loom/next/files";
|
|
6542
6867
|
import {
|
|
@@ -7143,14 +7468,88 @@ function buildValibotBarrelText(generatedNames, refinementNames) {
|
|
|
7143
7468
|
? `export * from "./refinements/${name}";`
|
|
7144
7469
|
: `export * from "./generated/${name}";`).join("\n")}\n`;
|
|
7145
7470
|
}
|
|
7146
|
-
|
|
7471
|
+
const VALIBOT_BARREL_LINE = /^export\s*\*\s*from\s*["']\.\/(generated|refinements)\/([^"']+)["']\s*;?$/;
|
|
7472
|
+
async function directoryHasModule(directory, name) {
|
|
7473
|
+
try {
|
|
7474
|
+
return (await (0, promises_1.readdir)(directory)).some((entry) => entry === name || stripModuleExtension(entry) === name);
|
|
7475
|
+
}
|
|
7476
|
+
catch (error) {
|
|
7477
|
+
if (isNodeErrorCode(error, "ENOENT"))
|
|
7478
|
+
return false;
|
|
7479
|
+
throw error;
|
|
7480
|
+
}
|
|
7481
|
+
}
|
|
7482
|
+
/**
|
|
7483
|
+
* Whether a valibot barrel holds only export lines Loom generates, so it can
|
|
7484
|
+
* be rebuilt without losing a hand-written export. Loom exports each `.ts`
|
|
7485
|
+
* module of the generated and refinement directories except `index` and
|
|
7486
|
+
* `_`-prefixed ones, once each, and a refinement replaces the generated
|
|
7487
|
+
* module of the same name. So a `./generated/<name>` line beside a
|
|
7488
|
+
* `./refinements/<name>` line was added by hand, while one without it is
|
|
7489
|
+
* what Loom wrote before that refinement existed. A line for a module that
|
|
7490
|
+
* no longer exists is stale Loom output; a line for another module that does
|
|
7491
|
+
* exist was added by hand.
|
|
7492
|
+
*/
|
|
7493
|
+
async function isLoomValibotBarrel(cwd, config, text, generatedNames, refinementNames) {
|
|
7494
|
+
const lines = [];
|
|
7495
|
+
const seen = new Set();
|
|
7496
|
+
for (const line of normalizeText(text).split("\n")) {
|
|
7497
|
+
const trimmed = line.trim();
|
|
7498
|
+
if (!trimmed)
|
|
7499
|
+
continue;
|
|
7500
|
+
const match = trimmed.match(VALIBOT_BARREL_LINE);
|
|
7501
|
+
if (!match)
|
|
7502
|
+
return false;
|
|
7503
|
+
const [, kind, name] = match;
|
|
7504
|
+
if (name === "index" || name.startsWith("_") || name.includes("/")) {
|
|
7505
|
+
return false;
|
|
7506
|
+
}
|
|
7507
|
+
const key = `${kind}/${name}`;
|
|
7508
|
+
if (seen.has(key))
|
|
7509
|
+
return false;
|
|
7510
|
+
seen.add(key);
|
|
7511
|
+
lines.push({ kind, name });
|
|
7512
|
+
}
|
|
7513
|
+
for (const { kind, name } of lines) {
|
|
7514
|
+
if (kind === "refinements" && refinementNames.includes(name))
|
|
7515
|
+
continue;
|
|
7516
|
+
if (kind === "generated" && generatedNames.includes(name)) {
|
|
7517
|
+
if (refinementNames.includes(name) && seen.has(`refinements/${name}`)) {
|
|
7518
|
+
return false;
|
|
7519
|
+
}
|
|
7520
|
+
continue;
|
|
7521
|
+
}
|
|
7522
|
+
const directory = kind === "generated"
|
|
7523
|
+
? config.dirs.valibotGeneratedDir
|
|
7524
|
+
: config.dirs.valibotRefinementsDir;
|
|
7525
|
+
if (await directoryHasModule((0, node_path_1.join)(cwd, directory), name))
|
|
7526
|
+
return false;
|
|
7527
|
+
}
|
|
7528
|
+
return true;
|
|
7529
|
+
}
|
|
7530
|
+
async function readValibotBarrelState(cwd, config) {
|
|
7147
7531
|
const generatedNames = await readTsModuleNames((0, node_path_1.join)(cwd, config.dirs.valibotGeneratedDir));
|
|
7148
7532
|
const refinementNames = await readTsModuleNames((0, node_path_1.join)(cwd, config.dirs.valibotRefinementsDir));
|
|
7149
|
-
const
|
|
7150
|
-
|
|
7151
|
-
|
|
7533
|
+
const proof = {
|
|
7534
|
+
isLoomOutput: (text) => isLoomValibotBarrel(cwd, config, text, generatedNames, refinementNames),
|
|
7535
|
+
};
|
|
7536
|
+
return {
|
|
7537
|
+
proof,
|
|
7538
|
+
text: buildValibotBarrelText(generatedNames, refinementNames),
|
|
7539
|
+
};
|
|
7540
|
+
}
|
|
7541
|
+
async function syncValibotBarrel(cwd, config) {
|
|
7542
|
+
const barrel = await readValibotBarrelState(cwd, config);
|
|
7543
|
+
if (!barrel.text) {
|
|
7544
|
+
return { changed: false, note: null };
|
|
7152
7545
|
}
|
|
7153
|
-
|
|
7546
|
+
const result = await (0, managedFiles_js_1.syncManagedFile)((0, node_path_1.join)(cwd, config.modules.valibotBarrelModule), barrel.text, barrel.proof);
|
|
7547
|
+
return {
|
|
7548
|
+
changed: result.state === "created" || result.state === "updated",
|
|
7549
|
+
note: result.state === "customized"
|
|
7550
|
+
? formatPreservedManagedFileNote(config.modules.valibotBarrelModule, result.difference, "Keep only `export * from` lines for the generated and refinement modules there, or add the missing exports by hand.")
|
|
7551
|
+
: null,
|
|
7552
|
+
};
|
|
7154
7553
|
}
|
|
7155
7554
|
function getLatestManagedSchemaConfig(schema) {
|
|
7156
7555
|
const latest = {
|
|
@@ -7375,8 +7774,7 @@ async function syncDbSchemas(cwd) {
|
|
|
7375
7774
|
(!mailFeature || mailFeature.status !== "active")) {
|
|
7376
7775
|
notes.push("No active Loom-managed DB schemas are configured.");
|
|
7377
7776
|
}
|
|
7378
|
-
|
|
7379
|
-
if (await writeTextIfChanged(manifestPath, stringifyJson(manifest))) {
|
|
7777
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
7380
7778
|
changedFiles.push("loom.json");
|
|
7381
7779
|
}
|
|
7382
7780
|
if (changedFiles.length) {
|
|
@@ -7406,8 +7804,7 @@ async function configureFilesIdGeneration(cwd, idGeneration) {
|
|
|
7406
7804
|
const config = getFilesConfig(framework, dbConfig, filesFeature.config);
|
|
7407
7805
|
config.schema.idGeneration = idGeneration;
|
|
7408
7806
|
filesFeature.config = config;
|
|
7409
|
-
const
|
|
7410
|
-
const changedFiles = await writeTextIfChanged(manifestPath, nextText)
|
|
7807
|
+
const changedFiles = await writeManifestIfChanged(cwd, manifest)
|
|
7411
7808
|
? ["loom.json"]
|
|
7412
7809
|
: [];
|
|
7413
7810
|
return {
|
|
@@ -8086,9 +8483,12 @@ async function setupLocalFiles(cwd, options = {}) {
|
|
|
8086
8483
|
notes.push(`Run ${tooling.dependencies.manager} install to update the dependency lockfile.`);
|
|
8087
8484
|
}
|
|
8088
8485
|
if (!storageText || isGeneratedFilesStorageStub(storageText)) {
|
|
8089
|
-
|
|
8486
|
+
const storageUpdate = await replaceFilesStorageStub(storagePath, config.modules.storageModule);
|
|
8487
|
+
if (storageUpdate.changed) {
|
|
8090
8488
|
changedFiles.push(config.modules.storageModule);
|
|
8091
8489
|
}
|
|
8490
|
+
if (storageUpdate.note)
|
|
8491
|
+
notes.push(storageUpdate.note);
|
|
8092
8492
|
}
|
|
8093
8493
|
config.storage.adapter = "s3";
|
|
8094
8494
|
if (config.storage.provider) {
|
|
@@ -8099,7 +8499,7 @@ async function setupLocalFiles(cwd, options = {}) {
|
|
|
8099
8499
|
};
|
|
8100
8500
|
}
|
|
8101
8501
|
feature.config = config;
|
|
8102
|
-
if (await
|
|
8502
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
8103
8503
|
changedFiles.push("loom.json");
|
|
8104
8504
|
}
|
|
8105
8505
|
return {
|
|
@@ -8351,7 +8751,7 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8351
8751
|
};
|
|
8352
8752
|
feature.config = config;
|
|
8353
8753
|
manifest.features.files = feature;
|
|
8354
|
-
if (await
|
|
8754
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
8355
8755
|
changedFiles.push("loom.json");
|
|
8356
8756
|
}
|
|
8357
8757
|
for (const bucket of new Set(Object.values(buckets))) {
|
|
@@ -8381,9 +8781,12 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8381
8781
|
const storagePath = (0, node_path_1.join)(cwd, config.modules.storageModule);
|
|
8382
8782
|
const storageText = await readTextIfExists(storagePath);
|
|
8383
8783
|
if (!storageText || isGeneratedFilesStorageStub(storageText)) {
|
|
8384
|
-
|
|
8784
|
+
const storageUpdate = await replaceFilesStorageStub(storagePath, config.modules.storageModule);
|
|
8785
|
+
if (storageUpdate.changed) {
|
|
8385
8786
|
changedFiles.push(config.modules.storageModule);
|
|
8386
8787
|
}
|
|
8788
|
+
if (storageUpdate.note)
|
|
8789
|
+
notes.push(storageUpdate.note);
|
|
8387
8790
|
}
|
|
8388
8791
|
else if (!storageText.includes("@gadicc/loom/files/s3")) {
|
|
8389
8792
|
notes.push(`Preserved customized storage module ${config.modules.storageModule}; wire it to the canonical FILES_S3_* variables manually.`);
|
|
@@ -8476,7 +8879,7 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8476
8879
|
catch (error) {
|
|
8477
8880
|
config.storage.provider.connectionStatus = "partial";
|
|
8478
8881
|
feature.config = config;
|
|
8479
|
-
await
|
|
8882
|
+
await writeManifestIfChanged(cwd, manifest);
|
|
8480
8883
|
throw new Error(`R2 buckets are ready, but Vercel configuration is incomplete: ${error instanceof Error ? error.message : String(error)} Rerun \`loom files r2 setup\`; Loom will reuse the existing buckets.`);
|
|
8481
8884
|
}
|
|
8482
8885
|
const secretsConfigured = FILES_R2_ENVIRONMENTS.every((environment) => ["FILES_S3_ACCESS_KEY_ID", "FILES_S3_SECRET_ACCESS_KEY"].every((name) => hasExactEnvName(envListings.get(environment) ?? "", name)));
|
|
@@ -8486,7 +8889,7 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8486
8889
|
? "configured"
|
|
8487
8890
|
: "credentials-required";
|
|
8488
8891
|
feature.config = config;
|
|
8489
|
-
if (await
|
|
8892
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
8490
8893
|
if (!changedFiles.includes("loom.json"))
|
|
8491
8894
|
changedFiles.push("loom.json");
|
|
8492
8895
|
}
|
|
@@ -9611,7 +10014,7 @@ async function setupVercelNeon(cwd, options = {}) {
|
|
|
9611
10014
|
recordNeonProviderConfig(feature, framework, resourceName, "connected", undefined, options.region);
|
|
9612
10015
|
manifest.features.db = feature;
|
|
9613
10016
|
const changedFiles = [];
|
|
9614
|
-
if (await
|
|
10017
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
9615
10018
|
changedFiles.push("loom.json");
|
|
9616
10019
|
}
|
|
9617
10020
|
return {
|
|
@@ -9630,7 +10033,7 @@ async function setupVercelNeon(cwd, options = {}) {
|
|
|
9630
10033
|
recordNeonProviderConfig(feature, framework, resourceName, "provisioned", undefined, options.region);
|
|
9631
10034
|
manifest.features.db = feature;
|
|
9632
10035
|
const changedFiles = [];
|
|
9633
|
-
if (await
|
|
10036
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
9634
10037
|
changedFiles.push("loom.json");
|
|
9635
10038
|
}
|
|
9636
10039
|
return {
|
|
@@ -9660,7 +10063,7 @@ async function setupVercelNeon(cwd, options = {}) {
|
|
|
9660
10063
|
recordNeonProviderConfig(feature, framework, resourceName, result.code === 0 ? "connected" : "provisioned", provisionSuccess?.dashboardUrl, options.region);
|
|
9661
10064
|
manifest.features.db = feature;
|
|
9662
10065
|
const changedFiles = [];
|
|
9663
|
-
if (await
|
|
10066
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
9664
10067
|
changedFiles.push("loom.json");
|
|
9665
10068
|
}
|
|
9666
10069
|
const notes = result.code === 0
|
|
@@ -9793,7 +10196,9 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
9793
10196
|
dependencies: JOBS_DEFAULT_DEPENDENCIES,
|
|
9794
10197
|
devDependencies: JOBS_DEFAULT_DEV_DEPENDENCIES,
|
|
9795
10198
|
});
|
|
9796
|
-
const scriptsUpdate = await
|
|
10199
|
+
const scriptsUpdate = await syncManagedTasks(cwd, manifest, currentFeature, getJobsManagedTasks(config));
|
|
10200
|
+
setManagedRecords(feature, "managedTasks", scriptsUpdate.records);
|
|
10201
|
+
notes.push(...formatPreservedTaskNotes(scriptsUpdate, "jobs"));
|
|
9797
10202
|
if (dependencyUpdate.changed)
|
|
9798
10203
|
changedFiles.push(dependencyUpdate.config);
|
|
9799
10204
|
if (scriptsUpdate.changedKeys.length)
|
|
@@ -9848,9 +10253,18 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
9848
10253
|
if (relativePath === config.directRunner.scriptPath &&
|
|
9849
10254
|
currentText !== null &&
|
|
9850
10255
|
isLegacyLoomJobsDirectRunner(currentText)) {
|
|
9851
|
-
|
|
10256
|
+
// Replace a dotenv-era runner only when it is exactly what an older
|
|
10257
|
+
// Loom wrote; an edited one keeps its app code.
|
|
10258
|
+
const legacyRunners = (0, legacyManagedOutputs_js_1.legacyJobsDirectRunnerOutputs)(getJobsDirectRunnerCatalogImportPath(config, framework));
|
|
10259
|
+
const result = await (0, managedFiles_js_1.syncManagedFile)(path, text, {
|
|
10260
|
+
knownOutputs: legacyRunners,
|
|
10261
|
+
});
|
|
10262
|
+
if (result.state === "updated") {
|
|
9852
10263
|
changedFiles.push(relativePath);
|
|
9853
10264
|
}
|
|
10265
|
+
else if (result.state === "customized") {
|
|
10266
|
+
notes.push(`Preserved local edits in the dotenv-based jobs direct runner ${relativePath} (${(0, managedFiles_js_1.describeManagedFileDifference)(currentText, legacyRunners)}); Loom did not replace it. Remove its dotenv import and \`dotenv.config(...)\` call and run it through \`loom env\`, or delete it and rerun \`loom add jobs\` to restore Loom's runner.`);
|
|
10267
|
+
}
|
|
9854
10268
|
continue;
|
|
9855
10269
|
}
|
|
9856
10270
|
const scaffoldState = await scaffoldTextFile(path, text);
|
|
@@ -9862,9 +10276,10 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
9862
10276
|
notes.push(`Preserved existing jobs scaffold file: ${relativePath}`);
|
|
9863
10277
|
}
|
|
9864
10278
|
}
|
|
9865
|
-
const staticRouteSync = await syncJobsStaticRoutes(cwd, config);
|
|
10279
|
+
const staticRouteSync = await syncJobsStaticRoutes(cwd, config, currentFeature);
|
|
9866
10280
|
changedFiles.push(...staticRouteSync.changedFiles);
|
|
9867
10281
|
notes.push(...staticRouteSync.notes);
|
|
10282
|
+
setManagedFileRecords(feature, staticRouteSync.records);
|
|
9868
10283
|
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
9869
10284
|
const catalogPath = (0, node_path_1.join)(cwd, jobsRoot, "index.ts");
|
|
9870
10285
|
const metaCatalogPath = (0, node_path_1.join)(cwd, jobsRoot, "indexWithMetaOnly.ts");
|
|
@@ -9904,7 +10319,9 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
9904
10319
|
devDependencies: DB_DEFAULT_DEV_DEPENDENCIES,
|
|
9905
10320
|
remove: DB_MOVED_DEPENDENCIES,
|
|
9906
10321
|
});
|
|
9907
|
-
const scriptsUpdate = await
|
|
10322
|
+
const scriptsUpdate = await syncManagedTasks(cwd, manifest, currentFeature, getDbManagedTasks(config, tooling));
|
|
10323
|
+
setManagedRecords(feature, "managedTasks", scriptsUpdate.records);
|
|
10324
|
+
notes.push(...formatPreservedTaskNotes(scriptsUpdate, "db"));
|
|
9908
10325
|
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
9909
10326
|
if (dependencyUpdate.changed)
|
|
9910
10327
|
changedFiles.push(dependencyUpdate.config);
|
|
@@ -9919,26 +10336,21 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
9919
10336
|
if (dependencyUpdate.removedKeys.length) {
|
|
9920
10337
|
notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${dependencyUpdate.removedKeys.join(", ")}`);
|
|
9921
10338
|
}
|
|
9922
|
-
const
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
],
|
|
9935
|
-
];
|
|
9936
|
-
for (const [relativePath, text] of managedFiles) {
|
|
9937
|
-
const path = (0, node_path_1.join)(cwd, relativePath);
|
|
9938
|
-
if (await writeTextIfChanged(path, text)) {
|
|
9939
|
-
changedFiles.push(relativePath);
|
|
10339
|
+
const managedFileRecords = {};
|
|
10340
|
+
for (const managedFile of getDbManagedFiles(config, testRunner, tooling)) {
|
|
10341
|
+
const result = await (0, managedFiles_js_1.syncManagedFile)((0, node_path_1.join)(cwd, managedFile.relativePath), managedFile.text, {
|
|
10342
|
+
knownOutputs: managedFile.knownOutputs,
|
|
10343
|
+
recordedHash: recordedManagedFileHash(currentFeature, managedFile.relativePath),
|
|
10344
|
+
});
|
|
10345
|
+
recordManagedFileSync(managedFileRecords, currentFeature, managedFile.relativePath, result);
|
|
10346
|
+
if (result.state === "created" || result.state === "updated") {
|
|
10347
|
+
changedFiles.push(managedFile.relativePath);
|
|
10348
|
+
}
|
|
10349
|
+
else if (result.state === "customized") {
|
|
10350
|
+
notes.push(formatPreservedManagedFileNote(managedFile.relativePath, result.difference, "Move app-specific code to a separate module, then delete the file and rerun `loom add db` to restore the Loom wrapper."));
|
|
9940
10351
|
}
|
|
9941
10352
|
}
|
|
10353
|
+
setManagedFileRecords(feature, managedFileRecords);
|
|
9942
10354
|
const scaffoldFiles = [
|
|
9943
10355
|
[config.modules.fixtureDumpScript, dbFixturesScriptTemplate(config)],
|
|
9944
10356
|
[(0, node_path_1.join)(config.dirs.fixtureDir, ".gitkeep"), ""],
|
|
@@ -9954,9 +10366,12 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
9954
10366
|
notes.push(`Preserved existing DB scaffold file: ${relativePath}`);
|
|
9955
10367
|
}
|
|
9956
10368
|
}
|
|
9957
|
-
|
|
10369
|
+
const barrelSync = await syncValibotBarrel(cwd, config);
|
|
10370
|
+
if (barrelSync.changed) {
|
|
9958
10371
|
changedFiles.push(config.modules.valibotBarrelModule);
|
|
9959
10372
|
}
|
|
10373
|
+
if (barrelSync.note)
|
|
10374
|
+
notes.push(barrelSync.note);
|
|
9960
10375
|
const schemaIndexPath = (0, node_path_1.join)(cwd, config.dirs.schemaDir, "index.ts");
|
|
9961
10376
|
if (!await exists(schemaIndexPath)) {
|
|
9962
10377
|
notes.push(`Missing ${config.dirs.schemaDir}/index.ts. Add your app-local Drizzle schema barrel there so Loom-managed DB helpers can import it.`);
|
|
@@ -10265,6 +10680,26 @@ function linguiCliCommand(tooling) {
|
|
|
10265
10680
|
return "yarn lingui";
|
|
10266
10681
|
}
|
|
10267
10682
|
}
|
|
10683
|
+
function getLinguiManagedTasks(config, tooling) {
|
|
10684
|
+
// Lingui tasks have followed the recorded dependency manager since the
|
|
10685
|
+
// feature was added, so there is no earlier value to accept.
|
|
10686
|
+
const executable = linguiCliCommand(tooling);
|
|
10687
|
+
return [
|
|
10688
|
+
{
|
|
10689
|
+
definition: `${executable} extract --clean`,
|
|
10690
|
+
knownValues: [],
|
|
10691
|
+
name: config.tasks.extract,
|
|
10692
|
+
},
|
|
10693
|
+
{
|
|
10694
|
+
definition: `${executable} compile`,
|
|
10695
|
+
knownValues: [],
|
|
10696
|
+
name: config.tasks.compile,
|
|
10697
|
+
},
|
|
10698
|
+
];
|
|
10699
|
+
}
|
|
10700
|
+
const PWA_MANAGED_TASKS = [
|
|
10701
|
+
{ definition: PWA_BUILD_SCRIPT, knownValues: [], name: "pwa:build" },
|
|
10702
|
+
];
|
|
10268
10703
|
function linguiConfigTemplate(framework) {
|
|
10269
10704
|
const sourceRoot = framework.srcDir ? "src/" : "";
|
|
10270
10705
|
return `import { formatter } from "@lingui/format-po";
|
|
@@ -10414,19 +10849,10 @@ async function applyLinguiFeature(cwd, framework, manifest, activate) {
|
|
|
10414
10849
|
else if (activate && configState === "preserved") {
|
|
10415
10850
|
notes.push(`Preserved existing Lingui config: ${config.configFile}`);
|
|
10416
10851
|
}
|
|
10417
|
-
const
|
|
10418
|
-
|
|
10419
|
-
|
|
10420
|
-
|
|
10421
|
-
[config.tasks.compile, `${executable} compile`],
|
|
10422
|
-
]) {
|
|
10423
|
-
const result = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, {
|
|
10424
|
-
definition: command,
|
|
10425
|
-
name,
|
|
10426
|
-
});
|
|
10427
|
-
if (result.changed)
|
|
10428
|
-
taskChanges.push(name);
|
|
10429
|
-
}
|
|
10852
|
+
const linguiTasks = await syncManagedTasks(cwd, manifest, currentFeature, getLinguiManagedTasks(config, tooling));
|
|
10853
|
+
setManagedRecords(feature, "managedTasks", linguiTasks.records);
|
|
10854
|
+
const taskChanges = [...linguiTasks.changedKeys];
|
|
10855
|
+
notes.push(...formatPreservedTaskNotes(linguiTasks, "lingui"));
|
|
10430
10856
|
let taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
10431
10857
|
if (!(0, projectTooling_js_1.getTaskCommand)(taskStore.definitions[config.tasks.build])) {
|
|
10432
10858
|
const result = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, {
|
|
@@ -10456,9 +10882,15 @@ async function applyLinguiFeature(cwd, framework, manifest, activate) {
|
|
|
10456
10882
|
const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
|
|
10457
10883
|
if (!poDeclarations.length) {
|
|
10458
10884
|
const declarationPath = `${framework.srcDir ? "src/" : ""}lingui.d.ts`;
|
|
10459
|
-
|
|
10885
|
+
// Loom's declaration file always declares `*.po`, so an existing file
|
|
10886
|
+
// without one is the app's own and is never replaced.
|
|
10887
|
+
const declarationState = await scaffoldTextFile((0, node_path_1.join)(cwd, declarationPath), linguiPoDeclarationTemplate());
|
|
10888
|
+
if (declarationState === "created") {
|
|
10460
10889
|
changedFiles.push(declarationPath);
|
|
10461
10890
|
}
|
|
10891
|
+
else if (declarationState === "preserved") {
|
|
10892
|
+
notes.push(`Preserved existing ${declarationPath}, which does not declare \`*.po\` modules; add \`declare module "*.po"\` there or in another declaration file for the Lingui loader.`);
|
|
10893
|
+
}
|
|
10462
10894
|
}
|
|
10463
10895
|
}
|
|
10464
10896
|
if (framework.kind === "nextjs") {
|
|
@@ -10510,12 +10942,10 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
10510
10942
|
if (dependencyUpdate.changed)
|
|
10511
10943
|
changedFiles.push(dependencyUpdate.config);
|
|
10512
10944
|
const scriptsChanged = [];
|
|
10513
|
-
const
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
if (pwaTask.changed)
|
|
10518
|
-
scriptsChanged.push("pwa:build");
|
|
10945
|
+
const pwaTasks = await syncManagedTasks(cwd, manifest, currentFeature, PWA_MANAGED_TASKS);
|
|
10946
|
+
setManagedRecords(feature, "managedTasks", pwaTasks.records);
|
|
10947
|
+
scriptsChanged.push(...pwaTasks.changedKeys);
|
|
10948
|
+
notes.push(...formatPreservedTaskNotes(pwaTasks, "pwa"));
|
|
10519
10949
|
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
10520
10950
|
const buildCommand = (0, projectTooling_js_1.getTaskCommand)(taskStore.definitions.build);
|
|
10521
10951
|
if (!buildCommand) {
|
|
@@ -10560,14 +10990,27 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
10560
10990
|
notes.push(`Preserved existing PWA service worker file: ${config.modules.serviceWorkerModule}`);
|
|
10561
10991
|
}
|
|
10562
10992
|
const clientProviderPath = (0, node_path_1.join)(cwd, config.modules.clientProviderModule);
|
|
10563
|
-
const
|
|
10993
|
+
const managedFileRecords = {};
|
|
10564
10994
|
if (config.provider.managed) {
|
|
10565
|
-
|
|
10995
|
+
// `loom add pwa` may refresh the recorded adapter, so the provider the
|
|
10996
|
+
// previous configuration rendered is also Loom's output.
|
|
10997
|
+
const previousConfig = currentConfig
|
|
10998
|
+
? await getPwaConfig(cwd, framework, packageJson, currentConfig, false)
|
|
10999
|
+
: config;
|
|
11000
|
+
const result = await (0, managedFiles_js_1.syncManagedFile)(clientProviderPath, pwaClientProviderTemplate(config), {
|
|
11001
|
+
knownOutputs: [pwaClientProviderTemplate(previousConfig)],
|
|
11002
|
+
recordedHash: recordedManagedFileHash(currentFeature, config.modules.clientProviderModule),
|
|
11003
|
+
});
|
|
11004
|
+
recordManagedFileSync(managedFileRecords, currentFeature, config.modules.clientProviderModule, result);
|
|
11005
|
+
if (result.state === "created" || result.state === "updated") {
|
|
10566
11006
|
changedFiles.push(config.modules.clientProviderModule);
|
|
10567
11007
|
}
|
|
10568
|
-
if (
|
|
11008
|
+
if (result.state === "created") {
|
|
10569
11009
|
notes.push(`Scaffolded ${config.modules.clientProviderModule}. Wrap the app's root layout or provider tree with LoomPwaProvider to register the service worker.`);
|
|
10570
11010
|
}
|
|
11011
|
+
else if (result.state === "customized") {
|
|
11012
|
+
notes.push(formatPreservedManagedFileNote(config.modules.clientProviderModule, result.difference, PWA_CUSTOMIZED_PROVIDER_RESOLUTION));
|
|
11013
|
+
}
|
|
10571
11014
|
}
|
|
10572
11015
|
else {
|
|
10573
11016
|
const clientProviderState = await scaffoldTextFile(clientProviderPath, pwaClientProviderTemplate(config));
|
|
@@ -10578,6 +11021,7 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
10578
11021
|
notes.push(`Preserved existing PWA client provider file: ${config.modules.clientProviderModule}`);
|
|
10579
11022
|
}
|
|
10580
11023
|
}
|
|
11024
|
+
setManagedFileRecords(feature, managedFileRecords);
|
|
10581
11025
|
if (config.confirmAdapter === "mui") {
|
|
10582
11026
|
notes.push("Detected @mui/material; PWA update prompts should use @gadicc/loom/mui/confirm.");
|
|
10583
11027
|
}
|
|
@@ -10598,14 +11042,14 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
10598
11042
|
return { issues, suggestions: [], warnings: [] };
|
|
10599
11043
|
}
|
|
10600
11044
|
const config = mergeJobsConfig(framework, feature.config);
|
|
10601
|
-
const
|
|
10602
|
-
const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
|
|
11045
|
+
const taskCheck = await checkManagedTasks(cwd, manifest, feature, getJobsManagedTasks(config));
|
|
10603
11046
|
for (const taskName of taskCheck.mismatches) {
|
|
10604
11047
|
issues.push(taskCheck.config === "package.json"
|
|
10605
11048
|
? `Jobs package.json script does not match Loom defaults: ${taskName}`
|
|
10606
11049
|
: `Jobs task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
10607
11050
|
suggestions.add("Run `loom add jobs`.");
|
|
10608
11051
|
}
|
|
11052
|
+
addCustomizedTaskWarnings(taskCheck, "jobs", warnings, suggestions);
|
|
10609
11053
|
const requiredFiles = [
|
|
10610
11054
|
JOBS_SCRIPTS_TSCONFIG_PATH,
|
|
10611
11055
|
config.directRunner?.scriptPath,
|
|
@@ -10656,8 +11100,14 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
10656
11100
|
const plans = getJobsStaticRoutePlans(cwd, config);
|
|
10657
11101
|
const expectedPaths = new Set(plans.map((plan) => plan.path));
|
|
10658
11102
|
for (const plan of plans) {
|
|
10659
|
-
const
|
|
10660
|
-
if (
|
|
11103
|
+
const classification = await (0, managedFiles_js_1.classifyManagedFile)(await readTextIfExists(plan.path), plan.text, jobsStaticRouteProof(config, feature, plan.relativePath));
|
|
11104
|
+
if (classification.state === "current")
|
|
11105
|
+
continue;
|
|
11106
|
+
if (classification.state === "customized") {
|
|
11107
|
+
issues.push(`Jobs static route does not match loom manifest config: ${plan.relativePath} (${classification.difference})`);
|
|
11108
|
+
suggestions.add(`Loom does not overwrite edited or app-owned static job routes. ${JOBS_STATIC_ROUTE_EDIT_RESOLUTION}`);
|
|
11109
|
+
}
|
|
11110
|
+
else {
|
|
10661
11111
|
issues.push(`Jobs static route does not match loom manifest config: ${plan.relativePath}`);
|
|
10662
11112
|
suggestions.add("Run `loom add jobs` to sync static job routes.");
|
|
10663
11113
|
}
|
|
@@ -10665,8 +11115,12 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
10665
11115
|
for (const routePath of await findManagedJobsStaticRoutePaths(cwd, config)) {
|
|
10666
11116
|
if (expectedPaths.has(routePath))
|
|
10667
11117
|
continue;
|
|
10668
|
-
|
|
10669
|
-
|
|
11118
|
+
const relativePath = (0, node_path_1.relative)(cwd, routePath).replaceAll("\\", "/");
|
|
11119
|
+
issues.push(`Managed jobs static route is not declared in loom.json: ${relativePath}`);
|
|
11120
|
+
const routeState = await (0, managedFiles_js_1.classifyManagedFile)(await readTextIfExists(routePath), "", jobsStaticRouteProof(config, feature, relativePath));
|
|
11121
|
+
suggestions.add(routeState.state === "loom-output"
|
|
11122
|
+
? "Run `loom add jobs` to sync static job routes."
|
|
11123
|
+
: `Loom does not delete edited static job routes: delete ${relativePath} yourself if the job is gone, or remove its \`${LOOM_MANAGED_STATIC_JOB_ROUTE_MARKER}\` marker line to keep it.`);
|
|
10670
11124
|
}
|
|
10671
11125
|
const routeModuleText = await readTextIfExists((0, node_path_1.join)(cwd, config.modules.routeModule));
|
|
10672
11126
|
if (routeModuleText &&
|
|
@@ -10809,7 +11263,6 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10809
11263
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
10810
11264
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
10811
11265
|
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
10812
|
-
const expectedScripts = getDbExpectedScripts(config, tooling);
|
|
10813
11266
|
const migrationFlowCheck = await checkDbProductionMigrationFlow(cwd, options.production ?? false, productionBranch);
|
|
10814
11267
|
issues.push(...migrationFlowCheck.issues);
|
|
10815
11268
|
warnings.push(...migrationFlowCheck.warnings);
|
|
@@ -10841,13 +11294,14 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10841
11294
|
suggestions.add(`Run loom add db to rewrite ${tooling.dependencies.config}.`);
|
|
10842
11295
|
}
|
|
10843
11296
|
}
|
|
10844
|
-
const taskCheck = await
|
|
11297
|
+
const taskCheck = await checkManagedTasks(cwd, manifest, feature, getDbManagedTasks(config, tooling));
|
|
10845
11298
|
for (const taskName of taskCheck.mismatches) {
|
|
10846
11299
|
issues.push(taskCheck.config === "package.json"
|
|
10847
11300
|
? `DB package.json script does not match Loom defaults: ${taskName}`
|
|
10848
11301
|
: `DB task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
10849
11302
|
suggestions.add("Run `loom add db`.");
|
|
10850
11303
|
}
|
|
11304
|
+
addCustomizedTaskWarnings(taskCheck, "db", warnings, suggestions);
|
|
10851
11305
|
const requiredFiles = [
|
|
10852
11306
|
config.modules.neonModule,
|
|
10853
11307
|
config.modules.neonFullModule,
|
|
@@ -10864,44 +11318,22 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10864
11318
|
suggestions.add("Run `loom add db`.");
|
|
10865
11319
|
}
|
|
10866
11320
|
}
|
|
10867
|
-
const
|
|
10868
|
-
|
|
10869
|
-
config.modules.neonModule,
|
|
10870
|
-
dbNeonTemplate(),
|
|
10871
|
-
"DB neon module does not match the Loom-managed wrapper",
|
|
10872
|
-
],
|
|
10873
|
-
[
|
|
10874
|
-
config.modules.neonFullModule,
|
|
10875
|
-
dbNeonFullTemplate(),
|
|
10876
|
-
"DB neonFull module does not match the Loom-managed wrapper",
|
|
10877
|
-
],
|
|
10878
|
-
[
|
|
10879
|
-
config.modules.drizzleConfig,
|
|
10880
|
-
dbDrizzleConfigTemplate(config),
|
|
10881
|
-
"Drizzle config does not match the Loom-managed wrapper",
|
|
10882
|
-
],
|
|
10883
|
-
[
|
|
10884
|
-
config.modules.pgliteHarnessModule,
|
|
10885
|
-
dbPgliteHarnessTemplate(config, testRunner),
|
|
10886
|
-
"PGlite test harness does not match the Loom-managed wrapper",
|
|
10887
|
-
],
|
|
10888
|
-
[
|
|
10889
|
-
config.modules.scriptsTsconfig,
|
|
10890
|
-
dbScriptsTsconfigTemplate(),
|
|
10891
|
-
"DB scripts tsconfig does not match the Loom-managed template",
|
|
10892
|
-
],
|
|
10893
|
-
[
|
|
10894
|
-
config.modules.refinementsCommonModule,
|
|
10895
|
-
dbRefinementsCommonTemplate(),
|
|
10896
|
-
"Valibot refinements common module does not match the Loom-managed wrapper",
|
|
10897
|
-
],
|
|
10898
|
-
];
|
|
10899
|
-
for (const [relativePath, expectedText, message] of exactManagedFileChecks) {
|
|
10900
|
-
const currentText = await readTextIfExists((0, node_path_1.join)(cwd, relativePath));
|
|
11321
|
+
for (const managedFile of getDbManagedFiles(config, testRunner, tooling)) {
|
|
11322
|
+
const currentText = await readTextIfExists((0, node_path_1.join)(cwd, managedFile.relativePath));
|
|
10901
11323
|
if (!currentText)
|
|
10902
11324
|
continue;
|
|
10903
|
-
|
|
10904
|
-
|
|
11325
|
+
const classification = await (0, managedFiles_js_1.classifyManagedFile)(currentText, managedFile.text, {
|
|
11326
|
+
knownOutputs: managedFile.knownOutputs,
|
|
11327
|
+
recordedHash: recordedManagedFileHash(feature, managedFile.relativePath),
|
|
11328
|
+
});
|
|
11329
|
+
if (classification.state === "current")
|
|
11330
|
+
continue;
|
|
11331
|
+
if (classification.state === "customized") {
|
|
11332
|
+
issues.push(`${managedFile.mismatch}: ${managedFile.relativePath} (${classification.difference})`);
|
|
11333
|
+
suggestions.add("Loom does not overwrite local edits in its DB wrappers: move app-specific code to a separate module, delete the edited wrapper, then run `loom add db` to restore it.");
|
|
11334
|
+
}
|
|
11335
|
+
else {
|
|
11336
|
+
issues.push(`${managedFile.mismatch}: ${managedFile.relativePath}`);
|
|
10905
11337
|
suggestions.add("Run `loom add db` to restore the Loom-managed DB wrappers.");
|
|
10906
11338
|
}
|
|
10907
11339
|
}
|
|
@@ -10932,20 +11364,24 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10932
11364
|
}
|
|
10933
11365
|
}
|
|
10934
11366
|
}
|
|
10935
|
-
const
|
|
10936
|
-
const
|
|
10937
|
-
const expectedBarrelText = buildValibotBarrelText(generatedNames, refinementNames);
|
|
11367
|
+
const barrel = await readValibotBarrelState(cwd, config);
|
|
11368
|
+
const expectedBarrelText = barrel.text;
|
|
10938
11369
|
const barrelPath = (0, node_path_1.join)(cwd, config.modules.valibotBarrelModule);
|
|
10939
11370
|
const barrelText = await readTextIfExists(barrelPath);
|
|
10940
11371
|
if (expectedBarrelText) {
|
|
10941
|
-
|
|
11372
|
+
const classification = await (0, managedFiles_js_1.classifyManagedFile)(barrelText, expectedBarrelText, barrel.proof);
|
|
11373
|
+
if (classification.state === "missing") {
|
|
10942
11374
|
issues.push(`Valibot barrel is missing while generated/refinement modules exist: ${config.modules.valibotBarrelModule}`);
|
|
10943
11375
|
suggestions.add("Run `loom db schema-gen` to refresh generated validation exports.");
|
|
10944
11376
|
}
|
|
10945
|
-
else if (
|
|
11377
|
+
else if (classification.state === "loom-output") {
|
|
10946
11378
|
issues.push(`Valibot barrel does not match the generated/refinement modules: ${config.modules.valibotBarrelModule}`);
|
|
10947
11379
|
suggestions.add("Run `loom db schema-gen` to rebuild the generated validation exports and barrel.");
|
|
10948
11380
|
}
|
|
11381
|
+
else if (classification.state === "customized") {
|
|
11382
|
+
issues.push(`Valibot barrel does not match the generated/refinement modules: ${config.modules.valibotBarrelModule} (${classification.difference})`);
|
|
11383
|
+
suggestions.add(`Loom does not overwrite hand-written exports in ${config.modules.valibotBarrelModule}: keep only \`export * from\` lines for the generated and refinement modules there, or add the missing exports by hand.`);
|
|
11384
|
+
}
|
|
10949
11385
|
}
|
|
10950
11386
|
else if (barrelText) {
|
|
10951
11387
|
warnings.push(`Valibot barrel exists but no generated/refinement modules were discovered: ${config.modules.valibotBarrelModule}`);
|
|
@@ -12672,6 +13108,8 @@ async function checkLinguiFeature(cwd, framework, manifest, options) {
|
|
|
12672
13108
|
issues.push(`Lingui config is missing: ${config.configFile}`);
|
|
12673
13109
|
suggestions.add("Run `loom add lingui`.");
|
|
12674
13110
|
}
|
|
13111
|
+
// Missing or broken tasks are issues below; edited working ones only warn.
|
|
13112
|
+
addCustomizedTaskWarnings(await checkManagedTasks(cwd, manifest, feature, getLinguiManagedTasks(config, tooling)), "lingui", warnings, suggestions);
|
|
12675
13113
|
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
12676
13114
|
if (!linguiTaskRuns((0, projectTooling_js_1.getTaskCommand)(taskStore.definitions[config.tasks.extract]), "extract")) {
|
|
12677
13115
|
issues.push(`Lingui extraction task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.extract}`);
|
|
@@ -12793,6 +13231,9 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
12793
13231
|
suggestions.add("Run `loom add pwa`.");
|
|
12794
13232
|
}
|
|
12795
13233
|
}
|
|
13234
|
+
// A missing or broken pwa:build is an issue below; an edited working one
|
|
13235
|
+
// only warns.
|
|
13236
|
+
addCustomizedTaskWarnings(await checkManagedTasks(cwd, manifest, feature, PWA_MANAGED_TASKS), "pwa", warnings, suggestions);
|
|
12796
13237
|
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
12797
13238
|
if (!scriptRunsSerwistBuild((0, projectTooling_js_1.getTaskCommand)(taskStore.definitions["pwa:build"]))) {
|
|
12798
13239
|
issues.push(`PWA task in ${tooling.tasks.config} does not build Serwist: pwa:build`);
|
|
@@ -12884,6 +13325,15 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
12884
13325
|
}
|
|
12885
13326
|
const clientProviderText = await readTextIfExists((0, node_path_1.join)(cwd, config.modules.clientProviderModule));
|
|
12886
13327
|
if (clientProviderText) {
|
|
13328
|
+
if (config.provider.managed) {
|
|
13329
|
+
const classification = await (0, managedFiles_js_1.classifyManagedFile)(clientProviderText, pwaClientProviderTemplate(config), {
|
|
13330
|
+
recordedHash: recordedManagedFileHash(feature, config.modules.clientProviderModule),
|
|
13331
|
+
});
|
|
13332
|
+
if (classification.state === "customized") {
|
|
13333
|
+
warnings.push(`PWA client provider is recorded as Loom-managed but has local edits that Loom will not overwrite: ${config.modules.clientProviderModule} (${classification.difference})`);
|
|
13334
|
+
suggestions.add(`PWA client provider ${config.modules.clientProviderModule}: ${PWA_CUSTOMIZED_PROVIDER_RESOLUTION}`);
|
|
13335
|
+
}
|
|
13336
|
+
}
|
|
12887
13337
|
if (!await isPwaClientProviderMounted(cwd, framework, config)) {
|
|
12888
13338
|
issues.push(`PWA client provider is not mounted by the app root provider tree: ${config.modules.clientProviderModule}`);
|
|
12889
13339
|
suggestions.add("Wrap the app root layout or existing client provider with LoomPwaProvider.");
|
|
@@ -13080,11 +13530,9 @@ async function initProject(cwd, versionRange) {
|
|
|
13080
13530
|
notes.push(...packageSkillInit.notes);
|
|
13081
13531
|
if (await ensureExternalSkillsGitignore(cwd))
|
|
13082
13532
|
changedFiles.push(".gitignore");
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13086
|
-
if (manifestChanged) {
|
|
13087
|
-
await (0, promises_1.writeFile)(loomManifestPath, manifestText, "utf8");
|
|
13533
|
+
// The new manifest shares the existing features object, which the feature
|
|
13534
|
+
// hooks update in place, so compare with the file on disk.
|
|
13535
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
13088
13536
|
changedFiles.push("loom.json");
|
|
13089
13537
|
}
|
|
13090
13538
|
return {
|
|
@@ -13110,8 +13558,7 @@ async function addFeature(cwd, featureKey, versionRange) {
|
|
|
13110
13558
|
...skillSync.changedFiles,
|
|
13111
13559
|
];
|
|
13112
13560
|
const notes = [...base.notes, ...result.notes, ...skillSync.notes];
|
|
13113
|
-
|
|
13114
|
-
if (await writeTextIfChanged(manifestPath, stringifyJson(base.manifest))) {
|
|
13561
|
+
if (await writeManifestIfChanged(cwd, base.manifest)) {
|
|
13115
13562
|
changedFiles.push("loom.json");
|
|
13116
13563
|
}
|
|
13117
13564
|
return {
|
|
@@ -13169,7 +13616,7 @@ async function integrateApiKeysJobs(cwd, permission, allowQueryParam = false) {
|
|
|
13169
13616
|
};
|
|
13170
13617
|
feature.config = config;
|
|
13171
13618
|
manifest.features["api-keys"] = feature;
|
|
13172
|
-
const changed = await
|
|
13619
|
+
const changed = await writeManifestIfChanged(cwd, manifest);
|
|
13173
13620
|
return {
|
|
13174
13621
|
changedFiles: changed ? ["loom.json"] : [],
|
|
13175
13622
|
notes: [
|
|
@@ -13207,7 +13654,7 @@ async function configureApiKeyRetention(cwd, enabled, overrides = {}) {
|
|
|
13207
13654
|
};
|
|
13208
13655
|
feature.config = config;
|
|
13209
13656
|
manifest.features["api-keys"] = feature;
|
|
13210
|
-
const changed = await
|
|
13657
|
+
const changed = await writeManifestIfChanged(cwd, manifest);
|
|
13211
13658
|
return {
|
|
13212
13659
|
changedFiles: changed ? ["loom.json"] : [],
|
|
13213
13660
|
notes: enabled
|
|
@@ -13351,7 +13798,7 @@ async function checkProject(cwd, env = node_process_1.default.env, options = {})
|
|
|
13351
13798
|
for (const suggestion of agentsCheck.suggestions) {
|
|
13352
13799
|
suggestions.add(suggestion);
|
|
13353
13800
|
}
|
|
13354
|
-
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest);
|
|
13801
|
+
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest, framework);
|
|
13355
13802
|
for (const issue of envRunnerCheck.issues) {
|
|
13356
13803
|
issues.push(issue);
|
|
13357
13804
|
}
|
|
@@ -14424,9 +14871,12 @@ async function runDbSchemaGen(cwd, forwardedArgs, io) {
|
|
|
14424
14871
|
io.out("Biome is not installed; generated Valibot files were left unformatted.");
|
|
14425
14872
|
}
|
|
14426
14873
|
}
|
|
14427
|
-
|
|
14874
|
+
const barrelSync = await syncValibotBarrel(cwd, config);
|
|
14875
|
+
if (barrelSync.changed) {
|
|
14428
14876
|
io.out(`Updated ${config.modules.valibotBarrelModule}.`);
|
|
14429
14877
|
}
|
|
14878
|
+
if (barrelSync.note)
|
|
14879
|
+
io.out(`Note: ${barrelSync.note}`);
|
|
14430
14880
|
return 0;
|
|
14431
14881
|
}
|
|
14432
14882
|
async function runDbFixtures(cwd, forwardedArgs) {
|