@vxrn/compiler 1.27.1 → 2.0.0-beta.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cache.cjs +106 -117
- package/dist/cjs/configure.cjs +26 -28
- package/dist/cjs/constants.cjs +56 -60
- package/dist/cjs/index.cjs +420 -443
- package/dist/cjs/reactNativeCodegen.cjs +105 -114
- package/dist/cjs/reactNativeViewConfig.cjs +362 -381
- package/dist/cjs/refresh-runtime.cjs +390 -397
- package/dist/cjs/transformBabel.cjs +273 -263
- package/dist/cjs/transformHermesAsync.cjs +36 -47
- package/dist/cjs/transformHermesLoops.cjs +279 -281
- package/dist/cjs/transformSWC.cjs +183 -200
- package/dist/cjs/transformWorklets.cjs +107 -95
- package/dist/cjs/types.cjs +9 -11
- package/dist/cjs/worklets/autoworklet.cjs +277 -222
- package/dist/cjs/worklets/globals.cjs +124 -60
- package/dist/cjs/worklets/hash.cjs +23 -27
- package/dist/cjs/worklets/scope.cjs +338 -359
- package/dist/cjs/worklets/serialize.cjs +73 -75
- package/dist/cjs/worklets/transform.cjs +217 -222
- package/dist/cjs/worklets/types.cjs +9 -11
- package/dist/esm/cache.mjs +90 -97
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +11 -10
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/constants.mjs +41 -41
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/index.js +417 -425
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +417 -425
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/reactNativeCodegen.mjs +90 -88
- package/dist/esm/reactNativeCodegen.mjs.map +1 -1
- package/dist/esm/reactNativeViewConfig.mjs +347 -362
- package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
- package/dist/esm/refresh-runtime.mjs +372 -376
- package/dist/esm/refresh-runtime.mjs.map +1 -1
- package/dist/esm/transformBabel.mjs +255 -237
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformHermesAsync.mjs +20 -21
- package/dist/esm/transformHermesAsync.mjs.map +1 -1
- package/dist/esm/transformHermesLoops.mjs +264 -255
- package/dist/esm/transformHermesLoops.mjs.map +1 -1
- package/dist/esm/transformSWC.mjs +163 -171
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformWorklets.mjs +89 -69
- package/dist/esm/transformWorklets.mjs.map +1 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/worklets/autoworklet.mjs +258 -200
- package/dist/esm/worklets/autoworklet.mjs.map +1 -1
- package/dist/esm/worklets/globals.mjs +109 -42
- package/dist/esm/worklets/globals.mjs.map +1 -1
- package/dist/esm/worklets/hash.mjs +10 -9
- package/dist/esm/worklets/hash.mjs.map +1 -1
- package/dist/esm/worklets/scope.mjs +325 -341
- package/dist/esm/worklets/scope.mjs.map +1 -1
- package/dist/esm/worklets/serialize.mjs +60 -58
- package/dist/esm/worklets/serialize.mjs.map +1 -1
- package/dist/esm/worklets/transform.mjs +201 -197
- package/dist/esm/worklets/transform.mjs.map +1 -1
- package/dist/esm/worklets/types.mjs +0 -2
- package/package.json +7 -6
- package/src/transformBabel.test.ts +77 -17
- package/src/transformBabel.ts +28 -12
- package/types/transformBabel.d.ts +12 -0
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformSWC.d.ts +1 -4
- package/types/transformSWC.d.ts.map +1 -1
- package/dist/cjs/transformBabel.test.cjs +0 -652
- package/dist/cjs/transformHermesLoops.test.cjs +0 -257
- package/dist/cjs/transformSWC.test.cjs +0 -117
- package/dist/cjs/transformWorklets.test.cjs +0 -604
- package/dist/esm/transformBabel.test.mjs +0 -629
- package/dist/esm/transformBabel.test.mjs.map +0 -1
- package/dist/esm/transformHermesLoops.test.mjs +0 -234
- package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
- package/dist/esm/transformSWC.test.mjs +0 -118
- package/dist/esm/transformSWC.test.mjs.map +0 -1
- package/dist/esm/transformWorklets.test.mjs +0 -581
- package/dist/esm/transformWorklets.test.mjs.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/worklets/types.mjs.map +0 -1
- package/types/transformBabel.test.d.ts +0 -2
- package/types/transformBabel.test.d.ts.map +0 -1
- package/types/transformHermesLoops.test.d.ts +0 -2
- package/types/transformHermesLoops.test.d.ts.map +0 -1
- package/types/transformSWC.test.d.ts +0 -2
- package/types/transformSWC.test.d.ts.map +0 -1
- package/types/transformWorklets.test.d.ts +0 -2
- package/types/transformWorklets.test.d.ts.map +0 -1
|
@@ -1,652 +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
|
-
});
|
|
449
|
-
(0, import_vitest.describe)("explicit swc/oxc per-file choice with a user babel config", () => {
|
|
450
|
-
(0, import_vitest.it)("returns null for swc/oxc string and object forms", () => {
|
|
451
|
-
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-")));
|
|
452
|
-
const userConfig = import_node_path.default.join(projectRoot, "babel.config.js");
|
|
453
|
-
import_node_fs.default.writeFileSync(userConfig, "module.exports = { plugins: [] }");
|
|
454
|
-
try {
|
|
455
|
-
const base = {
|
|
456
|
-
id: import_node_path.default.join(projectRoot, "src", "index.tsx"),
|
|
457
|
-
code: `export const x = 1`,
|
|
458
|
-
projectRoot,
|
|
459
|
-
development: true,
|
|
460
|
-
environment: "client",
|
|
461
|
-
reactForRNVersion: "19"
|
|
462
|
-
};
|
|
463
|
-
(0, import_vitest.expect)((0, import_transformBabel.getBabelOptions)({
|
|
464
|
-
...base,
|
|
465
|
-
userSetting: "swc"
|
|
466
|
-
})).toBeNull();
|
|
467
|
-
(0, import_vitest.expect)((0, import_transformBabel.getBabelOptions)({
|
|
468
|
-
...base,
|
|
469
|
-
userSetting: "oxc"
|
|
470
|
-
})).toBeNull();
|
|
471
|
-
(0, import_vitest.expect)((0, import_transformBabel.getBabelOptions)({
|
|
472
|
-
...base,
|
|
473
|
-
userSetting: {
|
|
474
|
-
transform: "swc"
|
|
475
|
-
}
|
|
476
|
-
})).toBeNull();
|
|
477
|
-
(0, import_vitest.expect)((0, import_transformBabel.getBabelOptions)({
|
|
478
|
-
...base,
|
|
479
|
-
userSetting: {
|
|
480
|
-
transform: "oxc"
|
|
481
|
-
}
|
|
482
|
-
})).toBeNull();
|
|
483
|
-
(0, import_vitest.expect)((0, import_transformBabel.getBabelOptions)({
|
|
484
|
-
...base,
|
|
485
|
-
userSetting: "babel"
|
|
486
|
-
})?.configFile).toBe(userConfig);
|
|
487
|
-
(0, import_vitest.expect)((0, import_transformBabel.getBabelOptions)({
|
|
488
|
-
...base,
|
|
489
|
-
userSetting: {
|
|
490
|
-
transform: "babel"
|
|
491
|
-
}
|
|
492
|
-
})?.configFile).toBe(userConfig);
|
|
493
|
-
(0, import_vitest.expect)((0, import_transformBabel.getBabelOptions)(base)?.configFile).toBe(userConfig);
|
|
494
|
-
} finally {
|
|
495
|
-
import_node_fs.default.rmSync(projectRoot, {
|
|
496
|
-
recursive: true,
|
|
497
|
-
force: true
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
});
|
|
501
|
-
(0, import_vitest.it)("skips the transform end-to-end for object-form swc", async () => {
|
|
502
|
-
const {
|
|
503
|
-
createVXRNCompilerPlugin
|
|
504
|
-
} = await import("./index");
|
|
505
|
-
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-")));
|
|
506
|
-
const srcDir = import_node_path.default.join(projectRoot, "src");
|
|
507
|
-
import_node_fs.default.mkdirSync(srcDir, {
|
|
508
|
-
recursive: true
|
|
509
|
-
});
|
|
510
|
-
const file = import_node_path.default.join(srcDir, "index.ts");
|
|
511
|
-
const code = `export const x = 1`;
|
|
512
|
-
import_node_fs.default.writeFileSync(file, code);
|
|
513
|
-
import_node_fs.default.writeFileSync(import_node_path.default.join(projectRoot, "babel.config.js"), "module.exports = { plugins: [] }");
|
|
514
|
-
(0, import_configure.configureVXRNCompilerPlugin)({
|
|
515
|
-
enableCompiler: false,
|
|
516
|
-
enableReanimated: false
|
|
517
|
-
});
|
|
518
|
-
try {
|
|
519
|
-
const plugins = await createVXRNCompilerPlugin({
|
|
520
|
-
transform: () => ({
|
|
521
|
-
transform: "swc"
|
|
522
|
-
})
|
|
523
|
-
});
|
|
524
|
-
const plugin = plugins.find(p => p.name === "one:compiler");
|
|
525
|
-
await plugin.configResolved({
|
|
526
|
-
root: projectRoot,
|
|
527
|
-
build: {}
|
|
528
|
-
});
|
|
529
|
-
const hook = plugin.transform.handler || plugin.transform;
|
|
530
|
-
const result = await hook.call({
|
|
531
|
-
environment: {
|
|
532
|
-
name: "client"
|
|
533
|
-
}
|
|
534
|
-
}, code, file);
|
|
535
|
-
(0, import_vitest.expect)(result == null).toBe(true);
|
|
536
|
-
} finally {
|
|
537
|
-
(0, import_configure.configureVXRNCompilerPlugin)({
|
|
538
|
-
enableCompiler: false,
|
|
539
|
-
enableReanimated: false
|
|
540
|
-
});
|
|
541
|
-
import_node_fs.default.rmSync(projectRoot, {
|
|
542
|
-
recursive: true,
|
|
543
|
-
force: true
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
(0, import_vitest.describe)("user babel config end-to-end through the compiler plugin", () => {
|
|
549
|
-
(0, import_vitest.it)("runs the user config when default plugins are empty", async () => {
|
|
550
|
-
const {
|
|
551
|
-
createVXRNCompilerPlugin
|
|
552
|
-
} = await import("./index");
|
|
553
|
-
const projectRoot = import_node_fs.default.realpathSync(import_node_fs.default.mkdtempSync(import_node_path.default.join(import_node_os.default.tmpdir(), "vxrn-babel-e2e-")));
|
|
554
|
-
const srcDir = import_node_path.default.join(projectRoot, "src");
|
|
555
|
-
import_node_fs.default.mkdirSync(srcDir, {
|
|
556
|
-
recursive: true
|
|
557
|
-
});
|
|
558
|
-
const file = import_node_path.default.join(srcDir, "index.ts");
|
|
559
|
-
const marker = "babel-e2e-probe";
|
|
560
|
-
const code = `/* ${marker} */ export const x = 1`;
|
|
561
|
-
import_node_fs.default.writeFileSync(file, code);
|
|
562
|
-
import_node_fs.default.writeFileSync(import_node_path.default.join(projectRoot, "babel.config.json"), JSON.stringify({
|
|
563
|
-
comments: false
|
|
564
|
-
}));
|
|
565
|
-
(0, import_configure.configureVXRNCompilerPlugin)({
|
|
566
|
-
enableCompiler: false,
|
|
567
|
-
enableReanimated: false
|
|
568
|
-
});
|
|
569
|
-
try {
|
|
570
|
-
const plugins = await createVXRNCompilerPlugin();
|
|
571
|
-
const plugin = plugins.find(p => p.name === "one:compiler");
|
|
572
|
-
await plugin.configResolved({
|
|
573
|
-
root: projectRoot,
|
|
574
|
-
build: {}
|
|
575
|
-
});
|
|
576
|
-
const hook = plugin.transform.handler || plugin.transform;
|
|
577
|
-
const result = await hook.call({
|
|
578
|
-
environment: {
|
|
579
|
-
name: "client"
|
|
580
|
-
}
|
|
581
|
-
}, code, file);
|
|
582
|
-
(0, import_vitest.expect)(result).toBeDefined();
|
|
583
|
-
(0, import_vitest.expect)(result.code).toContain("export const x = 1");
|
|
584
|
-
(0, import_vitest.expect)(result.code).not.toContain(marker);
|
|
585
|
-
} finally {
|
|
586
|
-
(0, import_configure.configureVXRNCompilerPlugin)({
|
|
587
|
-
enableCompiler: false,
|
|
588
|
-
enableReanimated: false
|
|
589
|
-
});
|
|
590
|
-
import_node_fs.default.rmSync(projectRoot, {
|
|
591
|
-
recursive: true,
|
|
592
|
-
force: true
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
(0, import_vitest.it)("invalidates the cache when the user babel config is added or edited", async () => {
|
|
597
|
-
const {
|
|
598
|
-
createVXRNCompilerPlugin
|
|
599
|
-
} = await import("./index");
|
|
600
|
-
const projectRoot = import_node_fs.default.realpathSync(import_node_fs.default.mkdtempSync(import_node_path.default.join(import_node_os.default.tmpdir(), "vxrn-babel-cache-")));
|
|
601
|
-
const srcDir = import_node_path.default.join(projectRoot, "src");
|
|
602
|
-
import_node_fs.default.mkdirSync(srcDir, {
|
|
603
|
-
recursive: true
|
|
604
|
-
});
|
|
605
|
-
const file = import_node_path.default.join(srcDir, "index.ts");
|
|
606
|
-
const marker = "babel-cache-probe";
|
|
607
|
-
const code = `/* ${marker} */ export const x = 1`;
|
|
608
|
-
import_node_fs.default.writeFileSync(file, code);
|
|
609
|
-
const userConfig = import_node_path.default.join(projectRoot, "babel.config.json");
|
|
610
|
-
(0, import_configure.configureVXRNCompilerPlugin)({
|
|
611
|
-
enableCompiler: false,
|
|
612
|
-
enableReanimated: false
|
|
613
|
-
});
|
|
614
|
-
try {
|
|
615
|
-
const plugins = await createVXRNCompilerPlugin({
|
|
616
|
-
transform: () => "babel"
|
|
617
|
-
});
|
|
618
|
-
const plugin = plugins.find(p => p.name === "one:compiler");
|
|
619
|
-
await plugin.configResolved({
|
|
620
|
-
root: projectRoot,
|
|
621
|
-
build: {}
|
|
622
|
-
});
|
|
623
|
-
const hook = plugin.transform.handler || plugin.transform;
|
|
624
|
-
const context = {
|
|
625
|
-
environment: {
|
|
626
|
-
name: "client"
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
const res1 = await hook.call(context, code, file);
|
|
630
|
-
(0, import_vitest.expect)(res1.code).toContain(marker);
|
|
631
|
-
import_node_fs.default.writeFileSync(userConfig, JSON.stringify({
|
|
632
|
-
comments: false
|
|
633
|
-
}));
|
|
634
|
-
const res2 = await hook.call(context, code, file);
|
|
635
|
-
(0, import_vitest.expect)(res2.code).not.toContain(marker);
|
|
636
|
-
import_node_fs.default.writeFileSync(userConfig, JSON.stringify({
|
|
637
|
-
comments: true
|
|
638
|
-
}));
|
|
639
|
-
const res3 = await hook.call(context, code, file);
|
|
640
|
-
(0, import_vitest.expect)(res3.code).toContain(marker);
|
|
641
|
-
} finally {
|
|
642
|
-
(0, import_configure.configureVXRNCompilerPlugin)({
|
|
643
|
-
enableCompiler: false,
|
|
644
|
-
enableReanimated: false
|
|
645
|
-
});
|
|
646
|
-
import_node_fs.default.rmSync(projectRoot, {
|
|
647
|
-
recursive: true,
|
|
648
|
-
force: true
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
});
|