@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.
Files changed (89) hide show
  1. package/dist/cjs/cache.cjs +106 -117
  2. package/dist/cjs/configure.cjs +26 -28
  3. package/dist/cjs/constants.cjs +56 -60
  4. package/dist/cjs/index.cjs +420 -443
  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 -263
  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 +90 -97
  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 -425
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/index.mjs +417 -425
  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 -237
  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/transformBabel.test.ts +77 -17
  63. package/src/transformBabel.ts +28 -12
  64. package/types/transformBabel.d.ts +12 -0
  65. package/types/transformBabel.d.ts.map +1 -1
  66. package/types/transformSWC.d.ts +1 -4
  67. package/types/transformSWC.d.ts.map +1 -1
  68. package/dist/cjs/transformBabel.test.cjs +0 -652
  69. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  70. package/dist/cjs/transformSWC.test.cjs +0 -117
  71. package/dist/cjs/transformWorklets.test.cjs +0 -604
  72. package/dist/esm/transformBabel.test.mjs +0 -629
  73. package/dist/esm/transformBabel.test.mjs.map +0 -1
  74. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  75. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  76. package/dist/esm/transformSWC.test.mjs +0 -118
  77. package/dist/esm/transformSWC.test.mjs.map +0 -1
  78. package/dist/esm/transformWorklets.test.mjs +0 -581
  79. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  80. package/dist/esm/types.mjs.map +0 -1
  81. package/dist/esm/worklets/types.mjs.map +0 -1
  82. package/types/transformBabel.test.d.ts +0 -2
  83. package/types/transformBabel.test.d.ts.map +0 -1
  84. package/types/transformHermesLoops.test.d.ts +0 -2
  85. package/types/transformHermesLoops.test.d.ts.map +0 -1
  86. package/types/transformSWC.test.d.ts +0 -2
  87. package/types/transformSWC.test.d.ts.map +0 -1
  88. package/types/transformWorklets.test.d.ts +0 -2
  89. 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
- 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 userBabelConfigPath = typeof babelOptions.configFile === "string" ? babelOptions.configFile : null;
116
- const cached = getCachedTransform(id, code, environment, userBabelConfigPath);
117
- if (cached) {
118
- perfStats.babel.byEnvironment[environment].transforms++;
119
- if (hasCompilerPlugin && (cached.code.includes("react/compiler-runtime") || cached.code.includes("react-compiler-runtime"))) {
120
- debug?.(` \u{1FA84} [compiler] ${relative(process.cwd(), id)} (cached)`);
121
- logCompiled(true, 0);
122
- }
123
- debug?.(`[babel/cached] ${id}`);
124
- return cached;
125
- }
126
- const isWorkletPlugin = entry => {
127
- if (!entry) return false;
128
- const name = typeof entry === "string" ? entry : Array.isArray(entry) ? entry[0] : null;
129
- return typeof name === "string" && (name.includes("react-native-worklets") || name.includes("react-native-reanimated"));
130
- };
131
- const workletEntry = babelOptions.plugins?.find(isWorkletPlugin);
132
- const workletPluginOptions = Array.isArray(workletEntry) ? workletEntry[1] : void 0;
133
- const useWorklets = isNativeWorkletsEnabled() && (Boolean(workletEntry) || shouldTransformWorklets({
134
- id,
135
- code
136
- }));
137
- let curCode = code;
138
- let workletPreparation = null;
139
- let compilerOut = null;
140
- const compilerPluginIndex = babelOptions.plugins?.findIndex(x => Array.isArray(x) && x[0] === "babel-plugin-react-compiler") ?? -1;
141
- if (compilerPluginIndex !== -1) {
142
- const compilerPluginConfig = babelOptions.plugins[compilerPluginIndex];
143
- const compilerPluginOptions = compilerPluginConfig[1] || {};
144
- const useBabelCompiler = compilerPluginOptions.compiler === "babel" || process.env.ONE_REACT_COMPILER === "babel" || process.env.VXRN_REACT_COMPILER === "babel";
145
- if (!useBabelCompiler) {
146
- if (useWorklets) {
147
- workletPreparation = prepareWorkletsForReactCompiler(id, curCode, shouldSourceMap());
148
- if (workletPreparation) curCode = workletPreparation.code;
149
- }
150
- compilerOut = await transformOxcReactCompiler(id, curCode, compilerPluginOptions, shouldSourceMap());
151
- if (compilerOut) curCode = compilerOut.code;
152
- babelOptions.plugins.splice(compilerPluginIndex, 1);
153
- }
154
- }
155
- let workletsOut = null;
156
- if (useWorklets) {
157
- workletsOut = await transformWorklets(id, curCode, shouldSourceMap(), {
158
- projectRoot,
159
- ...workletPluginOptions
160
- });
161
- babelOptions.plugins = babelOptions.plugins?.filter(entry => !isWorkletPlugin(entry));
162
- curCode = workletsOut.code;
163
- }
164
- const startTime = Date.now();
165
- let babelOut = null;
166
- if (babelOptions.plugins?.length === 0 && !babelOptions.configFile && !babelOptions.babelrc) {
167
- let finalMap = void 0;
168
- if (shouldSourceMap()) {
169
- const intermediateMaps = [workletPreparation?.map, compilerOut?.map, workletsOut?.map].filter(Boolean);
170
- if (intermediateMaps.length === 1) {
171
- finalMap = intermediateMaps[0];
172
- } else if (intermediateMaps.length > 1) {
173
- const remapping = (await import("@jridgewell/remapping")).default;
174
- finalMap = remapping(intermediateMaps.slice().reverse(), () => null);
175
- }
176
- }
177
- babelOut = {
178
- code: curCode,
179
- map: finalMap
180
- };
181
- } else {
182
- const babelOptsWithMap = shouldSourceMap() && (workletsOut?.map || compilerOut?.map || workletPreparation?.map) ? {
183
- ...babelOptions,
184
- sourceMaps: true
185
- } : babelOptions;
186
- babelOut = await transformBabel(id, curCode, babelOptsWithMap);
187
- if (shouldSourceMap() && babelOut?.map) {
188
- const priorMaps = [workletPreparation?.map, compilerOut?.map, workletsOut?.map].filter(Boolean);
189
- if (priorMaps.length > 0) {
190
- const remapping = (await import("@jridgewell/remapping")).default;
191
- babelOut.map = remapping([babelOut.map, ...priorMaps.slice().reverse()], () => null);
192
- }
193
- }
194
- }
195
- const babelTime = Date.now() - startTime;
196
- if (babelOut?.code) {
197
- perfStats.babel.totalTransforms++;
198
- perfStats.babel.totalTime += babelTime;
199
- perfStats.babel.byEnvironment[environment].transforms++;
200
- perfStats.babel.byEnvironment[environment].time += babelTime;
201
- if (hasCompilerPlugin && (babelOut.code.includes("react/compiler-runtime") || babelOut.code.includes("react-compiler-runtime"))) {
202
- debug?.(` \u{1FA84} [compiler] ${relative(process.cwd(), id)} (${babelTime}ms)`);
203
- logCompiled(false, babelTime);
204
- }
205
- debug?.(`[babel] ${id}`);
206
- 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}
207
210
  // vxrn-did-babel`;
208
- const result = {
209
- code: outCode,
210
- map: babelOut.map
211
- };
212
- setCachedTransform(id, code, result, environment, userBabelConfigPath);
213
- return result;
214
- }
215
- }
216
- }
217
- 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;
218
221
  }
219
222
  async function createVXRNCompilerPlugin(optionsIn) {
220
- const reactVersion = await (async () => {
221
- const path = resolvePath("react/package.json");
222
- const json = JSON.parse(await readFile(path, "utf-8"));
223
- return json.version;
224
- })();
225
- const envNames = {
226
- ios: true,
227
- android: true,
228
- client: true,
229
- ssr: true
230
- };
231
- function getEnvName(name) {
232
- if (name === "worker") return "ssr";
233
- if (!envNames[name]) throw new Error(`Invalid env: ${name}`);
234
- return name;
235
- }
236
- const reactForRNVersion = reactVersion.split(".")[0];
237
- const cssTransformCache = /* @__PURE__ */new Map();
238
- const rolldownPath = resolvePath("rolldown");
239
- const rolldownNodeMods = rolldownPath.slice(0, rolldownPath.indexOf(sep + "node_modules"));
240
- let config;
241
- return [{
242
- name: "one:compiler-resolve-refresh-runtime",
243
- apply: "serve",
244
- enforce: "pre",
245
- // Run before Vite default resolve to avoid syscalls
246
- resolveId: id => id === runtimePublicPath || id === `${runtimePublicPath}.map` ? id : void 0,
247
- load: id => {
248
- const basePath = dirname(fileURLToPath(import.meta.url));
249
- if (id === runtimePublicPath) {
250
- return readFileSync(join(basePath, "refresh-runtime.mjs"), "utf-8").replace(/\/\/# sourceMappingURL=.*/, "");
251
- }
252
- if (id === `${runtimePublicPath}.map`) {
253
- return JSON.stringify({
254
- version: 3,
255
- sources: [],
256
- mappings: ""
257
- });
258
- }
259
- return void 0;
260
- }
261
- }, {
262
- name: `one:compiler-css-to-js`,
263
- // only .css files can match, so let rust reject everything else
264
- transform: {
265
- filter: {
266
- id: /\.css$/
267
- },
268
- handler(codeIn, id) {
269
- const environment = getEnvName(this.environment.name);
270
- if (configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
271
- {
272
- const data = JSON.stringify(cssToReactNativeRuntime(codeIn, {
273
- inlineRem: 16
274
- }));
275
- const code = `require("nativewind/dist/index.js").__require().StyleSheet.registerCompiled(${data})`;
276
- const newId = `${id}.js`;
277
- const cssId = newId.replace(rolldownNodeMods + sep, "");
278
- cssTransformCache.set(cssId, code);
279
- return {
280
- code,
281
- id: newId,
282
- map: null
283
- };
284
- }
285
- }
286
- }
287
- },
288
- generateBundle(_, bundle) {
289
- const environment = getEnvName(this.environment.name);
290
- if (configuration.enableNativeCSS && (environment === "ios" || environment === "android")) {
291
- const rootJSName = Object.keys(bundle).find(i => {
292
- const chunk = bundle[i];
293
- return chunk.type == "chunk" && chunk.fileName.match(/.[cm]?js(?:\?.+)?$/) != null;
294
- });
295
- if (!rootJSName) {
296
- throw new Error(`Can't find root js, internal one error`);
297
- }
298
- const rootJS = bundle[rootJSName];
299
- const cssAssets = Object.keys(bundle).filter(i => bundle[i].fileName.endsWith(".css.js"));
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
- 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: {
325
- rolldownOptions: {
326
- plugins: [{
327
- name: `transform-before-optimize-deps-${environment}`,
328
- async transform(code, id) {
329
- if (!nodeModulesFilter.test(id)) {
330
- return null;
331
- }
332
- perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;
333
- const production = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test";
334
- debug?.(`[rolldown optimizeDeps] ${id}`);
335
- const result = await performBabelTransform({
336
- id,
337
- code,
338
- projectRoot: config.root,
339
- environment,
340
- production,
341
- reactForRNVersion,
342
- optionsIn
343
- });
344
- if (!result) {
345
- return null;
346
- }
347
- perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;
348
- return {
349
- code: result.code,
350
- map: result.map
351
- };
352
- },
353
- buildEnd() {
354
- if (process.env.DEBUG_COMPILER_PERF) {
355
- const stats = perfStats.optimizeDeps.byEnvironment[environment];
356
- const elapsed = Date.now() - stats.startTime;
357
- console.info(`[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`);
358
- }
359
- const allDone = Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2;
360
- if (allDone) {
361
- logCacheStats();
362
- logPerfSummary();
363
- }
364
- }
365
- }]
366
- }
367
- },
368
- define: {
369
- "process.env.NATIVEWIND_OS": JSON.stringify(environment === "ios" || environment === "android" ? "native" : "web")
370
- }
371
- };
372
- };
373
- return {
374
- environments: {
375
- ios: createEnvironmentConfig("ios"),
376
- android: createEnvironmentConfig("android"),
377
- client: createEnvironmentConfig("client"),
378
- ssr: createEnvironmentConfig("ssr")
379
- }
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'
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
- if (isNative && configuration.enableNativewind) {
397
- code = `import * as x from 'nativewind'
387
+ }
388
+ if (isNative && configuration.enableNativewind) {
389
+ code = `import * as x from 'nativewind'
398
390
  ${code}`;
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
- // wraps client-side TSX/JSX with React Refresh preamble + import.meta.hot.accept
426
- // runs after vite:oxc (no enforce:'pre') so it sees the already-transformed code
427
- {
428
- name: "one:react-refresh-web",
429
- apply: "serve",
430
- transform(code, _id) {
431
- if (this.environment.name !== "client") return;
432
- if (code.includes(runtimePublicPath)) return;
433
- const id = _id.split("?")[0];
434
- if (id.includes("node_modules")) return;
435
- if (id.includes("virtual:")) return;
436
- if (id === runtimePublicPath) return;
437
- const ext = extname(id);
438
- if (ext !== ".tsx" && ext !== ".jsx") return;
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
- if (hasRefreshCalls) {
444
- 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.");
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
- out += code;
453
- if (hasRefreshCalls) {
454
- out += `
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
- out += `
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
- return {
471
- code: out,
472
- map: null
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