lambda-live-debugger 1.2.6 → 1.3.0

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.
@@ -1,4 +1,5 @@
1
1
  import { defineConfig } from 'vitepress';
2
+ import markdownItYouTubeEmbed from './markdown-it-youtube-embed.js';
2
3
 
3
4
  // https://vitepress.dev/reference/site-config
4
5
  export default defineConfig({
@@ -106,4 +107,9 @@ export default defineConfig({
106
107
  },
107
108
  ],
108
109
  },
110
+ markdown: {
111
+ config: (md) => {
112
+ md.use(markdownItYouTubeEmbed);
113
+ },
114
+ },
109
115
  });
@@ -0,0 +1,45 @@
1
+ import { PluginWithOptions } from 'markdown-it';
2
+ import { RuleCore } from 'markdown-it/lib/parser_core.mjs';
3
+
4
+ const markdownItYouTubeEmbed: PluginWithOptions<void> = (md) => {
5
+ const youtubeEmbedRule: RuleCore = (state) => {
6
+ const tokens = state.tokens;
7
+
8
+ for (let i = 0; i < tokens.length; i++) {
9
+ const token = tokens[i];
10
+
11
+ if (
12
+ token.type === 'inline' &&
13
+ token.children &&
14
+ token.children.length >= 1 &&
15
+ token.children[0].type === 'link_open'
16
+ ) {
17
+ const linkToken = token.children[0];
18
+ const href = linkToken.attrGet('href');
19
+
20
+ if (href && href.startsWith('https://www.youtube.com/watch?v=')) {
21
+ const videoId = href.split('v=')[1];
22
+ const iframeHtml = `
23
+ <div class="responsive-video">
24
+ <iframe
25
+ src="https://www.youtube.com/embed/${videoId}"
26
+ frameborder="0"
27
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
28
+ allowfullscreen>
29
+ </iframe>
30
+ </div>
31
+ `;
32
+
33
+ // Replace current token with a new HTML block token
34
+ const newToken = new state.Token('html_block', '', 0);
35
+ newToken.content = iframeHtml;
36
+ tokens[i] = newToken;
37
+ }
38
+ }
39
+ }
40
+ };
41
+
42
+ md.core.ruler.push('youtube_embed', youtubeEmbedRule);
43
+ };
44
+
45
+ export default markdownItYouTubeEmbed;
@@ -25,3 +25,20 @@
25
25
  .VPSidebar {
26
26
  padding-bottom: 20px !important;
27
27
  }
28
+
29
+ .responsive-video {
30
+ position: relative;
31
+ padding-bottom: 56.25%; /* 16:9 aspect ratio */
32
+ height: 0;
33
+ overflow: hidden;
34
+ max-width: 100%;
35
+ background: #000;
36
+ }
37
+
38
+ .responsive-video iframe {
39
+ position: absolute;
40
+ top: 0;
41
+ left: 0;
42
+ width: 100%;
43
+ height: 100%;
44
+ }
package/README.md CHANGED
@@ -7,12 +7,14 @@ This tool offers similar functionality to [SST](https://sst.dev/) and [Serverles
7
7
  It supports the following frameworks:
8
8
 
9
9
  - AWS CDK v2
10
- - Serverless Framework v3 (SLS)
10
+ - Serverless Framework v3 (SLS) and [`osls` fork](https://github.com/oss-serverless/serverless)
11
11
  - AWS Serverless Application Model (SAM)
12
12
  - Terraform
13
13
  - Any other framework or setup by implementing a simple function in TypeScript
14
14
  - ... (Need support for another framework? Let me know!)
15
15
 
16
+ [![Video presentation of Lambda Live Debugger](https://img.youtube.com/vi/BrhybwyDM0I/0.jpg)](https://www.youtube.com/watch?v=BrhybwyDM0I)
17
+
16
18
  ## Why?
17
19
 
18
20
  Serverless is amazing and solves many issues with traditional systems. However, writing code for Lambda functions can be challenging. The cycle of writing, deploying, running, fixing, and redeploying is time-consuming and tedious. You could use tools to run Lambda locally or use unit/integration tests; those approaches often don't replicate the actual environment closely enough.
Binary file
@@ -51,51 +51,35 @@ export class SlsFramework {
51
51
  let resolveVariablesMeta;
52
52
  let sources;
53
53
  let Serverless;
54
+ let error1;
54
55
  try {
55
- // lazy load modules
56
- resolveConfigurationPath = (await import(
57
- //@ts-ignore
58
- 'serverless/lib/cli/resolve-configuration-path.js')).default;
59
- readConfiguration = (await import(
60
- //@ts-ignore
61
- 'serverless/lib/configuration/read.js')).default;
62
- resolveVariables = (await import(
63
- //@ts-ignore
64
- 'serverless/lib/configuration/variables/resolve.js')).default;
65
- resolveVariablesMeta = (await import(
66
- //@ts-ignore
67
- 'serverless/lib/configuration/variables/resolve-meta.js')).default;
68
- const env = await import(
69
- //@ts-ignore
70
- 'serverless/lib/configuration/variables/sources/env.js');
71
- const file = await import(
72
- //@ts-ignore
73
- 'serverless/lib/configuration/variables/sources/file.js');
74
- const opt = await import(
75
- //@ts-ignore
76
- 'serverless/lib/configuration/variables/sources/opt.js');
77
- const self = await import(
78
- //@ts-ignore
79
- 'serverless/lib/configuration/variables/sources/self.js');
80
- const strToBool = await import(
81
- //@ts-ignore
82
- 'serverless/lib/configuration/variables/sources/str-to-bool.js');
83
- const sls = await import(
84
- //@ts-ignores
85
- 'serverless/lib/configuration/variables/sources/instance-dependent/get-sls.js');
86
- sources = {
87
- env: env.default,
88
- file: file.default,
89
- opt: opt.default,
90
- self: self.default,
91
- strToBool: strToBool.default,
92
- sls: sls.default(),
93
- };
94
- Serverless = (await import('serverless')).default;
56
+ try {
57
+ const frameworkFunctions = await loadFramework('serverless');
58
+ resolveConfigurationPath = frameworkFunctions.resolveConfigurationPath;
59
+ readConfiguration = frameworkFunctions.readConfiguration;
60
+ resolveVariables = frameworkFunctions.resolveVariables;
61
+ resolveVariablesMeta = frameworkFunctions.resolveVariablesMeta;
62
+ sources = frameworkFunctions.sources;
63
+ Serverless = frameworkFunctions.Serverless;
64
+ Logger.verbose(`[SLS] Npm module 'serverless' loaded`);
65
+ }
66
+ catch (error) {
67
+ Logger.verbose(`[SLS] Failed to load npm module 'serverless'`, error);
68
+ error1 = error;
69
+ const frameworkFunctions = await loadFramework('osls');
70
+ resolveConfigurationPath = frameworkFunctions.resolveConfigurationPath;
71
+ readConfiguration = frameworkFunctions.readConfiguration;
72
+ resolveVariables = frameworkFunctions.resolveVariables;
73
+ resolveVariablesMeta = frameworkFunctions.resolveVariablesMeta;
74
+ sources = frameworkFunctions.sources;
75
+ Serverless = frameworkFunctions.Serverless;
76
+ Logger.verbose(`[SLS] Npm module 'osls' loaded`);
77
+ }
95
78
  }
96
- catch (error) {
97
- Logger.error('Error loading serverless modules', error);
98
- Logger.log('If you are running Lambda Live Debugger from a global installation, install Serverless Framework globally as well. If you are using monorepo, install Serverless Framework also in the project root folder.');
79
+ catch (error2) {
80
+ const error = error1 ?? error2;
81
+ Logger.error('Error loading serverless (or osls) module', error);
82
+ Logger.log('If you are running Lambda Live Debugger from a global installation, install Serverless Framework globally as well. If you are using monorepo, install Serverless Framework also in the project root folder. The fork of Serverless Framework https://github.com/oss-serverless/serverless is also supported.');
99
83
  throw new Error(`Error loading serverless modules. ${error.message}`, {
100
84
  cause: error,
101
85
  });
@@ -242,3 +226,53 @@ export class SlsFramework {
242
226
  }
243
227
  }
244
228
  export const slsFramework = new SlsFramework();
229
+ async function loadFramework(npmName) {
230
+ // lazy load modules
231
+ const resolveConfigurationPath = (await import(
232
+ //@ts-ignore
233
+ `${npmName}/lib/cli/resolve-configuration-path.js`)).default;
234
+ const readConfiguration = (await import(
235
+ //@ts-ignore
236
+ `${npmName}/lib/configuration/read.js`)).default;
237
+ const resolveVariables = (await import(
238
+ //@ts-ignore
239
+ `${npmName}/lib/configuration/variables/resolve.js`)).default;
240
+ const resolveVariablesMeta = (await import(
241
+ //@ts-ignore
242
+ `${npmName}/lib/configuration/variables/resolve-meta.js`)).default;
243
+ const env = await import(
244
+ //@ts-ignore
245
+ `${npmName}/lib/configuration/variables/sources/env.js`);
246
+ const file = await import(
247
+ //@ts-ignore
248
+ `${npmName}/lib/configuration/variables/sources/file.js`);
249
+ const opt = await import(
250
+ //@ts-ignore
251
+ `${npmName}/lib/configuration/variables/sources/opt.js`);
252
+ const self = await import(
253
+ //@ts-ignore
254
+ `${npmName}/lib/configuration/variables/sources/self.js`);
255
+ const strToBool = await import(
256
+ //@ts-ignore
257
+ `${npmName}/lib/configuration/variables/sources/str-to-bool.js`);
258
+ const sls = await import(
259
+ //@ts-ignores
260
+ `${npmName}/lib/configuration/variables/sources/instance-dependent/get-sls.js`);
261
+ const sources = {
262
+ env: env.default,
263
+ file: file.default,
264
+ opt: opt.default,
265
+ self: self.default,
266
+ strToBool: strToBool.default,
267
+ sls: sls.default(),
268
+ };
269
+ const Serverless = (await import(npmName)).default;
270
+ return {
271
+ resolveConfigurationPath,
272
+ readConfiguration,
273
+ resolveVariablesMeta,
274
+ resolveVariables,
275
+ sources,
276
+ Serverless,
277
+ };
278
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-live-debugger",
3
- "version": "1.2.6",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Debug Lambda functions locally like it is running in the cloud",
6
6
  "repository": {
@@ -60,6 +60,12 @@
60
60
  "test-sls-esbuild-cjs-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sls-esbuild-cjs.test.ts",
61
61
  "test-sls-esbuild-esm": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sls-esbuild-esm.test.ts",
62
62
  "test-sls-esbuild-esm-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sls-esbuild-esm.test.ts",
63
+ "test-osls-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/osls-basic.test.ts",
64
+ "test-osls-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/osls-basic.test.ts",
65
+ "test-osls-esbuild-cjs": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/osls-esbuild-cjs.test.ts",
66
+ "test-osls-esbuild-cjs-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/osls-esbuild-cjs.test.ts",
67
+ "test-osls-esbuild-esm": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/osls-esbuild-esm.test.ts",
68
+ "test-osls-esbuild-esm-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/osls-esbuild-esm.test.ts",
63
69
  "test-sam-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sam-basic.test.ts",
64
70
  "test-sam-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-basic.test.ts",
65
71
  "test-sam-alt": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sam-alt.test.ts",
@@ -89,6 +95,7 @@
89
95
  "prettier": "^3.3.3",
90
96
  "semantic-release": "^23.0.8",
91
97
  "serverless": "^3.38.0",
98
+ "osls": "^3.41.0",
92
99
  "serverless-esbuild": "^1.52.1",
93
100
  "tsx": "^4.7.1",
94
101
  "typescript-eslint": "^8.0.0",
@@ -141,6 +148,10 @@
141
148
  "test/cdk-config",
142
149
  "test/sls-basic",
143
150
  "test/sls-esbuild",
151
+ "test/sls-esbuild-cjs",
152
+ "test/osls-basic",
153
+ "test/osls-esbuild",
154
+ "test/osls-esbuild-cjs",
144
155
  "test/sam-basic",
145
156
  "test/sam-alt",
146
157
  "test/terraform-basic"
@@ -0,0 +1,33 @@
1
+ import { readFile, writeFile } from 'fs/promises';
2
+ import { argv } from 'process';
3
+
4
+ /**
5
+ * Prepare the package.json file for testing.
6
+ * Remove everything that is not needed for testing.
7
+ * @param {*} testCase
8
+ */
9
+ async function modifyPackageJson(testCase) {
10
+ const filePath = 'package.json';
11
+
12
+ const data = await readFile(filePath, 'utf-8');
13
+ const packageJson = JSON.parse(data);
14
+
15
+ // Delete scripts and devDependencies nodes
16
+ delete packageJson.scripts;
17
+ delete packageJson.devDependencies;
18
+
19
+ // Replace workspaces node with the test and the test case workspaces
20
+ // With this all the necessary npm packages will be installed
21
+ packageJson.workspaces = ['test', `test/${testCase}`];
22
+
23
+ await writeFile(filePath, JSON.stringify(packageJson, null, 2), 'utf-8');
24
+ console.log(`Modified ${filePath} successfully!`);
25
+ }
26
+
27
+ const [testCase] = argv.slice(2);
28
+ if (!testCase) {
29
+ console.error('Usage: node prepareForTest.js <testCase>');
30
+ process.exit(1);
31
+ }
32
+
33
+ void modifyPackageJson(testCase).catch(console.error);