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