Skip to content

Commit b76b27e

Browse files
committed
refactor: simplify
1 parent faf29d3 commit b76b27e

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

packages/plugin-rsc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"magic-string": "^0.30.17",
4545
"periscopic": "^4.0.2",
4646
"turbo-stream": "^3.1.0",
47+
"use-sync-external-store": "^1.5.0",
4748
"vitefu": "^1.1.1"
4849
},
4950
"devDependencies": {
@@ -61,7 +62,6 @@
6162
"rsc-html-stream": "^0.0.7",
6263
"tinyexec": "^1.0.1",
6364
"tsdown": "^0.13.2",
64-
"use-sync-external-store": "^1.5.0",
6565
"vite-plugin-inspect": "^11.3.2"
6666
},
6767
"peerDependencies": {

packages/plugin-rsc/src/plugin.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,20 +2128,17 @@ function validateImportPlugin(): Plugin {
21282128
function 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

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)