diff --git a/console/deploy/console.yaml b/console/deploy/console.yaml index 2314fcd..22aefbd 100644 --- a/console/deploy/console.yaml +++ b/console/deploy/console.yaml @@ -58,7 +58,7 @@ spec: serviceAccountName: fission-console containers: - name: console - image: naeel/fission-console:v1.3.94 + image: naeel/fission-console:v1.3.95 imagePullPolicy: Always ports: - containerPort: 8090 diff --git a/console/internal/api/package.go b/console/internal/api/package.go index c2e74aa..6010563 100644 --- a/console/internal/api/package.go +++ b/console/internal/api/package.go @@ -113,7 +113,7 @@ func decodeArchiveBytesToSource(decoded []byte) (string, error) { return "", io.ErrUnexpectedEOF } -var nodeJSWrapperPattern = regexp.MustCompile(`(?s)^const __mod = \{ exports: \{\} \};\s*\(new Function\('module', 'exports', (.+?)\)\)\(__mod, __mod\.exports\);\s*const _fn = __mod\.exports;`) +var nodeJSWrapperPattern = regexp.MustCompile(`(?s)^const __mod = \{ exports: \{\} \};\s*\(new Function\('module', 'exports', (?:'require', )?(.+?)\)\)\(__mod, __mod\.exports(?:, require)?\);\s*const _fn = __mod\.exports;`) func decodeNodeJSWrapperSource(decoded []byte) (string, bool) { text := string(decoded) diff --git a/console/internal/runtime/nodejs.go b/console/internal/runtime/nodejs.go index c01b5a9..95cebf7 100644 --- a/console/internal/runtime/nodejs.go +++ b/console/internal/runtime/nodejs.go @@ -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) { diff --git a/console/internal/runtime/nodejs_test.go b/console/internal/runtime/nodejs_test.go index 4afeda9..ea1b338 100644 --- a/console/internal/runtime/nodejs_test.go +++ b/console/internal/runtime/nodejs_test.go @@ -33,18 +33,20 @@ func TestBuildJSDeployZipExportsMainAndHandler(t *testing.T) { files[file.Name] = string(content) } - if files["package.json"] != `{"type":"module"}` { - t.Fatalf("package.json = %q, want ESM marker", files["package.json"]) - } - mainJS := files["main.js"] - if !strings.Contains(mainJS, `export { __invoke as main, __invoke as handler };`) { - t.Fatalf("main.js does not export both main and handler: %s", mainJS) + if mainJS == "" { + t.Fatalf("main.js not found in zip, files: %v", files) } - if !strings.Contains(mainJS, `export default __invoke;`) { - t.Fatalf("main.js does not export default invoke: %s", mainJS) + if !strings.Contains(mainJS, `new Function('module', 'exports', 'require',`) { + t.Fatalf("main.js does not pass require to new Function: %s", mainJS) + } + if !strings.Contains(mainJS, `__mod.exports, require)`) { + t.Fatalf("main.js does not forward require: %s", mainJS) + } + if !strings.Contains(mainJS, `module.exports = __invoke`) { + t.Fatalf("main.js does not export __invoke via module.exports: %s", mainJS) } if !strings.Contains(mainJS, `_fn.default || _fn.handler || _fn.main`) { t.Fatalf("main.js lost user export resolution: %s", mainJS) } -} \ No newline at end of file +} diff --git a/console/ui/index.html b/console/ui/index.html index b35e6d7..3760974 100644 --- a/console/ui/index.html +++ b/console/ui/index.html @@ -103,7 +103,7 @@
NUBES
FISSION CONSOLE
-
v1.3.94
+
v1.3.95
@@ -626,7 +626,7 @@ psycopg2-binary" style="width:100%; box-sizing:border-box; font-family:monospace
- v1.3.94 + v1.3.95