fix: nodejs wrapper передаёт require в new Function (v1.3.95)

This commit is contained in:
“Naeel”
2026-05-19 16:48:19 +04:00
parent 27dbe3bccb
commit fe8870af71
5 changed files with 20 additions and 16 deletions
+5 -3
View File
@@ -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) {