From 07502aeaae00182f62e3118be5bb352b395238b5 Mon Sep 17 00:00:00 2001 From: Ian Mark Muninio Date: Mon, 5 Feb 2024 19:00:41 +0800 Subject: [PATCH] Added support for nested property handler resolution for nodejs. --- checks/handler_check.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/checks/handler_check.go b/checks/handler_check.go index 49dddcce..364d1a48 100644 --- a/checks/handler_check.go +++ b/checks/handler_check.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "path/filepath" "strings" "github.com/newrelic/newrelic-lambda-extension/config" @@ -35,8 +36,8 @@ func handlerCheck(ctx context.Context, conf *config.Configuration, reg *api.Regi func (r runtimeConfig) check(h handlerConfigs) bool { functionHandler := r.getTrueHandler(h) - p := removePathMethodName(functionHandler) if r.language == Node { + p := removePathMethodNameNode(functionHandler) pJS := pathFormatter(p, "js") cJS := pathFormatter(p, "cjs") pMJS := pathFormatter(p, "mjs") @@ -45,6 +46,7 @@ func (r runtimeConfig) check(h handlerConfigs) bool { return true } } else { + p := removePathMethodName(functionHandler) p = pathFormatter(p, r.fileType) } return util.PathExists(p) @@ -74,6 +76,16 @@ func removePathMethodName(p string) string { return strings.Join(s[:len(s)-1], "/") } +func removePathMethodNameNode(p string) string { + mh := filepath.Base(p) + mr := p[0:strings.Index(p, mh)] + + s := strings.Split(mh, ".") + m := s[0] + + return filepath.Join(mr, m) +} + func pathFormatter(functionHandler string, fileType string) string { p := fmt.Sprintf("%s/%s.%s", handlerPath, functionHandler, fileType) return p