-
Notifications
You must be signed in to change notification settings - Fork 54
fix: remove deprecated Vite customResolver usage #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Brentlok
merged 3 commits into
uni-stack:main
from
saseungmin:fix/vite-custom-resolver-deprecation
Sep 20, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| import path from 'node:path' | ||
| import { createServer, type Plugin, type UserConfig } from 'vite' | ||
| import { describe, expect, test, vi } from 'vitest' | ||
|
|
||
| import { uniwind } from '@/bundler/adapters/vite/vite' | ||
| import type { UniwindConfig } from '@/bundler/types' | ||
|
|
||
| const config: UniwindConfig = { | ||
| cssEntryFile: './tests/test.css', | ||
| } | ||
|
|
||
| const getPluginConfig = async (plugin: Plugin) => { | ||
| const hook = plugin.config | ||
|
|
||
| if (hook === undefined) { | ||
| throw new Error('Expected the Uniwind plugin to define a config hook') | ||
| } | ||
|
|
||
| const handler = typeof hook === 'function' ? hook : hook.handler | ||
|
|
||
| return await Reflect.apply(handler, {}, [ | ||
| {}, | ||
| { | ||
| command: 'build', | ||
| mode: 'test', | ||
| isSsrBuild: false, | ||
| isPreview: false, | ||
| }, | ||
| ]) as UserConfig | ||
| } | ||
|
|
||
| const getReactNativeAlias = async (plugin: Plugin) => { | ||
| const pluginConfig = await getPluginConfig(plugin) | ||
| const aliases = pluginConfig.resolve?.alias | ||
|
|
||
| if (!Array.isArray(aliases)) { | ||
| throw new TypeError('Expected the Uniwind plugin to define aliases as an array') | ||
| } | ||
|
|
||
| const alias = aliases[0] | ||
|
|
||
| if (alias === undefined || typeof alias === 'string') { | ||
| throw new TypeError('Expected the Uniwind plugin to define a React Native alias') | ||
| } | ||
|
|
||
| return alias | ||
| } | ||
|
|
||
| const runResolveId = async ( | ||
| plugin: Plugin, | ||
| context: { resolve: ReturnType<typeof vi.fn> }, | ||
| source: string, | ||
| importer: string | undefined, | ||
| ) => { | ||
| const hook = plugin.resolveId | ||
|
|
||
| if (hook === undefined) { | ||
| throw new Error('Expected the Uniwind plugin to define a resolveId hook') | ||
| } | ||
|
|
||
| const handler = typeof hook === 'function' ? hook : hook.handler | ||
|
|
||
| return await Reflect.apply(handler, context, [source, importer]) | ||
| } | ||
|
|
||
| describe('Vite adapter', () => { | ||
| test('avoids the deprecated customResolver with Vite 8', async () => { | ||
| const plugin = uniwind(config) | ||
| const alias = await getReactNativeAlias(plugin) | ||
|
|
||
| expect(alias).not.toHaveProperty('customResolver') | ||
| }) | ||
|
|
||
| test('resolves Uniwind internal React Native imports through React Native Web with Vite 8', async () => { | ||
| const plugin = uniwind(config) | ||
| const alias = await getReactNativeAlias(plugin) | ||
| const importer = path.resolve('node_modules/uniwind/dist/module/components/web/View.js').replaceAll('/', '\\') | ||
| const source = alias.replacement.replaceAll('/', '\\') | ||
| const resolved = { id: path.resolve('node_modules/react-native-web/index.js') } | ||
| const resolve = vi.fn().mockResolvedValue(resolved) | ||
|
|
||
| await expect(runResolveId(plugin, { resolve }, source, importer)).resolves.toBe(resolved) | ||
| expect(resolve).toHaveBeenCalledWith('react-native-web', importer, { skipSelf: true }) | ||
| }) | ||
|
|
||
| test('resolves an internal React Native import through the Vite plugin pipeline', async () => { | ||
| const plugin = uniwind(config) | ||
|
|
||
| plugin.buildStart = undefined | ||
| plugin.generateBundle = undefined | ||
|
|
||
| const server = await createServer({ | ||
| configFile: false, | ||
| logLevel: 'silent', | ||
| plugins: [plugin], | ||
| server: { middlewareMode: true }, | ||
| }) | ||
|
|
||
| try { | ||
| const importer = path.resolve('node_modules/uniwind/dist/module/components/web/View.js') | ||
| const resolved = await server.pluginContainer.resolveId('react-native', importer) | ||
| const expected = await server.pluginContainer.resolveId('react-native-web', importer) | ||
|
|
||
| expect(expected?.id).toBeDefined() | ||
| expect(resolved?.id).toBe(expected?.id) | ||
| } finally { | ||
| await server.close() | ||
| } | ||
| }) | ||
|
|
||
| test('leaves application React Native imports on the Uniwind component alias', async () => { | ||
| const plugin = uniwind(config) | ||
| const alias = await getReactNativeAlias(plugin) | ||
| const resolve = vi.fn() | ||
|
|
||
| await expect(runResolveId( | ||
| plugin, | ||
| { resolve }, | ||
| alias.replacement, | ||
| path.resolve('src/App.tsx'), | ||
| )).resolves.toBeUndefined() | ||
| expect(resolve).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test.each( | ||
| [ | ||
| ['has no importer', undefined, 'component'], | ||
| ['does not target the component alias', 'internal', 'react-native'], | ||
| ] as const, | ||
| )('does not delegate when the import %s', async (_case, importerType, sourceType) => { | ||
| const plugin = uniwind(config) | ||
| const alias = await getReactNativeAlias(plugin) | ||
| const importer = importerType === 'internal' | ||
| ? path.resolve('node_modules/uniwind/dist/module/components/web/View.js') | ||
| : undefined | ||
| const source = sourceType === 'component' ? alias.replacement : sourceType | ||
| const resolve = vi.fn() | ||
|
|
||
| await expect(runResolveId(plugin, { resolve }, source, importer)).resolves.toBeUndefined() | ||
| expect(resolve).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('preserves ordered stylesheet resolution before React Native Web delegation', async () => { | ||
| const plugin = uniwind(config) | ||
| const importer = path.resolve( | ||
| 'node_modules/react-native-web/dist/exports/StyleSheet/index.js', | ||
| ) | ||
| const resolve = vi.fn() | ||
|
|
||
| const resolved = await runResolveId( | ||
| plugin, | ||
| { resolve }, | ||
| './createOrderedCSSStyleSheet', | ||
| importer, | ||
| ) | ||
|
|
||
| expect(resolved).toBe(path.resolve( | ||
| 'src/bundler/adapters/module/components/web/createOrderedCSSStyleSheet.js', | ||
| )) | ||
| expect(resolve).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.