@cedarjs/vite 5.0.0-canary.2593 → 5.0.0-canary.2594
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/cjs/index.js +7 -8
- package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +126 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -8
- package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts +24 -0
- package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-routes-auto-loader.js +98 -0
- package/package.json +13 -13
package/dist/cjs/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
cedarNodePolyfills: () => import_vite_plugin_cedar_node_polyfills2.cedarNodePolyfills,
|
|
40
40
|
cedarRemoveDevFatalErrorPage: () => import_vite_plugin_cedar_remove_dev_fatal_error_page2.cedarRemoveDevFatalErrorPage,
|
|
41
41
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
42
|
+
cedarRoutesAutoLoaderPlugin: () => import_vite_plugin_cedar_routes_auto_loader2.cedarRoutesAutoLoaderPlugin,
|
|
42
43
|
cedarSwapApolloProvider: () => import_vite_plugin_swap_apollo_provider2.cedarSwapApolloProvider,
|
|
43
44
|
cedarTransformJsAsJsx: () => import_vite_plugin_jsx_loader2.cedarTransformJsAsJsx,
|
|
44
45
|
cedarUniversalDeployPlugin: () => import_vite_plugin_cedar_universal_deploy.cedarUniversalDeployPlugin,
|
|
@@ -58,6 +59,7 @@ var import_vite_plugin_cedar_html_env = require("./plugins/vite-plugin-cedar-htm
|
|
|
58
59
|
var import_vite_plugin_cedar_node_polyfills = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
59
60
|
var import_vite_plugin_cedar_remove_dev_fatal_error_page = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
60
61
|
var import_vite_plugin_cedar_remove_from_bundle = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
62
|
+
var import_vite_plugin_cedar_routes_auto_loader = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
|
|
61
63
|
var import_vite_plugin_cedar_wait_for_api_server = require("./plugins/vite-plugin-cedar-wait-for-api-server.js");
|
|
62
64
|
var import_vite_plugin_cedarjs_resolve_cedar_style_imports = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
|
|
63
65
|
var import_vite_plugin_jsx_loader = require("./plugins/vite-plugin-jsx-loader.js");
|
|
@@ -71,6 +73,7 @@ var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-ht
|
|
|
71
73
|
var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
|
|
72
74
|
var import_vite_plugin_cedar_node_polyfills2 = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
73
75
|
var import_vite_plugin_cedar_remove_dev_fatal_error_page2 = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
76
|
+
var import_vite_plugin_cedar_routes_auto_loader2 = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
|
|
74
77
|
var import_vite_plugin_cedar_remove_from_bundle2 = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
75
78
|
var import_vite_plugin_cedarjs_resolve_cedar_style_imports2 = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
|
|
76
79
|
var import_vite_plugin_cedarjs_job_path_injector = require("./plugins/vite-plugin-cedarjs-job-path-injector.js");
|
|
@@ -86,14 +89,7 @@ function cedar({ mode } = {}) {
|
|
|
86
89
|
forVite: true
|
|
87
90
|
});
|
|
88
91
|
const babelConfig = {
|
|
89
|
-
...webSideDefaultBabelConfig
|
|
90
|
-
// For RSC we don't want to include the routes auto-loader plugin as we
|
|
91
|
-
// handle that differently in each specific RSC build stage
|
|
92
|
-
overrides: rscEnabled ? webSideDefaultBabelConfig.overrides.filter((override) => {
|
|
93
|
-
return !override.plugins?.some((plugin) => {
|
|
94
|
-
return Array.isArray(plugin) && plugin[2] === "babel-plugin-redwood-routes-auto-loader";
|
|
95
|
-
});
|
|
96
|
-
}) : webSideDefaultBabelConfig.overrides
|
|
92
|
+
...webSideDefaultBabelConfig
|
|
97
93
|
};
|
|
98
94
|
return [
|
|
99
95
|
mode === "test" && (0, import_vitest.cedarJsRouterImportTransformPlugin)(),
|
|
@@ -110,6 +106,8 @@ function cedar({ mode } = {}) {
|
|
|
110
106
|
(0, import_vite_plugin_jsx_loader.cedarTransformJsAsJsx)(),
|
|
111
107
|
(0, import_vite_plugin_cedar_remove_from_bundle.cedarRemoveFromBundle)(),
|
|
112
108
|
(0, import_vite_plugin_cedar_remove_dev_fatal_error_page.cedarRemoveDevFatalErrorPage)(),
|
|
109
|
+
// RSC handles route auto-loading differently in each build stage
|
|
110
|
+
!rscEnabled && (0, import_vite_plugin_cedar_routes_auto_loader.cedarRoutesAutoLoaderPlugin)(),
|
|
113
111
|
(0, import_plugin_react.default)({ babel: babelConfig })
|
|
114
112
|
];
|
|
115
113
|
}
|
|
@@ -127,6 +125,7 @@ var index_default = cedar;
|
|
|
127
125
|
cedarNodePolyfills,
|
|
128
126
|
cedarRemoveDevFatalErrorPage,
|
|
129
127
|
cedarRemoveFromBundle,
|
|
128
|
+
cedarRoutesAutoLoaderPlugin,
|
|
130
129
|
cedarSwapApolloProvider,
|
|
131
130
|
cedarTransformJsAsJsx,
|
|
132
131
|
cedarUniversalDeployPlugin,
|
|
@@ -0,0 +1,126 @@
|
|
|
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_routes_auto_loader_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_routes_auto_loader_exports, {
|
|
31
|
+
cedarRoutesAutoLoaderPlugin: () => cedarRoutesAutoLoaderPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_routes_auto_loader_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_vite = require("vite");
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
function getPathRelativeToSrc(maybeAbsolutePath) {
|
|
39
|
+
const withoutExt = maybeAbsolutePath.replace(/\.[^/.]+$/, "");
|
|
40
|
+
if (withoutExt.startsWith("src/")) {
|
|
41
|
+
const basePath = import_node_path.default.join((0, import_project_config.getPaths)().web.base, withoutExt);
|
|
42
|
+
const resolved = (0, import_project_config.resolveFile)(basePath) || (0, import_project_config.resolveFile)(import_node_path.default.join(basePath, "index")) || (0, import_project_config.resolveFile)(import_node_path.default.join(basePath, import_node_path.default.basename(basePath)));
|
|
43
|
+
if (resolved) {
|
|
44
|
+
const resolvedWithoutExt = resolved.replace(/\.[^/.]+$/, "");
|
|
45
|
+
return "./" + import_node_path.default.relative((0, import_project_config.getPaths)().web.src, resolvedWithoutExt);
|
|
46
|
+
}
|
|
47
|
+
return "./" + withoutExt.slice("src/".length);
|
|
48
|
+
}
|
|
49
|
+
if (!import_node_path.default.isAbsolute(withoutExt)) {
|
|
50
|
+
return withoutExt;
|
|
51
|
+
}
|
|
52
|
+
return `./${import_node_path.default.relative((0, import_project_config.getPaths)().web.src, withoutExt)}`;
|
|
53
|
+
}
|
|
54
|
+
function withRelativeImports(page) {
|
|
55
|
+
return {
|
|
56
|
+
...page,
|
|
57
|
+
relativeImport: (0, import_project_config.ensurePosixPath)(getPathRelativeToSrc(page.importPath))
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function cedarRoutesAutoLoaderPlugin() {
|
|
61
|
+
const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
|
|
62
|
+
const initialPages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
|
|
63
|
+
const duplicatePageImportNames = /* @__PURE__ */ new Set();
|
|
64
|
+
const sortedPageImportNames = initialPages.map((page) => page.importName).sort();
|
|
65
|
+
for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
|
|
66
|
+
if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
|
|
67
|
+
duplicatePageImportNames.add(sortedPageImportNames[i]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (duplicatePageImportNames.size > 0) {
|
|
71
|
+
const pageNames = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${pageNames}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
name: "cedar-routes-auto-loader",
|
|
78
|
+
transform(code, id) {
|
|
79
|
+
if ((0, import_vite.normalizePath)(id) !== routesFileId) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
let pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
|
|
83
|
+
const importRe = /^import\s+\w+\s+from\s+['"]([^'"]+)['"]/gm;
|
|
84
|
+
const appPath = (0, import_project_config.resolveFile)(import_node_path.default.join((0, import_project_config.getPaths)().web.src, "App"));
|
|
85
|
+
if (appPath) {
|
|
86
|
+
const appSource = import_node_fs.default.readFileSync(appPath, "utf8");
|
|
87
|
+
let appMatch;
|
|
88
|
+
while ((appMatch = importRe.exec(appSource)) !== null) {
|
|
89
|
+
const rel = (0, import_project_config.ensurePosixPath)(
|
|
90
|
+
getPathRelativeToSrc((0, import_project_config.importStatementPath)(appMatch[1]))
|
|
91
|
+
);
|
|
92
|
+
pages = pages.filter((page) => page.relativeImport !== rel);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
importRe.lastIndex = 0;
|
|
96
|
+
let routesMatch;
|
|
97
|
+
while ((routesMatch = importRe.exec(code)) !== null) {
|
|
98
|
+
const rel = (0, import_project_config.ensurePosixPath)(
|
|
99
|
+
getPathRelativeToSrc((0, import_project_config.importStatementPath)(routesMatch[1]))
|
|
100
|
+
);
|
|
101
|
+
pages = pages.filter((page) => page.relativeImport !== rel);
|
|
102
|
+
}
|
|
103
|
+
if (pages.length === 0) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const lines = [`import { lazy } from 'react'`];
|
|
107
|
+
for (const { importName, relativeImport } of pages) {
|
|
108
|
+
lines.push(
|
|
109
|
+
`const ${importName} = {`,
|
|
110
|
+
` name: "${importName}",`,
|
|
111
|
+
` prerenderLoader: (name) => ({ default: globalThis.__REDWOOD__PRERENDER_PAGES[name] }),`,
|
|
112
|
+
` LazyComponent: lazy(() => import("${relativeImport}")),`,
|
|
113
|
+
`}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
code: lines.join("\n") + "\n\n" + code,
|
|
118
|
+
map: null
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
+
0 && (module.exports = {
|
|
125
|
+
cedarRoutesAutoLoaderPlugin
|
|
126
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { cedarHtmlEnvPlugin } from './plugins/vite-plugin-cedar-html-env.js';
|
|
|
7
7
|
export { cedarImportDirPlugin } from './plugins/vite-plugin-cedar-import-dir.js';
|
|
8
8
|
export { cedarNodePolyfills } from './plugins/vite-plugin-cedar-node-polyfills.js';
|
|
9
9
|
export { cedarRemoveDevFatalErrorPage } from './plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js';
|
|
10
|
+
export { cedarRoutesAutoLoaderPlugin } from './plugins/vite-plugin-cedar-routes-auto-loader.js';
|
|
10
11
|
export { cedarRemoveFromBundle } from './plugins/vite-plugin-cedar-remove-from-bundle.js';
|
|
11
12
|
export { cedarjsResolveCedarStyleImportsPlugin } from './plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js';
|
|
12
13
|
export { cedarjsJobPathInjectorPlugin } from './plugins/vite-plugin-cedarjs-job-path-injector.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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,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
|
@@ -12,6 +12,7 @@ import { cedarHtmlEnvPlugin } from "./plugins/vite-plugin-cedar-html-env.js";
|
|
|
12
12
|
import { cedarNodePolyfills } from "./plugins/vite-plugin-cedar-node-polyfills.js";
|
|
13
13
|
import { cedarRemoveDevFatalErrorPage } from "./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js";
|
|
14
14
|
import { cedarRemoveFromBundle } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
|
|
15
|
+
import { cedarRoutesAutoLoaderPlugin } from "./plugins/vite-plugin-cedar-routes-auto-loader.js";
|
|
15
16
|
import { cedarWaitForApiServer } from "./plugins/vite-plugin-cedar-wait-for-api-server.js";
|
|
16
17
|
import { cedarjsResolveCedarStyleImportsPlugin } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
|
|
17
18
|
import { cedarTransformJsAsJsx } from "./plugins/vite-plugin-jsx-loader.js";
|
|
@@ -25,6 +26,7 @@ import { cedarHtmlEnvPlugin as cedarHtmlEnvPlugin2 } from "./plugins/vite-plugin
|
|
|
25
26
|
import { cedarImportDirPlugin } from "./plugins/vite-plugin-cedar-import-dir.js";
|
|
26
27
|
import { cedarNodePolyfills as cedarNodePolyfills2 } from "./plugins/vite-plugin-cedar-node-polyfills.js";
|
|
27
28
|
import { cedarRemoveDevFatalErrorPage as cedarRemoveDevFatalErrorPage2 } from "./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js";
|
|
29
|
+
import { cedarRoutesAutoLoaderPlugin as cedarRoutesAutoLoaderPlugin2 } from "./plugins/vite-plugin-cedar-routes-auto-loader.js";
|
|
28
30
|
import { cedarRemoveFromBundle as cedarRemoveFromBundle2 } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
|
|
29
31
|
import { cedarjsResolveCedarStyleImportsPlugin as cedarjsResolveCedarStyleImportsPlugin2 } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
|
|
30
32
|
import { cedarjsJobPathInjectorPlugin } from "./plugins/vite-plugin-cedarjs-job-path-injector.js";
|
|
@@ -40,14 +42,7 @@ function cedar({ mode } = {}) {
|
|
|
40
42
|
forVite: true
|
|
41
43
|
});
|
|
42
44
|
const babelConfig = {
|
|
43
|
-
...webSideDefaultBabelConfig
|
|
44
|
-
// For RSC we don't want to include the routes auto-loader plugin as we
|
|
45
|
-
// handle that differently in each specific RSC build stage
|
|
46
|
-
overrides: rscEnabled ? webSideDefaultBabelConfig.overrides.filter((override) => {
|
|
47
|
-
return !override.plugins?.some((plugin) => {
|
|
48
|
-
return Array.isArray(plugin) && plugin[2] === "babel-plugin-redwood-routes-auto-loader";
|
|
49
|
-
});
|
|
50
|
-
}) : webSideDefaultBabelConfig.overrides
|
|
45
|
+
...webSideDefaultBabelConfig
|
|
51
46
|
};
|
|
52
47
|
return [
|
|
53
48
|
mode === "test" && cedarJsRouterImportTransformPlugin(),
|
|
@@ -64,6 +59,8 @@ function cedar({ mode } = {}) {
|
|
|
64
59
|
cedarTransformJsAsJsx(),
|
|
65
60
|
cedarRemoveFromBundle(),
|
|
66
61
|
cedarRemoveDevFatalErrorPage(),
|
|
62
|
+
// RSC handles route auto-loading differently in each build stage
|
|
63
|
+
!rscEnabled && cedarRoutesAutoLoaderPlugin(),
|
|
67
64
|
react({ babel: babelConfig })
|
|
68
65
|
];
|
|
69
66
|
}
|
|
@@ -80,6 +77,7 @@ export {
|
|
|
80
77
|
cedarNodePolyfills2 as cedarNodePolyfills,
|
|
81
78
|
cedarRemoveDevFatalErrorPage2 as cedarRemoveDevFatalErrorPage,
|
|
82
79
|
cedarRemoveFromBundle2 as cedarRemoveFromBundle,
|
|
80
|
+
cedarRoutesAutoLoaderPlugin2 as cedarRoutesAutoLoaderPlugin,
|
|
83
81
|
cedarSwapApolloProvider2 as cedarSwapApolloProvider,
|
|
84
82
|
cedarTransformJsAsJsx2 as cedarTransformJsAsJsx,
|
|
85
83
|
cedarUniversalDeployPlugin,
|
|
@@ -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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "5.0.0-canary.
|
|
3
|
+
"version": "5.0.0-canary.2594",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
"@babel/parser": "7.29.7",
|
|
64
64
|
"@babel/traverse": "7.29.7",
|
|
65
65
|
"@babel/types": "7.29.7",
|
|
66
|
-
"@cedarjs/api": "5.0.0-canary.
|
|
67
|
-
"@cedarjs/babel-config": "5.0.0-canary.
|
|
68
|
-
"@cedarjs/context": "5.0.0-canary.
|
|
69
|
-
"@cedarjs/cookie-jar": "5.0.0-canary.
|
|
70
|
-
"@cedarjs/graphql-server": "5.0.0-canary.
|
|
71
|
-
"@cedarjs/internal": "5.0.0-canary.
|
|
72
|
-
"@cedarjs/project-config": "5.0.0-canary.
|
|
73
|
-
"@cedarjs/server-store": "5.0.0-canary.
|
|
74
|
-
"@cedarjs/testing": "5.0.0-canary.
|
|
66
|
+
"@cedarjs/api": "5.0.0-canary.2594",
|
|
67
|
+
"@cedarjs/babel-config": "5.0.0-canary.2594",
|
|
68
|
+
"@cedarjs/context": "5.0.0-canary.2594",
|
|
69
|
+
"@cedarjs/cookie-jar": "5.0.0-canary.2594",
|
|
70
|
+
"@cedarjs/graphql-server": "5.0.0-canary.2594",
|
|
71
|
+
"@cedarjs/internal": "5.0.0-canary.2594",
|
|
72
|
+
"@cedarjs/project-config": "5.0.0-canary.2594",
|
|
73
|
+
"@cedarjs/server-store": "5.0.0-canary.2594",
|
|
74
|
+
"@cedarjs/testing": "5.0.0-canary.2594",
|
|
75
75
|
"@fastify/url-data": "6.0.3",
|
|
76
76
|
"@swc/core": "1.15.41",
|
|
77
77
|
"@universal-deploy/store": "^0.2.1",
|
|
@@ -105,9 +105,9 @@
|
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@arethetypeswrong/cli": "0.18.4",
|
|
108
|
-
"@cedarjs/auth": "5.0.0-canary.
|
|
109
|
-
"@cedarjs/router": "5.0.0-canary.
|
|
110
|
-
"@cedarjs/web": "5.0.0-canary.
|
|
108
|
+
"@cedarjs/auth": "5.0.0-canary.2594",
|
|
109
|
+
"@cedarjs/router": "5.0.0-canary.2594",
|
|
110
|
+
"@cedarjs/web": "5.0.0-canary.2594",
|
|
111
111
|
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
|
|
112
112
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
113
113
|
"@types/aws-lambda": "8.10.162",
|