@vxrn/compiler 1.25.3 → 1.25.5
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/package.json +3 -3
- package/src/index.ts +5 -0
- package/src/transformBabel.test.ts +44 -2
- package/src/transformBabel.ts +2 -7
- package/src/types.ts +1 -0
- package/types/types.d.ts +1 -0
- package/dist/cjs/cache.cjs +0 -132
- package/dist/cjs/configure.cjs +0 -37
- package/dist/cjs/constants.cjs +0 -77
- package/dist/cjs/index.cjs +0 -425
- package/dist/cjs/refresh-runtime.cjs +0 -452
- package/dist/cjs/transformBabel.cjs +0 -271
- package/dist/cjs/transformBabel.test.cjs +0 -19
- package/dist/cjs/transformSWC.cjs +0 -318
- package/dist/cjs/types.cjs +0 -18
- package/dist/esm/cache.mjs +0 -104
- package/dist/esm/cache.mjs.map +0 -1
- package/dist/esm/configure.mjs +0 -11
- package/dist/esm/configure.mjs.map +0 -1
- package/dist/esm/constants.mjs +0 -48
- package/dist/esm/constants.mjs.map +0 -1
- package/dist/esm/index.js +0 -398
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs +0 -398
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/refresh-runtime.mjs +0 -421
- package/dist/esm/refresh-runtime.mjs.map +0 -1
- package/dist/esm/transformBabel.mjs +0 -233
- package/dist/esm/transformBabel.mjs.map +0 -1
- package/dist/esm/transformBabel.test.mjs +0 -20
- package/dist/esm/transformBabel.test.mjs.map +0 -1
- package/dist/esm/transformSWC.mjs +0 -292
- package/dist/esm/transformSWC.mjs.map +0 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.mjs.map +0 -1
- package/types/cache.d.ts.map +0 -1
- package/types/configure.d.ts.map +0 -1
- package/types/constants.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/transformBabel.d.ts.map +0 -1
- package/types/transformBabel.test.d.ts.map +0 -1
- package/types/transformSWC.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
package/dist/cjs/index.cjs
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all) __defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: () => from[key],
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
22
|
-
value: true
|
|
23
|
-
}), mod);
|
|
24
|
-
var index_exports = {};
|
|
25
|
-
__export(index_exports, {
|
|
26
|
-
createVXRNCompilerPlugin: () => createVXRNCompilerPlugin
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
var import_node_fs = require("node:fs");
|
|
30
|
-
var import_promises = require("node:fs/promises");
|
|
31
|
-
var import_node_path = require("node:path");
|
|
32
|
-
var import_node_url = require("node:url");
|
|
33
|
-
var import_utils = require("@vxrn/utils");
|
|
34
|
-
var import_css_to_rn = require("react-native-css-interop/css-to-rn/index.js");
|
|
35
|
-
var import_configure = require("./configure.cjs");
|
|
36
|
-
var import_constants = require("./constants.cjs");
|
|
37
|
-
var import_transformBabel = require("./transformBabel.cjs");
|
|
38
|
-
var import_cache = require("./cache.cjs");
|
|
39
|
-
__reExport(index_exports, require("./configure.cjs"), module.exports);
|
|
40
|
-
__reExport(index_exports, require("./transformBabel.cjs"), module.exports);
|
|
41
|
-
__reExport(index_exports, require("./transformSWC.cjs"), module.exports);
|
|
42
|
-
const import_meta = {};
|
|
43
|
-
const perfStats = {
|
|
44
|
-
babel: {
|
|
45
|
-
totalCalls: 0,
|
|
46
|
-
totalTransforms: 0,
|
|
47
|
-
totalTime: 0,
|
|
48
|
-
byEnvironment: {}
|
|
49
|
-
},
|
|
50
|
-
optimizeDeps: {
|
|
51
|
-
byEnvironment: {}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
function logPerfSummary() {
|
|
55
|
-
if (!process.env.DEBUG_COMPILER_PERF) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
console.info("\n\u{1F4CA} [Compiler Performance Summary]");
|
|
59
|
-
console.info(`Babel: ${perfStats.babel.totalTransforms} transforms / ${perfStats.babel.totalCalls} calls (${(perfStats.babel.totalTransforms / Math.max(perfStats.babel.totalCalls, 1) * 100).toFixed(1)}% transform rate)`);
|
|
60
|
-
console.info(`Babel total time: ${perfStats.babel.totalTime}ms`);
|
|
61
|
-
for (const [env, stats] of Object.entries(perfStats.babel.byEnvironment)) {
|
|
62
|
-
if (stats.transforms > 0) {
|
|
63
|
-
console.info(` ${env}: ${stats.transforms} transforms, ${stats.time}ms (${(stats.time / stats.transforms).toFixed(1)}ms avg)`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
for (const [env, stats] of Object.entries(perfStats.optimizeDeps.byEnvironment)) {
|
|
67
|
-
const elapsed = Date.now() - stats.startTime;
|
|
68
|
-
console.info(`optimizeDeps ${env}: checked ${stats.filesChecked} files, transformed ${stats.filesTransformed} (${elapsed}ms)`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const compilerLog = {
|
|
72
|
-
compiled: 0,
|
|
73
|
-
cached: 0,
|
|
74
|
-
time: 0,
|
|
75
|
-
// typed loose because the dom lib types setTimeout as number, but node gives
|
|
76
|
-
// us a Timeout we need to unref so the debounce never holds the process open
|
|
77
|
-
timer: null
|
|
78
|
-
};
|
|
79
|
-
function logCompiled(cached, ms) {
|
|
80
|
-
if (cached) {
|
|
81
|
-
compilerLog.cached++;
|
|
82
|
-
} else {
|
|
83
|
-
compilerLog.compiled++;
|
|
84
|
-
compilerLog.time += ms;
|
|
85
|
-
}
|
|
86
|
-
if (compilerLog.timer) clearTimeout(compilerLog.timer);
|
|
87
|
-
compilerLog.timer = setTimeout(() => {
|
|
88
|
-
const total = compilerLog.compiled + compilerLog.cached;
|
|
89
|
-
const detail = compilerLog.compiled ? `${compilerLog.compiled} compiled in ${compilerLog.time}ms${compilerLog.cached ? `, ${compilerLog.cached} cached` : ""}` : `all cached`;
|
|
90
|
-
console.info(` \u{1FA84} [compiler] ${total} file${total === 1 ? "" : "s"} (${detail})`);
|
|
91
|
-
compilerLog.compiled = 0;
|
|
92
|
-
compilerLog.cached = 0;
|
|
93
|
-
compilerLog.time = 0;
|
|
94
|
-
compilerLog.timer = null;
|
|
95
|
-
}, 500);
|
|
96
|
-
compilerLog.timer.unref?.();
|
|
97
|
-
}
|
|
98
|
-
async function performBabelTransform({
|
|
99
|
-
id,
|
|
100
|
-
code,
|
|
101
|
-
environment,
|
|
102
|
-
production,
|
|
103
|
-
reactForRNVersion,
|
|
104
|
-
optionsIn
|
|
105
|
-
}) {
|
|
106
|
-
perfStats.babel.totalCalls++;
|
|
107
|
-
if (!perfStats.babel.byEnvironment[environment]) {
|
|
108
|
-
perfStats.babel.byEnvironment[environment] = {
|
|
109
|
-
calls: 0,
|
|
110
|
-
transforms: 0,
|
|
111
|
-
time: 0
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
perfStats.babel.byEnvironment[environment].calls++;
|
|
115
|
-
const transformProps = {
|
|
116
|
-
id,
|
|
117
|
-
code,
|
|
118
|
-
development: !production,
|
|
119
|
-
environment,
|
|
120
|
-
reactForRNVersion
|
|
121
|
-
};
|
|
122
|
-
const userTransform = optionsIn?.transform?.(transformProps);
|
|
123
|
-
if (userTransform === false) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
if (userTransform !== "swc") {
|
|
127
|
-
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
128
|
-
...transformProps,
|
|
129
|
-
userSetting: userTransform
|
|
130
|
-
});
|
|
131
|
-
if (babelOptions) {
|
|
132
|
-
const hasCompilerPlugin = babelOptions.plugins?.some(x => Array.isArray(x) && x[0] === "babel-plugin-react-compiler");
|
|
133
|
-
const cached = (0, import_cache.getCachedTransform)(id, code, environment);
|
|
134
|
-
if (cached) {
|
|
135
|
-
perfStats.babel.byEnvironment[environment].transforms++;
|
|
136
|
-
if (hasCompilerPlugin && (cached.code.includes("react/compiler-runtime") || cached.code.includes("react-compiler-runtime"))) {
|
|
137
|
-
(0, import_constants.debug)?.(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)} (cached)`);
|
|
138
|
-
logCompiled(true, 0);
|
|
139
|
-
}
|
|
140
|
-
(0, import_constants.debug)?.(`[babel/cached] ${id}`);
|
|
141
|
-
return cached;
|
|
142
|
-
}
|
|
143
|
-
const compilerOnly = hasCompilerPlugin && babelOptions.plugins?.length === 1;
|
|
144
|
-
const compilerTarget = compilerOnly ? babelOptions.plugins[0][1]?.target ?? "19" : "19";
|
|
145
|
-
const startTime = Date.now();
|
|
146
|
-
const babelOut = compilerOnly ? await (0, import_transformBabel.transformOxcReactCompiler)(id, code, compilerTarget) : await (0, import_transformBabel.transformBabel)(id, code, babelOptions);
|
|
147
|
-
const babelTime = Date.now() - startTime;
|
|
148
|
-
if (babelOut?.code) {
|
|
149
|
-
perfStats.babel.totalTransforms++;
|
|
150
|
-
perfStats.babel.totalTime += babelTime;
|
|
151
|
-
perfStats.babel.byEnvironment[environment].transforms++;
|
|
152
|
-
perfStats.babel.byEnvironment[environment].time += babelTime;
|
|
153
|
-
if (hasCompilerPlugin && (babelOut.code.includes("react/compiler-runtime") || babelOut.code.includes("react-compiler-runtime"))) {
|
|
154
|
-
(0, import_constants.debug)?.(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)} (${babelTime}ms)`);
|
|
155
|
-
logCompiled(false, babelTime);
|
|
156
|
-
}
|
|
157
|
-
(0, import_constants.debug)?.(`[babel] ${id}`);
|
|
158
|
-
const outCode = `${babelOut.code}
|
|
159
|
-
// vxrn-did-babel`;
|
|
160
|
-
const result = {
|
|
161
|
-
code: outCode,
|
|
162
|
-
map: babelOut.map
|
|
163
|
-
};
|
|
164
|
-
(0, import_cache.setCachedTransform)(id, code, result, environment);
|
|
165
|
-
return result;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
async function createVXRNCompilerPlugin(optionsIn) {
|
|
172
|
-
const reactVersion = await (async () => {
|
|
173
|
-
const path = (0, import_utils.resolvePath)("react/package.json");
|
|
174
|
-
const json = JSON.parse(await (0, import_promises.readFile)(path, "utf-8"));
|
|
175
|
-
return json.version;
|
|
176
|
-
})();
|
|
177
|
-
const envNames = {
|
|
178
|
-
ios: true,
|
|
179
|
-
android: true,
|
|
180
|
-
client: true,
|
|
181
|
-
ssr: true
|
|
182
|
-
};
|
|
183
|
-
function getEnvName(name) {
|
|
184
|
-
if (!envNames[name]) throw new Error(`Invalid env: ${name}`);
|
|
185
|
-
return name;
|
|
186
|
-
}
|
|
187
|
-
const reactForRNVersion = reactVersion.split(".")[0];
|
|
188
|
-
const cssTransformCache = /* @__PURE__ */new Map();
|
|
189
|
-
const rolldownPath = (0, import_utils.resolvePath)("rolldown");
|
|
190
|
-
const rolldownNodeMods = rolldownPath.slice(0, rolldownPath.indexOf(import_node_path.sep + "node_modules"));
|
|
191
|
-
let config;
|
|
192
|
-
return [{
|
|
193
|
-
name: "one:compiler-resolve-refresh-runtime",
|
|
194
|
-
apply: "serve",
|
|
195
|
-
enforce: "pre",
|
|
196
|
-
// Run before Vite default resolve to avoid syscalls
|
|
197
|
-
resolveId: id => id === import_constants.runtimePublicPath || id === `${import_constants.runtimePublicPath}.map` ? id : void 0,
|
|
198
|
-
load: id => {
|
|
199
|
-
const basePath = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
200
|
-
if (id === import_constants.runtimePublicPath) {
|
|
201
|
-
return (0, import_node_fs.readFileSync)((0, import_node_path.join)(basePath, "refresh-runtime.mjs"), "utf-8").replace(/\/\/# sourceMappingURL=.*/, "");
|
|
202
|
-
}
|
|
203
|
-
if (id === `${import_constants.runtimePublicPath}.map`) {
|
|
204
|
-
return JSON.stringify({
|
|
205
|
-
version: 3,
|
|
206
|
-
sources: [],
|
|
207
|
-
mappings: ""
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
return void 0;
|
|
211
|
-
}
|
|
212
|
-
}, {
|
|
213
|
-
name: `one:compiler-css-to-js`,
|
|
214
|
-
// only .css files can match, so let rust reject everything else
|
|
215
|
-
transform: {
|
|
216
|
-
filter: {
|
|
217
|
-
id: /\.css$/
|
|
218
|
-
},
|
|
219
|
-
handler(codeIn, id) {
|
|
220
|
-
const environment = getEnvName(this.environment.name);
|
|
221
|
-
if (import_configure.configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
|
|
222
|
-
{
|
|
223
|
-
const data = JSON.stringify((0, import_css_to_rn.cssToReactNativeRuntime)(codeIn, {
|
|
224
|
-
inlineRem: 16
|
|
225
|
-
}));
|
|
226
|
-
const code = `require("nativewind/dist/index.js").__require().StyleSheet.registerCompiled(${data})`;
|
|
227
|
-
const newId = `${id}.js`;
|
|
228
|
-
const cssId = newId.replace(rolldownNodeMods + import_node_path.sep, "");
|
|
229
|
-
cssTransformCache.set(cssId, code);
|
|
230
|
-
return {
|
|
231
|
-
code,
|
|
232
|
-
id: newId,
|
|
233
|
-
map: null
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
generateBundle(_, bundle) {
|
|
240
|
-
const environment = getEnvName(this.environment.name);
|
|
241
|
-
if (import_configure.configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
|
|
242
|
-
const rootJSName = Object.keys(bundle).find(i => {
|
|
243
|
-
const chunk = bundle[i];
|
|
244
|
-
return chunk.type == "chunk" && chunk.fileName.match(/.[cm]?js(?:\?.+)?$/) != null;
|
|
245
|
-
});
|
|
246
|
-
if (!rootJSName) {
|
|
247
|
-
throw new Error(`Can't find root js, internal one error`);
|
|
248
|
-
}
|
|
249
|
-
const rootJS = bundle[rootJSName];
|
|
250
|
-
const cssAssets = Object.keys(bundle).filter(i => bundle[i].fileName.endsWith(".css.js"));
|
|
251
|
-
for (const name of cssAssets) {
|
|
252
|
-
delete bundle[name];
|
|
253
|
-
const jsCSS = cssTransformCache.get(name);
|
|
254
|
-
rootJS.code = `
|
|
255
|
-
${jsCSS}
|
|
256
|
-
${rootJS.code}
|
|
257
|
-
`;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}, {
|
|
262
|
-
name: "one:compiler",
|
|
263
|
-
enforce: "pre",
|
|
264
|
-
config: () => {
|
|
265
|
-
const nodeModulesFilter = /node_modules[/\\].*\.(tsx?|jsx?|mjs|cjs)$/;
|
|
266
|
-
const createEnvironmentConfig = environment => {
|
|
267
|
-
if (!perfStats.optimizeDeps.byEnvironment[environment]) {
|
|
268
|
-
perfStats.optimizeDeps.byEnvironment[environment] = {
|
|
269
|
-
filesChecked: 0,
|
|
270
|
-
filesTransformed: 0,
|
|
271
|
-
startTime: Date.now()
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
return {
|
|
275
|
-
optimizeDeps: {
|
|
276
|
-
rolldownOptions: {
|
|
277
|
-
plugins: [{
|
|
278
|
-
name: `transform-before-optimize-deps-${environment}`,
|
|
279
|
-
async transform(code, id) {
|
|
280
|
-
if (!nodeModulesFilter.test(id)) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;
|
|
284
|
-
const production = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test";
|
|
285
|
-
(0, import_constants.debug)?.(`[rolldown optimizeDeps] ${id}`);
|
|
286
|
-
const result = await performBabelTransform({
|
|
287
|
-
id,
|
|
288
|
-
code,
|
|
289
|
-
environment,
|
|
290
|
-
production,
|
|
291
|
-
reactForRNVersion,
|
|
292
|
-
optionsIn
|
|
293
|
-
});
|
|
294
|
-
if (!result) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;
|
|
298
|
-
return {
|
|
299
|
-
code: result.code,
|
|
300
|
-
map: result.map
|
|
301
|
-
};
|
|
302
|
-
},
|
|
303
|
-
buildEnd() {
|
|
304
|
-
if (process.env.DEBUG_COMPILER_PERF) {
|
|
305
|
-
const stats = perfStats.optimizeDeps.byEnvironment[environment];
|
|
306
|
-
const elapsed = Date.now() - stats.startTime;
|
|
307
|
-
console.info(`[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`);
|
|
308
|
-
}
|
|
309
|
-
const allDone = Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2;
|
|
310
|
-
if (allDone) {
|
|
311
|
-
(0, import_cache.logCacheStats)();
|
|
312
|
-
logPerfSummary();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}]
|
|
316
|
-
}
|
|
317
|
-
},
|
|
318
|
-
define: {
|
|
319
|
-
"process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
};
|
|
323
|
-
return {
|
|
324
|
-
environments: {
|
|
325
|
-
ios: createEnvironmentConfig("ios"),
|
|
326
|
-
android: createEnvironmentConfig("android"),
|
|
327
|
-
client: createEnvironmentConfig("client"),
|
|
328
|
-
ssr: createEnvironmentConfig("ssr")
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
},
|
|
332
|
-
configResolved(resolvedConfig) {
|
|
333
|
-
config = resolvedConfig;
|
|
334
|
-
},
|
|
335
|
-
async transform(codeIn, _id) {
|
|
336
|
-
let code = codeIn;
|
|
337
|
-
const environment = getEnvName(this.environment.name);
|
|
338
|
-
const isNative = environment === "ios" || environment === "android";
|
|
339
|
-
const production = config.command === "build" || process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
|
|
340
|
-
const isEntry = _id.includes("one-entry-native");
|
|
341
|
-
if (isEntry) {
|
|
342
|
-
if (isNative && !production) {
|
|
343
|
-
code = `import '@vxrn/vite-native-client'
|
|
344
|
-
${code}`;
|
|
345
|
-
}
|
|
346
|
-
if (isNative && import_configure.configuration.enableNativewind) {
|
|
347
|
-
code = `import * as x from 'nativewind'
|
|
348
|
-
${code}`;
|
|
349
|
-
}
|
|
350
|
-
return code;
|
|
351
|
-
}
|
|
352
|
-
const id = _id.split("?")[0];
|
|
353
|
-
const extension = (0, import_node_path.extname)(id);
|
|
354
|
-
if (extension === ".css" || !import_constants.validParsers.has(extension)) {
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
if (id.includes(`virtual:`)) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if (codeIn.endsWith(`// vxrn-did-babel`)) {
|
|
361
|
-
(0, import_constants.debug)?.(`[skip babel] ${id}`);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
return performBabelTransform({
|
|
365
|
-
id,
|
|
366
|
-
code: codeIn,
|
|
367
|
-
environment,
|
|
368
|
-
production,
|
|
369
|
-
reactForRNVersion,
|
|
370
|
-
optionsIn
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
},
|
|
374
|
-
// wraps client-side TSX/JSX with React Refresh preamble + import.meta.hot.accept
|
|
375
|
-
// runs after vite:oxc (no enforce:'pre') so it sees the already-transformed code
|
|
376
|
-
{
|
|
377
|
-
name: "one:react-refresh-web",
|
|
378
|
-
apply: "serve",
|
|
379
|
-
transform(code, _id) {
|
|
380
|
-
if (this.environment.name !== "client") return;
|
|
381
|
-
if (code.includes(import_constants.runtimePublicPath)) return;
|
|
382
|
-
const id = _id.split("?")[0];
|
|
383
|
-
if (id.includes("node_modules")) return;
|
|
384
|
-
if (id.includes("virtual:")) return;
|
|
385
|
-
if (id === import_constants.runtimePublicPath) return;
|
|
386
|
-
const ext = (0, import_node_path.extname)(id);
|
|
387
|
-
if (ext !== ".tsx" && ext !== ".jsx") return;
|
|
388
|
-
const hasRefreshCalls = /\$RefreshReg\$\(/.test(code);
|
|
389
|
-
let out = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
390
|
-
|
|
391
|
-
`;
|
|
392
|
-
if (hasRefreshCalls) {
|
|
393
|
-
out += `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
394
|
-
const prevRefreshReg = window.$RefreshReg$;
|
|
395
|
-
const prevRefreshSig = window.$RefreshSig$;
|
|
396
|
-
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
397
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
398
|
-
|
|
399
|
-
`;
|
|
400
|
-
}
|
|
401
|
-
out += code;
|
|
402
|
-
if (hasRefreshCalls) {
|
|
403
|
-
out += `
|
|
404
|
-
|
|
405
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
406
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
407
|
-
`;
|
|
408
|
-
}
|
|
409
|
-
out += `
|
|
410
|
-
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
411
|
-
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
412
|
-
import.meta.hot.accept((nextExports) => {
|
|
413
|
-
if (!nextExports) return;
|
|
414
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
|
|
415
|
-
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
`;
|
|
419
|
-
return {
|
|
420
|
-
code: out,
|
|
421
|
-
map: null
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
}];
|
|
425
|
-
}
|