@cedarjs/prerender 9.0.0-canary.1784 → 9.0.0-canary.3124
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/apolloState.d.ts +13 -0
- package/dist/apolloState.d.ts.map +1 -0
- package/dist/apolloState.js +6 -0
- package/dist/browserUtils/index.d.ts +1 -1
- package/dist/browserUtils/index.d.ts.map +1 -1
- package/dist/build-and-import/buildAndImport.d.ts +1 -1
- package/dist/build-and-import/buildAndImport.d.ts.map +1 -1
- package/dist/build-and-import/buildAndImport.js +22 -9
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedar-remove-dev-fatal-error-page.d.ts +14 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedar-remove-dev-fatal-error-page.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedar-remove-dev-fatal-error-page.js +29 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.d.ts.map +1 -1
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +2 -1
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts +4 -3
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts.map +1 -1
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts.map +1 -1
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.d.ts.map +1 -1
- package/dist/detection/detection.d.ts.map +1 -1
- package/dist/detection/detection.js +1 -3
- package/dist/graphql/graphql.d.ts +17 -2
- package/dist/graphql/graphql.d.ts.map +1 -1
- package/dist/graphql/node-runner.d.ts +1 -1
- package/dist/graphql/node-runner.d.ts.map +1 -1
- package/dist/graphql/node-runner.js +27 -37
- package/dist/{cjs/index.d.ts.map → index.d.ts.map} +1 -1
- package/dist/index.js +1 -0
- package/dist/runPrerender.d.ts.map +1 -0
- package/dist/{runPrerenderEsm.js → runPrerender.js} +76 -63
- package/package.json +36 -65
- package/LICENSE +0 -21
- 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 -97
- 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 -76
- package/dist/babelPlugins/utils.d.ts +0 -2
- package/dist/babelPlugins/utils.d.ts.map +0 -1
- package/dist/babelPlugins/utils.js +0 -15
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -5
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.js +0 -121
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +0 -5
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +0 -1
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +0 -100
- package/dist/cjs/babelPlugins/utils.d.ts +0 -2
- package/dist/cjs/babelPlugins/utils.d.ts.map +0 -1
- package/dist/cjs/babelPlugins/utils.js +0 -49
- package/dist/cjs/browserUtils/index.d.ts +0 -8
- package/dist/cjs/browserUtils/index.d.ts.map +0 -1
- package/dist/cjs/browserUtils/index.js +0 -47
- package/dist/cjs/build-and-import/buildAndImport.js +0 -173
- package/dist/cjs/build-and-import/load-tsconfig.d.js +0 -1
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +0 -183
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js +0 -83
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.js +0 -125
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js +0 -48
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js +0 -66
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js +0 -118
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js +0 -146
- package/dist/cjs/build-and-import/rollupPlugins/utils.js +0 -78
- package/dist/cjs/build-and-import/utils.js +0 -68
- package/dist/cjs/detection/detection.d.ts +0 -11
- package/dist/cjs/detection/detection.d.ts.map +0 -1
- package/dist/cjs/detection/detection.js +0 -48
- package/dist/cjs/errors.d.ts +0 -19
- package/dist/cjs/errors.d.ts.map +0 -1
- package/dist/cjs/errors.js +0 -52
- package/dist/cjs/graphql/graphql.d.ts +0 -19
- package/dist/cjs/graphql/graphql.d.ts.map +0 -1
- package/dist/cjs/graphql/graphql.js +0 -152
- package/dist/cjs/graphql/node-runner.js +0 -109
- package/dist/cjs/graphql/vite-plugin-cedar-auto-import.js +0 -107
- package/dist/cjs/graphql/vite-plugin-cedar-import-dir.js +0 -118
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/internal.d.ts +0 -28
- package/dist/cjs/internal.d.ts.map +0 -1
- package/dist/cjs/internal.js +0 -135
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/runPrerender.d.ts.map +0 -1
- package/dist/cjs/runPrerender.js +0 -307
- package/dist/cjs/runPrerenderEsm.js +0 -304
- package/dist/graphql/vite-plugin-cedar-import-dir.d.ts +0 -19
- package/dist/graphql/vite-plugin-cedar-import-dir.d.ts.map +0 -1
- package/dist/graphql/vite-plugin-cedar-import-dir.js +0 -84
- package/dist/runPrerenderEsm.d.ts +0 -9
- package/dist/runPrerenderEsm.d.ts.map +0 -1
- /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{cjs/runPrerender.d.ts → runPrerender.d.ts} +0 -0
package/dist/cjs/internal.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var internal_exports = {};
|
|
30
|
-
__export(internal_exports, {
|
|
31
|
-
getPathsFromTypeScriptConfig: () => getPathsFromTypeScriptConfig,
|
|
32
|
-
getRootHtmlPath: () => getRootHtmlPath,
|
|
33
|
-
parseTypeScriptConfigFiles: () => parseTypeScriptConfigFiles,
|
|
34
|
-
registerShims: () => registerShims,
|
|
35
|
-
writeToDist: () => writeToDist
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(internal_exports);
|
|
38
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
39
|
-
var import_path = __toESM(require("path"), 1);
|
|
40
|
-
var import_fetch = require("@whatwg-node/fetch");
|
|
41
|
-
var import_typescript = require("typescript");
|
|
42
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
43
|
-
const INDEX_FILE = import_path.default.join((0, import_project_config.getPaths)().web.dist, "index.html");
|
|
44
|
-
const DEFAULT_INDEX = import_path.default.join((0, import_project_config.getPaths)().web.dist, "200.html");
|
|
45
|
-
const getRootHtmlPath = () => {
|
|
46
|
-
if (import_node_fs.default.existsSync(DEFAULT_INDEX)) {
|
|
47
|
-
return DEFAULT_INDEX;
|
|
48
|
-
} else {
|
|
49
|
-
return INDEX_FILE;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const registerShims = (routerPath) => {
|
|
53
|
-
const rwjsConfig = (0, import_project_config.getConfig)();
|
|
54
|
-
globalThis.RWJS_ENV = {
|
|
55
|
-
RWJS_API_GRAPHQL_URL: rwjsConfig.web.apiGraphQLUrl ?? rwjsConfig.web.apiUrl + "/graphql",
|
|
56
|
-
RWJS_API_URL: rwjsConfig.web.apiUrl,
|
|
57
|
-
__REDWOOD__APP_TITLE: rwjsConfig.web.title
|
|
58
|
-
};
|
|
59
|
-
globalThis.RWJS_DEBUG_ENV = {
|
|
60
|
-
RWJS_SRC_ROOT: (0, import_project_config.getPaths)().web.src
|
|
61
|
-
};
|
|
62
|
-
globalThis.__REDWOOD__PRERENDERING = true;
|
|
63
|
-
globalThis.__REDWOOD__HELMET_CONTEXT = {};
|
|
64
|
-
process.env.__REDWOOD__PRERENDERING = "1";
|
|
65
|
-
globalThis.location = {
|
|
66
|
-
...globalThis.location,
|
|
67
|
-
pathname: routerPath
|
|
68
|
-
};
|
|
69
|
-
if (!globalThis.fetch) {
|
|
70
|
-
globalThis.fetch = import_fetch.fetch;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const writeToDist = (outputHtmlPath, renderOutput) => {
|
|
74
|
-
const dirName = import_path.default.dirname(outputHtmlPath);
|
|
75
|
-
const exist = import_node_fs.default.existsSync(dirName);
|
|
76
|
-
if (!exist) {
|
|
77
|
-
import_node_fs.default.mkdirSync(dirName, { recursive: true });
|
|
78
|
-
}
|
|
79
|
-
import_node_fs.default.writeFileSync(outputHtmlPath, renderOutput);
|
|
80
|
-
};
|
|
81
|
-
const parseTypeScriptConfigFiles = () => {
|
|
82
|
-
const rwPaths = (0, import_project_config.getPaths)();
|
|
83
|
-
const parseConfigFile = (basePath) => {
|
|
84
|
-
let configPath = import_path.default.join(basePath, "tsconfig.json");
|
|
85
|
-
if (!import_node_fs.default.existsSync(configPath)) {
|
|
86
|
-
configPath = import_path.default.join(basePath, "jsconfig.json");
|
|
87
|
-
if (!import_node_fs.default.existsSync(configPath)) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return (0, import_typescript.parseConfigFileTextToJson)(
|
|
92
|
-
configPath,
|
|
93
|
-
import_node_fs.default.readFileSync(configPath, "utf-8")
|
|
94
|
-
);
|
|
95
|
-
};
|
|
96
|
-
const apiConfig = parseConfigFile(rwPaths.api.base);
|
|
97
|
-
const webConfig = parseConfigFile(rwPaths.web.base);
|
|
98
|
-
return {
|
|
99
|
-
api: apiConfig?.config ?? null,
|
|
100
|
-
web: webConfig?.config ?? null
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
function getPathsFromTypeScriptConfig(config, rootDir) {
|
|
104
|
-
if (!config) {
|
|
105
|
-
return [];
|
|
106
|
-
}
|
|
107
|
-
if (!config.compilerOptions?.paths) {
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
110
|
-
const { baseUrl, paths } = config.compilerOptions;
|
|
111
|
-
let absoluteBase;
|
|
112
|
-
if (baseUrl) {
|
|
113
|
-
absoluteBase = import_path.default.isAbsolute(baseUrl) ? baseUrl : import_path.default.join(rootDir, baseUrl);
|
|
114
|
-
} else {
|
|
115
|
-
absoluteBase = rootDir;
|
|
116
|
-
}
|
|
117
|
-
const aliases = [];
|
|
118
|
-
for (const [key, value] of Object.entries(paths)) {
|
|
119
|
-
if (key.match(/src\/|\$api\/\*|types\/\*|\@cedarjs\/.*/g)) {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
const aliasKey = key.replace("/*", "");
|
|
123
|
-
const aliasValue = import_path.default.join(absoluteBase, value[0].replace("/*", ""));
|
|
124
|
-
aliases.push({ find: aliasKey, replacement: aliasValue });
|
|
125
|
-
}
|
|
126
|
-
return aliases;
|
|
127
|
-
}
|
|
128
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
-
0 && (module.exports = {
|
|
130
|
-
getPathsFromTypeScriptConfig,
|
|
131
|
-
getRootHtmlPath,
|
|
132
|
-
parseTypeScriptConfigFiles,
|
|
133
|
-
registerShims,
|
|
134
|
-
writeToDist
|
|
135
|
-
});
|
package/dist/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runPrerender.d.ts","sourceRoot":"","sources":["../../src/runPrerender.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAmO7C,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,CAkIzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
|
package/dist/cjs/runPrerender.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
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_node_fs = __toESM(require("node:fs"), 1);
|
|
36
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
-
var import_react = __toESM(require("react"), 1);
|
|
38
|
-
var apolloClient = __toESM(require("@apollo/client"), 1);
|
|
39
|
-
var import_cheerio = require("cheerio");
|
|
40
|
-
var import_server = __toESM(require("react-dom/server"), 1);
|
|
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 = require("./babelPlugins/babel-plugin-redwood-cell.js");
|
|
46
|
-
var import_babel_plugin_redwood_prerender_media_imports = require("./babelPlugins/babel-plugin-redwood-prerender-media-imports.js");
|
|
47
|
-
var import_detection = require("./detection/detection.js");
|
|
48
|
-
var import_errors = require("./errors.js");
|
|
49
|
-
var import_graphql = require("./graphql/graphql.js");
|
|
50
|
-
var import_internal = require("./internal.js");
|
|
51
|
-
const { ApolloClient, InMemoryCache } = apolloClient.default || apolloClient;
|
|
52
|
-
const prerenderApolloClient = new ApolloClient({ cache: new InMemoryCache() });
|
|
53
|
-
async function recursivelyRender(App, Routes, renderPath, fileImporter, gqlHandler, queryCache) {
|
|
54
|
-
const { CellCacheContextProvider, getOperationName } = require("@cedarjs/web");
|
|
55
|
-
let shouldShowGraphqlHandlerNotFoundWarn = false;
|
|
56
|
-
await Promise.all(
|
|
57
|
-
Object.entries(queryCache).map(async ([cacheKey, value]) => {
|
|
58
|
-
if (value.hasProcessed) {
|
|
59
|
-
return Promise.resolve("");
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
const resultString = await (0, import_graphql.executeQuery)(
|
|
63
|
-
fileImporter,
|
|
64
|
-
gqlHandler,
|
|
65
|
-
value.query,
|
|
66
|
-
value.variables
|
|
67
|
-
);
|
|
68
|
-
let result;
|
|
69
|
-
try {
|
|
70
|
-
result = JSON.parse(resultString);
|
|
71
|
-
} catch (e) {
|
|
72
|
-
if (e instanceof SyntaxError) {
|
|
73
|
-
throw new import_errors.JSONParseError({
|
|
74
|
-
query: value.query,
|
|
75
|
-
variables: value.variables,
|
|
76
|
-
result: resultString
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (result.errors) {
|
|
81
|
-
const message = result.errors[0].message ?? JSON.stringify(result.errors, null, 4);
|
|
82
|
-
if (result.errors[0]?.extensions?.code === "UNAUTHENTICATED") {
|
|
83
|
-
const queryName = getOperationName(value.query);
|
|
84
|
-
console.error(
|
|
85
|
-
`
|
|
86
|
-
|
|
87
|
-
\u{1F6D1} Cannot prerender the query ${queryName} as it requires auth.
|
|
88
|
-
`
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
throw new import_errors.PrerenderGqlError(message);
|
|
92
|
-
}
|
|
93
|
-
queryCache[cacheKey] = {
|
|
94
|
-
...value,
|
|
95
|
-
data: result.data,
|
|
96
|
-
hasProcessed: true
|
|
97
|
-
};
|
|
98
|
-
return result;
|
|
99
|
-
} catch (e) {
|
|
100
|
-
if (e instanceof import_errors.GqlHandlerImportError) {
|
|
101
|
-
shouldShowGraphqlHandlerNotFoundWarn = true;
|
|
102
|
-
queryCache[cacheKey] = {
|
|
103
|
-
...value,
|
|
104
|
-
// tried to fetch, but failed
|
|
105
|
-
renderLoading: true,
|
|
106
|
-
hasProcessed: true
|
|
107
|
-
};
|
|
108
|
-
return;
|
|
109
|
-
} else {
|
|
110
|
-
throw e;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
);
|
|
115
|
-
const prerenderUrl = process.env.RWJS_PRERENDER_ORIGIN || "http://localhost" + renderPath;
|
|
116
|
-
const componentAsHtml = import_server.default.renderToString(
|
|
117
|
-
/* @__PURE__ */ import_react.default.createElement(import_router.LocationProvider, { location: new URL(prerenderUrl) }, /* @__PURE__ */ import_react.default.createElement(CellCacheContextProvider, { queryCache }, /* @__PURE__ */ import_react.default.createElement(App, null, /* @__PURE__ */ import_react.default.createElement(Routes, null))))
|
|
118
|
-
);
|
|
119
|
-
if (Object.values(queryCache).some((value) => !value.hasProcessed)) {
|
|
120
|
-
return recursivelyRender(
|
|
121
|
-
App,
|
|
122
|
-
Routes,
|
|
123
|
-
renderPath,
|
|
124
|
-
fileImporter,
|
|
125
|
-
gqlHandler,
|
|
126
|
-
queryCache
|
|
127
|
-
);
|
|
128
|
-
} else {
|
|
129
|
-
if (shouldShowGraphqlHandlerNotFoundWarn) {
|
|
130
|
-
console.warn(
|
|
131
|
-
'\n \u26A0\uFE0F Could not load your GraphQL handler. \n Your Cells have been prerendered in the "Loading" state. \n'
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
return Promise.resolve(componentAsHtml);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function insertChunkLoadingScript(indexHtmlTree, renderPath) {
|
|
138
|
-
const prerenderRoutes = (0, import_detection.detectPrerenderRoutes)();
|
|
139
|
-
const route = prerenderRoutes.find((route2) => {
|
|
140
|
-
if (!route2.routePath) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
return (0, import_util.matchPath)(route2.routePath, renderPath).match;
|
|
144
|
-
});
|
|
145
|
-
if (!route) {
|
|
146
|
-
throw new Error("Could not find a Route matching " + renderPath);
|
|
147
|
-
}
|
|
148
|
-
if (!route.pageIdentifier) {
|
|
149
|
-
throw new Error(`Route for ${renderPath} has no pageIdentifier`);
|
|
150
|
-
}
|
|
151
|
-
const buildManifest = JSON.parse(
|
|
152
|
-
import_node_fs.default.readFileSync(
|
|
153
|
-
import_node_path.default.join((0, import_project_config.getPaths)().web.dist, "client-build-manifest.json"),
|
|
154
|
-
"utf-8"
|
|
155
|
-
)
|
|
156
|
-
);
|
|
157
|
-
const chunkPaths = [];
|
|
158
|
-
if (route?.filePath) {
|
|
159
|
-
const pagesIndex = route.filePath.indexOf(import_node_path.default.join("web", "src", "pages")) + 8;
|
|
160
|
-
const pagePath = (0, import_project_config.ensurePosixPath)(route.filePath.slice(pagesIndex));
|
|
161
|
-
const pageChunkPath = buildManifest[pagePath]?.file;
|
|
162
|
-
if (pageChunkPath) {
|
|
163
|
-
chunkPaths.push("/" + pageChunkPath);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (chunkPaths.length === 0) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
chunkPaths.forEach((chunkPath) => {
|
|
170
|
-
indexHtmlTree("head").prepend(
|
|
171
|
-
`<script defer="defer" src="${chunkPath}" type="module"></script>`
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
chunkPaths.forEach((chunkPath) => {
|
|
175
|
-
const fullChunkPath = import_node_path.default.join((0, import_project_config.getPaths)().web.dist, chunkPath);
|
|
176
|
-
const jsChunk = import_node_fs.default.readFileSync(fullChunkPath, "utf-8");
|
|
177
|
-
const matches = jsChunk.match(/export\s*\{\s*\w+ as default\s*\}/g) || [];
|
|
178
|
-
const lastIndex = jsChunk.lastIndexOf(matches[matches.length - 1]);
|
|
179
|
-
const varNameMatch = jsChunk.slice(lastIndex).match(/export\s*\{\s*(\w+) as default\s*\}/);
|
|
180
|
-
import_node_fs.default.writeFileSync(
|
|
181
|
-
fullChunkPath,
|
|
182
|
-
jsChunk + `globalThis.__REDWOOD__PRERENDER_PAGES = globalThis.__REDWOOD__PRERENDER_PAGES || {};
|
|
183
|
-
globalThis.__REDWOOD__PRERENDER_PAGES.${route?.pageIdentifier}=${varNameMatch?.[1]};
|
|
184
|
-
`
|
|
185
|
-
);
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
const runPrerender = async ({
|
|
189
|
-
queryCache,
|
|
190
|
-
renderPath
|
|
191
|
-
}) => {
|
|
192
|
-
(0, import_internal.registerShims)(renderPath);
|
|
193
|
-
(0, import_babel_config.registerApiSideBabelHook)({
|
|
194
|
-
plugins: [
|
|
195
|
-
[
|
|
196
|
-
"babel-plugin-module-resolver",
|
|
197
|
-
{
|
|
198
|
-
alias: {
|
|
199
|
-
api: (0, import_project_config.getPaths)().api.base,
|
|
200
|
-
web: (0, import_project_config.getPaths)().web.base
|
|
201
|
-
},
|
|
202
|
-
loglevel: "silent"
|
|
203
|
-
// to silence the unnecessary warnings
|
|
204
|
-
}
|
|
205
|
-
]
|
|
206
|
-
],
|
|
207
|
-
overrides: [
|
|
208
|
-
{
|
|
209
|
-
test: ["./api/"],
|
|
210
|
-
plugins: [
|
|
211
|
-
[
|
|
212
|
-
"babel-plugin-module-resolver",
|
|
213
|
-
{
|
|
214
|
-
alias: {
|
|
215
|
-
src: (0, import_project_config.getPaths)().api.src
|
|
216
|
-
},
|
|
217
|
-
loglevel: "silent"
|
|
218
|
-
},
|
|
219
|
-
"exec-api-src-module-resolver"
|
|
220
|
-
]
|
|
221
|
-
]
|
|
222
|
-
}
|
|
223
|
-
]
|
|
224
|
-
});
|
|
225
|
-
const gqlHandler = await (0, import_graphql.getGqlHandler)(require);
|
|
226
|
-
(0, import_babel_config.registerWebSideBabelHook)({
|
|
227
|
-
overrides: [
|
|
228
|
-
{
|
|
229
|
-
plugins: [
|
|
230
|
-
["ignore-html-and-css-imports"],
|
|
231
|
-
// webpack/postcss handles CSS imports
|
|
232
|
-
[import_babel_plugin_redwood_prerender_media_imports.babelPluginRedwoodPrerenderMediaImports]
|
|
233
|
-
]
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
test: /.+Cell.(js|tsx|jsx)$/,
|
|
237
|
-
plugins: [import_babel_plugin_redwood_cell.babelPluginRedwoodCell]
|
|
238
|
-
}
|
|
239
|
-
],
|
|
240
|
-
options: {
|
|
241
|
-
forPrerender: true
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
const indexContent = import_node_fs.default.readFileSync((0, import_internal.getRootHtmlPath)()).toString();
|
|
245
|
-
const { default: App } = require((0, import_project_config.getPaths)().web.app);
|
|
246
|
-
const { default: Routes } = require((0, import_project_config.getPaths)().web.routes);
|
|
247
|
-
const componentAsHtml = await recursivelyRender(
|
|
248
|
-
App,
|
|
249
|
-
Routes,
|
|
250
|
-
renderPath,
|
|
251
|
-
require,
|
|
252
|
-
gqlHandler,
|
|
253
|
-
queryCache
|
|
254
|
-
);
|
|
255
|
-
const { helmet } = globalThis.__REDWOOD__HELMET_CONTEXT;
|
|
256
|
-
Object.keys(queryCache).forEach((queryKey) => {
|
|
257
|
-
const { query, variables, data } = queryCache[queryKey];
|
|
258
|
-
prerenderApolloClient.writeQuery({
|
|
259
|
-
query,
|
|
260
|
-
variables,
|
|
261
|
-
data
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
const indexHtmlTree = (0, import_cheerio.load)(indexContent);
|
|
265
|
-
if (helmet) {
|
|
266
|
-
const helmetElements = `
|
|
267
|
-
${helmet?.link.toString()}
|
|
268
|
-
${helmet?.meta.toString()}
|
|
269
|
-
${helmet?.script.toString()}
|
|
270
|
-
${helmet?.noscript.toString()}
|
|
271
|
-
`;
|
|
272
|
-
indexHtmlTree("head").prepend(helmetElements);
|
|
273
|
-
const titleHtmlTag = helmet.title.toString();
|
|
274
|
-
if ((0, import_cheerio.load)(titleHtmlTag)("title").text() !== "") {
|
|
275
|
-
if (indexHtmlTree("title").text().length === 0) {
|
|
276
|
-
indexHtmlTree("head").prepend(titleHtmlTag);
|
|
277
|
-
} else {
|
|
278
|
-
indexHtmlTree("title").replaceWith(titleHtmlTag);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
indexHtmlTree("head").append(
|
|
283
|
-
`<script> globalThis.__REDWOOD__APOLLO_STATE = ${JSON.stringify(
|
|
284
|
-
prerenderApolloClient.extract()
|
|
285
|
-
)}</script>`
|
|
286
|
-
);
|
|
287
|
-
prerenderApolloClient.resetStore();
|
|
288
|
-
insertChunkLoadingScript(indexHtmlTree, renderPath);
|
|
289
|
-
indexHtmlTree("#redwood-app").append(componentAsHtml);
|
|
290
|
-
const renderOutput = indexHtmlTree.html();
|
|
291
|
-
return renderOutput;
|
|
292
|
-
};
|
|
293
|
-
const writePrerenderedHtmlFile = (outputHtmlPath, content) => {
|
|
294
|
-
const outputHtmlAbsPath = import_node_path.default.join((0, import_project_config.getPaths)().base, outputHtmlPath);
|
|
295
|
-
if (outputHtmlPath === "web/dist/index.html") {
|
|
296
|
-
const html200Path = import_node_path.default.join((0, import_project_config.getPaths)().web.dist, "200.html");
|
|
297
|
-
if (!import_node_fs.default.existsSync(html200Path)) {
|
|
298
|
-
import_node_fs.default.copyFileSync(outputHtmlAbsPath, html200Path);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
(0, import_internal.writeToDist)(outputHtmlAbsPath, content);
|
|
302
|
-
};
|
|
303
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
304
|
-
0 && (module.exports = {
|
|
305
|
-
runPrerender,
|
|
306
|
-
writePrerenderedHtmlFile
|
|
307
|
-
});
|