Skip to content
Merged
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions src/lib/run-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ async function invokeAction ({ actionRequestContext, logger }) {
}
}
}

// if we run an action, we will restore the process.env after the call
// we must do this before we load the action because code can execute on require/import
const preCallEnv = cloneDeep(process.env)
Comment thread
purplecabbage marked this conversation as resolved.
Outdated
// generate an activationID just like openwhisk
process.env.__OW_ACTIVATION_ID = crypto.randomBytes(16).toString('hex')
Comment thread
purplecabbage marked this conversation as resolved.

Expand All @@ -366,10 +370,15 @@ async function invokeAction ({ actionRequestContext, logger }) {

if (actionFunction) {
try {
// get cwd and process.env before changing it, so we can restore it later
Comment thread
purplecabbage marked this conversation as resolved.
Outdated
const originalCwd = process.cwd()
process.chdir(path.dirname(action.function))
process.env.__OW_ACTION_NAME = `/${process.env.__OW_NAMESPACE}/${packageName}/${actionName}`
const response = await actionFunction(params)
delete process.env.__OW_ACTION_NAME
logger.debug('restoring process.env and cwd')
process.env = preCallEnv // restore the environment variables
Comment thread
purplecabbage marked this conversation as resolved.
Outdated
process.chdir(originalCwd) // restore the original working directory

let statusCode, headers, body

Expand Down