@@ -2128,20 +2128,17 @@ function validateImportPlugin(): Plugin {
21282128function vendorUseSyncExternalStorePlugin ( ) : Plugin [ ] {
21292129 // vendor and optimize use-sync-external-store out of the box
21302130 // since this is a commonly used cjs dep (e.g. swr, @tanstack/react-store)
2131- const DEP_NAME = 'use-sync-external-store'
2132- const VENDOR_DEP_NAME = `${ PKG_NAME } /vendor/use-sync-external-store`
2133-
2134- // map exports
2135- // cf. https://github.com/facebook/react/blob/c499adf8c89bbfd884f4d3a58c4e510001383525/packages/use-sync-external-store/package.json#L5-L20
2136- const alias : Record < string , string > = {
2137- [ DEP_NAME ] : `${ VENDOR_DEP_NAME } /index` ,
2138- [ `${ DEP_NAME } /with-selector` ] : `${ VENDOR_DEP_NAME } /with-selector` ,
2139- [ `${ DEP_NAME } /with-selector.js` ] : `${ VENDOR_DEP_NAME } /with-selector` ,
2140- [ `${ DEP_NAME } /shim` ] : `${ VENDOR_DEP_NAME } /shim/index` ,
2141- [ `${ DEP_NAME } /shim/index.js` ] : `${ VENDOR_DEP_NAME } /shim/index` ,
2142- [ `${ DEP_NAME } /shim/with-selector` ] : `${ VENDOR_DEP_NAME } /shim/with-selector` ,
2143- [ `${ DEP_NAME } /shim/with-selector.js` ] : `${ VENDOR_DEP_NAME } /shim/with-selector` ,
2144- }
2131+
2132+ // https://github.com/facebook/react/blob/c499adf8c89bbfd884f4d3a58c4e510001383525/packages/use-sync-external-store/package.json#L5-L20
2133+ const exports = [
2134+ 'use-sync-external-store' ,
2135+ 'use-sync-external-store/with-selector' ,
2136+ 'use-sync-external-store/with-selector.js' ,
2137+ 'use-sync-external-store/shim' ,
2138+ 'use-sync-external-store/shim/index.js' ,
2139+ 'use-sync-external-store/shim/with-selector' ,
2140+ 'use-sync-external-store/shim/with-selector.js' ,
2141+ ]
21452142
21462143 return [
21472144 {
@@ -2152,29 +2149,13 @@ function vendorUseSyncExternalStorePlugin(): Plugin[] {
21522149 environments : {
21532150 ssr : {
21542151 optimizeDeps : {
2155- include : [ ... new Set ( Object . values ( alias ) ) ] ,
2152+ include : exports . map ( ( e ) => ` ${ PKG_NAME } > ${ e } ` ) ,
21562153 } ,
21572154 } ,
21582155 } ,
21592156 }
21602157 } ,
21612158 } ,
2162- // TODO: why not alias?
2163- {
2164- name : 'rsc:vendor-use-sync-external-store:resolve' ,
2165- applyToEnvironment : ( e ) => e . name === 'ssr' ,
2166- enforce : 'pre' ,
2167- resolveId : {
2168- order : 'pre' ,
2169- async handler ( source ) {
2170- const target = alias [ source ]
2171- if ( target ) {
2172- const resolved = await this . resolve ( target )
2173- return resolved
2174- }
2175- } ,
2176- } ,
2177- } ,
21782159 ]
21792160}
21802161
0 commit comments