Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support esm #613

Merged
merged 2 commits into from
Oct 24, 2022
Merged
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
15 changes: 13 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Edit the .env, deploy.env, ${program.contextFile}, \
event_sources.json and ${program.eventFile} files as needed.`)
}

run (program) {
async run (program) {
if (!['nodejs14.x', 'nodejs16.x'].includes(program.runtime)) {
console.error(`Runtime [${program.runtime}] is not supported.`)
process.exit(254)
Expand All @@ -67,7 +67,18 @@ event_sources.json and ${program.eventFile} files as needed.`)
this._setRunTimeEnvironmentVars(program)
}

const handler = require(path.join(process.cwd(), filename))[handlername]
const handlerFilePath = (() => {
const filePath = path.join(process.cwd(), filename)
if (path.sep === '\\') {
// Convert because of error in Windows.
// Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]:
// Only URLs with a scheme in: file, data are supported by the default ESM loader.
// On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
return 'file:///' + filePath.split(path.sep).join('/')
}
return filePath
})()
const handler = (await import(handlerFilePath))[handlername]
const event = require(path.join(process.cwd(), program.eventFile))
const context = require(path.join(process.cwd(), program.contextFile))
const enableRunMultipleEvents = (() => {
Expand Down