@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/script/src/cli/mod.js
CHANGED
|
@@ -80,6 +80,7 @@ const retention_js_1 = require("../apiKeys/retention.js");
|
|
|
80
80
|
const projectSkills_js_1 = require("./projectSkills.js");
|
|
81
81
|
const migrationEnv_js_1 = require("./migrationEnv.js");
|
|
82
82
|
const vercelBuildEnv_js_1 = require("./vercelBuildEnv.js");
|
|
83
|
+
const projectTooling_js_1 = require("./projectTooling.js");
|
|
83
84
|
exports.DEFAULT_LOOM_RANGE = "^1.0.0";
|
|
84
85
|
exports.LOOM_DEPENDENCY = "@gadicc/loom";
|
|
85
86
|
exports.LOOM_MANIFEST_SCHEMA = "https://loom.gadicc.local/project-manifest.schema.json";
|
|
@@ -167,6 +168,18 @@ const managedSkills = [
|
|
|
167
168
|
relativePackagePath: "skills/loom-files",
|
|
168
169
|
skillName: "loom-files",
|
|
169
170
|
},
|
|
171
|
+
{
|
|
172
|
+
featureKey: "mail",
|
|
173
|
+
label: "loom mail skill",
|
|
174
|
+
relativePackagePath: "skills/loom-mail",
|
|
175
|
+
skillName: "loom-mail",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
featureKey: "lingui",
|
|
179
|
+
label: "loom Lingui skill",
|
|
180
|
+
relativePackagePath: "skills/loom-lingui",
|
|
181
|
+
skillName: "loom-lingui",
|
|
182
|
+
},
|
|
170
183
|
];
|
|
171
184
|
const featureDefinitions = [
|
|
172
185
|
{
|
|
@@ -189,6 +202,14 @@ const featureDefinitions = [
|
|
|
189
202
|
key: "jobs",
|
|
190
203
|
description: "Shared App Router admin jobs pages, route handlers, direct-run helpers, and job controller wiring.",
|
|
191
204
|
},
|
|
205
|
+
{
|
|
206
|
+
key: "lingui",
|
|
207
|
+
description: "Lingui catalog source policy, generated-catalog ignores, dependencies, tasks, and build wiring.",
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
key: "mail",
|
|
211
|
+
description: "Durable outgoing mail, Postal transport/webhooks, and admin-gated test-mail UI.",
|
|
212
|
+
},
|
|
192
213
|
{
|
|
193
214
|
key: "pwa",
|
|
194
215
|
description: "Shared Serwist PWA worker, provider lifecycle, update prompts, and build wiring.",
|
|
@@ -240,6 +261,13 @@ const DEFAULT_MINIO_ENDPOINT = "http://127.0.0.1:9000";
|
|
|
240
261
|
const API_KEY_AUDIT_SCHEMA_BLUEPRINT_VERSION = 3;
|
|
241
262
|
const API_KEY_AUDIT_SCHEMA_DEFAULT_EXPORT = "loomApiKeyAuditEventsTable";
|
|
242
263
|
const API_KEY_AUDIT_SCHEMA_DEFAULT_TABLE = "loom_api_key_audit_events";
|
|
264
|
+
const MAIL_SCHEMA_BLUEPRINT_VERSION = 1;
|
|
265
|
+
const MAIL_SCHEMA_DEFAULT_EXPORTS = [
|
|
266
|
+
"loomMailMessagesTable",
|
|
267
|
+
"loomMailDeliveriesTable",
|
|
268
|
+
"loomMailEventsTable",
|
|
269
|
+
];
|
|
270
|
+
const MAIL_SCHEMA_DEFAULT_TABLE = "loom_mail_messages";
|
|
243
271
|
const PWA_DEFAULT_DEPENDENCIES = {
|
|
244
272
|
"@serwist/next": "^9.5.11",
|
|
245
273
|
};
|
|
@@ -255,6 +283,30 @@ const PWA_GITIGNORE_LINES = [
|
|
|
255
283
|
"/public/workbox-*.js",
|
|
256
284
|
"/public/workbox-*.js.map",
|
|
257
285
|
];
|
|
286
|
+
const LINGUI_DEFAULT_DEPENDENCIES = {
|
|
287
|
+
"@lingui/core": "^6.5.0",
|
|
288
|
+
"@lingui/react": "^6.5.0",
|
|
289
|
+
};
|
|
290
|
+
const LINGUI_DEFAULT_DEV_DEPENDENCIES = {
|
|
291
|
+
"@lingui/cli": "^6.5.0",
|
|
292
|
+
"@lingui/format-po": "^6.5.0",
|
|
293
|
+
"@lingui/swc-plugin": "^6.5.0",
|
|
294
|
+
};
|
|
295
|
+
const LINGUI_LOADER_DEV_DEPENDENCIES = {
|
|
296
|
+
"@lingui/loader": "^6.5.0",
|
|
297
|
+
};
|
|
298
|
+
const LINGUI_CONFIG_CANDIDATES = [
|
|
299
|
+
"lingui.config.ts",
|
|
300
|
+
"lingui.config.js",
|
|
301
|
+
"lingui.config.mts",
|
|
302
|
+
"lingui.config.mjs",
|
|
303
|
+
"lingui.config.cjs",
|
|
304
|
+
];
|
|
305
|
+
const LINGUI_DEFAULT_TASKS = {
|
|
306
|
+
build: "build",
|
|
307
|
+
compile: "i18n:compile",
|
|
308
|
+
extract: "i18n:extract",
|
|
309
|
+
};
|
|
258
310
|
const PWA_UPDATE_PROMPT = "A newer version of this web app is available. Reload to update?";
|
|
259
311
|
const DB_CONNECTION_ENV_NAMES = [
|
|
260
312
|
"DATABASE_URL",
|
|
@@ -382,11 +434,14 @@ async function readManifestFramework(cwd) {
|
|
|
382
434
|
if (manifest?.project?.framework) {
|
|
383
435
|
return manifest.project.framework;
|
|
384
436
|
}
|
|
385
|
-
|
|
386
|
-
|
|
437
|
+
let metadata;
|
|
438
|
+
try {
|
|
439
|
+
metadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
387
442
|
return null;
|
|
388
443
|
}
|
|
389
|
-
return await detectFramework(cwd,
|
|
444
|
+
return await detectFramework(cwd, metadata.packageJson);
|
|
390
445
|
}
|
|
391
446
|
async function loadProjectEnv(cwd) {
|
|
392
447
|
const framework = await readManifestFramework(cwd);
|
|
@@ -482,7 +537,8 @@ function dbScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
|
482
537
|
return false;
|
|
483
538
|
}
|
|
484
539
|
return !scriptUsesLoomEnvRunner(scriptCommand) &&
|
|
485
|
-
!/\
|
|
540
|
+
!/\b(?:pnpm|yarn|npx)\s+drizzle-kit\b/.test(scriptCommand) &&
|
|
541
|
+
!/\bdeno\s+run\s+-A\s+npm:drizzle-kit\b/.test(scriptCommand);
|
|
486
542
|
}
|
|
487
543
|
function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
488
544
|
if (!scriptCommand) {
|
|
@@ -491,7 +547,7 @@ function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
|
|
|
491
547
|
return (scriptName === "job" || scriptCommand.includes("jobDirect.ts")) &&
|
|
492
548
|
!scriptUsesLoomEnvRunner(scriptCommand);
|
|
493
549
|
}
|
|
494
|
-
async function checkEnvRunnerAdoption(cwd, manifest
|
|
550
|
+
async function checkEnvRunnerAdoption(cwd, manifest) {
|
|
495
551
|
const issues = [];
|
|
496
552
|
const suggestions = new Set();
|
|
497
553
|
const activeDb = manifest.features.db?.status === "active";
|
|
@@ -506,14 +562,25 @@ async function checkEnvRunnerAdoption(cwd, manifest, packageJson) {
|
|
|
506
562
|
if (directEnvLoaderFiles.length) {
|
|
507
563
|
suggestions.add("Move env loading into package scripts with `loom env -- <command>` and remove `dotenv`/`@next/env` imports from implementation files.");
|
|
508
564
|
}
|
|
509
|
-
|
|
565
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
566
|
+
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
567
|
+
for (const [scriptName, definition] of Object.entries(taskStore.definitions)) {
|
|
568
|
+
const scriptCommand = (0, projectTooling_js_1.getTaskCommand)(definition);
|
|
510
569
|
if (activeDb && dbScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
511
|
-
issues.push(
|
|
512
|
-
|
|
570
|
+
issues.push(taskStore.config === "package.json"
|
|
571
|
+
? `DB package.json script bypasses the Loom env runner: ${scriptName}`
|
|
572
|
+
: `DB task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
573
|
+
suggestions.add(taskStore.config === "package.json"
|
|
574
|
+
? "Run `loom add db` to refresh DB package scripts."
|
|
575
|
+
: "Run `loom add db` to refresh DB tasks.");
|
|
513
576
|
}
|
|
514
577
|
if (activeJobs && jobsScriptBypassesEnvRunner(scriptName, scriptCommand)) {
|
|
515
|
-
issues.push(
|
|
516
|
-
|
|
578
|
+
issues.push(taskStore.config === "package.json"
|
|
579
|
+
? `Jobs package.json script bypasses the Loom env runner: ${scriptName}`
|
|
580
|
+
: `Jobs task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
|
|
581
|
+
suggestions.add(taskStore.config === "package.json"
|
|
582
|
+
? "Run `loom add jobs` to refresh jobs package scripts."
|
|
583
|
+
: "Run `loom add jobs` to refresh jobs tasks.");
|
|
517
584
|
}
|
|
518
585
|
}
|
|
519
586
|
return {
|
|
@@ -778,6 +845,29 @@ function ensurePwaGitignoreText(existingText) {
|
|
|
778
845
|
text: nextText,
|
|
779
846
|
};
|
|
780
847
|
}
|
|
848
|
+
function normalizeGitignorePattern(pattern) {
|
|
849
|
+
return pattern.trim().replaceAll("\\", "/").replace(/^\.\//, "");
|
|
850
|
+
}
|
|
851
|
+
function linguiGitignoreLineMatches(line, expectedLine) {
|
|
852
|
+
const normalized = normalizeGitignorePattern(line).replace(/^\//, "");
|
|
853
|
+
const expected = normalizeGitignorePattern(expectedLine).replace(/^\//, "");
|
|
854
|
+
return normalized === expected;
|
|
855
|
+
}
|
|
856
|
+
function ensureLinguiGitignoreText(existingText, generatedCatalogs) {
|
|
857
|
+
const normalized = existingText ? normalizeText(existingText) : "";
|
|
858
|
+
const lines = normalized
|
|
859
|
+
.split("\n")
|
|
860
|
+
.filter((line, index, array) => index < array.length - 1 || line !== "");
|
|
861
|
+
const missingLines = generatedCatalogs.filter((expectedLine) => !lines.some((line) => linguiGitignoreLineMatches(line, expectedLine)));
|
|
862
|
+
const nextText = missingLines.length
|
|
863
|
+
? `${[...lines, ...missingLines].join("\n")}\n`
|
|
864
|
+
: normalized;
|
|
865
|
+
return {
|
|
866
|
+
changed: nextText !== normalized,
|
|
867
|
+
missingLines,
|
|
868
|
+
text: nextText,
|
|
869
|
+
};
|
|
870
|
+
}
|
|
781
871
|
function loomDevStateGitignoreLineMatches(line) {
|
|
782
872
|
const normalized = line.trim().replace(/^\/?/, "");
|
|
783
873
|
return normalized === exports.LOOM_LOCAL_DEV_STATE_GITIGNORE_LINE ||
|
|
@@ -811,58 +901,30 @@ function ensurePackageJsonDependency(packageJson, versionRange = exports.DEFAULT
|
|
|
811
901
|
previous: current,
|
|
812
902
|
};
|
|
813
903
|
}
|
|
814
|
-
function
|
|
815
|
-
|
|
816
|
-
nextPackageJson[field] ??= {};
|
|
817
|
-
const changedKeys = [];
|
|
818
|
-
for (const [dependencyName, versionRange] of Object.entries(dependencies)) {
|
|
819
|
-
if (!nextPackageJson[field][dependencyName]) {
|
|
820
|
-
nextPackageJson[field][dependencyName] = versionRange;
|
|
821
|
-
changedKeys.push(dependencyName);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return {
|
|
825
|
-
changed: changedKeys.length > 0,
|
|
826
|
-
changedKeys,
|
|
827
|
-
packageJson: nextPackageJson,
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
function removePackageJsonDependencies(packageJson, dependencyNames) {
|
|
831
|
-
const nextPackageJson = structuredClone(packageJson);
|
|
832
|
-
const removedKeys = [];
|
|
833
|
-
for (const dependencyName of dependencyNames) {
|
|
834
|
-
if (nextPackageJson.dependencies?.[dependencyName]) {
|
|
835
|
-
delete nextPackageJson.dependencies[dependencyName];
|
|
836
|
-
removedKeys.push(dependencyName);
|
|
837
|
-
}
|
|
838
|
-
if (nextPackageJson.devDependencies?.[dependencyName]) {
|
|
839
|
-
delete nextPackageJson.devDependencies[dependencyName];
|
|
840
|
-
removedKeys.push(dependencyName);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
return {
|
|
844
|
-
changed: removedKeys.length > 0,
|
|
845
|
-
packageJson: nextPackageJson,
|
|
846
|
-
removedKeys,
|
|
847
|
-
};
|
|
904
|
+
async function getProjectTooling(cwd, manifest) {
|
|
905
|
+
return await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest.project?.tooling);
|
|
848
906
|
}
|
|
849
|
-
function
|
|
850
|
-
const
|
|
851
|
-
nextPackageJson.scripts ??= {};
|
|
907
|
+
async function ensureProjectTasks(cwd, manifest, tasks) {
|
|
908
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
852
909
|
const changedKeys = [];
|
|
853
|
-
for (const [
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
changedKeys.push(
|
|
857
|
-
}
|
|
910
|
+
for (const [name, definition] of Object.entries(tasks)) {
|
|
911
|
+
const result = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, { definition, name });
|
|
912
|
+
if (result.changed)
|
|
913
|
+
changedKeys.push(name);
|
|
858
914
|
}
|
|
915
|
+
return { changedKeys, config: tooling.tasks.config, tooling };
|
|
916
|
+
}
|
|
917
|
+
async function checkProjectTasks(cwd, manifest, expected) {
|
|
918
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
919
|
+
const store = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
859
920
|
return {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
921
|
+
config: tooling.tasks.config,
|
|
922
|
+
mismatches: Object.entries(expected).flatMap(([name, command]) => (0, projectTooling_js_1.getTaskCommand)(store.definitions[name]) === command ? [] : [name]),
|
|
923
|
+
store,
|
|
924
|
+
tooling,
|
|
863
925
|
};
|
|
864
926
|
}
|
|
865
|
-
function buildManifest(cwd, packageJson, framework, existingManifest) {
|
|
927
|
+
function buildManifest(cwd, packageJson, framework, existingManifest, tooling) {
|
|
866
928
|
return {
|
|
867
929
|
$schema: existingManifest?.$schema ?? exports.LOOM_MANIFEST_SCHEMA,
|
|
868
930
|
version: 1,
|
|
@@ -874,6 +936,7 @@ function buildManifest(cwd, packageJson, framework, existingManifest) {
|
|
|
874
936
|
...existingManifest?.project?.framework,
|
|
875
937
|
...framework,
|
|
876
938
|
},
|
|
939
|
+
tooling: existingManifest?.project?.tooling ?? tooling,
|
|
877
940
|
},
|
|
878
941
|
features: existingManifest?.features ?? {},
|
|
879
942
|
};
|
|
@@ -893,33 +956,6 @@ function hasPackageDependency(packageJson, dependencyName) {
|
|
|
893
956
|
return Boolean(packageJson.dependencies?.[dependencyName] ||
|
|
894
957
|
packageJson.devDependencies?.[dependencyName]);
|
|
895
958
|
}
|
|
896
|
-
async function detectPackageManager(cwd, packageJson) {
|
|
897
|
-
if (packageJson.packageManager?.startsWith("pnpm@")) {
|
|
898
|
-
return "pnpm";
|
|
899
|
-
}
|
|
900
|
-
if (packageJson.packageManager?.startsWith("yarn@")) {
|
|
901
|
-
return "yarn";
|
|
902
|
-
}
|
|
903
|
-
if (packageJson.packageManager?.startsWith("npm@")) {
|
|
904
|
-
return "npm";
|
|
905
|
-
}
|
|
906
|
-
if (await exists((0, node_path_1.join)(cwd, "pnpm-lock.yaml"))) {
|
|
907
|
-
return "pnpm";
|
|
908
|
-
}
|
|
909
|
-
if (await exists((0, node_path_1.join)(cwd, "yarn.lock"))) {
|
|
910
|
-
return "yarn";
|
|
911
|
-
}
|
|
912
|
-
return "npm";
|
|
913
|
-
}
|
|
914
|
-
function getRunScriptCommand(packageManager, scriptName) {
|
|
915
|
-
if (packageManager === "pnpm") {
|
|
916
|
-
return `pnpm ${scriptName}`;
|
|
917
|
-
}
|
|
918
|
-
if (packageManager === "yarn") {
|
|
919
|
-
return `yarn ${scriptName}`;
|
|
920
|
-
}
|
|
921
|
-
return `npm run ${scriptName}`;
|
|
922
|
-
}
|
|
923
959
|
function scriptRunsSerwistBuild(script) {
|
|
924
960
|
return Boolean(script && (/\bserwist\s+build\b/.test(script) ||
|
|
925
961
|
script.includes("@serwist/cli") ||
|
|
@@ -934,35 +970,6 @@ function formatTsNumberLiteral(value) {
|
|
|
934
970
|
function numberLiteralRegExp(value) {
|
|
935
971
|
return String(value).split("").map((digit) => `${digit}_?`).join("");
|
|
936
972
|
}
|
|
937
|
-
function ensurePwaPackageJsonScripts(packageJson, packageManager) {
|
|
938
|
-
const nextPackageJson = structuredClone(packageJson);
|
|
939
|
-
nextPackageJson.scripts ??= {};
|
|
940
|
-
const changedKeys = [];
|
|
941
|
-
const notes = [];
|
|
942
|
-
if (nextPackageJson.scripts["pwa:build"] !== PWA_BUILD_SCRIPT) {
|
|
943
|
-
nextPackageJson.scripts["pwa:build"] = PWA_BUILD_SCRIPT;
|
|
944
|
-
changedKeys.push("pwa:build");
|
|
945
|
-
}
|
|
946
|
-
const buildScript = nextPackageJson.scripts.build;
|
|
947
|
-
if (!buildScript) {
|
|
948
|
-
nextPackageJson.scripts.build = `next build && ${getRunScriptCommand(packageManager, "pwa:build")}`;
|
|
949
|
-
changedKeys.push("build");
|
|
950
|
-
}
|
|
951
|
-
else if (buildScript.includes("next build") &&
|
|
952
|
-
!scriptRunsSerwistBuild(buildScript)) {
|
|
953
|
-
nextPackageJson.scripts.build = `${buildScript} && ${getRunScriptCommand(packageManager, "pwa:build")}`;
|
|
954
|
-
changedKeys.push("build");
|
|
955
|
-
}
|
|
956
|
-
else if (!scriptRunsSerwistBuild(buildScript)) {
|
|
957
|
-
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.");
|
|
958
|
-
}
|
|
959
|
-
return {
|
|
960
|
-
changed: changedKeys.length > 0,
|
|
961
|
-
changedKeys,
|
|
962
|
-
notes,
|
|
963
|
-
packageJson: nextPackageJson,
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
973
|
function getJobsConfig(framework) {
|
|
967
974
|
const appRoot = framework.srcDir ? "src/app" : "app";
|
|
968
975
|
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
@@ -1205,12 +1212,37 @@ async function mergeAuthConfig(cwd, framework, featureConfig) {
|
|
|
1205
1212
|
},
|
|
1206
1213
|
};
|
|
1207
1214
|
}
|
|
1208
|
-
function
|
|
1215
|
+
function dependencyExecutable(tooling, executable) {
|
|
1216
|
+
switch (tooling.manager) {
|
|
1217
|
+
case "deno":
|
|
1218
|
+
return `deno run -A npm:${executable}`;
|
|
1219
|
+
case "npm":
|
|
1220
|
+
return `npx ${executable}`;
|
|
1221
|
+
case "pnpm":
|
|
1222
|
+
return `pnpm ${executable}`;
|
|
1223
|
+
case "yarn":
|
|
1224
|
+
return `yarn ${executable}`;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
function dependencyRefreshCommand(tooling, name, version) {
|
|
1228
|
+
switch (tooling.manager) {
|
|
1229
|
+
case "deno":
|
|
1230
|
+
return "deno install";
|
|
1231
|
+
case "npm":
|
|
1232
|
+
return `npm install --save-exact ${name}@${version}`;
|
|
1233
|
+
case "pnpm":
|
|
1234
|
+
return `pnpm update --no-save ${name}@${version} && pnpm install`;
|
|
1235
|
+
case "yarn":
|
|
1236
|
+
return `yarn add --exact ${name}@${version}`;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function getDbExpectedScripts(config, tooling) {
|
|
1240
|
+
const drizzleKit = dependencyExecutable(tooling.dependencies, "drizzle-kit");
|
|
1209
1241
|
return {
|
|
1210
1242
|
"db:fixtures": "loom db fixtures",
|
|
1211
|
-
"db:generate":
|
|
1212
|
-
"db:migrate":
|
|
1213
|
-
"db:push":
|
|
1243
|
+
"db:generate": `${drizzleKit} generate`,
|
|
1244
|
+
"db:migrate": `${drizzleKit} migrate`,
|
|
1245
|
+
"db:push": `${drizzleKit} push`,
|
|
1214
1246
|
"drizzle-kit": `NODE_OPTIONS='--import tsx' loom env -- drizzle-kit --config=./${config.modules.drizzleConfig}`,
|
|
1215
1247
|
"schema:gen": "loom db schema-gen",
|
|
1216
1248
|
};
|
|
@@ -1487,6 +1519,145 @@ export const ${exportName} = pgTable(
|
|
|
1487
1519
|
);
|
|
1488
1520
|
`;
|
|
1489
1521
|
}
|
|
1522
|
+
function buildMailSchemaText(config) {
|
|
1523
|
+
const [messagesExport, deliveriesExport, eventsExport] = [
|
|
1524
|
+
config.exports[0] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[0],
|
|
1525
|
+
config.exports[1] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[1],
|
|
1526
|
+
config.exports[2] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[2],
|
|
1527
|
+
];
|
|
1528
|
+
const messagesTable = config.tableName;
|
|
1529
|
+
const tablePrefix = messagesTable.endsWith("_messages")
|
|
1530
|
+
? messagesTable.slice(0, -"_messages".length)
|
|
1531
|
+
: messagesTable;
|
|
1532
|
+
const deliveriesTable = `${tablePrefix}_deliveries`;
|
|
1533
|
+
const eventsTable = `${tablePrefix}_events`;
|
|
1534
|
+
const indexName = (table, suffix) => filesSchemaIndexName(table, suffix);
|
|
1535
|
+
return `import { sql } from "drizzle-orm";
|
|
1536
|
+
import {
|
|
1537
|
+
index,
|
|
1538
|
+
integer,
|
|
1539
|
+
jsonb,
|
|
1540
|
+
pgTable,
|
|
1541
|
+
text,
|
|
1542
|
+
timestamp,
|
|
1543
|
+
uniqueIndex,
|
|
1544
|
+
uuid,
|
|
1545
|
+
} from "drizzle-orm/pg-core";
|
|
1546
|
+
|
|
1547
|
+
// Loom-managed schema blueprint: mail v${MAIL_SCHEMA_BLUEPRINT_VERSION}.
|
|
1548
|
+
// Keep app-specific domain associations in separate local schema files.
|
|
1549
|
+
export const ${messagesExport} = pgTable(
|
|
1550
|
+
"${messagesTable}",
|
|
1551
|
+
{
|
|
1552
|
+
id: uuid("id").default(sql\`uuid_generate_v7()\`).primaryKey(),
|
|
1553
|
+
provider: text("provider").notNull(),
|
|
1554
|
+
status: text("status").notNull().default("queued"),
|
|
1555
|
+
fromEmail: text("from_email").notNull(),
|
|
1556
|
+
fromName: text("from_name"),
|
|
1557
|
+
to: jsonb("to").notNull().$type<string[]>().default(sql\`'[]'::jsonb\`),
|
|
1558
|
+
cc: jsonb("cc").notNull().$type<string[]>().default(sql\`'[]'::jsonb\`),
|
|
1559
|
+
bcc: jsonb("bcc").notNull().$type<string[]>().default(sql\`'[]'::jsonb\`),
|
|
1560
|
+
subject: text("subject").notNull(),
|
|
1561
|
+
plainBody: text("plain_body"),
|
|
1562
|
+
htmlBody: text("html_body"),
|
|
1563
|
+
replyTo: text("reply_to"),
|
|
1564
|
+
tag: text("tag"),
|
|
1565
|
+
headers: jsonb("headers").notNull().$type<Record<string, string>>()
|
|
1566
|
+
.default(sql\`'{}'::jsonb\`),
|
|
1567
|
+
attachments: jsonb("attachments").notNull()
|
|
1568
|
+
.$type<Array<{ contentType?: string | null; data: string; name: string }>>()
|
|
1569
|
+
.default(sql\`'[]'::jsonb\`),
|
|
1570
|
+
metadata: jsonb("metadata").notNull().$type<Record<string, unknown>>()
|
|
1571
|
+
.default(sql\`'{}'::jsonb\`),
|
|
1572
|
+
providerMessageId: text("provider_message_id"),
|
|
1573
|
+
attemptCount: integer("attempt_count").notNull().default(0),
|
|
1574
|
+
availableAt: timestamp("available_at", { mode: "date", withTimezone: true })
|
|
1575
|
+
.notNull().defaultNow(),
|
|
1576
|
+
leaseToken: text("lease_token"),
|
|
1577
|
+
leaseExpiresAt: timestamp("lease_expires_at", { mode: "date", withTimezone: true }),
|
|
1578
|
+
lastErrorCode: text("last_error_code"),
|
|
1579
|
+
lastErrorMessage: text("last_error_message"),
|
|
1580
|
+
sentAt: timestamp("sent_at", { mode: "date", withTimezone: true }),
|
|
1581
|
+
failedAt: timestamp("failed_at", { mode: "date", withTimezone: true }),
|
|
1582
|
+
deliveredAt: timestamp("delivered_at", { mode: "date", withTimezone: true }),
|
|
1583
|
+
cancelledAt: timestamp("cancelled_at", { mode: "date", withTimezone: true }),
|
|
1584
|
+
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
|
|
1585
|
+
.notNull().defaultNow(),
|
|
1586
|
+
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true })
|
|
1587
|
+
.notNull().defaultNow(),
|
|
1588
|
+
},
|
|
1589
|
+
(table) => [
|
|
1590
|
+
index("${indexName(messagesTable, "outbox_idx")}").on(
|
|
1591
|
+
table.status,
|
|
1592
|
+
table.availableAt,
|
|
1593
|
+
table.leaseExpiresAt,
|
|
1594
|
+
),
|
|
1595
|
+
index("${indexName(messagesTable, "provider_message_idx")}").on(
|
|
1596
|
+
table.provider,
|
|
1597
|
+
table.providerMessageId,
|
|
1598
|
+
),
|
|
1599
|
+
index("${indexName(messagesTable, "created_idx")}").on(table.createdAt),
|
|
1600
|
+
],
|
|
1601
|
+
);
|
|
1602
|
+
|
|
1603
|
+
export const ${deliveriesExport} = pgTable(
|
|
1604
|
+
"${deliveriesTable}",
|
|
1605
|
+
{
|
|
1606
|
+
id: uuid("id").default(sql\`uuid_generate_v7()\`).primaryKey(),
|
|
1607
|
+
messageId: uuid("message_id").notNull()
|
|
1608
|
+
.references(() => ${messagesExport}.id, { onDelete: "cascade" }),
|
|
1609
|
+
kind: text("kind").notNull(),
|
|
1610
|
+
email: text("email").notNull(),
|
|
1611
|
+
status: text("status").notNull().default("queued"),
|
|
1612
|
+
providerDeliveryId: text("provider_delivery_id"),
|
|
1613
|
+
providerToken: text("provider_token"),
|
|
1614
|
+
lastErrorCode: text("last_error_code"),
|
|
1615
|
+
lastErrorMessage: text("last_error_message"),
|
|
1616
|
+
deliveredAt: timestamp("delivered_at", { mode: "date", withTimezone: true }),
|
|
1617
|
+
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
|
|
1618
|
+
.notNull().defaultNow(),
|
|
1619
|
+
updatedAt: timestamp("updated_at", { mode: "date", withTimezone: true })
|
|
1620
|
+
.notNull().defaultNow(),
|
|
1621
|
+
},
|
|
1622
|
+
(table) => [
|
|
1623
|
+
index("${indexName(deliveriesTable, "message_idx")}").on(table.messageId),
|
|
1624
|
+
index("${indexName(deliveriesTable, "provider_delivery_idx")}").on(
|
|
1625
|
+
table.providerDeliveryId,
|
|
1626
|
+
),
|
|
1627
|
+
index("${indexName(deliveriesTable, "recipient_idx")}").on(table.email),
|
|
1628
|
+
],
|
|
1629
|
+
);
|
|
1630
|
+
|
|
1631
|
+
export const ${eventsExport} = pgTable(
|
|
1632
|
+
"${eventsTable}",
|
|
1633
|
+
{
|
|
1634
|
+
id: uuid("id").default(sql\`uuid_generate_v7()\`).primaryKey(),
|
|
1635
|
+
messageId: uuid("message_id").notNull()
|
|
1636
|
+
.references(() => ${messagesExport}.id, { onDelete: "cascade" }),
|
|
1637
|
+
deliveryId: uuid("delivery_id")
|
|
1638
|
+
.references(() => ${deliveriesExport}.id, { onDelete: "set null" }),
|
|
1639
|
+
provider: text("provider").notNull(),
|
|
1640
|
+
providerEventId: text("provider_event_id"),
|
|
1641
|
+
eventType: text("event_type").notNull(),
|
|
1642
|
+
sourceEvent: text("source_event").notNull(),
|
|
1643
|
+
payload: jsonb("payload").notNull().$type<Record<string, unknown>>()
|
|
1644
|
+
.default(sql\`'{}'::jsonb\`),
|
|
1645
|
+
occurredAt: timestamp("occurred_at", { mode: "date", withTimezone: true })
|
|
1646
|
+
.notNull().defaultNow(),
|
|
1647
|
+
},
|
|
1648
|
+
(table) => [
|
|
1649
|
+
index("${indexName(eventsTable, "message_occurred_idx")}").on(
|
|
1650
|
+
table.messageId,
|
|
1651
|
+
table.occurredAt,
|
|
1652
|
+
),
|
|
1653
|
+
uniqueIndex("${indexName(eventsTable, "provider_event_unique")}").on(
|
|
1654
|
+
table.provider,
|
|
1655
|
+
table.providerEventId,
|
|
1656
|
+
),
|
|
1657
|
+
],
|
|
1658
|
+
);
|
|
1659
|
+
`;
|
|
1660
|
+
}
|
|
1490
1661
|
function getFilesDefaultSchemaConfig(dbConfig) {
|
|
1491
1662
|
const baseConfig = {
|
|
1492
1663
|
blueprint: "files",
|
|
@@ -1502,6 +1673,20 @@ function getFilesDefaultSchemaConfig(dbConfig) {
|
|
|
1502
1673
|
hash: hashManagedSchemaText(buildFilesSchemaText(baseConfig)),
|
|
1503
1674
|
};
|
|
1504
1675
|
}
|
|
1676
|
+
function getMailDefaultSchemaConfig(dbConfig) {
|
|
1677
|
+
const baseConfig = {
|
|
1678
|
+
blueprint: "mail",
|
|
1679
|
+
exports: [...MAIL_SCHEMA_DEFAULT_EXPORTS],
|
|
1680
|
+
mode: "managed-local",
|
|
1681
|
+
module: (0, node_path_1.join)(dbConfig.dirs.schemaDir, "loomMail.ts"),
|
|
1682
|
+
tableName: MAIL_SCHEMA_DEFAULT_TABLE,
|
|
1683
|
+
version: MAIL_SCHEMA_BLUEPRINT_VERSION,
|
|
1684
|
+
};
|
|
1685
|
+
return {
|
|
1686
|
+
...baseConfig,
|
|
1687
|
+
hash: hashManagedSchemaText(buildMailSchemaText(baseConfig)),
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1505
1690
|
function getApiKeysDefaultSchemaConfig(dbConfig) {
|
|
1506
1691
|
const baseConfig = {
|
|
1507
1692
|
blueprint: "api-key-audit",
|
|
@@ -1597,6 +1782,23 @@ function mergeManagedLocalSchemaConfig(dbConfig, schemaConfig) {
|
|
|
1597
1782
|
hashManagedSchemaText(buildFilesSchemaText(merged)),
|
|
1598
1783
|
};
|
|
1599
1784
|
}
|
|
1785
|
+
function mergeMailSchemaConfig(dbConfig, schemaConfig) {
|
|
1786
|
+
const defaults = getMailDefaultSchemaConfig(dbConfig);
|
|
1787
|
+
const merged = {
|
|
1788
|
+
...defaults,
|
|
1789
|
+
...schemaConfig,
|
|
1790
|
+
blueprint: "mail",
|
|
1791
|
+
exports: schemaConfig?.exports?.length === 3
|
|
1792
|
+
? schemaConfig.exports
|
|
1793
|
+
: defaults.exports,
|
|
1794
|
+
mode: "managed-local",
|
|
1795
|
+
};
|
|
1796
|
+
return {
|
|
1797
|
+
...merged,
|
|
1798
|
+
hash: schemaConfig?.hash ??
|
|
1799
|
+
hashManagedSchemaText(buildMailSchemaText(merged)),
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1600
1802
|
function getFilesConfig(framework, dbConfig, featureConfig) {
|
|
1601
1803
|
const appRoot = framework.srcDir ? "src/app" : "app";
|
|
1602
1804
|
const filesRoot = framework.srcDir ? "src/files" : "files";
|
|
@@ -1620,6 +1822,44 @@ function getFilesConfig(framework, dbConfig, featureConfig) {
|
|
|
1620
1822
|
},
|
|
1621
1823
|
};
|
|
1622
1824
|
}
|
|
1825
|
+
function getMailConfig(framework, dbConfig, packageJson, featureConfig, jobsActive) {
|
|
1826
|
+
const appRoot = framework.srcDir ? "src/app" : "app";
|
|
1827
|
+
const mailRoot = framework.srcDir ? "src/mail" : "mail";
|
|
1828
|
+
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
1829
|
+
return {
|
|
1830
|
+
entrypoints: {
|
|
1831
|
+
adminPage: featureConfig?.entrypoints?.adminPage ??
|
|
1832
|
+
`${appRoot}/admin/mail/page.tsx`,
|
|
1833
|
+
webhookRoute: featureConfig?.entrypoints?.webhookRoute ??
|
|
1834
|
+
`${appRoot}/api/mail/postal/route.ts`,
|
|
1835
|
+
},
|
|
1836
|
+
jobs: {
|
|
1837
|
+
enabled: featureConfig?.jobs?.enabled ?? jobsActive,
|
|
1838
|
+
},
|
|
1839
|
+
modules: {
|
|
1840
|
+
accessModule: featureConfig?.modules?.accessModule ??
|
|
1841
|
+
`${mailRoot}/access.ts`,
|
|
1842
|
+
actionsModule: featureConfig?.modules?.actionsModule ??
|
|
1843
|
+
`${mailRoot}/actions.ts`,
|
|
1844
|
+
jobModule: featureConfig?.modules?.jobModule ??
|
|
1845
|
+
`${jobsRoot}/mail-drain.ts`,
|
|
1846
|
+
repositoryModule: featureConfig?.modules?.repositoryModule ??
|
|
1847
|
+
`${mailRoot}/repository.ts`,
|
|
1848
|
+
serviceModule: featureConfig?.modules?.serviceModule ??
|
|
1849
|
+
`${mailRoot}/service.ts`,
|
|
1850
|
+
transportModule: featureConfig?.modules?.transportModule ??
|
|
1851
|
+
`${mailRoot}/transport.ts`,
|
|
1852
|
+
},
|
|
1853
|
+
provider: "postal",
|
|
1854
|
+
schema: mergeMailSchemaConfig(dbConfig, featureConfig?.schema),
|
|
1855
|
+
ui: {
|
|
1856
|
+
adapter: featureConfig?.ui?.adapter ??
|
|
1857
|
+
(hasPackageDependency(packageJson, "@mui/material")
|
|
1858
|
+
? "mui"
|
|
1859
|
+
: "headless"),
|
|
1860
|
+
},
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1623
1863
|
function normalizeText(text) {
|
|
1624
1864
|
return text.replaceAll("\r\n", "\n");
|
|
1625
1865
|
}
|
|
@@ -1635,9 +1875,10 @@ For all work in this repo:
|
|
|
1635
1875
|
1. Use the \`loom\` skill first.
|
|
1636
1876
|
2. Read \`loom.json\` before making Loom-related changes.
|
|
1637
1877
|
3. Treat active Loom features and configured paths as the contract between the app and the shared package.
|
|
1638
|
-
4.
|
|
1639
|
-
5.
|
|
1640
|
-
6.
|
|
1878
|
+
4. Read \`project.tooling\` in \`loom.json\`; do not assume tasks live in \`package.json\` or that pnpm is the runner.
|
|
1879
|
+
5. If the task touches a specific active Loom feature, also use the matching feature skill such as \`loom-jobs\`.
|
|
1880
|
+
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.
|
|
1881
|
+
7. Keep project-specific rules outside this managed block; shared Loom policy lives in the \`loom\` skill.
|
|
1641
1882
|
${exports.LOOM_MANAGED_AGENTS_END}
|
|
1642
1883
|
`;
|
|
1643
1884
|
}
|
|
@@ -1900,6 +2141,37 @@ async function ensurePnpmProject(cwd, packageJson) {
|
|
|
1900
2141
|
}
|
|
1901
2142
|
throw new Error("loom dev local/published currently supports pnpm projects only.");
|
|
1902
2143
|
}
|
|
2144
|
+
function usesDenoTooling(tooling) {
|
|
2145
|
+
return tooling.tasks.runner === "deno" ||
|
|
2146
|
+
tooling.dependencies.manager === "deno";
|
|
2147
|
+
}
|
|
2148
|
+
async function getDenoConfigForLinks(cwd, tooling) {
|
|
2149
|
+
for (const config of [
|
|
2150
|
+
tooling.tasks.config,
|
|
2151
|
+
tooling.dependencies.config,
|
|
2152
|
+
"deno.json",
|
|
2153
|
+
"deno.jsonc",
|
|
2154
|
+
]) {
|
|
2155
|
+
if ((config === "deno.json" || config === "deno.jsonc") &&
|
|
2156
|
+
await exists((0, node_path_1.join)(cwd, config))) {
|
|
2157
|
+
return config;
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
throw new Error("Deno local development requires a deno.json or deno.jsonc workspace root.");
|
|
2161
|
+
}
|
|
2162
|
+
async function findLocalLoomDenoLink(cwd, links) {
|
|
2163
|
+
for (const link of links) {
|
|
2164
|
+
const path = (0, node_path_1.resolve)(cwd, link);
|
|
2165
|
+
const packageText = await readTextIfExists((0, node_path_1.join)(path, "package.json"));
|
|
2166
|
+
if (!packageText)
|
|
2167
|
+
continue;
|
|
2168
|
+
if (parseJson(packageText, `${link}/package.json`).name ===
|
|
2169
|
+
exports.LOOM_DEPENDENCY) {
|
|
2170
|
+
return { link, path };
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
return null;
|
|
2174
|
+
}
|
|
1903
2175
|
async function resolveLocalLoomPackagePath(cwd, inputPath) {
|
|
1904
2176
|
const resolvedInput = (0, node_path_1.resolve)(cwd, inputPath);
|
|
1905
2177
|
const candidates = [resolvedInput, (0, node_path_1.join)(resolvedInput, "npm")];
|
|
@@ -2015,6 +2287,9 @@ async function readPackageVersion(packagePath) {
|
|
|
2015
2287
|
}
|
|
2016
2288
|
return parseJson(packageJsonText, (0, node_path_1.join)(packagePath, "package.json")).version;
|
|
2017
2289
|
}
|
|
2290
|
+
function versionFromDependencySpec(spec) {
|
|
2291
|
+
return spec?.match(/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/)?.[1];
|
|
2292
|
+
}
|
|
2018
2293
|
async function getGitStdout(commandRunner, cwd, args, env) {
|
|
2019
2294
|
const result = await commandRunner("git", args, { cwd, env });
|
|
2020
2295
|
if (result.code !== 0) {
|
|
@@ -2081,7 +2356,7 @@ async function writeLocalDevStateIfChanged(cwd, state) {
|
|
|
2081
2356
|
await (0, promises_1.writeFile)(gitignorePath, gitignoreUpdate.text, "utf8");
|
|
2082
2357
|
gitignoreChanged = true;
|
|
2083
2358
|
}
|
|
2084
|
-
return stateChanged
|
|
2359
|
+
return { gitignoreChanged, stateChanged };
|
|
2085
2360
|
}
|
|
2086
2361
|
async function getCurrentLocalDevState(cwd, workspaceText) {
|
|
2087
2362
|
return getManagedDevState(workspaceText) ?? await readLocalDevState(cwd);
|
|
@@ -2197,10 +2472,19 @@ async function resolveLoomCommitPublication(sourceRoot, sourceCommit, commandRun
|
|
|
2197
2472
|
return { status: "no-release-tag" };
|
|
2198
2473
|
}
|
|
2199
2474
|
async function syncLocalDevPackage(cwd, options = {}) {
|
|
2475
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2476
|
+
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling);
|
|
2477
|
+
const denoMode = usesDenoTooling(tooling);
|
|
2200
2478
|
const workspacePath = (0, node_path_1.join)(cwd, "pnpm-workspace.yaml");
|
|
2201
2479
|
const workspaceText = await readTextIfExists(workspacePath);
|
|
2202
2480
|
const overrideSpec = getManagedDevOverrideSpec(workspaceText);
|
|
2203
|
-
|
|
2481
|
+
const denoConfig = denoMode
|
|
2482
|
+
? await getDenoConfigForLinks(cwd, tooling)
|
|
2483
|
+
: null;
|
|
2484
|
+
const denoLink = denoConfig
|
|
2485
|
+
? await findLocalLoomDenoLink(cwd, await (0, projectTooling_js_1.readDenoLinks)(cwd, denoConfig))
|
|
2486
|
+
: null;
|
|
2487
|
+
if (!overrideSpec && !denoLink) {
|
|
2204
2488
|
if (options.requireActive) {
|
|
2205
2489
|
throw new Error("No managed Loom local-dev override is active. Run `loom dev local /path/to/loom` first.");
|
|
2206
2490
|
}
|
|
@@ -2213,20 +2497,31 @@ async function syncLocalDevPackage(cwd, options = {}) {
|
|
|
2213
2497
|
};
|
|
2214
2498
|
}
|
|
2215
2499
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
2216
|
-
|
|
2500
|
+
if (!denoMode)
|
|
2501
|
+
await ensurePnpmProject(cwd, packageJson);
|
|
2217
2502
|
const commandRunner = options.commandRunner ?? defaultCommandRunner;
|
|
2218
2503
|
const env = options.env ?? node_process_1.default.env;
|
|
2219
|
-
const localPackagePath =
|
|
2504
|
+
const localPackagePath = denoLink?.path ??
|
|
2505
|
+
fileSpecToPath(cwd, overrideSpec);
|
|
2220
2506
|
const sourceRoot = await resolveLocalLoomSourceRoot(localPackagePath);
|
|
2507
|
+
const configuredSpec = packageJson.dependencies?.[exports.LOOM_DEPENDENCY] ??
|
|
2508
|
+
packageJson.devDependencies?.[exports.LOOM_DEPENDENCY];
|
|
2509
|
+
const desiredLocalVersion = await readPackageVersion((0, node_path_1.join)(cwd, "node_modules", exports.LOOM_DEPENDENCY)) ?? versionFromDependencySpec(configuredSpec) ??
|
|
2510
|
+
await readPackageVersion(localPackagePath);
|
|
2511
|
+
const currentLocalVersion = await readPackageVersion(localPackagePath);
|
|
2512
|
+
const buildEnv = desiredLocalVersion && !env.NPM_PACKAGE_VERSION
|
|
2513
|
+
? { ...env, NPM_PACKAGE_VERSION: desiredLocalVersion }
|
|
2514
|
+
: env;
|
|
2221
2515
|
const ranCommands = [];
|
|
2222
2516
|
let buildRan = false;
|
|
2223
|
-
if (options.force ||
|
|
2517
|
+
if (options.force || denoMode && currentLocalVersion !== desiredLocalVersion ||
|
|
2518
|
+
await isLocalLoomBuildStale(sourceRoot, localPackagePath)) {
|
|
2224
2519
|
if (!sourceRoot) {
|
|
2225
2520
|
throw new Error(`Could not find the Loom source checkout for ${localPackagePath}; cannot rebuild the local package.`);
|
|
2226
2521
|
}
|
|
2227
2522
|
await runCommandOrThrow(commandRunner, "deno", ["task", "build"], {
|
|
2228
2523
|
cwd: sourceRoot,
|
|
2229
|
-
env,
|
|
2524
|
+
env: buildEnv,
|
|
2230
2525
|
stdio: "inherit",
|
|
2231
2526
|
});
|
|
2232
2527
|
ranCommands.push("deno task build");
|
|
@@ -2236,25 +2531,39 @@ async function syncLocalDevPackage(cwd, options = {}) {
|
|
|
2236
2531
|
await isInstalledLocalLoomPackageStale(cwd, localPackagePath);
|
|
2237
2532
|
let packageRefreshRan = false;
|
|
2238
2533
|
if (options.force || packageRefreshNeeded) {
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2534
|
+
if (denoMode) {
|
|
2535
|
+
await runCommandOrThrow(commandRunner, "deno", ["install"], {
|
|
2536
|
+
cwd,
|
|
2537
|
+
env,
|
|
2538
|
+
stdio: "inherit",
|
|
2539
|
+
});
|
|
2540
|
+
ranCommands.push("deno install");
|
|
2541
|
+
}
|
|
2542
|
+
else {
|
|
2543
|
+
const packageSpec = `${exports.LOOM_DEPENDENCY}@file:${localPackagePath}`;
|
|
2544
|
+
await runCommandOrThrow(commandRunner, "pnpm", ["update", "--no-save", packageSpec], { cwd, env, stdio: "inherit" });
|
|
2545
|
+
ranCommands.push(`pnpm update --no-save ${packageSpec}`);
|
|
2546
|
+
await runCommandOrThrow(commandRunner, "pnpm", ["install"], {
|
|
2547
|
+
cwd,
|
|
2548
|
+
env,
|
|
2549
|
+
stdio: "inherit",
|
|
2550
|
+
});
|
|
2551
|
+
ranCommands.push("pnpm install");
|
|
2552
|
+
}
|
|
2248
2553
|
packageRefreshRan = true;
|
|
2249
2554
|
}
|
|
2250
2555
|
const currentWorkspaceText = await readTextIfExists(workspacePath);
|
|
2251
|
-
const currentState =
|
|
2556
|
+
const currentState = denoMode
|
|
2557
|
+
? await readLocalDevState(cwd)
|
|
2558
|
+
: await getCurrentLocalDevState(cwd, currentWorkspaceText);
|
|
2252
2559
|
let state = null;
|
|
2253
2560
|
if (buildRan || packageRefreshRan || !currentState) {
|
|
2254
2561
|
state = await buildLocalDevState(localPackagePath, sourceRoot, commandRunner, env);
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2562
|
+
if (!denoMode) {
|
|
2563
|
+
const stateUpdate = setManagedDevStateText(await readTextIfExists(workspacePath), overrideSpec, state);
|
|
2564
|
+
if (stateUpdate.changed) {
|
|
2565
|
+
await writeTextOrDeleteIfEmpty(workspacePath, stateUpdate.text);
|
|
2566
|
+
}
|
|
2258
2567
|
}
|
|
2259
2568
|
}
|
|
2260
2569
|
if (state ?? currentState) {
|
|
@@ -2283,16 +2592,43 @@ async function syncLocalDevPackage(cwd, options = {}) {
|
|
|
2283
2592
|
};
|
|
2284
2593
|
}
|
|
2285
2594
|
async function useLocalDevPackage(cwd, inputPath) {
|
|
2286
|
-
const
|
|
2287
|
-
const
|
|
2288
|
-
|
|
2289
|
-
|
|
2595
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
2596
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2597
|
+
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling);
|
|
2598
|
+
const localPackagePath = await resolveLocalLoomPackagePath(cwd, inputPath);
|
|
2599
|
+
const publishedSpec = getPublishedLoomDependencySpec(packageJson);
|
|
2600
|
+
if (usesDenoTooling(tooling)) {
|
|
2601
|
+
if (!await exists((0, node_path_1.join)(localPackagePath, "deno.json"))) {
|
|
2602
|
+
throw new Error(`Local Deno development requires ${localPackagePath}/deno.json. Rebuild the Loom npm output before linking it.`);
|
|
2603
|
+
}
|
|
2604
|
+
const denoConfig = await getDenoConfigForLinks(cwd, tooling);
|
|
2605
|
+
const relativeLocalPackagePath = (0, node_path_1.relative)(cwd, localPackagePath)
|
|
2606
|
+
.replaceAll("\\", "/");
|
|
2607
|
+
const update = await (0, projectTooling_js_1.mutateDenoLinks)(cwd, denoConfig, {
|
|
2608
|
+
add: relativeLocalPackagePath,
|
|
2609
|
+
});
|
|
2610
|
+
const state = {
|
|
2611
|
+
dependency: exports.LOOM_DEPENDENCY,
|
|
2612
|
+
localPackagePath,
|
|
2613
|
+
packageVersion: await readPackageVersion(localPackagePath),
|
|
2614
|
+
syncedAt: new Date().toISOString(),
|
|
2615
|
+
version: 1,
|
|
2616
|
+
};
|
|
2617
|
+
const stateUpdate = await writeLocalDevStateIfChanged(cwd, state);
|
|
2618
|
+
const changedFiles = update.changed ? [denoConfig] : [];
|
|
2619
|
+
if (stateUpdate.gitignoreChanged)
|
|
2620
|
+
changedFiles.push(".gitignore");
|
|
2621
|
+
return {
|
|
2622
|
+
changedFiles,
|
|
2623
|
+
notes: [
|
|
2624
|
+
`Local Loom dev link is active in ${denoConfig}: ${localPackagePath}`,
|
|
2625
|
+
"Run `loom dev sync` to rebuild the local Loom package and refresh Deno's dependency installation when needed.",
|
|
2626
|
+
`Before committing or shipping a published build, run loom dev published, then deno install to restore ${exports.LOOM_DEPENDENCY}@${publishedSpec}.`,
|
|
2627
|
+
],
|
|
2628
|
+
};
|
|
2290
2629
|
}
|
|
2291
|
-
const packageJson = parseJson(packageJsonText, "package.json");
|
|
2292
2630
|
await ensurePnpmProject(cwd, packageJson);
|
|
2293
|
-
const localPackagePath = await resolveLocalLoomPackagePath(cwd, inputPath);
|
|
2294
2631
|
const overrideSpec = `file:${localPackagePath}`;
|
|
2295
|
-
const publishedSpec = getPublishedLoomDependencySpec(packageJson);
|
|
2296
2632
|
const workspacePath = (0, node_path_1.join)(cwd, "pnpm-workspace.yaml");
|
|
2297
2633
|
const update = ensurePnpmWorkspaceLocalDevText(await readTextIfExists(workspacePath), overrideSpec);
|
|
2298
2634
|
if (update.conflict) {
|
|
@@ -2313,20 +2649,30 @@ async function useLocalDevPackage(cwd, inputPath) {
|
|
|
2313
2649
|
};
|
|
2314
2650
|
}
|
|
2315
2651
|
async function usePublishedDevPackage(cwd, options = {}) {
|
|
2316
|
-
const
|
|
2317
|
-
const
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
await ensurePnpmProject(cwd, packageJson);
|
|
2652
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
2653
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2654
|
+
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling);
|
|
2655
|
+
const denoMode = usesDenoTooling(tooling);
|
|
2656
|
+
if (!denoMode)
|
|
2657
|
+
await ensurePnpmProject(cwd, packageJson);
|
|
2323
2658
|
const commandRunner = options.commandRunner ?? defaultCommandRunner;
|
|
2324
2659
|
const env = options.env ?? node_process_1.default.env;
|
|
2325
2660
|
const workspacePath = (0, node_path_1.join)(cwd, "pnpm-workspace.yaml");
|
|
2326
2661
|
const workspaceText = await readTextIfExists(workspacePath);
|
|
2327
|
-
const
|
|
2328
|
-
|
|
2329
|
-
|
|
2662
|
+
const denoConfig = denoMode
|
|
2663
|
+
? await getDenoConfigForLinks(cwd, tooling)
|
|
2664
|
+
: null;
|
|
2665
|
+
const denoLink = denoConfig
|
|
2666
|
+
? await findLocalLoomDenoLink(cwd, await (0, projectTooling_js_1.readDenoLinks)(cwd, denoConfig))
|
|
2667
|
+
: null;
|
|
2668
|
+
const activeOverrideSpec = denoLink?.link ??
|
|
2669
|
+
getManagedDevOverrideSpec(workspaceText);
|
|
2670
|
+
const localLockfileResolution = denoMode
|
|
2671
|
+
? null
|
|
2672
|
+
: await getProjectLocalLoomLockfileResolution(cwd);
|
|
2673
|
+
const state = denoMode
|
|
2674
|
+
? await readLocalDevState(cwd)
|
|
2675
|
+
: await getCurrentLocalDevState(cwd, workspaceText);
|
|
2330
2676
|
const notes = [];
|
|
2331
2677
|
let publishedSpec = getPublishedLoomDependencySpec(packageJson);
|
|
2332
2678
|
const needsPublicationProof = Boolean(activeOverrideSpec || localLockfileResolution);
|
|
@@ -2349,21 +2695,33 @@ async function usePublishedDevPackage(cwd, options = {}) {
|
|
|
2349
2695
|
else if (needsPublicationProof) {
|
|
2350
2696
|
notes.push("No recorded Loom sync commit was found; switching back to the existing published dependency without proving whether local Loom changes were required.");
|
|
2351
2697
|
}
|
|
2352
|
-
const dependencyUpdate =
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
}
|
|
2356
|
-
const
|
|
2698
|
+
const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, {
|
|
2699
|
+
dependencies: { [exports.LOOM_DEPENDENCY]: publishedSpec },
|
|
2700
|
+
replace: true,
|
|
2701
|
+
});
|
|
2702
|
+
const denoUpdate = denoConfig && denoLink
|
|
2703
|
+
? await (0, projectTooling_js_1.mutateDenoLinks)(cwd, denoConfig, { remove: denoLink.link })
|
|
2704
|
+
: null;
|
|
2705
|
+
const update = denoMode
|
|
2706
|
+
? { changed: denoUpdate?.changed ?? false, text: "" }
|
|
2707
|
+
: clearPnpmWorkspaceLocalDevText(await readTextIfExists(workspacePath));
|
|
2357
2708
|
const changedFiles = [];
|
|
2358
2709
|
if (dependencyUpdate.changed) {
|
|
2359
|
-
changedFiles.push(
|
|
2710
|
+
changedFiles.push(dependencyUpdate.config);
|
|
2360
2711
|
}
|
|
2361
2712
|
if (update.changed) {
|
|
2362
|
-
|
|
2363
|
-
|
|
2713
|
+
if (denoMode) {
|
|
2714
|
+
changedFiles.push(denoConfig);
|
|
2715
|
+
}
|
|
2716
|
+
else {
|
|
2717
|
+
await writeTextOrDeleteIfEmpty(workspacePath, update.text);
|
|
2718
|
+
changedFiles.push("pnpm-workspace.yaml");
|
|
2719
|
+
}
|
|
2364
2720
|
}
|
|
2365
2721
|
if (update.changed || localLockfileResolution) {
|
|
2366
|
-
notes.push(
|
|
2722
|
+
notes.push(denoMode
|
|
2723
|
+
? `Run \`deno install\` in this project to return node_modules and deno.lock to published ${exports.LOOM_DEPENDENCY}@${publishedSpec}.`
|
|
2724
|
+
: `Run \`pnpm update --no-save ${exports.LOOM_DEPENDENCY}@${publishedSpec}\` and then \`pnpm install\` in this project to return node_modules and the lockfile to the published ${exports.LOOM_DEPENDENCY} dependency.`);
|
|
2367
2725
|
}
|
|
2368
2726
|
if (localLockfileResolution) {
|
|
2369
2727
|
notes.push(`pnpm-lock.yaml still resolves ${exports.LOOM_DEPENDENCY} to ${localLockfileResolution} until that update is run.`);
|
|
@@ -2497,26 +2855,43 @@ async function checkManagedAgentsFile(cwd) {
|
|
|
2497
2855
|
};
|
|
2498
2856
|
}
|
|
2499
2857
|
async function checkManagedLocalDevOverride(cwd, production = false) {
|
|
2858
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2859
|
+
let denoLink = null;
|
|
2860
|
+
let denoConfig = null;
|
|
2861
|
+
try {
|
|
2862
|
+
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling);
|
|
2863
|
+
if (usesDenoTooling(tooling)) {
|
|
2864
|
+
denoConfig = await getDenoConfigForLinks(cwd, tooling);
|
|
2865
|
+
denoLink = await findLocalLoomDenoLink(cwd, await (0, projectTooling_js_1.readDenoLinks)(cwd, denoConfig));
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
catch {
|
|
2869
|
+
// The main project tooling check reports invalid configuration separately.
|
|
2870
|
+
}
|
|
2500
2871
|
const workspaceText = await readTextIfExists((0, node_path_1.join)(cwd, "pnpm-workspace.yaml"));
|
|
2501
2872
|
const overrideSpec = getManagedDevOverrideSpec(workspaceText);
|
|
2502
|
-
if (!overrideSpec) {
|
|
2873
|
+
if (!overrideSpec && !denoLink) {
|
|
2503
2874
|
return {
|
|
2504
2875
|
issues: [],
|
|
2505
2876
|
suggestions: [],
|
|
2506
2877
|
warnings: [],
|
|
2507
2878
|
};
|
|
2508
2879
|
}
|
|
2880
|
+
const location = denoLink
|
|
2881
|
+
? `${denoConfig} links: ${denoLink.link}`
|
|
2882
|
+
: `pnpm-workspace.yaml: ${overrideSpec}`;
|
|
2883
|
+
const restore = denoLink
|
|
2884
|
+
? "Run `loom dev published`, then run `deno install` before committing or shipping a published build."
|
|
2885
|
+
: `Run \`loom dev published\`, then follow its printed \`pnpm update --no-save ${exports.LOOM_DEPENDENCY}@<version>\` command and run \`pnpm install\` before committing or shipping a published build.`;
|
|
2509
2886
|
return {
|
|
2510
2887
|
issues: production
|
|
2511
2888
|
? [
|
|
2512
|
-
`Local Loom dev override is active in
|
|
2889
|
+
`Local Loom dev override is active in ${location}`,
|
|
2513
2890
|
]
|
|
2514
2891
|
: [],
|
|
2515
|
-
suggestions: [
|
|
2516
|
-
`Run \`loom dev published\`, then follow its printed \`pnpm update --no-save ${exports.LOOM_DEPENDENCY}@<version>\` command and run \`pnpm install\` before committing or shipping a published build.`,
|
|
2517
|
-
],
|
|
2892
|
+
suggestions: [restore],
|
|
2518
2893
|
warnings: production ? [] : [
|
|
2519
|
-
`Local Loom dev override is active in
|
|
2894
|
+
`Local Loom dev override is active in ${location}`,
|
|
2520
2895
|
],
|
|
2521
2896
|
};
|
|
2522
2897
|
}
|
|
@@ -2557,6 +2932,18 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2557
2932
|
const warnings = [];
|
|
2558
2933
|
const dependency = packageJson.dependencies?.[exports.LOOM_DEPENDENCY];
|
|
2559
2934
|
const production = options.production;
|
|
2935
|
+
const projectMetadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
2936
|
+
let dependencyTooling = {
|
|
2937
|
+
config: projectMetadata.config,
|
|
2938
|
+
manager: projectMetadata.config === "package.json" ? "pnpm" : "deno",
|
|
2939
|
+
};
|
|
2940
|
+
try {
|
|
2941
|
+
const manifest = await readManifestIfExists(cwd);
|
|
2942
|
+
dependencyTooling = (await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling)).dependencies;
|
|
2943
|
+
}
|
|
2944
|
+
catch {
|
|
2945
|
+
// The main tooling check owns the validation error; release hints can fall back.
|
|
2946
|
+
}
|
|
2560
2947
|
const localLockfileResolution = await getProjectLocalLoomLockfileResolution(cwd);
|
|
2561
2948
|
const devState = await readLocalDevState(cwd);
|
|
2562
2949
|
if (localLockfileResolution) {
|
|
@@ -2590,8 +2977,8 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2590
2977
|
"package-equivalent"
|
|
2591
2978
|
? `package-relevant files match ${exports.LOOM_DEPENDENCY}@${publication.version}`
|
|
2592
2979
|
: `it is published as ${exports.LOOM_DEPENDENCY}@${publication.version}`;
|
|
2593
|
-
addReleaseCheckMessage(issues, warnings, production, `This app was last synced against Loom commit ${shortCommit}; ${publicationDescription}, but
|
|
2594
|
-
suggestions.add(`Run
|
|
2980
|
+
addReleaseCheckMessage(issues, warnings, production, `This app was last synced against Loom commit ${shortCommit}; ${publicationDescription}, but ${dependencyTooling.config} is pinned to ${dependency}.`);
|
|
2981
|
+
suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, exports.LOOM_DEPENDENCY, publication.version)}.`);
|
|
2595
2982
|
}
|
|
2596
2983
|
else if (localLockfileResolution) {
|
|
2597
2984
|
const publicationDescription = publication.reason ===
|
|
@@ -2599,7 +2986,7 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2599
2986
|
? `has no package-relevant changes after ${publication.tag}, so ${exports.LOOM_DEPENDENCY}@${publication.version} covers it`
|
|
2600
2987
|
: `is published as ${exports.LOOM_DEPENDENCY}@${publication.version}`;
|
|
2601
2988
|
warnings.push(`The synced Loom commit ${shortCommit} ${publicationDescription}; refresh the lockfile away from ${localLockfileResolution}.`);
|
|
2602
|
-
suggestions.add(`Run
|
|
2989
|
+
suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, exports.LOOM_DEPENDENCY, publication.version)}.`);
|
|
2603
2990
|
}
|
|
2604
2991
|
break;
|
|
2605
2992
|
}
|
|
@@ -2624,8 +3011,8 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
|
|
|
2624
3011
|
else {
|
|
2625
3012
|
const installedPackage = parseJson(installedPackageText, (0, node_path_1.join)("node_modules", exports.LOOM_DEPENDENCY, "package.json"));
|
|
2626
3013
|
if (installedPackage.version !== dependency) {
|
|
2627
|
-
issues.push(`Installed ${exports.LOOM_DEPENDENCY} version ${installedPackage.version} does not match
|
|
2628
|
-
suggestions.add(`Run
|
|
3014
|
+
issues.push(`Installed ${exports.LOOM_DEPENDENCY} version ${installedPackage.version} does not match ${dependencyTooling.config} ${dependency}.`);
|
|
3015
|
+
suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, exports.LOOM_DEPENDENCY, dependency)}.`);
|
|
2629
3016
|
}
|
|
2630
3017
|
}
|
|
2631
3018
|
}
|
|
@@ -2699,7 +3086,7 @@ function getGithubWorkflowStepBlocks(text) {
|
|
|
2699
3086
|
}
|
|
2700
3087
|
function workflowInstallsNodeDependencies(stepBlocks) {
|
|
2701
3088
|
return stepBlocks.some((block) => /uses:\s*actions\/setup-node@/m.test(block) ||
|
|
2702
|
-
/\b(?:pnpm\s+(?:install|i)|npm\s+(?:ci|install)|yarn\s+install|bun\s+install)\b/
|
|
3089
|
+
/\b(?:deno\s+install|pnpm\s+(?:install|i)|npm\s+(?:ci|install)|yarn\s+install|bun\s+install)\b/
|
|
2703
3090
|
.test(block));
|
|
2704
3091
|
}
|
|
2705
3092
|
function hasGithubPackagesSetupNodeConfig(stepBlocks) {
|
|
@@ -2822,14 +3209,14 @@ function githubWorkflowRunsOnMainPush(text) {
|
|
|
2822
3209
|
return !hasBranchFilter && !ignoresMain;
|
|
2823
3210
|
}
|
|
2824
3211
|
function workflowStepRunsDbMigrate(block) {
|
|
2825
|
-
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/
|
|
3212
|
+
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/
|
|
2826
3213
|
.test(block) ||
|
|
2827
3214
|
/\bdrizzle-kit\s+migrate\b/.test(block) ||
|
|
2828
3215
|
/spawnSync\(\s*["']pnpm["'][\s\S]*["']db:migrate["']/.test(block);
|
|
2829
3216
|
}
|
|
2830
3217
|
function workflowStepUsesVercelCommand(block, subcommand) {
|
|
2831
3218
|
const launcher = String
|
|
2832
|
-
.raw `(?:vercel|pnpm\s+(?:dlx|exec)\s+vercel(?:@[^\s]+)?|npx\s+vercel(?:@[^\s]+)?|yarn\s+(?:dlx\s+)?vercel(?:@[^\s]+)?|bunx\s+vercel(?:@[^\s]+)?)`;
|
|
3219
|
+
.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]+)?)`;
|
|
2833
3220
|
const globalFlags = String
|
|
2834
3221
|
.raw `(?:\s+(?:--[A-Za-z-]+(?:=(?:"[^"]+"|'[^']+'|[^\s]+)|\s+(?:"[^"]+"|'[^']+'|[^\s]+))?|-[A-Za-z](?:\s+(?:"[^"]+"|'[^']+'|[^\s]+))?))*`;
|
|
2835
3222
|
return new RegExp(String.raw `\b${launcher}${globalFlags}\s+${subcommand}\b`)
|
|
@@ -3791,10 +4178,13 @@ function dbScriptsTsconfigTemplate() {
|
|
|
3791
4178
|
}
|
|
3792
4179
|
`;
|
|
3793
4180
|
}
|
|
3794
|
-
function dbPgliteHarnessTemplate(config) {
|
|
4181
|
+
function dbPgliteHarnessTemplate(config, testRunner = "vitest") {
|
|
3795
4182
|
const schemaImportPath = toRelativeImportPath(config.modules.pgliteHarnessModule, (0, node_path_1.join)(config.dirs.schemaDir, "index.ts"));
|
|
4183
|
+
const afterAllImport = testRunner === "deno"
|
|
4184
|
+
? 'import { afterAll } from "jsr:@std/testing@^1.0.19/bdd";'
|
|
4185
|
+
: 'import { afterAll } from "vitest";';
|
|
3796
4186
|
return `import { createMemoryPgliteHarness } from "@gadicc/loom/db/testing";
|
|
3797
|
-
|
|
4187
|
+
${afterAllImport}
|
|
3798
4188
|
import * as schema from "${schemaImportPath}";
|
|
3799
4189
|
|
|
3800
4190
|
const harness = await createMemoryPgliteHarness({
|
|
@@ -3815,6 +4205,14 @@ afterAll(closeMemoryPglite);
|
|
|
3815
4205
|
export const { client, db, tableLoader } = harness;
|
|
3816
4206
|
`;
|
|
3817
4207
|
}
|
|
4208
|
+
async function getDbTestRunner(cwd, tooling) {
|
|
4209
|
+
if (tooling.tasks.runner !== "deno")
|
|
4210
|
+
return "vitest";
|
|
4211
|
+
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
4212
|
+
return /\bvitest\b/.test((0, projectTooling_js_1.getTaskCommand)(taskStore.definitions.test) ?? "")
|
|
4213
|
+
? "vitest"
|
|
4214
|
+
: "deno";
|
|
4215
|
+
}
|
|
3818
4216
|
function dbFixturesScriptTemplate(config) {
|
|
3819
4217
|
const schemaImportPath = toRelativeImportPath(config.modules.fixtureDumpScript, (0, node_path_1.join)(config.dirs.schemaDir, "index.ts"));
|
|
3820
4218
|
const neonImportPath = toRelativeImportPath(config.modules.fixtureDumpScript, config.modules.neonModule);
|
|
@@ -4129,34 +4527,588 @@ export const { GET, POST } = createFilesRouteHandlers({
|
|
|
4129
4527
|
});
|
|
4130
4528
|
`;
|
|
4131
4529
|
}
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
.filter((entry) => entry.isFile() && entry.name.endsWith(".ts"))
|
|
4137
|
-
.map((entry) => entry.name.replace(/\.ts$/, ""))
|
|
4138
|
-
.filter((name) => name !== "index" && !name.startsWith("_"))
|
|
4139
|
-
.sort();
|
|
4140
|
-
}
|
|
4141
|
-
catch (error) {
|
|
4142
|
-
if (isNodeErrorCode(error, "ENOENT")) {
|
|
4143
|
-
return [];
|
|
4144
|
-
}
|
|
4145
|
-
throw error;
|
|
4146
|
-
}
|
|
4530
|
+
function mailAccessTemplate() {
|
|
4531
|
+
return `// Generated deny-all boundary. Replace with the app's fresh admin check.
|
|
4532
|
+
export async function authorizeMailAdmin(): Promise<void> {
|
|
4533
|
+
throw new Error("Mail admin access policy is not configured.");
|
|
4147
4534
|
}
|
|
4148
|
-
|
|
4149
|
-
const refinementSet = new Set(refinementNames);
|
|
4150
|
-
const names = [...new Set([...generatedNames, ...refinementNames])].sort();
|
|
4151
|
-
if (!names.length) {
|
|
4152
|
-
return null;
|
|
4153
|
-
}
|
|
4154
|
-
return `${names.map((name) => refinementSet.has(name)
|
|
4155
|
-
? `export * from "./refinements/${name}";`
|
|
4156
|
-
: `export * from "./generated/${name}";`).join("\n")}\n`;
|
|
4535
|
+
`;
|
|
4157
4536
|
}
|
|
4158
|
-
|
|
4159
|
-
|
|
4537
|
+
function mailTransportTemplate() {
|
|
4538
|
+
return `import type { LoomMailTransport } from "@gadicc/loom/mail";
|
|
4539
|
+
import {
|
|
4540
|
+
createPostalMailTransport,
|
|
4541
|
+
type PostalWebhookPublicKey,
|
|
4542
|
+
} from "@gadicc/loom/mail/postal";
|
|
4543
|
+
|
|
4544
|
+
function requireEnv(name: "POSTAL_API_KEY" | "POSTAL_FROM_EMAIL" | "POSTAL_HOST") {
|
|
4545
|
+
const value = process.env[name]?.trim();
|
|
4546
|
+
if (!value) throw new Error(\`\${name} is not set.\`);
|
|
4547
|
+
return value;
|
|
4548
|
+
}
|
|
4549
|
+
|
|
4550
|
+
export const mailTransport: LoomMailTransport = {
|
|
4551
|
+
provider: "postal",
|
|
4552
|
+
send(message) {
|
|
4553
|
+
return createPostalMailTransport({
|
|
4554
|
+
apiKey: requireEnv("POSTAL_API_KEY"),
|
|
4555
|
+
host: requireEnv("POSTAL_HOST"),
|
|
4556
|
+
}).send(message);
|
|
4557
|
+
},
|
|
4558
|
+
};
|
|
4559
|
+
|
|
4560
|
+
export function getDefaultMailFromEmail() {
|
|
4561
|
+
return requireEnv("POSTAL_FROM_EMAIL");
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
export function getPostalWebhookPublicKeys(): PostalWebhookPublicKey[] {
|
|
4565
|
+
const raw = process.env.POSTAL_WEBHOOK_PUBLIC_KEYS?.trim();
|
|
4566
|
+
if (!raw) throw new Error("POSTAL_WEBHOOK_PUBLIC_KEYS is not set.");
|
|
4567
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
4568
|
+
if (!Array.isArray(parsed)) {
|
|
4569
|
+
throw new Error("POSTAL_WEBHOOK_PUBLIC_KEYS must be a JSON array of public JWKs.");
|
|
4570
|
+
}
|
|
4571
|
+
return parsed.map((candidate) => {
|
|
4572
|
+
if (
|
|
4573
|
+
typeof candidate !== "object" || candidate === null ||
|
|
4574
|
+
!("kid" in candidate) || typeof candidate.kid !== "string" ||
|
|
4575
|
+
!("kty" in candidate) || candidate.kty !== "RSA"
|
|
4576
|
+
) {
|
|
4577
|
+
throw new Error("Every Postal webhook key must be an RSA JWK with a kid.");
|
|
4578
|
+
}
|
|
4579
|
+
return candidate as PostalWebhookPublicKey;
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
4582
|
+
`;
|
|
4583
|
+
}
|
|
4584
|
+
function mailServiceTemplate(config) {
|
|
4585
|
+
return `import { createLoomMailService } from "@gadicc/loom/mail";
|
|
4586
|
+
import { mailRepository } from "${toAliasImportPath(config.modules.repositoryModule)}";
|
|
4587
|
+
import {
|
|
4588
|
+
getDefaultMailFromEmail,
|
|
4589
|
+
mailTransport,
|
|
4590
|
+
} from "${toAliasImportPath(config.modules.transportModule)}";
|
|
4591
|
+
|
|
4592
|
+
export const mailService = createLoomMailService({
|
|
4593
|
+
get defaultFromEmail() {
|
|
4594
|
+
return getDefaultMailFromEmail();
|
|
4595
|
+
},
|
|
4596
|
+
repository: mailRepository,
|
|
4597
|
+
transport: mailTransport,
|
|
4598
|
+
});
|
|
4599
|
+
`;
|
|
4600
|
+
}
|
|
4601
|
+
function mailRepositoryTemplate(config, dbConfig) {
|
|
4602
|
+
const [messages, deliveries, events] = [
|
|
4603
|
+
config.schema.exports[0] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[0],
|
|
4604
|
+
config.schema.exports[1] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[1],
|
|
4605
|
+
config.schema.exports[2] ?? MAIL_SCHEMA_DEFAULT_EXPORTS[2],
|
|
4606
|
+
];
|
|
4607
|
+
return `import { and, asc, desc, eq, lte, or } from "drizzle-orm";
|
|
4608
|
+
import type {
|
|
4609
|
+
LoomMailDeliveryRecord,
|
|
4610
|
+
LoomMailDeliveryStatus,
|
|
4611
|
+
LoomMailMessageRecord,
|
|
4612
|
+
LoomMailRepository,
|
|
4613
|
+
} from "@gadicc/loom/mail";
|
|
4614
|
+
import { db } from "${toAliasImportPath(dbConfig.modules.neonFullModule)}";
|
|
4615
|
+
import {
|
|
4616
|
+
${deliveries},
|
|
4617
|
+
${events},
|
|
4618
|
+
${messages},
|
|
4619
|
+
} from "${toAliasImportPath(config.schema.module)}";
|
|
4620
|
+
|
|
4621
|
+
type MessageRow = typeof ${messages}.$inferSelect;
|
|
4622
|
+
type MessageInsert = typeof ${messages}.$inferInsert;
|
|
4623
|
+
type DeliveryRow = typeof ${deliveries}.$inferSelect;
|
|
4624
|
+
|
|
4625
|
+
function toMessage(row: MessageRow): LoomMailMessageRecord {
|
|
4626
|
+
return row as LoomMailMessageRecord;
|
|
4627
|
+
}
|
|
4628
|
+
|
|
4629
|
+
function toDelivery(row: DeliveryRow): LoomMailDeliveryRecord {
|
|
4630
|
+
return row as LoomMailDeliveryRecord;
|
|
4631
|
+
}
|
|
4632
|
+
|
|
4633
|
+
function aggregateStatus(statuses: LoomMailDeliveryStatus[]) {
|
|
4634
|
+
if (statuses.length === 0) return "sent" as const;
|
|
4635
|
+
if (statuses.every((status) => status === "delivered")) return "delivered" as const;
|
|
4636
|
+
const terminal = new Set<LoomMailDeliveryStatus>([
|
|
4637
|
+
"bounced", "cancelled", "delivered", "failed",
|
|
4638
|
+
]);
|
|
4639
|
+
if (statuses.every((status) => terminal.has(status))) {
|
|
4640
|
+
return statuses.includes("delivered") ? "partially_delivered" as const : "failed" as const;
|
|
4641
|
+
}
|
|
4642
|
+
return "sent" as const;
|
|
4643
|
+
}
|
|
4644
|
+
|
|
4645
|
+
export const mailRepository = {
|
|
4646
|
+
async cancel(messageId, occurredAt) {
|
|
4647
|
+
return db.transaction(async (trx) => {
|
|
4648
|
+
const [current] = await trx.select().from(${messages})
|
|
4649
|
+
.where(eq(${messages}.id, messageId)).limit(1).for("update");
|
|
4650
|
+
if (!current || !["queued", "failed"].includes(current.status)) return false;
|
|
4651
|
+
await trx.update(${messages}).set({
|
|
4652
|
+
cancelledAt: occurredAt,
|
|
4653
|
+
leaseExpiresAt: null,
|
|
4654
|
+
leaseToken: null,
|
|
4655
|
+
status: "cancelled",
|
|
4656
|
+
updatedAt: occurredAt,
|
|
4657
|
+
}).where(eq(${messages}.id, messageId));
|
|
4658
|
+
await trx.update(${deliveries}).set({ status: "cancelled", updatedAt: occurredAt })
|
|
4659
|
+
.where(and(eq(${deliveries}.messageId, messageId), eq(${deliveries}.status, "queued")));
|
|
4660
|
+
await trx.insert(${events}).values({
|
|
4661
|
+
eventType: "cancelled",
|
|
4662
|
+
messageId,
|
|
4663
|
+
payload: {},
|
|
4664
|
+
provider: current.provider,
|
|
4665
|
+
sourceEvent: "cancelled",
|
|
4666
|
+
occurredAt,
|
|
4667
|
+
});
|
|
4668
|
+
return true;
|
|
4669
|
+
});
|
|
4670
|
+
},
|
|
4671
|
+
|
|
4672
|
+
async claim(request) {
|
|
4673
|
+
return db.transaction(async (trx) => {
|
|
4674
|
+
const due = or(
|
|
4675
|
+
eq(${messages}.status, "queued"),
|
|
4676
|
+
and(eq(${messages}.status, "sending"), lte(${messages}.leaseExpiresAt, request.now)),
|
|
4677
|
+
);
|
|
4678
|
+
const [current] = await trx.select().from(${messages})
|
|
4679
|
+
.where(and(
|
|
4680
|
+
request.messageId ? eq(${messages}.id, request.messageId) : undefined,
|
|
4681
|
+
lte(${messages}.availableAt, request.now),
|
|
4682
|
+
due,
|
|
4683
|
+
))
|
|
4684
|
+
.orderBy(asc(${messages}.availableAt), asc(${messages}.createdAt))
|
|
4685
|
+
.limit(1)
|
|
4686
|
+
.for("update", { skipLocked: true });
|
|
4687
|
+
if (!current) return null;
|
|
4688
|
+
const [claimed] = await trx.update(${messages}).set({
|
|
4689
|
+
attemptCount: current.attemptCount + 1,
|
|
4690
|
+
leaseExpiresAt: request.leaseExpiresAt,
|
|
4691
|
+
leaseToken: request.leaseToken,
|
|
4692
|
+
status: "sending",
|
|
4693
|
+
updatedAt: request.now,
|
|
4694
|
+
}).where(eq(${messages}.id, current.id)).returning();
|
|
4695
|
+
if (!claimed) return null;
|
|
4696
|
+
await trx.insert(${events}).values({
|
|
4697
|
+
eventType: "attempted",
|
|
4698
|
+
messageId: current.id,
|
|
4699
|
+
payload: {
|
|
4700
|
+
attemptCount: claimed.attemptCount,
|
|
4701
|
+
leaseExpiresAt: request.leaseExpiresAt.toISOString(),
|
|
4702
|
+
},
|
|
4703
|
+
provider: current.provider,
|
|
4704
|
+
sourceEvent: "attempted",
|
|
4705
|
+
occurredAt: request.now,
|
|
4706
|
+
});
|
|
4707
|
+
return toMessage(claimed) as ReturnType<typeof toMessage> & {
|
|
4708
|
+
leaseExpiresAt: Date;
|
|
4709
|
+
leaseToken: string;
|
|
4710
|
+
status: "sending";
|
|
4711
|
+
};
|
|
4712
|
+
});
|
|
4713
|
+
},
|
|
4714
|
+
|
|
4715
|
+
async completeFailure(input) {
|
|
4716
|
+
return db.transaction(async (trx) => {
|
|
4717
|
+
const [updated] = await trx.update(${messages}).set({
|
|
4718
|
+
availableAt: input.retryAt ?? input.occurredAt,
|
|
4719
|
+
failedAt: input.retryAt ? null : input.occurredAt,
|
|
4720
|
+
lastErrorCode: input.failure.code,
|
|
4721
|
+
lastErrorMessage: input.failure.message,
|
|
4722
|
+
leaseExpiresAt: null,
|
|
4723
|
+
leaseToken: null,
|
|
4724
|
+
status: input.retryAt ? "queued" : "failed",
|
|
4725
|
+
updatedAt: input.occurredAt,
|
|
4726
|
+
}).where(and(
|
|
4727
|
+
eq(${messages}.id, input.messageId),
|
|
4728
|
+
eq(${messages}.status, "sending"),
|
|
4729
|
+
eq(${messages}.leaseToken, input.leaseToken),
|
|
4730
|
+
)).returning({ provider: ${messages}.provider });
|
|
4731
|
+
if (!updated) return false;
|
|
4732
|
+
await trx.insert(${events}).values({
|
|
4733
|
+
eventType: input.retryAt ? "retry_scheduled" : "failed",
|
|
4734
|
+
messageId: input.messageId,
|
|
4735
|
+
payload: {
|
|
4736
|
+
code: input.failure.code,
|
|
4737
|
+
message: input.failure.message,
|
|
4738
|
+
retryAt: input.retryAt?.toISOString() ?? null,
|
|
4739
|
+
retryable: input.failure.retryable,
|
|
4740
|
+
...input.failure.payload,
|
|
4741
|
+
},
|
|
4742
|
+
provider: updated.provider,
|
|
4743
|
+
sourceEvent: input.retryAt ? "retry_scheduled" : "failed",
|
|
4744
|
+
occurredAt: input.occurredAt,
|
|
4745
|
+
});
|
|
4746
|
+
return true;
|
|
4747
|
+
});
|
|
4748
|
+
},
|
|
4749
|
+
|
|
4750
|
+
async completeSuccess(input) {
|
|
4751
|
+
return db.transaction(async (trx) => {
|
|
4752
|
+
const [updated] = await trx.update(${messages}).set({
|
|
4753
|
+
lastErrorCode: null,
|
|
4754
|
+
lastErrorMessage: null,
|
|
4755
|
+
leaseExpiresAt: null,
|
|
4756
|
+
leaseToken: null,
|
|
4757
|
+
providerMessageId: input.result.providerMessageId,
|
|
4758
|
+
sentAt: input.occurredAt,
|
|
4759
|
+
status: "sent",
|
|
4760
|
+
updatedAt: input.occurredAt,
|
|
4761
|
+
}).where(and(
|
|
4762
|
+
eq(${messages}.id, input.messageId),
|
|
4763
|
+
eq(${messages}.status, "sending"),
|
|
4764
|
+
eq(${messages}.leaseToken, input.leaseToken),
|
|
4765
|
+
)).returning({ provider: ${messages}.provider });
|
|
4766
|
+
if (!updated) return false;
|
|
4767
|
+
for (const result of input.result.deliveries) {
|
|
4768
|
+
await trx.update(${deliveries}).set({
|
|
4769
|
+
providerDeliveryId: result.providerDeliveryId,
|
|
4770
|
+
providerToken: result.providerToken,
|
|
4771
|
+
status: "accepted",
|
|
4772
|
+
updatedAt: input.occurredAt,
|
|
4773
|
+
}).where(and(
|
|
4774
|
+
eq(${deliveries}.messageId, input.messageId),
|
|
4775
|
+
eq(${deliveries}.email, result.email),
|
|
4776
|
+
eq(${deliveries}.status, "queued"),
|
|
4777
|
+
));
|
|
4778
|
+
}
|
|
4779
|
+
await trx.insert(${events}).values({
|
|
4780
|
+
eventType: "sent",
|
|
4781
|
+
messageId: input.messageId,
|
|
4782
|
+
payload: {
|
|
4783
|
+
providerMessageId: input.result.providerMessageId,
|
|
4784
|
+
providerResponse: input.result.providerResponse ?? {},
|
|
4785
|
+
},
|
|
4786
|
+
provider: updated.provider,
|
|
4787
|
+
sourceEvent: "sent",
|
|
4788
|
+
occurredAt: input.occurredAt,
|
|
4789
|
+
});
|
|
4790
|
+
return true;
|
|
4791
|
+
});
|
|
4792
|
+
},
|
|
4793
|
+
|
|
4794
|
+
async enqueue(input, occurredAt) {
|
|
4795
|
+
return db.transaction(async (trx) => {
|
|
4796
|
+
const [message] = await trx.insert(${messages}).values({
|
|
4797
|
+
...input,
|
|
4798
|
+
availableAt: occurredAt,
|
|
4799
|
+
createdAt: occurredAt,
|
|
4800
|
+
updatedAt: occurredAt,
|
|
4801
|
+
} as MessageInsert).returning();
|
|
4802
|
+
if (!message) throw new Error("Failed to enqueue mail.");
|
|
4803
|
+
const recipients = [
|
|
4804
|
+
...input.to.map((email) => ({ email, kind: "to" })),
|
|
4805
|
+
...input.cc.map((email) => ({ email, kind: "cc" })),
|
|
4806
|
+
...input.bcc.map((email) => ({ email, kind: "bcc" })),
|
|
4807
|
+
];
|
|
4808
|
+
await trx.insert(${deliveries}).values(recipients.map((recipient) => ({
|
|
4809
|
+
...recipient,
|
|
4810
|
+
messageId: message.id,
|
|
4811
|
+
createdAt: occurredAt,
|
|
4812
|
+
updatedAt: occurredAt,
|
|
4813
|
+
})));
|
|
4814
|
+
await trx.insert(${events}).values({
|
|
4815
|
+
eventType: "queued",
|
|
4816
|
+
messageId: message.id,
|
|
4817
|
+
payload: { bcc: input.bcc, cc: input.cc, to: input.to },
|
|
4818
|
+
provider: input.provider,
|
|
4819
|
+
sourceEvent: "queued",
|
|
4820
|
+
occurredAt,
|
|
4821
|
+
});
|
|
4822
|
+
return toMessage(message);
|
|
4823
|
+
});
|
|
4824
|
+
},
|
|
4825
|
+
|
|
4826
|
+
async findById(messageId) {
|
|
4827
|
+
const [row] = await db.select().from(${messages})
|
|
4828
|
+
.where(eq(${messages}.id, messageId)).limit(1);
|
|
4829
|
+
return row ? toMessage(row) : null;
|
|
4830
|
+
},
|
|
4831
|
+
|
|
4832
|
+
async listDeliveries(messageId: string) {
|
|
4833
|
+
const rows = await db.select().from(${deliveries})
|
|
4834
|
+
.where(eq(${deliveries}.messageId, messageId));
|
|
4835
|
+
return rows.map(toDelivery);
|
|
4836
|
+
},
|
|
4837
|
+
|
|
4838
|
+
async listRecent(limit = 100) {
|
|
4839
|
+
const rows = await db.select().from(${messages})
|
|
4840
|
+
.orderBy(desc(${messages}.createdAt)).limit(limit);
|
|
4841
|
+
return rows.map(toMessage);
|
|
4842
|
+
},
|
|
4843
|
+
|
|
4844
|
+
async recordProviderEvent(event) {
|
|
4845
|
+
return db.transaction(async (trx) => {
|
|
4846
|
+
let [delivery] = event.providerDeliveryId
|
|
4847
|
+
? await trx.select().from(${deliveries})
|
|
4848
|
+
.where(eq(${deliveries}.providerDeliveryId, event.providerDeliveryId)).limit(1)
|
|
4849
|
+
: [];
|
|
4850
|
+
let [message] = delivery
|
|
4851
|
+
? await trx.select().from(${messages})
|
|
4852
|
+
.where(eq(${messages}.id, delivery.messageId)).limit(1)
|
|
4853
|
+
: event.providerMessageId
|
|
4854
|
+
? await trx.select().from(${messages})
|
|
4855
|
+
.where(and(
|
|
4856
|
+
eq(${messages}.provider, event.provider),
|
|
4857
|
+
eq(${messages}.providerMessageId, event.providerMessageId),
|
|
4858
|
+
)).limit(1)
|
|
4859
|
+
: [];
|
|
4860
|
+
if (message && message.provider !== event.provider) {
|
|
4861
|
+
return { inserted: false, messageId: null };
|
|
4862
|
+
}
|
|
4863
|
+
if (!message) return { inserted: false, messageId: null };
|
|
4864
|
+
if (!delivery && event.recipient) {
|
|
4865
|
+
[delivery] = await trx.select().from(${deliveries}).where(and(
|
|
4866
|
+
eq(${deliveries}.messageId, message.id),
|
|
4867
|
+
eq(${deliveries}.email, event.recipient),
|
|
4868
|
+
)).limit(1);
|
|
4869
|
+
}
|
|
4870
|
+
const [inserted] = await trx.insert(${events}).values({
|
|
4871
|
+
deliveryId: delivery?.id ?? null,
|
|
4872
|
+
eventType: event.eventType,
|
|
4873
|
+
messageId: message.id,
|
|
4874
|
+
occurredAt: event.occurredAt,
|
|
4875
|
+
payload: event.payload,
|
|
4876
|
+
provider: event.provider,
|
|
4877
|
+
providerEventId: event.providerEventId,
|
|
4878
|
+
sourceEvent: event.sourceEvent,
|
|
4879
|
+
}).onConflictDoNothing().returning({ id: ${events}.id });
|
|
4880
|
+
if (!inserted) return { inserted: false, messageId: message.id };
|
|
4881
|
+
|
|
4882
|
+
if (delivery && event.eventType !== "unknown") {
|
|
4883
|
+
const nextStatus = event.eventType;
|
|
4884
|
+
await trx.update(${deliveries}).set({
|
|
4885
|
+
deliveredAt: nextStatus === "delivered" ? event.occurredAt : delivery.deliveredAt,
|
|
4886
|
+
lastErrorCode: ["bounced", "failed", "held"].includes(nextStatus)
|
|
4887
|
+
? event.sourceEvent : delivery.lastErrorCode,
|
|
4888
|
+
lastErrorMessage: ["bounced", "failed", "held"].includes(nextStatus)
|
|
4889
|
+
? String(event.payload.message ?? event.sourceEvent) : delivery.lastErrorMessage,
|
|
4890
|
+
status: nextStatus,
|
|
4891
|
+
updatedAt: event.occurredAt,
|
|
4892
|
+
}).where(eq(${deliveries}.id, delivery.id));
|
|
4893
|
+
}
|
|
4894
|
+
const statusRows = await trx.select({ status: ${deliveries}.status })
|
|
4895
|
+
.from(${deliveries}).where(eq(${deliveries}.messageId, message.id));
|
|
4896
|
+
const status = aggregateStatus(
|
|
4897
|
+
statusRows.map((row) => row.status as LoomMailDeliveryStatus),
|
|
4898
|
+
);
|
|
4899
|
+
await trx.update(${messages}).set({
|
|
4900
|
+
deliveredAt: status === "delivered" ? event.occurredAt : message.deliveredAt,
|
|
4901
|
+
failedAt: status === "failed" ? event.occurredAt : message.failedAt,
|
|
4902
|
+
status,
|
|
4903
|
+
updatedAt: event.occurredAt,
|
|
4904
|
+
}).where(eq(${messages}.id, message.id));
|
|
4905
|
+
return { inserted: true, messageId: message.id };
|
|
4906
|
+
});
|
|
4907
|
+
},
|
|
4908
|
+
} satisfies LoomMailRepository & {
|
|
4909
|
+
listDeliveries(messageId: string): Promise<LoomMailDeliveryRecord[]>;
|
|
4910
|
+
listRecent(limit?: number): Promise<LoomMailMessageRecord[]>;
|
|
4911
|
+
};
|
|
4912
|
+
`;
|
|
4913
|
+
}
|
|
4914
|
+
function mailActionsTemplate(config) {
|
|
4915
|
+
const adminPath = config.entrypoints.adminPage
|
|
4916
|
+
.replace(/^src\/app|^app/, "")
|
|
4917
|
+
.replace(/\/page\.tsx$/, "") || "/";
|
|
4918
|
+
return `"use server";
|
|
4919
|
+
|
|
4920
|
+
import { LoomMailDeliveryError } from "@gadicc/loom/mail";
|
|
4921
|
+
import { revalidatePath } from "next/cache";
|
|
4922
|
+
import { authorizeMailAdmin } from "${toAliasImportPath(config.modules.accessModule)}";
|
|
4923
|
+
import { mailRepository } from "${toAliasImportPath(config.modules.repositoryModule)}";
|
|
4924
|
+
import { mailService } from "${toAliasImportPath(config.modules.serviceModule)}";
|
|
4925
|
+
|
|
4926
|
+
export interface MailTestActionState {
|
|
4927
|
+
message: string | null;
|
|
4928
|
+
messageId?: string;
|
|
4929
|
+
status: "error" | "idle" | "success";
|
|
4930
|
+
}
|
|
4931
|
+
|
|
4932
|
+
function text(formData: FormData, key: string) {
|
|
4933
|
+
const value = formData.get(key);
|
|
4934
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
4935
|
+
}
|
|
4936
|
+
|
|
4937
|
+
function recipients(value?: string) {
|
|
4938
|
+
return (value ?? "").split(/[,\\n]+/).map((item) => item.trim()).filter(Boolean);
|
|
4939
|
+
}
|
|
4940
|
+
|
|
4941
|
+
export async function sendTestMail(
|
|
4942
|
+
_previous: MailTestActionState,
|
|
4943
|
+
formData: FormData,
|
|
4944
|
+
): Promise<MailTestActionState> {
|
|
4945
|
+
await authorizeMailAdmin();
|
|
4946
|
+
try {
|
|
4947
|
+
const result = await mailService.sendMail({
|
|
4948
|
+
bcc: recipients(text(formData, "bcc")),
|
|
4949
|
+
cc: recipients(text(formData, "cc")),
|
|
4950
|
+
htmlBody: text(formData, "htmlBody"),
|
|
4951
|
+
metadata: { sentFromMailAdmin: true },
|
|
4952
|
+
plainBody: text(formData, "plainBody"),
|
|
4953
|
+
replyTo: text(formData, "replyTo"),
|
|
4954
|
+
subject: text(formData, "subject") ?? "",
|
|
4955
|
+
tag: text(formData, "tag"),
|
|
4956
|
+
to: recipients(text(formData, "to")),
|
|
4957
|
+
});
|
|
4958
|
+
revalidatePath("${adminPath}");
|
|
4959
|
+
return {
|
|
4960
|
+
message: "Test email accepted by the provider.",
|
|
4961
|
+
messageId: result.message.id,
|
|
4962
|
+
status: "success",
|
|
4963
|
+
};
|
|
4964
|
+
} catch (error) {
|
|
4965
|
+
return {
|
|
4966
|
+
message: error instanceof Error ? error.message : "Mail send failed.",
|
|
4967
|
+
messageId: error instanceof LoomMailDeliveryError ? error.messageId : undefined,
|
|
4968
|
+
status: "error",
|
|
4969
|
+
};
|
|
4970
|
+
}
|
|
4971
|
+
}
|
|
4972
|
+
|
|
4973
|
+
function requiredMessageId(formData: FormData) {
|
|
4974
|
+
const messageId = text(formData, "messageId");
|
|
4975
|
+
if (!messageId) throw new Error("Missing mail message id.");
|
|
4976
|
+
return messageId;
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4979
|
+
export async function cancelMail(formData: FormData) {
|
|
4980
|
+
await authorizeMailAdmin();
|
|
4981
|
+
if (!await mailService.cancelMail(requiredMessageId(formData))) {
|
|
4982
|
+
throw new Error("Mail message cannot be cancelled in its current state.");
|
|
4983
|
+
}
|
|
4984
|
+
revalidatePath("${adminPath}");
|
|
4985
|
+
}
|
|
4986
|
+
|
|
4987
|
+
export async function retryMail(formData: FormData) {
|
|
4988
|
+
await authorizeMailAdmin();
|
|
4989
|
+
const sourceId = requiredMessageId(formData);
|
|
4990
|
+
const source = await mailRepository.findById(sourceId);
|
|
4991
|
+
if (!source) throw new Error("Mail message not found.");
|
|
4992
|
+
await mailService.sendMail({
|
|
4993
|
+
attachments: source.attachments,
|
|
4994
|
+
bcc: source.bcc,
|
|
4995
|
+
cc: source.cc,
|
|
4996
|
+
fromEmail: source.fromEmail,
|
|
4997
|
+
fromName: source.fromName ?? undefined,
|
|
4998
|
+
headers: source.headers,
|
|
4999
|
+
htmlBody: source.htmlBody ?? undefined,
|
|
5000
|
+
metadata: { ...source.metadata, retriedFromMessageId: source.id },
|
|
5001
|
+
plainBody: source.plainBody ?? undefined,
|
|
5002
|
+
replyTo: source.replyTo ?? undefined,
|
|
5003
|
+
subject: source.subject,
|
|
5004
|
+
tag: source.tag ?? undefined,
|
|
5005
|
+
to: source.to,
|
|
5006
|
+
});
|
|
5007
|
+
revalidatePath("${adminPath}");
|
|
5008
|
+
}
|
|
5009
|
+
`;
|
|
5010
|
+
}
|
|
5011
|
+
function mailAdminPageTemplate(config) {
|
|
5012
|
+
if (config.ui.adapter !== "mui") {
|
|
5013
|
+
return `import { authorizeMailAdmin } from "${toAliasImportPath(config.modules.accessModule)}";
|
|
5014
|
+
|
|
5015
|
+
export default async function MailAdminPage() {
|
|
5016
|
+
await authorizeMailAdmin();
|
|
5017
|
+
return <main><h1>Mail</h1><p>Connect an app-owned admin UI to the Loom mail service.</p></main>;
|
|
5018
|
+
}
|
|
5019
|
+
`;
|
|
5020
|
+
}
|
|
5021
|
+
return `import { AdminMailConsole, type MailAdminRow } from "@gadicc/loom/mui/mail";
|
|
5022
|
+
import { authorizeMailAdmin } from "${toAliasImportPath(config.modules.accessModule)}";
|
|
5023
|
+
import { cancelMail, retryMail, sendTestMail } from "${toAliasImportPath(config.modules.actionsModule)}";
|
|
5024
|
+
import { mailRepository } from "${toAliasImportPath(config.modules.repositoryModule)}";
|
|
5025
|
+
|
|
5026
|
+
export default async function MailAdminPage() {
|
|
5027
|
+
await authorizeMailAdmin();
|
|
5028
|
+
const messages = await mailRepository.listRecent(100);
|
|
5029
|
+
const deliveries = await Promise.all(
|
|
5030
|
+
messages.map((message) => mailRepository.listDeliveries(message.id)),
|
|
5031
|
+
);
|
|
5032
|
+
const rows: MailAdminRow[] = messages.map((message, index) => ({
|
|
5033
|
+
createdAt: message.createdAt.toISOString(),
|
|
5034
|
+
id: message.id,
|
|
5035
|
+
providerMessageId: message.providerMessageId,
|
|
5036
|
+
recipients: (deliveries[index] ?? []).map((delivery) => ({
|
|
5037
|
+
email: delivery.email,
|
|
5038
|
+
kind: delivery.kind,
|
|
5039
|
+
status: delivery.status,
|
|
5040
|
+
})),
|
|
5041
|
+
status: message.status,
|
|
5042
|
+
subject: message.subject,
|
|
5043
|
+
tag: message.tag,
|
|
5044
|
+
}));
|
|
5045
|
+
return (
|
|
5046
|
+
<AdminMailConsole
|
|
5047
|
+
cancelAction={cancelMail}
|
|
5048
|
+
retryAction={retryMail}
|
|
5049
|
+
rows={rows}
|
|
5050
|
+
testAction={sendTestMail}
|
|
5051
|
+
/>
|
|
5052
|
+
);
|
|
5053
|
+
}
|
|
5054
|
+
`;
|
|
5055
|
+
}
|
|
5056
|
+
function mailWebhookRouteTemplate(config) {
|
|
5057
|
+
return `import { createPostalWebhookRouteHandler } from "@gadicc/loom/next/mail";
|
|
5058
|
+
import { mailService } from "${toAliasImportPath(config.modules.serviceModule)}";
|
|
5059
|
+
import { getPostalWebhookPublicKeys } from "${toAliasImportPath(config.modules.transportModule)}";
|
|
5060
|
+
|
|
5061
|
+
export const POST = createPostalWebhookRouteHandler({
|
|
5062
|
+
handleEvent: (event) => mailService.handleProviderEvent(event),
|
|
5063
|
+
publicKeys: getPostalWebhookPublicKeys,
|
|
5064
|
+
});
|
|
5065
|
+
`;
|
|
5066
|
+
}
|
|
5067
|
+
function mailJobTemplate(config) {
|
|
5068
|
+
return `import type { Job } from "@gadicc/loom/jobs";
|
|
5069
|
+
import { mailService } from "${toAliasImportPath(config.modules.serviceModule)}";
|
|
5070
|
+
|
|
5071
|
+
export const meta = {
|
|
5072
|
+
id: "mail-drain",
|
|
5073
|
+
desc: "Deliver due messages from the durable mail outbox.",
|
|
5074
|
+
};
|
|
5075
|
+
|
|
5076
|
+
export const handler: Job["handler"] = async (job, params) => {
|
|
5077
|
+
const parsed = typeof params.limit === "string" ? Number(params.limit) : Number.NaN;
|
|
5078
|
+
const limit = Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 20;
|
|
5079
|
+
const result = await mailService.drain(limit);
|
|
5080
|
+
job.json({ result });
|
|
5081
|
+
};
|
|
5082
|
+
`;
|
|
5083
|
+
}
|
|
5084
|
+
async function readTsModuleNames(path) {
|
|
5085
|
+
try {
|
|
5086
|
+
const entries = await (0, promises_1.readdir)(path, { withFileTypes: true });
|
|
5087
|
+
return entries
|
|
5088
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".ts"))
|
|
5089
|
+
.map((entry) => entry.name.replace(/\.ts$/, ""))
|
|
5090
|
+
.filter((name) => name !== "index" && !name.startsWith("_"))
|
|
5091
|
+
.sort();
|
|
5092
|
+
}
|
|
5093
|
+
catch (error) {
|
|
5094
|
+
if (isNodeErrorCode(error, "ENOENT")) {
|
|
5095
|
+
return [];
|
|
5096
|
+
}
|
|
5097
|
+
throw error;
|
|
5098
|
+
}
|
|
5099
|
+
}
|
|
5100
|
+
function buildValibotBarrelText(generatedNames, refinementNames) {
|
|
5101
|
+
const refinementSet = new Set(refinementNames);
|
|
5102
|
+
const names = [...new Set([...generatedNames, ...refinementNames])].sort();
|
|
5103
|
+
if (!names.length) {
|
|
5104
|
+
return null;
|
|
5105
|
+
}
|
|
5106
|
+
return `${names.map((name) => refinementSet.has(name)
|
|
5107
|
+
? `export * from "./refinements/${name}";`
|
|
5108
|
+
: `export * from "./generated/${name}";`).join("\n")}\n`;
|
|
5109
|
+
}
|
|
5110
|
+
async function syncValibotBarrel(cwd, config) {
|
|
5111
|
+
const generatedNames = await readTsModuleNames((0, node_path_1.join)(cwd, config.dirs.valibotGeneratedDir));
|
|
4160
5112
|
const refinementNames = await readTsModuleNames((0, node_path_1.join)(cwd, config.dirs.valibotRefinementsDir));
|
|
4161
5113
|
const text = buildValibotBarrelText(generatedNames, refinementNames);
|
|
4162
5114
|
if (!text) {
|
|
@@ -4171,7 +5123,9 @@ function getLatestManagedSchemaConfig(schema) {
|
|
|
4171
5123
|
? schema.idGeneration === "uuid-v7"
|
|
4172
5124
|
? FILES_SCHEMA_UUID_V7_BLUEPRINT_VERSION
|
|
4173
5125
|
: FILES_SCHEMA_UUID_V4_BLUEPRINT_VERSION
|
|
4174
|
-
:
|
|
5126
|
+
: schema.blueprint === "mail"
|
|
5127
|
+
? MAIL_SCHEMA_BLUEPRINT_VERSION
|
|
5128
|
+
: API_KEY_AUDIT_SCHEMA_BLUEPRINT_VERSION,
|
|
4175
5129
|
};
|
|
4176
5130
|
return {
|
|
4177
5131
|
...latest,
|
|
@@ -4184,6 +5138,8 @@ function getManagedSchemaText(schema) {
|
|
|
4184
5138
|
return buildApiKeyAuditSchemaText(schema);
|
|
4185
5139
|
case "files":
|
|
4186
5140
|
return buildFilesSchemaText(schema);
|
|
5141
|
+
case "mail":
|
|
5142
|
+
return buildMailSchemaText(schema);
|
|
4187
5143
|
}
|
|
4188
5144
|
}
|
|
4189
5145
|
function getSchemaBarrelExportLine(schema, dbConfig) {
|
|
@@ -4295,14 +5251,11 @@ async function materializeManagedSchema(cwd, schema, dbConfig) {
|
|
|
4295
5251
|
};
|
|
4296
5252
|
}
|
|
4297
5253
|
async function readProjectPackageJson(cwd) {
|
|
4298
|
-
const
|
|
4299
|
-
const packageJsonText = await readTextIfExists(packageJsonPath);
|
|
4300
|
-
if (!packageJsonText) {
|
|
4301
|
-
throw new Error(`No package.json found in ${cwd}`);
|
|
4302
|
-
}
|
|
5254
|
+
const metadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
4303
5255
|
return {
|
|
4304
|
-
packageJson:
|
|
4305
|
-
packageJsonPath,
|
|
5256
|
+
packageJson: metadata.packageJson,
|
|
5257
|
+
packageJsonPath: metadata.path,
|
|
5258
|
+
projectConfig: metadata.config,
|
|
4306
5259
|
};
|
|
4307
5260
|
}
|
|
4308
5261
|
async function resolveDbProjectConfig(cwd) {
|
|
@@ -4365,8 +5318,25 @@ async function syncDbSchemas(cwd) {
|
|
|
4365
5318
|
suggestions.add("Move API-key audit schema additions to separate local schema files, then rerun `loom db schemas sync`.");
|
|
4366
5319
|
}
|
|
4367
5320
|
}
|
|
5321
|
+
const mailFeature = manifest.features.mail;
|
|
5322
|
+
if (mailFeature?.status === "active") {
|
|
5323
|
+
const mailConfig = getMailConfig(framework, dbConfig, (await readProjectPackageJson(cwd)).packageJson, mailFeature.config, manifest.features.jobs?.status === "active");
|
|
5324
|
+
const materialized = await materializeManagedSchema(cwd, mailConfig.schema, dbConfig);
|
|
5325
|
+
changedFiles.push(...materialized.changedFiles);
|
|
5326
|
+
issues.push(...materialized.issues);
|
|
5327
|
+
notes.push(...materialized.notes);
|
|
5328
|
+
if (!materialized.issues.length) {
|
|
5329
|
+
mailConfig.schema = materialized.schema;
|
|
5330
|
+
mailFeature.config = mailConfig;
|
|
5331
|
+
manifest.features.mail = mailFeature;
|
|
5332
|
+
}
|
|
5333
|
+
else {
|
|
5334
|
+
suggestions.add("Move mail schema additions to separate local schema files, then rerun `loom db schemas sync`.");
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
4368
5337
|
if ((!filesFeature || filesFeature.status !== "active") &&
|
|
4369
|
-
(!apiKeysFeature || apiKeysFeature.status !== "active")
|
|
5338
|
+
(!apiKeysFeature || apiKeysFeature.status !== "active") &&
|
|
5339
|
+
(!mailFeature || mailFeature.status !== "active")) {
|
|
4370
5340
|
notes.push("No active Loom-managed DB schemas are configured.");
|
|
4371
5341
|
}
|
|
4372
5342
|
const manifestPath = (0, node_path_1.join)(cwd, "loom.json");
|
|
@@ -4374,7 +5344,8 @@ async function syncDbSchemas(cwd) {
|
|
|
4374
5344
|
changedFiles.push("loom.json");
|
|
4375
5345
|
}
|
|
4376
5346
|
if (changedFiles.length) {
|
|
4377
|
-
|
|
5347
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
5348
|
+
notes.push(`No migrations were generated. Review the schema diff, then run ${(0, projectTooling_js_1.formatTaskInvocation)(tooling.tasks, "db:generate")} if the schema changed.`);
|
|
4378
5349
|
}
|
|
4379
5350
|
return {
|
|
4380
5351
|
changedFiles: [...new Set(changedFiles)],
|
|
@@ -4715,7 +5686,7 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
4715
5686
|
if (options.localProvider === "r2" && !options.localBucket) {
|
|
4716
5687
|
throw new Error("--local-provider r2 requires an explicit --local-bucket.");
|
|
4717
5688
|
}
|
|
4718
|
-
const { packageJson
|
|
5689
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
4719
5690
|
const framework = await detectFramework(cwd, packageJson);
|
|
4720
5691
|
const manifestPath = (0, node_path_1.join)(cwd, "loom.json");
|
|
4721
5692
|
const manifestText = await readTextIfExists(manifestPath);
|
|
@@ -4723,6 +5694,7 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
4723
5694
|
throw new Error("Missing loom.json. Run `loom add files` first.");
|
|
4724
5695
|
}
|
|
4725
5696
|
const manifest = parseJson(manifestText, "loom.json");
|
|
5697
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
4726
5698
|
const feature = manifest.features.files;
|
|
4727
5699
|
if (!feature || feature.status !== "active") {
|
|
4728
5700
|
throw new Error("The files feature is not active. Run `loom add files` first.");
|
|
@@ -4880,11 +5852,10 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
4880
5852
|
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.`);
|
|
4881
5853
|
}
|
|
4882
5854
|
}
|
|
4883
|
-
const dependencyUpdate =
|
|
5855
|
+
const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, { dependencies: FILES_S3_DEPENDENCIES });
|
|
4884
5856
|
if (dependencyUpdate.changed) {
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
notes.push(`Added files storage dependency: ${dependencyUpdate.changedKeys.join(", ")}.`);
|
|
5857
|
+
changedFiles.push(dependencyUpdate.config);
|
|
5858
|
+
notes.push(`Added files storage dependency: ${dependencyUpdate.changedKeys.join(", ")} to ${dependencyUpdate.config}.`);
|
|
4888
5859
|
}
|
|
4889
5860
|
const storagePath = (0, node_path_1.join)(cwd, config.modules.storageModule);
|
|
4890
5861
|
const storageText = await readTextIfExists(storagePath);
|
|
@@ -6337,26 +7308,21 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
6337
7308
|
? structuredClone(currentFeature)
|
|
6338
7309
|
: { status: "planned" };
|
|
6339
7310
|
const config = mergeJobsConfig(framework, feature.config);
|
|
6340
|
-
const
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
if (
|
|
6349
|
-
scriptsUpdate.
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
}
|
|
6353
|
-
if (dependencyUpdate.changedKeys.length ||
|
|
6354
|
-
devDependencyUpdate.changedKeys.length) {
|
|
6355
|
-
notes.push(`Added jobs package.json dependencies: ${[...dependencyUpdate.changedKeys, ...devDependencyUpdate.changedKeys]
|
|
6356
|
-
.join(", ")}`);
|
|
7311
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7312
|
+
const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, {
|
|
7313
|
+
dependencies: JOBS_DEFAULT_DEPENDENCIES,
|
|
7314
|
+
devDependencies: JOBS_DEFAULT_DEV_DEPENDENCIES,
|
|
7315
|
+
});
|
|
7316
|
+
const scriptsUpdate = await ensureProjectTasks(cwd, manifest, getJobsExpectedScripts(config));
|
|
7317
|
+
if (dependencyUpdate.changed)
|
|
7318
|
+
changedFiles.push(dependencyUpdate.config);
|
|
7319
|
+
if (scriptsUpdate.changedKeys.length)
|
|
7320
|
+
changedFiles.push(scriptsUpdate.config);
|
|
7321
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
7322
|
+
notes.push(`Added jobs dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
6357
7323
|
}
|
|
6358
7324
|
if (scriptsUpdate.changedKeys.length) {
|
|
6359
|
-
notes.push(`Updated jobs
|
|
7325
|
+
notes.push(`Updated jobs tasks in ${scriptsUpdate.config}: ${scriptsUpdate.changedKeys.join(", ")}`);
|
|
6360
7326
|
}
|
|
6361
7327
|
if (activate && feature.status !== "active") {
|
|
6362
7328
|
feature.status = "active";
|
|
@@ -6451,41 +7417,35 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
|
|
|
6451
7417
|
}
|
|
6452
7418
|
feature.config = config;
|
|
6453
7419
|
manifest.features.db = feature;
|
|
6454
|
-
const
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
const
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
packageJsonChanged ||= removedDependencyUpdate.changed;
|
|
6469
|
-
if (packageJsonChanged) {
|
|
6470
|
-
await (0, promises_1.writeFile)(packageJsonPath, stringifyJson(nextPackageJson), "utf8");
|
|
6471
|
-
changedFiles.push("package.json");
|
|
6472
|
-
}
|
|
6473
|
-
if (dependencyUpdate.changedKeys.length ||
|
|
6474
|
-
devDependencyUpdate.changedKeys.length) {
|
|
6475
|
-
notes.push(`Added DB package.json dependencies: ${[...dependencyUpdate.changedKeys, ...devDependencyUpdate.changedKeys]
|
|
6476
|
-
.join(", ")}`);
|
|
7420
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7421
|
+
const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, {
|
|
7422
|
+
dependencies: DB_DEFAULT_DEPENDENCIES,
|
|
7423
|
+
devDependencies: DB_DEFAULT_DEV_DEPENDENCIES,
|
|
7424
|
+
remove: DB_MOVED_DEPENDENCIES,
|
|
7425
|
+
});
|
|
7426
|
+
const scriptsUpdate = await ensureProjectTasks(cwd, manifest, getDbExpectedScripts(config, tooling));
|
|
7427
|
+
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
7428
|
+
if (dependencyUpdate.changed)
|
|
7429
|
+
changedFiles.push(dependencyUpdate.config);
|
|
7430
|
+
if (scriptsUpdate.changedKeys.length)
|
|
7431
|
+
changedFiles.push(scriptsUpdate.config);
|
|
7432
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
7433
|
+
notes.push(`Added DB dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
6477
7434
|
}
|
|
6478
7435
|
if (scriptsUpdate.changedKeys.length) {
|
|
6479
|
-
notes.push(`Updated DB
|
|
7436
|
+
notes.push(`Updated DB tasks in ${scriptsUpdate.config}: ${scriptsUpdate.changedKeys.join(", ")}`);
|
|
6480
7437
|
}
|
|
6481
|
-
if (
|
|
6482
|
-
notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${
|
|
7438
|
+
if (dependencyUpdate.removedKeys.length) {
|
|
7439
|
+
notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${dependencyUpdate.removedKeys.join(", ")}`);
|
|
6483
7440
|
}
|
|
6484
7441
|
const managedFiles = [
|
|
6485
7442
|
[config.modules.neonModule, dbNeonTemplate()],
|
|
6486
7443
|
[config.modules.neonFullModule, dbNeonFullTemplate()],
|
|
6487
7444
|
[config.modules.drizzleConfig, dbDrizzleConfigTemplate(config)],
|
|
6488
|
-
[
|
|
7445
|
+
[
|
|
7446
|
+
config.modules.pgliteHarnessModule,
|
|
7447
|
+
dbPgliteHarnessTemplate(config, testRunner),
|
|
7448
|
+
],
|
|
6489
7449
|
[config.modules.scriptsTsconfig, dbScriptsTsconfigTemplate()],
|
|
6490
7450
|
[
|
|
6491
7451
|
config.modules.refinementsCommonModule,
|
|
@@ -6555,7 +7515,8 @@ async function applyFilesFeature(cwd, framework, manifest, activate) {
|
|
|
6555
7515
|
changedFiles.push(...materialized.changedFiles);
|
|
6556
7516
|
notes.push(...materialized.notes);
|
|
6557
7517
|
config.schema = materialized.schema;
|
|
6558
|
-
|
|
7518
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7519
|
+
notes.push(`No migration was generated. Review the schema diff, then run ${(0, projectTooling_js_1.formatTaskInvocation)(tooling.tasks, "db:generate")} when you are ready to create the app-local migration.`);
|
|
6559
7520
|
}
|
|
6560
7521
|
const scaffoldFiles = [
|
|
6561
7522
|
[
|
|
@@ -6593,6 +7554,93 @@ async function applyFilesFeature(cwd, framework, manifest, activate) {
|
|
|
6593
7554
|
manifest.features.files = feature;
|
|
6594
7555
|
return { changedFiles, notes };
|
|
6595
7556
|
}
|
|
7557
|
+
async function applyMailFeature(cwd, framework, manifest, activate) {
|
|
7558
|
+
const changedFiles = [];
|
|
7559
|
+
const notes = [];
|
|
7560
|
+
const currentFeature = manifest.features.mail;
|
|
7561
|
+
if (!activate && currentFeature?.status !== "active") {
|
|
7562
|
+
return { changedFiles, notes };
|
|
7563
|
+
}
|
|
7564
|
+
for (const dependency of ["auth", "db"]) {
|
|
7565
|
+
if (manifest.features[dependency]?.status !== "active") {
|
|
7566
|
+
if (activate) {
|
|
7567
|
+
throw new Error(`The mail feature requires the active ${dependency} feature. Run \`loom add ${dependency}\` first.`);
|
|
7568
|
+
}
|
|
7569
|
+
notes.push(`Mail requires the active ${dependency} feature.`);
|
|
7570
|
+
return { changedFiles, notes };
|
|
7571
|
+
}
|
|
7572
|
+
}
|
|
7573
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
7574
|
+
const dbConfig = mergeDbConfig(framework, manifest.features.db.config);
|
|
7575
|
+
const config = getMailConfig(framework, dbConfig, packageJson, currentFeature?.config, manifest.features.jobs?.status === "active");
|
|
7576
|
+
const feature = currentFeature
|
|
7577
|
+
? structuredClone(currentFeature)
|
|
7578
|
+
: { status: "planned" };
|
|
7579
|
+
if (activate && feature.status !== "active") {
|
|
7580
|
+
feature.status = "active";
|
|
7581
|
+
feature.activatedOn ??= todayIso();
|
|
7582
|
+
}
|
|
7583
|
+
if (activate) {
|
|
7584
|
+
const materialized = await materializeManagedSchema(cwd, config.schema, dbConfig);
|
|
7585
|
+
if (materialized.issues.length) {
|
|
7586
|
+
throw new Error(materialized.issues.join("\n"));
|
|
7587
|
+
}
|
|
7588
|
+
changedFiles.push(...materialized.changedFiles);
|
|
7589
|
+
notes.push(...materialized.notes);
|
|
7590
|
+
config.schema = materialized.schema;
|
|
7591
|
+
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.");
|
|
7592
|
+
}
|
|
7593
|
+
const scaffolds = [
|
|
7594
|
+
[config.modules.accessModule, mailAccessTemplate(), "admin access policy"],
|
|
7595
|
+
[
|
|
7596
|
+
config.modules.repositoryModule,
|
|
7597
|
+
mailRepositoryTemplate(config, dbConfig),
|
|
7598
|
+
"repository",
|
|
7599
|
+
],
|
|
7600
|
+
[
|
|
7601
|
+
config.modules.transportModule,
|
|
7602
|
+
mailTransportTemplate(),
|
|
7603
|
+
"Postal transport",
|
|
7604
|
+
],
|
|
7605
|
+
[config.modules.serviceModule, mailServiceTemplate(config), "service"],
|
|
7606
|
+
[
|
|
7607
|
+
config.modules.actionsModule,
|
|
7608
|
+
mailActionsTemplate(config),
|
|
7609
|
+
"admin actions",
|
|
7610
|
+
],
|
|
7611
|
+
[config.entrypoints.adminPage, mailAdminPageTemplate(config), "admin page"],
|
|
7612
|
+
[
|
|
7613
|
+
config.entrypoints.webhookRoute,
|
|
7614
|
+
mailWebhookRouteTemplate(config),
|
|
7615
|
+
"Postal webhook route",
|
|
7616
|
+
],
|
|
7617
|
+
];
|
|
7618
|
+
if (config.jobs.enabled) {
|
|
7619
|
+
scaffolds.push([
|
|
7620
|
+
config.modules.jobModule,
|
|
7621
|
+
mailJobTemplate(config),
|
|
7622
|
+
"outbox drain job",
|
|
7623
|
+
]);
|
|
7624
|
+
}
|
|
7625
|
+
for (const [relativePath, text, label] of scaffolds) {
|
|
7626
|
+
const scaffoldState = await scaffoldTextFile((0, node_path_1.join)(cwd, relativePath), text);
|
|
7627
|
+
if (scaffoldState === "created") {
|
|
7628
|
+
changedFiles.push(relativePath);
|
|
7629
|
+
}
|
|
7630
|
+
else if (activate && scaffoldState === "preserved") {
|
|
7631
|
+
notes.push(`Preserved existing mail ${label}: ${relativePath}`);
|
|
7632
|
+
}
|
|
7633
|
+
}
|
|
7634
|
+
if (config.ui.adapter === "mui") {
|
|
7635
|
+
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.`);
|
|
7636
|
+
}
|
|
7637
|
+
if (config.jobs.enabled) {
|
|
7638
|
+
notes.push(`Register ${config.modules.jobModule} in the app-owned jobs catalogs and scheduling policy; Loom did not rewrite them.`);
|
|
7639
|
+
}
|
|
7640
|
+
feature.config = config;
|
|
7641
|
+
manifest.features.mail = feature;
|
|
7642
|
+
return { changedFiles, notes };
|
|
7643
|
+
}
|
|
6596
7644
|
async function applyApiKeysFeature(cwd, framework, manifest, activate) {
|
|
6597
7645
|
const changedFiles = [];
|
|
6598
7646
|
const notes = [];
|
|
@@ -6724,12 +7772,246 @@ async function applyAuthFeature(cwd, framework, manifest, activate) {
|
|
|
6724
7772
|
}
|
|
6725
7773
|
return { changedFiles, notes };
|
|
6726
7774
|
}
|
|
7775
|
+
function linguiCliCommand(tooling) {
|
|
7776
|
+
switch (tooling.dependencies.manager) {
|
|
7777
|
+
case "deno":
|
|
7778
|
+
return "deno run -A npm:@lingui/cli";
|
|
7779
|
+
case "npm":
|
|
7780
|
+
return "npx lingui";
|
|
7781
|
+
case "pnpm":
|
|
7782
|
+
return "pnpm lingui";
|
|
7783
|
+
case "yarn":
|
|
7784
|
+
return "yarn lingui";
|
|
7785
|
+
}
|
|
7786
|
+
}
|
|
7787
|
+
function linguiConfigTemplate(framework) {
|
|
7788
|
+
const sourceRoot = framework.srcDir ? "src/" : "";
|
|
7789
|
+
return `import { formatter } from "@lingui/format-po";
|
|
7790
|
+
|
|
7791
|
+
/** @type {import("@lingui/conf").LinguiConfig} */
|
|
7792
|
+
export default {
|
|
7793
|
+
locales: ["en"],
|
|
7794
|
+
sourceLocale: "en",
|
|
7795
|
+
catalogs: [
|
|
7796
|
+
{
|
|
7797
|
+
path: "<rootDir>/${sourceRoot}locales/{locale}/messages",
|
|
7798
|
+
include: ["<rootDir>/${sourceRoot}**/*.{ts,tsx}"],
|
|
7799
|
+
},
|
|
7800
|
+
],
|
|
7801
|
+
format: formatter({ lineNumbers: false }),
|
|
7802
|
+
};
|
|
7803
|
+
`;
|
|
7804
|
+
}
|
|
7805
|
+
function generatedLinguiCatalogsFromConfig(configText, framework) {
|
|
7806
|
+
const paths = [...configText.matchAll(/\bpath\s*:\s*["'`]([^"'`]+)["'`]/g)]
|
|
7807
|
+
.map((match) => match[1])
|
|
7808
|
+
.filter((path) => Boolean(path))
|
|
7809
|
+
.map((path) => path
|
|
7810
|
+
.replace(/^<rootDir>\//, "")
|
|
7811
|
+
.replaceAll("{locale}", "*")
|
|
7812
|
+
.replaceAll("{name}", "*")
|
|
7813
|
+
.replaceAll("\\", "/")
|
|
7814
|
+
.replace(/\.(?:js|po)$/, "") + ".js");
|
|
7815
|
+
return [
|
|
7816
|
+
...new Set(paths.length
|
|
7817
|
+
? paths
|
|
7818
|
+
: [`${framework.srcDir ? "src/" : ""}locales/*/messages.js`]),
|
|
7819
|
+
];
|
|
7820
|
+
}
|
|
7821
|
+
async function findLinguiConfigPath(cwd) {
|
|
7822
|
+
return await findFirstExistingRelativePath(cwd, [
|
|
7823
|
+
...LINGUI_CONFIG_CANDIDATES,
|
|
7824
|
+
]);
|
|
7825
|
+
}
|
|
7826
|
+
async function findSourceFilesMatching(cwd, pattern, relativeDir = "") {
|
|
7827
|
+
const results = [];
|
|
7828
|
+
let entries;
|
|
7829
|
+
try {
|
|
7830
|
+
entries = await (0, promises_1.readdir)((0, node_path_1.join)(cwd, relativeDir), { withFileTypes: true });
|
|
7831
|
+
}
|
|
7832
|
+
catch (error) {
|
|
7833
|
+
if (isNodeErrorCode(error, "ENOENT"))
|
|
7834
|
+
return results;
|
|
7835
|
+
throw error;
|
|
7836
|
+
}
|
|
7837
|
+
for (const entry of entries) {
|
|
7838
|
+
const relativePath = relativeDir
|
|
7839
|
+
? (0, node_path_1.join)(relativeDir, entry.name)
|
|
7840
|
+
: entry.name;
|
|
7841
|
+
if (entry.isDirectory()) {
|
|
7842
|
+
if (!ENV_LOADER_SCAN_IGNORED_DIRS.has(entry.name)) {
|
|
7843
|
+
results.push(...await findSourceFilesMatching(cwd, pattern, relativePath));
|
|
7844
|
+
}
|
|
7845
|
+
continue;
|
|
7846
|
+
}
|
|
7847
|
+
if (!entry.isFile() || !hasScannedSourceExtension(entry.name))
|
|
7848
|
+
continue;
|
|
7849
|
+
const text = await readTextIfExists((0, node_path_1.join)(cwd, relativePath));
|
|
7850
|
+
pattern.lastIndex = 0;
|
|
7851
|
+
if (text && pattern.test(text)) {
|
|
7852
|
+
results.push(relativePath.replaceAll("\\", "/"));
|
|
7853
|
+
}
|
|
7854
|
+
}
|
|
7855
|
+
return results.sort();
|
|
7856
|
+
}
|
|
7857
|
+
async function detectLinguiCatalogMode(cwd) {
|
|
7858
|
+
const poImports = await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']+\.po["']/);
|
|
7859
|
+
if (poImports.length)
|
|
7860
|
+
return "loader";
|
|
7861
|
+
const nextConfigPath = await findNextConfigPath(cwd);
|
|
7862
|
+
const nextConfigText = nextConfigPath
|
|
7863
|
+
? await readTextIfExists((0, node_path_1.join)(cwd, nextConfigPath))
|
|
7864
|
+
: null;
|
|
7865
|
+
return nextConfigText?.includes("@lingui/loader") ? "loader" : "precompile";
|
|
7866
|
+
}
|
|
7867
|
+
async function getLinguiConfig(cwd, framework, currentConfig) {
|
|
7868
|
+
const configFile = currentConfig?.configFile ??
|
|
7869
|
+
await findLinguiConfigPath(cwd) ?? "lingui.config.ts";
|
|
7870
|
+
const configText = await readTextIfExists((0, node_path_1.join)(cwd, configFile)) ??
|
|
7871
|
+
linguiConfigTemplate(framework);
|
|
7872
|
+
return {
|
|
7873
|
+
catalogMode: currentConfig?.catalogMode ??
|
|
7874
|
+
await detectLinguiCatalogMode(cwd),
|
|
7875
|
+
configFile,
|
|
7876
|
+
generatedCatalogs: currentConfig?.generatedCatalogs?.length
|
|
7877
|
+
? [...new Set(currentConfig.generatedCatalogs)]
|
|
7878
|
+
: generatedLinguiCatalogsFromConfig(configText, framework),
|
|
7879
|
+
tasks: {
|
|
7880
|
+
...LINGUI_DEFAULT_TASKS,
|
|
7881
|
+
...currentConfig?.tasks,
|
|
7882
|
+
},
|
|
7883
|
+
};
|
|
7884
|
+
}
|
|
7885
|
+
function linguiTaskRuns(command, action) {
|
|
7886
|
+
return Boolean(command?.includes("lingui") &&
|
|
7887
|
+
new RegExp(`(?:^|\\s)${action}(?:\\s|$)`).test(command));
|
|
7888
|
+
}
|
|
7889
|
+
function dependencyMajor(spec) {
|
|
7890
|
+
const match = spec?.match(/(?:^|[^0-9])(\d+)\./);
|
|
7891
|
+
return match ? Number(match[1]) : null;
|
|
7892
|
+
}
|
|
7893
|
+
function linguiPoDeclarationTemplate() {
|
|
7894
|
+
return `declare module "*.po" {
|
|
7895
|
+
import type { Messages } from "@lingui/core";
|
|
7896
|
+
|
|
7897
|
+
export const messages: Messages;
|
|
7898
|
+
}
|
|
7899
|
+
`;
|
|
7900
|
+
}
|
|
7901
|
+
async function applyLinguiFeature(cwd, framework, manifest, activate) {
|
|
7902
|
+
const changedFiles = [];
|
|
7903
|
+
const notes = [];
|
|
7904
|
+
const currentFeature = manifest.features.lingui;
|
|
7905
|
+
const config = await getLinguiConfig(cwd, framework, currentFeature?.config);
|
|
7906
|
+
const feature = currentFeature
|
|
7907
|
+
? structuredClone(currentFeature)
|
|
7908
|
+
: { status: "planned" };
|
|
7909
|
+
if (activate && feature.status !== "active") {
|
|
7910
|
+
feature.status = "active";
|
|
7911
|
+
feature.activatedOn ??= todayIso();
|
|
7912
|
+
}
|
|
7913
|
+
feature.config = config;
|
|
7914
|
+
manifest.features.lingui = feature;
|
|
7915
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
7916
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7917
|
+
const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, {
|
|
7918
|
+
dependencies: LINGUI_DEFAULT_DEPENDENCIES,
|
|
7919
|
+
devDependencies: {
|
|
7920
|
+
...LINGUI_DEFAULT_DEV_DEPENDENCIES,
|
|
7921
|
+
...(config.catalogMode === "loader"
|
|
7922
|
+
? LINGUI_LOADER_DEV_DEPENDENCIES
|
|
7923
|
+
: {}),
|
|
7924
|
+
},
|
|
7925
|
+
});
|
|
7926
|
+
if (dependencyUpdate.changed)
|
|
7927
|
+
changedFiles.push(dependencyUpdate.config);
|
|
7928
|
+
const configState = await scaffoldTextFile((0, node_path_1.join)(cwd, config.configFile), linguiConfigTemplate(framework));
|
|
7929
|
+
if (configState === "created") {
|
|
7930
|
+
changedFiles.push(config.configFile);
|
|
7931
|
+
notes.push(`Scaffolded ${config.configFile} with an English starter locale; update its locales and catalog include paths for the app.`);
|
|
7932
|
+
}
|
|
7933
|
+
else if (activate && configState === "preserved") {
|
|
7934
|
+
notes.push(`Preserved existing Lingui config: ${config.configFile}`);
|
|
7935
|
+
}
|
|
7936
|
+
const taskChanges = [];
|
|
7937
|
+
const executable = linguiCliCommand(tooling);
|
|
7938
|
+
for (const [name, command] of [
|
|
7939
|
+
[config.tasks.extract, `${executable} extract --clean`],
|
|
7940
|
+
[config.tasks.compile, `${executable} compile`],
|
|
7941
|
+
]) {
|
|
7942
|
+
const result = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, {
|
|
7943
|
+
definition: command,
|
|
7944
|
+
name,
|
|
7945
|
+
});
|
|
7946
|
+
if (result.changed)
|
|
7947
|
+
taskChanges.push(name);
|
|
7948
|
+
}
|
|
7949
|
+
let taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
7950
|
+
if (!(0, projectTooling_js_1.getTaskCommand)(taskStore.definitions[config.tasks.build])) {
|
|
7951
|
+
const result = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, {
|
|
7952
|
+
definition: framework.kind === "nextjs" ? "next build" : "build",
|
|
7953
|
+
name: config.tasks.build,
|
|
7954
|
+
});
|
|
7955
|
+
if (result.changed)
|
|
7956
|
+
taskChanges.push(config.tasks.build);
|
|
7957
|
+
taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
7958
|
+
}
|
|
7959
|
+
const buildCommand = (0, projectTooling_js_1.getTaskCommand)(taskStore.definitions[config.tasks.build]);
|
|
7960
|
+
if (config.catalogMode === "precompile" && buildCommand &&
|
|
7961
|
+
!(0, projectTooling_js_1.taskInvokes)(taskStore, config.tasks.build, config.tasks.compile)) {
|
|
7962
|
+
const result = await (0, projectTooling_js_1.ensureTaskPrerequisite)(cwd, tooling.tasks, config.tasks.build, config.tasks.compile);
|
|
7963
|
+
if (result.changed)
|
|
7964
|
+
taskChanges.push(config.tasks.build);
|
|
7965
|
+
}
|
|
7966
|
+
if (taskChanges.length)
|
|
7967
|
+
changedFiles.push(tooling.tasks.config);
|
|
7968
|
+
const gitignorePath = (0, node_path_1.join)(cwd, ".gitignore");
|
|
7969
|
+
const gitignoreUpdate = ensureLinguiGitignoreText(await readTextIfExists(gitignorePath), config.generatedCatalogs);
|
|
7970
|
+
if (gitignoreUpdate.changed) {
|
|
7971
|
+
await (0, promises_1.writeFile)(gitignorePath, gitignoreUpdate.text, "utf8");
|
|
7972
|
+
changedFiles.push(".gitignore");
|
|
7973
|
+
}
|
|
7974
|
+
if (config.catalogMode === "loader") {
|
|
7975
|
+
const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
|
|
7976
|
+
if (!poDeclarations.length) {
|
|
7977
|
+
const declarationPath = `${framework.srcDir ? "src/" : ""}lingui.d.ts`;
|
|
7978
|
+
if (await writeTextIfChanged((0, node_path_1.join)(cwd, declarationPath), linguiPoDeclarationTemplate())) {
|
|
7979
|
+
changedFiles.push(declarationPath);
|
|
7980
|
+
}
|
|
7981
|
+
}
|
|
7982
|
+
}
|
|
7983
|
+
if (framework.kind === "nextjs") {
|
|
7984
|
+
const nextConfigPath = await findNextConfigPath(cwd);
|
|
7985
|
+
const nextConfigText = nextConfigPath
|
|
7986
|
+
? await readTextIfExists((0, node_path_1.join)(cwd, nextConfigPath))
|
|
7987
|
+
: null;
|
|
7988
|
+
if (!nextConfigText?.includes("@lingui/swc-plugin")) {
|
|
7989
|
+
notes.push("Add @lingui/swc-plugin to experimental.swcPlugins in the app-owned Next config.");
|
|
7990
|
+
}
|
|
7991
|
+
if (config.catalogMode === "loader" &&
|
|
7992
|
+
!nextConfigText?.includes("@lingui/loader")) {
|
|
7993
|
+
notes.push("Add @lingui/loader .po rules for Turbopack and webpack in the app-owned Next config.");
|
|
7994
|
+
}
|
|
7995
|
+
}
|
|
7996
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
7997
|
+
notes.push(`Added Lingui dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
7998
|
+
}
|
|
7999
|
+
if (taskChanges.length) {
|
|
8000
|
+
notes.push(`Updated Lingui tasks in ${tooling.tasks.config}: ${[...new Set(taskChanges)].join(", ")}`);
|
|
8001
|
+
}
|
|
8002
|
+
if (packageJson.dependencies?.["@lingui/macro"] ||
|
|
8003
|
+
packageJson.devDependencies?.["@lingui/macro"]) {
|
|
8004
|
+
notes.push("The legacy @lingui/macro package remains app-owned; migrate imports to the v6 macro entrypoints before removing it.");
|
|
8005
|
+
}
|
|
8006
|
+
return { changedFiles, notes };
|
|
8007
|
+
}
|
|
6727
8008
|
async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
6728
8009
|
const changedFiles = [];
|
|
6729
8010
|
const notes = [];
|
|
6730
8011
|
const currentFeature = manifest.features.pwa;
|
|
6731
8012
|
const currentConfig = currentFeature?.config;
|
|
6732
|
-
const {
|
|
8013
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
8014
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
6733
8015
|
const config = await getPwaConfig(cwd, framework, packageJson, currentConfig, activate);
|
|
6734
8016
|
const feature = currentFeature
|
|
6735
8017
|
? structuredClone(currentFeature)
|
|
@@ -6740,31 +8022,48 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
|
|
|
6740
8022
|
}
|
|
6741
8023
|
feature.config = config;
|
|
6742
8024
|
manifest.features.pwa = feature;
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
8025
|
+
const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, {
|
|
8026
|
+
dependencies: PWA_DEFAULT_DEPENDENCIES,
|
|
8027
|
+
devDependencies: PWA_DEFAULT_DEV_DEPENDENCIES,
|
|
8028
|
+
});
|
|
8029
|
+
if (dependencyUpdate.changed)
|
|
8030
|
+
changedFiles.push(dependencyUpdate.config);
|
|
8031
|
+
const scriptsChanged = [];
|
|
8032
|
+
const pwaTask = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, {
|
|
8033
|
+
definition: PWA_BUILD_SCRIPT,
|
|
8034
|
+
name: "pwa:build",
|
|
8035
|
+
});
|
|
8036
|
+
if (pwaTask.changed)
|
|
8037
|
+
scriptsChanged.push("pwa:build");
|
|
8038
|
+
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
8039
|
+
const buildCommand = (0, projectTooling_js_1.getTaskCommand)(taskStore.definitions.build);
|
|
8040
|
+
if (!buildCommand) {
|
|
8041
|
+
const build = await (0, projectTooling_js_1.ensureTask)(cwd, tooling.tasks, {
|
|
8042
|
+
definition: `next build && ${(0, projectTooling_js_1.formatTaskInvocation)(tooling.tasks, "pwa:build")}`,
|
|
8043
|
+
name: "build",
|
|
8044
|
+
});
|
|
8045
|
+
if (build.changed)
|
|
8046
|
+
scriptsChanged.push("build");
|
|
6763
8047
|
}
|
|
6764
|
-
if (
|
|
6765
|
-
|
|
8048
|
+
else if (buildCommand.includes("next build") &&
|
|
8049
|
+
!(0, projectTooling_js_1.taskInvokes)(taskStore, "build", "pwa:build") &&
|
|
8050
|
+
!scriptRunsSerwistBuild(buildCommand)) {
|
|
8051
|
+
const build = await (0, projectTooling_js_1.ensureTaskFollowup)(cwd, tooling.tasks, "build", "pwa:build");
|
|
8052
|
+
if (build.changed)
|
|
8053
|
+
scriptsChanged.push("build");
|
|
8054
|
+
}
|
|
8055
|
+
else if (!(0, projectTooling_js_1.taskInvokes)(taskStore, "build", "pwa:build") &&
|
|
8056
|
+
!scriptRunsSerwistBuild(buildCommand)) {
|
|
8057
|
+
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.");
|
|
8058
|
+
}
|
|
8059
|
+
if (scriptsChanged.length)
|
|
8060
|
+
changedFiles.push(tooling.tasks.config);
|
|
8061
|
+
if (dependencyUpdate.changedKeys.length) {
|
|
8062
|
+
notes.push(`Added PWA dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
|
|
8063
|
+
}
|
|
8064
|
+
if (scriptsChanged.length) {
|
|
8065
|
+
notes.push(`Updated PWA tasks in ${tooling.tasks.config}: ${scriptsChanged.join(", ")}`);
|
|
6766
8066
|
}
|
|
6767
|
-
notes.push(...scriptsUpdate.notes);
|
|
6768
8067
|
const serwistConfigState = await scaffoldTextFile((0, node_path_1.join)(cwd, config.modules.serwistConfig), pwaSerwistConfigTemplate(config));
|
|
6769
8068
|
if (serwistConfigState === "created") {
|
|
6770
8069
|
changedFiles.push(config.modules.serwistConfig);
|
|
@@ -6818,13 +8117,13 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
6818
8117
|
return { issues, suggestions: [], warnings: [] };
|
|
6819
8118
|
}
|
|
6820
8119
|
const config = mergeJobsConfig(framework, feature.config);
|
|
6821
|
-
const { packageJson } = await readProjectPackageJson(cwd);
|
|
6822
8120
|
const expectedScripts = getJobsExpectedScripts(config);
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
8121
|
+
const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
|
|
8122
|
+
for (const taskName of taskCheck.mismatches) {
|
|
8123
|
+
issues.push(taskCheck.config === "package.json"
|
|
8124
|
+
? `Jobs package.json script does not match Loom defaults: ${taskName}`
|
|
8125
|
+
: `Jobs task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
8126
|
+
suggestions.add("Run `loom add jobs`.");
|
|
6828
8127
|
}
|
|
6829
8128
|
const requiredFiles = [
|
|
6830
8129
|
JOBS_SCRIPTS_TSCONFIG_PATH,
|
|
@@ -6981,7 +8280,9 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
6981
8280
|
}
|
|
6982
8281
|
const config = mergeDbConfig(framework, feature.config);
|
|
6983
8282
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
6984
|
-
const
|
|
8283
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
8284
|
+
const testRunner = await getDbTestRunner(cwd, tooling);
|
|
8285
|
+
const expectedScripts = getDbExpectedScripts(config, tooling);
|
|
6985
8286
|
const migrationFlowCheck = await checkDbProductionMigrationFlow(cwd, options.production ?? false);
|
|
6986
8287
|
issues.push(...migrationFlowCheck.issues);
|
|
6987
8288
|
warnings.push(...migrationFlowCheck.warnings);
|
|
@@ -6989,29 +8290,36 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
6989
8290
|
suggestions.add(suggestion);
|
|
6990
8291
|
}
|
|
6991
8292
|
for (const dependencyName of Object.keys(DB_DEFAULT_DEPENDENCIES)) {
|
|
6992
|
-
if (!packageJson
|
|
6993
|
-
issues.push(
|
|
8293
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
8294
|
+
issues.push(tooling.dependencies.config === "package.json"
|
|
8295
|
+
? `DB dependency is missing from package.json dependencies: ${dependencyName}`
|
|
8296
|
+
: `DB dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
6994
8297
|
suggestions.add("Run `loom add db`.");
|
|
6995
8298
|
}
|
|
6996
8299
|
}
|
|
6997
8300
|
for (const dependencyName of Object.keys(DB_DEFAULT_DEV_DEPENDENCIES)) {
|
|
6998
|
-
if (!packageJson
|
|
6999
|
-
issues.push(
|
|
8301
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
8302
|
+
issues.push(tooling.dependencies.config === "package.json"
|
|
8303
|
+
? `DB dependency is missing from package.json devDependencies: ${dependencyName}`
|
|
8304
|
+
: `DB development dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
7000
8305
|
suggestions.add("Run `loom add db`.");
|
|
7001
8306
|
}
|
|
7002
8307
|
}
|
|
7003
8308
|
for (const dependencyName of DB_MOVED_DEPENDENCIES) {
|
|
7004
8309
|
if (packageJson.dependencies?.[dependencyName] ||
|
|
7005
8310
|
packageJson.devDependencies?.[dependencyName]) {
|
|
7006
|
-
issues.push(
|
|
7007
|
-
|
|
8311
|
+
issues.push(tooling.dependencies.config === "package.json"
|
|
8312
|
+
? `Consumer package.json still declares a Loom-managed DB generator dependency: ${dependencyName}`
|
|
8313
|
+
: `Consumer ${tooling.dependencies.config} still declares a Loom-managed DB generator dependency: ${dependencyName}`);
|
|
8314
|
+
suggestions.add(`Run loom add db to rewrite ${tooling.dependencies.config}.`);
|
|
7008
8315
|
}
|
|
7009
8316
|
}
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
8317
|
+
const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
|
|
8318
|
+
for (const taskName of taskCheck.mismatches) {
|
|
8319
|
+
issues.push(taskCheck.config === "package.json"
|
|
8320
|
+
? `DB package.json script does not match Loom defaults: ${taskName}`
|
|
8321
|
+
: `DB task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
|
|
8322
|
+
suggestions.add("Run `loom add db`.");
|
|
7015
8323
|
}
|
|
7016
8324
|
const requiredFiles = [
|
|
7017
8325
|
config.modules.neonModule,
|
|
@@ -7047,7 +8355,7 @@ async function checkDbFeature(cwd, framework, manifest, options) {
|
|
|
7047
8355
|
],
|
|
7048
8356
|
[
|
|
7049
8357
|
config.modules.pgliteHarnessModule,
|
|
7050
|
-
dbPgliteHarnessTemplate(config),
|
|
8358
|
+
dbPgliteHarnessTemplate(config, testRunner),
|
|
7051
8359
|
"PGlite test harness does not match the Loom-managed wrapper",
|
|
7052
8360
|
],
|
|
7053
8361
|
[
|
|
@@ -7138,6 +8446,8 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7138
8446
|
const dbConfig = mergeDbConfig(framework, dbFeature.config);
|
|
7139
8447
|
const config = getFilesConfig(framework, dbConfig, feature.config);
|
|
7140
8448
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
8449
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
8450
|
+
const generateCommand = (0, projectTooling_js_1.formatTaskInvocation)(tooling.tasks, "db:generate");
|
|
7141
8451
|
const schema = config.schema;
|
|
7142
8452
|
const latestSchema = getLatestManagedSchemaConfig(schema);
|
|
7143
8453
|
if (schema.mode !== "managed-local" || schema.blueprint !== "files") {
|
|
@@ -7151,7 +8461,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7151
8461
|
}
|
|
7152
8462
|
else if (schema.version < supportedVersion) {
|
|
7153
8463
|
warnings.push(`Files schema blueprint is stale: ${schema.version} < ${supportedVersion}.`);
|
|
7154
|
-
suggestions.add(
|
|
8464
|
+
suggestions.add(`Run loom db schemas sync, review the schema diff, then run ${generateCommand} if the schema changed.`);
|
|
7155
8465
|
}
|
|
7156
8466
|
const schemaRelativeToDir = (0, node_path_1.relative)(dbConfig.dirs.schemaDir, schema.module)
|
|
7157
8467
|
.replaceAll("\\", "/");
|
|
@@ -7166,7 +8476,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7166
8476
|
const schemaText = await readTextIfExists((0, node_path_1.join)(cwd, schema.module));
|
|
7167
8477
|
if (!schemaText) {
|
|
7168
8478
|
issues.push(`Files schema file is missing: ${schema.module}`);
|
|
7169
|
-
suggestions.add(
|
|
8479
|
+
suggestions.add(`Run loom db schemas sync, review the schema diff, then run ${generateCommand} if the schema changed.`);
|
|
7170
8480
|
}
|
|
7171
8481
|
else {
|
|
7172
8482
|
const currentHash = hashManagedSchemaText(schemaText);
|
|
@@ -7282,8 +8592,8 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7282
8592
|
suggestions.add("Replace the generated files storage stub with an S3 or app-specific storage adapter before production use.");
|
|
7283
8593
|
}
|
|
7284
8594
|
if (config.storage.adapter === "s3") {
|
|
7285
|
-
if (!packageJson
|
|
7286
|
-
issues.push(
|
|
8595
|
+
if (!hasPackageDependency(packageJson, "@aws-sdk/client-s3")) {
|
|
8596
|
+
issues.push(`Files S3/R2 storage requires @aws-sdk/client-s3 in ${tooling.dependencies.config}.`);
|
|
7287
8597
|
suggestions.add("Run `loom files r2 setup` to restore the dependency.");
|
|
7288
8598
|
}
|
|
7289
8599
|
for (const envName of FILES_S3_REQUIRED_ENV_NAMES) {
|
|
@@ -7351,6 +8661,147 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
|
|
|
7351
8661
|
warnings,
|
|
7352
8662
|
};
|
|
7353
8663
|
}
|
|
8664
|
+
async function checkMailFeature(cwd, framework, manifest, options) {
|
|
8665
|
+
const issues = [];
|
|
8666
|
+
const suggestions = new Set();
|
|
8667
|
+
const warnings = [];
|
|
8668
|
+
const feature = manifest.features.mail;
|
|
8669
|
+
if (!feature || feature.status !== "active") {
|
|
8670
|
+
return { issues, suggestions: [], warnings };
|
|
8671
|
+
}
|
|
8672
|
+
for (const dependency of ["auth", "db"]) {
|
|
8673
|
+
if (manifest.features[dependency]?.status !== "active") {
|
|
8674
|
+
issues.push(`Mail feature requires the active ${dependency} feature.`);
|
|
8675
|
+
suggestions.add(`Run \`loom add ${dependency}\` before using mail.`);
|
|
8676
|
+
}
|
|
8677
|
+
}
|
|
8678
|
+
if (issues.length)
|
|
8679
|
+
return { issues, suggestions: [...suggestions], warnings };
|
|
8680
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
8681
|
+
const dbConfig = mergeDbConfig(framework, manifest.features.db.config);
|
|
8682
|
+
const config = getMailConfig(framework, dbConfig, packageJson, feature.config, manifest.features.jobs?.status === "active");
|
|
8683
|
+
const schema = config.schema;
|
|
8684
|
+
const latestSchema = getLatestManagedSchemaConfig(schema);
|
|
8685
|
+
if (schema.mode !== "managed-local" || schema.blueprint !== "mail") {
|
|
8686
|
+
issues.push("Mail must use the managed-local mail schema blueprint.");
|
|
8687
|
+
suggestions.add("Run `loom add mail` to restore the mail schema config.");
|
|
8688
|
+
}
|
|
8689
|
+
if (schema.exports.length !== 3) {
|
|
8690
|
+
issues.push("Mail schema must configure message, delivery, and event exports.");
|
|
8691
|
+
}
|
|
8692
|
+
if (schema.version > MAIL_SCHEMA_BLUEPRINT_VERSION) {
|
|
8693
|
+
issues.push(`Mail schema blueprint version ${schema.version} is newer than this Loom package supports.`);
|
|
8694
|
+
}
|
|
8695
|
+
else if (schema.version < MAIL_SCHEMA_BLUEPRINT_VERSION) {
|
|
8696
|
+
warnings.push(`Mail schema blueprint is stale: ${schema.version} < ${MAIL_SCHEMA_BLUEPRINT_VERSION}.`);
|
|
8697
|
+
suggestions.add("Run `loom db schemas sync`, then review and migrate the diff.");
|
|
8698
|
+
}
|
|
8699
|
+
const schemaText = await readTextIfExists((0, node_path_1.join)(cwd, schema.module));
|
|
8700
|
+
if (!schemaText) {
|
|
8701
|
+
issues.push(`Mail schema file is missing: ${schema.module}`);
|
|
8702
|
+
suggestions.add("Run `loom db schemas sync`.");
|
|
8703
|
+
}
|
|
8704
|
+
else {
|
|
8705
|
+
const currentHash = hashManagedSchemaText(schemaText);
|
|
8706
|
+
if (currentHash !== schema.hash) {
|
|
8707
|
+
if (currentHash === latestSchema.hash) {
|
|
8708
|
+
warnings.push(`Mail schema manifest hash is stale for ${schema.module}.`);
|
|
8709
|
+
suggestions.add("Run `loom db schemas sync` to refresh loom.json.");
|
|
8710
|
+
}
|
|
8711
|
+
else {
|
|
8712
|
+
issues.push(`Mail schema file has local edits outside the managed hash: ${schema.module}`);
|
|
8713
|
+
suggestions.add("Move app-specific mail schema additions to a separate file, then run `loom db schemas sync`.");
|
|
8714
|
+
}
|
|
8715
|
+
}
|
|
8716
|
+
const barrelText = await readTextIfExists((0, node_path_1.join)(cwd, dbConfig.dirs.schemaDir, "index.ts"));
|
|
8717
|
+
if (!barrelText || !schemaBarrelExportsModule(barrelText, schema, dbConfig)) {
|
|
8718
|
+
issues.push(`DB schema barrel does not export the managed mail schema: ${dbConfig.dirs.schemaDir}/index.ts`);
|
|
8719
|
+
suggestions.add("Run `loom db schemas sync`.");
|
|
8720
|
+
}
|
|
8721
|
+
}
|
|
8722
|
+
const requiredFiles = [
|
|
8723
|
+
config.modules.accessModule,
|
|
8724
|
+
config.modules.actionsModule,
|
|
8725
|
+
config.modules.repositoryModule,
|
|
8726
|
+
config.modules.serviceModule,
|
|
8727
|
+
config.modules.transportModule,
|
|
8728
|
+
config.entrypoints.adminPage,
|
|
8729
|
+
config.entrypoints.webhookRoute,
|
|
8730
|
+
...(config.jobs.enabled ? [config.modules.jobModule] : []),
|
|
8731
|
+
];
|
|
8732
|
+
for (const relativePath of requiredFiles) {
|
|
8733
|
+
if (!await exists((0, node_path_1.join)(cwd, relativePath))) {
|
|
8734
|
+
issues.push(`Mail scaffold file is missing: ${relativePath}`);
|
|
8735
|
+
suggestions.add("Run `loom add mail` to restore missing scaffolds.");
|
|
8736
|
+
}
|
|
8737
|
+
}
|
|
8738
|
+
const accessText = await readTextIfExists((0, node_path_1.join)(cwd, config.modules.accessModule));
|
|
8739
|
+
if (accessText && !accessText.includes("authorizeMailAdmin")) {
|
|
8740
|
+
issues.push(`Mail access module does not export authorizeMailAdmin: ${config.modules.accessModule}`);
|
|
8741
|
+
}
|
|
8742
|
+
const generatedDenyAll = accessText?.includes("Mail admin access policy is not configured.") ?? false;
|
|
8743
|
+
if (generatedDenyAll) {
|
|
8744
|
+
const message = `Mail admin access still uses the generated deny-all stub: ${config.modules.accessModule}`;
|
|
8745
|
+
if (options.production)
|
|
8746
|
+
issues.push(message);
|
|
8747
|
+
else
|
|
8748
|
+
warnings.push(message);
|
|
8749
|
+
suggestions.add("Connect authorizeMailAdmin() to the app's fresh session/admin-role check.");
|
|
8750
|
+
}
|
|
8751
|
+
const contentChecks = [
|
|
8752
|
+
[
|
|
8753
|
+
config.modules.repositoryModule,
|
|
8754
|
+
"@gadicc/loom/mail",
|
|
8755
|
+
"Mail repository is not typed against the shared mail contract",
|
|
8756
|
+
],
|
|
8757
|
+
[
|
|
8758
|
+
config.modules.serviceModule,
|
|
8759
|
+
"createLoomMailService",
|
|
8760
|
+
"Mail service is not wired to the shared durable service",
|
|
8761
|
+
],
|
|
8762
|
+
[
|
|
8763
|
+
config.modules.transportModule,
|
|
8764
|
+
"createPostalMailTransport",
|
|
8765
|
+
"Mail transport is not wired to the Postal adapter",
|
|
8766
|
+
],
|
|
8767
|
+
[
|
|
8768
|
+
config.modules.transportModule,
|
|
8769
|
+
"POSTAL_WEBHOOK_PUBLIC_KEYS",
|
|
8770
|
+
"Mail transport does not configure Postal webhook public keys",
|
|
8771
|
+
],
|
|
8772
|
+
[
|
|
8773
|
+
config.entrypoints.webhookRoute,
|
|
8774
|
+
"createPostalWebhookRouteHandler",
|
|
8775
|
+
"Mail webhook route does not use the signed shared route handler",
|
|
8776
|
+
],
|
|
8777
|
+
[
|
|
8778
|
+
config.modules.actionsModule,
|
|
8779
|
+
"authorizeMailAdmin",
|
|
8780
|
+
"Mail admin actions do not enforce the app-owned admin boundary",
|
|
8781
|
+
],
|
|
8782
|
+
[
|
|
8783
|
+
config.entrypoints.adminPage,
|
|
8784
|
+
"authorizeMailAdmin",
|
|
8785
|
+
"Mail admin page does not enforce the app-owned admin boundary",
|
|
8786
|
+
],
|
|
8787
|
+
];
|
|
8788
|
+
for (const [relativePath, snippet, label] of contentChecks) {
|
|
8789
|
+
const text = await readTextIfExists((0, node_path_1.join)(cwd, relativePath));
|
|
8790
|
+
if (text && !text.includes(snippet)) {
|
|
8791
|
+
issues.push(`${label}: ${relativePath}`);
|
|
8792
|
+
suggestions.add("Run `loom add mail` or update loom.json for intentional paths.");
|
|
8793
|
+
}
|
|
8794
|
+
}
|
|
8795
|
+
if (config.ui.adapter === "mui" &&
|
|
8796
|
+
!hasPackageDependency(packageJson, "@mui/material")) {
|
|
8797
|
+
issues.push("Mail's MUI adapter is active but @mui/material is not installed.");
|
|
8798
|
+
}
|
|
8799
|
+
if (config.jobs.enabled && manifest.features.jobs?.status !== "active") {
|
|
8800
|
+
warnings.push("Mail drain job is enabled while the Loom jobs feature is inactive.");
|
|
8801
|
+
suggestions.add("Run `loom add jobs` or disable features.mail.config.jobs.enabled.");
|
|
8802
|
+
}
|
|
8803
|
+
return { issues, suggestions: [...suggestions], warnings };
|
|
8804
|
+
}
|
|
7354
8805
|
function packageDependencySpec(packageJson, dependencyName) {
|
|
7355
8806
|
return packageJson.dependencies?.[dependencyName] ??
|
|
7356
8807
|
packageJson.devDependencies?.[dependencyName];
|
|
@@ -7626,6 +9077,125 @@ async function findNextConfigPath(cwd) {
|
|
|
7626
9077
|
];
|
|
7627
9078
|
return await findFirstExistingRelativePath(cwd, candidates);
|
|
7628
9079
|
}
|
|
9080
|
+
async function checkLinguiFeature(cwd, framework, manifest, options) {
|
|
9081
|
+
const issues = [];
|
|
9082
|
+
const suggestions = new Set();
|
|
9083
|
+
const warnings = [];
|
|
9084
|
+
const feature = manifest.features.lingui;
|
|
9085
|
+
if (!feature || feature.status !== "active") {
|
|
9086
|
+
return { issues, suggestions: [], warnings };
|
|
9087
|
+
}
|
|
9088
|
+
const { packageJson } = await readProjectPackageJson(cwd);
|
|
9089
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
9090
|
+
const config = await getLinguiConfig(cwd, framework, feature.config);
|
|
9091
|
+
const requiredDependencies = {
|
|
9092
|
+
...LINGUI_DEFAULT_DEPENDENCIES,
|
|
9093
|
+
...LINGUI_DEFAULT_DEV_DEPENDENCIES,
|
|
9094
|
+
...(config.catalogMode === "loader" ? LINGUI_LOADER_DEV_DEPENDENCIES : {}),
|
|
9095
|
+
};
|
|
9096
|
+
for (const dependencyName of Object.keys(requiredDependencies)) {
|
|
9097
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
9098
|
+
issues.push(`Lingui dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
9099
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9100
|
+
}
|
|
9101
|
+
}
|
|
9102
|
+
if (!await exists((0, node_path_1.join)(cwd, config.configFile))) {
|
|
9103
|
+
issues.push(`Lingui config is missing: ${config.configFile}`);
|
|
9104
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9105
|
+
}
|
|
9106
|
+
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
9107
|
+
if (!linguiTaskRuns((0, projectTooling_js_1.getTaskCommand)(taskStore.definitions[config.tasks.extract]), "extract")) {
|
|
9108
|
+
issues.push(`Lingui extraction task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.extract}`);
|
|
9109
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9110
|
+
}
|
|
9111
|
+
if (!linguiTaskRuns((0, projectTooling_js_1.getTaskCommand)(taskStore.definitions[config.tasks.compile]), "compile")) {
|
|
9112
|
+
issues.push(`Lingui compile task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.compile}`);
|
|
9113
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9114
|
+
}
|
|
9115
|
+
if (config.catalogMode === "precompile") {
|
|
9116
|
+
if (!(0, projectTooling_js_1.taskInvokes)(taskStore, config.tasks.build, config.tasks.compile)) {
|
|
9117
|
+
issues.push(`Build task does not compile Lingui catalogs in ${tooling.tasks.config}: ${config.tasks.build}`);
|
|
9118
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9119
|
+
}
|
|
9120
|
+
else {
|
|
9121
|
+
const buildCommand = (0, projectTooling_js_1.getTaskCommand)(taskStore.definitions[config.tasks.build]);
|
|
9122
|
+
if (buildCommand?.includes("next build") &&
|
|
9123
|
+
!(0, projectTooling_js_1.taskRunsBeforeCommand)(taskStore, config.tasks.build, config.tasks.compile, "next build")) {
|
|
9124
|
+
issues.push(`Lingui catalogs are compiled after Next.js starts building in ${tooling.tasks.config}: ${config.tasks.build}`);
|
|
9125
|
+
suggestions.add(`Run ${config.tasks.compile} before the framework build command.`);
|
|
9126
|
+
}
|
|
9127
|
+
}
|
|
9128
|
+
}
|
|
9129
|
+
const gitignoreUpdate = ensureLinguiGitignoreText(await readTextIfExists((0, node_path_1.join)(cwd, ".gitignore")), config.generatedCatalogs);
|
|
9130
|
+
if (gitignoreUpdate.missingLines.length) {
|
|
9131
|
+
issues.push(`Lingui generated catalogs are missing from .gitignore: ${gitignoreUpdate.missingLines.join(", ")}`);
|
|
9132
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9133
|
+
}
|
|
9134
|
+
const gitResult = await (options.commandRunner ?? defaultCommandRunner)("git", ["ls-files", "--", ...config.generatedCatalogs], { cwd, stdio: "pipe" });
|
|
9135
|
+
const trackedCatalogs = gitResult.code === 0
|
|
9136
|
+
? gitResult.stdout.trim().split(/\r?\n/).filter(Boolean)
|
|
9137
|
+
: [];
|
|
9138
|
+
if (trackedCatalogs.length) {
|
|
9139
|
+
issues.push(`Lingui generated catalogs are still tracked by git: ${trackedCatalogs.join(", ")}`);
|
|
9140
|
+
suggestions.add("Remove generated catalogs from the git index while keeping the source .po catalogs tracked.");
|
|
9141
|
+
}
|
|
9142
|
+
const nextConfigPath = await findNextConfigPath(cwd);
|
|
9143
|
+
const nextConfigText = nextConfigPath
|
|
9144
|
+
? await readTextIfExists((0, node_path_1.join)(cwd, nextConfigPath))
|
|
9145
|
+
: null;
|
|
9146
|
+
if (framework.kind === "nextjs") {
|
|
9147
|
+
if (!nextConfigText?.includes("@lingui/swc-plugin")) {
|
|
9148
|
+
issues.push(`Next config is missing @lingui/swc-plugin${nextConfigPath ? `: ${nextConfigPath}` : "."}`);
|
|
9149
|
+
suggestions.add("Add @lingui/swc-plugin to experimental.swcPlugins in the Next config.");
|
|
9150
|
+
}
|
|
9151
|
+
if (config.catalogMode === "loader" &&
|
|
9152
|
+
!nextConfigText?.includes("@lingui/loader")) {
|
|
9153
|
+
issues.push(`Lingui loader mode is not wired in the Next config${nextConfigPath ? `: ${nextConfigPath}` : "."}`);
|
|
9154
|
+
suggestions.add("Add matching .po rules for Turbopack and webpack, or switch the manifest to precompile mode.");
|
|
9155
|
+
}
|
|
9156
|
+
if (nextConfigText && /\breactCompiler\s*:\s*true/.test(nextConfigText)) {
|
|
9157
|
+
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.");
|
|
9158
|
+
}
|
|
9159
|
+
}
|
|
9160
|
+
const poImports = await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']+\.po["']/);
|
|
9161
|
+
if (config.catalogMode === "precompile" && poImports.length) {
|
|
9162
|
+
issues.push(`Lingui is configured for precompile mode but source files import .po catalogs: ${poImports.join(", ")}`);
|
|
9163
|
+
suggestions.add("Switch loom.json to loader mode or import the generated .js catalogs.");
|
|
9164
|
+
}
|
|
9165
|
+
if (config.catalogMode === "loader" && !poImports.length) {
|
|
9166
|
+
warnings.push("Lingui is configured for loader mode, but no source .po imports were found.");
|
|
9167
|
+
}
|
|
9168
|
+
if (config.catalogMode === "loader") {
|
|
9169
|
+
const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
|
|
9170
|
+
if (!poDeclarations.length) {
|
|
9171
|
+
issues.push("Lingui loader mode is missing a TypeScript *.po module declaration.");
|
|
9172
|
+
suggestions.add("Run `loom add lingui`.");
|
|
9173
|
+
}
|
|
9174
|
+
}
|
|
9175
|
+
const configImports = (await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']*lingui\.config(?:\.[cm]?[jt]s)?["']/)).filter((relativePath) => relativePath !== config.configFile);
|
|
9176
|
+
if (configImports.length) {
|
|
9177
|
+
warnings.push(`Lingui config is imported by runtime source; keep config evaluation build-time only: ${configImports.join(", ")}`);
|
|
9178
|
+
}
|
|
9179
|
+
const linguiCoreMajor = dependencyMajor(packageJson.dependencies?.["@lingui/core"] ??
|
|
9180
|
+
packageJson.devDependencies?.["@lingui/core"]);
|
|
9181
|
+
const legacyMacroSpec = packageJson.dependencies?.["@lingui/macro"] ??
|
|
9182
|
+
packageJson.devDependencies?.["@lingui/macro"];
|
|
9183
|
+
if (legacyMacroSpec && linguiCoreMajor !== null &&
|
|
9184
|
+
dependencyMajor(legacyMacroSpec) !== linguiCoreMajor) {
|
|
9185
|
+
warnings.push(`Legacy @lingui/macro (${legacyMacroSpec}) does not match @lingui/core's major version; prefer @lingui/react/macro and @lingui/core/macro imports.`);
|
|
9186
|
+
}
|
|
9187
|
+
const linguiFamilyMajors = Object.keys(requiredDependencies).flatMap((dependencyName) => {
|
|
9188
|
+
const spec = packageJson.dependencies?.[dependencyName] ??
|
|
9189
|
+
packageJson.devDependencies?.[dependencyName];
|
|
9190
|
+
const major = dependencyMajor(spec);
|
|
9191
|
+
return major === null ? [] : [`${dependencyName}@${major}`];
|
|
9192
|
+
});
|
|
9193
|
+
if (new Set(linguiFamilyMajors.map((entry) => entry.split("@").at(-1))).size >
|
|
9194
|
+
1) {
|
|
9195
|
+
warnings.push(`Lingui packages span multiple major versions: ${linguiFamilyMajors.join(", ")}`);
|
|
9196
|
+
}
|
|
9197
|
+
return { issues, suggestions: [...suggestions], warnings };
|
|
9198
|
+
}
|
|
7629
9199
|
async function checkPwaFeature(cwd, framework, manifest) {
|
|
7630
9200
|
const issues = [];
|
|
7631
9201
|
const suggestions = new Set();
|
|
@@ -7635,6 +9205,7 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
7635
9205
|
return { issues, suggestions: [], warnings };
|
|
7636
9206
|
}
|
|
7637
9207
|
const { packageJson } = await readProjectPackageJson(cwd);
|
|
9208
|
+
const tooling = await getProjectTooling(cwd, manifest);
|
|
7638
9209
|
const config = await getPwaConfig(cwd, framework, packageJson, feature.config, false);
|
|
7639
9210
|
const hasMui = hasPackageDependency(packageJson, "@mui/material");
|
|
7640
9211
|
if (framework.kind !== "nextjs" || framework.router !== "app") {
|
|
@@ -7642,23 +9213,25 @@ async function checkPwaFeature(cwd, framework, manifest) {
|
|
|
7642
9213
|
suggestions.add("Update loom.json if this project intentionally uses a custom PWA integration.");
|
|
7643
9214
|
}
|
|
7644
9215
|
for (const dependencyName of Object.keys(PWA_DEFAULT_DEPENDENCIES)) {
|
|
7645
|
-
if (!packageJson
|
|
7646
|
-
issues.push(`PWA dependency is missing from
|
|
9216
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
9217
|
+
issues.push(`PWA dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
7647
9218
|
suggestions.add("Run `loom add pwa`.");
|
|
7648
9219
|
}
|
|
7649
9220
|
}
|
|
7650
9221
|
for (const dependencyName of Object.keys(PWA_DEFAULT_DEV_DEPENDENCIES)) {
|
|
7651
|
-
if (!packageJson
|
|
7652
|
-
issues.push(`PWA dependency is missing from
|
|
9222
|
+
if (!hasPackageDependency(packageJson, dependencyName)) {
|
|
9223
|
+
issues.push(`PWA development dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
|
|
7653
9224
|
suggestions.add("Run `loom add pwa`.");
|
|
7654
9225
|
}
|
|
7655
9226
|
}
|
|
7656
|
-
|
|
7657
|
-
|
|
9227
|
+
const taskStore = await (0, projectTooling_js_1.readTaskStore)(cwd, tooling.tasks);
|
|
9228
|
+
if (!scriptRunsSerwistBuild((0, projectTooling_js_1.getTaskCommand)(taskStore.definitions["pwa:build"]))) {
|
|
9229
|
+
issues.push(`PWA task in ${tooling.tasks.config} does not build Serwist: pwa:build`);
|
|
7658
9230
|
suggestions.add("Run `loom add pwa`.");
|
|
7659
9231
|
}
|
|
7660
|
-
if (!scriptRunsSerwistBuild(
|
|
7661
|
-
|
|
9232
|
+
if (!scriptRunsSerwistBuild((0, projectTooling_js_1.getTaskCommand)(taskStore.definitions.build)) &&
|
|
9233
|
+
!(0, projectTooling_js_1.taskInvokes)(taskStore, "build", "pwa:build")) {
|
|
9234
|
+
issues.push(`PWA build task in ${tooling.tasks.config} does not run Serwist after the Next.js build.`);
|
|
7662
9235
|
suggestions.add("Run `loom add pwa`.");
|
|
7663
9236
|
}
|
|
7664
9237
|
const gitignoreUpdate = ensurePwaGitignoreText(await readTextIfExists((0, node_path_1.join)(cwd, ".gitignore")));
|
|
@@ -7839,6 +9412,14 @@ const featureHooks = {
|
|
|
7839
9412
|
apply: applyJobsFeature,
|
|
7840
9413
|
check: checkJobsFeature,
|
|
7841
9414
|
},
|
|
9415
|
+
lingui: {
|
|
9416
|
+
apply: applyLinguiFeature,
|
|
9417
|
+
check: checkLinguiFeature,
|
|
9418
|
+
},
|
|
9419
|
+
mail: {
|
|
9420
|
+
apply: applyMailFeature,
|
|
9421
|
+
check: checkMailFeature,
|
|
9422
|
+
},
|
|
7842
9423
|
pwa: {
|
|
7843
9424
|
apply: applyPwaFeature,
|
|
7844
9425
|
check: checkPwaFeature,
|
|
@@ -7862,11 +9443,14 @@ async function ensureActiveFeatureScaffolds(cwd, framework, manifest) {
|
|
|
7862
9443
|
async function initProject(cwd, versionRange) {
|
|
7863
9444
|
const changedFiles = [];
|
|
7864
9445
|
const notes = [];
|
|
7865
|
-
const
|
|
7866
|
-
const
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
9446
|
+
const loomManifestPath = (0, node_path_1.join)(cwd, "loom.json");
|
|
9447
|
+
const existingManifestText = await readTextIfExists(loomManifestPath);
|
|
9448
|
+
const existingManifest = existingManifestText
|
|
9449
|
+
? parseJson(existingManifestText, "loom.json")
|
|
9450
|
+
: null;
|
|
9451
|
+
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, existingManifest?.project?.tooling);
|
|
9452
|
+
const initialMetadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
9453
|
+
const initialPackageJson = initialMetadata.packageJson;
|
|
7870
9454
|
const npmrcPath = (0, node_path_1.join)(cwd, ".npmrc");
|
|
7871
9455
|
const npmrcUpdate = removeLegacyLoomNpmrcText(await readTextIfExists(npmrcPath));
|
|
7872
9456
|
if (npmrcUpdate.changed) {
|
|
@@ -7874,19 +9458,23 @@ async function initProject(cwd, versionRange) {
|
|
|
7874
9458
|
changedFiles.push(".npmrc");
|
|
7875
9459
|
notes.push("Removed Loom's obsolete GitHub Packages registry configuration.");
|
|
7876
9460
|
}
|
|
7877
|
-
const
|
|
7878
|
-
|
|
9461
|
+
const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, {
|
|
9462
|
+
dependencies: {
|
|
9463
|
+
[exports.LOOM_DEPENDENCY]: versionRange ??
|
|
9464
|
+
getPublishedLoomDependencySpec(initialPackageJson),
|
|
9465
|
+
},
|
|
9466
|
+
replace: true,
|
|
9467
|
+
});
|
|
7879
9468
|
if (dependencyUpdate.changed) {
|
|
7880
|
-
|
|
7881
|
-
|
|
9469
|
+
changedFiles.push(tooling.dependencies.config);
|
|
9470
|
+
if (tooling.dependencies.config !== "package.json") {
|
|
9471
|
+
notes.push(`Recorded ${exports.LOOM_DEPENDENCY} in ${tooling.dependencies.config} imports and enabled Deno's local node_modules directory when needed.`);
|
|
9472
|
+
}
|
|
7882
9473
|
}
|
|
7883
|
-
const
|
|
7884
|
-
|
|
7885
|
-
const
|
|
7886
|
-
const
|
|
7887
|
-
? parseJson(existingManifestText, "loom.json")
|
|
7888
|
-
: null;
|
|
7889
|
-
const manifest = buildManifest(cwd, dependencyUpdate.packageJson, framework, existingManifest);
|
|
9474
|
+
const packageJson = (await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd))
|
|
9475
|
+
.packageJson;
|
|
9476
|
+
const framework = await detectFramework(cwd, packageJson);
|
|
9477
|
+
const manifest = buildManifest(cwd, packageJson, framework, existingManifest, tooling);
|
|
7890
9478
|
const featureInit = await ensureActiveFeatureScaffolds(cwd, framework, manifest);
|
|
7891
9479
|
changedFiles.push(...featureInit.changedFiles);
|
|
7892
9480
|
notes.push(...featureInit.notes);
|
|
@@ -7897,7 +9485,7 @@ async function initProject(cwd, versionRange) {
|
|
|
7897
9485
|
if (agentsInit.changed) {
|
|
7898
9486
|
changedFiles.push("AGENTS.md");
|
|
7899
9487
|
}
|
|
7900
|
-
const nextAgentsInit = await ensureNextAgentsFile(cwd,
|
|
9488
|
+
const nextAgentsInit = await ensureNextAgentsFile(cwd, packageJson);
|
|
7901
9489
|
if (nextAgentsInit.changed)
|
|
7902
9490
|
changedFiles.push("AGENTS.md");
|
|
7903
9491
|
if (nextAgentsInit.note)
|
|
@@ -7921,7 +9509,8 @@ async function initProject(cwd, versionRange) {
|
|
|
7921
9509
|
framework,
|
|
7922
9510
|
manifest,
|
|
7923
9511
|
notes,
|
|
7924
|
-
packageJson:
|
|
9512
|
+
packageJson: (await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd))
|
|
9513
|
+
.packageJson,
|
|
7925
9514
|
};
|
|
7926
9515
|
}
|
|
7927
9516
|
async function addFeature(cwd, featureKey, versionRange) {
|
|
@@ -8067,18 +9656,20 @@ async function checkProject(cwd, env = node_process_1.default.env, options = {})
|
|
|
8067
9656
|
const issues = [];
|
|
8068
9657
|
const suggestions = new Set();
|
|
8069
9658
|
const warnings = [];
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
9659
|
+
let projectMetadata;
|
|
9660
|
+
try {
|
|
9661
|
+
projectMetadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
9662
|
+
}
|
|
9663
|
+
catch (error) {
|
|
8073
9664
|
return {
|
|
8074
|
-
issues: [
|
|
9665
|
+
issues: [error.message],
|
|
8075
9666
|
suggestions: [
|
|
8076
|
-
"Run `loom init` from a project
|
|
9667
|
+
"Run `loom init` from a project with package.json, deno.json, or deno.jsonc.",
|
|
8077
9668
|
],
|
|
8078
9669
|
warnings: [],
|
|
8079
9670
|
};
|
|
8080
9671
|
}
|
|
8081
|
-
const packageJson =
|
|
9672
|
+
const packageJson = projectMetadata.packageJson;
|
|
8082
9673
|
const npmrcText = await readTextIfExists((0, node_path_1.join)(cwd, ".npmrc"));
|
|
8083
9674
|
if (removeLegacyLoomNpmrcText(npmrcText).changed) {
|
|
8084
9675
|
warnings.push(".npmrc retains Loom's obsolete GitHub Packages registry configuration.");
|
|
@@ -8087,7 +9678,7 @@ async function checkProject(cwd, env = node_process_1.default.env, options = {})
|
|
|
8087
9678
|
const framework = await detectFramework(cwd, packageJson);
|
|
8088
9679
|
const dependency = packageJson.dependencies?.[exports.LOOM_DEPENDENCY];
|
|
8089
9680
|
if (!dependency) {
|
|
8090
|
-
issues.push(`Missing ${exports.LOOM_DEPENDENCY} in
|
|
9681
|
+
issues.push(`Missing ${exports.LOOM_DEPENDENCY} in ${projectMetadata.config} dependencies/imports.`);
|
|
8091
9682
|
suggestions.add("Run `loom init`.");
|
|
8092
9683
|
}
|
|
8093
9684
|
else if (isLocalPackageSpec(dependency)) {
|
|
@@ -8104,6 +9695,26 @@ async function checkProject(cwd, env = node_process_1.default.env, options = {})
|
|
|
8104
9695
|
manifest = parseJson(manifestText, "loom.json");
|
|
8105
9696
|
}
|
|
8106
9697
|
if (manifest) {
|
|
9698
|
+
let tooling = null;
|
|
9699
|
+
if (!manifest.project?.tooling) {
|
|
9700
|
+
warnings.push("loom.json does not record authoritative project tooling.");
|
|
9701
|
+
suggestions.add("Run `loom init` to adopt the detected project tooling.");
|
|
9702
|
+
}
|
|
9703
|
+
try {
|
|
9704
|
+
tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest.project?.tooling);
|
|
9705
|
+
}
|
|
9706
|
+
catch (error) {
|
|
9707
|
+
issues.push(`Invalid project tooling configuration: ${error.message}`);
|
|
9708
|
+
suggestions.add("Fix the recorded project.tooling config in loom.json.");
|
|
9709
|
+
}
|
|
9710
|
+
if (tooling) {
|
|
9711
|
+
for (const conflict of await (0, projectTooling_js_1.findTaskConflicts)(cwd, tooling.tasks)) {
|
|
9712
|
+
const deploymentWarning = conflict.name === "build"
|
|
9713
|
+
? " Deployment may invoke the wrong build task."
|
|
9714
|
+
: "";
|
|
9715
|
+
warnings.push(`Conflicting '${conflict.name}' tasks in ${conflict.authoritativeConfig} (authoritative) and ${conflict.secondaryConfig}.${deploymentWarning}`);
|
|
9716
|
+
}
|
|
9717
|
+
}
|
|
8107
9718
|
for (const [featureKey, feature] of Object.entries(manifest.features)) {
|
|
8108
9719
|
if (feature.status !== "active")
|
|
8109
9720
|
continue;
|
|
@@ -8135,7 +9746,7 @@ async function checkProject(cwd, env = node_process_1.default.env, options = {})
|
|
|
8135
9746
|
for (const suggestion of agentsCheck.suggestions) {
|
|
8136
9747
|
suggestions.add(suggestion);
|
|
8137
9748
|
}
|
|
8138
|
-
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest
|
|
9749
|
+
const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest);
|
|
8139
9750
|
for (const issue of envRunnerCheck.issues) {
|
|
8140
9751
|
issues.push(issue);
|
|
8141
9752
|
}
|
|
@@ -8189,13 +9800,16 @@ async function checkProjectNetwork(cwd, env = node_process_1.default.env, option
|
|
|
8189
9800
|
const suggestions = new Set();
|
|
8190
9801
|
const warnings = [];
|
|
8191
9802
|
const steps = [];
|
|
8192
|
-
|
|
8193
|
-
|
|
9803
|
+
let projectMetadata;
|
|
9804
|
+
try {
|
|
9805
|
+
projectMetadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
9806
|
+
}
|
|
9807
|
+
catch (error) {
|
|
8194
9808
|
return {
|
|
8195
|
-
issues: [
|
|
9809
|
+
issues: [error.message],
|
|
8196
9810
|
steps,
|
|
8197
9811
|
suggestions: [
|
|
8198
|
-
"Run `loom init` from a
|
|
9812
|
+
"Run `loom init` from a package.json or Deno project.",
|
|
8199
9813
|
],
|
|
8200
9814
|
warnings,
|
|
8201
9815
|
};
|
|
@@ -8209,7 +9823,7 @@ async function checkProjectNetwork(cwd, env = node_process_1.default.env, option
|
|
|
8209
9823
|
warnings,
|
|
8210
9824
|
};
|
|
8211
9825
|
}
|
|
8212
|
-
const packageJson =
|
|
9826
|
+
const packageJson = projectMetadata.packageJson;
|
|
8213
9827
|
const framework = await detectFramework(cwd, packageJson);
|
|
8214
9828
|
const manifest = parseJson(manifestText, "loom.json");
|
|
8215
9829
|
const context = {
|
|
@@ -8538,13 +10152,15 @@ function formatSkillLinkState(state) {
|
|
|
8538
10152
|
}
|
|
8539
10153
|
}
|
|
8540
10154
|
async function runStatus(cwd, io) {
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8544
|
-
|
|
10155
|
+
let projectMetadata;
|
|
10156
|
+
try {
|
|
10157
|
+
projectMetadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
10158
|
+
}
|
|
10159
|
+
catch (error) {
|
|
10160
|
+
io.err(error.message);
|
|
8545
10161
|
return 1;
|
|
8546
10162
|
}
|
|
8547
|
-
const packageJson =
|
|
10163
|
+
const packageJson = projectMetadata.packageJson;
|
|
8548
10164
|
const manifestText = await readTextIfExists((0, node_path_1.join)(cwd, "loom.json"));
|
|
8549
10165
|
const manifest = manifestText
|
|
8550
10166
|
? parseJson(manifestText, "loom.json")
|
|
@@ -8559,6 +10175,19 @@ async function runStatus(cwd, io) {
|
|
|
8559
10175
|
: null;
|
|
8560
10176
|
const workspaceText = await readTextIfExists((0, node_path_1.join)(cwd, "pnpm-workspace.yaml"));
|
|
8561
10177
|
const overrideSpec = getManagedDevOverrideSpec(workspaceText);
|
|
10178
|
+
let denoOverride = null;
|
|
10179
|
+
try {
|
|
10180
|
+
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling);
|
|
10181
|
+
if (usesDenoTooling(tooling)) {
|
|
10182
|
+
const config = await getDenoConfigForLinks(cwd, tooling);
|
|
10183
|
+
const link = await findLocalLoomDenoLink(cwd, await (0, projectTooling_js_1.readDenoLinks)(cwd, config));
|
|
10184
|
+
if (link)
|
|
10185
|
+
denoOverride = { config, link: link.link };
|
|
10186
|
+
}
|
|
10187
|
+
}
|
|
10188
|
+
catch {
|
|
10189
|
+
// Status reports stored project data even when live detection fails.
|
|
10190
|
+
}
|
|
8562
10191
|
const localLockfileResolution = await getProjectLocalLoomLockfileResolution(cwd);
|
|
8563
10192
|
const devState = getManagedDevState(workspaceText) ??
|
|
8564
10193
|
await readLocalDevState(cwd);
|
|
@@ -8567,14 +10196,22 @@ async function runStatus(cwd, io) {
|
|
|
8567
10196
|
io.out(`Loom status for ${projectName}`);
|
|
8568
10197
|
io.out("");
|
|
8569
10198
|
io.out("Package:");
|
|
8570
|
-
io.out(`
|
|
10199
|
+
io.out(` ${projectMetadata.config}: ${dependencySpec ? `${exports.LOOM_DEPENDENCY} ${dependencySpec}` : "not declared"}`);
|
|
8571
10200
|
io.out(` installed: ${installedPackage?.version ?? "not installed"}`);
|
|
8572
|
-
io.out(` local dev override: ${
|
|
10201
|
+
io.out(` local dev override: ${denoOverride
|
|
10202
|
+
? `active (${denoOverride.config} links ${denoOverride.link})`
|
|
10203
|
+
: overrideSpec
|
|
10204
|
+
? `active (${overrideSpec})`
|
|
10205
|
+
: "none"}`);
|
|
8573
10206
|
io.out(` lockfile local resolution: ${localLockfileResolution ?? "none"}`);
|
|
8574
10207
|
io.out("");
|
|
8575
10208
|
io.out("Project:");
|
|
8576
10209
|
io.out(` loom.json: ${manifest ? `version ${manifest.version}` : "missing"}`);
|
|
8577
10210
|
io.out(` framework: ${formatFrameworkInfo(framework)}`);
|
|
10211
|
+
if (manifest?.project?.tooling) {
|
|
10212
|
+
io.out(` tasks: ${manifest.project.tooling.tasks.config} via ${manifest.project.tooling.tasks.runner}`);
|
|
10213
|
+
io.out(` dependencies: ${manifest.project.tooling.dependencies.config} via ${manifest.project.tooling.dependencies.manager}`);
|
|
10214
|
+
}
|
|
8578
10215
|
io.out("");
|
|
8579
10216
|
io.out("Features:");
|
|
8580
10217
|
if (!manifest) {
|
|
@@ -8663,7 +10300,7 @@ function printHelp({ out }) {
|
|
|
8663
10300
|
out("loom <command>");
|
|
8664
10301
|
out("");
|
|
8665
10302
|
out("Commands:");
|
|
8666
|
-
out(" init Set up package
|
|
10303
|
+
out(" init Set up package/Deno config, loom.json, managed AGENTS.md guidance, first-party links, and package skills.");
|
|
8667
10304
|
out(" add <feature> Activate a shared feature. Run `loom add` to list available features.");
|
|
8668
10305
|
out(" files id-generation uuid-v4|uuid-v7 Select the managed Files schema ID default.");
|
|
8669
10306
|
out(" files r2 setup Create/reuse private Cloudflare R2 buckets, configure Vercel Production/Preview, and configure local MinIO by default.");
|
|
@@ -8685,8 +10322,8 @@ function printHelp({ out }) {
|
|
|
8685
10322
|
out(" db release setup-github Create/update GitHub production release config for staged Vercel deploys.");
|
|
8686
10323
|
out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
|
|
8687
10324
|
out(" db release verify-build-env <output> <manifest> Reject build-only placeholders in a deployable Vercel artifact.");
|
|
8688
|
-
out(" dev local Enable local Loom development using a managed
|
|
8689
|
-
out(" dev sync Rebuild
|
|
10325
|
+
out(" dev local Enable local Loom development using a managed pnpm override or Deno link.");
|
|
10326
|
+
out(" dev sync Rebuild local Loom and refresh this project's pnpm or Deno install when linked.");
|
|
8690
10327
|
out(" dev published Remove the managed local-dev override and return to the published dependency.");
|
|
8691
10328
|
out("");
|
|
8692
10329
|
out("Options:");
|
|
@@ -8925,12 +10562,15 @@ async function runSkills(cwd, command, args, io, options) {
|
|
|
8925
10562
|
printSkillsHelp(io);
|
|
8926
10563
|
return 0;
|
|
8927
10564
|
}
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
10565
|
+
let projectMetadata;
|
|
10566
|
+
try {
|
|
10567
|
+
projectMetadata = await (0, projectTooling_js_1.readProjectPackageMetadata)(cwd);
|
|
10568
|
+
}
|
|
10569
|
+
catch (error) {
|
|
10570
|
+
io.err(error.message);
|
|
8931
10571
|
return 1;
|
|
8932
10572
|
}
|
|
8933
|
-
const packageJson =
|
|
10573
|
+
const packageJson = projectMetadata.packageJson;
|
|
8934
10574
|
const manifestText = await readTextIfExists((0, node_path_1.join)(cwd, "loom.json"));
|
|
8935
10575
|
const manifest = manifestText
|
|
8936
10576
|
? parseJson(manifestText, "loom.json")
|
|
@@ -9098,7 +10738,16 @@ async function runDbSchemaGen(cwd, forwardedArgs, io) {
|
|
|
9098
10738
|
if (!isNodeErrorCode(error, "MODULE_NOT_FOUND")) {
|
|
9099
10739
|
throw error;
|
|
9100
10740
|
}
|
|
9101
|
-
|
|
10741
|
+
const manifest = await readManifestIfExists(cwd);
|
|
10742
|
+
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling);
|
|
10743
|
+
if (usesDenoTooling(tooling)) {
|
|
10744
|
+
const formatExitCode = await runInheritedChild("deno", ["fmt", config.dirs.valibotGeneratedDir], cwd);
|
|
10745
|
+
if (formatExitCode !== 0)
|
|
10746
|
+
return formatExitCode;
|
|
10747
|
+
}
|
|
10748
|
+
else {
|
|
10749
|
+
io.out("Biome is not installed; generated Valibot files were left unformatted.");
|
|
10750
|
+
}
|
|
9102
10751
|
}
|
|
9103
10752
|
if (await syncValibotBarrel(cwd, config)) {
|
|
9104
10753
|
io.out(`Updated ${config.modules.valibotBarrelModule}.`);
|
|
@@ -9401,7 +11050,7 @@ async function runDev(cwd, mode, pathInput, io, options = {}) {
|
|
|
9401
11050
|
io.out(`Updated ${result.changedFiles.join(", ")}.`);
|
|
9402
11051
|
}
|
|
9403
11052
|
else if (result.notes.length) {
|
|
9404
|
-
io.out("Project
|
|
11053
|
+
io.out("Project config uses a published @gadicc/loom dependency, but follow-up is still needed.");
|
|
9405
11054
|
}
|
|
9406
11055
|
else {
|
|
9407
11056
|
io.out("Project already uses the published @gadicc/loom dependency.");
|