@cedarjs/prerender 0.9.1-next.21 → 0.9.1-next.23
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/babelPlugins/babel-plugin-redwood-cell.d.ts +5 -0
- package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/dist/babelPlugins/babel-plugin-redwood-cell.js +97 -0
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +5 -0
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +1 -0
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +76 -0
- package/dist/babelPlugins/utils.d.ts +2 -0
- package/dist/babelPlugins/utils.d.ts.map +1 -0
- package/dist/babelPlugins/utils.js +15 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts +5 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.js +121 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +5 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +1 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +100 -0
- package/dist/cjs/babelPlugins/utils.d.ts +2 -0
- package/dist/cjs/babelPlugins/utils.d.ts.map +1 -0
- package/dist/cjs/babelPlugins/utils.js +49 -0
- package/dist/cjs/browserUtils/index.d.ts +8 -0
- package/dist/cjs/browserUtils/index.d.ts.map +1 -0
- package/dist/cjs/browserUtils/index.js +47 -0
- package/dist/cjs/build-and-import/buildAndImport.js +173 -0
- package/dist/cjs/build-and-import/load-tsconfig.d.js +1 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +183 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js +83 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.js +125 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js +48 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js +66 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js +118 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js +146 -0
- package/dist/cjs/build-and-import/rollupPlugins/utils.js +78 -0
- package/dist/cjs/build-and-import/utils.js +68 -0
- package/dist/cjs/detection/detection.d.ts +11 -0
- package/dist/cjs/detection/detection.d.ts.map +1 -0
- package/dist/cjs/detection/detection.js +48 -0
- package/dist/cjs/errors.d.ts +19 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +52 -0
- package/dist/cjs/graphql/graphql.d.ts +19 -0
- package/dist/cjs/graphql/graphql.d.ts.map +1 -0
- package/dist/cjs/graphql/graphql.js +152 -0
- package/dist/cjs/graphql/node-runner.js +109 -0
- package/dist/cjs/graphql/vite-plugin-cedar-auto-import.js +107 -0
- package/dist/cjs/graphql/vite-plugin-cedar-import-dir.js +118 -0
- package/dist/{index.d.ts.map → cjs/index.d.ts.map} +1 -1
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/internal.d.ts +28 -0
- package/dist/cjs/internal.d.ts.map +1 -0
- package/dist/cjs/internal.js +135 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/runPrerender.d.ts.map +1 -0
- package/dist/cjs/runPrerender.js +307 -0
- package/dist/cjs/runPrerenderEsm.js +304 -0
- package/dist/graphql/graphql.d.ts +3 -3
- package/dist/graphql/graphql.d.ts.map +1 -1
- package/dist/graphql/graphql.js +4 -4
- package/dist/runPrerenderEsm.d.ts +9 -0
- package/dist/runPrerenderEsm.d.ts.map +1 -0
- package/dist/{runPrerender.js → runPrerenderEsm.js} +5 -5
- package/package.json +44 -17
- package/dist/index.js +0 -1
- package/dist/runPrerender.d.ts.map +0 -1
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{runPrerender.d.ts → cjs/runPrerender.d.ts} +0 -0
package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
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 rollup_plugin_cedarjs_prerender_media_imports_exports = {};
|
|
30
|
+
__export(rollup_plugin_cedarjs_prerender_media_imports_exports, {
|
|
31
|
+
cedarjsPrerenderMediaImportsPlugin: () => cedarjsPrerenderMediaImportsPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(rollup_plugin_cedarjs_prerender_media_imports_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
|
+
var import_node_path = require("node:path");
|
|
36
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
+
var import_utils = require("./utils.js");
|
|
38
|
+
const defaultExtensions = [
|
|
39
|
+
".ico",
|
|
40
|
+
".jpg",
|
|
41
|
+
".jpeg",
|
|
42
|
+
".png",
|
|
43
|
+
".gif",
|
|
44
|
+
".svg",
|
|
45
|
+
".eot",
|
|
46
|
+
".otf",
|
|
47
|
+
".webp",
|
|
48
|
+
".ttf",
|
|
49
|
+
".woff",
|
|
50
|
+
".woff2",
|
|
51
|
+
".cur",
|
|
52
|
+
".ani",
|
|
53
|
+
".pdf",
|
|
54
|
+
".bmp"
|
|
55
|
+
];
|
|
56
|
+
function cedarjsPrerenderMediaImportsPlugin(options = {}) {
|
|
57
|
+
const extensions = options.extensions || defaultExtensions;
|
|
58
|
+
let buildManifest = null;
|
|
59
|
+
return {
|
|
60
|
+
name: "cedarjs-prerender-media-imports",
|
|
61
|
+
buildStart() {
|
|
62
|
+
try {
|
|
63
|
+
const manifestPath = (0, import_node_path.join)(
|
|
64
|
+
(0, import_project_config.getPaths)().web.dist,
|
|
65
|
+
"client-build-manifest.json"
|
|
66
|
+
);
|
|
67
|
+
buildManifest = JSON.parse(import_node_fs.default.readFileSync(manifestPath, "utf-8"));
|
|
68
|
+
} catch {
|
|
69
|
+
buildManifest = {};
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
resolveId(source, _importer) {
|
|
73
|
+
const ext = (0, import_node_path.extname)(source);
|
|
74
|
+
if (!ext || !extensions.includes(ext)) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
id: source,
|
|
79
|
+
external: false
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
load(id) {
|
|
83
|
+
const ext = (0, import_node_path.extname)(id);
|
|
84
|
+
if (!ext || !extensions.includes(ext)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const importerModule = Array.from(this.getModuleIds()).find(
|
|
88
|
+
(moduleId) => {
|
|
89
|
+
const moduleInfo = this.getModuleInfo(moduleId);
|
|
90
|
+
return moduleInfo?.importedIds?.includes(id);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
let absPath;
|
|
94
|
+
let viteManifestKey;
|
|
95
|
+
if (importerModule && importerModule !== "entry.js") {
|
|
96
|
+
const importerDir = (0, import_node_path.dirname)(importerModule);
|
|
97
|
+
absPath = (0, import_node_path.join)(importerDir, id);
|
|
98
|
+
viteManifestKey = (0, import_project_config.ensurePosixPath)((0, import_node_path.relative)((0, import_project_config.getPaths)().web.src, absPath));
|
|
99
|
+
} else {
|
|
100
|
+
const normalizedId = id.startsWith("./") ? id.slice(2) : id;
|
|
101
|
+
absPath = (0, import_node_path.join)((0, import_project_config.getPaths)().web.src, normalizedId);
|
|
102
|
+
viteManifestKey = (0, import_project_config.ensurePosixPath)(normalizedId);
|
|
103
|
+
}
|
|
104
|
+
const copiedAssetPath = buildManifest?.[viteManifestKey]?.file;
|
|
105
|
+
let assetSrc;
|
|
106
|
+
if (copiedAssetPath) {
|
|
107
|
+
assetSrc = copiedAssetPath;
|
|
108
|
+
} else {
|
|
109
|
+
assetSrc = (0, import_utils.convertToDataUrl)(absPath);
|
|
110
|
+
}
|
|
111
|
+
return `export default ${JSON.stringify(assetSrc)};`;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
cedarjsPrerenderMediaImportsPlugin
|
|
118
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
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 rollup_plugin_cedarjs_routes_auto_loader_exports = {};
|
|
30
|
+
__export(rollup_plugin_cedarjs_routes_auto_loader_exports, {
|
|
31
|
+
cedarjsRoutesAutoLoaderPlugin: () => cedarjsRoutesAutoLoaderPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(rollup_plugin_cedarjs_routes_auto_loader_exports);
|
|
34
|
+
var import_path = __toESM(require("path"), 1);
|
|
35
|
+
var import_pluginutils = require("@rollup/pluginutils");
|
|
36
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
+
var import_utils = require("./utils.js");
|
|
38
|
+
function getPathRelativeToSrc(maybeAbsolutePath) {
|
|
39
|
+
if (!import_path.default.isAbsolute(maybeAbsolutePath)) {
|
|
40
|
+
return maybeAbsolutePath;
|
|
41
|
+
}
|
|
42
|
+
return `./${import_path.default.relative((0, import_project_config.getPaths)().web.src, maybeAbsolutePath)}`;
|
|
43
|
+
}
|
|
44
|
+
function withRelativeImports(page) {
|
|
45
|
+
return {
|
|
46
|
+
...page,
|
|
47
|
+
relativeImport: (0, import_project_config.ensurePosixPath)(getPathRelativeToSrc(page.importPath))
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function cedarjsRoutesAutoLoaderPlugin() {
|
|
51
|
+
let pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
|
|
52
|
+
const duplicatePageImportNames = /* @__PURE__ */ new Set();
|
|
53
|
+
const sortedPageImportNames = pages.map((page) => page.importName).sort();
|
|
54
|
+
for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
|
|
55
|
+
if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
|
|
56
|
+
duplicatePageImportNames.add(sortedPageImportNames[i]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (duplicatePageImportNames.size > 0) {
|
|
60
|
+
const dirList = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${dirList}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const filter = (0, import_pluginutils.createFilter)(["**/src/Routes.{tsx,jsx,js}"]);
|
|
66
|
+
return {
|
|
67
|
+
name: "cedarjs-routes-auto-loader",
|
|
68
|
+
buildStart() {
|
|
69
|
+
pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
|
|
70
|
+
},
|
|
71
|
+
transform(code, id) {
|
|
72
|
+
if (!filter(id)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
let currentPages = [...pages];
|
|
76
|
+
const importRegex = /import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g;
|
|
77
|
+
let match;
|
|
78
|
+
const excludedPages = /* @__PURE__ */ new Set();
|
|
79
|
+
while ((match = importRegex.exec(code)) !== null) {
|
|
80
|
+
const [_fullMatch, defaultImportName, importPath] = match;
|
|
81
|
+
const importPathWithoutExtension = importPath.replace(
|
|
82
|
+
/\.(js|jsx|ts|tsx)$/,
|
|
83
|
+
""
|
|
84
|
+
);
|
|
85
|
+
const normalizedPathBase = importPathWithoutExtension.replace(
|
|
86
|
+
/\/[^/]+$/,
|
|
87
|
+
""
|
|
88
|
+
);
|
|
89
|
+
const normalizedPathFull = importPathWithoutExtension;
|
|
90
|
+
const userImportRelativePaths = [
|
|
91
|
+
getPathRelativeToSrc((0, import_project_config.importStatementPath)(normalizedPathBase)),
|
|
92
|
+
getPathRelativeToSrc((0, import_project_config.importStatementPath)(normalizedPathFull))
|
|
93
|
+
];
|
|
94
|
+
const pageThatUserImported = currentPages.find((page) => {
|
|
95
|
+
const pageRelativeImport = page.relativeImport.replace(
|
|
96
|
+
/\.(js|jsx|ts|tsx)$/,
|
|
97
|
+
""
|
|
98
|
+
);
|
|
99
|
+
const importNameMatches = page.importName === defaultImportName;
|
|
100
|
+
const pathMatches = userImportRelativePaths.some(
|
|
101
|
+
(path2) => pageRelativeImport === (0, import_project_config.ensurePosixPath)(path2) || pageRelativeImport.endsWith(`/${path2.split("/").pop()}`)
|
|
102
|
+
);
|
|
103
|
+
return importNameMatches || pathMatches;
|
|
104
|
+
});
|
|
105
|
+
if (pageThatUserImported) {
|
|
106
|
+
excludedPages.add(pageThatUserImported.importName);
|
|
107
|
+
currentPages = currentPages.filter(
|
|
108
|
+
(page) => page !== pageThatUserImported
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (currentPages.length === 0) {
|
|
113
|
+
return { code, map: null };
|
|
114
|
+
}
|
|
115
|
+
const imports = [];
|
|
116
|
+
const declarations = [];
|
|
117
|
+
imports.push(`import { lazy } from 'react'`);
|
|
118
|
+
for (const { importName, relativeImport } of currentPages) {
|
|
119
|
+
if (excludedPages.has(importName)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
imports.push(
|
|
123
|
+
`import __cedarjs_prerender__${importName} from '${relativeImport}';`
|
|
124
|
+
);
|
|
125
|
+
const declaration = (0, import_utils.dedent)(8)`const ${importName} = {
|
|
126
|
+
name: "${importName}",
|
|
127
|
+
prerenderLoader: (name) => ({ default: __cedarjs_prerender__${importName} }),
|
|
128
|
+
LazyComponent: lazy(() => import("${relativeImport}"))
|
|
129
|
+
}`;
|
|
130
|
+
declarations.push(declaration);
|
|
131
|
+
}
|
|
132
|
+
const autoLoaderCode = imports.join("\n") + "\n\n" + declarations.join("\n\n");
|
|
133
|
+
const finalCode = `${autoLoaderCode}
|
|
134
|
+
|
|
135
|
+
${code}`;
|
|
136
|
+
return {
|
|
137
|
+
code: finalCode,
|
|
138
|
+
map: null
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
cedarjsRoutesAutoLoaderPlugin
|
|
146
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
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 utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
convertToDataUrl: () => convertToDataUrl,
|
|
32
|
+
dedent: () => dedent
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
35
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
36
|
+
var import_mime_types = __toESM(require("mime-types"), 1);
|
|
37
|
+
function convertToDataUrl(assetPath) {
|
|
38
|
+
try {
|
|
39
|
+
const base64AssetContents = import_fs.default.readFileSync(assetPath, "base64");
|
|
40
|
+
const mimeType = import_mime_types.default.lookup(assetPath);
|
|
41
|
+
return `data:${mimeType};base64,${base64AssetContents}`;
|
|
42
|
+
} catch {
|
|
43
|
+
console.warn(`Could not read file ${assetPath} for conversion to data uri`);
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function dedent(indentLevel) {
|
|
48
|
+
return (strings, ...values) => {
|
|
49
|
+
let result = strings[0];
|
|
50
|
+
for (let i = 0; i < values.length; i++) {
|
|
51
|
+
result += values[i] + strings[i + 1];
|
|
52
|
+
}
|
|
53
|
+
const lines = result.split("\n");
|
|
54
|
+
while (lines.length > 0 && lines[0].trim() === "") {
|
|
55
|
+
lines.shift();
|
|
56
|
+
}
|
|
57
|
+
while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
|
|
58
|
+
lines.pop();
|
|
59
|
+
}
|
|
60
|
+
const minIndent = indentLevel;
|
|
61
|
+
const dedentedLines = lines.map((line) => {
|
|
62
|
+
if (line.trim() === "") {
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
const match = line.match(/^(\s*)/);
|
|
66
|
+
if (match && match[1].length >= minIndent) {
|
|
67
|
+
return line.slice(minIndent);
|
|
68
|
+
}
|
|
69
|
+
return line;
|
|
70
|
+
});
|
|
71
|
+
return dedentedLines.join("\n");
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
convertToDataUrl,
|
|
77
|
+
dedent
|
|
78
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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 utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
JS_EXT_RE: () => JS_EXT_RE,
|
|
32
|
+
getPkgType: () => getPkgType,
|
|
33
|
+
getRandomId: () => getRandomId,
|
|
34
|
+
isValidJsFile: () => isValidJsFile,
|
|
35
|
+
makeFilePath: () => makeFilePath
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(utils_exports);
|
|
38
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
39
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
40
|
+
var import_node_url = require("node:url");
|
|
41
|
+
const JS_EXT_RE = /\.([mc]?[tj]s|[tj]sx)$/;
|
|
42
|
+
function getPkgType() {
|
|
43
|
+
try {
|
|
44
|
+
const pkg = JSON.parse(
|
|
45
|
+
import_node_fs.default.readFileSync(import_node_path.default.resolve("package.json"), "utf-8")
|
|
46
|
+
);
|
|
47
|
+
return pkg.type;
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
const getRandomId = () => {
|
|
53
|
+
return Math.random().toString(36).substring(2, 15);
|
|
54
|
+
};
|
|
55
|
+
function isValidJsFile(filepath) {
|
|
56
|
+
return JS_EXT_RE.test(filepath);
|
|
57
|
+
}
|
|
58
|
+
function makeFilePath(path2) {
|
|
59
|
+
return (0, import_node_url.pathToFileURL)(path2).href;
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
JS_EXT_RE,
|
|
64
|
+
getPkgType,
|
|
65
|
+
getRandomId,
|
|
66
|
+
isValidJsFile,
|
|
67
|
+
makeFilePath
|
|
68
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const detectPrerenderRoutes: () => {
|
|
2
|
+
name: string | undefined;
|
|
3
|
+
path: string | undefined;
|
|
4
|
+
routePath: string | undefined;
|
|
5
|
+
hasParams: boolean;
|
|
6
|
+
id: string;
|
|
7
|
+
isNotFound: boolean;
|
|
8
|
+
filePath: string | undefined;
|
|
9
|
+
pageIdentifier: string | undefined;
|
|
10
|
+
}[];
|
|
11
|
+
//# sourceMappingURL=detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detection.d.ts","sourceRoot":"","sources":["../../../src/detection/detection.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB;;;;;;;;;GAsBjC,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 detection_exports = {};
|
|
20
|
+
__export(detection_exports, {
|
|
21
|
+
detectPrerenderRoutes: () => detectPrerenderRoutes
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(detection_exports);
|
|
24
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
25
|
+
var import_structure = require("@cedarjs/structure");
|
|
26
|
+
const detectPrerenderRoutes = () => {
|
|
27
|
+
const rwProject = (0, import_structure.getProject)((0, import_project_config.getPaths)().base);
|
|
28
|
+
const routes = rwProject.getRouter().routes;
|
|
29
|
+
const prerenderRoutes = routes.filter((route) => route.prerender).map((route) => ({
|
|
30
|
+
name: route.isNotFound ? "404" : route.name,
|
|
31
|
+
// `path` will be updated/expanded later where route parameters will be
|
|
32
|
+
// replaced with actual values
|
|
33
|
+
path: route.isNotFound ? "/404" : route.path,
|
|
34
|
+
// `routePath` is always the path specified on the <Route> component
|
|
35
|
+
// (or the special /404 path)
|
|
36
|
+
routePath: route.isNotFound ? "/404" : route.path,
|
|
37
|
+
hasParams: route.hasParameters,
|
|
38
|
+
id: route.id,
|
|
39
|
+
isNotFound: route.isNotFound,
|
|
40
|
+
filePath: route.page?.filePath,
|
|
41
|
+
pageIdentifier: route.page_identifier_str
|
|
42
|
+
}));
|
|
43
|
+
return prerenderRoutes;
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
detectPrerenderRoutes
|
|
48
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DocumentNode } from 'graphql';
|
|
2
|
+
export declare class PrerenderGqlError extends Error {
|
|
3
|
+
stack: string;
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class GqlHandlerImportError extends Error {
|
|
7
|
+
stack: string;
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
interface JSONParseErrorArgs {
|
|
11
|
+
query: DocumentNode;
|
|
12
|
+
variables?: Record<string, unknown>;
|
|
13
|
+
result: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class JSONParseError extends Error {
|
|
16
|
+
constructor({ query, variables, result }: JSONParseErrorArgs);
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,KAAK,EAAE,MAAM,CAAA;gBAED,OAAO,EAAE,MAAM;CAO5B;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,KAAK,EAAE,MAAM,CAAA;gBAED,OAAO,EAAE,MAAM;CAO5B;AAED,UAAU,kBAAkB;IAC1B,KAAK,EAAE,YAAY,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,kBAAkB;CAY7D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
GqlHandlerImportError: () => GqlHandlerImportError,
|
|
22
|
+
JSONParseError: () => JSONParseError,
|
|
23
|
+
PrerenderGqlError: () => PrerenderGqlError
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(errors_exports);
|
|
26
|
+
var import_graphql = require("graphql");
|
|
27
|
+
class PrerenderGqlError extends Error {
|
|
28
|
+
stack;
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super("GQL error: " + message);
|
|
31
|
+
this.stack = this.message;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class GqlHandlerImportError extends Error {
|
|
35
|
+
stack;
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super("Gql Handler Import Error: " + message);
|
|
38
|
+
this.stack = this.message;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class JSONParseError extends Error {
|
|
42
|
+
constructor({ query, variables, result }) {
|
|
43
|
+
const message = "Could not parse the GraphQL response.\n Request: " + (0, import_graphql.print)(query).split("\n").join("\n ") + "\n Variables: " + JSON.stringify(variables) + "\n Response: " + result;
|
|
44
|
+
super(message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
GqlHandlerImportError,
|
|
50
|
+
JSONParseError,
|
|
51
|
+
PrerenderGqlError
|
|
52
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DocumentNode } from 'graphql';
|
|
2
|
+
export type FileImporter = (path: string) => Promise<any>;
|
|
3
|
+
/**
|
|
4
|
+
* Loads the graphql server, with all the user's settings
|
|
5
|
+
* And execute the query against it
|
|
6
|
+
*
|
|
7
|
+
* Note that this function does NOT throw errors, even when
|
|
8
|
+
* there is a GraphQL error. Instead, it returns the result with the graphql
|
|
9
|
+
* error.
|
|
10
|
+
*/
|
|
11
|
+
export declare function executeQuery(fileImporter: FileImporter, gqlHandler: (args: any) => Promise<any>, query: DocumentNode, variables?: Record<string, unknown>): Promise<any>;
|
|
12
|
+
/**
|
|
13
|
+
* Finds the graphql handler, returns a function
|
|
14
|
+
* that can be used to execute queries against it
|
|
15
|
+
*
|
|
16
|
+
* Throws GqlHandlerImportError, so that we can warn the user (but not blow up)
|
|
17
|
+
*/
|
|
18
|
+
export declare function getGqlHandler(fileImporter: FileImporter): Promise<(operation: Record<string, unknown>) => Promise<any>>;
|
|
19
|
+
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -0,0 +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"}
|