lambda-live-debugger 0.0.102 → 0.0.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
|
@@ -9,6 +9,7 @@ import { Logger } from "../logger.mjs";
|
|
|
9
9
|
import { Worker } from "node:worker_threads";
|
|
10
10
|
import { getModuleDirname, getProjectDirname } from "../getDirname.mjs";
|
|
11
11
|
import { Configuration } from "../configuration.mjs";
|
|
12
|
+
import { findNpmPath } from "../utils/findNpmPath.mjs";
|
|
12
13
|
/**
|
|
13
14
|
* Support for AWS CDK framework
|
|
14
15
|
*/
|
|
@@ -216,10 +217,13 @@ export class CdkFramework {
|
|
|
216
217
|
};
|
|
217
218
|
process.env.CDK_CONTEXT_JSON = JSON.stringify(CDK_CONTEXT_JSON);
|
|
218
219
|
Logger.verbose(`[CDK] Context:`, JSON.stringify(CDK_CONTEXT_JSON, null, 2));
|
|
220
|
+
const awsCdkLibPath = await findNpmPath(path.join(getProjectDirname(), config.subfolder ?? "/"), "aws-cdk-lib");
|
|
221
|
+
Logger.verbose(`[CDK] aws-cdk-lib path: ${awsCdkLibPath}`);
|
|
219
222
|
const lambdas = await new Promise((resolve, reject) => {
|
|
220
223
|
const worker = new Worker(path.resolve(path.join(getModuleDirname(), "frameworks/cdkFrameworkWorker.mjs")), {
|
|
221
224
|
workerData: {
|
|
222
225
|
verbose: Configuration.config.verbose,
|
|
226
|
+
awsCdkLibPath,
|
|
223
227
|
},
|
|
224
228
|
});
|
|
225
229
|
worker.on("message", (message) => {
|
|
@@ -22,7 +22,7 @@ parentPort.on("message", async (data) => {
|
|
|
22
22
|
// execute code to get the data into global.lambdas
|
|
23
23
|
const codeFile = await fs.readFile(data.compileOutput, "utf8");
|
|
24
24
|
|
|
25
|
-
fixCdkPaths();
|
|
25
|
+
await fixCdkPaths(workerData.awsCdkLibPath);
|
|
26
26
|
|
|
27
27
|
eval(codeFile);
|
|
28
28
|
|
|
@@ -54,12 +54,11 @@ parentPort.on("message", async (data) => {
|
|
|
54
54
|
/**
|
|
55
55
|
* Some paths are not resolved correctly in the CDK code, so we need to fix them
|
|
56
56
|
*/
|
|
57
|
-
function fixCdkPaths() {
|
|
58
|
-
//
|
|
57
|
+
async function fixCdkPaths(awsCdkLibPath) {
|
|
58
|
+
// leave this lines for manual debugging
|
|
59
|
+
//const awsCdkLibPath = path.resolve("node_modules/aws-cdk-lib");
|
|
60
|
+
//const path = require("path");
|
|
59
61
|
|
|
60
|
-
// Get the path to the aws-cdk-lib module
|
|
61
|
-
let awsCdkLibPath = require.resolve("aws-cdk-lib");
|
|
62
|
-
awsCdkLibPath = awsCdkLibPath.replace("/index.js", "");
|
|
63
62
|
Logger.verbose(`[CDK] [Worker] aws-cdk-lib PATH ${awsCdkLibPath}`);
|
|
64
63
|
|
|
65
64
|
const pathsFix = {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
/**
|
|
4
|
+
* Function to find the path of a module in the directory and parent directories
|
|
5
|
+
* @param {*} dir
|
|
6
|
+
* @param {*} moduleName
|
|
7
|
+
*/
|
|
8
|
+
export async function findNpmPath(dir, moduleName) {
|
|
9
|
+
if (dir === "/")
|
|
10
|
+
return undefined;
|
|
11
|
+
try {
|
|
12
|
+
await fs.access(path.join(dir, "package.json"));
|
|
13
|
+
const modulePath = await checkModuleInPackageJson(dir, moduleName);
|
|
14
|
+
if (modulePath) {
|
|
15
|
+
return modulePath;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// ignore, no package.json in this directory
|
|
20
|
+
}
|
|
21
|
+
return await findNpmPath(path.resolve(path.join(dir, "..")), moduleName);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Function to check if a module exists in package.json and return the path
|
|
25
|
+
* @param {*} dir
|
|
26
|
+
* @param {*} moduleName
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
async function checkModuleInPackageJson(dir, moduleName) {
|
|
30
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
31
|
+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
|
|
32
|
+
const dependencies = packageJson.dependencies || {};
|
|
33
|
+
const devDependencies = packageJson.devDependencies || {};
|
|
34
|
+
if (dependencies[moduleName] || devDependencies[moduleName]) {
|
|
35
|
+
const modulePath = path.join(dir, "node_modules", moduleName);
|
|
36
|
+
try {
|
|
37
|
+
await fs.access(modulePath);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return modulePath;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|