@@ -402,11 +402,7 @@ export interface ProjectOptions {
402
402
*/
403
403
env : Record < string , string >
404
404
405
- defineEnv : {
406
- client : Record < string , string >
407
- edge : Record < string , string >
408
- nodejs : Record < string , string >
409
- }
405
+ defineEnv : DefineEnv
410
406
411
407
/**
412
408
* Whether to watch the filesystem for file changes.
@@ -419,10 +415,12 @@ export interface ProjectOptions {
419
415
serverAddr : string
420
416
}
421
417
418
+ type RustifiedEnv = { name : string ; value : string } [ ]
419
+
422
420
export interface DefineEnv {
423
- client : Record < string , string >
424
- edge : Record < string , string >
425
- nodejs : Record < string , string >
421
+ client : RustifiedEnv
422
+ edge : RustifiedEnv
423
+ nodejs : RustifiedEnv
426
424
}
427
425
428
426
export function createDefineEnv ( {
@@ -439,31 +437,30 @@ export function createDefineEnv({
439
437
DefineEnvPluginOptions ,
440
438
'isClient' | 'isNodeOrEdgeCompilation' | 'isEdgeServer' | 'isNodeServer'
441
439
> ) : DefineEnv {
442
- let defineEnv : Record <
443
- 'client' | 'edge' | 'nodejs' ,
444
- Record < string , string >
445
- > = {
446
- client : { } ,
447
- edge : { } ,
448
- nodejs : { } ,
440
+ let defineEnv : DefineEnv = {
441
+ client : [ ] ,
442
+ edge : [ ] ,
443
+ nodejs : [ ] ,
449
444
}
450
445
451
446
for ( const variant of Object . keys ( defineEnv ) as ( keyof typeof defineEnv ) [ ] ) {
452
- defineEnv [ variant ] = getDefineEnv ( {
453
- allowedRevalidateHeaderKeys,
454
- clientRouterFilters,
455
- config,
456
- dev,
457
- distDir,
458
- fetchCacheKeyPrefix,
459
- hasRewrites,
460
- isClient : variant === 'client' ,
461
- isEdgeServer : variant === 'edge' ,
462
- isNodeOrEdgeCompilation : variant === 'nodejs' || variant === 'edge' ,
463
- isNodeServer : variant === 'nodejs' ,
464
- middlewareMatchers,
465
- previewModeId,
466
- } )
447
+ defineEnv [ variant ] = rustifyEnv (
448
+ getDefineEnv ( {
449
+ allowedRevalidateHeaderKeys,
450
+ clientRouterFilters,
451
+ config,
452
+ dev,
453
+ distDir,
454
+ fetchCacheKeyPrefix,
455
+ hasRewrites,
456
+ isClient : variant === 'client' ,
457
+ isEdgeServer : variant === 'edge' ,
458
+ isNodeOrEdgeCompilation : variant === 'nodejs' || variant === 'edge' ,
459
+ isNodeServer : variant === 'nodejs' ,
460
+ middlewareMatchers,
461
+ previewModeId,
462
+ } )
463
+ )
467
464
}
468
465
469
466
return defineEnv
@@ -623,6 +620,15 @@ export type WrittenEndpoint =
623
620
config : EndpointConfig
624
621
}
625
622
623
+ function rustifyEnv ( env : Record < string , string > ) : RustifiedEnv {
624
+ return Object . entries ( env )
625
+ . filter ( ( [ _ , value ] ) => value != null )
626
+ . map ( ( [ name , value ] ) => ( {
627
+ name,
628
+ value,
629
+ } ) )
630
+ }
631
+
626
632
// TODO(sokra) Support wasm option.
627
633
function bindingToApi ( binding : any , _wasm : boolean ) {
628
634
type NativeFunction < T > = (
@@ -747,15 +753,6 @@ function bindingToApi(binding: any, _wasm: boolean) {
747
753
} )
748
754
}
749
755
750
- function rustifyEnv ( env : Record < string , string > ) {
751
- return Object . entries ( env )
752
- . filter ( ( [ _ , value ] ) => value != null )
753
- . map ( ( [ name , value ] ) => ( {
754
- name,
755
- value,
756
- } ) )
757
- }
758
-
759
756
async function rustifyProjectOptions (
760
757
options : Partial < ProjectOptions >
761
758
) : Promise < any > {
@@ -765,11 +762,7 @@ function bindingToApi(binding: any, _wasm: boolean) {
765
762
options . nextConfig && ( await serializeNextConfig ( options . nextConfig ) ) ,
766
763
jsConfig : options . jsConfig && JSON . stringify ( options . jsConfig ) ,
767
764
env : options . env && rustifyEnv ( options . env ) ,
768
- defineEnv : options . defineEnv && {
769
- client : rustifyEnv ( options . defineEnv . client ) ,
770
- edge : rustifyEnv ( options . defineEnv . edge ) ,
771
- nodejs : rustifyEnv ( options . defineEnv . nodejs ) ,
772
- } ,
765
+ defineEnv : options . defineEnv ,
773
766
}
774
767
}
775
768
0 commit comments