@vxrn/compiler 1.27.0 → 1.27.1-1789509973946

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