Skip to content

Commit

Permalink
fix: __dirname in esm
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed May 31, 2022
1 parent 7c1454b commit 0cdf1b9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import debugLog from '../../debugLog.js'
import serverlessLog, { logRoutes } from '../../serverlessLog.js'
import {
detectEncoding,
generateHapiPath,
getHttpApiCorsConfig,
jsonPath,
splitHandlerPathAndName,
generateHapiPath,
} from '../../utils/index.js'

const { parse, stringify } = JSON
Expand Down
4 changes: 3 additions & 1 deletion src/events/http/authJWTSettingsExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default function authJWTSettingsExtractor(
serverlessLog(`WARNING: ${warningMessage}`)
}

return { unsupportedAuth: true }
return {
unsupportedAuth: true,
}
}

const buildSuccessResult = (authorizerName) => ({ authorizerName })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from 'node:path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { execaNode } from 'execa'

const childProcessHelperPath = path.resolve(__dirname, 'childProcessHelper.js')
const __dirname = dirname(fileURLToPath(import.meta.url))
const childProcessHelperPath = resolve(__dirname, 'childProcessHelper.js')

export default class ChildProcessRunner {
#allowCache = false
Expand Down Expand Up @@ -43,10 +45,10 @@ export default class ChildProcessRunner {
},
)

const message = new Promise((resolve, reject) => {
const message = new Promise((res, rej) => {
childProcess.on('message', (data) => {
if (data.error) reject(data.error)
else resolve(data)
if (data.error) rej(data.error)
else res(data)
})
}).finally(() => {
childProcess.kill()
Expand Down
5 changes: 4 additions & 1 deletion src/lambda/handler-runner/python-runner/PythonRunner.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { spawn } from 'node:child_process'
import { EOL, platform } from 'node:os'
import { delimiter, join, relative, resolve } from 'node:path'
import { delimiter, dirname, join, relative, resolve } from 'node:path'
import process, { cwd } from 'node:process'
import readline from 'node:readline'
import { fileURLToPath } from 'node:url'

const { parse, stringify } = JSON
const { assign } = Object
const { has } = Reflect

const __dirname = dirname(fileURLToPath(import.meta.url))

export default class PythonRunner {
#allowCache = false
#env = null
Expand Down
7 changes: 5 additions & 2 deletions src/lambda/handler-runner/ruby-runner/RubyRunner.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { EOL, platform } from 'node:os'
import { relative, resolve } from 'node:path'
import { dirname, relative, resolve } from 'node:path'
import { cwd } from 'node:process'
import { fileURLToPath } from 'node:url'
import { execa } from 'execa'

const { parse, stringify } = JSON
const { has } = Reflect

const __dirname = dirname(fileURLToPath(import.meta.url))

export default class RubyRunner {
#allowCache = false
#env = null
#handlerName = null
#handlerPath = null
#allowCache = false

constructor(funOptions, env, allowCache, v3Utils) {
const { handlerName, handlerPath } = funOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { resolve } from 'node:path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { MessageChannel, Worker } from 'node:worker_threads'

const __dirname = dirname(fileURLToPath(import.meta.url))
const workerThreadHelperPath = resolve(__dirname, './workerThreadHelper.js')

export default class WorkerThreadRunner {
Expand Down Expand Up @@ -34,18 +36,18 @@ export default class WorkerThreadRunner {
}

run(event, context) {
return new Promise((_resolve, reject) => {
return new Promise((res, rej) => {
const { port1, port2 } = new MessageChannel()

port1
.on('message', _resolve)
.on('message', res)
// emitted if the worker thread throws an uncaught exception.
// In that case, the worker will be terminated.
.on('error', reject)
.on('error', rej)
// TODO
.on('exit', (code) => {
if (code !== 0) {
reject(new Error(`Worker stopped with exit code ${code}`))
rej(new Error(`Worker stopped with exit code ${code}`))
}
})

Expand Down

0 comments on commit 0cdf1b9

Please sign in to comment.