@vxrn/vite-plugin-metro 1.26.0 → 1.26.1-1789332805082
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/babel-plugins/import-meta-env-plugin.cjs +14 -25
- package/dist/cjs/babel-plugins/import-meta-env-plugin.native.js +14 -25
- package/dist/cjs/babel-plugins/import-meta-env-plugin.native.js.map +1 -1
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.cjs +5 -2
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js +5 -2
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/cjs/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/cjs/transformer/metroNativeWorker.test.cjs +36 -0
- package/dist/cjs/transformer/metroNativeWorker.test.native.js +36 -0
- package/dist/cjs/transformer/metroNativeWorker.test.native.js.map +1 -1
- package/dist/esm/babel-plugins/import-meta-env-plugin.mjs +1 -1
- package/dist/esm/babel-plugins/import-meta-env-plugin.mjs.map +1 -1
- package/dist/esm/babel-plugins/import-meta-env-plugin.native.js +1 -1
- package/dist/esm/babel-plugins/import-meta-env-plugin.native.js.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs +5 -2
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js +5 -2
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.mjs.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.test.mjs +31 -0
- package/dist/esm/transformer/metroNativeWorker.test.mjs.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.test.native.js +31 -0
- package/dist/esm/transformer/metroNativeWorker.test.native.js.map +1 -1
- package/package.json +4 -5
- package/src/babel-plugins/import-meta-env-plugin.ts +1 -2
- package/src/metro-config/getMetroConfigFromViteConfig.ts +27 -4
- package/src/transformer/metroNativeWorker.test.ts +191 -87
- package/src/transformer/metroNativeWorker.ts +241 -62
- package/types/babel-plugins/import-meta-env-plugin.d.ts +1 -1
- package/types/babel-plugins/import-meta-env-plugin.d.ts.map +1 -1
- package/types/metro-config/getMetroConfigFromViteConfig.d.ts.map +1 -1
- package/types/transformer/metroNativeWorker.d.ts.map +1 -1
|
@@ -3,6 +3,7 @@ import * as babel from '@babel/core'
|
|
|
3
3
|
import * as vm from 'node:vm'
|
|
4
4
|
import { parseSync } from 'oxc-parser'
|
|
5
5
|
import * as fs from 'node:fs'
|
|
6
|
+
import * as os from 'node:os'
|
|
6
7
|
import * as path from 'node:path'
|
|
7
8
|
import { createRequire } from 'node:module'
|
|
8
9
|
import {
|
|
@@ -80,28 +81,45 @@ function assertZeroBabelCalls() {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
describe('metroNativeWorker', () => {
|
|
83
|
-
it.each([
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
it.each([
|
|
85
|
+
['data.json', true],
|
|
86
|
+
['data.json', false],
|
|
87
|
+
['data.js', false],
|
|
88
|
+
] as const)(
|
|
89
|
+
'minifies %s with source maps enabled=%s without stale mappings',
|
|
90
|
+
async (filename, sourceMap) => {
|
|
91
|
+
const result = await transform(
|
|
92
|
+
{
|
|
93
|
+
minifierPath: createRequire(import.meta.url).resolve('metro-minify-terser'),
|
|
94
|
+
minifierConfig: { sourceMap },
|
|
95
|
+
},
|
|
96
|
+
'/project',
|
|
97
|
+
filename,
|
|
98
|
+
Buffer.from(
|
|
99
|
+
filename.endsWith('.json') ? '{"answer":42}' : 'module.exports = { answer: 42 }'
|
|
100
|
+
),
|
|
101
|
+
{ dev: false, minify: true, platform: 'ios', type: 'module' }
|
|
102
|
+
)
|
|
103
|
+
const module = { exports: {} as any }
|
|
104
|
+
const { code, map } = result.output[0].data
|
|
105
|
+
vm.runInNewContext(code, {
|
|
106
|
+
__d(factory: any) {
|
|
107
|
+
factory(
|
|
108
|
+
{},
|
|
109
|
+
() => {},
|
|
110
|
+
() => {},
|
|
111
|
+
() => {},
|
|
112
|
+
module,
|
|
113
|
+
module.exports,
|
|
114
|
+
[]
|
|
115
|
+
)
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
expect(module.exports.answer).toBe(42)
|
|
119
|
+
expect(map.every((entry) => entry.length === 2)).toBe(true)
|
|
120
|
+
assertZeroBabelCalls()
|
|
121
|
+
}
|
|
122
|
+
)
|
|
105
123
|
|
|
106
124
|
it('minifies production modules with executable output and original source locations', async () => {
|
|
107
125
|
const source = 'exports.answer = function answer(value) {\n return value + 42\n}\n'
|
|
@@ -119,7 +137,15 @@ describe('metroNativeWorker', () => {
|
|
|
119
137
|
const module = { exports: {} as any }
|
|
120
138
|
vm.runInNewContext(code, {
|
|
121
139
|
__d(factory: any) {
|
|
122
|
-
factory(
|
|
140
|
+
factory(
|
|
141
|
+
{},
|
|
142
|
+
() => {},
|
|
143
|
+
() => {},
|
|
144
|
+
() => {},
|
|
145
|
+
module,
|
|
146
|
+
module.exports,
|
|
147
|
+
[]
|
|
148
|
+
)
|
|
123
149
|
},
|
|
124
150
|
})
|
|
125
151
|
expect(module.exports.answer(8)).toBe(50)
|
|
@@ -207,10 +233,14 @@ describe('metroNativeWorker', () => {
|
|
|
207
233
|
`
|
|
208
234
|
|
|
209
235
|
const off = extractDependencies(code, 'setup.js')
|
|
210
|
-
expect(
|
|
236
|
+
expect(
|
|
237
|
+
off.find((d) => d.name === 'react-native-worklets-core')!.data.isOptional
|
|
238
|
+
).toBeUndefined()
|
|
211
239
|
|
|
212
240
|
const on = extractDependencies(code, 'setup.js', { allowOptionalDependencies: true })
|
|
213
|
-
expect(on.find((d) => d.name === 'react-native-worklets-core')!.data.isOptional).toBe(
|
|
241
|
+
expect(on.find((d) => d.name === 'react-native-worklets-core')!.data.isOptional).toBe(
|
|
242
|
+
true
|
|
243
|
+
)
|
|
214
244
|
expect(on.find((d) => d.name === './always-there')!.data.isOptional).toBeUndefined()
|
|
215
245
|
|
|
216
246
|
const excluded = extractDependencies(code, 'setup.js', {
|
|
@@ -361,7 +391,9 @@ describe('metroNativeWorker', () => {
|
|
|
361
391
|
expect(result.dependencies).toEqual([])
|
|
362
392
|
expect(result.output).toHaveLength(1)
|
|
363
393
|
expect(result.output[0].type).toBe('js/module')
|
|
364
|
-
expect(result.output[0].data.code).toContain(
|
|
394
|
+
expect(result.output[0].data.code).toContain(
|
|
395
|
+
'module.exports = {"name":"my-package","version":"1.0.0"}'
|
|
396
|
+
)
|
|
365
397
|
expect(result.output[0].data.code).toContain('__d(function (global, require')
|
|
366
398
|
})
|
|
367
399
|
|
|
@@ -409,8 +441,14 @@ describe('metroNativeWorker', () => {
|
|
|
409
441
|
})
|
|
410
442
|
|
|
411
443
|
it('generates a deterministic cache key without Babel', () => {
|
|
412
|
-
const key1 = getCacheKey(
|
|
413
|
-
|
|
444
|
+
const key1 = getCacheKey(
|
|
445
|
+
{ globalPrefix: '__one_', minifierPath: 'terser' },
|
|
446
|
+
{ projectRoot: '/app' }
|
|
447
|
+
)
|
|
448
|
+
const key2 = getCacheKey(
|
|
449
|
+
{ globalPrefix: '__one_', minifierPath: 'terser' },
|
|
450
|
+
{ projectRoot: '/app' }
|
|
451
|
+
)
|
|
414
452
|
const key3 = getCacheKey({ globalPrefix: '__other_' }, { projectRoot: '/app' })
|
|
415
453
|
|
|
416
454
|
assertZeroBabelCalls()
|
|
@@ -455,12 +493,53 @@ describe('metroNativeWorker', () => {
|
|
|
455
493
|
delete process.env.ONE_METRO_NATIVE_TRANSFORMS
|
|
456
494
|
})
|
|
457
495
|
|
|
496
|
+
it('falls back to default Metro babel transformer when a user babel config exists', async () => {
|
|
497
|
+
const tempDir = path.join(process.cwd(), `.tmp-metro-test-${Date.now()}`)
|
|
498
|
+
fs.mkdirSync(tempDir, { recursive: true })
|
|
499
|
+
fs.writeFileSync(path.join(tempDir, 'package.json'), '{}')
|
|
500
|
+
try {
|
|
501
|
+
const mockViteConfig = { root: tempDir } as any
|
|
502
|
+
delete process.env.ONE_METRO_NATIVE_TRANSFORMS
|
|
503
|
+
|
|
504
|
+
// With no config, defaults to metroNativeWorker
|
|
505
|
+
const config1 = await buildMetroConfigInputFromViteConfig(mockViteConfig, {})
|
|
506
|
+
expect(config1.defaultConfig.transformerPath).toContain('metroNativeWorker')
|
|
507
|
+
|
|
508
|
+
// Generated @one-generated config is ignored, still uses metroNativeWorker
|
|
509
|
+
const babelConfigPath = path.join(tempDir, 'babel.config.js')
|
|
510
|
+
fs.writeFileSync(babelConfigPath, '// @one-generated\nmodule.exports = {}')
|
|
511
|
+
const config2 = await buildMetroConfigInputFromViteConfig(mockViteConfig, {})
|
|
512
|
+
expect(config2.defaultConfig.transformerPath).toContain('metroNativeWorker')
|
|
513
|
+
|
|
514
|
+
// User config: falls back to metro default transformer (not metroNativeWorker)
|
|
515
|
+
fs.writeFileSync(babelConfigPath, 'module.exports = { plugins: ["my-plugin"] }')
|
|
516
|
+
const config3 = await buildMetroConfigInputFromViteConfig(mockViteConfig, {})
|
|
517
|
+
expect(config3.defaultConfig.transformerPath).not.toContain('metroNativeWorker')
|
|
518
|
+
|
|
519
|
+
// Explicit env var ONE_METRO_NATIVE_TRANSFORMS=1 forces native worker even with user babel config
|
|
520
|
+
process.env.ONE_METRO_NATIVE_TRANSFORMS = '1'
|
|
521
|
+
const config4 = await buildMetroConfigInputFromViteConfig(mockViteConfig, {})
|
|
522
|
+
expect(config4.defaultConfig.transformerPath).toContain('metroNativeWorker')
|
|
523
|
+
delete process.env.ONE_METRO_NATIVE_TRANSFORMS
|
|
524
|
+
|
|
525
|
+
// Explicit nativeTransforms: true also forces native worker
|
|
526
|
+
const config5 = await buildMetroConfigInputFromViteConfig(mockViteConfig, {
|
|
527
|
+
nativeTransforms: true,
|
|
528
|
+
})
|
|
529
|
+
expect(config5.defaultConfig.transformerPath).toContain('metroNativeWorker')
|
|
530
|
+
} finally {
|
|
531
|
+
delete process.env.ONE_METRO_NATIVE_TRANSFORMS
|
|
532
|
+
fs.rmSync(tempDir, { recursive: true, force: true })
|
|
533
|
+
}
|
|
534
|
+
})
|
|
535
|
+
|
|
458
536
|
it('transforms and executes a real 2-module Metro bundle through metro-runtime require polyfill', async () => {
|
|
459
537
|
// Probe 1 verification:
|
|
460
538
|
// Module 2 (dep.js): exports a value
|
|
461
539
|
// Module 1 (a.js): requires dep.js using Metro dependency ABI and exports computed result
|
|
462
540
|
const depSource = 'exports.value = 42;'
|
|
463
|
-
const aSource =
|
|
541
|
+
const aSource =
|
|
542
|
+
'const dep = require("./dep"); module.exports = { doubled: dep.value * 2 };'
|
|
464
543
|
|
|
465
544
|
// Transform dep.js (Module 2)
|
|
466
545
|
const depRes = await transform(
|
|
@@ -478,19 +557,13 @@ describe('metroNativeWorker', () => {
|
|
|
478
557
|
)
|
|
479
558
|
|
|
480
559
|
// Transform a.js (Module 1) which depends on dep.js (dependency slot 0 -> moduleId 2)
|
|
481
|
-
const aRes = await transform(
|
|
482
|
-
|
|
483
|
-
'
|
|
484
|
-
'
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
platform: 'ios',
|
|
489
|
-
type: 'module',
|
|
490
|
-
moduleId: 1,
|
|
491
|
-
dependencyIds: [2],
|
|
492
|
-
} as any
|
|
493
|
-
)
|
|
560
|
+
const aRes = await transform({}, '/project', 'a.js', Buffer.from(aSource, 'utf8'), {
|
|
561
|
+
dev: false,
|
|
562
|
+
platform: 'ios',
|
|
563
|
+
type: 'module',
|
|
564
|
+
moduleId: 1,
|
|
565
|
+
dependencyIds: [2],
|
|
566
|
+
} as any)
|
|
494
567
|
|
|
495
568
|
assertZeroBabelCalls()
|
|
496
569
|
|
|
@@ -526,7 +599,8 @@ describe('metroNativeWorker', () => {
|
|
|
526
599
|
|
|
527
600
|
it('transforms and executes a 2-module Metro bundle with ESM imports in dev mode', async () => {
|
|
528
601
|
const depSource = 'export const greeting = "Hello Metro Native";'
|
|
529
|
-
const aSource =
|
|
602
|
+
const aSource =
|
|
603
|
+
'import { greeting } from "./dep"; export const message = greeting.toUpperCase();'
|
|
530
604
|
|
|
531
605
|
// Transform dep.js (Module 2)
|
|
532
606
|
const depRes = await transform(
|
|
@@ -544,19 +618,13 @@ describe('metroNativeWorker', () => {
|
|
|
544
618
|
)
|
|
545
619
|
|
|
546
620
|
// Transform a.js (Module 1) depending on dep.js (dependency slot 0 -> moduleId 2)
|
|
547
|
-
const aRes = await transform(
|
|
548
|
-
|
|
549
|
-
'
|
|
550
|
-
'
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
platform: 'ios',
|
|
555
|
-
type: 'module',
|
|
556
|
-
moduleId: 1,
|
|
557
|
-
dependencyIds: [2],
|
|
558
|
-
} as any
|
|
559
|
-
)
|
|
621
|
+
const aRes = await transform({}, '/project', 'a.js', Buffer.from(aSource, 'utf8'), {
|
|
622
|
+
dev: true,
|
|
623
|
+
platform: 'ios',
|
|
624
|
+
type: 'module',
|
|
625
|
+
moduleId: 1,
|
|
626
|
+
dependencyIds: [2],
|
|
627
|
+
} as any)
|
|
560
628
|
|
|
561
629
|
assertZeroBabelCalls()
|
|
562
630
|
|
|
@@ -583,7 +651,8 @@ describe('metroNativeWorker', () => {
|
|
|
583
651
|
// Exact probe from Astra:
|
|
584
652
|
// function f(require){return require("./local")}; module.exports=f(x=>x);
|
|
585
653
|
// require is shadowed by parameter: must NOT extract ./local, and must NOT rewrite require
|
|
586
|
-
const input =
|
|
654
|
+
const input =
|
|
655
|
+
'function f(require){return require("./local")}; module.exports=f(x=>x);'
|
|
587
656
|
|
|
588
657
|
const res = await transform(
|
|
589
658
|
{},
|
|
@@ -635,13 +704,11 @@ describe('metroNativeWorker', () => {
|
|
|
635
704
|
const c = await import('./dep');
|
|
636
705
|
}
|
|
637
706
|
`
|
|
638
|
-
const res = await transform(
|
|
639
|
-
|
|
640
|
-
'
|
|
641
|
-
'
|
|
642
|
-
|
|
643
|
-
{ dev: false, platform: 'ios', type: 'module' }
|
|
644
|
-
)
|
|
707
|
+
const res = await transform({}, '/project', 'index.js', Buffer.from(code, 'utf8'), {
|
|
708
|
+
dev: false,
|
|
709
|
+
platform: 'ios',
|
|
710
|
+
type: 'module',
|
|
711
|
+
})
|
|
645
712
|
|
|
646
713
|
assertZeroBabelCalls()
|
|
647
714
|
|
|
@@ -649,8 +716,12 @@ describe('metroNativeWorker', () => {
|
|
|
649
716
|
const depNames = res.dependencies.map((d) => d.name)
|
|
650
717
|
expect(depNames).toContain('./dep')
|
|
651
718
|
|
|
652
|
-
const syncDep = res.dependencies.find(
|
|
653
|
-
|
|
719
|
+
const syncDep = res.dependencies.find(
|
|
720
|
+
(d) => d.name === './dep' && d.data.asyncType === null
|
|
721
|
+
)!
|
|
722
|
+
const asyncDep = res.dependencies.find(
|
|
723
|
+
(d) => d.name === './dep' && d.data.asyncType === 'async'
|
|
724
|
+
)!
|
|
654
725
|
expect(syncDep).toBeDefined()
|
|
655
726
|
expect(asyncDep).toBeDefined()
|
|
656
727
|
expect(syncDep.data.index).not.toEqual(asyncDep.data.index)
|
|
@@ -721,7 +792,8 @@ describe('metroNativeWorker', () => {
|
|
|
721
792
|
// Exact probe from Astra:
|
|
722
793
|
// function f(){const x=require("./local"); function require(x){return x}; return x} module.exports=f();
|
|
723
794
|
// function require is hoisted to f's function scope, so require("./local") is a local call and needs no module.
|
|
724
|
-
const input =
|
|
795
|
+
const input =
|
|
796
|
+
'function f(){const x=require("./local"); function require(x){return x}; return x} module.exports=f();'
|
|
725
797
|
|
|
726
798
|
const res = await transform(
|
|
727
799
|
{},
|
|
@@ -823,7 +895,10 @@ describe('metroNativeWorker', () => {
|
|
|
823
895
|
const polyfillCode = fs.readFileSync(polyfillPath, 'utf8')
|
|
824
896
|
const asyncRequirePath = require.resolve('metro-runtime/src/modules/asyncRequire.js')
|
|
825
897
|
const asyncRequireSource = fs.readFileSync(asyncRequirePath, 'utf8')
|
|
826
|
-
const wrappedAsyncRequire = wrapModule(asyncRequireSource, {
|
|
898
|
+
const wrappedAsyncRequire = wrapModule(asyncRequireSource, {
|
|
899
|
+
moduleId: 1,
|
|
900
|
+
dependencyIds: [],
|
|
901
|
+
})
|
|
827
902
|
|
|
828
903
|
for (const isDev of [true, false]) {
|
|
829
904
|
const contextObj = {
|
|
@@ -844,7 +919,9 @@ describe('metroNativeWorker', () => {
|
|
|
844
919
|
expect(typeof mainFn).toBe('function')
|
|
845
920
|
|
|
846
921
|
const promise = mainFn()
|
|
847
|
-
expect(
|
|
922
|
+
expect(
|
|
923
|
+
promise instanceof Promise || (promise && typeof promise.then === 'function')
|
|
924
|
+
).toBe(true)
|
|
848
925
|
|
|
849
926
|
const resolved = await promise
|
|
850
927
|
expect(resolved.message).toBe('hello dynamic')
|
|
@@ -945,11 +1022,17 @@ describe('metroNativeWorker', () => {
|
|
|
945
1022
|
export const ctx = require.context(routeRoot, true, /\\.tsx$/)
|
|
946
1023
|
`
|
|
947
1024
|
|
|
948
|
-
const result = await transform(
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1025
|
+
const result = await transform(
|
|
1026
|
+
{},
|
|
1027
|
+
'/project',
|
|
1028
|
+
'entry.js',
|
|
1029
|
+
Buffer.from(sourceCode, 'utf8'),
|
|
1030
|
+
{
|
|
1031
|
+
dev: true,
|
|
1032
|
+
platform: 'ios',
|
|
1033
|
+
type: 'module',
|
|
1034
|
+
}
|
|
1035
|
+
)
|
|
953
1036
|
|
|
954
1037
|
const contextDep = result.dependencies.find((d) => d.data.contextParams != null)
|
|
955
1038
|
expect(contextDep?.name).toBe('./app')
|
|
@@ -967,7 +1050,15 @@ describe('metroNativeWorker', () => {
|
|
|
967
1050
|
req.context = () => {
|
|
968
1051
|
throw new Error('fallbackRequireContext reached')
|
|
969
1052
|
}
|
|
970
|
-
factory(
|
|
1053
|
+
factory(
|
|
1054
|
+
{},
|
|
1055
|
+
req,
|
|
1056
|
+
() => ({}),
|
|
1057
|
+
() => ({}),
|
|
1058
|
+
module,
|
|
1059
|
+
module.exports,
|
|
1060
|
+
['./app']
|
|
1061
|
+
)
|
|
971
1062
|
ctx = module.exports.ctx
|
|
972
1063
|
},
|
|
973
1064
|
}
|
|
@@ -989,11 +1080,17 @@ describe('metroNativeWorker', () => {
|
|
|
989
1080
|
}
|
|
990
1081
|
`
|
|
991
1082
|
|
|
992
|
-
const result = await transform(
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1083
|
+
const result = await transform(
|
|
1084
|
+
{},
|
|
1085
|
+
'/project',
|
|
1086
|
+
'loops.ts',
|
|
1087
|
+
Buffer.from(sourceCode, 'utf8'),
|
|
1088
|
+
{
|
|
1089
|
+
dev: true,
|
|
1090
|
+
platform: 'ios',
|
|
1091
|
+
type: 'module',
|
|
1092
|
+
}
|
|
1093
|
+
)
|
|
997
1094
|
|
|
998
1095
|
const code = result.output[0].data.code
|
|
999
1096
|
|
|
@@ -1002,16 +1099,21 @@ describe('metroNativeWorker', () => {
|
|
|
1002
1099
|
// Rewriting the heads that way reproduces Hermes on a runtime that is
|
|
1003
1100
|
// otherwise spec-correct, which is what makes this assertion meaningful:
|
|
1004
1101
|
// the untransformed source returns 2,2,b,b,y,y under it.
|
|
1005
|
-
const asHermesWouldSeeIt = code.replace(
|
|
1006
|
-
/\bfor\s*\(\s*(let|const)\b/g,
|
|
1007
|
-
'for (var'
|
|
1008
|
-
)
|
|
1102
|
+
const asHermesWouldSeeIt = code.replace(/\bfor\s*\(\s*(let|const)\b/g, 'for (var')
|
|
1009
1103
|
|
|
1010
1104
|
let collect: any
|
|
1011
1105
|
const sandbox: any = {
|
|
1012
1106
|
__d: (factory: any) => {
|
|
1013
1107
|
const module = { exports: {} as any }
|
|
1014
|
-
factory(
|
|
1108
|
+
factory(
|
|
1109
|
+
{},
|
|
1110
|
+
() => ({}),
|
|
1111
|
+
() => ({}),
|
|
1112
|
+
() => ({}),
|
|
1113
|
+
module,
|
|
1114
|
+
module.exports,
|
|
1115
|
+
[]
|
|
1116
|
+
)
|
|
1015
1117
|
collect = module.exports.collect
|
|
1016
1118
|
},
|
|
1017
1119
|
}
|
|
@@ -1095,7 +1197,9 @@ export const all = { ...import.meta.env };`,
|
|
|
1095
1197
|
|
|
1096
1198
|
it('folds a ternary and keeps a branch it cannot resolve', () => {
|
|
1097
1199
|
expect(
|
|
1098
|
-
applyInlineEnvVars('const a = import.meta.env.DEV ? x : y;', 'a.ts', true, {
|
|
1200
|
+
applyInlineEnvVars('const a = import.meta.env.DEV ? x : y;', 'a.ts', true, {
|
|
1201
|
+
DEV: false,
|
|
1202
|
+
})
|
|
1099
1203
|
).toContain('const a = y;')
|
|
1100
1204
|
const dynamic = 'const a = flag ? x : y;'
|
|
1101
1205
|
expect(applyInlineEnvVars(dynamic, 'a.ts', true, { DEV: false })).toBe(dynamic)
|
|
@@ -1181,7 +1285,7 @@ export const all = { ...import.meta.env };`,
|
|
|
1181
1285
|
expect(parsed.program.body.map((n: any) => n.type)).toContain('ThrowStatement')
|
|
1182
1286
|
})
|
|
1183
1287
|
|
|
1184
|
-
it(
|
|
1288
|
+
it("reads the router root off one's remove-server-code plugin entry", () => {
|
|
1185
1289
|
const options: any = {
|
|
1186
1290
|
customTransformOptions: {
|
|
1187
1291
|
vite: {
|