@vxrn/compiler 2.0.0-beta.33.1 → 2.0.0-beta.45.1
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 +112 -109
- package/dist/cjs/configure.cjs +26 -28
- package/dist/cjs/constants.cjs +56 -60
- package/dist/cjs/index.cjs +420 -438
- package/dist/cjs/reactNativeCodegen.cjs +105 -114
- package/dist/cjs/reactNativeViewConfig.cjs +362 -381
- package/dist/cjs/refresh-runtime.cjs +390 -397
- package/dist/cjs/transformBabel.cjs +278 -218
- package/dist/cjs/transformHermesAsync.cjs +36 -47
- package/dist/cjs/transformHermesLoops.cjs +279 -281
- package/dist/cjs/transformSWC.cjs +183 -200
- package/dist/cjs/transformWorklets.cjs +107 -95
- package/dist/cjs/types.cjs +9 -11
- package/dist/cjs/worklets/autoworklet.cjs +277 -222
- package/dist/cjs/worklets/globals.cjs +124 -60
- package/dist/cjs/worklets/hash.cjs +23 -27
- package/dist/cjs/worklets/scope.cjs +338 -359
- package/dist/cjs/worklets/serialize.cjs +73 -75
- package/dist/cjs/worklets/transform.cjs +217 -222
- package/dist/cjs/worklets/types.cjs +9 -11
- package/dist/esm/cache.mjs +96 -89
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +11 -10
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/constants.mjs +41 -41
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/index.js +417 -420
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +417 -420
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/reactNativeCodegen.mjs +90 -88
- package/dist/esm/reactNativeCodegen.mjs.map +1 -1
- package/dist/esm/reactNativeViewConfig.mjs +347 -362
- package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
- package/dist/esm/refresh-runtime.mjs +372 -376
- package/dist/esm/refresh-runtime.mjs.map +1 -1
- package/dist/esm/transformBabel.mjs +261 -194
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformHermesAsync.mjs +20 -21
- package/dist/esm/transformHermesAsync.mjs.map +1 -1
- package/dist/esm/transformHermesLoops.mjs +264 -255
- package/dist/esm/transformHermesLoops.mjs.map +1 -1
- package/dist/esm/transformSWC.mjs +163 -171
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformWorklets.mjs +89 -69
- package/dist/esm/transformWorklets.mjs.map +1 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/worklets/autoworklet.mjs +258 -200
- package/dist/esm/worklets/autoworklet.mjs.map +1 -1
- package/dist/esm/worklets/globals.mjs +109 -42
- package/dist/esm/worklets/globals.mjs.map +1 -1
- package/dist/esm/worklets/hash.mjs +10 -9
- package/dist/esm/worklets/hash.mjs.map +1 -1
- package/dist/esm/worklets/scope.mjs +325 -341
- package/dist/esm/worklets/scope.mjs.map +1 -1
- package/dist/esm/worklets/serialize.mjs +60 -58
- package/dist/esm/worklets/serialize.mjs.map +1 -1
- package/dist/esm/worklets/transform.mjs +201 -197
- package/dist/esm/worklets/transform.mjs.map +1 -1
- package/dist/esm/worklets/types.mjs +0 -2
- package/package.json +7 -6
- package/src/cache.ts +37 -7
- package/src/index.ts +33 -18
- package/src/transformBabel.test.ts +311 -1
- package/src/transformBabel.ts +110 -13
- package/types/cache.d.ts +2 -2
- package/types/cache.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/transformBabel.d.ts +16 -1
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformSWC.d.ts +1 -4
- package/types/transformSWC.d.ts.map +1 -1
- package/dist/cjs/transformBabel.test.cjs +0 -360
- package/dist/cjs/transformHermesLoops.test.cjs +0 -257
- package/dist/cjs/transformSWC.test.cjs +0 -117
- package/dist/cjs/transformWorklets.test.cjs +0 -604
- package/dist/esm/transformBabel.test.mjs +0 -337
- package/dist/esm/transformBabel.test.mjs.map +0 -1
- package/dist/esm/transformHermesLoops.test.mjs +0 -234
- package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
- package/dist/esm/transformSWC.test.mjs +0 -118
- package/dist/esm/transformSWC.test.mjs.map +0 -1
- package/dist/esm/transformWorklets.test.mjs +0 -581
- package/dist/esm/transformWorklets.test.mjs.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/worklets/types.mjs.map +0 -1
- package/types/transformBabel.test.d.ts +0 -2
- package/types/transformBabel.test.d.ts.map +0 -1
- package/types/transformHermesLoops.test.d.ts +0 -2
- package/types/transformHermesLoops.test.d.ts.map +0 -1
- package/types/transformSWC.test.d.ts +0 -2
- package/types/transformSWC.test.d.ts.map +0 -1
- package/types/transformWorklets.test.d.ts +0 -2
- package/types/transformWorklets.test.d.ts.map +0 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -5,39 +5,32 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
21
|
};
|
|
22
22
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
-
value: mod,
|
|
30
|
-
enumerable: true
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
31
26
|
}) : target, mod));
|
|
32
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
33
|
-
value: true
|
|
34
|
-
}), mod);
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
28
|
var index_exports = {};
|
|
36
29
|
__export(index_exports, {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
JS_GLOBALS: () => import_globals.JS_GLOBALS,
|
|
31
|
+
clearTransformCache: () => import_cache2.clearTransformCache,
|
|
32
|
+
createVXRNCompilerPlugin: () => createVXRNCompilerPlugin,
|
|
33
|
+
getClosureVariables: () => import_scope.getClosureVariables
|
|
41
34
|
});
|
|
42
35
|
module.exports = __toCommonJS(index_exports);
|
|
43
36
|
var import_node_fs = require("node:fs");
|
|
@@ -64,438 +57,426 @@ var import_globals = require("./worklets/globals.cjs");
|
|
|
64
57
|
var import_scope = require("./worklets/scope.cjs");
|
|
65
58
|
const import_meta = {};
|
|
66
59
|
const perfStats = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
byEnvironment: {}
|
|
75
|
-
}
|
|
60
|
+
babel: {
|
|
61
|
+
totalCalls: 0,
|
|
62
|
+
totalTransforms: 0,
|
|
63
|
+
totalTime: 0,
|
|
64
|
+
byEnvironment: {}
|
|
65
|
+
},
|
|
66
|
+
optimizeDeps: { byEnvironment: {} }
|
|
76
67
|
};
|
|
77
68
|
function logPerfSummary() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
69
|
+
if (!process.env.DEBUG_COMPILER_PERF) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
console.info("\n📊 [Compiler Performance Summary]");
|
|
73
|
+
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)`);
|
|
74
|
+
console.info(`Babel total time: ${perfStats.babel.totalTime}ms`);
|
|
75
|
+
for (const [env, stats] of Object.entries(perfStats.babel.byEnvironment)) {
|
|
76
|
+
if (stats.transforms > 0) {
|
|
77
|
+
console.info(` ${env}: ${stats.transforms} transforms, ${stats.time}ms (${(stats.time / stats.transforms).toFixed(1)}ms avg)`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const [env, stats] of Object.entries(perfStats.optimizeDeps.byEnvironment)) {
|
|
81
|
+
const elapsed = Date.now() - stats.startTime;
|
|
82
|
+
console.info(`optimizeDeps ${env}: checked ${stats.filesChecked} files, transformed ${stats.filesTransformed} (${elapsed}ms)`);
|
|
83
|
+
}
|
|
93
84
|
}
|
|
94
85
|
const compilerLog = {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// us a Timeout we need to unref so the debounce never holds the process open
|
|
100
|
-
timer: null
|
|
86
|
+
compiled: 0,
|
|
87
|
+
cached: 0,
|
|
88
|
+
time: 0,
|
|
89
|
+
timer: null
|
|
101
90
|
};
|
|
102
91
|
function logCompiled(cached, ms) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
92
|
+
if (cached) {
|
|
93
|
+
compilerLog.cached++;
|
|
94
|
+
} else {
|
|
95
|
+
compilerLog.compiled++;
|
|
96
|
+
compilerLog.time += ms;
|
|
97
|
+
}
|
|
98
|
+
if (compilerLog.timer) clearTimeout(compilerLog.timer);
|
|
99
|
+
compilerLog.timer = setTimeout(() => {
|
|
100
|
+
const total = compilerLog.compiled + compilerLog.cached;
|
|
101
|
+
const detail = compilerLog.compiled ? `${compilerLog.compiled} compiled in ${compilerLog.time}ms${compilerLog.cached ? `, ${compilerLog.cached} cached` : ""}` : `all cached`;
|
|
102
|
+
console.info(` \u{1FA84} [compiler] ${total} file${total === 1 ? "" : "s"} (${detail})`);
|
|
103
|
+
compilerLog.compiled = 0;
|
|
104
|
+
compilerLog.cached = 0;
|
|
105
|
+
compilerLog.time = 0;
|
|
106
|
+
compilerLog.timer = null;
|
|
107
|
+
}, 500);
|
|
108
|
+
compilerLog.timer.unref?.();
|
|
120
109
|
}
|
|
121
|
-
async function performBabelTransform({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
110
|
+
async function performBabelTransform({ id, code, projectRoot, environment, production, reactForRNVersion, optionsIn }) {
|
|
111
|
+
perfStats.babel.totalCalls++;
|
|
112
|
+
if (!perfStats.babel.byEnvironment[environment]) {
|
|
113
|
+
perfStats.babel.byEnvironment[environment] = {
|
|
114
|
+
calls: 0,
|
|
115
|
+
transforms: 0,
|
|
116
|
+
time: 0
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
perfStats.babel.byEnvironment[environment].calls++;
|
|
120
|
+
const transformProps = {
|
|
121
|
+
id,
|
|
122
|
+
code,
|
|
123
|
+
projectRoot,
|
|
124
|
+
development: !production,
|
|
125
|
+
environment,
|
|
126
|
+
reactForRNVersion
|
|
127
|
+
};
|
|
128
|
+
const userTransform = optionsIn?.transform?.(transformProps);
|
|
129
|
+
if (userTransform === false) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (userTransform !== "swc" && userTransform !== "oxc") {
|
|
133
|
+
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
134
|
+
...transformProps,
|
|
135
|
+
userSetting: userTransform
|
|
136
|
+
});
|
|
137
|
+
if (babelOptions) {
|
|
138
|
+
const hasCompilerPlugin = babelOptions.plugins?.some((x) => Array.isArray(x) && x[0] === "babel-plugin-react-compiler");
|
|
139
|
+
const userBabelConfigPath = typeof babelOptions.configFile === "string" ? babelOptions.configFile : null;
|
|
140
|
+
const cached = (0, import_cache.getCachedTransform)(id, code, environment, userBabelConfigPath);
|
|
141
|
+
if (cached) {
|
|
142
|
+
perfStats.babel.byEnvironment[environment].transforms++;
|
|
143
|
+
if (hasCompilerPlugin && (cached.code.includes("react/compiler-runtime") || cached.code.includes("react-compiler-runtime"))) {
|
|
144
|
+
(0, import_constants.debug)?.(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)} (cached)`);
|
|
145
|
+
logCompiled(true, 0);
|
|
146
|
+
}
|
|
147
|
+
(0, import_constants.debug)?.(`[babel/cached] ${id}`);
|
|
148
|
+
return cached;
|
|
149
|
+
}
|
|
150
|
+
const isWorkletPlugin = (entry) => {
|
|
151
|
+
if (!entry) return false;
|
|
152
|
+
const name = typeof entry === "string" ? entry : Array.isArray(entry) ? entry[0] : null;
|
|
153
|
+
return typeof name === "string" && (name.includes("react-native-worklets") || name.includes("react-native-reanimated"));
|
|
154
|
+
};
|
|
155
|
+
const workletEntry = babelOptions.plugins?.find(isWorkletPlugin);
|
|
156
|
+
const workletPluginOptions = Array.isArray(workletEntry) ? workletEntry[1] : void 0;
|
|
157
|
+
const useWorklets = (0, import_configure.isNativeWorkletsEnabled)() && (Boolean(workletEntry) || (0, import_transformWorklets.shouldTransformWorklets)({
|
|
158
|
+
id,
|
|
159
|
+
code
|
|
160
|
+
}));
|
|
161
|
+
let curCode = code;
|
|
162
|
+
let workletPreparation = null;
|
|
163
|
+
let compilerOut = null;
|
|
164
|
+
const compilerPluginIndex = babelOptions.plugins?.findIndex((x) => Array.isArray(x) && x[0] === "babel-plugin-react-compiler") ?? -1;
|
|
165
|
+
if (compilerPluginIndex !== -1) {
|
|
166
|
+
const compilerPluginConfig = babelOptions.plugins[compilerPluginIndex];
|
|
167
|
+
const compilerPluginOptions = compilerPluginConfig[1] || {};
|
|
168
|
+
const useBabelCompiler = compilerPluginOptions.compiler === "babel" || process.env.ONE_REACT_COMPILER === "babel" || process.env.VXRN_REACT_COMPILER === "babel";
|
|
169
|
+
if (!useBabelCompiler) {
|
|
170
|
+
if (useWorklets) {
|
|
171
|
+
workletPreparation = (0, import_transformWorklets.prepareWorkletsForReactCompiler)(id, curCode, (0, import_transformSWC.shouldSourceMap)());
|
|
172
|
+
if (workletPreparation) curCode = workletPreparation.code;
|
|
173
|
+
}
|
|
174
|
+
compilerOut = await (0, import_transformBabel.transformOxcReactCompiler)(id, curCode, compilerPluginOptions, (0, import_transformSWC.shouldSourceMap)());
|
|
175
|
+
if (compilerOut) curCode = compilerOut.code;
|
|
176
|
+
babelOptions.plugins.splice(compilerPluginIndex, 1);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
let workletsOut = null;
|
|
180
|
+
if (useWorklets) {
|
|
181
|
+
workletsOut = await (0, import_transformWorklets.transformWorklets)(id, curCode, (0, import_transformSWC.shouldSourceMap)(), {
|
|
182
|
+
projectRoot,
|
|
183
|
+
...workletPluginOptions
|
|
184
|
+
});
|
|
185
|
+
babelOptions.plugins = babelOptions.plugins?.filter((entry) => !isWorkletPlugin(entry));
|
|
186
|
+
curCode = workletsOut.code;
|
|
187
|
+
}
|
|
188
|
+
const startTime = Date.now();
|
|
189
|
+
let babelOut = null;
|
|
190
|
+
if (babelOptions.plugins?.length === 0 && !babelOptions.configFile && !babelOptions.babelrc) {
|
|
191
|
+
let finalMap = void 0;
|
|
192
|
+
if ((0, import_transformSWC.shouldSourceMap)()) {
|
|
193
|
+
const intermediateMaps = [
|
|
194
|
+
workletPreparation?.map,
|
|
195
|
+
compilerOut?.map,
|
|
196
|
+
workletsOut?.map
|
|
197
|
+
].filter(Boolean);
|
|
198
|
+
if (intermediateMaps.length === 1) {
|
|
199
|
+
finalMap = intermediateMaps[0];
|
|
200
|
+
} else if (intermediateMaps.length > 1) {
|
|
201
|
+
const remapping = (await import("@jridgewell/remapping")).default;
|
|
202
|
+
finalMap = remapping(intermediateMaps.slice().reverse(), () => null);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
babelOut = {
|
|
206
|
+
code: curCode,
|
|
207
|
+
map: finalMap
|
|
208
|
+
};
|
|
209
|
+
} else {
|
|
210
|
+
const babelOptsWithMap = (0, import_transformSWC.shouldSourceMap)() && (workletsOut?.map || compilerOut?.map || workletPreparation?.map) ? {
|
|
211
|
+
...babelOptions,
|
|
212
|
+
sourceMaps: true
|
|
213
|
+
} : babelOptions;
|
|
214
|
+
babelOut = await (0, import_transformBabel.transformBabel)(id, curCode, babelOptsWithMap);
|
|
215
|
+
if ((0, import_transformSWC.shouldSourceMap)() && babelOut?.map) {
|
|
216
|
+
const priorMaps = [
|
|
217
|
+
workletPreparation?.map,
|
|
218
|
+
compilerOut?.map,
|
|
219
|
+
workletsOut?.map
|
|
220
|
+
].filter(Boolean);
|
|
221
|
+
if (priorMaps.length > 0) {
|
|
222
|
+
const remapping = (await import("@jridgewell/remapping")).default;
|
|
223
|
+
babelOut.map = remapping([babelOut.map, ...priorMaps.slice().reverse()], () => null);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const babelTime = Date.now() - startTime;
|
|
228
|
+
if (babelOut?.code) {
|
|
229
|
+
perfStats.babel.totalTransforms++;
|
|
230
|
+
perfStats.babel.totalTime += babelTime;
|
|
231
|
+
perfStats.babel.byEnvironment[environment].transforms++;
|
|
232
|
+
perfStats.babel.byEnvironment[environment].time += babelTime;
|
|
233
|
+
if (hasCompilerPlugin && (babelOut.code.includes("react/compiler-runtime") || babelOut.code.includes("react-compiler-runtime"))) {
|
|
234
|
+
(0, import_constants.debug)?.(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)} (${babelTime}ms)`);
|
|
235
|
+
logCompiled(false, babelTime);
|
|
236
|
+
}
|
|
237
|
+
(0, import_constants.debug)?.(`[babel] ${id}`);
|
|
238
|
+
const outCode = `${babelOut.code}
|
|
245
239
|
// vxrn-did-babel`;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
240
|
+
const result = {
|
|
241
|
+
code: outCode,
|
|
242
|
+
map: babelOut.map
|
|
243
|
+
};
|
|
244
|
+
(0, import_cache.setCachedTransform)(id, code, result, environment, userBabelConfigPath);
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
256
250
|
}
|
|
257
251
|
async function createVXRNCompilerPlugin(optionsIn) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
for (const name of cssAssets) {
|
|
339
|
-
delete bundle[name];
|
|
340
|
-
const jsCSS = cssTransformCache.get(name);
|
|
341
|
-
rootJS.code = `
|
|
252
|
+
const reactVersion = await (async () => {
|
|
253
|
+
const path = (0, import_utils.resolvePath)("react/package.json");
|
|
254
|
+
const json = JSON.parse(await (0, import_promises.readFile)(path, "utf-8"));
|
|
255
|
+
return json.version;
|
|
256
|
+
})();
|
|
257
|
+
const envNames = {
|
|
258
|
+
ios: true,
|
|
259
|
+
android: true,
|
|
260
|
+
client: true,
|
|
261
|
+
ssr: true
|
|
262
|
+
};
|
|
263
|
+
function getEnvName(name) {
|
|
264
|
+
if (name === "worker") return "ssr";
|
|
265
|
+
if (!envNames[name]) throw new Error(`Invalid env: ${name}`);
|
|
266
|
+
return name;
|
|
267
|
+
}
|
|
268
|
+
const reactForRNVersion = reactVersion.split(".")[0];
|
|
269
|
+
const cssTransformCache = /* @__PURE__ */ new Map();
|
|
270
|
+
const rolldownPath = (0, import_utils.resolvePath)("rolldown");
|
|
271
|
+
const rolldownNodeMods = rolldownPath.slice(0, rolldownPath.indexOf(import_node_path.sep + "node_modules"));
|
|
272
|
+
let config;
|
|
273
|
+
return [
|
|
274
|
+
{
|
|
275
|
+
name: "one:compiler-resolve-refresh-runtime",
|
|
276
|
+
apply: "serve",
|
|
277
|
+
enforce: "pre",
|
|
278
|
+
resolveId: (id) => id === import_constants.runtimePublicPath || id === `${import_constants.runtimePublicPath}.map` ? id : void 0,
|
|
279
|
+
load: (id) => {
|
|
280
|
+
const basePath = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
281
|
+
if (id === import_constants.runtimePublicPath) {
|
|
282
|
+
return (0, import_node_fs.readFileSync)((0, import_node_path.join)(basePath, "refresh-runtime.mjs"), "utf-8").replace(/\/\/# sourceMappingURL=.*/, "");
|
|
283
|
+
}
|
|
284
|
+
if (id === `${import_constants.runtimePublicPath}.map`) {
|
|
285
|
+
return JSON.stringify({
|
|
286
|
+
version: 3,
|
|
287
|
+
sources: [],
|
|
288
|
+
mappings: ""
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return void 0;
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
name: `one:compiler-css-to-js`,
|
|
296
|
+
transform: {
|
|
297
|
+
filter: { id: /\.css$/ },
|
|
298
|
+
handler(codeIn, id) {
|
|
299
|
+
const environment = getEnvName(this.environment.name);
|
|
300
|
+
if (import_configure.configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
|
|
301
|
+
{
|
|
302
|
+
const data = JSON.stringify((0, import_css_to_rn.cssToReactNativeRuntime)(codeIn, { inlineRem: 16 }));
|
|
303
|
+
const code = `require("nativewind/dist/index.js").__require().StyleSheet.registerCompiled(${data})`;
|
|
304
|
+
const newId = `${id}.js`;
|
|
305
|
+
const cssId = newId.replace(rolldownNodeMods + import_node_path.sep, "");
|
|
306
|
+
cssTransformCache.set(cssId, code);
|
|
307
|
+
return {
|
|
308
|
+
code,
|
|
309
|
+
id: newId,
|
|
310
|
+
map: null
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
generateBundle(_, bundle) {
|
|
317
|
+
const environment = getEnvName(this.environment.name);
|
|
318
|
+
if (import_configure.configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
|
|
319
|
+
const rootJSName = Object.keys(bundle).find((i) => {
|
|
320
|
+
const chunk = bundle[i];
|
|
321
|
+
return chunk.type == "chunk" && chunk.fileName.match(/.[cm]?js(?:\?.+)?$/) != null;
|
|
322
|
+
});
|
|
323
|
+
if (!rootJSName) {
|
|
324
|
+
throw new Error(`Can't find root js, internal one error`);
|
|
325
|
+
}
|
|
326
|
+
const rootJS = bundle[rootJSName];
|
|
327
|
+
const cssAssets = Object.keys(bundle).filter((i) => bundle[i].fileName.endsWith(".css.js"));
|
|
328
|
+
for (const name of cssAssets) {
|
|
329
|
+
delete bundle[name];
|
|
330
|
+
const jsCSS = cssTransformCache.get(name);
|
|
331
|
+
rootJS.code = `
|
|
342
332
|
${jsCSS}
|
|
343
333
|
${rootJS.code}
|
|
344
334
|
`;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const environment = getEnvName(this.environment.name);
|
|
426
|
-
const isNative = environment === "ios" || environment === "android";
|
|
427
|
-
const production = config.command === "build" || process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || '""') === "production";
|
|
428
|
-
const isEntry = _id.includes("one-entry-native");
|
|
429
|
-
if (isEntry) {
|
|
430
|
-
if (isNative && !production) {
|
|
431
|
-
code = `import '@vxrn/vite-native-client'
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: "one:compiler",
|
|
341
|
+
enforce: "pre",
|
|
342
|
+
config: () => {
|
|
343
|
+
const nodeModulesFilter = /node_modules[/\\].*\.(tsx?|jsx?|mjs|cjs)$/;
|
|
344
|
+
const createEnvironmentConfig = (environment) => {
|
|
345
|
+
if (!perfStats.optimizeDeps.byEnvironment[environment]) {
|
|
346
|
+
perfStats.optimizeDeps.byEnvironment[environment] = {
|
|
347
|
+
filesChecked: 0,
|
|
348
|
+
filesTransformed: 0,
|
|
349
|
+
startTime: Date.now()
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
optimizeDeps: { rolldownOptions: { plugins: [{
|
|
354
|
+
name: `transform-before-optimize-deps-${environment}`,
|
|
355
|
+
async transform(code, id) {
|
|
356
|
+
if (!nodeModulesFilter.test(id)) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;
|
|
360
|
+
const production = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test";
|
|
361
|
+
(0, import_constants.debug)?.(`[rolldown optimizeDeps] ${id}`);
|
|
362
|
+
const result = await performBabelTransform({
|
|
363
|
+
id,
|
|
364
|
+
code,
|
|
365
|
+
projectRoot: config.root,
|
|
366
|
+
environment,
|
|
367
|
+
production,
|
|
368
|
+
reactForRNVersion,
|
|
369
|
+
optionsIn
|
|
370
|
+
});
|
|
371
|
+
if (!result) {
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;
|
|
375
|
+
return {
|
|
376
|
+
code: result.code,
|
|
377
|
+
map: result.map
|
|
378
|
+
};
|
|
379
|
+
},
|
|
380
|
+
buildEnd() {
|
|
381
|
+
if (process.env.DEBUG_COMPILER_PERF) {
|
|
382
|
+
const stats = perfStats.optimizeDeps.byEnvironment[environment];
|
|
383
|
+
const elapsed = Date.now() - stats.startTime;
|
|
384
|
+
console.info(`[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`);
|
|
385
|
+
}
|
|
386
|
+
const allDone = Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2;
|
|
387
|
+
if (allDone) {
|
|
388
|
+
(0, import_cache.logCacheStats)();
|
|
389
|
+
logPerfSummary();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}] } },
|
|
393
|
+
define: { "process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web") }
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
return { environments: {
|
|
397
|
+
ios: createEnvironmentConfig("ios"),
|
|
398
|
+
android: createEnvironmentConfig("android"),
|
|
399
|
+
client: createEnvironmentConfig("client"),
|
|
400
|
+
ssr: createEnvironmentConfig("ssr")
|
|
401
|
+
} };
|
|
402
|
+
},
|
|
403
|
+
configResolved(resolvedConfig) {
|
|
404
|
+
config = resolvedConfig;
|
|
405
|
+
},
|
|
406
|
+
async transform(codeIn, _id) {
|
|
407
|
+
let code = codeIn;
|
|
408
|
+
const environment = getEnvName(this.environment.name);
|
|
409
|
+
const isNative = environment === "ios" || environment === "android";
|
|
410
|
+
const production = config.command === "build" || process.env.NODE_ENV === "production" || JSON.parse(this.environment.config?.define?.["process.env.NODE_ENV"] || "\"\"") === "production";
|
|
411
|
+
const isEntry = _id.includes("one-entry-native");
|
|
412
|
+
if (isEntry) {
|
|
413
|
+
if (isNative && !production) {
|
|
414
|
+
code = `import '@vxrn/vite-native-client'
|
|
432
415
|
${code}`;
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
416
|
+
}
|
|
417
|
+
if (isNative && import_configure.configuration.enableNativewind) {
|
|
418
|
+
code = `import * as x from 'nativewind'
|
|
436
419
|
${code}`;
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const hasRefreshCalls = /\$RefreshReg\$\(/.test(code);
|
|
478
|
-
let out = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
420
|
+
}
|
|
421
|
+
return code;
|
|
422
|
+
}
|
|
423
|
+
const id = _id.split("?")[0];
|
|
424
|
+
const extension = (0, import_node_path.extname)(id);
|
|
425
|
+
if (extension === ".css" || !import_constants.validParsers.has(extension)) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (id.includes(`virtual:`)) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (codeIn.endsWith(`// vxrn-did-babel`)) {
|
|
432
|
+
(0, import_constants.debug)?.(`[skip babel] ${id}`);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
return performBabelTransform({
|
|
436
|
+
id,
|
|
437
|
+
code: codeIn,
|
|
438
|
+
projectRoot: config.root,
|
|
439
|
+
environment,
|
|
440
|
+
production,
|
|
441
|
+
reactForRNVersion,
|
|
442
|
+
optionsIn
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: "one:react-refresh-web",
|
|
448
|
+
apply: "serve",
|
|
449
|
+
transform(code, _id) {
|
|
450
|
+
if (this.environment.name !== "client") return;
|
|
451
|
+
if (code.includes(import_constants.runtimePublicPath)) return;
|
|
452
|
+
const id = _id.split("?")[0];
|
|
453
|
+
if (id.includes("node_modules")) return;
|
|
454
|
+
if (id.includes("virtual:")) return;
|
|
455
|
+
if (id === import_constants.runtimePublicPath) return;
|
|
456
|
+
const ext = (0, import_node_path.extname)(id);
|
|
457
|
+
if (ext !== ".tsx" && ext !== ".jsx") return;
|
|
458
|
+
const hasRefreshCalls = /\$RefreshReg\$\(/.test(code);
|
|
459
|
+
let out = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
479
460
|
|
|
480
461
|
`;
|
|
481
|
-
|
|
482
|
-
|
|
462
|
+
if (hasRefreshCalls) {
|
|
463
|
+
out += `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
483
464
|
const prevRefreshReg = window.$RefreshReg$;
|
|
484
465
|
const prevRefreshSig = window.$RefreshSig$;
|
|
485
466
|
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
486
467
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
487
468
|
|
|
488
469
|
`;
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
470
|
+
}
|
|
471
|
+
out += code;
|
|
472
|
+
if (hasRefreshCalls) {
|
|
473
|
+
out += `
|
|
493
474
|
|
|
494
475
|
window.$RefreshReg$ = prevRefreshReg;
|
|
495
476
|
window.$RefreshSig$ = prevRefreshSig;
|
|
496
477
|
`;
|
|
497
|
-
|
|
498
|
-
|
|
478
|
+
}
|
|
479
|
+
out += `
|
|
499
480
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
500
481
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
501
482
|
import.meta.hot.accept((nextExports) => {
|
|
@@ -505,10 +486,11 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
|
505
486
|
});
|
|
506
487
|
});
|
|
507
488
|
`;
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
489
|
+
return {
|
|
490
|
+
code: out,
|
|
491
|
+
map: null
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
];
|
|
496
|
+
}
|