@farm.js/search 0.1.0-beta.2 → 0.1.0-beta.3

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":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAmF1F;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKhF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGnE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKtD;AAYD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAwB3E"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoF1F;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKhF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGnE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKtD;AAYD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAwB3E"}
package/dist/build.js CHANGED
@@ -53,6 +53,7 @@ export async function writeSearchIndex(input) {
53
53
  }
54
54
  indexedRoutes.push(route);
55
55
  }
56
+ await assertOutputPathIsOwned(outputPath);
56
57
  await rm(outputPath, { recursive: true, force: true });
57
58
  await mkdir(path.dirname(outputPath), { recursive: true });
58
59
  const written = await index.writeFiles({ outputPath });
@@ -183,6 +184,51 @@ function resolveOutputPath(publicDir, bundlePath) {
183
184
  }
184
185
  return outputPath;
185
186
  }
187
+ /**
188
+ * Refuse to delete prerendered pages that happen to live where the index goes.
189
+ *
190
+ * The index directory is wiped before it is rewritten, and it comes from the
191
+ * `output` option, so `output: "search"` on a site that also prerenders a
192
+ * `/search` page pointed the wipe at the app's own pages. `collectHtmlFiles`
193
+ * skips this directory, so those pages were left out of the index and then
194
+ * deleted from the deploy output, with a success log and a zero exit.
195
+ *
196
+ * Only HTML is treated as the app's: a previous bundle leaves non-HTML files
197
+ * behind, and clearing those is this function's normal job.
198
+ */
199
+ async function assertOutputPathIsOwned(outputPath) {
200
+ const pages = await findHtmlFile(outputPath);
201
+ if (!pages)
202
+ return;
203
+ throw new Error(`The search index directory ${outputPath} contains a prerendered page (${path.relative(outputPath, pages)}), ` +
204
+ `so it will not be replaced. Give \`search({ output })\` a directory of its own, ` +
205
+ `or move the conflicting route, then build again.`);
206
+ }
207
+ /** The first HTML file at any depth, or undefined when there is none. */
208
+ async function findHtmlFile(directory) {
209
+ let entries;
210
+ try {
211
+ entries = await readdir(directory, { withFileTypes: true });
212
+ }
213
+ catch (error) {
214
+ // Nothing there yet is the ordinary first build.
215
+ if (error.code === "ENOENT")
216
+ return undefined;
217
+ throw error;
218
+ }
219
+ for (const entry of entries) {
220
+ const entryPath = path.join(directory, entry.name);
221
+ if (entry.isDirectory()) {
222
+ const nested = await findHtmlFile(entryPath);
223
+ if (nested)
224
+ return nested;
225
+ }
226
+ else if (entry.isFile() && entry.name.toLowerCase().endsWith(".html")) {
227
+ return entryPath;
228
+ }
229
+ }
230
+ return undefined;
231
+ }
186
232
  async function assertOutputPathInside(publicDir, outputPath) {
187
233
  const realPublicDir = await realpath(publicDir);
188
234
  let existingAncestor = outputPath;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type SearchOptions } from "./config.js";
2
+ import type { FarmSearchPublicConfig } from "./types.js";
2
3
  export type { ResolvedSearchOptions, SearchOptions } from "./config.js";
3
4
  export type { FarmSearchClient, SearchClientOptions, SearchFilterCounts, SearchFilterExpression, SearchFilterPrimitive, SearchFilters, SearchQueryOptions, SearchResponse, SearchResult, SearchSort, SearchSubResult, SearchTimings, } from "./types.js";
4
5
  /** Build a static Pagefind index from Farm's emitted HTML pages. */
5
- export declare function search(options?: SearchOptions): import("@farm.js/core/plugin").FarmPlugin;
6
+ export declare function search(options?: SearchOptions): import("@farm.js/core/plugin").FarmPlugin<undefined, Record<string, never>, void, FarmSearchPublicConfig, unknown, false, import("@farm.js/core/plugin").PluginRoutes>;
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAGvE,YAAY,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,oEAAoE;AACpE,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,6CAkGjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,YAAY,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,oEAAoE;AACpE,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,0KAkGjD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/search",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.3",
4
4
  "description": "Build-time static page search for Farm.js applications",
5
5
  "keywords": [
6
6
  "farm.js",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "pagefind": "^1.5.2",
40
- "@farm.js/core": "0.1.0-beta.105"
40
+ "@farm.js/core": "0.1.0-beta.108"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^20.10.5",