@cedarjs/vite 4.2.1-next.0 → 4.2.1-next.269

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 (73) hide show
  1. package/bins/cedar-unified-dev.mjs +7 -0
  2. package/dist/apiDevMiddleware.d.ts.map +1 -1
  3. package/dist/apiDevMiddleware.js +18 -5
  4. package/dist/buildApp.d.ts +2 -1
  5. package/dist/buildApp.d.ts.map +1 -1
  6. package/dist/buildApp.js +151 -26
  7. package/dist/buildFeServer.d.ts.map +1 -1
  8. package/dist/buildFeServer.js +1 -1
  9. package/dist/buildRouteHooks.d.ts.map +1 -1
  10. package/dist/buildRouteHooks.js +7 -3
  11. package/dist/cedar-unified-dev.d.ts +13 -2
  12. package/dist/cedar-unified-dev.d.ts.map +1 -1
  13. package/dist/cedar-unified-dev.js +171 -16
  14. package/dist/cjs/apiDevMiddleware.js +18 -5
  15. package/dist/cjs/buildApp.js +154 -29
  16. package/dist/cjs/buildFeServer.js +1 -1
  17. package/dist/cjs/buildRouteHooks.js +17 -3
  18. package/dist/cjs/cedar-unified-dev.js +184 -16
  19. package/dist/cjs/devFeServer.js +2 -1
  20. package/dist/cjs/index.js +18 -8
  21. package/dist/cjs/lib/getMergedConfig.js +12 -4
  22. package/dist/cjs/lib/workspacePackageAliases.js +2 -8
  23. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +95 -0
  24. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +20 -5
  25. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +61 -0
  26. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +126 -0
  27. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +202 -14
  28. package/dist/cjs/runFeServer.js +2 -1
  29. package/dist/cjs/utils.js +2 -1
  30. package/dist/devFeServer.d.ts +1 -0
  31. package/dist/devFeServer.js +2 -1
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +14 -8
  35. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  36. package/dist/lib/getMergedConfig.js +12 -4
  37. package/dist/lib/workspacePackageAliases.d.ts.map +1 -1
  38. package/dist/lib/workspacePackageAliases.js +2 -8
  39. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts +44 -0
  40. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +1 -0
  41. package/dist/plugins/vite-plugin-cedar-context-wrapping.js +60 -0
  42. package/dist/plugins/vite-plugin-cedar-entry-injection.d.ts.map +1 -1
  43. package/dist/plugins/vite-plugin-cedar-entry-injection.js +20 -5
  44. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts +15 -0
  45. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts.map +1 -0
  46. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +37 -0
  47. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts +24 -0
  48. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts.map +1 -0
  49. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.js +98 -0
  50. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
  51. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +202 -14
  52. package/dist/runFeServer.d.ts +1 -0
  53. package/dist/runFeServer.d.ts.map +1 -1
  54. package/dist/runFeServer.js +2 -1
  55. package/dist/utils.d.ts.map +1 -1
  56. package/dist/utils.js +2 -1
  57. package/package.json +31 -61
  58. package/dist/buildUDApiServer.d.ts +0 -24
  59. package/dist/buildUDApiServer.d.ts.map +0 -1
  60. package/dist/buildUDApiServer.js +0 -41
  61. package/dist/cjs/buildUDApiServer.js +0 -75
  62. package/dist/cjs/ud-handlers/catch-all.js +0 -65
  63. package/dist/cjs/ud-handlers/function.js +0 -47
  64. package/dist/cjs/ud-handlers/graphql.js +0 -59
  65. package/dist/ud-handlers/catch-all.d.ts +0 -15
  66. package/dist/ud-handlers/catch-all.d.ts.map +0 -1
  67. package/dist/ud-handlers/catch-all.js +0 -41
  68. package/dist/ud-handlers/function.d.ts +0 -5
  69. package/dist/ud-handlers/function.d.ts.map +0 -1
  70. package/dist/ud-handlers/function.js +0 -23
  71. package/dist/ud-handlers/graphql.d.ts +0 -7
  72. package/dist/ud-handlers/graphql.d.ts.map +0 -1
  73. package/dist/ud-handlers/graphql.js +0 -35
package/dist/cjs/utils.js CHANGED
@@ -28,6 +28,7 @@ __export(utils_exports, {
28
28
  module.exports = __toCommonJS(utils_exports);
29
29
  var import_node_url = require("node:url");
30
30
  var import_project_config = require("@cedarjs/project-config");
31
+ var import_packageManager = require("@cedarjs/project-config/packageManager");
31
32
  function stripQueryStringAndHashFromPath(url) {
32
33
  return url.split("?")[0].split("#")[0];
33
34
  }
@@ -36,7 +37,7 @@ function ensureProcessDirWeb(webDir = (0, import_project_config.getPaths)().web.
36
37
  console.error("\u26A0\uFE0F Warning: CWD is ", process.cwd());
37
38
  console.warn("~".repeat(50));
38
39
  console.warn(
39
- "The cwd must be web/. Please use `yarn cedar <command>` or run the command from the web/ directory."
40
+ `The cwd must be web/. Please use \`${(0, import_packageManager.prettyPrintCedarCommand)(["<command>"])}\` or run the command from the web/ directory.`
40
41
  );
41
42
  console.log(`Changing cwd to ${webDir}....`);
42
43
  console.log();
@@ -1,2 +1,3 @@
1
+ #!/usr/bin/env node
1
2
  export {};
2
3
  //# sourceMappingURL=devFeServer.d.ts.map
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  import { createServerAdapter } from "@whatwg-node/server";
2
3
  import express from "express";
3
4
  import { createServer as createViteServer } from "vite";
@@ -40,7 +41,7 @@ async function createServer() {
40
41
  }
41
42
  if (!rwPaths.web.viteConfig) {
42
43
  throw new Error(
43
- "Vite config not found. You need to setup your project with Vite using `yarn cedar setup vite`"
44
+ "Vite config not found. Please set up Vite before running the dev server."
44
45
  );
45
46
  }
46
47
  const vite = await createViteServer({
package/dist/index.d.ts CHANGED
@@ -2,10 +2,14 @@ import type { PluginOption } from 'vite';
2
2
  export { cedarAutoImportsPlugin } from './plugins/vite-plugin-cedar-auto-import.js';
3
3
  export { cedarCjsCompatPlugin } from './plugins/vite-plugin-cedar-cjs-compat.js';
4
4
  export { cedarCellTransform } from './plugins/vite-plugin-cedar-cell.js';
5
+ export { cedarContextWrappingPlugin } from './plugins/vite-plugin-cedar-context-wrapping.js';
6
+ export { applyContextWrapping } from './plugins/vite-plugin-cedar-context-wrapping.js';
5
7
  export { cedarEntryInjectionPlugin } from './plugins/vite-plugin-cedar-entry-injection.js';
6
8
  export { cedarHtmlEnvPlugin } from './plugins/vite-plugin-cedar-html-env.js';
7
9
  export { cedarImportDirPlugin } from './plugins/vite-plugin-cedar-import-dir.js';
8
10
  export { cedarNodePolyfills } from './plugins/vite-plugin-cedar-node-polyfills.js';
11
+ export { cedarRemoveDevFatalErrorPage } from './plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js';
12
+ export { cedarRoutesAutoLoaderPlugin } from './plugins/vite-plugin-cedar-routes-auto-loader.js';
9
13
  export { cedarRemoveFromBundle } from './plugins/vite-plugin-cedar-remove-from-bundle.js';
10
14
  export { cedarjsResolveCedarStyleImportsPlugin } from './plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js';
11
15
  export { cedarjsJobPathInjectorPlugin } from './plugins/vite-plugin-cedarjs-job-path-injector.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAqBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAyClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAuBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAA;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAgClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
package/dist/index.js CHANGED
@@ -10,7 +10,9 @@ import { cedarCellTransform } from "./plugins/vite-plugin-cedar-cell.js";
10
10
  import { cedarEntryInjectionPlugin } from "./plugins/vite-plugin-cedar-entry-injection.js";
11
11
  import { cedarHtmlEnvPlugin } from "./plugins/vite-plugin-cedar-html-env.js";
12
12
  import { cedarNodePolyfills } from "./plugins/vite-plugin-cedar-node-polyfills.js";
13
+ import { cedarRemoveDevFatalErrorPage } from "./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js";
13
14
  import { cedarRemoveFromBundle } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
15
+ import { cedarRoutesAutoLoaderPlugin } from "./plugins/vite-plugin-cedar-routes-auto-loader.js";
14
16
  import { cedarWaitForApiServer } from "./plugins/vite-plugin-cedar-wait-for-api-server.js";
15
17
  import { cedarjsResolveCedarStyleImportsPlugin } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
16
18
  import { cedarTransformJsAsJsx } from "./plugins/vite-plugin-jsx-loader.js";
@@ -19,10 +21,14 @@ import { cedarSwapApolloProvider } from "./plugins/vite-plugin-swap-apollo-provi
19
21
  import { cedarAutoImportsPlugin } from "./plugins/vite-plugin-cedar-auto-import.js";
20
22
  import { cedarCjsCompatPlugin } from "./plugins/vite-plugin-cedar-cjs-compat.js";
21
23
  import { cedarCellTransform as cedarCellTransform2 } from "./plugins/vite-plugin-cedar-cell.js";
24
+ import { cedarContextWrappingPlugin } from "./plugins/vite-plugin-cedar-context-wrapping.js";
25
+ import { applyContextWrapping } from "./plugins/vite-plugin-cedar-context-wrapping.js";
22
26
  import { cedarEntryInjectionPlugin as cedarEntryInjectionPlugin2 } from "./plugins/vite-plugin-cedar-entry-injection.js";
23
27
  import { cedarHtmlEnvPlugin as cedarHtmlEnvPlugin2 } from "./plugins/vite-plugin-cedar-html-env.js";
24
28
  import { cedarImportDirPlugin } from "./plugins/vite-plugin-cedar-import-dir.js";
25
29
  import { cedarNodePolyfills as cedarNodePolyfills2 } from "./plugins/vite-plugin-cedar-node-polyfills.js";
30
+ import { cedarRemoveDevFatalErrorPage as cedarRemoveDevFatalErrorPage2 } from "./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js";
31
+ import { cedarRoutesAutoLoaderPlugin as cedarRoutesAutoLoaderPlugin2 } from "./plugins/vite-plugin-cedar-routes-auto-loader.js";
26
32
  import { cedarRemoveFromBundle as cedarRemoveFromBundle2 } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
27
33
  import { cedarjsResolveCedarStyleImportsPlugin as cedarjsResolveCedarStyleImportsPlugin2 } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
28
34
  import { cedarjsJobPathInjectorPlugin } from "./plugins/vite-plugin-cedarjs-job-path-injector.js";
@@ -38,14 +44,7 @@ function cedar({ mode } = {}) {
38
44
  forVite: true
39
45
  });
40
46
  const babelConfig = {
41
- ...webSideDefaultBabelConfig,
42
- // For RSC we don't want to include the routes auto-loader plugin as we
43
- // handle that differently in each specific RSC build stage
44
- overrides: rscEnabled ? webSideDefaultBabelConfig.overrides.filter((override) => {
45
- return !override.plugins?.some((plugin) => {
46
- return Array.isArray(plugin) && plugin[2] === "babel-plugin-redwood-routes-auto-loader";
47
- });
48
- }) : webSideDefaultBabelConfig.overrides
47
+ ...webSideDefaultBabelConfig
49
48
  };
50
49
  return [
51
50
  mode === "test" && cedarJsRouterImportTransformPlugin(),
@@ -61,21 +60,28 @@ function cedar({ mode } = {}) {
61
60
  cedarCellTransform(),
62
61
  cedarTransformJsAsJsx(),
63
62
  cedarRemoveFromBundle(),
63
+ cedarRemoveDevFatalErrorPage(),
64
+ // RSC handles route auto-loading differently in each build stage
65
+ !rscEnabled && cedarRoutesAutoLoaderPlugin(),
64
66
  react({ babel: babelConfig })
65
67
  ];
66
68
  }
67
69
  var index_default = cedar;
68
70
  export {
71
+ applyContextWrapping,
69
72
  cedar,
70
73
  cedarAutoImportsPlugin,
71
74
  cedarCellTransform2 as cedarCellTransform,
72
75
  cedarCjsCompatPlugin,
76
+ cedarContextWrappingPlugin,
73
77
  cedarEntryInjectionPlugin2 as cedarEntryInjectionPlugin,
74
78
  cedarHtmlEnvPlugin2 as cedarHtmlEnvPlugin,
75
79
  cedarImportDirPlugin,
76
80
  cedarMergedConfig2 as cedarMergedConfig,
77
81
  cedarNodePolyfills2 as cedarNodePolyfills,
82
+ cedarRemoveDevFatalErrorPage2 as cedarRemoveDevFatalErrorPage,
78
83
  cedarRemoveFromBundle2 as cedarRemoveFromBundle,
84
+ cedarRoutesAutoLoaderPlugin2 as cedarRoutesAutoLoaderPlugin,
79
85
  cedarSwapApolloProvider2 as cedarSwapApolloProvider,
80
86
  cedarTransformJsAsJsx2 as cedarTransformJsAsJsx,
81
87
  cedarUniversalDeployPlugin,
@@ -1 +1 @@
1
- {"version":3,"file":"getMergedConfig.d.ts","sourceRoot":"","sources":["../../src/lib/getMergedConfig.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAS5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAC5D,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CAqHpE"}
1
+ {"version":3,"file":"getMergedConfig.d.ts","sourceRoot":"","sources":["../../src/lib/getMergedConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAS5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAC5D,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CA4HpE"}
@@ -21,9 +21,14 @@ function getMergedConfig(cedarConfig, cedarPaths) {
21
21
  apiPort = cedarConfig.api.port;
22
22
  }
23
23
  const defaultCedarViteConfig = {
24
- root: cedarPaths.web.src,
24
+ root: cedarPaths.web.base,
25
25
  resolve: {
26
- alias: workspaceAliases
26
+ alias: {
27
+ ...workspaceAliases,
28
+ // In test mode, register the virtual module alias so that
29
+ // MockProviders can resolve the user's Routes file
30
+ ...env.mode === "test" ? { "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes } : {}
31
+ }
27
32
  },
28
33
  // @MARK: when we have these aliases, the warnings from the FE server go
29
34
  // away BUT, if you have imports like this:
@@ -75,7 +80,7 @@ function getMergedConfig(cedarConfig, cedarPaths) {
75
80
  // Note that sourcemap can be boolean or 'inline'
76
81
  sourcemap: !env.isSsrBuild && cedarConfig.web.sourceMap,
77
82
  rollupOptions: {
78
- input: getRollupInput(!!env.isSsrBuild)
83
+ input: getRollupInput(userConfig, !!env.isSsrBuild)
79
84
  }
80
85
  },
81
86
  // @MARK: do not set buildSsrCjsExternalHeuristics here
@@ -108,9 +113,12 @@ function getMergedConfig(cedarConfig, cedarPaths) {
108
113
  return mergeConfig(defaultCedarViteConfig, userConfig);
109
114
  };
110
115
  }
111
- function getRollupInput(ssr) {
116
+ function getRollupInput(userConfig, ssr) {
112
117
  const cedarConfig = getConfig();
113
118
  const cedarPaths = getPaths();
119
+ if (userConfig.build?.rollupOptions?.input) {
120
+ return userConfig.build.rollupOptions.input;
121
+ }
114
122
  if (!cedarPaths.web.entryClient) {
115
123
  throw new Error("entryClient not defined");
116
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"workspacePackageAliases.d.ts","sourceRoot":"","sources":["../../src/lib/workspacePackageAliases.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AA2D5D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,KAAK,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiExB"}
1
+ {"version":3,"file":"workspacePackageAliases.d.ts","sourceRoot":"","sources":["../../src/lib/workspacePackageAliases.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AA4D5D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,KAAK,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoDxB"}
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { normalizePath } from "vite";
4
+ import { getNonApiWebWorkspaces } from "@cedarjs/project-config/workspaces";
4
5
  function findSourceEntry(pkgDir, pkgJson) {
5
6
  let distEntry = null;
6
7
  if (typeof pkgJson.main === "string") {
@@ -38,14 +39,7 @@ function getWorkspacePackageAliases(cedarPaths, cedarConfig) {
38
39
  return {};
39
40
  }
40
41
  try {
41
- const rootPkgPath = path.join(cedarPaths.base, "package.json");
42
- const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, "utf-8"));
43
- if (!Array.isArray(rootPkg.workspaces) || rootPkg.workspaces.length <= 2) {
44
- return {};
45
- }
46
- const nonApiWebWorkspaces = rootPkg.workspaces.filter(
47
- (w) => w !== "api" && w !== "web"
48
- );
42
+ const nonApiWebWorkspaces = getNonApiWebWorkspaces(cedarPaths.base);
49
43
  if (nonApiWebWorkspaces.length === 0) {
50
44
  return {};
51
45
  }
@@ -0,0 +1,44 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin that wraps user API functions to ensure context isolation has
4
+ * been performed. This should already be done at the request level but in
5
+ * serverless environments like Netlify we need to do this at the function
6
+ * level as a safeguard.
7
+ *
8
+ * For each file in `api/src/functions/` that exports a `handler`, this plugin:
9
+ *
10
+ * 1. Adds an import at the top of the file:
11
+ * import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '@cedarjs/context/dist/store'
12
+ *
13
+ * 2. Renames the original handler:
14
+ * const __rw_handler = <original handler value>
15
+ *
16
+ * 3. Replaces the handler export with a wrapper that checks context isolation:
17
+ * export const handler = (__rw_event, __rw__context) => {
18
+ * const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
19
+ * if (__rw_contextStore === undefined) {
20
+ * return __rw_getAsyncStoreInstance().run(new Map(), __rw_handler, __rw_event, __rw__context)
21
+ * }
22
+ * return __rw_handler(__rw_event, __rw__context)
23
+ * }
24
+ *
25
+ * This replaces `babel-plugin-redwood-context-wrapping` for Vite builds.
26
+ * The babel plugin is still used for Jest and prerender.
27
+ */
28
+ export declare function cedarContextWrappingPlugin({ projectIsEsm, }?: {
29
+ projectIsEsm?: boolean;
30
+ }): Plugin;
31
+ /**
32
+ * Wraps the `handler` export of an API function file with an async context
33
+ * store guard. Returns the transformed code, or `null` if the file does not
34
+ * export a `handler`.
35
+ *
36
+ * This is the context-isolation safeguard that used to be performed by
37
+ * `babel-plugin-redwood-context-wrapping`. It is exported as a standalone
38
+ * function so it can be applied from build pipelines that don't go through
39
+ * Vite's plugin pipeline (e.g. the legacy esbuild API build).
40
+ */
41
+ export declare function applyContextWrapping(code: string, { projectIsEsm }?: {
42
+ projectIsEsm?: boolean;
43
+ }): string | null;
44
+ //# sourceMappingURL=vite-plugin-cedar-context-wrapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAoB,GACrB,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG,MAAM,CAuBd;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CAsDf"}
@@ -0,0 +1,60 @@
1
+ import path from "node:path";
2
+ import { normalizePath } from "vite";
3
+ import { getPaths } from "@cedarjs/project-config";
4
+ function cedarContextWrappingPlugin({
5
+ projectIsEsm = false
6
+ } = {}) {
7
+ return {
8
+ name: "cedar-context-wrapping",
9
+ transform(code, id) {
10
+ let paths;
11
+ try {
12
+ paths = getPaths();
13
+ } catch {
14
+ return null;
15
+ }
16
+ const functionsDir = normalizePath(path.join(paths.api.src, "functions"));
17
+ if (!normalizePath(id).startsWith(functionsDir + "/")) {
18
+ return null;
19
+ }
20
+ const wrapped = applyContextWrapping(code, { projectIsEsm });
21
+ return wrapped ? { code: wrapped, map: null } : null;
22
+ }
23
+ };
24
+ }
25
+ function applyContextWrapping(code, { projectIsEsm = false } = {}) {
26
+ const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
27
+ const handlerMatch = handlerRe.exec(code);
28
+ if (!handlerMatch) {
29
+ return null;
30
+ }
31
+ const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
32
+ const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
33
+ const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
34
+ const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
35
+ `;
36
+ const handlerStart = handlerMatch.index;
37
+ const before = code.slice(0, handlerStart);
38
+ const after = code.slice(handlerStart);
39
+ const renamed = after.replace(handlerRe, "const __rw_handler =");
40
+ const wrappedHandler = `
41
+ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
42
+ // The store will be undefined if no context isolation has been performed yet
43
+ const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
44
+ if (__rw_contextStore === undefined) {
45
+ return __rw_getAsyncStoreInstance().run(
46
+ new Map(),
47
+ __rw_handler,
48
+ __rw_event,
49
+ __rw__context
50
+ )
51
+ }
52
+ return __rw_handler(__rw_event, __rw__context)
53
+ }
54
+ `;
55
+ return before + importStatement + renamed + wrappedHandler;
56
+ }
57
+ export {
58
+ applyContextWrapping,
59
+ cedarContextWrappingPlugin
60
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-entry-injection.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-entry-injection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC,wBAAgB,yBAAyB,IAAI,MAAM,CA6DlD"}
1
+ {"version":3,"file":"vite-plugin-cedar-entry-injection.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-entry-injection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC,wBAAgB,yBAAyB,IAAI,MAAM,CAqFlD"}
@@ -3,21 +3,36 @@ import path from "node:path";
3
3
  import { normalizePath } from "vite";
4
4
  import { getPaths } from "@cedarjs/project-config";
5
5
  function cedarEntryInjectionPlugin() {
6
- const rwPaths = getPaths();
7
- const clientEntryPath = rwPaths.web.entryClient;
6
+ const cedarPaths = getPaths();
7
+ const clientEntryPath = cedarPaths.web.entryClient;
8
8
  if (!clientEntryPath) {
9
9
  throw new Error(
10
10
  "Vite client entry point not found. Please check that your project has an entry.client.{jsx,tsx} file in the web/src directory."
11
11
  );
12
12
  }
13
- const relativeEntryPath = path.relative(rwPaths.web.src, clientEntryPath);
13
+ const relativeEntryPath = normalizePath(
14
+ path.relative(cedarPaths.web.base, clientEntryPath)
15
+ );
14
16
  return {
15
17
  name: "cedar-entry-injection",
18
+ // Vite's dependency optimizer and dev server resolve the script tag
19
+ // src="/src/entry.client.{tsx,jsx}" as an absolute filesystem path
20
+ // (/src/entry.client.tsx) instead of relative to the Vite root.
21
+ // This hook maps it to the real file path so Vite can find it.
22
+ resolveId(id) {
23
+ if (id === "/" + relativeEntryPath) {
24
+ return clientEntryPath;
25
+ }
26
+ return null;
27
+ },
16
28
  // ---------- Bundle injection ----------
17
29
  // Used by Vite during dev, to inject the entrypoint.
18
30
  transformIndexHtml: {
19
31
  order: "pre",
20
- handler: (html) => {
32
+ handler: (html, ctx) => {
33
+ if (!ctx.filename || normalizePath(ctx.filename) !== normalizePath(cedarPaths.web.html)) {
34
+ return html;
35
+ }
21
36
  if (fs.existsSync(clientEntryPath)) {
22
37
  return html.replace(
23
38
  "</head>",
@@ -34,7 +49,7 @@ function cedarEntryInjectionPlugin() {
34
49
  // Used by rollup during build to inject the entrypoint
35
50
  // but note index.html does not come through as an id during dev
36
51
  transform: (code, id) => {
37
- if (fs.existsSync(clientEntryPath) && normalizePath(id) === normalizePath(rwPaths.web.html)) {
52
+ if (fs.existsSync(clientEntryPath) && normalizePath(id) === normalizePath(cedarPaths.web.html)) {
38
53
  return {
39
54
  code: code.replace(
40
55
  "</head>",
@@ -0,0 +1,15 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin to remove the DevFatalErrorPage import in production builds.
4
+ *
5
+ * Replaces:
6
+ * import { DevFatalErrorPage } from '@cedarjs/web/dist/components/DevFatalErrorPage'
7
+ * with:
8
+ * const DevFatalErrorPage = undefined
9
+ *
10
+ * This ensures the DevFatalErrorPage component is not shipped in the
11
+ * production bundle. In development, the import is kept so the page
12
+ * renders when an unhandled error bubbles to the top of the app.
13
+ */
14
+ export declare function cedarRemoveDevFatalErrorPage(): Plugin;
15
+ //# sourceMappingURL=vite-plugin-cedar-remove-dev-fatal-error-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-remove-dev-fatal-error-page.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAA;AAclD;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAgCrD"}
@@ -0,0 +1,37 @@
1
+ const DEV_FATAL_ERROR_PAGE_MODULE = "@cedarjs/web/dist/components/DevFatalErrorPage";
2
+ function escapeRegExp(s) {
3
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ }
5
+ const ESCAPED_MODULE = escapeRegExp(DEV_FATAL_ERROR_PAGE_MODULE);
6
+ const IMPORT_PATTERN = new RegExp(
7
+ `import\\s*\\{[^}]*\\bDevFatalErrorPage\\b[^}]*\\}\\s*from\\s*['"]${ESCAPED_MODULE}['"]`
8
+ );
9
+ function cedarRemoveDevFatalErrorPage() {
10
+ let config;
11
+ return {
12
+ name: "cedar-remove-dev-fatal-error-page",
13
+ apply: "build",
14
+ configResolved(resolvedConfig) {
15
+ config = resolvedConfig;
16
+ },
17
+ transform(code) {
18
+ if (config.command === "build" && config.mode === "development") {
19
+ return null;
20
+ }
21
+ if (!code.includes(DEV_FATAL_ERROR_PAGE_MODULE)) {
22
+ return null;
23
+ }
24
+ const newCode = code.replace(
25
+ IMPORT_PATTERN,
26
+ "const DevFatalErrorPage = undefined"
27
+ );
28
+ if (newCode === code) {
29
+ return null;
30
+ }
31
+ return { code: newCode, map: null };
32
+ }
33
+ };
34
+ }
35
+ export {
36
+ cedarRemoveDevFatalErrorPage
37
+ };
@@ -0,0 +1,24 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin to auto-load page components into the Routes file.
4
+ *
5
+ * For each page found in `web/src/pages` that is not already explicitly
6
+ * imported in Routes.tsx, this plugin prepends a lazy-loaded declaration:
7
+ *
8
+ * ```js
9
+ * const PageName = {
10
+ * name: "PageName",
11
+ * prerenderLoader: (name) => ({ default: globalThis.__REDWOOD__PRERENDER_PAGES[name] }),
12
+ * LazyComponent: lazy(() => import("./pages/PageName/PageName")),
13
+ * }
14
+ * ```
15
+ *
16
+ * Pages already imported by App.tsx are also excluded to avoid Vite's
17
+ * "dynamically imported by Routes.tsx but also statically imported by App.tsx"
18
+ * warning.
19
+ *
20
+ * This replaces `babel-plugin-redwood-routes-auto-loader` for Vite builds.
21
+ * The babel plugin is still used for Jest and prerender.
22
+ */
23
+ export declare function cedarRoutesAutoLoaderPlugin(): Plugin;
24
+ //# sourceMappingURL=vite-plugin-cedar-routes-auto-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-routes-auto-loader.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-routes-auto-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAqDlC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAsFpD"}
@@ -0,0 +1,98 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { normalizePath } from "vite";
4
+ import {
5
+ ensurePosixPath,
6
+ getPaths,
7
+ importStatementPath,
8
+ processPagesDir,
9
+ resolveFile
10
+ } from "@cedarjs/project-config";
11
+ function getPathRelativeToSrc(maybeAbsolutePath) {
12
+ const withoutExt = maybeAbsolutePath.replace(/\.[^/.]+$/, "");
13
+ if (withoutExt.startsWith("src/")) {
14
+ const basePath = path.join(getPaths().web.base, withoutExt);
15
+ const resolved = resolveFile(basePath) || resolveFile(path.join(basePath, "index")) || resolveFile(path.join(basePath, path.basename(basePath)));
16
+ if (resolved) {
17
+ const resolvedWithoutExt = resolved.replace(/\.[^/.]+$/, "");
18
+ return "./" + path.relative(getPaths().web.src, resolvedWithoutExt);
19
+ }
20
+ return "./" + withoutExt.slice("src/".length);
21
+ }
22
+ if (!path.isAbsolute(withoutExt)) {
23
+ return withoutExt;
24
+ }
25
+ return `./${path.relative(getPaths().web.src, withoutExt)}`;
26
+ }
27
+ function withRelativeImports(page) {
28
+ return {
29
+ ...page,
30
+ relativeImport: ensurePosixPath(getPathRelativeToSrc(page.importPath))
31
+ };
32
+ }
33
+ function cedarRoutesAutoLoaderPlugin() {
34
+ const routesFileId = normalizePath(getPaths().web.routes);
35
+ const initialPages = processPagesDir().map(withRelativeImports);
36
+ const duplicatePageImportNames = /* @__PURE__ */ new Set();
37
+ const sortedPageImportNames = initialPages.map((page) => page.importName).sort();
38
+ for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
39
+ if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
40
+ duplicatePageImportNames.add(sortedPageImportNames[i]);
41
+ }
42
+ }
43
+ if (duplicatePageImportNames.size > 0) {
44
+ const pageNames = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
45
+ throw new Error(
46
+ `Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${pageNames}`
47
+ );
48
+ }
49
+ return {
50
+ name: "cedar-routes-auto-loader",
51
+ transform(code, id) {
52
+ if (normalizePath(id) !== routesFileId) {
53
+ return null;
54
+ }
55
+ let pages = processPagesDir().map(withRelativeImports);
56
+ const importRe = /^import\s+\w+\s+from\s+['"]([^'"]+)['"]/gm;
57
+ const appPath = resolveFile(path.join(getPaths().web.src, "App"));
58
+ if (appPath) {
59
+ const appSource = fs.readFileSync(appPath, "utf8");
60
+ let appMatch;
61
+ while ((appMatch = importRe.exec(appSource)) !== null) {
62
+ const rel = ensurePosixPath(
63
+ getPathRelativeToSrc(importStatementPath(appMatch[1]))
64
+ );
65
+ pages = pages.filter((page) => page.relativeImport !== rel);
66
+ }
67
+ }
68
+ importRe.lastIndex = 0;
69
+ let routesMatch;
70
+ while ((routesMatch = importRe.exec(code)) !== null) {
71
+ const rel = ensurePosixPath(
72
+ getPathRelativeToSrc(importStatementPath(routesMatch[1]))
73
+ );
74
+ pages = pages.filter((page) => page.relativeImport !== rel);
75
+ }
76
+ if (pages.length === 0) {
77
+ return null;
78
+ }
79
+ const lines = [`import { lazy } from 'react'`];
80
+ for (const { importName, relativeImport } of pages) {
81
+ lines.push(
82
+ `const ${importName} = {`,
83
+ ` name: "${importName}",`,
84
+ ` prerenderLoader: (name) => ({ default: globalThis.__REDWOOD__PRERENDER_PAGES[name] }),`,
85
+ ` LazyComponent: lazy(() => import("${relativeImport}")),`,
86
+ `}`
87
+ );
88
+ }
89
+ return {
90
+ code: lines.join("\n") + "\n\n" + code,
91
+ map: null
92
+ };
93
+ }
94
+ };
95
+ }
96
+ export {
97
+ cedarRoutesAutoLoaderPlugin
98
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AA6GD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CA4DR"}
1
+ {"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AA6GD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CA0GR"}