Skip to content

Commit

Permalink
fix: temporary revert nested modules (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk authored May 17, 2022
1 parent 9ff4cf3 commit f4317e4
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 219 deletions.
4 changes: 1 addition & 3 deletions src/lambda/LambdaFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export default class LambdaFunction {
const _servicePath = resolve(servicePath, options.location || '')

const { handler, name, package: functionPackage = {} } = functionDefinition
const [handlerPath, handlerName, handlerModuleNesting] =
splitHandlerPathAndName(handler)
const [handlerPath, handlerName] = splitHandlerPathAndName(handler)

const memorySize =
functionDefinition.memorySize ||
Expand Down Expand Up @@ -114,7 +113,6 @@ export default class LambdaFunction {
functionKey,
handler,
handlerName,
handlerModuleNesting,
codeDir: this.#codeDir,
handlerPath: resolve(this.#codeDir, handlerPath),
runtime,
Expand Down
145 changes: 145 additions & 0 deletions src/lambda/__tests__/fixtures/lambdaFunction.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
'use strict'

exports.contextDoneHandler = function contextDoneHandler(event, context) {
context.done(null, 'foo')
}

exports.contextDoneHandlerDeferred = function contextDoneHandlerDeferred(
event,
context,
) {
setTimeout(() => context.done(null, 'foo'), 100)
}

exports.contextSucceedHandler = function contextSucceedHandler(event, context) {
context.succeed('foo')
}

exports.contextSucceedHandlerDeferred = function contextSucceedHandlerDeferred(
event,
context,
) {
setTimeout(() => context.succeed('foo'), 100)
}

exports.callbackHandler = function callbackHandler(event, context, callback) {
callback(null, 'foo')
}

exports.callbackHandlerDeferred = function callbackHandlerDeferred(
event,
context,
callback,
) {
setTimeout(() => callback(null, 'foo'), 100)
}

exports.promiseHandler = function promiseHandler() {
return Promise.resolve('foo')
}

exports.promiseHandlerDeferred = function promiseDeferred() {
return new Promise((resolve) => {
setTimeout(() => resolve('foo'), 100)
})
}

exports.asyncFunctionHandler = async function asyncFunctionHandler() {
return 'foo'
}

exports.asyncFunctionHandlerObject = async function asyncFunctionHandler() {
return {
foo: 'bar',
}
}

// we deliberately test the case where a 'callback' is defined
// in the handler, but a promise is being returned to protect from a
// potential naive implementation, e.g.
//
// const { promisify } = 'utils'
// const promisifiedHandler = handler.length === 3 ? promisify(handler) : handler
//
// if someone would return a promise, but also defines callback, without using it
// the handler would not be returning anything
exports.promiseWithDefinedCallbackHandler =
function promiseWithDefinedCallbackHandler(
event, // eslint-disable-line no-unused-vars
context, // eslint-disable-line no-unused-vars
callback, // eslint-disable-line no-unused-vars
) {
return Promise.resolve('Hello Promise!')
}

exports.contextSucceedWithContextDoneHandler =
function contextSucceedWithContextDoneHandler(event, context) {
context.succeed('Hello Context.succeed!')

context.done(null, 'Hello Context.done!')
}

exports.callbackWithContextDoneHandler =
function callbackWithContextDoneHandler(event, context, callback) {
callback(null, 'Hello Callback!')

context.done(null, 'Hello Context.done!')
}

exports.callbackWithPromiseHandler = function callbackWithPromiseHandler(
event,
context,
callback,
) {
callback(null, 'Hello Callback!')

return Promise.resolve('Hello Promise!')
}

exports.callbackInsidePromiseHandler = function callbackInsidePromiseHandler(
event,
context,
callback,
) {
return new Promise((resolve) => {
callback(null, 'Hello Callback!')

resolve('Hello Promise!')
})
}

exports.requestIdHandler = async function requestIdHandler(event, context) {
return context.awsRequestId
}

exports.remainingExecutionTimeHandler =
async function remainingExecutionTimeHandler(event, context) {
const first = context.getRemainingTimeInMillis()

await new Promise((resolve) => {
setTimeout(resolve, 100)
})

const second = context.getRemainingTimeInMillis()

await new Promise((resolve) => {
setTimeout(resolve, 200)
})

const third = context.getRemainingTimeInMillis()

return [first, second, third]
}

exports.defaultTimeoutHandler = async function defaultTimeoutHandler(
event,
context,
) {
return context.getRemainingTimeInMillis()
}

exports.executionTimeInMillisHandler = function executionTimeInMillisHandler() {
return new Promise((resolve) => {
setTimeout(resolve, 100)
})
}
123 changes: 0 additions & 123 deletions src/lambda/__tests__/fixtures/lambdaFunction.js

This file was deleted.

11 changes: 2 additions & 9 deletions src/lambda/handler-runner/HandlerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,8 @@ export default class HandlerRunner {
const { useDocker, useChildProcesses, useWorkerThreads, allowCache } =
this.#options

const {
functionKey,
handlerName,
handlerPath,
handlerModuleNesting,
runtime,
timeout,
} = this.#funOptions
const { functionKey, handlerName, handlerPath, runtime, timeout } =
this.#funOptions

if (this.log) {
this.log.debug(`Loading handler... (${handlerPath})`)
Expand Down Expand Up @@ -113,7 +107,6 @@ export default class HandlerRunner {
functionKey,
handlerPath,
handlerName,
handlerModuleNesting,
this.#env,
timeout,
allowCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ export default class ChildProcessRunner {
#functionKey = null
#handlerName = null
#handlerPath = null
#handlerModuleNesting = null
#timeout = null
#allowCache = false

constructor(funOptions, env, allowCache, v3Utils) {
const {
functionKey,
handlerName,
handlerPath,
handlerModuleNesting,
timeout,
} = funOptions
const { functionKey, handlerName, handlerPath, timeout } = funOptions

if (v3Utils) {
this.log = v3Utils.log
Expand All @@ -32,7 +25,6 @@ export default class ChildProcessRunner {
this.#functionKey = functionKey
this.#handlerName = handlerName
this.#handlerPath = handlerPath
this.#handlerModuleNesting = handlerModuleNesting
this.#timeout = timeout
this.#allowCache = allowCache
}
Expand All @@ -44,12 +36,7 @@ export default class ChildProcessRunner {
async run(event, context) {
const childProcess = node(
childProcessHelperPath,
[
this.#functionKey,
this.#handlerName,
this.#handlerPath,
this.#handlerModuleNesting,
],
[this.#functionKey, this.#handlerName, this.#handlerPath],
{
env: this.#env,
stdio: 'inherit',
Expand Down
Loading

0 comments on commit f4317e4

Please sign in to comment.