@cedarjs/prerender 0.9.1-next.0 → 0.9.1-next.19
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/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin-cedarjs-prerender-media-imports.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AA6BpC,MAAM,WAAW,4BAA4B;IAC3C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kCAAkC,CAChD,OAAO,GAAE,4BAAiC,GACzC,MAAM,CA0ER"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { extname, join, relative, dirname } from "node:path";
|
|
3
|
+
import { ensurePosixPath, getPaths } from "@cedarjs/project-config";
|
|
4
|
+
import { convertToDataUrl } from "./utils.js";
|
|
5
|
+
const defaultExtensions = [
|
|
6
|
+
".ico",
|
|
7
|
+
".jpg",
|
|
8
|
+
".jpeg",
|
|
9
|
+
".png",
|
|
10
|
+
".gif",
|
|
11
|
+
".svg",
|
|
12
|
+
".eot",
|
|
13
|
+
".otf",
|
|
14
|
+
".webp",
|
|
15
|
+
".ttf",
|
|
16
|
+
".woff",
|
|
17
|
+
".woff2",
|
|
18
|
+
".cur",
|
|
19
|
+
".ani",
|
|
20
|
+
".pdf",
|
|
21
|
+
".bmp"
|
|
22
|
+
];
|
|
23
|
+
function cedarjsPrerenderMediaImportsPlugin(options = {}) {
|
|
24
|
+
const extensions = options.extensions || defaultExtensions;
|
|
25
|
+
let buildManifest = null;
|
|
26
|
+
return {
|
|
27
|
+
name: "cedarjs-prerender-media-imports",
|
|
28
|
+
buildStart() {
|
|
29
|
+
try {
|
|
30
|
+
const manifestPath = join(
|
|
31
|
+
getPaths().web.dist,
|
|
32
|
+
"client-build-manifest.json"
|
|
33
|
+
);
|
|
34
|
+
buildManifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
35
|
+
} catch {
|
|
36
|
+
buildManifest = {};
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
resolveId(source, _importer) {
|
|
40
|
+
const ext = extname(source);
|
|
41
|
+
if (!ext || !extensions.includes(ext)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
id: source,
|
|
46
|
+
external: false
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
load(id) {
|
|
50
|
+
const ext = extname(id);
|
|
51
|
+
if (!ext || !extensions.includes(ext)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const importerModule = Array.from(this.getModuleIds()).find(
|
|
55
|
+
(moduleId) => {
|
|
56
|
+
const moduleInfo = this.getModuleInfo(moduleId);
|
|
57
|
+
return moduleInfo?.importedIds?.includes(id);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
let absPath;
|
|
61
|
+
let viteManifestKey;
|
|
62
|
+
if (importerModule && importerModule !== "entry.js") {
|
|
63
|
+
const importerDir = dirname(importerModule);
|
|
64
|
+
absPath = join(importerDir, id);
|
|
65
|
+
viteManifestKey = ensurePosixPath(relative(getPaths().web.src, absPath));
|
|
66
|
+
} else {
|
|
67
|
+
const normalizedId = id.startsWith("./") ? id.slice(2) : id;
|
|
68
|
+
absPath = join(getPaths().web.src, normalizedId);
|
|
69
|
+
viteManifestKey = ensurePosixPath(normalizedId);
|
|
70
|
+
}
|
|
71
|
+
const copiedAssetPath = buildManifest?.[viteManifestKey]?.file;
|
|
72
|
+
let assetSrc;
|
|
73
|
+
if (copiedAssetPath) {
|
|
74
|
+
assetSrc = copiedAssetPath;
|
|
75
|
+
} else {
|
|
76
|
+
assetSrc = convertToDataUrl(absPath);
|
|
77
|
+
}
|
|
78
|
+
return `export default ${JSON.stringify(assetSrc)};`;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
cedarjsPrerenderMediaImportsPlugin
|
|
84
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin-cedarjs-routes-auto-loader.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAYpC,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAuBD,wBAAgB,6BAA6B,IAAI,MAAM,CAoJtD"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
3
|
+
import {
|
|
4
|
+
ensurePosixPath,
|
|
5
|
+
getPaths,
|
|
6
|
+
importStatementPath,
|
|
7
|
+
processPagesDir
|
|
8
|
+
} from "@cedarjs/project-config";
|
|
9
|
+
import { dedent } from "./utils.js";
|
|
10
|
+
function getPathRelativeToSrc(maybeAbsolutePath) {
|
|
11
|
+
if (!path.isAbsolute(maybeAbsolutePath)) {
|
|
12
|
+
return maybeAbsolutePath;
|
|
13
|
+
}
|
|
14
|
+
return `./${path.relative(getPaths().web.src, maybeAbsolutePath)}`;
|
|
15
|
+
}
|
|
16
|
+
function withRelativeImports(page) {
|
|
17
|
+
return {
|
|
18
|
+
...page,
|
|
19
|
+
relativeImport: ensurePosixPath(getPathRelativeToSrc(page.importPath))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function cedarjsRoutesAutoLoaderPlugin() {
|
|
23
|
+
let pages = processPagesDir().map(withRelativeImports);
|
|
24
|
+
const duplicatePageImportNames = /* @__PURE__ */ new Set();
|
|
25
|
+
const sortedPageImportNames = pages.map((page) => page.importName).sort();
|
|
26
|
+
for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
|
|
27
|
+
if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
|
|
28
|
+
duplicatePageImportNames.add(sortedPageImportNames[i]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (duplicatePageImportNames.size > 0) {
|
|
32
|
+
const dirList = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${dirList}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const filter = createFilter(["**/src/Routes.{tsx,jsx,js}"]);
|
|
38
|
+
return {
|
|
39
|
+
name: "cedarjs-routes-auto-loader",
|
|
40
|
+
buildStart() {
|
|
41
|
+
pages = processPagesDir().map(withRelativeImports);
|
|
42
|
+
},
|
|
43
|
+
transform(code, id) {
|
|
44
|
+
if (!filter(id)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
let currentPages = [...pages];
|
|
48
|
+
const importRegex = /import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g;
|
|
49
|
+
let match;
|
|
50
|
+
const excludedPages = /* @__PURE__ */ new Set();
|
|
51
|
+
while ((match = importRegex.exec(code)) !== null) {
|
|
52
|
+
const [_fullMatch, defaultImportName, importPath] = match;
|
|
53
|
+
const importPathWithoutExtension = importPath.replace(
|
|
54
|
+
/\.(js|jsx|ts|tsx)$/,
|
|
55
|
+
""
|
|
56
|
+
);
|
|
57
|
+
const normalizedPathBase = importPathWithoutExtension.replace(
|
|
58
|
+
/\/[^/]+$/,
|
|
59
|
+
""
|
|
60
|
+
);
|
|
61
|
+
const normalizedPathFull = importPathWithoutExtension;
|
|
62
|
+
const userImportRelativePaths = [
|
|
63
|
+
getPathRelativeToSrc(importStatementPath(normalizedPathBase)),
|
|
64
|
+
getPathRelativeToSrc(importStatementPath(normalizedPathFull))
|
|
65
|
+
];
|
|
66
|
+
const pageThatUserImported = currentPages.find((page) => {
|
|
67
|
+
const pageRelativeImport = page.relativeImport.replace(
|
|
68
|
+
/\.(js|jsx|ts|tsx)$/,
|
|
69
|
+
""
|
|
70
|
+
);
|
|
71
|
+
const importNameMatches = page.importName === defaultImportName;
|
|
72
|
+
const pathMatches = userImportRelativePaths.some(
|
|
73
|
+
(path2) => pageRelativeImport === ensurePosixPath(path2) || pageRelativeImport.endsWith(`/${path2.split("/").pop()}`)
|
|
74
|
+
);
|
|
75
|
+
return importNameMatches || pathMatches;
|
|
76
|
+
});
|
|
77
|
+
if (pageThatUserImported) {
|
|
78
|
+
excludedPages.add(pageThatUserImported.importName);
|
|
79
|
+
currentPages = currentPages.filter(
|
|
80
|
+
(page) => page !== pageThatUserImported
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (currentPages.length === 0) {
|
|
85
|
+
return { code, map: null };
|
|
86
|
+
}
|
|
87
|
+
const imports = [];
|
|
88
|
+
const declarations = [];
|
|
89
|
+
imports.push(`import { lazy } from 'react'`);
|
|
90
|
+
for (const { importName, relativeImport } of currentPages) {
|
|
91
|
+
if (excludedPages.has(importName)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
imports.push(
|
|
95
|
+
`import __cedarjs_prerender__${importName} from '${relativeImport}';`
|
|
96
|
+
);
|
|
97
|
+
const declaration = dedent(8)`const ${importName} = {
|
|
98
|
+
name: "${importName}",
|
|
99
|
+
prerenderLoader: (name) => ({ default: __cedarjs_prerender__${importName} }),
|
|
100
|
+
LazyComponent: lazy(() => import("${relativeImport}"))
|
|
101
|
+
}`;
|
|
102
|
+
declarations.push(declaration);
|
|
103
|
+
}
|
|
104
|
+
const autoLoaderCode = imports.join("\n") + "\n\n" + declarations.join("\n\n");
|
|
105
|
+
const finalCode = `${autoLoaderCode}
|
|
106
|
+
|
|
107
|
+
${code}`;
|
|
108
|
+
return {
|
|
109
|
+
code: finalCode,
|
|
110
|
+
map: null
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
cedarjsRoutesAutoLoaderPlugin
|
|
117
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/utils.ts"],"names":[],"mappings":"AASA,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,UASjD;AAED,wBAAgB,MAAM,CAAC,WAAW,EAAE,MAAM,aACvB,oBAAoB,aAAa,GAAG,EAAE,YAuCxD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import mime from "mime-types";
|
|
3
|
+
function convertToDataUrl(assetPath) {
|
|
4
|
+
try {
|
|
5
|
+
const base64AssetContents = fs.readFileSync(assetPath, "base64");
|
|
6
|
+
const mimeType = mime.lookup(assetPath);
|
|
7
|
+
return `data:${mimeType};base64,${base64AssetContents}`;
|
|
8
|
+
} catch {
|
|
9
|
+
console.warn(`Could not read file ${assetPath} for conversion to data uri`);
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function dedent(indentLevel) {
|
|
14
|
+
return (strings, ...values) => {
|
|
15
|
+
let result = strings[0];
|
|
16
|
+
for (let i = 0; i < values.length; i++) {
|
|
17
|
+
result += values[i] + strings[i + 1];
|
|
18
|
+
}
|
|
19
|
+
const lines = result.split("\n");
|
|
20
|
+
while (lines.length > 0 && lines[0].trim() === "") {
|
|
21
|
+
lines.shift();
|
|
22
|
+
}
|
|
23
|
+
while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
|
|
24
|
+
lines.pop();
|
|
25
|
+
}
|
|
26
|
+
const minIndent = indentLevel;
|
|
27
|
+
const dedentedLines = lines.map((line) => {
|
|
28
|
+
if (line.trim() === "") {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
const match = line.match(/^(\s*)/);
|
|
32
|
+
if (match && match[1].length >= minIndent) {
|
|
33
|
+
return line.slice(minIndent);
|
|
34
|
+
}
|
|
35
|
+
return line;
|
|
36
|
+
});
|
|
37
|
+
return dedentedLines.join("\n");
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
convertToDataUrl,
|
|
42
|
+
dedent
|
|
43
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Match .mjs, .cts, .ts, .jsx etc */
|
|
2
|
+
export declare const JS_EXT_RE: RegExp;
|
|
3
|
+
export type RequireFunction = (outfile: string, ctx: {
|
|
4
|
+
format: 'cjs' | 'esm';
|
|
5
|
+
}) => any;
|
|
6
|
+
export declare function getPkgType(): any;
|
|
7
|
+
export declare const getRandomId: () => string;
|
|
8
|
+
export declare function isValidJsFile(filepath: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a file path to a URL path (file://...)
|
|
11
|
+
* Without this, absolute paths can't be imported on Windows
|
|
12
|
+
*/
|
|
13
|
+
export declare function makeFilePath(path: string): string;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/build-and-import/utils.ts"],"names":[],"mappings":"AAIA,sCAAsC;AACtC,eAAO,MAAM,SAAS,QAA2B,CAAA;AAEjD,MAAM,MAAM,eAAe,GAAG,CAC5B,OAAO,EAAE,MAAM,EACf,GAAG,EAAE;IAAE,MAAM,EAAE,KAAK,GAAG,KAAK,CAAA;CAAE,KAC3B,GAAG,CAAA;AAER,wBAAgB,UAAU,QAYzB;AAED,eAAO,MAAM,WAAW,cAEvB,CAAA;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,WAE7C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,UAExC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
const JS_EXT_RE = /\.([mc]?[tj]s|[tj]sx)$/;
|
|
5
|
+
function getPkgType() {
|
|
6
|
+
try {
|
|
7
|
+
const pkg = JSON.parse(
|
|
8
|
+
fs.readFileSync(path.resolve("package.json"), "utf-8")
|
|
9
|
+
);
|
|
10
|
+
return pkg.type;
|
|
11
|
+
} catch {
|
|
12
|
+
}
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
const getRandomId = () => {
|
|
16
|
+
return Math.random().toString(36).substring(2, 15);
|
|
17
|
+
};
|
|
18
|
+
function isValidJsFile(filepath) {
|
|
19
|
+
return JS_EXT_RE.test(filepath);
|
|
20
|
+
}
|
|
21
|
+
function makeFilePath(path2) {
|
|
22
|
+
return pathToFileURL(path2).href;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
JS_EXT_RE,
|
|
26
|
+
getPkgType,
|
|
27
|
+
getRandomId,
|
|
28
|
+
isValidJsFile,
|
|
29
|
+
makeFilePath
|
|
30
|
+
};
|
|
@@ -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,24 @@
|
|
|
1
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
2
|
+
import { getProject } from "@cedarjs/structure";
|
|
3
|
+
const detectPrerenderRoutes = () => {
|
|
4
|
+
const rwProject = getProject(getPaths().base);
|
|
5
|
+
const routes = rwProject.getRouter().routes;
|
|
6
|
+
const prerenderRoutes = routes.filter((route) => route.prerender).map((route) => ({
|
|
7
|
+
name: route.isNotFound ? "404" : route.name,
|
|
8
|
+
// `path` will be updated/expanded later where route parameters will be
|
|
9
|
+
// replaced with actual values
|
|
10
|
+
path: route.isNotFound ? "/404" : route.path,
|
|
11
|
+
// `routePath` is always the path specified on the <Route> component
|
|
12
|
+
// (or the special /404 path)
|
|
13
|
+
routePath: route.isNotFound ? "/404" : route.path,
|
|
14
|
+
hasParams: route.hasParameters,
|
|
15
|
+
id: route.id,
|
|
16
|
+
isNotFound: route.isNotFound,
|
|
17
|
+
filePath: route.page?.filePath,
|
|
18
|
+
pageIdentifier: route.page_identifier_str
|
|
19
|
+
}));
|
|
20
|
+
return prerenderRoutes;
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
detectPrerenderRoutes
|
|
24
|
+
};
|
package/dist/errors.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
|
|
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");
|
|
1
|
+
import { print } from "graphql";
|
|
27
2
|
class PrerenderGqlError extends Error {
|
|
28
3
|
stack;
|
|
29
4
|
constructor(message) {
|
|
@@ -40,13 +15,12 @@ class GqlHandlerImportError extends Error {
|
|
|
40
15
|
}
|
|
41
16
|
class JSONParseError extends Error {
|
|
42
17
|
constructor({ query, variables, result }) {
|
|
43
|
-
const message = "Could not parse the GraphQL response.\n Request: " +
|
|
18
|
+
const message = "Could not parse the GraphQL response.\n Request: " + print(query).split("\n").join("\n ") + "\n Variables: " + JSON.stringify(variables) + "\n Response: " + result;
|
|
44
19
|
super(message);
|
|
45
20
|
}
|
|
46
21
|
}
|
|
47
|
-
|
|
48
|
-
0 && (module.exports = {
|
|
22
|
+
export {
|
|
49
23
|
GqlHandlerImportError,
|
|
50
24
|
JSONParseError,
|
|
51
25
|
PrerenderGqlError
|
|
52
|
-
}
|
|
26
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { DocumentNode } from 'graphql';
|
|
2
|
+
import type { NodeRunner } from './node-runner.js';
|
|
2
3
|
/**
|
|
3
4
|
* Loads the graphql server, with all the user's settings
|
|
4
5
|
* And execute the query against it
|
|
5
6
|
*
|
|
6
7
|
* Note that this function does NOT throw errors, even when
|
|
7
|
-
* there is a GraphQL error. Instead, it returns the result with the graphql
|
|
8
|
-
*
|
|
9
|
-
* @returns {Promise<QueryResult>}
|
|
8
|
+
* there is a GraphQL error. Instead, it returns the result with the graphql
|
|
9
|
+
* error.
|
|
10
10
|
*/
|
|
11
|
-
export declare function executeQuery(gqlHandler: (args: any) => Promise<any>, query: DocumentNode, variables?: Record<string, unknown>): Promise<any>;
|
|
11
|
+
export declare function executeQuery(nodeRunner: NodeRunner, gqlHandler: (args: any) => Promise<any>, query: DocumentNode, variables?: Record<string, unknown>): Promise<any>;
|
|
12
12
|
/**
|
|
13
13
|
* Finds the graphql handler, returns a function
|
|
14
14
|
* that can be used to execute queries against it
|
|
15
15
|
*
|
|
16
16
|
* Throws GqlHandlerImportError, so that we can warn the user (but not blow up)
|
|
17
17
|
*/
|
|
18
|
-
export declare function getGqlHandler(): Promise<(operation: Record<string, unknown>) => Promise<any>>;
|
|
18
|
+
export declare function getGqlHandler(nodeRunner: NodeRunner): Promise<(operation: Record<string, unknown>) => Promise<any>>;
|
|
19
19
|
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/graphql/graphql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
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,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AASlD;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,UAAU,EACtB,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,UAAU,EAAE,UAAU,uBAM7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,mBAUnD"}
|
package/dist/graphql/graphql.js
CHANGED
|
@@ -1,53 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 graphql_exports = {};
|
|
30
|
-
__export(graphql_exports, {
|
|
31
|
-
executeQuery: () => executeQuery,
|
|
32
|
-
getGqlHandler: () => getGqlHandler
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(graphql_exports);
|
|
35
|
-
var import_path = __toESM(require("path"));
|
|
36
|
-
var import_graphql = require("graphql");
|
|
37
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
-
var import_graphql2 = require("@cedarjs/web/dist/graphql.js");
|
|
39
|
-
var import_errors = require("../errors");
|
|
40
|
-
async function executeQuery(gqlHandler, query, variables) {
|
|
41
|
-
const config = (0, import_project_config.getConfig)();
|
|
42
|
-
const operationName = (0, import_graphql2.getOperationName)(query);
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { print } from "graphql";
|
|
3
|
+
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
4
|
+
import { getOperationName } from "@cedarjs/web/dist/graphql.js";
|
|
5
|
+
import { GqlHandlerImportError } from "../errors.js";
|
|
6
|
+
async function executeQuery(nodeRunner, gqlHandler, query, variables) {
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
const operationName = getOperationName(query);
|
|
43
9
|
const operation = {
|
|
44
10
|
operationName,
|
|
45
|
-
query:
|
|
11
|
+
query: print(query),
|
|
46
12
|
variables
|
|
47
13
|
};
|
|
48
14
|
if (config.graphql.trustedDocuments) {
|
|
49
|
-
const documentsPath =
|
|
50
|
-
const documents =
|
|
15
|
+
const documentsPath = path.join(getPaths().web.graphql, "graphql");
|
|
16
|
+
const documents = await nodeRunner.importFile(documentsPath);
|
|
51
17
|
const documentName = operationName[0].toUpperCase() + operationName.slice(1) + "Document";
|
|
52
18
|
const queryHash = documents?.[documentName]?.__meta__?.hash;
|
|
53
19
|
operation.query = void 0;
|
|
@@ -61,16 +27,16 @@ async function executeQuery(gqlHandler, query, variables) {
|
|
|
61
27
|
const handlerResult = await gqlHandler(operation);
|
|
62
28
|
return handlerResult?.body;
|
|
63
29
|
}
|
|
64
|
-
async function getGqlHandler() {
|
|
65
|
-
const gqlPath =
|
|
30
|
+
async function getGqlHandler(nodeRunner) {
|
|
31
|
+
const gqlPath = path.join(getPaths().api.functions, "graphql");
|
|
66
32
|
try {
|
|
67
|
-
const { handler } =
|
|
33
|
+
const { handler } = await nodeRunner.importFile(gqlPath);
|
|
68
34
|
return async (operation) => {
|
|
69
35
|
return await handler(buildApiEvent(operation), buildContext());
|
|
70
36
|
};
|
|
71
37
|
} catch {
|
|
72
38
|
return () => {
|
|
73
|
-
throw new
|
|
39
|
+
throw new GqlHandlerImportError(
|
|
74
40
|
`Unable to import GraphQL handler at ${gqlPath}`
|
|
75
41
|
);
|
|
76
42
|
};
|
|
@@ -145,8 +111,7 @@ function buildContext() {
|
|
|
145
111
|
}
|
|
146
112
|
};
|
|
147
113
|
}
|
|
148
|
-
|
|
149
|
-
0 && (module.exports = {
|
|
114
|
+
export {
|
|
150
115
|
executeQuery,
|
|
151
116
|
getGqlHandler
|
|
152
|
-
}
|
|
117
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
export declare class NodeRunner {
|
|
3
|
+
private viteServer?;
|
|
4
|
+
private runner?;
|
|
5
|
+
private readonly customViteConfig;
|
|
6
|
+
constructor(customViteConfig?: UserConfig);
|
|
7
|
+
init(): Promise<void>;
|
|
8
|
+
importFile(filePath: string): Promise<any>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=node-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-runner.d.ts","sourceRoot":"","sources":["../../src/graphql/node-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,MAAM,CAAA;AAsDrD,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAC,CAA2B;IAC9C,OAAO,CAAC,MAAM,CAAC,CAA4B;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAY;gBAEjC,gBAAgB,GAAE,UAAe;IAIvC,IAAI;IA6BJ,UAAU,CAAC,QAAQ,EAAE,MAAM;IAQ3B,KAAK;CAGZ"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createServer, version as viteVersion, mergeConfig } from "vite";
|
|
2
|
+
import { ViteNodeRunner } from "vite-node/client";
|
|
3
|
+
import { ViteNodeServer } from "vite-node/server";
|
|
4
|
+
import { installSourcemapsSupport } from "vite-node/source-map";
|
|
5
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
6
|
+
import {
|
|
7
|
+
cedarCellTransform,
|
|
8
|
+
cedarjsDirectoryNamedImportPlugin,
|
|
9
|
+
cedarjsJobPathInjectorPlugin,
|
|
10
|
+
cedarSwapApolloProvider
|
|
11
|
+
} from "@cedarjs/vite";
|
|
12
|
+
import { cedarAutoImportsPlugin } from "./vite-plugin-cedar-auto-import.js";
|
|
13
|
+
import { cedarImportDirPlugin } from "./vite-plugin-cedar-import-dir.js";
|
|
14
|
+
async function createViteServer(customConfig = {}) {
|
|
15
|
+
const defaultConfig = {
|
|
16
|
+
mode: "production",
|
|
17
|
+
optimizeDeps: {
|
|
18
|
+
// This is recommended in the vite-node readme
|
|
19
|
+
noDiscovery: true,
|
|
20
|
+
include: void 0
|
|
21
|
+
},
|
|
22
|
+
resolve: {
|
|
23
|
+
alias: [
|
|
24
|
+
{
|
|
25
|
+
find: /^src\/(.*?)(\.([jt]sx?))?$/,
|
|
26
|
+
replacement: getPaths().api.src + "/$1"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
plugins: [
|
|
31
|
+
cedarImportDirPlugin(),
|
|
32
|
+
cedarAutoImportsPlugin(),
|
|
33
|
+
cedarjsDirectoryNamedImportPlugin(),
|
|
34
|
+
cedarCellTransform(),
|
|
35
|
+
cedarjsJobPathInjectorPlugin(),
|
|
36
|
+
cedarSwapApolloProvider()
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
const mergedConfig = mergeConfig(defaultConfig, customConfig);
|
|
40
|
+
const server = await createServer(mergedConfig);
|
|
41
|
+
if (Number(viteVersion.split(".")[0]) < 6) {
|
|
42
|
+
await server.pluginContainer.buildStart({});
|
|
43
|
+
}
|
|
44
|
+
return server;
|
|
45
|
+
}
|
|
46
|
+
class NodeRunner {
|
|
47
|
+
viteServer = void 0;
|
|
48
|
+
runner = void 0;
|
|
49
|
+
customViteConfig;
|
|
50
|
+
constructor(customViteConfig = {}) {
|
|
51
|
+
this.customViteConfig = customViteConfig;
|
|
52
|
+
}
|
|
53
|
+
async init() {
|
|
54
|
+
this.viteServer = await createViteServer(this.customViteConfig);
|
|
55
|
+
const nodeServer = new ViteNodeServer(this.viteServer, {
|
|
56
|
+
transformMode: {
|
|
57
|
+
ssr: [/.*/],
|
|
58
|
+
web: [/\/web\//]
|
|
59
|
+
},
|
|
60
|
+
deps: {
|
|
61
|
+
fallbackCJS: true
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
installSourcemapsSupport({
|
|
65
|
+
getSourceMap: (source) => nodeServer?.getSourceMap(source)
|
|
66
|
+
});
|
|
67
|
+
this.runner = new ViteNodeRunner({
|
|
68
|
+
root: this.viteServer.config.root,
|
|
69
|
+
base: this.viteServer.config.base,
|
|
70
|
+
fetchModule(id) {
|
|
71
|
+
return nodeServer.fetchModule(id);
|
|
72
|
+
},
|
|
73
|
+
resolveId(id, importer) {
|
|
74
|
+
return nodeServer.resolveId(id, importer);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async importFile(filePath) {
|
|
79
|
+
if (!this.runner) {
|
|
80
|
+
await this.init();
|
|
81
|
+
}
|
|
82
|
+
return this.runner?.executeFile(filePath);
|
|
83
|
+
}
|
|
84
|
+
async close() {
|
|
85
|
+
await this.viteServer?.close();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
NodeRunner
|
|
90
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-auto-import.d.ts","sourceRoot":"","sources":["../../src/graphql/vite-plugin-cedar-auto-import.ts"],"names":[],"mappings":"AAWA,wBAAgB,sBAAsB,UA2ErC"}
|