vite-plugin-react-server 0.3.18 → 1.0.0
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 +220 -141
- package/bin/patch.mjs +8 -2
- package/dist/package.json +15 -8
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +6 -2
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +23 -0
- package/dist/plugin/collect-manifest-client-files.d.ts.map +1 -0
- package/dist/plugin/collect-manifest-client-files.js +131 -0
- package/dist/plugin/collect-manifest-client-files.js.map +1 -0
- package/dist/plugin/components.d.ts +3 -13
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +3 -13
- package/dist/plugin/config/defaults.d.ts +14 -6
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +9 -5
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js +2 -7
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/mimeTypes.d.ts +2 -0
- package/dist/plugin/config/mimeTypes.d.ts.map +1 -0
- package/dist/plugin/config/mimeTypes.js +24 -0
- package/dist/plugin/config/mimeTypes.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +2 -2
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +47 -28
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +1 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +9 -5
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +181 -147
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy-dir.js +23 -18
- package/dist/plugin/copy-dir.js.map +1 -0
- package/dist/plugin/css-collector-inline.d.ts +10 -0
- package/dist/plugin/css-collector-inline.d.ts.map +1 -0
- package/dist/plugin/css-collector-inline.js +55 -0
- package/dist/plugin/css-collector-inline.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +14 -0
- package/dist/plugin/css-collector.d.ts.map +1 -0
- package/dist/plugin/css-collector.js +49 -0
- package/dist/plugin/css-collector.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +17 -0
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -0
- package/dist/plugin/helpers/createHandler.js +111 -0
- package/dist/plugin/helpers/createHandler.js.map +1 -0
- package/dist/plugin/helpers/createRscStream.d.ts +27 -0
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -0
- package/dist/plugin/helpers/createRscStream.js +80 -0
- package/dist/plugin/helpers/createRscStream.js.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +12 -4
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/html.d.ts +5 -0
- package/dist/plugin/html.d.ts.map +1 -0
- package/dist/plugin/html.js +11 -0
- package/dist/plugin/html.js.map +1 -0
- 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 +8 -5
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.js.map +1 -1
- package/dist/plugin/loader/react-loader.js +2 -2
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +49 -14
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +21 -78
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +2 -0
- package/dist/plugin/react-server/index.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts +2 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +92 -225
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-static/index.d.ts +2 -0
- package/dist/plugin/react-static/index.d.ts.map +1 -0
- package/dist/plugin/react-static/index.js +1 -0
- package/dist/plugin/react-static/plugin.d.ts +7 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -0
- package/dist/plugin/react-static/plugin.js +207 -0
- package/dist/plugin/react-static/plugin.js.map +1 -0
- package/dist/plugin/react-static/types.d.ts +2 -0
- package/dist/plugin/react-static/types.d.ts.map +1 -0
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +9 -0
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/root.d.ts +2 -0
- package/dist/plugin/root.d.ts.map +1 -0
- package/dist/plugin/root.js +12 -0
- package/dist/plugin/root.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +32 -23
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/types.d.ts +1 -18
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +70 -15
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +0 -1
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.d.ts +30 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +30 -2
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +3 -5
- 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 +12 -3
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/renderPages.d.ts +13 -26
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +138 -86
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +104 -84
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +13 -18
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +4 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/types.d.ts +3 -0
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -6
- package/plugin/checkFilesExist.ts +7 -3
- package/plugin/collect-manifest-client-files.ts +167 -0
- package/plugin/components.ts +3 -0
- package/plugin/config/defaults.tsx +70 -0
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/mimeTypes.ts +17 -0
- package/plugin/config/resolveOptions.ts +58 -45
- package/plugin/config/resolvePages.ts +8 -4
- package/plugin/config/resolveUserConfig.ts +220 -176
- package/plugin/css-collector-inline.tsx +60 -0
- package/plugin/css-collector.tsx +62 -0
- package/plugin/helpers/createHandler.ts +135 -0
- package/plugin/helpers/createRscStream.ts +109 -0
- package/plugin/helpers/getBundleManifest.ts +14 -5
- package/plugin/html.tsx +9 -0
- package/plugin/loader/createBuildLoader.ts +9 -6
- package/plugin/loader/css-loader.ts +0 -2
- package/plugin/loader/react-loader.ts +2 -2
- package/plugin/preserver/plugin.ts +64 -17
- package/plugin/react-client/plugin.ts +23 -93
- package/plugin/react-server/index.ts +2 -0
- package/plugin/react-server/plugin.ts +111 -302
- package/plugin/react-static/index.ts +1 -0
- package/plugin/react-static/plugin.ts +256 -0
- package/plugin/react-static/types.ts +3 -0
- package/plugin/resolvePage.ts +9 -0
- package/plugin/root.ts +4 -0
- package/plugin/transformer/plugin.ts +40 -31
- package/plugin/transformer/types.ts +0 -19
- package/plugin/types.ts +77 -16
- package/plugin/worker/createWorker.ts +1 -1
- package/plugin/worker/html/README.md +63 -0
- package/plugin/worker/html/html-worker.development.tsx +89 -2
- package/plugin/worker/html/html-worker.production.tsx +8 -10
- package/plugin/worker/html/messageHandler.ts +12 -3
- package/plugin/worker/html/renderPages.ts +178 -138
- package/plugin/worker/rsc/README.md +58 -0
- package/plugin/worker/rsc/messageHandler.tsx +112 -113
- package/plugin/worker/rsc/rsc-worker.development.ts +12 -22
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -1
- package/plugin/worker/rsc/state.ts +0 -3
- package/plugin/worker/types.ts +3 -0
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +114 -12
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +10571 -121
- package/tsconfig.json +2 -2
- package/dist/plugin/collect-css-manifest.d.ts +0 -4
- package/dist/plugin/collect-css-manifest.d.ts.map +0 -1
- package/dist/plugin/collect-css-manifest.js +0 -65
- package/dist/plugin/collect-css-manifest.js.map +0 -1
- package/dist/plugin/config/createModuleIdGenerator.d.ts +0 -11
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +0 -1
- package/dist/plugin/config/createModuleIdGenerator.js +0 -44
- package/dist/plugin/config/createModuleIdGenerator.js.map +0 -1
- package/dist/plugin/getEnv.d.ts +0 -19
- package/dist/plugin/getEnv.d.ts.map +0 -1
- package/dist/plugin/getEnv.js +0 -107
- package/dist/plugin/loader/createCssLoader.d.ts +0 -30
- package/dist/plugin/loader/createCssLoader.d.ts.map +0 -1
- package/dist/plugin/loader/createCssLoader.js +0 -35
- package/dist/plugin/loader/createPageLoader.d.ts +0 -24
- package/dist/plugin/loader/createPageLoader.d.ts.map +0 -1
- package/dist/plugin/loader/createPageLoader.js +0 -50
- package/dist/plugin/loader/rsc/messageHandler.d.ts +0 -2
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +0 -1
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +0 -2
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +0 -1
- package/dist/plugin/loader/rsc/rsc-worker.development.js +0 -1
- package/dist/plugin/module-graph.d.ts +0 -10
- package/dist/plugin/module-graph.d.ts.map +0 -1
- package/dist/plugin/module-graph.js +0 -35
- package/dist/plugin/react-server/createHandler.d.ts +0 -17
- package/dist/plugin/react-server/createHandler.d.ts.map +0 -1
- package/dist/plugin/react-server/createHandler.js +0 -126
- package/dist/plugin/react-server/createHandler.js.map +0 -1
- package/dist/plugin/react-server/createRscStream.d.ts +0 -16
- package/dist/plugin/react-server/createRscStream.d.ts.map +0 -1
- package/dist/plugin/react-server/createRscStream.js +0 -70
- package/dist/plugin/react-server/createRscStream.js.map +0 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +0 -4
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +0 -1
- package/dist/plugin/react-server/createSsrHandler.js +0 -95
- package/dist/plugin/utils/logger.d.ts +0 -9
- package/dist/plugin/utils/logger.d.ts.map +0 -1
- package/dist/plugin/utils/logger.js +0 -68
- package/dist/plugin/utils/logger.js.map +0 -1
- package/dist/plugin/worker/html/plugin.d.ts +0 -4
- package/dist/plugin/worker/html/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/html/plugin.js +0 -94
- package/dist/plugin/worker/plugin.d.ts +0 -19
- package/dist/plugin/worker/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/plugin.js +0 -23
- package/dist/plugin/worker/rsc/plugin.d.ts +0 -4
- package/dist/plugin/worker/rsc/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js +0 -76
- package/plugin/collect-css-manifest.ts +0 -82
- package/plugin/components.tsx +0 -14
- package/plugin/config/createModuleIdGenerator.ts +0 -52
- package/plugin/config/defaults.ts +0 -51
- package/plugin/getEnv.ts +0 -135
- package/plugin/loader/createCssLoader.ts +0 -73
- package/plugin/loader/createPageLoader.ts +0 -103
- package/plugin/loader/rsc/messageHandler.tsx +0 -1
- package/plugin/loader/rsc/rsc-worker.development.ts +0 -1
- package/plugin/module-graph.ts +0 -48
- package/plugin/react-server/createHandler.ts +0 -162
- package/plugin/react-server/createRscStream.ts +0 -86
- package/plugin/react-server/createSsrHandler.ts +0 -125
- package/plugin/utils/logger.ts +0 -52
- package/plugin/worker/html/plugin.ts +0 -101
- package/plugin/worker/plugin.ts +0 -26
- package/plugin/worker/rsc/plugin.ts +0 -84
- /package/dist/plugin/{loader/rsc/messageHandler.js → react-static/types.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Vite plugin for React Server Components (RSC)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/plugin/index.js",
|
|
@@ -19,13 +19,15 @@
|
|
|
19
19
|
".": "./dist/plugin/index.js",
|
|
20
20
|
"./client": "./dist/client.js",
|
|
21
21
|
"./server": "./dist/server.js",
|
|
22
|
+
"./static": "./dist/static.js",
|
|
22
23
|
"./html-worker": "./dist/plugin/worker/html-worker.js",
|
|
23
24
|
"./rsc-worker": "./dist/plugin/worker/rsc-worker.js",
|
|
24
25
|
"./loader": "./dist/plugin/worker/loader.js",
|
|
25
26
|
"./package.json": "./package.json",
|
|
26
27
|
"./patch": "./scripts/patch.mjs",
|
|
27
28
|
"./check-react-version": "./scripts/check-react-version.mjs",
|
|
28
|
-
"./css-loader": "./dist/plugin/loader/css-loader.js"
|
|
29
|
+
"./css-loader": "./dist/plugin/loader/css-loader.js",
|
|
30
|
+
"./components": "./dist/plugin/components.js"
|
|
29
31
|
},
|
|
30
32
|
"typesVersions": {
|
|
31
33
|
"*": {
|
|
@@ -38,11 +40,17 @@
|
|
|
38
40
|
"server": [
|
|
39
41
|
"./dist/plugin/react-server/plugin.d.ts"
|
|
40
42
|
],
|
|
43
|
+
"static": [
|
|
44
|
+
"./dist/plugin/static/plugin.d.ts"
|
|
45
|
+
],
|
|
41
46
|
"worker": [
|
|
42
47
|
"./dist/plugin/worker/worker.d.ts"
|
|
43
48
|
],
|
|
44
49
|
"loader": [
|
|
45
50
|
"./dist/plugin/worker/loader.d.ts"
|
|
51
|
+
],
|
|
52
|
+
"components": [
|
|
53
|
+
"./dist/plugin/components.d.ts"
|
|
46
54
|
]
|
|
47
55
|
}
|
|
48
56
|
},
|
|
@@ -91,8 +99,8 @@
|
|
|
91
99
|
},
|
|
92
100
|
"homepage": "https://github.com/nicobrinkkemper/vite-plugin-react-server#readme",
|
|
93
101
|
"peerDependencies": {
|
|
94
|
-
"react": "^0.0.0-experimental-
|
|
95
|
-
"react-dom": "^0.0.0-experimental-
|
|
102
|
+
"react": "^0.0.0-experimental-f9d78089-20250306",
|
|
103
|
+
"react-dom": "^0.0.0-experimental-f9d78089-20250306",
|
|
96
104
|
"vite": "*"
|
|
97
105
|
},
|
|
98
106
|
"peerDependenciesMeta": {
|
|
@@ -120,13 +128,13 @@
|
|
|
120
128
|
"typescript": "^5.7.3",
|
|
121
129
|
"vite": "^6.0.11",
|
|
122
130
|
"vitest": "^3.0.4",
|
|
123
|
-
"webpack-sources": "^3.2.3"
|
|
131
|
+
"webpack-sources": "^3.2.3",
|
|
132
|
+
"tsx": "^4.19.2"
|
|
124
133
|
},
|
|
125
134
|
"bin": {
|
|
126
135
|
"check-react-version": "./scripts/check-react-version.mjs",
|
|
127
136
|
"patch": "./bin/patch.mjs"
|
|
128
137
|
},
|
|
129
138
|
"dependencies": {
|
|
130
|
-
"tsx": "^4.19.2"
|
|
131
139
|
}
|
|
132
140
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import type { CheckFilesExistReturn, ResolvedUserOptions } from "./types.js";
|
|
4
|
-
import { normalizePath } from "vite";
|
|
5
4
|
import { createInputNormalizer } from "./helpers/inputNormalizer.js";
|
|
6
5
|
|
|
6
|
+
let stashedFiles: CheckFilesExistReturn | null = null;
|
|
7
|
+
|
|
7
8
|
const resolveFileOption = (pageOrProps: string | ((url: string) => string)) => {
|
|
8
9
|
if (typeof pageOrProps === "string") {
|
|
9
10
|
return () => pageOrProps;
|
|
@@ -16,6 +17,9 @@ export async function checkFilesExist(
|
|
|
16
17
|
options: ResolvedUserOptions,
|
|
17
18
|
root: string
|
|
18
19
|
): Promise<CheckFilesExistReturn> {
|
|
20
|
+
if(stashedFiles){
|
|
21
|
+
return stashedFiles;
|
|
22
|
+
}
|
|
19
23
|
if (!root || root === "") {
|
|
20
24
|
throw new Error("Root not found");
|
|
21
25
|
}
|
|
@@ -57,6 +61,6 @@ export async function checkFilesExist(
|
|
|
57
61
|
pageMap.set(pageKey, pageValue);
|
|
58
62
|
propsMap.set(propsKey, propsValue);
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
return
|
|
64
|
+
stashedFiles = { pageMap, pageSet, propsMap, propsSet, urlMap, errors };
|
|
65
|
+
return stashedFiles;
|
|
62
66
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Manifest, ModuleGraph } from "vite";
|
|
2
|
+
import { createInputNormalizer } from "./helpers/inputNormalizer.js";
|
|
3
|
+
import { DEFAULT_CONFIG } from "./config/defaults.js";
|
|
4
|
+
|
|
5
|
+
export async function collectModuleGraphCss({
|
|
6
|
+
moduleGraph,
|
|
7
|
+
pagePath,
|
|
8
|
+
onCss,
|
|
9
|
+
parentUrl,
|
|
10
|
+
}: {
|
|
11
|
+
moduleGraph: ModuleGraph;
|
|
12
|
+
pagePath: string;
|
|
13
|
+
onCss?: (path: string, parentUrl: string) => void;
|
|
14
|
+
parentUrl?: string;
|
|
15
|
+
}) {
|
|
16
|
+
if (!pagePath) return new Map<string, string>();
|
|
17
|
+
|
|
18
|
+
const cssFiles = new Map<string, string>();
|
|
19
|
+
const pageModule = await moduleGraph.getModuleByUrl(pagePath, true);
|
|
20
|
+
if (!pageModule) {
|
|
21
|
+
return new Map<string, string>();
|
|
22
|
+
}
|
|
23
|
+
const seen = new Set<string>();
|
|
24
|
+
const walkModule = (mod: any) => {
|
|
25
|
+
if (!mod?.id || seen.has(mod.id)) return;
|
|
26
|
+
seen.add(mod.id);
|
|
27
|
+
if (mod?.id?.endsWith(".css")) {
|
|
28
|
+
cssFiles.set(mod?.url, mod?.id);
|
|
29
|
+
onCss?.(mod?.url, parentUrl ?? pagePath);
|
|
30
|
+
}
|
|
31
|
+
mod?.importedModules?.forEach((imp: any) => walkModule(imp));
|
|
32
|
+
};
|
|
33
|
+
walkModule(pageModule);
|
|
34
|
+
return cssFiles;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function collectManifestClientFiles({
|
|
38
|
+
manifest,
|
|
39
|
+
root,
|
|
40
|
+
pagePath,
|
|
41
|
+
preserveModulesRoot,
|
|
42
|
+
moduleBase,
|
|
43
|
+
onCss,
|
|
44
|
+
onClientModule,
|
|
45
|
+
testClient = DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents,
|
|
46
|
+
testJson = DEFAULT_CONFIG.AUTO_DISCOVER.jsonPattern,
|
|
47
|
+
}: {
|
|
48
|
+
manifest: Manifest;
|
|
49
|
+
root: string;
|
|
50
|
+
pagePath: string;
|
|
51
|
+
preserveModulesRoot?: boolean;
|
|
52
|
+
moduleBase?: string;
|
|
53
|
+
onCss?: (path: string, parentUrl: string) => void;
|
|
54
|
+
onClientModule?: (path: string, parentUrl: string) => void;
|
|
55
|
+
parentUrl?: string;
|
|
56
|
+
testClient?: (id: string) => boolean;
|
|
57
|
+
testJson?: (id: string) => boolean;
|
|
58
|
+
}) {
|
|
59
|
+
const normalizer = createInputNormalizer({
|
|
60
|
+
root,
|
|
61
|
+
removeExtension: true,
|
|
62
|
+
preserveModulesRoot: preserveModulesRoot ? moduleBase : undefined,
|
|
63
|
+
});
|
|
64
|
+
const [_, value] = normalizer(pagePath);
|
|
65
|
+
|
|
66
|
+
const cssFiles = new Map<string, string>();
|
|
67
|
+
const clientFiles = new Map<string, string>();
|
|
68
|
+
const seen = new Set<string>();
|
|
69
|
+
const manifestValues = Object.values(manifest);
|
|
70
|
+
|
|
71
|
+
// Try different variations of the path
|
|
72
|
+
const possibleKeys = [
|
|
73
|
+
value, // Relative path
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const walkManifestEntry = (id: string, parentUrl: string) => {
|
|
77
|
+
if (seen.has(id)) return;
|
|
78
|
+
seen.add(id);
|
|
79
|
+
|
|
80
|
+
// Get the manifest entry
|
|
81
|
+
const entry = manifest[id] ?? manifestValues.find((e) => id === e.file);
|
|
82
|
+
if (!entry) {
|
|
83
|
+
const hasKey = Object.keys(manifest).find((key) => id === key);
|
|
84
|
+
if (hasKey) {
|
|
85
|
+
console.log(
|
|
86
|
+
`Manifest entry found for ${id}, but it is ${typeof entry}`
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
} else {
|
|
90
|
+
console.log(
|
|
91
|
+
`No manifest entry found for ${id}, possible keys: ${Object.keys(
|
|
92
|
+
manifest
|
|
93
|
+
).join(", ")}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (
|
|
99
|
+
(typeof testClient === "function" &&
|
|
100
|
+
typeof onClientModule === "function" &&
|
|
101
|
+
testClient(entry.file)) ||
|
|
102
|
+
(typeof testJson === "function" && testJson(entry.file))
|
|
103
|
+
) {
|
|
104
|
+
onClientModule?.(entry.file ?? "", parentUrl);
|
|
105
|
+
clientFiles.set(id, entry.name ?? "");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Add direct CSS from the css array
|
|
109
|
+
if (entry.css) {
|
|
110
|
+
entry.css.forEach((css: string) => {
|
|
111
|
+
cssFiles.set(css, css);
|
|
112
|
+
onCss?.(css, id);
|
|
113
|
+
onClientModule?.(css, id);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Walk imports recursively
|
|
118
|
+
if (entry.imports) {
|
|
119
|
+
entry.imports.forEach((imp: string) =>
|
|
120
|
+
walkManifestEntry(imp, entry.file)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Also check dynamicImports
|
|
125
|
+
if (entry.dynamicImports) {
|
|
126
|
+
entry.dynamicImports.forEach((imp: string) =>
|
|
127
|
+
walkManifestEntry(imp, entry.file)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Try all possible keys
|
|
133
|
+
for (const possibleKey of possibleKeys) {
|
|
134
|
+
if (manifest[possibleKey]) {
|
|
135
|
+
walkManifestEntry(possibleKey, pagePath);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// If no entry found by key, try matching by file
|
|
141
|
+
if (cssFiles.size === 0) {
|
|
142
|
+
const entry = manifestValues.find(
|
|
143
|
+
(e) =>
|
|
144
|
+
possibleKeys.includes(e.file) ||
|
|
145
|
+
(e.src && possibleKeys.includes(e.src)) ||
|
|
146
|
+
(e.name && possibleKeys.includes(e.name))
|
|
147
|
+
);
|
|
148
|
+
if (entry) {
|
|
149
|
+
walkManifestEntry(value, pagePath);
|
|
150
|
+
} else {
|
|
151
|
+
const hasKey = Object.keys(manifest).find((key) => value === key);
|
|
152
|
+
if (hasKey) {
|
|
153
|
+
console.warn(
|
|
154
|
+
`Manifest entry found for ${value}, but it is ${typeof manifest[hasKey]}`
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
console.warn(
|
|
158
|
+
`No manifest entry found for ${value} (tried all possible keys: ${possibleKeys.join(
|
|
159
|
+
", "
|
|
160
|
+
)} for manifest keys: ${Object.keys(manifest).join(", ")})`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return { cssFiles, clientFiles };
|
|
167
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CssCollector } from "../css-collector.js";
|
|
2
|
+
import { Html } from "../html.js";
|
|
3
|
+
export const DEFAULT_CONFIG = {
|
|
4
|
+
FILE_REGEX: /\.(m|c)?(j|t)sx?$/,
|
|
5
|
+
CLIENT_ASSETS_DIR: "assets",
|
|
6
|
+
RSC_DIR: "rsc",
|
|
7
|
+
MODULE_BASE: "src",
|
|
8
|
+
MODULE_BASE_PATH: "",
|
|
9
|
+
MODULE_BASE_URL: "",
|
|
10
|
+
PAGE: "src/page/page.tsx",
|
|
11
|
+
PROPS: "src/page/props.ts",
|
|
12
|
+
CLIENT_ENTRY: "src/client.tsx",
|
|
13
|
+
SERVER_ENTRY: "src/server.tsx",
|
|
14
|
+
PAGE_EXPORT_NAME: "Page",
|
|
15
|
+
PROPS_EXPORT_NAME: "props",
|
|
16
|
+
HTML_WORKER_PATH: `worker/html/html-worker.${
|
|
17
|
+
process.env["NODE_ENV"] === "development" ? "development" : "production"
|
|
18
|
+
}.js`,
|
|
19
|
+
RSC_WORKER_PATH: `worker/rsc/rsc-worker.${
|
|
20
|
+
process.env["NODE_ENV"] === "development" ? "development" : "production"
|
|
21
|
+
}.js`,
|
|
22
|
+
LOADER_PATH: "worker/loader.js",
|
|
23
|
+
RSC_EXTENSION: ".rsc",
|
|
24
|
+
CSS_COLLECTOR: CssCollector,
|
|
25
|
+
HTML: Html,
|
|
26
|
+
COLLECT_CSS: true,
|
|
27
|
+
COLLECT_ASSETS: true,
|
|
28
|
+
INLINE_CSS: true,
|
|
29
|
+
DEV_PORT: 5173,
|
|
30
|
+
PREVIEW_PORT: 4173,
|
|
31
|
+
DEV_HOST: "localhost",
|
|
32
|
+
PREVIEW_HOST: "localhost",
|
|
33
|
+
ENV_PREFIX: "VITE_",
|
|
34
|
+
BUILD: {
|
|
35
|
+
pages: () => ["/"],
|
|
36
|
+
client: "client",
|
|
37
|
+
server: "server",
|
|
38
|
+
static: "static",
|
|
39
|
+
api: "api",
|
|
40
|
+
outDir: "dist",
|
|
41
|
+
assetsDir: "assets",
|
|
42
|
+
hash: "hash",
|
|
43
|
+
preserveModulesRoot: true,
|
|
44
|
+
},
|
|
45
|
+
CSS: {
|
|
46
|
+
inlineThreshold: 4096, // 4KB
|
|
47
|
+
inlinePatterns: [/\.module\.css$/], // Always inline CSS modules
|
|
48
|
+
linkPatterns: [/node_modules/], // Always link node_modules CSS
|
|
49
|
+
},
|
|
50
|
+
MODULE_BASE_EXCEPTIONS: [] as string[],
|
|
51
|
+
AUTO_DISCOVER: {
|
|
52
|
+
modulePattern: (n: string) => DEFAULT_CONFIG.FILE_REGEX.test(n),
|
|
53
|
+
pagePattern: (n: string) =>
|
|
54
|
+
n.toLowerCase().endsWith("/page") || n.toLowerCase() === "page",
|
|
55
|
+
propsPattern: (n: string) =>
|
|
56
|
+
n.toLowerCase().endsWith("/props") || n.toLowerCase() === "props",
|
|
57
|
+
clientComponents: (n: string) =>
|
|
58
|
+
n.toLowerCase().endsWith(".client") || n.toLowerCase() === "client",
|
|
59
|
+
serverFunctions: (n: string) =>
|
|
60
|
+
n.toLowerCase().endsWith(".server") || n.toLowerCase() === "server",
|
|
61
|
+
cssPattern: (n: string) => n.toLowerCase().endsWith(".css"),
|
|
62
|
+
cssModulePattern: (n: string) => n.toLowerCase().endsWith(".css.js"),
|
|
63
|
+
vendorPattern: (n: string) =>
|
|
64
|
+
n.toLowerCase().startsWith("node_modules") ||
|
|
65
|
+
n.toLowerCase().startsWith("_virtual"),
|
|
66
|
+
htmlPattern: (n: string) => n.toLowerCase().endsWith(".html"),
|
|
67
|
+
jsonPattern: (n: string) => n.toLowerCase().endsWith(".json"),
|
|
68
|
+
},
|
|
69
|
+
MODULE_ID: (id: string) => id,
|
|
70
|
+
} as const;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { join
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
1
|
+
import { join } from 'node:path';
|
|
3
2
|
|
|
4
3
|
export const getNodePath = (root: string = process.cwd()): string => {
|
|
5
4
|
return process.env['module_root'] ?? join(root, "node_modules");
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
export const getPluginRoot = (): string => {
|
|
9
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
return join(__dirname, '..');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
7
|
export const getMode = (): "production" | "development" | "test" => {
|
|
14
8
|
return process.env['NODE_ENV'] === "development"
|
|
15
9
|
? "development"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
export const MIME_TYPES: Record<string, string> = {
|
|
3
|
+
'.html': 'text/html',
|
|
4
|
+
'.css': 'text/css',
|
|
5
|
+
'.js': 'application/javascript',
|
|
6
|
+
'.json': 'application/json',
|
|
7
|
+
'.png': 'image/png',
|
|
8
|
+
'.jpg': 'image/jpeg',
|
|
9
|
+
'.jpeg': 'image/jpeg',
|
|
10
|
+
'.gif': 'image/gif',
|
|
11
|
+
'.svg': 'image/svg+xml',
|
|
12
|
+
'.ico': 'image/x-icon',
|
|
13
|
+
'.woff': 'font/woff',
|
|
14
|
+
'.woff2': 'font/woff2',
|
|
15
|
+
'.ttf': 'font/ttf',
|
|
16
|
+
'.rsc': 'text/x-component'
|
|
17
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { PreRenderedAsset } from "rollup";
|
|
2
2
|
import type { PreRenderedChunk } from "rollup";
|
|
3
|
-
import type { StreamPluginOptions, ResolvedUserOptions } from "../types.js";
|
|
3
|
+
import type { StreamPluginOptions, ResolvedUserOptions, InlineCssCollectorProps, CssCollectorProps } from "../types.js";
|
|
4
4
|
import { DEFAULT_CONFIG } from "./defaults.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { pluginRoot } from "../root.js";
|
|
7
|
+
import { InlineCssCollector } from "../css-collector-inline.js";
|
|
8
|
+
import { CssCollector } from "../css-collector.js";
|
|
7
9
|
|
|
8
10
|
const resolveAutoDiscoverMatcher = (
|
|
9
11
|
options: undefined | string | RegExp | ((path: string) => boolean),
|
|
@@ -45,18 +47,18 @@ const handleSearchQuery = (path: string) => {
|
|
|
45
47
|
|
|
46
48
|
const applyPattern = (
|
|
47
49
|
path: string,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
_pattern?: string | RegExp | ((path: string) => boolean) | undefined,
|
|
51
|
+
_fallback?: string | undefined
|
|
50
52
|
) => {
|
|
51
53
|
// 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
54
|
return path;
|
|
53
55
|
};
|
|
54
56
|
|
|
55
|
-
export const resolveOptions = (
|
|
56
|
-
options: StreamPluginOptions
|
|
57
|
-
isClient: boolean
|
|
57
|
+
export const resolveOptions = <InlineCSS extends boolean = boolean>(
|
|
58
|
+
options: StreamPluginOptions<InlineCSS>,
|
|
59
|
+
isClient: boolean
|
|
58
60
|
):
|
|
59
|
-
| { type: "success"; userOptions: ResolvedUserOptions }
|
|
61
|
+
| { type: "success"; userOptions: ResolvedUserOptions<InlineCSS> }
|
|
60
62
|
| { type: "error"; error: Error } => {
|
|
61
63
|
const projectRoot = options.projectRoot ?? process.cwd();
|
|
62
64
|
const {
|
|
@@ -149,7 +151,9 @@ export const resolveOptions = (
|
|
|
149
151
|
const hashString = hashOption === "" ? "" : `-[${hashOption}]`;
|
|
150
152
|
const hash = (n: string | null) => {
|
|
151
153
|
if (!n) return "";
|
|
152
|
-
if (hashString === "")
|
|
154
|
+
if (hashString === "" || ( !isClient && !n.endsWith('.css') && !n.endsWith('.json') ) ) {
|
|
155
|
+
return n;
|
|
156
|
+
}
|
|
153
157
|
const extensionIndex = n.lastIndexOf(".");
|
|
154
158
|
if (extensionIndex !== -1) {
|
|
155
159
|
// put hash between extension and filename
|
|
@@ -172,19 +176,27 @@ export const resolveOptions = (
|
|
|
172
176
|
if (testVendor(path)) {
|
|
173
177
|
return path;
|
|
174
178
|
}
|
|
175
|
-
|
|
179
|
+
|
|
176
180
|
if (testCssModule(path)) {
|
|
177
181
|
// For CSS modules, keep the .css.js extension
|
|
178
|
-
return applyPattern(
|
|
182
|
+
return applyPattern(
|
|
183
|
+
path,
|
|
184
|
+
options.autoDiscover?.cssModulePattern,
|
|
185
|
+
".css.js"
|
|
186
|
+
);
|
|
179
187
|
}
|
|
180
|
-
|
|
188
|
+
|
|
181
189
|
if (testCss(path)) {
|
|
182
190
|
// For regular CSS files, keep the .css extension
|
|
183
191
|
return applyPattern(path, options.autoDiscover?.cssPattern, ".css");
|
|
184
192
|
}
|
|
185
193
|
|
|
186
194
|
if (testClientComponents(path)) {
|
|
187
|
-
return applyPattern(
|
|
195
|
+
return applyPattern(
|
|
196
|
+
path,
|
|
197
|
+
options.autoDiscover?.clientComponents,
|
|
198
|
+
"client"
|
|
199
|
+
);
|
|
188
200
|
}
|
|
189
201
|
if (testHtml(path)) {
|
|
190
202
|
return applyPattern(path, options.autoDiscover?.htmlPattern, ".html");
|
|
@@ -209,7 +221,11 @@ export const resolveOptions = (
|
|
|
209
221
|
);
|
|
210
222
|
}
|
|
211
223
|
if (testServerFunctions(path)) {
|
|
212
|
-
return applyPattern(
|
|
224
|
+
return applyPattern(
|
|
225
|
+
path,
|
|
226
|
+
options.autoDiscover?.serverFunctions,
|
|
227
|
+
"server"
|
|
228
|
+
);
|
|
213
229
|
}
|
|
214
230
|
if (testModulePattern(path)) {
|
|
215
231
|
return path;
|
|
@@ -220,23 +236,23 @@ export const resolveOptions = (
|
|
|
220
236
|
const entryFile = (n: PreRenderedChunk) => {
|
|
221
237
|
if (testVendor(n.name)) {
|
|
222
238
|
const search = n.facadeModuleId?.split("?")[1];
|
|
223
|
-
if(search) {
|
|
224
|
-
return `${n.name}.${search}.js
|
|
239
|
+
if (search) {
|
|
240
|
+
return hash(`${n.name}.${search}.js`);
|
|
225
241
|
} else {
|
|
226
|
-
return n.name
|
|
242
|
+
return hash(`${n.name}.js`);
|
|
227
243
|
}
|
|
228
244
|
}
|
|
229
|
-
return addJS(getOutputPath(ensureModuleBase(ensureNoRoot(n.name))));
|
|
245
|
+
return hash(addJS(getOutputPath(ensureModuleBase(ensureNoRoot(n.name)))));
|
|
230
246
|
};
|
|
231
247
|
|
|
232
248
|
const chunkFile = (n: PreRenderedChunk) => {
|
|
233
249
|
// For chunks, we always want .js
|
|
234
|
-
return addJS(getOutputPath(ensureModuleBase(ensureNoRoot(
|
|
250
|
+
return hash(addJS(getOutputPath(ensureModuleBase(ensureNoRoot("_" + n.name)))));
|
|
235
251
|
};
|
|
236
252
|
|
|
237
253
|
const assetFile = (n: PreRenderedAsset) => {
|
|
238
254
|
// For assets, keep the original extension
|
|
239
|
-
return getOutputPath(ensureModuleBase(ensureNoRoot(n.names[0])));
|
|
255
|
+
return hash(getOutputPath(ensureModuleBase(ensureNoRoot(n.names[0]))));
|
|
240
256
|
};
|
|
241
257
|
|
|
242
258
|
const build =
|
|
@@ -286,13 +302,23 @@ export const resolveOptions = (
|
|
|
286
302
|
const moduleBasePath =
|
|
287
303
|
typeof options.moduleBasePath === "string"
|
|
288
304
|
? options.moduleBasePath
|
|
289
|
-
:
|
|
290
|
-
? options.moduleBase
|
|
291
|
-
: "/" + options.moduleBase;
|
|
305
|
+
: DEFAULT_CONFIG.MODULE_BASE_PATH;
|
|
292
306
|
const moduleBaseURL =
|
|
293
307
|
typeof options.moduleBaseURL === "string"
|
|
294
308
|
? options.moduleBaseURL
|
|
295
|
-
:
|
|
309
|
+
: DEFAULT_CONFIG.MODULE_BASE_URL;
|
|
310
|
+
const rscWorkerPath =
|
|
311
|
+
typeof options.rscWorkerPath === "string"
|
|
312
|
+
? join(projectRoot, options.rscWorkerPath)
|
|
313
|
+
: join(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
|
|
314
|
+
const htmlWorkerPath =
|
|
315
|
+
typeof options.htmlWorkerPath === "string"
|
|
316
|
+
? join(projectRoot, options.htmlWorkerPath)
|
|
317
|
+
: join(pluginRoot, DEFAULT_CONFIG.HTML_WORKER_PATH);
|
|
318
|
+
const loaderPath =
|
|
319
|
+
typeof options.loaderPath === "string"
|
|
320
|
+
? join(projectRoot, options.loaderPath)
|
|
321
|
+
: join(pluginRoot, DEFAULT_CONFIG.LOADER_PATH);
|
|
296
322
|
|
|
297
323
|
const autoDiscover = {
|
|
298
324
|
modulePattern: testModulePattern,
|
|
@@ -305,27 +331,13 @@ export const resolveOptions = (
|
|
|
305
331
|
cssModulePattern: testCssModule,
|
|
306
332
|
vendorPattern: testVendor,
|
|
307
333
|
};
|
|
308
|
-
|
|
309
|
-
const
|
|
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
|
-
|
|
334
|
+
const inlineCss = options.inlineCss;
|
|
335
|
+
const InlineOrLinkCssCollector = options.CssCollector ?? inlineCss ? InlineCssCollector : CssCollector;
|
|
323
336
|
try {
|
|
324
337
|
return {
|
|
325
338
|
type: "success",
|
|
326
339
|
userOptions: {
|
|
327
340
|
projectRoot,
|
|
328
|
-
moduleId: moduleId,
|
|
329
341
|
moduleBase,
|
|
330
342
|
moduleBasePath,
|
|
331
343
|
moduleBaseURL,
|
|
@@ -333,14 +345,15 @@ export const resolveOptions = (
|
|
|
333
345
|
Page: options.Page ?? DEFAULT_CONFIG.PAGE,
|
|
334
346
|
props: options.props ?? DEFAULT_CONFIG.PROPS,
|
|
335
347
|
Html: options.Html ?? DEFAULT_CONFIG.HTML,
|
|
348
|
+
CssCollector: InlineOrLinkCssCollector as InlineCSS extends true ? React.FC<React.PropsWithChildren<InlineCssCollectorProps>> : React.FC<React.PropsWithChildren<CssCollectorProps>>,
|
|
336
349
|
pageExportName: pageExportName,
|
|
337
350
|
propsExportName: propsExportName,
|
|
338
351
|
collectCss: options.collectCss ?? DEFAULT_CONFIG.COLLECT_CSS,
|
|
339
352
|
collectAssets: options.collectAssets ?? DEFAULT_CONFIG.COLLECT_ASSETS,
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
rscWorkerPath:
|
|
343
|
-
loaderPath:
|
|
353
|
+
inlineCss: options.inlineCss ?? DEFAULT_CONFIG.INLINE_CSS,
|
|
354
|
+
htmlWorkerPath: htmlWorkerPath,
|
|
355
|
+
rscWorkerPath: rscWorkerPath,
|
|
356
|
+
loaderPath: loaderPath,
|
|
344
357
|
clientEntry: options.clientEntry ?? DEFAULT_CONFIG.CLIENT_ENTRY,
|
|
345
358
|
serverEntry: options.serverEntry ?? DEFAULT_CONFIG.SERVER_ENTRY,
|
|
346
359
|
moduleBaseExceptions: options.moduleBaseExceptions ?? [],
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ResolvedUserOptions } from '../types.js';
|
|
2
2
|
|
|
3
|
+
export let stashedPages: string[] = [];
|
|
3
4
|
export async function resolvePages(
|
|
4
5
|
pages: ResolvedUserOptions["build"]["pages"]
|
|
5
6
|
): Promise<{ type: "success"; error?:never; pages: string[] } | { type: "error"; error: Error; pages?:never }> {
|
|
7
|
+
if(stashedPages.length > 0){
|
|
8
|
+
return { type: "success", pages: stashedPages };
|
|
9
|
+
}
|
|
6
10
|
if (!pages) {
|
|
7
11
|
return { type: "success", pages: [] };
|
|
8
12
|
}
|
|
@@ -10,24 +14,24 @@ export async function resolvePages(
|
|
|
10
14
|
try {
|
|
11
15
|
// Handle function
|
|
12
16
|
if (typeof pages === "function") {
|
|
13
|
-
|
|
14
|
-
return resolvePages(result);
|
|
17
|
+
return resolvePages(pages());
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
// Handle Promise
|
|
18
21
|
if (pages instanceof Promise) {
|
|
19
|
-
|
|
20
|
-
return resolvePages(result);
|
|
22
|
+
return resolvePages(await pages);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// Handle string
|
|
24
26
|
if (typeof pages === "string") {
|
|
27
|
+
stashedPages = [pages];
|
|
25
28
|
return { type: "success", pages: [pages] };
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
// Handle array
|
|
29
32
|
if (Array.isArray(pages)) {
|
|
30
33
|
if (pages.every(page => typeof page === "string")) {
|
|
34
|
+
stashedPages = pages;
|
|
31
35
|
return { type: "success", pages };
|
|
32
36
|
}
|
|
33
37
|
throw new Error('All pages must be strings');
|