@@ -59,10 +59,6 @@ describe("transformBuildCondition", () => {
5959 expect ( defaultExport . transformedExports ) . toEqual ( {
6060 "." : "/path/to/index.js" ,
6161 "./server" : {
62- "react-server" : {
63- workerd : "./server.edge.js" ,
64- other : "./server.js" ,
65- } ,
6662 default : "./server.js" ,
6763 } ,
6864 } ) ;
@@ -80,7 +76,7 @@ describe("transformBuildCondition", () => {
8076 } ) ;
8177 } ) ;
8278
83- test ( "only consider leaves " , ( ) => {
79+ test ( "object-valued condition " , ( ) => {
8480 const exports = {
8581 "." : "/path/to/index.js" ,
8682 "./server" : {
@@ -92,7 +88,7 @@ describe("transformBuildCondition", () => {
9288
9389 const workerd = transformBuildCondition ( exports , "workerd" ) ;
9490
95- expect ( workerd . hasBuildCondition ) . toBe ( false ) ;
91+ expect ( workerd . hasBuildCondition ) . toBe ( true ) ;
9692 expect ( workerd . transformedExports ) . toEqual ( {
9793 "." : "/path/to/index.js" ,
9894 "./server" : {
@@ -102,6 +98,25 @@ describe("transformBuildCondition", () => {
10298 } ,
10399 } ) ;
104100 } ) ;
101+
102+ test ( "preserve sibling subtree that nests the condition" , ( ) => {
103+ const exports = {
104+ "react-server" : {
105+ workerd : "./rsc.edge.js" ,
106+ } ,
107+ workerd : "./top.edge.js" ,
108+ } ;
109+
110+ const workerd = transformBuildCondition ( exports , "workerd" ) ;
111+
112+ expect ( workerd . hasBuildCondition ) . toBe ( true ) ;
113+ expect ( workerd . transformedExports ) . toEqual ( {
114+ "react-server" : {
115+ workerd : "./rsc.edge.js" ,
116+ } ,
117+ workerd : "./top.edge.js" ,
118+ } ) ;
119+ } ) ;
105120} ) ;
106121
107122describe ( "transformPackageJson" , ( ) => {
@@ -176,6 +191,38 @@ describe("transformPackageJson", () => {
176191 expect ( hasBuildCondition ) . toBe ( true ) ;
177192 } ) ;
178193
194+ // https://github.com/opennextjs/opennextjs-cloudflare/issues/1153
195+ // Matches the exports field of pg-cloudflare@1.3.0.
196+ test ( "exports with object-valued workerd condition (pg-cloudflare)" , ( ) => {
197+ const json = {
198+ name : "pg-cloudflare" ,
199+ exports : {
200+ "." : {
201+ workerd : {
202+ import : "./esm/index.mjs" ,
203+ require : "./dist/index.js" ,
204+ } ,
205+ default : "./dist/empty.js" ,
206+ } ,
207+ "./package.json" : "./package.json" ,
208+ } ,
209+ } ;
210+ const { transformed, hasBuildCondition } = transformPackageJson ( json ) ;
211+ expect ( transformed ) . toEqual ( {
212+ name : "pg-cloudflare" ,
213+ exports : {
214+ "." : {
215+ workerd : {
216+ import : "./esm/index.mjs" ,
217+ require : "./dist/index.js" ,
218+ } ,
219+ } ,
220+ "./package.json" : "./package.json" ,
221+ } ,
222+ } ) ;
223+ expect ( hasBuildCondition ) . toBe ( true ) ;
224+ } ) ;
225+
179226 test ( "exports and imports with workerd condition both nested and top level" , ( ) => {
180227 const json = {
181228 name : "test" ,
0 commit comments