Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/core/src/lambda/commands/editLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getFunctionInfo,
getLambdaDetails,
getTempLocation,
lambdaEdits,
lambdaTempPath,
setFunctionInfo,
} from '../utils'
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
})
}
Expand Down
68 changes: 22 additions & 46 deletions packages/core/src/lambda/commands/uploadLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand All @@ -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(),
Expand Down Expand Up @@ -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
Expand All @@ -234,23 +215,23 @@ export class UploadLambdaWizard extends Wizard<UploadLambdaWizardState> {
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) => {
Expand All @@ -277,12 +258,7 @@ export class UploadLambdaWizard extends Wizard<UploadLambdaWizardState> {
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
}
Expand Down
20 changes: 0 additions & 20 deletions packages/core/src/lambda/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 0 additions & 47 deletions packages/core/src/test/lambda/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Lambda upload from directory doesn't allow selection of directory"
}
Loading