@@ -37,7 +37,7 @@ describe("publish", () => {
37
37
} ) ;
38
38
39
39
it ( "should be able to use the `build.upload.main` config as the entry-point for ESM sources" , async ( ) => {
40
- writeWranglerToml ( "./index.js" ) ;
40
+ writeWranglerToml ( { main : "./index.js" } ) ;
41
41
writeEsmWorkerSource ( ) ;
42
42
mockUploadWorkerRequest ( ) ;
43
43
mockSubDomainRequest ( ) ;
@@ -105,6 +105,57 @@ describe("publish", () => {
105
105
expect ( stderr ) . toMatchInlineSnapshot ( `""` ) ;
106
106
expect ( error ) . toMatchInlineSnapshot ( `undefined` ) ;
107
107
} ) ;
108
+
109
+ it ( "should warn if there is a `site.entry-point` configuration" , async ( ) => {
110
+ writeWranglerToml ( {
111
+ entryPoint : "./index.js" ,
112
+ } ) ;
113
+ writeEsmWorkerSource ( ) ;
114
+ mockUploadWorkerRequest ( ) ;
115
+ mockSubDomainRequest ( ) ;
116
+
117
+ const { stdout, stderr, error, warnings } = await runWrangler (
118
+ "publish ./index.js"
119
+ ) ;
120
+
121
+ expect ( stripTimings ( stdout ) ) . toMatchInlineSnapshot ( `
122
+ "Uploaded
123
+ test-name
124
+ (TIMINGS)
125
+ Deployed
126
+ test-name
127
+ (TIMINGS)
128
+
129
+ test-name.test-sub-domain.workers.dev"
130
+ ` ) ;
131
+ expect ( stderr ) . toMatchInlineSnapshot ( `""` ) ;
132
+ expect ( error ) . toMatchInlineSnapshot ( `undefined` ) ;
133
+ expect ( warnings ) . toMatchInlineSnapshot ( `
134
+ "Deprecation notice: The \`site.entry-point\` config field is no longer used.
135
+ The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`build.upload.main\` config field.
136
+ Please remove the \`site.entry-point\` field from the \`wrangler.toml\` file."
137
+ ` ) ;
138
+ } ) ;
139
+
140
+ it ( "should error if there is no entry-point specified" , async ( ) => {
141
+ writeWranglerToml ( ) ;
142
+ writeEsmWorkerSource ( ) ;
143
+ mockUploadWorkerRequest ( ) ;
144
+ mockSubDomainRequest ( ) ;
145
+
146
+ const { stdout, stderr, error } = await runWrangler ( "publish" ) ;
147
+
148
+ expect ( stripTimings ( stdout ) ) . toMatchInlineSnapshot ( `""` ) ;
149
+ expect ( stderr ) . toMatchInlineSnapshot ( `
150
+ "Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`build.upload.main\` config field.
151
+
152
+ [32m%s[0m
153
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
154
+ ` ) ;
155
+ expect ( error ) . toMatchInlineSnapshot (
156
+ `[Error: Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`build.upload.main\` config field.]`
157
+ ) ;
158
+ } ) ;
108
159
} ) ;
109
160
110
161
describe ( "asset upload" , ( ) => {
@@ -117,7 +168,7 @@ describe("publish", () => {
117
168
title : "__test-name_sites_assets" ,
118
169
id : "__test-name_sites_assets-id" ,
119
170
} ;
120
- writeWranglerToml ( "./index.js" , "assets" ) ;
171
+ writeWranglerToml ( { main : "./index.js" , bucket : "assets" } ) ;
121
172
writeEsmWorkerSource ( ) ;
122
173
writeAssets ( assets ) ;
123
174
mockUploadWorkerRequest ( ) ;
@@ -154,7 +205,7 @@ describe("publish", () => {
154
205
title : "__test-name_sites_assets" ,
155
206
id : "__test-name_sites_assets-id" ,
156
207
} ;
157
- writeWranglerToml ( "./index.js" , "assets" ) ;
208
+ writeWranglerToml ( { main : "./index.js" , bucket : "assets" } ) ;
158
209
writeEsmWorkerSource ( ) ;
159
210
writeAssets ( assets ) ;
160
211
mockUploadWorkerRequest ( ) ;
@@ -196,7 +247,7 @@ describe("publish", () => {
196
247
title : "__test-name_sites_assets" ,
197
248
id : "__test-name_sites_assets-id" ,
198
249
} ;
199
- writeWranglerToml ( "./index.js" , "assets" ) ;
250
+ writeWranglerToml ( { main : "./index.js" , bucket : "assets" } ) ;
200
251
writeEsmWorkerSource ( ) ;
201
252
writeAssets ( assets ) ;
202
253
mockUploadWorkerRequest ( ) ;
@@ -237,7 +288,7 @@ describe("publish", () => {
237
288
title : "__test-name_sites_assets" ,
238
289
id : "__test-name_sites_assets-id" ,
239
290
} ;
240
- writeWranglerToml ( "./index.js" , "assets" ) ;
291
+ writeWranglerToml ( { main : "./index.js" , bucket : "assets" } ) ;
241
292
writeEsmWorkerSource ( ) ;
242
293
writeAssets ( assets ) ;
243
294
mockUploadWorkerRequest ( ) ;
@@ -278,7 +329,11 @@ describe("publish", () => {
278
329
title : "__test-name_sites_assets" ,
279
330
id : "__test-name_sites_assets-id" ,
280
331
} ;
281
- writeWranglerToml ( "./index.js" , "assets" , [ "file-1.txt" ] ) ;
332
+ writeWranglerToml ( {
333
+ main : "./index.js" ,
334
+ bucket : "assets" ,
335
+ include : [ "file-1.txt" ] ,
336
+ } ) ;
282
337
writeEsmWorkerSource ( ) ;
283
338
writeAssets ( assets ) ;
284
339
mockUploadWorkerRequest ( ) ;
@@ -317,7 +372,11 @@ describe("publish", () => {
317
372
title : "__test-name_sites_assets" ,
318
373
id : "__test-name_sites_assets-id" ,
319
374
} ;
320
- writeWranglerToml ( "./index.js" , "assets" , undefined , [ "file-2.txt" ] ) ;
375
+ writeWranglerToml ( {
376
+ main : "./index.js" ,
377
+ bucket : "assets" ,
378
+ exclude : [ "file-2.txt" ] ,
379
+ } ) ;
321
380
writeEsmWorkerSource ( ) ;
322
381
writeAssets ( assets ) ;
323
382
mockUploadWorkerRequest ( ) ;
@@ -356,7 +415,11 @@ describe("publish", () => {
356
415
title : "__test-name_sites_assets" ,
357
416
id : "__test-name_sites_assets-id" ,
358
417
} ;
359
- writeWranglerToml ( "./index.js" , "assets" , [ "file-2.txt" ] ) ;
418
+ writeWranglerToml ( {
419
+ main : "./index.js" ,
420
+ bucket : "assets" ,
421
+ include : [ "file-2.txt" ] ,
422
+ } ) ;
360
423
writeEsmWorkerSource ( ) ;
361
424
writeAssets ( assets ) ;
362
425
mockUploadWorkerRequest ( ) ;
@@ -397,9 +460,11 @@ describe("publish", () => {
397
460
title : "__test-name_sites_assets" ,
398
461
id : "__test-name_sites_assets-id" ,
399
462
} ;
400
- writeWranglerToml ( "./index.js" , "assets" , undefined , [
401
- "assets/file-1.txt" ,
402
- ] ) ;
463
+ writeWranglerToml ( {
464
+ main : "./index.js" ,
465
+ bucket : "assets" ,
466
+ exclude : [ "assets/file-1.txt" ] ,
467
+ } ) ;
403
468
writeEsmWorkerSource ( ) ;
404
469
writeAssets ( assets ) ;
405
470
mockUploadWorkerRequest ( ) ;
@@ -446,7 +511,7 @@ describe("publish", () => {
446
511
title : "__test-name_sites_assets" ,
447
512
id : "__test-name_sites_assets-id" ,
448
513
} ;
449
- writeWranglerToml ( "./index.js" , "assets" ) ;
514
+ writeWranglerToml ( { main : "./index.js" , bucket : "assets" } ) ;
450
515
writeEsmWorkerSource ( ) ;
451
516
writeAssets ( assets ) ;
452
517
mockUploadWorkerRequest ( ) ;
@@ -492,7 +557,7 @@ describe("publish", () => {
492
557
title : "__test-name_sites_assets" ,
493
558
id : "__test-name_sites_assets-id" ,
494
559
} ;
495
- writeWranglerToml ( "./index.js" , "assets" ) ;
560
+ writeWranglerToml ( { main : "./index.js" , bucket : "assets" } ) ;
496
561
writeEsmWorkerSource ( ) ;
497
562
writeAssets ( assets ) ;
498
563
mockUploadWorkerRequest ( ) ;
@@ -535,9 +600,11 @@ describe("publish", () => {
535
600
title : "__test-name_sites_assets" ,
536
601
id : "__test-name_sites_assets-id" ,
537
602
} ;
538
- writeWranglerToml ( "./index.js" , "assets" , undefined , [
539
- "assets/file-1.txt" ,
540
- ] ) ;
603
+ writeWranglerToml ( {
604
+ main : "./index.js" ,
605
+ bucket : "assets" ,
606
+ exclude : [ "assets/file-1.txt" ] ,
607
+ } ) ;
541
608
writeEsmWorkerSource ( ) ;
542
609
writeAssets ( assets ) ;
543
610
mockUploadWorkerRequest ( ) ;
@@ -571,7 +638,7 @@ describe("publish", () => {
571
638
title : "__test-name_sites_assets" ,
572
639
id : "__test-name_sites_assets-id" ,
573
640
} ;
574
- writeWranglerToml ( "./index.js" , "assets" ) ;
641
+ writeWranglerToml ( { main : "./index.js" , bucket : "assets" } ) ;
575
642
writeEsmWorkerSource ( ) ;
576
643
writeAssets ( [ longFilePathAsset ] ) ;
577
644
mockUploadWorkerRequest ( ) ;
@@ -598,22 +665,30 @@ describe("publish", () => {
598
665
} ) ;
599
666
600
667
/** Write a mock wrangler.toml file to disk. */
601
- function writeWranglerToml (
602
- main ?: string ,
603
- bucket ?: string ,
604
- include ?: string [ ] ,
605
- exclude ?: string [ ]
606
- ) {
668
+ function writeWranglerToml ( {
669
+ main,
670
+ bucket,
671
+ include,
672
+ exclude,
673
+ entryPoint,
674
+ } : {
675
+ main ?: string ;
676
+ bucket ?: string ;
677
+ include ?: string [ ] ;
678
+ exclude ?: string [ ] ;
679
+ entryPoint ?: string ;
680
+ } = { } ) {
607
681
fs . writeFileSync (
608
682
"./wrangler.toml" ,
609
683
[
610
684
`compatibility_date = "2022-01-12"` ,
611
685
`name = "test-name"` ,
612
686
main !== undefined ? `[build.upload]\nmain = "${ main } "` : "" ,
613
- bucket || include || exclude ? "[site]" : "" ,
687
+ bucket || include || exclude || entryPoint ? "[site]" : "" ,
614
688
bucket !== undefined ? `bucket = "${ bucket } "` : "" ,
615
689
include !== undefined ? `include = ${ JSON . stringify ( include ) } ` : "" ,
616
690
exclude !== undefined ? `exclude = ${ JSON . stringify ( exclude ) } ` : "" ,
691
+ entryPoint !== undefined ? `entry-point = "${ entryPoint } "` : "" ,
617
692
] . join ( "\n" ) ,
618
693
"utf-8"
619
694
) ;
0 commit comments