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