@@ -15,16 +15,15 @@ import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
1515 * @param condition The build condition to look for
1616 * @returns An object with the transformed exports and a boolean indicating if the build condition was found
1717 */
18- export function transformBuildCondition (
19- exports : { [ key : string ] : unknown } ,
20- condition : string
21- ) {
18+ export function transformBuildCondition ( exports : { [ key : string ] : unknown } , condition : string ) {
2219 const transformed : { [ key : string ] : unknown } = { } ;
23- const hasTopLevelBuildCondition = Object . keys ( exports ) . some ( ( key ) => ( key === condition && typeof exports [ key ] === "string" ) ) ;
20+ const hasTopLevelBuildCondition = Object . keys ( exports ) . some (
21+ ( key ) => key === condition && typeof exports [ key ] === "string"
22+ ) ;
2423 let hasBuildCondition = hasTopLevelBuildCondition ;
2524 for ( const [ key , value ] of Object . entries ( exports ) ) {
2625 if ( typeof value === "object" && value != null ) {
27- const { transformedExports, hasBuildCondition : innerBuildCondition } = transformBuildCondition (
26+ const { transformedExports, hasBuildCondition : innerBuildCondition } = transformBuildCondition (
2827 value as { [ key : string ] : unknown } ,
2928 condition
3029 ) ;
@@ -34,15 +33,14 @@ export function transformBuildCondition(
3433 // If it doesn't have the build condition, we need to keep everything as is
3534 // If it has the build condition, we need to keep only the build condition
3635 // and remove everything else
37- if ( ! hasTopLevelBuildCondition ) {
36+ if ( ! hasTopLevelBuildCondition ) {
3837 transformed [ key ] = value ;
39- } else if ( key === condition ) {
38+ } else if ( key === condition ) {
4039 transformed [ key ] = value ;
4140 }
42-
4341 }
4442 }
45- return { transformedExports : transformed , hasBuildCondition} ;
43+ return { transformedExports : transformed , hasBuildCondition } ;
4644}
4745// We only care about these 2 fields
4846interface PackageJson {
@@ -52,7 +50,7 @@ interface PackageJson {
5250}
5351
5452/**
55- *
53+ *
5654 * @param json The package.json object
5755 * @returns An object with the transformed package.json and a boolean indicating if the build condition was found
5856 */
@@ -69,7 +67,7 @@ export function transformPackageJson(json: PackageJson) {
6967 transformed . imports = imp . transformedExports ;
7068 hasBuildCondition = hasBuildCondition || imp . hasBuildCondition ;
7169 }
72- return { transformed, hasBuildCondition} ;
70+ return { transformed, hasBuildCondition } ;
7371}
7472
7573export async function copyWorkerdPackages ( options : BuildOptions , nodePackages : Map < string , string > ) {
@@ -81,23 +79,15 @@ export async function copyWorkerdPackages(options: BuildOptions, nodePackages: M
8179 for ( const [ src , dst ] of nodePackages . entries ( ) ) {
8280 try {
8381 const pkgJson = JSON . parse ( await fs . readFile ( path . join ( src , "package.json" ) , "utf8" ) ) ;
84- const { transformed, hasBuildCondition} = transformPackageJson ( pkgJson ) ;
82+ const { transformed, hasBuildCondition } = transformPackageJson ( pkgJson ) ;
8583 const match = src . match ( isNodeModuleRegex ) ;
86- if (
87- match ?. groups ?. pkg &&
88- externalPackages . includes ( match . groups . pkg ) &&
89- hasBuildCondition
90- ) {
84+ if ( match ?. groups ?. pkg && externalPackages . includes ( match . groups . pkg ) && hasBuildCondition ) {
9185 logger . debug (
9286 `Copying package using a workerd condition: ${ path . relative ( options . appPath , src ) } -> ${ path . relative ( options . appPath , dst ) } `
9387 ) ;
9488 fs . cp ( src , dst , { recursive : true , force : true } ) ;
9589 // Write the transformed package.json
96- await fs . writeFile (
97- path . join ( dst , "package.json" ) ,
98- JSON . stringify ( transformed ) ,
99- "utf8"
100- ) ;
90+ await fs . writeFile ( path . join ( dst , "package.json" ) , JSON . stringify ( transformed ) , "utf8" ) ;
10191 }
10292 } catch {
10393 logger . error ( `Failed to copy ${ src } ` ) ;
0 commit comments