@yysng/astro-boilerplate 1.1.22 → 1.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysng/astro-boilerplate",
3
- "version": "1.1.22",
3
+ "version": "1.1.25",
4
4
  "description": "Astro + Sanity Boilerplate with AEO Layers 1–5",
5
5
  "type": "module",
6
6
  "exports": {
@@ -2,10 +2,9 @@ let contentRoot = null;
2
2
 
3
3
  export function setContentRoot(path) {
4
4
  contentRoot = path;
5
+ globalThis.__CONTENT_ROOT__ = path;
5
6
  }
6
7
 
7
8
  export function getContentRoot() {
8
- // When running on edge, we no longer require filesystem root.
9
- // Loader will use import.meta.glob instead.
10
9
  return contentRoot;
11
10
  }
@@ -1,15 +1,14 @@
1
- import { CONTENT_REGISTRY } from "./registry.js";
2
- import { readLocal } from "./storage.js";
3
-
4
1
  export async function loadContent(key, env = {}) {
5
2
  const entry = CONTENT_REGISTRY[key];
6
3
  if (!entry) throw new Error(`Unknown content key: ${key}`);
7
4
 
8
5
  if (env?.CONTENT_KV) {
9
6
  const stored = await env.CONTENT_KV.get(entry.file, "json");
10
- if (stored) return stored;
11
- throw new Error(`KV missing content for ${entry.file}`);
7
+ if (!stored) throw new Error(`Missing KV content: ${entry.file}`);
8
+ return stored;
12
9
  }
13
10
 
11
+ // Only import storage on Node
12
+ const { readLocal } = await import("./storage.js");
14
13
  return await readLocal(entry.file);
15
14
  }
@@ -1,20 +1,27 @@
1
- import fs from "fs/promises";
2
- import path from "path";
3
- import { getContentRoot } from "./config.js";
1
+ let fs, path;
2
+
3
+ if (typeof process !== "undefined" && process.versions?.node) {
4
+ fs = await import("fs/promises");
5
+ path = await import("path");
6
+ }
4
7
 
5
8
  export async function readLocal(file) {
6
- const root = getContentRoot();
7
- if (!root) throw new Error("Content root not configured");
9
+ if (!fs || !path) {
10
+ throw new Error("Filesystem not available in this runtime");
11
+ }
8
12
 
13
+ const root = globalThis.__CONTENT_ROOT__;
9
14
  const filePath = path.join(root, file);
10
15
  const raw = await fs.readFile(filePath, "utf-8");
11
16
  return JSON.parse(raw);
12
17
  }
13
18
 
14
19
  export async function writeLocal(file, data) {
15
- const root = getContentRoot();
16
- if (!root) throw new Error("Content root not configured");
20
+ if (!fs || !path) {
21
+ throw new Error("Filesystem not available in this runtime");
22
+ }
17
23
 
24
+ const root = globalThis.__CONTENT_ROOT__;
18
25
  const filePath = path.join(root, file);
19
26
  await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
20
27
  }