vite-plugin-react-server 0.3.0 → 0.3.4
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 +73 -40
- package/dist/assertServerCondition.d.ts +2 -0
- package/dist/assertServerCondition.d.ts.map +1 -0
- package/dist/bin/patch.js +51 -0
- package/dist/bin/patch.js.map +1 -0
- package/dist/build/createBuildConfig.d.ts +7 -6
- package/dist/build/createBuildConfig.d.ts.map +1 -1
- package/dist/build/mergeInputs.d.ts +5 -0
- package/dist/build/mergeInputs.d.ts.map +1 -0
- package/dist/helpers/inputNormalizer.d.ts +6 -0
- package/dist/helpers/inputNormalizer.d.ts.map +1 -0
- package/dist/helpers/normalizedRelativePath.d.ts +3 -1
- package/dist/helpers/normalizedRelativePath.d.ts.map +1 -1
- package/dist/helpers/tryManifest.d.ts +10 -3
- package/dist/helpers/tryManifest.d.ts.map +1 -1
- package/dist/html/createPageLoader.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/options.d.ts +13 -8
- package/dist/options.d.ts.map +1 -1
- package/dist/plugin.d.ts +2 -7
- package/dist/plugin.d.ts.map +1 -1
- package/dist/react-client/plugin.js +1 -1
- package/dist/react-server/plugin.d.ts.map +1 -1
- package/dist/react-server/plugin.js +108 -61
- package/dist/react-server/plugin.js.map +1 -1
- package/dist/scripts/check-react-version.js +34 -0
- package/dist/scripts/check-react-version.js.map +1 -0
- package/dist/src/build/createBuildConfig.js +44 -0
- package/dist/src/build/createBuildConfig.js.map +1 -0
- package/dist/src/build/mergeInputs.js +16 -0
- package/dist/src/build/mergeInputs.js.map +1 -0
- package/dist/src/checkFilesExist.js.map +1 -0
- package/dist/src/collect-css-manifest.js.map +1 -0
- package/dist/src/components.js.map +1 -0
- package/dist/src/getEnv.js.map +1 -0
- package/dist/src/helpers/inputNormalizer.js +11 -0
- package/dist/src/helpers/inputNormalizer.js.map +1 -0
- package/dist/src/helpers/normalizedRelativePath.js +34 -0
- package/dist/src/helpers/normalizedRelativePath.js.map +1 -0
- package/dist/src/helpers/tryManifest.js +27 -0
- package/dist/src/helpers/tryManifest.js.map +1 -0
- package/dist/{html → src/html}/createPageLoader.js +3 -1
- package/dist/src/html/createPageLoader.js.map +1 -0
- package/dist/{options.js → src/options.js} +80 -24
- package/dist/src/options.js.map +1 -0
- package/dist/src/react-server/createHandler.js.map +1 -0
- package/dist/src/react-server/createRscStream.js.map +1 -0
- package/dist/src/resolvePage.js.map +1 -0
- package/dist/src/resolveProps.js.map +1 -0
- package/dist/src/worker/createHtmlStream.js +62 -0
- package/dist/src/worker/createHtmlStream.js.map +1 -0
- package/dist/{worker → src/worker}/createWorker.js +9 -8
- package/dist/src/worker/createWorker.js.map +1 -0
- package/dist/src/worker/renderPages.js.map +1 -0
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/worker/createWorker.d.ts +8 -1
- package/dist/worker/createWorker.d.ts.map +1 -1
- package/dist/worker/loader.js +7 -0
- package/dist/worker/loader.js.map +1 -0
- package/dist/worker/worker.js +112 -0
- package/dist/worker/worker.js.map +1 -0
- package/package.json +109 -111
- package/patches/react-server-dom-esm+0.0.1.patch +13424 -0
- package/scripts/bump-version.mjs +68 -0
- package/scripts/check-react-version.mjs +48 -0
- package/src/assertServerCondition.ts +13 -0
- package/src/build/createBuildConfig.ts +27 -44
- package/src/build/mergeInputs.ts +42 -0
- package/src/helpers/inputNormalizer.ts +22 -0
- package/src/helpers/normalizedRelativePath.ts +25 -25
- package/src/helpers/tryManifest.ts +19 -5
- package/src/html/createPageLoader.ts +2 -0
- package/src/options.ts +119 -47
- package/src/plugin.ts +4 -30
- package/src/react-server/createSsrHandler.ts +1 -1
- package/src/react-server/plugin.ts +116 -56
- package/src/types.ts +19 -1
- package/src/worker/createWorker.ts +12 -7
- package/tsconfig.json +2 -0
- package/dist/build/createBuildConfig.js +0 -55
- package/dist/build/createBuildConfig.js.map +0 -1
- package/dist/checkFilesExist.js.map +0 -1
- package/dist/collect-css-manifest.js.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/getEnv.js.map +0 -1
- package/dist/helpers/normalizedRelativePath.js +0 -31
- package/dist/helpers/normalizedRelativePath.js.map +0 -1
- package/dist/html/createPageLoader.js.map +0 -1
- package/dist/options.js.map +0 -1
- package/dist/plugin.js +0 -31
- package/dist/plugin.js.map +0 -1
- package/dist/react-server/createHandler.js.map +0 -1
- package/dist/react-server/createRscStream.js.map +0 -1
- package/dist/resolvePage.js.map +0 -1
- package/dist/resolveProps.js.map +0 -1
- package/dist/transformer/index.js +0 -54
- package/dist/transformer/index.js.map +0 -1
- package/dist/transformer/preserveDirectives.js +0 -72
- package/dist/transformer/preserveDirectives.js.map +0 -1
- package/dist/transformer/transformer.js +0 -80
- package/dist/transformer/transformer.js.map +0 -1
- package/dist/worker/createWorker.js.map +0 -1
- package/dist/worker/renderPages.js.map +0 -1
- /package/dist/{checkFilesExist.js → src/checkFilesExist.js} +0 -0
- /package/dist/{collect-css-manifest.js → src/collect-css-manifest.js} +0 -0
- /package/dist/{components.js → src/components.js} +0 -0
- /package/dist/{getEnv.js → src/getEnv.js} +0 -0
- /package/dist/{react-server → src/react-server}/createHandler.js +0 -0
- /package/dist/{react-server → src/react-server}/createRscStream.js +0 -0
- /package/dist/{resolvePage.js → src/resolvePage.js} +0 -0
- /package/dist/{resolveProps.js → src/resolveProps.js} +0 -0
- /package/dist/{worker → src/worker}/renderPages.js +0 -0
package/tsconfig.json
CHANGED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { dirname, resolve } from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { DEFAULT_CONFIG } from "../options.js";
|
|
4
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
|
-
function createBuildConfig({
|
|
6
|
-
root,
|
|
7
|
-
base,
|
|
8
|
-
outDir,
|
|
9
|
-
entries,
|
|
10
|
-
options
|
|
11
|
-
}) {
|
|
12
|
-
const entryInputs = Object.fromEntries(
|
|
13
|
-
entries.map((entry) => {
|
|
14
|
-
const relativePath = entry.replace(root + "/", "");
|
|
15
|
-
const key = relativePath.replace(/\.[^/.]+$/, "");
|
|
16
|
-
return [key, entry];
|
|
17
|
-
})
|
|
18
|
-
);
|
|
19
|
-
const workerPath = options?.workerPath ? resolve(root, options.workerPath) : resolve(__dirname, "..", DEFAULT_CONFIG.WORKER_PATH);
|
|
20
|
-
const loaderPath = options?.loaderPath ? resolve(root, options.loaderPath) : resolve(__dirname, "..", DEFAULT_CONFIG.LOADER_PATH);
|
|
21
|
-
const config = {
|
|
22
|
-
configFile: false,
|
|
23
|
-
root,
|
|
24
|
-
base,
|
|
25
|
-
build: {
|
|
26
|
-
target: "node18",
|
|
27
|
-
ssr: true,
|
|
28
|
-
ssrEmitAssets: false,
|
|
29
|
-
manifest: true,
|
|
30
|
-
ssrManifest: true,
|
|
31
|
-
outDir,
|
|
32
|
-
rollupOptions: {
|
|
33
|
-
input: {
|
|
34
|
-
...entryInputs,
|
|
35
|
-
worker: workerPath,
|
|
36
|
-
loader: loaderPath
|
|
37
|
-
},
|
|
38
|
-
output: {
|
|
39
|
-
format: "esm",
|
|
40
|
-
preserveModules: true,
|
|
41
|
-
hoistTransitiveImports: false,
|
|
42
|
-
esModule: true,
|
|
43
|
-
entryFileNames: "[name].js",
|
|
44
|
-
chunkFileNames: "[name].js",
|
|
45
|
-
assetFileNames: "[name][extname]"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return config;
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
createBuildConfig
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=createBuildConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildConfig.js","sources":["../../src/build/createBuildConfig.ts"],"sourcesContent":["import { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { InlineConfig } from \"vite\";\nimport { DEFAULT_CONFIG } from \"../options.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\ntype CreateBuildConfigOptions = {\n root: string;\n base: string;\n outDir: string;\n entries: string[];\n options?: StreamPluginOptions;\n};\n\nexport function createBuildConfig({\n root,\n base,\n outDir,\n entries,\n options,\n}: CreateBuildConfigOptions) {\n // Transform entries into proper input format with unique keys\n const entryInputs = Object.fromEntries(\n entries.map((entry) => {\n // Get the path relative to root\n const relativePath = entry.replace(root + \"/\", \"\");\n // Create a unique key based on the full path\n const key = relativePath.replace(/\\.[^/.]+$/, \"\"); // Remove extension\n\n return [key, entry];\n })\n );\n\n const workerPath = options?.workerPath\n ? resolve(root, options.workerPath)\n : resolve(__dirname, \"..\", DEFAULT_CONFIG.WORKER_PATH);\n\n const loaderPath = options?.loaderPath\n ? resolve(root, options.loaderPath)\n : resolve(__dirname, \"..\", DEFAULT_CONFIG.LOADER_PATH);\n\n const config: InlineConfig = {\n configFile: false,\n root,\n base,\n build: {\n target: \"node18\",\n ssr: true,\n ssrEmitAssets: false,\n manifest: true,\n ssrManifest: true,\n outDir,\n rollupOptions: {\n input: {\n ...entryInputs,\n worker: workerPath,\n loader: loaderPath,\n },\n output: {\n format: \"esm\",\n preserveModules: true,\n hoistTransitiveImports: false,\n esModule: true,\n entryFileNames: \"[name].js\",\n chunkFileNames: \"[name].js\",\n assetFileNames: \"[name][extname]\",\n },\n },\n },\n };\n\n return config;\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAUjD,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA6B;AAE3B,QAAM,cAAc,OAAO;AAAA,IACzB,QAAQ,IAAI,CAAC,UAAU;AAErB,YAAM,eAAe,MAAM,QAAQ,OAAO,KAAK,EAAE;AAEjD,YAAM,MAAM,aAAa,QAAQ,aAAa,EAAE;AAEzC,aAAA,CAAC,KAAK,KAAK;AAAA,IACnB,CAAA;AAAA,EACH;AAEA,QAAM,aAAa,SAAS,aACxB,QAAQ,MAAM,QAAQ,UAAU,IAChC,QAAQ,WAAW,MAAM,eAAe,WAAW;AAEvD,QAAM,aAAa,SAAS,aACxB,QAAQ,MAAM,QAAQ,UAAU,IAChC,QAAQ,WAAW,MAAM,eAAe,WAAW;AAEvD,QAAM,SAAuB;AAAA,IAC3B,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,KAAK;AAAA,MACL,eAAe;AAAA,MACf,UAAU;AAAA,MACV,aAAa;AAAA,MACb;AAAA,MACA,eAAe;AAAA,QACb,OAAO;AAAA,UACL,GAAG;AAAA,UACH,QAAQ;AAAA,UACR,QAAQ;AAAA,QACV;AAAA,QACA,QAAQ;AAAA,UACN,QAAQ;AAAA,UACR,iBAAiB;AAAA,UACjB,wBAAwB;AAAA,UACxB,UAAU;AAAA,UACV,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,QAAA;AAAA,MAClB;AAAA,IACF;AAAA,EAEJ;AAEO,SAAA;AACT;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkFilesExist.js","sources":["../src/checkFilesExist.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { StreamPluginOptions } from \"./types.js\";\n\nexport async function checkFilesExist(\n pages: string[],\n options: Pick<StreamPluginOptions, \"Page\" | \"props\">,\n root: string\n) {\n const errors: string[] = [];\n const pageSet = new Set<string>();\n const pageMap = new Map<string, string>();\n // Check if files exist when string paths are provided\n if (typeof options.Page === \"string\") {\n const pagePath = resolve(root, options.Page);\n pageMap.set(options.Page, pagePath);\n if (!pageSet.has(pagePath)) {\n if (!existsSync(pagePath)) {\n errors.push(`Page file not found: ${pagePath}`);\n }\n pageSet.add(pagePath);\n }\n } else if (typeof options.Page === \"function\" && pages) {\n for (const page of pages) {\n const pagePath = options.Page(resolve(root, page));\n pageMap.set(page, pagePath);\n if (pageSet.has(pagePath)) {\n continue;\n }\n if (!existsSync(pagePath)) {\n errors.push(`Page file not found: ${pagePath}`);\n }\n pageSet.add(pagePath);\n }\n }\n\n const propsSet = new Set<string>();\n const propsMap = new Map<string, string>();\n if (typeof options.props === \"string\") {\n const propsPath = resolve(root, options.props);\n propsMap.set(options.props, propsPath);\n if (!propsSet.has(propsPath)) {\n if (!existsSync(propsPath)) {\n errors.push(`Props file not found: ${propsPath}`);\n }\n propsSet.add(propsPath);\n }\n } else if (typeof options.props === \"function\" && pages) {\n for (const page of pages) {\n const propsPath = options.props(resolve(root, page));\n propsMap.set(page, propsPath);\n if (propsSet.has(propsPath)) {\n continue;\n }\n if (!existsSync(propsPath)) {\n errors.push(`Props file not found: ${propsPath}`);\n }\n propsSet.add(propsPath);\n }\n }\n\n if (errors.length) {\n throw new Error(\"React Stream Plugin Validation:\\n\" + errors.join(\"\\n\"));\n }\n\n return { pageMap, pageSet, propsMap, propsSet };\n}\n"],"names":[],"mappings":";;AAIsB,eAAA,gBACpB,OACA,SACA,MACA;AACA,QAAM,SAAmB,CAAC;AACpB,QAAA,8BAAc,IAAY;AAC1B,QAAA,8BAAc,IAAoB;AAEpC,MAAA,OAAO,QAAQ,SAAS,UAAU;AACpC,UAAM,WAAW,QAAQ,MAAM,QAAQ,IAAI;AACnC,YAAA,IAAI,QAAQ,MAAM,QAAQ;AAClC,QAAI,CAAC,QAAQ,IAAI,QAAQ,GAAG;AACtB,UAAA,CAAC,WAAW,QAAQ,GAAG;AAClB,eAAA,KAAK,wBAAwB,QAAQ,EAAE;AAAA,MAAA;AAEhD,cAAQ,IAAI,QAAQ;AAAA,IAAA;AAAA,EAEb,WAAA,OAAO,QAAQ,SAAS,cAAc,OAAO;AACtD,eAAW,QAAQ,OAAO;AACxB,YAAM,WAAW,QAAQ,KAAK,QAAQ,MAAM,IAAI,CAAC;AACzC,cAAA,IAAI,MAAM,QAAQ;AACtB,UAAA,QAAQ,IAAI,QAAQ,GAAG;AACzB;AAAA,MAAA;AAEE,UAAA,CAAC,WAAW,QAAQ,GAAG;AAClB,eAAA,KAAK,wBAAwB,QAAQ,EAAE;AAAA,MAAA;AAEhD,cAAQ,IAAI,QAAQ;AAAA,IAAA;AAAA,EACtB;AAGI,QAAA,+BAAe,IAAY;AAC3B,QAAA,+BAAe,IAAoB;AACrC,MAAA,OAAO,QAAQ,UAAU,UAAU;AACrC,UAAM,YAAY,QAAQ,MAAM,QAAQ,KAAK;AACpC,aAAA,IAAI,QAAQ,OAAO,SAAS;AACrC,QAAI,CAAC,SAAS,IAAI,SAAS,GAAG;AACxB,UAAA,CAAC,WAAW,SAAS,GAAG;AACnB,eAAA,KAAK,yBAAyB,SAAS,EAAE;AAAA,MAAA;AAElD,eAAS,IAAI,SAAS;AAAA,IAAA;AAAA,EAEf,WAAA,OAAO,QAAQ,UAAU,cAAc,OAAO;AACvD,eAAW,QAAQ,OAAO;AACxB,YAAM,YAAY,QAAQ,MAAM,QAAQ,MAAM,IAAI,CAAC;AAC1C,eAAA,IAAI,MAAM,SAAS;AACxB,UAAA,SAAS,IAAI,SAAS,GAAG;AAC3B;AAAA,MAAA;AAEE,UAAA,CAAC,WAAW,SAAS,GAAG;AACnB,eAAA,KAAK,yBAAyB,SAAS,EAAE;AAAA,MAAA;AAElD,eAAS,IAAI,SAAS;AAAA,IAAA;AAAA,EACxB;AAGF,MAAI,OAAO,QAAQ;AACjB,UAAM,IAAI,MAAM,sCAAsC,OAAO,KAAK,IAAI,CAAC;AAAA,EAAA;AAGzE,SAAO,EAAE,SAAS,SAAS,UAAU,SAAS;AAChD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collect-css-manifest.js","sources":["../src/collect-css-manifest.ts"],"sourcesContent":["import type { Manifest, ModuleGraph } from \"vite\";\n\nexport async function collectModuleGraphCss(\n moduleGraph: ModuleGraph,\n pagePath: string\n) {\n if (!pagePath) return new Map<string, string>();\n\n const cssFiles = new Map<string, string>();\n const pageModule = await moduleGraph.getModuleByUrl(pagePath, true);\n if (!pageModule) {\n return new Map<string, string>();\n }\n const seen = new Set<string>();\n const walkModule = (mod: any) => {\n if (!mod?.id || seen.has(mod.id)) return;\n seen.add(mod.id);\n if (mod?.id?.endsWith(\".css\")) {\n cssFiles.set(mod?.url, mod?.id);\n }\n mod?.importedModules?.forEach((imp: any) => walkModule(imp));\n };\n walkModule(pageModule);\n return cssFiles;\n}\n\nexport function collectManifestCss(\n manifest: Manifest,\n root: string,\n pagePath: string,\n onCss?: (path: string) => void\n) {\n const relativePagePath = pagePath.startsWith(root + \"/\")\n ? pagePath.slice(root.length + 1)\n : pagePath;\n if (!relativePagePath) return new Map<string, string>();\n const cssFiles = new Map<string, string>();\n const seen = new Set<string>();\n\n const walkManifestEntry = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n if (id.endsWith(\".css\")) {\n cssFiles.set(id, id);\n onCss?.(id);\n return;\n }\n // Get the manifest entry\n const entry = manifest[id];\n if (!entry) return;\n\n // Add direct CSS\n if (entry.css) {\n entry.css.forEach((css: string) => {\n cssFiles.set(entry.file, css);\n onCss?.(css);\n });\n }\n\n // Walk imports recursively\n if (entry.imports) {\n entry.imports.forEach((imp: string) => walkManifestEntry(imp));\n }\n\n // Also check dynamicImports\n if (entry.dynamicImports) {\n entry.dynamicImports.forEach((imp: string) => walkManifestEntry(imp));\n }\n };\n\n if (manifest[relativePagePath]) {\n walkManifestEntry(relativePagePath);\n }\n\n return cssFiles;\n}\n"],"names":[],"mappings":"AAEsB,eAAA,sBACpB,aACA,UACA;AACA,MAAI,CAAC,SAAiB,QAAA,oBAAI,IAAoB;AAExC,QAAA,+BAAe,IAAoB;AACzC,QAAM,aAAa,MAAM,YAAY,eAAe,UAAU,IAAI;AAClE,MAAI,CAAC,YAAY;AACf,+BAAW,IAAoB;AAAA,EAAA;AAE3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AAAA,EAAA;AAG7B,SAAA;AACT;"}
|
package/dist/components.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../src/components.tsx"],"sourcesContent":["import { createElement } from 'react';\n\n/**\n * A component that emits <link> tags for CSS files during streaming.\n * The high precedence ensures they bubble up to the document head.\n */\nexport function CssCollector({ url }: { url: string }) {\n return createElement('link', {\n key: url,\n rel: 'stylesheet',\n href: url,\n precedence: 'high'\n });\n} "],"names":[],"mappings":";AAMgB,SAAA,aAAa,EAAE,OAAwB;AACrD,SAAO,cAAc,QAAQ;AAAA,IAC3B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,EAAA,CACb;AACH;"}
|
package/dist/getEnv.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getEnv.js","sources":["../src/getEnv.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { ConfigEnv, UserConfig } from \"vite\";\nimport { loadEnv } from \"vite\";\nimport { DEFAULT_CONFIG } from \"./options.js\";\n\n/**\n * Get environment variables for Vite, sets defaults to ensure the server can start with BASE_URL and PUBLIC_URL\n *\n * @param config - Vite configuration object\n * @param { isPreview: boolean } - Object containing a boolean indicating if the environment is for preview\n * @returns An object containing the environment variables\n */\nexport function getEnv(config: UserConfig, configEnv: ConfigEnv) {\n const isLocal =\n config.mode === \"development\"\n\n const envName = isLocal\n ? `${config.mode}.local`\n : config.mode\n ? config.mode\n : \"production\";\n const environmentName = config.mode ?? envName ?? \"production\";\n\n const env = loadEnv(\n environmentName,\n config.envDir ?? config.root ?? process.cwd(),\n config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX ?? \"VITE_\"\n );\n\n // Get server config\n const serverConfig = config.server || {};\n const previewConfig = config.preview || {};\n const host = configEnv.isPreview\n ? previewConfig.host ?? DEFAULT_CONFIG.PREVIEW_HOST\n : serverConfig.host ?? DEFAULT_CONFIG.DEV_HOST;\n let previewPort = previewConfig.port ?? DEFAULT_CONFIG.PREVIEW_PORT;\n let devPort = serverConfig.port ?? DEFAULT_CONFIG.DEV_PORT;\n\n let homepage = env[\"VITE_BASE_URL\"]\n if (configEnv.command === \"build\" && (!homepage || homepage === \"\")) {\n try {\n const packageJson = JSON.parse(\n readFileSync(resolve(config.root ?? \"\", \"package.json\"), \"utf-8\")\n );\n homepage = packageJson.homepage ?? \"\";\n if (!homepage || homepage === \"\") {\n console.warn(\n \"[RSC] 🔧 For production builds, please set 'homepage' in package.json, or set VITE_BASE_URL in your environment\"\n );\n }\n } catch (e) {\n console.error(e);\n }\n }\n\n let baseUrl =\n env[\"VITE_BASE_URL\"] && env[\"VITE_PUBLIC_URL\"] !== \"\"\n ? env[\"VITE_BASE_URL\"]\n : configEnv.isPreview\n ? `http://${host}:${previewPort}`\n : configEnv.command === \"serve\"\n ? `http://${host}:${devPort}`\n : homepage;\n\n let publicUrl =\n env[\"VITE_PUBLIC_URL\"] && env[\"VITE_PUBLIC_URL\"] !== \"\"\n ? env[\"VITE_PUBLIC_URL\"]\n : \"\";\n\n // Determine port and host based on mode\n const port = configEnv.isPreview\n ? previewConfig.port || DEFAULT_CONFIG.PREVIEW_PORT // Preview server\n : serverConfig.port || DEFAULT_CONFIG.DEV_PORT; // Dev server\n\n // Build base URL\n if (configEnv.isPreview && `http://${host}:${port}` !== baseUrl) {\n console.log(\n `VITE_BASE_URL: \\\"${baseUrl}\\\" wasn't configured correctly for this server, overriding to: \\\"http://${host}:${port}\\\"`\n );\n baseUrl = `http://${host}:${port}`;\n }\n\n const envPrefix =\n typeof config.envPrefix === \"string\"\n ? config.envPrefix\n : Array.isArray(config.envPrefix)\n ? config.envPrefix[0]\n : DEFAULT_CONFIG.ENV_PREFIX;\n\n const nodeProcessEnv = {\n NODE_ENV: configEnv.command === \"build\" ? \"production\" : \"development\",\n };\n const defineProcess = Object.entries(nodeProcessEnv)\n .map(([key, value]) => {\n switch (key) {\n case \"NODE_ENV\":\n const isDev =\n value === \"\"\n ? configEnv.command === \"build\"\n ? false\n : true\n : value === \"development\";\n return [`import.meta.env.DEV`, JSON.stringify(isDev)];\n default:\n return null;\n }\n })\n .filter(Array.isArray);\n\n const defineImportMeta = Object.entries(env).map(([key, value]) => [\n `import.meta.env.${key}`,\n key === \"VITE_BASE_URL\"\n ? value\n ? JSON.stringify(value)\n : JSON.stringify(baseUrl)\n : key === \"VITE_PUBLIC_URL\"\n ? value\n ? JSON.stringify(value)\n : JSON.stringify(publicUrl)\n : JSON.stringify(value),\n ]);\n const define = Object.fromEntries([...defineProcess, ...defineImportMeta]);\n\n return {\n baseUrl,\n publicUrl,\n port,\n host,\n envPrefix,\n environmentName,\n env,\n define,\n };\n}\n"],"names":[],"mappings":";;;;AAagB,SAAA,OAAO,QAAoB,WAAsB;AACzD,QAAA,UACJ,OAAO,SAAS;AAEZ,QAAA,UAAU,UACZ,GAAG,OAAO,IAAI,WACd,OAAO,OACP,OAAO,OACP;AACE,QAAA,kBAAkB,OAAO,QAAQ,WAAW;AAElD,QAAM,MAAM;AAAA,IACV;AAAA,IACA,OAAO,UAAU,OAAO,QAAQ,QAAQ,IAAI;AAAA,IAC5C,OAAO,aAAa,eAAe,cAAc;AAAA,EACnD;AAGM,QAAA,eAAe,OAAO,UAAU,CAAC;AACjC,QAAA,gBAAgB,OAAO,WAAW,CAAC;AACnC,QAAA,OAAO,UAAU,YACnB,cAAc,QAAQ,eAAe,eACrC,aAAa,QAAQ,eAAe;AACpC,MAAA,cAAc,cAAc,QAAQ,eAAe;AACnD,MAAA,UAAU,aAAa,QAAQ,eAAe;AAE9C,MAAA,WAAW,IAAI,eAAe;AAClC,MAAI,UAAU,YAAY,YAAY,CAAC,YAAY,aAAa,KAAK;AAC/D,QAAA;AACF,YAAM,cAAc,KAAK;AAAA,QACvB,aAAa,QAAQ,OAAO,QAAQ,IAAI,cAAc,GAAG,OAAO;AAAA,MAClE;AACA,iBAAW,YAA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KAAK,KAAK,MAAM;AAAA,IACjE,mBAAmB,GAAG;AAAA,IACtB,QAAQ,kBACJ,QACE,KAAK,UAAU,KAAK,IACpB,KAAK,UAAU,OAAO,IACxB,QAAQ,oBACR,QACE,KAAK,UAAU,KAAK,IACpB,KAAK,UAAU,SAAS,IAC1B,KAAK,UAAU,KAAK;AAAA,EAAA,CACzB;AACK,QAAA,SAAS,OAAO,YAAY,CAAC,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAElE,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from "vite";
|
|
2
|
-
const createNormalizedRelativePath = (options = {
|
|
3
|
-
root: process.cwd(),
|
|
4
|
-
outDir: ["dist", "build"],
|
|
5
|
-
moduleBase: "src",
|
|
6
|
-
noLeadingSlash: false
|
|
7
|
-
}) => {
|
|
8
|
-
const base = options.noLeadingSlash && options.moduleBase.startsWith("/") ? options.moduleBase.slice(1) : options.moduleBase;
|
|
9
|
-
const removeOutDir = Array.isArray(options.outDir) ? (path) => options.outDir.map((dir) => path.startsWith(dir)).some((v) => v) ? path.slice(options.outDir[0].length) : path : (path) => options.outDir === path ? path.slice(options.outDir.length) : path;
|
|
10
|
-
const removeRoot = (path) => {
|
|
11
|
-
const normalized = normalizePath(path);
|
|
12
|
-
const relative = normalized.startsWith(options.root) ? normalized.slice(options.root.length) : normalized;
|
|
13
|
-
return relative;
|
|
14
|
-
};
|
|
15
|
-
const ensureModuleBase = (path) => {
|
|
16
|
-
if (options.noLeadingSlash && path.startsWith("/")) {
|
|
17
|
-
return path.slice(1);
|
|
18
|
-
}
|
|
19
|
-
if (!path.startsWith(base)) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Path ${path} does not start with module base ${base}, this will not work down the line.`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return path;
|
|
25
|
-
};
|
|
26
|
-
return (path) => ensureModuleBase(removeOutDir(removeRoot(path)));
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
createNormalizedRelativePath
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=normalizedRelativePath.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizedRelativePath.js","sources":["../../src/helpers/normalizedRelativePath.ts"],"sourcesContent":["import { normalizePath } from \"vite\";\n\ntype NormalizedRelativePathOptions = {\n // will automatically remove this part\n root: string;\n // will automatically see this as a optional extra part of the rootDir that will be removed\n outDir: string | string[];\n // will ensure it always starts with this path, if it does not it will be added\n moduleBase: string;\n // will ensure it never starts with a leading /, which in some cases is needed (vite entry), other cases it is not for example from project root /\n noLeadingSlash: boolean;\n};\n\nexport const createNormalizedRelativePath = (\n options: NormalizedRelativePathOptions = {\n root: process.cwd(),\n outDir: [\"dist\", \"build\"],\n moduleBase: \"src\",\n noLeadingSlash: false,\n }\n) => {\n const base =\n options.noLeadingSlash && options.moduleBase.startsWith(\"/\")\n ? options.moduleBase.slice(1)\n : options.moduleBase;\n const removeOutDir = Array.isArray(options.outDir)\n ? (path: string) =>\n (options.outDir as string[])\n .map((dir) => path.startsWith(dir))\n .some((v) => v)\n ? path.slice(options.outDir[0].length)\n : path\n : (path: string) =>\n (options.outDir as string) === path\n ? path.slice(options.outDir.length)\n : path;\n\n const removeRoot = (path: string) => {\n const normalized = normalizePath(path);\n const relative = normalized.startsWith(options.root)\n ? normalized.slice(options.root.length)\n : normalized;\n return relative;\n };\n\n const ensureModuleBase = (path: string) => {\n if (options.noLeadingSlash && path.startsWith(\"/\")) {\n return path.slice(1);\n }\n if (!path.startsWith(base)) {\n throw new Error(\n `Path ${path} does not start with module base ${base}, this will not work down the line.`\n );\n }\n return path;\n };\n\n return (path: string) => ensureModuleBase(removeOutDir(removeRoot(path)));\n};\n"],"names":[],"mappings":";AAaa,MAAA,+BAA+B,CAC1C,UAAyC;AAAA,EACvC,MAAM,QAAQ,IAAI;AAAA,EAClB,QAAQ,CAAC,QAAQ,OAAO;AAAA,EACxB,YAAY;AAAA,EACZ,gBAAgB;AAClB,MACG;AACH,QAAM,OACJ,QAAQ,kBAAkB,QAAQ,WAAW,WAAW,GAAG,IACvD,QAAQ,WAAW,MAAM,CAAC,IAC1B,QAAQ;AACd,QAAM,eAAe,MAAM,QAAQ,QAAQ,MAAM,IAC7C,CAAC,SACE,QAAQ,OACN,IAAI,CAAC,QAAQ,KAAK,WAAW,GAAG,CAAC,EACjC,KAAK,CAAC,MAAM,CAAC,IACZ,KAAK,MAAM,QAAQ,OAAO,CAAC,EAAE,MAAM,IACnC,OACN,CAAC,SACE,QAAQ,WAAsB,OAC3B,KAAK,MAAM,QAAQ,OAAO,MAAM,IAChC;AAEJ,QAAA,aAAa,CAAC,SAAiB;AAC7B,UAAA,aAAa,cAAc,IAAI;AAC/B,UAAA,WAAW,WAAW,WAAW,QAAQ,IAAI,IAC/C,WAAW,MAAM,QAAQ,KAAK,MAAM,IACpC;AACG,WAAA;AAAA,EACT;AAEM,QAAA,mBAAmB,CAAC,SAAiB;AACzC,QAAI,QAAQ,kBAAkB,KAAK,WAAW,GAAG,GAAG;AAC3C,aAAA,KAAK,MAAM,CAAC;AAAA,IAAA;AAErB,QAAI,CAAC,KAAK,WAAW,IAAI,GAAG;AAC1B,YAAM,IAAI;AAAA,QACR,QAAQ,IAAI,oCAAoC,IAAI;AAAA,MACtD;AAAA,IAAA;AAEK,WAAA;AAAA,EACT;AAEA,SAAO,CAAC,SAAiB,iBAAiB,aAAa,WAAW,IAAI,CAAC,CAAC;AAC1E;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createPageLoader.js","sources":["../../src/html/createPageLoader.ts"],"sourcesContent":["import { resolve as resolvePath } from \"node:path\";\nimport { load } from \"react-server-dom-esm/node-loader\";\nimport {\n registerClientReference,\n registerServerReference,\n} from \"react-server-dom-esm/server.node\";\nimport { createNormalizedRelativePath } from \"../helpers/normalizedRelativePath.js\";\n\ntype CreatePageLoaderOptions = {\n manifest: Record<string, { file: string }>;\n root: string;\n outDir: string;\n moduleBase: string;\n registerServer?: string[];\n registerClient?: string[];\n alwaysRegisterServer?: boolean;\n alwaysRegisterClient?: boolean;\n};\n\ntype CreateDefaultLoaderOptions = {\n id: string;\n registerServer?: string[];\n registerClient?: string[];\n alwaysRegisterServer?: boolean;\n alwaysRegisterClient?: boolean;\n};\n\nexport const createDefaultLoader = ({\n id,\n registerServer,\n registerClient,\n alwaysRegisterServer = false,\n alwaysRegisterClient = false,\n}: CreateDefaultLoaderOptions) => {\n const mapper = ([key, value]: [string, any]) => {\n try {\n if (\n registerClient?.includes(key) ||\n (alwaysRegisterClient && typeof value === \"function\")\n ) {\n return [key, registerClientReference(value, id, key)];\n }\n if (\n registerServer?.includes(key) ||\n (alwaysRegisterServer && typeof value === \"function\")\n ) {\n return [key, registerServerReference(value, id, key)];\n }\n return [key, value];\n } catch (e) {\n console.error(\"[RSC] Error registering reference:\", key, value, e);\n return [key, value];\n }\n };\n return async (url: string) =>\n Object.fromEntries(Object.entries(await import(url)).map(mapper));\n};\n\nexport const createPageLoader = ({\n manifest,\n root,\n outDir,\n moduleBase,\n registerServer,\n registerClient,\n alwaysRegisterServer,\n alwaysRegisterClient,\n}: CreatePageLoaderOptions) => {\n const pathNormalizer = createNormalizedRelativePath({\n root,\n outDir,\n moduleBase,\n noLeadingSlash: true,\n });\n return async (id: string) => {\n const normalizedId = pathNormalizer(id);\n const entry =\n normalizedId in manifest\n ? manifest[normalizedId]\n : Object.values(manifest).find((entry) => entry.file === normalizedId);\n if (!entry) {\n throw new Error(\n `Could not find manifest entry for ${id}, ${normalizedId} from ${root}`\n );\n }\n const loaderResult = await load(\n resolvePath(root, outDir, entry.file),\n { format: \"module\" },\n createDefaultLoader({\n id,\n registerServer,\n registerClient,\n alwaysRegisterServer,\n alwaysRegisterClient,\n })\n );\n return loaderResult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,IAAA;AAEF,UAAM,eAAe,MAAM;AAAA,MACzBC,QAAY,MAAM,QAAQ,MAAM,IAAI;AAAA,MACpC,EAAE,QAAQ,SAAS;AAAA,MACnB,oBAAoB;AAAA,QAClB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD,CAAA;AAAA,IACH;AACO,WAAA;AAAA,EACT;AACF;"}
|
package/dist/options.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sources":["../src/options.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { ConfigEnv, ResolvedConfig, UserConfig } from \"vite\";\nimport type { ResolvedUserOptions, StreamPluginOptions } from \"./types.js\";\n// Default configuration values\nexport const DEFAULT_CONFIG = {\n FILE_REGEX: /\\.(m|c)?(j|t)sx?$/,\n CLIENT_ASSETS_DIR: \"assets\",\n RSC_DIR: \"rsc\",\n MODULE_BASE: \"src\",\n MODULE_BASE_PATH: \"/src\",\n MODULE_BASE_URL: \"/src\",\n PAGE: \"/src/page/page.tsx\",\n PROPS: \"/src/page/props.ts\",\n CLIENT_ENTRY: \"/src/client.tsx\",\n PAGE_EXPORT: \"Page\",\n PROPS_EXPORT: \"props\",\n // relative from plugin root\n WORKER_PATH: \"worker/worker.tsx\",\n LOADER_PATH: \"worker/loader.ts\",\n RSC_EXTENSION: \".rsc\",\n HTML: ({ children }: { children: any }) => children,\n COLLECT_CSS: true,\n COLLECT_ASSETS: true,\n PAGE_PATTERN: \"/src/page/**/*.page.tsx\",\n PROPS_PATTERN: \"/src/page/**/*.props.ts\",\n DEV_PORT: 5173,\n PREVIEW_PORT: 4173,\n DEV_HOST: \"localhost\",\n PREVIEW_HOST: \"localhost\",\n ENV_PREFIX: \"VITE_\",\n BUILD: {\n pages: () => [\"/\"],\n client: \"dist/client\",\n server: \"dist/server\",\n },\n} as const;\n\nexport const resolveConfig = <T extends ResolvedConfig>(\n config: T,\n resolvedUserConfig: UserConfig,\n userOptions: ResolvedUserOptions\n) => {\n return {\n ...config,\n build: {\n ...config.build,\n assetsDir: config.build?.assetsDir ?? DEFAULT_CONFIG.CLIENT_ASSETS_DIR,\n },\n };\n};\n\nexport const resolveUserConfig = (\n condition: \"react-client\" | \"react-server\",\n input: string[],\n config: UserConfig,\n configEnv: ConfigEnv,\n userOptions: ResolvedUserOptions\n):\n | { type: \"error\"; error: Error }\n | {\n type: \"success\";\n userConfig: Required<Pick<UserConfig, \"root\" | \"build\" | \"mode\">> &\n Omit<UserConfig, \"root\" | \"build\" | \"mode\">;\n } => {\n const isReactServer = condition === \"react-server\";\n const isViteServer = configEnv.command === \"serve\";\n const isVitePreview = configEnv.isPreview;\n\n if (isReactServer && configEnv.command === \"build\") {\n if (!config.build?.rollupOptions?.input) {\n config = {\n ...config,\n build: {\n ...config.build,\n rollupOptions: {\n ...config.build?.rollupOptions,\n input: input\n }\n }\n }\n }\n }\n\n if (typeof config.build?.assetsDir === 'string' && userOptions.assetsDir !== config.build?.assetsDir) {\n return {\n type: \"error\",\n error: new Error(\n `assetsDir cannot be changed after the config has been resolved, before: ${userOptions.assetsDir}, after: ${config.build?.assetsDir}`\n ),\n };\n }\n\n if (isReactServer) {\n if (configEnv.command === \"build\") {\n if (!configEnv.isSsrBuild) {\n return {\n type: \"error\",\n error: new Error(\n \"ssr must be true when using the server plugin, NODE_OPTIONS='--conditions react-server' vite build --ssr\"\n ),\n };\n }\n } else if (!isViteServer) {\n return {\n type: \"error\",\n error: new Error(\n isViteServer\n ? `react-server condition was not set. Please use \\`NODE_OPTIONS='--conditions react-server' vite${\n isVitePreview ? \" preview\" : \"\"\n }\\``\n : \"react-server condition was not set. Please use `NODE_OPTIONS='--conditions react-server' vite build --ssr`\"\n ),\n };\n } else if (!configEnv.isSsrBuild && configEnv.command !== 'serve') {\n return {\n type: \"error\",\n error: new Error(\n \"Vite was run with the react-server condition, but is making a client build.\"\n ),\n };\n }\n }\n\n const { root: configRoot, mode: configMode, ...configRest } = config;\n const { outDir: configOutDir, assetsDir: configAssetsDir, ssr: configSsr, manifest: configManifest, ssrManifest: configSsrManifest, target: configTarget, ...configBuildRest } = config.build ?? {};\n\n return {\n type: \"success\",\n userConfig: {\n ...configRest,\n root: configRoot ?? userOptions.projectRoot ?? process.cwd(),\n mode: configMode ?? process.env[\"NODE_ENV\"] ?? \"production\",\n build: {\n ...configBuildRest,\n ssr: configSsr ?? isReactServer,\n manifest: configManifest ?? true,\n ssrManifest: configSsrManifest ?? true,\n target: configTarget ?? \"es2020\",\n outDir:\n typeof configOutDir === \"string\"\n ? configOutDir\n : isReactServer\n ? userOptions.build.server\n : userOptions.build.client,\n assetsDir:\n typeof configAssetsDir === \"string\"\n ? configAssetsDir\n : isReactServer\n ? ''\n : DEFAULT_CONFIG.CLIENT_ASSETS_DIR,\n },\n },\n };\n};\n\nexport const resolveOptions = (\n options: StreamPluginOptions\n):\n | { type: \"error\"; error: Error }\n | {\n type: \"success\";\n userOptions: ResolvedUserOptions;\n } => {\n const projectRoot = options.projectRoot ?? process.cwd();\n /** the module base can be assumed to not have a leading slash */\n const moduleBase =\n typeof options.moduleBase === \"string\"\n ? options.moduleBase.startsWith(path.sep)\n ? options.moduleBase.slice(path.sep.length)\n : options.moduleBase\n : DEFAULT_CONFIG.MODULE_BASE;\n\n if (\n typeof options.moduleBase === \"string\" &&\n options.moduleBase !== moduleBase\n ) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBase ${options.moduleBase} is invalid, should be like ${moduleBase}`\n ),\n };\n }\n\n const moduleBasePath =\n typeof options.moduleBasePath === \"string\"\n ? !options.moduleBasePath.startsWith(path.sep)\n ? `${path.sep}${options.moduleBasePath}`\n : options.moduleBasePath\n : `${path.sep}${moduleBase}`;\n\n if (!moduleBasePath.includes(moduleBase)) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBasePath ${moduleBasePath} is invalid, should include moduleBase ${moduleBase}`\n ),\n };\n }\n\n const moduleBaseURL =\n typeof options.moduleBaseURL === \"string\"\n ? !options.moduleBaseURL.endsWith(moduleBasePath)\n ? path.join(options.moduleBaseURL, moduleBasePath)\n : options.moduleBaseURL\n : moduleBasePath;\n\n if (!moduleBaseURL.includes(moduleBasePath)) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBaseURL ${moduleBaseURL} is invalid, should include moduleBasePath ${moduleBasePath}`\n ),\n };\n }\n\n if (\n typeof options.moduleBaseURL === \"string\" &&\n options.moduleBaseURL !== moduleBaseURL\n ) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBaseURL ${options.moduleBaseURL} is invalid, should be like ${moduleBaseURL}`\n ),\n };\n }\n\n const build = options.build\n ? {\n client: options.build.client ?? DEFAULT_CONFIG.BUILD.client,\n pages: options.build.pages ?? DEFAULT_CONFIG.BUILD.pages,\n server: options.build.server ?? DEFAULT_CONFIG.BUILD.server,\n }\n : DEFAULT_CONFIG.BUILD;\n\n return {\n type: \"success\",\n userOptions: {\n moduleBase,\n moduleBasePath,\n moduleBaseURL,\n build,\n Page: options.Page ?? DEFAULT_CONFIG.PAGE,\n props: options.props ?? DEFAULT_CONFIG.PROPS,\n Html: options.Html ?? DEFAULT_CONFIG.HTML,\n pageExportName: options.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT,\n propsExportName: options.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT,\n collectCss: options.collectCss ?? DEFAULT_CONFIG.COLLECT_CSS,\n collectAssets: options.collectAssets ?? DEFAULT_CONFIG.COLLECT_ASSETS,\n projectRoot: projectRoot,\n assetsDir: options.assetsDir ?? DEFAULT_CONFIG.CLIENT_ASSETS_DIR,\n } satisfies ResolvedUserOptions,\n };\n};\n\nexport async function resolvePages(\n pages: ResolvedUserOptions[\"build\"][\"pages\"]\n): Promise<\n | {\n type: \"success\";\n pages: string[];\n }\n | {\n type: \"error\";\n error: Error;\n }\n> {\n if (!pages) {\n return {\n type: \"success\",\n pages: [],\n };\n }\n if (typeof pages === \"function\") {\n try {\n return resolvePages(await Promise.resolve(pages()));\n } catch (error) {\n return {\n type: \"error\",\n error:\n error instanceof Error\n ? error\n : new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n pages\n )}\"`,\n {\n cause: error,\n }\n ),\n };\n }\n }\n try {\n const result = pages;\n const awaited = \"then\" in result ? await result : result;\n if (typeof awaited === \"string\") {\n return {\n type: \"success\",\n pages: [awaited],\n };\n }\n if (Array.isArray(awaited)) {\n if (awaited.every((page) => typeof page === \"string\")) {\n return {\n type: \"success\",\n pages: awaited,\n };\n } else {\n return {\n type: \"error\",\n error: new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n awaited.find((page) => typeof page !== \"string\")\n )}\"`,\n {\n cause: awaited,\n }\n ),\n };\n }\n }\n return {\n type: \"error\",\n error: new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n pages\n )}\"`,\n {\n cause: pages,\n }\n ),\n };\n } catch (error) {\n return {\n type: \"error\",\n error:\n error instanceof Error\n ? error\n : new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n error\n )}\"`,\n {\n cause: error,\n }\n ),\n };\n }\n}\n"],"names":[],"mappings":";AAIO,MAAM,iBAAiB;AAAA,EAC5B,YAAY;AAAA,EACZ,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAAA,EAEd,aAAa;AAAA,EACb,aAAa;AAAA,EACb,eAAe;AAAA,EACf,MAAM,CAAC,EAAE,SAAA,MAAkC;AAAA,EAC3C,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,UAAU;AAAA,EACV,cAAc;AAAA,EACd,UAAU;AAAA,EACV,cAA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QACT,oHAAoH,KAAK;AAAA,UACvH;AAAA,QACD,CAAA;AAAA,QACD;AAAA,UACE,OAAO;AAAA,QAAA;AAAA,MACT;AAAA,IAEJ;AAAA,WACO,OAAO;AACP,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OACE,iBAAiB,QACb,QACA,IAAI;AAAA,QACF,oHAAoH,KAAK;AAAA,UACvH;AAAA,QACD,CAAA;AAAA,QACD;AAAA,UACE,OAAO;AAAA,QAAA;AAAA,MACT;AAAA,IAEV;AAAA,EAAA;AAEJ;"}
|
package/dist/plugin.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { resolveOptions } from "./options.js";
|
|
2
|
-
import { viteReactClientTransformPlugin } from "./transformer/index.js";
|
|
3
|
-
import { preserveDirectives } from "./transformer/preserveDirectives.js";
|
|
4
|
-
const getCondition = (options = {}) => {
|
|
5
|
-
const nodeOptions = options?.env?.["NODE_OPTIONS"] ?? process.env["NODE_OPTIONS"];
|
|
6
|
-
return nodeOptions?.match(/--conditions=react-server/) ? "server" : "client";
|
|
7
|
-
};
|
|
8
|
-
const reactStreamPlugin = async (options) => {
|
|
9
|
-
const condition = getCondition();
|
|
10
|
-
try {
|
|
11
|
-
const resolvedOptions = resolveOptions(options);
|
|
12
|
-
if (resolvedOptions.type === "error") {
|
|
13
|
-
throw resolvedOptions.error;
|
|
14
|
-
}
|
|
15
|
-
options = resolvedOptions.userOptions;
|
|
16
|
-
} catch (error) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
`[vite:react-stream:${condition}] ${error.message}`
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
return condition === "server" ? [
|
|
22
|
-
(await import("./react-server/plugin.js")).reactStreamPlugin(options),
|
|
23
|
-
viteReactClientTransformPlugin(),
|
|
24
|
-
preserveDirectives()
|
|
25
|
-
] : [(await import("./react-client/plugin.js")).reactStreamPlugin(options)];
|
|
26
|
-
};
|
|
27
|
-
export {
|
|
28
|
-
getCondition,
|
|
29
|
-
reactStreamPlugin
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"sourcesContent":["import { resolveOptions } from \"./options.js\";\nimport { viteReactClientTransformPlugin } from \"./transformer/index.js\";\nimport { preserveDirectives } from \"./transformer/preserveDirectives.js\";\nimport type { StreamPluginOptions } from \"./types.js\";\n\nexport const getCondition = (options: { env?: typeof process.env } = {}) => {\n const nodeOptions = options?.env?.['NODE_OPTIONS'] ?? process.env['NODE_OPTIONS'];\n return nodeOptions?.match(/--conditions=react-server/) ? \"server\" : \"client\";\n};\n\nexport const reactStreamPlugin = async (options: StreamPluginOptions) => {\n const condition = getCondition();\n try {\n const resolvedOptions = resolveOptions(options);\n if (resolvedOptions.type === \"error\") {\n throw resolvedOptions.error;\n }\n options = resolvedOptions.userOptions;\n } catch (error) {\n throw new Error(\n `[vite:react-stream:${condition}] ${(error as Error).message}`\n );\n }\n return condition === \"server\"\n ? [\n (await import(`./react-server/plugin.js`)).reactStreamPlugin(options),\n viteReactClientTransformPlugin(),\n preserveDirectives(),\n ]\n : [(await import(`./react-client/plugin.js`)).reactStreamPlugin(options)];\n};\n"],"names":[],"mappings":";;;AAKO,MAAM,eAAe,CAAC,UAAwC,OAAO;AAC1E,QAAM,cAAc,SAAS,MAAM,cAAc,KAAK,QAAQ,IAAI,cAAc;AAChF,SAAO,aAAa,MAAM,2BAA2B,IAAI,WAAW;AACtE;AAEa,MAAA,oBAAoB,OAAO,YAAiC;AACvE,QAAM,YAAY,aAAa;AAC3B,MAAA;AACI,UAAA,kBAAkB,eAAe,OAAO;AAC1C,QAAA,gBAAgB,SAAS,SAAS;AACpC,YAAM,gBAAgB;AAAA,IAAA;AAExB,cAAU,gBAAgB;AAAA,WACnB,OAAO;AACd,UAAM,IAAI;AAAA,MACR,sBAAsB,SAAS,KAAM,MAAgB,OAAO;AAAA,IAC9D;AAAA,EAAA;AAEF,SAAO,cAAc,WACjB;AAAA,KACG,MAAM,OAAO,0BAA0B,GAAG,kBAAkB,OAAO;AAAA,IACpE,+BAA+B;AAAA,IAC/B,mBAAmB;AAAA,EAAA,IAErB,EAAE,MAAM,OAAO,0BAA0B,GAAG,kBAAkB,OAAO,CAAC;AAC5E;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHandler.js","sources":["../../src/react-server/createHandler.ts"],"sourcesContent":["import { createLogger } from \"vite\";\nimport {\n collectManifestCss,\n collectModuleGraphCss,\n} from \"../collect-css-manifest.js\";\nimport { DEFAULT_CONFIG } from \"../options.js\";\nimport { resolvePage } from \"../resolvePage.js\";\nimport { resolveProps } from \"../resolveProps.js\";\nimport type { CreateHandlerOptions, StreamPluginOptions } from \"../types.js\";\nimport { createRscStream } from \"./createRscStream.js\";\n\nexport async function createHandler<T>(\n url: string,\n pluginOptions: Pick<\n StreamPluginOptions,\n \"Page\" | \"props\" | \"build\" | \"Html\" | \"pageExportName\" | \"propsExportName\"\n > &\n Required<\n Pick<StreamPluginOptions, \"moduleBase\" | \"moduleBasePath\" | \"projectRoot\">\n >,\n streamOptions: CreateHandlerOptions<T>\n) {\n const root = pluginOptions.projectRoot ?? process.cwd();\n\n const Html = pluginOptions.Html ?? DEFAULT_CONFIG.HTML;\n const pageExportName =\n pluginOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT;\n const propsExportName =\n pluginOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT;\n const controller = new AbortController();\n\n const cssFiles = streamOptions.cssFiles;\n const propsPath =\n typeof pluginOptions.props === \"function\"\n ? pluginOptions.props(url)\n : pluginOptions.props;\n const pagePath =\n typeof pluginOptions.Page === \"function\"\n ? pluginOptions.Page(url)\n : pluginOptions.Page;\n\n const cssModules = new Set<string>();\n\n if (!(streamOptions.manifest || streamOptions.moduleGraph))\n throw new Error(\"Missing manifest or moduleGraph, pass it to options.\");\n\n const getCss = streamOptions.manifest\n ? (id: string) =>\n collectManifestCss(\n streamOptions.manifest!,\n root,\n id,\n streamOptions.onCssFile\n )\n : (id: string) => collectModuleGraphCss(streamOptions.moduleGraph!, id);\n\n const loadWithCss = async (id: string) => {\n if (!id) return {};\n\n try {\n const mod = await streamOptions.loader(id);\n const pageCss = await Promise.resolve(getCss(id));\n Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));\n return mod as Record<string, any>;\n } catch (e: any) {\n if (e.message?.includes(\"module runner has been closed\")) {\n return { type: \"skip\" } as Record<string, any>;\n } else {\n return { type: \"error\", error: e } as Record<string, any>;\n }\n }\n };\n\n const PropsModule = await resolveProps({\n propsModule: await loadWithCss(propsPath ?? pagePath),\n path: String(propsPath ?? pagePath),\n exportName: propsExportName,\n url,\n });\n if (PropsModule.type === \"error\")\n return { type: PropsModule.type, error: PropsModule?.error };\n if (PropsModule.type === \"skip\") return { type: PropsModule.type };\n const props = PropsModule[propsExportName as keyof typeof PropsModule] as any;\n if (props?.type === \"error\") return { type: props.type, error: props.error };\n if (props?.type === \"skip\") return { type: props.type };\n\n const PageModule = await resolvePage({\n pageModule: await loadWithCss(pagePath),\n path: pagePath,\n exportName: pageExportName,\n url,\n });\n if (PageModule.type === \"error\")\n return { type: PageModule.type, error: PageModule.error };\n if (PageModule.type === \"skip\") return { type: PageModule.type };\n const Page = PageModule[pageExportName as keyof typeof PageModule] as any;\n if (Page?.type === \"error\") return { type: Page.type, error: Page.error };\n if (Page?.type === \"skip\") return { type: Page.type };\n if (!(typeof Page === \"function\")) {\n return {\n type: \"error\",\n error: new Error(\"Invalid Page component: \" + pagePath, {\n cause: Page,\n }),\n };\n }\n if (!(typeof props === \"object\")) {\n return {\n type: \"error\",\n error: new Error(\"Invalid props: \" + propsPath, {\n cause: props,\n }),\n };\n }\n\n // Add any additional CSS files\n if (streamOptions.cssFiles) {\n streamOptions.cssFiles.forEach((css) => cssModules.add(css));\n }\n const stream = createRscStream({\n Html: Html,\n Page: Page,\n props: props,\n moduleBasePath: pluginOptions.moduleBasePath, // eg /src\n logger: streamOptions.logger ?? createLogger(),\n cssFiles: Array.from(cssModules),\n route: url,\n url,\n pipableStreamOptions: streamOptions.pipableStreamOptions,\n });\n\n if (!stream) {\n return { type: \"skip\" as const };\n }\n\n return {\n type: \"success\" as const,\n controller,\n stream,\n assets: {\n css: cssFiles,\n },\n };\n}\n"],"names":[],"mappings":";;;;;;AAWsB,eAAA,cACpB,KACA,eAOA,eACA;AACA,QAAM,OAAO,cAAc,eAAe,QAAQ,IAAI;AAEhD,QAAA,OAAO,cAAc,QAAQ,eAAe;AAC5C,QAAA,iBACJ,cAAc,kBAAkB,eAAe;AAC3C,QAAA,kBACJ,cAAc,mBAAmB,eAAe;AAC5C,QAAA,aAAa,IAAI,gBAAgB;AAEvC,QAAM,WAAW,cAAc;AACzB,QAAA,YACJ,OAAO,cAAc,UAAU,aAC3B,cAAc,MAAM,GAAG,IACvB,cAAc;AACd,QAAA,WACJ,OAAO,cAAc,SAAS,aAC1B,cAAc,KAAK,GAAG,IACtB,cAAc;AAEd,QAAA,iCAAiB,IAAY;AAE/B,MAAA,EAAE,cAAc,YAAY,cAAc;AACtC,UAAA,IAAI,MAAM,sDAAsD;AAExE,QAAM,SAAS,cAAc,WACzB,CAAC,OACC;AAAA,IACE,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA,cAAc;AAAA,MAElB,CAAC,OAAe,sBAAsB,cAAc,aAAc,EAAE;AAElE,QAAA,cAAc,OAAO,OAAe;AACpC,QAAA,CAAC,GAAI,QAAO,CAAC;AAEb,QAAA;AACF,YAAM,MAAM,MAAM,cAAc,OAAO,EAAE;AACzC,YAAM,UAAU,MAAM,QAAQ,QAAQ,OAAO,EAAE,CAAC;AAC1C,YAAA,KAAK,QAAQ,MAAM,EAAE,QAAQ,CAAC,QAAQ,WAAW,IAAI,GAAG,CAAC;AACxD,aAAA;AAAA,aACA,GAAQ;AACf,UAAI,EAAE,SAAS,SAA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AW;AACzB,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI,MAAM,oBAAoB,WAAW;AAAA,QAC9C,OAAO;AAAA,MACR,CAAA;AAAA,IACH;AAAA,EAAA;AAIF,MAAI,cAAc,UAAU;AAC1B,kBAAc,SAAS,QAAQ,CAAC,QAAQ,WAAW,IAAI,GAAG,CAAC;AAAA,EAAA;AAE7D,QAAM,SAAS,gBAAgB;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,cAAc;AAAA;AAAA,IAC9B,QAAQ,cAAc,UAAU,aAAa;AAAA,IAC7C,UAAU,MAAM,KAAK,UAAU;AAAA,IAC/B,OAAO;AAAA,IACP;AAAA,IACA,sBAAsB,cAAc;AAAA,EAAA,CACrC;AAED,MAAI,CAAC,QAAQ;AACJ,WAAA,EAAE,MAAM,OAAgB;AAAA,EAAA;AAG1B,SAAA;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,MACN,KAAK;AAAA,IAAA;AAAA,EAET;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRscStream.js","sources":["../../src/react-server/createRscStream.ts"],"sourcesContent":["import React from \"react\";\nimport {\n renderToPipeableStream,\n type PipeableStream,\n} from \"react-server-dom-esm/server.node\";\nimport { CssCollector } from \"../components.js\";\nimport type { RscStreamOptions } from \"../types.js\";\n\nexport function createRscStream(\n streamOptions: RscStreamOptions\n): PipeableStream {\n const {\n Html,\n Page,\n props,\n logger,\n cssFiles,\n route,\n url,\n moduleBasePath,\n pipableStreamOptions,\n } = streamOptions;\n const css = Array.isArray(cssFiles)\n ? cssFiles.map((css, index) =>\n React.createElement(CssCollector, {\n key: `css-${index}`,\n url: css,\n })\n )\n : [];\n return renderToPipeableStream(\n React.createElement(\n Html,\n {\n key: \"html\",\n pageProps: props,\n moduleBasePath: moduleBasePath,\n route,\n url,\n },\n React.createElement(Page, { key: \"page\", ...props }),\n ...css\n ),\n moduleBasePath,\n {\n onError: logger?.error ?? console.error,\n onPostpone: logger?.info ?? console.info,\n environmentName: \"Server\",\n ...pipableStreamOptions,\n }\n );\n}\n"],"names":["css"],"mappings":";;;AAQO,SAAS,gBACd,eACgB;AACV,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AACJ,QAAM,MAAM,MAAM,QAAQ,QAAQ,IAC9B,SAAS;AAAA,IAAI,CAACA,MAAK,UACjB,MAAM,cAAc,cAAc;AAAA,MAChC,KAAK,OAAO,KAAK;AAAA,MACjB,KAAKA;AAAAA,IACN,CAAA;AAAA,EAAA,IAEH,CAAC;AACE,SAAA;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,QACE,KAAK;AAAA,QACL,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,MAAM,cAAc,MAAM,EAAE,KAAK,QAAQ,GAAG,OAAO;AAAA,MACnD,GAAG;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,MACE,SAAS,QAAQ,SAAS,QAAQ;AAAA,MAClC,YAAY,QAAQ,QAAQ,QAAQ;AAAA,MACpC,iBAAiB;AAAA,MACjB,GAAG;AAAA,IAAA;AAAA,EAEP;AACF;"}
|
package/dist/resolvePage.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePage.js","sources":["../src/resolvePage.ts"],"sourcesContent":["type ResolvePageOptions = {\n pageModule: Record<string, any>;\n path: string;\n url: string;\n exportName: string;\n};\n\ntype ResolvePageResult =\n | { type: \"success\"; key: string; Page: any }\n | { type: \"error\"; error: Error }\n | { type: \"skip\" };\n\nexport async function resolvePage({\n pageModule,\n path,\n url,\n exportName,\n}: ResolvePageOptions): Promise<ResolvePageResult> {\n if (!pageModule) {\n return {\n type: \"error\",\n error: new Error(`pageModule is ${typeof pageModule}`),\n };\n }\n const keys =\n typeof pageModule === \"object\" && pageModule != null\n ? Object.keys(pageModule)\n : [];\n const found = keys.find((v) => v === exportName || v === url || v === path);\n if (found) {\n if (typeof pageModule[found] === \"function\") {\n return {\n type: \"success\",\n key: found,\n Page: pageModule[found],\n };\n } else {\n if (\n typeof pageModule === \"object\" &&\n pageModule != null &&\n Object.keys(pageModule).includes(\"type\")\n )\n return pageModule as ResolvePageResult;\n return {\n type: \"error\",\n [exportName]: () => found,\n error: pageModule[found][\"error\"],\n };\n }\n }\n if (keys.includes(\"type\")) return pageModule as ResolvePageResult;\n return {\n type: \"error\",\n error: new Error(\n `Could not find Page export \"${exportName}\" in \"${path}\". ${\n typeof pageModule === \"object\" && pageModule != null\n ? keys.length\n ? \"Available exports: \" + keys.join(\", \")\n : \"The object was defined but has no properties.\"\n : \"typeof pageModule =\" + typeof pageModule\n }`,\n { cause: pageModule }\n ),\n };\n}\n"],"names":[],"mappings":"AAYA,eAAsB,YAAY;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmD;AACjD,MAAI,CAAC,YAAY;AACR,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI,MAAM,iBAAiB,OAAO,UAAU,EAAE;AAAA,IACvD;AAAA,EAAA;AAEI,QAAA,OACJ,OAAO,eAAe,YAAY,cAAc,OAC5C,OAAO,KAAK,UAAU,IACtB,CAAC;AACD,QAAA,QAAQ,KAAK,KAAK,CAAC,MAAM,MAAM,cAAc,MAAM,OAAO,MAAM,IAAI;AAC1E,MAAI,OAAO;AACT,QAAI,OAAO,WAAW,KAAK,MAAM,YAAY;AACpC,aAAA;AAAA,QACL,MAAM;AAAA,QACN,KAAK;AAAA,QACL,MAAM,WAAW,KAAK;AAAA,MACxB;AAAA,IAAA,OACK;AAEH,UAAA,OAAO,eAAe,YACtB,cAAc,QACd,OAAO,KAAK,UAAU,EAAE,SAAS,MAAM;AAEhC,eAAA;AACF,aAAA;AAAA,QACL,MAAM;AAAA,QACN,CAAC,UAAU,GAAG,MAAM;AAAA,QACpB,OAAO,WAAW,KAAK,EAAE,OAAO;AAAA,MAClC;AAAA,IAAA;AAAA,EACF;AAEF,MAAI,KAAK,SAAS,MAAM,EAAU,QAAA;AAC3B,SAAA;AAAA,IACL,MAAM;AAAA,IACN,OAAO,IAAI;AAAA,MACT,+BAA+B,UAAU,SAAS,IAAI,MACpD,OAAO,eAAe,YAAY,cAAc,OAC5C,KAAK,SACH,wBAAwB,KAAK,KAAK,IAAI,IACtC,kDACF,wBAAwB,OAAO,UACrC;AAAA,MACA,EAAE,OAAO,WAAW;AAAA,IAAA;AAAA,EAExB;AACF;"}
|
package/dist/resolveProps.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveProps.js","sources":["../src/resolveProps.ts"],"sourcesContent":["type ResolvePropsOptions = {\n propsModule: Record<string, any>;\n path: string;\n exportName: string;\n url: string;\n};\n\ntype ResolvePropsResult =\n | { type: \"success\"; key: string; props: any }\n | { type: \"error\"; error: Error }\n | { type: \"skip\" };\n\nfunction isFunction(value: any) {\n return typeof value === \"function\";\n}\n\nexport async function resolveProps({\n propsModule,\n path,\n exportName,\n url,\n}: ResolvePropsOptions): Promise<ResolvePropsResult> {\n if (!propsModule) {\n return {\n type: \"error\",\n error: new Error(`propsModule is ${typeof propsModule}`),\n };\n }\n\n if (typeof propsModule !== \"object\") {\n return {\n type: \"error\",\n error: new Error(\n `propsModule must be an object, got ${typeof propsModule}`\n ),\n };\n }\n\n const keys = Object.keys(propsModule);\n const found = keys.find((v) => v === exportName || v === url || v === path);\n if (found) {\n const value = propsModule[found];\n\n try {\n // If it's a function, call it with the URL\n if (isFunction(value)) {\n const props = await value(url);\n return {\n type: \"success\",\n key: found,\n props,\n };\n }\n\n // If it's a promise, await it\n if (value && typeof value.then === \"function\") {\n const props = await value;\n return {\n type: \"success\",\n key: found,\n props,\n };\n }\n\n // If it's a plain object, use it directly\n if (typeof value === \"object\" && value !== null) {\n return {\n type: \"success\",\n key: found,\n props: value,\n };\n }\n\n console.warn(found, \"error in resolveProps\", propsModule, url, path);\n return {\n type: \"error\",\n error: new Error(\n `Expected props export \"${exportName}\" in \"${path}\" to be a function, promise, or object that resolves to props, instead got typeof ${typeof value}.`\n ),\n };\n } catch (error) {\n console.warn(found, \"error in resolveProps\", propsModule, url, path);\n return {\n type: \"error\",\n error: error as Error,\n };\n }\n }\n const commonjs = keys.find((v) => v === \"exports\");\n\n if (!!commonjs) {\n const exportKeys = (commonjs as unknown as { exports: any })[\"exports\"]\n ? Object.keys((commonjs as unknown as { exports: any })[\"exports\"])\n : [];\n const foundCommonJS = exportKeys.find(\n (v) => v === exportName || v === url || v === path\n );\n return {\n type: \"error\",\n error: new Error(\n `Expected props export \"${exportName}\" in \"${path}\", but instead got \"exports\" with ${\n !!foundCommonJS\n ? foundCommonJS.toString()\n : exportKeys.length\n ? exportKeys.join(\", \")\n : \"no keys\"\n }, this will not work. Make sure to set esModule: true in rollupOptions.output`\n ),\n };\n }\n\n return {\n type: \"error\",\n error: new Error(\n `Could not find props export \"${exportName}\" in \"${path}\". ${\n keys.length\n ? \"Available exports: \" + keys.join(\", \")\n : \"The object was defined but has no properties.\"\n }`\n ),\n };\n}\n"],"names":[],"mappings":"AAYA,SAAS,WAAW,OAAY;AAC9B,SAAO,OAAO,UAAU;AAC1B;AAEA,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAqD;AACnD,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI,MAAM,kBAAkB,OAAO,WAAW,EAAE;AAAA,IACzD;AAAA,EAAA;AAGE,MAAA,OAAO,gBAAgB,UAAU;AAC5B,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI;AAAA,QACT,sCAAsC,OAAO,WAAW;AAAA,MAAA;AAAA,IAE5D;AAAA,EAAA;AA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AI;AAAA,QACT,0BAA0B,UAAU,SAAS,IAAI,qCAC/C,CAAC,CAAC,gBACE,cAAc,aACd,WAAW,SACX,WAAW,KAAK,IAAI,IACpB,SACN;AAAA,MAAA;AAAA,IAEJ;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,OAAO,IAAI;AAAA,MACT,gCAAgC,UAAU,SAAS,IAAI,MACrD,KAAK,SACD,wBAAwB,KAAK,KAAK,IAAI,IACtC,+CACN;AAAA,IAAA;AAAA,EAEJ;AACF;"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from "vite";
|
|
2
|
-
import { DEFAULT_CONFIG } from "../options.js";
|
|
3
|
-
import { createRscTransformer } from "./transformer.js";
|
|
4
|
-
function viteReactClientTransformPlugin(options) {
|
|
5
|
-
if (process.env["NODE_OPTIONS"]?.match(/--conditions=react-server/)) {
|
|
6
|
-
console.log("react-server");
|
|
7
|
-
} else {
|
|
8
|
-
throw new Error('react-server condition not found, set NODE_OPTIONS="--conditions react-server"');
|
|
9
|
-
}
|
|
10
|
-
const projectRoot = process.cwd();
|
|
11
|
-
const include = DEFAULT_CONFIG.FILE_REGEX;
|
|
12
|
-
const exclude = options?.exclude;
|
|
13
|
-
let transform;
|
|
14
|
-
return {
|
|
15
|
-
name: "vite:react-stream-transformer",
|
|
16
|
-
enforce: "pre",
|
|
17
|
-
configResolved(config) {
|
|
18
|
-
transform = createRscTransformer({
|
|
19
|
-
moduleId: moduleIdDefault({
|
|
20
|
-
projectRoot,
|
|
21
|
-
output: {
|
|
22
|
-
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server
|
|
23
|
-
},
|
|
24
|
-
isProduction: config.isProduction
|
|
25
|
-
})
|
|
26
|
-
}).transform;
|
|
27
|
-
},
|
|
28
|
-
transform(code, id, opts) {
|
|
29
|
-
if (!matchPattern(id, include) || exclude) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
const directiveMatch = code.startsWith('"use client"') || code.startsWith("'use client'");
|
|
33
|
-
if (!directiveMatch) return null;
|
|
34
|
-
return transform(code, id, opts);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const moduleIdDefault = ({
|
|
39
|
-
projectRoot,
|
|
40
|
-
output: _,
|
|
41
|
-
isProduction
|
|
42
|
-
}) => (moduleId) => {
|
|
43
|
-
const normalized = normalizePath(moduleId);
|
|
44
|
-
const noRoot = normalized.startsWith(projectRoot) ? normalized.slice(projectRoot.length) : normalized;
|
|
45
|
-
if (!isProduction) {
|
|
46
|
-
return noRoot;
|
|
47
|
-
}
|
|
48
|
-
return noRoot.replace(DEFAULT_CONFIG.FILE_REGEX, ".js");
|
|
49
|
-
};
|
|
50
|
-
const matchPattern = (file, pattern) => Array.isArray(pattern) ? pattern.some((p) => file.match(p)) : file.match(pattern);
|
|
51
|
-
export {
|
|
52
|
-
viteReactClientTransformPlugin
|
|
53
|
-
};
|
|
54
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/transformer/index.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { normalizePath } from \"vite\";\nimport { DEFAULT_CONFIG } from \"../options.js\";\nimport { createRscTransformer } from \"./transformer.js\";\nimport type { ViteReactClientTransformOptions } from \"./types.js\";\n\n\n/**\n * Plugin for transforming React Client Components.\n *\n * Core responsibilities:\n * 1. Detects \"use client\" directives\n * 2. Transforms client components for RSC boundaries\n * 3. Adds client reference metadata for RSC\n *\n * When a component is marked with \"use client\", it:\n * - Gets transformed into a client reference\n * - Maintains module ID for RSC boundaries\n * - Preserves class/function behavior\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [\n * viteReactClientTransformPlugin({\n * projectRoot: process.cwd(),\n * })\n * ]\n * });\n * ```\n */\n\nexport function viteReactClientTransformPlugin(\n options?: ViteReactClientTransformOptions\n): Plugin {\n if(process.env['NODE_OPTIONS']?.match(/--conditions=react-server/)) {\n console.log('react-server')\n } else {\n throw new Error('react-server condition not found, set NODE_OPTIONS=\"--conditions react-server\"')\n }\n const projectRoot = options?.projectRoot || process.cwd();\n const include = options?.include || DEFAULT_CONFIG.FILE_REGEX;\n const exclude = options?.exclude;\n let transform: any;\n // get the file we are imported from (parent)\n\n return {\n name: \"vite:react-stream-transformer\",\n enforce: \"pre\",\n\n configResolved(config) {\n transform = createRscTransformer({\n moduleId:\n options?.moduleId ||\n moduleIdDefault({\n projectRoot: projectRoot,\n output: {\n dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,\n },\n isProduction: config.isProduction,\n }),\n }).transform;\n },\n\n transform(code: string, id: string, opts) {\n // Skip if file doesn't match patterns\n if (\n !matchPattern(id, include) ||\n (exclude && matchPattern(id, exclude))\n ) {\n return null;\n }\n\n // Look for use client directive at start of file (no exceptions)\n const directiveMatch =\n code.startsWith('\"use client\"') || code.startsWith(\"'use client'\");\n if (!directiveMatch) return null;\n\n // Transform client components\n return transform(code, id, opts);\n },\n };\n}\n\nconst moduleIdDefault =\n ({\n projectRoot,\n output: _,\n isProduction,\n }: {\n isProduction: boolean;\n projectRoot: string;\n output: { dir: string };\n }) =>\n (moduleId: string) => {\n const normalized = normalizePath(moduleId);\n const noRoot = normalized.startsWith(projectRoot)\n ? normalized.slice(projectRoot.length)\n : normalized;\n if (!isProduction) {\n return noRoot;\n }\n return noRoot.replace(DEFAULT_CONFIG.FILE_REGEX, \".js\");\n };\n\nconst matchPattern = (\n file: string,\n pattern: string | RegExp | (string | RegExp)[]\n) =>\n Array.isArray(pattern)\n ? pattern.some((p) => file.match(p as RegExp))\n : file.match(pattern as RegExp);\n"],"names":[],"mappings":";;;AAgCO,SAAS,+BACd,SACQ;AACR,MAAG,QAAQ,IAAI,cAAc,GAAG,MAAM,2BAA2B,GAAG;AAClE,YAAQ,IAAI,cAAc;AAAA,EAAA,OACrB;AACC,UAAA,IAAI,MAAM,gFAAgF;AAAA,EAAA;AAElG,QAAM,cAAsC,QAAQ,IAAI;AAClD,QAAA,UAA8B,eAAe;AACnD,QAAM,UAAU,SAAS;AACrB,MAAA;AAGG,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,eAAe,QAAQ;AACrB,kBAAY,qBAAqB;AAAA,QAC/B,UAEE,gBAAgB;AAAA,UACd;AAAA,UACA,QAAQ;AAAA,YACN,KAAK,OAAO,OAAO,UAAU,eAAe,MAAM;AAAA,UACpD;AAAA,UACA,cAAc,OAAO;AAAA,QACtB,CAAA;AAAA,MACJ,CAAA,EAAE;AAAA,IACL;AAAA,IAEA,UAAU,MAAc,IAAY,MAAM;AAGtC,UAAA,CAAC,aAAa,IAAI,OAAO,KACxB,SACD;AACO,eAAA;AAAA,MAAA;AAIT,YAAM,iBACJ,KAAK,WAAW,cAAc,KAAK,KAAK,WAAW,cAAc;AAC/D,UAAA,CAAC,eAAuB,QAAA;AAGrB,aAAA,UAAU,MAAM,IAAI,IAAI;AAAA,IAAA;AAAA,EAEnC;AACF;AAEA,MAAM,kBACJ,CAAC;AAAA,EACC;AAAA,EACA,QAAQ;AAAA,EACR;AACF,MAKA,CAAC,aAAqB;AACd,QAAA,aAAa,cAAc,QAAQ;AACnC,QAAA,SAAS,WAAW,WAAW,WAAW,IAC5C,WAAW,MAAM,YAAY,MAAM,IACnC;AACJ,MAAI,CAAC,cAAc;AACV,WAAA;AAAA,EAAA;AAET,SAAO,OAAO,QAAQ,eAAe,YAAY,KAAK;AACxD;AAEF,MAAM,eAAe,CACnB,MACA,YAEA,MAAM,QAAQ,OAAO,IACjB,QAAQ,KAAK,CAAC,MAAM,KAAK,MAAM,CAAW,CAAC,IAC3C,KAAK,MAAM,OAAiB;"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { SourceMapGenerator } from "source-map";
|
|
2
|
-
import { DEFAULT_CONFIG } from "../options.js";
|
|
3
|
-
const REACT_DIRECTIVES = /* @__PURE__ */ new Set(["use client", "use server", "use no-memo"]);
|
|
4
|
-
function preserveDirectives(options) {
|
|
5
|
-
const meta = {
|
|
6
|
-
directives: {}
|
|
7
|
-
};
|
|
8
|
-
const fileRegex = DEFAULT_CONFIG.FILE_REGEX;
|
|
9
|
-
return {
|
|
10
|
-
name: "react-preserve-directives",
|
|
11
|
-
transform: {
|
|
12
|
-
order: "post",
|
|
13
|
-
handler(code, id) {
|
|
14
|
-
if (!fileRegex.test(id)) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const ast = this.parse(code);
|
|
18
|
-
if (ast.type !== "Program") {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
let hasDirectives = false;
|
|
22
|
-
const directives = /* @__PURE__ */ new Set();
|
|
23
|
-
for (const node of ast.body) {
|
|
24
|
-
if (node.type !== "ExpressionStatement") {
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
if (node.expression.type === "Literal" && typeof node.expression.value === "string" && REACT_DIRECTIVES.has(node.expression.value)) {
|
|
28
|
-
directives.add(node.expression.value);
|
|
29
|
-
hasDirectives = true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (!hasDirectives) return null;
|
|
33
|
-
meta.directives[id] = directives;
|
|
34
|
-
const map = new SourceMapGenerator({
|
|
35
|
-
file: id,
|
|
36
|
-
sourceRoot: ""
|
|
37
|
-
});
|
|
38
|
-
map.setSourceContent(id, code);
|
|
39
|
-
return {
|
|
40
|
-
code,
|
|
41
|
-
map: map.toString(),
|
|
42
|
-
meta: { directives: Array.from(directives) }
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
renderChunk(code, chunk) {
|
|
47
|
-
const moduleIds = chunk.moduleIds;
|
|
48
|
-
const chunkDirectives = moduleIds.map((id) => meta.directives[id]).filter((dirs) => !!dirs).reduce((acc, dirs) => {
|
|
49
|
-
dirs.forEach((d) => acc.add(d));
|
|
50
|
-
return acc;
|
|
51
|
-
}, /* @__PURE__ */ new Set());
|
|
52
|
-
if (chunkDirectives.size) {
|
|
53
|
-
const directiveCode = Array.from(chunkDirectives).map((d) => `"${d}";`).join("\n");
|
|
54
|
-
return {
|
|
55
|
-
code: `${directiveCode}
|
|
56
|
-
${code}`
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
},
|
|
61
|
-
onLog(level, log) {
|
|
62
|
-
if (log.code === "MODULE_LEVEL_DIRECTIVE" && level === "warn") {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return this.warn(log);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
export {
|
|
70
|
-
preserveDirectives
|
|
71
|
-
};
|
|
72
|
-
//# sourceMappingURL=preserveDirectives.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preserveDirectives.js","sources":["../../src/transformer/preserveDirectives.ts"],"sourcesContent":["import type { Node } from \"estree\";\nimport type { Plugin } from \"rollup\";\nimport { SourceMapGenerator } from \"source-map\";\nimport { DEFAULT_CONFIG } from \"../options.js\";\nimport type { Options } from \"../types.js\";\n\nconst REACT_DIRECTIVES = new Set([\"use client\", \"use server\", \"use no-memo\"]);\n\ninterface PreserveDirectiveMeta {\n directives: Record<string, Set<string>>;\n}\n\nexport function preserveDirectives(options?: Pick<Options, \"include\">): Plugin {\n const meta: PreserveDirectiveMeta = {\n directives: {},\n };\n const fileRegex = options?.include ?? DEFAULT_CONFIG.FILE_REGEX;\n\n return {\n name: \"react-preserve-directives\",\n transform: {\n order: \"post\",\n handler(code, id) {\n if (!fileRegex.test(id)) {\n return null;\n }\n\n const ast = this.parse(code) as Node;\n if (ast.type !== \"Program\") {\n return null;\n }\n\n let hasDirectives = false;\n const directives = new Set<string>();\n\n // Look for directives at start of file\n for (const node of ast.body) {\n if (node.type !== \"ExpressionStatement\") {\n break;\n }\n\n if (\n node.expression.type === \"Literal\" &&\n typeof node.expression.value === \"string\" &&\n REACT_DIRECTIVES.has(node.expression.value)\n ) {\n directives.add(node.expression.value);\n hasDirectives = true;\n }\n }\n\n if (!hasDirectives) return null;\n\n meta.directives[id] = directives;\n\n // Generate source map\n const map = new SourceMapGenerator({\n file: id,\n sourceRoot: \"\",\n });\n map.setSourceContent(id, code);\n\n return {\n code,\n map: map.toString(),\n meta: { directives: Array.from(directives) },\n };\n },\n },\n\n renderChunk(code, chunk) {\n const moduleIds = chunk.moduleIds;\n const chunkDirectives = moduleIds\n .map((id) => meta.directives[id])\n .filter((dirs): dirs is Set<string> => !!dirs)\n .reduce((acc, dirs) => {\n dirs.forEach((d) => acc.add(d));\n return acc;\n }, new Set<string>());\n\n if (chunkDirectives.size) {\n const directiveCode = Array.from(chunkDirectives)\n .map((d) => `\"${d}\";`)\n .join(\"\\n\");\n return {\n code: `${directiveCode}\\n${code}`,\n };\n }\n\n return null;\n },\n\n onLog(level, log) {\n if (log.code === \"MODULE_LEVEL_DIRECTIVE\" && level === \"warn\") {\n return false;\n }\n return this.warn(log);\n },\n };\n}\n"],"names":[],"mappings":";;AAMA,MAAM,mBAAuB,oBAAA,IAAI,CAAC,cAAc,cAAc,aAAa,CAAC;AAMrE,SAAS,mBAAmB,SAA4C;AAC7E,QAAM,OAA8B;AAAA,IAClC,YAAY,CAAA;AAAA,EACd;AACM,QAAA,YAAgC,eAAe;AAE9C,SAAA;AAAA,IACL,MAAM;AAAA,IACN,WAAW;AAAA,MACT,OAAO;AAAA,MACP,QAAQ,MAAM,IAAI;AAChB,YAAI,CAAC,UAAU,KAAK,EAAE,GAAG;AAChB,iBAAA;AAAA,QAAA;AAGH,cAAA,MAAM,KAAK,MAAM,IAAI;AACvB,YAAA,IAAI,SAAS,WAAW;AACnB,iBAAA;AAAA,QAAA;AAGT,YAAI,gBAAgB;AACd,cAAA,iCAAiB,IAAY;AAGxB,mBAAA,QAAQ,IAAI,MAAM;AACvB,cAAA,KAAK,SAAS,uBAAuB;AACvC;AAAA,UAAA;AAGF,cACE,KAAK,WAAW,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source-map";
|
|
2
|
-
function createRscTransformer(options) {
|
|
3
|
-
return {
|
|
4
|
-
name: "vite:react-stream-transformer",
|
|
5
|
-
enforce: "post",
|
|
6
|
-
async transform(code, path, { ssr }) {
|
|
7
|
-
try {
|
|
8
|
-
let transformedCode = code;
|
|
9
|
-
const directiveMatch = code.match(/^["']use client["'];?/);
|
|
10
|
-
const moduleId = options.moduleId(path, ssr);
|
|
11
|
-
console.log("[RSC Transform] Module path transformation:", {
|
|
12
|
-
original: path,
|
|
13
|
-
transformed: moduleId
|
|
14
|
-
});
|
|
15
|
-
const exportMatches = Array.from(
|
|
16
|
-
code.matchAll(/export\s+(?:const|let|var|function|class)\s+(\w+)/g)
|
|
17
|
-
);
|
|
18
|
-
if (!exportMatches.length) {
|
|
19
|
-
console.warn(`[RSC] No exports found in client component: ${path}`);
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
for (const [fullMatch, exportName] of exportMatches) {
|
|
23
|
-
if (!exportName) {
|
|
24
|
-
console.warn(`[RSC] Invalid export in client component: ${path}`);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
const isClass = fullMatch.includes("class");
|
|
28
|
-
transformedCode = transformedCode.replace(
|
|
29
|
-
fullMatch,
|
|
30
|
-
fullMatch.replace("export ", "")
|
|
31
|
-
);
|
|
32
|
-
if (!directiveMatch || directiveMatch.index !== 0) {
|
|
33
|
-
transformedCode += `
|
|
34
|
-
const ${exportName}Ref = Object.defineProperties(
|
|
35
|
-
${isClass ? `class extends ${exportName} {
|
|
36
|
-
constructor(...args) { super(...args); }
|
|
37
|
-
}` : `function(...args) { return ${exportName}.apply(null, args); }`},
|
|
38
|
-
{
|
|
39
|
-
$$typeof: { value: Symbol.for("react.server.reference") },
|
|
40
|
-
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} },
|
|
41
|
-
$$filepath: { value: ${JSON.stringify(path)} },
|
|
42
|
-
$$async: { value: true }
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
export { ${exportName}Ref as ${exportName} };
|
|
46
|
-
`;
|
|
47
|
-
} else {
|
|
48
|
-
transformedCode += `
|
|
49
|
-
const ${exportName}Ref = Object.defineProperties(
|
|
50
|
-
${isClass ? `class extends ${exportName} {
|
|
51
|
-
constructor(...args) { super(...args); }
|
|
52
|
-
}` : `function(...args) { return ${exportName}.apply(null, args); }`},
|
|
53
|
-
{
|
|
54
|
-
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
55
|
-
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} },
|
|
56
|
-
$$filepath: { value: ${JSON.stringify(path)} }
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
export { ${exportName}Ref as ${exportName} };
|
|
60
|
-
`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
code: transformedCode,
|
|
65
|
-
map: new SourceMapGenerator({ file: path }).toString()
|
|
66
|
-
};
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error(
|
|
69
|
-
`[RSC] Error transforming client component: ${path}`,
|
|
70
|
-
error
|
|
71
|
-
);
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
export {
|
|
78
|
-
createRscTransformer
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=transformer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.js","sources":["../../src/transformer/transformer.ts"],"sourcesContent":["import { SourceMapGenerator } from \"source-map\";\nimport type { TransformerOptions } from \"./types.js\";\n\nexport function createRscTransformer(options: TransformerOptions) {\n return {\n name: \"vite:react-stream-transformer\",\n enforce: \"post\" as const,\n\n async transform(\n code: string,\n path: string,\n { ssr }: { inMap: null | string; ssr: boolean }\n ) {\n try {\n let transformedCode = code;\n const directiveMatch = code.match(/^[\"']use client[\"'];?/);\n const moduleId = options.moduleId(path, ssr);\n\n // Log the path transformation\n console.log(\"[RSC Transform] Module path transformation:\", {\n original: path,\n transformed: moduleId,\n });\n\n // Find all named exports\n const exportMatches = Array.from(\n code.matchAll(/export\\s+(?:const|let|var|function|class)\\s+(\\w+)/g)\n );\n\n if (!exportMatches.length) {\n console.warn(`[RSC] No exports found in client component: ${path}`);\n return null;\n }\n\n // Transform each export\n for (const [fullMatch, exportName] of exportMatches) {\n if (!exportName) {\n console.warn(`[RSC] Invalid export in client component: ${path}`);\n continue;\n }\n\n const isClass = fullMatch.includes(\"class\");\n\n // Remove export keyword\n transformedCode = transformedCode.replace(\n fullMatch,\n fullMatch.replace(\"export \", \"\")\n );\n\n if (!directiveMatch || directiveMatch.index !== 0) {\n // Server component\n transformedCode += `\nconst ${exportName}Ref = Object.defineProperties(\n ${\n isClass\n ? `class extends ${exportName} {\n constructor(...args) { super(...args); }\n }`\n : `function(...args) { return ${exportName}.apply(null, args); }`\n },\n {\n $$typeof: { value: Symbol.for(\"react.server.reference\") },\n $$id: { value: ${JSON.stringify(moduleId + \"#\" + exportName)} },\n $$filepath: { value: ${JSON.stringify(path)} },\n $$async: { value: true }\n }\n);\nexport { ${exportName}Ref as ${exportName} };\n`;\n } else {\n // Client component\n transformedCode += `\nconst ${exportName}Ref = Object.defineProperties(\n ${\n isClass\n ? `class extends ${exportName} {\n constructor(...args) { super(...args); }\n }`\n : `function(...args) { return ${exportName}.apply(null, args); }`\n },\n {\n $$typeof: { value: Symbol.for(\"react.client.reference\") },\n $$id: { value: ${JSON.stringify(moduleId + \"#\" + exportName)} },\n $$filepath: { value: ${JSON.stringify(path)} }\n }\n);\nexport { ${exportName}Ref as ${exportName} };\n`;\n }\n }\n\n return {\n code: transformedCode,\n map: new SourceMapGenerator({ file: path }).toString(),\n };\n } catch (error) {\n console.error(\n `[RSC] Error transforming client component: ${path}`,\n error\n );\n throw error;\n }\n },\n };\n}\n\n/**\n * transformedCode += `\nconst ${exportName}Ref = Object.defineProperties(\n ${\n isClass\n ? `class extends ${exportName} {\n constructor(...args) { super(...args); }\n }`\n : `function(...args) { return ${exportName}.apply(null, args); }`\n },\n {\n $$typeof: { value: Symbol.for(\"react.client.reference\") },\n $$id: { value: ${JSON.stringify(moduleId + \"#\" + exportName)} }\n }\n);\nexport { ${exportName}Ref as ${exportName} };`;\n */\n"],"names":[],"mappings":";AAGO,SAAS,qBAAqB,SAA6B;AACzD,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,MAAM,UACJ,MACA,MACA,EAAE,OACF;AACI,UAAA;AACF,YAAI,kBAAkB;AAChB,cAAA,iBAAiB,KAAK,MAAM,uBAAuB;AACzD,cAAM,WAAW,QAAQ,SAAS,MAAM,GAAG;AAG3C,gBAAQ,IAAI,+CAA+C;AAAA,UACzD,UAAU;AAAA,UACV,aAAa;AAAA,QAAA,CACd;AAGD,cAAM,gBAAgB,MAAM;AAAA,UAC1B,KAAK,SAAS,oDAAoD;AAAA,QACpE;AAEI,YAAA,CAAC,cAAc,QAAQ;AACjB,kBAAA,KAAK,+CAA+C,IAAI,EAAE;AAC3D,iBAAA;AAAA,QAAA;AAIT,mBAAW,CAAC,WAAW,UAAU,KAAK,eAAe;AACnD,cAAI,CAAC,YAAY;AACP,oBAAA,KAAK,6CAA6C,IAAI,EAAE;AAChE;AAAA,UAAA;AAGI,gBAAA,UAAU,UAAU,SAAS,OAAO;AAG1C,4BAAkB,gBAAgB;AAAA,YAChC;AAAA,YACA,UAAU,QAAQ,WAAW,EAAE;AAAA,UACjC;AAEA,cAAI,CAAC,kBAAkB,eAAe,UAAU,GAAG;AAE9B,+BAAA;AAAA,QACvB,UAAU;AAAA,IAEd,UACI,iBAAiB,UAAU;AAAA;AAAA,aAG3B,8BAA8B,UAAU,uBAC9C;AAAA;AAAA;AAAA,qBAGmB,KAAK,UAAU,WAAW,MAAM,UAAU,CAAC;AAAA,2BACrC,KAAK,UAAU,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA,WAIpC,UAAU,UAAU,UAAU;AAAA;AAAA,UAAA,OAExB;AAEc,+BAAA;AAAA,QACvB,UAAU;AAAA,IAEd,UACI,iBAAiB,UAAU;AAAA;AAAA,aAG3B,8BAA8B,UAAU,uBAC9C;AAAA;AAAA;AAAA,qBAGmB,KAAK,UAAU,WAAW,MAAM,UAAU,CAAC;AAAA,2BACrC,KAAK,UAAU,IAAI,CAAC;AAAA;AAAA;AAAA,WAGpC,UAAU,UAAU,UAAU;AAAA;AAAA,UAAA;AAAA,QAE/B;AAGK,eAAA;AAAA,UACL,MAAM;AAAA,UACN,KAAK,IAAI,mBAAmB,EAAE,MAAM,KAAK,CAAC,EAAE,SAAS;AAAA,QACvD;AAAA,eACO,OAAO;AACN,gBAAA;AAAA,UACN,8CAA8C,IAAI;AAAA,UAClD;AAAA,QACF;AACM,cAAA;AAAA,MAAA;AAAA,IACR;AAAA,EAEJ;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createWorker.js","sources":["../../src/worker/createWorker.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { Worker } from \"node:worker_threads\";\n\nexport async function createWorker(\n projectRoot: string,\n outDir: string,\n fileName: string,\n mode: \"production\" | \"development\"\n) {\n console.log(\"[Worker] Creating worker...\");\n const workerPath = resolve(projectRoot, outDir, fileName);\n console.log(\"[Worker] Worker path:\", workerPath);\n\n try {\n const worker = new Worker(workerPath, {\n env: {\n NODE_OPTIONS: \"\",\n NODE_PATH: resolve(projectRoot, \"node_modules\"),\n NODE_ENV: mode,\n },\n });\n worker.setMaxListeners(1000);\n\n // Wait for worker to be ready\n await new Promise<void>((resolve, reject) => {\n worker.once(\"message\", (message) => {\n if (message.type === \"READY\") {\n resolve();\n }\n });\n worker.once(\"error\", reject);\n });\n\n return worker;\n } catch (error) {\n console.error(\"[Worker] Startup error:\", error);\n throw error;\n }\n}\n"],"names":["resolve"],"mappings":";;AAGA,eAAsB,aACpB,aACA,QACA,UACA,MACA;AACA,UAAQ,IAAI,6BAA6B;AACzC,QAAM,aAAa,QAAQ,aAAa,QAAQ,QAAQ;AAChD,UAAA,IAAI,yBAAyB,UAAU;AAE3C,MAAA;AACI,UAAA,SAAS,IAAI,OAAO,YAAY;AAAA,MACpC,KAAK;AAAA,QACH,cAAc;AAAA,QACd,WAAW,QAAQ,aAAa,cAAc;AAAA,QAC9C,UAAU;AAAA,MAAA;AAAA,IACZ,CACD;AACD,WAAO,gBAAgB,GAAI;AAG3B,UAAM,IAAI,QAAc,CAACA,UAAS,WAAW;AACpC,aAAA,KAAK,WAAW,CAAC,YAAY;AAC9B,YAAA,QAAQ,SAAS,SAAS;AAC5BA,mBAAQ;AAAA,QAAA;AAAA,MACV,CACD;AACM,aAAA,KAAK,SAAS,MAAM;AAAA,IAAA,CAC5B;AAEM,WAAA;AAAA,WACA,OAAO;AACN,YAAA,MAAM,2BAA2B,KAAK;AACxC,UAAA;AAAA,EAAA;AAEV;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderPages.js","sources":["../../src/worker/renderPages.ts"],"sourcesContent":["import { join, resolve as resolvePath } from \"node:path\";\nimport { Transform } from \"node:stream\";\nimport type { Worker } from \"node:worker_threads\";\nimport type { PipeableStreamOptions } from \"react-dom/server.node\";\nimport { createHandler } from \"../react-server/createHandler.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\nimport type {\n WorkerRscChunkMessage,\n WorkerRscEndMessage,\n} from \"./types.js\";\n\ntype RenderPagesOptions = {\n pluginOptions: Required<\n Pick<\n StreamPluginOptions,\n \"moduleBase\" | \"moduleBasePath\" | \"moduleBaseURL\" | \"projectRoot\"\n >\n > &\n Pick<\n StreamPluginOptions,\n \"Page\" | \"props\" | \"build\" | \"Html\" | \"pageExportName\" | \"propsExportName\"\n >;\n outDir: string;\n manifest: Record<string, { file: string }>;\n worker: Worker;\n pipableStreamOptions?: PipeableStreamOptions;\n loader: (id: string) => Promise<Record<string, any>>;\n onCssFile?: (path: string) => void;\n clientCss?: string[];\n};\n\nexport async function renderPages(\n routes: string[],\n options: RenderPagesOptions\n) {\n const destinationRoot = resolvePath(\n options.pluginOptions.projectRoot,\n options.outDir\n );\n const failedRoutes = new Map<string, Error>();\n const moduleBasePath = join(\n destinationRoot,\n options.pluginOptions.moduleBasePath\n );\n const moduleBaseURL = options.pluginOptions.moduleBaseURL;\n\n const htmlRoot = resolvePath(\n options.pluginOptions.projectRoot,\n options.pluginOptions.build?.client ?? options.outDir\n );\n const filesOutputted: string[] = [];\n\n options.worker.on(\"message\", (msg) => {\n switch (msg.type) {\n case \"ERROR\":\n console.error(\"[RenderPages] Worker error:\", msg.error);\n break;\n case \"HTML\":\n filesOutputted.push(msg.outputPath);\n if (filesOutputted.length === routes.length) {\n renderPromises.push(\n new Promise<void>((resolve) => {\n options.worker.removeAllListeners();\n options.worker.terminate();\n resolve();\n })\n );\n }\n break;\n default:\n break;\n }\n });\n const pipableStreamOptions = options.pipableStreamOptions ?? {};\n\n // Create promises for each route in the batch\n const renderPromises = routes.map(async (route) => {\n try {\n // Wait for handler creation\n const result = await createHandler(route, options.pluginOptions, {\n loader: options.loader,\n manifest: options.manifest,\n });\n\n if (result.type !== \"success\") {\n return;\n }\n const htmlOutputPath = join(htmlRoot, route, \"index.html\");\n\n // Create a promise that resolves when the worker completes\n await new Promise<void>((resolve, reject) => {\n // Pipe RSC stream to worker\n const transform = new Transform({\n transform(chunk, _encoding, callback) {\n // Send raw chunk\n options.worker.postMessage({\n type: \"RSC_CHUNK\",\n id: route,\n chunk: chunk,\n moduleBasePath,\n moduleBaseURL,\n htmlOutputPath: htmlOutputPath,\n outDir: options.outDir,\n pipableStreamOptions,\n } satisfies WorkerRscChunkMessage);\n callback();\n },\n flush(callback) {\n options.worker.postMessage({\n type: \"RSC_END\",\n id: route,\n } satisfies WorkerRscEndMessage);\n callback();\n },\n });\n\n // Listen for worker response for this route\n const messageHandler = (msg: any) => {\n if (msg.route === route) {\n if (msg.type === \"ERROR\") {\n options.worker.removeListener(\"message\", messageHandler);\n reject(new Error(msg.error));\n } else if (msg.type === \"HTML\") {\n options.worker.removeListener(\"message\", messageHandler);\n resolve();\n }\n }\n };\n\n options.worker.on(\"message\", messageHandler);\n result.stream?.pipe(transform);\n });\n } catch (error) {\n failedRoutes.set(route, error as Error);\n }\n });\n\n // Wait for all routes to complete\n await Promise.all(renderPromises);\n\n if (failedRoutes.size > 0) {\n console.error(\"[vite-react-stream] Failed routes:\", failedRoutes);\n }\n}\n"],"names":["resolvePath","resolve"],"mappings":";;;AA+BsB,eAAA,YACpB,QACA,SACA;AACA,QAAM,kBAAkBA;AAAAA,IACtB,QAAQ,cAAc;AAAA,IACtB,QAAQ;AAAA,EACV;AACM,QAAA,mCAAmB,IAAmB;AAC5C,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA,QAAQ,cAAc;AAAA,EACxB;AACM,QAAA,gBAAgB,QAAQ,cAAc;AAE5C,QAAM,WAAWA;AAAAA,IACf,QAAQ,cAAc;AAAA,IACtB,QAAQ,cAAc,OAAO,UAAU,QAAQ;AAAA,EACjD;AACA,QAAM,iBAA2B,CAAC;AAElC,UAAQ,OAAO,GAAG,WAAW,CAAC,QAAQ;AACpC,YAAQ,IAAI,MAAM;AAAA,MAChB,KAAK;AACK,gBAAA,MAAM,+BAA+B,IAAI,KAAK;AACtD;AAAA,MACF,KAAK;AACY,uBAAA,KAAK,IAAI,UAAU;AAC9B,YAAA,eAAe,WAAW,OAAO,QAAQ;AAC5B,yBAAA;AAAA,YACb,IAAI,QAAc,CAACC,aAAY;AAC7B,sBAAQ,OAAO,mBAAmB;AAClC,sBAAQ,OAAO,UAAU;AACjB,cAAAA,SAAA;AAAA,YACT,CAAA;AAAA,UACH;AAAA,QAAA;AAEF;AAAA,IAEA;AAAA,EACJ,CACD;AACK,QAAA,uBAAuB,QAAQ,wBAAwB,CAAC;AAG9D,QAAM,iBAAiB,OAAO,IAAI,OAAO,UAAU;AAC7C,QAAA;AAEF,YAAM,SAAS,MAAM,cAAc,OAAO,QAAQ,eAAe;AAA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es
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|