@gadicc/loom 1.17.0 → 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.
@@ -10,6 +10,7 @@ import { DEFAULT_API_KEY_AUDIT_RETENTION } from "../apiKeys/retention.js";
10
10
  import { checkProjectSkills, getProjectSkillStatus, LOOM_EXTERNAL_SKILLS_GITIGNORE_LINE, removeLegacyNextSkillLink, setProjectSkillDisabled, syncExternalProjectSkills, syncInstalledPackageSkills, } from "./projectSkills.js";
11
11
  import { resolveMigrationEnvironment, resolveMigrationEnvironmentFromEnvFile, } from "./migrationEnv.js";
12
12
  import { prepareVercelBuildEnvironment, verifyVercelBuildArtifact, } from "./vercelBuildEnv.js";
13
+ import { detectProjectTooling, ensureTask, ensureTaskFollowup, ensureTaskPrerequisite, findTaskConflicts, formatTaskInvocation, getTaskCommand, mutateDenoLinks, mutateProjectDependencies, readDenoLinks, readProjectPackageMetadata, readTaskStore, taskInvokes, taskRunsBeforeCommand, } from "./projectTooling.js";
13
14
  export const DEFAULT_LOOM_RANGE = "^1.0.0";
14
15
  export const LOOM_DEPENDENCY = "@gadicc/loom";
15
16
  export const LOOM_MANIFEST_SCHEMA = "https://loom.gadicc.local/project-manifest.schema.json";
@@ -103,6 +104,12 @@ const managedSkills = [
103
104
  relativePackagePath: "skills/loom-mail",
104
105
  skillName: "loom-mail",
105
106
  },
107
+ {
108
+ featureKey: "lingui",
109
+ label: "loom Lingui skill",
110
+ relativePackagePath: "skills/loom-lingui",
111
+ skillName: "loom-lingui",
112
+ },
106
113
  ];
107
114
  const featureDefinitions = [
108
115
  {
@@ -125,6 +132,10 @@ const featureDefinitions = [
125
132
  key: "jobs",
126
133
  description: "Shared App Router admin jobs pages, route handlers, direct-run helpers, and job controller wiring.",
127
134
  },
135
+ {
136
+ key: "lingui",
137
+ description: "Lingui catalog source policy, generated-catalog ignores, dependencies, tasks, and build wiring.",
138
+ },
128
139
  {
129
140
  key: "mail",
130
141
  description: "Durable outgoing mail, Postal transport/webhooks, and admin-gated test-mail UI.",
@@ -202,6 +213,30 @@ const PWA_GITIGNORE_LINES = [
202
213
  "/public/workbox-*.js",
203
214
  "/public/workbox-*.js.map",
204
215
  ];
216
+ const LINGUI_DEFAULT_DEPENDENCIES = {
217
+ "@lingui/core": "^6.5.0",
218
+ "@lingui/react": "^6.5.0",
219
+ };
220
+ const LINGUI_DEFAULT_DEV_DEPENDENCIES = {
221
+ "@lingui/cli": "^6.5.0",
222
+ "@lingui/format-po": "^6.5.0",
223
+ "@lingui/swc-plugin": "^6.5.0",
224
+ };
225
+ const LINGUI_LOADER_DEV_DEPENDENCIES = {
226
+ "@lingui/loader": "^6.5.0",
227
+ };
228
+ const LINGUI_CONFIG_CANDIDATES = [
229
+ "lingui.config.ts",
230
+ "lingui.config.js",
231
+ "lingui.config.mts",
232
+ "lingui.config.mjs",
233
+ "lingui.config.cjs",
234
+ ];
235
+ const LINGUI_DEFAULT_TASKS = {
236
+ build: "build",
237
+ compile: "i18n:compile",
238
+ extract: "i18n:extract",
239
+ };
205
240
  const PWA_UPDATE_PROMPT = "A newer version of this web app is available. Reload to update?";
206
241
  const DB_CONNECTION_ENV_NAMES = [
207
242
  "DATABASE_URL",
@@ -329,11 +364,14 @@ async function readManifestFramework(cwd) {
329
364
  if (manifest?.project?.framework) {
330
365
  return manifest.project.framework;
331
366
  }
332
- const packageJsonText = await readTextIfExists(join(cwd, "package.json"));
333
- if (!packageJsonText) {
367
+ let metadata;
368
+ try {
369
+ metadata = await readProjectPackageMetadata(cwd);
370
+ }
371
+ catch {
334
372
  return null;
335
373
  }
336
- return await detectFramework(cwd, parseJson(packageJsonText, "package.json"));
374
+ return await detectFramework(cwd, metadata.packageJson);
337
375
  }
338
376
  async function loadProjectEnv(cwd) {
339
377
  const framework = await readManifestFramework(cwd);
@@ -429,7 +467,8 @@ function dbScriptBypassesEnvRunner(scriptName, scriptCommand) {
429
467
  return false;
430
468
  }
431
469
  return !scriptUsesLoomEnvRunner(scriptCommand) &&
432
- !/\bpnpm\s+drizzle-kit\b/.test(scriptCommand);
470
+ !/\b(?:pnpm|yarn|npx)\s+drizzle-kit\b/.test(scriptCommand) &&
471
+ !/\bdeno\s+run\s+-A\s+npm:drizzle-kit\b/.test(scriptCommand);
433
472
  }
434
473
  function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
435
474
  if (!scriptCommand) {
@@ -438,7 +477,7 @@ function jobsScriptBypassesEnvRunner(scriptName, scriptCommand) {
438
477
  return (scriptName === "job" || scriptCommand.includes("jobDirect.ts")) &&
439
478
  !scriptUsesLoomEnvRunner(scriptCommand);
440
479
  }
441
- async function checkEnvRunnerAdoption(cwd, manifest, packageJson) {
480
+ async function checkEnvRunnerAdoption(cwd, manifest) {
442
481
  const issues = [];
443
482
  const suggestions = new Set();
444
483
  const activeDb = manifest.features.db?.status === "active";
@@ -453,14 +492,25 @@ async function checkEnvRunnerAdoption(cwd, manifest, packageJson) {
453
492
  if (directEnvLoaderFiles.length) {
454
493
  suggestions.add("Move env loading into package scripts with `loom env -- <command>` and remove `dotenv`/`@next/env` imports from implementation files.");
455
494
  }
456
- for (const [scriptName, scriptCommand] of Object.entries(packageJson.scripts ?? {})) {
495
+ const tooling = await getProjectTooling(cwd, manifest);
496
+ const taskStore = await readTaskStore(cwd, tooling.tasks);
497
+ for (const [scriptName, definition] of Object.entries(taskStore.definitions)) {
498
+ const scriptCommand = getTaskCommand(definition);
457
499
  if (activeDb && dbScriptBypassesEnvRunner(scriptName, scriptCommand)) {
458
- issues.push(`DB package.json script bypasses the Loom env runner: ${scriptName}`);
459
- suggestions.add("Run `loom add db` to refresh DB package scripts.");
500
+ issues.push(taskStore.config === "package.json"
501
+ ? `DB package.json script bypasses the Loom env runner: ${scriptName}`
502
+ : `DB task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
503
+ suggestions.add(taskStore.config === "package.json"
504
+ ? "Run `loom add db` to refresh DB package scripts."
505
+ : "Run `loom add db` to refresh DB tasks.");
460
506
  }
461
507
  if (activeJobs && jobsScriptBypassesEnvRunner(scriptName, scriptCommand)) {
462
- issues.push(`Jobs package.json script bypasses the Loom env runner: ${scriptName}`);
463
- suggestions.add("Run `loom add jobs` to refresh jobs package scripts.");
508
+ issues.push(taskStore.config === "package.json"
509
+ ? `Jobs package.json script bypasses the Loom env runner: ${scriptName}`
510
+ : `Jobs task in ${taskStore.config} bypasses the Loom env runner: ${scriptName}`);
511
+ suggestions.add(taskStore.config === "package.json"
512
+ ? "Run `loom add jobs` to refresh jobs package scripts."
513
+ : "Run `loom add jobs` to refresh jobs tasks.");
464
514
  }
465
515
  }
466
516
  return {
@@ -725,6 +775,29 @@ function ensurePwaGitignoreText(existingText) {
725
775
  text: nextText,
726
776
  };
727
777
  }
778
+ function normalizeGitignorePattern(pattern) {
779
+ return pattern.trim().replaceAll("\\", "/").replace(/^\.\//, "");
780
+ }
781
+ function linguiGitignoreLineMatches(line, expectedLine) {
782
+ const normalized = normalizeGitignorePattern(line).replace(/^\//, "");
783
+ const expected = normalizeGitignorePattern(expectedLine).replace(/^\//, "");
784
+ return normalized === expected;
785
+ }
786
+ function ensureLinguiGitignoreText(existingText, generatedCatalogs) {
787
+ const normalized = existingText ? normalizeText(existingText) : "";
788
+ const lines = normalized
789
+ .split("\n")
790
+ .filter((line, index, array) => index < array.length - 1 || line !== "");
791
+ const missingLines = generatedCatalogs.filter((expectedLine) => !lines.some((line) => linguiGitignoreLineMatches(line, expectedLine)));
792
+ const nextText = missingLines.length
793
+ ? `${[...lines, ...missingLines].join("\n")}\n`
794
+ : normalized;
795
+ return {
796
+ changed: nextText !== normalized,
797
+ missingLines,
798
+ text: nextText,
799
+ };
800
+ }
728
801
  function loomDevStateGitignoreLineMatches(line) {
729
802
  const normalized = line.trim().replace(/^\/?/, "");
730
803
  return normalized === LOOM_LOCAL_DEV_STATE_GITIGNORE_LINE ||
@@ -758,58 +831,30 @@ export function ensurePackageJsonDependency(packageJson, versionRange = DEFAULT_
758
831
  previous: current,
759
832
  };
760
833
  }
761
- function ensurePackageJsonDependencies(packageJson, field, dependencies) {
762
- const nextPackageJson = structuredClone(packageJson);
763
- nextPackageJson[field] ??= {};
764
- const changedKeys = [];
765
- for (const [dependencyName, versionRange] of Object.entries(dependencies)) {
766
- if (!nextPackageJson[field][dependencyName]) {
767
- nextPackageJson[field][dependencyName] = versionRange;
768
- changedKeys.push(dependencyName);
769
- }
770
- }
771
- return {
772
- changed: changedKeys.length > 0,
773
- changedKeys,
774
- packageJson: nextPackageJson,
775
- };
834
+ async function getProjectTooling(cwd, manifest) {
835
+ return await detectProjectTooling(cwd, manifest.project?.tooling);
776
836
  }
777
- function removePackageJsonDependencies(packageJson, dependencyNames) {
778
- const nextPackageJson = structuredClone(packageJson);
779
- const removedKeys = [];
780
- for (const dependencyName of dependencyNames) {
781
- if (nextPackageJson.dependencies?.[dependencyName]) {
782
- delete nextPackageJson.dependencies[dependencyName];
783
- removedKeys.push(dependencyName);
784
- }
785
- if (nextPackageJson.devDependencies?.[dependencyName]) {
786
- delete nextPackageJson.devDependencies[dependencyName];
787
- removedKeys.push(dependencyName);
788
- }
789
- }
790
- return {
791
- changed: removedKeys.length > 0,
792
- packageJson: nextPackageJson,
793
- removedKeys,
794
- };
795
- }
796
- function ensurePackageJsonScripts(packageJson, scripts) {
797
- const nextPackageJson = structuredClone(packageJson);
798
- nextPackageJson.scripts ??= {};
837
+ async function ensureProjectTasks(cwd, manifest, tasks) {
838
+ const tooling = await getProjectTooling(cwd, manifest);
799
839
  const changedKeys = [];
800
- for (const [scriptName, scriptCommand] of Object.entries(scripts)) {
801
- if (nextPackageJson.scripts[scriptName] !== scriptCommand) {
802
- nextPackageJson.scripts[scriptName] = scriptCommand;
803
- changedKeys.push(scriptName);
804
- }
840
+ for (const [name, definition] of Object.entries(tasks)) {
841
+ const result = await ensureTask(cwd, tooling.tasks, { definition, name });
842
+ if (result.changed)
843
+ changedKeys.push(name);
805
844
  }
845
+ return { changedKeys, config: tooling.tasks.config, tooling };
846
+ }
847
+ async function checkProjectTasks(cwd, manifest, expected) {
848
+ const tooling = await getProjectTooling(cwd, manifest);
849
+ const store = await readTaskStore(cwd, tooling.tasks);
806
850
  return {
807
- changed: changedKeys.length > 0,
808
- changedKeys,
809
- packageJson: nextPackageJson,
851
+ config: tooling.tasks.config,
852
+ mismatches: Object.entries(expected).flatMap(([name, command]) => getTaskCommand(store.definitions[name]) === command ? [] : [name]),
853
+ store,
854
+ tooling,
810
855
  };
811
856
  }
812
- export function buildManifest(cwd, packageJson, framework, existingManifest) {
857
+ export function buildManifest(cwd, packageJson, framework, existingManifest, tooling) {
813
858
  return {
814
859
  $schema: existingManifest?.$schema ?? LOOM_MANIFEST_SCHEMA,
815
860
  version: 1,
@@ -821,6 +866,7 @@ export function buildManifest(cwd, packageJson, framework, existingManifest) {
821
866
  ...existingManifest?.project?.framework,
822
867
  ...framework,
823
868
  },
869
+ tooling: existingManifest?.project?.tooling ?? tooling,
824
870
  },
825
871
  features: existingManifest?.features ?? {},
826
872
  };
@@ -840,33 +886,6 @@ function hasPackageDependency(packageJson, dependencyName) {
840
886
  return Boolean(packageJson.dependencies?.[dependencyName] ||
841
887
  packageJson.devDependencies?.[dependencyName]);
842
888
  }
843
- async function detectPackageManager(cwd, packageJson) {
844
- if (packageJson.packageManager?.startsWith("pnpm@")) {
845
- return "pnpm";
846
- }
847
- if (packageJson.packageManager?.startsWith("yarn@")) {
848
- return "yarn";
849
- }
850
- if (packageJson.packageManager?.startsWith("npm@")) {
851
- return "npm";
852
- }
853
- if (await exists(join(cwd, "pnpm-lock.yaml"))) {
854
- return "pnpm";
855
- }
856
- if (await exists(join(cwd, "yarn.lock"))) {
857
- return "yarn";
858
- }
859
- return "npm";
860
- }
861
- function getRunScriptCommand(packageManager, scriptName) {
862
- if (packageManager === "pnpm") {
863
- return `pnpm ${scriptName}`;
864
- }
865
- if (packageManager === "yarn") {
866
- return `yarn ${scriptName}`;
867
- }
868
- return `npm run ${scriptName}`;
869
- }
870
889
  function scriptRunsSerwistBuild(script) {
871
890
  return Boolean(script && (/\bserwist\s+build\b/.test(script) ||
872
891
  script.includes("@serwist/cli") ||
@@ -881,35 +900,6 @@ function formatTsNumberLiteral(value) {
881
900
  function numberLiteralRegExp(value) {
882
901
  return String(value).split("").map((digit) => `${digit}_?`).join("");
883
902
  }
884
- function ensurePwaPackageJsonScripts(packageJson, packageManager) {
885
- const nextPackageJson = structuredClone(packageJson);
886
- nextPackageJson.scripts ??= {};
887
- const changedKeys = [];
888
- const notes = [];
889
- if (nextPackageJson.scripts["pwa:build"] !== PWA_BUILD_SCRIPT) {
890
- nextPackageJson.scripts["pwa:build"] = PWA_BUILD_SCRIPT;
891
- changedKeys.push("pwa:build");
892
- }
893
- const buildScript = nextPackageJson.scripts.build;
894
- if (!buildScript) {
895
- nextPackageJson.scripts.build = `next build && ${getRunScriptCommand(packageManager, "pwa:build")}`;
896
- changedKeys.push("build");
897
- }
898
- else if (buildScript.includes("next build") &&
899
- !scriptRunsSerwistBuild(buildScript)) {
900
- nextPackageJson.scripts.build = `${buildScript} && ${getRunScriptCommand(packageManager, "pwa:build")}`;
901
- changedKeys.push("build");
902
- }
903
- else if (!scriptRunsSerwistBuild(buildScript)) {
904
- 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.");
905
- }
906
- return {
907
- changed: changedKeys.length > 0,
908
- changedKeys,
909
- notes,
910
- packageJson: nextPackageJson,
911
- };
912
- }
913
903
  function getJobsConfig(framework) {
914
904
  const appRoot = framework.srcDir ? "src/app" : "app";
915
905
  const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
@@ -1152,12 +1142,37 @@ async function mergeAuthConfig(cwd, framework, featureConfig) {
1152
1142
  },
1153
1143
  };
1154
1144
  }
1155
- function getDbExpectedScripts(config) {
1145
+ function dependencyExecutable(tooling, executable) {
1146
+ switch (tooling.manager) {
1147
+ case "deno":
1148
+ return `deno run -A npm:${executable}`;
1149
+ case "npm":
1150
+ return `npx ${executable}`;
1151
+ case "pnpm":
1152
+ return `pnpm ${executable}`;
1153
+ case "yarn":
1154
+ return `yarn ${executable}`;
1155
+ }
1156
+ }
1157
+ function dependencyRefreshCommand(tooling, name, version) {
1158
+ switch (tooling.manager) {
1159
+ case "deno":
1160
+ return "deno install";
1161
+ case "npm":
1162
+ return `npm install --save-exact ${name}@${version}`;
1163
+ case "pnpm":
1164
+ return `pnpm update --no-save ${name}@${version} && pnpm install`;
1165
+ case "yarn":
1166
+ return `yarn add --exact ${name}@${version}`;
1167
+ }
1168
+ }
1169
+ function getDbExpectedScripts(config, tooling) {
1170
+ const drizzleKit = dependencyExecutable(tooling.dependencies, "drizzle-kit");
1156
1171
  return {
1157
1172
  "db:fixtures": "loom db fixtures",
1158
- "db:generate": "pnpm drizzle-kit generate",
1159
- "db:migrate": "pnpm drizzle-kit migrate",
1160
- "db:push": "pnpm drizzle-kit push",
1173
+ "db:generate": `${drizzleKit} generate`,
1174
+ "db:migrate": `${drizzleKit} migrate`,
1175
+ "db:push": `${drizzleKit} push`,
1161
1176
  "drizzle-kit": `NODE_OPTIONS='--import tsx' loom env -- drizzle-kit --config=./${config.modules.drizzleConfig}`,
1162
1177
  "schema:gen": "loom db schema-gen",
1163
1178
  };
@@ -1790,9 +1805,10 @@ For all work in this repo:
1790
1805
  1. Use the \`loom\` skill first.
1791
1806
  2. Read \`loom.json\` before making Loom-related changes.
1792
1807
  3. Treat active Loom features and configured paths as the contract between the app and the shared package.
1793
- 4. If the task touches a specific active Loom feature, also use the matching feature skill such as \`loom-jobs\`.
1794
- 5. Next commands load \`.env*\` themselves; non-Next commands that need env should use project scripts or \`loom env -- <command>\`, not inline env-loader imports.
1795
- 6. Keep project-specific rules outside this managed block; shared Loom policy lives in the \`loom\` skill.
1808
+ 4. Read \`project.tooling\` in \`loom.json\`; do not assume tasks live in \`package.json\` or that pnpm is the runner.
1809
+ 5. If the task touches a specific active Loom feature, also use the matching feature skill such as \`loom-jobs\`.
1810
+ 6. Next commands load \`.env*\` themselves; non-Next commands that need env should use the authoritative project task or \`loom env -- <command>\`, not inline env-loader imports.
1811
+ 7. Keep project-specific rules outside this managed block; shared Loom policy lives in the \`loom\` skill.
1796
1812
  ${LOOM_MANAGED_AGENTS_END}
1797
1813
  `;
1798
1814
  }
@@ -2055,6 +2071,37 @@ async function ensurePnpmProject(cwd, packageJson) {
2055
2071
  }
2056
2072
  throw new Error("loom dev local/published currently supports pnpm projects only.");
2057
2073
  }
2074
+ function usesDenoTooling(tooling) {
2075
+ return tooling.tasks.runner === "deno" ||
2076
+ tooling.dependencies.manager === "deno";
2077
+ }
2078
+ async function getDenoConfigForLinks(cwd, tooling) {
2079
+ for (const config of [
2080
+ tooling.tasks.config,
2081
+ tooling.dependencies.config,
2082
+ "deno.json",
2083
+ "deno.jsonc",
2084
+ ]) {
2085
+ if ((config === "deno.json" || config === "deno.jsonc") &&
2086
+ await exists(join(cwd, config))) {
2087
+ return config;
2088
+ }
2089
+ }
2090
+ throw new Error("Deno local development requires a deno.json or deno.jsonc workspace root.");
2091
+ }
2092
+ async function findLocalLoomDenoLink(cwd, links) {
2093
+ for (const link of links) {
2094
+ const path = resolve(cwd, link);
2095
+ const packageText = await readTextIfExists(join(path, "package.json"));
2096
+ if (!packageText)
2097
+ continue;
2098
+ if (parseJson(packageText, `${link}/package.json`).name ===
2099
+ LOOM_DEPENDENCY) {
2100
+ return { link, path };
2101
+ }
2102
+ }
2103
+ return null;
2104
+ }
2058
2105
  async function resolveLocalLoomPackagePath(cwd, inputPath) {
2059
2106
  const resolvedInput = resolve(cwd, inputPath);
2060
2107
  const candidates = [resolvedInput, join(resolvedInput, "npm")];
@@ -2170,6 +2217,9 @@ async function readPackageVersion(packagePath) {
2170
2217
  }
2171
2218
  return parseJson(packageJsonText, join(packagePath, "package.json")).version;
2172
2219
  }
2220
+ function versionFromDependencySpec(spec) {
2221
+ return spec?.match(/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/)?.[1];
2222
+ }
2173
2223
  async function getGitStdout(commandRunner, cwd, args, env) {
2174
2224
  const result = await commandRunner("git", args, { cwd, env });
2175
2225
  if (result.code !== 0) {
@@ -2236,7 +2286,7 @@ async function writeLocalDevStateIfChanged(cwd, state) {
2236
2286
  await writeFile(gitignorePath, gitignoreUpdate.text, "utf8");
2237
2287
  gitignoreChanged = true;
2238
2288
  }
2239
- return stateChanged || gitignoreChanged;
2289
+ return { gitignoreChanged, stateChanged };
2240
2290
  }
2241
2291
  async function getCurrentLocalDevState(cwd, workspaceText) {
2242
2292
  return getManagedDevState(workspaceText) ?? await readLocalDevState(cwd);
@@ -2352,10 +2402,19 @@ async function resolveLoomCommitPublication(sourceRoot, sourceCommit, commandRun
2352
2402
  return { status: "no-release-tag" };
2353
2403
  }
2354
2404
  export async function syncLocalDevPackage(cwd, options = {}) {
2405
+ const manifest = await readManifestIfExists(cwd);
2406
+ const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
2407
+ const denoMode = usesDenoTooling(tooling);
2355
2408
  const workspacePath = join(cwd, "pnpm-workspace.yaml");
2356
2409
  const workspaceText = await readTextIfExists(workspacePath);
2357
2410
  const overrideSpec = getManagedDevOverrideSpec(workspaceText);
2358
- if (!overrideSpec) {
2411
+ const denoConfig = denoMode
2412
+ ? await getDenoConfigForLinks(cwd, tooling)
2413
+ : null;
2414
+ const denoLink = denoConfig
2415
+ ? await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, denoConfig))
2416
+ : null;
2417
+ if (!overrideSpec && !denoLink) {
2359
2418
  if (options.requireActive) {
2360
2419
  throw new Error("No managed Loom local-dev override is active. Run `loom dev local /path/to/loom` first.");
2361
2420
  }
@@ -2368,20 +2427,31 @@ export async function syncLocalDevPackage(cwd, options = {}) {
2368
2427
  };
2369
2428
  }
2370
2429
  const { packageJson } = await readProjectPackageJson(cwd);
2371
- await ensurePnpmProject(cwd, packageJson);
2430
+ if (!denoMode)
2431
+ await ensurePnpmProject(cwd, packageJson);
2372
2432
  const commandRunner = options.commandRunner ?? defaultCommandRunner;
2373
2433
  const env = options.env ?? process.env;
2374
- const localPackagePath = fileSpecToPath(cwd, overrideSpec);
2434
+ const localPackagePath = denoLink?.path ??
2435
+ fileSpecToPath(cwd, overrideSpec);
2375
2436
  const sourceRoot = await resolveLocalLoomSourceRoot(localPackagePath);
2437
+ const configuredSpec = packageJson.dependencies?.[LOOM_DEPENDENCY] ??
2438
+ packageJson.devDependencies?.[LOOM_DEPENDENCY];
2439
+ const desiredLocalVersion = await readPackageVersion(join(cwd, "node_modules", LOOM_DEPENDENCY)) ?? versionFromDependencySpec(configuredSpec) ??
2440
+ await readPackageVersion(localPackagePath);
2441
+ const currentLocalVersion = await readPackageVersion(localPackagePath);
2442
+ const buildEnv = desiredLocalVersion && !env.NPM_PACKAGE_VERSION
2443
+ ? { ...env, NPM_PACKAGE_VERSION: desiredLocalVersion }
2444
+ : env;
2376
2445
  const ranCommands = [];
2377
2446
  let buildRan = false;
2378
- if (options.force || await isLocalLoomBuildStale(sourceRoot, localPackagePath)) {
2447
+ if (options.force || denoMode && currentLocalVersion !== desiredLocalVersion ||
2448
+ await isLocalLoomBuildStale(sourceRoot, localPackagePath)) {
2379
2449
  if (!sourceRoot) {
2380
2450
  throw new Error(`Could not find the Loom source checkout for ${localPackagePath}; cannot rebuild the local package.`);
2381
2451
  }
2382
2452
  await runCommandOrThrow(commandRunner, "deno", ["task", "build"], {
2383
2453
  cwd: sourceRoot,
2384
- env,
2454
+ env: buildEnv,
2385
2455
  stdio: "inherit",
2386
2456
  });
2387
2457
  ranCommands.push("deno task build");
@@ -2391,25 +2461,39 @@ export async function syncLocalDevPackage(cwd, options = {}) {
2391
2461
  await isInstalledLocalLoomPackageStale(cwd, localPackagePath);
2392
2462
  let packageRefreshRan = false;
2393
2463
  if (options.force || packageRefreshNeeded) {
2394
- const packageSpec = `${LOOM_DEPENDENCY}@file:${localPackagePath}`;
2395
- await runCommandOrThrow(commandRunner, "pnpm", ["update", "--no-save", packageSpec], { cwd, env, stdio: "inherit" });
2396
- ranCommands.push(`pnpm update --no-save ${packageSpec}`);
2397
- await runCommandOrThrow(commandRunner, "pnpm", ["install"], {
2398
- cwd,
2399
- env,
2400
- stdio: "inherit",
2401
- });
2402
- ranCommands.push("pnpm install");
2464
+ if (denoMode) {
2465
+ await runCommandOrThrow(commandRunner, "deno", ["install"], {
2466
+ cwd,
2467
+ env,
2468
+ stdio: "inherit",
2469
+ });
2470
+ ranCommands.push("deno install");
2471
+ }
2472
+ else {
2473
+ const packageSpec = `${LOOM_DEPENDENCY}@file:${localPackagePath}`;
2474
+ await runCommandOrThrow(commandRunner, "pnpm", ["update", "--no-save", packageSpec], { cwd, env, stdio: "inherit" });
2475
+ ranCommands.push(`pnpm update --no-save ${packageSpec}`);
2476
+ await runCommandOrThrow(commandRunner, "pnpm", ["install"], {
2477
+ cwd,
2478
+ env,
2479
+ stdio: "inherit",
2480
+ });
2481
+ ranCommands.push("pnpm install");
2482
+ }
2403
2483
  packageRefreshRan = true;
2404
2484
  }
2405
2485
  const currentWorkspaceText = await readTextIfExists(workspacePath);
2406
- const currentState = await getCurrentLocalDevState(cwd, currentWorkspaceText);
2486
+ const currentState = denoMode
2487
+ ? await readLocalDevState(cwd)
2488
+ : await getCurrentLocalDevState(cwd, currentWorkspaceText);
2407
2489
  let state = null;
2408
2490
  if (buildRan || packageRefreshRan || !currentState) {
2409
2491
  state = await buildLocalDevState(localPackagePath, sourceRoot, commandRunner, env);
2410
- const stateUpdate = setManagedDevStateText(await readTextIfExists(workspacePath), overrideSpec, state);
2411
- if (stateUpdate.changed) {
2412
- await writeTextOrDeleteIfEmpty(workspacePath, stateUpdate.text);
2492
+ if (!denoMode) {
2493
+ const stateUpdate = setManagedDevStateText(await readTextIfExists(workspacePath), overrideSpec, state);
2494
+ if (stateUpdate.changed) {
2495
+ await writeTextOrDeleteIfEmpty(workspacePath, stateUpdate.text);
2496
+ }
2413
2497
  }
2414
2498
  }
2415
2499
  if (state ?? currentState) {
@@ -2438,16 +2522,43 @@ export async function syncLocalDevPackage(cwd, options = {}) {
2438
2522
  };
2439
2523
  }
2440
2524
  export async function useLocalDevPackage(cwd, inputPath) {
2441
- const packageJsonPath = join(cwd, "package.json");
2442
- const packageJsonText = await readTextIfExists(packageJsonPath);
2443
- if (!packageJsonText) {
2444
- throw new Error(`No package.json found in ${cwd}`);
2525
+ const { packageJson } = await readProjectPackageJson(cwd);
2526
+ const manifest = await readManifestIfExists(cwd);
2527
+ const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
2528
+ const localPackagePath = await resolveLocalLoomPackagePath(cwd, inputPath);
2529
+ const publishedSpec = getPublishedLoomDependencySpec(packageJson);
2530
+ if (usesDenoTooling(tooling)) {
2531
+ if (!await exists(join(localPackagePath, "deno.json"))) {
2532
+ throw new Error(`Local Deno development requires ${localPackagePath}/deno.json. Rebuild the Loom npm output before linking it.`);
2533
+ }
2534
+ const denoConfig = await getDenoConfigForLinks(cwd, tooling);
2535
+ const relativeLocalPackagePath = relative(cwd, localPackagePath)
2536
+ .replaceAll("\\", "/");
2537
+ const update = await mutateDenoLinks(cwd, denoConfig, {
2538
+ add: relativeLocalPackagePath,
2539
+ });
2540
+ const state = {
2541
+ dependency: LOOM_DEPENDENCY,
2542
+ localPackagePath,
2543
+ packageVersion: await readPackageVersion(localPackagePath),
2544
+ syncedAt: new Date().toISOString(),
2545
+ version: 1,
2546
+ };
2547
+ const stateUpdate = await writeLocalDevStateIfChanged(cwd, state);
2548
+ const changedFiles = update.changed ? [denoConfig] : [];
2549
+ if (stateUpdate.gitignoreChanged)
2550
+ changedFiles.push(".gitignore");
2551
+ return {
2552
+ changedFiles,
2553
+ notes: [
2554
+ `Local Loom dev link is active in ${denoConfig}: ${localPackagePath}`,
2555
+ "Run `loom dev sync` to rebuild the local Loom package and refresh Deno's dependency installation when needed.",
2556
+ `Before committing or shipping a published build, run loom dev published, then deno install to restore ${LOOM_DEPENDENCY}@${publishedSpec}.`,
2557
+ ],
2558
+ };
2445
2559
  }
2446
- const packageJson = parseJson(packageJsonText, "package.json");
2447
2560
  await ensurePnpmProject(cwd, packageJson);
2448
- const localPackagePath = await resolveLocalLoomPackagePath(cwd, inputPath);
2449
2561
  const overrideSpec = `file:${localPackagePath}`;
2450
- const publishedSpec = getPublishedLoomDependencySpec(packageJson);
2451
2562
  const workspacePath = join(cwd, "pnpm-workspace.yaml");
2452
2563
  const update = ensurePnpmWorkspaceLocalDevText(await readTextIfExists(workspacePath), overrideSpec);
2453
2564
  if (update.conflict) {
@@ -2468,20 +2579,30 @@ export async function useLocalDevPackage(cwd, inputPath) {
2468
2579
  };
2469
2580
  }
2470
2581
  export async function usePublishedDevPackage(cwd, options = {}) {
2471
- const packageJsonPath = join(cwd, "package.json");
2472
- const packageJsonText = await readTextIfExists(packageJsonPath);
2473
- if (!packageJsonText) {
2474
- throw new Error(`No package.json found in ${cwd}`);
2475
- }
2476
- const packageJson = parseJson(packageJsonText, "package.json");
2477
- await ensurePnpmProject(cwd, packageJson);
2582
+ const { packageJson } = await readProjectPackageJson(cwd);
2583
+ const manifest = await readManifestIfExists(cwd);
2584
+ const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
2585
+ const denoMode = usesDenoTooling(tooling);
2586
+ if (!denoMode)
2587
+ await ensurePnpmProject(cwd, packageJson);
2478
2588
  const commandRunner = options.commandRunner ?? defaultCommandRunner;
2479
2589
  const env = options.env ?? process.env;
2480
2590
  const workspacePath = join(cwd, "pnpm-workspace.yaml");
2481
2591
  const workspaceText = await readTextIfExists(workspacePath);
2482
- const activeOverrideSpec = getManagedDevOverrideSpec(workspaceText);
2483
- const localLockfileResolution = await getProjectLocalLoomLockfileResolution(cwd);
2484
- const state = await getCurrentLocalDevState(cwd, workspaceText);
2592
+ const denoConfig = denoMode
2593
+ ? await getDenoConfigForLinks(cwd, tooling)
2594
+ : null;
2595
+ const denoLink = denoConfig
2596
+ ? await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, denoConfig))
2597
+ : null;
2598
+ const activeOverrideSpec = denoLink?.link ??
2599
+ getManagedDevOverrideSpec(workspaceText);
2600
+ const localLockfileResolution = denoMode
2601
+ ? null
2602
+ : await getProjectLocalLoomLockfileResolution(cwd);
2603
+ const state = denoMode
2604
+ ? await readLocalDevState(cwd)
2605
+ : await getCurrentLocalDevState(cwd, workspaceText);
2485
2606
  const notes = [];
2486
2607
  let publishedSpec = getPublishedLoomDependencySpec(packageJson);
2487
2608
  const needsPublicationProof = Boolean(activeOverrideSpec || localLockfileResolution);
@@ -2504,21 +2625,33 @@ export async function usePublishedDevPackage(cwd, options = {}) {
2504
2625
  else if (needsPublicationProof) {
2505
2626
  notes.push("No recorded Loom sync commit was found; switching back to the existing published dependency without proving whether local Loom changes were required.");
2506
2627
  }
2507
- const dependencyUpdate = ensurePackageJsonDependency(packageJson, publishedSpec);
2508
- if (dependencyUpdate.changed) {
2509
- await writeFile(packageJsonPath, stringifyJson(dependencyUpdate.packageJson), "utf8");
2510
- }
2511
- const update = clearPnpmWorkspaceLocalDevText(await readTextIfExists(workspacePath));
2628
+ const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
2629
+ dependencies: { [LOOM_DEPENDENCY]: publishedSpec },
2630
+ replace: true,
2631
+ });
2632
+ const denoUpdate = denoConfig && denoLink
2633
+ ? await mutateDenoLinks(cwd, denoConfig, { remove: denoLink.link })
2634
+ : null;
2635
+ const update = denoMode
2636
+ ? { changed: denoUpdate?.changed ?? false, text: "" }
2637
+ : clearPnpmWorkspaceLocalDevText(await readTextIfExists(workspacePath));
2512
2638
  const changedFiles = [];
2513
2639
  if (dependencyUpdate.changed) {
2514
- changedFiles.push("package.json");
2640
+ changedFiles.push(dependencyUpdate.config);
2515
2641
  }
2516
2642
  if (update.changed) {
2517
- await writeTextOrDeleteIfEmpty(workspacePath, update.text);
2518
- changedFiles.push("pnpm-workspace.yaml");
2643
+ if (denoMode) {
2644
+ changedFiles.push(denoConfig);
2645
+ }
2646
+ else {
2647
+ await writeTextOrDeleteIfEmpty(workspacePath, update.text);
2648
+ changedFiles.push("pnpm-workspace.yaml");
2649
+ }
2519
2650
  }
2520
2651
  if (update.changed || localLockfileResolution) {
2521
- notes.push(`Run \`pnpm update --no-save ${LOOM_DEPENDENCY}@${publishedSpec}\` and then \`pnpm install\` in this project to return node_modules and the lockfile to the published ${LOOM_DEPENDENCY} dependency.`);
2652
+ notes.push(denoMode
2653
+ ? `Run \`deno install\` in this project to return node_modules and deno.lock to published ${LOOM_DEPENDENCY}@${publishedSpec}.`
2654
+ : `Run \`pnpm update --no-save ${LOOM_DEPENDENCY}@${publishedSpec}\` and then \`pnpm install\` in this project to return node_modules and the lockfile to the published ${LOOM_DEPENDENCY} dependency.`);
2522
2655
  }
2523
2656
  if (localLockfileResolution) {
2524
2657
  notes.push(`pnpm-lock.yaml still resolves ${LOOM_DEPENDENCY} to ${localLockfileResolution} until that update is run.`);
@@ -2652,26 +2785,43 @@ async function checkManagedAgentsFile(cwd) {
2652
2785
  };
2653
2786
  }
2654
2787
  async function checkManagedLocalDevOverride(cwd, production = false) {
2788
+ const manifest = await readManifestIfExists(cwd);
2789
+ let denoLink = null;
2790
+ let denoConfig = null;
2791
+ try {
2792
+ const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
2793
+ if (usesDenoTooling(tooling)) {
2794
+ denoConfig = await getDenoConfigForLinks(cwd, tooling);
2795
+ denoLink = await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, denoConfig));
2796
+ }
2797
+ }
2798
+ catch {
2799
+ // The main project tooling check reports invalid configuration separately.
2800
+ }
2655
2801
  const workspaceText = await readTextIfExists(join(cwd, "pnpm-workspace.yaml"));
2656
2802
  const overrideSpec = getManagedDevOverrideSpec(workspaceText);
2657
- if (!overrideSpec) {
2803
+ if (!overrideSpec && !denoLink) {
2658
2804
  return {
2659
2805
  issues: [],
2660
2806
  suggestions: [],
2661
2807
  warnings: [],
2662
2808
  };
2663
2809
  }
2810
+ const location = denoLink
2811
+ ? `${denoConfig} links: ${denoLink.link}`
2812
+ : `pnpm-workspace.yaml: ${overrideSpec}`;
2813
+ const restore = denoLink
2814
+ ? "Run `loom dev published`, then run `deno install` before committing or shipping a published build."
2815
+ : `Run \`loom dev published\`, then follow its printed \`pnpm update --no-save ${LOOM_DEPENDENCY}@<version>\` command and run \`pnpm install\` before committing or shipping a published build.`;
2664
2816
  return {
2665
2817
  issues: production
2666
2818
  ? [
2667
- `Local Loom dev override is active in pnpm-workspace.yaml: ${overrideSpec}`,
2819
+ `Local Loom dev override is active in ${location}`,
2668
2820
  ]
2669
2821
  : [],
2670
- suggestions: [
2671
- `Run \`loom dev published\`, then follow its printed \`pnpm update --no-save ${LOOM_DEPENDENCY}@<version>\` command and run \`pnpm install\` before committing or shipping a published build.`,
2672
- ],
2822
+ suggestions: [restore],
2673
2823
  warnings: production ? [] : [
2674
- `Local Loom dev override is active in pnpm-workspace.yaml: ${overrideSpec}`,
2824
+ `Local Loom dev override is active in ${location}`,
2675
2825
  ],
2676
2826
  };
2677
2827
  }
@@ -2712,6 +2862,18 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
2712
2862
  const warnings = [];
2713
2863
  const dependency = packageJson.dependencies?.[LOOM_DEPENDENCY];
2714
2864
  const production = options.production;
2865
+ const projectMetadata = await readProjectPackageMetadata(cwd);
2866
+ let dependencyTooling = {
2867
+ config: projectMetadata.config,
2868
+ manager: projectMetadata.config === "package.json" ? "pnpm" : "deno",
2869
+ };
2870
+ try {
2871
+ const manifest = await readManifestIfExists(cwd);
2872
+ dependencyTooling = (await detectProjectTooling(cwd, manifest?.project?.tooling)).dependencies;
2873
+ }
2874
+ catch {
2875
+ // The main tooling check owns the validation error; release hints can fall back.
2876
+ }
2715
2877
  const localLockfileResolution = await getProjectLocalLoomLockfileResolution(cwd);
2716
2878
  const devState = await readLocalDevState(cwd);
2717
2879
  if (localLockfileResolution) {
@@ -2745,8 +2907,8 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
2745
2907
  "package-equivalent"
2746
2908
  ? `package-relevant files match ${LOOM_DEPENDENCY}@${publication.version}`
2747
2909
  : `it is published as ${LOOM_DEPENDENCY}@${publication.version}`;
2748
- addReleaseCheckMessage(issues, warnings, production, `This app was last synced against Loom commit ${shortCommit}; ${publicationDescription}, but package.json is pinned to ${dependency}.`);
2749
- suggestions.add(`Run \`pnpm update --no-save ${LOOM_DEPENDENCY}@${publication.version}\` and then \`pnpm install\`.`);
2910
+ addReleaseCheckMessage(issues, warnings, production, `This app was last synced against Loom commit ${shortCommit}; ${publicationDescription}, but ${dependencyTooling.config} is pinned to ${dependency}.`);
2911
+ suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, LOOM_DEPENDENCY, publication.version)}.`);
2750
2912
  }
2751
2913
  else if (localLockfileResolution) {
2752
2914
  const publicationDescription = publication.reason ===
@@ -2754,7 +2916,7 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
2754
2916
  ? `has no package-relevant changes after ${publication.tag}, so ${LOOM_DEPENDENCY}@${publication.version} covers it`
2755
2917
  : `is published as ${LOOM_DEPENDENCY}@${publication.version}`;
2756
2918
  warnings.push(`The synced Loom commit ${shortCommit} ${publicationDescription}; refresh the lockfile away from ${localLockfileResolution}.`);
2757
- suggestions.add(`Run \`pnpm update --no-save ${LOOM_DEPENDENCY}@${publication.version}\` and then \`pnpm install\`.`);
2919
+ suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, LOOM_DEPENDENCY, publication.version)}.`);
2758
2920
  }
2759
2921
  break;
2760
2922
  }
@@ -2779,8 +2941,8 @@ async function checkLoomReleaseState(cwd, packageJson, options) {
2779
2941
  else {
2780
2942
  const installedPackage = parseJson(installedPackageText, join("node_modules", LOOM_DEPENDENCY, "package.json"));
2781
2943
  if (installedPackage.version !== dependency) {
2782
- issues.push(`Installed ${LOOM_DEPENDENCY} version ${installedPackage.version} does not match package.json ${dependency}.`);
2783
- suggestions.add(`Run \`pnpm update --no-save ${LOOM_DEPENDENCY}@${dependency}\` and then \`pnpm install\`.`);
2944
+ issues.push(`Installed ${LOOM_DEPENDENCY} version ${installedPackage.version} does not match ${dependencyTooling.config} ${dependency}.`);
2945
+ suggestions.add(`Run ${dependencyRefreshCommand(dependencyTooling, LOOM_DEPENDENCY, dependency)}.`);
2784
2946
  }
2785
2947
  }
2786
2948
  }
@@ -2854,7 +3016,7 @@ function getGithubWorkflowStepBlocks(text) {
2854
3016
  }
2855
3017
  function workflowInstallsNodeDependencies(stepBlocks) {
2856
3018
  return stepBlocks.some((block) => /uses:\s*actions\/setup-node@/m.test(block) ||
2857
- /\b(?:pnpm\s+(?:install|i)|npm\s+(?:ci|install)|yarn\s+install|bun\s+install)\b/
3019
+ /\b(?:deno\s+install|pnpm\s+(?:install|i)|npm\s+(?:ci|install)|yarn\s+install|bun\s+install)\b/
2858
3020
  .test(block));
2859
3021
  }
2860
3022
  function hasGithubPackagesSetupNodeConfig(stepBlocks) {
@@ -2977,14 +3139,14 @@ function githubWorkflowRunsOnMainPush(text) {
2977
3139
  return !hasBranchFilter && !ignoresMain;
2978
3140
  }
2979
3141
  function workflowStepRunsDbMigrate(block) {
2980
- return /\b(?:pnpm\s+(?:run\s+)?db:migrate|npm\s+run\s+db:migrate|yarn\s+(?:run\s+)?db:migrate|bun\s+run\s+db:migrate)\b/
3142
+ return /\b(?:deno\s+task\s+db:migrate|pnpm\s+(?:run\s+)?db:migrate|npm\s+run\s+db:migrate|yarn\s+(?:run\s+)?db:migrate|bun\s+run\s+db:migrate)\b/
2981
3143
  .test(block) ||
2982
3144
  /\bdrizzle-kit\s+migrate\b/.test(block) ||
2983
3145
  /spawnSync\(\s*["']pnpm["'][\s\S]*["']db:migrate["']/.test(block);
2984
3146
  }
2985
3147
  function workflowStepUsesVercelCommand(block, subcommand) {
2986
3148
  const launcher = String
2987
- .raw `(?:vercel|pnpm\s+(?:dlx|exec)\s+vercel(?:@[^\s]+)?|npx\s+vercel(?:@[^\s]+)?|yarn\s+(?:dlx\s+)?vercel(?:@[^\s]+)?|bunx\s+vercel(?:@[^\s]+)?)`;
3149
+ .raw `(?:vercel|deno\s+run\s+-A\s+npm:vercel(?:@[^\s]+)?|pnpm\s+(?:dlx|exec)\s+vercel(?:@[^\s]+)?|npx\s+vercel(?:@[^\s]+)?|yarn\s+(?:dlx\s+)?vercel(?:@[^\s]+)?|bunx\s+vercel(?:@[^\s]+)?)`;
2988
3150
  const globalFlags = String
2989
3151
  .raw `(?:\s+(?:--[A-Za-z-]+(?:=(?:"[^"]+"|'[^']+'|[^\s]+)|\s+(?:"[^"]+"|'[^']+'|[^\s]+))?|-[A-Za-z](?:\s+(?:"[^"]+"|'[^']+'|[^\s]+))?))*`;
2990
3152
  return new RegExp(String.raw `\b${launcher}${globalFlags}\s+${subcommand}\b`)
@@ -3946,10 +4108,13 @@ function dbScriptsTsconfigTemplate() {
3946
4108
  }
3947
4109
  `;
3948
4110
  }
3949
- function dbPgliteHarnessTemplate(config) {
4111
+ function dbPgliteHarnessTemplate(config, testRunner = "vitest") {
3950
4112
  const schemaImportPath = toRelativeImportPath(config.modules.pgliteHarnessModule, join(config.dirs.schemaDir, "index.ts"));
4113
+ const afterAllImport = testRunner === "deno"
4114
+ ? 'import { afterAll } from "jsr:@std/testing@^1.0.19/bdd";'
4115
+ : 'import { afterAll } from "vitest";';
3951
4116
  return `import { createMemoryPgliteHarness } from "@gadicc/loom/db/testing";
3952
- import { afterAll } from "vitest";
4117
+ ${afterAllImport}
3953
4118
  import * as schema from "${schemaImportPath}";
3954
4119
 
3955
4120
  const harness = await createMemoryPgliteHarness({
@@ -3970,6 +4135,14 @@ afterAll(closeMemoryPglite);
3970
4135
  export const { client, db, tableLoader } = harness;
3971
4136
  `;
3972
4137
  }
4138
+ async function getDbTestRunner(cwd, tooling) {
4139
+ if (tooling.tasks.runner !== "deno")
4140
+ return "vitest";
4141
+ const taskStore = await readTaskStore(cwd, tooling.tasks);
4142
+ return /\bvitest\b/.test(getTaskCommand(taskStore.definitions.test) ?? "")
4143
+ ? "vitest"
4144
+ : "deno";
4145
+ }
3973
4146
  function dbFixturesScriptTemplate(config) {
3974
4147
  const schemaImportPath = toRelativeImportPath(config.modules.fixtureDumpScript, join(config.dirs.schemaDir, "index.ts"));
3975
4148
  const neonImportPath = toRelativeImportPath(config.modules.fixtureDumpScript, config.modules.neonModule);
@@ -5008,14 +5181,11 @@ async function materializeManagedSchema(cwd, schema, dbConfig) {
5008
5181
  };
5009
5182
  }
5010
5183
  async function readProjectPackageJson(cwd) {
5011
- const packageJsonPath = join(cwd, "package.json");
5012
- const packageJsonText = await readTextIfExists(packageJsonPath);
5013
- if (!packageJsonText) {
5014
- throw new Error(`No package.json found in ${cwd}`);
5015
- }
5184
+ const metadata = await readProjectPackageMetadata(cwd);
5016
5185
  return {
5017
- packageJson: parseJson(packageJsonText, "package.json"),
5018
- packageJsonPath,
5186
+ packageJson: metadata.packageJson,
5187
+ packageJsonPath: metadata.path,
5188
+ projectConfig: metadata.config,
5019
5189
  };
5020
5190
  }
5021
5191
  async function resolveDbProjectConfig(cwd) {
@@ -5104,7 +5274,8 @@ export async function syncDbSchemas(cwd) {
5104
5274
  changedFiles.push("loom.json");
5105
5275
  }
5106
5276
  if (changedFiles.length) {
5107
- notes.push("No migrations were generated. Review the schema diff, then run `pnpm db:generate` if the schema changed.");
5277
+ const tooling = await getProjectTooling(cwd, manifest);
5278
+ notes.push(`No migrations were generated. Review the schema diff, then run ${formatTaskInvocation(tooling.tasks, "db:generate")} if the schema changed.`);
5108
5279
  }
5109
5280
  return {
5110
5281
  changedFiles: [...new Set(changedFiles)],
@@ -5445,7 +5616,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
5445
5616
  if (options.localProvider === "r2" && !options.localBucket) {
5446
5617
  throw new Error("--local-provider r2 requires an explicit --local-bucket.");
5447
5618
  }
5448
- const { packageJson, packageJsonPath } = await readProjectPackageJson(cwd);
5619
+ const { packageJson } = await readProjectPackageJson(cwd);
5449
5620
  const framework = await detectFramework(cwd, packageJson);
5450
5621
  const manifestPath = join(cwd, "loom.json");
5451
5622
  const manifestText = await readTextIfExists(manifestPath);
@@ -5453,6 +5624,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
5453
5624
  throw new Error("Missing loom.json. Run `loom add files` first.");
5454
5625
  }
5455
5626
  const manifest = parseJson(manifestText, "loom.json");
5627
+ const tooling = await getProjectTooling(cwd, manifest);
5456
5628
  const feature = manifest.features.files;
5457
5629
  if (!feature || feature.status !== "active") {
5458
5630
  throw new Error("The files feature is not active. Run `loom add files` first.");
@@ -5610,11 +5782,10 @@ export async function setupCloudflareR2(cwd, options = {}) {
5610
5782
  throw new Error(`R2 bucket \`${bucket}\` exists, but Loom could not verify its private-access policy: ${privacy.detail}. Rerun after Wrangler can inspect public URL and custom-domain settings.`);
5611
5783
  }
5612
5784
  }
5613
- const dependencyUpdate = ensurePackageJsonDependencies(packageJson, "dependencies", FILES_S3_DEPENDENCIES);
5785
+ const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, { dependencies: FILES_S3_DEPENDENCIES });
5614
5786
  if (dependencyUpdate.changed) {
5615
- await writeFile(packageJsonPath, stringifyJson(dependencyUpdate.packageJson), "utf8");
5616
- changedFiles.push("package.json");
5617
- notes.push(`Added files storage dependency: ${dependencyUpdate.changedKeys.join(", ")}.`);
5787
+ changedFiles.push(dependencyUpdate.config);
5788
+ notes.push(`Added files storage dependency: ${dependencyUpdate.changedKeys.join(", ")} to ${dependencyUpdate.config}.`);
5618
5789
  }
5619
5790
  const storagePath = join(cwd, config.modules.storageModule);
5620
5791
  const storageText = await readTextIfExists(storagePath);
@@ -7067,26 +7238,21 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
7067
7238
  ? structuredClone(currentFeature)
7068
7239
  : { status: "planned" };
7069
7240
  const config = mergeJobsConfig(framework, feature.config);
7070
- const { packageJsonPath, packageJson } = await readProjectPackageJson(cwd);
7071
- let nextPackageJson = packageJson;
7072
- const dependencyUpdate = ensurePackageJsonDependencies(nextPackageJson, "dependencies", JOBS_DEFAULT_DEPENDENCIES);
7073
- nextPackageJson = dependencyUpdate.packageJson;
7074
- const devDependencyUpdate = ensurePackageJsonDependencies(nextPackageJson, "devDependencies", JOBS_DEFAULT_DEV_DEPENDENCIES);
7075
- nextPackageJson = devDependencyUpdate.packageJson;
7076
- const scriptsUpdate = ensurePackageJsonScripts(nextPackageJson, getJobsExpectedScripts(config));
7077
- nextPackageJson = scriptsUpdate.packageJson;
7078
- if (dependencyUpdate.changed || devDependencyUpdate.changed ||
7079
- scriptsUpdate.changed) {
7080
- await writeFile(packageJsonPath, stringifyJson(nextPackageJson), "utf8");
7081
- changedFiles.push("package.json");
7082
- }
7083
- if (dependencyUpdate.changedKeys.length ||
7084
- devDependencyUpdate.changedKeys.length) {
7085
- notes.push(`Added jobs package.json dependencies: ${[...dependencyUpdate.changedKeys, ...devDependencyUpdate.changedKeys]
7086
- .join(", ")}`);
7241
+ const tooling = await getProjectTooling(cwd, manifest);
7242
+ const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
7243
+ dependencies: JOBS_DEFAULT_DEPENDENCIES,
7244
+ devDependencies: JOBS_DEFAULT_DEV_DEPENDENCIES,
7245
+ });
7246
+ const scriptsUpdate = await ensureProjectTasks(cwd, manifest, getJobsExpectedScripts(config));
7247
+ if (dependencyUpdate.changed)
7248
+ changedFiles.push(dependencyUpdate.config);
7249
+ if (scriptsUpdate.changedKeys.length)
7250
+ changedFiles.push(scriptsUpdate.config);
7251
+ if (dependencyUpdate.changedKeys.length) {
7252
+ notes.push(`Added jobs dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
7087
7253
  }
7088
7254
  if (scriptsUpdate.changedKeys.length) {
7089
- notes.push(`Updated jobs package.json scripts: ${scriptsUpdate.changedKeys.join(", ")}`);
7255
+ notes.push(`Updated jobs tasks in ${scriptsUpdate.config}: ${scriptsUpdate.changedKeys.join(", ")}`);
7090
7256
  }
7091
7257
  if (activate && feature.status !== "active") {
7092
7258
  feature.status = "active";
@@ -7181,41 +7347,35 @@ async function applyDbFeature(cwd, framework, manifest, activate) {
7181
7347
  }
7182
7348
  feature.config = config;
7183
7349
  manifest.features.db = feature;
7184
- const { packageJsonPath, packageJson } = await readProjectPackageJson(cwd);
7185
- let nextPackageJson = packageJson;
7186
- let packageJsonChanged = false;
7187
- const dependencyUpdate = ensurePackageJsonDependencies(nextPackageJson, "dependencies", DB_DEFAULT_DEPENDENCIES);
7188
- nextPackageJson = dependencyUpdate.packageJson;
7189
- packageJsonChanged ||= dependencyUpdate.changed;
7190
- const devDependencyUpdate = ensurePackageJsonDependencies(nextPackageJson, "devDependencies", DB_DEFAULT_DEV_DEPENDENCIES);
7191
- nextPackageJson = devDependencyUpdate.packageJson;
7192
- packageJsonChanged ||= devDependencyUpdate.changed;
7193
- const scriptsUpdate = ensurePackageJsonScripts(nextPackageJson, getDbExpectedScripts(config));
7194
- nextPackageJson = scriptsUpdate.packageJson;
7195
- packageJsonChanged ||= scriptsUpdate.changed;
7196
- const removedDependencyUpdate = removePackageJsonDependencies(nextPackageJson, DB_MOVED_DEPENDENCIES);
7197
- nextPackageJson = removedDependencyUpdate.packageJson;
7198
- packageJsonChanged ||= removedDependencyUpdate.changed;
7199
- if (packageJsonChanged) {
7200
- await writeFile(packageJsonPath, stringifyJson(nextPackageJson), "utf8");
7201
- changedFiles.push("package.json");
7202
- }
7203
- if (dependencyUpdate.changedKeys.length ||
7204
- devDependencyUpdate.changedKeys.length) {
7205
- notes.push(`Added DB package.json dependencies: ${[...dependencyUpdate.changedKeys, ...devDependencyUpdate.changedKeys]
7206
- .join(", ")}`);
7350
+ const tooling = await getProjectTooling(cwd, manifest);
7351
+ const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
7352
+ dependencies: DB_DEFAULT_DEPENDENCIES,
7353
+ devDependencies: DB_DEFAULT_DEV_DEPENDENCIES,
7354
+ remove: DB_MOVED_DEPENDENCIES,
7355
+ });
7356
+ const scriptsUpdate = await ensureProjectTasks(cwd, manifest, getDbExpectedScripts(config, tooling));
7357
+ const testRunner = await getDbTestRunner(cwd, tooling);
7358
+ if (dependencyUpdate.changed)
7359
+ changedFiles.push(dependencyUpdate.config);
7360
+ if (scriptsUpdate.changedKeys.length)
7361
+ changedFiles.push(scriptsUpdate.config);
7362
+ if (dependencyUpdate.changedKeys.length) {
7363
+ notes.push(`Added DB dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
7207
7364
  }
7208
7365
  if (scriptsUpdate.changedKeys.length) {
7209
- notes.push(`Updated DB package.json scripts: ${scriptsUpdate.changedKeys.join(", ")}`);
7366
+ notes.push(`Updated DB tasks in ${scriptsUpdate.config}: ${scriptsUpdate.changedKeys.join(", ")}`);
7210
7367
  }
7211
- if (removedDependencyUpdate.removedKeys.length) {
7212
- notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${removedDependencyUpdate.removedKeys.join(", ")}`);
7368
+ if (dependencyUpdate.removedKeys.length) {
7369
+ notes.push(`Removed consumer-managed DB generator dependencies now owned by Loom: ${dependencyUpdate.removedKeys.join(", ")}`);
7213
7370
  }
7214
7371
  const managedFiles = [
7215
7372
  [config.modules.neonModule, dbNeonTemplate()],
7216
7373
  [config.modules.neonFullModule, dbNeonFullTemplate()],
7217
7374
  [config.modules.drizzleConfig, dbDrizzleConfigTemplate(config)],
7218
- [config.modules.pgliteHarnessModule, dbPgliteHarnessTemplate(config)],
7375
+ [
7376
+ config.modules.pgliteHarnessModule,
7377
+ dbPgliteHarnessTemplate(config, testRunner),
7378
+ ],
7219
7379
  [config.modules.scriptsTsconfig, dbScriptsTsconfigTemplate()],
7220
7380
  [
7221
7381
  config.modules.refinementsCommonModule,
@@ -7285,7 +7445,8 @@ async function applyFilesFeature(cwd, framework, manifest, activate) {
7285
7445
  changedFiles.push(...materialized.changedFiles);
7286
7446
  notes.push(...materialized.notes);
7287
7447
  config.schema = materialized.schema;
7288
- notes.push("No migration was generated. Review the schema diff, then run `pnpm db:generate` when you are ready to create the app-local migration.");
7448
+ const tooling = await getProjectTooling(cwd, manifest);
7449
+ notes.push(`No migration was generated. Review the schema diff, then run ${formatTaskInvocation(tooling.tasks, "db:generate")} when you are ready to create the app-local migration.`);
7289
7450
  }
7290
7451
  const scaffoldFiles = [
7291
7452
  [
@@ -7541,12 +7702,246 @@ async function applyAuthFeature(cwd, framework, manifest, activate) {
7541
7702
  }
7542
7703
  return { changedFiles, notes };
7543
7704
  }
7705
+ function linguiCliCommand(tooling) {
7706
+ switch (tooling.dependencies.manager) {
7707
+ case "deno":
7708
+ return "deno run -A npm:@lingui/cli";
7709
+ case "npm":
7710
+ return "npx lingui";
7711
+ case "pnpm":
7712
+ return "pnpm lingui";
7713
+ case "yarn":
7714
+ return "yarn lingui";
7715
+ }
7716
+ }
7717
+ function linguiConfigTemplate(framework) {
7718
+ const sourceRoot = framework.srcDir ? "src/" : "";
7719
+ return `import { formatter } from "@lingui/format-po";
7720
+
7721
+ /** @type {import("@lingui/conf").LinguiConfig} */
7722
+ export default {
7723
+ locales: ["en"],
7724
+ sourceLocale: "en",
7725
+ catalogs: [
7726
+ {
7727
+ path: "<rootDir>/${sourceRoot}locales/{locale}/messages",
7728
+ include: ["<rootDir>/${sourceRoot}**/*.{ts,tsx}"],
7729
+ },
7730
+ ],
7731
+ format: formatter({ lineNumbers: false }),
7732
+ };
7733
+ `;
7734
+ }
7735
+ function generatedLinguiCatalogsFromConfig(configText, framework) {
7736
+ const paths = [...configText.matchAll(/\bpath\s*:\s*["'`]([^"'`]+)["'`]/g)]
7737
+ .map((match) => match[1])
7738
+ .filter((path) => Boolean(path))
7739
+ .map((path) => path
7740
+ .replace(/^<rootDir>\//, "")
7741
+ .replaceAll("{locale}", "*")
7742
+ .replaceAll("{name}", "*")
7743
+ .replaceAll("\\", "/")
7744
+ .replace(/\.(?:js|po)$/, "") + ".js");
7745
+ return [
7746
+ ...new Set(paths.length
7747
+ ? paths
7748
+ : [`${framework.srcDir ? "src/" : ""}locales/*/messages.js`]),
7749
+ ];
7750
+ }
7751
+ async function findLinguiConfigPath(cwd) {
7752
+ return await findFirstExistingRelativePath(cwd, [
7753
+ ...LINGUI_CONFIG_CANDIDATES,
7754
+ ]);
7755
+ }
7756
+ async function findSourceFilesMatching(cwd, pattern, relativeDir = "") {
7757
+ const results = [];
7758
+ let entries;
7759
+ try {
7760
+ entries = await readdir(join(cwd, relativeDir), { withFileTypes: true });
7761
+ }
7762
+ catch (error) {
7763
+ if (isNodeErrorCode(error, "ENOENT"))
7764
+ return results;
7765
+ throw error;
7766
+ }
7767
+ for (const entry of entries) {
7768
+ const relativePath = relativeDir
7769
+ ? join(relativeDir, entry.name)
7770
+ : entry.name;
7771
+ if (entry.isDirectory()) {
7772
+ if (!ENV_LOADER_SCAN_IGNORED_DIRS.has(entry.name)) {
7773
+ results.push(...await findSourceFilesMatching(cwd, pattern, relativePath));
7774
+ }
7775
+ continue;
7776
+ }
7777
+ if (!entry.isFile() || !hasScannedSourceExtension(entry.name))
7778
+ continue;
7779
+ const text = await readTextIfExists(join(cwd, relativePath));
7780
+ pattern.lastIndex = 0;
7781
+ if (text && pattern.test(text)) {
7782
+ results.push(relativePath.replaceAll("\\", "/"));
7783
+ }
7784
+ }
7785
+ return results.sort();
7786
+ }
7787
+ async function detectLinguiCatalogMode(cwd) {
7788
+ const poImports = await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']+\.po["']/);
7789
+ if (poImports.length)
7790
+ return "loader";
7791
+ const nextConfigPath = await findNextConfigPath(cwd);
7792
+ const nextConfigText = nextConfigPath
7793
+ ? await readTextIfExists(join(cwd, nextConfigPath))
7794
+ : null;
7795
+ return nextConfigText?.includes("@lingui/loader") ? "loader" : "precompile";
7796
+ }
7797
+ async function getLinguiConfig(cwd, framework, currentConfig) {
7798
+ const configFile = currentConfig?.configFile ??
7799
+ await findLinguiConfigPath(cwd) ?? "lingui.config.ts";
7800
+ const configText = await readTextIfExists(join(cwd, configFile)) ??
7801
+ linguiConfigTemplate(framework);
7802
+ return {
7803
+ catalogMode: currentConfig?.catalogMode ??
7804
+ await detectLinguiCatalogMode(cwd),
7805
+ configFile,
7806
+ generatedCatalogs: currentConfig?.generatedCatalogs?.length
7807
+ ? [...new Set(currentConfig.generatedCatalogs)]
7808
+ : generatedLinguiCatalogsFromConfig(configText, framework),
7809
+ tasks: {
7810
+ ...LINGUI_DEFAULT_TASKS,
7811
+ ...currentConfig?.tasks,
7812
+ },
7813
+ };
7814
+ }
7815
+ function linguiTaskRuns(command, action) {
7816
+ return Boolean(command?.includes("lingui") &&
7817
+ new RegExp(`(?:^|\\s)${action}(?:\\s|$)`).test(command));
7818
+ }
7819
+ function dependencyMajor(spec) {
7820
+ const match = spec?.match(/(?:^|[^0-9])(\d+)\./);
7821
+ return match ? Number(match[1]) : null;
7822
+ }
7823
+ function linguiPoDeclarationTemplate() {
7824
+ return `declare module "*.po" {
7825
+ import type { Messages } from "@lingui/core";
7826
+
7827
+ export const messages: Messages;
7828
+ }
7829
+ `;
7830
+ }
7831
+ async function applyLinguiFeature(cwd, framework, manifest, activate) {
7832
+ const changedFiles = [];
7833
+ const notes = [];
7834
+ const currentFeature = manifest.features.lingui;
7835
+ const config = await getLinguiConfig(cwd, framework, currentFeature?.config);
7836
+ const feature = currentFeature
7837
+ ? structuredClone(currentFeature)
7838
+ : { status: "planned" };
7839
+ if (activate && feature.status !== "active") {
7840
+ feature.status = "active";
7841
+ feature.activatedOn ??= todayIso();
7842
+ }
7843
+ feature.config = config;
7844
+ manifest.features.lingui = feature;
7845
+ const { packageJson } = await readProjectPackageJson(cwd);
7846
+ const tooling = await getProjectTooling(cwd, manifest);
7847
+ const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
7848
+ dependencies: LINGUI_DEFAULT_DEPENDENCIES,
7849
+ devDependencies: {
7850
+ ...LINGUI_DEFAULT_DEV_DEPENDENCIES,
7851
+ ...(config.catalogMode === "loader"
7852
+ ? LINGUI_LOADER_DEV_DEPENDENCIES
7853
+ : {}),
7854
+ },
7855
+ });
7856
+ if (dependencyUpdate.changed)
7857
+ changedFiles.push(dependencyUpdate.config);
7858
+ const configState = await scaffoldTextFile(join(cwd, config.configFile), linguiConfigTemplate(framework));
7859
+ if (configState === "created") {
7860
+ changedFiles.push(config.configFile);
7861
+ notes.push(`Scaffolded ${config.configFile} with an English starter locale; update its locales and catalog include paths for the app.`);
7862
+ }
7863
+ else if (activate && configState === "preserved") {
7864
+ notes.push(`Preserved existing Lingui config: ${config.configFile}`);
7865
+ }
7866
+ const taskChanges = [];
7867
+ const executable = linguiCliCommand(tooling);
7868
+ for (const [name, command] of [
7869
+ [config.tasks.extract, `${executable} extract --clean`],
7870
+ [config.tasks.compile, `${executable} compile`],
7871
+ ]) {
7872
+ const result = await ensureTask(cwd, tooling.tasks, {
7873
+ definition: command,
7874
+ name,
7875
+ });
7876
+ if (result.changed)
7877
+ taskChanges.push(name);
7878
+ }
7879
+ let taskStore = await readTaskStore(cwd, tooling.tasks);
7880
+ if (!getTaskCommand(taskStore.definitions[config.tasks.build])) {
7881
+ const result = await ensureTask(cwd, tooling.tasks, {
7882
+ definition: framework.kind === "nextjs" ? "next build" : "build",
7883
+ name: config.tasks.build,
7884
+ });
7885
+ if (result.changed)
7886
+ taskChanges.push(config.tasks.build);
7887
+ taskStore = await readTaskStore(cwd, tooling.tasks);
7888
+ }
7889
+ const buildCommand = getTaskCommand(taskStore.definitions[config.tasks.build]);
7890
+ if (config.catalogMode === "precompile" && buildCommand &&
7891
+ !taskInvokes(taskStore, config.tasks.build, config.tasks.compile)) {
7892
+ const result = await ensureTaskPrerequisite(cwd, tooling.tasks, config.tasks.build, config.tasks.compile);
7893
+ if (result.changed)
7894
+ taskChanges.push(config.tasks.build);
7895
+ }
7896
+ if (taskChanges.length)
7897
+ changedFiles.push(tooling.tasks.config);
7898
+ const gitignorePath = join(cwd, ".gitignore");
7899
+ const gitignoreUpdate = ensureLinguiGitignoreText(await readTextIfExists(gitignorePath), config.generatedCatalogs);
7900
+ if (gitignoreUpdate.changed) {
7901
+ await writeFile(gitignorePath, gitignoreUpdate.text, "utf8");
7902
+ changedFiles.push(".gitignore");
7903
+ }
7904
+ if (config.catalogMode === "loader") {
7905
+ const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
7906
+ if (!poDeclarations.length) {
7907
+ const declarationPath = `${framework.srcDir ? "src/" : ""}lingui.d.ts`;
7908
+ if (await writeTextIfChanged(join(cwd, declarationPath), linguiPoDeclarationTemplate())) {
7909
+ changedFiles.push(declarationPath);
7910
+ }
7911
+ }
7912
+ }
7913
+ if (framework.kind === "nextjs") {
7914
+ const nextConfigPath = await findNextConfigPath(cwd);
7915
+ const nextConfigText = nextConfigPath
7916
+ ? await readTextIfExists(join(cwd, nextConfigPath))
7917
+ : null;
7918
+ if (!nextConfigText?.includes("@lingui/swc-plugin")) {
7919
+ notes.push("Add @lingui/swc-plugin to experimental.swcPlugins in the app-owned Next config.");
7920
+ }
7921
+ if (config.catalogMode === "loader" &&
7922
+ !nextConfigText?.includes("@lingui/loader")) {
7923
+ notes.push("Add @lingui/loader .po rules for Turbopack and webpack in the app-owned Next config.");
7924
+ }
7925
+ }
7926
+ if (dependencyUpdate.changedKeys.length) {
7927
+ notes.push(`Added Lingui dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
7928
+ }
7929
+ if (taskChanges.length) {
7930
+ notes.push(`Updated Lingui tasks in ${tooling.tasks.config}: ${[...new Set(taskChanges)].join(", ")}`);
7931
+ }
7932
+ if (packageJson.dependencies?.["@lingui/macro"] ||
7933
+ packageJson.devDependencies?.["@lingui/macro"]) {
7934
+ notes.push("The legacy @lingui/macro package remains app-owned; migrate imports to the v6 macro entrypoints before removing it.");
7935
+ }
7936
+ return { changedFiles, notes };
7937
+ }
7544
7938
  async function applyPwaFeature(cwd, framework, manifest, activate) {
7545
7939
  const changedFiles = [];
7546
7940
  const notes = [];
7547
7941
  const currentFeature = manifest.features.pwa;
7548
7942
  const currentConfig = currentFeature?.config;
7549
- const { packageJsonPath, packageJson } = await readProjectPackageJson(cwd);
7943
+ const { packageJson } = await readProjectPackageJson(cwd);
7944
+ const tooling = await getProjectTooling(cwd, manifest);
7550
7945
  const config = await getPwaConfig(cwd, framework, packageJson, currentConfig, activate);
7551
7946
  const feature = currentFeature
7552
7947
  ? structuredClone(currentFeature)
@@ -7557,31 +7952,48 @@ async function applyPwaFeature(cwd, framework, manifest, activate) {
7557
7952
  }
7558
7953
  feature.config = config;
7559
7954
  manifest.features.pwa = feature;
7560
- let nextPackageJson = packageJson;
7561
- let packageJsonChanged = false;
7562
- const dependencyUpdate = ensurePackageJsonDependencies(nextPackageJson, "dependencies", PWA_DEFAULT_DEPENDENCIES);
7563
- nextPackageJson = dependencyUpdate.packageJson;
7564
- packageJsonChanged ||= dependencyUpdate.changed;
7565
- const devDependencyUpdate = ensurePackageJsonDependencies(nextPackageJson, "devDependencies", PWA_DEFAULT_DEV_DEPENDENCIES);
7566
- nextPackageJson = devDependencyUpdate.packageJson;
7567
- packageJsonChanged ||= devDependencyUpdate.changed;
7568
- const packageManager = await detectPackageManager(cwd, nextPackageJson);
7569
- const scriptsUpdate = ensurePwaPackageJsonScripts(nextPackageJson, packageManager);
7570
- nextPackageJson = scriptsUpdate.packageJson;
7571
- packageJsonChanged ||= scriptsUpdate.changed;
7572
- if (packageJsonChanged) {
7573
- await writeFile(packageJsonPath, stringifyJson(nextPackageJson), "utf8");
7574
- changedFiles.push("package.json");
7575
- }
7576
- if (dependencyUpdate.changedKeys.length ||
7577
- devDependencyUpdate.changedKeys.length) {
7578
- notes.push(`Added PWA package.json dependencies: ${[...dependencyUpdate.changedKeys, ...devDependencyUpdate.changedKeys]
7579
- .join(", ")}`);
7955
+ const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
7956
+ dependencies: PWA_DEFAULT_DEPENDENCIES,
7957
+ devDependencies: PWA_DEFAULT_DEV_DEPENDENCIES,
7958
+ });
7959
+ if (dependencyUpdate.changed)
7960
+ changedFiles.push(dependencyUpdate.config);
7961
+ const scriptsChanged = [];
7962
+ const pwaTask = await ensureTask(cwd, tooling.tasks, {
7963
+ definition: PWA_BUILD_SCRIPT,
7964
+ name: "pwa:build",
7965
+ });
7966
+ if (pwaTask.changed)
7967
+ scriptsChanged.push("pwa:build");
7968
+ const taskStore = await readTaskStore(cwd, tooling.tasks);
7969
+ const buildCommand = getTaskCommand(taskStore.definitions.build);
7970
+ if (!buildCommand) {
7971
+ const build = await ensureTask(cwd, tooling.tasks, {
7972
+ definition: `next build && ${formatTaskInvocation(tooling.tasks, "pwa:build")}`,
7973
+ name: "build",
7974
+ });
7975
+ if (build.changed)
7976
+ scriptsChanged.push("build");
7580
7977
  }
7581
- if (scriptsUpdate.changedKeys.length) {
7582
- notes.push(`Updated PWA package.json scripts: ${scriptsUpdate.changedKeys.join(", ")}`);
7978
+ else if (buildCommand.includes("next build") &&
7979
+ !taskInvokes(taskStore, "build", "pwa:build") &&
7980
+ !scriptRunsSerwistBuild(buildCommand)) {
7981
+ const build = await ensureTaskFollowup(cwd, tooling.tasks, "build", "pwa:build");
7982
+ if (build.changed)
7983
+ scriptsChanged.push("build");
7984
+ }
7985
+ else if (!taskInvokes(taskStore, "build", "pwa:build") &&
7986
+ !scriptRunsSerwistBuild(buildCommand)) {
7987
+ notes.push("PWA build task was added, but the existing build task does not visibly run `next build`; wire `pwa:build` after the app's Next.js build step.");
7988
+ }
7989
+ if (scriptsChanged.length)
7990
+ changedFiles.push(tooling.tasks.config);
7991
+ if (dependencyUpdate.changedKeys.length) {
7992
+ notes.push(`Added PWA dependencies to ${dependencyUpdate.config}: ${dependencyUpdate.changedKeys.join(", ")}`);
7993
+ }
7994
+ if (scriptsChanged.length) {
7995
+ notes.push(`Updated PWA tasks in ${tooling.tasks.config}: ${scriptsChanged.join(", ")}`);
7583
7996
  }
7584
- notes.push(...scriptsUpdate.notes);
7585
7997
  const serwistConfigState = await scaffoldTextFile(join(cwd, config.modules.serwistConfig), pwaSerwistConfigTemplate(config));
7586
7998
  if (serwistConfigState === "created") {
7587
7999
  changedFiles.push(config.modules.serwistConfig);
@@ -7635,13 +8047,13 @@ async function checkJobsFeature(cwd, framework, manifest) {
7635
8047
  return { issues, suggestions: [], warnings: [] };
7636
8048
  }
7637
8049
  const config = mergeJobsConfig(framework, feature.config);
7638
- const { packageJson } = await readProjectPackageJson(cwd);
7639
8050
  const expectedScripts = getJobsExpectedScripts(config);
7640
- for (const [scriptName, scriptCommand] of Object.entries(expectedScripts)) {
7641
- if (packageJson.scripts?.[scriptName] !== scriptCommand) {
7642
- issues.push(`Jobs package.json script does not match Loom defaults: ${scriptName}`);
7643
- suggestions.add("Run `loom add jobs`.");
7644
- }
8051
+ const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
8052
+ for (const taskName of taskCheck.mismatches) {
8053
+ issues.push(taskCheck.config === "package.json"
8054
+ ? `Jobs package.json script does not match Loom defaults: ${taskName}`
8055
+ : `Jobs task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
8056
+ suggestions.add("Run `loom add jobs`.");
7645
8057
  }
7646
8058
  const requiredFiles = [
7647
8059
  JOBS_SCRIPTS_TSCONFIG_PATH,
@@ -7798,7 +8210,9 @@ async function checkDbFeature(cwd, framework, manifest, options) {
7798
8210
  }
7799
8211
  const config = mergeDbConfig(framework, feature.config);
7800
8212
  const { packageJson } = await readProjectPackageJson(cwd);
7801
- const expectedScripts = getDbExpectedScripts(config);
8213
+ const tooling = await getProjectTooling(cwd, manifest);
8214
+ const testRunner = await getDbTestRunner(cwd, tooling);
8215
+ const expectedScripts = getDbExpectedScripts(config, tooling);
7802
8216
  const migrationFlowCheck = await checkDbProductionMigrationFlow(cwd, options.production ?? false);
7803
8217
  issues.push(...migrationFlowCheck.issues);
7804
8218
  warnings.push(...migrationFlowCheck.warnings);
@@ -7806,29 +8220,36 @@ async function checkDbFeature(cwd, framework, manifest, options) {
7806
8220
  suggestions.add(suggestion);
7807
8221
  }
7808
8222
  for (const dependencyName of Object.keys(DB_DEFAULT_DEPENDENCIES)) {
7809
- if (!packageJson.dependencies?.[dependencyName]) {
7810
- issues.push(`DB dependency is missing from package.json dependencies: ${dependencyName}`);
8223
+ if (!hasPackageDependency(packageJson, dependencyName)) {
8224
+ issues.push(tooling.dependencies.config === "package.json"
8225
+ ? `DB dependency is missing from package.json dependencies: ${dependencyName}`
8226
+ : `DB dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
7811
8227
  suggestions.add("Run `loom add db`.");
7812
8228
  }
7813
8229
  }
7814
8230
  for (const dependencyName of Object.keys(DB_DEFAULT_DEV_DEPENDENCIES)) {
7815
- if (!packageJson.devDependencies?.[dependencyName]) {
7816
- issues.push(`DB dependency is missing from package.json devDependencies: ${dependencyName}`);
8231
+ if (!hasPackageDependency(packageJson, dependencyName)) {
8232
+ issues.push(tooling.dependencies.config === "package.json"
8233
+ ? `DB dependency is missing from package.json devDependencies: ${dependencyName}`
8234
+ : `DB development dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
7817
8235
  suggestions.add("Run `loom add db`.");
7818
8236
  }
7819
8237
  }
7820
8238
  for (const dependencyName of DB_MOVED_DEPENDENCIES) {
7821
8239
  if (packageJson.dependencies?.[dependencyName] ||
7822
8240
  packageJson.devDependencies?.[dependencyName]) {
7823
- issues.push(`Consumer package.json still declares a Loom-managed DB generator dependency: ${dependencyName}`);
7824
- suggestions.add("Run `loom add db` to rewrite package.json.");
8241
+ issues.push(tooling.dependencies.config === "package.json"
8242
+ ? `Consumer package.json still declares a Loom-managed DB generator dependency: ${dependencyName}`
8243
+ : `Consumer ${tooling.dependencies.config} still declares a Loom-managed DB generator dependency: ${dependencyName}`);
8244
+ suggestions.add(`Run loom add db to rewrite ${tooling.dependencies.config}.`);
7825
8245
  }
7826
8246
  }
7827
- for (const [scriptName, scriptCommand] of Object.entries(expectedScripts)) {
7828
- if (packageJson.scripts?.[scriptName] !== scriptCommand) {
7829
- issues.push(`DB package.json script does not match Loom defaults: ${scriptName}`);
7830
- suggestions.add("Run `loom add db`.");
7831
- }
8247
+ const taskCheck = await checkProjectTasks(cwd, manifest, expectedScripts);
8248
+ for (const taskName of taskCheck.mismatches) {
8249
+ issues.push(taskCheck.config === "package.json"
8250
+ ? `DB package.json script does not match Loom defaults: ${taskName}`
8251
+ : `DB task in ${taskCheck.config} does not match Loom defaults: ${taskName}`);
8252
+ suggestions.add("Run `loom add db`.");
7832
8253
  }
7833
8254
  const requiredFiles = [
7834
8255
  config.modules.neonModule,
@@ -7864,7 +8285,7 @@ async function checkDbFeature(cwd, framework, manifest, options) {
7864
8285
  ],
7865
8286
  [
7866
8287
  config.modules.pgliteHarnessModule,
7867
- dbPgliteHarnessTemplate(config),
8288
+ dbPgliteHarnessTemplate(config, testRunner),
7868
8289
  "PGlite test harness does not match the Loom-managed wrapper",
7869
8290
  ],
7870
8291
  [
@@ -7955,6 +8376,8 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
7955
8376
  const dbConfig = mergeDbConfig(framework, dbFeature.config);
7956
8377
  const config = getFilesConfig(framework, dbConfig, feature.config);
7957
8378
  const { packageJson } = await readProjectPackageJson(cwd);
8379
+ const tooling = await getProjectTooling(cwd, manifest);
8380
+ const generateCommand = formatTaskInvocation(tooling.tasks, "db:generate");
7958
8381
  const schema = config.schema;
7959
8382
  const latestSchema = getLatestManagedSchemaConfig(schema);
7960
8383
  if (schema.mode !== "managed-local" || schema.blueprint !== "files") {
@@ -7968,7 +8391,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
7968
8391
  }
7969
8392
  else if (schema.version < supportedVersion) {
7970
8393
  warnings.push(`Files schema blueprint is stale: ${schema.version} < ${supportedVersion}.`);
7971
- suggestions.add("Run `loom db schemas sync`, review the schema diff, then run `pnpm db:generate` if the schema changed.");
8394
+ suggestions.add(`Run loom db schemas sync, review the schema diff, then run ${generateCommand} if the schema changed.`);
7972
8395
  }
7973
8396
  const schemaRelativeToDir = relative(dbConfig.dirs.schemaDir, schema.module)
7974
8397
  .replaceAll("\\", "/");
@@ -7983,7 +8406,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
7983
8406
  const schemaText = await readTextIfExists(join(cwd, schema.module));
7984
8407
  if (!schemaText) {
7985
8408
  issues.push(`Files schema file is missing: ${schema.module}`);
7986
- suggestions.add("Run `loom db schemas sync`, review the schema diff, then run `pnpm db:generate` if the schema changed.");
8409
+ suggestions.add(`Run loom db schemas sync, review the schema diff, then run ${generateCommand} if the schema changed.`);
7987
8410
  }
7988
8411
  else {
7989
8412
  const currentHash = hashManagedSchemaText(schemaText);
@@ -8099,8 +8522,8 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
8099
8522
  suggestions.add("Replace the generated files storage stub with an S3 or app-specific storage adapter before production use.");
8100
8523
  }
8101
8524
  if (config.storage.adapter === "s3") {
8102
- if (!packageJson.dependencies?.["@aws-sdk/client-s3"]) {
8103
- issues.push("Files S3/R2 storage requires @aws-sdk/client-s3 in package.json dependencies.");
8525
+ if (!hasPackageDependency(packageJson, "@aws-sdk/client-s3")) {
8526
+ issues.push(`Files S3/R2 storage requires @aws-sdk/client-s3 in ${tooling.dependencies.config}.`);
8104
8527
  suggestions.add("Run `loom files r2 setup` to restore the dependency.");
8105
8528
  }
8106
8529
  for (const envName of FILES_S3_REQUIRED_ENV_NAMES) {
@@ -8584,6 +9007,125 @@ async function findNextConfigPath(cwd) {
8584
9007
  ];
8585
9008
  return await findFirstExistingRelativePath(cwd, candidates);
8586
9009
  }
9010
+ async function checkLinguiFeature(cwd, framework, manifest, options) {
9011
+ const issues = [];
9012
+ const suggestions = new Set();
9013
+ const warnings = [];
9014
+ const feature = manifest.features.lingui;
9015
+ if (!feature || feature.status !== "active") {
9016
+ return { issues, suggestions: [], warnings };
9017
+ }
9018
+ const { packageJson } = await readProjectPackageJson(cwd);
9019
+ const tooling = await getProjectTooling(cwd, manifest);
9020
+ const config = await getLinguiConfig(cwd, framework, feature.config);
9021
+ const requiredDependencies = {
9022
+ ...LINGUI_DEFAULT_DEPENDENCIES,
9023
+ ...LINGUI_DEFAULT_DEV_DEPENDENCIES,
9024
+ ...(config.catalogMode === "loader" ? LINGUI_LOADER_DEV_DEPENDENCIES : {}),
9025
+ };
9026
+ for (const dependencyName of Object.keys(requiredDependencies)) {
9027
+ if (!hasPackageDependency(packageJson, dependencyName)) {
9028
+ issues.push(`Lingui dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
9029
+ suggestions.add("Run `loom add lingui`.");
9030
+ }
9031
+ }
9032
+ if (!await exists(join(cwd, config.configFile))) {
9033
+ issues.push(`Lingui config is missing: ${config.configFile}`);
9034
+ suggestions.add("Run `loom add lingui`.");
9035
+ }
9036
+ const taskStore = await readTaskStore(cwd, tooling.tasks);
9037
+ if (!linguiTaskRuns(getTaskCommand(taskStore.definitions[config.tasks.extract]), "extract")) {
9038
+ issues.push(`Lingui extraction task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.extract}`);
9039
+ suggestions.add("Run `loom add lingui`.");
9040
+ }
9041
+ if (!linguiTaskRuns(getTaskCommand(taskStore.definitions[config.tasks.compile]), "compile")) {
9042
+ issues.push(`Lingui compile task is missing or invalid in ${tooling.tasks.config}: ${config.tasks.compile}`);
9043
+ suggestions.add("Run `loom add lingui`.");
9044
+ }
9045
+ if (config.catalogMode === "precompile") {
9046
+ if (!taskInvokes(taskStore, config.tasks.build, config.tasks.compile)) {
9047
+ issues.push(`Build task does not compile Lingui catalogs in ${tooling.tasks.config}: ${config.tasks.build}`);
9048
+ suggestions.add("Run `loom add lingui`.");
9049
+ }
9050
+ else {
9051
+ const buildCommand = getTaskCommand(taskStore.definitions[config.tasks.build]);
9052
+ if (buildCommand?.includes("next build") &&
9053
+ !taskRunsBeforeCommand(taskStore, config.tasks.build, config.tasks.compile, "next build")) {
9054
+ issues.push(`Lingui catalogs are compiled after Next.js starts building in ${tooling.tasks.config}: ${config.tasks.build}`);
9055
+ suggestions.add(`Run ${config.tasks.compile} before the framework build command.`);
9056
+ }
9057
+ }
9058
+ }
9059
+ const gitignoreUpdate = ensureLinguiGitignoreText(await readTextIfExists(join(cwd, ".gitignore")), config.generatedCatalogs);
9060
+ if (gitignoreUpdate.missingLines.length) {
9061
+ issues.push(`Lingui generated catalogs are missing from .gitignore: ${gitignoreUpdate.missingLines.join(", ")}`);
9062
+ suggestions.add("Run `loom add lingui`.");
9063
+ }
9064
+ const gitResult = await (options.commandRunner ?? defaultCommandRunner)("git", ["ls-files", "--", ...config.generatedCatalogs], { cwd, stdio: "pipe" });
9065
+ const trackedCatalogs = gitResult.code === 0
9066
+ ? gitResult.stdout.trim().split(/\r?\n/).filter(Boolean)
9067
+ : [];
9068
+ if (trackedCatalogs.length) {
9069
+ issues.push(`Lingui generated catalogs are still tracked by git: ${trackedCatalogs.join(", ")}`);
9070
+ suggestions.add("Remove generated catalogs from the git index while keeping the source .po catalogs tracked.");
9071
+ }
9072
+ const nextConfigPath = await findNextConfigPath(cwd);
9073
+ const nextConfigText = nextConfigPath
9074
+ ? await readTextIfExists(join(cwd, nextConfigPath))
9075
+ : null;
9076
+ if (framework.kind === "nextjs") {
9077
+ if (!nextConfigText?.includes("@lingui/swc-plugin")) {
9078
+ issues.push(`Next config is missing @lingui/swc-plugin${nextConfigPath ? `: ${nextConfigPath}` : "."}`);
9079
+ suggestions.add("Add @lingui/swc-plugin to experimental.swcPlugins in the Next config.");
9080
+ }
9081
+ if (config.catalogMode === "loader" &&
9082
+ !nextConfigText?.includes("@lingui/loader")) {
9083
+ issues.push(`Lingui loader mode is not wired in the Next config${nextConfigPath ? `: ${nextConfigPath}` : "."}`);
9084
+ suggestions.add("Add matching .po rules for Turbopack and webpack, or switch the manifest to precompile mode.");
9085
+ }
9086
+ if (nextConfigText && /\breactCompiler\s*:\s*true/.test(nextConfigText)) {
9087
+ warnings.push("Next.js React Compiler and the Lingui SWC plugin are both enabled; keep this combination covered by a production build test when upgrading either tool.");
9088
+ }
9089
+ }
9090
+ const poImports = await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']+\.po["']/);
9091
+ if (config.catalogMode === "precompile" && poImports.length) {
9092
+ issues.push(`Lingui is configured for precompile mode but source files import .po catalogs: ${poImports.join(", ")}`);
9093
+ suggestions.add("Switch loom.json to loader mode or import the generated .js catalogs.");
9094
+ }
9095
+ if (config.catalogMode === "loader" && !poImports.length) {
9096
+ warnings.push("Lingui is configured for loader mode, but no source .po imports were found.");
9097
+ }
9098
+ if (config.catalogMode === "loader") {
9099
+ const poDeclarations = await findSourceFilesMatching(cwd, /declare\s+module\s+["']\*\.po["']/);
9100
+ if (!poDeclarations.length) {
9101
+ issues.push("Lingui loader mode is missing a TypeScript *.po module declaration.");
9102
+ suggestions.add("Run `loom add lingui`.");
9103
+ }
9104
+ }
9105
+ const configImports = (await findSourceFilesMatching(cwd, /(?:from\s+|import\s*\()\s*["'][^"']*lingui\.config(?:\.[cm]?[jt]s)?["']/)).filter((relativePath) => relativePath !== config.configFile);
9106
+ if (configImports.length) {
9107
+ warnings.push(`Lingui config is imported by runtime source; keep config evaluation build-time only: ${configImports.join(", ")}`);
9108
+ }
9109
+ const linguiCoreMajor = dependencyMajor(packageJson.dependencies?.["@lingui/core"] ??
9110
+ packageJson.devDependencies?.["@lingui/core"]);
9111
+ const legacyMacroSpec = packageJson.dependencies?.["@lingui/macro"] ??
9112
+ packageJson.devDependencies?.["@lingui/macro"];
9113
+ if (legacyMacroSpec && linguiCoreMajor !== null &&
9114
+ dependencyMajor(legacyMacroSpec) !== linguiCoreMajor) {
9115
+ warnings.push(`Legacy @lingui/macro (${legacyMacroSpec}) does not match @lingui/core's major version; prefer @lingui/react/macro and @lingui/core/macro imports.`);
9116
+ }
9117
+ const linguiFamilyMajors = Object.keys(requiredDependencies).flatMap((dependencyName) => {
9118
+ const spec = packageJson.dependencies?.[dependencyName] ??
9119
+ packageJson.devDependencies?.[dependencyName];
9120
+ const major = dependencyMajor(spec);
9121
+ return major === null ? [] : [`${dependencyName}@${major}`];
9122
+ });
9123
+ if (new Set(linguiFamilyMajors.map((entry) => entry.split("@").at(-1))).size >
9124
+ 1) {
9125
+ warnings.push(`Lingui packages span multiple major versions: ${linguiFamilyMajors.join(", ")}`);
9126
+ }
9127
+ return { issues, suggestions: [...suggestions], warnings };
9128
+ }
8587
9129
  async function checkPwaFeature(cwd, framework, manifest) {
8588
9130
  const issues = [];
8589
9131
  const suggestions = new Set();
@@ -8593,6 +9135,7 @@ async function checkPwaFeature(cwd, framework, manifest) {
8593
9135
  return { issues, suggestions: [], warnings };
8594
9136
  }
8595
9137
  const { packageJson } = await readProjectPackageJson(cwd);
9138
+ const tooling = await getProjectTooling(cwd, manifest);
8596
9139
  const config = await getPwaConfig(cwd, framework, packageJson, feature.config, false);
8597
9140
  const hasMui = hasPackageDependency(packageJson, "@mui/material");
8598
9141
  if (framework.kind !== "nextjs" || framework.router !== "app") {
@@ -8600,23 +9143,25 @@ async function checkPwaFeature(cwd, framework, manifest) {
8600
9143
  suggestions.add("Update loom.json if this project intentionally uses a custom PWA integration.");
8601
9144
  }
8602
9145
  for (const dependencyName of Object.keys(PWA_DEFAULT_DEPENDENCIES)) {
8603
- if (!packageJson.dependencies?.[dependencyName]) {
8604
- issues.push(`PWA dependency is missing from package.json dependencies: ${dependencyName}`);
9146
+ if (!hasPackageDependency(packageJson, dependencyName)) {
9147
+ issues.push(`PWA dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
8605
9148
  suggestions.add("Run `loom add pwa`.");
8606
9149
  }
8607
9150
  }
8608
9151
  for (const dependencyName of Object.keys(PWA_DEFAULT_DEV_DEPENDENCIES)) {
8609
- if (!packageJson.devDependencies?.[dependencyName]) {
8610
- issues.push(`PWA dependency is missing from package.json devDependencies: ${dependencyName}`);
9152
+ if (!hasPackageDependency(packageJson, dependencyName)) {
9153
+ issues.push(`PWA development dependency is missing from ${tooling.dependencies.config}: ${dependencyName}`);
8611
9154
  suggestions.add("Run `loom add pwa`.");
8612
9155
  }
8613
9156
  }
8614
- if (!scriptRunsSerwistBuild(packageJson.scripts?.["pwa:build"])) {
8615
- issues.push("PWA package.json script does not build Serwist: pwa:build");
9157
+ const taskStore = await readTaskStore(cwd, tooling.tasks);
9158
+ if (!scriptRunsSerwistBuild(getTaskCommand(taskStore.definitions["pwa:build"]))) {
9159
+ issues.push(`PWA task in ${tooling.tasks.config} does not build Serwist: pwa:build`);
8616
9160
  suggestions.add("Run `loom add pwa`.");
8617
9161
  }
8618
- if (!scriptRunsSerwistBuild(packageJson.scripts?.build)) {
8619
- issues.push("PWA package.json build script does not run Serwist after the Next.js build.");
9162
+ if (!scriptRunsSerwistBuild(getTaskCommand(taskStore.definitions.build)) &&
9163
+ !taskInvokes(taskStore, "build", "pwa:build")) {
9164
+ issues.push(`PWA build task in ${tooling.tasks.config} does not run Serwist after the Next.js build.`);
8620
9165
  suggestions.add("Run `loom add pwa`.");
8621
9166
  }
8622
9167
  const gitignoreUpdate = ensurePwaGitignoreText(await readTextIfExists(join(cwd, ".gitignore")));
@@ -8797,6 +9342,10 @@ const featureHooks = {
8797
9342
  apply: applyJobsFeature,
8798
9343
  check: checkJobsFeature,
8799
9344
  },
9345
+ lingui: {
9346
+ apply: applyLinguiFeature,
9347
+ check: checkLinguiFeature,
9348
+ },
8800
9349
  mail: {
8801
9350
  apply: applyMailFeature,
8802
9351
  check: checkMailFeature,
@@ -8824,11 +9373,14 @@ async function ensureActiveFeatureScaffolds(cwd, framework, manifest) {
8824
9373
  export async function initProject(cwd, versionRange) {
8825
9374
  const changedFiles = [];
8826
9375
  const notes = [];
8827
- const packageJsonPath = join(cwd, "package.json");
8828
- const packageJsonText = await readTextIfExists(packageJsonPath);
8829
- if (!packageJsonText) {
8830
- throw new Error(`No package.json found in ${cwd}`);
8831
- }
9376
+ const loomManifestPath = join(cwd, "loom.json");
9377
+ const existingManifestText = await readTextIfExists(loomManifestPath);
9378
+ const existingManifest = existingManifestText
9379
+ ? parseJson(existingManifestText, "loom.json")
9380
+ : null;
9381
+ const tooling = await detectProjectTooling(cwd, existingManifest?.project?.tooling);
9382
+ const initialMetadata = await readProjectPackageMetadata(cwd);
9383
+ const initialPackageJson = initialMetadata.packageJson;
8832
9384
  const npmrcPath = join(cwd, ".npmrc");
8833
9385
  const npmrcUpdate = removeLegacyLoomNpmrcText(await readTextIfExists(npmrcPath));
8834
9386
  if (npmrcUpdate.changed) {
@@ -8836,19 +9388,23 @@ export async function initProject(cwd, versionRange) {
8836
9388
  changedFiles.push(".npmrc");
8837
9389
  notes.push("Removed Loom's obsolete GitHub Packages registry configuration.");
8838
9390
  }
8839
- const packageJson = parseJson(packageJsonText, "package.json");
8840
- const dependencyUpdate = ensurePackageJsonDependency(packageJson, versionRange ?? getPublishedLoomDependencySpec(packageJson));
9391
+ const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
9392
+ dependencies: {
9393
+ [LOOM_DEPENDENCY]: versionRange ??
9394
+ getPublishedLoomDependencySpec(initialPackageJson),
9395
+ },
9396
+ replace: true,
9397
+ });
8841
9398
  if (dependencyUpdate.changed) {
8842
- await writeFile(packageJsonPath, stringifyJson(dependencyUpdate.packageJson), "utf8");
8843
- changedFiles.push("package.json");
9399
+ changedFiles.push(tooling.dependencies.config);
9400
+ if (tooling.dependencies.config !== "package.json") {
9401
+ notes.push(`Recorded ${LOOM_DEPENDENCY} in ${tooling.dependencies.config} imports and enabled Deno's local node_modules directory when needed.`);
9402
+ }
8844
9403
  }
8845
- const framework = await detectFramework(cwd, dependencyUpdate.packageJson);
8846
- const loomManifestPath = join(cwd, "loom.json");
8847
- const existingManifestText = await readTextIfExists(loomManifestPath);
8848
- const existingManifest = existingManifestText
8849
- ? parseJson(existingManifestText, "loom.json")
8850
- : null;
8851
- const manifest = buildManifest(cwd, dependencyUpdate.packageJson, framework, existingManifest);
9404
+ const packageJson = (await readProjectPackageMetadata(cwd))
9405
+ .packageJson;
9406
+ const framework = await detectFramework(cwd, packageJson);
9407
+ const manifest = buildManifest(cwd, packageJson, framework, existingManifest, tooling);
8852
9408
  const featureInit = await ensureActiveFeatureScaffolds(cwd, framework, manifest);
8853
9409
  changedFiles.push(...featureInit.changedFiles);
8854
9410
  notes.push(...featureInit.notes);
@@ -8859,7 +9415,7 @@ export async function initProject(cwd, versionRange) {
8859
9415
  if (agentsInit.changed) {
8860
9416
  changedFiles.push("AGENTS.md");
8861
9417
  }
8862
- const nextAgentsInit = await ensureNextAgentsFile(cwd, dependencyUpdate.packageJson);
9418
+ const nextAgentsInit = await ensureNextAgentsFile(cwd, packageJson);
8863
9419
  if (nextAgentsInit.changed)
8864
9420
  changedFiles.push("AGENTS.md");
8865
9421
  if (nextAgentsInit.note)
@@ -8883,7 +9439,8 @@ export async function initProject(cwd, versionRange) {
8883
9439
  framework,
8884
9440
  manifest,
8885
9441
  notes,
8886
- packageJson: parseJson(await readFile(packageJsonPath, "utf8"), "package.json"),
9442
+ packageJson: (await readProjectPackageMetadata(cwd))
9443
+ .packageJson,
8887
9444
  };
8888
9445
  }
8889
9446
  export async function addFeature(cwd, featureKey, versionRange) {
@@ -9029,18 +9586,20 @@ export async function checkProject(cwd, env = process.env, options = {}) {
9029
9586
  const issues = [];
9030
9587
  const suggestions = new Set();
9031
9588
  const warnings = [];
9032
- const packageJsonPath = join(cwd, "package.json");
9033
- const packageJsonText = await readTextIfExists(packageJsonPath);
9034
- if (!packageJsonText) {
9589
+ let projectMetadata;
9590
+ try {
9591
+ projectMetadata = await readProjectPackageMetadata(cwd);
9592
+ }
9593
+ catch (error) {
9035
9594
  return {
9036
- issues: [`Missing ${packageJsonPath}`],
9595
+ issues: [error.message],
9037
9596
  suggestions: [
9038
- "Run `loom init` from a project that already has package.json.",
9597
+ "Run `loom init` from a project with package.json, deno.json, or deno.jsonc.",
9039
9598
  ],
9040
9599
  warnings: [],
9041
9600
  };
9042
9601
  }
9043
- const packageJson = parseJson(packageJsonText, "package.json");
9602
+ const packageJson = projectMetadata.packageJson;
9044
9603
  const npmrcText = await readTextIfExists(join(cwd, ".npmrc"));
9045
9604
  if (removeLegacyLoomNpmrcText(npmrcText).changed) {
9046
9605
  warnings.push(".npmrc retains Loom's obsolete GitHub Packages registry configuration.");
@@ -9049,7 +9608,7 @@ export async function checkProject(cwd, env = process.env, options = {}) {
9049
9608
  const framework = await detectFramework(cwd, packageJson);
9050
9609
  const dependency = packageJson.dependencies?.[LOOM_DEPENDENCY];
9051
9610
  if (!dependency) {
9052
- issues.push(`Missing ${LOOM_DEPENDENCY} in package.json dependencies.`);
9611
+ issues.push(`Missing ${LOOM_DEPENDENCY} in ${projectMetadata.config} dependencies/imports.`);
9053
9612
  suggestions.add("Run `loom init`.");
9054
9613
  }
9055
9614
  else if (isLocalPackageSpec(dependency)) {
@@ -9066,6 +9625,26 @@ export async function checkProject(cwd, env = process.env, options = {}) {
9066
9625
  manifest = parseJson(manifestText, "loom.json");
9067
9626
  }
9068
9627
  if (manifest) {
9628
+ let tooling = null;
9629
+ if (!manifest.project?.tooling) {
9630
+ warnings.push("loom.json does not record authoritative project tooling.");
9631
+ suggestions.add("Run `loom init` to adopt the detected project tooling.");
9632
+ }
9633
+ try {
9634
+ tooling = await detectProjectTooling(cwd, manifest.project?.tooling);
9635
+ }
9636
+ catch (error) {
9637
+ issues.push(`Invalid project tooling configuration: ${error.message}`);
9638
+ suggestions.add("Fix the recorded project.tooling config in loom.json.");
9639
+ }
9640
+ if (tooling) {
9641
+ for (const conflict of await findTaskConflicts(cwd, tooling.tasks)) {
9642
+ const deploymentWarning = conflict.name === "build"
9643
+ ? " Deployment may invoke the wrong build task."
9644
+ : "";
9645
+ warnings.push(`Conflicting '${conflict.name}' tasks in ${conflict.authoritativeConfig} (authoritative) and ${conflict.secondaryConfig}.${deploymentWarning}`);
9646
+ }
9647
+ }
9069
9648
  for (const [featureKey, feature] of Object.entries(manifest.features)) {
9070
9649
  if (feature.status !== "active")
9071
9650
  continue;
@@ -9097,7 +9676,7 @@ export async function checkProject(cwd, env = process.env, options = {}) {
9097
9676
  for (const suggestion of agentsCheck.suggestions) {
9098
9677
  suggestions.add(suggestion);
9099
9678
  }
9100
- const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest, packageJson);
9679
+ const envRunnerCheck = await checkEnvRunnerAdoption(cwd, manifest);
9101
9680
  for (const issue of envRunnerCheck.issues) {
9102
9681
  issues.push(issue);
9103
9682
  }
@@ -9151,13 +9730,16 @@ export async function checkProjectNetwork(cwd, env = process.env, options = {})
9151
9730
  const suggestions = new Set();
9152
9731
  const warnings = [];
9153
9732
  const steps = [];
9154
- const packageJsonText = await readTextIfExists(join(cwd, "package.json"));
9155
- if (!packageJsonText) {
9733
+ let projectMetadata;
9734
+ try {
9735
+ projectMetadata = await readProjectPackageMetadata(cwd);
9736
+ }
9737
+ catch (error) {
9156
9738
  return {
9157
- issues: [`Missing ${join(cwd, "package.json")}`],
9739
+ issues: [error.message],
9158
9740
  steps,
9159
9741
  suggestions: [
9160
- "Run `loom init` from a project that already has package.json.",
9742
+ "Run `loom init` from a package.json or Deno project.",
9161
9743
  ],
9162
9744
  warnings,
9163
9745
  };
@@ -9171,7 +9753,7 @@ export async function checkProjectNetwork(cwd, env = process.env, options = {})
9171
9753
  warnings,
9172
9754
  };
9173
9755
  }
9174
- const packageJson = parseJson(packageJsonText, "package.json");
9756
+ const packageJson = projectMetadata.packageJson;
9175
9757
  const framework = await detectFramework(cwd, packageJson);
9176
9758
  const manifest = parseJson(manifestText, "loom.json");
9177
9759
  const context = {
@@ -9500,13 +10082,15 @@ function formatSkillLinkState(state) {
9500
10082
  }
9501
10083
  }
9502
10084
  async function runStatus(cwd, io) {
9503
- const packageJsonPath = join(cwd, "package.json");
9504
- const packageJsonText = await readTextIfExists(packageJsonPath);
9505
- if (!packageJsonText) {
9506
- io.err(`No package.json found in ${cwd}.`);
10085
+ let projectMetadata;
10086
+ try {
10087
+ projectMetadata = await readProjectPackageMetadata(cwd);
10088
+ }
10089
+ catch (error) {
10090
+ io.err(error.message);
9507
10091
  return 1;
9508
10092
  }
9509
- const packageJson = parseJson(packageJsonText, "package.json");
10093
+ const packageJson = projectMetadata.packageJson;
9510
10094
  const manifestText = await readTextIfExists(join(cwd, "loom.json"));
9511
10095
  const manifest = manifestText
9512
10096
  ? parseJson(manifestText, "loom.json")
@@ -9521,6 +10105,19 @@ async function runStatus(cwd, io) {
9521
10105
  : null;
9522
10106
  const workspaceText = await readTextIfExists(join(cwd, "pnpm-workspace.yaml"));
9523
10107
  const overrideSpec = getManagedDevOverrideSpec(workspaceText);
10108
+ let denoOverride = null;
10109
+ try {
10110
+ const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
10111
+ if (usesDenoTooling(tooling)) {
10112
+ const config = await getDenoConfigForLinks(cwd, tooling);
10113
+ const link = await findLocalLoomDenoLink(cwd, await readDenoLinks(cwd, config));
10114
+ if (link)
10115
+ denoOverride = { config, link: link.link };
10116
+ }
10117
+ }
10118
+ catch {
10119
+ // Status reports stored project data even when live detection fails.
10120
+ }
9524
10121
  const localLockfileResolution = await getProjectLocalLoomLockfileResolution(cwd);
9525
10122
  const devState = getManagedDevState(workspaceText) ??
9526
10123
  await readLocalDevState(cwd);
@@ -9529,14 +10126,22 @@ async function runStatus(cwd, io) {
9529
10126
  io.out(`Loom status for ${projectName}`);
9530
10127
  io.out("");
9531
10128
  io.out("Package:");
9532
- io.out(` package.json: ${dependencySpec ? `${LOOM_DEPENDENCY} ${dependencySpec}` : "not declared"}`);
10129
+ io.out(` ${projectMetadata.config}: ${dependencySpec ? `${LOOM_DEPENDENCY} ${dependencySpec}` : "not declared"}`);
9533
10130
  io.out(` installed: ${installedPackage?.version ?? "not installed"}`);
9534
- io.out(` local dev override: ${overrideSpec ? `active (${overrideSpec})` : "none"}`);
10131
+ io.out(` local dev override: ${denoOverride
10132
+ ? `active (${denoOverride.config} links ${denoOverride.link})`
10133
+ : overrideSpec
10134
+ ? `active (${overrideSpec})`
10135
+ : "none"}`);
9535
10136
  io.out(` lockfile local resolution: ${localLockfileResolution ?? "none"}`);
9536
10137
  io.out("");
9537
10138
  io.out("Project:");
9538
10139
  io.out(` loom.json: ${manifest ? `version ${manifest.version}` : "missing"}`);
9539
10140
  io.out(` framework: ${formatFrameworkInfo(framework)}`);
10141
+ if (manifest?.project?.tooling) {
10142
+ io.out(` tasks: ${manifest.project.tooling.tasks.config} via ${manifest.project.tooling.tasks.runner}`);
10143
+ io.out(` dependencies: ${manifest.project.tooling.dependencies.config} via ${manifest.project.tooling.dependencies.manager}`);
10144
+ }
9540
10145
  io.out("");
9541
10146
  io.out("Features:");
9542
10147
  if (!manifest) {
@@ -9625,7 +10230,7 @@ function printHelp({ out }) {
9625
10230
  out("loom <command>");
9626
10231
  out("");
9627
10232
  out("Commands:");
9628
- out(" init Set up package.json, loom.json, managed AGENTS.md guidance, first-party links, and npm package skills.");
10233
+ out(" init Set up package/Deno config, loom.json, managed AGENTS.md guidance, first-party links, and package skills.");
9629
10234
  out(" add <feature> Activate a shared feature. Run `loom add` to list available features.");
9630
10235
  out(" files id-generation uuid-v4|uuid-v7 Select the managed Files schema ID default.");
9631
10236
  out(" files r2 setup Create/reuse private Cloudflare R2 buckets, configure Vercel Production/Preview, and configure local MinIO by default.");
@@ -9647,8 +10252,8 @@ function printHelp({ out }) {
9647
10252
  out(" db release setup-github Create/update GitHub production release config for staged Vercel deploys.");
9648
10253
  out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
9649
10254
  out(" db release verify-build-env <output> <manifest> Reject build-only placeholders in a deployable Vercel artifact.");
9650
- out(" dev local Enable local Loom development using a managed file: override in pnpm-workspace.yaml.");
9651
- out(" dev sync Rebuild the local Loom package and refresh this project's pnpm install when the managed local-dev override is active.");
10255
+ out(" dev local Enable local Loom development using a managed pnpm override or Deno link.");
10256
+ out(" dev sync Rebuild local Loom and refresh this project's pnpm or Deno install when linked.");
9652
10257
  out(" dev published Remove the managed local-dev override and return to the published dependency.");
9653
10258
  out("");
9654
10259
  out("Options:");
@@ -9887,12 +10492,15 @@ async function runSkills(cwd, command, args, io, options) {
9887
10492
  printSkillsHelp(io);
9888
10493
  return 0;
9889
10494
  }
9890
- const packageJsonText = await readTextIfExists(join(cwd, "package.json"));
9891
- if (!packageJsonText) {
9892
- io.err(`No package.json found in ${cwd}.`);
10495
+ let projectMetadata;
10496
+ try {
10497
+ projectMetadata = await readProjectPackageMetadata(cwd);
10498
+ }
10499
+ catch (error) {
10500
+ io.err(error.message);
9893
10501
  return 1;
9894
10502
  }
9895
- const packageJson = parseJson(packageJsonText, "package.json");
10503
+ const packageJson = projectMetadata.packageJson;
9896
10504
  const manifestText = await readTextIfExists(join(cwd, "loom.json"));
9897
10505
  const manifest = manifestText
9898
10506
  ? parseJson(manifestText, "loom.json")
@@ -10060,7 +10668,16 @@ async function runDbSchemaGen(cwd, forwardedArgs, io) {
10060
10668
  if (!isNodeErrorCode(error, "MODULE_NOT_FOUND")) {
10061
10669
  throw error;
10062
10670
  }
10063
- io.out("Biome is not installed; generated Valibot files were left unformatted.");
10671
+ const manifest = await readManifestIfExists(cwd);
10672
+ const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
10673
+ if (usesDenoTooling(tooling)) {
10674
+ const formatExitCode = await runInheritedChild("deno", ["fmt", config.dirs.valibotGeneratedDir], cwd);
10675
+ if (formatExitCode !== 0)
10676
+ return formatExitCode;
10677
+ }
10678
+ else {
10679
+ io.out("Biome is not installed; generated Valibot files were left unformatted.");
10680
+ }
10064
10681
  }
10065
10682
  if (await syncValibotBarrel(cwd, config)) {
10066
10683
  io.out(`Updated ${config.modules.valibotBarrelModule}.`);
@@ -10363,7 +10980,7 @@ async function runDev(cwd, mode, pathInput, io, options = {}) {
10363
10980
  io.out(`Updated ${result.changedFiles.join(", ")}.`);
10364
10981
  }
10365
10982
  else if (result.notes.length) {
10366
- io.out("Project package.json uses a published @gadicc/loom dependency, but follow-up is still needed.");
10983
+ io.out("Project config uses a published @gadicc/loom dependency, but follow-up is still needed.");
10367
10984
  }
10368
10985
  else {
10369
10986
  io.out("Project already uses the published @gadicc/loom dependency.");