Skip to content

Commit cc9e789

Browse files
authored
fix: "Upload Lambda" from template.yaml asks for directory #3043
Problem: When "Upload Lambda" is invoked from a template.yaml file in the vscode file explorer, the wizard prompts for the choice of a zip or a directory and then which directory. These steps are redundant. Solution: When "Upload Lambda" is invoked from a template.yaml, skip the wizard steps that ask to choose a directory.
1 parent 24519eb commit cc9e789

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Upload Lambda wizard will skip prompts and auto select parent directory when invoked from a template file."
4+
}

src/lambda/commands/uploadLambda.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,13 @@ export class UploadLambdaWizard extends Wizard<UploadLambdaWizardState> {
212212
super({ initState: { lambda } })
213213
this.form.lambda.region.bindPrompter(() => createRegionPrompter().transform(region => region.id))
214214

215-
if (invokePath && fs.statSync(invokePath.fsPath).isDirectory()) {
215+
if (invokePath) {
216216
this.form.uploadType.setDefault('directory')
217-
this.form.targetUri.setDefault(invokePath)
217+
if (fs.statSync(invokePath.fsPath).isFile()) {
218+
this.form.targetUri.setDefault(vscode.Uri.file(path.dirname(invokePath.fsPath)))
219+
} else {
220+
this.form.targetUri.setDefault(invokePath)
221+
}
218222
} else {
219223
this.form.uploadType.bindPrompter(() => createUploadTypePrompter())
220224
this.form.targetUri.bindPrompter(({ uploadType }) => {

src/test/lambda/wizards/uploadLambdaWizard.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
*/
55

66
import * as vscode from 'vscode'
7+
import * as path from 'path'
8+
import * as assert from 'assert'
9+
import * as fs from 'fs-extra'
10+
import { writeFileSync } from 'fs-extra'
711
import { createWizardTester, WizardTester } from '../../shared/wizards/wizardTestUtils'
812
import { UploadLambdaWizard, UploadLambdaWizardState, LambdaFunction } from '../../../lambda/commands/uploadLambda'
913
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
@@ -54,6 +58,9 @@ describe('UploadLambdaWizard', function () {
5458
invokePath = vscode.Uri.file(tempDir)
5559
tester = createWizardTester(new UploadLambdaWizard(undefined, invokePath))
5660
})
61+
afterEach(async function () {
62+
await fs.remove(tempDir)
63+
})
5764

5865
it('skip select directory, auto selected', function () {
5966
tester.lambda.region.assertShow(1)
@@ -65,4 +72,30 @@ describe('UploadLambdaWizard', function () {
6572
tester.confirmedDeploy.assertShow(3)
6673
})
6774
})
75+
76+
describe('invoked from template', function () {
77+
let tempDir: string
78+
let tempDirUri: vscode.Uri
79+
let invokePath: vscode.Uri
80+
beforeEach(async function () {
81+
tempDir = await makeTemporaryToolkitFolder()
82+
tempDirUri = vscode.Uri.file(tempDir)
83+
writeFileSync(path.join(tempDir, 'template.yaml'), '')
84+
invokePath = vscode.Uri.file(path.join(tempDir, 'template.yaml'))
85+
tester = createWizardTester(new UploadLambdaWizard(undefined, invokePath))
86+
})
87+
afterEach(async function () {
88+
await fs.remove(tempDir)
89+
})
90+
91+
it('skip select directory, auto selected', function () {
92+
tester.lambda.region.assertShow(1)
93+
tester.uploadType.assertDoesNotShow()
94+
tester.uploadType.assertValue('directory')
95+
tester.targetUri.assertDoesNotShow()
96+
assert.strictEqual(tester.targetUri.value?.fsPath, tempDirUri.fsPath)
97+
tester.lambda.name.assertShow(2)
98+
tester.confirmedDeploy.assertShow(3)
99+
})
100+
})
68101
})

0 commit comments

Comments
 (0)