@@ -48,7 +48,7 @@ import {
48
48
withRollupError ,
49
49
} from './plugins/utils'
50
50
import { createDebug } from '@hiogawa/utils'
51
- import { transformScanBuildStrip } from './plugins/scan'
51
+ import { scanBuildStripPlugin } from './plugins/scan'
52
52
import { validateImportPlugin } from './plugins/validate-import'
53
53
import { vitePluginFindSourceMapURL } from './plugins/find-source-map-url'
54
54
import { parseCssVirtual , toCssVirtual , parseIdQuery } from './plugins/shared'
@@ -90,6 +90,8 @@ function resolvePackage(name: string) {
90
90
return pathToFileURL ( require . resolve ( name ) ) . href
91
91
}
92
92
93
+ export type { RscPluginManager }
94
+
93
95
class RscPluginManager {
94
96
server ! : ViteDevServer
95
97
config ! : ResolvedConfig
@@ -979,9 +981,23 @@ import.meta.hot.on("rsc:update", () => {
979
981
return code
980
982
} ,
981
983
) ,
984
+ ...vitePluginRscMinimal ( rscPluginOptions , manager ) ,
985
+ ...vitePluginFindSourceMapURL ( ) ,
986
+ ...vitePluginRscCss ( rscPluginOptions , manager ) ,
987
+ ...( rscPluginOptions . validateImports !== false
988
+ ? [ validateImportPlugin ( ) ]
989
+ : [ ] ) ,
990
+ scanBuildStripPlugin ( { manager } ) ,
991
+ ...cjsModuleRunnerPlugin ( ) ,
992
+ ...globalAsyncLocalStoragePlugin ( ) ,
993
+ ]
994
+ }
995
+
996
+ // make `AsyncLocalStorage` available globally for React edge build (required for React.cache, ssr preload, etc.)
997
+ // https://github.com/facebook/react/blob/f14d7f0d2597ea25da12bcf97772e8803f2a394c/packages/react-server/src/forks/ReactFlightServerConfig.dom-edge.js#L16-L19
998
+ function globalAsyncLocalStoragePlugin ( ) : Plugin [ ] {
999
+ return [
982
1000
{
983
- // make `AsyncLocalStorage` available globally for React edge build (required for React.cache, ssr preload, etc.)
984
- // https://github.com/facebook/react/blob/f14d7f0d2597ea25da12bcf97772e8803f2a394c/packages/react-server/src/forks/ReactFlightServerConfig.dom-edge.js#L16-L19
985
1001
name : 'rsc:inject-async-local-storage' ,
986
1002
transform : {
987
1003
handler ( code ) {
@@ -1004,36 +1020,9 @@ import.meta.hot.on("rsc:update", () => {
1004
1020
} ,
1005
1021
} ,
1006
1022
} ,
1007
- ...vitePluginRscMinimal ( rscPluginOptions , manager ) ,
1008
- ...vitePluginFindSourceMapURL ( ) ,
1009
- ...vitePluginRscCss ( rscPluginOptions , manager ) ,
1010
- ...( rscPluginOptions . validateImports !== false
1011
- ? [ validateImportPlugin ( ) ]
1012
- : [ ] ) ,
1013
- scanBuildStripPlugin ( { manager } ) ,
1014
- ...cjsModuleRunnerPlugin ( ) ,
1015
1023
]
1016
1024
}
1017
1025
1018
- // During scan build, we strip all code but imports to
1019
- // traverse module graph faster and just discover client/server references.
1020
- function scanBuildStripPlugin ( {
1021
- manager,
1022
- } : {
1023
- manager : RscPluginManager
1024
- } ) : Plugin {
1025
- return {
1026
- name : 'rsc:scan-strip' ,
1027
- apply : 'build' ,
1028
- enforce : 'post' ,
1029
- async transform ( code , _id , _options ) {
1030
- if ( ! manager . isScanBuild ) return
1031
- const output = await transformScanBuildStrip ( code )
1032
- return { code : output , map : { mappings : '' } }
1033
- } ,
1034
- }
1035
- }
1036
-
1037
1026
function vitePluginUseClient (
1038
1027
useClientPluginOptions : Pick <
1039
1028
RscPluginOptions ,
0 commit comments