Lines 38-78javascript
38const node_path_1 = __importStar(require("node:path"));
39const node_url_1 = require("node:url");
40const node_worker_threads_1 = require("node:worker_threads");
41// ============================================================================
42// Worker Thread Code (runs in worker context)
43// ============================================================================
44const parseHandler = (handler) => {
45 const [handlerFile, handlerMethod] = handler.split('.');
46 return [handlerFile, handlerMethod];
48const resolveHandlerPath = (codeDir, servicePath, handlerFile) => servicePath
49 ? node_path_1.default.resolve(servicePath, codeDir, handlerFile)
50 : node_path_1.default.resolve(codeDir, handlerFile);
51const loadHandlerModule = async (handlerPath) => {
53 // eslint-disable-next-line @typescript-eslint/no-require-imports
54 return require(handlerPath);
57 // Dynamic import — use Function constructor to prevent TypeScript CJS transform
58 // which would replace import() with require() that breaks with file:// URLs
59 const importModule = new Function('specifier', 'return import(specifier)');
60 const fileUrl = (0, node_url_1.pathToFileURL)(handlerPath + '.js').href;
LowEval
Package source references a known benign dynamic code generation pattern.
dist/src/stack/localStack/functionRunner.jsView on unpkg · L58 61 return importModule(fileUrl);
64const getHandlerFunction = (handlerModule, handlerMethod, handlerPath) => {
65 const handlerFn = handlerModule[handlerMethod];
66 if (typeof handlerFn !== 'function') {
67 throw new Error(`Handler "${handlerMethod}" not found or is not a function in ${handlerPath}`);
71const invokeHandler = (handlerFn, event, context) => new Promise((resolve, reject) => {
72 // Callback-style handler (3+ parameters)
73 if (handlerFn.length >= 3) {
75 handlerFn(event, context, (error, result) => {
76 return error ? reject(error) : resolve(result);