@gadicc/loom 1.35.1 → 1.35.3
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/esm/src/mail/postal.d.ts.map +1 -1
- package/esm/src/mail/postal.js +2 -1
- 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/script/src/mail/postal.d.ts.map +1 -1
- package/script/src/mail/postal.js +2 -1
- 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/esm/src/cli/mod.js
CHANGED
|
@@ -13,13 +13,15 @@ import { resolveProductionBranch, } from "./releaseConfig.js";
|
|
|
13
13
|
import { configureGithubVercelReleaseCredential, } from "./releaseCredentials.js";
|
|
14
14
|
import { runGithubReleaseTrustCommand } from "./releaseTrustCommand.js";
|
|
15
15
|
import { checkLocalDatabase, setupLocalDatabase } from "./localDb.js";
|
|
16
|
+
import { classifyManagedFile, classifyManagedTask, describeManagedFileDifference, hashManagedFileText, removeManagedFile, syncManagedFile, } from "./managedFiles.js";
|
|
17
|
+
import { legacyDbPgliteHarnessOutputs, legacyDbTaskValues, legacyJobsDirectRunnerOutputs, legacyJobsTaskValues, } from "./legacyManagedOutputs.js";
|
|
16
18
|
import { BETTER_AUTH_API_KEY_HTTP_PATHS } from "../apiKeys/betterAuth.js";
|
|
17
19
|
import { DEFAULT_API_KEY_AUDIT_RETENTION } from "../apiKeys/retention.js";
|
|
18
20
|
import { checkProjectSkills, getProjectSkillStatus, LOOM_EXTERNAL_SKILLS_GITIGNORE_LINE, removeLegacyNextSkillLink, setProjectSkillDisabled, syncExternalProjectSkills, syncInstalledPackageSkills, } from "./projectSkills.js";
|
|
19
21
|
import { resolveMigrationEnvironment, resolveMigrationEnvironmentFromEnvFile, verifyMigrationConnection, verifyMigrationConnectionFromEnvFile, } from "./migrationEnv.js";
|
|
20
22
|
import { prepareVercelBuildEnvironment, verifyVercelBuildArtifact, } from "./vercelBuildEnv.js";
|
|
21
23
|
import { parseVercelReleaseTimeout, prepareVercelProjectRelease, promoteVercelProjectRelease, } from "./vercelProjectRelease.js";
|
|
22
|
-
import { detectProjectTooling, ensureTask, ensureTaskFollowup, ensureTaskPrerequisite, findTaskConflicts, formatTaskInvocation, getTaskCommand, mutateDenoLinks, mutatePackageJsonOverride, mutateProjectDependencies, parseJsonc, readDenoLinks, readProjectPackageMetadata, readTaskStore, taskInvokes, taskRunsBeforeCommand, } from "./projectTooling.js";
|
|
24
|
+
import { detectProjectTooling, ensureTask, ensureTaskFollowup, ensureTaskPrerequisite, findTaskConflicts, formatTaskInvocation, getTaskCommand, jsonValuesEqual, mutateDenoLinks, mutatePackageJsonOverride, mutateProjectDependencies, parseJsonc, patchJsonText, readDenoLinks, readProjectPackageMetadata, readTaskStore, taskInvokes, taskRunsBeforeCommand, } from "./projectTooling.js";
|
|
23
25
|
import { withLocalDevLock, } from "./localDevLock.js";
|
|
24
26
|
import { computeLoomSourceFingerprint, computePackageContentDigest, computePackageTreeSignature, findNewPeerVariantDuplicates, findPackageTreeDifference, formatLoomBuildStamp, getLockfileOverride, getLockfileRootImporterDependency, hasLoomBuildProvenance, LOOM_BUILD_STAMP_FILE, LOOM_PACKAGE_RELEVANT_PATHS, readLoomBuildStamp, } from "./localDevPackage.js";
|
|
25
27
|
export const DEFAULT_LOOM_RANGE = "^1.0.0";
|
|
@@ -317,6 +319,62 @@ async function writeTextIfChanged(path, text) {
|
|
|
317
319
|
await writeFile(path, text, "utf8");
|
|
318
320
|
return true;
|
|
319
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Writes loom.json when its data changed, ignoring key order. An existing
|
|
324
|
+
* file is patched member by member, so the consumer's formatting and key
|
|
325
|
+
* order survive and a formatter such as Biome has nothing to change; only a
|
|
326
|
+
* new file is written whole.
|
|
327
|
+
*/
|
|
328
|
+
async function writeManifestIfChanged(cwd, manifest) {
|
|
329
|
+
const path = join(cwd, "loom.json");
|
|
330
|
+
const currentText = await readTextIfExists(path);
|
|
331
|
+
if (currentText === null) {
|
|
332
|
+
await writeFile(path, stringifyJson(manifest), "utf8");
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
if (jsonValuesEqual(parseJson(currentText, "loom.json"), manifest)) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
await writeFile(path, patchJsonText(currentText, manifest), "utf8");
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
function recordedManagedFileHash(feature, relativePath) {
|
|
342
|
+
return feature?.managedFiles?.[relativePath];
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Notes one managed-file sync in `records`: Loom's hash when the file now
|
|
346
|
+
* holds or matches Loom output, otherwise the previous record, so the file is
|
|
347
|
+
* recognised again if its local edits are reverted.
|
|
348
|
+
*/
|
|
349
|
+
function recordManagedFileSync(records, feature, relativePath, result) {
|
|
350
|
+
const hash = result.hash ?? recordedManagedFileHash(feature, relativePath);
|
|
351
|
+
if (hash)
|
|
352
|
+
records[relativePath] = hash;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Reports a managed file Loom left alone because it has local edits, naming
|
|
356
|
+
* the file, the difference and how to resolve it.
|
|
357
|
+
*/
|
|
358
|
+
function formatPreservedManagedFileNote(relativePath, difference, resolution) {
|
|
359
|
+
return `Preserved local edits in Loom-managed ${relativePath}${difference ? ` (${difference})` : ""}; Loom did not update it. ${resolution}`;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Replaces a feature's managed-file or managed-task record with what this
|
|
363
|
+
* sync manages, sorted so loom.json stays stable. Entries Loom no longer
|
|
364
|
+
* manages drop out.
|
|
365
|
+
*/
|
|
366
|
+
function setManagedRecords(feature, key, records) {
|
|
367
|
+
const entries = Object.entries(records).sort(([left], [right]) => left.localeCompare(right));
|
|
368
|
+
if (entries.length) {
|
|
369
|
+
feature[key] = Object.fromEntries(entries);
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
delete feature[key];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function setManagedFileRecords(feature, records) {
|
|
376
|
+
setManagedRecords(feature, "managedFiles", records);
|
|
377
|
+
}
|
|
320
378
|
export async function defaultCommandRunner(command, args, options) {
|
|
321
379
|
return await new Promise((resolvePromise) => {
|
|
322
380
|
const inherit = options.stdio === "inherit" ||
|
|
@@ -505,7 +563,7 @@ function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
|
505
563
|
return (scriptName === "job" || scriptCommand.includes("jobDirect.ts")) &&
|
|
506
564
|
!scriptUsesLoomEnvRunner(scriptCommand);
|
|
507
565
|
}
|
|
508
|
-
async function checkEnvRunnerAdoption(cwd, manifest) {
|
|
566
|
+
async function checkEnvRunnerAdoption(cwd, manifest, framework) {
|
|
509
567
|
const issues = [];
|
|
510
568
|
const suggestions = new Set();
|
|
511
569
|
const activeDb = manifest.features.db?.status === "active";
|
|
@@ -522,23 +580,53 @@ async function checkEnvRunnerAdoption(cwd, manifest) {
|
|
|
522
580
|
}
|
|
523
581
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
524
582
|
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
583
|
+
// `loom add` refreshes only tasks whose value is provably Loom's; an edited
|
|
584
|
+
// task has to be moved onto `loom env` by hand.
|
|
585
|
+
const loomTasks = new Map();
|
|
586
|
+
if (activeDb) {
|
|
587
|
+
const dbConfig = mergeDbConfig(framework, manifest.features.db.config);
|
|
588
|
+
for (const task of getDbManagedTasks(dbConfig, tooling)) {
|
|
589
|
+
loomTasks.set(task.name, [manifest.features.db, task]);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (activeJobs) {
|
|
593
|
+
const jobsConfig = mergeJobsConfig(framework, manifest.features.jobs.config);
|
|
594
|
+
for (const task of getJobsManagedTasks(jobsConfig)) {
|
|
595
|
+
loomTasks.set(task.name, [manifest.features.jobs, task]);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const loomRefreshes = (name, definition) => {
|
|
599
|
+
const entry = loomTasks.get(name);
|
|
600
|
+
if (!entry)
|
|
601
|
+
return false;
|
|
602
|
+
const [feature, task] = entry;
|
|
603
|
+
return classifyManagedTask(definition, task.definition, {
|
|
604
|
+
knownValues: task.knownValues,
|
|
605
|
+
recordedHash: feature.managedTasks?.[name],
|
|
606
|
+
}).state !== "customized";
|
|
607
|
+
};
|
|
608
|
+
const handEditSuggestion = (name) => `Loom does not overwrite edited tasks: change ${name} in ${taskStore.config} to run its command through \`loom env -- <command>\`.`;
|
|
525
609
|
for (const [scriptName, definition] of Object.entries(taskStore.definitions)) {
|
|
526
610
|
const scriptCommand = getTaskCommand(definition);
|
|
527
611
|
if (activeDb && dbScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
528
612
|
issues.push(taskStore.config === "package.json"
|
|
529
613
|
? `DB package.json script bypasses the Loom env runner: ${scriptName}`
|
|
530
614
|
: `DB task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
531
|
-
suggestions.add(
|
|
532
|
-
?
|
|
533
|
-
:
|
|
615
|
+
suggestions.add(!loomRefreshes(scriptName, definition)
|
|
616
|
+
? handEditSuggestion(scriptName)
|
|
617
|
+
: taskStore.config === "package.json"
|
|
618
|
+
? "Run `loom add db` to refresh DB package scripts."
|
|
619
|
+
: "Run `loom add db` to refresh DB tasks.");
|
|
534
620
|
}
|
|
535
621
|
if (activeJobs && jobsScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
536
622
|
issues.push(taskStore.config === "package.json"
|
|
537
623
|
? `Jobs package.json script bypasses the Loom env runner: ${scriptName}`
|
|
538
624
|
: `Jobs task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
539
|
-
suggestions.add(
|
|
540
|
-
?
|
|
541
|
-
:
|
|
625
|
+
suggestions.add(!loomRefreshes(scriptName, definition)
|
|
626
|
+
? handEditSuggestion(scriptName)
|
|
627
|
+
: taskStore.config === "package.json"
|
|
628
|
+
? "Run `loom add jobs` to refresh jobs package scripts."
|
|
629
|
+
: "Run `loom add jobs` to refresh jobs tasks.");
|
|
542
630
|
}
|
|
543
631
|
}
|
|
544
632
|
return {
|
|
@@ -1072,25 +1160,89 @@ export function ensurePackageJsonDependency(packageJson, versionRange = DEFAULT_
|
|
|
1072
1160
|
async function getProjectTooling(cwd, manifest) {
|
|
1073
1161
|
return await detectProjectTooling(cwd, manifest.project?.tooling);
|
|
1074
1162
|
}
|
|
1075
|
-
|
|
1163
|
+
function formatTaskValue(definition) {
|
|
1164
|
+
return `\`${typeof definition === "string" ? definition : JSON.stringify(definition)}\``;
|
|
1165
|
+
}
|
|
1166
|
+
/** Shows a kept task's local value next to Loom's value. */
|
|
1167
|
+
function formatCustomizedTaskValues({ current, task }) {
|
|
1168
|
+
return `(local: ${formatTaskValue(current)}; Loom: ${formatTaskValue(task.definition)})`;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Creates missing Loom-owned tasks and updates those whose value is provably
|
|
1172
|
+
* Loom's (recorded hash, current value or a known earlier value), through
|
|
1173
|
+
* localized edits of the config `project.tooling` records. Edited tasks are
|
|
1174
|
+
* left alone and returned so the caller can report them.
|
|
1175
|
+
*/
|
|
1176
|
+
async function syncManagedTasks(cwd, manifest, feature, tasks) {
|
|
1076
1177
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
1077
1178
|
const changedKeys = [];
|
|
1078
|
-
|
|
1079
|
-
|
|
1179
|
+
const customized = [];
|
|
1180
|
+
const records = {};
|
|
1181
|
+
for (const task of tasks) {
|
|
1182
|
+
const store = await readTaskStore(cwd, tooling.tasks);
|
|
1183
|
+
const current = store.definitions[task.name];
|
|
1184
|
+
const classification = classifyManagedTask(current, task.definition, {
|
|
1185
|
+
knownValues: task.knownValues,
|
|
1186
|
+
recordedHash: feature?.managedTasks?.[task.name],
|
|
1187
|
+
});
|
|
1188
|
+
if (classification.state === "customized") {
|
|
1189
|
+
customized.push({ current, task });
|
|
1190
|
+
const previous = feature?.managedTasks?.[task.name];
|
|
1191
|
+
if (previous)
|
|
1192
|
+
records[task.name] = previous;
|
|
1193
|
+
continue;
|
|
1194
|
+
}
|
|
1195
|
+
records[task.name] = classification.expectedHash;
|
|
1196
|
+
// A value that matches apart from whitespace keeps the app's spelling.
|
|
1197
|
+
if (classification.state === "current")
|
|
1198
|
+
continue;
|
|
1199
|
+
const result = await ensureTask(cwd, tooling.tasks, {
|
|
1200
|
+
definition: task.definition,
|
|
1201
|
+
name: task.name,
|
|
1202
|
+
});
|
|
1080
1203
|
if (result.changed)
|
|
1081
|
-
changedKeys.push(name);
|
|
1204
|
+
changedKeys.push(task.name);
|
|
1082
1205
|
}
|
|
1083
|
-
return { changedKeys, config: tooling.tasks.config,
|
|
1206
|
+
return { changedKeys, config: tooling.tasks.config, customized, records };
|
|
1084
1207
|
}
|
|
1085
|
-
|
|
1208
|
+
/**
|
|
1209
|
+
* Compares Loom-owned tasks with Loom's values without writing: `mismatches`
|
|
1210
|
+
* are missing tasks or unedited older Loom values that `loom add` updates;
|
|
1211
|
+
* `customized` tasks have edits Loom will not overwrite.
|
|
1212
|
+
*/
|
|
1213
|
+
async function checkManagedTasks(cwd, manifest, feature, tasks) {
|
|
1086
1214
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
1087
1215
|
const store = await readTaskStore(cwd, tooling.tasks);
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
store
|
|
1092
|
-
|
|
1093
|
-
|
|
1216
|
+
const mismatches = [];
|
|
1217
|
+
const customized = [];
|
|
1218
|
+
for (const task of tasks) {
|
|
1219
|
+
const current = store.definitions[task.name];
|
|
1220
|
+
const { state } = classifyManagedTask(current, task.definition, {
|
|
1221
|
+
knownValues: task.knownValues,
|
|
1222
|
+
recordedHash: feature?.managedTasks?.[task.name],
|
|
1223
|
+
});
|
|
1224
|
+
if (state === "customized") {
|
|
1225
|
+
customized.push({ current, task });
|
|
1226
|
+
}
|
|
1227
|
+
else if (state !== "current") {
|
|
1228
|
+
mismatches.push(task.name);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
return { config: tooling.tasks.config, customized, mismatches, store };
|
|
1232
|
+
}
|
|
1233
|
+
/** Notes for Loom-owned tasks that `loom init` or `loom add` left alone. */
|
|
1234
|
+
function formatPreservedTaskNotes(sync, featureKey) {
|
|
1235
|
+
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}\`.`);
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* `loom check` warnings for Loom-owned tasks with local edits, naming each
|
|
1239
|
+
* task and showing both values.
|
|
1240
|
+
*/
|
|
1241
|
+
function addCustomizedTaskWarnings(check, featureKey, warnings, suggestions) {
|
|
1242
|
+
for (const customized of check.customized) {
|
|
1243
|
+
warnings.push(`Loom-managed task ${customized.task.name} in ${check.config} has local edits that Loom will not overwrite ${formatCustomizedTaskValues(customized)}`);
|
|
1244
|
+
suggestions.add(`To restore Loom's value for an edited ${featureKey} task, delete the task and rerun \`loom add ${featureKey}\`.`);
|
|
1245
|
+
}
|
|
1094
1246
|
}
|
|
1095
1247
|
export function buildManifest(cwd, packageJson, framework, existingManifest, tooling) {
|
|
1096
1248
|
return {
|
|
@@ -1436,6 +1588,14 @@ function getDbExpectedScripts(config, tooling) {
|
|
|
1436
1588
|
"schema:gen": "loom db schema-gen",
|
|
1437
1589
|
};
|
|
1438
1590
|
}
|
|
1591
|
+
function getDbManagedTasks(config, tooling) {
|
|
1592
|
+
const legacy = legacyDbTaskValues(config.modules.drizzleConfig);
|
|
1593
|
+
return Object.entries(getDbExpectedScripts(config, tooling)).map(([name, definition]) => ({
|
|
1594
|
+
definition,
|
|
1595
|
+
knownValues: legacy[name] ?? [],
|
|
1596
|
+
name,
|
|
1597
|
+
}));
|
|
1598
|
+
}
|
|
1439
1599
|
function mergeDbConfig(framework, featureConfig) {
|
|
1440
1600
|
const defaults = getDbConfig(framework);
|
|
1441
1601
|
return {
|
|
@@ -3094,6 +3254,15 @@ function compareParsedVersions(left, right) {
|
|
|
3094
3254
|
}
|
|
3095
3255
|
return left.prerelease.localeCompare(right.prerelease);
|
|
3096
3256
|
}
|
|
3257
|
+
/**
|
|
3258
|
+
* Whether `version` is a newer release than the exact pin `pinned`. Pin
|
|
3259
|
+
* advice must never suggest moving an app back to an older Loom.
|
|
3260
|
+
*/
|
|
3261
|
+
function isNewerLoomVersion(version, pinned) {
|
|
3262
|
+
const candidate = parseSemverTag(version);
|
|
3263
|
+
const pin = parseSemverTag(pinned);
|
|
3264
|
+
return !!candidate && !!pin && compareParsedVersions(candidate, pin) > 0;
|
|
3265
|
+
}
|
|
3097
3266
|
async function findPublishedLoomPublicationForCommit(sourceRoot, sourceCommit, commandRunner, env, preferredSpec,
|
|
3098
3267
|
/** Names the commit in refusals, such as "Loom commit abc, which built X,". */
|
|
3099
3268
|
subject) {
|
|
@@ -4000,8 +4169,17 @@ async function usePublishedDevPackageLocked(cwd, options) {
|
|
|
4000
4169
|
lockfileText,
|
|
4001
4170
|
preferredSpec: publishedSpec,
|
|
4002
4171
|
});
|
|
4003
|
-
publishedSpec = proof.publication.version;
|
|
4004
4172
|
notes.push(proof.note);
|
|
4173
|
+
// Never move an exact pin back: a checkout without the newest tags names
|
|
4174
|
+
// the oldest release it knows that covers the build, and a newer pin
|
|
4175
|
+
// (Loom releases only from main) covers it too.
|
|
4176
|
+
if (isExactSemverVersion(publishedSpec) &&
|
|
4177
|
+
isNewerLoomVersion(publishedSpec, proof.publication.version)) {
|
|
4178
|
+
notes.push(`The pinned ${LOOM_DEPENDENCY}@${publishedSpec} is newer than ${proof.publication.version}, so the pin stays at ${publishedSpec}.`);
|
|
4179
|
+
}
|
|
4180
|
+
else {
|
|
4181
|
+
publishedSpec = proof.publication.version;
|
|
4182
|
+
}
|
|
4005
4183
|
}
|
|
4006
4184
|
const changedFiles = [];
|
|
4007
4185
|
let catalogChanged = false;
|
|
@@ -4584,7 +4762,7 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
4584
4762
|
await exists(devState.sourceRoot)) {
|
|
4585
4763
|
const publication = await resolveLoomCommitPublication(devState.sourceRoot, devState.sourceCommit, options.commandRunner, options.env, dependency);
|
|
4586
4764
|
if (publication.status === "published" &&
|
|
4587
|
-
publication.version
|
|
4765
|
+
isNewerLoomVersion(publication.version, dependency)) {
|
|
4588
4766
|
warnings.push(`This app was last synced against Loom commit ${shortCommit}; ${publication.reason === "package-equivalent"
|
|
4589
4767
|
? `package-relevant files match ${LOOM_DEPENDENCY}@${publication.version}`
|
|
4590
4768
|
: `it is published as ${LOOM_DEPENDENCY}@${publication.version}`}, but ${pinLocation} is pinned to ${dependency}.`);
|
|
@@ -4618,9 +4796,17 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
4618
4796
|
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.`);
|
|
4619
4797
|
suggestions.add("Publish Loom first, fetch tags, then rerun `loom dev published`.");
|
|
4620
4798
|
break;
|
|
4621
|
-
case "published":
|
|
4622
|
-
|
|
4623
|
-
|
|
4799
|
+
case "published": {
|
|
4800
|
+
// Advice only ever moves the pin forward. A checkout without the
|
|
4801
|
+
// newest tags reports the oldest release it knows that contains
|
|
4802
|
+
// the commit; an exact pin newer than that covers it too.
|
|
4803
|
+
const pinCovers = !!dependency &&
|
|
4804
|
+
isExactSemverVersion(dependency) &&
|
|
4805
|
+
!isNewerLoomVersion(publication.version, dependency);
|
|
4806
|
+
const coveringVersion = pinCovers && dependency
|
|
4807
|
+
? dependency
|
|
4808
|
+
: publication.version;
|
|
4809
|
+
if (dependency && isExactSemverVersion(dependency) && !pinCovers) {
|
|
4624
4810
|
const publicationDescription = publication.reason ===
|
|
4625
4811
|
"package-equivalent"
|
|
4626
4812
|
? `package-relevant files match ${LOOM_DEPENDENCY}@${publication.version}`
|
|
@@ -4635,16 +4821,20 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
4635
4821
|
"package-equivalent"
|
|
4636
4822
|
? `has no package-relevant changes after ${publication.tag}, so ${LOOM_DEPENDENCY}@${publication.version} covers it`
|
|
4637
4823
|
: `is published as ${LOOM_DEPENDENCY}@${publication.version}`;
|
|
4638
|
-
|
|
4824
|
+
const newerPin = coveringVersion !== publication.version
|
|
4825
|
+
? ` (the pinned ${coveringVersion} is newer)`
|
|
4826
|
+
: "";
|
|
4827
|
+
warnings.push(`The synced Loom commit ${shortCommit} ${publicationDescription}${newerPin}; refresh the lockfile away from ${localLockfileResolution}.`);
|
|
4639
4828
|
suggestions.add(pnpmOverrideActive
|
|
4640
4829
|
? "Run `loom dev published`, which pins the covering version, then run `pnpm install`."
|
|
4641
|
-
: catalogName && dependency ===
|
|
4830
|
+
: catalogName && dependency === coveringVersion
|
|
4642
4831
|
// pnpm keeps a local resolution while the catalog version
|
|
4643
4832
|
// it was linked under is unchanged.
|
|
4644
4833
|
? "Restore pnpm-lock.yaml from git and run `pnpm install`."
|
|
4645
|
-
: pinSuggestion(
|
|
4834
|
+
: pinSuggestion(coveringVersion));
|
|
4646
4835
|
}
|
|
4647
4836
|
break;
|
|
4837
|
+
}
|
|
4648
4838
|
}
|
|
4649
4839
|
}
|
|
4650
4840
|
}
|
|
@@ -5723,9 +5913,16 @@ function getJobsExpectedScripts(config) {
|
|
|
5723
5913
|
job: `TSX_TSCONFIG=./${JOBS_SCRIPTS_TSCONFIG_PATH} loom env -- node --conditions=react-server --import tsx ${config.directRunner.scriptPath}`,
|
|
5724
5914
|
};
|
|
5725
5915
|
}
|
|
5726
|
-
function
|
|
5916
|
+
function getJobsManagedTasks(config) {
|
|
5917
|
+
const legacy = legacyJobsTaskValues(JOBS_SCRIPTS_TSCONFIG_PATH, config.directRunner.scriptPath);
|
|
5918
|
+
return Object.entries(getJobsExpectedScripts(config)).map(([name, definition]) => ({ definition, knownValues: legacy[name] ?? [], name }));
|
|
5919
|
+
}
|
|
5920
|
+
function getJobsDirectRunnerCatalogImportPath(config, framework) {
|
|
5727
5921
|
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
5728
|
-
|
|
5922
|
+
return toRelativeImportPath(config.directRunner.scriptPath, `${jobsRoot}/index.ts`);
|
|
5923
|
+
}
|
|
5924
|
+
function jobsDirectRunnerTemplate(config, framework) {
|
|
5925
|
+
const catalogImportPath = getJobsDirectRunnerCatalogImportPath(config, framework);
|
|
5729
5926
|
return `import {
|
|
5730
5927
|
createJobCatalogFromSource,
|
|
5731
5928
|
createJobExecution,
|
|
@@ -5855,24 +6052,64 @@ function jobsThinRouteTemplate(source) {
|
|
|
5855
6052
|
export const maxDuration = ${DEFAULT_JOBS_MAX_DURATION_SECONDS};
|
|
5856
6053
|
`;
|
|
5857
6054
|
}
|
|
5858
|
-
function
|
|
5859
|
-
if (!config.staticRoutes) {
|
|
5860
|
-
throw new Error("Static jobs route config is required");
|
|
5861
|
-
}
|
|
6055
|
+
function renderJobsStaticRoute(values) {
|
|
5862
6056
|
return `${LOOM_MANAGED_STATIC_JOB_ROUTE_MARKER}
|
|
5863
6057
|
// Generated by \`loom add jobs\` from loom.json. Do not edit directly.
|
|
5864
6058
|
|
|
5865
|
-
import { ${
|
|
5866
|
-
import * as job from "${moduleSpecifier}";
|
|
6059
|
+
import { ${values.handlerFactoryExport} } from "${values.routeModuleSpecifier}";
|
|
6060
|
+
import * as job from "${values.moduleSpecifier}";
|
|
5867
6061
|
|
|
5868
6062
|
// Next.js route segment config must be a direct, statically analyzable export.
|
|
5869
|
-
export const maxDuration = ${maxDuration};
|
|
6063
|
+
export const maxDuration = ${values.maxDuration};
|
|
5870
6064
|
|
|
5871
|
-
const handler = ${
|
|
6065
|
+
const handler = ${values.handlerFactoryExport}(job);
|
|
5872
6066
|
|
|
5873
6067
|
export { handler as GET, handler as POST };
|
|
5874
6068
|
`;
|
|
5875
6069
|
}
|
|
6070
|
+
function jobsStaticRouteTemplate(config, moduleSpecifier, maxDuration) {
|
|
6071
|
+
if (!config.staticRoutes) {
|
|
6072
|
+
throw new Error("Static jobs route config is required");
|
|
6073
|
+
}
|
|
6074
|
+
return renderJobsStaticRoute({
|
|
6075
|
+
handlerFactoryExport: config.staticRoutes.handlerFactoryExport,
|
|
6076
|
+
maxDuration,
|
|
6077
|
+
moduleSpecifier,
|
|
6078
|
+
routeModuleSpecifier: toAliasImportPath(config.modules.routeModule),
|
|
6079
|
+
});
|
|
6080
|
+
}
|
|
6081
|
+
/**
|
|
6082
|
+
* Whether a marked static job route is exactly Loom's template for the
|
|
6083
|
+
* configured handler factory and route module, with any job module and
|
|
6084
|
+
* `maxDuration`. Those two values come from loom.json, so such a route is
|
|
6085
|
+
* stale Loom output that Loom may update or remove. A different factory or
|
|
6086
|
+
* route module (an audited wrapper, say), or any other edit, makes the file
|
|
6087
|
+
* the app's. This only covers routes from before Loom recorded their hashes.
|
|
6088
|
+
*/
|
|
6089
|
+
function isLoomJobsStaticRoute(text, config) {
|
|
6090
|
+
if (!config.staticRoutes)
|
|
6091
|
+
return false;
|
|
6092
|
+
if (!text.startsWith(LOOM_MANAGED_STATIC_JOB_ROUTE_MARKER))
|
|
6093
|
+
return false;
|
|
6094
|
+
const job = text.match(/import\s*\*\s*as\s+job\s+from\s*["']([^"']+)["']/);
|
|
6095
|
+
const maxDuration = text.match(/export\s+const\s+maxDuration\s*=\s*(\d+)/);
|
|
6096
|
+
if (!job || !maxDuration)
|
|
6097
|
+
return false;
|
|
6098
|
+
return hashManagedFileText(text) ===
|
|
6099
|
+
hashManagedFileText(renderJobsStaticRoute({
|
|
6100
|
+
handlerFactoryExport: config.staticRoutes.handlerFactoryExport,
|
|
6101
|
+
maxDuration: Number(maxDuration[1]),
|
|
6102
|
+
moduleSpecifier: job[1],
|
|
6103
|
+
routeModuleSpecifier: toAliasImportPath(config.modules.routeModule),
|
|
6104
|
+
}));
|
|
6105
|
+
}
|
|
6106
|
+
function jobsStaticRouteProof(config, feature, relativePath) {
|
|
6107
|
+
return {
|
|
6108
|
+
isLoomOutput: (text) => isLoomJobsStaticRoute(text, config),
|
|
6109
|
+
recordedHash: recordedManagedFileHash(feature, relativePath),
|
|
6110
|
+
};
|
|
6111
|
+
}
|
|
6112
|
+
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.`;
|
|
5876
6113
|
function assertPositiveJobsMaxDuration(value, label) {
|
|
5877
6114
|
if (!Number.isInteger(value) || value <= 0) {
|
|
5878
6115
|
throw new Error(`${label} must be a positive integer`);
|
|
@@ -5940,11 +6177,12 @@ async function findManagedJobsStaticRoutePaths(cwd, config) {
|
|
|
5940
6177
|
}
|
|
5941
6178
|
return managedPaths;
|
|
5942
6179
|
}
|
|
5943
|
-
async function syncJobsStaticRoutes(cwd, config) {
|
|
6180
|
+
async function syncJobsStaticRoutes(cwd, config, feature) {
|
|
5944
6181
|
const changedFiles = [];
|
|
5945
6182
|
const notes = [];
|
|
6183
|
+
const records = {};
|
|
5946
6184
|
if (!config.staticRoutes)
|
|
5947
|
-
return { changedFiles, notes };
|
|
6185
|
+
return { changedFiles, notes, records };
|
|
5948
6186
|
const plans = getJobsStaticRoutePlans(cwd, config);
|
|
5949
6187
|
const expectedPaths = new Set(plans.map((plan) => plan.path));
|
|
5950
6188
|
for (const plan of plans) {
|
|
@@ -5954,21 +6192,33 @@ async function syncJobsStaticRoutes(cwd, config) {
|
|
|
5954
6192
|
notes.push(`Preserved unmanaged jobs static route file: ${plan.relativePath}`);
|
|
5955
6193
|
continue;
|
|
5956
6194
|
}
|
|
5957
|
-
|
|
6195
|
+
const result = await syncManagedFile(plan.path, plan.text, jobsStaticRouteProof(config, feature, plan.relativePath));
|
|
6196
|
+
recordManagedFileSync(records, feature, plan.relativePath, result);
|
|
6197
|
+
if (result.state === "created" || result.state === "updated") {
|
|
5958
6198
|
changedFiles.push(plan.relativePath);
|
|
5959
6199
|
}
|
|
6200
|
+
else if (result.state === "customized") {
|
|
6201
|
+
notes.push(formatPreservedManagedFileNote(plan.relativePath, result.difference, JOBS_STATIC_ROUTE_EDIT_RESOLUTION));
|
|
6202
|
+
}
|
|
5960
6203
|
}
|
|
5961
6204
|
for (const routePath of await findManagedJobsStaticRoutePaths(cwd, config)) {
|
|
5962
6205
|
if (expectedPaths.has(routePath))
|
|
5963
6206
|
continue;
|
|
5964
|
-
|
|
6207
|
+
const relativePath = relative(cwd, routePath).replaceAll("\\", "/");
|
|
6208
|
+
const removal = await removeManagedFile(routePath, jobsStaticRouteProof(config, feature, relativePath));
|
|
6209
|
+
if (removal === "customized") {
|
|
6210
|
+
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.`);
|
|
6211
|
+
continue;
|
|
6212
|
+
}
|
|
6213
|
+
if (removal !== "removed")
|
|
6214
|
+
continue;
|
|
5965
6215
|
const routeDirectory = dirname(routePath);
|
|
5966
6216
|
if ((await readdir(routeDirectory)).length === 0) {
|
|
5967
6217
|
await rm(routeDirectory, { recursive: true });
|
|
5968
6218
|
}
|
|
5969
|
-
changedFiles.push(
|
|
6219
|
+
changedFiles.push(relativePath);
|
|
5970
6220
|
}
|
|
5971
|
-
return { changedFiles, notes };
|
|
6221
|
+
return { changedFiles, notes, records };
|
|
5972
6222
|
}
|
|
5973
6223
|
function pwaSerwistConfigTemplate(config) {
|
|
5974
6224
|
return `import { serwist } from "@serwist/next/config";
|
|
@@ -6023,6 +6273,7 @@ function pwaLifecyclePropLines(config) {
|
|
|
6023
6273
|
: ` updateCheckIntervalMs={${formatTsNumberLiteral(config.updateCheckIntervalMs)}}`,
|
|
6024
6274
|
].filter((line) => line !== null);
|
|
6025
6275
|
}
|
|
6276
|
+
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`.";
|
|
6026
6277
|
function pwaClientProviderTemplate(config) {
|
|
6027
6278
|
const lifecyclePropLines = pwaLifecyclePropLines(config);
|
|
6028
6279
|
const headlessLifecycle = lifecyclePropLines.length
|
|
@@ -6147,6 +6398,57 @@ afterAll(closeMemoryPglite);
|
|
|
6147
6398
|
export const { client, db, tableLoader } = harness;
|
|
6148
6399
|
`;
|
|
6149
6400
|
}
|
|
6401
|
+
function getDbManagedFiles(config, testRunner, tooling) {
|
|
6402
|
+
const schemaImportPath = toRelativeImportPath(config.modules.pgliteHarnessModule, join(config.dirs.schemaDir, "index.ts"));
|
|
6403
|
+
return [
|
|
6404
|
+
{
|
|
6405
|
+
knownOutputs: [],
|
|
6406
|
+
mismatch: "DB neon module does not match the Loom-managed wrapper",
|
|
6407
|
+
relativePath: config.modules.neonModule,
|
|
6408
|
+
text: dbNeonTemplate(),
|
|
6409
|
+
},
|
|
6410
|
+
{
|
|
6411
|
+
knownOutputs: [],
|
|
6412
|
+
mismatch: "DB neonFull module does not match the Loom-managed wrapper",
|
|
6413
|
+
relativePath: config.modules.neonFullModule,
|
|
6414
|
+
text: dbNeonFullTemplate(),
|
|
6415
|
+
},
|
|
6416
|
+
{
|
|
6417
|
+
knownOutputs: [],
|
|
6418
|
+
mismatch: "Drizzle config does not match the Loom-managed wrapper",
|
|
6419
|
+
relativePath: config.modules.drizzleConfig,
|
|
6420
|
+
text: dbDrizzleConfigTemplate(config),
|
|
6421
|
+
},
|
|
6422
|
+
{
|
|
6423
|
+
knownOutputs: [
|
|
6424
|
+
// With Deno tasks the harness follows whether the `test` task runs
|
|
6425
|
+
// vitest, which can change, so either runner's harness may be what
|
|
6426
|
+
// Loom wrote. Other runners only ever got the vitest harness.
|
|
6427
|
+
...(tooling.tasks.runner === "deno"
|
|
6428
|
+
? [
|
|
6429
|
+
dbPgliteHarnessTemplate(config, testRunner === "deno" ? "vitest" : "deno"),
|
|
6430
|
+
]
|
|
6431
|
+
: []),
|
|
6432
|
+
...legacyDbPgliteHarnessOutputs(schemaImportPath, config.dirs.fixtureDir),
|
|
6433
|
+
],
|
|
6434
|
+
mismatch: "PGlite test harness does not match the Loom-managed wrapper",
|
|
6435
|
+
relativePath: config.modules.pgliteHarnessModule,
|
|
6436
|
+
text: dbPgliteHarnessTemplate(config, testRunner),
|
|
6437
|
+
},
|
|
6438
|
+
{
|
|
6439
|
+
knownOutputs: [],
|
|
6440
|
+
mismatch: "DB scripts tsconfig does not match the Loom-managed template",
|
|
6441
|
+
relativePath: config.modules.scriptsTsconfig,
|
|
6442
|
+
text: dbScriptsTsconfigTemplate(),
|
|
6443
|
+
},
|
|
6444
|
+
{
|
|
6445
|
+
knownOutputs: [],
|
|
6446
|
+
mismatch: "Valibot refinements common module does not match the Loom-managed wrapper",
|
|
6447
|
+
relativePath: config.modules.refinementsCommonModule,
|
|
6448
|
+
text: dbRefinementsCommonTemplate(),
|
|
6449
|
+
},
|
|
6450
|
+
];
|
|
6451
|
+
}
|
|
6150
6452
|
async function getDbTestRunner(cwd, tooling) {
|
|
6151
6453
|
if (tooling.tasks.runner !== "deno")
|
|
6152
6454
|
return "vitest";
|
|
@@ -6464,6 +6766,29 @@ function isGeneratedFilesStorageStub(text) {
|
|
|
6464
6766
|
"storageNotConfigured();",
|
|
6465
6767
|
].every((part) => text.includes(part));
|
|
6466
6768
|
}
|
|
6769
|
+
/**
|
|
6770
|
+
* Installs the S3 storage adapter in place of the generated not-configured
|
|
6771
|
+
* stub, but only while the stub is exactly Loom's scaffold: an edited stub is
|
|
6772
|
+
* the app's and stays.
|
|
6773
|
+
*/
|
|
6774
|
+
async function replaceFilesStorageStub(storagePath, relativePath) {
|
|
6775
|
+
const stub = filesStorageTemplate();
|
|
6776
|
+
const result = await syncManagedFile(storagePath, filesS3StorageTemplate(), {
|
|
6777
|
+
knownOutputs: [stub],
|
|
6778
|
+
});
|
|
6779
|
+
if (result.state !== "customized") {
|
|
6780
|
+
return {
|
|
6781
|
+
changed: result.state === "created" || result.state === "updated",
|
|
6782
|
+
note: null,
|
|
6783
|
+
};
|
|
6784
|
+
}
|
|
6785
|
+
// The edits that matter are the app's changes to Loom's stub.
|
|
6786
|
+
const currentText = await readTextIfExists(storagePath) ?? "";
|
|
6787
|
+
return {
|
|
6788
|
+
changed: false,
|
|
6789
|
+
note: formatPreservedManagedFileNote(relativePath, 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."),
|
|
6790
|
+
};
|
|
6791
|
+
}
|
|
6467
6792
|
function filesRouteTemplate(config) {
|
|
6468
6793
|
return `import { createFilesRouteHandlers } from "@gadicc/loom/next/files";
|
|
6469
6794
|
import {
|
|
@@ -7070,14 +7395,88 @@ function buildValibotBarrelText(generatedNames, refinementNames) {
|
|
|
7070
7395
|
? `export * from "./refinements/${name}";`
|
|
7071
7396
|
: `export * from "./generated/${name}";`).join("\n")}\n`;
|
|
7072
7397
|
}
|
|
7073
|
-
|
|
7398
|
+
const VALIBOT_BARREL_LINE = /^export\s*\*\s*from\s*["']\.\/(generated|refinements)\/([^"']+)["']\s*;?$/;
|
|
7399
|
+
async function directoryHasModule(directory, name) {
|
|
7400
|
+
try {
|
|
7401
|
+
return (await readdir(directory)).some((entry) => entry === name || stripModuleExtension(entry) === name);
|
|
7402
|
+
}
|
|
7403
|
+
catch (error) {
|
|
7404
|
+
if (isNodeErrorCode(error, "ENOENT"))
|
|
7405
|
+
return false;
|
|
7406
|
+
throw error;
|
|
7407
|
+
}
|
|
7408
|
+
}
|
|
7409
|
+
/**
|
|
7410
|
+
* Whether a valibot barrel holds only export lines Loom generates, so it can
|
|
7411
|
+
* be rebuilt without losing a hand-written export. Loom exports each `.ts`
|
|
7412
|
+
* module of the generated and refinement directories except `index` and
|
|
7413
|
+
* `_`-prefixed ones, once each, and a refinement replaces the generated
|
|
7414
|
+
* module of the same name. So a `./generated/<name>` line beside a
|
|
7415
|
+
* `./refinements/<name>` line was added by hand, while one without it is
|
|
7416
|
+
* what Loom wrote before that refinement existed. A line for a module that
|
|
7417
|
+
* no longer exists is stale Loom output; a line for another module that does
|
|
7418
|
+
* exist was added by hand.
|
|
7419
|
+
*/
|
|
7420
|
+
async function isLoomValibotBarrel(cwd, config, text, generatedNames, refinementNames) {
|
|
7421
|
+
const lines = [];
|
|
7422
|
+
const seen = new Set();
|
|
7423
|
+
for (const line of normalizeText(text).split("\n")) {
|
|
7424
|
+
const trimmed = line.trim();
|
|
7425
|
+
if (!trimmed)
|
|
7426
|
+
continue;
|
|
7427
|
+
const match = trimmed.match(VALIBOT_BARREL_LINE);
|
|
7428
|
+
if (!match)
|
|
7429
|
+
return false;
|
|
7430
|
+
const [, kind, name] = match;
|
|
7431
|
+
if (name === "index" || name.startsWith("_") || name.includes("/")) {
|
|
7432
|
+
return false;
|
|
7433
|
+
}
|
|
7434
|
+
const key = `${kind}/${name}`;
|
|
7435
|
+
if (seen.has(key))
|
|
7436
|
+
return false;
|
|
7437
|
+
seen.add(key);
|
|
7438
|
+
lines.push({ kind, name });
|
|
7439
|
+
}
|
|
7440
|
+
for (const { kind, name } of lines) {
|
|
7441
|
+
if (kind === "refinements" && refinementNames.includes(name))
|
|
7442
|
+
continue;
|
|
7443
|
+
if (kind === "generated" && generatedNames.includes(name)) {
|
|
7444
|
+
if (refinementNames.includes(name) && seen.has(`refinements/${name}`)) {
|
|
7445
|
+
return false;
|
|
7446
|
+
}
|
|
7447
|
+
continue;
|
|
7448
|
+
}
|
|
7449
|
+
const directory = kind === "generated"
|
|
7450
|
+
? config.dirs.valibotGeneratedDir
|
|
7451
|
+
: config.dirs.valibotRefinementsDir;
|
|
7452
|
+
if (await directoryHasModule(join(cwd, directory), name))
|
|
7453
|
+
return false;
|
|
7454
|
+
}
|
|
7455
|
+
return true;
|
|
7456
|
+
}
|
|
7457
|
+
async function readValibotBarrelState(cwd, config) {
|
|
7074
7458
|
const generatedNames = await readTsModuleNames(join(cwd, config.dirs.valibotGeneratedDir));
|
|
7075
7459
|
const refinementNames = await readTsModuleNames(join(cwd, config.dirs.valibotRefinementsDir));
|
|
7076
|
-
const
|
|
7077
|
-
|
|
7078
|
-
|
|
7460
|
+
const proof = {
|
|
7461
|
+
isLoomOutput: (text) => isLoomValibotBarrel(cwd, config, text, generatedNames, refinementNames),
|
|
7462
|
+
};
|
|
7463
|
+
return {
|
|
7464
|
+
proof,
|
|
7465
|
+
text: buildValibotBarrelText(generatedNames, refinementNames),
|
|
7466
|
+
};
|
|
7467
|
+
}
|
|
7468
|
+
async function syncValibotBarrel(cwd, config) {
|
|
7469
|
+
const barrel = await readValibotBarrelState(cwd, config);
|
|
7470
|
+
if (!barrel.text) {
|
|
7471
|
+
return { changed: false, note: null };
|
|
7079
7472
|
}
|
|
7080
|
-
|
|
7473
|
+
const result = await syncManagedFile(join(cwd, config.modules.valibotBarrelModule), barrel.text, barrel.proof);
|
|
7474
|
+
return {
|
|
7475
|
+
changed: result.state === "created" || result.state === "updated",
|
|
7476
|
+
note: result.state === "customized"
|
|
7477
|
+
? 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.")
|
|
7478
|
+
: null,
|
|
7479
|
+
};
|
|
7081
7480
|
}
|
|
7082
7481
|
function getLatestManagedSchemaConfig(schema) {
|
|
7083
7482
|
const latest = {
|
|
@@ -7302,8 +7701,7 @@ export async function syncDbSchemas(cwd) {
|
|
|
7302
7701
|
(!mailFeature || mailFeature.status !== "active")) {
|
|
7303
7702
|
notes.push("No active Loom-managed DB schemas are configured.");
|
|
7304
7703
|
}
|
|
7305
|
-
|
|
7306
|
-
if (await writeTextIfChanged(manifestPath, stringifyJson(manifest))) {
|
|
7704
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
7307
7705
|
changedFiles.push("loom.json");
|
|
7308
7706
|
}
|
|
7309
7707
|
if (changedFiles.length) {
|
|
@@ -7333,8 +7731,7 @@ export async function configureFilesIdGeneration(cwd, idGeneration) {
|
|
|
7333
7731
|
const config = getFilesConfig(framework, dbConfig, filesFeature.config);
|
|
7334
7732
|
config.schema.idGeneration = idGeneration;
|
|
7335
7733
|
filesFeature.config = config;
|
|
7336
|
-
const
|
|
7337
|
-
const changedFiles = await writeTextIfChanged(manifestPath, nextText)
|
|
7734
|
+
const changedFiles = await writeManifestIfChanged(cwd, manifest)
|
|
7338
7735
|
? ["loom.json"]
|
|
7339
7736
|
: [];
|
|
7340
7737
|
return {
|
|
@@ -8013,9 +8410,12 @@ export async function setupLocalFiles(cwd, options = {}) {
|
|
|
8013
8410
|
notes.push(`Run ${tooling.dependencies.manager} install to update the dependency lockfile.`);
|
|
8014
8411
|
}
|
|
8015
8412
|
if (!storageText || isGeneratedFilesStorageStub(storageText)) {
|
|
8016
|
-
|
|
8413
|
+
const storageUpdate = await replaceFilesStorageStub(storagePath, config.modules.storageModule);
|
|
8414
|
+
if (storageUpdate.changed) {
|
|
8017
8415
|
changedFiles.push(config.modules.storageModule);
|
|
8018
8416
|
}
|
|
8417
|
+
if (storageUpdate.note)
|
|
8418
|
+
notes.push(storageUpdate.note);
|
|
8019
8419
|
}
|
|
8020
8420
|
config.storage.adapter = "s3";
|
|
8021
8421
|
if (config.storage.provider) {
|
|
@@ -8026,7 +8426,7 @@ export async function setupLocalFiles(cwd, options = {}) {
|
|
|
8026
8426
|
};
|
|
8027
8427
|
}
|
|
8028
8428
|
feature.config = config;
|
|
8029
|
-
if (await
|
|
8429
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
8030
8430
|
changedFiles.push("loom.json");
|
|
8031
8431
|
}
|
|
8032
8432
|
return {
|
|
@@ -8278,7 +8678,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8278
8678
|
};
|
|
8279
8679
|
feature.config = config;
|
|
8280
8680
|
manifest.features.files = feature;
|
|
8281
|
-
if (await
|
|
8681
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
8282
8682
|
changedFiles.push("loom.json");
|
|
8283
8683
|
}
|
|
8284
8684
|
for (const bucket of new Set(Object.values(buckets))) {
|
|
@@ -8308,9 +8708,12 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8308
8708
|
const storagePath = join(cwd, config.modules.storageModule);
|
|
8309
8709
|
const storageText = await readTextIfExists(storagePath);
|
|
8310
8710
|
if (!storageText || isGeneratedFilesStorageStub(storageText)) {
|
|
8311
|
-
|
|
8711
|
+
const storageUpdate = await replaceFilesStorageStub(storagePath, config.modules.storageModule);
|
|
8712
|
+
if (storageUpdate.changed) {
|
|
8312
8713
|
changedFiles.push(config.modules.storageModule);
|
|
8313
8714
|
}
|
|
8715
|
+
if (storageUpdate.note)
|
|
8716
|
+
notes.push(storageUpdate.note);
|
|
8314
8717
|
}
|
|
8315
8718
|
else if (!storageText.includes("@gadicc/loom/files/s3")) {
|
|
8316
8719
|
notes.push(`Preserved customized storage module ${config.modules.storageModule}; wire it to the canonical FILES_S3_* variables manually.`);
|
|
@@ -8403,7 +8806,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8403
8806
|
catch (error) {
|
|
8404
8807
|
config.storage.provider.connectionStatus = "partial";
|
|
8405
8808
|
feature.config = config;
|
|
8406
|
-
await
|
|
8809
|
+
await writeManifestIfChanged(cwd, manifest);
|
|
8407
8810
|
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.`);
|
|
8408
8811
|
}
|
|
8409
8812
|
const secretsConfigured = FILES_R2_ENVIRONMENTS.every((environment) => ["FILES_S3_ACCESS_KEY_ID", "FILES_S3_SECRET_ACCESS_KEY"].every((name) => hasExactEnvName(envListings.get(environment) ?? "", name)));
|
|
@@ -8413,7 +8816,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8413
8816
|
? "configured"
|
|
8414
8817
|
: "credentials-required";
|
|
8415
8818
|
feature.config = config;
|
|
8416
|
-
if (await
|
|
8819
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
8417
8820
|
if (!changedFiles.includes("loom.json"))
|
|
8418
8821
|
changedFiles.push("loom.json");
|
|
8419
8822
|
}
|
|
@@ -9538,7 +9941,7 @@ export async function setupVercelNeon(cwd, options = {}) {
|
|
|
9538
9941
|
recordNeonProviderConfig(feature, framework, resourceName, "connected", undefined, options.region);
|
|
9539
9942
|
manifest.features.db = feature;
|
|
9540
9943
|
const changedFiles = [];
|
|
9541
|
-
if (await
|
|
9944
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
9542
9945
|
changedFiles.push("loom.json");
|
|
9543
9946
|
}
|
|
9544
9947
|
return {
|
|
@@ -9557,7 +9960,7 @@ export async function setupVercelNeon(cwd, options = {}) {
|
|
|
9557
9960
|
recordNeonProviderConfig(feature, framework, resourceName, "provisioned", undefined, options.region);
|
|
9558
9961
|
manifest.features.db = feature;
|
|
9559
9962
|
const changedFiles = [];
|
|
9560
|
-
if (await
|
|
9963
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
9561
9964
|
changedFiles.push("loom.json");
|
|
9562
9965
|
}
|
|
9563
9966
|
return {
|
|
@@ -9587,7 +9990,7 @@ export async function setupVercelNeon(cwd, options = {}) {
|
|
|
9587
9990
|
recordNeonProviderConfig(feature, framework, resourceName, result.code === 0 ? "connected" : "provisioned", provisionSuccess?.dashboardUrl, options.region);
|
|
9588
9991
|
manifest.features.db = feature;
|
|
9589
9992
|
const changedFiles = [];
|
|
9590
|
-
if (await
|
|
9993
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
9591
9994
|
changedFiles.push("loom.json");
|
|
9592
9995
|
}
|
|
9593
9996
|
const notes = result.code === 0
|
|
@@ -9720,7 +10123,9 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
9720
10123
|
dependencies: JOBS_DEFAULT_DEPENDENCIES,
|
|
9721
10124
|
devDependencies: JOBS_DEFAULT_DEV_DEPENDENCIES,
|
|
9722
10125
|
});
|
|
9723
|
-
const scriptsUpdate = await
|
|
10126
|
+
const scriptsUpdate = await syncManagedTasks(cwd, manifest, currentFeature, getJobsManagedTasks(config));
|
|
10127
|
+
setManagedRecords(feature, "managedTasks", scriptsUpdate.records);
|
|
10128
|
+
notes.push(...formatPreservedTaskNotes(scriptsUpdate, "jobs"));
|
|
9724
10129
|
if (dependencyUpdate.changed)
|
|
9725
10130
|
changedFiles.push(dependencyUpdate.config);
|
|
9726
10131
|
if (scriptsUpdate.changedKeys.length)
|
|
@@ -9775,9 +10180,18 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
9775
10180
|
if (relativePath === config.directRunner.scriptPath &&
|
|
9776
10181
|
currentText !== null &&
|
|
9777
10182
|
isLegacyLoomJobsDirectRunner(currentText)) {
|
|
9778
|
-
|
|
10183
|
+
// Replace a dotenv-era runner only when it is exactly what an older
|
|
10184
|
+
// Loom wrote; an edited one keeps its app code.
|
|
10185
|
+
const legacyRunners = legacyJobsDirectRunnerOutputs(getJobsDirectRunnerCatalogImportPath(config, framework));
|
|
10186
|
+
const result = await syncManagedFile(path, text, {
|
|
10187
|
+
knownOutputs: legacyRunners,
|
|
10188
|
+
});
|
|
10189
|
+
if (result.state === "updated") {
|
|
9779
10190
|
changedFiles.push(relativePath);
|
|
9780
10191
|
}
|
|
10192
|
+
else if (result.state === "customized") {
|
|
10193
|
+
notes.push(`Preserved local edits in the dotenv-based jobs direct runner ${relativePath} (${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.`);
|
|
10194
|
+
}
|
|
9781
10195
|
continue;
|
|
9782
10196
|
}
|
|
9783
10197
|
const scaffoldState = await scaffoldTextFile(path, text);
|
|
@@ -9789,9 +10203,10 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
9789
10203
|
notes.push(`Preserved existing jobs scaffold file: ${relativePath}`);
|
|
9790
10204
|
}
|
|
9791
10205
|
}
|
|
9792
|
-
const staticRouteSync = await syncJobsStaticRoutes(cwd, config);
|
|
10206
|
+
const staticRouteSync = await syncJobsStaticRoutes(cwd, config, currentFeature);
|
|
9793
10207
|
changedFiles.push(...staticRouteSync.changedFiles);
|
|
9794
10208
|
notes.push(...staticRouteSync.notes);
|
|
10209
|
+
setManagedFileRecords(feature, staticRouteSync.records);
|
|
9795
10210
|
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
9796
10211
|
const catalogPath = join(cwd, jobsRoot, "index.ts");
|
|
9797
10212
|
const metaCatalogPath = join(cwd, jobsRoot, "indexWithMetaOnly.ts");
|
|
@@ -9831,7 +10246,9 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
9831
10246
|
devDependencies: DB_DEFAULT_DEV_DEPENDENCIES,
|
|
9832
10247
|
remove: DB_MOVED_DEPENDENCIES,
|
|
9833
10248
|
});
|
|
9834
|
-
const scriptsUpdate = await
|
|
10249
|
+
const scriptsUpdate = await syncManagedTasks(cwd, manifest, currentFeature, getDbManagedTasks(config, tooling));
|
|
10250
|
+
setManagedRecords(feature, "managedTasks", scriptsUpdate.records);
|
|
10251
|
+
notes.push(...formatPreservedTaskNotes(scriptsUpdate, "db"));
|
|
9835
10252
|
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
9836
10253
|
if (dependencyUpdate.changed)
|
|
9837
10254
|
changedFiles.push(dependencyUpdate.config);
|
|
@@ -9846,26 +10263,21 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
9846
10263
|
if (dependencyUpdate.removedKeys.length) {
|
|
9847
10264
|
notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${dependencyUpdate.removedKeys.join(", ")}`);
|
|
9848
10265
|
}
|
|
9849
|
-
const
|
|
9850
|
-
|
|
9851
|
-
|
|
9852
|
-
|
|
9853
|
-
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
9861
|
-
],
|
|
9862
|
-
];
|
|
9863
|
-
for (const [relativePath, text] of managedFiles) {
|
|
9864
|
-
const path = join(cwd, relativePath);
|
|
9865
|
-
if (await writeTextIfChanged(path, text)) {
|
|
9866
|
-
changedFiles.push(relativePath);
|
|
10266
|
+
const managedFileRecords = {};
|
|
10267
|
+
for (const managedFile of getDbManagedFiles(config, testRunner, tooling)) {
|
|
10268
|
+
const result = await syncManagedFile(join(cwd, managedFile.relativePath), managedFile.text, {
|
|
10269
|
+
knownOutputs: managedFile.knownOutputs,
|
|
10270
|
+
recordedHash: recordedManagedFileHash(currentFeature, managedFile.relativePath),
|
|
10271
|
+
});
|
|
10272
|
+
recordManagedFileSync(managedFileRecords, currentFeature, managedFile.relativePath, result);
|
|
10273
|
+
if (result.state === "created" || result.state === "updated") {
|
|
10274
|
+
changedFiles.push(managedFile.relativePath);
|
|
10275
|
+
}
|
|
10276
|
+
else if (result.state === "customized") {
|
|
10277
|
+
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."));
|
|
9867
10278
|
}
|
|
9868
10279
|
}
|
|
10280
|
+
setManagedFileRecords(feature, managedFileRecords);
|
|
9869
10281
|
const scaffoldFiles = [
|
|
9870
10282
|
[config.modules.fixtureDumpScript, dbFixturesScriptTemplate(config)],
|
|
9871
10283
|
[join(config.dirs.fixtureDir, ".gitkeep"), ""],
|
|
@@ -9881,9 +10293,12 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
9881
10293
|
notes.push(`Preserved existing DB scaffold file: ${relativePath}`);
|
|
9882
10294
|
}
|
|
9883
10295
|
}
|
|
9884
|
-
|
|
10296
|
+
const barrelSync = await syncValibotBarrel(cwd, config);
|
|
10297
|
+
if (barrelSync.changed) {
|
|
9885
10298
|
changedFiles.push(config.modules.valibotBarrelModule);
|
|
9886
10299
|
}
|
|
10300
|
+
if (barrelSync.note)
|
|
10301
|
+
notes.push(barrelSync.note);
|
|
9887
10302
|
const schemaIndexPath = join(cwd, config.dirs.schemaDir, "index.ts");
|
|
9888
10303
|
if (!await exists(schemaIndexPath)) {
|
|
9889
10304
|
notes.push(`Missing ${config.dirs.schemaDir}/index.ts. Add your app-local Drizzle schema barrel there so Loom-managed DB helpers can import it.`);
|
|
@@ -10192,6 +10607,26 @@ function linguiCliCommand(tooling) {
|
|
|
10192
10607
|
return "yarn lingui";
|
|
10193
10608
|
}
|
|
10194
10609
|
}
|
|
10610
|
+
function getLinguiManagedTasks(config, tooling) {
|
|
10611
|
+
// Lingui tasks have followed the recorded dependency manager since the
|
|
10612
|
+
// feature was added, so there is no earlier value to accept.
|
|
10613
|
+
const executable = linguiCliCommand(tooling);
|
|
10614
|
+
return [
|
|
10615
|
+
{
|
|
10616
|
+
definition: `${executable} extract --clean`,
|
|
10617
|
+
knownValues: [],
|
|
10618
|
+
name: config.tasks.extract,
|
|
10619
|
+
},
|
|
10620
|
+
{
|
|
10621
|
+
definition: `${executable} compile`,
|
|
10622
|
+
knownValues: [],
|
|
10623
|
+
name: config.tasks.compile,
|
|
10624
|
+
},
|
|
10625
|
+
];
|
|
10626
|
+
}
|
|
10627
|
+
const PWA_MANAGED_TASKS = [
|
|
10628
|
+
{ definition: PWA_BUILD_SCRIPT, knownValues: [], name: "pwa:build" },
|
|
10629
|
+
];
|
|
10195
10630
|
function linguiConfigTemplate(framework) {
|
|
10196
10631
|
const sourceRoot = framework.srcDir ? "src/" : "";
|
|
10197
10632
|
return `import { formatter } from "@lingui/format-po";
|
|
@@ -10341,19 +10776,10 @@ async function applyLinguiFeature(cwd, framework, manifest, activate) {
|
|
|
10341
10776
|
else if (activate && configState === "preserved") {
|
|
10342
10777
|
notes.push(`Preserved existing Lingui config: ${config.configFile}`);
|
|
10343
10778
|
}
|
|
10344
|
-
const
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
[config.tasks.compile, `${executable} compile`],
|
|
10349
|
-
]) {
|
|
10350
|
-
const result = await ensureTask(cwd, tooling.tasks, {
|
|
10351
|
-
definition: command,
|
|
10352
|
-
name,
|
|
10353
|
-
});
|
|
10354
|
-
if (result.changed)
|
|
10355
|
-
taskChanges.push(name);
|
|
10356
|
-
}
|
|
10779
|
+
const linguiTasks = await syncManagedTasks(cwd, manifest, currentFeature, getLinguiManagedTasks(config, tooling));
|
|
10780
|
+
setManagedRecords(feature, "managedTasks", linguiTasks.records);
|
|
10781
|
+
const taskChanges = [...linguiTasks.changedKeys];
|
|
10782
|
+
notes.push(...formatPreservedTaskNotes(linguiTasks, "lingui"));
|
|
10357
10783
|
let taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
10358
10784
|
if (!getTaskCommand(taskStore.definitions[config.tasks.build])) {
|
|
10359
10785
|
const result = await ensureTask(cwd, tooling.tasks, {
|
|
@@ -10383,9 +10809,15 @@ async function applyLinguiFeature(cwd, framework, manifest, activate) {
|
|
|
10383
10809
|
const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
|
|
10384
10810
|
if (!poDeclarations.length) {
|
|
10385
10811
|
const declarationPath = `${framework.srcDir ? "src/" : ""}lingui.d.ts`;
|
|
10386
|
-
|
|
10812
|
+
// Loom's declaration file always declares `*.po`, so an existing file
|
|
10813
|
+
// without one is the app's own and is never replaced.
|
|
10814
|
+
const declarationState = await scaffoldTextFile(join(cwd, declarationPath), linguiPoDeclarationTemplate());
|
|
10815
|
+
if (declarationState === "created") {
|
|
10387
10816
|
changedFiles.push(declarationPath);
|
|
10388
10817
|
}
|
|
10818
|
+
else if (declarationState === "preserved") {
|
|
10819
|
+
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.`);
|
|
10820
|
+
}
|
|
10389
10821
|
}
|
|
10390
10822
|
}
|
|
10391
10823
|
if (framework.kind === "nextjs") {
|
|
@@ -10437,12 +10869,10 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
10437
10869
|
if (dependencyUpdate.changed)
|
|
10438
10870
|
changedFiles.push(dependencyUpdate.config);
|
|
10439
10871
|
const scriptsChanged = [];
|
|
10440
|
-
const
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
if (pwaTask.changed)
|
|
10445
|
-
scriptsChanged.push("pwa:build");
|
|
10872
|
+
const pwaTasks = await syncManagedTasks(cwd, manifest, currentFeature, PWA_MANAGED_TASKS);
|
|
10873
|
+
setManagedRecords(feature, "managedTasks", pwaTasks.records);
|
|
10874
|
+
scriptsChanged.push(...pwaTasks.changedKeys);
|
|
10875
|
+
notes.push(...formatPreservedTaskNotes(pwaTasks, "pwa"));
|
|
10446
10876
|
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
10447
10877
|
const buildCommand = getTaskCommand(taskStore.definitions.build);
|
|
10448
10878
|
if (!buildCommand) {
|
|
@@ -10487,14 +10917,27 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
10487
10917
|
notes.push(`Preserved existing PWA service worker file: ${config.modules.serviceWorkerModule}`);
|
|
10488
10918
|
}
|
|
10489
10919
|
const clientProviderPath = join(cwd, config.modules.clientProviderModule);
|
|
10490
|
-
const
|
|
10920
|
+
const managedFileRecords = {};
|
|
10491
10921
|
if (config.provider.managed) {
|
|
10492
|
-
|
|
10922
|
+
// `loom add pwa` may refresh the recorded adapter, so the provider the
|
|
10923
|
+
// previous configuration rendered is also Loom's output.
|
|
10924
|
+
const previousConfig = currentConfig
|
|
10925
|
+
? await getPwaConfig(cwd, framework, packageJson, currentConfig, false)
|
|
10926
|
+
: config;
|
|
10927
|
+
const result = await syncManagedFile(clientProviderPath, pwaClientProviderTemplate(config), {
|
|
10928
|
+
knownOutputs: [pwaClientProviderTemplate(previousConfig)],
|
|
10929
|
+
recordedHash: recordedManagedFileHash(currentFeature, config.modules.clientProviderModule),
|
|
10930
|
+
});
|
|
10931
|
+
recordManagedFileSync(managedFileRecords, currentFeature, config.modules.clientProviderModule, result);
|
|
10932
|
+
if (result.state === "created" || result.state === "updated") {
|
|
10493
10933
|
changedFiles.push(config.modules.clientProviderModule);
|
|
10494
10934
|
}
|
|
10495
|
-
if (
|
|
10935
|
+
if (result.state === "created") {
|
|
10496
10936
|
notes.push(`Scaffolded ${config.modules.clientProviderModule}. Wrap the app's root layout or provider tree with LoomPwaProvider to register the service worker.`);
|
|
10497
10937
|
}
|
|
10938
|
+
else if (result.state === "customized") {
|
|
10939
|
+
notes.push(formatPreservedManagedFileNote(config.modules.clientProviderModule, result.difference, PWA_CUSTOMIZED_PROVIDER_RESOLUTION));
|
|
10940
|
+
}
|
|
10498
10941
|
}
|
|
10499
10942
|
else {
|
|
10500
10943
|
const clientProviderState = await scaffoldTextFile(clientProviderPath, pwaClientProviderTemplate(config));
|
|
@@ -10505,6 +10948,7 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
10505
10948
|
notes.push(`Preserved existing PWA client provider file: ${config.modules.clientProviderModule}`);
|
|
10506
10949
|
}
|
|
10507
10950
|
}
|
|
10951
|
+
setManagedFileRecords(feature, managedFileRecords);
|
|
10508
10952
|
if (config.confirmAdapter === "mui") {
|
|
10509
10953
|
notes.push("Detected @mui/material; PWA update prompts should use @gadicc/loom/mui/confirm.");
|
|
10510
10954
|
}
|
|
@@ -10525,14 +10969,14 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
10525
10969
|
return { issues, suggestions: [], warnings: [] };
|
|
10526
10970
|
}
|
|
10527
10971
|
const config = mergeJobsConfig(framework, feature.config);
|
|
10528
|
-
const
|
|
10529
|
-
const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
|
|
10972
|
+
const taskCheck = await checkManagedTasks(cwd, manifest, feature, getJobsManagedTasks(config));
|
|
10530
10973
|
for (const taskName of taskCheck.mismatches) {
|
|
10531
10974
|
issues.push(taskCheck.config === "package.json"
|
|
10532
10975
|
? `Jobs package.json script does not match Loom defaults: ${taskName}`
|
|
10533
10976
|
: `Jobs task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
10534
10977
|
suggestions.add("Run `loom add jobs`.");
|
|
10535
10978
|
}
|
|
10979
|
+
addCustomizedTaskWarnings(taskCheck, "jobs", warnings, suggestions);
|
|
10536
10980
|
const requiredFiles = [
|
|
10537
10981
|
JOBS_SCRIPTS_TSCONFIG_PATH,
|
|
10538
10982
|
config.directRunner?.scriptPath,
|
|
@@ -10583,8 +11027,14 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
10583
11027
|
const plans = getJobsStaticRoutePlans(cwd, config);
|
|
10584
11028
|
const expectedPaths = new Set(plans.map((plan) => plan.path));
|
|
10585
11029
|
for (const plan of plans) {
|
|
10586
|
-
const
|
|
10587
|
-
if (
|
|
11030
|
+
const classification = await classifyManagedFile(await readTextIfExists(plan.path), plan.text, jobsStaticRouteProof(config, feature, plan.relativePath));
|
|
11031
|
+
if (classification.state === "current")
|
|
11032
|
+
continue;
|
|
11033
|
+
if (classification.state === "customized") {
|
|
11034
|
+
issues.push(`Jobs static route does not match loom manifest config: ${plan.relativePath} (${classification.difference})`);
|
|
11035
|
+
suggestions.add(`Loom does not overwrite edited or app-owned static job routes. ${JOBS_STATIC_ROUTE_EDIT_RESOLUTION}`);
|
|
11036
|
+
}
|
|
11037
|
+
else {
|
|
10588
11038
|
issues.push(`Jobs static route does not match loom manifest config: ${plan.relativePath}`);
|
|
10589
11039
|
suggestions.add("Run `loom add jobs` to sync static job routes.");
|
|
10590
11040
|
}
|
|
@@ -10592,8 +11042,12 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
10592
11042
|
for (const routePath of await findManagedJobsStaticRoutePaths(cwd, config)) {
|
|
10593
11043
|
if (expectedPaths.has(routePath))
|
|
10594
11044
|
continue;
|
|
10595
|
-
|
|
10596
|
-
|
|
11045
|
+
const relativePath = relative(cwd, routePath).replaceAll("\\", "/");
|
|
11046
|
+
issues.push(`Managed jobs static route is not declared in loom.json: ${relativePath}`);
|
|
11047
|
+
const routeState = await classifyManagedFile(await readTextIfExists(routePath), "", jobsStaticRouteProof(config, feature, relativePath));
|
|
11048
|
+
suggestions.add(routeState.state === "loom-output"
|
|
11049
|
+
? "Run `loom add jobs` to sync static job routes."
|
|
11050
|
+
: `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.`);
|
|
10597
11051
|
}
|
|
10598
11052
|
const routeModuleText = await readTextIfExists(join(cwd, config.modules.routeModule));
|
|
10599
11053
|
if (routeModuleText &&
|
|
@@ -10736,7 +11190,6 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10736
11190
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
10737
11191
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
10738
11192
|
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
10739
|
-
const expectedScripts = getDbExpectedScripts(config, tooling);
|
|
10740
11193
|
const migrationFlowCheck = await checkDbProductionMigrationFlow(cwd, options.production ?? false, productionBranch);
|
|
10741
11194
|
issues.push(...migrationFlowCheck.issues);
|
|
10742
11195
|
warnings.push(...migrationFlowCheck.warnings);
|
|
@@ -10768,13 +11221,14 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10768
11221
|
suggestions.add(`Run loom add db to rewrite ${tooling.dependencies.config}.`);
|
|
10769
11222
|
}
|
|
10770
11223
|
}
|
|
10771
|
-
const taskCheck = await
|
|
11224
|
+
const taskCheck = await checkManagedTasks(cwd, manifest, feature, getDbManagedTasks(config, tooling));
|
|
10772
11225
|
for (const taskName of taskCheck.mismatches) {
|
|
10773
11226
|
issues.push(taskCheck.config === "package.json"
|
|
10774
11227
|
? `DB package.json script does not match Loom defaults: ${taskName}`
|
|
10775
11228
|
: `DB task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
10776
11229
|
suggestions.add("Run `loom add db`.");
|
|
10777
11230
|
}
|
|
11231
|
+
addCustomizedTaskWarnings(taskCheck, "db", warnings, suggestions);
|
|
10778
11232
|
const requiredFiles = [
|
|
10779
11233
|
config.modules.neonModule,
|
|
10780
11234
|
config.modules.neonFullModule,
|
|
@@ -10791,44 +11245,22 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10791
11245
|
suggestions.add("Run `loom add db`.");
|
|
10792
11246
|
}
|
|
10793
11247
|
}
|
|
10794
|
-
const
|
|
10795
|
-
|
|
10796
|
-
config.modules.neonModule,
|
|
10797
|
-
dbNeonTemplate(),
|
|
10798
|
-
"DB neon module does not match the Loom-managed wrapper",
|
|
10799
|
-
],
|
|
10800
|
-
[
|
|
10801
|
-
config.modules.neonFullModule,
|
|
10802
|
-
dbNeonFullTemplate(),
|
|
10803
|
-
"DB neonFull module does not match the Loom-managed wrapper",
|
|
10804
|
-
],
|
|
10805
|
-
[
|
|
10806
|
-
config.modules.drizzleConfig,
|
|
10807
|
-
dbDrizzleConfigTemplate(config),
|
|
10808
|
-
"Drizzle config does not match the Loom-managed wrapper",
|
|
10809
|
-
],
|
|
10810
|
-
[
|
|
10811
|
-
config.modules.pgliteHarnessModule,
|
|
10812
|
-
dbPgliteHarnessTemplate(config, testRunner),
|
|
10813
|
-
"PGlite test harness does not match the Loom-managed wrapper",
|
|
10814
|
-
],
|
|
10815
|
-
[
|
|
10816
|
-
config.modules.scriptsTsconfig,
|
|
10817
|
-
dbScriptsTsconfigTemplate(),
|
|
10818
|
-
"DB scripts tsconfig does not match the Loom-managed template",
|
|
10819
|
-
],
|
|
10820
|
-
[
|
|
10821
|
-
config.modules.refinementsCommonModule,
|
|
10822
|
-
dbRefinementsCommonTemplate(),
|
|
10823
|
-
"Valibot refinements common module does not match the Loom-managed wrapper",
|
|
10824
|
-
],
|
|
10825
|
-
];
|
|
10826
|
-
for (const [relativePath, expectedText, message] of exactManagedFileChecks) {
|
|
10827
|
-
const currentText = await readTextIfExists(join(cwd, relativePath));
|
|
11248
|
+
for (const managedFile of getDbManagedFiles(config, testRunner, tooling)) {
|
|
11249
|
+
const currentText = await readTextIfExists(join(cwd, managedFile.relativePath));
|
|
10828
11250
|
if (!currentText)
|
|
10829
11251
|
continue;
|
|
10830
|
-
|
|
10831
|
-
|
|
11252
|
+
const classification = await classifyManagedFile(currentText, managedFile.text, {
|
|
11253
|
+
knownOutputs: managedFile.knownOutputs,
|
|
11254
|
+
recordedHash: recordedManagedFileHash(feature, managedFile.relativePath),
|
|
11255
|
+
});
|
|
11256
|
+
if (classification.state === "current")
|
|
11257
|
+
continue;
|
|
11258
|
+
if (classification.state === "customized") {
|
|
11259
|
+
issues.push(`${managedFile.mismatch}: ${managedFile.relativePath} (${classification.difference})`);
|
|
11260
|
+
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.");
|
|
11261
|
+
}
|
|
11262
|
+
else {
|
|
11263
|
+
issues.push(`${managedFile.mismatch}: ${managedFile.relativePath}`);
|
|
10832
11264
|
suggestions.add("Run `loom add db` to restore the Loom-managed DB wrappers.");
|
|
10833
11265
|
}
|
|
10834
11266
|
}
|
|
@@ -10859,20 +11291,24 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
10859
11291
|
}
|
|
10860
11292
|
}
|
|
10861
11293
|
}
|
|
10862
|
-
const
|
|
10863
|
-
const
|
|
10864
|
-
const expectedBarrelText = buildValibotBarrelText(generatedNames, refinementNames);
|
|
11294
|
+
const barrel = await readValibotBarrelState(cwd, config);
|
|
11295
|
+
const expectedBarrelText = barrel.text;
|
|
10865
11296
|
const barrelPath = join(cwd, config.modules.valibotBarrelModule);
|
|
10866
11297
|
const barrelText = await readTextIfExists(barrelPath);
|
|
10867
11298
|
if (expectedBarrelText) {
|
|
10868
|
-
|
|
11299
|
+
const classification = await classifyManagedFile(barrelText, expectedBarrelText, barrel.proof);
|
|
11300
|
+
if (classification.state === "missing") {
|
|
10869
11301
|
issues.push(`Valibot barrel is missing while generated/refinement modules exist: ${config.modules.valibotBarrelModule}`);
|
|
10870
11302
|
suggestions.add("Run `loom db schema-gen` to refresh generated validation exports.");
|
|
10871
11303
|
}
|
|
10872
|
-
else if (
|
|
11304
|
+
else if (classification.state === "loom-output") {
|
|
10873
11305
|
issues.push(`Valibot barrel does not match the generated/refinement modules: ${config.modules.valibotBarrelModule}`);
|
|
10874
11306
|
suggestions.add("Run `loom db schema-gen` to rebuild the generated validation exports and barrel.");
|
|
10875
11307
|
}
|
|
11308
|
+
else if (classification.state === "customized") {
|
|
11309
|
+
issues.push(`Valibot barrel does not match the generated/refinement modules: ${config.modules.valibotBarrelModule} (${classification.difference})`);
|
|
11310
|
+
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.`);
|
|
11311
|
+
}
|
|
10876
11312
|
}
|
|
10877
11313
|
else if (barrelText) {
|
|
10878
11314
|
warnings.push(`Valibot barrel exists but no generated/refinement modules were discovered: ${config.modules.valibotBarrelModule}`);
|
|
@@ -12599,6 +13035,8 @@ async function checkLinguiFeature(cwd, framework, manifest, options) {
|
|
|
12599
13035
|
issues.push(`Lingui config is missing: ${config.configFile}`);
|
|
12600
13036
|
suggestions.add("Run `loom add lingui`.");
|
|
12601
13037
|
}
|
|
13038
|
+
// Missing or broken tasks are issues below; edited working ones only warn.
|
|
13039
|
+
addCustomizedTaskWarnings(await checkManagedTasks(cwd, manifest, feature, getLinguiManagedTasks(config, tooling)), "lingui", warnings, suggestions);
|
|
12602
13040
|
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
12603
13041
|
if (!linguiTaskRuns(getTaskCommand(taskStore.definitions[config.tasks.extract]), "extract")) {
|
|
12604
13042
|
issues.push(`Lingui extraction task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.extract}`);
|
|
@@ -12720,6 +13158,9 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
12720
13158
|
suggestions.add("Run `loom add pwa`.");
|
|
12721
13159
|
}
|
|
12722
13160
|
}
|
|
13161
|
+
// A missing or broken pwa:build is an issue below; an edited working one
|
|
13162
|
+
// only warns.
|
|
13163
|
+
addCustomizedTaskWarnings(await checkManagedTasks(cwd, manifest, feature, PWA_MANAGED_TASKS), "pwa", warnings, suggestions);
|
|
12723
13164
|
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
12724
13165
|
if (!scriptRunsSerwistBuild(getTaskCommand(taskStore.definitions["pwa:build"]))) {
|
|
12725
13166
|
issues.push(`PWA task in ${tooling.tasks.config} does not build Serwist: pwa:build`);
|
|
@@ -12811,6 +13252,15 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
12811
13252
|
}
|
|
12812
13253
|
const clientProviderText = await readTextIfExists(join(cwd, config.modules.clientProviderModule));
|
|
12813
13254
|
if (clientProviderText) {
|
|
13255
|
+
if (config.provider.managed) {
|
|
13256
|
+
const classification = await classifyManagedFile(clientProviderText, pwaClientProviderTemplate(config), {
|
|
13257
|
+
recordedHash: recordedManagedFileHash(feature, config.modules.clientProviderModule),
|
|
13258
|
+
});
|
|
13259
|
+
if (classification.state === "customized") {
|
|
13260
|
+
warnings.push(`PWA client provider is recorded as Loom-managed but has local edits that Loom will not overwrite: ${config.modules.clientProviderModule} (${classification.difference})`);
|
|
13261
|
+
suggestions.add(`PWA client provider ${config.modules.clientProviderModule}: ${PWA_CUSTOMIZED_PROVIDER_RESOLUTION}`);
|
|
13262
|
+
}
|
|
13263
|
+
}
|
|
12814
13264
|
if (!await isPwaClientProviderMounted(cwd, framework, config)) {
|
|
12815
13265
|
issues.push(`PWA client provider is not mounted by the app root provider tree: ${config.modules.clientProviderModule}`);
|
|
12816
13266
|
suggestions.add("Wrap the app root layout or existing client provider with LoomPwaProvider.");
|
|
@@ -13007,11 +13457,9 @@ export async function initProject(cwd, versionRange) {
|
|
|
13007
13457
|
notes.push(...packageSkillInit.notes);
|
|
13008
13458
|
if (await ensureExternalSkillsGitignore(cwd))
|
|
13009
13459
|
changedFiles.push(".gitignore");
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
13013
|
-
if (manifestChanged) {
|
|
13014
|
-
await writeFile(loomManifestPath, manifestText, "utf8");
|
|
13460
|
+
// The new manifest shares the existing features object, which the feature
|
|
13461
|
+
// hooks update in place, so compare with the file on disk.
|
|
13462
|
+
if (await writeManifestIfChanged(cwd, manifest)) {
|
|
13015
13463
|
changedFiles.push("loom.json");
|
|
13016
13464
|
}
|
|
13017
13465
|
return {
|
|
@@ -13037,8 +13485,7 @@ export async function addFeature(cwd, featureKey, versionRange) {
|
|
|
13037
13485
|
...skillSync.changedFiles,
|
|
13038
13486
|
];
|
|
13039
13487
|
const notes = [...base.notes, ...result.notes, ...skillSync.notes];
|
|
13040
|
-
|
|
13041
|
-
if (await writeTextIfChanged(manifestPath, stringifyJson(base.manifest))) {
|
|
13488
|
+
if (await writeManifestIfChanged(cwd, base.manifest)) {
|
|
13042
13489
|
changedFiles.push("loom.json");
|
|
13043
13490
|
}
|
|
13044
13491
|
return {
|
|
@@ -13096,7 +13543,7 @@ export async function integrateApiKeysJobs(cwd, permission, allowQueryParam = fa
|
|
|
13096
13543
|
};
|
|
13097
13544
|
feature.config = config;
|
|
13098
13545
|
manifest.features["api-keys"] = feature;
|
|
13099
|
-
const changed = await
|
|
13546
|
+
const changed = await writeManifestIfChanged(cwd, manifest);
|
|
13100
13547
|
return {
|
|
13101
13548
|
changedFiles: changed ? ["loom.json"] : [],
|
|
13102
13549
|
notes: [
|
|
@@ -13134,7 +13581,7 @@ export async function configureApiKeyRetention(cwd, enabled, overrides = {}) {
|
|
|
13134
13581
|
};
|
|
13135
13582
|
feature.config = config;
|
|
13136
13583
|
manifest.features["api-keys"] = feature;
|
|
13137
|
-
const changed = await
|
|
13584
|
+
const changed = await writeManifestIfChanged(cwd, manifest);
|
|
13138
13585
|
return {
|
|
13139
13586
|
changedFiles: changed ? ["loom.json"] : [],
|
|
13140
13587
|
notes: enabled
|
|
@@ -13278,7 +13725,7 @@ export async function checkProject(cwd, env = process.env, options = {}) {
|
|
|
13278
13725
|
for (const suggestion of agentsCheck.suggestions) {
|
|
13279
13726
|
suggestions.add(suggestion);
|
|
13280
13727
|
}
|
|
13281
|
-
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest);
|
|
13728
|
+
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest, framework);
|
|
13282
13729
|
for (const issue of envRunnerCheck.issues) {
|
|
13283
13730
|
issues.push(issue);
|
|
13284
13731
|
}
|
|
@@ -14351,9 +14798,12 @@ async function runDbSchemaGen(cwd, forwardedArgs, io) {
|
|
|
14351
14798
|
io.out("Biome is not installed; generated Valibot files were left unformatted.");
|
|
14352
14799
|
}
|
|
14353
14800
|
}
|
|
14354
|
-
|
|
14801
|
+
const barrelSync = await syncValibotBarrel(cwd, config);
|
|
14802
|
+
if (barrelSync.changed) {
|
|
14355
14803
|
io.out(`Updated ${config.modules.valibotBarrelModule}.`);
|
|
14356
14804
|
}
|
|
14805
|
+
if (barrelSync.note)
|
|
14806
|
+
io.out(`Note: ${barrelSync.note}`);
|
|
14357
14807
|
return 0;
|
|
14358
14808
|
}
|
|
14359
14809
|
async function runDbFixtures(cwd, forwardedArgs) {
|