@cedarjs/prerender 5.0.7-next.338 → 5.0.7

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.
Files changed (32) hide show
  1. package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -1
  2. package/dist/babelPlugins/babel-plugin-redwood-cell.js +1 -2
  3. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +1 -1
  4. package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +1 -2
  5. package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.d.ts.map +1 -1
  6. package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +1 -2
  7. package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts +3 -4
  8. package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts.map +1 -1
  9. package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts.map +1 -1
  10. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -1
  11. package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.js +1 -2
  12. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +1 -1
  13. package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +1 -2
  14. package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +1 -2
  15. package/dist/cjs/graphql/node-runner.js +2 -1
  16. package/dist/cjs/graphql/vite-plugin-cedar-import-dir.js +118 -0
  17. package/dist/cjs/runPrerender.d.ts.map +1 -1
  18. package/dist/cjs/runPrerender.js +10 -14
  19. package/dist/cjs/runPrerenderEsm.js +5 -9
  20. package/dist/graphql/node-runner.js +2 -2
  21. package/dist/graphql/vite-plugin-cedar-import-dir.d.ts +19 -0
  22. package/dist/graphql/vite-plugin-cedar-import-dir.d.ts.map +1 -0
  23. package/dist/graphql/vite-plugin-cedar-import-dir.js +84 -0
  24. package/dist/runPrerenderEsm.d.ts.map +1 -1
  25. package/dist/runPrerenderEsm.js +5 -9
  26. package/package.json +18 -17
  27. package/dist/apolloState.d.ts +0 -13
  28. package/dist/apolloState.d.ts.map +0 -1
  29. package/dist/apolloState.js +0 -6
  30. package/dist/cjs/apolloState.d.ts +0 -13
  31. package/dist/cjs/apolloState.d.ts.map +0 -1
  32. package/dist/cjs/apolloState.js +0 -30
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-redwood-cell.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/babel-plugin-redwood-cell.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAgCnD,wBAAgB,sBAAsB,CAAC,EACrC,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAmHZ"}
1
+ {"version":3,"file":"babel-plugin-redwood-cell.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/babel-plugin-redwood-cell.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AA+BnD,wBAAgB,sBAAsB,CAAC,EACrC,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAgHZ"}
@@ -2,7 +2,6 @@ import { parse } from "path";
2
2
  const EXPECTED_EXPORTS_FROM_CELL = [
3
3
  "beforeQuery",
4
4
  "QUERY",
5
- "FRAGMENT",
6
5
  "data",
7
6
  "isEmpty",
8
7
  "afterQuery",
@@ -45,7 +44,7 @@ function babelPluginRedwoodCell({
45
44
  hasDefaultExport = false;
46
45
  },
47
46
  exit(path) {
48
- const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("FRAGMENT") || exportNames.includes("data");
47
+ const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("data");
49
48
  if (hasDefaultExport || !hasQueryOrDataExport) {
50
49
  return;
51
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-redwood-prerender-media-imports.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/babel-plugin-redwood-prerender-media-imports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAY,MAAM,aAAa,CAAA;AAuC7D,wBAAgB,uCAAuC,CAAC,EACtD,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAqDZ"}
1
+ {"version":3,"file":"babel-plugin-redwood-prerender-media-imports.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/babel-plugin-redwood-prerender-media-imports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAY,MAAM,aAAa,CAAA;AAyC7D,wBAAgB,uCAAuC,CAAC,EACtD,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAqDZ"}
@@ -2,8 +2,7 @@ import { extname, join, relative, dirname } from "path";
2
2
  import { ensurePosixPath, getPaths } from "@cedarjs/project-config";
3
3
  import { convertToDataUrl } from "./utils.js";
4
4
  const defaultOptions = {
5
- // Media file extensions that Vite emits as assets, and that we therefore
6
- // have to resolve to their built asset path (or a data URL) when prerendering
5
+ // This list of extensions matches config for file-loader in
7
6
  extensions: [
8
7
  ".ico",
9
8
  ".jpg",
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-cedarjs-cell.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAoBpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAsK5C"}
1
+ {"version":3,"file":"rollup-plugin-cedarjs-cell.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAmBpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAmK5C"}
@@ -7,7 +7,6 @@ const generate = babelGenerator.default;
7
7
  const EXPECTED_EXPORTS_FROM_CELL = [
8
8
  "beforeQuery",
9
9
  "QUERY",
10
- "FRAGMENT",
11
10
  "data",
12
11
  "isEmpty",
13
12
  "afterQuery",
@@ -65,7 +64,7 @@ function cellTransformPlugin() {
65
64
  }
66
65
  }
67
66
  });
68
- const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("FRAGMENT") || exportNames.includes("data");
67
+ const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("data");
69
68
  if (hasDefaultExport || !hasQueryOrDataExport) {
70
69
  return null;
71
70
  }
@@ -1,9 +1,8 @@
1
1
  import type { Plugin as RollupPlugin } from 'rollup';
2
2
  /**
3
- * A Rollup plugin that ignores imports of HTML and CSS files by replacing them
4
- * with empty modules. This is useful when bundling code that imports these
5
- * files for the browser build (where Vite handles them), but you want Rollup to
6
- * ignore them during the build process.
3
+ * A Rollup plugin that ignores imports of HTML and CSS files by replacing them with empty modules.
4
+ * This is useful when bundling code that imports these files for webpack or other bundlers,
5
+ * but you want Rollup to ignore them during the build process.
7
6
  *
8
7
  * @param options Configuration options
9
8
  * @returns Rollup plugin
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,6BAA6B,QAAO,YAyBhD,CAAA"}
1
+ {"version":3,"file":"rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,6BAA6B,QAAO,YAyBhD,CAAA"}
@@ -1 +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;AA8BpC,MAAM,WAAW,4BAA4B;IAC3C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kCAAkC,CAChD,OAAO,GAAE,4BAAiC,GACzC,MAAM,CA0ER"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-redwood-cell.d.ts","sourceRoot":"","sources":["../../../src/babelPlugins/babel-plugin-redwood-cell.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAgCnD,wBAAgB,sBAAsB,CAAC,EACrC,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAmHZ"}
1
+ {"version":3,"file":"babel-plugin-redwood-cell.d.ts","sourceRoot":"","sources":["../../../src/babelPlugins/babel-plugin-redwood-cell.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AA+BnD,wBAAgB,sBAAsB,CAAC,EACrC,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAgHZ"}
@@ -25,7 +25,6 @@ var import_path = require("path");
25
25
  const EXPECTED_EXPORTS_FROM_CELL = [
26
26
  "beforeQuery",
27
27
  "QUERY",
28
- "FRAGMENT",
29
28
  "data",
30
29
  "isEmpty",
31
30
  "afterQuery",
@@ -68,7 +67,7 @@ function babelPluginRedwoodCell({
68
67
  hasDefaultExport = false;
69
68
  },
70
69
  exit(path) {
71
- const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("FRAGMENT") || exportNames.includes("data");
70
+ const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("data");
72
71
  if (hasDefaultExport || !hasQueryOrDataExport) {
73
72
  return;
74
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-redwood-prerender-media-imports.d.ts","sourceRoot":"","sources":["../../../src/babelPlugins/babel-plugin-redwood-prerender-media-imports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAY,MAAM,aAAa,CAAA;AAuC7D,wBAAgB,uCAAuC,CAAC,EACtD,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAqDZ"}
1
+ {"version":3,"file":"babel-plugin-redwood-prerender-media-imports.d.ts","sourceRoot":"","sources":["../../../src/babelPlugins/babel-plugin-redwood-prerender-media-imports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAY,MAAM,aAAa,CAAA;AAyC7D,wBAAgB,uCAAuC,CAAC,EACtD,KAAK,EAAE,CAAC,GACT,EAAE;IACD,KAAK,EAAE,OAAO,KAAK,CAAA;CACpB,GAAG,SAAS,CAqDZ"}
@@ -25,8 +25,7 @@ var import_path = require("path");
25
25
  var import_project_config = require("@cedarjs/project-config");
26
26
  var import_utils = require("./utils.js");
27
27
  const defaultOptions = {
28
- // Media file extensions that Vite emits as assets, and that we therefore
29
- // have to resolve to their built asset path (or a data URL) when prerendering
28
+ // This list of extensions matches config for file-loader in
30
29
  extensions: [
31
30
  ".ico",
32
31
  ".jpg",
@@ -40,7 +40,6 @@ const generate = import_generator.default.default;
40
40
  const EXPECTED_EXPORTS_FROM_CELL = [
41
41
  "beforeQuery",
42
42
  "QUERY",
43
- "FRAGMENT",
44
43
  "data",
45
44
  "isEmpty",
46
45
  "afterQuery",
@@ -98,7 +97,7 @@ function cellTransformPlugin() {
98
97
  }
99
98
  }
100
99
  });
101
- const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("FRAGMENT") || exportNames.includes("data");
100
+ const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("data");
102
101
  if (hasDefaultExport || !hasQueryOrDataExport) {
103
102
  return null;
104
103
  }
@@ -25,6 +25,7 @@ var import_vite = require("vite");
25
25
  var import_project_config = require("@cedarjs/project-config");
26
26
  var import_vite2 = require("@cedarjs/vite");
27
27
  var import_vite_plugin_cedar_auto_import = require("./vite-plugin-cedar-auto-import.js");
28
+ var import_vite_plugin_cedar_import_dir = require("./vite-plugin-cedar-import-dir.js");
28
29
  async function createViteServer(customConfig = {}) {
29
30
  const defaultConfig = {
30
31
  mode: "production",
@@ -49,7 +50,7 @@ async function createViteServer(customConfig = {}) {
49
50
  },
50
51
  plugins: [
51
52
  (0, import_vite2.cedarCjsCompatPlugin)(),
52
- (0, import_vite2.cedarImportDirPlugin)(),
53
+ (0, import_vite_plugin_cedar_import_dir.cedarImportDirPlugin)(),
53
54
  (0, import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin)(),
54
55
  (0, import_vite2.cedarjsResolveCedarStyleImportsPlugin)(),
55
56
  (0, import_vite2.cedarCellTransform)(),
@@ -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 vite_plugin_cedar_import_dir_exports = {};
30
+ __export(vite_plugin_cedar_import_dir_exports, {
31
+ cedarImportDirPlugin: () => cedarImportDirPlugin
32
+ });
33
+ module.exports = __toCommonJS(vite_plugin_cedar_import_dir_exports);
34
+ var import_node_path = __toESM(require("node:path"), 1);
35
+ var import_napi = require("@ast-grep/napi");
36
+ var import_fast_glob = __toESM(require("fast-glob"), 1);
37
+ var import_project_config = require("@cedarjs/project-config");
38
+ function cedarImportDirPlugin() {
39
+ return {
40
+ name: "vite-plugin-cedar-import-dir",
41
+ enforce: "pre",
42
+ async transform(code, id) {
43
+ if (!code.includes("/**/")) {
44
+ return null;
45
+ }
46
+ const ext = import_node_path.default.extname(id);
47
+ const language = ext === ".ts" || ext === ".tsx" ? import_napi.Lang.TypeScript : import_napi.Lang.JavaScript;
48
+ let ast;
49
+ try {
50
+ ast = (0, import_napi.parse)(language, code);
51
+ } catch (error) {
52
+ console.warn("Failed to parse file:", id);
53
+ console.warn(error);
54
+ return null;
55
+ }
56
+ const root = ast.root();
57
+ let hasTransformations = false;
58
+ const edits = [];
59
+ const globImports = root.findAll({
60
+ rule: {
61
+ pattern: "import $DEFAULT_IMPORT from $SOURCE"
62
+ }
63
+ });
64
+ for (const importNode of globImports) {
65
+ const sourceNode = importNode.getMatch("SOURCE");
66
+ const defaultImportNode = importNode.getMatch("DEFAULT_IMPORT");
67
+ if (!sourceNode || !defaultImportNode) {
68
+ continue;
69
+ }
70
+ const sourceValue = sourceNode.text().slice(1, -1);
71
+ if (!sourceValue.includes("/**/")) {
72
+ continue;
73
+ }
74
+ hasTransformations = true;
75
+ const importName = defaultImportNode.text();
76
+ const importGlob = (0, import_project_config.importStatementPath)(sourceValue);
77
+ const cwd = importGlob.startsWith("src/") ? (0, import_project_config.getPaths)().api.base : import_node_path.default.dirname(id);
78
+ try {
79
+ const dirFiles = import_fast_glob.default.sync(importGlob, { cwd }).filter(
80
+ (n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
81
+ );
82
+ const staticGlob = importGlob.split("*")[0];
83
+ const filePathToVarName = (filePath) => {
84
+ return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
85
+ };
86
+ let replacement = `let ${importName} = {};
87
+ `;
88
+ for (const filePath of dirFiles) {
89
+ const { dir: fileDir, name: fileName } = import_node_path.default.parse(filePath);
90
+ const fileImportPath = fileDir + "/" + fileName;
91
+ const filePathVarName = filePathToVarName(filePath);
92
+ const namespaceImportName = `${importName}_${filePathVarName}`;
93
+ replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
94
+ `;
95
+ replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
96
+ `;
97
+ }
98
+ edits.push(importNode.replace(replacement.trim()));
99
+ } catch (error) {
100
+ console.warn(`Failed to process glob import: ${sourceValue}`, error);
101
+ }
102
+ }
103
+ if (hasTransformations && edits.length > 0) {
104
+ const transformedCode = root.commitEdits(edits);
105
+ return {
106
+ code: transformedCode,
107
+ map: null
108
+ // For simplicity, not generating source maps
109
+ };
110
+ }
111
+ return null;
112
+ }
113
+ };
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ cedarImportDirPlugin
118
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"runPrerender.d.ts","sourceRoot":"","sources":["../../src/runPrerender.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA2O7C,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,CAuIzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
1
+ {"version":3,"file":"runPrerender.d.ts","sourceRoot":"","sources":["../../src/runPrerender.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAsO7C,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"}
@@ -40,7 +40,8 @@ var import_cheerio = require("cheerio");
40
40
  var import_server = __toESM(require("react-dom/server"), 1);
41
41
  var import_babel_config = require("@cedarjs/babel-config");
42
42
  var import_project_config = require("@cedarjs/project-config");
43
- var import_apolloState = require("./apolloState.js");
43
+ var import_router = require("@cedarjs/router");
44
+ var import_util = require("@cedarjs/router/dist/util");
44
45
  var import_babel_plugin_redwood_cell = require("./babelPlugins/babel-plugin-redwood-cell.js");
45
46
  var import_babel_plugin_redwood_prerender_media_imports = require("./babelPlugins/babel-plugin-redwood-prerender-media-imports.js");
46
47
  var import_detection = require("./detection/detection.js");
@@ -51,7 +52,6 @@ const { ApolloClient, InMemoryCache } = apolloClient.default || apolloClient;
51
52
  const prerenderApolloClient = new ApolloClient({ cache: new InMemoryCache() });
52
53
  async function recursivelyRender(App, Routes, renderPath, fileImporter, gqlHandler, queryCache) {
53
54
  const { CellCacheContextProvider, getOperationName } = require("@cedarjs/web");
54
- const { LocationProvider } = require("@cedarjs/router");
55
55
  let shouldShowGraphqlHandlerNotFoundWarn = false;
56
56
  await Promise.all(
57
57
  Object.entries(queryCache).map(async ([cacheKey, value]) => {
@@ -114,7 +114,7 @@ async function recursivelyRender(App, Routes, renderPath, fileImporter, gqlHandl
114
114
  );
115
115
  const prerenderUrl = process.env.RWJS_PRERENDER_ORIGIN || "http://localhost" + renderPath;
116
116
  const componentAsHtml = import_server.default.renderToString(
117
- /* @__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))))
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
118
  );
119
119
  if (Object.values(queryCache).some((value) => !value.hasProcessed)) {
120
120
  return recursivelyRender(
@@ -135,13 +135,12 @@ async function recursivelyRender(App, Routes, renderPath, fileImporter, gqlHandl
135
135
  }
136
136
  }
137
137
  function insertChunkLoadingScript(indexHtmlTree, renderPath) {
138
- const { matchPath } = require("@cedarjs/router/dist/util");
139
138
  const prerenderRoutes = (0, import_detection.detectPrerenderRoutes)();
140
139
  const route = prerenderRoutes.find((route2) => {
141
140
  if (!route2.routePath) {
142
141
  return false;
143
142
  }
144
- return matchPath(route2.routePath, renderPath).match;
143
+ return (0, import_util.matchPath)(route2.routePath, renderPath).match;
145
144
  });
146
145
  if (!route) {
147
146
  throw new Error("Could not find a Route matching " + renderPath);
@@ -228,8 +227,8 @@ const runPrerender = async ({
228
227
  overrides: [
229
228
  {
230
229
  plugins: [
231
- // Vite handles CSS imports for the browser build
232
230
  ["ignore-html-and-css-imports"],
231
+ // webpack/postcss handles CSS imports
233
232
  [import_babel_plugin_redwood_prerender_media_imports.babelPluginRedwoodPrerenderMediaImports]
234
233
  ]
235
234
  },
@@ -280,14 +279,11 @@ const runPrerender = async ({
280
279
  }
281
280
  }
282
281
  }
283
- const apolloState = prerenderApolloClient.extract();
284
- if ((0, import_apolloState.hasApolloState)(apolloState)) {
285
- indexHtmlTree("head").append(
286
- `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
287
- apolloState
288
- )}</script>`
289
- );
290
- }
282
+ indexHtmlTree("head").append(
283
+ `<script> globalThis.__REDWOOD__APOLLO_STATE = ${JSON.stringify(
284
+ prerenderApolloClient.extract()
285
+ )}</script>`
286
+ );
291
287
  prerenderApolloClient.resetStore();
292
288
  insertChunkLoadingScript(indexHtmlTree, renderPath);
293
289
  indexHtmlTree("#cedar-app, #redwood-app").append(componentAsHtml);
@@ -40,7 +40,6 @@ var import_cheerio = require("cheerio");
40
40
  var import_server = __toESM(require("react-dom/server"), 1);
41
41
  var import_project_config = require("@cedarjs/project-config");
42
42
  var import_util = require("@cedarjs/router/dist/util");
43
- var import_apolloState = require("./apolloState.js");
44
43
  var import_buildAndImport = require("./build-and-import/buildAndImport.js");
45
44
  var import_detection = require("./detection/detection.js");
46
45
  var import_errors = require("./errors.js");
@@ -277,14 +276,11 @@ const runPrerender = async ({
277
276
  }
278
277
  }
279
278
  }
280
- const apolloState = prerenderApolloClient.extract();
281
- if ((0, import_apolloState.hasApolloState)(apolloState)) {
282
- indexHtmlTree("head").append(
283
- `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
284
- apolloState
285
- )}</script>`
286
- );
287
- }
279
+ indexHtmlTree("head").append(
280
+ `<script> globalThis.__REDWOOD__APOLLO_STATE = ${JSON.stringify(
281
+ prerenderApolloClient.extract()
282
+ )}</script>`
283
+ );
288
284
  prerenderApolloClient.resetStore();
289
285
  insertChunkLoadingScript(indexHtmlTree, renderPath);
290
286
  indexHtmlTree("#cedar-app, #redwood-app").append(componentAsHtml);
@@ -5,10 +5,10 @@ import {
5
5
  cedarjsResolveCedarStyleImportsPlugin,
6
6
  cedarjsJobPathInjectorPlugin,
7
7
  cedarSwapApolloProvider,
8
- cedarCjsCompatPlugin,
9
- cedarImportDirPlugin
8
+ cedarCjsCompatPlugin
10
9
  } from "@cedarjs/vite";
11
10
  import { cedarAutoImportsPlugin } from "./vite-plugin-cedar-auto-import.js";
11
+ import { cedarImportDirPlugin } from "./vite-plugin-cedar-import-dir.js";
12
12
  async function createViteServer(customConfig = {}) {
13
13
  const defaultConfig = {
14
14
  mode: "production",
@@ -0,0 +1,19 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,84 @@
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 +1 @@
1
- {"version":3,"file":"runPrerenderEsm.d.ts","sourceRoot":"","sources":["../src/runPrerenderEsm.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAqQ7C,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,CA4HzC,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,MAAM,EACtB,SAAS,MAAM,SAchB,CAAA"}
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"}
@@ -10,7 +10,6 @@ import {
10
10
  importStatementPath
11
11
  } from "@cedarjs/project-config";
12
12
  import { matchPath } from "@cedarjs/router/dist/util";
13
- import { hasApolloState } from "./apolloState.js";
14
13
  import { buildAndImport } from "./build-and-import/buildAndImport.js";
15
14
  import { detectPrerenderRoutes } from "./detection/detection.js";
16
15
  import {
@@ -251,14 +250,11 @@ const runPrerender = async ({
251
250
  }
252
251
  }
253
252
  }
254
- const apolloState = prerenderApolloClient.extract();
255
- if (hasApolloState(apolloState)) {
256
- indexHtmlTree("head").append(
257
- `<script> globalThis.__CEDAR__APOLLO_STATE = ${JSON.stringify(
258
- apolloState
259
- )}</script>`
260
- );
261
- }
253
+ indexHtmlTree("head").append(
254
+ `<script> globalThis.__REDWOOD__APOLLO_STATE = ${JSON.stringify(
255
+ prerenderApolloClient.extract()
256
+ )}</script>`
257
+ );
262
258
  prerenderApolloClient.resetStore();
263
259
  insertChunkLoadingScript(indexHtmlTree, renderPath);
264
260
  indexHtmlTree("#cedar-app, #redwood-app").append(componentAsHtml);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/prerender",
3
- "version": "5.0.7-next.338",
3
+ "version": "5.0.7",
4
4
  "description": "CedarJS prerender",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,18 +67,19 @@
67
67
  "test:watch": "vitest watch"
68
68
  },
69
69
  "dependencies": {
70
- "@babel/generator": "7.29.8",
71
- "@babel/parser": "7.29.8",
72
- "@babel/traverse": "7.29.8",
73
- "@cedarjs/babel-config": "5.0.7-next.338",
74
- "@cedarjs/project-config": "5.0.7-next.338",
75
- "@cedarjs/structure": "5.0.7-next.338",
76
- "@cedarjs/vite": "5.0.7-next.338",
70
+ "@ast-grep/napi": "0.43.0",
71
+ "@babel/generator": "7.29.7",
72
+ "@babel/parser": "7.29.7",
73
+ "@babel/traverse": "7.29.7",
74
+ "@cedarjs/babel-config": "5.0.7",
75
+ "@cedarjs/project-config": "5.0.7",
76
+ "@cedarjs/structure": "5.0.7",
77
+ "@cedarjs/vite": "5.0.7",
77
78
  "@rollup/plugin-alias": "5.1.1",
78
79
  "@rollup/plugin-commonjs": "28.0.9",
79
80
  "@rollup/plugin-node-resolve": "16.0.3",
80
81
  "@rollup/plugin-replace": "6.0.3",
81
- "@swc/core": "1.16.0",
82
+ "@swc/core": "1.15.41",
82
83
  "@whatwg-node/fetch": "0.10.13",
83
84
  "babel-plugin-ignore-html-and-css-imports": "0.1.0",
84
85
  "cheerio": "1.2.0",
@@ -88,23 +89,23 @@
88
89
  "rollup-plugin-swc3": "0.12.1",
89
90
  "unimport": "5.7.0",
90
91
  "unplugin-auto-import": "19.3.0",
91
- "vite": "7.3.6"
92
+ "vite": "7.3.5"
92
93
  },
93
94
  "devDependencies": {
94
- "@cedarjs/framework-tools": "5.0.7-next.338",
95
- "@cedarjs/router": "5.0.7-next.338",
96
- "@cedarjs/web": "5.0.7-next.338",
95
+ "@cedarjs/framework-tools": "5.0.7",
96
+ "@cedarjs/router": "5.0.7",
97
+ "@cedarjs/web": "5.0.7",
97
98
  "@types/mime-types": "2.1.4",
98
99
  "@types/react": "^18.2.55",
99
100
  "babel-plugin-tester": "11.0.4",
100
101
  "concurrently": "9.2.4",
101
- "publint": "0.3.23",
102
+ "publint": "0.3.21",
102
103
  "typescript": "5.9.3",
103
- "vitest": "4.1.10"
104
+ "vitest": "3.2.6"
104
105
  },
105
106
  "peerDependencies": {
106
- "@cedarjs/router": "5.0.7-next.338",
107
- "@cedarjs/web": "5.0.7-next.338",
107
+ "@cedarjs/router": "5.0.7",
108
+ "@cedarjs/web": "5.0.7",
108
109
  "react": "18.3.1",
109
110
  "react-dom": "18.3.1"
110
111
  },
@@ -1,13 +0,0 @@
1
- /**
2
- * Whether an extracted Apollo cache state is non-empty and worth inlining
3
- * into the prerendered HTML as a bootstrap `<script>`.
4
- *
5
- * Only emit the Apollo state bootstrap when there is state to restore. Both
6
- * consumers (`CedarApolloProvider` and the suspense provider) already do
7
- * `.restore(globalThis?.__CEDAR__APOLLO_STATE ?? {})`, so an empty payload is
8
- * a no-op. It is still an inline `<script>` though, which every strict-CSP app
9
- * has to allow-list with a hash that goes stale whenever the payload changes.
10
- * A page that prerenders no Cells emits nothing.
11
- */
12
- export declare function hasApolloState(state: unknown): state is Record<string, unknown>;
13
- //# sourceMappingURL=apolloState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apolloState.d.ts","sourceRoot":"","sources":["../src/apolloState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIlC"}
@@ -1,6 +0,0 @@
1
- function hasApolloState(state) {
2
- return typeof state === "object" && state !== null && Object.keys(state).length > 0;
3
- }
4
- export {
5
- hasApolloState
6
- };
@@ -1,13 +0,0 @@
1
- /**
2
- * Whether an extracted Apollo cache state is non-empty and worth inlining
3
- * into the prerendered HTML as a bootstrap `<script>`.
4
- *
5
- * Only emit the Apollo state bootstrap when there is state to restore. Both
6
- * consumers (`CedarApolloProvider` and the suspense provider) already do
7
- * `.restore(globalThis?.__CEDAR__APOLLO_STATE ?? {})`, so an empty payload is
8
- * a no-op. It is still an inline `<script>` though, which every strict-CSP app
9
- * has to allow-list with a hash that goes stale whenever the payload changes.
10
- * A page that prerenders no Cells emits nothing.
11
- */
12
- export declare function hasApolloState(state: unknown): state is Record<string, unknown>;
13
- //# sourceMappingURL=apolloState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apolloState.d.ts","sourceRoot":"","sources":["../../src/apolloState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIlC"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var apolloState_exports = {};
20
- __export(apolloState_exports, {
21
- hasApolloState: () => hasApolloState
22
- });
23
- module.exports = __toCommonJS(apolloState_exports);
24
- function hasApolloState(state) {
25
- return typeof state === "object" && state !== null && Object.keys(state).length > 0;
26
- }
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- hasApolloState
30
- });