Skip to content

Commit b1a31ae

Browse files
committed
refactor: use utils from @rolldown/pluginutils
1 parent cc23cdb commit b1a31ae

File tree

9 files changed

+31
-29
lines changed

9 files changed

+31
-29
lines changed

packages/common/filter-utils.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/common/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export * from './filter-utils'
21
export * from './refresh-utils'
32
export * from './warning'

packages/plugin-react-oxc/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@
4646
"@vitejs/react-common": "workspace:*",
4747
"unbuild": "^3.5.0",
4848
"vite": "catalog:rolldown-vite"
49+
},
50+
"dependencies": {
51+
"@rolldown/pluginutils": "1.0.0-beta.9"
4952
}
5053
}

packages/plugin-react-oxc/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import type { BuildOptions, Plugin, PluginOption } from 'vite'
55
import {
66
addRefreshWrapper,
77
avoidSourceMapOption,
8-
exactRegex,
98
getPreambleCode,
109
runtimePublicPath,
1110
silenceUseClientWarning,
1211
} from '@vitejs/react-common'
12+
import { exactRegex } from '@rolldown/pluginutils'
1313

1414
const _dirname = dirname(fileURLToPath(import.meta.url))
1515

packages/plugin-react-swc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc#readme",
3131
"dependencies": {
32+
"@rolldown/pluginutils": "1.0.0-beta.9",
3233
"@swc/core": "^1.11.22"
3334
},
3435
"peerDependencies": {

packages/plugin-react-swc/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import {
1414
import type { PluginOption } from 'vite'
1515
import {
1616
addRefreshWrapper,
17-
exactRegex,
1817
getPreambleCode,
1918
runtimePublicPath,
2019
silenceUseClientWarning,
2120
} from '@vitejs/react-common'
21+
import { exactRegex } from '@rolldown/pluginutils'
2222

2323
/* eslint-disable no-restricted-globals */
2424
const _dirname =

packages/plugin-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@babel/core": "^7.26.10",
5252
"@babel/plugin-transform-react-jsx-self": "^7.25.9",
5353
"@babel/plugin-transform-react-jsx-source": "^7.25.9",
54+
"@rolldown/pluginutils": "1.0.0-beta.9",
5455
"@types/babel__core": "^7.20.5",
5556
"react-refresh": "^0.17.0"
5657
},

packages/plugin-react/src/index.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import * as vite from 'vite'
88
import type { Plugin, PluginOption, ResolvedConfig } from 'vite'
99
import {
1010
addRefreshWrapper,
11-
exactRegex,
1211
getPreambleCode,
1312
preambleCode,
1413
runtimePublicPath,
1514
silenceUseClientWarning,
1615
} from '@vitejs/react-common'
16+
import {
17+
exactRegex,
18+
makeIdFiltersToMatchWithQuery,
19+
} from '@rolldown/pluginutils'
1720

1821
const _dirname = dirname(fileURLToPath(import.meta.url))
1922

@@ -198,9 +201,11 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
198201
transform: {
199202
filter: {
200203
id: {
201-
include: ensureArray(include).map(matchWithQuery),
204+
include: makeIdFiltersToMatchWithQuery(include),
202205
exclude: [
203-
...(exclude ? ensureArray(exclude).map(matchWithQuery) : []),
206+
...(exclude
207+
? makeIdFiltersToMatchWithQuery(ensureArray(exclude))
208+
: []),
204209
/\/node_modules\//,
205210
],
206211
},
@@ -448,18 +453,3 @@ function getReactCompilerRuntimeModule(
448453
function ensureArray<T>(value: T | T[]): T[] {
449454
return Array.isArray(value) ? value : [value]
450455
}
451-
452-
function matchWithQuery(input: string | RegExp) {
453-
if (typeof input === 'string') {
454-
return `${input}{?*,}`
455-
}
456-
return addQueryToRegex(input)
457-
}
458-
459-
function addQueryToRegex(input: RegExp) {
460-
return new RegExp(
461-
// replace `$` with `(?:\?.*)?$` (ignore `\$`)
462-
input.source.replace(/(?<!\\)\$/g, '(?:\\?.*)?$'),
463-
input.flags,
464-
)
465-
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)