snapshot before legacy cleanup

This commit is contained in:
Naeel
2026-04-27 07:36:06 +03:00
parent 9461026546
commit 7cfe20bf76
25 changed files with 1430 additions and 261 deletions
+9 -1
View File
@@ -22,6 +22,11 @@ import (
// Результат: zip с двумя файлами:
// - package.json: {"type":"module"}
// - main.js: ESM wrapper + инлайн пользовательский код через new Function
//
// Совместимость entrypoint:
// UI исторически отправлял entrypoint="handler", а backend по умолчанию использует
// entrypoint="main". Чтобы specialization не ломался из-за несовпадения,
// wrapper экспортирует обе точки входа: named exports main и handler, а также default.
func BuildJSDeployZip(code string) ([]byte, error) {
// Сериализуем пользовательский код в JSON строку чтобы безопасно инлайнить
// в JavaScript-литерал — экранирует кавычки, переводы строк, спецсимволы.
@@ -38,7 +43,7 @@ func BuildJSDeployZip(code string) ([]byte, error) {
(new Function('module', 'exports', %s))(__mod, __mod.exports);
const _fn = __mod.exports;
export default async function(ctx) {
async function __invoke(ctx) {
const fn = typeof _fn === 'function' ? _fn : (_fn.default || _fn.handler || _fn.main);
if (!fn) throw new Error('no exported function found in user code');
const result = await fn(ctx);
@@ -46,6 +51,9 @@ export default async function(ctx) {
if (typeof result.status !== 'undefined') return result;
return { status: 200, ...result };
}
export { __invoke as main, __invoke as handler };
export default __invoke;
`, string(codeJSON))
var buf bytes.Buffer