@treeseed/core 0.8.14 → 0.8.15

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.
Files changed (2) hide show
  1. package/dist/dev.js +42 -4
  2. package/package.json +2 -2
package/dist/dev.js CHANGED
@@ -1,9 +1,10 @@
1
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
2
2
  import { spawn, spawnSync } from "node:child_process";
3
3
  import { createRequire } from "node:module";
4
4
  import { dirname, isAbsolute, resolve, sep } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { setTimeout as delay } from "node:timers/promises";
7
+ import { DatabaseSync } from "node:sqlite";
7
8
  import {
8
9
  applyTreeseedEnvironmentToProcess,
9
10
  assertTreeseedCommandEnvironment,
@@ -112,7 +113,7 @@ function normalizeFeedbackMode(value) {
112
113
  return value ?? "live";
113
114
  }
114
115
  function normalizeOpenMode(value) {
115
- return value ?? "auto";
116
+ return value ?? "off";
116
117
  }
117
118
  function normalizeLocalRuntimeMode(value) {
118
119
  return value === "provider" || value === "local" ? value : "auto";
@@ -234,6 +235,42 @@ function resetActionForPath(id, label, path) {
234
235
  detail: existsSync(path) ? void 0 : "Path does not exist."
235
236
  };
236
237
  }
238
+ function resolveLocalD1SqlitePath(persistTo) {
239
+ if (/\.sqlite$/u.test(persistTo) && existsSync(persistTo)) {
240
+ return persistTo;
241
+ }
242
+ const miniflareRoot = resolve(persistTo, "miniflare-D1DatabaseObject");
243
+ if (existsSync(miniflareRoot)) {
244
+ const candidates = readdirSync(miniflareRoot).filter((entry) => /\.sqlite$/u.test(entry) && entry !== "metadata.sqlite").map((entry) => {
245
+ const path = resolve(miniflareRoot, entry);
246
+ return {
247
+ path,
248
+ size: statSync(path).size
249
+ };
250
+ }).sort((left, right) => right.size - left.size || left.path.localeCompare(right.path));
251
+ if (candidates[0]?.path) {
252
+ return candidates[0].path;
253
+ }
254
+ }
255
+ const siteDataPath = resolve(persistTo, "site-data.sqlite");
256
+ return existsSync(siteDataPath) ? siteDataPath : null;
257
+ }
258
+ function resolveSeededLocalProjectId(persistTo, projectSlug = "market") {
259
+ const sqlitePath = resolveLocalD1SqlitePath(persistTo);
260
+ if (!sqlitePath) return null;
261
+ let db = null;
262
+ try {
263
+ db = new DatabaseSync(sqlitePath, { readOnly: true });
264
+ const row = db.prepare(
265
+ `SELECT id FROM projects WHERE LOWER(slug) = LOWER(?) ORDER BY created_at ASC LIMIT 1`
266
+ ).get(projectSlug);
267
+ return typeof row?.id === "string" && row.id.trim() ? row.id.trim() : null;
268
+ } catch {
269
+ return null;
270
+ } finally {
271
+ db?.close();
272
+ }
273
+ }
237
274
  function createTreeseedIntegratedDevResetPlan(options) {
238
275
  if (!options.enabled) {
239
276
  return null;
@@ -484,7 +521,6 @@ function createTreeseedIntegratedDevPlan(options = {}) {
484
521
  const apiPort = normalizePort(options.apiPort, TREESEED_DEFAULT_API_PORT);
485
522
  const machineEnv = resolveLocalMachineEnv(tenantRoot);
486
523
  const mergedEnv = { ...process.env, ...machineEnv, ...options.env ?? {} };
487
- const projectId = options.projectId ?? mergedEnv.TREESEED_PROJECT_ID;
488
524
  const teamId = options.teamId ?? mergedEnv.TREESEED_HOSTING_TEAM_ID;
489
525
  const apiBaseUrl = options.apiHost != null || options.apiPort != null ? `http://${apiHost}:${apiPort}` : mergedEnv.TREESEED_API_BASE_URL?.trim() || `http://${apiHost}:${apiPort}`;
490
526
  const selectedCommandIds = selectedSurfaceCommandIds(options);
@@ -495,6 +531,8 @@ function createTreeseedIntegratedDevPlan(options = {}) {
495
531
  const deployConfig = loadDevDeployConfig(tenantRoot);
496
532
  const webLocalRuntime = selectWebLocalRuntime(deployConfig?.surfaces?.web, fallbackWebProviderFromDeployConfig(deployConfig));
497
533
  const usesCloudflareWebRuntime = webLocalRuntime.selected === "cloudflare-wrangler-local";
534
+ const localD1PersistTo = mergedEnv.TREESEED_API_D1_LOCAL_PERSIST_TO ?? (usesCloudflareWebRuntime ? resolve(tenantRoot, ".treeseed", "generated", "environments", "local", ".wrangler", "state", "v3", "d1") : resolve(tenantRoot, ".wrangler", "state", "v3", "d1"));
535
+ const projectId = options.projectId ?? mergedEnv.TREESEED_PROJECT_ID ?? resolveSeededLocalProjectId(localD1PersistTo);
498
536
  const webEntrypoint = resolveNodeEntrypoint(
499
537
  sdkPackageRoot,
500
538
  "scripts/tenant-astro-command.ts",
@@ -528,7 +566,7 @@ function createTreeseedIntegratedDevPlan(options = {}) {
528
566
  TREESEED_HOSTING_TEAM_ID: teamId ?? mergedEnv.TREESEED_HOSTING_TEAM_ID,
529
567
  TREESEED_API_D1_DATABASE_NAME: mergedEnv.TREESEED_API_D1_DATABASE_NAME ?? "SITE_DATA_DB",
530
568
  SITE_DATA_DB: mergedEnv.SITE_DATA_DB ?? "SITE_DATA_DB",
531
- TREESEED_API_D1_LOCAL_PERSIST_TO: mergedEnv.TREESEED_API_D1_LOCAL_PERSIST_TO ?? (usesCloudflareWebRuntime ? resolve(tenantRoot, ".treeseed", "generated", "environments", "local", ".wrangler", "state", "v3", "d1") : resolve(tenantRoot, ".wrangler", "state", "v3", "d1")),
569
+ TREESEED_API_D1_LOCAL_PERSIST_TO: localD1PersistTo,
532
570
  TREESEED_FORM_TOKEN_SECRET: mergedEnv.TREESEED_FORM_TOKEN_SECRET ?? "treeseed-local-form-token-secret",
533
571
  TREESEED_BETTER_AUTH_SECRET: mergedEnv.TREESEED_BETTER_AUTH_SECRET ?? "treeseed-local-better-auth-secret-minimum-32-characters",
534
572
  TREESEED_SMTP_HOST: TREESEED_DEFAULT_LOCAL_SMTP_HOST,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/core",
3
- "version": "0.8.14",
3
+ "version": "0.8.15",
4
4
  "description": "Treeseed web framework package for Astro/Starlight site runtimes.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "@astrojs/sitemap": "3.7.0",
71
71
  "@astrojs/starlight": "0.37.6",
72
72
  "@tailwindcss/vite": "^4.1.4",
73
- "@treeseed/sdk": "0.8.14",
73
+ "@treeseed/sdk": "0.8.15",
74
74
  "astro": "^5.6.1",
75
75
  "esbuild": "^0.28.0",
76
76
  "katex": "^0.16.22",