vite-plugin-react-server 0.3.11 → 0.3.12
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/package.json +15 -11
- package/dist/plugin/checkFilesExist.d.ts +2 -2
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +39 -57
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
- package/dist/plugin/collect-css-manifest.js +5 -0
- package/dist/plugin/collect-css-manifest.js.map +1 -1
- package/dist/plugin/components.js +10 -15
- package/dist/plugin/config/createModuleIdGenerator.js +1 -1
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +5 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +12 -12
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.js +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +73 -52
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +53 -65
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +6 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +48 -19
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts +1 -2
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +52 -46
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +29 -26
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.d.ts +16 -0
- package/dist/plugin/loader/css-loader.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.js +70 -0
- package/dist/plugin/loader/css-loader.js.map +1 -0
- package/dist/plugin/loader/react-loader.d.ts +17 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.js +647 -0
- package/dist/plugin/loader/react-loader.js.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.js +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
- package/dist/plugin/react-client/index.js +2 -2
- package/dist/plugin/react-client/index.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +202 -25
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +10 -4
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts +15 -3
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +52 -49
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +24 -20
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +65 -52
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/types.d.ts +5 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/logger.d.ts +9 -0
- package/dist/plugin/utils/logger.d.ts.map +1 -0
- package/dist/plugin/utils/logger.js +68 -0
- package/dist/plugin/utils/logger.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +1 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +23 -36
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +5 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +10 -19
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/renderPages.d.ts +2 -2
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +130 -131
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/rsc/index.d.ts +1 -3
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/index.js +1 -9
- package/dist/plugin/worker/rsc/index.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.js +107 -0
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/plugin.js +74 -80
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
- package/dist/plugin/worker/rsc/state.d.ts +11 -0
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/state.js +12 -0
- package/dist/plugin/worker/rsc/state.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +60 -46
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -11
- package/plugin/checkFilesExist.ts +42 -62
- package/plugin/collect-css-manifest.ts +5 -1
- package/plugin/config/createModuleIdGenerator.ts +1 -1
- package/plugin/config/defaults.ts +13 -15
- package/plugin/config/resolveOptions.ts +134 -76
- package/plugin/config/resolveUserConfig.ts +75 -76
- package/plugin/helpers/getBundleManifest.ts +69 -31
- package/plugin/helpers/inputNormalizer.ts +82 -70
- package/plugin/helpers/tryManifest.ts +1 -1
- package/plugin/loader/createBuildLoader.ts +38 -41
- package/plugin/loader/css-loader.ts +96 -0
- package/plugin/loader/react-loader.ts +945 -0
- package/plugin/loader/rsc/messageHandler.tsx +1 -0
- package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
- package/plugin/react-client/index.ts +1 -1
- package/plugin/react-client/plugin.ts +266 -41
- package/plugin/react-server/createHandler.ts +9 -5
- package/plugin/react-server/createRscStream.ts +75 -54
- package/plugin/react-server/plugin.ts +26 -21
- package/plugin/transformer/plugin.ts +67 -76
- package/plugin/types/global.d.ts +8 -0
- package/plugin/types.ts +2 -0
- package/plugin/utils/logger.ts +52 -0
- package/plugin/worker/createWorker.ts +43 -44
- package/plugin/worker/html/html-worker.production.tsx +7 -2
- package/plugin/worker/html/messageHandler.ts +13 -21
- package/plugin/worker/html/renderPages.ts +146 -179
- package/plugin/worker/rsc/index.ts +4 -13
- package/plugin/worker/rsc/messageHandler.tsx +143 -0
- package/plugin/worker/rsc/plugin.ts +38 -37
- package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
- package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
- package/plugin/worker/rsc/rsc-worker.tsx +5 -128
- package/plugin/worker/rsc/state.ts +37 -0
- package/plugin/worker/types.ts +79 -55
- package/scripts/check-react-version.mjs +17 -7
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts +0 -8
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
- package/dist/plugin/helpers/getModuleManifest.d.ts +0 -17
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js +0 -23
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -12
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +0 -33
- package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
- package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveFilePath.js +0 -74
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
- package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
- package/dist/plugin/helpers/validateModuleBase.js +0 -16
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
- package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
- package/dist/plugin/transformer/transformer-client-components.d.ts +0 -30
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-client-components.js +0 -122
- package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.js +0 -90
- package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/createRscStream.js +0 -39
- package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
- package/dist/plugin/worker/rsc/development.d.ts +0 -5
- package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/development.js +0 -13
- package/dist/plugin/worker/rsc/development.js.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js.map +0 -1
- package/dist/plugin/worker/rsc/production.d.ts +0 -5
- package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/production.js +0 -13
- package/dist/plugin/worker/rsc/production.js.map +0 -1
- package/plugin/helpers/createClientInputNormalizer.ts +0 -48
- package/plugin/helpers/createServerInputNormalizer.ts +0 -52
- package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
- package/plugin/helpers/getModuleManifest.ts +0 -36
- package/plugin/helpers/inputNormalizerWorker.ts +0 -52
- package/plugin/helpers/normalizedRelativePath.ts +0 -59
- package/plugin/helpers/resolveFilePath.ts +0 -108
- package/plugin/helpers/resolveWorkerModule.ts +0 -41
- package/plugin/helpers/validateModuleBase.ts +0 -30
- package/plugin/helpers/validateResolvedConfig.ts +0 -21
- package/plugin/transformer/transformer-client-components.ts +0 -168
- package/plugin/transformer/transformer-server-actions.ts +0 -125
- package/plugin/worker/rsc/createRscStream.ts +0 -42
- package/plugin/worker/rsc/development.ts +0 -6
- package/plugin/worker/rsc/production.ts +0 -6
- package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
|
@@ -2,8 +2,8 @@ import type { PreRenderedAsset } from "rollup";
|
|
|
2
2
|
import type { PreRenderedChunk } from "rollup";
|
|
3
3
|
import type { StreamPluginOptions, ResolvedUserOptions } from "../types.js";
|
|
4
4
|
import { DEFAULT_CONFIG } from "./defaults.js";
|
|
5
|
-
import { join } from "path";
|
|
6
5
|
import { createModuleIdGenerator } from "./createModuleIdGenerator.js";
|
|
6
|
+
import { normalizePath } from "vite";
|
|
7
7
|
|
|
8
8
|
const resolveAutoDiscoverMatcher = (
|
|
9
9
|
options: undefined | string | RegExp | ((path: string) => boolean),
|
|
@@ -26,6 +26,32 @@ const resolveAutoDiscoverMatcher = (
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
const addJS = (path: string) => {
|
|
30
|
+
if (path.endsWith(".js")) return path;
|
|
31
|
+
if (path.endsWith("/.")) return path.slice(0, -2) + ".js";
|
|
32
|
+
if (path.endsWith(".")) return path + "js";
|
|
33
|
+
return path + ".js";
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const handleSearchQuery = (path: string) => {
|
|
37
|
+
// make the query part of the name of the file so it's not ending up like index1, index2, etc.
|
|
38
|
+
const searchQuery = path.split("?")[1];
|
|
39
|
+
if (!searchQuery) return path;
|
|
40
|
+
// add the folder before the filename
|
|
41
|
+
const folder = path.split("/").slice(0, -1).join("/");
|
|
42
|
+
const filename = path.split("/").pop();
|
|
43
|
+
return `${folder}/${filename}?${searchQuery}`;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const applyPattern = (
|
|
47
|
+
path: string,
|
|
48
|
+
pattern?: string | RegExp | ((path: string) => boolean) | undefined,
|
|
49
|
+
fallback?: string | undefined
|
|
50
|
+
) => {
|
|
51
|
+
// TODO: What to actually do here? I guess we could replace the extension, but it's not needed since we map them from the manifest anyway.
|
|
52
|
+
return path;
|
|
53
|
+
};
|
|
54
|
+
|
|
29
55
|
export const resolveOptions = (
|
|
30
56
|
options: StreamPluginOptions,
|
|
31
57
|
isClient: boolean = false
|
|
@@ -33,7 +59,10 @@ export const resolveOptions = (
|
|
|
33
59
|
| { type: "success"; userOptions: ResolvedUserOptions }
|
|
34
60
|
| { type: "error"; error: Error } => {
|
|
35
61
|
const projectRoot = options.projectRoot ?? process.cwd();
|
|
36
|
-
const {
|
|
62
|
+
const {
|
|
63
|
+
pageExportName = DEFAULT_CONFIG.PAGE_EXPORT_NAME,
|
|
64
|
+
propsExportName = DEFAULT_CONFIG.PROPS_EXPORT_NAME,
|
|
65
|
+
} = options;
|
|
37
66
|
const pages =
|
|
38
67
|
typeof options.build?.pages === "function"
|
|
39
68
|
? options.build.pages
|
|
@@ -47,13 +76,26 @@ export const resolveOptions = (
|
|
|
47
76
|
const staticBuild = options.build?.static ?? DEFAULT_CONFIG.BUILD.static;
|
|
48
77
|
const outDir = options.build?.outDir ?? DEFAULT_CONFIG.BUILD.outDir;
|
|
49
78
|
const assetsDir =
|
|
50
|
-
options.build?.assetsDir ??
|
|
51
|
-
`${DEFAULT_CONFIG.CLIENT_ASSETS_DIR}`;
|
|
79
|
+
options.build?.assetsDir ?? `${DEFAULT_CONFIG.CLIENT_ASSETS_DIR}`;
|
|
52
80
|
|
|
53
81
|
const ensureModuleBase = (n: string | null) => {
|
|
54
|
-
if(!n) return
|
|
82
|
+
if (!n) return "";
|
|
55
83
|
return n.startsWith(moduleBase + "/") ? n.slice(moduleBase.length + 1) : n;
|
|
84
|
+
};
|
|
85
|
+
const hasWrongRoot = !projectRoot.startsWith("/");
|
|
86
|
+
if (hasWrongRoot) {
|
|
87
|
+
console.warn("projectRoot is not a full path", projectRoot);
|
|
56
88
|
}
|
|
89
|
+
const wrongRoot = !hasWrongRoot ? projectRoot.slice(1) : projectRoot;
|
|
90
|
+
const ensureNoRoot = (n: string | null) => {
|
|
91
|
+
if (!n) return "";
|
|
92
|
+
if (n.startsWith(wrongRoot)) {
|
|
93
|
+
return n.slice(wrongRoot.length + 1);
|
|
94
|
+
}
|
|
95
|
+
return n.startsWith(projectRoot + "/")
|
|
96
|
+
? n.slice(projectRoot.length + 1)
|
|
97
|
+
: n;
|
|
98
|
+
};
|
|
57
99
|
|
|
58
100
|
const testModulePattern = resolveAutoDiscoverMatcher(
|
|
59
101
|
options.autoDiscover?.modulePattern,
|
|
@@ -97,94 +139,105 @@ export const resolveOptions = (
|
|
|
97
139
|
options.autoDiscover?.vendorPattern,
|
|
98
140
|
DEFAULT_CONFIG.AUTO_DISCOVER.vendorPattern
|
|
99
141
|
);
|
|
100
|
-
const preserveModulesRoot =
|
|
101
|
-
|
|
102
|
-
|
|
142
|
+
const preserveModulesRoot =
|
|
143
|
+
options.build?.preserveModulesRoot ??
|
|
144
|
+
DEFAULT_CONFIG.BUILD.preserveModulesRoot;
|
|
145
|
+
const hashOption =
|
|
146
|
+
typeof options.build?.hash === "string"
|
|
147
|
+
? options.build.hash
|
|
148
|
+
: DEFAULT_CONFIG.BUILD.hash;
|
|
149
|
+
const hashString = hashOption === "" ? "" : `-[${hashOption}]`;
|
|
103
150
|
const hash = (n: string | null) => {
|
|
104
|
-
if(!n) return
|
|
105
|
-
if(hashString ===
|
|
106
|
-
const extensionIndex = n.lastIndexOf(
|
|
107
|
-
if(extensionIndex !== -1
|
|
151
|
+
if (!n) return "";
|
|
152
|
+
if (hashString === "") return n;
|
|
153
|
+
const extensionIndex = n.lastIndexOf(".");
|
|
154
|
+
if (extensionIndex !== -1) {
|
|
108
155
|
// put hash between extension and filename
|
|
109
|
-
const extension = n.slice(extensionIndex)
|
|
110
|
-
const filename = n.slice(0, extensionIndex)
|
|
156
|
+
const extension = n.slice(extensionIndex);
|
|
157
|
+
const filename = n.slice(0, extensionIndex);
|
|
111
158
|
return filename + hashString + extension;
|
|
112
159
|
} else {
|
|
113
160
|
return n + hashString;
|
|
114
161
|
}
|
|
115
|
-
}
|
|
162
|
+
};
|
|
116
163
|
|
|
117
164
|
const getOutputPath = (n: string | null) => {
|
|
118
|
-
if(!n) return
|
|
165
|
+
if (!n) return "";
|
|
166
|
+
let path = handleSearchQuery(n);
|
|
119
167
|
// Remove src/ prefix if present
|
|
120
|
-
|
|
121
|
-
?
|
|
122
|
-
:
|
|
168
|
+
path = path.startsWith(moduleBase + "/")
|
|
169
|
+
? path.slice(moduleBase.length + 1)
|
|
170
|
+
: path;
|
|
123
171
|
|
|
124
|
-
if (
|
|
125
|
-
return
|
|
172
|
+
if (testVendor(path)) {
|
|
173
|
+
return path;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (testCssModule(path)) {
|
|
177
|
+
// For CSS modules, keep the .css.js extension
|
|
178
|
+
return applyPattern(path, options.autoDiscover?.cssModulePattern, ".css.js");
|
|
126
179
|
}
|
|
180
|
+
|
|
127
181
|
if (testCss(path)) {
|
|
128
|
-
|
|
182
|
+
// For regular CSS files, keep the .css extension
|
|
183
|
+
return applyPattern(path, options.autoDiscover?.cssPattern, ".css");
|
|
129
184
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return `${path.replace(options.autoDiscover.htmlPattern, '.js')}`;
|
|
134
|
-
} else {
|
|
135
|
-
return `${path.replace('.html', '')}`;
|
|
136
|
-
}
|
|
185
|
+
|
|
186
|
+
if (testClientComponents(path)) {
|
|
187
|
+
return applyPattern(path, options.autoDiscover?.clientComponents, "client");
|
|
137
188
|
}
|
|
138
|
-
if(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return `${path}`;
|
|
144
|
-
}
|
|
189
|
+
if (testHtml(path)) {
|
|
190
|
+
return applyPattern(path, options.autoDiscover?.htmlPattern, ".html");
|
|
191
|
+
}
|
|
192
|
+
if (testJson(path)) {
|
|
193
|
+
return applyPattern(path, options.autoDiscover?.jsonPattern, ".json");
|
|
145
194
|
}
|
|
146
195
|
if (testPropsPattern(path)) {
|
|
147
|
-
return
|
|
196
|
+
return applyPattern(
|
|
197
|
+
path,
|
|
198
|
+
options.autoDiscover?.propsPattern,
|
|
199
|
+
options.propsExportName?.toLowerCase() ??
|
|
200
|
+
DEFAULT_CONFIG.PROPS_EXPORT_NAME.toLowerCase()
|
|
201
|
+
);
|
|
148
202
|
}
|
|
149
203
|
if (testPagePattern(path)) {
|
|
150
|
-
return
|
|
204
|
+
return applyPattern(
|
|
205
|
+
path,
|
|
206
|
+
options.autoDiscover?.pagePattern,
|
|
207
|
+
options.pageExportName?.toLowerCase() ??
|
|
208
|
+
DEFAULT_CONFIG.PAGE_EXPORT_NAME.toLowerCase()
|
|
209
|
+
);
|
|
151
210
|
}
|
|
152
211
|
if (testServerFunctions(path)) {
|
|
153
|
-
return
|
|
212
|
+
return applyPattern(path, options.autoDiscover?.serverFunctions, "server");
|
|
154
213
|
}
|
|
155
|
-
if(
|
|
156
|
-
|
|
157
|
-
// if it's not a function, use it as an option for replace
|
|
158
|
-
return `${path.replace(options.autoDiscover.cssModulePattern, '.js')}`;
|
|
159
|
-
} else {
|
|
160
|
-
return `${path.replace('.css.js', '.js')}`;
|
|
161
|
-
}
|
|
214
|
+
if (testModulePattern(path)) {
|
|
215
|
+
return path;
|
|
162
216
|
}
|
|
163
|
-
|
|
164
|
-
return `vendor`;
|
|
165
|
-
}
|
|
166
|
-
return `${path}`;
|
|
217
|
+
return path;
|
|
167
218
|
};
|
|
168
219
|
|
|
169
220
|
const entryFile = (n: PreRenderedChunk) => {
|
|
170
|
-
if(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
221
|
+
if (testVendor(n.name)) {
|
|
222
|
+
const search = n.facadeModuleId?.split("?")[1];
|
|
223
|
+
if(search) {
|
|
224
|
+
return `${n.name}.${search}.js`;
|
|
225
|
+
} else {
|
|
226
|
+
return n.name + ".js";
|
|
227
|
+
}
|
|
174
228
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
229
|
+
return addJS(getOutputPath(ensureModuleBase(ensureNoRoot(n.name))));
|
|
230
|
+
};
|
|
178
231
|
|
|
179
232
|
const chunkFile = (n: PreRenderedChunk) => {
|
|
180
|
-
|
|
181
|
-
return
|
|
182
|
-
}
|
|
233
|
+
// For chunks, we always want .js
|
|
234
|
+
return addJS(getOutputPath(ensureModuleBase(ensureNoRoot('_'+n.name))));
|
|
235
|
+
};
|
|
183
236
|
|
|
184
237
|
const assetFile = (n: PreRenderedAsset) => {
|
|
185
|
-
|
|
186
|
-
return
|
|
187
|
-
}
|
|
238
|
+
// For assets, keep the original extension
|
|
239
|
+
return getOutputPath(ensureModuleBase(ensureNoRoot(n.names[0])));
|
|
240
|
+
};
|
|
188
241
|
|
|
189
242
|
const build =
|
|
190
243
|
typeof options.build === "object" && options.build !== null
|
|
@@ -240,7 +293,7 @@ export const resolveOptions = (
|
|
|
240
293
|
typeof options.moduleBaseURL === "string"
|
|
241
294
|
? options.moduleBaseURL
|
|
242
295
|
: moduleBasePath ?? DEFAULT_CONFIG.MODULE_BASE_URL;
|
|
243
|
-
|
|
296
|
+
|
|
244
297
|
const autoDiscover = {
|
|
245
298
|
modulePattern: testModulePattern,
|
|
246
299
|
cssPattern: testCss,
|
|
@@ -253,23 +306,26 @@ export const resolveOptions = (
|
|
|
253
306
|
vendorPattern: testVendor,
|
|
254
307
|
};
|
|
255
308
|
|
|
256
|
-
const moduleId =
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
309
|
+
const moduleId =
|
|
310
|
+
typeof options.moduleId === "function"
|
|
311
|
+
? options.moduleId
|
|
312
|
+
: createModuleIdGenerator({
|
|
313
|
+
isProduction: process.env["NODE_ENV"] === "production",
|
|
314
|
+
inputRoot: projectRoot,
|
|
315
|
+
client: client,
|
|
316
|
+
server: server,
|
|
317
|
+
moduleBase: moduleBase,
|
|
318
|
+
preserveModulesRoot: preserveModulesRoot,
|
|
319
|
+
removeExtension: DEFAULT_CONFIG.FILE_REGEX,
|
|
320
|
+
imports: {},
|
|
321
|
+
});
|
|
266
322
|
|
|
267
323
|
try {
|
|
268
324
|
return {
|
|
269
325
|
type: "success",
|
|
270
326
|
userOptions: {
|
|
271
327
|
projectRoot,
|
|
272
|
-
moduleId,
|
|
328
|
+
moduleId: moduleId,
|
|
273
329
|
moduleBase,
|
|
274
330
|
moduleBasePath,
|
|
275
331
|
moduleBaseURL,
|
|
@@ -290,7 +346,9 @@ export const resolveOptions = (
|
|
|
290
346
|
moduleBaseExceptions: options.moduleBaseExceptions ?? [],
|
|
291
347
|
autoDiscover: autoDiscover,
|
|
292
348
|
pipableStreamOptions: options.pipableStreamOptions ?? {
|
|
293
|
-
bootstrapModules: [
|
|
349
|
+
bootstrapModules: [
|
|
350
|
+
options.clientEntry ?? DEFAULT_CONFIG.CLIENT_ENTRY,
|
|
351
|
+
],
|
|
294
352
|
},
|
|
295
353
|
},
|
|
296
354
|
};
|
|
@@ -34,7 +34,10 @@ export function resolveUserConfig({
|
|
|
34
34
|
|
|
35
35
|
const normalizer = createInputNormalizer({
|
|
36
36
|
root,
|
|
37
|
-
preserveModulesRoot:
|
|
37
|
+
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
38
|
+
? userOptions.moduleBase
|
|
39
|
+
: undefined,
|
|
40
|
+
removeExtension: true,
|
|
38
41
|
});
|
|
39
42
|
|
|
40
43
|
const serverEntry = userOptions.serverEntry
|
|
@@ -55,16 +58,13 @@ export function resolveUserConfig({
|
|
|
55
58
|
const allFiles = globSync(`**/*.client.*`, {
|
|
56
59
|
cwd: join(root, userOptions.moduleBase),
|
|
57
60
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
const [key, value] = normalizer(join(userOptions.moduleBase, path));
|
|
63
|
-
return [key, value];
|
|
64
|
-
})) {
|
|
65
|
-
// check if not already in the inputs
|
|
61
|
+
|
|
62
|
+
for (const file of allFiles) {
|
|
63
|
+
const [key, value] = normalizer(join(userOptions.moduleBase, file));
|
|
66
64
|
if (!inputs[key]) {
|
|
67
65
|
inputs[key] = value;
|
|
66
|
+
} else {
|
|
67
|
+
console.warn(`[RSC] Client file already exists: ${key}`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return inputs;
|
|
@@ -73,25 +73,33 @@ export function resolveUserConfig({
|
|
|
73
73
|
const allFiles = globSync(`${userOptions.moduleBase}/**/*.server.*`, {
|
|
74
74
|
cwd: join(root, userOptions.moduleBase),
|
|
75
75
|
});
|
|
76
|
-
for (const
|
|
76
|
+
for (const file of allFiles) {
|
|
77
|
+
const [key, value] = normalizer(join(userOptions.moduleBase, file));
|
|
77
78
|
if (!inputs[key]) {
|
|
78
79
|
inputs[key] = value;
|
|
80
|
+
} else {
|
|
81
|
+
console.warn(`[RSC] Server file already exists: ${key}`);
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
return inputs;
|
|
82
85
|
};
|
|
83
86
|
const autoDiscoveredFiles = (inputs: Record<string, string>) => {
|
|
84
|
-
if(!files)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
for (const [key, value] of
|
|
87
|
+
if (!files) return inputs;
|
|
88
|
+
|
|
89
|
+
// Add page files without extra prefix
|
|
90
|
+
for (const [key, value] of files.pageMap) {
|
|
88
91
|
if (!inputs[key]) {
|
|
89
92
|
inputs[key] = value;
|
|
93
|
+
} else {
|
|
94
|
+
console.warn(`[RSC] Page file already exists: ${key}`);
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
|
-
|
|
97
|
+
// Add props files without extra prefix
|
|
98
|
+
for (const [key, value] of files.propsMap) {
|
|
93
99
|
if (!inputs[key]) {
|
|
94
100
|
inputs[key] = value;
|
|
101
|
+
} else {
|
|
102
|
+
console.warn(`[RSC] Props file already exists: ${key}`);
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
105
|
return inputs;
|
|
@@ -102,21 +110,37 @@ export function resolveUserConfig({
|
|
|
102
110
|
? autoDiscoveredClientFiles(clientEntry)
|
|
103
111
|
: autoDiscoveredServerFiles(autoDiscoveredFiles(serverEntry ?? {}));
|
|
104
112
|
|
|
105
|
-
if (userOptions.build.preserveModulesRoot) {
|
|
106
|
-
inputs = Object.fromEntries(
|
|
107
|
-
Object.entries(inputs).map(([key, value]) => {
|
|
108
|
-
if (key.startsWith(userOptions.moduleBase + "/")) {
|
|
109
|
-
return [key.slice(userOptions.moduleBase.length + 1), value];
|
|
110
|
-
}
|
|
111
|
-
return [key, value];
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
113
|
const envDir = isClient
|
|
117
114
|
? userOptions.build.client
|
|
118
115
|
: userOptions.build.server;
|
|
116
|
+
|
|
117
|
+
const pluginOutput = {
|
|
118
|
+
preserveModules: !isClient,
|
|
119
|
+
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
120
|
+
? userOptions.moduleBase
|
|
121
|
+
: undefined,
|
|
122
|
+
entryFileNames: userOptions.build.entryFile,
|
|
123
|
+
assetFileNames: userOptions.build.assetFile,
|
|
124
|
+
chunkFileNames: userOptions.build.chunkFile,
|
|
125
|
+
format: "esm",
|
|
126
|
+
exports: "named",
|
|
127
|
+
hoistTransitiveImports: false,
|
|
128
|
+
generatedCode: {
|
|
129
|
+
constBindings: true,
|
|
130
|
+
objectShorthand: true,
|
|
131
|
+
},
|
|
132
|
+
interop: "auto",
|
|
133
|
+
} satisfies OutputOptions;
|
|
134
|
+
|
|
135
|
+
const newOutput = Array.isArray(config.build?.rollupOptions?.output)
|
|
136
|
+
? [...config.build?.rollupOptions?.output, pluginOutput]
|
|
137
|
+
: typeof config.build?.rollupOptions?.output === "object" &&
|
|
138
|
+
config.build?.rollupOptions?.output !== null
|
|
139
|
+
? [config.build?.rollupOptions?.output, pluginOutput]
|
|
140
|
+
: pluginOutput;
|
|
141
|
+
|
|
119
142
|
if (isClient) {
|
|
143
|
+
// client build options
|
|
120
144
|
return {
|
|
121
145
|
type: "success",
|
|
122
146
|
userConfig: {
|
|
@@ -125,69 +149,46 @@ export function resolveUserConfig({
|
|
|
125
149
|
mode: configEnv.command === "build" ? "production" : "development",
|
|
126
150
|
resolve: {
|
|
127
151
|
external: ["react", "react-dom"],
|
|
128
|
-
alias: {
|
|
129
|
-
[userOptions.moduleBasePath]: join(root, userOptions.moduleBasePath),
|
|
130
|
-
[userOptions.moduleBase]: join(root, userOptions.moduleBase),
|
|
131
|
-
['index.html']: join(root, 'index.html')
|
|
132
|
-
}
|
|
152
|
+
alias: {},
|
|
133
153
|
},
|
|
134
154
|
ssr: {
|
|
135
155
|
target: "node",
|
|
136
|
-
external: [
|
|
156
|
+
external: [
|
|
157
|
+
"react",
|
|
158
|
+
"react-dom",
|
|
159
|
+
"react-server-dom-esm/client.browser",
|
|
160
|
+
],
|
|
137
161
|
resolve: {
|
|
138
|
-
conditions: ["react-server"],
|
|
139
162
|
externalConditions: ["react-server"],
|
|
140
163
|
},
|
|
141
164
|
},
|
|
165
|
+
// client build options
|
|
142
166
|
build: {
|
|
143
167
|
...config.build,
|
|
144
168
|
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
145
169
|
outDir: join(userOptions.build.outDir, envDir),
|
|
146
|
-
assetsDir: userOptions.build.assetsDir,
|
|
170
|
+
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
147
171
|
// modern browsers
|
|
148
172
|
target: ["esnext"],
|
|
149
173
|
minify: true,
|
|
150
|
-
ssr:
|
|
174
|
+
ssr:
|
|
175
|
+
typeof configEnv.isSsrBuild === "boolean"
|
|
176
|
+
? configEnv.isSsrBuild
|
|
177
|
+
: true,
|
|
151
178
|
manifest: config.build?.manifest ?? `.vite/manifest.json`,
|
|
152
179
|
ssrManifest: config.build?.ssrManifest ?? `.vite/ssr-manifest.json`,
|
|
153
|
-
ssrEmitAssets: true,
|
|
180
|
+
ssrEmitAssets: config.build?.ssrEmitAssets ?? true,
|
|
154
181
|
rollupOptions: {
|
|
155
182
|
...config.build?.rollupOptions,
|
|
156
183
|
input: inputs,
|
|
157
|
-
output:
|
|
158
|
-
|
|
159
|
-
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
160
|
-
? userOptions.moduleBase
|
|
161
|
-
: undefined,
|
|
162
|
-
},
|
|
184
|
+
output: newOutput,
|
|
185
|
+
preserveEntrySignatures: "exports-only",
|
|
163
186
|
},
|
|
164
187
|
},
|
|
165
188
|
},
|
|
166
189
|
};
|
|
167
190
|
}
|
|
168
|
-
|
|
169
|
-
const pluginOutput = {
|
|
170
|
-
preserveModules: true,
|
|
171
|
-
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
172
|
-
? userOptions.moduleBase
|
|
173
|
-
: undefined,
|
|
174
|
-
entryFileNames: userOptions.build.entryFile,
|
|
175
|
-
assetFileNames: userOptions.build.assetFile,
|
|
176
|
-
chunkFileNames: userOptions.build.chunkFile,
|
|
177
|
-
format: "esm",
|
|
178
|
-
exports: "named",
|
|
179
|
-
hoistTransitiveImports: false,
|
|
180
|
-
generatedCode: {
|
|
181
|
-
constBindings: true,
|
|
182
|
-
objectShorthand: true,
|
|
183
|
-
},
|
|
184
|
-
interop: "auto",
|
|
185
|
-
} satisfies OutputOptions;
|
|
186
|
-
const newOutput = Array.isArray(config.build?.rollupOptions?.output) ?
|
|
187
|
-
[...config.build?.rollupOptions?.output, pluginOutput]
|
|
188
|
-
: typeof config.build?.rollupOptions?.output === 'object' && config.build?.rollupOptions?.output !== null ?
|
|
189
|
-
[config.build?.rollupOptions?.output, pluginOutput]
|
|
190
|
-
: pluginOutput
|
|
191
|
+
// server build options
|
|
191
192
|
return {
|
|
192
193
|
type: "success",
|
|
193
194
|
userConfig: {
|
|
@@ -195,27 +196,25 @@ export function resolveUserConfig({
|
|
|
195
196
|
root: root,
|
|
196
197
|
mode: configEnv.command === "build" ? "production" : "development",
|
|
197
198
|
resolve: {
|
|
198
|
-
alias: {
|
|
199
|
-
|
|
200
|
-
[userOptions.moduleBase]: join(root, userOptions.moduleBase),
|
|
201
|
-
['index.html']: join(root, 'index.html')
|
|
202
|
-
}
|
|
199
|
+
alias: {},
|
|
200
|
+
externalConditions: ["react-server"],
|
|
203
201
|
},
|
|
202
|
+
// server build options
|
|
204
203
|
build: {
|
|
205
204
|
...config.build,
|
|
206
205
|
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
207
206
|
outDir: join(userOptions.build.outDir, envDir),
|
|
208
|
-
target: "node18",
|
|
209
|
-
minify: true,
|
|
210
|
-
ssr: true,
|
|
207
|
+
target: config.build?.target ?? "node18",
|
|
208
|
+
minify: config.build?.minify ?? true,
|
|
209
|
+
ssr: config.build?.ssr ?? configEnv.isSsrBuild ?? true,
|
|
211
210
|
manifest: config.build?.manifest ?? `.vite/manifest.json`,
|
|
212
211
|
ssrManifest: config.build?.ssrManifest ?? `.vite/ssr-manifest.json`,
|
|
213
|
-
ssrEmitAssets: true,
|
|
212
|
+
ssrEmitAssets: config.build?.ssrEmitAssets ?? true,
|
|
214
213
|
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
215
|
-
rollupOptions:
|
|
214
|
+
rollupOptions: {
|
|
216
215
|
...config.build?.rollupOptions,
|
|
217
216
|
input: inputs,
|
|
218
|
-
preserveEntrySignatures: "strict",
|
|
217
|
+
preserveEntrySignatures: config.build?.rollupOptions?.preserveEntrySignatures ?? "strict",
|
|
219
218
|
output: newOutput,
|
|
220
219
|
},
|
|
221
220
|
},
|