@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
|
@@ -1,304 +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 runPrerenderEsm_exports = {};
|
|
30
|
-
__export(runPrerenderEsm_exports, {
|
|
31
|
-
runPrerender: () => runPrerender,
|
|
32
|
-
writePrerenderedHtmlFile: () => writePrerenderedHtmlFile
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(runPrerenderEsm_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_project_config = require("@cedarjs/project-config");
|
|
42
|
-
var import_util = require("@cedarjs/router/dist/util");
|
|
43
|
-
var import_buildAndImport = require("./build-and-import/buildAndImport.js");
|
|
44
|
-
var import_detection = require("./detection/detection.js");
|
|
45
|
-
var import_errors = require("./errors.js");
|
|
46
|
-
var import_graphql = require("./graphql/graphql.js");
|
|
47
|
-
var import_node_runner = require("./graphql/node-runner.js");
|
|
48
|
-
var import_internal = require("./internal.js");
|
|
49
|
-
const { ApolloClient, InMemoryCache } = apolloClient.default;
|
|
50
|
-
const prerenderApolloClient = new ApolloClient({ cache: new InMemoryCache() });
|
|
51
|
-
async function recursivelyRender(App, Routes, CellCacheContextProvider, LocationProvider, renderPath, fileImporter, gqlHandler, queryCache) {
|
|
52
|
-
const { getOperationName } = await import("@cedarjs/web");
|
|
53
|
-
let shouldShowGraphqlHandlerNotFoundWarn = false;
|
|
54
|
-
await Promise.all(
|
|
55
|
-
Object.entries(queryCache).map(async ([cacheKey, value]) => {
|
|
56
|
-
if (value.hasProcessed) {
|
|
57
|
-
return Promise.resolve("");
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
const resultString = await (0, import_graphql.executeQuery)(
|
|
61
|
-
fileImporter,
|
|
62
|
-
gqlHandler,
|
|
63
|
-
value.query,
|
|
64
|
-
value.variables
|
|
65
|
-
);
|
|
66
|
-
let result;
|
|
67
|
-
try {
|
|
68
|
-
result = JSON.parse(resultString);
|
|
69
|
-
} catch (e) {
|
|
70
|
-
if (e instanceof SyntaxError) {
|
|
71
|
-
throw new import_errors.JSONParseError({
|
|
72
|
-
query: value.query,
|
|
73
|
-
variables: value.variables,
|
|
74
|
-
result: resultString
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (result.errors) {
|
|
79
|
-
const message = result.errors[0].message ?? JSON.stringify(result.errors, null, 4);
|
|
80
|
-
if (result.errors[0]?.extensions?.code === "UNAUTHENTICATED") {
|
|
81
|
-
const queryName = getOperationName(value.query);
|
|
82
|
-
console.error(
|
|
83
|
-
`
|
|
84
|
-
|
|
85
|
-
\u{1F6D1} Cannot prerender the query ${queryName} as it requires auth.
|
|
86
|
-
`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
throw new import_errors.PrerenderGqlError(message);
|
|
90
|
-
}
|
|
91
|
-
queryCache[cacheKey] = {
|
|
92
|
-
...value,
|
|
93
|
-
data: result.data,
|
|
94
|
-
hasProcessed: true
|
|
95
|
-
};
|
|
96
|
-
return result;
|
|
97
|
-
} catch (e) {
|
|
98
|
-
if (e instanceof import_errors.GqlHandlerImportError) {
|
|
99
|
-
shouldShowGraphqlHandlerNotFoundWarn = true;
|
|
100
|
-
queryCache[cacheKey] = {
|
|
101
|
-
...value,
|
|
102
|
-
// tried to fetch, but failed
|
|
103
|
-
renderLoading: true,
|
|
104
|
-
hasProcessed: true
|
|
105
|
-
};
|
|
106
|
-
return;
|
|
107
|
-
} else {
|
|
108
|
-
throw e;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
const prerenderUrl = process.env.RWJS_PRERENDER_ORIGIN || "http://localhost" + renderPath;
|
|
114
|
-
const componentAsHtml = import_server.default.renderToString(
|
|
115
|
-
/* @__PURE__ */ import_react.default.createElement(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))))
|
|
116
|
-
);
|
|
117
|
-
if (Object.values(queryCache).some((value) => !value.hasProcessed)) {
|
|
118
|
-
return recursivelyRender(
|
|
119
|
-
App,
|
|
120
|
-
Routes,
|
|
121
|
-
CellCacheContextProvider,
|
|
122
|
-
LocationProvider,
|
|
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
|
-
async function createCombinedEntry({ appPath, routesPath, outDir }) {
|
|
189
|
-
const combinedContent = `
|
|
190
|
-
import { LocationProvider } from '@cedarjs/router'
|
|
191
|
-
import { CellCacheContextProvider } from '@cedarjs/web'
|
|
192
|
-
|
|
193
|
-
import App from "${(0, import_project_config.importStatementPath)(appPath.replace(".tsx", ""))}";
|
|
194
|
-
import Routes from "${(0, import_project_config.importStatementPath)(routesPath.replace(".tsx", ""))}";
|
|
195
|
-
|
|
196
|
-
export { LocationProvider, CellCacheContextProvider, App, Routes };
|
|
197
|
-
`;
|
|
198
|
-
const tempFilePath = import_node_path.default.join(outDir, "__prerender-temp-entry.tsx");
|
|
199
|
-
await import_node_fs.default.promises.writeFile(tempFilePath, combinedContent, "utf8");
|
|
200
|
-
return tempFilePath;
|
|
201
|
-
}
|
|
202
|
-
const renderCache = {};
|
|
203
|
-
const runPrerender = async ({
|
|
204
|
-
queryCache,
|
|
205
|
-
renderPath
|
|
206
|
-
}) => {
|
|
207
|
-
(0, import_internal.registerShims)(renderPath);
|
|
208
|
-
const nodeRunner = new import_node_runner.NodeRunner();
|
|
209
|
-
const gqlHandler = await (0, import_graphql.getGqlHandler)(nodeRunner.importFile.bind(nodeRunner));
|
|
210
|
-
const prerenderDistPath = import_node_path.default.join((0, import_project_config.getPaths)().web.dist, "__prerender");
|
|
211
|
-
import_node_fs.default.mkdirSync(prerenderDistPath, { recursive: true });
|
|
212
|
-
if (!renderCache.App) {
|
|
213
|
-
const entryPath = await createCombinedEntry({
|
|
214
|
-
appPath: (0, import_project_config.getPaths)().web.app,
|
|
215
|
-
routesPath: (0, import_project_config.getPaths)().web.routes,
|
|
216
|
-
outDir: prerenderDistPath
|
|
217
|
-
});
|
|
218
|
-
const required = await (0, import_buildAndImport.buildAndImport)({
|
|
219
|
-
filepath: entryPath,
|
|
220
|
-
preserveTemporaryFile: true
|
|
221
|
-
});
|
|
222
|
-
renderCache.App = required.App;
|
|
223
|
-
renderCache.Routes = required.Routes;
|
|
224
|
-
renderCache.CellCacheContextProvider = required.CellCacheContextProvider;
|
|
225
|
-
renderCache.LocationProvider = required.LocationProvider;
|
|
226
|
-
}
|
|
227
|
-
const { LocationProvider, App, Routes, CellCacheContextProvider } = renderCache;
|
|
228
|
-
if (!App) {
|
|
229
|
-
throw new Error("App not found");
|
|
230
|
-
}
|
|
231
|
-
if (!Routes) {
|
|
232
|
-
throw new Error("Routes not found");
|
|
233
|
-
}
|
|
234
|
-
if (!CellCacheContextProvider) {
|
|
235
|
-
throw new Error("CellCacheContextProvider not found");
|
|
236
|
-
}
|
|
237
|
-
if (!LocationProvider) {
|
|
238
|
-
throw new Error("LocationProvider not found");
|
|
239
|
-
}
|
|
240
|
-
const componentAsHtml = await recursivelyRender(
|
|
241
|
-
App,
|
|
242
|
-
Routes,
|
|
243
|
-
CellCacheContextProvider,
|
|
244
|
-
LocationProvider,
|
|
245
|
-
renderPath,
|
|
246
|
-
nodeRunner.importFile.bind(nodeRunner),
|
|
247
|
-
gqlHandler,
|
|
248
|
-
queryCache
|
|
249
|
-
);
|
|
250
|
-
nodeRunner.close();
|
|
251
|
-
const { helmet } = globalThis.__REDWOOD__HELMET_CONTEXT;
|
|
252
|
-
Object.keys(queryCache).forEach((queryKey) => {
|
|
253
|
-
const { query, variables, data } = queryCache[queryKey];
|
|
254
|
-
prerenderApolloClient.writeQuery({
|
|
255
|
-
query,
|
|
256
|
-
variables,
|
|
257
|
-
data
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
const indexContent = import_node_fs.default.readFileSync((0, import_internal.getRootHtmlPath)()).toString();
|
|
261
|
-
const indexHtmlTree = (0, import_cheerio.load)(indexContent);
|
|
262
|
-
if (helmet) {
|
|
263
|
-
const helmetElements = `
|
|
264
|
-
${helmet?.link.toString()}
|
|
265
|
-
${helmet?.meta.toString()}
|
|
266
|
-
${helmet?.script.toString()}
|
|
267
|
-
${helmet?.noscript.toString()}
|
|
268
|
-
`;
|
|
269
|
-
indexHtmlTree("head").prepend(helmetElements);
|
|
270
|
-
const titleHtmlTag = helmet.title.toString();
|
|
271
|
-
if ((0, import_cheerio.load)(titleHtmlTag)("title").text() !== "") {
|
|
272
|
-
if (indexHtmlTree("title").text().length === 0) {
|
|
273
|
-
indexHtmlTree("head").prepend(titleHtmlTag);
|
|
274
|
-
} else {
|
|
275
|
-
indexHtmlTree("title").replaceWith(titleHtmlTag);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
indexHtmlTree("head").append(
|
|
280
|
-
`<script> globalThis.__REDWOOD__APOLLO_STATE = ${JSON.stringify(
|
|
281
|
-
prerenderApolloClient.extract()
|
|
282
|
-
)}</script>`
|
|
283
|
-
);
|
|
284
|
-
prerenderApolloClient.resetStore();
|
|
285
|
-
insertChunkLoadingScript(indexHtmlTree, renderPath);
|
|
286
|
-
indexHtmlTree("#redwood-app").append(componentAsHtml);
|
|
287
|
-
const renderOutput = indexHtmlTree.html();
|
|
288
|
-
return renderOutput;
|
|
289
|
-
};
|
|
290
|
-
const writePrerenderedHtmlFile = (outputHtmlPath, content) => {
|
|
291
|
-
const outputHtmlAbsPath = import_node_path.default.join((0, import_project_config.getPaths)().base, outputHtmlPath);
|
|
292
|
-
if (outputHtmlPath === "web/dist/index.html") {
|
|
293
|
-
const html200Path = import_node_path.default.join((0, import_project_config.getPaths)().web.dist, "200.html");
|
|
294
|
-
if (!import_node_fs.default.existsSync(html200Path)) {
|
|
295
|
-
import_node_fs.default.copyFileSync(outputHtmlAbsPath, html200Path);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
(0, import_internal.writeToDist)(outputHtmlAbsPath, content);
|
|
299
|
-
};
|
|
300
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
301
|
-
0 && (module.exports = {
|
|
302
|
-
runPrerender,
|
|
303
|
-
writePrerenderedHtmlFile
|
|
304
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/**
|
|
3
|
-
* This Vite plugin will search for import statements that include a glob double
|
|
4
|
-
* star `**` in the source part of the statement. The files that are matched are
|
|
5
|
-
* imported and appended to an object.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* Given a directory "src/services" that contains "a.js", "b.ts" and
|
|
9
|
-
* "nested/c.js" will produce the following results:
|
|
10
|
-
* ```js
|
|
11
|
-
* import services from 'src/services/**\/*.{js,ts}'
|
|
12
|
-
* console.log(services)
|
|
13
|
-
* // services.a = import('src/services/a')
|
|
14
|
-
* // services.b = import('src/services/b')
|
|
15
|
-
* // services.nested_c = import('src/services/nested/c')
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function cedarImportDirPlugin(): Plugin;
|
|
19
|
-
//# sourceMappingURL=vite-plugin-cedar-import-dir.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-import-dir.d.ts","sourceRoot":"","sources":["../../src/graphql/vite-plugin-cedar-import-dir.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAgH7C"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { parse, Lang } from "@ast-grep/napi";
|
|
3
|
-
import fg from "fast-glob";
|
|
4
|
-
import { importStatementPath, getPaths } from "@cedarjs/project-config";
|
|
5
|
-
function cedarImportDirPlugin() {
|
|
6
|
-
return {
|
|
7
|
-
name: "vite-plugin-cedar-import-dir",
|
|
8
|
-
enforce: "pre",
|
|
9
|
-
async transform(code, id) {
|
|
10
|
-
if (!code.includes("/**/")) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const ext = path.extname(id);
|
|
14
|
-
const language = ext === ".ts" || ext === ".tsx" ? Lang.TypeScript : Lang.JavaScript;
|
|
15
|
-
let ast;
|
|
16
|
-
try {
|
|
17
|
-
ast = parse(language, code);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.warn("Failed to parse file:", id);
|
|
20
|
-
console.warn(error);
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const root = ast.root();
|
|
24
|
-
let hasTransformations = false;
|
|
25
|
-
const edits = [];
|
|
26
|
-
const globImports = root.findAll({
|
|
27
|
-
rule: {
|
|
28
|
-
pattern: "import $DEFAULT_IMPORT from $SOURCE"
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
for (const importNode of globImports) {
|
|
32
|
-
const sourceNode = importNode.getMatch("SOURCE");
|
|
33
|
-
const defaultImportNode = importNode.getMatch("DEFAULT_IMPORT");
|
|
34
|
-
if (!sourceNode || !defaultImportNode) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
const sourceValue = sourceNode.text().slice(1, -1);
|
|
38
|
-
if (!sourceValue.includes("/**/")) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
hasTransformations = true;
|
|
42
|
-
const importName = defaultImportNode.text();
|
|
43
|
-
const importGlob = importStatementPath(sourceValue);
|
|
44
|
-
const cwd = importGlob.startsWith("src/") ? getPaths().api.base : path.dirname(id);
|
|
45
|
-
try {
|
|
46
|
-
const dirFiles = fg.sync(importGlob, { cwd }).filter(
|
|
47
|
-
(n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
|
|
48
|
-
);
|
|
49
|
-
const staticGlob = importGlob.split("*")[0];
|
|
50
|
-
const filePathToVarName = (filePath) => {
|
|
51
|
-
return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
52
|
-
};
|
|
53
|
-
let replacement = `let ${importName} = {};
|
|
54
|
-
`;
|
|
55
|
-
for (const filePath of dirFiles) {
|
|
56
|
-
const { dir: fileDir, name: fileName } = path.parse(filePath);
|
|
57
|
-
const fileImportPath = fileDir + "/" + fileName;
|
|
58
|
-
const filePathVarName = filePathToVarName(filePath);
|
|
59
|
-
const namespaceImportName = `${importName}_${filePathVarName}`;
|
|
60
|
-
replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
|
|
61
|
-
`;
|
|
62
|
-
replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
|
|
63
|
-
`;
|
|
64
|
-
}
|
|
65
|
-
edits.push(importNode.replace(replacement.trim()));
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.warn(`Failed to process glob import: ${sourceValue}`, error);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (hasTransformations && edits.length > 0) {
|
|
71
|
-
const transformedCode = root.commitEdits(edits);
|
|
72
|
-
return {
|
|
73
|
-
code: transformedCode,
|
|
74
|
-
map: null
|
|
75
|
-
// For simplicity, not generating source maps
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
export {
|
|
83
|
-
cedarImportDirPlugin
|
|
84
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { QueryInfo } from '@cedarjs/web';
|
|
2
|
-
interface PrerenderParams {
|
|
3
|
-
queryCache: Record<string, QueryInfo>;
|
|
4
|
-
renderPath: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const runPrerender: ({ queryCache, renderPath, }: PrerenderParams) => Promise<string | void>;
|
|
7
|
-
export declare const writePrerenderedHtmlFile: (outputHtmlPath: string, content: string) => void;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=runPrerenderEsm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runPrerenderEsm.d.ts","sourceRoot":"","sources":["../src/runPrerenderEsm.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAoQ7C,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,CAwHzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
|
|
File without changes
|
|
File without changes
|