Skip to content

Commit

Permalink
feat(app-service): support global in cloud functions
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jun 7, 2022
1 parent 484f8af commit 5faf2ff
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ interface IExports {
declare const module: IModule
declare const exports: IExports
declare const console: FunctionConsole
declare const global: typeof globalThis
/**
* 主函数,云函数的入口函数
*/
Expand Down
84 changes: 84 additions & 0 deletions packages/app-service/package-lock.json

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

1 change: 1 addition & 0 deletions packages/app-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@aws-sdk/s3-request-presigner": "^3.72.0",
"alipay-sdk": "^3.1.7",
"axios": "^0.21.1",
"cross-fetch": "^3.1.5",
"database-proxy": "^0.8.2",
"dayjs": "^1.10.7",
"dotenv": "^8.2.0",
Expand Down
10 changes: 8 additions & 2 deletions packages/app-service/src/support/function-engine/engine.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { URL } from 'node:url'

import * as vm from 'vm'
import { nanosecond2ms } from '../utils'
Expand Down Expand Up @@ -75,7 +76,7 @@ export class FunctionEngine {
const _module = {
exports: {}
}
return {
const sandbox = {
__context__: functionContext,
__filename: functionContext.__function_name,
module: _module,
Expand All @@ -89,8 +90,13 @@ export class FunctionEngine {
clearInterval: clearInterval,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
process: { env: {} }
process: { env: {} },
URL: URL,
global: null,
}

sandbox.global = sandbox
return sandbox
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/app-service/src/support/function-engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export interface RuntimeContext {
__filename: string,
process: {
env: { [key: string]: string },
}
},
global: RuntimeContext
}

/**
Expand Down

0 comments on commit 5faf2ff

Please sign in to comment.