vite-plugin-react-server 0.3.10 → 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/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json +16 -14
- package/dist/plugin/assertServerCondition.d.ts +5 -1
- package/dist/plugin/assertServerCondition.d.ts.map +1 -1
- package/dist/plugin/assertServerCondition.js +1 -3
- package/dist/plugin/checkFilesExist.d.ts +2 -2
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +43 -58
- 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.d.ts +11 -0
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +1 -0
- package/dist/plugin/config/createModuleIdGenerator.js +44 -0
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +27 -24
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +26 -31
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.js +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +223 -16
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +2 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -2
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +149 -50
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +25 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.js +72 -0
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +14 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +128 -16
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +3 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +6 -2
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +37 -9
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createPageLoader.js +0 -7
- 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/plugin.d.ts +0 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +3 -2
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +2 -1
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +19 -1
- package/dist/plugin/react-client/index.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts +2 -2
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +283 -10
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts +2 -2
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +15 -9
- 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 +53 -36
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +2 -2
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.js +5 -12
- package/dist/plugin/react-server/index.js +18 -9
- package/dist/plugin/react-server/index.js.map +1 -0
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +147 -137
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts +2 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +68 -75
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/types.d.ts +4 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +56 -20
- 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 +33 -28
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/html/plugin.js +10 -5
- package/dist/plugin/worker/html/renderPages.d.ts +7 -6
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +147 -93
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/loader.d.ts +1 -11
- package/dist/plugin/worker/loader.d.ts.map +1 -1
- package/dist/plugin/worker/loader.js +2 -2
- package/dist/plugin/worker/loader.js.map +1 -1
- package/dist/plugin/worker/plugin.d.ts +10 -1
- package/dist/plugin/worker/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/plugin.js +10 -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 +62 -35
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -3
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -14
- package/plugin/assertServerCondition.ts +2 -3
- package/plugin/checkFilesExist.ts +46 -66
- package/plugin/collect-css-manifest.ts +5 -1
- package/plugin/config/createModuleIdGenerator.ts +52 -0
- package/plugin/config/defaults.ts +27 -20
- package/plugin/config/resolveOptions.ts +311 -25
- package/plugin/config/resolvePages.ts +1 -1
- package/plugin/config/resolveUserConfig.ts +195 -61
- package/plugin/helpers/getBundleManifest.ts +113 -0
- package/plugin/helpers/inputNormalizer.ts +186 -25
- package/plugin/helpers/tryManifest.ts +3 -1
- package/plugin/loader/createBuildLoader.ts +50 -9
- package/plugin/loader/createPageLoader.ts +1 -7
- 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/plugin.ts +2 -1
- package/plugin/preserver/plugin.ts +2 -1
- package/plugin/react-client/index.ts +12 -1
- package/plugin/react-client/plugin.ts +351 -11
- package/plugin/react-server/createHandler.ts +16 -18
- package/plugin/react-server/createRscStream.ts +75 -42
- package/plugin/react-server/createSsrHandler.ts +7 -26
- package/plugin/react-server/plugin.ts +192 -155
- package/plugin/transformer/plugin.ts +70 -104
- package/plugin/transformer/types.ts +4 -0
- package/plugin/types/global.d.ts +8 -0
- package/plugin/types.ts +120 -64
- 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 +42 -35
- package/plugin/worker/html/plugin.ts +15 -11
- package/plugin/worker/html/renderPages.ts +177 -123
- package/plugin/worker/loader.ts +4 -13
- package/plugin/worker/plugin.ts +10 -1
- 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 +83 -38
- 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/node_modules/magic-string/dist/magic-string.es.js +0 -1283
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.d.ts +0 -3
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.js +0 -14
- package/dist/plugin/build/createServerBuildConfig.d.ts +0 -12
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createServerBuildConfig.js +0 -40
- package/dist/plugin/build/createSharedBuildConfig.d.ts +0 -5
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createSharedBuildConfig.js +0 -28
- package/dist/plugin/build/mergeInputs.d.ts +0 -9
- package/dist/plugin/build/mergeInputs.d.ts.map +0 -1
- package/dist/plugin/build/mergeInputs.js +0 -56
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/config/moduleIdDefault.d.ts +0 -8
- package/dist/plugin/config/moduleIdDefault.d.ts.map +0 -1
- package/dist/plugin/config/moduleIdDefault.js +0 -23
- package/dist/plugin/config/moduleIdDefault.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 -12
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js +0 -24
- package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -11
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +0 -30
- 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/react-server/createDevMiddleware.d.ts +0 -8
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevMiddleware.js +0 -68
- package/dist/plugin/react-server/createDevServer.d.ts +0 -4
- package/dist/plugin/react-server/createDevServer.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevServer.js +0 -4
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts +0 -10
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/plugin/react-server/createReactNodeStreamer.js +0 -7
- package/dist/plugin/transformer/transformer-client-components.d.ts +0 -21
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-client-components.js +0 -61
- 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 -76
- package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
- 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/build/createClientBuildConfig.ts +0 -21
- package/plugin/build/createServerBuildConfig.ts +0 -66
- package/plugin/build/createSharedBuildConfig.ts +0 -35
- package/plugin/build/mergeInputs.ts +0 -58
- package/plugin/config/moduleIdDefault.ts +0 -23
- 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 -31
- package/plugin/helpers/inputNormalizerWorker.ts +0 -47
- 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/react-server/createDevMiddleware.ts +0 -91
- package/plugin/react-server/createDevServer.ts +0 -9
- package/plugin/react-server/createReactNodeStreamer.ts +0 -26
- package/plugin/transformer/transformer-client-components.ts +0 -94
- package/plugin/transformer/transformer-server-actions.ts +0 -110
- 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
|
@@ -1,16 +1,288 @@
|
|
|
1
|
+
import type { PreRenderedAsset } from "rollup";
|
|
2
|
+
import type { PreRenderedChunk } from "rollup";
|
|
1
3
|
import type { StreamPluginOptions, ResolvedUserOptions } from "../types.js";
|
|
2
4
|
import { DEFAULT_CONFIG } from "./defaults.js";
|
|
5
|
+
import { createModuleIdGenerator } from "./createModuleIdGenerator.js";
|
|
6
|
+
import { normalizePath } from "vite";
|
|
7
|
+
|
|
8
|
+
const resolveAutoDiscoverMatcher = (
|
|
9
|
+
options: undefined | string | RegExp | ((path: string) => boolean),
|
|
10
|
+
fallback: RegExp | ((path: string) => boolean)
|
|
11
|
+
) => {
|
|
12
|
+
if (!options) {
|
|
13
|
+
if (typeof fallback === "function") {
|
|
14
|
+
return fallback;
|
|
15
|
+
} else {
|
|
16
|
+
return (path: string) => fallback.test(path);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (typeof options === "string") {
|
|
20
|
+
const matcher = new RegExp(options);
|
|
21
|
+
return (path: string) => matcher.test(path);
|
|
22
|
+
} else if (typeof options === "function") {
|
|
23
|
+
return options;
|
|
24
|
+
} else {
|
|
25
|
+
return (path: string) => options.test(path);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
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
|
+
};
|
|
3
54
|
|
|
4
55
|
export const resolveOptions = (
|
|
5
|
-
options: StreamPluginOptions
|
|
56
|
+
options: StreamPluginOptions,
|
|
57
|
+
isClient: boolean = false
|
|
6
58
|
):
|
|
7
59
|
| { type: "success"; userOptions: ResolvedUserOptions }
|
|
8
60
|
| { type: "error"; error: Error } => {
|
|
9
61
|
const projectRoot = options.projectRoot ?? process.cwd();
|
|
62
|
+
const {
|
|
63
|
+
pageExportName = DEFAULT_CONFIG.PAGE_EXPORT_NAME,
|
|
64
|
+
propsExportName = DEFAULT_CONFIG.PROPS_EXPORT_NAME,
|
|
65
|
+
} = options;
|
|
66
|
+
const pages =
|
|
67
|
+
typeof options.build?.pages === "function"
|
|
68
|
+
? options.build.pages
|
|
69
|
+
: Array.isArray(options.build?.pages)
|
|
70
|
+
? options.build.pages
|
|
71
|
+
: DEFAULT_CONFIG.BUILD.pages;
|
|
72
|
+
let client = options.build?.client ?? DEFAULT_CONFIG.BUILD.client;
|
|
73
|
+
let server = options.build?.server ?? DEFAULT_CONFIG.BUILD.server;
|
|
74
|
+
|
|
75
|
+
const api = options.build?.api ?? DEFAULT_CONFIG.BUILD.api;
|
|
76
|
+
const staticBuild = options.build?.static ?? DEFAULT_CONFIG.BUILD.static;
|
|
77
|
+
const outDir = options.build?.outDir ?? DEFAULT_CONFIG.BUILD.outDir;
|
|
78
|
+
const assetsDir =
|
|
79
|
+
options.build?.assetsDir ?? `${DEFAULT_CONFIG.CLIENT_ASSETS_DIR}`;
|
|
80
|
+
|
|
81
|
+
const ensureModuleBase = (n: string | null) => {
|
|
82
|
+
if (!n) return "";
|
|
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);
|
|
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
|
+
};
|
|
99
|
+
|
|
100
|
+
const testModulePattern = resolveAutoDiscoverMatcher(
|
|
101
|
+
options.autoDiscover?.modulePattern,
|
|
102
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.modulePattern
|
|
103
|
+
);
|
|
10
104
|
|
|
11
|
-
const
|
|
105
|
+
const testJson = resolveAutoDiscoverMatcher(
|
|
106
|
+
options.autoDiscover?.jsonPattern,
|
|
107
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.jsonPattern
|
|
108
|
+
);
|
|
12
109
|
|
|
13
|
-
const
|
|
110
|
+
const testCss = resolveAutoDiscoverMatcher(
|
|
111
|
+
options.autoDiscover?.cssPattern,
|
|
112
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.cssPattern
|
|
113
|
+
);
|
|
114
|
+
const testHtml = resolveAutoDiscoverMatcher(
|
|
115
|
+
options.autoDiscover?.htmlPattern,
|
|
116
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.htmlPattern
|
|
117
|
+
);
|
|
118
|
+
const testClientComponents = resolveAutoDiscoverMatcher(
|
|
119
|
+
options.autoDiscover?.clientComponents,
|
|
120
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents
|
|
121
|
+
);
|
|
122
|
+
const testServerFunctions = resolveAutoDiscoverMatcher(
|
|
123
|
+
options.autoDiscover?.serverFunctions,
|
|
124
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions
|
|
125
|
+
);
|
|
126
|
+
const testPropsPattern = resolveAutoDiscoverMatcher(
|
|
127
|
+
options.autoDiscover?.propsPattern,
|
|
128
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.propsPattern
|
|
129
|
+
);
|
|
130
|
+
const testPagePattern = resolveAutoDiscoverMatcher(
|
|
131
|
+
options.autoDiscover?.pagePattern,
|
|
132
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.pagePattern
|
|
133
|
+
);
|
|
134
|
+
const testCssModule = resolveAutoDiscoverMatcher(
|
|
135
|
+
options.autoDiscover?.cssModulePattern,
|
|
136
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.cssModulePattern
|
|
137
|
+
);
|
|
138
|
+
const testVendor = resolveAutoDiscoverMatcher(
|
|
139
|
+
options.autoDiscover?.vendorPattern,
|
|
140
|
+
DEFAULT_CONFIG.AUTO_DISCOVER.vendorPattern
|
|
141
|
+
);
|
|
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}]`;
|
|
150
|
+
const hash = (n: string | null) => {
|
|
151
|
+
if (!n) return "";
|
|
152
|
+
if (hashString === "") return n;
|
|
153
|
+
const extensionIndex = n.lastIndexOf(".");
|
|
154
|
+
if (extensionIndex !== -1) {
|
|
155
|
+
// put hash between extension and filename
|
|
156
|
+
const extension = n.slice(extensionIndex);
|
|
157
|
+
const filename = n.slice(0, extensionIndex);
|
|
158
|
+
return filename + hashString + extension;
|
|
159
|
+
} else {
|
|
160
|
+
return n + hashString;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const getOutputPath = (n: string | null) => {
|
|
165
|
+
if (!n) return "";
|
|
166
|
+
let path = handleSearchQuery(n);
|
|
167
|
+
// Remove src/ prefix if present
|
|
168
|
+
path = path.startsWith(moduleBase + "/")
|
|
169
|
+
? path.slice(moduleBase.length + 1)
|
|
170
|
+
: path;
|
|
171
|
+
|
|
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");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (testCss(path)) {
|
|
182
|
+
// For regular CSS files, keep the .css extension
|
|
183
|
+
return applyPattern(path, options.autoDiscover?.cssPattern, ".css");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (testClientComponents(path)) {
|
|
187
|
+
return applyPattern(path, options.autoDiscover?.clientComponents, "client");
|
|
188
|
+
}
|
|
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");
|
|
194
|
+
}
|
|
195
|
+
if (testPropsPattern(path)) {
|
|
196
|
+
return applyPattern(
|
|
197
|
+
path,
|
|
198
|
+
options.autoDiscover?.propsPattern,
|
|
199
|
+
options.propsExportName?.toLowerCase() ??
|
|
200
|
+
DEFAULT_CONFIG.PROPS_EXPORT_NAME.toLowerCase()
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
if (testPagePattern(path)) {
|
|
204
|
+
return applyPattern(
|
|
205
|
+
path,
|
|
206
|
+
options.autoDiscover?.pagePattern,
|
|
207
|
+
options.pageExportName?.toLowerCase() ??
|
|
208
|
+
DEFAULT_CONFIG.PAGE_EXPORT_NAME.toLowerCase()
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
if (testServerFunctions(path)) {
|
|
212
|
+
return applyPattern(path, options.autoDiscover?.serverFunctions, "server");
|
|
213
|
+
}
|
|
214
|
+
if (testModulePattern(path)) {
|
|
215
|
+
return path;
|
|
216
|
+
}
|
|
217
|
+
return path;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const entryFile = (n: PreRenderedChunk) => {
|
|
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
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return addJS(getOutputPath(ensureModuleBase(ensureNoRoot(n.name))));
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const chunkFile = (n: PreRenderedChunk) => {
|
|
233
|
+
// For chunks, we always want .js
|
|
234
|
+
return addJS(getOutputPath(ensureModuleBase(ensureNoRoot('_'+n.name))));
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const assetFile = (n: PreRenderedAsset) => {
|
|
238
|
+
// For assets, keep the original extension
|
|
239
|
+
return getOutputPath(ensureModuleBase(ensureNoRoot(n.names[0])));
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const build =
|
|
243
|
+
typeof options.build === "object" && options.build !== null
|
|
244
|
+
? {
|
|
245
|
+
pages,
|
|
246
|
+
client,
|
|
247
|
+
server,
|
|
248
|
+
static: staticBuild,
|
|
249
|
+
outDir,
|
|
250
|
+
assetsDir,
|
|
251
|
+
api,
|
|
252
|
+
hash: hashOption,
|
|
253
|
+
preserveModulesRoot,
|
|
254
|
+
entryFile:
|
|
255
|
+
typeof options.build?.entryFile === "function"
|
|
256
|
+
? options.build.entryFile
|
|
257
|
+
: entryFile,
|
|
258
|
+
chunkFile:
|
|
259
|
+
typeof options.build?.chunkFile === "function"
|
|
260
|
+
? options.build.chunkFile
|
|
261
|
+
: chunkFile,
|
|
262
|
+
assetFile:
|
|
263
|
+
typeof options.build?.assetFile === "function"
|
|
264
|
+
? options.build.assetFile
|
|
265
|
+
: assetFile,
|
|
266
|
+
}
|
|
267
|
+
: {
|
|
268
|
+
pages,
|
|
269
|
+
client,
|
|
270
|
+
server,
|
|
271
|
+
static: staticBuild,
|
|
272
|
+
outDir,
|
|
273
|
+
assetsDir,
|
|
274
|
+
api,
|
|
275
|
+
hash: hashOption,
|
|
276
|
+
preserveModulesRoot,
|
|
277
|
+
entryFile,
|
|
278
|
+
chunkFile,
|
|
279
|
+
assetFile,
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const moduleBase =
|
|
283
|
+
typeof options.moduleBase === "string"
|
|
284
|
+
? options.moduleBase
|
|
285
|
+
: DEFAULT_CONFIG.MODULE_BASE;
|
|
14
286
|
const moduleBasePath =
|
|
15
287
|
typeof options.moduleBasePath === "string"
|
|
16
288
|
? options.moduleBasePath
|
|
@@ -21,28 +293,50 @@ export const resolveOptions = (
|
|
|
21
293
|
typeof options.moduleBaseURL === "string"
|
|
22
294
|
? options.moduleBaseURL
|
|
23
295
|
: moduleBasePath ?? DEFAULT_CONFIG.MODULE_BASE_URL;
|
|
296
|
+
|
|
297
|
+
const autoDiscover = {
|
|
298
|
+
modulePattern: testModulePattern,
|
|
299
|
+
cssPattern: testCss,
|
|
300
|
+
jsonPattern: testJson,
|
|
301
|
+
clientComponents: testClientComponents,
|
|
302
|
+
serverFunctions: testServerFunctions,
|
|
303
|
+
propsPattern: testPropsPattern,
|
|
304
|
+
pagePattern: testPagePattern,
|
|
305
|
+
cssModulePattern: testCssModule,
|
|
306
|
+
vendorPattern: testVendor,
|
|
307
|
+
};
|
|
308
|
+
|
|
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
|
+
});
|
|
322
|
+
|
|
24
323
|
try {
|
|
25
324
|
return {
|
|
26
325
|
type: "success",
|
|
27
326
|
userOptions: {
|
|
28
327
|
projectRoot,
|
|
328
|
+
moduleId: moduleId,
|
|
29
329
|
moduleBase,
|
|
30
330
|
moduleBasePath,
|
|
31
331
|
moduleBaseURL,
|
|
32
|
-
build:
|
|
33
|
-
pages: build.pages ?? DEFAULT_CONFIG.BUILD.pages,
|
|
34
|
-
client: build.client ?? DEFAULT_CONFIG.BUILD.client,
|
|
35
|
-
server: build.server ?? DEFAULT_CONFIG.BUILD.server,
|
|
36
|
-
static: build.static ?? DEFAULT_CONFIG.BUILD.static,
|
|
37
|
-
},
|
|
332
|
+
build: build,
|
|
38
333
|
Page: options.Page ?? DEFAULT_CONFIG.PAGE,
|
|
39
334
|
props: options.props ?? DEFAULT_CONFIG.PROPS,
|
|
40
335
|
Html: options.Html ?? DEFAULT_CONFIG.HTML,
|
|
41
|
-
pageExportName:
|
|
42
|
-
propsExportName:
|
|
336
|
+
pageExportName: pageExportName,
|
|
337
|
+
propsExportName: propsExportName,
|
|
43
338
|
collectCss: options.collectCss ?? DEFAULT_CONFIG.COLLECT_CSS,
|
|
44
339
|
collectAssets: options.collectAssets ?? DEFAULT_CONFIG.COLLECT_ASSETS,
|
|
45
|
-
assetsDir: options.assetsDir ?? DEFAULT_CONFIG.CLIENT_ASSETS_DIR,
|
|
46
340
|
htmlWorkerPath:
|
|
47
341
|
options.htmlWorkerPath ?? DEFAULT_CONFIG.HTML_WORKER_PATH,
|
|
48
342
|
rscWorkerPath: options.rscWorkerPath ?? DEFAULT_CONFIG.RSC_WORKER_PATH,
|
|
@@ -50,19 +344,11 @@ export const resolveOptions = (
|
|
|
50
344
|
clientEntry: options.clientEntry ?? DEFAULT_CONFIG.CLIENT_ENTRY,
|
|
51
345
|
serverEntry: options.serverEntry ?? DEFAULT_CONFIG.SERVER_ENTRY,
|
|
52
346
|
moduleBaseExceptions: options.moduleBaseExceptions ?? [],
|
|
53
|
-
autoDiscover:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
DEFAULT_CONFIG.
|
|
57
|
-
|
|
58
|
-
options.autoDiscover?.propsPattern ??
|
|
59
|
-
DEFAULT_CONFIG.AUTO_DISCOVER.propsPattern,
|
|
60
|
-
clientComponents:
|
|
61
|
-
options.autoDiscover?.clientComponents ??
|
|
62
|
-
DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents,
|
|
63
|
-
serverFunctions:
|
|
64
|
-
options.autoDiscover?.serverFunctions ??
|
|
65
|
-
DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions,
|
|
347
|
+
autoDiscover: autoDiscover,
|
|
348
|
+
pipableStreamOptions: options.pipableStreamOptions ?? {
|
|
349
|
+
bootstrapModules: [
|
|
350
|
+
options.clientEntry ?? DEFAULT_CONFIG.CLIENT_ENTRY,
|
|
351
|
+
],
|
|
66
352
|
},
|
|
67
353
|
},
|
|
68
354
|
};
|
|
@@ -2,7 +2,7 @@ import type { ResolvedUserOptions } from '../types.js';
|
|
|
2
2
|
|
|
3
3
|
export async function resolvePages(
|
|
4
4
|
pages: ResolvedUserOptions["build"]["pages"]
|
|
5
|
-
): Promise<{ type: "success"; pages: string[] } | { type: "error"; error: Error }> {
|
|
5
|
+
): Promise<{ type: "success"; error?:never; pages: string[] } | { type: "error"; error: Error; pages?:never }> {
|
|
6
6
|
if (!pages) {
|
|
7
7
|
return { type: "success", pages: [] };
|
|
8
8
|
}
|
|
@@ -1,96 +1,230 @@
|
|
|
1
1
|
import type { ConfigEnv, UserConfig } from "vite";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
CheckFilesExistReturn,
|
|
4
|
+
ResolvedUserConfig,
|
|
5
|
+
ResolvedUserOptions,
|
|
6
|
+
} from "../types.js";
|
|
4
7
|
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
5
|
-
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import { globSync } from "fs";
|
|
11
|
+
import type { OutputOptions } from "rollup";
|
|
6
12
|
export type ResolveUserConfigProps = {
|
|
7
|
-
|
|
13
|
+
isClient?: boolean;
|
|
8
14
|
config: UserConfig;
|
|
9
15
|
configEnv: ConfigEnv;
|
|
10
16
|
userOptions: ResolvedUserOptions;
|
|
11
17
|
files?: CheckFilesExistReturn;
|
|
12
18
|
};
|
|
13
19
|
|
|
14
|
-
export type ResolveUserConfigReturn =
|
|
20
|
+
export type ResolveUserConfigReturn =
|
|
15
21
|
| { type: "success"; userConfig: ResolvedUserConfig }
|
|
16
22
|
| { type: "error"; error: Error };
|
|
17
23
|
|
|
18
24
|
export function resolveUserConfig({
|
|
19
|
-
|
|
25
|
+
isClient = false,
|
|
20
26
|
config,
|
|
21
27
|
configEnv,
|
|
22
28
|
userOptions,
|
|
23
|
-
files
|
|
29
|
+
files,
|
|
24
30
|
}: ResolveUserConfigProps): ResolveUserConfigReturn {
|
|
25
|
-
|
|
26
|
-
|
|
27
31
|
try {
|
|
28
32
|
// Get existing inputs
|
|
29
33
|
const root = config.root ?? userOptions.projectRoot ?? process.cwd();
|
|
30
|
-
const existingInput = config.build?.rollupOptions?.input || {};
|
|
31
|
-
const currentInputs = typeof existingInput === 'string' ? { default: existingInput } : existingInput;
|
|
32
|
-
const normalizer = createInputNormalizer(root);
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
const normalizer = createInputNormalizer({
|
|
36
|
+
root,
|
|
37
|
+
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
38
|
+
? userOptions.moduleBase
|
|
39
|
+
: undefined,
|
|
40
|
+
removeExtension: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const serverEntry = userOptions.serverEntry
|
|
44
|
+
? Object.fromEntries([
|
|
45
|
+
normalizer([userOptions.serverEntry, userOptions.serverEntry]),
|
|
46
|
+
])
|
|
47
|
+
: null;
|
|
48
|
+
const clientEntry = userOptions.clientEntry
|
|
49
|
+
? Object.fromEntries(
|
|
50
|
+
[
|
|
51
|
+
[userOptions.clientEntry, userOptions.clientEntry],
|
|
52
|
+
["index.html", "index.html"],
|
|
53
|
+
].map(normalizer)
|
|
54
|
+
)
|
|
55
|
+
: { "index.html": "index.html" };
|
|
56
|
+
|
|
57
|
+
const autoDiscoveredClientFiles = (inputs: Record<string, string>) => {
|
|
58
|
+
const allFiles = globSync(`**/*.client.*`, {
|
|
59
|
+
cwd: join(root, userOptions.moduleBase),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
for (const file of allFiles) {
|
|
63
|
+
const [key, value] = normalizer(join(userOptions.moduleBase, file));
|
|
64
|
+
if (!inputs[key]) {
|
|
65
|
+
inputs[key] = value;
|
|
66
|
+
} else {
|
|
67
|
+
console.warn(`[RSC] Client file already exists: ${key}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return inputs;
|
|
48
71
|
};
|
|
72
|
+
const autoDiscoveredServerFiles = (inputs: Record<string, string>) => {
|
|
73
|
+
const allFiles = globSync(`${userOptions.moduleBase}/**/*.server.*`, {
|
|
74
|
+
cwd: join(root, userOptions.moduleBase),
|
|
75
|
+
});
|
|
76
|
+
for (const file of allFiles) {
|
|
77
|
+
const [key, value] = normalizer(join(userOptions.moduleBase, file));
|
|
78
|
+
if (!inputs[key]) {
|
|
79
|
+
inputs[key] = value;
|
|
80
|
+
} else {
|
|
81
|
+
console.warn(`[RSC] Server file already exists: ${key}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return inputs;
|
|
85
|
+
};
|
|
86
|
+
const autoDiscoveredFiles = (inputs: Record<string, string>) => {
|
|
87
|
+
if (!files) return inputs;
|
|
49
88
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
outDir: condition === 'react-server' ? userOptions.build.server : userOptions.build.client,
|
|
57
|
-
assetsDir: condition === 'react-server' ? "" : DEFAULT_CONFIG.CLIENT_ASSETS_DIR,
|
|
58
|
-
ssr: condition === 'react-server',
|
|
59
|
-
target: condition === 'react-server' ? 'node18' : 'es2020',
|
|
60
|
-
minify: condition === 'react-server' ? false : true,
|
|
61
|
-
manifest: true,
|
|
62
|
-
ssrManifest: false,
|
|
63
|
-
ssrEmitAssets: true,
|
|
64
|
-
rollupOptions: {
|
|
65
|
-
...config.build?.rollupOptions,
|
|
66
|
-
input: inputs,
|
|
67
|
-
preserveEntrySignatures: 'strict',
|
|
68
|
-
output: condition === 'react-server' ? {
|
|
69
|
-
preserveModules: true,
|
|
70
|
-
entryFileNames: '[name].js',
|
|
71
|
-
assetFileNames: '[name].[ext]',
|
|
72
|
-
chunkFileNames: '[name].[ext]',
|
|
73
|
-
format: 'esm',
|
|
74
|
-
exports: 'named',
|
|
75
|
-
hoistTransitiveImports: false,
|
|
76
|
-
generatedCode: {
|
|
77
|
-
constBindings: true,
|
|
78
|
-
objectShorthand: true
|
|
79
|
-
},
|
|
80
|
-
interop: 'auto'
|
|
81
|
-
} : undefined
|
|
89
|
+
// Add page files without extra prefix
|
|
90
|
+
for (const [key, value] of files.pageMap) {
|
|
91
|
+
if (!inputs[key]) {
|
|
92
|
+
inputs[key] = value;
|
|
93
|
+
} else {
|
|
94
|
+
console.warn(`[RSC] Page file already exists: ${key}`);
|
|
82
95
|
}
|
|
83
96
|
}
|
|
97
|
+
// Add props files without extra prefix
|
|
98
|
+
for (const [key, value] of files.propsMap) {
|
|
99
|
+
if (!inputs[key]) {
|
|
100
|
+
inputs[key] = value;
|
|
101
|
+
} else {
|
|
102
|
+
console.warn(`[RSC] Props file already exists: ${key}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return inputs;
|
|
84
106
|
};
|
|
85
107
|
|
|
108
|
+
// Add inputs based on condition
|
|
109
|
+
let inputs = isClient
|
|
110
|
+
? autoDiscoveredClientFiles(clientEntry)
|
|
111
|
+
: autoDiscoveredServerFiles(autoDiscoveredFiles(serverEntry ?? {}));
|
|
112
|
+
|
|
113
|
+
const envDir = isClient
|
|
114
|
+
? userOptions.build.client
|
|
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
|
+
|
|
142
|
+
if (isClient) {
|
|
143
|
+
// client build options
|
|
144
|
+
return {
|
|
145
|
+
type: "success",
|
|
146
|
+
userConfig: {
|
|
147
|
+
...config,
|
|
148
|
+
root: root,
|
|
149
|
+
mode: configEnv.command === "build" ? "production" : "development",
|
|
150
|
+
resolve: {
|
|
151
|
+
external: ["react", "react-dom"],
|
|
152
|
+
alias: {},
|
|
153
|
+
},
|
|
154
|
+
ssr: {
|
|
155
|
+
target: "node",
|
|
156
|
+
external: [
|
|
157
|
+
"react",
|
|
158
|
+
"react-dom",
|
|
159
|
+
"react-server-dom-esm/client.browser",
|
|
160
|
+
],
|
|
161
|
+
resolve: {
|
|
162
|
+
externalConditions: ["react-server"],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
// client build options
|
|
166
|
+
build: {
|
|
167
|
+
...config.build,
|
|
168
|
+
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
169
|
+
outDir: join(userOptions.build.outDir, envDir),
|
|
170
|
+
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
171
|
+
// modern browsers
|
|
172
|
+
target: ["esnext"],
|
|
173
|
+
minify: true,
|
|
174
|
+
ssr:
|
|
175
|
+
typeof configEnv.isSsrBuild === "boolean"
|
|
176
|
+
? configEnv.isSsrBuild
|
|
177
|
+
: true,
|
|
178
|
+
manifest: config.build?.manifest ?? `.vite/manifest.json`,
|
|
179
|
+
ssrManifest: config.build?.ssrManifest ?? `.vite/ssr-manifest.json`,
|
|
180
|
+
ssrEmitAssets: config.build?.ssrEmitAssets ?? true,
|
|
181
|
+
rollupOptions: {
|
|
182
|
+
...config.build?.rollupOptions,
|
|
183
|
+
input: inputs,
|
|
184
|
+
output: newOutput,
|
|
185
|
+
preserveEntrySignatures: "exports-only",
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// server build options
|
|
86
192
|
return {
|
|
87
193
|
type: "success",
|
|
88
|
-
userConfig:
|
|
194
|
+
userConfig: {
|
|
195
|
+
...config,
|
|
196
|
+
root: root,
|
|
197
|
+
mode: configEnv.command === "build" ? "production" : "development",
|
|
198
|
+
resolve: {
|
|
199
|
+
alias: {},
|
|
200
|
+
externalConditions: ["react-server"],
|
|
201
|
+
},
|
|
202
|
+
// server build options
|
|
203
|
+
build: {
|
|
204
|
+
...config.build,
|
|
205
|
+
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
206
|
+
outDir: join(userOptions.build.outDir, envDir),
|
|
207
|
+
target: config.build?.target ?? "node18",
|
|
208
|
+
minify: config.build?.minify ?? true,
|
|
209
|
+
ssr: config.build?.ssr ?? configEnv.isSsrBuild ?? true,
|
|
210
|
+
manifest: config.build?.manifest ?? `.vite/manifest.json`,
|
|
211
|
+
ssrManifest: config.build?.ssrManifest ?? `.vite/ssr-manifest.json`,
|
|
212
|
+
ssrEmitAssets: config.build?.ssrEmitAssets ?? true,
|
|
213
|
+
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
214
|
+
rollupOptions: {
|
|
215
|
+
...config.build?.rollupOptions,
|
|
216
|
+
input: inputs,
|
|
217
|
+
preserveEntrySignatures: config.build?.rollupOptions?.preserveEntrySignatures ?? "strict",
|
|
218
|
+
output: newOutput,
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
89
222
|
};
|
|
90
223
|
} catch (error) {
|
|
91
224
|
return {
|
|
92
225
|
type: "error",
|
|
93
|
-
error:
|
|
226
|
+
error:
|
|
227
|
+
error instanceof Error ? error : new Error("Failed to resolve config"),
|
|
94
228
|
};
|
|
95
229
|
}
|
|
96
|
-
}
|
|
230
|
+
}
|