@vitejs/plugin-react-swc 3.6.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +16 -12
- package/index.mjs +16 -12
- package/package.json +2 -2
- package/refresh-runtime.js +7 -14
package/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ var _dirname = typeof __dirname !== "undefined" ? __dirname : (0, import_path.di
|
|
|
14
14
|
var resolve = (0, import_module.createRequire)(
|
|
15
15
|
typeof __filename !== "undefined" ? __filename : import_meta.url
|
|
16
16
|
).resolve;
|
|
17
|
+
var reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
|
17
18
|
var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
18
19
|
var _a, _b;
|
|
19
20
|
var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b.webcontainer;
|
|
@@ -46,8 +47,7 @@ var react = (_options) => {
|
|
|
46
47
|
}
|
|
47
48
|
}),
|
|
48
49
|
configResolved(config) {
|
|
49
|
-
if (config.server.hmr === false)
|
|
50
|
-
hmrDisabled = true;
|
|
50
|
+
if (config.server.hmr === false) hmrDisabled = true;
|
|
51
51
|
const mdxIndex = config.plugins.findIndex(
|
|
52
52
|
(p) => p.name === "@mdx-js/rollup"
|
|
53
53
|
);
|
|
@@ -87,14 +87,18 @@ var react = (_options) => {
|
|
|
87
87
|
importSource: options.jsxImportSource
|
|
88
88
|
}
|
|
89
89
|
);
|
|
90
|
-
if (!result)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
if (!result) return;
|
|
91
|
+
if (!refresh) return result;
|
|
92
|
+
const hasRefresh = refreshContentRE.test(result.code);
|
|
93
|
+
if (!hasRefresh && !reactCompRE.test(result.code)) return result;
|
|
94
|
+
const sourceMap = JSON.parse(result.map);
|
|
95
|
+
sourceMap.mappings = ";;" + sourceMap.mappings;
|
|
95
96
|
result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
|
|
96
97
|
|
|
97
|
-
|
|
98
|
+
${result.code}`;
|
|
99
|
+
if (hasRefresh) {
|
|
100
|
+
sourceMap.mappings = ";;;;;;" + sourceMap.mappings;
|
|
101
|
+
result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
98
102
|
const prevRefreshReg = window.$RefreshReg$;
|
|
99
103
|
const prevRefreshSig = window.$RefreshSig$;
|
|
100
104
|
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
@@ -104,6 +108,9 @@ ${result.code}
|
|
|
104
108
|
|
|
105
109
|
window.$RefreshReg$ = prevRefreshReg;
|
|
106
110
|
window.$RefreshSig$ = prevRefreshSig;
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
result.code += `
|
|
107
114
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
108
115
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
109
116
|
import.meta.hot.accept((nextExports) => {
|
|
@@ -113,8 +120,6 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
|
113
120
|
});
|
|
114
121
|
});
|
|
115
122
|
`;
|
|
116
|
-
const sourceMap = JSON.parse(result.map);
|
|
117
|
-
sourceMap.mappings = ";;;;;;;;" + sourceMap.mappings;
|
|
118
123
|
return { code: result.code, map: sourceMap };
|
|
119
124
|
}
|
|
120
125
|
},
|
|
@@ -152,8 +157,7 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
152
157
|
// JSX is required to trigger fast refresh transformations, even if MDX already transforms it
|
|
153
158
|
{ syntax: "ecmascript", jsx: true }
|
|
154
159
|
) : void 0;
|
|
155
|
-
if (!parser)
|
|
156
|
-
return;
|
|
160
|
+
if (!parser) return;
|
|
157
161
|
let result;
|
|
158
162
|
try {
|
|
159
163
|
result = await (0, import_core.transform)(code, {
|
package/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ var _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToP
|
|
|
15
15
|
var resolve = createRequire(
|
|
16
16
|
typeof __filename !== "undefined" ? __filename : import.meta.url
|
|
17
17
|
).resolve;
|
|
18
|
+
var reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
|
18
19
|
var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
19
20
|
var _a, _b;
|
|
20
21
|
var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b.webcontainer;
|
|
@@ -47,8 +48,7 @@ var react = (_options) => {
|
|
|
47
48
|
}
|
|
48
49
|
}),
|
|
49
50
|
configResolved(config) {
|
|
50
|
-
if (config.server.hmr === false)
|
|
51
|
-
hmrDisabled = true;
|
|
51
|
+
if (config.server.hmr === false) hmrDisabled = true;
|
|
52
52
|
const mdxIndex = config.plugins.findIndex(
|
|
53
53
|
(p) => p.name === "@mdx-js/rollup"
|
|
54
54
|
);
|
|
@@ -88,14 +88,18 @@ var react = (_options) => {
|
|
|
88
88
|
importSource: options.jsxImportSource
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
|
-
if (!result)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
if (!result) return;
|
|
92
|
+
if (!refresh) return result;
|
|
93
|
+
const hasRefresh = refreshContentRE.test(result.code);
|
|
94
|
+
if (!hasRefresh && !reactCompRE.test(result.code)) return result;
|
|
95
|
+
const sourceMap = JSON.parse(result.map);
|
|
96
|
+
sourceMap.mappings = ";;" + sourceMap.mappings;
|
|
96
97
|
result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
${result.code}`;
|
|
100
|
+
if (hasRefresh) {
|
|
101
|
+
sourceMap.mappings = ";;;;;;" + sourceMap.mappings;
|
|
102
|
+
result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
99
103
|
const prevRefreshReg = window.$RefreshReg$;
|
|
100
104
|
const prevRefreshSig = window.$RefreshSig$;
|
|
101
105
|
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
@@ -105,6 +109,9 @@ ${result.code}
|
|
|
105
109
|
|
|
106
110
|
window.$RefreshReg$ = prevRefreshReg;
|
|
107
111
|
window.$RefreshSig$ = prevRefreshSig;
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
result.code += `
|
|
108
115
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
109
116
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
110
117
|
import.meta.hot.accept((nextExports) => {
|
|
@@ -114,8 +121,6 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
|
114
121
|
});
|
|
115
122
|
});
|
|
116
123
|
`;
|
|
117
|
-
const sourceMap = JSON.parse(result.map);
|
|
118
|
-
sourceMap.mappings = ";;;;;;;;" + sourceMap.mappings;
|
|
119
124
|
return { code: result.code, map: sourceMap };
|
|
120
125
|
}
|
|
121
126
|
},
|
|
@@ -153,8 +158,7 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
|
|
|
153
158
|
// JSX is required to trigger fast refresh transformations, even if MDX already transforms it
|
|
154
159
|
{ syntax: "ecmascript", jsx: true }
|
|
155
160
|
) : void 0;
|
|
156
|
-
if (!parser)
|
|
157
|
-
return;
|
|
161
|
+
if (!parser) return;
|
|
158
162
|
let result;
|
|
159
163
|
try {
|
|
160
164
|
result = await transform(code, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-react-swc",
|
|
3
3
|
"description": "Speed up your Vite dev server with SWC",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.7.0",
|
|
5
5
|
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:vitejs/vite-plugin-react-swc",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"vite": "^4 || ^5"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@swc/core": "^1.
|
|
31
|
+
"@swc/core": "^1.5.7"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/refresh-runtime.js
CHANGED
|
@@ -374,8 +374,7 @@ function getRefreshReg(filename) {
|
|
|
374
374
|
}
|
|
375
375
|
function registerExportsForReactRefresh(filename, moduleExports) {
|
|
376
376
|
for (const key in moduleExports) {
|
|
377
|
-
if (key === "__esModule")
|
|
378
|
-
continue;
|
|
377
|
+
if (key === "__esModule") continue;
|
|
379
378
|
const exportValue = moduleExports[key];
|
|
380
379
|
if (isLikelyComponentType(exportValue)) {
|
|
381
380
|
register(exportValue, filename + " export " + key);
|
|
@@ -394,8 +393,7 @@ window.__registerBeforePerformReactRefresh = (cb) => {
|
|
|
394
393
|
hooks.push(cb);
|
|
395
394
|
};
|
|
396
395
|
const enqueueUpdate = debounce(async () => {
|
|
397
|
-
if (hooks.length)
|
|
398
|
-
await Promise.all(hooks.map((cb) => cb()));
|
|
396
|
+
if (hooks.length) await Promise.all(hooks.map((cb) => cb()));
|
|
399
397
|
performReactRefresh();
|
|
400
398
|
}, 16);
|
|
401
399
|
function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
|
|
@@ -421,8 +419,7 @@ function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
|
|
|
421
419
|
nextExports,
|
|
422
420
|
(key, value) => {
|
|
423
421
|
hasExports = true;
|
|
424
|
-
if (isLikelyComponentType(value))
|
|
425
|
-
return true;
|
|
422
|
+
if (isLikelyComponentType(value)) return true;
|
|
426
423
|
return prevExports[key] === nextExports[key];
|
|
427
424
|
}
|
|
428
425
|
);
|
|
@@ -434,15 +431,11 @@ function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
|
|
|
434
431
|
}
|
|
435
432
|
function predicateOnExport(ignoredExports, moduleExports, predicate) {
|
|
436
433
|
for (const key in moduleExports) {
|
|
437
|
-
if (key === "__esModule")
|
|
438
|
-
|
|
439
|
-
if (ignoredExports.includes(key))
|
|
440
|
-
continue;
|
|
434
|
+
if (key === "__esModule") continue;
|
|
435
|
+
if (ignoredExports.includes(key)) continue;
|
|
441
436
|
const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
|
|
442
|
-
if (desc && desc.get)
|
|
443
|
-
|
|
444
|
-
if (!predicate(key, moduleExports[key]))
|
|
445
|
-
return key;
|
|
437
|
+
if (desc && desc.get) return key;
|
|
438
|
+
if (!predicate(key, moduleExports[key])) return key;
|
|
446
439
|
}
|
|
447
440
|
return true;
|
|
448
441
|
}
|