@cedarjs/prerender 0.9.1-next.0 → 0.9.1-next.20
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/dist/browserUtils/index.js +4 -31
- package/dist/build-and-import/buildAndImport.d.ts +12 -0
- package/dist/build-and-import/buildAndImport.d.ts.map +1 -0
- package/dist/build-and-import/buildAndImport.js +142 -0
- package/dist/build-and-import/load-tsconfig.d.js +0 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.d.ts +23 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +149 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.d.ts +3 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js +49 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.d.ts +9 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.js +91 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts +24 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js +24 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.d.ts +3 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js +32 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts +25 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js +84 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.d.ts +6 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js +117 -0
- package/dist/build-and-import/rollupPlugins/utils.d.ts +3 -0
- package/dist/build-and-import/rollupPlugins/utils.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/utils.js +43 -0
- package/dist/build-and-import/utils.d.ts +14 -0
- package/dist/build-and-import/utils.d.ts.map +1 -0
- package/dist/build-and-import/utils.js +30 -0
- package/dist/detection/{index.d.ts → detection.d.ts} +1 -1
- package/dist/detection/detection.d.ts.map +1 -0
- package/dist/detection/detection.js +24 -0
- package/dist/errors.js +4 -30
- package/dist/graphql/graphql.d.ts +5 -5
- package/dist/graphql/graphql.d.ts.map +1 -1
- package/dist/graphql/graphql.js +17 -52
- package/dist/graphql/node-runner.d.ts +11 -0
- package/dist/graphql/node-runner.d.ts.map +1 -0
- package/dist/graphql/node-runner.js +90 -0
- package/dist/graphql/vite-plugin-cedar-auto-import.d.ts +2 -0
- package/dist/graphql/vite-plugin-cedar-auto-import.d.ts.map +1 -0
- package/dist/graphql/vite-plugin-cedar-auto-import.js +77 -0
- package/dist/graphql/vite-plugin-cedar-import-dir.d.ts +19 -0
- package/dist/graphql/vite-plugin-cedar-import-dir.d.ts.map +1 -0
- package/dist/graphql/vite-plugin-cedar-import-dir.js +84 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -22
- package/dist/internal.d.ts +24 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +66 -52
- package/dist/runPrerender.d.ts.map +1 -1
- package/dist/runPrerender.js +116 -137
- package/package.json +24 -12
- package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -5
- package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
- package/dist/babelPlugins/babel-plugin-redwood-cell.js +0 -115
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +0 -5
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +0 -1
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +0 -94
- package/dist/babelPlugins/utils.d.ts +0 -2
- package/dist/babelPlugins/utils.d.ts.map +0 -1
- package/dist/babelPlugins/utils.js +0 -49
- package/dist/detection/index.d.ts.map +0 -1
- package/dist/detection/index.js +0 -48
package/dist/runPrerender.js
CHANGED
|
@@ -1,56 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var runPrerender_exports = {};
|
|
30
|
-
__export(runPrerender_exports, {
|
|
31
|
-
runPrerender: () => runPrerender,
|
|
32
|
-
writePrerenderedHtmlFile: () => writePrerenderedHtmlFile
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(runPrerender_exports);
|
|
35
|
-
var import_fs = __toESM(require("fs"));
|
|
36
|
-
var import_path = __toESM(require("path"));
|
|
37
|
-
var import_react = __toESM(require("react"));
|
|
38
|
-
var import_client = require("@apollo/client");
|
|
39
|
-
var import_cheerio = require("cheerio");
|
|
40
|
-
var import_server = __toESM(require("react-dom/server"));
|
|
41
|
-
var import_babel_config = require("@cedarjs/babel-config");
|
|
42
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
43
|
-
var import_router = require("@cedarjs/router");
|
|
44
|
-
var import_util = require("@cedarjs/router/dist/util");
|
|
45
|
-
var import_babel_plugin_redwood_cell = __toESM(require("./babelPlugins/babel-plugin-redwood-cell"));
|
|
46
|
-
var import_babel_plugin_redwood_prerender_media_imports = __toESM(require("./babelPlugins/babel-plugin-redwood-prerender-media-imports"));
|
|
47
|
-
var import_detection = require("./detection");
|
|
48
|
-
var import_errors = require("./errors");
|
|
49
|
-
var import_graphql = require("./graphql/graphql");
|
|
50
|
-
var import_internal = require("./internal");
|
|
51
|
-
const prerenderApolloClient = new import_client.ApolloClient({ cache: new import_client.InMemoryCache() });
|
|
52
|
-
async function recursivelyRender(App, Routes, renderPath, gqlHandler, queryCache) {
|
|
53
|
-
const { CellCacheContextProvider, getOperationName } = require("@cedarjs/web");
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import * as apolloClient from "@apollo/client";
|
|
5
|
+
import { load as loadHtml } from "cheerio";
|
|
6
|
+
import ReactDOMServer from "react-dom/server";
|
|
7
|
+
import {
|
|
8
|
+
getPaths,
|
|
9
|
+
ensurePosixPath,
|
|
10
|
+
importStatementPath
|
|
11
|
+
} from "@cedarjs/project-config";
|
|
12
|
+
import { matchPath } from "@cedarjs/router/dist/util";
|
|
13
|
+
import { buildAndImport } from "./build-and-import/buildAndImport.js";
|
|
14
|
+
import { detectPrerenderRoutes } from "./detection/detection.js";
|
|
15
|
+
import {
|
|
16
|
+
GqlHandlerImportError,
|
|
17
|
+
JSONParseError,
|
|
18
|
+
PrerenderGqlError
|
|
19
|
+
} from "./errors.js";
|
|
20
|
+
import { executeQuery, getGqlHandler } from "./graphql/graphql.js";
|
|
21
|
+
import { NodeRunner } from "./graphql/node-runner.js";
|
|
22
|
+
import { getRootHtmlPath, registerShims, writeToDist } from "./internal.js";
|
|
23
|
+
const { ApolloClient, InMemoryCache } = apolloClient.default;
|
|
24
|
+
const prerenderApolloClient = new ApolloClient({ cache: new InMemoryCache() });
|
|
25
|
+
async function recursivelyRender(App, Routes, CellCacheContextProvider, LocationProvider, renderPath, nodeRunner, gqlHandler, queryCache) {
|
|
26
|
+
const { getOperationName } = await import("@cedarjs/web");
|
|
54
27
|
let shouldShowGraphqlHandlerNotFoundWarn = false;
|
|
55
28
|
await Promise.all(
|
|
56
29
|
Object.entries(queryCache).map(async ([cacheKey, value]) => {
|
|
@@ -58,7 +31,8 @@ async function recursivelyRender(App, Routes, renderPath, gqlHandler, queryCache
|
|
|
58
31
|
return Promise.resolve("");
|
|
59
32
|
}
|
|
60
33
|
try {
|
|
61
|
-
const resultString = await
|
|
34
|
+
const resultString = await executeQuery(
|
|
35
|
+
nodeRunner,
|
|
62
36
|
gqlHandler,
|
|
63
37
|
value.query,
|
|
64
38
|
value.variables
|
|
@@ -68,7 +42,7 @@ async function recursivelyRender(App, Routes, renderPath, gqlHandler, queryCache
|
|
|
68
42
|
result = JSON.parse(resultString);
|
|
69
43
|
} catch (e) {
|
|
70
44
|
if (e instanceof SyntaxError) {
|
|
71
|
-
throw new
|
|
45
|
+
throw new JSONParseError({
|
|
72
46
|
query: value.query,
|
|
73
47
|
variables: value.variables,
|
|
74
48
|
result: resultString
|
|
@@ -78,16 +52,15 @@ async function recursivelyRender(App, Routes, renderPath, gqlHandler, queryCache
|
|
|
78
52
|
if (result.errors) {
|
|
79
53
|
const message = result.errors[0].message ?? JSON.stringify(result.errors, null, 4);
|
|
80
54
|
if (result.errors[0]?.extensions?.code === "UNAUTHENTICATED") {
|
|
55
|
+
const queryName = getOperationName(value.query);
|
|
81
56
|
console.error(
|
|
82
57
|
`
|
|
83
58
|
|
|
84
|
-
\u{1F6D1} Cannot prerender the query ${
|
|
85
|
-
value.query
|
|
86
|
-
)} as it requires auth.
|
|
59
|
+
\u{1F6D1} Cannot prerender the query ${queryName} as it requires auth.
|
|
87
60
|
`
|
|
88
61
|
);
|
|
89
62
|
}
|
|
90
|
-
throw new
|
|
63
|
+
throw new PrerenderGqlError(message);
|
|
91
64
|
}
|
|
92
65
|
queryCache[cacheKey] = {
|
|
93
66
|
...value,
|
|
@@ -96,7 +69,7 @@ async function recursivelyRender(App, Routes, renderPath, gqlHandler, queryCache
|
|
|
96
69
|
};
|
|
97
70
|
return result;
|
|
98
71
|
} catch (e) {
|
|
99
|
-
if (e instanceof
|
|
72
|
+
if (e instanceof GqlHandlerImportError) {
|
|
100
73
|
shouldShowGraphqlHandlerNotFoundWarn = true;
|
|
101
74
|
queryCache[cacheKey] = {
|
|
102
75
|
...value,
|
|
@@ -112,11 +85,20 @@ async function recursivelyRender(App, Routes, renderPath, gqlHandler, queryCache
|
|
|
112
85
|
})
|
|
113
86
|
);
|
|
114
87
|
const prerenderUrl = process.env.RWJS_PRERENDER_ORIGIN || "http://localhost" + renderPath;
|
|
115
|
-
const componentAsHtml =
|
|
116
|
-
/* @__PURE__ */
|
|
88
|
+
const componentAsHtml = ReactDOMServer.renderToString(
|
|
89
|
+
/* @__PURE__ */ React.createElement(LocationProvider, { location: new URL(prerenderUrl) }, /* @__PURE__ */ React.createElement(CellCacheContextProvider, { queryCache }, /* @__PURE__ */ React.createElement(App, null, /* @__PURE__ */ React.createElement(Routes, null))))
|
|
117
90
|
);
|
|
118
91
|
if (Object.values(queryCache).some((value) => !value.hasProcessed)) {
|
|
119
|
-
return recursivelyRender(
|
|
92
|
+
return recursivelyRender(
|
|
93
|
+
App,
|
|
94
|
+
Routes,
|
|
95
|
+
CellCacheContextProvider,
|
|
96
|
+
LocationProvider,
|
|
97
|
+
renderPath,
|
|
98
|
+
nodeRunner,
|
|
99
|
+
gqlHandler,
|
|
100
|
+
queryCache
|
|
101
|
+
);
|
|
120
102
|
} else {
|
|
121
103
|
if (shouldShowGraphqlHandlerNotFoundWarn) {
|
|
122
104
|
console.warn(
|
|
@@ -127,12 +109,12 @@ async function recursivelyRender(App, Routes, renderPath, gqlHandler, queryCache
|
|
|
127
109
|
}
|
|
128
110
|
}
|
|
129
111
|
function insertChunkLoadingScript(indexHtmlTree, renderPath) {
|
|
130
|
-
const prerenderRoutes =
|
|
112
|
+
const prerenderRoutes = detectPrerenderRoutes();
|
|
131
113
|
const route = prerenderRoutes.find((route2) => {
|
|
132
114
|
if (!route2.routePath) {
|
|
133
115
|
return false;
|
|
134
116
|
}
|
|
135
|
-
return
|
|
117
|
+
return matchPath(route2.routePath, renderPath).match;
|
|
136
118
|
});
|
|
137
119
|
if (!route) {
|
|
138
120
|
throw new Error("Could not find a Route matching " + renderPath);
|
|
@@ -141,15 +123,15 @@ function insertChunkLoadingScript(indexHtmlTree, renderPath) {
|
|
|
141
123
|
throw new Error(`Route for ${renderPath} has no pageIdentifier`);
|
|
142
124
|
}
|
|
143
125
|
const buildManifest = JSON.parse(
|
|
144
|
-
|
|
145
|
-
|
|
126
|
+
fs.readFileSync(
|
|
127
|
+
path.join(getPaths().web.dist, "client-build-manifest.json"),
|
|
146
128
|
"utf-8"
|
|
147
129
|
)
|
|
148
130
|
);
|
|
149
131
|
const chunkPaths = [];
|
|
150
132
|
if (route?.filePath) {
|
|
151
|
-
const pagesIndex = route.filePath.indexOf(
|
|
152
|
-
const pagePath =
|
|
133
|
+
const pagesIndex = route.filePath.indexOf(path.join("web", "src", "pages")) + 8;
|
|
134
|
+
const pagePath = ensurePosixPath(route.filePath.slice(pagesIndex));
|
|
153
135
|
const pageChunkPath = buildManifest[pagePath]?.file;
|
|
154
136
|
if (pageChunkPath) {
|
|
155
137
|
chunkPaths.push("/" + pageChunkPath);
|
|
@@ -164,12 +146,12 @@ function insertChunkLoadingScript(indexHtmlTree, renderPath) {
|
|
|
164
146
|
);
|
|
165
147
|
});
|
|
166
148
|
chunkPaths.forEach((chunkPath) => {
|
|
167
|
-
const fullChunkPath =
|
|
168
|
-
const jsChunk =
|
|
149
|
+
const fullChunkPath = path.join(getPaths().web.dist, chunkPath);
|
|
150
|
+
const jsChunk = fs.readFileSync(fullChunkPath, "utf-8");
|
|
169
151
|
const matches = jsChunk.match(/export\s*\{\s*\w+ as default\s*\}/g) || [];
|
|
170
152
|
const lastIndex = jsChunk.lastIndexOf(matches[matches.length - 1]);
|
|
171
153
|
const varNameMatch = jsChunk.slice(lastIndex).match(/export\s*\{\s*(\w+) as default\s*\}/);
|
|
172
|
-
|
|
154
|
+
fs.writeFileSync(
|
|
173
155
|
fullChunkPath,
|
|
174
156
|
jsChunk + `globalThis.__REDWOOD__PRERENDER_PAGES = globalThis.__REDWOOD__PRERENDER_PAGES || {};
|
|
175
157
|
globalThis.__REDWOOD__PRERENDER_PAGES.${route?.pageIdentifier}=${varNameMatch?.[1]};
|
|
@@ -177,72 +159,69 @@ globalThis.__REDWOOD__PRERENDER_PAGES.${route?.pageIdentifier}=${varNameMatch?.[
|
|
|
177
159
|
);
|
|
178
160
|
});
|
|
179
161
|
}
|
|
162
|
+
async function createCombinedEntry({ appPath, routesPath, outDir }) {
|
|
163
|
+
const combinedContent = `
|
|
164
|
+
import { LocationProvider } from '@cedarjs/router'
|
|
165
|
+
import { CellCacheContextProvider } from '@cedarjs/web'
|
|
166
|
+
|
|
167
|
+
import App from "${importStatementPath(appPath.replace(".tsx", ""))}";
|
|
168
|
+
import Routes from "${importStatementPath(routesPath.replace(".tsx", ""))}";
|
|
169
|
+
|
|
170
|
+
export { LocationProvider, CellCacheContextProvider, App, Routes };
|
|
171
|
+
`;
|
|
172
|
+
const tempFilePath = path.join(outDir, "__prerender-temp-entry.tsx");
|
|
173
|
+
await fs.promises.writeFile(tempFilePath, combinedContent, "utf8");
|
|
174
|
+
return tempFilePath;
|
|
175
|
+
}
|
|
176
|
+
const renderCache = {};
|
|
180
177
|
const runPrerender = async ({
|
|
181
178
|
queryCache,
|
|
182
179
|
renderPath
|
|
183
180
|
}) => {
|
|
184
|
-
|
|
185
|
-
(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
const gqlHandler = await (0, import_graphql.getGqlHandler)();
|
|
218
|
-
(0, import_babel_config.registerWebSideBabelHook)({
|
|
219
|
-
overrides: [
|
|
220
|
-
{
|
|
221
|
-
plugins: [
|
|
222
|
-
["ignore-html-and-css-imports"],
|
|
223
|
-
// webpack/postcss handles CSS imports
|
|
224
|
-
[import_babel_plugin_redwood_prerender_media_imports.default]
|
|
225
|
-
]
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
test: /.+Cell.(js|tsx|jsx)$/,
|
|
229
|
-
plugins: [import_babel_plugin_redwood_cell.default]
|
|
230
|
-
}
|
|
231
|
-
],
|
|
232
|
-
options: {
|
|
233
|
-
forPrerender: true
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
const indexContent = import_fs.default.readFileSync((0, import_internal.getRootHtmlPath)()).toString();
|
|
237
|
-
const { default: App } = require((0, import_project_config.getPaths)().web.app);
|
|
238
|
-
const { default: Routes } = require((0, import_project_config.getPaths)().web.routes);
|
|
181
|
+
registerShims(renderPath);
|
|
182
|
+
const nodeRunner = new NodeRunner();
|
|
183
|
+
const gqlHandler = await getGqlHandler(nodeRunner);
|
|
184
|
+
const prerenderDistPath = path.join(getPaths().web.dist, "__prerender");
|
|
185
|
+
fs.mkdirSync(prerenderDistPath, { recursive: true });
|
|
186
|
+
if (!renderCache.App) {
|
|
187
|
+
const entryPath = await createCombinedEntry({
|
|
188
|
+
appPath: getPaths().web.app,
|
|
189
|
+
routesPath: getPaths().web.routes,
|
|
190
|
+
outDir: prerenderDistPath
|
|
191
|
+
});
|
|
192
|
+
const required = await buildAndImport({
|
|
193
|
+
filepath: entryPath,
|
|
194
|
+
preserveTemporaryFile: true
|
|
195
|
+
});
|
|
196
|
+
renderCache.App = required.App;
|
|
197
|
+
renderCache.Routes = required.Routes;
|
|
198
|
+
renderCache.CellCacheContextProvider = required.CellCacheContextProvider;
|
|
199
|
+
renderCache.LocationProvider = required.LocationProvider;
|
|
200
|
+
}
|
|
201
|
+
const { LocationProvider, App, Routes, CellCacheContextProvider } = renderCache;
|
|
202
|
+
if (!App) {
|
|
203
|
+
throw new Error("App not found");
|
|
204
|
+
}
|
|
205
|
+
if (!Routes) {
|
|
206
|
+
throw new Error("Routes not found");
|
|
207
|
+
}
|
|
208
|
+
if (!CellCacheContextProvider) {
|
|
209
|
+
throw new Error("CellCacheContextProvider not found");
|
|
210
|
+
}
|
|
211
|
+
if (!LocationProvider) {
|
|
212
|
+
throw new Error("LocationProvider not found");
|
|
213
|
+
}
|
|
239
214
|
const componentAsHtml = await recursivelyRender(
|
|
240
215
|
App,
|
|
241
216
|
Routes,
|
|
217
|
+
CellCacheContextProvider,
|
|
218
|
+
LocationProvider,
|
|
242
219
|
renderPath,
|
|
220
|
+
nodeRunner,
|
|
243
221
|
gqlHandler,
|
|
244
222
|
queryCache
|
|
245
223
|
);
|
|
224
|
+
nodeRunner.close();
|
|
246
225
|
const { helmet } = globalThis.__REDWOOD__HELMET_CONTEXT;
|
|
247
226
|
Object.keys(queryCache).forEach((queryKey) => {
|
|
248
227
|
const { query, variables, data } = queryCache[queryKey];
|
|
@@ -252,7 +231,8 @@ const runPrerender = async ({
|
|
|
252
231
|
data
|
|
253
232
|
});
|
|
254
233
|
});
|
|
255
|
-
const
|
|
234
|
+
const indexContent = fs.readFileSync(getRootHtmlPath()).toString();
|
|
235
|
+
const indexHtmlTree = loadHtml(indexContent);
|
|
256
236
|
if (helmet) {
|
|
257
237
|
const helmetElements = `
|
|
258
238
|
${helmet?.link.toString()}
|
|
@@ -262,7 +242,7 @@ const runPrerender = async ({
|
|
|
262
242
|
`;
|
|
263
243
|
indexHtmlTree("head").prepend(helmetElements);
|
|
264
244
|
const titleHtmlTag = helmet.title.toString();
|
|
265
|
-
if ((
|
|
245
|
+
if (loadHtml(titleHtmlTag)("title").text() !== "") {
|
|
266
246
|
if (indexHtmlTree("title").text().length === 0) {
|
|
267
247
|
indexHtmlTree("head").prepend(titleHtmlTag);
|
|
268
248
|
} else {
|
|
@@ -282,17 +262,16 @@ const runPrerender = async ({
|
|
|
282
262
|
return renderOutput;
|
|
283
263
|
};
|
|
284
264
|
const writePrerenderedHtmlFile = (outputHtmlPath, content) => {
|
|
285
|
-
const outputHtmlAbsPath =
|
|
265
|
+
const outputHtmlAbsPath = path.join(getPaths().base, outputHtmlPath);
|
|
286
266
|
if (outputHtmlPath === "web/dist/index.html") {
|
|
287
|
-
const html200Path =
|
|
288
|
-
if (!
|
|
289
|
-
|
|
267
|
+
const html200Path = path.join(getPaths().web.dist, "200.html");
|
|
268
|
+
if (!fs.existsSync(html200Path)) {
|
|
269
|
+
fs.copyFileSync(outputHtmlAbsPath, html200Path);
|
|
290
270
|
}
|
|
291
271
|
}
|
|
292
|
-
|
|
272
|
+
writeToDist(outputHtmlAbsPath, content);
|
|
293
273
|
};
|
|
294
|
-
|
|
295
|
-
0 && (module.exports = {
|
|
274
|
+
export {
|
|
296
275
|
runPrerender,
|
|
297
276
|
writePrerenderedHtmlFile
|
|
298
|
-
}
|
|
277
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/prerender",
|
|
3
|
-
"version": "0.9.1-next.
|
|
3
|
+
"version": "0.9.1-next.20+35268ced1",
|
|
4
4
|
"description": "CedarJS prerender",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"directory": "packages/prerender"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"type": "
|
|
11
|
+
"type": "module",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"default": "./dist/browserUtils/index.js"
|
|
20
20
|
},
|
|
21
21
|
"./detection": {
|
|
22
|
-
"types": "./dist/detection/
|
|
23
|
-
"default": "./dist/detection/
|
|
22
|
+
"types": "./dist/detection/detection.d.ts",
|
|
23
|
+
"default": "./dist/detection/detection.js"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"main": "dist/index.js",
|
|
@@ -40,11 +40,16 @@
|
|
|
40
40
|
"test:watch": "vitest watch"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"@cedarjs/
|
|
43
|
+
"@ast-grep/napi": "0.39.3",
|
|
44
|
+
"@babel/generator": "7.27.5",
|
|
45
|
+
"@babel/parser": "7.27.5",
|
|
46
|
+
"@babel/traverse": "7.27.4",
|
|
47
|
+
"@cedarjs/babel-config": "0.9.1-next.20+35268ced1",
|
|
48
|
+
"@cedarjs/project-config": "0.9.1-next.20+35268ced1",
|
|
49
|
+
"@cedarjs/router": "0.9.1-next.20+35268ced1",
|
|
50
|
+
"@cedarjs/structure": "0.9.1-next.20+35268ced1",
|
|
51
|
+
"@cedarjs/vite": "0.9.1-next.20+35268ced1",
|
|
52
|
+
"@cedarjs/web": "0.9.1-next.20+35268ced1",
|
|
48
53
|
"@rollup/plugin-alias": "5.1.1",
|
|
49
54
|
"@rollup/plugin-commonjs": "28.0.6",
|
|
50
55
|
"@rollup/plugin-node-resolve": "16.0.1",
|
|
@@ -54,11 +59,18 @@
|
|
|
54
59
|
"babel-plugin-ignore-html-and-css-imports": "0.1.0",
|
|
55
60
|
"cheerio": "1.0.0",
|
|
56
61
|
"graphql": "16.9.0",
|
|
57
|
-
"mime-types": "2.1.35"
|
|
62
|
+
"mime-types": "2.1.35",
|
|
63
|
+
"rollup": "4.24.0",
|
|
64
|
+
"rollup-plugin-swc3": "0.12.1",
|
|
65
|
+
"unimport": "5.0.1",
|
|
66
|
+
"unplugin-auto-import": "19.3.0",
|
|
67
|
+
"vite": "5.4.19",
|
|
68
|
+
"vite-node": "3.2.4"
|
|
58
69
|
},
|
|
59
70
|
"devDependencies": {
|
|
60
|
-
"@cedarjs/framework-tools": "0.9.1-next.
|
|
71
|
+
"@cedarjs/framework-tools": "0.9.1-next.20",
|
|
61
72
|
"@types/mime-types": "2.1.4",
|
|
73
|
+
"@types/react": "^18.2.55",
|
|
62
74
|
"babel-plugin-tester": "11.0.4",
|
|
63
75
|
"concurrently": "8.2.2",
|
|
64
76
|
"publint": "0.3.12",
|
|
@@ -77,5 +89,5 @@
|
|
|
77
89
|
"react": "react",
|
|
78
90
|
"react-dom": "react-dom"
|
|
79
91
|
},
|
|
80
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "35268ced1bf28181c4e51d16208306d745402127"
|
|
81
93
|
}
|
|
@@ -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;AA+BnD,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAgHzE"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var babel_plugin_redwood_cell_exports = {};
|
|
20
|
-
__export(babel_plugin_redwood_cell_exports, {
|
|
21
|
-
default: () => babel_plugin_redwood_cell_default
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(babel_plugin_redwood_cell_exports);
|
|
24
|
-
var import_path = require("path");
|
|
25
|
-
const EXPECTED_EXPORTS_FROM_CELL = [
|
|
26
|
-
"beforeQuery",
|
|
27
|
-
"QUERY",
|
|
28
|
-
"data",
|
|
29
|
-
"isEmpty",
|
|
30
|
-
"afterQuery",
|
|
31
|
-
"Loading",
|
|
32
|
-
"Success",
|
|
33
|
-
"Failure",
|
|
34
|
-
"Empty"
|
|
35
|
-
];
|
|
36
|
-
function babel_plugin_redwood_cell_default({ types: t }) {
|
|
37
|
-
let exportNames = [];
|
|
38
|
-
let hasDefaultExport = false;
|
|
39
|
-
return {
|
|
40
|
-
name: "babel-plugin-redwood-cell",
|
|
41
|
-
visitor: {
|
|
42
|
-
ExportDefaultDeclaration() {
|
|
43
|
-
hasDefaultExport = true;
|
|
44
|
-
},
|
|
45
|
-
ExportNamedDeclaration(path) {
|
|
46
|
-
const declaration = path.node.declaration;
|
|
47
|
-
if (!declaration) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
let name;
|
|
51
|
-
if (declaration.type === "VariableDeclaration") {
|
|
52
|
-
const id = declaration.declarations[0].id;
|
|
53
|
-
name = id.name;
|
|
54
|
-
}
|
|
55
|
-
if (declaration.type === "FunctionDeclaration") {
|
|
56
|
-
name = declaration?.id?.name;
|
|
57
|
-
}
|
|
58
|
-
if (name && EXPECTED_EXPORTS_FROM_CELL.includes(name)) {
|
|
59
|
-
exportNames.push(name);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
Program: {
|
|
63
|
-
enter() {
|
|
64
|
-
exportNames = [];
|
|
65
|
-
hasDefaultExport = false;
|
|
66
|
-
},
|
|
67
|
-
exit(path) {
|
|
68
|
-
const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("data");
|
|
69
|
-
if (hasDefaultExport || !hasQueryOrDataExport) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const createCellHookName = exportNames.includes("data") ? "createServerCell" : "createCell";
|
|
73
|
-
const importFrom = exportNames.includes("data") ? "@cedarjs/web/dist/components/cell/createServerCell" : "@cedarjs/web";
|
|
74
|
-
path.node.body.unshift(
|
|
75
|
-
t.importDeclaration(
|
|
76
|
-
[
|
|
77
|
-
t.importSpecifier(
|
|
78
|
-
t.identifier(createCellHookName),
|
|
79
|
-
t.identifier(createCellHookName)
|
|
80
|
-
)
|
|
81
|
-
],
|
|
82
|
-
t.stringLiteral(importFrom)
|
|
83
|
-
)
|
|
84
|
-
);
|
|
85
|
-
path.node.body.push(
|
|
86
|
-
t.exportDefaultDeclaration(
|
|
87
|
-
t.callExpression(t.identifier(createCellHookName), [
|
|
88
|
-
t.objectExpression([
|
|
89
|
-
...exportNames.map(
|
|
90
|
-
(name) => t.objectProperty(
|
|
91
|
-
t.identifier(name),
|
|
92
|
-
t.identifier(name),
|
|
93
|
-
false,
|
|
94
|
-
true
|
|
95
|
-
)
|
|
96
|
-
),
|
|
97
|
-
// Add the `displayName` property so we can name the Cell
|
|
98
|
-
// after the filename.
|
|
99
|
-
t.objectProperty(
|
|
100
|
-
t.identifier("displayName"),
|
|
101
|
-
t.stringLiteral(
|
|
102
|
-
(0, import_path.parse)(this.file.opts.filename).name
|
|
103
|
-
),
|
|
104
|
-
false,
|
|
105
|
-
true
|
|
106
|
-
)
|
|
107
|
-
])
|
|
108
|
-
])
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
@@ -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,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,GAAG,SAAS,CAqDzE"}
|