@vitejs/plugin-react
Advanced tools
+22
-55
@@ -17,18 +17,11 @@ import { dirname, join } from "node:path"; | ||
| const getPreambleCode = (base) => preambleCode.replace("__BASE__", base); | ||
| const avoidSourceMapOption = Symbol(); | ||
| function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") { | ||
| function addRefreshWrapper(code, pluginName, id, reactRefreshHost = "") { | ||
| const hasRefresh = refreshContentRE.test(code); | ||
| const onlyReactComp = !hasRefresh && reactCompRE.test(code); | ||
| const normalizedMap = map === avoidSourceMapOption ? null : map; | ||
| if (!hasRefresh && !onlyReactComp) return { | ||
| code, | ||
| map: normalizedMap | ||
| }; | ||
| const avoidSourceMap = map === avoidSourceMapOption; | ||
| const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap; | ||
| if (!hasRefresh && !onlyReactComp) return void 0; | ||
| let newCode = code; | ||
| if (hasRefresh) { | ||
| const refreshHead = removeLineBreaksIfNeeded(`let prevRefreshReg; | ||
| let prevRefreshSig; | ||
| newCode += ` | ||
| import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}"; | ||
| const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope; | ||
| if (import.meta.hot && !inWebWorker) { | ||
@@ -41,25 +34,2 @@ if (!window.$RefreshReg$) { | ||
| prevRefreshReg = window.$RefreshReg$; | ||
| prevRefreshSig = window.$RefreshSig$; | ||
| window.$RefreshReg$ = RefreshRuntime.getRefreshReg(${JSON.stringify(id)}); | ||
| window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform; | ||
| } | ||
| `, avoidSourceMap); | ||
| newCode = `${refreshHead}${newCode} | ||
| if (import.meta.hot && !inWebWorker) { | ||
| window.$RefreshReg$ = prevRefreshReg; | ||
| window.$RefreshSig$ = prevRefreshSig; | ||
| } | ||
| `; | ||
| if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings; | ||
| } | ||
| const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}"; | ||
| const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope; | ||
| `, avoidSourceMap); | ||
| newCode = `${sharedHead}${newCode} | ||
| if (import.meta.hot && !inWebWorker) { | ||
| RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => { | ||
@@ -75,11 +45,7 @@ RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports); | ||
| `; | ||
| if (newMap) newMap.mappings = ";;;" + newMap.mappings; | ||
| return { | ||
| code: newCode, | ||
| map: newMap | ||
| }; | ||
| if (hasRefresh) newCode += `function $RefreshReg$(type, id) { return RefreshRuntime.register(type, ${JSON.stringify(id)} + ' ' + id) } | ||
| function $RefreshSig$() { return RefreshRuntime.createSignatureFunctionForTransform(); } | ||
| `; | ||
| return newCode; | ||
| } | ||
| function removeLineBreaksIfNeeded(code, enabled) { | ||
| return enabled ? code.replace(/\n/g, "") : code; | ||
| } | ||
@@ -133,4 +99,4 @@ //#endregion | ||
| }, | ||
| jsxRefreshInclude: include, | ||
| jsxRefreshExclude: exclude | ||
| jsxRefreshInclude: makeIdFiltersToMatchWithQuery(include), | ||
| jsxRefreshExclude: makeIdFiltersToMatchWithQuery(exclude) | ||
| } }; | ||
@@ -144,4 +110,4 @@ else return { | ||
| }, | ||
| jsxRefreshInclude: include, | ||
| jsxRefreshExclude: exclude | ||
| jsxRefreshInclude: makeIdFiltersToMatchWithQuery(include), | ||
| jsxRefreshExclude: makeIdFiltersToMatchWithQuery(exclude) | ||
| }, | ||
@@ -220,4 +186,3 @@ optimizeDeps: { rollupOptions: { transform: { jsx: { runtime: "automatic" } } } } | ||
| if (tsRE.test(filepath)) parserPlugins.push("typescript"); | ||
| const babel$1 = await loadBabel(); | ||
| const result = await babel$1.transformAsync(code, { | ||
| const result = await (await loadBabel()).transformAsync(code, { | ||
| ...babelOptions, | ||
@@ -247,3 +212,6 @@ root: projectRoot, | ||
| }; | ||
| return addRefreshWrapper(result.code, result.map, "@vitejs/plugin-react", id, opts.reactRefreshHost); | ||
| return { | ||
| code: addRefreshWrapper(result.code, "@vitejs/plugin-react", id, opts.reactRefreshHost) ?? result.code, | ||
| map: result.map | ||
| }; | ||
| } | ||
@@ -265,9 +233,8 @@ } | ||
| const isJSX = filepath.endsWith("x"); | ||
| const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)); | ||
| if (!useFastRefresh) return; | ||
| const { code: newCode } = addRefreshWrapper(code, avoidSourceMapOption, "@vitejs/plugin-react", id, opts.reactRefreshHost); | ||
| return { | ||
| if (!(!skipFastRefresh && !ssr && (isJSX || code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)))) return; | ||
| const newCode = addRefreshWrapper(code, "@vitejs/plugin-react", id, opts.reactRefreshHost); | ||
| return newCode ? { | ||
| code: newCode, | ||
| map: null | ||
| }; | ||
| } : void 0; | ||
| } | ||
@@ -274,0 +241,0 @@ } |
@@ -246,3 +246,3 @@ /* global window */ | ||
| function register(type, id) { | ||
| export function register(type, id) { | ||
| if (type === null) { | ||
@@ -568,6 +568,2 @@ return | ||
| export function getRefreshReg(filename) { | ||
| return (type, id) => register(type, filename + ' ' + id) | ||
| } | ||
| // Taken from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/lib/runtime/RefreshUtils.js#L141 | ||
@@ -658,6 +654,3 @@ // This allows to resister components not detected by SWC like styled component | ||
| for (const key in moduleExports) { | ||
| if (key === '__esModule') continue | ||
| if (ignoredExports.includes(key)) continue | ||
| const desc = Object.getOwnPropertyDescriptor(moduleExports, key) | ||
| if (desc && desc.get) return key | ||
| if (!predicate(key, moduleExports[key])) return key | ||
@@ -664,0 +657,0 @@ } |
+5
-5
| { | ||
| "name": "@vitejs/plugin-react", | ||
| "version": "5.0.2", | ||
| "version": "5.0.3", | ||
| "license": "MIT", | ||
@@ -43,6 +43,6 @@ "author": "Evan You", | ||
| "dependencies": { | ||
| "@babel/core": "^7.28.3", | ||
| "@babel/core": "^7.28.4", | ||
| "@babel/plugin-transform-react-jsx-self": "^7.27.1", | ||
| "@babel/plugin-transform-react-jsx-source": "^7.27.1", | ||
| "@rolldown/pluginutils": "1.0.0-beta.34", | ||
| "@rolldown/pluginutils": "1.0.0-beta.35", | ||
| "@types/babel__core": "^7.20.5", | ||
@@ -56,6 +56,6 @@ "react-refresh": "^0.17.0" | ||
| "@vitejs/react-common": "workspace:*", | ||
| "babel-plugin-react-compiler": "19.1.0-rc.2", | ||
| "babel-plugin-react-compiler": "19.1.0-rc.3", | ||
| "react": "^19.1.1", | ||
| "react-dom": "^19.1.1", | ||
| "rolldown": "1.0.0-beta.34", | ||
| "rolldown": "1.0.0-beta.35", | ||
| "tsdown": "^0.14.2", | ||
@@ -62,0 +62,0 @@ "vitest": "^3.2.4" |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
43284
-2.52%993
-3.4%+ Added
- Removed
Updated