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