Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-otters-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react-rsbuild-plugin": patch
---

Add alias for `use-sync-external-store/with-selector.js` and `use-sync-external-store/shim/with-selector.js` pointing to @lynx-js/use-sync-external-store.
Original file line number Diff line number Diff line change
Expand Up @@ -343,38 +343,40 @@ describe('pluginReactLynx', () => {
const config = await rslib.inspectConfig()
expect(config.origin.bundlerConfigs[0]!.resolve!.alias)
.toMatchInlineSnapshot(`
{
"@lynx-js/preact-devtools$": false,
"@lynx-js/react$": "<WORKSPACE>/packages/react/runtime/lib/index.js",
"@lynx-js/react/compat$": "<WORKSPACE>/packages/react/runtime/compat/index.js",
"@lynx-js/react/debug$": false,
"@lynx-js/react/experimental/lazy/import$": "<WORKSPACE>/packages/react/runtime/lazy/import.js",
"@lynx-js/react/internal$": "<WORKSPACE>/packages/react/runtime/lib/internal.js",
"@lynx-js/react/legacy-react-runtime$": "<WORKSPACE>/packages/react/runtime/lib/legacy-react-runtime/index.js",
"@lynx-js/react/runtime-components$": "<WORKSPACE>/packages/react/components/lib/index.js",
"@lynx-js/react/worklet-runtime/bindings$": "<WORKSPACE>/packages/react/worklet-runtime/lib/bindings/index.js",
"@swc/helpers": "<WORKSPACE>/node_modules/<PNPM_INNER>/@swc/helpers",
"preact$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/dist/preact.mjs",
"preact/compat$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/dist/compat.mjs",
"preact/compat/client$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/client.mjs",
"preact/compat/jsx-dev-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/jsx-dev-runtime.mjs",
"preact/compat/jsx-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/jsx-runtime.mjs",
"preact/compat/scheduler$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/scheduler.mjs",
"preact/compat/server$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/server.mjs",
"preact/debug$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/debug/dist/debug.mjs",
"preact/devtools$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/devtools/dist/devtools.mjs",
"preact/hooks$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/hooks/dist/hooks.mjs",
"preact/jsx-dev-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/jsx-runtime/dist/jsxRuntime.mjs",
"preact/jsx-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/jsx-runtime/dist/jsxRuntime.mjs",
"preact/test-utils$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/test-utils/dist/testUtils.mjs",
"react$": "<WORKSPACE>/packages/react/runtime/lib/index.js",
"react-compiler-runtime": "<WORKSPACE>/node_modules/<PNPM_INNER>/react-compiler-runtime",
"use-sync-external-store$": "<WORKSPACE>/packages/use-sync-external-store/index.js",
"use-sync-external-store/shim$": "<WORKSPACE>/packages/use-sync-external-store/index.js",
"use-sync-external-store/shim/with-selector$": "<WORKSPACE>/packages/use-sync-external-store/with-selector.js",
"use-sync-external-store/with-selector$": "<WORKSPACE>/packages/use-sync-external-store/with-selector.js",
}
`)
{
"@lynx-js/preact-devtools$": false,
"@lynx-js/react$": "<WORKSPACE>/packages/react/runtime/lib/index.js",
"@lynx-js/react/compat$": "<WORKSPACE>/packages/react/runtime/compat/index.js",
"@lynx-js/react/debug$": false,
"@lynx-js/react/experimental/lazy/import$": "<WORKSPACE>/packages/react/runtime/lazy/import.js",
"@lynx-js/react/internal$": "<WORKSPACE>/packages/react/runtime/lib/internal.js",
"@lynx-js/react/legacy-react-runtime$": "<WORKSPACE>/packages/react/runtime/lib/legacy-react-runtime/index.js",
"@lynx-js/react/runtime-components$": "<WORKSPACE>/packages/react/components/lib/index.js",
"@lynx-js/react/worklet-runtime/bindings$": "<WORKSPACE>/packages/react/worklet-runtime/lib/bindings/index.js",
"@swc/helpers": "<WORKSPACE>/node_modules/<PNPM_INNER>/@swc/helpers",
"preact$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/dist/preact.mjs",
"preact/compat$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/dist/compat.mjs",
"preact/compat/client$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/client.mjs",
"preact/compat/jsx-dev-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/jsx-dev-runtime.mjs",
"preact/compat/jsx-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/jsx-runtime.mjs",
"preact/compat/scheduler$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/scheduler.mjs",
"preact/compat/server$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/compat/server.mjs",
"preact/debug$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/debug/dist/debug.mjs",
"preact/devtools$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/devtools/dist/devtools.mjs",
"preact/hooks$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/hooks/dist/hooks.mjs",
"preact/jsx-dev-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/jsx-runtime/dist/jsxRuntime.mjs",
"preact/jsx-runtime$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/jsx-runtime/dist/jsxRuntime.mjs",
"preact/test-utils$": "<WORKSPACE>/node_modules/<PNPM_INNER>/@hongzhiyuan/preact/test-utils/dist/testUtils.mjs",
"react$": "<WORKSPACE>/packages/react/runtime/lib/index.js",
"react-compiler-runtime": "<WORKSPACE>/node_modules/<PNPM_INNER>/react-compiler-runtime",
"use-sync-external-store$": "<WORKSPACE>/packages/use-sync-external-store/index.js",
"use-sync-external-store/shim$": "<WORKSPACE>/packages/use-sync-external-store/index.js",
"use-sync-external-store/shim/with-selector$": "<WORKSPACE>/packages/use-sync-external-store/with-selector.js",
"use-sync-external-store/shim/with-selector.js$": "<WORKSPACE>/packages/use-sync-external-store/with-selector.js",
"use-sync-external-store/with-selector$": "<WORKSPACE>/packages/use-sync-external-store/with-selector.js",
"use-sync-external-store/with-selector.js$": "<WORKSPACE>/packages/use-sync-external-store/with-selector.js",
}
`)
})

it('should handle macros', () => {
Expand Down
11 changes: 7 additions & 4 deletions packages/rspeedy/plugin-react/src/useSyncExternalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ export function applyUseSyncExternalStore(api: RsbuildPluginAPI): void {
const useSyncExternalStoreEntries = [
'use-sync-external-store',
'use-sync-external-store/with-selector',
'use-sync-external-store/with-selector.js',
'use-sync-external-store/shim',
'use-sync-external-store/shim/with-selector',
'use-sync-external-store/shim/with-selector.js',
]

await Promise.all(
useSyncExternalStoreEntries.map(entry =>
resolve(`@lynx-js/${entry}`).then(value => {
useSyncExternalStoreEntries.map(key => {
const entry = key.endsWith('.js') ? key.replace('.js', '') : key
return resolve(`@lynx-js/${entry}`).then(value => {
chain
.resolve
.alias
.set(`${entry}$`, value)
.set(`${key}$`, value)
})
),
}),
)
})
}
12 changes: 12 additions & 0 deletions packages/rspeedy/plugin-react/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ describe('Config', () => {
'/use-sync-external-store/with-selector.js'.replaceAll('/', path.sep),
),
)
expect(config.resolve.alias).toHaveProperty(
'use-sync-external-store/with-selector.js$',
expect.stringContaining(
'/use-sync-external-store/with-selector.js'.replaceAll('/', path.sep),
),
)
expect(config.resolve.alias).toHaveProperty(
'use-sync-external-store/shim$',
expect.stringContaining(
Expand All @@ -180,6 +186,12 @@ describe('Config', () => {
'/use-sync-external-store/with-selector.js'.replaceAll('/', path.sep),
),
)
expect(config.resolve.alias).toHaveProperty(
'use-sync-external-store/shim/with-selector.js$',
expect.stringContaining(
'/use-sync-external-store/with-selector.js'.replaceAll('/', path.sep),
),
)
})

test('alias with production', async () => {
Expand Down
Loading