@farm.js/content 0.1.0-beta.50 → 0.1.0-beta.52

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,KAAK,EAA0B,MAAM,aAAa,CAAC;AAGxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIpF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,2BAA2B,EAC3B,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,sFAAsF;AACtF,wBAAgB,OAAO,CAAC,KAAK,CAAC,YAAY,SAAS,kBAAkB,EACnE,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,GACpC,aAAa,CAAC,YAAY,CAAC,CAoM7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,KAAK,EAA0B,MAAM,aAAa,CAAC;AAIxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIpF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,2BAA2B,EAC3B,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,sFAAsF;AACtF,wBAAgB,OAAO,CAAC,KAAK,CAAC,YAAY,SAAS,kBAAkB,EACnE,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,GACpC,aAAa,CAAC,YAAY,CAAC,CAsL7B"}
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import fg from "fast-glob";
5
5
  import { asset } from "./assets.js";
6
6
  import { collection, files, isSupportedContentFile } from "./config.js";
7
7
  import { loadContentCollections, writeContentServerModule } from "./loader.js";
8
+ import { invalidateFileModules } from "./module-graph.js";
8
9
  import { registerContentWriteRuntime, setContentAfterWrite } from "./runtime.js";
9
10
  const CONTENT_SERVER_ID = "@farm.js/content/server";
10
11
  export { asset, collection, files };
@@ -89,17 +90,11 @@ export function content(options) {
89
90
  return;
90
91
  }
91
92
  await rebuild();
92
- const modules = server.moduleGraph.getModulesByFile?.(generatedFile);
93
- for (const module of modules ?? [])
94
- server.moduleGraph.invalidateModule(module);
93
+ invalidateFileModules(server.moduleGraph, generatedFile);
95
94
  server.ws.send({ type: "full-reload" });
96
95
  })
97
96
  .catch((error) => {
98
- const message = error instanceof Error ? error.message : String(error);
99
- server.ws.send({
100
- type: "error",
101
- err: { message, stack: error instanceof Error ? error.stack : undefined },
102
- });
97
+ reportContentRebuildError(server, error);
103
98
  });
104
99
  };
105
100
  server.watcher.on("all", onFile);
@@ -113,17 +108,11 @@ export function content(options) {
113
108
  .then(async () => {
114
109
  if (!(await rebuild()))
115
110
  return;
116
- const modules = server.moduleGraph.getModulesByFile?.(generatedFile);
117
- for (const module of modules ?? [])
118
- server.moduleGraph.invalidateModule(module);
111
+ invalidateFileModules(server.moduleGraph, generatedFile);
119
112
  server.ws.send({ type: "full-reload" });
120
113
  })
121
114
  .catch((error) => {
122
- const message = error instanceof Error ? error.message : String(error);
123
- server.ws.send({
124
- type: "error",
125
- err: { message, stack: error instanceof Error ? error.stack : undefined },
126
- });
115
+ reportContentRebuildError(server, error);
127
116
  }));
128
117
  await settled;
129
118
  });
@@ -151,9 +140,7 @@ export function content(options) {
151
140
  if (!(await rebuild()))
152
141
  return;
153
142
  lastPollError = undefined;
154
- const modules = server.moduleGraph.getModulesByFile?.(generatedFile);
155
- for (const module of modules ?? [])
156
- server.moduleGraph.invalidateModule(module);
143
+ invalidateFileModules(server.moduleGraph, generatedFile);
157
144
  server.ws.send({ type: "full-reload" });
158
145
  })
159
146
  .catch((error) => {
@@ -161,10 +148,7 @@ export function content(options) {
161
148
  if (message === lastPollError)
162
149
  return;
163
150
  lastPollError = message;
164
- server.ws.send({
165
- type: "error",
166
- err: { message, stack: error instanceof Error ? error.stack : undefined },
167
- });
151
+ reportContentRebuildError(server, error);
168
152
  });
169
153
  }, Math.min(...intervals));
170
154
  timer.unref?.();
@@ -214,6 +198,21 @@ async function assertGeneratedOutputInsideRoot(root, outputFile) {
214
198
  return;
215
199
  }
216
200
  }
201
+ /**
202
+ * Show a failed content rebuild in the browser overlay and in the dev terminal. A backend-only
203
+ * app (`renderer: false`) has no browser to show the overlay, and the API keeps serving the last
204
+ * good content, so the terminal is the only place the error would surface.
205
+ */
206
+ function reportContentRebuildError(server, error) {
207
+ const message = error instanceof Error ? error.message : String(error);
208
+ server.config?.logger.error(`[farm:content] ${message}`, {
209
+ error: error instanceof Error ? error : undefined,
210
+ });
211
+ server.ws.send({
212
+ type: "error",
213
+ err: { message, stack: error instanceof Error ? error.stack : undefined },
214
+ });
215
+ }
217
216
  async function shouldRebuildForFile(root, filePath, event, sourceFiles, collections) {
218
217
  if (sourceFiles.has(filePath))
219
218
  return true;
package/dist/loader.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface LoadedContent {
7
7
  }
8
8
  export declare function loadContentCollections(root: string, collections: ContentCollections, sourceFiles?: Set<string>): Promise<LoadedContent>;
9
9
  export declare function writeContentServerModule(outputFile: string, collections: Readonly<Record<string, readonly ContentEntry<any>[]>>, assetImports?: ReadonlyMap<string, ContentAssetImport>): Promise<boolean>;
10
+ export declare function normalizePath(value: string): string;
10
11
  type EncodedContentValue = null | boolean | number | string | ["undefined"] | ["date", string] | ["bigint", string] | ["array", EncodedContentValue[]] | ["object", Array<[string, EncodedContentValue]>];
11
12
  export declare function encodeContentValue(value: unknown, seen?: Set<object>): EncodedContentValue;
12
13
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAKV,kBAAkB,EAClB,YAAY,EAIb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,YAAY,CAAC,GA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M,CAAC,MAAM,EAAE,SAAS,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7E,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CAChE;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,kBAAkB,EAC/B,WAAW,GAAE,GAAG,CAAC,MAAM,CAAa,GACnC,OAAO,CAAC,aAAa,CAAC,CAuBxB;AAED,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EACnE,YAAY,GAAE,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAa,GAChE,OAAO,CAAC,OAAO,CAAC,CAsClB;AAsXD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAOD,KAAK,mBAAmB,GACpB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,CAAC,WAAW,CAAC,GACb,CAAC,MAAM,EAAE,MAAM,CAAC,GAChB,CAAC,QAAQ,EAAE,MAAM,CAAC,GAClB,CAAC,OAAO,EAAE,mBAAmB,EAAE,CAAC,GAChC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAErD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,cAAoB,GAAG,mBAAmB,CAmChG"}
package/dist/loader.js CHANGED
@@ -346,7 +346,7 @@ function countWords(body) {
346
346
  const normalized = body.trim();
347
347
  return normalized ? normalized.split(/\s+/).length : 0;
348
348
  }
349
- function normalizePath(value) {
349
+ export function normalizePath(value) {
350
350
  return value.replace(/\\/g, "/");
351
351
  }
352
352
  function toViteImportSpecifier(outputDirectory, filePath) {
@@ -0,0 +1,10 @@
1
+ export interface ContentModuleGraph {
2
+ getModulesByFile?(file: string): Set<unknown> | undefined;
3
+ invalidateModule(module: unknown): void;
4
+ }
5
+ /**
6
+ * Invalidate the modules Vite loaded from `file`. Vite keys its module graph by forward-slash
7
+ * paths, so a Windows path (`C:\app\...`) is normalized first or the lookup finds nothing.
8
+ */
9
+ export declare function invalidateFileModules(moduleGraph: ContentModuleGraph, file: string): void;
10
+ //# sourceMappingURL=module-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-graph.d.ts","sourceRoot":"","sources":["../src/module-graph.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC1D,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CACzC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIzF"}
@@ -0,0 +1,10 @@
1
+ import { normalizePath } from "./loader.js";
2
+ /**
3
+ * Invalidate the modules Vite loaded from `file`. Vite keys its module graph by forward-slash
4
+ * paths, so a Windows path (`C:\app\...`) is normalized first or the lookup finds nothing.
5
+ */
6
+ export function invalidateFileModules(moduleGraph, file) {
7
+ for (const module of moduleGraph.getModulesByFile?.(normalizePath(file)) ?? []) {
8
+ moduleGraph.invalidateModule(module);
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/content",
3
- "version": "0.1.0-beta.50",
3
+ "version": "0.1.0-beta.52",
4
4
  "description": "Typed local content collections for Farm.js applications",
5
5
  "keywords": [
6
6
  "content",
@@ -47,7 +47,7 @@
47
47
  "mdast-util-mdx": "^3.0.0",
48
48
  "micromark-extension-mdxjs": "^3.0.0",
49
49
  "yaml": "^2.8.0",
50
- "@farm.js/core": "0.1.51-beta.3"
50
+ "@farm.js/core": "0.1.67"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^22.20.5",