File tree Expand file tree Collapse file tree 5 files changed +19
-35
lines changed Expand file tree Collapse file tree 5 files changed +19
-35
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " wrangler " : minor
3+ ---
4+
5+ allow --name and --env args on wrangler deploy
Original file line number Diff line number Diff line change @@ -1004,19 +1004,17 @@ describe("deploy", () => {
10041004 ` ) ;
10051005 } ) ;
10061006
1007- it ( "should throw an error w/ helpful message when using --env --name" , async ( ) => {
1007+ it ( "should allow --env and --name to be used together " , async ( ) => {
10081008 writeWranglerConfig ( { env : { "some-env" : { } } } ) ;
10091009 writeWorkerSource ( ) ;
10101010 mockSubDomainRequest ( ) ;
1011+ mockUploadWorkerRequest ( {
1012+ env : "some-env" ,
1013+ expectedScriptName : "voyager" ,
1014+ legacyEnv : true ,
1015+ } ) ;
10111016 await runWrangler (
10121017 "deploy index.js --name voyager --env some-env --legacy-env true"
1013- ) . catch ( ( err ) =>
1014- expect ( err ) . toMatchInlineSnapshot ( `
1015- [Error: In legacy environment mode you cannot use --name and --env together. If you want to specify a Worker name for a specific environment you can add the following to your wrangler.toml file:
1016- [env.some-env]
1017- name = "voyager"
1018- ]
1019- ` )
10201018 ) ;
10211019 } ) ;
10221020 } ) ;
Original file line number Diff line number Diff line change @@ -42,13 +42,10 @@ export function mockUploadWorkerRequest(
4242 expectedContainers ?: { class_name : string } [ ] ;
4343 } = { }
4444) {
45- const expectedScriptName = ( options . expectedScriptName ??= "test-name" ) ;
4645 const handleUpload : HttpResponseResolver = async ( { params, request } ) => {
4746 const url = new URL ( request . url ) ;
4847 expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
49- expect ( params . scriptName ) . toEqual (
50- legacyEnv && env ? `${ expectedScriptName } -${ env } ` : expectedScriptName
51- ) ;
48+ expect ( params . scriptName ) . toEqual ( expectedScriptName ) ;
5249 if ( ! legacyEnv ) {
5350 expect ( params . envName ) . toEqual ( env ) ;
5451 }
@@ -185,6 +182,11 @@ export function mockUploadWorkerRequest(
185182 expectedObservability,
186183 expectedSettingsPatch,
187184 } = options ;
185+
186+ const expectedScriptName =
187+ options . expectedScriptName ??
188+ "test-name" + ( legacyEnv && env ? `-${ env } ` : "" ) ;
189+
188190 if ( env && ! legacyEnv ) {
189191 msw . use (
190192 http . put (
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export function mockGetWorkerSubdomain({
3939 previews_enabled = true ,
4040 env,
4141 legacyEnv = false ,
42- expectedScriptName = "test-name" ,
42+ expectedScriptName = "test-name" + ( legacyEnv && env ? `- ${ env } ` : "" ) ,
4343} : {
4444 enabled : boolean ;
4545 previews_enabled ?: boolean ;
@@ -56,9 +56,7 @@ export function mockGetWorkerSubdomain({
5656 url ,
5757 ( { params } ) => {
5858 expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
59- expect ( params . scriptName ) . toEqual (
60- legacyEnv && env ? `${ expectedScriptName } -${ env } ` : expectedScriptName
61- ) ;
59+ expect ( params . scriptName ) . toEqual ( expectedScriptName ) ;
6260 if ( ! legacyEnv ) {
6361 expect ( params . envName ) . toEqual ( env ) ;
6462 }
Original file line number Diff line number Diff line change 1- import { configFileName , formatConfigSnippet } from "../config" ;
2- import { CommandLineArgsError } from "../errors" ;
3- import { isLegacyEnv } from "./isLegacyEnv" ;
41import type { Config } from "../config" ;
52
63export function getScriptName (
74 args : { name : string | undefined ; env : string | undefined } ,
85 config : Config
96) : string | undefined {
10- if ( args . name && isLegacyEnv ( config ) && args . env ) {
11- throw new CommandLineArgsError (
12- `In legacy environment mode you cannot use --name and --env together. If you want to specify a Worker name for a specific environment you can add the following to your ${ configFileName ( config . configPath ) } file:\n` +
13- formatConfigSnippet (
14- {
15- env : {
16- [ args . env ] : {
17- name : args . name ,
18- } ,
19- } ,
20- } ,
21- config . configPath
22- )
23- ) ;
24- }
25-
267 return args . name ?? config . name ;
278}
You can’t perform that action at this time.
0 commit comments