lambda-live-debugger 0.0.94 → 0.0.95

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");
@@ -231,9 +235,14 @@ export async function getConfigFromWizard({ supportedFrameworks, currentFramewor
231
235
  */
232
236
  const config = getConfigFromAnswers(answers);
233
237
  if (save) {
234
- // save to file that looks like this:
235
- Logger.log("Saving to config file");
236
- const configContent = `
238
+ await saveConfiguration(config);
239
+ }
240
+ return config;
241
+ }
242
+ async function saveConfiguration(config) {
243
+ Logger.log(`Saving to config file ${configFileName}`);
244
+ // save to file that looks like this:
245
+ const configContent = `
237
246
  import { type LldConfigTs } from "lambda-live-debugger";
238
247
 
239
248
  export default {
@@ -255,15 +264,13 @@ export default {
255
264
  //},
256
265
  } satisfies LldConfigTs;
257
266
  `;
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;
267
+ // remove lines that contains undefined or ""
268
+ const configContentCleaned = configContent
269
+ .trim()
270
+ .split("\n")
271
+ .filter((l) => !l.includes("undefined") && !l.includes('""'))
272
+ .join("\n");
273
+ await fs.writeFile(configFileName, configContentCleaned);
267
274
  }
268
275
  function getConfigFromAnswers(answers) {
269
276
  const config = {
@@ -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
  }
@@ -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";
@@ -40,9 +40,10 @@ async function getVsCodeLaunchConfig(lldConfig) {
40
40
  //Logger.log("Not found", localFolder);
41
41
  }
42
42
  }
43
- if (!runtimeExecutableSet) {
44
- const globalModule1 = path.join(moduleDirname, "..", "..", ".bin/lld");
45
- const globalModule2 = path.join(moduleDirname, "..", "..", "bin/lld");
43
+ if (runtimeExecutableSet) {
44
+ const projectDirname = getProjectDirname();
45
+ const globalModule1 = path.join(projectDirname, "..", "..", ".bin/lld");
46
+ const globalModule2 = path.join(projectDirname, "..", "..", "bin/lld");
46
47
  const globalModule3 = path.join(moduleDirname, "..", "..", "..", "..", "bin/lld");
47
48
  const possibleFolders = {
48
49
  [localFolder]: "${workspaceFolder}/node_modules/.bin/lld",
@@ -104,6 +105,7 @@ async function writeConfiguration(filePath, jsonString, changes, position) {
104
105
  });
105
106
  const modifiedJsonString = applyEdits(jsonString, edits);
106
107
  // Write the modified JSON string back to the file
108
+ Logger.verbose(`Adding to VsCode configuration file: ${filePath}`);
107
109
  await fs.writeFile(filePath, modifiedJsonString, "utf-8");
108
110
  }
109
111
  catch (err) {
@@ -112,7 +114,7 @@ async function writeConfiguration(filePath, jsonString, changes, position) {
112
114
  }
113
115
  }
114
116
  async function getCurrentState() {
115
- const filePath = path.join(path.resolve(), ".vscode/launch.json");
117
+ const filePath = path.join(getProjectDirname(), ".vscode/launch.json");
116
118
  let createNewFile = false;
117
119
  // does file exist
118
120
  try {
@@ -130,6 +132,7 @@ async function getCurrentState() {
130
132
  return c.name === vsCodeLaunchConfig.configurations[0].name;
131
133
  });
132
134
  if (!exists) {
135
+ Logger.verbose(`${filePath} exists but configuration does not exist!`);
133
136
  return {
134
137
  state: "FILE_EXISTS_CONFIGURATION_DOES_NOT_EXIST",
135
138
  jsonString,
@@ -138,13 +141,14 @@ async function getCurrentState() {
138
141
  };
139
142
  }
140
143
  else {
141
- Logger.log("Configuration already exists!");
144
+ Logger.verbose(`Configuration already exists in ${filePath}`);
142
145
  return {
143
146
  state: "FILE_EXISTS_CONFIGURATION_EXISTS",
144
147
  };
145
148
  }
146
149
  }
147
150
  else {
151
+ Logger.verbose(`${filePath} does not exist!`);
148
152
  return {
149
153
  state: "FILE_DOES_NOT_EXIST",
150
154
  filePath,
@@ -169,6 +173,7 @@ async function addConfiguration(lldConfig) {
169
173
  else if (state.state === "FILE_DOES_NOT_EXIST") {
170
174
  // crete folder of filePath recursive if not exists
171
175
  await fs.mkdir(path.dirname(state.filePath), { recursive: true });
176
+ Logger.verbose(`Creating VsCode configuration file: ${state.filePath}`);
172
177
  await fs.writeFile(state.filePath, JSON.stringify(config, null, 2), "utf-8");
173
178
  }
174
179
  }
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.95",
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",