lambda-live-debugger 0.0.94 → 0.0.96

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Lambda Live Debugger is an indispensable tool for debugging AWS Lambda functions from your computer, even though they are deployed in the cloud. It supports Lambdas written in JavaScript or TypeScript.
6
6
 
7
- This tool offers similar functionality to [SST](https://sst.dev/) and [Serverless Framework v4](https://www.serverless.com/blog/serverless-framework-v4-general-availability), with the addition of an Observability mode.
7
+ This tool offers similar functionality to [SST](https://sst.dev/) and [Serverless Framework v4](https://www.serverless.com/blog/serverless-framework-v4-general-availability), with the addition of an Observability Mode.
8
8
 
9
9
  It supports the following frameworks:
10
10
 
@@ -202,7 +202,7 @@ Check the [open issues](https://github.com/ServerlessLife/lambda-live-debugger/i
202
202
 
203
203
  ## Authors:
204
204
 
205
- - [Marko (ServerlessLife)](https://github.com/ServerlessLife)
205
+ - [Marko (ServerlessLife)](https://www.serverlesslife.com/)
206
206
  - ⭐ Your name here for big code contributions
207
207
 
208
208
  ## Contributors (alphabetical)
@@ -6,6 +6,7 @@ import { ResourceDiscovery } from "../resourceDiscovery.mjs";
6
6
  import { GitIgnore } from "../gitignore.mjs";
7
7
  import { VsCode } from "../vsCode.mjs";
8
8
  import { Logger } from "../logger.mjs";
9
+ import { Configuration } from "../configuration.mjs";
9
10
  const configFileName = path.resolve(configFileDefaultName);
10
11
  /**
11
12
  * Get configuration from wizard
@@ -18,7 +19,7 @@ export async function getConfigFromWizard({ supportedFrameworks, currentFramewor
18
19
  {
19
20
  type: "list",
20
21
  name: "framework",
21
- message: `Which framework are you using (detected ${currentFramework})?`,
22
+ message: `Which framework are you using (detected: ${currentFramework ?? "?"})?`,
22
23
  choices: supportedFrameworks,
23
24
  default: currentConfig?.framework ?? currentFramework,
24
25
  },
@@ -156,6 +157,9 @@ export async function getConfigFromWizard({ supportedFrameworks, currentFramewor
156
157
  },
157
158
  ]);
158
159
  if (answersFilter.function === "Pick one") {
160
+ // I need to use congiration settings I accquired so far to get the list of lambdas
161
+ const configTemp = getConfigFromAnswers(answers);
162
+ Configuration.setConfig(configTemp); // not complete config
159
163
  lambdasList = await ResourceDiscovery.getLambdas(getConfigFromAnswers(answers));
160
164
  if (!lambdasList) {
161
165
  throw new Error("No Lambdas found");
@@ -219,6 +223,15 @@ export async function getConfigFromWizard({ supportedFrameworks, currentFramewor
219
223
  ]);
220
224
  answers.vscode = answersVsCode.vscode;
221
225
  }
226
+ const answersVerbose = await inquirer.prompt([
227
+ {
228
+ type: "confirm",
229
+ name: "verbose",
230
+ message: "Do you want to use verbose logging? This will log all events to the console.",
231
+ default: currentConfig?.verbose === true,
232
+ },
233
+ ]);
234
+ answers.verbose = answersVerbose.verbose;
222
235
  }
223
236
  /*
224
237
  {
@@ -231,9 +244,14 @@ export async function getConfigFromWizard({ supportedFrameworks, currentFramewor
231
244
  */
232
245
  const config = getConfigFromAnswers(answers);
233
246
  if (save) {
234
- // save to file that looks like this:
235
- Logger.log("Saving to config file");
236
- const configContent = `
247
+ await saveConfiguration(config);
248
+ }
249
+ return config;
250
+ }
251
+ async function saveConfiguration(config) {
252
+ Logger.log(`Saving to config file ${configFileName}`);
253
+ // save to file that looks like this:
254
+ const configContent = `
237
255
  import { type LldConfigTs } from "lambda-live-debugger";
238
256
 
239
257
  export default {
@@ -255,15 +273,13 @@ export default {
255
273
  //},
256
274
  } satisfies LldConfigTs;
257
275
  `;
258
- // remove lines that contains undefined or ""
259
- const configContentCleaned = configContent
260
- .trim()
261
- .split("\n")
262
- .filter((l) => !l.includes("undefined") && !l.includes('""'))
263
- .join("\n");
264
- await fs.writeFile(configFileName, configContentCleaned);
265
- }
266
- return config;
276
+ // remove lines that contains undefined or ""
277
+ const configContentCleaned = configContent
278
+ .trim()
279
+ .split("\n")
280
+ .filter((l) => !l.includes("undefined") && !l.includes('""'))
281
+ .join("\n");
282
+ await fs.writeFile(configFileName, configContentCleaned);
267
283
  }
268
284
  function getConfigFromAnswers(answers) {
269
285
  const config = {
@@ -281,7 +297,7 @@ function getConfigFromAnswers(answers) {
281
297
  interval: answers.interval !== undefined
282
298
  ? answers.interval
283
299
  : defaultObservableInterval,
284
- verbose: false,
300
+ verbose: answers.verbose,
285
301
  interactive: answers.interactive,
286
302
  gitignore: answers.gitignore,
287
303
  vscode: answers.vscode,
@@ -19,11 +19,17 @@ declare function getLambdas(): LambdaProps[];
19
19
  * Discover Lambdas
20
20
  */
21
21
  declare function discoverLambdas(): Promise<void>;
22
+ /**
23
+ * Set the configuration
24
+ * @param newConfig
25
+ */
26
+ declare function setConfig(newConfig: LldConfig): void;
22
27
  export declare const Configuration: {
23
28
  readConfig: typeof readConfig;
24
29
  readonly config: LldConfig;
25
30
  discoverLambdas: typeof discoverLambdas;
26
31
  getLambda: typeof getLambda;
27
32
  getLambdas: typeof getLambdas;
33
+ setConfig: typeof setConfig;
28
34
  };
29
35
  export {};
@@ -17,6 +17,7 @@ async function readConfig() {
17
17
  const supportedFrameworks = ResourceDiscovery.getSupportedFrameworksNames();
18
18
  const currentFramework = await ResourceDiscovery.getCurrentFrameworkName();
19
19
  const configFromCliArgs = await getConfigFromCliArgs(supportedFrameworks);
20
+ Logger.setVerbose(configFromCliArgs.verbose === true);
20
21
  const configFileName = configFromCliArgs.config || configFileDefaultName;
21
22
  const configFromConfigFile = (await getConfigTsFromConfigFile(configFileName))
22
23
  ?.default;
@@ -27,20 +28,20 @@ async function readConfig() {
27
28
  currentConfig: configFromConfigFile,
28
29
  });
29
30
  const debuggerId = await generateDebuggerId(!!configFromWizard.observable);
30
- config = {
31
+ setConfig({
31
32
  ...configFromWizard,
32
33
  debuggerId,
33
34
  start: false, // don't start the debugger after the wizard
34
- };
35
+ });
35
36
  }
36
37
  else {
37
38
  const configMerged = { ...configFromCliArgs, ...configFromConfigFile };
38
39
  const debuggerId = await generateDebuggerId(!!configMerged.observable);
39
- config = {
40
+ setConfig({
40
41
  ...configMerged,
41
42
  debuggerId,
42
43
  start: true,
43
- };
44
+ });
44
45
  }
45
46
  }
46
47
  /**
@@ -133,6 +134,13 @@ function saveDiscoveredLambdas(lambdasListNew) {
133
134
  .join("\n - ")}`);
134
135
  }
135
136
  }
137
+ /**
138
+ * Set the configuration
139
+ * @param newConfig
140
+ */
141
+ function setConfig(newConfig) {
142
+ config = newConfig;
143
+ }
136
144
  export const Configuration = {
137
145
  readConfig,
138
146
  get config() {
@@ -144,4 +152,5 @@ export const Configuration = {
144
152
  discoverLambdas,
145
153
  getLambda,
146
154
  getLambdas,
155
+ setConfig,
147
156
  };
Binary file
@@ -18,7 +18,7 @@ parentPort.on("message", async (data) => {
18
18
 
19
19
  // execute code to get the data into global.lambdas
20
20
  const codeFile = await fs.readFile(data.compileOutput, "utf8");
21
- const __dirname = path.resolve("./node_modules/aws-cdk-lib/x/x"); // CDK needs this, pure magic
21
+ const __dirname = path.resolve("./x"); // CDK needs this, pure magic
22
22
  eval(codeFile);
23
23
 
24
24
  if (global.lambdas.length === 0) {
@@ -63,7 +63,7 @@ async function onMessageFromLambda(message) {
63
63
  else {
64
64
  // first 50 characters of the response
65
65
  const requestPretty = message.data
66
- ? JSON.stringify(message.data).substring(0, 50)
66
+ ? JSON.stringify(message.data).substring(0, 100)
67
67
  : "";
68
68
  Logger.log(`${message.data.functionId} request: ${requestPretty}${requestPretty.length < 50 ? "" : "..."}`);
69
69
  }
@@ -74,7 +74,7 @@ async function onMessageFromLambda(message) {
74
74
  else {
75
75
  // first 50 characters of the response
76
76
  const responsePretty = response
77
- ? JSON.stringify(response).substring(0, 50)
77
+ ? JSON.stringify(response).substring(0, 100)
78
78
  : "";
79
79
  Logger.log(`${message.data.functionId} response: ${responsePretty}${responsePretty.length < 50 ? "" : "..."}`);
80
80
  }
@@ -24,7 +24,7 @@ async function run() {
24
24
  const version = await getVersion();
25
25
  await Configuration.readConfig();
26
26
  Logger.setVerbose(Configuration.config.verbose === true);
27
- Logger.verbose(`Parameters: \n ${Object.entries(Configuration.config)
27
+ Logger.verbose(`Parameters: \n${Object.entries(Configuration.config)
28
28
  .map(([key, value]) => ` - ${key}=${value}`)
29
29
  .join("\n")}`);
30
30
  Logger.verbose(`NPM module folder: ${getModuleDirname()}`);
@@ -27,7 +27,7 @@ async function runInWorker(input) {
27
27
  Logger.verbose(`[Function ${input.fuctionRequest.functionId}] [Worker ${input.fuctionRequest.workerId}] Reusing worker`);
28
28
  }
29
29
  worker.on("message", (msg) => {
30
- Logger.log("Worker message", msg);
30
+ Logger.verbose(`[Function ${input.fuctionRequest.functionId}] [Worker ${input.fuctionRequest.workerId}] Worker message`, JSON.stringify(msg));
31
31
  if (msg?.errorType) {
32
32
  reject(msg);
33
33
  }
@@ -36,7 +36,7 @@ async function runInWorker(input) {
36
36
  }
37
37
  });
38
38
  worker.on("error", (err) => {
39
- Logger.log("Worker error", err);
39
+ Logger.error(`[Function ${input.fuctionRequest.functionId}] [Worker ${input.fuctionRequest.workerId}] Error`, err);
40
40
  reject(err);
41
41
  });
42
42
  worker.postMessage({
package/dist/vsCode.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from "fs/promises";
2
2
  import path from "path";
3
3
  import { parse, printParseErrorCode, applyEdits, modify, } from "jsonc-parser";
4
- import { getModuleDirname } from "./getDirname.mjs";
4
+ import { getModuleDirname, getProjectDirname } from "./getDirname.mjs";
5
5
  import { Logger } from "./logger.mjs";
6
6
  async function getVsCodeLaunchConfig(lldConfig) {
7
7
  const localRuntimeExecutable = "${workspaceFolder}/node_modules/.bin/lld";
@@ -28,6 +28,7 @@ async function getVsCodeLaunchConfig(lldConfig) {
28
28
  let runtimeExecutableSet = false;
29
29
  //if installed locally
30
30
  if (moduleDirname.startsWith("/home/")) {
31
+ Logger.verbose("Lambda Live Debugger is installed locally");
31
32
  // check if file exists
32
33
  try {
33
34
  //Logger.log("Checking local folder", localFolder);
@@ -40,7 +41,11 @@ async function getVsCodeLaunchConfig(lldConfig) {
40
41
  //Logger.log("Not found", localFolder);
41
42
  }
42
43
  }
44
+ else {
45
+ Logger.verbose("Lambda Live Debugger is installed globally");
46
+ }
43
47
  if (!runtimeExecutableSet) {
48
+ Logger.verbose(`Setting absolute path for runtimeExecutable setting for VsCode configuration`);
44
49
  const globalModule1 = path.join(moduleDirname, "..", "..", ".bin/lld");
45
50
  const globalModule2 = path.join(moduleDirname, "..", "..", "bin/lld");
46
51
  const globalModule3 = path.join(moduleDirname, "..", "..", "..", "..", "bin/lld");
@@ -50,6 +55,7 @@ async function getVsCodeLaunchConfig(lldConfig) {
50
55
  [globalModule2]: globalModule2,
51
56
  [globalModule3]: globalModule3,
52
57
  };
58
+ Logger.verbose(`Checking the following possible folders for lld executable:`, JSON.stringify(possibleFolders, null, 2));
53
59
  // check each possible folder and set the runtimeExecutable
54
60
  for (const folder in possibleFolders) {
55
61
  try {
@@ -57,11 +63,11 @@ async function getVsCodeLaunchConfig(lldConfig) {
57
63
  await fs.access(folder, fs.constants.F_OK);
58
64
  config.configurations[0].runtimeExecutable = possibleFolders[folder];
59
65
  runtimeExecutableSet = true;
60
- //Logger.log("Found folder", folder);
66
+ Logger.verbose(`Found folder with lld executable: ${folder}`);
61
67
  break;
62
68
  }
63
69
  catch (err) {
64
- //Logger.log("Not found", folder);
70
+ // Not found
65
71
  }
66
72
  }
67
73
  if (!runtimeExecutableSet) {
@@ -104,6 +110,7 @@ async function writeConfiguration(filePath, jsonString, changes, position) {
104
110
  });
105
111
  const modifiedJsonString = applyEdits(jsonString, edits);
106
112
  // Write the modified JSON string back to the file
113
+ Logger.verbose(`Adding to VsCode configuration file: ${filePath}`);
107
114
  await fs.writeFile(filePath, modifiedJsonString, "utf-8");
108
115
  }
109
116
  catch (err) {
@@ -112,7 +119,7 @@ async function writeConfiguration(filePath, jsonString, changes, position) {
112
119
  }
113
120
  }
114
121
  async function getCurrentState() {
115
- const filePath = path.join(path.resolve(), ".vscode/launch.json");
122
+ const filePath = path.join(getProjectDirname(), ".vscode/launch.json");
116
123
  let createNewFile = false;
117
124
  // does file exist
118
125
  try {
@@ -130,6 +137,7 @@ async function getCurrentState() {
130
137
  return c.name === vsCodeLaunchConfig.configurations[0].name;
131
138
  });
132
139
  if (!exists) {
140
+ Logger.verbose(`${filePath} exists but configuration does not exist!`);
133
141
  return {
134
142
  state: "FILE_EXISTS_CONFIGURATION_DOES_NOT_EXIST",
135
143
  jsonString,
@@ -138,13 +146,14 @@ async function getCurrentState() {
138
146
  };
139
147
  }
140
148
  else {
141
- Logger.log("Configuration already exists!");
149
+ Logger.verbose(`Configuration already exists in ${filePath}`);
142
150
  return {
143
151
  state: "FILE_EXISTS_CONFIGURATION_EXISTS",
144
152
  };
145
153
  }
146
154
  }
147
155
  else {
156
+ Logger.verbose(`${filePath} does not exist!`);
148
157
  return {
149
158
  state: "FILE_DOES_NOT_EXIST",
150
159
  filePath,
@@ -169,6 +178,7 @@ async function addConfiguration(lldConfig) {
169
178
  else if (state.state === "FILE_DOES_NOT_EXIST") {
170
179
  // crete folder of filePath recursive if not exists
171
180
  await fs.mkdir(path.dirname(state.filePath), { recursive: true });
181
+ Logger.verbose(`Creating VsCode configuration file: ${state.filePath}`);
172
182
  await fs.writeFile(state.filePath, JSON.stringify(config, null, 2), "utf-8");
173
183
  }
174
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-live-debugger",
3
- "version": "0.0.94",
3
+ "version": "0.0.96",
4
4
  "type": "module",
5
5
  "description": "Debug Lambda functions locally like it is running in the cloud",
6
6
  "repository": {
@@ -60,7 +60,6 @@
60
60
  "devDependencies": {
61
61
  "@tsconfig/node20": "^20.1.4",
62
62
  "@types/aws-iot-device-sdk": "^2.2.8",
63
- "@types/commander": "^2.12.2",
64
63
  "@types/inquirer": "^9.0.7",
65
64
  "@types/node": "^20.11.16",
66
65
  "@types/serverless": "^3.12.22",