@cedarjs/prerender 7.0.0 → 8.0.0-canary.3263

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 (72) hide show
  1. package/dist/browserUtils/index.d.ts +1 -1
  2. package/dist/browserUtils/index.d.ts.map +1 -1
  3. package/dist/build-and-import/buildAndImport.d.ts +1 -1
  4. package/dist/build-and-import/buildAndImport.d.ts.map +1 -1
  5. package/dist/build-and-import/buildAndImport.js +2 -9
  6. package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.d.ts.map +1 -1
  7. package/dist/graphql/graphql.d.ts +17 -2
  8. package/dist/graphql/graphql.d.ts.map +1 -1
  9. package/dist/{cjs/index.d.ts.map → index.d.ts.map} +1 -1
  10. package/dist/index.js +1 -0
  11. package/dist/runPrerender.d.ts.map +1 -0
  12. package/dist/{runPrerenderEsm.js → runPrerender.js} +65 -56
  13. package/package.json +20 -51
  14. package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -5
  15. package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
  16. package/dist/babelPlugins/babel-plugin-redwood-cell.js +0 -98
  17. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +0 -5
  18. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +0 -1
  19. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +0 -77
  20. package/dist/babelPlugins/utils.d.ts +0 -2
  21. package/dist/babelPlugins/utils.d.ts.map +0 -1
  22. package/dist/babelPlugins/utils.js +0 -15
  23. package/dist/cjs/apolloState.d.ts +0 -13
  24. package/dist/cjs/apolloState.d.ts.map +0 -1
  25. package/dist/cjs/apolloState.js +0 -30
  26. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -5
  27. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
  28. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.js +0 -122
  29. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +0 -5
  30. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +0 -1
  31. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +0 -101
  32. package/dist/cjs/babelPlugins/utils.d.ts +0 -2
  33. package/dist/cjs/babelPlugins/utils.d.ts.map +0 -1
  34. package/dist/cjs/babelPlugins/utils.js +0 -49
  35. package/dist/cjs/browserUtils/index.d.ts +0 -8
  36. package/dist/cjs/browserUtils/index.d.ts.map +0 -1
  37. package/dist/cjs/browserUtils/index.js +0 -47
  38. package/dist/cjs/build-and-import/buildAndImport.js +0 -193
  39. package/dist/cjs/build-and-import/load-tsconfig.d.js +0 -1
  40. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedar-remove-dev-fatal-error-page.js +0 -53
  41. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +0 -184
  42. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js +0 -83
  43. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.js +0 -125
  44. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js +0 -48
  45. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js +0 -66
  46. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js +0 -118
  47. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js +0 -146
  48. package/dist/cjs/build-and-import/rollupPlugins/utils.js +0 -78
  49. package/dist/cjs/build-and-import/utils.js +0 -68
  50. package/dist/cjs/detection/detection.d.ts +0 -11
  51. package/dist/cjs/detection/detection.d.ts.map +0 -1
  52. package/dist/cjs/detection/detection.js +0 -46
  53. package/dist/cjs/errors.d.ts +0 -19
  54. package/dist/cjs/errors.d.ts.map +0 -1
  55. package/dist/cjs/errors.js +0 -52
  56. package/dist/cjs/graphql/graphql.d.ts +0 -19
  57. package/dist/cjs/graphql/graphql.d.ts.map +0 -1
  58. package/dist/cjs/graphql/graphql.js +0 -152
  59. package/dist/cjs/graphql/node-runner.js +0 -97
  60. package/dist/cjs/graphql/vite-plugin-cedar-auto-import.js +0 -107
  61. package/dist/cjs/index.js +0 -22
  62. package/dist/cjs/internal.d.ts +0 -28
  63. package/dist/cjs/internal.d.ts.map +0 -1
  64. package/dist/cjs/internal.js +0 -135
  65. package/dist/cjs/package.json +0 -1
  66. package/dist/cjs/runPrerender.d.ts.map +0 -1
  67. package/dist/cjs/runPrerender.js +0 -311
  68. package/dist/cjs/runPrerenderEsm.js +0 -308
  69. package/dist/runPrerenderEsm.d.ts +0 -9
  70. package/dist/runPrerenderEsm.d.ts.map +0 -1
  71. /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  72. /package/dist/{cjs/runPrerender.d.ts → runPrerender.d.ts} +0 -0
@@ -4,5 +4,5 @@ export declare const isBrowser: boolean;
4
4
  export declare const useIsBrowser: () => boolean;
5
5
  export declare const BrowserOnly: ({ children }: {
6
6
  children: ReactElement;
7
- }) => ReactElement<any, string | React.JSXElementConstructor<any>> | null;
7
+ }) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browserUtils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKzC,eAAO,MAAM,cAAc,QAAO,OAEjC,CAAA;AAED,eAAO,MAAM,SAAS,SAAoB,CAAA;AAE1C,eAAO,MAAM,YAAY,eAIxB,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,cAAc;IAAE,QAAQ,EAAE,YAAY,CAAA;CAAE,wEAInE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browserUtils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKzC,eAAO,MAAM,cAAc,QAAO,OAEjC,CAAA;AAED,eAAO,MAAM,SAAS,SAAoB,CAAA;AAE1C,eAAO,MAAM,YAAY,eAIxB,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,cAAc;IAAE,QAAQ,EAAE,YAAY,CAAA;CAAE,sFAInE,CAAA"}
@@ -7,6 +7,6 @@ interface Options {
7
7
  */
8
8
  preserveTemporaryFile?: boolean;
9
9
  }
10
- export declare function buildAndImport(options: Options): Promise<Record<string, React.FunctionComponent>>;
10
+ export declare function buildAndImport(options: Options): Promise<Record<string, React.ElementType>>;
11
11
  export {};
12
12
  //# sourceMappingURL=buildAndImport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildAndImport.d.ts","sourceRoot":"","sources":["../../src/build-and-import/buildAndImport.ts"],"names":[],"mappings":"AAqCA,UAAU,OAAO;IACf,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAsJlD"}
1
+ {"version":3,"file":"buildAndImport.d.ts","sourceRoot":"","sources":["../../src/build-and-import/buildAndImport.ts"],"names":[],"mappings":"AAqCA,UAAU,OAAO;IACf,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CA4I5C"}
@@ -7,7 +7,7 @@ import replace from "@rollup/plugin-replace";
7
7
  import { rollup } from "rollup";
8
8
  import { swc } from "rollup-plugin-swc3";
9
9
  import unimportPlugin from "unimport/unplugin";
10
- import { getConfig, getPaths, projectIsEsm } from "@cedarjs/project-config";
10
+ import { getConfig, getPaths } from "@cedarjs/project-config";
11
11
  import {
12
12
  getPathsFromTypeScriptConfig,
13
13
  parseTypeScriptConfigFiles
@@ -42,7 +42,6 @@ async function buildAndImport(options) {
42
42
  if (!fs.existsSync(outDir)) {
43
43
  fs.mkdirSync(outDir, { recursive: true });
44
44
  }
45
- const isEsm = projectIsEsm();
46
45
  const build = await rollup({
47
46
  input: [options.filepath],
48
47
  output: {
@@ -114,16 +113,10 @@ async function buildAndImport(options) {
114
113
  from: "react"
115
114
  },
116
115
  // import { gql } from 'graphql-tag'
117
- !useTrustedDocumentsGqlTag && isEsm && {
116
+ !useTrustedDocumentsGqlTag && {
118
117
  name: "gql",
119
118
  from: "graphql-tag"
120
119
  },
121
- // import gql from 'graphql-tag'
122
- !useTrustedDocumentsGqlTag && !isEsm && {
123
- name: "default",
124
- as: "gql",
125
- from: "graphql-tag"
126
- },
127
120
  // import { gql } from 'src/graphql/gql'
128
121
  useTrustedDocumentsGqlTag && {
129
122
  name: "gql",
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-cedarjs-routes-auto-loader.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAYpC,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAuBD,wBAAgB,6BAA6B,IAAI,MAAM,CAoJtD"}
1
+ {"version":3,"file":"rollup-plugin-cedarjs-routes-auto-loader.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAYpC,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAoBD,wBAAgB,6BAA6B,IAAI,MAAM,CAoJtD"}
@@ -1,5 +1,19 @@
1
1
  import type { DocumentNode } from 'graphql';
2
2
  export type FileImporter = (path: string) => Promise<any>;
3
+ /**
4
+ * The project's GraphQL API handler, wrapped so it can be called with a bare
5
+ * GraphQL operation. Resolves to the handler's response, whose `body` holds
6
+ * the JSON-encoded result.
7
+ */
8
+ export type GqlHandler = (operation: GqlOperation) => Promise<{
9
+ body?: string;
10
+ } | undefined>;
11
+ interface GqlOperation {
12
+ operationName: string;
13
+ query: string | undefined;
14
+ variables?: Record<string, unknown>;
15
+ extensions?: Record<string, unknown>;
16
+ }
3
17
  /**
4
18
  * Loads the graphql server, with all the user's settings
5
19
  * And execute the query against it
@@ -8,12 +22,13 @@ export type FileImporter = (path: string) => Promise<any>;
8
22
  * there is a GraphQL error. Instead, it returns the result with the graphql
9
23
  * error.
10
24
  */
11
- export declare function executeQuery(fileImporter: FileImporter, gqlHandler: (args: any) => Promise<any>, query: DocumentNode, variables?: Record<string, unknown>): Promise<any>;
25
+ export declare function executeQuery(fileImporter: FileImporter, gqlHandler: GqlHandler, query: DocumentNode, variables?: Record<string, unknown>): Promise<string | undefined>;
12
26
  /**
13
27
  * Finds the graphql handler, returns a function
14
28
  * that can be used to execute queries against it
15
29
  *
16
30
  * Throws GqlHandlerImportError, so that we can warn the user (but not blow up)
17
31
  */
18
- export declare function getGqlHandler(fileImporter: FileImporter): Promise<(operation: Record<string, unknown>) => Promise<any>>;
32
+ export declare function getGqlHandler(fileImporter: FileImporter): Promise<GqlHandler>;
33
+ export {};
19
34
  //# sourceMappingURL=graphql.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/graphql/graphql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AASzD;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EACvC,KAAK,EAAE,YAAY,EACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,gBAmCpC;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,YAAY,EAAE,YAAY,uBAMjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,mBAUnD"}
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/graphql/graphql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAEzD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,SAAS,EAAE,YAAY,KACpB,OAAO,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAAA;AAE3C,UAAU,YAAY;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,YAAY,EACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,+BAmCpC;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,UAAU,CAAC,CAgBrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./runPrerender.js";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runPrerender.d.ts","sourceRoot":"","sources":["../src/runPrerender.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA8Q7C,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACrC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,eAAO,MAAM,YAAY,GAAU,6BAGhC,eAAe,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAqIzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import React from "react";
4
- import * as apolloClient from "@apollo/client";
4
+ import { ApolloClient, ApolloLink, InMemoryCache } from "@apollo/client";
5
5
  import { load as loadHtml } from "cheerio";
6
6
  import ReactDOMServer from "react-dom/server";
7
7
  import {
@@ -21,9 +21,21 @@ import {
21
21
  import { executeQuery, getGqlHandler } from "./graphql/graphql.js";
22
22
  import { NodeRunner } from "./graphql/node-runner.js";
23
23
  import { getRootHtmlPath, registerShims, writeToDist } from "./internal.js";
24
- const { ApolloClient, InMemoryCache } = apolloClient.default;
25
- const prerenderApolloClient = new ApolloClient({ cache: new InMemoryCache() });
26
- async function recursivelyRender(App, Routes, CellCacheContextProvider, LocationProvider, renderPath, fileImporter, gqlHandler, queryCache) {
24
+ const prerenderApolloClient = new ApolloClient({
25
+ cache: new InMemoryCache(),
26
+ link: ApolloLink.empty()
27
+ });
28
+ async function recursivelyRender(args) {
29
+ const {
30
+ App,
31
+ Routes,
32
+ CellCacheContextProvider,
33
+ LocationProvider,
34
+ renderPath,
35
+ fileImporter,
36
+ gqlHandler,
37
+ queryCache
38
+ } = args;
27
39
  const { getOperationName } = await import("@cedarjs/web");
28
40
  let shouldShowGraphqlHandlerNotFoundWarn = false;
29
41
  await Promise.all(
@@ -40,13 +52,13 @@ async function recursivelyRender(App, Routes, CellCacheContextProvider, Location
40
52
  );
41
53
  let result;
42
54
  try {
43
- result = JSON.parse(resultString);
55
+ result = JSON.parse(resultString ?? "");
44
56
  } catch (e) {
45
57
  if (e instanceof SyntaxError) {
46
58
  throw new JSONParseError({
47
59
  query: value.query,
48
60
  variables: value.variables,
49
- result: resultString
61
+ result: resultString ?? ""
50
62
  });
51
63
  }
52
64
  }
@@ -90,16 +102,7 @@ async function recursivelyRender(App, Routes, CellCacheContextProvider, Location
90
102
  /* @__PURE__ */ React.createElement(LocationProvider, { location: new URL(prerenderUrl) }, /* @__PURE__ */ React.createElement(CellCacheContextProvider, { queryCache }, /* @__PURE__ */ React.createElement(App, null, /* @__PURE__ */ React.createElement(Routes, null))))
91
103
  );
92
104
  if (Object.values(queryCache).some((value) => !value.hasProcessed)) {
93
- return recursivelyRender(
94
- App,
95
- Routes,
96
- CellCacheContextProvider,
97
- LocationProvider,
98
- renderPath,
99
- fileImporter,
100
- gqlHandler,
101
- queryCache
102
- );
105
+ return recursivelyRender(args);
103
106
  } else {
104
107
  if (shouldShowGraphqlHandlerNotFoundWarn) {
105
108
  console.warn(
@@ -181,48 +184,54 @@ const runPrerender = async ({
181
184
  }) => {
182
185
  registerShims(renderPath);
183
186
  const nodeRunner = new NodeRunner();
184
- const gqlHandler = await getGqlHandler(nodeRunner.importFile.bind(nodeRunner));
185
- const prerenderDistPath = path.join(getPaths().web.dist, "__prerender");
186
- fs.mkdirSync(prerenderDistPath, { recursive: true });
187
- if (!renderCache.App) {
188
- const entryPath = await createCombinedEntry({
189
- appPath: getPaths().web.app,
190
- routesPath: getPaths().web.routes,
191
- outDir: prerenderDistPath
192
- });
193
- const required = await buildAndImport({
194
- filepath: entryPath,
195
- preserveTemporaryFile: true
187
+ let componentAsHtml;
188
+ try {
189
+ const gqlHandler = await getGqlHandler(
190
+ nodeRunner.importFile.bind(nodeRunner)
191
+ );
192
+ const prerenderDistPath = path.join(getPaths().web.dist, "__prerender");
193
+ fs.mkdirSync(prerenderDistPath, { recursive: true });
194
+ if (!renderCache.App) {
195
+ const entryPath = await createCombinedEntry({
196
+ appPath: getPaths().web.app,
197
+ routesPath: getPaths().web.routes,
198
+ outDir: prerenderDistPath
199
+ });
200
+ const required = await buildAndImport({
201
+ filepath: entryPath,
202
+ preserveTemporaryFile: true
203
+ });
204
+ renderCache.App = required.App;
205
+ renderCache.Routes = required.Routes;
206
+ renderCache.CellCacheContextProvider = required.CellCacheContextProvider;
207
+ renderCache.LocationProvider = required.LocationProvider;
208
+ }
209
+ const { LocationProvider, App, Routes, CellCacheContextProvider } = renderCache;
210
+ if (!App) {
211
+ throw new Error("App not found");
212
+ }
213
+ if (!Routes) {
214
+ throw new Error("Routes not found");
215
+ }
216
+ if (!CellCacheContextProvider) {
217
+ throw new Error("CellCacheContextProvider not found");
218
+ }
219
+ if (!LocationProvider) {
220
+ throw new Error("LocationProvider not found");
221
+ }
222
+ componentAsHtml = await recursivelyRender({
223
+ App,
224
+ Routes,
225
+ CellCacheContextProvider,
226
+ LocationProvider,
227
+ renderPath,
228
+ fileImporter: nodeRunner.importFile.bind(nodeRunner),
229
+ gqlHandler,
230
+ queryCache
196
231
  });
197
- renderCache.App = required.App;
198
- renderCache.Routes = required.Routes;
199
- renderCache.CellCacheContextProvider = required.CellCacheContextProvider;
200
- renderCache.LocationProvider = required.LocationProvider;
201
- }
202
- const { LocationProvider, App, Routes, CellCacheContextProvider } = renderCache;
203
- if (!App) {
204
- throw new Error("App not found");
205
- }
206
- if (!Routes) {
207
- throw new Error("Routes not found");
232
+ } finally {
233
+ await nodeRunner.close();
208
234
  }
209
- if (!CellCacheContextProvider) {
210
- throw new Error("CellCacheContextProvider not found");
211
- }
212
- if (!LocationProvider) {
213
- throw new Error("LocationProvider not found");
214
- }
215
- const componentAsHtml = await recursivelyRender(
216
- App,
217
- Routes,
218
- CellCacheContextProvider,
219
- LocationProvider,
220
- renderPath,
221
- nodeRunner.importFile.bind(nodeRunner),
222
- gqlHandler,
223
- queryCache
224
- );
225
- nodeRunner.close();
226
235
  const { helmet } = globalThis.__REDWOOD__HELMET_CONTEXT;
227
236
  Object.keys(queryCache).forEach((queryKey) => {
228
237
  const { query, variables, data } = queryCache[queryKey];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/prerender",
3
- "version": "7.0.0",
3
+ "version": "8.0.0-canary.3263",
4
4
  "description": "CedarJS prerender",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,46 +11,18 @@
11
11
  "type": "module",
12
12
  "exports": {
13
13
  ".": {
14
- "import": {
15
- "types": "./dist/runPrerenderEsm.d.ts",
16
- "default": "./dist/runPrerenderEsm.js"
17
- },
18
- "require": {
19
- "types": "./dist/cjs/runPrerender.d.ts",
20
- "default": "./dist/cjs/runPrerender.js"
21
- }
22
- },
23
- "./cjs": {
24
- "types": "./dist/cjs/runPrerender.d.ts",
25
- "default": "./dist/cjs/runPrerender.js"
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
26
16
  },
27
17
  "./browserUtils": {
28
- "import": {
29
- "types": "./dist/browserUtils/index.d.ts",
30
- "default": "./dist/browserUtils/index.js"
31
- },
32
- "require": {
33
- "types": "./dist/cjs/browserUtils/index.d.ts",
34
- "default": "./dist/cjs/browserUtils/index.js"
35
- }
18
+ "types": "./dist/browserUtils/index.d.ts",
19
+ "default": "./dist/browserUtils/index.js"
36
20
  },
37
21
  "./detection": {
38
- "import": {
39
- "types": "./dist/detection/detection.d.ts",
40
- "default": "./dist/detection/detection.js"
41
- },
42
- "require": {
43
- "types": "./dist/cjs/detection/detection.d.ts",
44
- "default": "./dist/cjs/detection/detection.js"
45
- }
46
- },
47
- "./cjs/detection": {
48
- "types": "./dist/cjs/detection/detection.d.ts",
49
- "default": "./dist/cjs/detection/detection.js"
22
+ "types": "./dist/detection/detection.d.ts",
23
+ "default": "./dist/detection/detection.js"
50
24
  }
51
25
  },
52
- "main": "dist/cjs/index.js",
53
- "types": "./dist/cjs/index.d.ts",
54
26
  "files": [
55
27
  "dist"
56
28
  ],
@@ -58,7 +30,6 @@
58
30
  "build": "node ./build.mts && yarn build:types",
59
31
  "build:pack": "yarn pack -o cedarjs-prerender.tgz",
60
32
  "build:types": "tsc --build --verbose ./tsconfig.build.json",
61
- "build:types-cjs": "tsc --build --verbose ./tsconfig.cjs.json",
62
33
  "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
63
34
  "check:attw": "yarn cedar-fwtools-attw",
64
35
  "check:package": "concurrently npm:check:attw yarn:publint",
@@ -70,17 +41,16 @@
70
41
  "@babel/generator": "7.29.8",
71
42
  "@babel/parser": "7.29.9",
72
43
  "@babel/traverse": "7.29.8",
73
- "@cedarjs/babel-config": "7.0.0",
74
- "@cedarjs/project-config": "7.0.0",
75
- "@cedarjs/structure": "7.0.0",
76
- "@cedarjs/vite": "7.0.0",
44
+ "@babel/types": "7.29.8",
45
+ "@cedarjs/project-config": "8.0.0-canary.3263",
46
+ "@cedarjs/structure": "8.0.0-canary.3263",
47
+ "@cedarjs/vite": "8.0.0-canary.3263",
77
48
  "@rollup/plugin-alias": "5.1.1",
78
49
  "@rollup/plugin-commonjs": "28.0.9",
79
50
  "@rollup/plugin-node-resolve": "16.0.3",
80
51
  "@rollup/plugin-replace": "6.0.3",
81
52
  "@swc/core": "1.16.2",
82
- "@whatwg-node/fetch": "0.10.13",
83
- "babel-plugin-ignore-html-and-css-imports": "0.1.0",
53
+ "@whatwg-node/fetch": "0.12.0",
84
54
  "cheerio": "1.2.0",
85
55
  "graphql": "16.14.2",
86
56
  "mime-types": "2.1.35",
@@ -91,22 +61,21 @@
91
61
  "vite": "7.3.6"
92
62
  },
93
63
  "devDependencies": {
94
- "@cedarjs/framework-tools": "7.0.0",
95
- "@cedarjs/router": "7.0.0",
96
- "@cedarjs/web": "7.0.0",
64
+ "@cedarjs/framework-tools": "8.0.0-canary.3263",
65
+ "@cedarjs/router": "8.0.0-canary.3263",
66
+ "@cedarjs/web": "8.0.0-canary.3263",
97
67
  "@types/mime-types": "2.1.4",
98
- "@types/react": "^18.2.55",
99
- "babel-plugin-tester": "11.0.4",
68
+ "@types/react": "^19.2.0",
100
69
  "concurrently": "9.2.4",
101
70
  "publint": "0.3.24",
102
71
  "typescript": "5.9.3",
103
72
  "vitest": "4.1.11"
104
73
  },
105
74
  "peerDependencies": {
106
- "@cedarjs/router": "7.0.0",
107
- "@cedarjs/web": "7.0.0",
108
- "react": "18.3.1",
109
- "react-dom": "18.3.1"
75
+ "@cedarjs/router": "8.0.0-canary.3263",
76
+ "@cedarjs/web": "8.0.0-canary.3263",
77
+ "react": "19.3.0",
78
+ "react-dom": "19.3.0"
110
79
  },
111
80
  "engines": {
112
81
  "node": ">=24"
@@ -1,5 +0,0 @@
1
- import type { PluginObj, types } from '@babel/core';
2
- export declare function babelPluginRedwoodCell({ types: t, }: {
3
- types: typeof types;
4
- }): PluginObj;
5
- //# sourceMappingURL=babel-plugin-redwood-cell.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-redwood-cell.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/babel-plugin-redwood-cell.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAgCnD,wBAAgB,sBAAsB,CAAC,EACrC,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAmHZ"}
@@ -1,98 +0,0 @@
1
- import { parse } from "path";
2
- const EXPECTED_EXPORTS_FROM_CELL = [
3
- "beforeQuery",
4
- "QUERY",
5
- "FRAGMENT",
6
- "data",
7
- "isEmpty",
8
- "afterQuery",
9
- "Loading",
10
- "Success",
11
- "Failure",
12
- "Empty"
13
- ];
14
- function babelPluginRedwoodCell({
15
- types: t
16
- }) {
17
- let exportNames = [];
18
- let hasDefaultExport = false;
19
- return {
20
- name: "babel-plugin-redwood-cell",
21
- visitor: {
22
- ExportDefaultDeclaration() {
23
- hasDefaultExport = true;
24
- },
25
- ExportNamedDeclaration(path) {
26
- const declaration = path.node.declaration;
27
- if (!declaration) {
28
- return;
29
- }
30
- let name;
31
- if (declaration.type === "VariableDeclaration") {
32
- const id = declaration.declarations[0].id;
33
- name = id.name;
34
- }
35
- if (declaration.type === "FunctionDeclaration") {
36
- name = declaration?.id?.name;
37
- }
38
- if (name && EXPECTED_EXPORTS_FROM_CELL.includes(name)) {
39
- exportNames.push(name);
40
- }
41
- },
42
- Program: {
43
- enter() {
44
- exportNames = [];
45
- hasDefaultExport = false;
46
- },
47
- exit(path) {
48
- const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("FRAGMENT") || exportNames.includes("data");
49
- if (hasDefaultExport || !hasQueryOrDataExport) {
50
- return;
51
- }
52
- const createCellHookName = exportNames.includes("data") ? "createServerCell" : "createCell";
53
- const importFrom = exportNames.includes("data") ? "@cedarjs/web/dist/components/cell/createServerCell" : "@cedarjs/web";
54
- path.node.body.unshift(
55
- t.importDeclaration(
56
- [
57
- t.importSpecifier(
58
- t.identifier(createCellHookName),
59
- t.identifier(createCellHookName)
60
- )
61
- ],
62
- t.stringLiteral(importFrom)
63
- )
64
- );
65
- path.node.body.push(
66
- t.exportDefaultDeclaration(
67
- t.callExpression(t.identifier(createCellHookName), [
68
- t.objectExpression([
69
- ...exportNames.map(
70
- (name) => t.objectProperty(
71
- t.identifier(name),
72
- t.identifier(name),
73
- false,
74
- true
75
- )
76
- ),
77
- // Add the `displayName` property so we can name the Cell
78
- // after the filename.
79
- t.objectProperty(
80
- t.identifier("displayName"),
81
- t.stringLiteral(
82
- parse(this.file.opts.filename).name
83
- ),
84
- false,
85
- true
86
- )
87
- ])
88
- ])
89
- )
90
- );
91
- }
92
- }
93
- }
94
- };
95
- }
96
- export {
97
- babelPluginRedwoodCell
98
- };
@@ -1,5 +0,0 @@
1
- import type { PluginObj, types } from '@babel/core';
2
- export declare function babelPluginRedwoodPrerenderMediaImports({ types: t, }: {
3
- types: typeof types;
4
- }): PluginObj;
5
- //# sourceMappingURL=babel-plugin-redwood-prerender-media-imports.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babel-plugin-redwood-prerender-media-imports.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/babel-plugin-redwood-prerender-media-imports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAY,MAAM,aAAa,CAAA;AAuC7D,wBAAgB,uCAAuC,CAAC,EACtD,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAqDZ"}
@@ -1,77 +0,0 @@
1
- import { extname, join, relative, dirname } from "path";
2
- import { ensurePosixPath, getPaths } from "@cedarjs/project-config";
3
- import { convertToDataUrl } from "./utils.js";
4
- const defaultOptions = {
5
- // Media file extensions that Vite emits as assets, and that we therefore
6
- // have to resolve to their built asset path (or a data URL) when prerendering
7
- extensions: [
8
- ".ico",
9
- ".jpg",
10
- ".jpeg",
11
- ".png",
12
- ".gif",
13
- ".svg",
14
- ".eot",
15
- ".otf",
16
- ".webp",
17
- ".ttf",
18
- ".woff",
19
- ".woff2",
20
- ".cur",
21
- ".ani",
22
- ".pdf",
23
- ".bmp"
24
- ]
25
- };
26
- function getVariableName(p) {
27
- if (p.node.specifiers?.[0]?.local) {
28
- return p.node.specifiers[0].local.name;
29
- }
30
- return null;
31
- }
32
- function babelPluginRedwoodPrerenderMediaImports({
33
- types: t
34
- }) {
35
- const manifestPath = join(getPaths().web.dist, "client-build-manifest.json");
36
- const buildManifest = require(manifestPath);
37
- return {
38
- name: "babel-plugin-redwood-prerender-media-imports",
39
- visitor: {
40
- ImportDeclaration(p, state) {
41
- const importPath = p.node.source.value;
42
- const ext = extname(importPath);
43
- const options = {
44
- ...defaultOptions,
45
- ...state.opts
46
- };
47
- if (ext && options.extensions.includes(ext)) {
48
- const importConstName = getVariableName(p);
49
- if (state.filename === void 0) {
50
- return;
51
- }
52
- const absPath = join(dirname(state.filename), p.node.source.value);
53
- const viteManifestKey = ensurePosixPath(
54
- relative(getPaths().web.src, absPath)
55
- );
56
- const copiedAssetPath = buildManifest[viteManifestKey]?.file;
57
- const assetSrc = copiedAssetPath ?? convertToDataUrl(
58
- join(state.file.opts.sourceRoot || "./", importPath)
59
- );
60
- if (importConstName) {
61
- p.replaceWith(
62
- t.variableDeclaration("const", [
63
- t.variableDeclarator(
64
- t.identifier(importConstName),
65
- t.stringLiteral(assetSrc)
66
- )
67
- ])
68
- );
69
- }
70
- }
71
- }
72
- }
73
- };
74
- }
75
- export {
76
- babelPluginRedwoodPrerenderMediaImports
77
- };
@@ -1,2 +0,0 @@
1
- export declare function convertToDataUrl(assetPath: string): string;
2
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/utils.ts"],"names":[],"mappings":"AAQA,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,UASjD"}
@@ -1,15 +0,0 @@
1
- import fs from "node:fs";
2
- import mime from "mime-types";
3
- function convertToDataUrl(assetPath) {
4
- try {
5
- const base64AssetContents = fs.readFileSync(assetPath, "base64");
6
- const mimeType = mime.lookup(assetPath);
7
- return `data:${mimeType};base64,${base64AssetContents}`;
8
- } catch {
9
- console.warn(`Could not read file ${assetPath} for conversion to data uri`);
10
- return "";
11
- }
12
- }
13
- export {
14
- convertToDataUrl
15
- };
@@ -1,13 +0,0 @@
1
- /**
2
- * Whether an extracted Apollo cache state is non-empty and worth inlining
3
- * into the prerendered HTML as a bootstrap `<script>`.
4
- *
5
- * Only emit the Apollo state bootstrap when there is state to restore. Both
6
- * consumers (`CedarApolloProvider` and the suspense provider) already do
7
- * `.restore(globalThis?.__CEDAR__APOLLO_STATE ?? {})`, so an empty payload is
8
- * a no-op. It is still an inline `<script>` though, which every strict-CSP app
9
- * has to allow-list with a hash that goes stale whenever the payload changes.
10
- * A page that prerenders no Cells emits nothing.
11
- */
12
- export declare function hasApolloState(state: unknown): state is Record<string, unknown>;
13
- //# sourceMappingURL=apolloState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apolloState.d.ts","sourceRoot":"","sources":["../../src/apolloState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIlC"}