@edgeone/react-router 0.0.1-beta.1

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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @edgeone/react-router
2
+
3
+ This adapter allows React Router to deploy your hybrid or server rendered site to [EdgeOne Pages](https://pages.edgeone.ai/).
4
+
5
+ ## Documentation
6
+
7
+ Read the [`@edgeone/react-router` docs](https://pages.edgeone.ai/document/framework-react-router)
8
+
9
+ ## Support
10
+
11
+ - Get help in the [EdgeOne Pages Discord](https://discord.com/invite/KpdcJ8xbq6).
12
+
13
+ - Check our [Product Introduction](https://pages.edgeone.ai/document/product-introduction) for more on integrations.
14
+
15
+ ## License
16
+
17
+ MIT
@@ -0,0 +1,12 @@
1
+ /**
2
+ * EdgeOne adapter for React Router v7 (SSR/SPA/Prerendering)
3
+ */
4
+ import type { Plugin } from "vite";
5
+ import { type ReactRouterAdapterOptions } from "@edgeone/vite-core";
6
+ export interface ReactRouterEdgeoneAdapterOptions extends ReactRouterAdapterOptions {
7
+ }
8
+ export declare function edgeoneReactRouterAdapter(options?: ReactRouterEdgeoneAdapterOptions): Plugin;
9
+ export default edgeoneReactRouterAdapter;
10
+ export { edgeoneReactRouterAdapter as edgeoneAdapter };
11
+ export type { ReactRouterAdapterOptions, RouteInfo, OutputConfig, BuildContext, BuildArtifacts, } from "@edgeone/vite-core";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,EAkBL,KAAK,yBAAyB,EAI/B,MAAM,oBAAoB,CAAC;AAyD5B,MAAM,WAAW,gCACf,SAAQ,yBAAyB;CAAG;AAqKtC,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,gCAAqC,GAC7C,MAAM,CAKR;AAED,eAAe,yBAAyB,CAAC;AACzC,OAAO,EAAE,yBAAyB,IAAI,cAAc,EAAE,CAAC;AAEvD,YAAY,EACV,yBAAyB,EACzB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,GACf,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * EdgeOne adapter for React Router v7 (SSR/SPA/Prerendering)
3
+ */
4
+ import path from "path";
5
+ import { createCoreAdapter, createStatefulAdapter, resolvePreset, pathExists, detectConfigFile, loadConfigFile, loadServerBuildRoutes, flattenRouteTree, generateServerWrapperCode, createDefaultOutputConfig, convertRoutesToOutputRoutes, logBuildArtifacts, } from "@edgeone/vite-core";
6
+ const REACT_ROUTER_SERVER_PRESET = {
7
+ imports: `import { createRequestHandler } from "react-router";`,
8
+ setup: `
9
+ const {
10
+ routes, assets, assetsBuildDirectory, basename,
11
+ entry, future, isSpaMode, publicPath, routeDiscovery, ssr
12
+ } = serverExports;
13
+
14
+ const buildConfig = {
15
+ assets, assetsBuildDirectory, basename, entry, future,
16
+ isSpaMode, publicPath, routes, routeDiscovery, ssr
17
+ };
18
+
19
+ const requestHandler = createRequestHandler(buildConfig);`,
20
+ invoke: "requestHandler(webRequest, ...args)",
21
+ };
22
+ /** Generate .data routes for React Router's Single Fetch */
23
+ function generateDataRoute(route, routePath, isStatic) {
24
+ if (isStatic || (!route.hasLoader && !route.hasAction))
25
+ return [];
26
+ if (routePath === "/")
27
+ return [{ path: "/_root.data", isStatic: false }];
28
+ if (routePath)
29
+ return [{ path: `${routePath}.data`, isStatic: false }];
30
+ return [];
31
+ }
32
+ function createReactRouterAdapter(_options) {
33
+ return createStatefulAdapter({ isSSR: true, isSpaMode: false, serverBuild: null, config: null }, (state) => ({
34
+ name: "react-router",
35
+ async detect(context) {
36
+ const { projectRoot, logger } = context;
37
+ const configPath = await detectConfigFile(projectRoot, [
38
+ "react-router.config.ts",
39
+ "react-router.config.js",
40
+ ]);
41
+ if (configPath) {
42
+ logger.verbose("Found React Router config:", configPath);
43
+ state.config = await loadConfigFile(configPath);
44
+ if (state.config?.ssr === false) {
45
+ state.isSSR = false;
46
+ state.isSpaMode = true;
47
+ }
48
+ else if (state.config?.ssr === true) {
49
+ state.isSSR = true;
50
+ state.isSpaMode = false;
51
+ }
52
+ return true;
53
+ }
54
+ const buildDir = state.config?.buildDirectory || "build";
55
+ const buildPath = path.join(projectRoot, buildDir, "client");
56
+ return pathExists(buildPath);
57
+ },
58
+ async getBuildArtifacts(context) {
59
+ const { projectRoot, logger } = context;
60
+ const buildDir = state.config?.buildDirectory || "build";
61
+ const serverBuildFile = state.config?.serverBuildFile || "index.js";
62
+ const clientDir = path.join(projectRoot, buildDir, "client");
63
+ const serverDir = path.join(projectRoot, buildDir, "server");
64
+ const serverEntry = path.join(serverDir, serverBuildFile);
65
+ const hasClient = await pathExists(clientDir);
66
+ const hasServer = await pathExists(serverEntry);
67
+ if (!hasServer) {
68
+ state.isSSR = false;
69
+ state.isSpaMode = true;
70
+ }
71
+ else {
72
+ const serverBuild = await loadServerBuildRoutes(serverEntry, logger);
73
+ if (serverBuild) {
74
+ state.serverBuild = serverBuild;
75
+ if (state.config?.ssr === undefined) {
76
+ state.isSSR = serverBuild.ssr !== false;
77
+ state.isSpaMode = serverBuild.isSpaMode === true;
78
+ }
79
+ }
80
+ }
81
+ const needsServer = state.isSSR && !state.isSpaMode;
82
+ logBuildArtifacts(logger, "React Router", {
83
+ clientDir: hasClient ? clientDir : null,
84
+ serverDir: needsServer && hasServer ? serverDir : null,
85
+ serverEntry: needsServer && hasServer ? serverEntry : null,
86
+ });
87
+ return {
88
+ clientDir: hasClient ? clientDir : null,
89
+ serverDir: needsServer && hasServer ? serverDir : null,
90
+ serverEntry: needsServer && hasServer ? serverEntry : null,
91
+ assetsDir: hasClient ? clientDir : null,
92
+ };
93
+ },
94
+ hooks: {
95
+ async generateRoutes(context) {
96
+ const { projectRoot, logger } = context;
97
+ if (!state.serverBuild) {
98
+ const buildDir = state.config?.buildDirectory || "build";
99
+ const serverBuildFile = state.config?.serverBuildFile || "index.js";
100
+ const serverEntry = path.join(projectRoot, buildDir, "server", serverBuildFile);
101
+ if (await pathExists(serverEntry)) {
102
+ state.serverBuild =
103
+ await loadServerBuildRoutes(serverEntry, logger);
104
+ }
105
+ }
106
+ if (state.serverBuild?.routes) {
107
+ const routes = flattenRouteTree(state.serverBuild.routes, {
108
+ isSSR: state.isSSR,
109
+ isSpaMode: state.isSpaMode,
110
+ onRouteProcessed: generateDataRoute,
111
+ });
112
+ if (state.isSSR && !state.isSpaMode) {
113
+ routes.push({ path: "/__manifest", isStatic: false });
114
+ }
115
+ logger.verbose(`Generated ${routes.length} routes from server build`);
116
+ return routes;
117
+ }
118
+ logger.warn("Cannot get routes from server build, using default");
119
+ return [
120
+ {
121
+ path: "/",
122
+ isStatic: state.isSpaMode || !state.isSSR,
123
+ srcRoute: "/",
124
+ },
125
+ ];
126
+ },
127
+ async generateConfig(_context, routes) {
128
+ const outputRoutes = convertRoutesToOutputRoutes(routes);
129
+ return createDefaultOutputConfig(outputRoutes, { isSSR: state.isSSR });
130
+ },
131
+ generateServerWrapper(_context, config) {
132
+ const resolved = resolvePreset(REACT_ROUTER_SERVER_PRESET);
133
+ return generateServerWrapperCode({
134
+ serverEntryPath: config.serverEntryPath,
135
+ imports: resolved.imports,
136
+ handlerSetup: resolved.setup,
137
+ handlerCall: resolved.invoke,
138
+ });
139
+ },
140
+ },
141
+ }));
142
+ }
143
+ export function edgeoneReactRouterAdapter(options = {}) {
144
+ return createCoreAdapter({
145
+ ...options,
146
+ adapter: createReactRouterAdapter(options),
147
+ });
148
+ }
149
+ export default edgeoneReactRouterAdapter;
150
+ export { edgeoneReactRouterAdapter as edgeoneAdapter };
151
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OA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1",
4
+ "description": "EdgeOne adapter for React Router v7 framework",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "prepublishOnly": "npm run build",
20
+ "release": "npm run build && npm version patch && npm publish",
21
+ "release:minor": "npm run build && npm version minor && npm publish",
22
+ "release:major": "npm run build && npm version major && npm publish"
23
+ },
24
+ "keywords": [
25
+ "vite",
26
+ "vite-plugin",
27
+ "react-router",
28
+ "edgeone",
29
+ "adapter",
30
+ "ssr"
31
+ ],
32
+ "author": "EdgeOne Team",
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "@edgeone/vite-core": "0.0.1-beta.1"
36
+ },
37
+ "peerDependencies": {
38
+ "@react-router/dev": "^7.0.0",
39
+ "react-router": "^7.0.0",
40
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.0.0",
44
+ "typescript": "^5.9.0",
45
+ "vite": "^7.1.0"
46
+ },
47
+ "engines": {
48
+ "node": ">=18.0.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }