@monkeyplus/flow 6.0.84 → 6.0.85

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.
@@ -1,7 +1,6 @@
1
1
  import { extname } from "node:path";
2
2
  import { consola } from "consola";
3
3
  import { defineEventHandler, getQuery, getRequestURL } from "nitro/h3";
4
- import { useStorage } from "nitro/storage";
5
4
  function normalizeQueryPath(path) {
6
5
  if (!path || path === "/") {
7
6
  return "/";
@@ -126,57 +125,40 @@ export async function readContentEntries() {
126
125
  }
127
126
  return entries2;
128
127
  };
129
- const storage = useStorage("assets:content");
130
- const keys = await storage.getKeys();
131
128
  const entries = [];
132
- if (keys.length === 0) {
133
- try {
134
- const fs = await import("node:fs/promises");
135
- const path = await import("node:path");
136
- const contentDir = path.resolve(process.cwd(), "content");
137
- async function walkDir(dir, baseDir) {
138
- const files = await fs.readdir(dir, { withFileTypes: true });
139
- for (const file of files) {
140
- const res = path.resolve(dir, file.name);
141
- if (file.isDirectory()) {
142
- await walkDir(res, baseDir);
143
- } else {
144
- const extension = path.extname(res).toLowerCase();
145
- if ([".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
146
- const relativePath = path.relative(baseDir, res);
147
- const normalizedKey = relativePath.replace(/\\/g, "/");
148
- const raw = await fs.readFile(res, "utf-8");
149
- const entry = parseContentFile(normalizedKey, raw);
150
- entries.push(entry);
151
- }
129
+ try {
130
+ const fs = await import("node:fs/promises");
131
+ const path = await import("node:path");
132
+ const contentDir = path.resolve(process.cwd(), "content");
133
+ async function walkDir(dir, baseDir) {
134
+ const files = await fs.readdir(dir, { withFileTypes: true });
135
+ for (const file of files) {
136
+ const res = path.resolve(dir, file.name);
137
+ if (file.isDirectory()) {
138
+ await walkDir(res, baseDir);
139
+ } else {
140
+ const extension = path.extname(res).toLowerCase();
141
+ if ([".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
142
+ const relativePath = path.relative(baseDir, res);
143
+ const normalizedKey = relativePath.replace(/\\/g, "/");
144
+ const raw = await fs.readFile(res, "utf-8");
145
+ const entry = parseContentFile(normalizedKey, raw);
146
+ entries.push(entry);
152
147
  }
153
148
  }
154
149
  }
155
- try {
156
- await fs.access(contentDir);
157
- await walkDir(contentDir, contentDir);
158
- } catch (e) {
159
- }
160
- const sorted = entries.sort((left, right) => left.path.localeCompare(right.path));
161
- return applyCmsPreview(sorted);
162
- } catch (e) {
163
- consola.error("[Flow Content] fs fallback failed:", e);
164
150
  }
165
- }
166
- for (const key of keys) {
167
- const normalizedKey = key.replace(/:/g, "/");
168
- const extension = extname(normalizedKey).toLowerCase();
169
- if (![".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
170
- continue;
171
- }
172
- const raw = await storage.getItem(key);
173
- if (raw !== null && raw !== void 0) {
174
- const entry = parseContentFile(normalizedKey, raw);
175
- entries.push(entry);
151
+ try {
152
+ await fs.access(contentDir);
153
+ await walkDir(contentDir, contentDir);
154
+ } catch (e) {
176
155
  }
156
+ const sorted = entries.sort((left, right) => left.path.localeCompare(right.path));
157
+ return applyCmsPreview(sorted);
158
+ } catch (e) {
159
+ consola.error("[Flow Content] fs reading failed:", e);
177
160
  }
178
- const sortedEntries = entries.sort((left, right) => left.path.localeCompare(right.path));
179
- return applyCmsPreview(sortedEntries);
161
+ return applyCmsPreview(entries);
180
162
  }
181
163
  function sortTree(nodes) {
182
164
  nodes.sort((left, right) => {
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.84",
3
+ "version": "6.0.85",
4
4
  "description": "@monkeyplus/flow package-first runtime with Vite, Nitro, Vue and a workspace playground.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -1,6 +1,9 @@
1
1
  import { definePlugin } from "nitro";
2
2
  import { consola } from "consola";
3
3
  export default definePlugin((nitroApp) => {
4
+ if (!globalThis.$fetch) {
5
+ globalThis.$fetch = nitroApp.localFetch;
6
+ }
4
7
  nitroApp.hooks.hook("request", (event) => {
5
8
  const pathname = new URL(event.req.url, "http://localhost").pathname;
6
9
  if (!pathname.startsWith("/api/")) {
@@ -77,11 +77,12 @@ async function fetchContent(route, queryParams) {
77
77
  const relativeTarget = withQuery(joinUrl(apiBase, route), query);
78
78
  if (typeof window === "undefined") {
79
79
  try {
80
- if (import.meta.env?.SSR || process.server || !localFetch) {
80
+ if (!localFetch) {
81
81
  let queryModule;
82
82
  try {
83
83
  queryModule = await import("../../modules/content/query.mjs");
84
- } catch {
84
+ } catch (tsErr) {
85
+ console.error("[queryContent] Error loading .ts:", tsErr);
85
86
  queryModule = await import("../../modules/content/query.js");
86
87
  }
87
88
  const { findContentEntries, buildContentTree, findContentTree, readContentEntries, processContentQuery } = queryModule;
@@ -97,6 +98,7 @@ async function fetchContent(route, queryParams) {
97
98
  return processContentQuery(entries, query, await readContentEntries());
98
99
  }
99
100
  } catch (e) {
101
+ console.error("[queryContent] Bypass failed:", e);
100
102
  }
101
103
  }
102
104
  const fetchFn = typeof window === "undefined" ? localFetch || fetch : fetch;