diff --git a/packages/core/src/lambda/commands/editLambda.ts b/packages/core/src/lambda/commands/editLambda.ts index 05476a8c765..b0b2498b528 100644 --- a/packages/core/src/lambda/commands/editLambda.ts +++ b/packages/core/src/lambda/commands/editLambda.ts @@ -12,7 +12,6 @@ import { getFunctionInfo, getLambdaDetails, getTempLocation, - lambdaEdits, lambdaTempPath, setFunctionInfo, } from '../utils' @@ -138,7 +137,6 @@ export async function editLambdaCommand(functionNode: LambdaFunctionNode) { export async function editLambda(lambda: LambdaFunction, onActivation?: boolean) { return await telemetry.lambda_quickEditFunction.run(async () => { telemetry.record({ source: onActivation ? 'workspace' : 'explorer' }) - const { name, region, configuration } = lambda const downloadLocation = getTempLocation(lambda.name, lambda.region) const downloadLocationName = vscode.workspace.asRelativePath(downloadLocation, true) @@ -201,9 +199,6 @@ export async function editLambda(lambda: LambdaFunction, onActivation?: boolean) watchForUpdates(lambda, vscode.Uri.file(downloadLocation)) } - const newEdit = { location: downloadLocationName, region, functionName: name, configuration } - lambdaEdits.push(newEdit) - return downloadLocation }) } diff --git a/packages/core/src/lambda/commands/uploadLambda.ts b/packages/core/src/lambda/commands/uploadLambda.ts index 8105506ee45..6bfd3777463 100644 --- a/packages/core/src/lambda/commands/uploadLambda.ts +++ b/packages/core/src/lambda/commands/uploadLambda.ts @@ -19,14 +19,13 @@ import { SamCliBuildInvocation } from '../../shared/sam/cli/samCliBuild' import { getSamCliContext } from '../../shared/sam/cli/samCliContext' import { SamTemplateGenerator } from '../../shared/templates/sam/samTemplateGenerator' import { addCodiconToString } from '../../shared/utilities/textUtilities' -import { getLambdaEditFromNameRegion, getLambdaDetails, listLambdaFunctions } from '../utils' +import { getLambdaDetails, listLambdaFunctions } from '../utils' import { getIdeProperties } from '../../shared/extensionUtilities' import { createQuickPick, DataQuickPickItem } from '../../shared/ui/pickerPrompter' import { createCommonButtons } from '../../shared/ui/buttons' import { StepEstimator, Wizard, WIZARD_BACK } from '../../shared/wizards/wizard' import { createSingleFileDialog } from '../../shared/ui/common/openDialog' import { Prompter, PromptResult } from '../../shared/ui/prompter' -import { SkipPrompter } from '../../shared/ui/common/skipPrompter' import { ToolkitError } from '../../shared/errors' import { FunctionConfiguration } from 'aws-sdk/clients/lambda' import globals from '../../shared/extensionGlobals' @@ -104,13 +103,6 @@ export async function uploadLambdaCommand(lambdaArg?: LambdaFunction, path?: vsc } else if (response.uploadType === 'directory' && response.directoryBuildType) { result = (await runUploadDirectory(lambda, response.directoryBuildType, response.targetUri)) ?? result result = 'Succeeded' - } else if (response.uploadType === 'edit') { - const functionPath = getLambdaEditFromNameRegion(lambda.name, lambda.region)?.location - if (!functionPath) { - throw new ToolkitError('Function had a local copy before, but not anymore') - } else { - await runUploadDirectory(lambda, 'zip', vscode.Uri.file(functionPath)) - } } // TODO(sijaden): potentially allow the wizard to easily support tagged-union states } catch (err) { @@ -139,8 +131,8 @@ export async function uploadLambdaCommand(lambdaArg?: LambdaFunction, path?: vsc /** * Selects the type of file to upload (zip/dir) and proceeds with the rest of the workflow. */ -function createUploadTypePrompter(lambda?: LambdaFunction) { - const items: DataQuickPickItem<'edit' | 'zip' | 'directory'>[] = [ +function createUploadTypePrompter() { + const items: DataQuickPickItem<'zip' | 'directory'>[] = [ { label: addCodiconToString('file-zip', localize('AWS.generic.filetype.zipfile', 'ZIP Archive')), data: 'zip', @@ -151,17 +143,6 @@ function createUploadTypePrompter(lambda?: LambdaFunction) { }, ] - if (lambda !== undefined) { - const { region, name: functionName } = lambda - const lambdaEdit = getLambdaEditFromNameRegion(functionName, region) - if (lambdaEdit) { - items.unshift({ - label: addCodiconToString('edit', localize('AWS.generic.filetype.edit', 'Local edit')), - data: 'edit', - }) - } - } - return createQuickPick(items, { title: localize('AWS.lambda.upload.title', 'Select Upload Type'), buttons: createCommonButtons(), @@ -215,7 +196,7 @@ function createConfirmDeploymentPrompter(lambda: LambdaFunction) { } export interface UploadLambdaWizardState { - readonly uploadType: 'edit' | 'zip' | 'directory' + readonly uploadType: 'zip' | 'directory' readonly targetUri: vscode.Uri readonly directoryBuildType: 'zip' | 'sam' readonly confirmedDeploy: boolean @@ -234,23 +215,23 @@ export class UploadLambdaWizard extends Wizard { this.form.targetUri.setDefault(this.invokePath) } } else { - this.form.uploadType.bindPrompter(() => createUploadTypePrompter(this.lambda)) - this.form.targetUri.bindPrompter( - ({ uploadType }) => { - if (uploadType === 'directory') { - return createSingleFileDialog({ - canSelectFolders: false, - canSelectFiles: true, - filters: { - 'ZIP archive': ['zip'], - }, - }) - } else { - return new SkipPrompter() - } - }, - { showWhen: ({ uploadType }) => uploadType !== 'edit' } - ) + this.form.uploadType.bindPrompter(() => createUploadTypePrompter()) + this.form.targetUri.bindPrompter(({ uploadType }) => { + if (uploadType === 'directory') { + return createSingleFileDialog({ + canSelectFolders: true, + canSelectFiles: false, + }) + } else { + return createSingleFileDialog({ + canSelectFolders: false, + canSelectFiles: true, + filters: { + 'ZIP archive': ['zip'], + }, + }) + } + }) } this.form.lambda.name.bindPrompter((state) => { @@ -277,12 +258,7 @@ export class UploadLambdaWizard extends Wizard { this.form.directoryBuildType.setDefault('zip') } - this.form.confirmedDeploy.bindPrompter( - (state) => { - return createConfirmDeploymentPrompter(state.lambda!) - }, - { showWhen: ({ uploadType }) => uploadType !== 'edit' } - ) + this.form.confirmedDeploy.bindPrompter((state) => createConfirmDeploymentPrompter(state.lambda!)) return this } diff --git a/packages/core/src/lambda/utils.ts b/packages/core/src/lambda/utils.ts index 4bb9063fedd..e4c2d929680 100644 --- a/packages/core/src/lambda/utils.ts +++ b/packages/core/src/lambda/utils.ts @@ -202,23 +202,3 @@ export function getTempRegionLocation(region: string) { export function getTempLocation(functionName: string, region: string) { return path.join(getTempRegionLocation(region), functionName) } - -type LambdaEdit = { - location: string - functionName: string - region: string - configuration?: Lambda.FunctionConfiguration -} - -// Array to keep the list of functions that are being edited. -export const lambdaEdits: LambdaEdit[] = [] - -// Given a particular function and region, it returns the full LambdaEdit object -export function getLambdaEditFromNameRegion(name: string, functionRegion: string) { - return lambdaEdits.find(({ functionName, region }) => functionName === name && region === functionRegion) -} - -// Given a particular localPath, it returns the full LambdaEdit object -export function getLambdaEditFromLocation(functionLocation: string) { - return lambdaEdits.find(({ location }) => location === functionLocation) -} diff --git a/packages/core/src/test/lambda/commands/editLambda.test.ts b/packages/core/src/test/lambda/commands/editLambda.test.ts index 9c38f767885..b6b1f88d623 100644 --- a/packages/core/src/test/lambda/commands/editLambda.test.ts +++ b/packages/core/src/test/lambda/commands/editLambda.test.ts @@ -75,7 +75,6 @@ describe('editLambda', function () { sinon.replace(require('../../../lambda/commands/editLambda'), 'promptDeploy', promptDeployStub) // Other stubs - sinon.stub(utils, 'lambdaEdits').value([]) sinon.stub(utils, 'getLambdaDetails').returns({ fileName: 'index.js', functionName: 'test-function' }) sinon.stub(fs, 'readdir').resolves([]) sinon.stub(fs, 'delete').resolves() diff --git a/packages/core/src/test/lambda/utils.test.ts b/packages/core/src/test/lambda/utils.test.ts index 72f5d3e63e4..9ea5eaf21cd 100644 --- a/packages/core/src/test/lambda/utils.test.ts +++ b/packages/core/src/test/lambda/utils.test.ts @@ -12,9 +12,6 @@ import { getFunctionInfo, setFunctionInfo, compareCodeSha, - lambdaEdits, - getLambdaEditFromNameRegion, - getLambdaEditFromLocation, } from '../../lambda/utils' import { LambdaFunction } from '../../lambda/commands/uploadLambda' import { DefaultLambdaClient } from '../../shared/clients/lambdaClient' @@ -187,48 +184,4 @@ describe('lambda utils', function () { assert.strictEqual(result, false) }) }) - - describe('lambdaEdits array functions', function () { - beforeEach(function () { - lambdaEdits.length = 0 - lambdaEdits.push( - { - location: '/tmp/func1', - functionName: 'func1', - region: 'us-east-1', - }, - { - location: '/tmp/func2', - functionName: 'func2', - region: 'us-west-2', - } - ) - }) - - describe('getLambdaEditFromNameRegion', function () { - it('finds edit by name and region', function () { - const result = getLambdaEditFromNameRegion('func1', 'us-east-1') - assert.strictEqual(result?.functionName, 'func1') - assert.strictEqual(result?.region, 'us-east-1') - }) - - it('returns undefined when not found', function () { - const result = getLambdaEditFromNameRegion('nonexistent', 'us-east-1') - assert.strictEqual(result, undefined) - }) - }) - - describe('getLambdaEditFromLocation', function () { - it('finds edit by location', function () { - const result = getLambdaEditFromLocation('/tmp/func2') - assert.strictEqual(result?.functionName, 'func2') - assert.strictEqual(result?.location, '/tmp/func2') - }) - - it('returns undefined when not found', function () { - const result = getLambdaEditFromLocation('/tmp/nonexistent') - assert.strictEqual(result, undefined) - }) - }) - }) }) diff --git a/packages/toolkit/.changes/next-release/Bug Fix-70bf4138-7b79-4fc1-8e6a-0637f0058da6.json b/packages/toolkit/.changes/next-release/Bug Fix-70bf4138-7b79-4fc1-8e6a-0637f0058da6.json new file mode 100644 index 00000000000..c11eb175a75 --- /dev/null +++ b/packages/toolkit/.changes/next-release/Bug Fix-70bf4138-7b79-4fc1-8e6a-0637f0058da6.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Lambda upload from directory doesn't allow selection of directory" +}