Skip to content

Commit

Permalink
fix(runtime): fix relative path of cloud function imports
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Nov 1, 2023
1 parent 0db715f commit 87e0ab0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
2 changes: 1 addition & 1 deletion runtimes/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export appid=your-app-id
telepresence intercept $appid -n laf-runtime -p 8000:8000 -e $(pwd)/.env

# after intercept command, you can use following command to check if intercept active
telepresence list -n $appid
telepresence list -n laf-runtime

# Start local service first, required nodejs version >= 18.0.0
npm install
Expand Down
79 changes: 38 additions & 41 deletions runtimes/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions runtimes/nodejs/src/support/engine/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class CloudFunction {
const wrapped = `
const require = (module) => {
fromModule.push(__filename)
return requireFunc(module, fromModule)
return requireFunc(module, fromModule, __filename)
}
${code};
const __main__ = exports.main || exports.default
Expand All @@ -123,7 +123,7 @@ export class CloudFunction {
const wrapped = `
const require = (module) => {
fromModule.push(__filename)
return requireFunc(module, fromModule)
return requireFunc(module, fromModule, __filename)
}
function __next__() {
Expand Down
7 changes: 3 additions & 4 deletions runtimes/nodejs/src/support/engine/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FunctionCache, FunctionContext } from '.'
import Config from '../../config'
import path from 'path'
import { FunctionCache } from './cache'
Expand All @@ -9,7 +8,7 @@ import { buildSandbox, createScript } from './utils'
export class FunctionModule {
private static cache: Map<string, any> = new Map()

static require(name: string, fromModule: string[]): any {
static require(name: string, fromModule: string[], filename: string): any {
if (name === '@/cloud-sdk') {
return require('@lafjs/cloud')
} else if (
Expand All @@ -20,7 +19,7 @@ export class FunctionModule {
if (!name.startsWith('@/')) {
const dirname = '/'
const filePath = path.join(
path.dirname(dirname + functionContext.__function_name),
path.dirname(dirname + filename),
name,
)
name = filePath.slice(dirname.length)
Expand Down Expand Up @@ -93,7 +92,7 @@ export class FunctionModule {
return `
const require = (name) => {
fromModule.push(__filename)
return requireFunc(name, fromModule)
return requireFunc(name, fromModule, __filename)
}
const exports = {};
${code}
Expand Down

0 comments on commit 87e0ab0

Please sign in to comment.