@gadicc/loom 1.16.1 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -41
- package/deno.json +3 -0
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/mod.d.ts +2 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- package/esm/src/cli/mod.d.ts +4 -2
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +2018 -369
- package/esm/src/cli/projectTooling.d.ts +138 -0
- package/esm/src/cli/projectTooling.d.ts.map +1 -0
- package/esm/src/cli/projectTooling.js +614 -0
- package/esm/src/mail/errors.d.ts +33 -0
- package/esm/src/mail/errors.d.ts.map +1 -0
- package/esm/src/mail/errors.js +89 -0
- package/esm/src/mail/memory.d.ts +30 -0
- package/esm/src/mail/memory.d.ts.map +1 -0
- package/esm/src/mail/memory.js +340 -0
- package/esm/src/mail/mod.d.ts +7 -0
- package/esm/src/mail/mod.d.ts.map +1 -0
- package/esm/src/mail/mod.js +6 -0
- package/esm/src/mail/postal.d.ts +57 -0
- package/esm/src/mail/postal.d.ts.map +1 -0
- package/esm/src/mail/postal.js +238 -0
- package/esm/src/mail/retry.d.ts +9 -0
- package/esm/src/mail/retry.d.ts.map +1 -0
- package/esm/src/mail/retry.js +19 -0
- package/esm/src/mail/service.d.ts +23 -0
- package/esm/src/mail/service.d.ts.map +1 -0
- package/esm/src/mail/service.js +185 -0
- package/esm/src/mail/types.d.ts +176 -0
- package/esm/src/mail/types.d.ts.map +1 -0
- package/esm/src/mail/types.js +1 -0
- package/esm/src/mui/mail.d.ts +29 -0
- package/esm/src/mui/mail.d.ts.map +1 -0
- package/esm/src/mui/mail.js +114 -0
- package/esm/src/mui/mailView.d.ts +20 -0
- package/esm/src/mui/mailView.d.ts.map +1 -0
- package/esm/src/mui/mailView.js +26 -0
- package/esm/src/mui/mod.d.ts +1 -0
- package/esm/src/mui/mod.d.ts.map +1 -1
- package/esm/src/mui/mod.js +1 -0
- package/esm/src/next/mail/mod.d.ts +3 -0
- package/esm/src/next/mail/mod.d.ts.map +1 -0
- package/esm/src/next/mail/mod.js +2 -0
- package/esm/src/next/mail/route.d.ts +12 -0
- package/esm/src/next/mail/route.d.ts.map +1 -0
- package/esm/src/next/mail/route.js +43 -0
- package/package.json +56 -2
- package/script/_dnt.polyfills.d.ts +6 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/mod.d.ts +2 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +2 -0
- package/script/src/cli/mod.d.ts +4 -2
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +2018 -369
- package/script/src/cli/projectTooling.d.ts +138 -0
- package/script/src/cli/projectTooling.d.ts.map +1 -0
- package/script/src/cli/projectTooling.js +634 -0
- package/script/src/mail/errors.d.ts +33 -0
- package/script/src/mail/errors.d.ts.map +1 -0
- package/script/src/mail/errors.js +97 -0
- package/script/src/mail/memory.d.ts +30 -0
- package/script/src/mail/memory.d.ts.map +1 -0
- package/script/src/mail/memory.js +345 -0
- package/script/src/mail/mod.d.ts +7 -0
- package/script/src/mail/mod.d.ts.map +1 -0
- package/script/src/mail/mod.js +22 -0
- package/script/src/mail/postal.d.ts +57 -0
- package/script/src/mail/postal.d.ts.map +1 -0
- package/script/src/mail/postal.js +245 -0
- package/script/src/mail/retry.d.ts +9 -0
- package/script/src/mail/retry.d.ts.map +1 -0
- package/script/src/mail/retry.js +22 -0
- package/script/src/mail/service.d.ts +23 -0
- package/script/src/mail/service.d.ts.map +1 -0
- package/script/src/mail/service.js +189 -0
- package/script/src/mail/types.d.ts +176 -0
- package/script/src/mail/types.d.ts.map +1 -0
- package/script/src/mail/types.js +2 -0
- package/script/src/mui/mail.d.ts +29 -0
- package/script/src/mui/mail.d.ts.map +1 -0
- package/script/src/mui/mail.js +159 -0
- package/script/src/mui/mailView.d.ts +20 -0
- package/script/src/mui/mailView.d.ts.map +1 -0
- package/script/src/mui/mailView.js +32 -0
- package/script/src/mui/mod.d.ts +1 -0
- package/script/src/mui/mod.d.ts.map +1 -1
- package/script/src/mui/mod.js +1 -0
- package/script/src/next/mail/mod.d.ts +3 -0
- package/script/src/next/mail/mod.d.ts.map +1 -0
- package/script/src/next/mail/mod.js +18 -0
- package/script/src/next/mail/route.d.ts +12 -0
- package/script/src/next/mail/route.d.ts.map +1 -0
- package/script/src/next/mail/route.js +46 -0
- package/skills/loom/SKILL.md +34 -22
- package/skills/loom-db/SKILL.md +9 -7
- package/skills/loom-db/references/db-stack.md +2 -1
- package/skills/loom-jobs/SKILL.md +9 -6
- package/skills/loom-lingui/SKILL.md +38 -0
- package/skills/loom-lingui/agents/openai.yaml +4 -0
- package/skills/loom-mail/SKILL.md +68 -0
package/esm/src/cli/mod.js
CHANGED
|
@@ -10,6 +10,7 @@ import { DEFAULT_API_KEY_AUDIT_RETENTION } from "../apiKeys/retention.js";
|
|
|
10
10
|
import { checkProjectSkills, getProjectSkillStatus, LOOM_EXTERNAL_SKILLS_GITIGNORE_LINE, removeLegacyNextSkillLink, setProjectSkillDisabled, syncExternalProjectSkills, syncInstalledPackageSkills, } from "./projectSkills.js";
|
|
11
11
|
import { resolveMigrationEnvironment, resolveMigrationEnvironmentFromEnvFile, } from "./migrationEnv.js";
|
|
12
12
|
import { prepareVercelBuildEnvironment, verifyVercelBuildArtifact, } from "./vercelBuildEnv.js";
|
|
13
|
+
import { detectProjectTooling, ensureTask, ensureTaskFollowup, ensureTaskPrerequisite, findTaskConflicts, formatTaskInvocation, getTaskCommand, mutateDenoLinks, mutateProjectDependencies, readDenoLinks, readProjectPackageMetadata, readTaskStore, taskInvokes, taskRunsBeforeCommand, } from "./projectTooling.js";
|
|
13
14
|
export const DEFAULT_LOOM_RANGE = "^1.0.0";
|
|
14
15
|
export const LOOM_DEPENDENCY = "@gadicc/loom";
|
|
15
16
|
export const LOOM_MANIFEST_SCHEMA = "https://loom.gadicc.local/project-manifest.schema.json";
|
|
@@ -97,6 +98,18 @@ const managedSkills = [
|
|
|
97
98
|
relativePackagePath: "skills/loom-files",
|
|
98
99
|
skillName: "loom-files",
|
|
99
100
|
},
|
|
101
|
+
{
|
|
102
|
+
featureKey: "mail",
|
|
103
|
+
label: "loom mail skill",
|
|
104
|
+
relativePackagePath: "skills/loom-mail",
|
|
105
|
+
skillName: "loom-mail",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
featureKey: "lingui",
|
|
109
|
+
label: "loom Lingui skill",
|
|
110
|
+
relativePackagePath: "skills/loom-lingui",
|
|
111
|
+
skillName: "loom-lingui",
|
|
112
|
+
},
|
|
100
113
|
];
|
|
101
114
|
const featureDefinitions = [
|
|
102
115
|
{
|
|
@@ -119,6 +132,14 @@ const featureDefinitions = [
|
|
|
119
132
|
key: "jobs",
|
|
120
133
|
description: "Shared App Router admin jobs pages, route handlers, direct-run helpers, and job controller wiring.",
|
|
121
134
|
},
|
|
135
|
+
{
|
|
136
|
+
key: "lingui",
|
|
137
|
+
description: "Lingui catalog source policy, generated-catalog ignores, dependencies, tasks, and build wiring.",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
key: "mail",
|
|
141
|
+
description: "Durable outgoing mail, Postal transport/webhooks, and admin-gated test-mail UI.",
|
|
142
|
+
},
|
|
122
143
|
{
|
|
123
144
|
key: "pwa",
|
|
124
145
|
description: "Shared Serwist PWA worker, provider lifecycle, update prompts, and build wiring.",
|
|
@@ -170,6 +191,13 @@ const DEFAULT_MINIO_ENDPOINT = "http://127.0.0.1:9000";
|
|
|
170
191
|
const API_KEY_AUDIT_SCHEMA_BLUEPRINT_VERSION = 3;
|
|
171
192
|
const API_KEY_AUDIT_SCHEMA_DEFAULT_EXPORT = "loomApiKeyAuditEventsTable";
|
|
172
193
|
const API_KEY_AUDIT_SCHEMA_DEFAULT_TABLE = "loom_api_key_audit_events";
|
|
194
|
+
const MAIL_SCHEMA_BLUEPRINT_VERSION = 1;
|
|
195
|
+
const MAIL_SCHEMA_DEFAULT_EXPORTS = [
|
|
196
|
+
"loomMailMessagesTable",
|
|
197
|
+
"loomMailDeliveriesTable",
|
|
198
|
+
"loomMailEventsTable",
|
|
199
|
+
];
|
|
200
|
+
const MAIL_SCHEMA_DEFAULT_TABLE = "loom_mail_messages";
|
|
173
201
|
const PWA_DEFAULT_DEPENDENCIES = {
|
|
174
202
|
"@serwist/next": "^9.5.11",
|
|
175
203
|
};
|
|
@@ -185,6 +213,30 @@ const PWA_GITIGNORE_LINES = [
|
|
|
185
213
|
"/public/workbox-*.js",
|
|
186
214
|
"/public/workbox-*.js.map",
|
|
187
215
|
];
|
|
216
|
+
const LINGUI_DEFAULT_DEPENDENCIES = {
|
|
217
|
+
"@lingui/core": "^6.5.0",
|
|
218
|
+
"@lingui/react": "^6.5.0",
|
|
219
|
+
};
|
|
220
|
+
const LINGUI_DEFAULT_DEV_DEPENDENCIES = {
|
|
221
|
+
"@lingui/cli": "^6.5.0",
|
|
222
|
+
"@lingui/format-po": "^6.5.0",
|
|
223
|
+
"@lingui/swc-plugin": "^6.5.0",
|
|
224
|
+
};
|
|
225
|
+
const LINGUI_LOADER_DEV_DEPENDENCIES = {
|
|
226
|
+
"@lingui/loader": "^6.5.0",
|
|
227
|
+
};
|
|
228
|
+
const LINGUI_CONFIG_CANDIDATES = [
|
|
229
|
+
"lingui.config.ts",
|
|
230
|
+
"lingui.config.js",
|
|
231
|
+
"lingui.config.mts",
|
|
232
|
+
"lingui.config.mjs",
|
|
233
|
+
"lingui.config.cjs",
|
|
234
|
+
];
|
|
235
|
+
const LINGUI_DEFAULT_TASKS = {
|
|
236
|
+
build: "build",
|
|
237
|
+
compile: "i18n:compile",
|
|
238
|
+
extract: "i18n:extract",
|
|
239
|
+
};
|
|
188
240
|
const PWA_UPDATE_PROMPT = "A newer version of this web app is available. Reload to update?";
|
|
189
241
|
const DB_CONNECTION_ENV_NAMES = [
|
|
190
242
|
"DATABASE_URL",
|
|
@@ -312,11 +364,14 @@ async function readManifestFramework(cwd) {
|
|
|
312
364
|
if (manifest?.project?.framework) {
|
|
313
365
|
return manifest.project.framework;
|
|
314
366
|
}
|
|
315
|
-
|
|
316
|
-
|
|
367
|
+
let metadata;
|
|
368
|
+
try {
|
|
369
|
+
metadata = await readProjectPackageMetadata(cwd);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
317
372
|
return null;
|
|
318
373
|
}
|
|
319
|
-
return await detectFramework(cwd,
|
|
374
|
+
return await detectFramework(cwd, metadata.packageJson);
|
|
320
375
|
}
|
|
321
376
|
async function loadProjectEnv(cwd) {
|
|
322
377
|
const framework = await readManifestFramework(cwd);
|
|
@@ -412,7 +467,8 @@ function dbScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
|
412
467
|
return false;
|
|
413
468
|
}
|
|
414
469
|
return !scriptUsesLoomEnvRunner(scriptCommand) &&
|
|
415
|
-
!/\
|
|
470
|
+
!/\b(?:pnpm|yarn|npx)\s+drizzle-kit\b/.test(scriptCommand) &&
|
|
471
|
+
!/\bdeno\s+run\s+-A\s+npm:drizzle-kit\b/.test(scriptCommand);
|
|
416
472
|
}
|
|
417
473
|
function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
418
474
|
if (!scriptCommand) {
|
|
@@ -421,7 +477,7 @@ function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
|
421
477
|
return (scriptName === "job" || scriptCommand.includes("jobDirect.ts")) &&
|
|
422
478
|
!scriptUsesLoomEnvRunner(scriptCommand);
|
|
423
479
|
}
|
|
424
|
-
async function checkEnvRunnerAdoption(cwd, manifest
|
|
480
|
+
async function checkEnvRunnerAdoption(cwd, manifest) {
|
|
425
481
|
const issues = [];
|
|
426
482
|
const suggestions = new Set();
|
|
427
483
|
const activeDb = manifest.features.db?.status === "active";
|
|
@@ -436,14 +492,25 @@ async function checkEnvRunnerAdoption(cwd, manifest, packageJson) {
|
|
|
436
492
|
if (directEnvLoaderFiles.length) {
|
|
437
493
|
suggestions.add("Move env loading into package scripts with `loom env -- <command>` and remove `dotenv`/`@next/env` imports from implementation files.");
|
|
438
494
|
}
|
|
439
|
-
|
|
495
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
496
|
+
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
497
|
+
for (const [scriptName, definition] of Object.entries(taskStore.definitions)) {
|
|
498
|
+
const scriptCommand = getTaskCommand(definition);
|
|
440
499
|
if (activeDb && dbScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
441
|
-
issues.push(
|
|
442
|
-
|
|
500
|
+
issues.push(taskStore.config === "package.json"
|
|
501
|
+
? `DB package.json script bypasses the Loom env runner: ${scriptName}`
|
|
502
|
+
: `DB task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
503
|
+
suggestions.add(taskStore.config === "package.json"
|
|
504
|
+
? "Run `loom add db` to refresh DB package scripts."
|
|
505
|
+
: "Run `loom add db` to refresh DB tasks.");
|
|
443
506
|
}
|
|
444
507
|
if (activeJobs && jobsScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
445
|
-
issues.push(
|
|
446
|
-
|
|
508
|
+
issues.push(taskStore.config === "package.json"
|
|
509
|
+
? `Jobs package.json script bypasses the Loom env runner: ${scriptName}`
|
|
510
|
+
: `Jobs task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
511
|
+
suggestions.add(taskStore.config === "package.json"
|
|
512
|
+
? "Run `loom add jobs` to refresh jobs package scripts."
|
|
513
|
+
: "Run `loom add jobs` to refresh jobs tasks.");
|
|
447
514
|
}
|
|
448
515
|
}
|
|
449
516
|
return {
|
|
@@ -708,6 +775,29 @@ function ensurePwaGitignoreText(existingText) {
|
|
|
708
775
|
text: nextText,
|
|
709
776
|
};
|
|
710
777
|
}
|
|
778
|
+
function normalizeGitignorePattern(pattern) {
|
|
779
|
+
return pattern.trim().replaceAll("\\", "/").replace(/^\.\//, "");
|
|
780
|
+
}
|
|
781
|
+
function linguiGitignoreLineMatches(line, expectedLine) {
|
|
782
|
+
const normalized = normalizeGitignorePattern(line).replace(/^\//, "");
|
|
783
|
+
const expected = normalizeGitignorePattern(expectedLine).replace(/^\//, "");
|
|
784
|
+
return normalized === expected;
|
|
785
|
+
}
|
|
786
|
+
function ensureLinguiGitignoreText(existingText, generatedCatalogs) {
|
|
787
|
+
const normalized = existingText ? normalizeText(existingText) : "";
|
|
788
|
+
const lines = normalized
|
|
789
|
+
.split("\n")
|
|
790
|
+
.filter((line, index, array) => index < array.length - 1 || line !== "");
|
|
791
|
+
const missingLines = generatedCatalogs.filter((expectedLine) => !lines.some((line) => linguiGitignoreLineMatches(line, expectedLine)));
|
|
792
|
+
const nextText = missingLines.length
|
|
793
|
+
? `${[...lines, ...missingLines].join("\n")}\n`
|
|
794
|
+
: normalized;
|
|
795
|
+
return {
|
|
796
|
+
changed: nextText !== normalized,
|
|
797
|
+
missingLines,
|
|
798
|
+
text: nextText,
|
|
799
|
+
};
|
|
800
|
+
}
|
|
711
801
|
function loomDevStateGitignoreLineMatches(line) {
|
|
712
802
|
const normalized = line.trim().replace(/^\/?/, "");
|
|
713
803
|
return normalized === LOOM_LOCAL_DEV_STATE_GITIGNORE_LINE ||
|
|
@@ -741,58 +831,30 @@ export function ensurePackageJsonDependency(packageJson, versionRange = DEFAULT_
|
|
|
741
831
|
previous: current,
|
|
742
832
|
};
|
|
743
833
|
}
|
|
744
|
-
function
|
|
745
|
-
|
|
746
|
-
nextPackageJson[field] ??= {};
|
|
747
|
-
const changedKeys = [];
|
|
748
|
-
for (const [dependencyName, versionRange] of Object.entries(dependencies)) {
|
|
749
|
-
if (!nextPackageJson[field][dependencyName]) {
|
|
750
|
-
nextPackageJson[field][dependencyName] = versionRange;
|
|
751
|
-
changedKeys.push(dependencyName);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
return {
|
|
755
|
-
changed: changedKeys.length > 0,
|
|
756
|
-
changedKeys,
|
|
757
|
-
packageJson: nextPackageJson,
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
function removePackageJsonDependencies(packageJson, dependencyNames) {
|
|
761
|
-
const nextPackageJson = structuredClone(packageJson);
|
|
762
|
-
const removedKeys = [];
|
|
763
|
-
for (const dependencyName of dependencyNames) {
|
|
764
|
-
if (nextPackageJson.dependencies?.[dependencyName]) {
|
|
765
|
-
delete nextPackageJson.dependencies[dependencyName];
|
|
766
|
-
removedKeys.push(dependencyName);
|
|
767
|
-
}
|
|
768
|
-
if (nextPackageJson.devDependencies?.[dependencyName]) {
|
|
769
|
-
delete nextPackageJson.devDependencies[dependencyName];
|
|
770
|
-
removedKeys.push(dependencyName);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
return {
|
|
774
|
-
changed: removedKeys.length > 0,
|
|
775
|
-
packageJson: nextPackageJson,
|
|
776
|
-
removedKeys,
|
|
777
|
-
};
|
|
834
|
+
async function getProjectTooling(cwd, manifest) {
|
|
835
|
+
return await detectProjectTooling(cwd, manifest.project?.tooling);
|
|
778
836
|
}
|
|
779
|
-
function
|
|
780
|
-
const
|
|
781
|
-
nextPackageJson.scripts ??= {};
|
|
837
|
+
async function ensureProjectTasks(cwd, manifest, tasks) {
|
|
838
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
782
839
|
const changedKeys = [];
|
|
783
|
-
for (const [
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
changedKeys.push(
|
|
787
|
-
}
|
|
840
|
+
for (const [name, definition] of Object.entries(tasks)) {
|
|
841
|
+
const result = await ensureTask(cwd, tooling.tasks, { definition, name });
|
|
842
|
+
if (result.changed)
|
|
843
|
+
changedKeys.push(name);
|
|
788
844
|
}
|
|
845
|
+
return { changedKeys, config: tooling.tasks.config, tooling };
|
|
846
|
+
}
|
|
847
|
+
async function checkProjectTasks(cwd, manifest, expected) {
|
|
848
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
849
|
+
const store = await readTaskStore(cwd, tooling.tasks);
|
|
789
850
|
return {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
851
|
+
config: tooling.tasks.config,
|
|
852
|
+
mismatches: Object.entries(expected).flatMap(([name, command]) => getTaskCommand(store.definitions[name]) === command ? [] : [name]),
|
|
853
|
+
store,
|
|
854
|
+
tooling,
|
|
793
855
|
};
|
|
794
856
|
}
|
|
795
|
-
export function buildManifest(cwd, packageJson, framework, existingManifest) {
|
|
857
|
+
export function buildManifest(cwd, packageJson, framework, existingManifest, tooling) {
|
|
796
858
|
return {
|
|
797
859
|
$schema: existingManifest?.$schema ?? LOOM_MANIFEST_SCHEMA,
|
|
798
860
|
version: 1,
|
|
@@ -804,6 +866,7 @@ export function buildManifest(cwd, packageJson, framework, existingManifest) {
|
|
|
804
866
|
...existingManifest?.project?.framework,
|
|
805
867
|
...framework,
|
|
806
868
|
},
|
|
869
|
+
tooling: existingManifest?.project?.tooling ?? tooling,
|
|
807
870
|
},
|
|
808
871
|
features: existingManifest?.features ?? {},
|
|
809
872
|
};
|
|
@@ -823,33 +886,6 @@ function hasPackageDependency(packageJson, dependencyName) {
|
|
|
823
886
|
return Boolean(packageJson.dependencies?.[dependencyName] ||
|
|
824
887
|
packageJson.devDependencies?.[dependencyName]);
|
|
825
888
|
}
|
|
826
|
-
async function detectPackageManager(cwd, packageJson) {
|
|
827
|
-
if (packageJson.packageManager?.startsWith("pnpm@")) {
|
|
828
|
-
return "pnpm";
|
|
829
|
-
}
|
|
830
|
-
if (packageJson.packageManager?.startsWith("yarn@")) {
|
|
831
|
-
return "yarn";
|
|
832
|
-
}
|
|
833
|
-
if (packageJson.packageManager?.startsWith("npm@")) {
|
|
834
|
-
return "npm";
|
|
835
|
-
}
|
|
836
|
-
if (await exists(join(cwd, "pnpm-lock.yaml"))) {
|
|
837
|
-
return "pnpm";
|
|
838
|
-
}
|
|
839
|
-
if (await exists(join(cwd, "yarn.lock"))) {
|
|
840
|
-
return "yarn";
|
|
841
|
-
}
|
|
842
|
-
return "npm";
|
|
843
|
-
}
|
|
844
|
-
function getRunScriptCommand(packageManager, scriptName) {
|
|
845
|
-
if (packageManager === "pnpm") {
|
|
846
|
-
return `pnpm ${scriptName}`;
|
|
847
|
-
}
|
|
848
|
-
if (packageManager === "yarn") {
|
|
849
|
-
return `yarn ${scriptName}`;
|
|
850
|
-
}
|
|
851
|
-
return `npm run ${scriptName}`;
|
|
852
|
-
}
|
|
853
889
|
function scriptRunsSerwistBuild(script) {
|
|
854
890
|
return Boolean(script && (/\bserwist\s+build\b/.test(script) ||
|
|
855
891
|
script.includes("@serwist/cli") ||
|
|
@@ -864,35 +900,6 @@ function formatTsNumberLiteral(value) {
|
|
|
864
900
|
function numberLiteralRegExp(value) {
|
|
865
901
|
return String(value).split("").map((digit) => `${digit}_?`).join("");
|
|
866
902
|
}
|
|
867
|
-
function ensurePwaPackageJsonScripts(packageJson, packageManager) {
|
|
868
|
-
const nextPackageJson = structuredClone(packageJson);
|
|
869
|
-
nextPackageJson.scripts ??= {};
|
|
870
|
-
const changedKeys = [];
|
|
871
|
-
const notes = [];
|
|
872
|
-
if (nextPackageJson.scripts["pwa:build"] !== PWA_BUILD_SCRIPT) {
|
|
873
|
-
nextPackageJson.scripts["pwa:build"] = PWA_BUILD_SCRIPT;
|
|
874
|
-
changedKeys.push("pwa:build");
|
|
875
|
-
}
|
|
876
|
-
const buildScript = nextPackageJson.scripts.build;
|
|
877
|
-
if (!buildScript) {
|
|
878
|
-
nextPackageJson.scripts.build = `next build && ${getRunScriptCommand(packageManager, "pwa:build")}`;
|
|
879
|
-
changedKeys.push("build");
|
|
880
|
-
}
|
|
881
|
-
else if (buildScript.includes("next build") &&
|
|
882
|
-
!scriptRunsSerwistBuild(buildScript)) {
|
|
883
|
-
nextPackageJson.scripts.build = `${buildScript} && ${getRunScriptCommand(packageManager, "pwa:build")}`;
|
|
884
|
-
changedKeys.push("build");
|
|
885
|
-
}
|
|
886
|
-
else if (!scriptRunsSerwistBuild(buildScript)) {
|
|
887
|
-
notes.push("PWA build script was added, but the existing build script does not visibly run `next build`; wire `pwa:build` after the app's Next.js build step.");
|
|
888
|
-
}
|
|
889
|
-
return {
|
|
890
|
-
changed: changedKeys.length > 0,
|
|
891
|
-
changedKeys,
|
|
892
|
-
notes,
|
|
893
|
-
packageJson: nextPackageJson,
|
|
894
|
-
};
|
|
895
|
-
}
|
|
896
903
|
function getJobsConfig(framework) {
|
|
897
904
|
const appRoot = framework.srcDir ? "src/app" : "app";
|
|
898
905
|
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
@@ -1135,12 +1142,37 @@ async function mergeAuthConfig(cwd, framework, featureConfig) {
|
|
|
1135
1142
|
},
|
|
1136
1143
|
};
|
|
1137
1144
|
}
|
|
1138
|
-
function
|
|
1145
|
+
function dependencyExecutable(tooling, executable) {
|
|
1146
|
+
switch (tooling.manager) {
|
|
1147
|
+
case "deno":
|
|
1148
|
+
return `deno run -A npm:${executable}`;
|
|
1149
|
+
case "npm":
|
|
1150
|
+
return `npx ${executable}`;
|
|
1151
|
+
case "pnpm":
|
|
1152
|
+
return `pnpm ${executable}`;
|
|
1153
|
+
case "yarn":
|
|
1154
|
+
return `yarn ${executable}`;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
function dependencyRefreshCommand(tooling, name, version) {
|
|
1158
|
+
switch (tooling.manager) {
|
|
1159
|
+
case "deno":
|
|
1160
|
+
return "deno install";
|
|
1161
|
+
case "npm":
|
|
1162
|
+
return `npm install --save-exact ${name}@${version}`;
|
|
1163
|
+
case "pnpm":
|
|
1164
|
+
return `pnpm update --no-save ${name}@${version} && pnpm install`;
|
|
1165
|
+
case "yarn":
|
|
1166
|
+
return `yarn add --exact ${name}@${version}`;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function getDbExpectedScripts(config, tooling) {
|
|
1170
|
+
const drizzleKit = dependencyExecutable(tooling.dependencies, "drizzle-kit");
|
|
1139
1171
|
return {
|
|
1140
1172
|
"db:fixtures": "loom db fixtures",
|
|
1141
|
-
"db:generate":
|
|
1142
|
-
"db:migrate":
|
|
1143
|
-
"db:push":
|
|
1173
|
+
"db:generate": `${drizzleKit} generate`,
|
|
1174
|
+
"db:migrate": `${drizzleKit} migrate`,
|
|
1175
|
+
"db:push": `${drizzleKit} push`,
|
|
1144
1176
|
"drizzle-kit": `NODE_OPTIONS='--import tsx' loom env -- drizzle-kit --config=./${config.modules.drizzleConfig}`,
|
|
1145
1177
|
"schema:gen": "loom db schema-gen",
|
|
1146
1178
|
};
|
|
@@ -1417,6 +1449,145 @@ export const ${exportName} = pgTable(
|
|
|
1417
1449
|
);
|
|
1418
1450
|
`;
|
|
1419
1451
|
}
|
|
1452
|
+
function buildMailSchemaText(config) {
|
|
1453
|
+
const [messagesExport, deliveriesExport, eventsExport] = [
|
|
1454
|
+
config.exports[0] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[0],
|
|
1455
|
+
config.exports[1] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[1],
|
|
1456
|
+
config.exports[2] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[2],
|
|
1457
|
+
];
|
|
1458
|
+
const messagesTable = config.tableName;
|
|
1459
|
+
const tablePrefix = messagesTable.endsWith("_messages")
|
|
1460
|
+
? messagesTable.slice(0, -"_messages".length)
|
|
1461
|
+
: messagesTable;
|
|
1462
|
+
const deliveriesTable = `${tablePrefix}_deliveries`;
|
|
1463
|
+
const eventsTable = `${tablePrefix}_events`;
|
|
1464
|
+
const indexName = (table, suffix) => filesSchemaIndexName(table, suffix);
|
|
1465
|
+
return `import { sql } from "drizzle-orm";
|
|
1466
|
+
import {
|
|
1467
|
+
index,
|
|
1468
|
+
integer,
|
|
1469
|
+
jsonb,
|
|
1470
|
+
pgTable,
|
|
1471
|
+
text,
|
|
1472
|
+
timestamp,
|
|
1473
|
+
uniqueIndex,
|
|
1474
|
+
uuid,
|
|
1475
|
+
} from "drizzle-orm/pg-core";
|
|
1476
|
+
|
|
1477
|
+
// Loom-managed schema blueprint: mail v${MAIL_SCHEMA_BLUEPRINT_VERSION}.
|
|
1478
|
+
// Keep app-specific domain associations in separate local schema files.
|
|
1479
|
+
export const ${messagesExport} = pgTable(
|
|
1480
|
+
"${messagesTable}",
|
|
1481
|
+
{
|
|
1482
|
+
id: uuid("id").default(sql\`uuid_generate_v7()\`).primaryKey(),
|
|
1483
|
+
provider: text("provider").notNull(),
|
|
1484
|
+
status: text("status").notNull().default("queued"),
|
|
1485
|
+
fromEmail: text("from_email").notNull(),
|
|
1486
|
+
fromName: text("from_name"),
|
|
1487
|
+
to: jsonb("to").notNull().$type<string[]>().default(sql\`'[]'::jsonb\`),
|
|
1488
|
+
cc: jsonb("cc").notNull().$type<string[]>().default(sql\`'[]'::jsonb\`),
|
|
1489
|
+
bcc: jsonb("bcc").notNull().$type<string[]>().default(sql\`'[]'::jsonb\`),
|
|
1490
|
+
subject: text("subject").notNull(),
|
|
1491
|
+
plainBody: text("plain_body"),
|
|
1492
|
+
htmlBody: text("html_body"),
|
|
1493
|
+
replyTo: text("reply_to"),
|
|
1494
|
+
tag: text("tag"),
|
|
1495
|
+
headers: jsonb("headers").notNull().$type<Record<string, string>>()
|
|
1496
|
+
.default(sql\`'{}'::jsonb\`),
|
|
1497
|
+
attachments: jsonb("attachments").notNull()
|
|
1498
|
+
.$type<Array<{ contentType?: string | null; data: string; name: string }>>()
|
|
1499
|
+
.default(sql\`'[]'::jsonb\`),
|
|
1500
|
+
metadata: jsonb("metadata").notNull().$type<Record<string, unknown>>()
|
|
1501
|
+
.default(sql\`'{}'::jsonb\`),
|
|
1502
|
+
providerMessageId: text("provider_message_id"),
|
|
1503
|
+
attemptCount: integer("attempt_count").notNull().default(0),
|
|
1504
|
+
availableAt: timestamp("available_at", { mode: "date", withTimezone: true })
|
|
1505
|
+
.notNull().defaultNow(),
|
|
1506
|
+
leaseToken: text("lease_token"),
|
|
1507
|
+
leaseExpiresAt: timestamp("lease_expires_at", { mode: "date", withTimezone: true }),
|
|
1508
|
+
lastErrorCode: text("last_error_code"),
|
|
1509
|
+
lastErrorMessage: text("last_error_message"),
|
|
1510
|
+
sentAt: timestamp("sent_at", { mode: "date", withTimezone: true }),
|
|
1511
|
+
failedAt: timestamp("failed_at", { mode: "date", withTimezone: true }),
|
|
1512
|
+
deliveredAt: timestamp("delivered_at", { mode: "date", withTimezone: true }),
|
|
1513
|
+
cancelledAt: timestamp("cancelled_at", { mode: "date", withTimezone: true }),
|
|
1514
|
+
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
|
|
1515
|
+
.notNull().defaultNow(),
|
|
1516
|
+
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true })
|
|
1517
|
+
.notNull().defaultNow(),
|
|
1518
|
+
},
|
|
1519
|
+
(table) => [
|
|
1520
|
+
index("${indexName(messagesTable, "outbox_idx")}").on(
|
|
1521
|
+
table.status,
|
|
1522
|
+
table.availableAt,
|
|
1523
|
+
table.leaseExpiresAt,
|
|
1524
|
+
),
|
|
1525
|
+
index("${indexName(messagesTable, "provider_message_idx")}").on(
|
|
1526
|
+
table.provider,
|
|
1527
|
+
table.providerMessageId,
|
|
1528
|
+
),
|
|
1529
|
+
index("${indexName(messagesTable, "created_idx")}").on(table.createdAt),
|
|
1530
|
+
],
|
|
1531
|
+
);
|
|
1532
|
+
|
|
1533
|
+
export const ${deliveriesExport} = pgTable(
|
|
1534
|
+
"${deliveriesTable}",
|
|
1535
|
+
{
|
|
1536
|
+
id: uuid("id").default(sql\`uuid_generate_v7()\`).primaryKey(),
|
|
1537
|
+
messageId: uuid("message_id").notNull()
|
|
1538
|
+
.references(() => ${messagesExport}.id, { onDelete: "cascade" }),
|
|
1539
|
+
kind: text("kind").notNull(),
|
|
1540
|
+
email: text("email").notNull(),
|
|
1541
|
+
status: text("status").notNull().default("queued"),
|
|
1542
|
+
providerDeliveryId: text("provider_delivery_id"),
|
|
1543
|
+
providerToken: text("provider_token"),
|
|
1544
|
+
lastErrorCode: text("last_error_code"),
|
|
1545
|
+
lastErrorMessage: text("last_error_message"),
|
|
1546
|
+
deliveredAt: timestamp("delivered_at", { mode: "date", withTimezone: true }),
|
|
1547
|
+
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
|
|
1548
|
+
.notNull().defaultNow(),
|
|
1549
|
+
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true })
|
|
1550
|
+
.notNull().defaultNow(),
|
|
1551
|
+
},
|
|
1552
|
+
(table) => [
|
|
1553
|
+
index("${indexName(deliveriesTable, "message_idx")}").on(table.messageId),
|
|
1554
|
+
index("${indexName(deliveriesTable, "provider_delivery_idx")}").on(
|
|
1555
|
+
table.providerDeliveryId,
|
|
1556
|
+
),
|
|
1557
|
+
index("${indexName(deliveriesTable, "recipient_idx")}").on(table.email),
|
|
1558
|
+
],
|
|
1559
|
+
);
|
|
1560
|
+
|
|
1561
|
+
export const ${eventsExport} = pgTable(
|
|
1562
|
+
"${eventsTable}",
|
|
1563
|
+
{
|
|
1564
|
+
id: uuid("id").default(sql\`uuid_generate_v7()\`).primaryKey(),
|
|
1565
|
+
messageId: uuid("message_id").notNull()
|
|
1566
|
+
.references(() => ${messagesExport}.id, { onDelete: "cascade" }),
|
|
1567
|
+
deliveryId: uuid("delivery_id")
|
|
1568
|
+
.references(() => ${deliveriesExport}.id, { onDelete: "set null" }),
|
|
1569
|
+
provider: text("provider").notNull(),
|
|
1570
|
+
providerEventId: text("provider_event_id"),
|
|
1571
|
+
eventType: text("event_type").notNull(),
|
|
1572
|
+
sourceEvent: text("source_event").notNull(),
|
|
1573
|
+
payload: jsonb("payload").notNull().$type<Record<string, unknown>>()
|
|
1574
|
+
.default(sql\`'{}'::jsonb\`),
|
|
1575
|
+
occurredAt: timestamp("occurred_at", { mode: "date", withTimezone: true })
|
|
1576
|
+
.notNull().defaultNow(),
|
|
1577
|
+
},
|
|
1578
|
+
(table) => [
|
|
1579
|
+
index("${indexName(eventsTable, "message_occurred_idx")}").on(
|
|
1580
|
+
table.messageId,
|
|
1581
|
+
table.occurredAt,
|
|
1582
|
+
),
|
|
1583
|
+
uniqueIndex("${indexName(eventsTable, "provider_event_unique")}").on(
|
|
1584
|
+
table.provider,
|
|
1585
|
+
table.providerEventId,
|
|
1586
|
+
),
|
|
1587
|
+
],
|
|
1588
|
+
);
|
|
1589
|
+
`;
|
|
1590
|
+
}
|
|
1420
1591
|
function getFilesDefaultSchemaConfig(dbConfig) {
|
|
1421
1592
|
const baseConfig = {
|
|
1422
1593
|
blueprint: "files",
|
|
@@ -1432,6 +1603,20 @@ function getFilesDefaultSchemaConfig(dbConfig) {
|
|
|
1432
1603
|
hash: hashManagedSchemaText(buildFilesSchemaText(baseConfig)),
|
|
1433
1604
|
};
|
|
1434
1605
|
}
|
|
1606
|
+
function getMailDefaultSchemaConfig(dbConfig) {
|
|
1607
|
+
const baseConfig = {
|
|
1608
|
+
blueprint: "mail",
|
|
1609
|
+
exports: [...MAIL_SCHEMA_DEFAULT_EXPORTS],
|
|
1610
|
+
mode: "managed-local",
|
|
1611
|
+
module: join(dbConfig.dirs.schemaDir, "loomMail.ts"),
|
|
1612
|
+
tableName: MAIL_SCHEMA_DEFAULT_TABLE,
|
|
1613
|
+
version: MAIL_SCHEMA_BLUEPRINT_VERSION,
|
|
1614
|
+
};
|
|
1615
|
+
return {
|
|
1616
|
+
...baseConfig,
|
|
1617
|
+
hash: hashManagedSchemaText(buildMailSchemaText(baseConfig)),
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1435
1620
|
function getApiKeysDefaultSchemaConfig(dbConfig) {
|
|
1436
1621
|
const baseConfig = {
|
|
1437
1622
|
blueprint: "api-key-audit",
|
|
@@ -1527,6 +1712,23 @@ function mergeManagedLocalSchemaConfig(dbConfig, schemaConfig) {
|
|
|
1527
1712
|
hashManagedSchemaText(buildFilesSchemaText(merged)),
|
|
1528
1713
|
};
|
|
1529
1714
|
}
|
|
1715
|
+
function mergeMailSchemaConfig(dbConfig, schemaConfig) {
|
|
1716
|
+
const defaults = getMailDefaultSchemaConfig(dbConfig);
|
|
1717
|
+
const merged = {
|
|
1718
|
+
...defaults,
|
|
1719
|
+
...schemaConfig,
|
|
1720
|
+
blueprint: "mail",
|
|
1721
|
+
exports: schemaConfig?.exports?.length === 3
|
|
1722
|
+
? schemaConfig.exports
|
|
1723
|
+
: defaults.exports,
|
|
1724
|
+
mode: "managed-local",
|
|
1725
|
+
};
|
|
1726
|
+
return {
|
|
1727
|
+
...merged,
|
|
1728
|
+
hash: schemaConfig?.hash ??
|
|
1729
|
+
hashManagedSchemaText(buildMailSchemaText(merged)),
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1530
1732
|
function getFilesConfig(framework, dbConfig, featureConfig) {
|
|
1531
1733
|
const appRoot = framework.srcDir ? "src/app" : "app";
|
|
1532
1734
|
const filesRoot = framework.srcDir ? "src/files" : "files";
|
|
@@ -1550,6 +1752,44 @@ function getFilesConfig(framework, dbConfig, featureConfig) {
|
|
|
1550
1752
|
},
|
|
1551
1753
|
};
|
|
1552
1754
|
}
|
|
1755
|
+
function getMailConfig(framework, dbConfig, packageJson, featureConfig, jobsActive) {
|
|
1756
|
+
const appRoot = framework.srcDir ? "src/app" : "app";
|
|
1757
|
+
const mailRoot = framework.srcDir ? "src/mail" : "mail";
|
|
1758
|
+
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
1759
|
+
return {
|
|
1760
|
+
entrypoints: {
|
|
1761
|
+
adminPage: featureConfig?.entrypoints?.adminPage ??
|
|
1762
|
+
`${appRoot}/admin/mail/page.tsx`,
|
|
1763
|
+
webhookRoute: featureConfig?.entrypoints?.webhookRoute ??
|
|
1764
|
+
`${appRoot}/api/mail/postal/route.ts`,
|
|
1765
|
+
},
|
|
1766
|
+
jobs: {
|
|
1767
|
+
enabled: featureConfig?.jobs?.enabled ?? jobsActive,
|
|
1768
|
+
},
|
|
1769
|
+
modules: {
|
|
1770
|
+
accessModule: featureConfig?.modules?.accessModule ??
|
|
1771
|
+
`${mailRoot}/access.ts`,
|
|
1772
|
+
actionsModule: featureConfig?.modules?.actionsModule ??
|
|
1773
|
+
`${mailRoot}/actions.ts`,
|
|
1774
|
+
jobModule: featureConfig?.modules?.jobModule ??
|
|
1775
|
+
`${jobsRoot}/mail-drain.ts`,
|
|
1776
|
+
repositoryModule: featureConfig?.modules?.repositoryModule ??
|
|
1777
|
+
`${mailRoot}/repository.ts`,
|
|
1778
|
+
serviceModule: featureConfig?.modules?.serviceModule ??
|
|
1779
|
+
`${mailRoot}/service.ts`,
|
|
1780
|
+
transportModule: featureConfig?.modules?.transportModule ??
|
|
1781
|
+
`${mailRoot}/transport.ts`,
|
|
1782
|
+
},
|
|
1783
|
+
provider: "postal",
|
|
1784
|
+
schema: mergeMailSchemaConfig(dbConfig, featureConfig?.schema),
|
|
1785
|
+
ui: {
|
|
1786
|
+
adapter: featureConfig?.ui?.adapter ??
|
|
1787
|
+
(hasPackageDependency(packageJson, "@mui/material")
|
|
1788
|
+
? "mui"
|
|
1789
|
+
: "headless"),
|
|
1790
|
+
},
|
|
1791
|
+
};
|
|
1792
|
+
}
|
|
1553
1793
|
function normalizeText(text) {
|
|
1554
1794
|
return text.replaceAll("\r\n", "\n");
|
|
1555
1795
|
}
|
|
@@ -1565,9 +1805,10 @@ For all work in this repo:
|
|
|
1565
1805
|
1. Use the \`loom\` skill first.
|
|
1566
1806
|
2. Read \`loom.json\` before making Loom-related changes.
|
|
1567
1807
|
3. Treat active Loom features and configured paths as the contract between the app and the shared package.
|
|
1568
|
-
4.
|
|
1569
|
-
5.
|
|
1570
|
-
6.
|
|
1808
|
+
4. Read \`project.tooling\` in \`loom.json\`; do not assume tasks live in \`package.json\` or that pnpm is the runner.
|
|
1809
|
+
5. If the task touches a specific active Loom feature, also use the matching feature skill such as \`loom-jobs\`.
|
|
1810
|
+
6. Next commands load \`.env*\` themselves; non-Next commands that need env should use the authoritative project task or \`loom env -- <command>\`, not inline env-loader imports.
|
|
1811
|
+
7. Keep project-specific rules outside this managed block; shared Loom policy lives in the \`loom\` skill.
|
|
1571
1812
|
${LOOM_MANAGED_AGENTS_END}
|
|
1572
1813
|
`;
|
|
1573
1814
|
}
|
|
@@ -1830,6 +2071,37 @@ async function ensurePnpmProject(cwd, packageJson) {
|
|
|
1830
2071
|
}
|
|
1831
2072
|
throw new Error("loom dev local/published currently supports pnpm projects only.");
|
|
1832
2073
|
}
|
|
2074
|
+
function usesDenoTooling(tooling) {
|
|
2075
|
+
return tooling.tasks.runner === "deno" ||
|
|
2076
|
+
tooling.dependencies.manager === "deno";
|
|
2077
|
+
}
|
|
2078
|
+
async function getDenoConfigForLinks(cwd, tooling) {
|
|
2079
|
+
for (const config of [
|
|
2080
|
+
tooling.tasks.config,
|
|
2081
|
+
tooling.dependencies.config,
|
|
2082
|
+
"deno.json",
|
|
2083
|
+
"deno.jsonc",
|
|
2084
|
+
]) {
|
|
2085
|
+
if ((config === "deno.json" || config === "deno.jsonc") &&
|
|
2086
|
+
await exists(join(cwd, config))) {
|
|
2087
|
+
return config;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
throw new Error("Deno local development requires a deno.json or deno.jsonc workspace root.");
|
|
2091
|
+
}
|
|
2092
|
+
async function findLocalLoomDenoLink(cwd, links) {
|
|
2093
|
+
for (const link of links) {
|
|
2094
|
+
const path = resolve(cwd, link);
|
|
2095
|
+
const packageText = await readTextIfExists(join(path, "package.json"));
|
|
2096
|
+
if (!packageText)
|
|
2097
|
+
continue;
|
|
2098
|
+
if (parseJson(packageText, `${link}/package.json`).name ===
|
|
2099
|
+
LOOM_DEPENDENCY) {
|
|
2100
|
+
return { link, path };
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
return null;
|
|
2104
|
+
}
|
|
1833
2105
|
async function resolveLocalLoomPackagePath(cwd, inputPath) {
|
|
1834
2106
|
const resolvedInput = resolve(cwd, inputPath);
|
|
1835
2107
|
const candidates = [resolvedInput, join(resolvedInput, "npm")];
|
|
@@ -1945,6 +2217,9 @@ async function readPackageVersion(packagePath) {
|
|
|
1945
2217
|
}
|
|
1946
2218
|
return parseJson(packageJsonText, join(packagePath, "package.json")).version;
|
|
1947
2219
|
}
|
|
2220
|
+
function versionFromDependencySpec(spec) {
|
|
2221
|
+
return spec?.match(/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/)?.[1];
|
|
2222
|
+
}
|
|
1948
2223
|
async function getGitStdout(commandRunner, cwd, args, env) {
|
|
1949
2224
|
const result = await commandRunner("git", args, { cwd, env });
|
|
1950
2225
|
if (result.code !== 0) {
|
|
@@ -2011,7 +2286,7 @@ async function writeLocalDevStateIfChanged(cwd, state) {
|
|
|
2011
2286
|
await writeFile(gitignorePath, gitignoreUpdate.text, "utf8");
|
|
2012
2287
|
gitignoreChanged = true;
|
|
2013
2288
|
}
|
|
2014
|
-
return stateChanged
|
|
2289
|
+
return { gitignoreChanged, stateChanged };
|
|
2015
2290
|
}
|
|
2016
2291
|
async function getCurrentLocalDevState(cwd, workspaceText) {
|
|
2017
2292
|
return getManagedDevState(workspaceText) ?? await readLocalDevState(cwd);
|
|
@@ -2127,10 +2402,19 @@ async function resolveLoomCommitPublication(sourceRoot, sourceCommit, commandRun
|
|
|
2127
2402
|
return { status: "no-release-tag" };
|
|
2128
2403
|
}
|
|
2129
2404
|
export async function syncLocalDevPackage(cwd, options = {}) {
|
|
2405
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2406
|
+
const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
|
|
2407
|
+
const denoMode = usesDenoTooling(tooling);
|
|
2130
2408
|
const workspacePath = join(cwd, "pnpm-workspace.yaml");
|
|
2131
2409
|
const workspaceText = await readTextIfExists(workspacePath);
|
|
2132
2410
|
const overrideSpec = getManagedDevOverrideSpec(workspaceText);
|
|
2133
|
-
|
|
2411
|
+
const denoConfig = denoMode
|
|
2412
|
+
? await getDenoConfigForLinks(cwd, tooling)
|
|
2413
|
+
: null;
|
|
2414
|
+
const denoLink = denoConfig
|
|
2415
|
+
? await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, denoConfig))
|
|
2416
|
+
: null;
|
|
2417
|
+
if (!overrideSpec && !denoLink) {
|
|
2134
2418
|
if (options.requireActive) {
|
|
2135
2419
|
throw new Error("No managed Loom local-dev override is active. Run `loom dev local /path/to/loom` first.");
|
|
2136
2420
|
}
|
|
@@ -2143,20 +2427,31 @@ export async function syncLocalDevPackage(cwd, options = {}) {
|
|
|
2143
2427
|
};
|
|
2144
2428
|
}
|
|
2145
2429
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
2146
|
-
|
|
2430
|
+
if (!denoMode)
|
|
2431
|
+
await ensurePnpmProject(cwd, packageJson);
|
|
2147
2432
|
const commandRunner = options.commandRunner ?? defaultCommandRunner;
|
|
2148
2433
|
const env = options.env ?? process.env;
|
|
2149
|
-
const localPackagePath =
|
|
2434
|
+
const localPackagePath = denoLink?.path ??
|
|
2435
|
+
fileSpecToPath(cwd, overrideSpec);
|
|
2150
2436
|
const sourceRoot = await resolveLocalLoomSourceRoot(localPackagePath);
|
|
2437
|
+
const configuredSpec = packageJson.dependencies?.[LOOM_DEPENDENCY] ??
|
|
2438
|
+
packageJson.devDependencies?.[LOOM_DEPENDENCY];
|
|
2439
|
+
const desiredLocalVersion = await readPackageVersion(join(cwd, "node_modules", LOOM_DEPENDENCY)) ?? versionFromDependencySpec(configuredSpec) ??
|
|
2440
|
+
await readPackageVersion(localPackagePath);
|
|
2441
|
+
const currentLocalVersion = await readPackageVersion(localPackagePath);
|
|
2442
|
+
const buildEnv = desiredLocalVersion && !env.NPM_PACKAGE_VERSION
|
|
2443
|
+
? { ...env, NPM_PACKAGE_VERSION: desiredLocalVersion }
|
|
2444
|
+
: env;
|
|
2151
2445
|
const ranCommands = [];
|
|
2152
2446
|
let buildRan = false;
|
|
2153
|
-
if (options.force ||
|
|
2447
|
+
if (options.force || denoMode && currentLocalVersion !== desiredLocalVersion ||
|
|
2448
|
+
await isLocalLoomBuildStale(sourceRoot, localPackagePath)) {
|
|
2154
2449
|
if (!sourceRoot) {
|
|
2155
2450
|
throw new Error(`Could not find the Loom source checkout for ${localPackagePath}; cannot rebuild the local package.`);
|
|
2156
2451
|
}
|
|
2157
2452
|
await runCommandOrThrow(commandRunner, "deno", ["task", "build"], {
|
|
2158
2453
|
cwd: sourceRoot,
|
|
2159
|
-
env,
|
|
2454
|
+
env: buildEnv,
|
|
2160
2455
|
stdio: "inherit",
|
|
2161
2456
|
});
|
|
2162
2457
|
ranCommands.push("deno task build");
|
|
@@ -2166,25 +2461,39 @@ export async function syncLocalDevPackage(cwd, options = {}) {
|
|
|
2166
2461
|
await isInstalledLocalLoomPackageStale(cwd, localPackagePath);
|
|
2167
2462
|
let packageRefreshRan = false;
|
|
2168
2463
|
if (options.force || packageRefreshNeeded) {
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2464
|
+
if (denoMode) {
|
|
2465
|
+
await runCommandOrThrow(commandRunner, "deno", ["install"], {
|
|
2466
|
+
cwd,
|
|
2467
|
+
env,
|
|
2468
|
+
stdio: "inherit",
|
|
2469
|
+
});
|
|
2470
|
+
ranCommands.push("deno install");
|
|
2471
|
+
}
|
|
2472
|
+
else {
|
|
2473
|
+
const packageSpec = `${LOOM_DEPENDENCY}@file:${localPackagePath}`;
|
|
2474
|
+
await runCommandOrThrow(commandRunner, "pnpm", ["update", "--no-save", packageSpec], { cwd, env, stdio: "inherit" });
|
|
2475
|
+
ranCommands.push(`pnpm update --no-save ${packageSpec}`);
|
|
2476
|
+
await runCommandOrThrow(commandRunner, "pnpm", ["install"], {
|
|
2477
|
+
cwd,
|
|
2478
|
+
env,
|
|
2479
|
+
stdio: "inherit",
|
|
2480
|
+
});
|
|
2481
|
+
ranCommands.push("pnpm install");
|
|
2482
|
+
}
|
|
2178
2483
|
packageRefreshRan = true;
|
|
2179
2484
|
}
|
|
2180
2485
|
const currentWorkspaceText = await readTextIfExists(workspacePath);
|
|
2181
|
-
const currentState =
|
|
2486
|
+
const currentState = denoMode
|
|
2487
|
+
? await readLocalDevState(cwd)
|
|
2488
|
+
: await getCurrentLocalDevState(cwd, currentWorkspaceText);
|
|
2182
2489
|
let state = null;
|
|
2183
2490
|
if (buildRan || packageRefreshRan || !currentState) {
|
|
2184
2491
|
state = await buildLocalDevState(localPackagePath, sourceRoot, commandRunner, env);
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2492
|
+
if (!denoMode) {
|
|
2493
|
+
const stateUpdate = setManagedDevStateText(await readTextIfExists(workspacePath), overrideSpec, state);
|
|
2494
|
+
if (stateUpdate.changed) {
|
|
2495
|
+
await writeTextOrDeleteIfEmpty(workspacePath, stateUpdate.text);
|
|
2496
|
+
}
|
|
2188
2497
|
}
|
|
2189
2498
|
}
|
|
2190
2499
|
if (state ?? currentState) {
|
|
@@ -2213,16 +2522,43 @@ export async function syncLocalDevPackage(cwd, options = {}) {
|
|
|
2213
2522
|
};
|
|
2214
2523
|
}
|
|
2215
2524
|
export async function useLocalDevPackage(cwd, inputPath) {
|
|
2216
|
-
const
|
|
2217
|
-
const
|
|
2218
|
-
|
|
2219
|
-
|
|
2525
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
2526
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2527
|
+
const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
|
|
2528
|
+
const localPackagePath = await resolveLocalLoomPackagePath(cwd, inputPath);
|
|
2529
|
+
const publishedSpec = getPublishedLoomDependencySpec(packageJson);
|
|
2530
|
+
if (usesDenoTooling(tooling)) {
|
|
2531
|
+
if (!await exists(join(localPackagePath, "deno.json"))) {
|
|
2532
|
+
throw new Error(`Local Deno development requires ${localPackagePath}/deno.json. Rebuild the Loom npm output before linking it.`);
|
|
2533
|
+
}
|
|
2534
|
+
const denoConfig = await getDenoConfigForLinks(cwd, tooling);
|
|
2535
|
+
const relativeLocalPackagePath = relative(cwd, localPackagePath)
|
|
2536
|
+
.replaceAll("\\", "/");
|
|
2537
|
+
const update = await mutateDenoLinks(cwd, denoConfig, {
|
|
2538
|
+
add: relativeLocalPackagePath,
|
|
2539
|
+
});
|
|
2540
|
+
const state = {
|
|
2541
|
+
dependency: LOOM_DEPENDENCY,
|
|
2542
|
+
localPackagePath,
|
|
2543
|
+
packageVersion: await readPackageVersion(localPackagePath),
|
|
2544
|
+
syncedAt: new Date().toISOString(),
|
|
2545
|
+
version: 1,
|
|
2546
|
+
};
|
|
2547
|
+
const stateUpdate = await writeLocalDevStateIfChanged(cwd, state);
|
|
2548
|
+
const changedFiles = update.changed ? [denoConfig] : [];
|
|
2549
|
+
if (stateUpdate.gitignoreChanged)
|
|
2550
|
+
changedFiles.push(".gitignore");
|
|
2551
|
+
return {
|
|
2552
|
+
changedFiles,
|
|
2553
|
+
notes: [
|
|
2554
|
+
`Local Loom dev link is active in ${denoConfig}: ${localPackagePath}`,
|
|
2555
|
+
"Run `loom dev sync` to rebuild the local Loom package and refresh Deno's dependency installation when needed.",
|
|
2556
|
+
`Before committing or shipping a published build, run loom dev published, then deno install to restore ${LOOM_DEPENDENCY}@${publishedSpec}.`,
|
|
2557
|
+
],
|
|
2558
|
+
};
|
|
2220
2559
|
}
|
|
2221
|
-
const packageJson = parseJson(packageJsonText, "package.json");
|
|
2222
2560
|
await ensurePnpmProject(cwd, packageJson);
|
|
2223
|
-
const localPackagePath = await resolveLocalLoomPackagePath(cwd, inputPath);
|
|
2224
2561
|
const overrideSpec = `file:${localPackagePath}`;
|
|
2225
|
-
const publishedSpec = getPublishedLoomDependencySpec(packageJson);
|
|
2226
2562
|
const workspacePath = join(cwd, "pnpm-workspace.yaml");
|
|
2227
2563
|
const update = ensurePnpmWorkspaceLocalDevText(await readTextIfExists(workspacePath), overrideSpec);
|
|
2228
2564
|
if (update.conflict) {
|
|
@@ -2243,20 +2579,30 @@ export async function useLocalDevPackage(cwd, inputPath) {
|
|
|
2243
2579
|
};
|
|
2244
2580
|
}
|
|
2245
2581
|
export async function usePublishedDevPackage(cwd, options = {}) {
|
|
2246
|
-
const
|
|
2247
|
-
const
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
await ensurePnpmProject(cwd, packageJson);
|
|
2582
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
2583
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2584
|
+
const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
|
|
2585
|
+
const denoMode = usesDenoTooling(tooling);
|
|
2586
|
+
if (!denoMode)
|
|
2587
|
+
await ensurePnpmProject(cwd, packageJson);
|
|
2253
2588
|
const commandRunner = options.commandRunner ?? defaultCommandRunner;
|
|
2254
2589
|
const env = options.env ?? process.env;
|
|
2255
2590
|
const workspacePath = join(cwd, "pnpm-workspace.yaml");
|
|
2256
2591
|
const workspaceText = await readTextIfExists(workspacePath);
|
|
2257
|
-
const
|
|
2258
|
-
|
|
2259
|
-
|
|
2592
|
+
const denoConfig = denoMode
|
|
2593
|
+
? await getDenoConfigForLinks(cwd, tooling)
|
|
2594
|
+
: null;
|
|
2595
|
+
const denoLink = denoConfig
|
|
2596
|
+
? await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, denoConfig))
|
|
2597
|
+
: null;
|
|
2598
|
+
const activeOverrideSpec = denoLink?.link ??
|
|
2599
|
+
getManagedDevOverrideSpec(workspaceText);
|
|
2600
|
+
const localLockfileResolution = denoMode
|
|
2601
|
+
? null
|
|
2602
|
+
: await getProjectLocalLoomLockfileResolution(cwd);
|
|
2603
|
+
const state = denoMode
|
|
2604
|
+
? await readLocalDevState(cwd)
|
|
2605
|
+
: await getCurrentLocalDevState(cwd, workspaceText);
|
|
2260
2606
|
const notes = [];
|
|
2261
2607
|
let publishedSpec = getPublishedLoomDependencySpec(packageJson);
|
|
2262
2608
|
const needsPublicationProof = Boolean(activeOverrideSpec || localLockfileResolution);
|
|
@@ -2279,21 +2625,33 @@ export async function usePublishedDevPackage(cwd, options = {}) {
|
|
|
2279
2625
|
else if (needsPublicationProof) {
|
|
2280
2626
|
notes.push("No recorded Loom sync commit was found; switching back to the existing published dependency without proving whether local Loom changes were required.");
|
|
2281
2627
|
}
|
|
2282
|
-
const dependencyUpdate =
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
}
|
|
2286
|
-
const
|
|
2628
|
+
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
|
|
2629
|
+
dependencies: { [LOOM_DEPENDENCY]: publishedSpec },
|
|
2630
|
+
replace: true,
|
|
2631
|
+
});
|
|
2632
|
+
const denoUpdate = denoConfig && denoLink
|
|
2633
|
+
? await mutateDenoLinks(cwd, denoConfig, { remove: denoLink.link })
|
|
2634
|
+
: null;
|
|
2635
|
+
const update = denoMode
|
|
2636
|
+
? { changed: denoUpdate?.changed ?? false, text: "" }
|
|
2637
|
+
: clearPnpmWorkspaceLocalDevText(await readTextIfExists(workspacePath));
|
|
2287
2638
|
const changedFiles = [];
|
|
2288
2639
|
if (dependencyUpdate.changed) {
|
|
2289
|
-
changedFiles.push(
|
|
2640
|
+
changedFiles.push(dependencyUpdate.config);
|
|
2290
2641
|
}
|
|
2291
2642
|
if (update.changed) {
|
|
2292
|
-
|
|
2293
|
-
|
|
2643
|
+
if (denoMode) {
|
|
2644
|
+
changedFiles.push(denoConfig);
|
|
2645
|
+
}
|
|
2646
|
+
else {
|
|
2647
|
+
await writeTextOrDeleteIfEmpty(workspacePath, update.text);
|
|
2648
|
+
changedFiles.push("pnpm-workspace.yaml");
|
|
2649
|
+
}
|
|
2294
2650
|
}
|
|
2295
2651
|
if (update.changed || localLockfileResolution) {
|
|
2296
|
-
notes.push(
|
|
2652
|
+
notes.push(denoMode
|
|
2653
|
+
? `Run \`deno install\` in this project to return node_modules and deno.lock to published ${LOOM_DEPENDENCY}@${publishedSpec}.`
|
|
2654
|
+
: `Run \`pnpm update --no-save ${LOOM_DEPENDENCY}@${publishedSpec}\` and then \`pnpm install\` in this project to return node_modules and the lockfile to the published ${LOOM_DEPENDENCY} dependency.`);
|
|
2297
2655
|
}
|
|
2298
2656
|
if (localLockfileResolution) {
|
|
2299
2657
|
notes.push(`pnpm-lock.yaml still resolves ${LOOM_DEPENDENCY} to ${localLockfileResolution} until that update is run.`);
|
|
@@ -2427,26 +2785,43 @@ async function checkManagedAgentsFile(cwd) {
|
|
|
2427
2785
|
};
|
|
2428
2786
|
}
|
|
2429
2787
|
async function checkManagedLocalDevOverride(cwd, production = false) {
|
|
2788
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2789
|
+
let denoLink = null;
|
|
2790
|
+
let denoConfig = null;
|
|
2791
|
+
try {
|
|
2792
|
+
const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
|
|
2793
|
+
if (usesDenoTooling(tooling)) {
|
|
2794
|
+
denoConfig = await getDenoConfigForLinks(cwd, tooling);
|
|
2795
|
+
denoLink = await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, denoConfig));
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
catch {
|
|
2799
|
+
// The main project tooling check reports invalid configuration separately.
|
|
2800
|
+
}
|
|
2430
2801
|
const workspaceText = await readTextIfExists(join(cwd, "pnpm-workspace.yaml"));
|
|
2431
2802
|
const overrideSpec = getManagedDevOverrideSpec(workspaceText);
|
|
2432
|
-
if (!overrideSpec) {
|
|
2803
|
+
if (!overrideSpec && !denoLink) {
|
|
2433
2804
|
return {
|
|
2434
2805
|
issues: [],
|
|
2435
2806
|
suggestions: [],
|
|
2436
2807
|
warnings: [],
|
|
2437
2808
|
};
|
|
2438
2809
|
}
|
|
2810
|
+
const location = denoLink
|
|
2811
|
+
? `${denoConfig} links: ${denoLink.link}`
|
|
2812
|
+
: `pnpm-workspace.yaml: ${overrideSpec}`;
|
|
2813
|
+
const restore = denoLink
|
|
2814
|
+
? "Run `loom dev published`, then run `deno install` before committing or shipping a published build."
|
|
2815
|
+
: `Run \`loom dev published\`, then follow its printed \`pnpm update --no-save ${LOOM_DEPENDENCY}@<version>\` command and run \`pnpm install\` before committing or shipping a published build.`;
|
|
2439
2816
|
return {
|
|
2440
2817
|
issues: production
|
|
2441
2818
|
? [
|
|
2442
|
-
`Local Loom dev override is active in
|
|
2819
|
+
`Local Loom dev override is active in ${location}`,
|
|
2443
2820
|
]
|
|
2444
2821
|
: [],
|
|
2445
|
-
suggestions: [
|
|
2446
|
-
`Run \`loom dev published\`, then follow its printed \`pnpm update --no-save ${LOOM_DEPENDENCY}@<version>\` command and run \`pnpm install\` before committing or shipping a published build.`,
|
|
2447
|
-
],
|
|
2822
|
+
suggestions: [restore],
|
|
2448
2823
|
warnings: production ? [] : [
|
|
2449
|
-
`Local Loom dev override is active in
|
|
2824
|
+
`Local Loom dev override is active in ${location}`,
|
|
2450
2825
|
],
|
|
2451
2826
|
};
|
|
2452
2827
|
}
|
|
@@ -2487,6 +2862,18 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2487
2862
|
const warnings = [];
|
|
2488
2863
|
const dependency = packageJson.dependencies?.[LOOM_DEPENDENCY];
|
|
2489
2864
|
const production = options.production;
|
|
2865
|
+
const projectMetadata = await readProjectPackageMetadata(cwd);
|
|
2866
|
+
let dependencyTooling = {
|
|
2867
|
+
config: projectMetadata.config,
|
|
2868
|
+
manager: projectMetadata.config === "package.json" ? "pnpm" : "deno",
|
|
2869
|
+
};
|
|
2870
|
+
try {
|
|
2871
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2872
|
+
dependencyTooling = (await detectProjectTooling(cwd, manifest?.project?.tooling)).dependencies;
|
|
2873
|
+
}
|
|
2874
|
+
catch {
|
|
2875
|
+
// The main tooling check owns the validation error; release hints can fall back.
|
|
2876
|
+
}
|
|
2490
2877
|
const localLockfileResolution = await getProjectLocalLoomLockfileResolution(cwd);
|
|
2491
2878
|
const devState = await readLocalDevState(cwd);
|
|
2492
2879
|
if (localLockfileResolution) {
|
|
@@ -2520,8 +2907,8 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2520
2907
|
"package-equivalent"
|
|
2521
2908
|
? `package-relevant files match ${LOOM_DEPENDENCY}@${publication.version}`
|
|
2522
2909
|
: `it is published as ${LOOM_DEPENDENCY}@${publication.version}`;
|
|
2523
|
-
addReleaseCheckMessage(issues, warnings, production, `This app was last synced against Loom commit ${shortCommit}; ${publicationDescription}, but
|
|
2524
|
-
suggestions.add(`Run
|
|
2910
|
+
addReleaseCheckMessage(issues, warnings, production, `This app was last synced against Loom commit ${shortCommit}; ${publicationDescription}, but ${dependencyTooling.config} is pinned to ${dependency}.`);
|
|
2911
|
+
suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, LOOM_DEPENDENCY, publication.version)}.`);
|
|
2525
2912
|
}
|
|
2526
2913
|
else if (localLockfileResolution) {
|
|
2527
2914
|
const publicationDescription = publication.reason ===
|
|
@@ -2529,7 +2916,7 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2529
2916
|
? `has no package-relevant changes after ${publication.tag}, so ${LOOM_DEPENDENCY}@${publication.version} covers it`
|
|
2530
2917
|
: `is published as ${LOOM_DEPENDENCY}@${publication.version}`;
|
|
2531
2918
|
warnings.push(`The synced Loom commit ${shortCommit} ${publicationDescription}; refresh the lockfile away from ${localLockfileResolution}.`);
|
|
2532
|
-
suggestions.add(`Run
|
|
2919
|
+
suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, LOOM_DEPENDENCY, publication.version)}.`);
|
|
2533
2920
|
}
|
|
2534
2921
|
break;
|
|
2535
2922
|
}
|
|
@@ -2554,8 +2941,8 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2554
2941
|
else {
|
|
2555
2942
|
const installedPackage = parseJson(installedPackageText, join("node_modules", LOOM_DEPENDENCY, "package.json"));
|
|
2556
2943
|
if (installedPackage.version !== dependency) {
|
|
2557
|
-
issues.push(`Installed ${LOOM_DEPENDENCY} version ${installedPackage.version} does not match
|
|
2558
|
-
suggestions.add(`Run
|
|
2944
|
+
issues.push(`Installed ${LOOM_DEPENDENCY} version ${installedPackage.version} does not match ${dependencyTooling.config} ${dependency}.`);
|
|
2945
|
+
suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, LOOM_DEPENDENCY, dependency)}.`);
|
|
2559
2946
|
}
|
|
2560
2947
|
}
|
|
2561
2948
|
}
|
|
@@ -2629,7 +3016,7 @@ function getGithubWorkflowStepBlocks(text) {
|
|
|
2629
3016
|
}
|
|
2630
3017
|
function workflowInstallsNodeDependencies(stepBlocks) {
|
|
2631
3018
|
return stepBlocks.some((block) => /uses:\s*actions\/setup-node@/m.test(block) ||
|
|
2632
|
-
/\b(?:pnpm\s+(?:install|i)|npm\s+(?:ci|install)|yarn\s+install|bun\s+install)\b/
|
|
3019
|
+
/\b(?:deno\s+install|pnpm\s+(?:install|i)|npm\s+(?:ci|install)|yarn\s+install|bun\s+install)\b/
|
|
2633
3020
|
.test(block));
|
|
2634
3021
|
}
|
|
2635
3022
|
function hasGithubPackagesSetupNodeConfig(stepBlocks) {
|
|
@@ -2752,14 +3139,14 @@ function githubWorkflowRunsOnMainPush(text) {
|
|
|
2752
3139
|
return !hasBranchFilter && !ignoresMain;
|
|
2753
3140
|
}
|
|
2754
3141
|
function workflowStepRunsDbMigrate(block) {
|
|
2755
|
-
return /\b(?:pnpm\s+(?:run\s+)?db:migrate|npm\s+run\s+db:migrate|yarn\s+(?:run\s+)?db:migrate|bun\s+run\s+db:migrate)\b/
|
|
3142
|
+
return /\b(?:deno\s+task\s+db:migrate|pnpm\s+(?:run\s+)?db:migrate|npm\s+run\s+db:migrate|yarn\s+(?:run\s+)?db:migrate|bun\s+run\s+db:migrate)\b/
|
|
2756
3143
|
.test(block) ||
|
|
2757
3144
|
/\bdrizzle-kit\s+migrate\b/.test(block) ||
|
|
2758
3145
|
/spawnSync\(\s*["']pnpm["'][\s\S]*["']db:migrate["']/.test(block);
|
|
2759
3146
|
}
|
|
2760
3147
|
function workflowStepUsesVercelCommand(block, subcommand) {
|
|
2761
3148
|
const launcher = String
|
|
2762
|
-
.raw `(?:vercel|pnpm\s+(?:dlx|exec)\s+vercel(?:@[^\s]+)?|npx\s+vercel(?:@[^\s]+)?|yarn\s+(?:dlx\s+)?vercel(?:@[^\s]+)?|bunx\s+vercel(?:@[^\s]+)?)`;
|
|
3149
|
+
.raw `(?:vercel|deno\s+run\s+-A\s+npm:vercel(?:@[^\s]+)?|pnpm\s+(?:dlx|exec)\s+vercel(?:@[^\s]+)?|npx\s+vercel(?:@[^\s]+)?|yarn\s+(?:dlx\s+)?vercel(?:@[^\s]+)?|bunx\s+vercel(?:@[^\s]+)?)`;
|
|
2763
3150
|
const globalFlags = String
|
|
2764
3151
|
.raw `(?:\s+(?:--[A-Za-z-]+(?:=(?:"[^"]+"|'[^']+'|[^\s]+)|\s+(?:"[^"]+"|'[^']+'|[^\s]+))?|-[A-Za-z](?:\s+(?:"[^"]+"|'[^']+'|[^\s]+))?))*`;
|
|
2765
3152
|
return new RegExp(String.raw `\b${launcher}${globalFlags}\s+${subcommand}\b`)
|
|
@@ -3721,10 +4108,13 @@ function dbScriptsTsconfigTemplate() {
|
|
|
3721
4108
|
}
|
|
3722
4109
|
`;
|
|
3723
4110
|
}
|
|
3724
|
-
function dbPgliteHarnessTemplate(config) {
|
|
4111
|
+
function dbPgliteHarnessTemplate(config, testRunner = "vitest") {
|
|
3725
4112
|
const schemaImportPath = toRelativeImportPath(config.modules.pgliteHarnessModule, join(config.dirs.schemaDir, "index.ts"));
|
|
4113
|
+
const afterAllImport = testRunner === "deno"
|
|
4114
|
+
? 'import { afterAll } from "jsr:@std/testing@^1.0.19/bdd";'
|
|
4115
|
+
: 'import { afterAll } from "vitest";';
|
|
3726
4116
|
return `import { createMemoryPgliteHarness } from "@gadicc/loom/db/testing";
|
|
3727
|
-
|
|
4117
|
+
${afterAllImport}
|
|
3728
4118
|
import * as schema from "${schemaImportPath}";
|
|
3729
4119
|
|
|
3730
4120
|
const harness = await createMemoryPgliteHarness({
|
|
@@ -3745,6 +4135,14 @@ afterAll(closeMemoryPglite);
|
|
|
3745
4135
|
export const { client, db, tableLoader } = harness;
|
|
3746
4136
|
`;
|
|
3747
4137
|
}
|
|
4138
|
+
async function getDbTestRunner(cwd, tooling) {
|
|
4139
|
+
if (tooling.tasks.runner !== "deno")
|
|
4140
|
+
return "vitest";
|
|
4141
|
+
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
4142
|
+
return /\bvitest\b/.test(getTaskCommand(taskStore.definitions.test) ?? "")
|
|
4143
|
+
? "vitest"
|
|
4144
|
+
: "deno";
|
|
4145
|
+
}
|
|
3748
4146
|
function dbFixturesScriptTemplate(config) {
|
|
3749
4147
|
const schemaImportPath = toRelativeImportPath(config.modules.fixtureDumpScript, join(config.dirs.schemaDir, "index.ts"));
|
|
3750
4148
|
const neonImportPath = toRelativeImportPath(config.modules.fixtureDumpScript, config.modules.neonModule);
|
|
@@ -4059,34 +4457,588 @@ export const { GET, POST } = createFilesRouteHandlers({
|
|
|
4059
4457
|
});
|
|
4060
4458
|
`;
|
|
4061
4459
|
}
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
.filter((entry) => entry.isFile() && entry.name.endsWith(".ts"))
|
|
4067
|
-
.map((entry) => entry.name.replace(/\.ts$/, ""))
|
|
4068
|
-
.filter((name) => name !== "index" && !name.startsWith("_"))
|
|
4069
|
-
.sort();
|
|
4070
|
-
}
|
|
4071
|
-
catch (error) {
|
|
4072
|
-
if (isNodeErrorCode(error, "ENOENT")) {
|
|
4073
|
-
return [];
|
|
4074
|
-
}
|
|
4075
|
-
throw error;
|
|
4076
|
-
}
|
|
4460
|
+
function mailAccessTemplate() {
|
|
4461
|
+
return `// Generated deny-all boundary. Replace with the app's fresh admin check.
|
|
4462
|
+
export async function authorizeMailAdmin(): Promise<void> {
|
|
4463
|
+
throw new Error("Mail admin access policy is not configured.");
|
|
4077
4464
|
}
|
|
4078
|
-
|
|
4079
|
-
const refinementSet = new Set(refinementNames);
|
|
4080
|
-
const names = [...new Set([...generatedNames, ...refinementNames])].sort();
|
|
4081
|
-
if (!names.length) {
|
|
4082
|
-
return null;
|
|
4083
|
-
}
|
|
4084
|
-
return `${names.map((name) => refinementSet.has(name)
|
|
4085
|
-
? `export * from "./refinements/${name}";`
|
|
4086
|
-
: `export * from "./generated/${name}";`).join("\n")}\n`;
|
|
4465
|
+
`;
|
|
4087
4466
|
}
|
|
4088
|
-
|
|
4089
|
-
|
|
4467
|
+
function mailTransportTemplate() {
|
|
4468
|
+
return `import type { LoomMailTransport } from "@gadicc/loom/mail";
|
|
4469
|
+
import {
|
|
4470
|
+
createPostalMailTransport,
|
|
4471
|
+
type PostalWebhookPublicKey,
|
|
4472
|
+
} from "@gadicc/loom/mail/postal";
|
|
4473
|
+
|
|
4474
|
+
function requireEnv(name: "POSTAL_API_KEY" | "POSTAL_FROM_EMAIL" | "POSTAL_HOST") {
|
|
4475
|
+
const value = process.env[name]?.trim();
|
|
4476
|
+
if (!value) throw new Error(\`\${name} is not set.\`);
|
|
4477
|
+
return value;
|
|
4478
|
+
}
|
|
4479
|
+
|
|
4480
|
+
export const mailTransport: LoomMailTransport = {
|
|
4481
|
+
provider: "postal",
|
|
4482
|
+
send(message) {
|
|
4483
|
+
return createPostalMailTransport({
|
|
4484
|
+
apiKey: requireEnv("POSTAL_API_KEY"),
|
|
4485
|
+
host: requireEnv("POSTAL_HOST"),
|
|
4486
|
+
}).send(message);
|
|
4487
|
+
},
|
|
4488
|
+
};
|
|
4489
|
+
|
|
4490
|
+
export function getDefaultMailFromEmail() {
|
|
4491
|
+
return requireEnv("POSTAL_FROM_EMAIL");
|
|
4492
|
+
}
|
|
4493
|
+
|
|
4494
|
+
export function getPostalWebhookPublicKeys(): PostalWebhookPublicKey[] {
|
|
4495
|
+
const raw = process.env.POSTAL_WEBHOOK_PUBLIC_KEYS?.trim();
|
|
4496
|
+
if (!raw) throw new Error("POSTAL_WEBHOOK_PUBLIC_KEYS is not set.");
|
|
4497
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
4498
|
+
if (!Array.isArray(parsed)) {
|
|
4499
|
+
throw new Error("POSTAL_WEBHOOK_PUBLIC_KEYS must be a JSON array of public JWKs.");
|
|
4500
|
+
}
|
|
4501
|
+
return parsed.map((candidate) => {
|
|
4502
|
+
if (
|
|
4503
|
+
typeof candidate !== "object" || candidate === null ||
|
|
4504
|
+
!("kid" in candidate) || typeof candidate.kid !== "string" ||
|
|
4505
|
+
!("kty" in candidate) || candidate.kty !== "RSA"
|
|
4506
|
+
) {
|
|
4507
|
+
throw new Error("Every Postal webhook key must be an RSA JWK with a kid.");
|
|
4508
|
+
}
|
|
4509
|
+
return candidate as PostalWebhookPublicKey;
|
|
4510
|
+
});
|
|
4511
|
+
}
|
|
4512
|
+
`;
|
|
4513
|
+
}
|
|
4514
|
+
function mailServiceTemplate(config) {
|
|
4515
|
+
return `import { createLoomMailService } from "@gadicc/loom/mail";
|
|
4516
|
+
import { mailRepository } from "${toAliasImportPath(config.modules.repositoryModule)}";
|
|
4517
|
+
import {
|
|
4518
|
+
getDefaultMailFromEmail,
|
|
4519
|
+
mailTransport,
|
|
4520
|
+
} from "${toAliasImportPath(config.modules.transportModule)}";
|
|
4521
|
+
|
|
4522
|
+
export const mailService = createLoomMailService({
|
|
4523
|
+
get defaultFromEmail() {
|
|
4524
|
+
return getDefaultMailFromEmail();
|
|
4525
|
+
},
|
|
4526
|
+
repository: mailRepository,
|
|
4527
|
+
transport: mailTransport,
|
|
4528
|
+
});
|
|
4529
|
+
`;
|
|
4530
|
+
}
|
|
4531
|
+
function mailRepositoryTemplate(config, dbConfig) {
|
|
4532
|
+
const [messages, deliveries, events] = [
|
|
4533
|
+
config.schema.exports[0] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[0],
|
|
4534
|
+
config.schema.exports[1] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[1],
|
|
4535
|
+
config.schema.exports[2] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[2],
|
|
4536
|
+
];
|
|
4537
|
+
return `import { and, asc, desc, eq, lte, or } from "drizzle-orm";
|
|
4538
|
+
import type {
|
|
4539
|
+
LoomMailDeliveryRecord,
|
|
4540
|
+
LoomMailDeliveryStatus,
|
|
4541
|
+
LoomMailMessageRecord,
|
|
4542
|
+
LoomMailRepository,
|
|
4543
|
+
} from "@gadicc/loom/mail";
|
|
4544
|
+
import { db } from "${toAliasImportPath(dbConfig.modules.neonFullModule)}";
|
|
4545
|
+
import {
|
|
4546
|
+
${deliveries},
|
|
4547
|
+
${events},
|
|
4548
|
+
${messages},
|
|
4549
|
+
} from "${toAliasImportPath(config.schema.module)}";
|
|
4550
|
+
|
|
4551
|
+
type MessageRow = typeof ${messages}.$inferSelect;
|
|
4552
|
+
type MessageInsert = typeof ${messages}.$inferInsert;
|
|
4553
|
+
type DeliveryRow = typeof ${deliveries}.$inferSelect;
|
|
4554
|
+
|
|
4555
|
+
function toMessage(row: MessageRow): LoomMailMessageRecord {
|
|
4556
|
+
return row as LoomMailMessageRecord;
|
|
4557
|
+
}
|
|
4558
|
+
|
|
4559
|
+
function toDelivery(row: DeliveryRow): LoomMailDeliveryRecord {
|
|
4560
|
+
return row as LoomMailDeliveryRecord;
|
|
4561
|
+
}
|
|
4562
|
+
|
|
4563
|
+
function aggregateStatus(statuses: LoomMailDeliveryStatus[]) {
|
|
4564
|
+
if (statuses.length === 0) return "sent" as const;
|
|
4565
|
+
if (statuses.every((status) => status === "delivered")) return "delivered" as const;
|
|
4566
|
+
const terminal = new Set<LoomMailDeliveryStatus>([
|
|
4567
|
+
"bounced", "cancelled", "delivered", "failed",
|
|
4568
|
+
]);
|
|
4569
|
+
if (statuses.every((status) => terminal.has(status))) {
|
|
4570
|
+
return statuses.includes("delivered") ? "partially_delivered" as const : "failed" as const;
|
|
4571
|
+
}
|
|
4572
|
+
return "sent" as const;
|
|
4573
|
+
}
|
|
4574
|
+
|
|
4575
|
+
export const mailRepository = {
|
|
4576
|
+
async cancel(messageId, occurredAt) {
|
|
4577
|
+
return db.transaction(async (trx) => {
|
|
4578
|
+
const [current] = await trx.select().from(${messages})
|
|
4579
|
+
.where(eq(${messages}.id, messageId)).limit(1).for("update");
|
|
4580
|
+
if (!current || !["queued", "failed"].includes(current.status)) return false;
|
|
4581
|
+
await trx.update(${messages}).set({
|
|
4582
|
+
cancelledAt: occurredAt,
|
|
4583
|
+
leaseExpiresAt: null,
|
|
4584
|
+
leaseToken: null,
|
|
4585
|
+
status: "cancelled",
|
|
4586
|
+
updatedAt: occurredAt,
|
|
4587
|
+
}).where(eq(${messages}.id, messageId));
|
|
4588
|
+
await trx.update(${deliveries}).set({ status: "cancelled", updatedAt: occurredAt })
|
|
4589
|
+
.where(and(eq(${deliveries}.messageId, messageId), eq(${deliveries}.status, "queued")));
|
|
4590
|
+
await trx.insert(${events}).values({
|
|
4591
|
+
eventType: "cancelled",
|
|
4592
|
+
messageId,
|
|
4593
|
+
payload: {},
|
|
4594
|
+
provider: current.provider,
|
|
4595
|
+
sourceEvent: "cancelled",
|
|
4596
|
+
occurredAt,
|
|
4597
|
+
});
|
|
4598
|
+
return true;
|
|
4599
|
+
});
|
|
4600
|
+
},
|
|
4601
|
+
|
|
4602
|
+
async claim(request) {
|
|
4603
|
+
return db.transaction(async (trx) => {
|
|
4604
|
+
const due = or(
|
|
4605
|
+
eq(${messages}.status, "queued"),
|
|
4606
|
+
and(eq(${messages}.status, "sending"), lte(${messages}.leaseExpiresAt, request.now)),
|
|
4607
|
+
);
|
|
4608
|
+
const [current] = await trx.select().from(${messages})
|
|
4609
|
+
.where(and(
|
|
4610
|
+
request.messageId ? eq(${messages}.id, request.messageId) : undefined,
|
|
4611
|
+
lte(${messages}.availableAt, request.now),
|
|
4612
|
+
due,
|
|
4613
|
+
))
|
|
4614
|
+
.orderBy(asc(${messages}.availableAt), asc(${messages}.createdAt))
|
|
4615
|
+
.limit(1)
|
|
4616
|
+
.for("update", { skipLocked: true });
|
|
4617
|
+
if (!current) return null;
|
|
4618
|
+
const [claimed] = await trx.update(${messages}).set({
|
|
4619
|
+
attemptCount: current.attemptCount + 1,
|
|
4620
|
+
leaseExpiresAt: request.leaseExpiresAt,
|
|
4621
|
+
leaseToken: request.leaseToken,
|
|
4622
|
+
status: "sending",
|
|
4623
|
+
updatedAt: request.now,
|
|
4624
|
+
}).where(eq(${messages}.id, current.id)).returning();
|
|
4625
|
+
if (!claimed) return null;
|
|
4626
|
+
await trx.insert(${events}).values({
|
|
4627
|
+
eventType: "attempted",
|
|
4628
|
+
messageId: current.id,
|
|
4629
|
+
payload: {
|
|
4630
|
+
attemptCount: claimed.attemptCount,
|
|
4631
|
+
leaseExpiresAt: request.leaseExpiresAt.toISOString(),
|
|
4632
|
+
},
|
|
4633
|
+
provider: current.provider,
|
|
4634
|
+
sourceEvent: "attempted",
|
|
4635
|
+
occurredAt: request.now,
|
|
4636
|
+
});
|
|
4637
|
+
return toMessage(claimed) as ReturnType<typeof toMessage> & {
|
|
4638
|
+
leaseExpiresAt: Date;
|
|
4639
|
+
leaseToken: string;
|
|
4640
|
+
status: "sending";
|
|
4641
|
+
};
|
|
4642
|
+
});
|
|
4643
|
+
},
|
|
4644
|
+
|
|
4645
|
+
async completeFailure(input) {
|
|
4646
|
+
return db.transaction(async (trx) => {
|
|
4647
|
+
const [updated] = await trx.update(${messages}).set({
|
|
4648
|
+
availableAt: input.retryAt ?? input.occurredAt,
|
|
4649
|
+
failedAt: input.retryAt ? null : input.occurredAt,
|
|
4650
|
+
lastErrorCode: input.failure.code,
|
|
4651
|
+
lastErrorMessage: input.failure.message,
|
|
4652
|
+
leaseExpiresAt: null,
|
|
4653
|
+
leaseToken: null,
|
|
4654
|
+
status: input.retryAt ? "queued" : "failed",
|
|
4655
|
+
updatedAt: input.occurredAt,
|
|
4656
|
+
}).where(and(
|
|
4657
|
+
eq(${messages}.id, input.messageId),
|
|
4658
|
+
eq(${messages}.status, "sending"),
|
|
4659
|
+
eq(${messages}.leaseToken, input.leaseToken),
|
|
4660
|
+
)).returning({ provider: ${messages}.provider });
|
|
4661
|
+
if (!updated) return false;
|
|
4662
|
+
await trx.insert(${events}).values({
|
|
4663
|
+
eventType: input.retryAt ? "retry_scheduled" : "failed",
|
|
4664
|
+
messageId: input.messageId,
|
|
4665
|
+
payload: {
|
|
4666
|
+
code: input.failure.code,
|
|
4667
|
+
message: input.failure.message,
|
|
4668
|
+
retryAt: input.retryAt?.toISOString() ?? null,
|
|
4669
|
+
retryable: input.failure.retryable,
|
|
4670
|
+
...input.failure.payload,
|
|
4671
|
+
},
|
|
4672
|
+
provider: updated.provider,
|
|
4673
|
+
sourceEvent: input.retryAt ? "retry_scheduled" : "failed",
|
|
4674
|
+
occurredAt: input.occurredAt,
|
|
4675
|
+
});
|
|
4676
|
+
return true;
|
|
4677
|
+
});
|
|
4678
|
+
},
|
|
4679
|
+
|
|
4680
|
+
async completeSuccess(input) {
|
|
4681
|
+
return db.transaction(async (trx) => {
|
|
4682
|
+
const [updated] = await trx.update(${messages}).set({
|
|
4683
|
+
lastErrorCode: null,
|
|
4684
|
+
lastErrorMessage: null,
|
|
4685
|
+
leaseExpiresAt: null,
|
|
4686
|
+
leaseToken: null,
|
|
4687
|
+
providerMessageId: input.result.providerMessageId,
|
|
4688
|
+
sentAt: input.occurredAt,
|
|
4689
|
+
status: "sent",
|
|
4690
|
+
updatedAt: input.occurredAt,
|
|
4691
|
+
}).where(and(
|
|
4692
|
+
eq(${messages}.id, input.messageId),
|
|
4693
|
+
eq(${messages}.status, "sending"),
|
|
4694
|
+
eq(${messages}.leaseToken, input.leaseToken),
|
|
4695
|
+
)).returning({ provider: ${messages}.provider });
|
|
4696
|
+
if (!updated) return false;
|
|
4697
|
+
for (const result of input.result.deliveries) {
|
|
4698
|
+
await trx.update(${deliveries}).set({
|
|
4699
|
+
providerDeliveryId: result.providerDeliveryId,
|
|
4700
|
+
providerToken: result.providerToken,
|
|
4701
|
+
status: "accepted",
|
|
4702
|
+
updatedAt: input.occurredAt,
|
|
4703
|
+
}).where(and(
|
|
4704
|
+
eq(${deliveries}.messageId, input.messageId),
|
|
4705
|
+
eq(${deliveries}.email, result.email),
|
|
4706
|
+
eq(${deliveries}.status, "queued"),
|
|
4707
|
+
));
|
|
4708
|
+
}
|
|
4709
|
+
await trx.insert(${events}).values({
|
|
4710
|
+
eventType: "sent",
|
|
4711
|
+
messageId: input.messageId,
|
|
4712
|
+
payload: {
|
|
4713
|
+
providerMessageId: input.result.providerMessageId,
|
|
4714
|
+
providerResponse: input.result.providerResponse ?? {},
|
|
4715
|
+
},
|
|
4716
|
+
provider: updated.provider,
|
|
4717
|
+
sourceEvent: "sent",
|
|
4718
|
+
occurredAt: input.occurredAt,
|
|
4719
|
+
});
|
|
4720
|
+
return true;
|
|
4721
|
+
});
|
|
4722
|
+
},
|
|
4723
|
+
|
|
4724
|
+
async enqueue(input, occurredAt) {
|
|
4725
|
+
return db.transaction(async (trx) => {
|
|
4726
|
+
const [message] = await trx.insert(${messages}).values({
|
|
4727
|
+
...input,
|
|
4728
|
+
availableAt: occurredAt,
|
|
4729
|
+
createdAt: occurredAt,
|
|
4730
|
+
updatedAt: occurredAt,
|
|
4731
|
+
} as MessageInsert).returning();
|
|
4732
|
+
if (!message) throw new Error("Failed to enqueue mail.");
|
|
4733
|
+
const recipients = [
|
|
4734
|
+
...input.to.map((email) => ({ email, kind: "to" })),
|
|
4735
|
+
...input.cc.map((email) => ({ email, kind: "cc" })),
|
|
4736
|
+
...input.bcc.map((email) => ({ email, kind: "bcc" })),
|
|
4737
|
+
];
|
|
4738
|
+
await trx.insert(${deliveries}).values(recipients.map((recipient) => ({
|
|
4739
|
+
...recipient,
|
|
4740
|
+
messageId: message.id,
|
|
4741
|
+
createdAt: occurredAt,
|
|
4742
|
+
updatedAt: occurredAt,
|
|
4743
|
+
})));
|
|
4744
|
+
await trx.insert(${events}).values({
|
|
4745
|
+
eventType: "queued",
|
|
4746
|
+
messageId: message.id,
|
|
4747
|
+
payload: { bcc: input.bcc, cc: input.cc, to: input.to },
|
|
4748
|
+
provider: input.provider,
|
|
4749
|
+
sourceEvent: "queued",
|
|
4750
|
+
occurredAt,
|
|
4751
|
+
});
|
|
4752
|
+
return toMessage(message);
|
|
4753
|
+
});
|
|
4754
|
+
},
|
|
4755
|
+
|
|
4756
|
+
async findById(messageId) {
|
|
4757
|
+
const [row] = await db.select().from(${messages})
|
|
4758
|
+
.where(eq(${messages}.id, messageId)).limit(1);
|
|
4759
|
+
return row ? toMessage(row) : null;
|
|
4760
|
+
},
|
|
4761
|
+
|
|
4762
|
+
async listDeliveries(messageId: string) {
|
|
4763
|
+
const rows = await db.select().from(${deliveries})
|
|
4764
|
+
.where(eq(${deliveries}.messageId, messageId));
|
|
4765
|
+
return rows.map(toDelivery);
|
|
4766
|
+
},
|
|
4767
|
+
|
|
4768
|
+
async listRecent(limit = 100) {
|
|
4769
|
+
const rows = await db.select().from(${messages})
|
|
4770
|
+
.orderBy(desc(${messages}.createdAt)).limit(limit);
|
|
4771
|
+
return rows.map(toMessage);
|
|
4772
|
+
},
|
|
4773
|
+
|
|
4774
|
+
async recordProviderEvent(event) {
|
|
4775
|
+
return db.transaction(async (trx) => {
|
|
4776
|
+
let [delivery] = event.providerDeliveryId
|
|
4777
|
+
? await trx.select().from(${deliveries})
|
|
4778
|
+
.where(eq(${deliveries}.providerDeliveryId, event.providerDeliveryId)).limit(1)
|
|
4779
|
+
: [];
|
|
4780
|
+
let [message] = delivery
|
|
4781
|
+
? await trx.select().from(${messages})
|
|
4782
|
+
.where(eq(${messages}.id, delivery.messageId)).limit(1)
|
|
4783
|
+
: event.providerMessageId
|
|
4784
|
+
? await trx.select().from(${messages})
|
|
4785
|
+
.where(and(
|
|
4786
|
+
eq(${messages}.provider, event.provider),
|
|
4787
|
+
eq(${messages}.providerMessageId, event.providerMessageId),
|
|
4788
|
+
)).limit(1)
|
|
4789
|
+
: [];
|
|
4790
|
+
if (message && message.provider !== event.provider) {
|
|
4791
|
+
return { inserted: false, messageId: null };
|
|
4792
|
+
}
|
|
4793
|
+
if (!message) return { inserted: false, messageId: null };
|
|
4794
|
+
if (!delivery && event.recipient) {
|
|
4795
|
+
[delivery] = await trx.select().from(${deliveries}).where(and(
|
|
4796
|
+
eq(${deliveries}.messageId, message.id),
|
|
4797
|
+
eq(${deliveries}.email, event.recipient),
|
|
4798
|
+
)).limit(1);
|
|
4799
|
+
}
|
|
4800
|
+
const [inserted] = await trx.insert(${events}).values({
|
|
4801
|
+
deliveryId: delivery?.id ?? null,
|
|
4802
|
+
eventType: event.eventType,
|
|
4803
|
+
messageId: message.id,
|
|
4804
|
+
occurredAt: event.occurredAt,
|
|
4805
|
+
payload: event.payload,
|
|
4806
|
+
provider: event.provider,
|
|
4807
|
+
providerEventId: event.providerEventId,
|
|
4808
|
+
sourceEvent: event.sourceEvent,
|
|
4809
|
+
}).onConflictDoNothing().returning({ id: ${events}.id });
|
|
4810
|
+
if (!inserted) return { inserted: false, messageId: message.id };
|
|
4811
|
+
|
|
4812
|
+
if (delivery && event.eventType !== "unknown") {
|
|
4813
|
+
const nextStatus = event.eventType;
|
|
4814
|
+
await trx.update(${deliveries}).set({
|
|
4815
|
+
deliveredAt: nextStatus === "delivered" ? event.occurredAt : delivery.deliveredAt,
|
|
4816
|
+
lastErrorCode: ["bounced", "failed", "held"].includes(nextStatus)
|
|
4817
|
+
? event.sourceEvent : delivery.lastErrorCode,
|
|
4818
|
+
lastErrorMessage: ["bounced", "failed", "held"].includes(nextStatus)
|
|
4819
|
+
? String(event.payload.message ?? event.sourceEvent) : delivery.lastErrorMessage,
|
|
4820
|
+
status: nextStatus,
|
|
4821
|
+
updatedAt: event.occurredAt,
|
|
4822
|
+
}).where(eq(${deliveries}.id, delivery.id));
|
|
4823
|
+
}
|
|
4824
|
+
const statusRows = await trx.select({ status: ${deliveries}.status })
|
|
4825
|
+
.from(${deliveries}).where(eq(${deliveries}.messageId, message.id));
|
|
4826
|
+
const status = aggregateStatus(
|
|
4827
|
+
statusRows.map((row) => row.status as LoomMailDeliveryStatus),
|
|
4828
|
+
);
|
|
4829
|
+
await trx.update(${messages}).set({
|
|
4830
|
+
deliveredAt: status === "delivered" ? event.occurredAt : message.deliveredAt,
|
|
4831
|
+
failedAt: status === "failed" ? event.occurredAt : message.failedAt,
|
|
4832
|
+
status,
|
|
4833
|
+
updatedAt: event.occurredAt,
|
|
4834
|
+
}).where(eq(${messages}.id, message.id));
|
|
4835
|
+
return { inserted: true, messageId: message.id };
|
|
4836
|
+
});
|
|
4837
|
+
},
|
|
4838
|
+
} satisfies LoomMailRepository & {
|
|
4839
|
+
listDeliveries(messageId: string): Promise<LoomMailDeliveryRecord[]>;
|
|
4840
|
+
listRecent(limit?: number): Promise<LoomMailMessageRecord[]>;
|
|
4841
|
+
};
|
|
4842
|
+
`;
|
|
4843
|
+
}
|
|
4844
|
+
function mailActionsTemplate(config) {
|
|
4845
|
+
const adminPath = config.entrypoints.adminPage
|
|
4846
|
+
.replace(/^src\/app|^app/, "")
|
|
4847
|
+
.replace(/\/page\.tsx$/, "") || "/";
|
|
4848
|
+
return `"use server";
|
|
4849
|
+
|
|
4850
|
+
import { LoomMailDeliveryError } from "@gadicc/loom/mail";
|
|
4851
|
+
import { revalidatePath } from "next/cache";
|
|
4852
|
+
import { authorizeMailAdmin } from "${toAliasImportPath(config.modules.accessModule)}";
|
|
4853
|
+
import { mailRepository } from "${toAliasImportPath(config.modules.repositoryModule)}";
|
|
4854
|
+
import { mailService } from "${toAliasImportPath(config.modules.serviceModule)}";
|
|
4855
|
+
|
|
4856
|
+
export interface MailTestActionState {
|
|
4857
|
+
message: string | null;
|
|
4858
|
+
messageId?: string;
|
|
4859
|
+
status: "error" | "idle" | "success";
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
function text(formData: FormData, key: string) {
|
|
4863
|
+
const value = formData.get(key);
|
|
4864
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
function recipients(value?: string) {
|
|
4868
|
+
return (value ?? "").split(/[,\\n]+/).map((item) => item.trim()).filter(Boolean);
|
|
4869
|
+
}
|
|
4870
|
+
|
|
4871
|
+
export async function sendTestMail(
|
|
4872
|
+
_previous: MailTestActionState,
|
|
4873
|
+
formData: FormData,
|
|
4874
|
+
): Promise<MailTestActionState> {
|
|
4875
|
+
await authorizeMailAdmin();
|
|
4876
|
+
try {
|
|
4877
|
+
const result = await mailService.sendMail({
|
|
4878
|
+
bcc: recipients(text(formData, "bcc")),
|
|
4879
|
+
cc: recipients(text(formData, "cc")),
|
|
4880
|
+
htmlBody: text(formData, "htmlBody"),
|
|
4881
|
+
metadata: { sentFromMailAdmin: true },
|
|
4882
|
+
plainBody: text(formData, "plainBody"),
|
|
4883
|
+
replyTo: text(formData, "replyTo"),
|
|
4884
|
+
subject: text(formData, "subject") ?? "",
|
|
4885
|
+
tag: text(formData, "tag"),
|
|
4886
|
+
to: recipients(text(formData, "to")),
|
|
4887
|
+
});
|
|
4888
|
+
revalidatePath("${adminPath}");
|
|
4889
|
+
return {
|
|
4890
|
+
message: "Test email accepted by the provider.",
|
|
4891
|
+
messageId: result.message.id,
|
|
4892
|
+
status: "success",
|
|
4893
|
+
};
|
|
4894
|
+
} catch (error) {
|
|
4895
|
+
return {
|
|
4896
|
+
message: error instanceof Error ? error.message : "Mail send failed.",
|
|
4897
|
+
messageId: error instanceof LoomMailDeliveryError ? error.messageId : undefined,
|
|
4898
|
+
status: "error",
|
|
4899
|
+
};
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4902
|
+
|
|
4903
|
+
function requiredMessageId(formData: FormData) {
|
|
4904
|
+
const messageId = text(formData, "messageId");
|
|
4905
|
+
if (!messageId) throw new Error("Missing mail message id.");
|
|
4906
|
+
return messageId;
|
|
4907
|
+
}
|
|
4908
|
+
|
|
4909
|
+
export async function cancelMail(formData: FormData) {
|
|
4910
|
+
await authorizeMailAdmin();
|
|
4911
|
+
if (!await mailService.cancelMail(requiredMessageId(formData))) {
|
|
4912
|
+
throw new Error("Mail message cannot be cancelled in its current state.");
|
|
4913
|
+
}
|
|
4914
|
+
revalidatePath("${adminPath}");
|
|
4915
|
+
}
|
|
4916
|
+
|
|
4917
|
+
export async function retryMail(formData: FormData) {
|
|
4918
|
+
await authorizeMailAdmin();
|
|
4919
|
+
const sourceId = requiredMessageId(formData);
|
|
4920
|
+
const source = await mailRepository.findById(sourceId);
|
|
4921
|
+
if (!source) throw new Error("Mail message not found.");
|
|
4922
|
+
await mailService.sendMail({
|
|
4923
|
+
attachments: source.attachments,
|
|
4924
|
+
bcc: source.bcc,
|
|
4925
|
+
cc: source.cc,
|
|
4926
|
+
fromEmail: source.fromEmail,
|
|
4927
|
+
fromName: source.fromName ?? undefined,
|
|
4928
|
+
headers: source.headers,
|
|
4929
|
+
htmlBody: source.htmlBody ?? undefined,
|
|
4930
|
+
metadata: { ...source.metadata, retriedFromMessageId: source.id },
|
|
4931
|
+
plainBody: source.plainBody ?? undefined,
|
|
4932
|
+
replyTo: source.replyTo ?? undefined,
|
|
4933
|
+
subject: source.subject,
|
|
4934
|
+
tag: source.tag ?? undefined,
|
|
4935
|
+
to: source.to,
|
|
4936
|
+
});
|
|
4937
|
+
revalidatePath("${adminPath}");
|
|
4938
|
+
}
|
|
4939
|
+
`;
|
|
4940
|
+
}
|
|
4941
|
+
function mailAdminPageTemplate(config) {
|
|
4942
|
+
if (config.ui.adapter !== "mui") {
|
|
4943
|
+
return `import { authorizeMailAdmin } from "${toAliasImportPath(config.modules.accessModule)}";
|
|
4944
|
+
|
|
4945
|
+
export default async function MailAdminPage() {
|
|
4946
|
+
await authorizeMailAdmin();
|
|
4947
|
+
return <main><h1>Mail</h1><p>Connect an app-owned admin UI to the Loom mail service.</p></main>;
|
|
4948
|
+
}
|
|
4949
|
+
`;
|
|
4950
|
+
}
|
|
4951
|
+
return `import { AdminMailConsole, type MailAdminRow } from "@gadicc/loom/mui/mail";
|
|
4952
|
+
import { authorizeMailAdmin } from "${toAliasImportPath(config.modules.accessModule)}";
|
|
4953
|
+
import { cancelMail, retryMail, sendTestMail } from "${toAliasImportPath(config.modules.actionsModule)}";
|
|
4954
|
+
import { mailRepository } from "${toAliasImportPath(config.modules.repositoryModule)}";
|
|
4955
|
+
|
|
4956
|
+
export default async function MailAdminPage() {
|
|
4957
|
+
await authorizeMailAdmin();
|
|
4958
|
+
const messages = await mailRepository.listRecent(100);
|
|
4959
|
+
const deliveries = await Promise.all(
|
|
4960
|
+
messages.map((message) => mailRepository.listDeliveries(message.id)),
|
|
4961
|
+
);
|
|
4962
|
+
const rows: MailAdminRow[] = messages.map((message, index) => ({
|
|
4963
|
+
createdAt: message.createdAt.toISOString(),
|
|
4964
|
+
id: message.id,
|
|
4965
|
+
providerMessageId: message.providerMessageId,
|
|
4966
|
+
recipients: (deliveries[index] ?? []).map((delivery) => ({
|
|
4967
|
+
email: delivery.email,
|
|
4968
|
+
kind: delivery.kind,
|
|
4969
|
+
status: delivery.status,
|
|
4970
|
+
})),
|
|
4971
|
+
status: message.status,
|
|
4972
|
+
subject: message.subject,
|
|
4973
|
+
tag: message.tag,
|
|
4974
|
+
}));
|
|
4975
|
+
return (
|
|
4976
|
+
<AdminMailConsole
|
|
4977
|
+
cancelAction={cancelMail}
|
|
4978
|
+
retryAction={retryMail}
|
|
4979
|
+
rows={rows}
|
|
4980
|
+
testAction={sendTestMail}
|
|
4981
|
+
/>
|
|
4982
|
+
);
|
|
4983
|
+
}
|
|
4984
|
+
`;
|
|
4985
|
+
}
|
|
4986
|
+
function mailWebhookRouteTemplate(config) {
|
|
4987
|
+
return `import { createPostalWebhookRouteHandler } from "@gadicc/loom/next/mail";
|
|
4988
|
+
import { mailService } from "${toAliasImportPath(config.modules.serviceModule)}";
|
|
4989
|
+
import { getPostalWebhookPublicKeys } from "${toAliasImportPath(config.modules.transportModule)}";
|
|
4990
|
+
|
|
4991
|
+
export const POST = createPostalWebhookRouteHandler({
|
|
4992
|
+
handleEvent: (event) => mailService.handleProviderEvent(event),
|
|
4993
|
+
publicKeys: getPostalWebhookPublicKeys,
|
|
4994
|
+
});
|
|
4995
|
+
`;
|
|
4996
|
+
}
|
|
4997
|
+
function mailJobTemplate(config) {
|
|
4998
|
+
return `import type { Job } from "@gadicc/loom/jobs";
|
|
4999
|
+
import { mailService } from "${toAliasImportPath(config.modules.serviceModule)}";
|
|
5000
|
+
|
|
5001
|
+
export const meta = {
|
|
5002
|
+
id: "mail-drain",
|
|
5003
|
+
desc: "Deliver due messages from the durable mail outbox.",
|
|
5004
|
+
};
|
|
5005
|
+
|
|
5006
|
+
export const handler: Job["handler"] = async (job, params) => {
|
|
5007
|
+
const parsed = typeof params.limit === "string" ? Number(params.limit) : Number.NaN;
|
|
5008
|
+
const limit = Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 20;
|
|
5009
|
+
const result = await mailService.drain(limit);
|
|
5010
|
+
job.json({ result });
|
|
5011
|
+
};
|
|
5012
|
+
`;
|
|
5013
|
+
}
|
|
5014
|
+
async function readTsModuleNames(path) {
|
|
5015
|
+
try {
|
|
5016
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
5017
|
+
return entries
|
|
5018
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".ts"))
|
|
5019
|
+
.map((entry) => entry.name.replace(/\.ts$/, ""))
|
|
5020
|
+
.filter((name) => name !== "index" && !name.startsWith("_"))
|
|
5021
|
+
.sort();
|
|
5022
|
+
}
|
|
5023
|
+
catch (error) {
|
|
5024
|
+
if (isNodeErrorCode(error, "ENOENT")) {
|
|
5025
|
+
return [];
|
|
5026
|
+
}
|
|
5027
|
+
throw error;
|
|
5028
|
+
}
|
|
5029
|
+
}
|
|
5030
|
+
function buildValibotBarrelText(generatedNames, refinementNames) {
|
|
5031
|
+
const refinementSet = new Set(refinementNames);
|
|
5032
|
+
const names = [...new Set([...generatedNames, ...refinementNames])].sort();
|
|
5033
|
+
if (!names.length) {
|
|
5034
|
+
return null;
|
|
5035
|
+
}
|
|
5036
|
+
return `${names.map((name) => refinementSet.has(name)
|
|
5037
|
+
? `export * from "./refinements/${name}";`
|
|
5038
|
+
: `export * from "./generated/${name}";`).join("\n")}\n`;
|
|
5039
|
+
}
|
|
5040
|
+
async function syncValibotBarrel(cwd, config) {
|
|
5041
|
+
const generatedNames = await readTsModuleNames(join(cwd, config.dirs.valibotGeneratedDir));
|
|
4090
5042
|
const refinementNames = await readTsModuleNames(join(cwd, config.dirs.valibotRefinementsDir));
|
|
4091
5043
|
const text = buildValibotBarrelText(generatedNames, refinementNames);
|
|
4092
5044
|
if (!text) {
|
|
@@ -4101,7 +5053,9 @@ function getLatestManagedSchemaConfig(schema) {
|
|
|
4101
5053
|
? schema.idGeneration === "uuid-v7"
|
|
4102
5054
|
? FILES_SCHEMA_UUID_V7_BLUEPRINT_VERSION
|
|
4103
5055
|
: FILES_SCHEMA_UUID_V4_BLUEPRINT_VERSION
|
|
4104
|
-
:
|
|
5056
|
+
: schema.blueprint === "mail"
|
|
5057
|
+
? MAIL_SCHEMA_BLUEPRINT_VERSION
|
|
5058
|
+
: API_KEY_AUDIT_SCHEMA_BLUEPRINT_VERSION,
|
|
4105
5059
|
};
|
|
4106
5060
|
return {
|
|
4107
5061
|
...latest,
|
|
@@ -4114,6 +5068,8 @@ function getManagedSchemaText(schema) {
|
|
|
4114
5068
|
return buildApiKeyAuditSchemaText(schema);
|
|
4115
5069
|
case "files":
|
|
4116
5070
|
return buildFilesSchemaText(schema);
|
|
5071
|
+
case "mail":
|
|
5072
|
+
return buildMailSchemaText(schema);
|
|
4117
5073
|
}
|
|
4118
5074
|
}
|
|
4119
5075
|
function getSchemaBarrelExportLine(schema, dbConfig) {
|
|
@@ -4225,14 +5181,11 @@ async function materializeManagedSchema(cwd, schema, dbConfig) {
|
|
|
4225
5181
|
};
|
|
4226
5182
|
}
|
|
4227
5183
|
async function readProjectPackageJson(cwd) {
|
|
4228
|
-
const
|
|
4229
|
-
const packageJsonText = await readTextIfExists(packageJsonPath);
|
|
4230
|
-
if (!packageJsonText) {
|
|
4231
|
-
throw new Error(`No package.json found in ${cwd}`);
|
|
4232
|
-
}
|
|
5184
|
+
const metadata = await readProjectPackageMetadata(cwd);
|
|
4233
5185
|
return {
|
|
4234
|
-
packageJson:
|
|
4235
|
-
packageJsonPath,
|
|
5186
|
+
packageJson: metadata.packageJson,
|
|
5187
|
+
packageJsonPath: metadata.path,
|
|
5188
|
+
projectConfig: metadata.config,
|
|
4236
5189
|
};
|
|
4237
5190
|
}
|
|
4238
5191
|
async function resolveDbProjectConfig(cwd) {
|
|
@@ -4295,8 +5248,25 @@ export async function syncDbSchemas(cwd) {
|
|
|
4295
5248
|
suggestions.add("Move API-key audit schema additions to separate local schema files, then rerun `loom db schemas sync`.");
|
|
4296
5249
|
}
|
|
4297
5250
|
}
|
|
5251
|
+
const mailFeature = manifest.features.mail;
|
|
5252
|
+
if (mailFeature?.status === "active") {
|
|
5253
|
+
const mailConfig = getMailConfig(framework, dbConfig, (await readProjectPackageJson(cwd)).packageJson, mailFeature.config, manifest.features.jobs?.status === "active");
|
|
5254
|
+
const materialized = await materializeManagedSchema(cwd, mailConfig.schema, dbConfig);
|
|
5255
|
+
changedFiles.push(...materialized.changedFiles);
|
|
5256
|
+
issues.push(...materialized.issues);
|
|
5257
|
+
notes.push(...materialized.notes);
|
|
5258
|
+
if (!materialized.issues.length) {
|
|
5259
|
+
mailConfig.schema = materialized.schema;
|
|
5260
|
+
mailFeature.config = mailConfig;
|
|
5261
|
+
manifest.features.mail = mailFeature;
|
|
5262
|
+
}
|
|
5263
|
+
else {
|
|
5264
|
+
suggestions.add("Move mail schema additions to separate local schema files, then rerun `loom db schemas sync`.");
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
4298
5267
|
if ((!filesFeature || filesFeature.status !== "active") &&
|
|
4299
|
-
(!apiKeysFeature || apiKeysFeature.status !== "active")
|
|
5268
|
+
(!apiKeysFeature || apiKeysFeature.status !== "active") &&
|
|
5269
|
+
(!mailFeature || mailFeature.status !== "active")) {
|
|
4300
5270
|
notes.push("No active Loom-managed DB schemas are configured.");
|
|
4301
5271
|
}
|
|
4302
5272
|
const manifestPath = join(cwd, "loom.json");
|
|
@@ -4304,7 +5274,8 @@ export async function syncDbSchemas(cwd) {
|
|
|
4304
5274
|
changedFiles.push("loom.json");
|
|
4305
5275
|
}
|
|
4306
5276
|
if (changedFiles.length) {
|
|
4307
|
-
|
|
5277
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
5278
|
+
notes.push(`No migrations were generated. Review the schema diff, then run ${formatTaskInvocation(tooling.tasks, "db:generate")} if the schema changed.`);
|
|
4308
5279
|
}
|
|
4309
5280
|
return {
|
|
4310
5281
|
changedFiles: [...new Set(changedFiles)],
|
|
@@ -4645,7 +5616,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
4645
5616
|
if (options.localProvider === "r2" && !options.localBucket) {
|
|
4646
5617
|
throw new Error("--local-provider r2 requires an explicit --local-bucket.");
|
|
4647
5618
|
}
|
|
4648
|
-
const { packageJson
|
|
5619
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
4649
5620
|
const framework = await detectFramework(cwd, packageJson);
|
|
4650
5621
|
const manifestPath = join(cwd, "loom.json");
|
|
4651
5622
|
const manifestText = await readTextIfExists(manifestPath);
|
|
@@ -4653,6 +5624,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
4653
5624
|
throw new Error("Missing loom.json. Run `loom add files` first.");
|
|
4654
5625
|
}
|
|
4655
5626
|
const manifest = parseJson(manifestText, "loom.json");
|
|
5627
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
4656
5628
|
const feature = manifest.features.files;
|
|
4657
5629
|
if (!feature || feature.status !== "active") {
|
|
4658
5630
|
throw new Error("The files feature is not active. Run `loom add files` first.");
|
|
@@ -4810,11 +5782,10 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
4810
5782
|
throw new Error(`R2 bucket \`${bucket}\` exists, but Loom could not verify its private-access policy: ${privacy.detail}. Rerun after Wrangler can inspect public URL and custom-domain settings.`);
|
|
4811
5783
|
}
|
|
4812
5784
|
}
|
|
4813
|
-
const dependencyUpdate =
|
|
5785
|
+
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, { dependencies: FILES_S3_DEPENDENCIES });
|
|
4814
5786
|
if (dependencyUpdate.changed) {
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
notes.push(`Added files storage dependency: ${dependencyUpdate.changedKeys.join(", ")}.`);
|
|
5787
|
+
changedFiles.push(dependencyUpdate.config);
|
|
5788
|
+
notes.push(`Added files storage dependency: ${dependencyUpdate.changedKeys.join(", ")} to ${dependencyUpdate.config}.`);
|
|
4818
5789
|
}
|
|
4819
5790
|
const storagePath = join(cwd, config.modules.storageModule);
|
|
4820
5791
|
const storageText = await readTextIfExists(storagePath);
|
|
@@ -6267,26 +7238,21 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
6267
7238
|
? structuredClone(currentFeature)
|
|
6268
7239
|
: { status: "planned" };
|
|
6269
7240
|
const config = mergeJobsConfig(framework, feature.config);
|
|
6270
|
-
const
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
if (
|
|
6279
|
-
scriptsUpdate.
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
}
|
|
6283
|
-
if (dependencyUpdate.changedKeys.length ||
|
|
6284
|
-
devDependencyUpdate.changedKeys.length) {
|
|
6285
|
-
notes.push(`Added jobs package.json dependencies: ${[...dependencyUpdate.changedKeys, ...devDependencyUpdate.changedKeys]
|
|
6286
|
-
.join(", ")}`);
|
|
7241
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7242
|
+
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
|
|
7243
|
+
dependencies: JOBS_DEFAULT_DEPENDENCIES,
|
|
7244
|
+
devDependencies: JOBS_DEFAULT_DEV_DEPENDENCIES,
|
|
7245
|
+
});
|
|
7246
|
+
const scriptsUpdate = await ensureProjectTasks(cwd, manifest, getJobsExpectedScripts(config));
|
|
7247
|
+
if (dependencyUpdate.changed)
|
|
7248
|
+
changedFiles.push(dependencyUpdate.config);
|
|
7249
|
+
if (scriptsUpdate.changedKeys.length)
|
|
7250
|
+
changedFiles.push(scriptsUpdate.config);
|
|
7251
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
7252
|
+
notes.push(`Added jobs dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
6287
7253
|
}
|
|
6288
7254
|
if (scriptsUpdate.changedKeys.length) {
|
|
6289
|
-
notes.push(`Updated jobs
|
|
7255
|
+
notes.push(`Updated jobs tasks in ${scriptsUpdate.config}: ${scriptsUpdate.changedKeys.join(", ")}`);
|
|
6290
7256
|
}
|
|
6291
7257
|
if (activate && feature.status !== "active") {
|
|
6292
7258
|
feature.status = "active";
|
|
@@ -6381,41 +7347,35 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
6381
7347
|
}
|
|
6382
7348
|
feature.config = config;
|
|
6383
7349
|
manifest.features.db = feature;
|
|
6384
|
-
const
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
const
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
packageJsonChanged ||= removedDependencyUpdate.changed;
|
|
6399
|
-
if (packageJsonChanged) {
|
|
6400
|
-
await writeFile(packageJsonPath, stringifyJson(nextPackageJson), "utf8");
|
|
6401
|
-
changedFiles.push("package.json");
|
|
6402
|
-
}
|
|
6403
|
-
if (dependencyUpdate.changedKeys.length ||
|
|
6404
|
-
devDependencyUpdate.changedKeys.length) {
|
|
6405
|
-
notes.push(`Added DB package.json dependencies: ${[...dependencyUpdate.changedKeys, ...devDependencyUpdate.changedKeys]
|
|
6406
|
-
.join(", ")}`);
|
|
7350
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7351
|
+
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
|
|
7352
|
+
dependencies: DB_DEFAULT_DEPENDENCIES,
|
|
7353
|
+
devDependencies: DB_DEFAULT_DEV_DEPENDENCIES,
|
|
7354
|
+
remove: DB_MOVED_DEPENDENCIES,
|
|
7355
|
+
});
|
|
7356
|
+
const scriptsUpdate = await ensureProjectTasks(cwd, manifest, getDbExpectedScripts(config, tooling));
|
|
7357
|
+
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
7358
|
+
if (dependencyUpdate.changed)
|
|
7359
|
+
changedFiles.push(dependencyUpdate.config);
|
|
7360
|
+
if (scriptsUpdate.changedKeys.length)
|
|
7361
|
+
changedFiles.push(scriptsUpdate.config);
|
|
7362
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
7363
|
+
notes.push(`Added DB dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
6407
7364
|
}
|
|
6408
7365
|
if (scriptsUpdate.changedKeys.length) {
|
|
6409
|
-
notes.push(`Updated DB
|
|
7366
|
+
notes.push(`Updated DB tasks in ${scriptsUpdate.config}: ${scriptsUpdate.changedKeys.join(", ")}`);
|
|
6410
7367
|
}
|
|
6411
|
-
if (
|
|
6412
|
-
notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${
|
|
7368
|
+
if (dependencyUpdate.removedKeys.length) {
|
|
7369
|
+
notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${dependencyUpdate.removedKeys.join(", ")}`);
|
|
6413
7370
|
}
|
|
6414
7371
|
const managedFiles = [
|
|
6415
7372
|
[config.modules.neonModule, dbNeonTemplate()],
|
|
6416
7373
|
[config.modules.neonFullModule, dbNeonFullTemplate()],
|
|
6417
7374
|
[config.modules.drizzleConfig, dbDrizzleConfigTemplate(config)],
|
|
6418
|
-
[
|
|
7375
|
+
[
|
|
7376
|
+
config.modules.pgliteHarnessModule,
|
|
7377
|
+
dbPgliteHarnessTemplate(config, testRunner),
|
|
7378
|
+
],
|
|
6419
7379
|
[config.modules.scriptsTsconfig, dbScriptsTsconfigTemplate()],
|
|
6420
7380
|
[
|
|
6421
7381
|
config.modules.refinementsCommonModule,
|
|
@@ -6485,7 +7445,8 @@ async function applyFilesFeature(cwd, framework, manifest, activate) {
|
|
|
6485
7445
|
changedFiles.push(...materialized.changedFiles);
|
|
6486
7446
|
notes.push(...materialized.notes);
|
|
6487
7447
|
config.schema = materialized.schema;
|
|
6488
|
-
|
|
7448
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7449
|
+
notes.push(`No migration was generated. Review the schema diff, then run ${formatTaskInvocation(tooling.tasks, "db:generate")} when you are ready to create the app-local migration.`);
|
|
6489
7450
|
}
|
|
6490
7451
|
const scaffoldFiles = [
|
|
6491
7452
|
[
|
|
@@ -6523,6 +7484,93 @@ async function applyFilesFeature(cwd, framework, manifest, activate) {
|
|
|
6523
7484
|
manifest.features.files = feature;
|
|
6524
7485
|
return { changedFiles, notes };
|
|
6525
7486
|
}
|
|
7487
|
+
async function applyMailFeature(cwd, framework, manifest, activate) {
|
|
7488
|
+
const changedFiles = [];
|
|
7489
|
+
const notes = [];
|
|
7490
|
+
const currentFeature = manifest.features.mail;
|
|
7491
|
+
if (!activate && currentFeature?.status !== "active") {
|
|
7492
|
+
return { changedFiles, notes };
|
|
7493
|
+
}
|
|
7494
|
+
for (const dependency of ["auth", "db"]) {
|
|
7495
|
+
if (manifest.features[dependency]?.status !== "active") {
|
|
7496
|
+
if (activate) {
|
|
7497
|
+
throw new Error(`The mail feature requires the active ${dependency} feature. Run \`loom add ${dependency}\` first.`);
|
|
7498
|
+
}
|
|
7499
|
+
notes.push(`Mail requires the active ${dependency} feature.`);
|
|
7500
|
+
return { changedFiles, notes };
|
|
7501
|
+
}
|
|
7502
|
+
}
|
|
7503
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
7504
|
+
const dbConfig = mergeDbConfig(framework, manifest.features.db.config);
|
|
7505
|
+
const config = getMailConfig(framework, dbConfig, packageJson, currentFeature?.config, manifest.features.jobs?.status === "active");
|
|
7506
|
+
const feature = currentFeature
|
|
7507
|
+
? structuredClone(currentFeature)
|
|
7508
|
+
: { status: "planned" };
|
|
7509
|
+
if (activate && feature.status !== "active") {
|
|
7510
|
+
feature.status = "active";
|
|
7511
|
+
feature.activatedOn ??= todayIso();
|
|
7512
|
+
}
|
|
7513
|
+
if (activate) {
|
|
7514
|
+
const materialized = await materializeManagedSchema(cwd, config.schema, dbConfig);
|
|
7515
|
+
if (materialized.issues.length) {
|
|
7516
|
+
throw new Error(materialized.issues.join("\n"));
|
|
7517
|
+
}
|
|
7518
|
+
changedFiles.push(...materialized.changedFiles);
|
|
7519
|
+
notes.push(...materialized.notes);
|
|
7520
|
+
config.schema = materialized.schema;
|
|
7521
|
+
notes.push("No migration was generated. Review the mail schema diff, then create and apply the app-local migration deliberately.", "Configure POSTAL_API_KEY, POSTAL_HOST, POSTAL_FROM_EMAIL, and POSTAL_WEBHOOK_PUBLIC_KEYS before sending mail or receiving webhooks.");
|
|
7522
|
+
}
|
|
7523
|
+
const scaffolds = [
|
|
7524
|
+
[config.modules.accessModule, mailAccessTemplate(), "admin access policy"],
|
|
7525
|
+
[
|
|
7526
|
+
config.modules.repositoryModule,
|
|
7527
|
+
mailRepositoryTemplate(config, dbConfig),
|
|
7528
|
+
"repository",
|
|
7529
|
+
],
|
|
7530
|
+
[
|
|
7531
|
+
config.modules.transportModule,
|
|
7532
|
+
mailTransportTemplate(),
|
|
7533
|
+
"Postal transport",
|
|
7534
|
+
],
|
|
7535
|
+
[config.modules.serviceModule, mailServiceTemplate(config), "service"],
|
|
7536
|
+
[
|
|
7537
|
+
config.modules.actionsModule,
|
|
7538
|
+
mailActionsTemplate(config),
|
|
7539
|
+
"admin actions",
|
|
7540
|
+
],
|
|
7541
|
+
[config.entrypoints.adminPage, mailAdminPageTemplate(config), "admin page"],
|
|
7542
|
+
[
|
|
7543
|
+
config.entrypoints.webhookRoute,
|
|
7544
|
+
mailWebhookRouteTemplate(config),
|
|
7545
|
+
"Postal webhook route",
|
|
7546
|
+
],
|
|
7547
|
+
];
|
|
7548
|
+
if (config.jobs.enabled) {
|
|
7549
|
+
scaffolds.push([
|
|
7550
|
+
config.modules.jobModule,
|
|
7551
|
+
mailJobTemplate(config),
|
|
7552
|
+
"outbox drain job",
|
|
7553
|
+
]);
|
|
7554
|
+
}
|
|
7555
|
+
for (const [relativePath, text, label] of scaffolds) {
|
|
7556
|
+
const scaffoldState = await scaffoldTextFile(join(cwd, relativePath), text);
|
|
7557
|
+
if (scaffoldState === "created") {
|
|
7558
|
+
changedFiles.push(relativePath);
|
|
7559
|
+
}
|
|
7560
|
+
else if (activate && scaffoldState === "preserved") {
|
|
7561
|
+
notes.push(`Preserved existing mail ${label}: ${relativePath}`);
|
|
7562
|
+
}
|
|
7563
|
+
}
|
|
7564
|
+
if (config.ui.adapter === "mui") {
|
|
7565
|
+
notes.push(`Scaffolded the MUI mail log and test-mail surface at ${config.entrypoints.adminPage}; it remains deny-all until authorizeMailAdmin() is connected to the app's fresh admin check.`);
|
|
7566
|
+
}
|
|
7567
|
+
if (config.jobs.enabled) {
|
|
7568
|
+
notes.push(`Register ${config.modules.jobModule} in the app-owned jobs catalogs and scheduling policy; Loom did not rewrite them.`);
|
|
7569
|
+
}
|
|
7570
|
+
feature.config = config;
|
|
7571
|
+
manifest.features.mail = feature;
|
|
7572
|
+
return { changedFiles, notes };
|
|
7573
|
+
}
|
|
6526
7574
|
async function applyApiKeysFeature(cwd, framework, manifest, activate) {
|
|
6527
7575
|
const changedFiles = [];
|
|
6528
7576
|
const notes = [];
|
|
@@ -6654,12 +7702,246 @@ async function applyAuthFeature(cwd, framework, manifest, activate) {
|
|
|
6654
7702
|
}
|
|
6655
7703
|
return { changedFiles, notes };
|
|
6656
7704
|
}
|
|
7705
|
+
function linguiCliCommand(tooling) {
|
|
7706
|
+
switch (tooling.dependencies.manager) {
|
|
7707
|
+
case "deno":
|
|
7708
|
+
return "deno run -A npm:@lingui/cli";
|
|
7709
|
+
case "npm":
|
|
7710
|
+
return "npx lingui";
|
|
7711
|
+
case "pnpm":
|
|
7712
|
+
return "pnpm lingui";
|
|
7713
|
+
case "yarn":
|
|
7714
|
+
return "yarn lingui";
|
|
7715
|
+
}
|
|
7716
|
+
}
|
|
7717
|
+
function linguiConfigTemplate(framework) {
|
|
7718
|
+
const sourceRoot = framework.srcDir ? "src/" : "";
|
|
7719
|
+
return `import { formatter } from "@lingui/format-po";
|
|
7720
|
+
|
|
7721
|
+
/** @type {import("@lingui/conf").LinguiConfig} */
|
|
7722
|
+
export default {
|
|
7723
|
+
locales: ["en"],
|
|
7724
|
+
sourceLocale: "en",
|
|
7725
|
+
catalogs: [
|
|
7726
|
+
{
|
|
7727
|
+
path: "<rootDir>/${sourceRoot}locales/{locale}/messages",
|
|
7728
|
+
include: ["<rootDir>/${sourceRoot}**/*.{ts,tsx}"],
|
|
7729
|
+
},
|
|
7730
|
+
],
|
|
7731
|
+
format: formatter({ lineNumbers: false }),
|
|
7732
|
+
};
|
|
7733
|
+
`;
|
|
7734
|
+
}
|
|
7735
|
+
function generatedLinguiCatalogsFromConfig(configText, framework) {
|
|
7736
|
+
const paths = [...configText.matchAll(/\bpath\s*:\s*["'`]([^"'`]+)["'`]/g)]
|
|
7737
|
+
.map((match) => match[1])
|
|
7738
|
+
.filter((path) => Boolean(path))
|
|
7739
|
+
.map((path) => path
|
|
7740
|
+
.replace(/^<rootDir>\//, "")
|
|
7741
|
+
.replaceAll("{locale}", "*")
|
|
7742
|
+
.replaceAll("{name}", "*")
|
|
7743
|
+
.replaceAll("\\", "/")
|
|
7744
|
+
.replace(/\.(?:js|po)$/, "") + ".js");
|
|
7745
|
+
return [
|
|
7746
|
+
...new Set(paths.length
|
|
7747
|
+
? paths
|
|
7748
|
+
: [`${framework.srcDir ? "src/" : ""}locales/*/messages.js`]),
|
|
7749
|
+
];
|
|
7750
|
+
}
|
|
7751
|
+
async function findLinguiConfigPath(cwd) {
|
|
7752
|
+
return await findFirstExistingRelativePath(cwd, [
|
|
7753
|
+
...LINGUI_CONFIG_CANDIDATES,
|
|
7754
|
+
]);
|
|
7755
|
+
}
|
|
7756
|
+
async function findSourceFilesMatching(cwd, pattern, relativeDir = "") {
|
|
7757
|
+
const results = [];
|
|
7758
|
+
let entries;
|
|
7759
|
+
try {
|
|
7760
|
+
entries = await readdir(join(cwd, relativeDir), { withFileTypes: true });
|
|
7761
|
+
}
|
|
7762
|
+
catch (error) {
|
|
7763
|
+
if (isNodeErrorCode(error, "ENOENT"))
|
|
7764
|
+
return results;
|
|
7765
|
+
throw error;
|
|
7766
|
+
}
|
|
7767
|
+
for (const entry of entries) {
|
|
7768
|
+
const relativePath = relativeDir
|
|
7769
|
+
? join(relativeDir, entry.name)
|
|
7770
|
+
: entry.name;
|
|
7771
|
+
if (entry.isDirectory()) {
|
|
7772
|
+
if (!ENV_LOADER_SCAN_IGNORED_DIRS.has(entry.name)) {
|
|
7773
|
+
results.push(...await findSourceFilesMatching(cwd, pattern, relativePath));
|
|
7774
|
+
}
|
|
7775
|
+
continue;
|
|
7776
|
+
}
|
|
7777
|
+
if (!entry.isFile() || !hasScannedSourceExtension(entry.name))
|
|
7778
|
+
continue;
|
|
7779
|
+
const text = await readTextIfExists(join(cwd, relativePath));
|
|
7780
|
+
pattern.lastIndex = 0;
|
|
7781
|
+
if (text && pattern.test(text)) {
|
|
7782
|
+
results.push(relativePath.replaceAll("\\", "/"));
|
|
7783
|
+
}
|
|
7784
|
+
}
|
|
7785
|
+
return results.sort();
|
|
7786
|
+
}
|
|
7787
|
+
async function detectLinguiCatalogMode(cwd) {
|
|
7788
|
+
const poImports = await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']+\.po["']/);
|
|
7789
|
+
if (poImports.length)
|
|
7790
|
+
return "loader";
|
|
7791
|
+
const nextConfigPath = await findNextConfigPath(cwd);
|
|
7792
|
+
const nextConfigText = nextConfigPath
|
|
7793
|
+
? await readTextIfExists(join(cwd, nextConfigPath))
|
|
7794
|
+
: null;
|
|
7795
|
+
return nextConfigText?.includes("@lingui/loader") ? "loader" : "precompile";
|
|
7796
|
+
}
|
|
7797
|
+
async function getLinguiConfig(cwd, framework, currentConfig) {
|
|
7798
|
+
const configFile = currentConfig?.configFile ??
|
|
7799
|
+
await findLinguiConfigPath(cwd) ?? "lingui.config.ts";
|
|
7800
|
+
const configText = await readTextIfExists(join(cwd, configFile)) ??
|
|
7801
|
+
linguiConfigTemplate(framework);
|
|
7802
|
+
return {
|
|
7803
|
+
catalogMode: currentConfig?.catalogMode ??
|
|
7804
|
+
await detectLinguiCatalogMode(cwd),
|
|
7805
|
+
configFile,
|
|
7806
|
+
generatedCatalogs: currentConfig?.generatedCatalogs?.length
|
|
7807
|
+
? [...new Set(currentConfig.generatedCatalogs)]
|
|
7808
|
+
: generatedLinguiCatalogsFromConfig(configText, framework),
|
|
7809
|
+
tasks: {
|
|
7810
|
+
...LINGUI_DEFAULT_TASKS,
|
|
7811
|
+
...currentConfig?.tasks,
|
|
7812
|
+
},
|
|
7813
|
+
};
|
|
7814
|
+
}
|
|
7815
|
+
function linguiTaskRuns(command, action) {
|
|
7816
|
+
return Boolean(command?.includes("lingui") &&
|
|
7817
|
+
new RegExp(`(?:^|\\s)${action}(?:\\s|$)`).test(command));
|
|
7818
|
+
}
|
|
7819
|
+
function dependencyMajor(spec) {
|
|
7820
|
+
const match = spec?.match(/(?:^|[^0-9])(\d+)\./);
|
|
7821
|
+
return match ? Number(match[1]) : null;
|
|
7822
|
+
}
|
|
7823
|
+
function linguiPoDeclarationTemplate() {
|
|
7824
|
+
return `declare module "*.po" {
|
|
7825
|
+
import type { Messages } from "@lingui/core";
|
|
7826
|
+
|
|
7827
|
+
export const messages: Messages;
|
|
7828
|
+
}
|
|
7829
|
+
`;
|
|
7830
|
+
}
|
|
7831
|
+
async function applyLinguiFeature(cwd, framework, manifest, activate) {
|
|
7832
|
+
const changedFiles = [];
|
|
7833
|
+
const notes = [];
|
|
7834
|
+
const currentFeature = manifest.features.lingui;
|
|
7835
|
+
const config = await getLinguiConfig(cwd, framework, currentFeature?.config);
|
|
7836
|
+
const feature = currentFeature
|
|
7837
|
+
? structuredClone(currentFeature)
|
|
7838
|
+
: { status: "planned" };
|
|
7839
|
+
if (activate && feature.status !== "active") {
|
|
7840
|
+
feature.status = "active";
|
|
7841
|
+
feature.activatedOn ??= todayIso();
|
|
7842
|
+
}
|
|
7843
|
+
feature.config = config;
|
|
7844
|
+
manifest.features.lingui = feature;
|
|
7845
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
7846
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7847
|
+
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
|
|
7848
|
+
dependencies: LINGUI_DEFAULT_DEPENDENCIES,
|
|
7849
|
+
devDependencies: {
|
|
7850
|
+
...LINGUI_DEFAULT_DEV_DEPENDENCIES,
|
|
7851
|
+
...(config.catalogMode === "loader"
|
|
7852
|
+
? LINGUI_LOADER_DEV_DEPENDENCIES
|
|
7853
|
+
: {}),
|
|
7854
|
+
},
|
|
7855
|
+
});
|
|
7856
|
+
if (dependencyUpdate.changed)
|
|
7857
|
+
changedFiles.push(dependencyUpdate.config);
|
|
7858
|
+
const configState = await scaffoldTextFile(join(cwd, config.configFile), linguiConfigTemplate(framework));
|
|
7859
|
+
if (configState === "created") {
|
|
7860
|
+
changedFiles.push(config.configFile);
|
|
7861
|
+
notes.push(`Scaffolded ${config.configFile} with an English starter locale; update its locales and catalog include paths for the app.`);
|
|
7862
|
+
}
|
|
7863
|
+
else if (activate && configState === "preserved") {
|
|
7864
|
+
notes.push(`Preserved existing Lingui config: ${config.configFile}`);
|
|
7865
|
+
}
|
|
7866
|
+
const taskChanges = [];
|
|
7867
|
+
const executable = linguiCliCommand(tooling);
|
|
7868
|
+
for (const [name, command] of [
|
|
7869
|
+
[config.tasks.extract, `${executable} extract --clean`],
|
|
7870
|
+
[config.tasks.compile, `${executable} compile`],
|
|
7871
|
+
]) {
|
|
7872
|
+
const result = await ensureTask(cwd, tooling.tasks, {
|
|
7873
|
+
definition: command,
|
|
7874
|
+
name,
|
|
7875
|
+
});
|
|
7876
|
+
if (result.changed)
|
|
7877
|
+
taskChanges.push(name);
|
|
7878
|
+
}
|
|
7879
|
+
let taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
7880
|
+
if (!getTaskCommand(taskStore.definitions[config.tasks.build])) {
|
|
7881
|
+
const result = await ensureTask(cwd, tooling.tasks, {
|
|
7882
|
+
definition: framework.kind === "nextjs" ? "next build" : "build",
|
|
7883
|
+
name: config.tasks.build,
|
|
7884
|
+
});
|
|
7885
|
+
if (result.changed)
|
|
7886
|
+
taskChanges.push(config.tasks.build);
|
|
7887
|
+
taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
7888
|
+
}
|
|
7889
|
+
const buildCommand = getTaskCommand(taskStore.definitions[config.tasks.build]);
|
|
7890
|
+
if (config.catalogMode === "precompile" && buildCommand &&
|
|
7891
|
+
!taskInvokes(taskStore, config.tasks.build, config.tasks.compile)) {
|
|
7892
|
+
const result = await ensureTaskPrerequisite(cwd, tooling.tasks, config.tasks.build, config.tasks.compile);
|
|
7893
|
+
if (result.changed)
|
|
7894
|
+
taskChanges.push(config.tasks.build);
|
|
7895
|
+
}
|
|
7896
|
+
if (taskChanges.length)
|
|
7897
|
+
changedFiles.push(tooling.tasks.config);
|
|
7898
|
+
const gitignorePath = join(cwd, ".gitignore");
|
|
7899
|
+
const gitignoreUpdate = ensureLinguiGitignoreText(await readTextIfExists(gitignorePath), config.generatedCatalogs);
|
|
7900
|
+
if (gitignoreUpdate.changed) {
|
|
7901
|
+
await writeFile(gitignorePath, gitignoreUpdate.text, "utf8");
|
|
7902
|
+
changedFiles.push(".gitignore");
|
|
7903
|
+
}
|
|
7904
|
+
if (config.catalogMode === "loader") {
|
|
7905
|
+
const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
|
|
7906
|
+
if (!poDeclarations.length) {
|
|
7907
|
+
const declarationPath = `${framework.srcDir ? "src/" : ""}lingui.d.ts`;
|
|
7908
|
+
if (await writeTextIfChanged(join(cwd, declarationPath), linguiPoDeclarationTemplate())) {
|
|
7909
|
+
changedFiles.push(declarationPath);
|
|
7910
|
+
}
|
|
7911
|
+
}
|
|
7912
|
+
}
|
|
7913
|
+
if (framework.kind === "nextjs") {
|
|
7914
|
+
const nextConfigPath = await findNextConfigPath(cwd);
|
|
7915
|
+
const nextConfigText = nextConfigPath
|
|
7916
|
+
? await readTextIfExists(join(cwd, nextConfigPath))
|
|
7917
|
+
: null;
|
|
7918
|
+
if (!nextConfigText?.includes("@lingui/swc-plugin")) {
|
|
7919
|
+
notes.push("Add @lingui/swc-plugin to experimental.swcPlugins in the app-owned Next config.");
|
|
7920
|
+
}
|
|
7921
|
+
if (config.catalogMode === "loader" &&
|
|
7922
|
+
!nextConfigText?.includes("@lingui/loader")) {
|
|
7923
|
+
notes.push("Add @lingui/loader .po rules for Turbopack and webpack in the app-owned Next config.");
|
|
7924
|
+
}
|
|
7925
|
+
}
|
|
7926
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
7927
|
+
notes.push(`Added Lingui dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
7928
|
+
}
|
|
7929
|
+
if (taskChanges.length) {
|
|
7930
|
+
notes.push(`Updated Lingui tasks in ${tooling.tasks.config}: ${[...new Set(taskChanges)].join(", ")}`);
|
|
7931
|
+
}
|
|
7932
|
+
if (packageJson.dependencies?.["@lingui/macro"] ||
|
|
7933
|
+
packageJson.devDependencies?.["@lingui/macro"]) {
|
|
7934
|
+
notes.push("The legacy @lingui/macro package remains app-owned; migrate imports to the v6 macro entrypoints before removing it.");
|
|
7935
|
+
}
|
|
7936
|
+
return { changedFiles, notes };
|
|
7937
|
+
}
|
|
6657
7938
|
async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
6658
7939
|
const changedFiles = [];
|
|
6659
7940
|
const notes = [];
|
|
6660
7941
|
const currentFeature = manifest.features.pwa;
|
|
6661
7942
|
const currentConfig = currentFeature?.config;
|
|
6662
|
-
const {
|
|
7943
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
7944
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
6663
7945
|
const config = await getPwaConfig(cwd, framework, packageJson, currentConfig, activate);
|
|
6664
7946
|
const feature = currentFeature
|
|
6665
7947
|
? structuredClone(currentFeature)
|
|
@@ -6670,31 +7952,48 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
6670
7952
|
}
|
|
6671
7953
|
feature.config = config;
|
|
6672
7954
|
manifest.features.pwa = feature;
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
7955
|
+
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
|
|
7956
|
+
dependencies: PWA_DEFAULT_DEPENDENCIES,
|
|
7957
|
+
devDependencies: PWA_DEFAULT_DEV_DEPENDENCIES,
|
|
7958
|
+
});
|
|
7959
|
+
if (dependencyUpdate.changed)
|
|
7960
|
+
changedFiles.push(dependencyUpdate.config);
|
|
7961
|
+
const scriptsChanged = [];
|
|
7962
|
+
const pwaTask = await ensureTask(cwd, tooling.tasks, {
|
|
7963
|
+
definition: PWA_BUILD_SCRIPT,
|
|
7964
|
+
name: "pwa:build",
|
|
7965
|
+
});
|
|
7966
|
+
if (pwaTask.changed)
|
|
7967
|
+
scriptsChanged.push("pwa:build");
|
|
7968
|
+
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
7969
|
+
const buildCommand = getTaskCommand(taskStore.definitions.build);
|
|
7970
|
+
if (!buildCommand) {
|
|
7971
|
+
const build = await ensureTask(cwd, tooling.tasks, {
|
|
7972
|
+
definition: `next build && ${formatTaskInvocation(tooling.tasks, "pwa:build")}`,
|
|
7973
|
+
name: "build",
|
|
7974
|
+
});
|
|
7975
|
+
if (build.changed)
|
|
7976
|
+
scriptsChanged.push("build");
|
|
6693
7977
|
}
|
|
6694
|
-
if (
|
|
6695
|
-
|
|
7978
|
+
else if (buildCommand.includes("next build") &&
|
|
7979
|
+
!taskInvokes(taskStore, "build", "pwa:build") &&
|
|
7980
|
+
!scriptRunsSerwistBuild(buildCommand)) {
|
|
7981
|
+
const build = await ensureTaskFollowup(cwd, tooling.tasks, "build", "pwa:build");
|
|
7982
|
+
if (build.changed)
|
|
7983
|
+
scriptsChanged.push("build");
|
|
7984
|
+
}
|
|
7985
|
+
else if (!taskInvokes(taskStore, "build", "pwa:build") &&
|
|
7986
|
+
!scriptRunsSerwistBuild(buildCommand)) {
|
|
7987
|
+
notes.push("PWA build task was added, but the existing build task does not visibly run `next build`; wire `pwa:build` after the app's Next.js build step.");
|
|
7988
|
+
}
|
|
7989
|
+
if (scriptsChanged.length)
|
|
7990
|
+
changedFiles.push(tooling.tasks.config);
|
|
7991
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
7992
|
+
notes.push(`Added PWA dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
7993
|
+
}
|
|
7994
|
+
if (scriptsChanged.length) {
|
|
7995
|
+
notes.push(`Updated PWA tasks in ${tooling.tasks.config}: ${scriptsChanged.join(", ")}`);
|
|
6696
7996
|
}
|
|
6697
|
-
notes.push(...scriptsUpdate.notes);
|
|
6698
7997
|
const serwistConfigState = await scaffoldTextFile(join(cwd, config.modules.serwistConfig), pwaSerwistConfigTemplate(config));
|
|
6699
7998
|
if (serwistConfigState === "created") {
|
|
6700
7999
|
changedFiles.push(config.modules.serwistConfig);
|
|
@@ -6748,13 +8047,13 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
6748
8047
|
return { issues, suggestions: [], warnings: [] };
|
|
6749
8048
|
}
|
|
6750
8049
|
const config = mergeJobsConfig(framework, feature.config);
|
|
6751
|
-
const { packageJson } = await readProjectPackageJson(cwd);
|
|
6752
8050
|
const expectedScripts = getJobsExpectedScripts(config);
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
8051
|
+
const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
|
|
8052
|
+
for (const taskName of taskCheck.mismatches) {
|
|
8053
|
+
issues.push(taskCheck.config === "package.json"
|
|
8054
|
+
? `Jobs package.json script does not match Loom defaults: ${taskName}`
|
|
8055
|
+
: `Jobs task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
8056
|
+
suggestions.add("Run `loom add jobs`.");
|
|
6758
8057
|
}
|
|
6759
8058
|
const requiredFiles = [
|
|
6760
8059
|
JOBS_SCRIPTS_TSCONFIG_PATH,
|
|
@@ -6911,7 +8210,9 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
6911
8210
|
}
|
|
6912
8211
|
const config = mergeDbConfig(framework, feature.config);
|
|
6913
8212
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
6914
|
-
const
|
|
8213
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
8214
|
+
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
8215
|
+
const expectedScripts = getDbExpectedScripts(config, tooling);
|
|
6915
8216
|
const migrationFlowCheck = await checkDbProductionMigrationFlow(cwd, options.production ?? false);
|
|
6916
8217
|
issues.push(...migrationFlowCheck.issues);
|
|
6917
8218
|
warnings.push(...migrationFlowCheck.warnings);
|
|
@@ -6919,29 +8220,36 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
6919
8220
|
suggestions.add(suggestion);
|
|
6920
8221
|
}
|
|
6921
8222
|
for (const dependencyName of Object.keys(DB_DEFAULT_DEPENDENCIES)) {
|
|
6922
|
-
if (!packageJson
|
|
6923
|
-
issues.push(
|
|
8223
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
8224
|
+
issues.push(tooling.dependencies.config === "package.json"
|
|
8225
|
+
? `DB dependency is missing from package.json dependencies: ${dependencyName}`
|
|
8226
|
+
: `DB dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
6924
8227
|
suggestions.add("Run `loom add db`.");
|
|
6925
8228
|
}
|
|
6926
8229
|
}
|
|
6927
8230
|
for (const dependencyName of Object.keys(DB_DEFAULT_DEV_DEPENDENCIES)) {
|
|
6928
|
-
if (!packageJson
|
|
6929
|
-
issues.push(
|
|
8231
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
8232
|
+
issues.push(tooling.dependencies.config === "package.json"
|
|
8233
|
+
? `DB dependency is missing from package.json devDependencies: ${dependencyName}`
|
|
8234
|
+
: `DB development dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
6930
8235
|
suggestions.add("Run `loom add db`.");
|
|
6931
8236
|
}
|
|
6932
8237
|
}
|
|
6933
8238
|
for (const dependencyName of DB_MOVED_DEPENDENCIES) {
|
|
6934
8239
|
if (packageJson.dependencies?.[dependencyName] ||
|
|
6935
8240
|
packageJson.devDependencies?.[dependencyName]) {
|
|
6936
|
-
issues.push(
|
|
6937
|
-
|
|
8241
|
+
issues.push(tooling.dependencies.config === "package.json"
|
|
8242
|
+
? `Consumer package.json still declares a Loom-managed DB generator dependency: ${dependencyName}`
|
|
8243
|
+
: `Consumer ${tooling.dependencies.config} still declares a Loom-managed DB generator dependency: ${dependencyName}`);
|
|
8244
|
+
suggestions.add(`Run loom add db to rewrite ${tooling.dependencies.config}.`);
|
|
6938
8245
|
}
|
|
6939
8246
|
}
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
8247
|
+
const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
|
|
8248
|
+
for (const taskName of taskCheck.mismatches) {
|
|
8249
|
+
issues.push(taskCheck.config === "package.json"
|
|
8250
|
+
? `DB package.json script does not match Loom defaults: ${taskName}`
|
|
8251
|
+
: `DB task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
8252
|
+
suggestions.add("Run `loom add db`.");
|
|
6945
8253
|
}
|
|
6946
8254
|
const requiredFiles = [
|
|
6947
8255
|
config.modules.neonModule,
|
|
@@ -6977,7 +8285,7 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
6977
8285
|
],
|
|
6978
8286
|
[
|
|
6979
8287
|
config.modules.pgliteHarnessModule,
|
|
6980
|
-
dbPgliteHarnessTemplate(config),
|
|
8288
|
+
dbPgliteHarnessTemplate(config, testRunner),
|
|
6981
8289
|
"PGlite test harness does not match the Loom-managed wrapper",
|
|
6982
8290
|
],
|
|
6983
8291
|
[
|
|
@@ -7068,6 +8376,8 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7068
8376
|
const dbConfig = mergeDbConfig(framework, dbFeature.config);
|
|
7069
8377
|
const config = getFilesConfig(framework, dbConfig, feature.config);
|
|
7070
8378
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
8379
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
8380
|
+
const generateCommand = formatTaskInvocation(tooling.tasks, "db:generate");
|
|
7071
8381
|
const schema = config.schema;
|
|
7072
8382
|
const latestSchema = getLatestManagedSchemaConfig(schema);
|
|
7073
8383
|
if (schema.mode !== "managed-local" || schema.blueprint !== "files") {
|
|
@@ -7081,7 +8391,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7081
8391
|
}
|
|
7082
8392
|
else if (schema.version < supportedVersion) {
|
|
7083
8393
|
warnings.push(`Files schema blueprint is stale: ${schema.version} < ${supportedVersion}.`);
|
|
7084
|
-
suggestions.add(
|
|
8394
|
+
suggestions.add(`Run loom db schemas sync, review the schema diff, then run ${generateCommand} if the schema changed.`);
|
|
7085
8395
|
}
|
|
7086
8396
|
const schemaRelativeToDir = relative(dbConfig.dirs.schemaDir, schema.module)
|
|
7087
8397
|
.replaceAll("\\", "/");
|
|
@@ -7096,7 +8406,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7096
8406
|
const schemaText = await readTextIfExists(join(cwd, schema.module));
|
|
7097
8407
|
if (!schemaText) {
|
|
7098
8408
|
issues.push(`Files schema file is missing: ${schema.module}`);
|
|
7099
|
-
suggestions.add(
|
|
8409
|
+
suggestions.add(`Run loom db schemas sync, review the schema diff, then run ${generateCommand} if the schema changed.`);
|
|
7100
8410
|
}
|
|
7101
8411
|
else {
|
|
7102
8412
|
const currentHash = hashManagedSchemaText(schemaText);
|
|
@@ -7212,8 +8522,8 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7212
8522
|
suggestions.add("Replace the generated files storage stub with an S3 or app-specific storage adapter before production use.");
|
|
7213
8523
|
}
|
|
7214
8524
|
if (config.storage.adapter === "s3") {
|
|
7215
|
-
if (!packageJson
|
|
7216
|
-
issues.push(
|
|
8525
|
+
if (!hasPackageDependency(packageJson, "@aws-sdk/client-s3")) {
|
|
8526
|
+
issues.push(`Files S3/R2 storage requires @aws-sdk/client-s3 in ${tooling.dependencies.config}.`);
|
|
7217
8527
|
suggestions.add("Run `loom files r2 setup` to restore the dependency.");
|
|
7218
8528
|
}
|
|
7219
8529
|
for (const envName of FILES_S3_REQUIRED_ENV_NAMES) {
|
|
@@ -7281,6 +8591,147 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7281
8591
|
warnings,
|
|
7282
8592
|
};
|
|
7283
8593
|
}
|
|
8594
|
+
async function checkMailFeature(cwd, framework, manifest, options) {
|
|
8595
|
+
const issues = [];
|
|
8596
|
+
const suggestions = new Set();
|
|
8597
|
+
const warnings = [];
|
|
8598
|
+
const feature = manifest.features.mail;
|
|
8599
|
+
if (!feature || feature.status !== "active") {
|
|
8600
|
+
return { issues, suggestions: [], warnings };
|
|
8601
|
+
}
|
|
8602
|
+
for (const dependency of ["auth", "db"]) {
|
|
8603
|
+
if (manifest.features[dependency]?.status !== "active") {
|
|
8604
|
+
issues.push(`Mail feature requires the active ${dependency} feature.`);
|
|
8605
|
+
suggestions.add(`Run \`loom add ${dependency}\` before using mail.`);
|
|
8606
|
+
}
|
|
8607
|
+
}
|
|
8608
|
+
if (issues.length)
|
|
8609
|
+
return { issues, suggestions: [...suggestions], warnings };
|
|
8610
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
8611
|
+
const dbConfig = mergeDbConfig(framework, manifest.features.db.config);
|
|
8612
|
+
const config = getMailConfig(framework, dbConfig, packageJson, feature.config, manifest.features.jobs?.status === "active");
|
|
8613
|
+
const schema = config.schema;
|
|
8614
|
+
const latestSchema = getLatestManagedSchemaConfig(schema);
|
|
8615
|
+
if (schema.mode !== "managed-local" || schema.blueprint !== "mail") {
|
|
8616
|
+
issues.push("Mail must use the managed-local mail schema blueprint.");
|
|
8617
|
+
suggestions.add("Run `loom add mail` to restore the mail schema config.");
|
|
8618
|
+
}
|
|
8619
|
+
if (schema.exports.length !== 3) {
|
|
8620
|
+
issues.push("Mail schema must configure message, delivery, and event exports.");
|
|
8621
|
+
}
|
|
8622
|
+
if (schema.version > MAIL_SCHEMA_BLUEPRINT_VERSION) {
|
|
8623
|
+
issues.push(`Mail schema blueprint version ${schema.version} is newer than this Loom package supports.`);
|
|
8624
|
+
}
|
|
8625
|
+
else if (schema.version < MAIL_SCHEMA_BLUEPRINT_VERSION) {
|
|
8626
|
+
warnings.push(`Mail schema blueprint is stale: ${schema.version} < ${MAIL_SCHEMA_BLUEPRINT_VERSION}.`);
|
|
8627
|
+
suggestions.add("Run `loom db schemas sync`, then review and migrate the diff.");
|
|
8628
|
+
}
|
|
8629
|
+
const schemaText = await readTextIfExists(join(cwd, schema.module));
|
|
8630
|
+
if (!schemaText) {
|
|
8631
|
+
issues.push(`Mail schema file is missing: ${schema.module}`);
|
|
8632
|
+
suggestions.add("Run `loom db schemas sync`.");
|
|
8633
|
+
}
|
|
8634
|
+
else {
|
|
8635
|
+
const currentHash = hashManagedSchemaText(schemaText);
|
|
8636
|
+
if (currentHash !== schema.hash) {
|
|
8637
|
+
if (currentHash === latestSchema.hash) {
|
|
8638
|
+
warnings.push(`Mail schema manifest hash is stale for ${schema.module}.`);
|
|
8639
|
+
suggestions.add("Run `loom db schemas sync` to refresh loom.json.");
|
|
8640
|
+
}
|
|
8641
|
+
else {
|
|
8642
|
+
issues.push(`Mail schema file has local edits outside the managed hash: ${schema.module}`);
|
|
8643
|
+
suggestions.add("Move app-specific mail schema additions to a separate file, then run `loom db schemas sync`.");
|
|
8644
|
+
}
|
|
8645
|
+
}
|
|
8646
|
+
const barrelText = await readTextIfExists(join(cwd, dbConfig.dirs.schemaDir, "index.ts"));
|
|
8647
|
+
if (!barrelText || !schemaBarrelExportsModule(barrelText, schema, dbConfig)) {
|
|
8648
|
+
issues.push(`DB schema barrel does not export the managed mail schema: ${dbConfig.dirs.schemaDir}/index.ts`);
|
|
8649
|
+
suggestions.add("Run `loom db schemas sync`.");
|
|
8650
|
+
}
|
|
8651
|
+
}
|
|
8652
|
+
const requiredFiles = [
|
|
8653
|
+
config.modules.accessModule,
|
|
8654
|
+
config.modules.actionsModule,
|
|
8655
|
+
config.modules.repositoryModule,
|
|
8656
|
+
config.modules.serviceModule,
|
|
8657
|
+
config.modules.transportModule,
|
|
8658
|
+
config.entrypoints.adminPage,
|
|
8659
|
+
config.entrypoints.webhookRoute,
|
|
8660
|
+
...(config.jobs.enabled ? [config.modules.jobModule] : []),
|
|
8661
|
+
];
|
|
8662
|
+
for (const relativePath of requiredFiles) {
|
|
8663
|
+
if (!await exists(join(cwd, relativePath))) {
|
|
8664
|
+
issues.push(`Mail scaffold file is missing: ${relativePath}`);
|
|
8665
|
+
suggestions.add("Run `loom add mail` to restore missing scaffolds.");
|
|
8666
|
+
}
|
|
8667
|
+
}
|
|
8668
|
+
const accessText = await readTextIfExists(join(cwd, config.modules.accessModule));
|
|
8669
|
+
if (accessText && !accessText.includes("authorizeMailAdmin")) {
|
|
8670
|
+
issues.push(`Mail access module does not export authorizeMailAdmin: ${config.modules.accessModule}`);
|
|
8671
|
+
}
|
|
8672
|
+
const generatedDenyAll = accessText?.includes("Mail admin access policy is not configured.") ?? false;
|
|
8673
|
+
if (generatedDenyAll) {
|
|
8674
|
+
const message = `Mail admin access still uses the generated deny-all stub: ${config.modules.accessModule}`;
|
|
8675
|
+
if (options.production)
|
|
8676
|
+
issues.push(message);
|
|
8677
|
+
else
|
|
8678
|
+
warnings.push(message);
|
|
8679
|
+
suggestions.add("Connect authorizeMailAdmin() to the app's fresh session/admin-role check.");
|
|
8680
|
+
}
|
|
8681
|
+
const contentChecks = [
|
|
8682
|
+
[
|
|
8683
|
+
config.modules.repositoryModule,
|
|
8684
|
+
"@gadicc/loom/mail",
|
|
8685
|
+
"Mail repository is not typed against the shared mail contract",
|
|
8686
|
+
],
|
|
8687
|
+
[
|
|
8688
|
+
config.modules.serviceModule,
|
|
8689
|
+
"createLoomMailService",
|
|
8690
|
+
"Mail service is not wired to the shared durable service",
|
|
8691
|
+
],
|
|
8692
|
+
[
|
|
8693
|
+
config.modules.transportModule,
|
|
8694
|
+
"createPostalMailTransport",
|
|
8695
|
+
"Mail transport is not wired to the Postal adapter",
|
|
8696
|
+
],
|
|
8697
|
+
[
|
|
8698
|
+
config.modules.transportModule,
|
|
8699
|
+
"POSTAL_WEBHOOK_PUBLIC_KEYS",
|
|
8700
|
+
"Mail transport does not configure Postal webhook public keys",
|
|
8701
|
+
],
|
|
8702
|
+
[
|
|
8703
|
+
config.entrypoints.webhookRoute,
|
|
8704
|
+
"createPostalWebhookRouteHandler",
|
|
8705
|
+
"Mail webhook route does not use the signed shared route handler",
|
|
8706
|
+
],
|
|
8707
|
+
[
|
|
8708
|
+
config.modules.actionsModule,
|
|
8709
|
+
"authorizeMailAdmin",
|
|
8710
|
+
"Mail admin actions do not enforce the app-owned admin boundary",
|
|
8711
|
+
],
|
|
8712
|
+
[
|
|
8713
|
+
config.entrypoints.adminPage,
|
|
8714
|
+
"authorizeMailAdmin",
|
|
8715
|
+
"Mail admin page does not enforce the app-owned admin boundary",
|
|
8716
|
+
],
|
|
8717
|
+
];
|
|
8718
|
+
for (const [relativePath, snippet, label] of contentChecks) {
|
|
8719
|
+
const text = await readTextIfExists(join(cwd, relativePath));
|
|
8720
|
+
if (text && !text.includes(snippet)) {
|
|
8721
|
+
issues.push(`${label}: ${relativePath}`);
|
|
8722
|
+
suggestions.add("Run `loom add mail` or update loom.json for intentional paths.");
|
|
8723
|
+
}
|
|
8724
|
+
}
|
|
8725
|
+
if (config.ui.adapter === "mui" &&
|
|
8726
|
+
!hasPackageDependency(packageJson, "@mui/material")) {
|
|
8727
|
+
issues.push("Mail's MUI adapter is active but @mui/material is not installed.");
|
|
8728
|
+
}
|
|
8729
|
+
if (config.jobs.enabled && manifest.features.jobs?.status !== "active") {
|
|
8730
|
+
warnings.push("Mail drain job is enabled while the Loom jobs feature is inactive.");
|
|
8731
|
+
suggestions.add("Run `loom add jobs` or disable features.mail.config.jobs.enabled.");
|
|
8732
|
+
}
|
|
8733
|
+
return { issues, suggestions: [...suggestions], warnings };
|
|
8734
|
+
}
|
|
7284
8735
|
function packageDependencySpec(packageJson, dependencyName) {
|
|
7285
8736
|
return packageJson.dependencies?.[dependencyName] ??
|
|
7286
8737
|
packageJson.devDependencies?.[dependencyName];
|
|
@@ -7556,6 +9007,125 @@ async function findNextConfigPath(cwd) {
|
|
|
7556
9007
|
];
|
|
7557
9008
|
return await findFirstExistingRelativePath(cwd, candidates);
|
|
7558
9009
|
}
|
|
9010
|
+
async function checkLinguiFeature(cwd, framework, manifest, options) {
|
|
9011
|
+
const issues = [];
|
|
9012
|
+
const suggestions = new Set();
|
|
9013
|
+
const warnings = [];
|
|
9014
|
+
const feature = manifest.features.lingui;
|
|
9015
|
+
if (!feature || feature.status !== "active") {
|
|
9016
|
+
return { issues, suggestions: [], warnings };
|
|
9017
|
+
}
|
|
9018
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
9019
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
9020
|
+
const config = await getLinguiConfig(cwd, framework, feature.config);
|
|
9021
|
+
const requiredDependencies = {
|
|
9022
|
+
...LINGUI_DEFAULT_DEPENDENCIES,
|
|
9023
|
+
...LINGUI_DEFAULT_DEV_DEPENDENCIES,
|
|
9024
|
+
...(config.catalogMode === "loader" ? LINGUI_LOADER_DEV_DEPENDENCIES : {}),
|
|
9025
|
+
};
|
|
9026
|
+
for (const dependencyName of Object.keys(requiredDependencies)) {
|
|
9027
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
9028
|
+
issues.push(`Lingui dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
9029
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9030
|
+
}
|
|
9031
|
+
}
|
|
9032
|
+
if (!await exists(join(cwd, config.configFile))) {
|
|
9033
|
+
issues.push(`Lingui config is missing: ${config.configFile}`);
|
|
9034
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9035
|
+
}
|
|
9036
|
+
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
9037
|
+
if (!linguiTaskRuns(getTaskCommand(taskStore.definitions[config.tasks.extract]), "extract")) {
|
|
9038
|
+
issues.push(`Lingui extraction task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.extract}`);
|
|
9039
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9040
|
+
}
|
|
9041
|
+
if (!linguiTaskRuns(getTaskCommand(taskStore.definitions[config.tasks.compile]), "compile")) {
|
|
9042
|
+
issues.push(`Lingui compile task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.compile}`);
|
|
9043
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9044
|
+
}
|
|
9045
|
+
if (config.catalogMode === "precompile") {
|
|
9046
|
+
if (!taskInvokes(taskStore, config.tasks.build, config.tasks.compile)) {
|
|
9047
|
+
issues.push(`Build task does not compile Lingui catalogs in ${tooling.tasks.config}: ${config.tasks.build}`);
|
|
9048
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9049
|
+
}
|
|
9050
|
+
else {
|
|
9051
|
+
const buildCommand = getTaskCommand(taskStore.definitions[config.tasks.build]);
|
|
9052
|
+
if (buildCommand?.includes("next build") &&
|
|
9053
|
+
!taskRunsBeforeCommand(taskStore, config.tasks.build, config.tasks.compile, "next build")) {
|
|
9054
|
+
issues.push(`Lingui catalogs are compiled after Next.js starts building in ${tooling.tasks.config}: ${config.tasks.build}`);
|
|
9055
|
+
suggestions.add(`Run ${config.tasks.compile} before the framework build command.`);
|
|
9056
|
+
}
|
|
9057
|
+
}
|
|
9058
|
+
}
|
|
9059
|
+
const gitignoreUpdate = ensureLinguiGitignoreText(await readTextIfExists(join(cwd, ".gitignore")), config.generatedCatalogs);
|
|
9060
|
+
if (gitignoreUpdate.missingLines.length) {
|
|
9061
|
+
issues.push(`Lingui generated catalogs are missing from .gitignore: ${gitignoreUpdate.missingLines.join(", ")}`);
|
|
9062
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9063
|
+
}
|
|
9064
|
+
const gitResult = await (options.commandRunner ?? defaultCommandRunner)("git", ["ls-files", "--", ...config.generatedCatalogs], { cwd, stdio: "pipe" });
|
|
9065
|
+
const trackedCatalogs = gitResult.code === 0
|
|
9066
|
+
? gitResult.stdout.trim().split(/\r?\n/).filter(Boolean)
|
|
9067
|
+
: [];
|
|
9068
|
+
if (trackedCatalogs.length) {
|
|
9069
|
+
issues.push(`Lingui generated catalogs are still tracked by git: ${trackedCatalogs.join(", ")}`);
|
|
9070
|
+
suggestions.add("Remove generated catalogs from the git index while keeping the source .po catalogs tracked.");
|
|
9071
|
+
}
|
|
9072
|
+
const nextConfigPath = await findNextConfigPath(cwd);
|
|
9073
|
+
const nextConfigText = nextConfigPath
|
|
9074
|
+
? await readTextIfExists(join(cwd, nextConfigPath))
|
|
9075
|
+
: null;
|
|
9076
|
+
if (framework.kind === "nextjs") {
|
|
9077
|
+
if (!nextConfigText?.includes("@lingui/swc-plugin")) {
|
|
9078
|
+
issues.push(`Next config is missing @lingui/swc-plugin${nextConfigPath ? `: ${nextConfigPath}` : "."}`);
|
|
9079
|
+
suggestions.add("Add @lingui/swc-plugin to experimental.swcPlugins in the Next config.");
|
|
9080
|
+
}
|
|
9081
|
+
if (config.catalogMode === "loader" &&
|
|
9082
|
+
!nextConfigText?.includes("@lingui/loader")) {
|
|
9083
|
+
issues.push(`Lingui loader mode is not wired in the Next config${nextConfigPath ? `: ${nextConfigPath}` : "."}`);
|
|
9084
|
+
suggestions.add("Add matching .po rules for Turbopack and webpack, or switch the manifest to precompile mode.");
|
|
9085
|
+
}
|
|
9086
|
+
if (nextConfigText && /\breactCompiler\s*:\s*true/.test(nextConfigText)) {
|
|
9087
|
+
warnings.push("Next.js React Compiler and the Lingui SWC plugin are both enabled; keep this combination covered by a production build test when upgrading either tool.");
|
|
9088
|
+
}
|
|
9089
|
+
}
|
|
9090
|
+
const poImports = await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']+\.po["']/);
|
|
9091
|
+
if (config.catalogMode === "precompile" && poImports.length) {
|
|
9092
|
+
issues.push(`Lingui is configured for precompile mode but source files import .po catalogs: ${poImports.join(", ")}`);
|
|
9093
|
+
suggestions.add("Switch loom.json to loader mode or import the generated .js catalogs.");
|
|
9094
|
+
}
|
|
9095
|
+
if (config.catalogMode === "loader" && !poImports.length) {
|
|
9096
|
+
warnings.push("Lingui is configured for loader mode, but no source .po imports were found.");
|
|
9097
|
+
}
|
|
9098
|
+
if (config.catalogMode === "loader") {
|
|
9099
|
+
const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
|
|
9100
|
+
if (!poDeclarations.length) {
|
|
9101
|
+
issues.push("Lingui loader mode is missing a TypeScript *.po module declaration.");
|
|
9102
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9103
|
+
}
|
|
9104
|
+
}
|
|
9105
|
+
const configImports = (await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']*lingui\.config(?:\.[cm]?[jt]s)?["']/)).filter((relativePath) => relativePath !== config.configFile);
|
|
9106
|
+
if (configImports.length) {
|
|
9107
|
+
warnings.push(`Lingui config is imported by runtime source; keep config evaluation build-time only: ${configImports.join(", ")}`);
|
|
9108
|
+
}
|
|
9109
|
+
const linguiCoreMajor = dependencyMajor(packageJson.dependencies?.["@lingui/core"] ??
|
|
9110
|
+
packageJson.devDependencies?.["@lingui/core"]);
|
|
9111
|
+
const legacyMacroSpec = packageJson.dependencies?.["@lingui/macro"] ??
|
|
9112
|
+
packageJson.devDependencies?.["@lingui/macro"];
|
|
9113
|
+
if (legacyMacroSpec && linguiCoreMajor !== null &&
|
|
9114
|
+
dependencyMajor(legacyMacroSpec) !== linguiCoreMajor) {
|
|
9115
|
+
warnings.push(`Legacy @lingui/macro (${legacyMacroSpec}) does not match @lingui/core's major version; prefer @lingui/react/macro and @lingui/core/macro imports.`);
|
|
9116
|
+
}
|
|
9117
|
+
const linguiFamilyMajors = Object.keys(requiredDependencies).flatMap((dependencyName) => {
|
|
9118
|
+
const spec = packageJson.dependencies?.[dependencyName] ??
|
|
9119
|
+
packageJson.devDependencies?.[dependencyName];
|
|
9120
|
+
const major = dependencyMajor(spec);
|
|
9121
|
+
return major === null ? [] : [`${dependencyName}@${major}`];
|
|
9122
|
+
});
|
|
9123
|
+
if (new Set(linguiFamilyMajors.map((entry) => entry.split("@").at(-1))).size >
|
|
9124
|
+
1) {
|
|
9125
|
+
warnings.push(`Lingui packages span multiple major versions: ${linguiFamilyMajors.join(", ")}`);
|
|
9126
|
+
}
|
|
9127
|
+
return { issues, suggestions: [...suggestions], warnings };
|
|
9128
|
+
}
|
|
7559
9129
|
async function checkPwaFeature(cwd, framework, manifest) {
|
|
7560
9130
|
const issues = [];
|
|
7561
9131
|
const suggestions = new Set();
|
|
@@ -7565,6 +9135,7 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
7565
9135
|
return { issues, suggestions: [], warnings };
|
|
7566
9136
|
}
|
|
7567
9137
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
9138
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7568
9139
|
const config = await getPwaConfig(cwd, framework, packageJson, feature.config, false);
|
|
7569
9140
|
const hasMui = hasPackageDependency(packageJson, "@mui/material");
|
|
7570
9141
|
if (framework.kind !== "nextjs" || framework.router !== "app") {
|
|
@@ -7572,23 +9143,25 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
7572
9143
|
suggestions.add("Update loom.json if this project intentionally uses a custom PWA integration.");
|
|
7573
9144
|
}
|
|
7574
9145
|
for (const dependencyName of Object.keys(PWA_DEFAULT_DEPENDENCIES)) {
|
|
7575
|
-
if (!packageJson
|
|
7576
|
-
issues.push(`PWA dependency is missing from
|
|
9146
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
9147
|
+
issues.push(`PWA dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
7577
9148
|
suggestions.add("Run `loom add pwa`.");
|
|
7578
9149
|
}
|
|
7579
9150
|
}
|
|
7580
9151
|
for (const dependencyName of Object.keys(PWA_DEFAULT_DEV_DEPENDENCIES)) {
|
|
7581
|
-
if (!packageJson
|
|
7582
|
-
issues.push(`PWA dependency is missing from
|
|
9152
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
9153
|
+
issues.push(`PWA development dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
7583
9154
|
suggestions.add("Run `loom add pwa`.");
|
|
7584
9155
|
}
|
|
7585
9156
|
}
|
|
7586
|
-
|
|
7587
|
-
|
|
9157
|
+
const taskStore = await readTaskStore(cwd, tooling.tasks);
|
|
9158
|
+
if (!scriptRunsSerwistBuild(getTaskCommand(taskStore.definitions["pwa:build"]))) {
|
|
9159
|
+
issues.push(`PWA task in ${tooling.tasks.config} does not build Serwist: pwa:build`);
|
|
7588
9160
|
suggestions.add("Run `loom add pwa`.");
|
|
7589
9161
|
}
|
|
7590
|
-
if (!scriptRunsSerwistBuild(
|
|
7591
|
-
|
|
9162
|
+
if (!scriptRunsSerwistBuild(getTaskCommand(taskStore.definitions.build)) &&
|
|
9163
|
+
!taskInvokes(taskStore, "build", "pwa:build")) {
|
|
9164
|
+
issues.push(`PWA build task in ${tooling.tasks.config} does not run Serwist after the Next.js build.`);
|
|
7592
9165
|
suggestions.add("Run `loom add pwa`.");
|
|
7593
9166
|
}
|
|
7594
9167
|
const gitignoreUpdate = ensurePwaGitignoreText(await readTextIfExists(join(cwd, ".gitignore")));
|
|
@@ -7769,6 +9342,14 @@ const featureHooks = {
|
|
|
7769
9342
|
apply: applyJobsFeature,
|
|
7770
9343
|
check: checkJobsFeature,
|
|
7771
9344
|
},
|
|
9345
|
+
lingui: {
|
|
9346
|
+
apply: applyLinguiFeature,
|
|
9347
|
+
check: checkLinguiFeature,
|
|
9348
|
+
},
|
|
9349
|
+
mail: {
|
|
9350
|
+
apply: applyMailFeature,
|
|
9351
|
+
check: checkMailFeature,
|
|
9352
|
+
},
|
|
7772
9353
|
pwa: {
|
|
7773
9354
|
apply: applyPwaFeature,
|
|
7774
9355
|
check: checkPwaFeature,
|
|
@@ -7792,11 +9373,14 @@ async function ensureActiveFeatureScaffolds(cwd, framework, manifest) {
|
|
|
7792
9373
|
export async function initProject(cwd, versionRange) {
|
|
7793
9374
|
const changedFiles = [];
|
|
7794
9375
|
const notes = [];
|
|
7795
|
-
const
|
|
7796
|
-
const
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
9376
|
+
const loomManifestPath = join(cwd, "loom.json");
|
|
9377
|
+
const existingManifestText = await readTextIfExists(loomManifestPath);
|
|
9378
|
+
const existingManifest = existingManifestText
|
|
9379
|
+
? parseJson(existingManifestText, "loom.json")
|
|
9380
|
+
: null;
|
|
9381
|
+
const tooling = await detectProjectTooling(cwd, existingManifest?.project?.tooling);
|
|
9382
|
+
const initialMetadata = await readProjectPackageMetadata(cwd);
|
|
9383
|
+
const initialPackageJson = initialMetadata.packageJson;
|
|
7800
9384
|
const npmrcPath = join(cwd, ".npmrc");
|
|
7801
9385
|
const npmrcUpdate = removeLegacyLoomNpmrcText(await readTextIfExists(npmrcPath));
|
|
7802
9386
|
if (npmrcUpdate.changed) {
|
|
@@ -7804,19 +9388,23 @@ export async function initProject(cwd, versionRange) {
|
|
|
7804
9388
|
changedFiles.push(".npmrc");
|
|
7805
9389
|
notes.push("Removed Loom's obsolete GitHub Packages registry configuration.");
|
|
7806
9390
|
}
|
|
7807
|
-
const
|
|
7808
|
-
|
|
9391
|
+
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
|
|
9392
|
+
dependencies: {
|
|
9393
|
+
[LOOM_DEPENDENCY]: versionRange ??
|
|
9394
|
+
getPublishedLoomDependencySpec(initialPackageJson),
|
|
9395
|
+
},
|
|
9396
|
+
replace: true,
|
|
9397
|
+
});
|
|
7809
9398
|
if (dependencyUpdate.changed) {
|
|
7810
|
-
|
|
7811
|
-
|
|
9399
|
+
changedFiles.push(tooling.dependencies.config);
|
|
9400
|
+
if (tooling.dependencies.config !== "package.json") {
|
|
9401
|
+
notes.push(`Recorded ${LOOM_DEPENDENCY} in ${tooling.dependencies.config} imports and enabled Deno's local node_modules directory when needed.`);
|
|
9402
|
+
}
|
|
7812
9403
|
}
|
|
7813
|
-
const
|
|
7814
|
-
|
|
7815
|
-
const
|
|
7816
|
-
const
|
|
7817
|
-
? parseJson(existingManifestText, "loom.json")
|
|
7818
|
-
: null;
|
|
7819
|
-
const manifest = buildManifest(cwd, dependencyUpdate.packageJson, framework, existingManifest);
|
|
9404
|
+
const packageJson = (await readProjectPackageMetadata(cwd))
|
|
9405
|
+
.packageJson;
|
|
9406
|
+
const framework = await detectFramework(cwd, packageJson);
|
|
9407
|
+
const manifest = buildManifest(cwd, packageJson, framework, existingManifest, tooling);
|
|
7820
9408
|
const featureInit = await ensureActiveFeatureScaffolds(cwd, framework, manifest);
|
|
7821
9409
|
changedFiles.push(...featureInit.changedFiles);
|
|
7822
9410
|
notes.push(...featureInit.notes);
|
|
@@ -7827,7 +9415,7 @@ export async function initProject(cwd, versionRange) {
|
|
|
7827
9415
|
if (agentsInit.changed) {
|
|
7828
9416
|
changedFiles.push("AGENTS.md");
|
|
7829
9417
|
}
|
|
7830
|
-
const nextAgentsInit = await ensureNextAgentsFile(cwd,
|
|
9418
|
+
const nextAgentsInit = await ensureNextAgentsFile(cwd, packageJson);
|
|
7831
9419
|
if (nextAgentsInit.changed)
|
|
7832
9420
|
changedFiles.push("AGENTS.md");
|
|
7833
9421
|
if (nextAgentsInit.note)
|
|
@@ -7851,7 +9439,8 @@ export async function initProject(cwd, versionRange) {
|
|
|
7851
9439
|
framework,
|
|
7852
9440
|
manifest,
|
|
7853
9441
|
notes,
|
|
7854
|
-
packageJson:
|
|
9442
|
+
packageJson: (await readProjectPackageMetadata(cwd))
|
|
9443
|
+
.packageJson,
|
|
7855
9444
|
};
|
|
7856
9445
|
}
|
|
7857
9446
|
export async function addFeature(cwd, featureKey, versionRange) {
|
|
@@ -7997,18 +9586,20 @@ export async function checkProject(cwd, env = process.env, options = {}) {
|
|
|
7997
9586
|
const issues = [];
|
|
7998
9587
|
const suggestions = new Set();
|
|
7999
9588
|
const warnings = [];
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
9589
|
+
let projectMetadata;
|
|
9590
|
+
try {
|
|
9591
|
+
projectMetadata = await readProjectPackageMetadata(cwd);
|
|
9592
|
+
}
|
|
9593
|
+
catch (error) {
|
|
8003
9594
|
return {
|
|
8004
|
-
issues: [
|
|
9595
|
+
issues: [error.message],
|
|
8005
9596
|
suggestions: [
|
|
8006
|
-
"Run `loom init` from a project
|
|
9597
|
+
"Run `loom init` from a project with package.json, deno.json, or deno.jsonc.",
|
|
8007
9598
|
],
|
|
8008
9599
|
warnings: [],
|
|
8009
9600
|
};
|
|
8010
9601
|
}
|
|
8011
|
-
const packageJson =
|
|
9602
|
+
const packageJson = projectMetadata.packageJson;
|
|
8012
9603
|
const npmrcText = await readTextIfExists(join(cwd, ".npmrc"));
|
|
8013
9604
|
if (removeLegacyLoomNpmrcText(npmrcText).changed) {
|
|
8014
9605
|
warnings.push(".npmrc retains Loom's obsolete GitHub Packages registry configuration.");
|
|
@@ -8017,7 +9608,7 @@ export async function checkProject(cwd, env = process.env, options = {}) {
|
|
|
8017
9608
|
const framework = await detectFramework(cwd, packageJson);
|
|
8018
9609
|
const dependency = packageJson.dependencies?.[LOOM_DEPENDENCY];
|
|
8019
9610
|
if (!dependency) {
|
|
8020
|
-
issues.push(`Missing ${LOOM_DEPENDENCY} in
|
|
9611
|
+
issues.push(`Missing ${LOOM_DEPENDENCY} in ${projectMetadata.config} dependencies/imports.`);
|
|
8021
9612
|
suggestions.add("Run `loom init`.");
|
|
8022
9613
|
}
|
|
8023
9614
|
else if (isLocalPackageSpec(dependency)) {
|
|
@@ -8034,6 +9625,26 @@ export async function checkProject(cwd, env = process.env, options = {}) {
|
|
|
8034
9625
|
manifest = parseJson(manifestText, "loom.json");
|
|
8035
9626
|
}
|
|
8036
9627
|
if (manifest) {
|
|
9628
|
+
let tooling = null;
|
|
9629
|
+
if (!manifest.project?.tooling) {
|
|
9630
|
+
warnings.push("loom.json does not record authoritative project tooling.");
|
|
9631
|
+
suggestions.add("Run `loom init` to adopt the detected project tooling.");
|
|
9632
|
+
}
|
|
9633
|
+
try {
|
|
9634
|
+
tooling = await detectProjectTooling(cwd, manifest.project?.tooling);
|
|
9635
|
+
}
|
|
9636
|
+
catch (error) {
|
|
9637
|
+
issues.push(`Invalid project tooling configuration: ${error.message}`);
|
|
9638
|
+
suggestions.add("Fix the recorded project.tooling config in loom.json.");
|
|
9639
|
+
}
|
|
9640
|
+
if (tooling) {
|
|
9641
|
+
for (const conflict of await findTaskConflicts(cwd, tooling.tasks)) {
|
|
9642
|
+
const deploymentWarning = conflict.name === "build"
|
|
9643
|
+
? " Deployment may invoke the wrong build task."
|
|
9644
|
+
: "";
|
|
9645
|
+
warnings.push(`Conflicting '${conflict.name}' tasks in ${conflict.authoritativeConfig} (authoritative) and ${conflict.secondaryConfig}.${deploymentWarning}`);
|
|
9646
|
+
}
|
|
9647
|
+
}
|
|
8037
9648
|
for (const [featureKey, feature] of Object.entries(manifest.features)) {
|
|
8038
9649
|
if (feature.status !== "active")
|
|
8039
9650
|
continue;
|
|
@@ -8065,7 +9676,7 @@ export async function checkProject(cwd, env = process.env, options = {}) {
|
|
|
8065
9676
|
for (const suggestion of agentsCheck.suggestions) {
|
|
8066
9677
|
suggestions.add(suggestion);
|
|
8067
9678
|
}
|
|
8068
|
-
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest
|
|
9679
|
+
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest);
|
|
8069
9680
|
for (const issue of envRunnerCheck.issues) {
|
|
8070
9681
|
issues.push(issue);
|
|
8071
9682
|
}
|
|
@@ -8119,13 +9730,16 @@ export async function checkProjectNetwork(cwd, env = process.env, options = {})
|
|
|
8119
9730
|
const suggestions = new Set();
|
|
8120
9731
|
const warnings = [];
|
|
8121
9732
|
const steps = [];
|
|
8122
|
-
|
|
8123
|
-
|
|
9733
|
+
let projectMetadata;
|
|
9734
|
+
try {
|
|
9735
|
+
projectMetadata = await readProjectPackageMetadata(cwd);
|
|
9736
|
+
}
|
|
9737
|
+
catch (error) {
|
|
8124
9738
|
return {
|
|
8125
|
-
issues: [
|
|
9739
|
+
issues: [error.message],
|
|
8126
9740
|
steps,
|
|
8127
9741
|
suggestions: [
|
|
8128
|
-
"Run `loom init` from a
|
|
9742
|
+
"Run `loom init` from a package.json or Deno project.",
|
|
8129
9743
|
],
|
|
8130
9744
|
warnings,
|
|
8131
9745
|
};
|
|
@@ -8139,7 +9753,7 @@ export async function checkProjectNetwork(cwd, env = process.env, options = {})
|
|
|
8139
9753
|
warnings,
|
|
8140
9754
|
};
|
|
8141
9755
|
}
|
|
8142
|
-
const packageJson =
|
|
9756
|
+
const packageJson = projectMetadata.packageJson;
|
|
8143
9757
|
const framework = await detectFramework(cwd, packageJson);
|
|
8144
9758
|
const manifest = parseJson(manifestText, "loom.json");
|
|
8145
9759
|
const context = {
|
|
@@ -8468,13 +10082,15 @@ function formatSkillLinkState(state) {
|
|
|
8468
10082
|
}
|
|
8469
10083
|
}
|
|
8470
10084
|
async function runStatus(cwd, io) {
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
10085
|
+
let projectMetadata;
|
|
10086
|
+
try {
|
|
10087
|
+
projectMetadata = await readProjectPackageMetadata(cwd);
|
|
10088
|
+
}
|
|
10089
|
+
catch (error) {
|
|
10090
|
+
io.err(error.message);
|
|
8475
10091
|
return 1;
|
|
8476
10092
|
}
|
|
8477
|
-
const packageJson =
|
|
10093
|
+
const packageJson = projectMetadata.packageJson;
|
|
8478
10094
|
const manifestText = await readTextIfExists(join(cwd, "loom.json"));
|
|
8479
10095
|
const manifest = manifestText
|
|
8480
10096
|
? parseJson(manifestText, "loom.json")
|
|
@@ -8489,6 +10105,19 @@ async function runStatus(cwd, io) {
|
|
|
8489
10105
|
: null;
|
|
8490
10106
|
const workspaceText = await readTextIfExists(join(cwd, "pnpm-workspace.yaml"));
|
|
8491
10107
|
const overrideSpec = getManagedDevOverrideSpec(workspaceText);
|
|
10108
|
+
let denoOverride = null;
|
|
10109
|
+
try {
|
|
10110
|
+
const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
|
|
10111
|
+
if (usesDenoTooling(tooling)) {
|
|
10112
|
+
const config = await getDenoConfigForLinks(cwd, tooling);
|
|
10113
|
+
const link = await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, config));
|
|
10114
|
+
if (link)
|
|
10115
|
+
denoOverride = { config, link: link.link };
|
|
10116
|
+
}
|
|
10117
|
+
}
|
|
10118
|
+
catch {
|
|
10119
|
+
// Status reports stored project data even when live detection fails.
|
|
10120
|
+
}
|
|
8492
10121
|
const localLockfileResolution = await getProjectLocalLoomLockfileResolution(cwd);
|
|
8493
10122
|
const devState = getManagedDevState(workspaceText) ??
|
|
8494
10123
|
await readLocalDevState(cwd);
|
|
@@ -8497,14 +10126,22 @@ async function runStatus(cwd, io) {
|
|
|
8497
10126
|
io.out(`Loom status for ${projectName}`);
|
|
8498
10127
|
io.out("");
|
|
8499
10128
|
io.out("Package:");
|
|
8500
|
-
io.out(`
|
|
10129
|
+
io.out(` ${projectMetadata.config}: ${dependencySpec ? `${LOOM_DEPENDENCY} ${dependencySpec}` : "not declared"}`);
|
|
8501
10130
|
io.out(` installed: ${installedPackage?.version ?? "not installed"}`);
|
|
8502
|
-
io.out(` local dev override: ${
|
|
10131
|
+
io.out(` local dev override: ${denoOverride
|
|
10132
|
+
? `active (${denoOverride.config} links ${denoOverride.link})`
|
|
10133
|
+
: overrideSpec
|
|
10134
|
+
? `active (${overrideSpec})`
|
|
10135
|
+
: "none"}`);
|
|
8503
10136
|
io.out(` lockfile local resolution: ${localLockfileResolution ?? "none"}`);
|
|
8504
10137
|
io.out("");
|
|
8505
10138
|
io.out("Project:");
|
|
8506
10139
|
io.out(` loom.json: ${manifest ? `version ${manifest.version}` : "missing"}`);
|
|
8507
10140
|
io.out(` framework: ${formatFrameworkInfo(framework)}`);
|
|
10141
|
+
if (manifest?.project?.tooling) {
|
|
10142
|
+
io.out(` tasks: ${manifest.project.tooling.tasks.config} via ${manifest.project.tooling.tasks.runner}`);
|
|
10143
|
+
io.out(` dependencies: ${manifest.project.tooling.dependencies.config} via ${manifest.project.tooling.dependencies.manager}`);
|
|
10144
|
+
}
|
|
8508
10145
|
io.out("");
|
|
8509
10146
|
io.out("Features:");
|
|
8510
10147
|
if (!manifest) {
|
|
@@ -8593,7 +10230,7 @@ function printHelp({ out }) {
|
|
|
8593
10230
|
out("loom <command>");
|
|
8594
10231
|
out("");
|
|
8595
10232
|
out("Commands:");
|
|
8596
|
-
out(" init Set up package
|
|
10233
|
+
out(" init Set up package/Deno config, loom.json, managed AGENTS.md guidance, first-party links, and package skills.");
|
|
8597
10234
|
out(" add <feature> Activate a shared feature. Run `loom add` to list available features.");
|
|
8598
10235
|
out(" files id-generation uuid-v4|uuid-v7 Select the managed Files schema ID default.");
|
|
8599
10236
|
out(" files r2 setup Create/reuse private Cloudflare R2 buckets, configure Vercel Production/Preview, and configure local MinIO by default.");
|
|
@@ -8615,8 +10252,8 @@ function printHelp({ out }) {
|
|
|
8615
10252
|
out(" db release setup-github Create/update GitHub production release config for staged Vercel deploys.");
|
|
8616
10253
|
out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
|
|
8617
10254
|
out(" db release verify-build-env <output> <manifest> Reject build-only placeholders in a deployable Vercel artifact.");
|
|
8618
|
-
out(" dev local Enable local Loom development using a managed
|
|
8619
|
-
out(" dev sync Rebuild
|
|
10255
|
+
out(" dev local Enable local Loom development using a managed pnpm override or Deno link.");
|
|
10256
|
+
out(" dev sync Rebuild local Loom and refresh this project's pnpm or Deno install when linked.");
|
|
8620
10257
|
out(" dev published Remove the managed local-dev override and return to the published dependency.");
|
|
8621
10258
|
out("");
|
|
8622
10259
|
out("Options:");
|
|
@@ -8855,12 +10492,15 @@ async function runSkills(cwd, command, args, io, options) {
|
|
|
8855
10492
|
printSkillsHelp(io);
|
|
8856
10493
|
return 0;
|
|
8857
10494
|
}
|
|
8858
|
-
|
|
8859
|
-
|
|
8860
|
-
|
|
10495
|
+
let projectMetadata;
|
|
10496
|
+
try {
|
|
10497
|
+
projectMetadata = await readProjectPackageMetadata(cwd);
|
|
10498
|
+
}
|
|
10499
|
+
catch (error) {
|
|
10500
|
+
io.err(error.message);
|
|
8861
10501
|
return 1;
|
|
8862
10502
|
}
|
|
8863
|
-
const packageJson =
|
|
10503
|
+
const packageJson = projectMetadata.packageJson;
|
|
8864
10504
|
const manifestText = await readTextIfExists(join(cwd, "loom.json"));
|
|
8865
10505
|
const manifest = manifestText
|
|
8866
10506
|
? parseJson(manifestText, "loom.json")
|
|
@@ -9028,7 +10668,16 @@ async function runDbSchemaGen(cwd, forwardedArgs, io) {
|
|
|
9028
10668
|
if (!isNodeErrorCode(error, "MODULE_NOT_FOUND")) {
|
|
9029
10669
|
throw error;
|
|
9030
10670
|
}
|
|
9031
|
-
|
|
10671
|
+
const manifest = await readManifestIfExists(cwd);
|
|
10672
|
+
const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
|
|
10673
|
+
if (usesDenoTooling(tooling)) {
|
|
10674
|
+
const formatExitCode = await runInheritedChild("deno", ["fmt", config.dirs.valibotGeneratedDir], cwd);
|
|
10675
|
+
if (formatExitCode !== 0)
|
|
10676
|
+
return formatExitCode;
|
|
10677
|
+
}
|
|
10678
|
+
else {
|
|
10679
|
+
io.out("Biome is not installed; generated Valibot files were left unformatted.");
|
|
10680
|
+
}
|
|
9032
10681
|
}
|
|
9033
10682
|
if (await syncValibotBarrel(cwd, config)) {
|
|
9034
10683
|
io.out(`Updated ${config.modules.valibotBarrelModule}.`);
|
|
@@ -9331,7 +10980,7 @@ async function runDev(cwd, mode, pathInput, io, options = {}) {
|
|
|
9331
10980
|
io.out(`Updated ${result.changedFiles.join(", ")}.`);
|
|
9332
10981
|
}
|
|
9333
10982
|
else if (result.notes.length) {
|
|
9334
|
-
io.out("Project
|
|
10983
|
+
io.out("Project config uses a published @gadicc/loom dependency, but follow-up is still needed.");
|
|
9335
10984
|
}
|
|
9336
10985
|
else {
|
|
9337
10986
|
io.out("Project already uses the published @gadicc/loom dependency.");
|