lambda-live-debugger 1.0.3 → 1.0.5
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 +2 -0
- package/dist/configuration/getConfigFromCliArgs.mjs +2 -0
- package/dist/configuration/getConfigFromWizard.mjs +22 -4
- package/dist/configuration.mjs +1 -1
- package/dist/extension/extension.zip +0 -0
- package/dist/frameworks/cdkFramework.mjs +2 -1
- package/dist/frameworks/iFrameworks.d.ts +1 -1
- package/dist/frameworks/samFramework.d.ts +7 -3
- package/dist/frameworks/samFramework.mjs +31 -11
- package/dist/resourceDiscovery.d.ts +1 -1
- package/dist/resourceDiscovery.mjs +5 -5
- package/dist/types/lldConfig.d.ts +12 -4
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -109,6 +109,8 @@ The configuration is saved to `lldebugger.config.ts`.
|
|
|
109
109
|
-o, --observable Observable mode
|
|
110
110
|
-i --interval <interval> Observable mode interval (default: "3000")
|
|
111
111
|
--config-env <evironment> SAM environment
|
|
112
|
+
--sam-config-file <file> SAM configuration file
|
|
113
|
+
--sam-template-file <file> SAM template file
|
|
112
114
|
--profile <profile> AWS profile to use
|
|
113
115
|
--region <region> AWS region to use
|
|
114
116
|
--role <role> AWS role to use
|
|
@@ -21,6 +21,8 @@ export async function getConfigFromCliArgs(supportedFrameworks = []) {
|
|
|
21
21
|
program.option('-o, --observable', 'Observable mode');
|
|
22
22
|
program.option('-i --interval <interval>', 'Observable mode interval', defaultObservableInterval.toString());
|
|
23
23
|
program.option('--config-env <evironment>', 'SAM environment');
|
|
24
|
+
program.option('--sam-config-file <file>', 'SAM configuration file');
|
|
25
|
+
program.option('--sam-template-file <file>', 'SAM template file');
|
|
24
26
|
program.option('--profile <profile>', 'AWS profile to use');
|
|
25
27
|
program.option('--region <region>', 'AWS region to use');
|
|
26
28
|
program.option('--role <role>', 'AWS role to use');
|
|
@@ -86,6 +86,18 @@ export async function getConfigFromWizard({ configFromCliArgs, supportedFramewor
|
|
|
86
86
|
message: 'Would you like to enter SAM environment?',
|
|
87
87
|
default: configFromCliArgs.configEnv ?? currentConfig?.configEnv,
|
|
88
88
|
},
|
|
89
|
+
{
|
|
90
|
+
type: 'input',
|
|
91
|
+
name: 'samConfigFile',
|
|
92
|
+
message: 'Would you like to enter SAM configuration file (default = samconfig.toml)?',
|
|
93
|
+
default: configFromCliArgs.samConfigFile ?? currentConfig?.samConfigFile,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: 'input',
|
|
97
|
+
name: 'samTemplateFile',
|
|
98
|
+
message: 'Would you like to enter SAM template file (default = template.yaml)?',
|
|
99
|
+
default: configFromCliArgs.samTemplateFile ?? currentConfig?.samTemplateFile,
|
|
100
|
+
},
|
|
89
101
|
]);
|
|
90
102
|
answers = { ...answers, ...samAnswers };
|
|
91
103
|
}
|
|
@@ -108,9 +120,9 @@ export async function getConfigFromWizard({ configFromCliArgs, supportedFramewor
|
|
|
108
120
|
type: 'confirm',
|
|
109
121
|
name: 'observable',
|
|
110
122
|
message: 'Do you want to use observable mode, which just sends events to the debugger and do not use the respose?',
|
|
111
|
-
default: configFromCliArgs.observable !== undefined
|
|
123
|
+
default: !!(configFromCliArgs.observable !== undefined
|
|
112
124
|
? configFromCliArgs.observable
|
|
113
|
-
: currentConfig?.observable,
|
|
125
|
+
: currentConfig?.observable),
|
|
114
126
|
},
|
|
115
127
|
]);
|
|
116
128
|
answers = { ...answers, ...answersObservable };
|
|
@@ -273,7 +285,7 @@ import { type LldConfigTs } from "lambda-live-debugger";
|
|
|
273
285
|
export default {
|
|
274
286
|
// Framework to use
|
|
275
287
|
framework: "${config.framework}",
|
|
276
|
-
// AWS CDK context
|
|
288
|
+
// AWS CDK framework context
|
|
277
289
|
context: ${config.context ? JSON.stringify(config.context) : undefined},
|
|
278
290
|
// Serverless Framework stage
|
|
279
291
|
stage: "${config.stage}",
|
|
@@ -287,8 +299,12 @@ export default {
|
|
|
287
299
|
region: "${config.region}",
|
|
288
300
|
// AWS role
|
|
289
301
|
role: "${config.role}",
|
|
290
|
-
// SAM environment
|
|
302
|
+
// SAM framework environment
|
|
291
303
|
configEnv: "${config.configEnv}",
|
|
304
|
+
// SAM framework configuration file
|
|
305
|
+
samConfigFile: "${config.samConfigFile}",
|
|
306
|
+
// SAM framework template file
|
|
307
|
+
samTemplateFile: "${config.samTemplateFile}",
|
|
292
308
|
// Observable mode
|
|
293
309
|
observable: ${config.observable},
|
|
294
310
|
// Observable mode interval
|
|
@@ -327,6 +343,8 @@ function getConfigFromAnswers(answers) {
|
|
|
327
343
|
region: answers.region,
|
|
328
344
|
role: answers.role,
|
|
329
345
|
configEnv: answers.configEnv,
|
|
346
|
+
samConfigFile: answers.samConfigFile,
|
|
347
|
+
samTemplateFile: answers.samTemplateFile,
|
|
330
348
|
observable: answers.observable,
|
|
331
349
|
interval: answers.interval !== undefined
|
|
332
350
|
? answers.interval
|
package/dist/configuration.mjs
CHANGED
|
@@ -17,7 +17,7 @@ async function readConfig() {
|
|
|
17
17
|
const supportedFrameworks = ResourceDiscovery.getSupportedFrameworksNames();
|
|
18
18
|
const configFromCliArgs = await getConfigFromCliArgs(supportedFrameworks);
|
|
19
19
|
Configuration.setConfig(configFromCliArgs); // not complete config
|
|
20
|
-
const currentFramework = await ResourceDiscovery.getCurrentFrameworkName();
|
|
20
|
+
const currentFramework = await ResourceDiscovery.getCurrentFrameworkName(configFromCliArgs);
|
|
21
21
|
Logger.setVerbose(configFromCliArgs.verbose === true);
|
|
22
22
|
const configFileName = configFromCliArgs.config || configFileDefaultName;
|
|
23
23
|
const configFromConfigFile = (await getConfigTsFromConfigFile(configFileName))
|
|
Binary file
|
|
@@ -228,9 +228,10 @@ export class CdkFramework {
|
|
|
228
228
|
banner: {
|
|
229
229
|
js: [
|
|
230
230
|
`import { createRequire as topLevelCreateRequire } from 'module';`,
|
|
231
|
+
`import.meta.url = 'file:///${dirname}/cdkFrameworkWorker.mjs';`,
|
|
231
232
|
`global.require = global.require ?? topLevelCreateRequire(import.meta.url);`,
|
|
232
233
|
`import { fileURLToPath as topLevelFileUrlToPath, URL as topLevelURL } from "url"`,
|
|
233
|
-
`global.__dirname =
|
|
234
|
+
`global.__dirname = global.__dirname ?? topLevelFileUrlToPath(new topLevelURL(".", import.meta.url))`,
|
|
234
235
|
].join('\n'),
|
|
235
236
|
},
|
|
236
237
|
}
|
|
@@ -5,8 +5,6 @@ import { LldConfigBase } from '../types/lldConfig.js';
|
|
|
5
5
|
* Support for AWS SAM framework
|
|
6
6
|
*/
|
|
7
7
|
export declare class SamFramework implements IFramework {
|
|
8
|
-
protected samConfigFile: string;
|
|
9
|
-
protected samTemplateFile: string;
|
|
10
8
|
/**
|
|
11
9
|
* Framework name
|
|
12
10
|
*/
|
|
@@ -15,7 +13,13 @@ export declare class SamFramework implements IFramework {
|
|
|
15
13
|
* Can this class handle the current project
|
|
16
14
|
* @returns
|
|
17
15
|
*/
|
|
18
|
-
canHandle(): Promise<boolean>;
|
|
16
|
+
canHandle(config: LldConfigBase): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Get configuration files
|
|
19
|
+
* @param config Configuration
|
|
20
|
+
* @returns Configuration files
|
|
21
|
+
*/
|
|
22
|
+
private getConfigFiles;
|
|
19
23
|
/**
|
|
20
24
|
* Get Lambda functions
|
|
21
25
|
* @param config Configuration
|
|
@@ -10,8 +10,6 @@ import { Logger } from '../logger.mjs';
|
|
|
10
10
|
* Support for AWS SAM framework
|
|
11
11
|
*/
|
|
12
12
|
export class SamFramework {
|
|
13
|
-
samConfigFile = 'samconfig.toml';
|
|
14
|
-
samTemplateFile = 'template.yaml';
|
|
15
13
|
/**
|
|
16
14
|
* Framework name
|
|
17
15
|
*/
|
|
@@ -22,23 +20,37 @@ export class SamFramework {
|
|
|
22
20
|
* Can this class handle the current project
|
|
23
21
|
* @returns
|
|
24
22
|
*/
|
|
25
|
-
async canHandle() {
|
|
23
|
+
async canHandle(config) {
|
|
24
|
+
const { samConfigFile, samTemplateFile } = this.getConfigFiles(config);
|
|
26
25
|
try {
|
|
27
|
-
await fs.access(
|
|
26
|
+
await fs.access(samConfigFile, constants.F_OK);
|
|
28
27
|
}
|
|
29
28
|
catch {
|
|
30
|
-
Logger.verbose(`[SAM] This is not a SAM framework project. ${
|
|
29
|
+
Logger.verbose(`[SAM] This is not a SAM framework project. ${samConfigFile} not found.`);
|
|
31
30
|
return false;
|
|
32
31
|
}
|
|
33
32
|
try {
|
|
34
|
-
await fs.access(
|
|
33
|
+
await fs.access(samTemplateFile, constants.F_OK);
|
|
35
34
|
}
|
|
36
35
|
catch {
|
|
37
|
-
Logger.verbose(`[SAM] This is not a SAM framework project. ${
|
|
36
|
+
Logger.verbose(`[SAM] This is not a SAM framework project. ${samTemplateFile} not found.`);
|
|
38
37
|
return false;
|
|
39
38
|
}
|
|
40
39
|
return true;
|
|
41
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Get configuration files
|
|
43
|
+
* @param config Configuration
|
|
44
|
+
* @returns Configuration files
|
|
45
|
+
*/
|
|
46
|
+
getConfigFiles(config) {
|
|
47
|
+
const samConfigFile = config.samConfigFile ?? 'samconfig.toml';
|
|
48
|
+
const samTemplateFile = config.samTemplateFile ?? 'template.yaml';
|
|
49
|
+
return {
|
|
50
|
+
samConfigFile: path.resolve(samConfigFile),
|
|
51
|
+
samTemplateFile: path.resolve(samTemplateFile),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
42
54
|
/**
|
|
43
55
|
* Get Lambda functions
|
|
44
56
|
* @param config Configuration
|
|
@@ -50,14 +62,22 @@ export class SamFramework {
|
|
|
50
62
|
profile: config.profile,
|
|
51
63
|
role: config.role,
|
|
52
64
|
};
|
|
65
|
+
const { samConfigFile, samTemplateFile } = this.getConfigFiles(config);
|
|
53
66
|
const environment = config.configEnv ?? 'default';
|
|
54
|
-
const samConfigContent = await fs.readFile(
|
|
55
|
-
|
|
67
|
+
const samConfigContent = await fs.readFile(samConfigFile, 'utf-8');
|
|
68
|
+
let samConfig;
|
|
69
|
+
// is toml extension
|
|
70
|
+
if (samConfigFile.endsWith('.toml')) {
|
|
71
|
+
samConfig = toml.parse(samConfigContent);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
samConfig = yaml.parse(samConfigContent);
|
|
75
|
+
}
|
|
56
76
|
const stackName = samConfig[environment]?.global?.parameters?.stack_name;
|
|
57
77
|
if (!stackName) {
|
|
58
|
-
throw new Error(`Stack name not found in ${
|
|
78
|
+
throw new Error(`Stack name not found in ${samConfigFile}`);
|
|
59
79
|
}
|
|
60
|
-
const samTemplateContent = await fs.readFile(path.resolve(
|
|
80
|
+
const samTemplateContent = await fs.readFile(path.resolve(samTemplateFile), 'utf-8');
|
|
61
81
|
const template = yaml.parse(samTemplateContent);
|
|
62
82
|
const lambdas = [];
|
|
63
83
|
// get all resources of type AWS::Serverless::Function
|
|
@@ -6,7 +6,7 @@ declare function getSupportedFrameworksNames(): string[];
|
|
|
6
6
|
/**
|
|
7
7
|
* Get the name of the current framework
|
|
8
8
|
*/
|
|
9
|
-
declare function getCurrentFrameworkName(): Promise<string | undefined>;
|
|
9
|
+
declare function getCurrentFrameworkName(config: LldConfig): Promise<string | undefined>;
|
|
10
10
|
declare function getLambdas(config: LldConfig): Promise<{
|
|
11
11
|
codePath: string;
|
|
12
12
|
functionName: string;
|
|
@@ -22,8 +22,8 @@ function getSupportedFrameworksNames() {
|
|
|
22
22
|
/**
|
|
23
23
|
* Get the name of the current framework
|
|
24
24
|
*/
|
|
25
|
-
async function getCurrentFrameworkName() {
|
|
26
|
-
const framework = await getCurrentFramework(frameworksSupported);
|
|
25
|
+
async function getCurrentFrameworkName(config) {
|
|
26
|
+
const framework = await getCurrentFramework(frameworksSupported, config);
|
|
27
27
|
return framework?.name;
|
|
28
28
|
}
|
|
29
29
|
async function getLambdas(config) {
|
|
@@ -37,7 +37,7 @@ async function getLambdas(config) {
|
|
|
37
37
|
frameworks = frameworks.filter((f) => f.name === config.framework);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
const framework = await getCurrentFramework(frameworks);
|
|
40
|
+
const framework = await getCurrentFramework(frameworks, config);
|
|
41
41
|
if (framework) {
|
|
42
42
|
Logger.verbose(`Getting resources with '${framework.name}' framework`);
|
|
43
43
|
resources = await framework.getLambdas(config);
|
|
@@ -61,10 +61,10 @@ async function getLambdas(config) {
|
|
|
61
61
|
/**
|
|
62
62
|
* Get the current framework
|
|
63
63
|
*/
|
|
64
|
-
async function getCurrentFramework(frameworks) {
|
|
64
|
+
async function getCurrentFramework(frameworks, config) {
|
|
65
65
|
let framework;
|
|
66
66
|
for (const f of frameworks) {
|
|
67
|
-
if (await f.canHandle()) {
|
|
67
|
+
if (await f.canHandle(config)) {
|
|
68
68
|
framework = f;
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
@@ -18,10 +18,6 @@ export type LldConfigBase = {
|
|
|
18
18
|
* Filter by function name
|
|
19
19
|
*/
|
|
20
20
|
function?: string;
|
|
21
|
-
/**
|
|
22
|
-
* SAM environment
|
|
23
|
-
*/
|
|
24
|
-
configEnv?: string;
|
|
25
21
|
/**
|
|
26
22
|
* Observable mode
|
|
27
23
|
* @default false
|
|
@@ -40,6 +36,18 @@ export type LldConfigBase = {
|
|
|
40
36
|
* Start debugger
|
|
41
37
|
*/
|
|
42
38
|
start?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* SAM framework cli parameter config-env
|
|
41
|
+
*/
|
|
42
|
+
configEnv?: string;
|
|
43
|
+
/**
|
|
44
|
+
* SAM framework cli parameter config-file
|
|
45
|
+
*/
|
|
46
|
+
samConfigFile?: string;
|
|
47
|
+
/**
|
|
48
|
+
* SAM framework cli parameter template-file
|
|
49
|
+
*/
|
|
50
|
+
samTemplateFile?: string;
|
|
43
51
|
/**
|
|
44
52
|
* Resources discovery function
|
|
45
53
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lambda-live-debugger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Debug Lambda functions locally like it is running in the cloud",
|
|
6
6
|
"repository": {
|
|
@@ -59,6 +59,8 @@
|
|
|
59
59
|
"test-sls-esbuild-esm-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sls-esbuild-esm.test.ts",
|
|
60
60
|
"test-sam-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sam-basic.test.ts",
|
|
61
61
|
"test-sam-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-basic.test.ts",
|
|
62
|
+
"test-sam-alt": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sam-alt.test.ts",
|
|
63
|
+
"test-sam-alt-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-alt.test.ts",
|
|
62
64
|
"test-terraform-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/terraform-basic.test.ts",
|
|
63
65
|
"test-terraform-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/terraform-basic.test.ts",
|
|
64
66
|
"docs:dev": "vitepress dev",
|
|
@@ -137,6 +139,7 @@
|
|
|
137
139
|
"test/sls-basic",
|
|
138
140
|
"test/sls-esbuild",
|
|
139
141
|
"test/sam-basic",
|
|
142
|
+
"test/sam-alt",
|
|
140
143
|
"test/terraform-basic"
|
|
141
144
|
]
|
|
142
145
|
}
|