@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
@@ -1,448 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
- get: () => from[key],
11
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
- });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
- value: mod,
23
- enumerable: true
24
- }) : target, mod));
25
- var import_node_fs = __toESM(require("node:fs"), 1);
26
- var import_node_os = __toESM(require("node:os"), 1);
27
- var import_node_path = __toESM(require("node:path"), 1);
28
- var import_vitest = require("vitest");
29
- var import_configure = require("./configure.cjs");
30
- var import_transformBabel = require("./transformBabel.cjs");
31
- (0, import_vitest.afterEach)(() => {
32
- (0, import_configure.configureVXRNCompilerPlugin)({
33
- enableReanimated: false
34
- });
35
- });
36
- (0, import_vitest.describe)("getBabelOptions Worklets resolution", () => {
37
- (0, import_vitest.it)("uses the app-installed Worklets Babel plugin", () => {
38
- const projectRoot = import_node_fs.default.realpathSync(import_node_fs.default.mkdtempSync(import_node_path.default.join(import_node_os.default.tmpdir(), "vxrn-worklets-")));
39
- const packageRoot = import_node_path.default.join(projectRoot, "node_modules", "react-native-worklets");
40
- const pluginPath = import_node_path.default.join(packageRoot, "plugin.js");
41
- import_node_fs.default.mkdirSync(packageRoot, {
42
- recursive: true
43
- });
44
- import_node_fs.default.writeFileSync(import_node_path.default.join(packageRoot, "package.json"), JSON.stringify({
45
- name: "react-native-worklets",
46
- version: "99.0.0"
47
- }));
48
- import_node_fs.default.writeFileSync(pluginPath, "module.exports = () => ({ visitor: {} })");
49
- try {
50
- (0, import_configure.configureVXRNCompilerPlugin)({
51
- enableReanimated: true
52
- });
53
- const options = (0, import_transformBabel.getBabelOptions)({
54
- id: import_node_path.default.join(projectRoot, "input.ts"),
55
- code: `export const worklet = () => {
56
- 'worklet'
57
- }`,
58
- development: true,
59
- environment: "ios",
60
- reactForRNVersion: "19",
61
- projectRoot
62
- });
63
- (0, import_vitest.expect)(options?.plugins).toContain(pluginPath);
64
- } finally {
65
- import_node_fs.default.rmSync(projectRoot, {
66
- recursive: true,
67
- force: true
68
- });
69
- }
70
- });
71
- });
72
- (0, import_vitest.describe)("transformBabel Flow parsing", () => {
73
- (0, import_vitest.it)("parses and strips React Native Flow as-casts", async () => {
74
- const result = await (0, import_transformBabel.transformBabel)("/project/VirtualViewNativeComponent.js", `
75
- // @flow strict-local
76
- import type { HostComponent } from './HostComponent'
77
- import codegenNativeComponent from './codegenNativeComponent'
78
-
79
- type Props = $ReadOnly<{ enabled?: boolean }>
80
-
81
- export default codegenNativeComponent<Props>('VirtualView') as HostComponent<Props>
82
- `, {
83
- plugins: []
84
- });
85
- (0, import_vitest.expect)(result?.code).toContain("codegenNativeComponent('VirtualView')");
86
- (0, import_vitest.expect)(result?.code).not.toContain("HostComponent");
87
- });
88
- (0, import_vitest.it)("rejects a required transform error instead of returning untransformed source", async () => {
89
- const negativeControl = () => ({
90
- visitor: {
91
- Program() {
92
- throw new Error("NATIVE_TRANSFORM_NEGATIVE_CONTROL");
93
- }
94
- }
95
- });
96
- await (0, import_vitest.expect)((0, import_transformBabel.transformBabel)("/project/TransformProbe.ts", "export const marker = 1", {
97
- plugins: [negativeControl]
98
- })).rejects.toThrow("NATIVE_TRANSFORM_NEGATIVE_CONTROL");
99
- });
100
- });
101
- (0, import_vitest.describe)("transformOxcReactCompiler", () => {
102
- const componentCode = `
103
- import { useState } from 'react'
104
-
105
- export function Counter() {
106
- const [count, setCount] = useState(0)
107
- return <button onClick={() => setCount(count + 1)}>{count}</button>
108
- }
109
- `;
110
- (0, import_vitest.it)("compiles and memoizes React components with Rust React Compiler", async () => {
111
- const result = await (0, import_transformBabel.transformOxcReactCompiler)("/project/Counter.tsx", componentCode, "19", false);
112
- (0, import_vitest.expect)(result.code).toContain("_c(");
113
- (0, import_vitest.expect)(result.code).toContain("react/compiler-runtime");
114
- (0, import_vitest.expect)(result.map).toBeUndefined();
115
- });
116
- (0, import_vitest.it)("generates source maps when requested", async () => {
117
- const result = await (0, import_transformBabel.transformOxcReactCompiler)("/project/Counter.tsx", componentCode, "19", true);
118
- (0, import_vitest.expect)(result.code).toContain("_c(");
119
- (0, import_vitest.expect)(result.map).toBeDefined();
120
- (0, import_vitest.expect)(result.map?.mappings).toBeDefined();
121
- });
122
- (0, import_vitest.it)("supports target 18", async () => {
123
- const result = await (0, import_transformBabel.transformOxcReactCompiler)("/project/Counter.tsx", componentCode, "18", false);
124
- (0, import_vitest.expect)(result.code).toContain("_c(");
125
- });
126
- (0, import_vitest.it)("supports mutating useSharedValue in useEffect via Reanimated environment defaults", async () => {
127
- const reanimatedCode = `
128
- import { useEffect } from 'react'
129
- import { useSharedValue } from 'react-native-reanimated'
130
-
131
- export function ReanimatedComponent() {
132
- const val = useSharedValue(0)
133
- useEffect(() => {
134
- val.value = 1
135
- }, [val])
136
- return <div>{val.value}</div>
137
- }
138
- `;
139
- const result = await (0, import_transformBabel.transformOxcReactCompiler)("/project/ReanimatedComponent.tsx", reanimatedCode, {
140
- target: "19"
141
- }, false);
142
- (0, import_vitest.expect)(result.code).toContain("_c(");
143
- });
144
- });
145
- (0, import_vitest.describe)("compiler plugin multi-stage source map composition", () => {
146
- (0, import_vitest.it)("composes earlier compiler maps when Babel also runs", async () => {
147
- const {
148
- createVXRNCompilerPlugin
149
- } = await import("./index");
150
- const {
151
- TraceMap,
152
- originalPositionFor
153
- } = await import("@jridgewell/trace-mapping");
154
- const origSourceMap = process.env.VXRN_ENABLE_SOURCE_MAP;
155
- const origBabelGen = process.env.VXRN_USE_BABEL_FOR_GENERATORS;
156
- process.env.VXRN_ENABLE_SOURCE_MAP = "1";
157
- process.env.VXRN_USE_BABEL_FOR_GENERATORS = "1";
158
- (0, import_configure.configureVXRNCompilerPlugin)({
159
- enableCompiler: true
160
- });
161
- const tempFile = import_node_path.default.join(import_node_os.default.tmpdir(), `Counter-${Date.now()}.tsx`);
162
- import_node_fs.default.writeFileSync(tempFile, `import { useState } from 'react'
163
-
164
- export function Counter() {
165
- const [count, setCount] = useState(0)
166
- return <button onClick={() => setCount(count + 1)}>{count}</button>
167
- }
168
-
169
- export async function* generatorProbe() {
170
- throw new Error("MARKER")
171
- }
172
- `);
173
- try {
174
- const plugins = await createVXRNCompilerPlugin();
175
- const plugin = plugins.find(p => p.name === "one:compiler");
176
- await plugin.configResolved({
177
- root: import_node_os.default.tmpdir(),
178
- build: {}
179
- });
180
- const hook = plugin.transform.handler || plugin.transform;
181
- const code = import_node_fs.default.readFileSync(tempFile, "utf8");
182
- const context = {
183
- environment: {
184
- name: "client"
185
- }
186
- };
187
- const result = await hook.call(context, code, tempFile);
188
- (0, import_vitest.expect)(result).toBeDefined();
189
- (0, import_vitest.expect)(result.map).toBeDefined();
190
- const tracer = new TraceMap(result.map);
191
- const lines = result.code.split("\n");
192
- const markerLineIndex = lines.findIndex(l => l.includes("MARKER"));
193
- (0, import_vitest.expect)(markerLineIndex).toBeGreaterThan(0);
194
- const markerCol = lines[markerLineIndex].indexOf("throw");
195
- const pos = originalPositionFor(tracer, {
196
- line: markerLineIndex + 1,
197
- column: markerCol
198
- });
199
- (0, import_vitest.expect)(pos.source).toBe(tempFile);
200
- (0, import_vitest.expect)(pos.line).toBe(9);
201
- } finally {
202
- if (origSourceMap !== void 0) {
203
- process.env.VXRN_ENABLE_SOURCE_MAP = origSourceMap;
204
- } else {
205
- delete process.env.VXRN_ENABLE_SOURCE_MAP;
206
- }
207
- if (origBabelGen !== void 0) {
208
- process.env.VXRN_USE_BABEL_FOR_GENERATORS = origBabelGen;
209
- } else {
210
- delete process.env.VXRN_USE_BABEL_FOR_GENERATORS;
211
- }
212
- (0, import_configure.configureVXRNCompilerPlugin)({
213
- enableCompiler: false
214
- });
215
- import_node_fs.default.rmSync(tempFile, {
216
- force: true
217
- });
218
- }
219
- });
220
- });
221
- (0, import_vitest.describe)("shared compiler worklets backend selection", () => {
222
- (0, import_vitest.it)("retains Babel for worklets by default when enableNativeWorklets is false", async () => {
223
- const {
224
- vi
225
- } = await import("vitest");
226
- const {
227
- createVXRNCompilerPlugin
228
- } = await import("./index");
229
- const workletsModule = await import("./transformWorklets");
230
- const workletSpy = vi.spyOn(workletsModule, "transformWorklets");
231
- (0, import_configure.configureVXRNCompilerPlugin)({
232
- enableReanimated: true,
233
- enableNativeWorklets: false
234
- });
235
- const tempFile = import_node_path.default.join(process.cwd(), `test-default-worklet-${Date.now()}.tsx`);
236
- const inputCode = `export function fn() { 'worklet'; return 1 }`;
237
- import_node_fs.default.writeFileSync(tempFile, inputCode);
238
- try {
239
- const plugins = await createVXRNCompilerPlugin();
240
- const plugin = plugins.find(p => p.name === "one:compiler");
241
- await plugin.configResolved({
242
- root: process.cwd(),
243
- build: {}
244
- });
245
- const hook = plugin.transform.handler || plugin.transform;
246
- const context = {
247
- environment: {
248
- name: "ios"
249
- }
250
- };
251
- const result = await hook.call(context, inputCode, tempFile);
252
- (0, import_vitest.expect)(result).toBeDefined();
253
- (0, import_vitest.expect)(workletSpy).not.toHaveBeenCalled();
254
- } finally {
255
- workletSpy.mockRestore();
256
- (0, import_configure.configureVXRNCompilerPlugin)({
257
- enableReanimated: false,
258
- enableNativeWorklets: false
259
- });
260
- import_node_fs.default.rmSync(tempFile, {
261
- force: true
262
- });
263
- }
264
- });
265
- (0, import_vitest.it)("uses native SWC for worklets when enableNativeWorklets is true", async () => {
266
- const compiler = await import("./index");
267
- const {
268
- vi
269
- } = await import("vitest");
270
- const workletsModule = await import("./transformWorklets");
271
- const workletSpy = vi.spyOn(workletsModule, "transformWorklets");
272
- (0, import_configure.configureVXRNCompilerPlugin)({
273
- enableReanimated: true,
274
- enableNativeWorklets: true
275
- });
276
- const tempFile = import_node_path.default.join(process.cwd(), `test-native-worklet-${Date.now()}.tsx`);
277
- const inputCode = `export function fn() { 'worklet'; return 1 }`;
278
- import_node_fs.default.writeFileSync(tempFile, inputCode);
279
- try {
280
- const plugins = await compiler.createVXRNCompilerPlugin();
281
- const plugin = plugins.find(p => p.name === "one:compiler");
282
- await plugin.configResolved({
283
- root: process.cwd(),
284
- build: {}
285
- });
286
- const hook = plugin.transform.handler || plugin.transform;
287
- const context = {
288
- environment: {
289
- name: "ios"
290
- }
291
- };
292
- const result = await hook.call(context, inputCode, tempFile);
293
- (0, import_vitest.expect)(result).toBeDefined();
294
- (0, import_vitest.expect)(workletSpy).toHaveBeenCalled();
295
- } finally {
296
- workletSpy.mockRestore();
297
- (0, import_configure.configureVXRNCompilerPlugin)({
298
- enableReanimated: false,
299
- enableNativeWorklets: false
300
- });
301
- import_node_fs.default.rmSync(tempFile, {
302
- force: true
303
- });
304
- }
305
- });
306
- (0, import_vitest.it)("invalidates cache when toggling worklets backend on the same unchanged file", async () => {
307
- const compiler = await import("./index");
308
- const {
309
- vi
310
- } = await import("vitest");
311
- const workletsModule = await import("./transformWorklets");
312
- const workletSpy = vi.spyOn(workletsModule, "transformWorklets");
313
- const tempFile = import_node_path.default.join(process.cwd(), `test-cache-toggle-${Date.now()}.tsx`);
314
- const inputCode = `export function fn() { 'worklet'; return 1 }`;
315
- import_node_fs.default.writeFileSync(tempFile, inputCode);
316
- try {
317
- (0, import_configure.configureVXRNCompilerPlugin)({
318
- enableReanimated: true,
319
- enableNativeWorklets: false
320
- });
321
- const plugins1 = await compiler.createVXRNCompilerPlugin();
322
- const plugin1 = plugins1.find(p => p.name === "one:compiler");
323
- await plugin1.configResolved({
324
- root: process.cwd(),
325
- build: {}
326
- });
327
- const hook1 = plugin1.transform.handler || plugin1.transform;
328
- const context = {
329
- environment: {
330
- name: "ios"
331
- }
332
- };
333
- const res1 = await hook1.call(context, inputCode, tempFile);
334
- (0, import_vitest.expect)(res1).toBeDefined();
335
- (0, import_vitest.expect)(workletSpy).toHaveBeenCalledTimes(0);
336
- (0, import_configure.configureVXRNCompilerPlugin)({
337
- enableReanimated: true,
338
- enableNativeWorklets: true
339
- });
340
- const plugins2 = await compiler.createVXRNCompilerPlugin();
341
- const plugin2 = plugins2.find(p => p.name === "one:compiler");
342
- await plugin2.configResolved({
343
- root: process.cwd(),
344
- build: {}
345
- });
346
- const hook2 = plugin2.transform.handler || plugin2.transform;
347
- const res2 = await hook2.call(context, inputCode, tempFile);
348
- (0, import_vitest.expect)(res2).toBeDefined();
349
- (0, import_vitest.expect)(workletSpy).toHaveBeenCalledTimes(1);
350
- const res3 = await hook2.call(context, inputCode, tempFile);
351
- (0, import_vitest.expect)(res3).toBeDefined();
352
- (0, import_vitest.expect)(workletSpy).toHaveBeenCalledTimes(1);
353
- (0, import_configure.configureVXRNCompilerPlugin)({
354
- enableReanimated: true,
355
- enableNativeWorklets: false
356
- });
357
- const plugins3 = await compiler.createVXRNCompilerPlugin();
358
- const plugin3 = plugins3.find(p => p.name === "one:compiler");
359
- await plugin3.configResolved({
360
- root: process.cwd(),
361
- build: {}
362
- });
363
- const hook3 = plugin3.transform.handler || plugin3.transform;
364
- const res4 = await hook3.call(context, inputCode, tempFile);
365
- (0, import_vitest.expect)(res4).toBeDefined();
366
- (0, import_vitest.expect)(workletSpy).toHaveBeenCalledTimes(1);
367
- } finally {
368
- workletSpy.mockRestore();
369
- (0, import_configure.configureVXRNCompilerPlugin)({
370
- enableReanimated: false,
371
- enableNativeWorklets: false
372
- });
373
- import_node_fs.default.rmSync(tempFile, {
374
- force: true
375
- });
376
- }
377
- });
378
- });
379
- (0, import_vitest.describe)("findUserBabelConfig and user Babel config respect", () => {
380
- (0, import_vitest.it)("finds user babel config and ignores generated configs", () => {
381
- const projectRoot = import_node_fs.default.realpathSync(import_node_fs.default.mkdtempSync(import_node_path.default.join(import_node_os.default.tmpdir(), "vxrn-babel-conf-")));
382
- try {
383
- (0, import_vitest.expect)((0, import_transformBabel.findUserBabelConfig)(projectRoot)).toBeNull();
384
- const generatedFile = import_node_path.default.join(projectRoot, "babel.config.js");
385
- import_node_fs.default.writeFileSync(generatedFile, "// @one-generated\nmodule.exports = {}");
386
- (0, import_vitest.expect)((0, import_transformBabel.findUserBabelConfig)(projectRoot)).toBeNull();
387
- import_node_fs.default.writeFileSync(generatedFile, "module.exports = { plugins: [] }");
388
- (0, import_vitest.expect)((0, import_transformBabel.findUserBabelConfig)(projectRoot)).toBe(generatedFile);
389
- } finally {
390
- import_node_fs.default.rmSync(projectRoot, {
391
- recursive: true,
392
- force: true
393
- });
394
- }
395
- });
396
- (0, import_vitest.it)("includes user configFile and babelrc in getBabelOptions for project files", () => {
397
- const projectRoot = import_node_fs.default.realpathSync(import_node_fs.default.mkdtempSync(import_node_path.default.join(import_node_os.default.tmpdir(), "vxrn-babel-conf-")));
398
- const userConfig = import_node_path.default.join(projectRoot, "babel.config.json");
399
- import_node_fs.default.writeFileSync(userConfig, '{"plugins": []}');
400
- try {
401
- const projectFileOptions = (0, import_transformBabel.getBabelOptions)({
402
- id: import_node_path.default.join(projectRoot, "src", "index.tsx"),
403
- code: `export const hello = () => 123`,
404
- projectRoot,
405
- development: true,
406
- environment: "client",
407
- reactForRNVersion: "19"
408
- });
409
- (0, import_vitest.expect)(projectFileOptions?.configFile).toBe(userConfig);
410
- (0, import_vitest.expect)(projectFileOptions?.babelrc).toBe(true);
411
- const nodeModulesOptions = (0, import_transformBabel.getBabelOptions)({
412
- id: import_node_path.default.join(projectRoot, "node_modules", "foo", "index.js"),
413
- code: `export const foo = 1`,
414
- projectRoot,
415
- development: true,
416
- environment: "client",
417
- reactForRNVersion: "19"
418
- });
419
- (0, import_vitest.expect)(nodeModulesOptions).toBeNull();
420
- } finally {
421
- import_node_fs.default.rmSync(projectRoot, {
422
- recursive: true,
423
- force: true
424
- });
425
- }
426
- });
427
- (0, import_vitest.it)("runs user babel config transforms via transformBabel", async () => {
428
- const projectRoot = import_node_fs.default.realpathSync(import_node_fs.default.mkdtempSync(import_node_path.default.join(import_node_os.default.tmpdir(), "vxrn-babel-conf-")));
429
- const userConfig = import_node_path.default.join(projectRoot, "babel.config.json");
430
- import_node_fs.default.writeFileSync(userConfig, JSON.stringify({
431
- comments: false
432
- }));
433
- try {
434
- const code = "/* remove me */ export const x = 1";
435
- const res = await (0, import_transformBabel.transformBabel)(import_node_path.default.join(projectRoot, "src", "index.ts"), code, {
436
- configFile: userConfig,
437
- babelrc: true
438
- });
439
- (0, import_vitest.expect)(res.code).not.toContain("remove me");
440
- (0, import_vitest.expect)(res.code).toContain("export const x = 1");
441
- } finally {
442
- import_node_fs.default.rmSync(projectRoot, {
443
- recursive: true,
444
- force: true
445
- });
446
- }
447
- });
448
- });