@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.
- package/dist/cjs/cache.cjs +112 -109
- package/dist/cjs/configure.cjs +26 -28
- package/dist/cjs/constants.cjs +56 -60
- package/dist/cjs/index.cjs +420 -442
- 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 -259
- 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 +96 -89
- 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 -424
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +417 -424
- 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 -233
- 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/cache.ts +37 -7
- package/src/index.ts +7 -3
- package/src/transformBabel.test.ts +209 -9
- package/src/transformBabel.ts +41 -12
- package/src/transformWorklets.test.ts +7 -1
- package/types/cache.d.ts +2 -2
- package/types/cache.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- 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 -448
- 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 -425
- 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
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
afterEach(() => {
|
|
14
14
|
configureVXRNCompilerPlugin({ enableReanimated: false })
|
|
15
15
|
})
|
|
16
|
-
|
|
17
16
|
describe('getBabelOptions Worklets resolution', () => {
|
|
18
17
|
it('uses the app-installed Worklets Babel plugin', () => {
|
|
19
18
|
const projectRoot = fs.realpathSync(
|
|
@@ -68,6 +67,27 @@ describe('transformBabel Flow parsing', () => {
|
|
|
68
67
|
expect(result?.code).not.toContain('HostComponent')
|
|
69
68
|
})
|
|
70
69
|
|
|
70
|
+
it('preserves React Native Flow enums as runtime values', async () => {
|
|
71
|
+
const result = await transformBabel(
|
|
72
|
+
'/project/VirtualView.js',
|
|
73
|
+
`
|
|
74
|
+
// @flow strict-local
|
|
75
|
+
export enum VirtualViewRenderState {
|
|
76
|
+
Unknown = 0,
|
|
77
|
+
Rendered = 1,
|
|
78
|
+
None = 2,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const rendered = VirtualViewRenderState.Rendered
|
|
82
|
+
`,
|
|
83
|
+
{ plugins: [] }
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
expect(result?.code).toContain('const VirtualViewRenderState =')
|
|
87
|
+
expect(result?.code).toContain('Rendered: 1')
|
|
88
|
+
expect(result?.code).toContain('VirtualViewRenderState.Rendered')
|
|
89
|
+
})
|
|
90
|
+
|
|
71
91
|
it('rejects a required transform error instead of returning untransformed source', async () => {
|
|
72
92
|
const negativeControl = () => ({
|
|
73
93
|
visitor: {
|
|
@@ -379,9 +399,12 @@ describe('findUserBabelConfig and user Babel config respect', () => {
|
|
|
379
399
|
try {
|
|
380
400
|
expect(findUserBabelConfig(projectRoot)).toBeNull()
|
|
381
401
|
|
|
382
|
-
//
|
|
402
|
+
// written by `one patch` with the generated marker -> ignored
|
|
383
403
|
const generatedFile = path.join(projectRoot, 'babel.config.js')
|
|
384
|
-
fs.writeFileSync(
|
|
404
|
+
fs.writeFileSync(
|
|
405
|
+
generatedFile,
|
|
406
|
+
'// @one/generated bundler-config\nmodule.exports = {}'
|
|
407
|
+
)
|
|
385
408
|
expect(findUserBabelConfig(projectRoot)).toBeNull()
|
|
386
409
|
|
|
387
410
|
// Overwritten with user config -> detected
|
|
@@ -440,19 +463,196 @@ describe('findUserBabelConfig and user Babel config respect', () => {
|
|
|
440
463
|
)
|
|
441
464
|
try {
|
|
442
465
|
const code = '/* remove me */ export const x = 1'
|
|
466
|
+
const res = await transformBabel(path.join(projectRoot, 'src', 'index.ts'), code, {
|
|
467
|
+
configFile: userConfig,
|
|
468
|
+
babelrc: true,
|
|
469
|
+
})
|
|
470
|
+
expect(res.code).not.toContain('remove me')
|
|
471
|
+
expect(res.code).toContain('export const x = 1')
|
|
472
|
+
} finally {
|
|
473
|
+
fs.rmSync(projectRoot, { recursive: true, force: true })
|
|
474
|
+
}
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
it('tells user babel config it runs in a bundler that keeps static esm', async () => {
|
|
478
|
+
const projectRoot = fs.realpathSync(
|
|
479
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'vxrn-babel-conf-'))
|
|
480
|
+
)
|
|
481
|
+
const userConfig = path.join(projectRoot, 'babel.config.js')
|
|
482
|
+
// presets such as babel-preset-expo read this caller to decide whether to
|
|
483
|
+
// rewrite esm to commonjs and import.meta to a metro runtime global
|
|
484
|
+
fs.writeFileSync(
|
|
485
|
+
userConfig,
|
|
486
|
+
`module.exports = (api) => ({
|
|
487
|
+
comments: !api.caller((c) => c?.name === 'vxrn' && c?.supportsStaticESM === true),
|
|
488
|
+
})`
|
|
489
|
+
)
|
|
490
|
+
try {
|
|
443
491
|
const res = await transformBabel(
|
|
444
492
|
path.join(projectRoot, 'src', 'index.ts'),
|
|
445
|
-
|
|
446
|
-
{
|
|
447
|
-
configFile: userConfig,
|
|
448
|
-
babelrc: true,
|
|
449
|
-
}
|
|
493
|
+
'/* remove me */ export const x = 1',
|
|
494
|
+
{ configFile: userConfig, babelrc: true }
|
|
450
495
|
)
|
|
451
496
|
expect(res.code).not.toContain('remove me')
|
|
452
|
-
expect(res.code).toContain('export const x = 1')
|
|
453
497
|
} finally {
|
|
454
498
|
fs.rmSync(projectRoot, { recursive: true, force: true })
|
|
455
499
|
}
|
|
456
500
|
})
|
|
457
501
|
})
|
|
502
|
+
describe('explicit swc/oxc per-file choice with a user babel config', () => {
|
|
503
|
+
it('returns null for swc/oxc string and object forms', () => {
|
|
504
|
+
const projectRoot = fs.realpathSync(
|
|
505
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'vxrn-babel-conf-'))
|
|
506
|
+
)
|
|
507
|
+
const userConfig = path.join(projectRoot, 'babel.config.js')
|
|
508
|
+
fs.writeFileSync(userConfig, 'module.exports = { plugins: [] }')
|
|
509
|
+
try {
|
|
510
|
+
const base = {
|
|
511
|
+
id: path.join(projectRoot, 'src', 'index.tsx'),
|
|
512
|
+
code: `export const x = 1`,
|
|
513
|
+
projectRoot,
|
|
514
|
+
development: true,
|
|
515
|
+
environment: 'client' as const,
|
|
516
|
+
reactForRNVersion: '19' as const,
|
|
517
|
+
}
|
|
518
|
+
// merely adding babel.config.js must not flip an explicit non-babel choice
|
|
519
|
+
expect(getBabelOptions({ ...base, userSetting: 'swc' })).toBeNull()
|
|
520
|
+
expect(getBabelOptions({ ...base, userSetting: 'oxc' })).toBeNull()
|
|
521
|
+
expect(getBabelOptions({ ...base, userSetting: { transform: 'swc' } })).toBeNull()
|
|
522
|
+
expect(getBabelOptions({ ...base, userSetting: { transform: 'oxc' } })).toBeNull()
|
|
523
|
+
// controls: babel choices still resolve through the user config
|
|
524
|
+
expect(getBabelOptions({ ...base, userSetting: 'babel' })?.configFile).toBe(
|
|
525
|
+
userConfig
|
|
526
|
+
)
|
|
527
|
+
expect(
|
|
528
|
+
getBabelOptions({ ...base, userSetting: { transform: 'babel' } })?.configFile
|
|
529
|
+
).toBe(userConfig)
|
|
530
|
+
expect(getBabelOptions(base)?.configFile).toBe(userConfig)
|
|
531
|
+
} finally {
|
|
532
|
+
fs.rmSync(projectRoot, { recursive: true, force: true })
|
|
533
|
+
}
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
it('skips the transform end-to-end for object-form swc', async () => {
|
|
537
|
+
const { createVXRNCompilerPlugin } = await import('./index')
|
|
538
|
+
const projectRoot = fs.realpathSync(
|
|
539
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'vxrn-babel-conf-'))
|
|
540
|
+
)
|
|
541
|
+
const srcDir = path.join(projectRoot, 'src')
|
|
542
|
+
fs.mkdirSync(srcDir, { recursive: true })
|
|
543
|
+
const file = path.join(srcDir, 'index.ts')
|
|
544
|
+
const code = `export const x = 1`
|
|
545
|
+
fs.writeFileSync(file, code)
|
|
546
|
+
fs.writeFileSync(
|
|
547
|
+
path.join(projectRoot, 'babel.config.js'),
|
|
548
|
+
'module.exports = { plugins: [] }'
|
|
549
|
+
)
|
|
550
|
+
configureVXRNCompilerPlugin({
|
|
551
|
+
enableCompiler: false,
|
|
552
|
+
enableReanimated: false,
|
|
553
|
+
})
|
|
554
|
+
try {
|
|
555
|
+
const plugins = await createVXRNCompilerPlugin({
|
|
556
|
+
transform: () => ({ transform: 'swc' }) as any,
|
|
557
|
+
})
|
|
558
|
+
const plugin = plugins.find((p: any) => p.name === 'one:compiler') as any
|
|
559
|
+
await plugin.configResolved({ root: projectRoot, build: {} })
|
|
560
|
+
const hook = plugin.transform.handler || plugin.transform
|
|
561
|
+
const result = await hook.call({ environment: { name: 'client' } }, code, file)
|
|
562
|
+
expect(result == null).toBe(true)
|
|
563
|
+
} finally {
|
|
564
|
+
configureVXRNCompilerPlugin({
|
|
565
|
+
enableCompiler: false,
|
|
566
|
+
enableReanimated: false,
|
|
567
|
+
})
|
|
568
|
+
fs.rmSync(projectRoot, { recursive: true, force: true })
|
|
569
|
+
}
|
|
570
|
+
})
|
|
571
|
+
})
|
|
458
572
|
|
|
573
|
+
describe('user babel config end-to-end through the compiler plugin', () => {
|
|
574
|
+
it('runs the user config when default plugins are empty', async () => {
|
|
575
|
+
const { createVXRNCompilerPlugin } = await import('./index')
|
|
576
|
+
const projectRoot = fs.realpathSync(
|
|
577
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'vxrn-babel-e2e-'))
|
|
578
|
+
)
|
|
579
|
+
const srcDir = path.join(projectRoot, 'src')
|
|
580
|
+
fs.mkdirSync(srcDir, { recursive: true })
|
|
581
|
+
const file = path.join(srcDir, 'index.ts')
|
|
582
|
+
const marker = 'babel-e2e-probe'
|
|
583
|
+
const code = `/* ${marker} */ export const x = 1`
|
|
584
|
+
fs.writeFileSync(file, code)
|
|
585
|
+
fs.writeFileSync(
|
|
586
|
+
path.join(projectRoot, 'babel.config.json'),
|
|
587
|
+
JSON.stringify({ comments: false })
|
|
588
|
+
)
|
|
589
|
+
configureVXRNCompilerPlugin({
|
|
590
|
+
enableCompiler: false,
|
|
591
|
+
enableReanimated: false,
|
|
592
|
+
})
|
|
593
|
+
try {
|
|
594
|
+
const plugins = await createVXRNCompilerPlugin()
|
|
595
|
+
const plugin = plugins.find((p: any) => p.name === 'one:compiler') as any
|
|
596
|
+
await plugin.configResolved({ root: projectRoot, build: {} })
|
|
597
|
+
const hook = plugin.transform.handler || plugin.transform
|
|
598
|
+
const result = await hook.call({ environment: { name: 'client' } }, code, file)
|
|
599
|
+
// default plugins are empty here, but the user configFile must still
|
|
600
|
+
// route through transformBabel instead of taking the skip fast-path
|
|
601
|
+
expect(result).toBeDefined()
|
|
602
|
+
expect(result.code).toContain('export const x = 1')
|
|
603
|
+
expect(result.code).not.toContain(marker)
|
|
604
|
+
} finally {
|
|
605
|
+
configureVXRNCompilerPlugin({
|
|
606
|
+
enableCompiler: false,
|
|
607
|
+
enableReanimated: false,
|
|
608
|
+
})
|
|
609
|
+
fs.rmSync(projectRoot, { recursive: true, force: true })
|
|
610
|
+
}
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
it('invalidates the cache when the user babel config is added or edited', async () => {
|
|
614
|
+
const { createVXRNCompilerPlugin } = await import('./index')
|
|
615
|
+
const projectRoot = fs.realpathSync(
|
|
616
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'vxrn-babel-cache-'))
|
|
617
|
+
)
|
|
618
|
+
const srcDir = path.join(projectRoot, 'src')
|
|
619
|
+
fs.mkdirSync(srcDir, { recursive: true })
|
|
620
|
+
const file = path.join(srcDir, 'index.ts')
|
|
621
|
+
const marker = 'babel-cache-probe'
|
|
622
|
+
const code = `/* ${marker} */ export const x = 1`
|
|
623
|
+
fs.writeFileSync(file, code)
|
|
624
|
+
const userConfig = path.join(projectRoot, 'babel.config.json')
|
|
625
|
+
configureVXRNCompilerPlugin({
|
|
626
|
+
enableCompiler: false,
|
|
627
|
+
enableReanimated: false,
|
|
628
|
+
})
|
|
629
|
+
try {
|
|
630
|
+
const plugins = await createVXRNCompilerPlugin({
|
|
631
|
+
transform: () => 'babel' as const,
|
|
632
|
+
})
|
|
633
|
+
const plugin = plugins.find((p: any) => p.name === 'one:compiler') as any
|
|
634
|
+
await plugin.configResolved({ root: projectRoot, build: {} })
|
|
635
|
+
const hook = plugin.transform.handler || plugin.transform
|
|
636
|
+
const context = { environment: { name: 'client' } }
|
|
637
|
+
|
|
638
|
+
const res1 = await hook.call(context, code, file)
|
|
639
|
+
expect(res1.code).toContain(marker)
|
|
640
|
+
|
|
641
|
+
// adding a config without touching the source must miss the cache
|
|
642
|
+
fs.writeFileSync(userConfig, JSON.stringify({ comments: false }))
|
|
643
|
+
const res2 = await hook.call(context, code, file)
|
|
644
|
+
expect(res2.code).not.toContain(marker)
|
|
645
|
+
|
|
646
|
+
// editing the config contents must miss again
|
|
647
|
+
fs.writeFileSync(userConfig, JSON.stringify({ comments: true }))
|
|
648
|
+
const res3 = await hook.call(context, code, file)
|
|
649
|
+
expect(res3.code).toContain(marker)
|
|
650
|
+
} finally {
|
|
651
|
+
configureVXRNCompilerPlugin({
|
|
652
|
+
enableCompiler: false,
|
|
653
|
+
enableReanimated: false,
|
|
654
|
+
})
|
|
655
|
+
fs.rmSync(projectRoot, { recursive: true, force: true })
|
|
656
|
+
}
|
|
657
|
+
})
|
|
658
|
+
})
|
package/src/transformBabel.ts
CHANGED
|
@@ -24,7 +24,8 @@ const USER_BABEL_CONFIG_FILES = [
|
|
|
24
24
|
'.babelrc.json',
|
|
25
25
|
] as const
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
// matches ONE_GENERATED_MARKER in one/src/cli/generateBundlerConfig.ts
|
|
28
|
+
const ONE_GENERATED_MARKER = '@one/generated bundler-config'
|
|
28
29
|
|
|
29
30
|
export function findUserBabelConfig(projectRoot?: string): string | null {
|
|
30
31
|
if (!projectRoot) return null
|
|
@@ -54,9 +55,7 @@ export function getBabelOptions(props: Props): babel.TransformOptions | null {
|
|
|
54
55
|
|
|
55
56
|
const isProjectFile = !props.id.includes('node_modules')
|
|
56
57
|
const userBabelConfig =
|
|
57
|
-
isProjectFile && props.projectRoot
|
|
58
|
-
? findUserBabelConfig(props.projectRoot)
|
|
59
|
-
: null
|
|
58
|
+
isProjectFile && props.projectRoot ? findUserBabelConfig(props.projectRoot) : null
|
|
60
59
|
|
|
61
60
|
if (props.userSetting === 'babel') {
|
|
62
61
|
return getOptions(props, true, userBabelConfig)
|
|
@@ -68,13 +67,24 @@ export function getBabelOptions(props: Props): babel.TransformOptions | null {
|
|
|
68
67
|
if (props.userSetting?.excludeDefaultPlugins) {
|
|
69
68
|
return {
|
|
70
69
|
...props.userSetting,
|
|
71
|
-
...(userBabelConfig
|
|
72
|
-
? { configFile: userBabelConfig, babelrc: true }
|
|
73
|
-
: {}),
|
|
70
|
+
...(userBabelConfig ? { configFile: userBabelConfig, babelrc: true } : {}),
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
73
|
return getOptions(props, false, userBabelConfig)
|
|
77
74
|
}
|
|
75
|
+
// an explicit per-file opt-out of babel survives a user config. without
|
|
76
|
+
// this, merely adding babel.config.js flips swc/oxc files to babel.
|
|
77
|
+
const userSetting = props.userSetting
|
|
78
|
+
if (
|
|
79
|
+
userSetting === 'swc' ||
|
|
80
|
+
userSetting === 'oxc' ||
|
|
81
|
+
userSetting === false ||
|
|
82
|
+
(typeof userSetting === 'object' &&
|
|
83
|
+
userSetting !== null &&
|
|
84
|
+
(userSetting.transform === 'swc' || userSetting.transform === 'oxc'))
|
|
85
|
+
) {
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
78
88
|
if (userBabelConfig) {
|
|
79
89
|
return getOptions(props, false, userBabelConfig)
|
|
80
90
|
}
|
|
@@ -125,9 +135,7 @@ const getOptions = (
|
|
|
125
135
|
if (plugins.length || userBabelConfig) {
|
|
126
136
|
return {
|
|
127
137
|
plugins,
|
|
128
|
-
...(userBabelConfig
|
|
129
|
-
? { configFile: userBabelConfig, babelrc: true }
|
|
130
|
-
: {}),
|
|
138
|
+
...(userBabelConfig ? { configFile: userBabelConfig, babelrc: true } : {}),
|
|
131
139
|
}
|
|
132
140
|
}
|
|
133
141
|
|
|
@@ -187,7 +195,10 @@ export async function transformOxcReactCompiler(
|
|
|
187
195
|
)
|
|
188
196
|
}
|
|
189
197
|
|
|
190
|
-
return {
|
|
198
|
+
return {
|
|
199
|
+
code: result.code,
|
|
200
|
+
map: sourceMap ? (result.map as any) : undefined,
|
|
201
|
+
}
|
|
191
202
|
}
|
|
192
203
|
|
|
193
204
|
/**
|
|
@@ -213,6 +224,13 @@ export async function transformBabel(
|
|
|
213
224
|
sourceMaps: false,
|
|
214
225
|
minified: false,
|
|
215
226
|
...options,
|
|
227
|
+
// vite and rolldown own module syntax and import.meta, so presets written for
|
|
228
|
+
// metro (babel-preset-expo) must keep esm instead of rewriting it for metro's runtime
|
|
229
|
+
caller: {
|
|
230
|
+
name: 'vxrn',
|
|
231
|
+
supportsStaticESM: true,
|
|
232
|
+
supportsDynamicImport: true,
|
|
233
|
+
},
|
|
216
234
|
presets: [
|
|
217
235
|
isTS
|
|
218
236
|
? [
|
|
@@ -236,7 +254,10 @@ export async function transformBabel(
|
|
|
236
254
|
plugins: [
|
|
237
255
|
...(isTS
|
|
238
256
|
? []
|
|
239
|
-
: [
|
|
257
|
+
: [
|
|
258
|
+
[hermesParserPlugin, { parseLangTypes: 'flow', reactRuntimeTarget: '19' }],
|
|
259
|
+
'babel-plugin-transform-flow-enums',
|
|
260
|
+
]),
|
|
240
261
|
...(options.plugins || []),
|
|
241
262
|
...(isTS ? [] : ['@babel/plugin-transform-flow-strip-types']),
|
|
242
263
|
],
|
|
@@ -252,6 +273,14 @@ export async function transformBabel(
|
|
|
252
273
|
})
|
|
253
274
|
}
|
|
254
275
|
|
|
276
|
+
export async function stripFlowTypes(id: string, code: string, sourceMaps = true) {
|
|
277
|
+
const result = await transformBabel(id, code, { sourceMaps })
|
|
278
|
+
return {
|
|
279
|
+
code: result.code!,
|
|
280
|
+
map: result.map,
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
255
284
|
const getBasePlugins = ({ development }: Props) =>
|
|
256
285
|
[
|
|
257
286
|
['@babel/plugin-transform-destructuring'],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import os from 'node:os'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
3
4
|
import path from 'node:path'
|
|
4
5
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
5
6
|
import { configureVXRNCompilerPlugin } from './configure'
|
|
@@ -381,7 +382,12 @@ describe('transformWorklets', () => {
|
|
|
381
382
|
expect(typeof scaleFn).toBe('function')
|
|
382
383
|
expect(scaleFn.__workletHash).toBeDefined()
|
|
383
384
|
expect(typeof scaleFn.__workletHash).toBe('number')
|
|
384
|
-
|
|
385
|
+
// /app has no package.json, so the stamp comes from the worklets runtime
|
|
386
|
+
// this workspace actually installs
|
|
387
|
+
const installedWorklets = createRequire(path.resolve(process.cwd(), 'package.json'))(
|
|
388
|
+
'react-native-worklets/package.json'
|
|
389
|
+
).version
|
|
390
|
+
expect(scaleFn.__pluginVersion).toBe(installedWorklets)
|
|
385
391
|
expect(scaleFn.__closure).toEqual({ multiplier: 5 })
|
|
386
392
|
expect(scaleFn.__initData).toBeDefined()
|
|
387
393
|
expect(scaleFn.__initData.code).toContain('__closure')
|
package/types/cache.d.ts
CHANGED
|
@@ -4,14 +4,14 @@ interface CacheStats {
|
|
|
4
4
|
writes: 0;
|
|
5
5
|
errors: 0;
|
|
6
6
|
}
|
|
7
|
-
export declare function getCachedTransform(filePath: string, code: string, environment: string): {
|
|
7
|
+
export declare function getCachedTransform(filePath: string, code: string, environment: string, userBabelConfigPath?: string | null): {
|
|
8
8
|
code: string;
|
|
9
9
|
map?: any;
|
|
10
10
|
} | null;
|
|
11
11
|
export declare function setCachedTransform(filePath: string, code: string, result: {
|
|
12
12
|
code: string;
|
|
13
13
|
map?: any;
|
|
14
|
-
}, environment: string): void;
|
|
14
|
+
}, environment: string, userBabelConfigPath?: string | null): void;
|
|
15
15
|
/** Drop every cached transform, for `react-native bundle --reset-cache`. */
|
|
16
16
|
export declare function clearTransformCache(): void;
|
|
17
17
|
export declare function getCacheStats(): CacheStats;
|
package/types/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AA4BA,UAAU,UAAU;IAClB,IAAI,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,CAAC,CAAA;IACT,MAAM,EAAE,CAAC,CAAA;IACT,MAAM,EAAE,CAAC,CAAA;CACV;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AA4BA,UAAU,UAAU;IAClB,IAAI,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,CAAC,CAAA;IACT,MAAM,EAAE,CAAC,CAAA;IACT,MAAM,EAAE,CAAC,CAAA;CACV;AA6ED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,GAClC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,IAAI,CAoCpC;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,GAAG,CAAA;CAAE,EACnC,WAAW,EAAE,MAAM,EACnB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,GAClC,IAAI,CAwBN;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED,wBAAgB,aAAa,IAAI,IAAI,CAapC"}
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAAE,YAAY,EAA8B,MAAM,MAAM,CAAA;AAcpE,OAAO,KAAK,EAAkC,OAAO,EAAE,MAAM,SAAS,CAAA;AAGtE,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAAE,YAAY,EAA8B,MAAM,MAAM,CAAA;AAcpE,OAAO,KAAK,EAAkC,OAAO,EAAE,MAAM,SAAS,CAAA;AAGtE,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AA0S3C,wBAAsB,wBAAwB,CAC5C,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,YAAY,EAAE,CAAC,CA6VzB"}
|
|
@@ -24,5 +24,17 @@ export declare function transformOxcReactCompiler(id: string, code: string, opti
|
|
|
24
24
|
* Transform input to mostly ES5 compatible code, keep ESM syntax, and transform generators.
|
|
25
25
|
*/
|
|
26
26
|
export declare function transformBabel(id: string, code: string, options: babel.TransformOptions): Promise<babel.BabelFileResult>;
|
|
27
|
+
export declare function stripFlowTypes(id: string, code: string, sourceMaps?: boolean): Promise<{
|
|
28
|
+
code: string;
|
|
29
|
+
map: {
|
|
30
|
+
version: number;
|
|
31
|
+
sources: string[];
|
|
32
|
+
names: string[];
|
|
33
|
+
sourceRoot?: string | undefined;
|
|
34
|
+
sourcesContent?: string[] | undefined;
|
|
35
|
+
mappings: string;
|
|
36
|
+
file: string;
|
|
37
|
+
} | null | undefined;
|
|
38
|
+
}>;
|
|
27
39
|
export {};
|
|
28
40
|
//# sourceMappingURL=transformBabel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformBabel.d.ts","sourceRoot":"","sources":["../src/transformBabel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAKzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEtE,KAAK,KAAK,GAAG,iBAAiB,GAAG;IAC/B,WAAW,CAAC,EAAE,oBAAoB,CAAA;CACnC,CAAA;
|
|
1
|
+
{"version":3,"file":"transformBabel.d.ts","sourceRoot":"","sources":["../src/transformBabel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAKzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEtE,KAAK,KAAK,GAAG,iBAAiB,GAAG;IAC/B,WAAW,CAAC,EAAE,oBAAoB,CAAA;CACnC,CAAA;AAeD,wBAAgB,mBAAmB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBvE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,gBAAgB,GAAG,IAAI,CA2C3E;AAqDD;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,eAAe,GAAE,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CAAE,CAAQ,EACtF,SAAS,UAAQ;;;GA4ClB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,KAAK,CAAC,gBAAgB,kCAgEhC;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,UAAO;;;;;;;;;;;GAM/E"}
|
package/types/transformSWC.d.ts
CHANGED
|
@@ -13,8 +13,5 @@ export declare const transformSWCStripJSX: (id: string, code: string) => Promise
|
|
|
13
13
|
code: string;
|
|
14
14
|
map: any;
|
|
15
15
|
} | undefined>;
|
|
16
|
-
export declare const transformOxcStripJSX:
|
|
17
|
-
code: string;
|
|
18
|
-
map: any;
|
|
19
|
-
} | undefined>;
|
|
16
|
+
export declare const transformOxcStripJSX: typeof transformSWCStripJSX;
|
|
20
17
|
//# sourceMappingURL=transformSWC.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformSWC.d.ts","sourceRoot":"","sources":["../src/transformSWC.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAKD,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAWjE;AAED,wBAAsB,YAAY,CAChC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GAAG;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EACpC,UAAU,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAkI7B;AAED,eAAO,MAAM,YAAY,qBAAe,CAAA;AA+HxC,wBAAgB,eAAe,YAE9B;AAyBD,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"transformSWC.d.ts","sourceRoot":"","sources":["../src/transformSWC.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAKD,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAWjE;AAED,wBAAsB,YAAY,CAChC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GAAG;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EACpC,UAAU,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAkI7B;AAED,eAAO,MAAM,YAAY,qBAAe,CAAA;AA+HxC,wBAAgB,eAAe,YAE9B;AAyBD,eAAO,MAAM,oBAAoB,OAAc,MAAM,QAAQ,MAAM;;SAwBxB,GAAG;cAC7C,CAAA;AAED,eAAO,MAAM,oBAAoB,6BAAuB,CAAA"}
|