Skip to content
Merged
Changes from 4 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
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,11 @@ 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 = Object.assign({}, process.env)
Comment thread
purplecabbage marked this conversation as resolved.
Outdated
const originalCwd = process.cwd()
// 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 Down Expand Up @@ -417,6 +422,10 @@ async function invokeAction ({ actionRequestContext, logger }) {
statusCode,
body: { error: 'Response is not valid \'message/http\'.' }
}
} finally {
logger.debug('restoring process.env and cwd')
process.env = preCallEnv // restore the environment variables
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reassigning process.env can break references elsewhere; instead clear the existing process.env and reassign properties, e.g. delete all keys then Object.assign(process.env, preCallEnv), to preserve the env object identity.

Copilot uses AI. Check for mistakes.
process.chdir(originalCwd) // restore the original working directory
}
} else {
// this case the action returned an error object, so we should use it
Expand Down