lambda-live-debugger 0.0.111 → 0.0.113
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.
- package/README.md +96 -10
- package/dist/configuration.mjs +1 -1
- package/dist/extension/extension.zip +0 -0
- package/dist/frameworks/cdkFramework.d.ts +26 -5
- package/dist/frameworks/cdkFramework.mjs +54 -33
- package/dist/frameworks/cdkFrameworkWorker.mjs +5 -1
- package/dist/frameworks/terraformFramework.d.ts +3 -2
- package/dist/frameworks/terraformFramework.mjs +3 -2
- package/dist/index.d.ts +4 -3
- package/dist/types/lldConfig.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,15 +146,6 @@ export default {
|
|
|
146
146
|
|
|
147
147
|
The setting are the same as for CLI parameters.
|
|
148
148
|
|
|
149
|
-
### Custom framework implementation and adjustment
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
getLambdas: async (foundLambdas) => {
|
|
153
|
-
//you can customize the list of lambdas here or create your own
|
|
154
|
-
//return foundLambdas;
|
|
155
|
-
},
|
|
156
|
-
```
|
|
157
|
-
|
|
158
149
|
### Debugging
|
|
159
150
|
|
|
160
151
|
You might want to configure your development tool for debugging. The wizard automatically configures for VsCode in `.vscode/launch.json`. Here is an example:
|
|
@@ -221,6 +212,101 @@ Only the basic setup is supported. Check the [test case](https://github.com/Serv
|
|
|
221
212
|
|
|
222
213
|
I am not a Terraform developer, so I only know the basics. Please provide a sample project so I can build better support.
|
|
223
214
|
|
|
215
|
+
### Custom framework implementation and adjustment
|
|
216
|
+
|
|
217
|
+
Configuration file `lldebugger.config.ts` enables you to modify the list of Lambdas, change the code path, esBuild configuration, or provide your own list of Lambdas, thereby supporting support **any framework**. For this to work, install Lambda Live Debugger locally in the project.
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
getLambdas: async (foundLambdas, config) => {
|
|
221
|
+
//you can customize the list of lambdas here or create your own
|
|
222
|
+
return foundLambdas;
|
|
223
|
+
},
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**Filter list of functions:**
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
getLambdas: async (foundLambdas, config) => {
|
|
230
|
+
return foundLambdas?.filter((l) =>
|
|
231
|
+
l.functionName.includes("myfunction"),
|
|
232
|
+
);
|
|
233
|
+
},
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Modify code path:**\
|
|
237
|
+
For example, when the framework has only a list of JavaScript files, but you transpiled them from TypeScript with your own solution.
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
getLambdas: async (foundLambdas, config) => {
|
|
241
|
+
if (foundLambdas) {
|
|
242
|
+
for (const lambda of foundLambdas) {
|
|
243
|
+
lambda.codePath = lambda.codePath
|
|
244
|
+
.replace("/dist/", "/src/")
|
|
245
|
+
.replace(".js", ".ts");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Modfiy esBuild configuration:**
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { type EsBuildOptions, type LldConfigTs } from "lambda-live-debugger";
|
|
255
|
+
|
|
256
|
+
export default {
|
|
257
|
+
...
|
|
258
|
+
getLambdas: async (foundLambdas, config) => {
|
|
259
|
+
if (foundLambdas) {
|
|
260
|
+
for (const lambda of foundLambdas) {
|
|
261
|
+
lambda.esBuildOptions = {
|
|
262
|
+
target: "node14",
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
} satisfies LldConfigTs;
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Provide your own list of Lambdas and support any framework**:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
export default {
|
|
274
|
+
//framework: <-- you do not need this line
|
|
275
|
+
...
|
|
276
|
+
getLambdas: async (foundLambdas, config) => {
|
|
277
|
+
return [
|
|
278
|
+
{
|
|
279
|
+
// function name as deployed on AWS
|
|
280
|
+
functionName: "mystack-myfunction",
|
|
281
|
+
codePath: "/src/myLambda.ts",
|
|
282
|
+
},
|
|
283
|
+
];
|
|
284
|
+
},
|
|
285
|
+
} satisfies LldConfigTs;
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**Modify existing framework support:**
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import { CdkFramework, type LldConfigBase, type LldConfigTs } from "lambda-live-debugger";
|
|
292
|
+
|
|
293
|
+
class MyCdkFramework extends CdkFramework {
|
|
294
|
+
override getCdkContext(
|
|
295
|
+
cdkConfigPath: string,
|
|
296
|
+
config: LldConfigBase,
|
|
297
|
+
) {
|
|
298
|
+
// your implementation
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export default {
|
|
303
|
+
...
|
|
304
|
+
getLambdas: async (foundLambdas, config) => {
|
|
305
|
+
return new MyCdkFramework().getLambdas(config);
|
|
306
|
+
}
|
|
307
|
+
} satisfies LldConfigTs;s
|
|
308
|
+
```
|
|
309
|
+
|
|
224
310
|
## Know issues
|
|
225
311
|
|
|
226
312
|
Check the [GitHub issues](https://github.com/ServerlessLife/lambda-live-debugger/issues).
|
|
@@ -235,7 +321,7 @@ Check the [GitHub issues](https://github.com/ServerlessLife/lambda-live-debugger
|
|
|
235
321
|
- Use descriptive titles with prefixes like "bug:", "help:", "feature:", or "discussion:".
|
|
236
322
|
- Enable verbose logging and provide the full log.
|
|
237
323
|
- Describe your setup in detail, or better yet, provide a sample project.
|
|
238
|
-
- Specify exact framework version (CDK, SLS, SAM ...) and exact
|
|
324
|
+
- Specify the exact framework version (CDK, SLS, SAM ...) and the exact Lambda Live Debugger version.
|
|
239
325
|
|
|
240
326
|
## Authors:
|
|
241
327
|
|
package/dist/configuration.mjs
CHANGED
|
@@ -118,7 +118,7 @@ async function discoverLambdas() {
|
|
|
118
118
|
noFramework = true;
|
|
119
119
|
}
|
|
120
120
|
if (config.getLambdas) {
|
|
121
|
-
lambdasListNew = await config.getLambdas(lambdasListNew);
|
|
121
|
+
lambdasListNew = await config.getLambdas(lambdasListNew, config);
|
|
122
122
|
}
|
|
123
123
|
if (!lambdasListNew) {
|
|
124
124
|
if (noFramework) {
|
|
Binary file
|
|
@@ -2,6 +2,7 @@ import { LambdaResource } from "../types/resourcesDiscovery.js";
|
|
|
2
2
|
import { IFramework } from "./iFrameworks.js";
|
|
3
3
|
import { AwsConfiguration } from "../types/awsConfiguration.js";
|
|
4
4
|
import { LldConfigBase } from "../types/lldConfig.js";
|
|
5
|
+
import { type BundlingOptions } from "aws-cdk-lib/aws-lambda-nodejs";
|
|
5
6
|
/**
|
|
6
7
|
* Support for AWS CDK framework
|
|
7
8
|
*/
|
|
@@ -38,12 +39,32 @@ export declare class CdkFramework implements IFramework {
|
|
|
38
39
|
* @returns
|
|
39
40
|
*/
|
|
40
41
|
protected getLambdasDataFromCdkByCompilingAndRunning(cdkConfigPath: string, config: LldConfigBase): Promise<{
|
|
41
|
-
cdkPath:
|
|
42
|
-
stackName:
|
|
42
|
+
cdkPath: string;
|
|
43
|
+
stackName: string;
|
|
43
44
|
packageJsonPath: string | undefined;
|
|
44
|
-
codePath:
|
|
45
|
-
handler:
|
|
46
|
-
bundling:
|
|
45
|
+
codePath: string;
|
|
46
|
+
handler: string | undefined;
|
|
47
|
+
bundling: BundlingOptions;
|
|
48
|
+
}[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Run CDK code in a node thread worker and return the Lambda functions
|
|
51
|
+
* @param param0
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
protected runCdkCodeAndReturnLambdas({ config, awsCdkLibPath, compileCodeFile, }: {
|
|
55
|
+
config: LldConfigBase;
|
|
56
|
+
awsCdkLibPath: string | undefined;
|
|
57
|
+
compileCodeFile: string;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
cdkPath: string;
|
|
60
|
+
stackName: string;
|
|
61
|
+
codePath?: string | undefined;
|
|
62
|
+
code: {
|
|
63
|
+
path?: string;
|
|
64
|
+
};
|
|
65
|
+
handler: string;
|
|
66
|
+
packageJsonPath: string;
|
|
67
|
+
bundling: BundlingOptions;
|
|
47
68
|
}[]>;
|
|
48
69
|
/**
|
|
49
70
|
* Get CDK context
|
|
@@ -8,7 +8,6 @@ import { CloudFormation } from "../cloudFormation.mjs";
|
|
|
8
8
|
import { Logger } from "../logger.mjs";
|
|
9
9
|
import { Worker } from "node:worker_threads";
|
|
10
10
|
import { getModuleDirname, getProjectDirname } from "../getDirname.mjs";
|
|
11
|
-
import { Configuration } from "../configuration.mjs";
|
|
12
11
|
import { findNpmPath } from "../utils/findNpmPath.mjs";
|
|
13
12
|
/**
|
|
14
13
|
* Support for AWS CDK framework
|
|
@@ -219,34 +218,11 @@ export class CdkFramework {
|
|
|
219
218
|
Logger.verbose(`[CDK] Context:`, JSON.stringify(CDK_CONTEXT_JSON, null, 2));
|
|
220
219
|
const awsCdkLibPath = await findNpmPath(path.join(getProjectDirname(), config.subfolder ?? "/"), "aws-cdk-lib");
|
|
221
220
|
Logger.verbose(`[CDK] aws-cdk-lib path: ${awsCdkLibPath}`);
|
|
222
|
-
const lambdas = await
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
awsCdkLibPath,
|
|
227
|
-
projectDirname: getProjectDirname(),
|
|
228
|
-
moduleDirname: getModuleDirname(),
|
|
229
|
-
},
|
|
230
|
-
});
|
|
231
|
-
worker.on("message", async (message) => {
|
|
232
|
-
resolve(message);
|
|
233
|
-
await worker.terminate();
|
|
234
|
-
});
|
|
235
|
-
worker.on("error", (error) => {
|
|
236
|
-
reject(new Error(`Error running CDK code in worker: ${error.message}`, {
|
|
237
|
-
cause: error,
|
|
238
|
-
}));
|
|
239
|
-
});
|
|
240
|
-
worker.on("exit", (code) => {
|
|
241
|
-
if (code !== 0) {
|
|
242
|
-
reject(new Error(`CDK worker stopped with exit code ${code}`));
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
worker.postMessage({
|
|
246
|
-
compileOutput,
|
|
247
|
-
});
|
|
221
|
+
const lambdas = await this.runCdkCodeAndReturnLambdas({
|
|
222
|
+
config,
|
|
223
|
+
awsCdkLibPath,
|
|
224
|
+
compileCodeFile: compileOutput,
|
|
248
225
|
});
|
|
249
|
-
Logger.verbose(`[CDK] Found the following Lambda functions in the CDK code:`, JSON.stringify(lambdas, null, 2));
|
|
250
226
|
const list = await Promise.all(lambdas.map(async (lambda) => {
|
|
251
227
|
// handler slit into file and file name
|
|
252
228
|
const handlerSplit = lambda.handler.split(".");
|
|
@@ -254,11 +230,19 @@ export class CdkFramework {
|
|
|
254
230
|
const filename = handlerSplit[0];
|
|
255
231
|
let codePath = lambda.codePath;
|
|
256
232
|
if (!codePath) {
|
|
257
|
-
const codePathJs =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
233
|
+
const codePathJs = lambda.code?.path
|
|
234
|
+
? path.join(lambda.code.path, `${filename}.js`)
|
|
235
|
+
: undefined;
|
|
236
|
+
const codePathCjs = lambda.code?.path
|
|
237
|
+
? path.join(lambda.code.path, `${filename}.cjs`)
|
|
238
|
+
: undefined;
|
|
239
|
+
const codePathMjs = lambda.code?.path
|
|
240
|
+
? path.join(lambda.code.path, `${filename}.mjs`)
|
|
241
|
+
: undefined;
|
|
242
|
+
// get the first file that exists
|
|
243
|
+
codePath = [codePathJs, codePathCjs, codePathMjs]
|
|
244
|
+
.filter((c) => c)
|
|
245
|
+
.find((file) => fs
|
|
262
246
|
.access(file)
|
|
263
247
|
.then(() => true)
|
|
264
248
|
.catch(() => false));
|
|
@@ -279,6 +263,43 @@ export class CdkFramework {
|
|
|
279
263
|
}));
|
|
280
264
|
return list;
|
|
281
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Run CDK code in a node thread worker and return the Lambda functions
|
|
268
|
+
* @param param0
|
|
269
|
+
* @returns
|
|
270
|
+
*/
|
|
271
|
+
async runCdkCodeAndReturnLambdas({ config, awsCdkLibPath, compileCodeFile, }) {
|
|
272
|
+
const lambdas = await new Promise((resolve, reject) => {
|
|
273
|
+
const worker = new Worker(path.resolve(path.join(getModuleDirname(), "frameworks/cdkFrameworkWorker.mjs")), {
|
|
274
|
+
workerData: {
|
|
275
|
+
verbose: config.verbose,
|
|
276
|
+
awsCdkLibPath,
|
|
277
|
+
projectDirname: getProjectDirname(),
|
|
278
|
+
moduleDirname: getModuleDirname(),
|
|
279
|
+
subfolder: config.subfolder,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
worker.on("message", async (message) => {
|
|
283
|
+
resolve(message);
|
|
284
|
+
await worker.terminate();
|
|
285
|
+
});
|
|
286
|
+
worker.on("error", (error) => {
|
|
287
|
+
reject(new Error(`Error running CDK code in worker: ${error.message}`, {
|
|
288
|
+
cause: error,
|
|
289
|
+
}));
|
|
290
|
+
});
|
|
291
|
+
worker.on("exit", (code) => {
|
|
292
|
+
if (code !== 0) {
|
|
293
|
+
reject(new Error(`CDK worker stopped with exit code ${code}`));
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
worker.postMessage({
|
|
297
|
+
compileOutput: compileCodeFile,
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
Logger.verbose(`[CDK] Found the following Lambda functions in the CDK code:`, JSON.stringify(lambdas, null, 2));
|
|
301
|
+
return lambdas;
|
|
302
|
+
}
|
|
282
303
|
/**
|
|
283
304
|
* Get CDK context
|
|
284
305
|
* @param cdkConfigPath
|
|
@@ -10,7 +10,11 @@ import { Logger } from "../logger.mjs";
|
|
|
10
10
|
|
|
11
11
|
Logger.setVerbose(workerData.verbose);
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
-
const __dirname = path.resolve(
|
|
13
|
+
const __dirname = path.resolve(
|
|
14
|
+
path.join(
|
|
15
|
+
...[workerData.projectDirname, workerData.subfolder, "x"].filter((p) => p),
|
|
16
|
+
),
|
|
17
|
+
);
|
|
14
18
|
|
|
15
19
|
Logger.verbose(`[CDK] [Worker] Started`);
|
|
16
20
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { LambdaResource } from "../types/resourcesDiscovery.js";
|
|
3
3
|
import { exec } from "child_process";
|
|
4
4
|
import { IFramework } from "./iFrameworks.js";
|
|
5
|
+
import { LldConfigBase } from "../types/lldConfig.js";
|
|
5
6
|
export declare const execAsync: typeof exec.__promisify__;
|
|
6
7
|
interface TerraformState {
|
|
7
8
|
resources: Array<{
|
|
@@ -31,10 +32,10 @@ export declare class TerraformFramework implements IFramework {
|
|
|
31
32
|
canHandle(): Promise<boolean>;
|
|
32
33
|
/**
|
|
33
34
|
* Get Lambda functions
|
|
34
|
-
* @param
|
|
35
|
+
* @param _config Configuration
|
|
35
36
|
* @returns Lambda functions
|
|
36
37
|
*/
|
|
37
|
-
getLambdas(): Promise<LambdaResource[]>;
|
|
38
|
+
getLambdas(config: LldConfigBase): Promise<LambdaResource[]>;
|
|
38
39
|
protected extractLambdaInfo(state: TerraformState): {
|
|
39
40
|
functionName: string;
|
|
40
41
|
sourceDir?: string | undefined;
|
|
@@ -32,10 +32,11 @@ export class TerraformFramework {
|
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Get Lambda functions
|
|
35
|
-
* @param
|
|
35
|
+
* @param _config Configuration
|
|
36
36
|
* @returns Lambda functions
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
async getLambdas(config) {
|
|
39
40
|
const state = await this.readTerraformState();
|
|
40
41
|
const lambdas = this.extractLambdaInfo(state);
|
|
41
42
|
Logger.verbose("[Terraform] Found Lambdas:", JSON.stringify(lambdas, null, 2));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { type LldConfigTs } from "./types/lldConfig.js";
|
|
2
|
-
export type { EsBuildOptions, BundlingType, LambdaResource
|
|
1
|
+
export { type LldConfigTs, type LldConfigBase } from "./types/lldConfig.js";
|
|
2
|
+
export type { EsBuildOptions, BundlingType, LambdaResource, } from "./types/resourcesDiscovery.js";
|
|
3
3
|
export { CdkFramework } from "./frameworks/cdkFramework.js";
|
|
4
4
|
export { SlsFramework } from "./frameworks/slsFramework.js";
|
|
5
5
|
export { SamFramework } from "./frameworks/samFramework.js";
|
|
6
6
|
export { TerraformFramework } from "./frameworks/terraformFramework.js";
|
|
7
|
-
export type
|
|
7
|
+
export { type IFramework } from "./frameworks/iFrameworks.js";
|
|
8
|
+
export { type AwsConfiguration } from "./types/awsConfiguration.js";
|
|
@@ -43,7 +43,7 @@ export type LldConfigBase = {
|
|
|
43
43
|
/**
|
|
44
44
|
* Resources discovery function
|
|
45
45
|
*/
|
|
46
|
-
getLambdas?: (foundFunctions?: LambdaResource[]) => Promise<LambdaResource[] | undefined>;
|
|
46
|
+
getLambdas?: (foundFunctions?: LambdaResource[], config?: LldConfigBase) => Promise<LambdaResource[] | undefined>;
|
|
47
47
|
/**
|
|
48
48
|
* Monorepo subfolder
|
|
49
49
|
*/
|