fix: nodejs wrapper передаёт require в new Function (v1.3.95)
This commit is contained in:
@@ -23,10 +23,12 @@ func BuildJSDeployZip(code string) ([]byte, error) {
|
||||
|
||||
// main.js — CommonJS wrapper:
|
||||
// 1. new Function создаёт функцию в пустом модульном контексте (нет import/export)
|
||||
// 2. Передаём ей module и exports как параметры → пользовательский CJS код работает
|
||||
// 3. Экспортируем main/handler/default через module.exports
|
||||
// 2. Передаём ей module, exports и require как параметры → пользовательский CJS код работает
|
||||
// 3. require передаётся явно, т.к. new Function выполняется в глобальном scope
|
||||
// и не имеет доступа к module-local require из CJS контекста main.js
|
||||
// 4. Экспортируем main/handler/default через module.exports
|
||||
wrapper := fmt.Sprintf(`const __mod = { exports: {} };
|
||||
(new Function('module', 'exports', %s))(__mod, __mod.exports);
|
||||
(new Function('module', 'exports', 'require', %s))(__mod, __mod.exports, require);
|
||||
const _fn = __mod.exports;
|
||||
|
||||
async function __invoke(ctx) {
|
||||
|
||||
Reference in New Issue
Block a user