lambda-live-debugger 0.0.112 → 0.0.114
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/.prettierrc +3 -1
- package/README.md +31 -33
- package/dist/awsCredentials.d.ts +2 -2
- package/dist/awsCredentials.mjs +1 -1
- package/dist/cloudFormation.d.ts +1 -1
- package/dist/cloudFormation.mjs +7 -7
- package/dist/configuration/getConfigFromCliArgs.d.ts +1 -1
- package/dist/configuration/getConfigFromCliArgs.mjs +22 -22
- package/dist/configuration/getConfigFromTsConfigFile.d.ts +1 -1
- package/dist/configuration/getConfigFromTsConfigFile.mjs +9 -9
- package/dist/configuration/getConfigFromWizard.d.ts +1 -1
- package/dist/configuration/getConfigFromWizard.mjs +78 -78
- package/dist/configuration.d.ts +2 -2
- package/dist/configuration.mjs +15 -15
- package/dist/constants.mjs +2 -2
- package/dist/extension/extension.zip +0 -0
- package/dist/extension/nodejs/node_modules/interceptor.js.map +1 -1
- package/dist/fileWatcher.mjs +11 -11
- package/dist/frameworks/cdkFramework.d.ts +5 -5
- package/dist/frameworks/cdkFramework.mjs +42 -41
- package/dist/frameworks/cdkFrameworkWorker.mjs +17 -13
- package/dist/frameworks/iFrameworks.d.ts +2 -2
- package/dist/frameworks/samFramework.d.ts +3 -3
- package/dist/frameworks/samFramework.mjs +19 -19
- package/dist/frameworks/slsFramework.d.ts +4 -4
- package/dist/frameworks/slsFramework.mjs +22 -22
- package/dist/frameworks/terraformFramework.d.ts +4 -4
- package/dist/frameworks/terraformFramework.mjs +34 -34
- package/dist/getDirname.mjs +3 -3
- package/dist/gitignore.mjs +11 -11
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +4 -4
- package/dist/infraDeploy.mjs +39 -39
- package/dist/ioTService.d.ts +6 -6
- package/dist/ioTService.mjs +19 -19
- package/dist/lambdaConnection.mjs +13 -13
- package/dist/lldebugger.mjs +22 -22
- package/dist/nodeEsBuild.mjs +30 -30
- package/dist/nodeHandler.d.ts +1 -1
- package/dist/nodeHandler.mjs +4 -4
- package/dist/nodeWorker.d.ts +1 -1
- package/dist/nodeWorker.mjs +14 -14
- package/dist/nodeWorkerRunner.mjs +9 -9
- package/dist/resourceDiscovery.d.ts +1 -1
- package/dist/resourceDiscovery.mjs +8 -8
- package/dist/types/lambdaProps.d.ts +1 -1
- package/dist/types/lldConfig.d.ts +4 -4
- package/dist/types/resourcesDiscovery.d.ts +2 -2
- package/dist/utils/findNpmPath.mjs +6 -6
- package/dist/utils/findPackageJson.mjs +6 -6
- package/dist/utils/getRootFolder.mjs +4 -4
- package/dist/utils/removeUndefinedProperties.mjs +1 -1
- package/dist/version.mjs +5 -5
- package/dist/vsCode.mjs +34 -34
- package/eslint.config.js +18 -18
- package/fix-imports.js +13 -13
- package/package.json +1 -1
package/dist/fileWatcher.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as chokidar from
|
|
2
|
-
import { NodeEsBuild } from
|
|
3
|
-
import { NodeWorker } from
|
|
4
|
-
import { Configuration } from
|
|
5
|
-
import { setTimeout } from
|
|
6
|
-
import { Logger } from
|
|
1
|
+
import * as chokidar from 'chokidar';
|
|
2
|
+
import { NodeEsBuild } from './nodeEsBuild.mjs';
|
|
3
|
+
import { NodeWorker } from './nodeWorker.mjs';
|
|
4
|
+
import { Configuration } from './configuration.mjs';
|
|
5
|
+
import { setTimeout } from 'node:timers/promises';
|
|
6
|
+
import { Logger } from './logger.mjs';
|
|
7
7
|
let processingChange = false;
|
|
8
8
|
/**
|
|
9
9
|
* Watch for file changes in a folder and trigger a rebuild of the Lambdas
|
|
@@ -17,17 +17,17 @@ function watchForFileChanges(folder) {
|
|
|
17
17
|
followSymlinks: false,
|
|
18
18
|
disableGlobbing: false,
|
|
19
19
|
ignored: [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
'**/node_modules/**',
|
|
21
|
+
'**/.lldebugger/**',
|
|
22
|
+
'**/.git/**',
|
|
23
|
+
'**/debug.log',
|
|
24
24
|
],
|
|
25
25
|
awaitWriteFinish: {
|
|
26
26
|
pollInterval: 100,
|
|
27
27
|
stabilityThreshold: 20,
|
|
28
28
|
},
|
|
29
29
|
});
|
|
30
|
-
watcher.on(
|
|
30
|
+
watcher.on('change', async () => {
|
|
31
31
|
if (processingChange) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { LambdaResource } from
|
|
2
|
-
import { IFramework } from
|
|
3
|
-
import { AwsConfiguration } from
|
|
4
|
-
import { LldConfigBase } from
|
|
5
|
-
import { type BundlingOptions } from
|
|
1
|
+
import { LambdaResource } from '../types/resourcesDiscovery.js';
|
|
2
|
+
import { IFramework } from './iFrameworks.js';
|
|
3
|
+
import { AwsConfiguration } from '../types/awsConfiguration.js';
|
|
4
|
+
import { LldConfigBase } from '../types/lldConfig.js';
|
|
5
|
+
import { type BundlingOptions } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
6
6
|
/**
|
|
7
7
|
* Support for AWS CDK framework
|
|
8
8
|
*/
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import * as esbuild from
|
|
2
|
-
import * as fs from
|
|
3
|
-
import * as path from
|
|
4
|
-
import { BundlingType } from
|
|
5
|
-
import { outputFolder } from
|
|
6
|
-
import { findPackageJson } from
|
|
7
|
-
import { CloudFormation } from
|
|
8
|
-
import { Logger } from
|
|
9
|
-
import { Worker } from
|
|
10
|
-
import { getModuleDirname, getProjectDirname } from
|
|
11
|
-
import { findNpmPath } from
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { BundlingType } from '../types/resourcesDiscovery.mjs';
|
|
5
|
+
import { outputFolder } from '../constants.mjs';
|
|
6
|
+
import { findPackageJson } from '../utils/findPackageJson.mjs';
|
|
7
|
+
import { CloudFormation } from '../cloudFormation.mjs';
|
|
8
|
+
import { Logger } from '../logger.mjs';
|
|
9
|
+
import { Worker } from 'node:worker_threads';
|
|
10
|
+
import { getModuleDirname, getProjectDirname } from '../getDirname.mjs';
|
|
11
|
+
import { findNpmPath } from '../utils/findNpmPath.mjs';
|
|
12
12
|
/**
|
|
13
13
|
* Support for AWS CDK framework
|
|
14
14
|
*/
|
|
@@ -17,7 +17,7 @@ export class CdkFramework {
|
|
|
17
17
|
* Framework name
|
|
18
18
|
*/
|
|
19
19
|
get name() {
|
|
20
|
-
return
|
|
20
|
+
return 'cdk';
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Can this class handle the current project
|
|
@@ -25,7 +25,7 @@ export class CdkFramework {
|
|
|
25
25
|
*/
|
|
26
26
|
async canHandle() {
|
|
27
27
|
// check if there is cdk.json
|
|
28
|
-
const cdkJsonPath = path.resolve(
|
|
28
|
+
const cdkJsonPath = path.resolve('cdk.json');
|
|
29
29
|
try {
|
|
30
30
|
await fs.access(cdkJsonPath, fs.constants.F_OK);
|
|
31
31
|
return true;
|
|
@@ -46,7 +46,7 @@ export class CdkFramework {
|
|
|
46
46
|
profile: config.profile,
|
|
47
47
|
role: config.role,
|
|
48
48
|
};
|
|
49
|
-
const cdkConfigPath =
|
|
49
|
+
const cdkConfigPath = 'cdk.json';
|
|
50
50
|
// read cdk.json and extract the entry file
|
|
51
51
|
const lambdasInCdk = await this.getLambdasDataFromCdkByCompilingAndRunning(cdkConfigPath, config);
|
|
52
52
|
Logger.verbose(`[CDK] Found Lambda functions:`, JSON.stringify(lambdasInCdk, null, 2));
|
|
@@ -57,7 +57,7 @@ export class CdkFramework {
|
|
|
57
57
|
return lambda.stackName;
|
|
58
58
|
})),
|
|
59
59
|
];
|
|
60
|
-
Logger.verbose(`[CDK] Found the following stacks in CDK: ${stackNames.join(
|
|
60
|
+
Logger.verbose(`[CDK] Found the following stacks in CDK: ${stackNames.join(', ')}`);
|
|
61
61
|
const lambdasDeployed = (await Promise.all(stackNames.map(async (stackName) => {
|
|
62
62
|
const lambdasInStackPromise = CloudFormation.getLambdasInStack(stackName, awsConfiguration);
|
|
63
63
|
const lambdasMetadataPromise = this.getLambdaCdkPathFromTemplateMetadata(stackName, awsConfiguration);
|
|
@@ -122,11 +122,11 @@ export class CdkFramework {
|
|
|
122
122
|
const cfTemplate = await CloudFormation.getCloudFormationStackTemplate(stackName, awsConfiguration);
|
|
123
123
|
// get all Lambda functions in the template
|
|
124
124
|
const lambdas = Object.entries(cfTemplate.Resources)
|
|
125
|
-
.filter(([, resource]) => resource.Type ===
|
|
125
|
+
.filter(([, resource]) => resource.Type === 'AWS::Lambda::Function')
|
|
126
126
|
.map(([key, resource]) => {
|
|
127
127
|
return {
|
|
128
128
|
logicalId: key,
|
|
129
|
-
cdkPath: resource.Metadata[
|
|
129
|
+
cdkPath: resource.Metadata['aws:cdk:path'],
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
return lambdas;
|
|
@@ -141,13 +141,13 @@ export class CdkFramework {
|
|
|
141
141
|
const entryFile = await this.getCdkEntryFile(cdkConfigPath);
|
|
142
142
|
// Define a plugin to prepend custom code to .ts or .tsx files
|
|
143
143
|
const injectCodePlugin = {
|
|
144
|
-
name:
|
|
144
|
+
name: 'injectCode',
|
|
145
145
|
setup(build) {
|
|
146
146
|
build.onLoad({ filter: /.*/ }, async (args) => {
|
|
147
147
|
const absolutePath = path.resolve(args.path);
|
|
148
|
-
let source = await fs.readFile(absolutePath,
|
|
149
|
-
if (args.path.includes(
|
|
150
|
-
const codeToFind =
|
|
148
|
+
let source = await fs.readFile(absolutePath, 'utf8');
|
|
149
|
+
if (args.path.includes('aws-cdk-lib/aws-lambda/lib/function.')) {
|
|
150
|
+
const codeToFind = 'try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_FunctionProps(props)}';
|
|
151
151
|
if (!source.includes(codeToFind)) {
|
|
152
152
|
throw new Error(`Can not find code to inject in ${args.path}`);
|
|
153
153
|
}
|
|
@@ -175,8 +175,8 @@ export class CdkFramework {
|
|
|
175
175
|
// });
|
|
176
176
|
global.lambdas.push(lambdaInfo);` + codeToFind);
|
|
177
177
|
}
|
|
178
|
-
if (args.path.includes(
|
|
179
|
-
const codeToFind =
|
|
178
|
+
if (args.path.includes('aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.')) {
|
|
179
|
+
const codeToFind = 'super(scope,id),this.requestDestinationArn=!1;';
|
|
180
180
|
if (!source.includes(codeToFind)) {
|
|
181
181
|
throw new Error(`Can not find code to inject in ${args.path}`);
|
|
182
182
|
}
|
|
@@ -185,7 +185,7 @@ export class CdkFramework {
|
|
|
185
185
|
}
|
|
186
186
|
return {
|
|
187
187
|
contents: source,
|
|
188
|
-
loader:
|
|
188
|
+
loader: 'default',
|
|
189
189
|
};
|
|
190
190
|
});
|
|
191
191
|
},
|
|
@@ -196,8 +196,8 @@ export class CdkFramework {
|
|
|
196
196
|
await esbuild.build({
|
|
197
197
|
entryPoints: [entryFile],
|
|
198
198
|
bundle: true,
|
|
199
|
-
platform:
|
|
200
|
-
target:
|
|
199
|
+
platform: 'node',
|
|
200
|
+
target: 'node18',
|
|
201
201
|
outfile: compileOutput,
|
|
202
202
|
sourcemap: false,
|
|
203
203
|
plugins: [injectCodePlugin],
|
|
@@ -212,11 +212,11 @@ export class CdkFramework {
|
|
|
212
212
|
const CDK_CONTEXT_JSON = {
|
|
213
213
|
...context,
|
|
214
214
|
// prevent compiling assets
|
|
215
|
-
|
|
215
|
+
'aws:cdk:bundling-stacks': [],
|
|
216
216
|
};
|
|
217
217
|
process.env.CDK_CONTEXT_JSON = JSON.stringify(CDK_CONTEXT_JSON);
|
|
218
218
|
Logger.verbose(`[CDK] Context:`, JSON.stringify(CDK_CONTEXT_JSON, null, 2));
|
|
219
|
-
const awsCdkLibPath = await findNpmPath(path.join(getProjectDirname(), config.subfolder ??
|
|
219
|
+
const awsCdkLibPath = await findNpmPath(path.join(getProjectDirname(), config.subfolder ?? '/'), 'aws-cdk-lib');
|
|
220
220
|
Logger.verbose(`[CDK] aws-cdk-lib path: ${awsCdkLibPath}`);
|
|
221
221
|
const lambdas = await this.runCdkCodeAndReturnLambdas({
|
|
222
222
|
config,
|
|
@@ -225,7 +225,7 @@ export class CdkFramework {
|
|
|
225
225
|
});
|
|
226
226
|
const list = await Promise.all(lambdas.map(async (lambda) => {
|
|
227
227
|
// handler slit into file and file name
|
|
228
|
-
const handlerSplit = lambda.handler.split(
|
|
228
|
+
const handlerSplit = lambda.handler.split('.');
|
|
229
229
|
const handler = handlerSplit.pop();
|
|
230
230
|
const filename = handlerSplit[0];
|
|
231
231
|
let codePath = lambda.codePath;
|
|
@@ -270,24 +270,25 @@ export class CdkFramework {
|
|
|
270
270
|
*/
|
|
271
271
|
async runCdkCodeAndReturnLambdas({ config, awsCdkLibPath, compileCodeFile, }) {
|
|
272
272
|
const lambdas = await new Promise((resolve, reject) => {
|
|
273
|
-
const worker = new Worker(path.resolve(path.join(getModuleDirname(),
|
|
273
|
+
const worker = new Worker(path.resolve(path.join(getModuleDirname(), 'frameworks/cdkFrameworkWorker.mjs')), {
|
|
274
274
|
workerData: {
|
|
275
275
|
verbose: config.verbose,
|
|
276
276
|
awsCdkLibPath,
|
|
277
277
|
projectDirname: getProjectDirname(),
|
|
278
278
|
moduleDirname: getModuleDirname(),
|
|
279
|
+
subfolder: config.subfolder,
|
|
279
280
|
},
|
|
280
281
|
});
|
|
281
|
-
worker.on(
|
|
282
|
+
worker.on('message', async (message) => {
|
|
282
283
|
resolve(message);
|
|
283
284
|
await worker.terminate();
|
|
284
285
|
});
|
|
285
|
-
worker.on(
|
|
286
|
+
worker.on('error', (error) => {
|
|
286
287
|
reject(new Error(`Error running CDK code in worker: ${error.message}`, {
|
|
287
288
|
cause: error,
|
|
288
289
|
}));
|
|
289
290
|
});
|
|
290
|
-
worker.on(
|
|
291
|
+
worker.on('exit', (code) => {
|
|
291
292
|
if (code !== 0) {
|
|
292
293
|
reject(new Error(`CDK worker stopped with exit code ${code}`));
|
|
293
294
|
}
|
|
@@ -309,7 +310,7 @@ export class CdkFramework {
|
|
|
309
310
|
// get CDK context from the command line
|
|
310
311
|
// get all "-c" and "--context" arguments from the command line
|
|
311
312
|
const contextFromLldConfig = config.context?.reduce((acc, arg) => {
|
|
312
|
-
const [key, value] = arg.split(
|
|
313
|
+
const [key, value] = arg.split('=');
|
|
313
314
|
if (key && value) {
|
|
314
315
|
acc[key] = value;
|
|
315
316
|
}
|
|
@@ -318,21 +319,21 @@ export class CdkFramework {
|
|
|
318
319
|
// get all context from 'cdk.context.json' if it exists
|
|
319
320
|
let contextFromJson = {};
|
|
320
321
|
try {
|
|
321
|
-
const cdkContextJson = await fs.readFile(
|
|
322
|
+
const cdkContextJson = await fs.readFile('cdk.context.json', 'utf8');
|
|
322
323
|
contextFromJson = JSON.parse(cdkContextJson);
|
|
323
324
|
}
|
|
324
325
|
catch (err) {
|
|
325
|
-
if (err.code !==
|
|
326
|
+
if (err.code !== 'ENOENT') {
|
|
326
327
|
throw new Error(`Error reading cdk.context.json: ${err.message}`);
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
// get context from cdk.json
|
|
330
331
|
let cdkJson = {};
|
|
331
332
|
try {
|
|
332
|
-
cdkJson = JSON.parse(await fs.readFile(cdkConfigPath,
|
|
333
|
+
cdkJson = JSON.parse(await fs.readFile(cdkConfigPath, 'utf8'));
|
|
333
334
|
}
|
|
334
335
|
catch (err) {
|
|
335
|
-
if (err.code !==
|
|
336
|
+
if (err.code !== 'ENOENT') {
|
|
336
337
|
throw new Error(`Error reading cdk.json: ${err.message}`);
|
|
337
338
|
}
|
|
338
339
|
}
|
|
@@ -344,13 +345,13 @@ export class CdkFramework {
|
|
|
344
345
|
* @returns
|
|
345
346
|
*/
|
|
346
347
|
async getCdkEntryFile(cdkConfigPath) {
|
|
347
|
-
const cdkJson = await fs.readFile(cdkConfigPath,
|
|
348
|
+
const cdkJson = await fs.readFile(cdkConfigPath, 'utf8');
|
|
348
349
|
const cdkConfig = JSON.parse(cdkJson);
|
|
349
350
|
const entry = cdkConfig.app;
|
|
350
351
|
// just file that ends with .ts
|
|
351
352
|
let entryFile = entry
|
|
352
|
-
?.split(
|
|
353
|
-
.find((file) => file.endsWith(
|
|
353
|
+
?.split(' ')
|
|
354
|
+
.find((file) => file.endsWith('.ts'))
|
|
354
355
|
?.trim();
|
|
355
356
|
if (!entryFile) {
|
|
356
357
|
throw new Error(`Entry file not found in ${cdkConfigPath}`);
|
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import { createRequire as topLevelCreateRequire } from
|
|
2
|
+
import { createRequire as topLevelCreateRequire } from 'module';
|
|
3
3
|
const require = topLevelCreateRequire(import.meta.url);
|
|
4
|
-
import path from
|
|
4
|
+
import path from 'path';
|
|
5
5
|
|
|
6
|
-
import { workerData, parentPort } from
|
|
7
|
-
import fs from
|
|
6
|
+
import { workerData, parentPort } from 'node:worker_threads';
|
|
7
|
+
import fs from 'fs/promises';
|
|
8
8
|
|
|
9
|
-
import { Logger } from
|
|
9
|
+
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
|
|
|
17
|
-
parentPort.on(
|
|
21
|
+
parentPort.on('message', async (data) => {
|
|
18
22
|
// this is global variable to store the data from the CDK code once it is executed
|
|
19
23
|
global.lambdas = [];
|
|
20
24
|
|
|
21
25
|
Logger.verbose(`[Worker ${workerData.workerId}] Received message`, data);
|
|
22
26
|
|
|
23
27
|
// execute code to get the data into global.lambdas
|
|
24
|
-
const codeFile = await fs.readFile(data.compileOutput,
|
|
28
|
+
const codeFile = await fs.readFile(data.compileOutput, 'utf8');
|
|
25
29
|
|
|
26
30
|
await fixCdkPaths(workerData.awsCdkLibPath);
|
|
27
31
|
|
|
28
32
|
eval(codeFile);
|
|
29
33
|
|
|
30
34
|
if (!global.lambdas || global.lambdas?.length === 0) {
|
|
31
|
-
throw new Error(
|
|
35
|
+
throw new Error('No Lambda functions found in the CDK code');
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
const lambdas = global.lambdas.map((lambda) => ({
|
|
@@ -63,15 +67,15 @@ async function fixCdkPaths(awsCdkLibPath) {
|
|
|
63
67
|
Logger.verbose(`[CDK] [Worker] aws-cdk-lib PATH ${awsCdkLibPath}`);
|
|
64
68
|
|
|
65
69
|
const pathsFix = {
|
|
66
|
-
|
|
70
|
+
'custom-resource-handlers/': `${awsCdkLibPath}/custom-resource-handlers/`,
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
// Create a proxy to intercept calls to the path module so we can fix paths
|
|
70
74
|
const pathProxy = new Proxy(path, {
|
|
71
75
|
get(target, prop) {
|
|
72
|
-
if (typeof target[prop] ===
|
|
76
|
+
if (typeof target[prop] === 'function') {
|
|
73
77
|
return function (...args) {
|
|
74
|
-
if (prop ===
|
|
78
|
+
if (prop === 'resolve') {
|
|
75
79
|
let resolvedPath = target[prop].apply(target, args);
|
|
76
80
|
|
|
77
81
|
for (const [key, value] of Object.entries(pathsFix)) {
|
|
@@ -96,7 +100,7 @@ async function fixCdkPaths(awsCdkLibPath) {
|
|
|
96
100
|
});
|
|
97
101
|
|
|
98
102
|
// Override the path module in the require cache
|
|
99
|
-
require.cache[require.resolve(
|
|
103
|
+
require.cache[require.resolve('path')] = {
|
|
100
104
|
exports: pathProxy,
|
|
101
105
|
};
|
|
102
106
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LldConfigBase } from
|
|
2
|
-
import { LambdaResource } from
|
|
1
|
+
import { LldConfigBase } from '../types/lldConfig.js';
|
|
2
|
+
import { LambdaResource } from '../types/resourcesDiscovery.js';
|
|
3
3
|
/**
|
|
4
4
|
* Framework support interface
|
|
5
5
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LambdaResource } from
|
|
2
|
-
import { IFramework } from
|
|
3
|
-
import { LldConfigBase } from
|
|
1
|
+
import { LambdaResource } from '../types/resourcesDiscovery.js';
|
|
2
|
+
import { IFramework } from './iFrameworks.js';
|
|
3
|
+
import { LldConfigBase } from '../types/lldConfig.js';
|
|
4
4
|
/**
|
|
5
5
|
* Support for AWS SAM framework
|
|
6
6
|
*/
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
3
|
-
import { constants } from
|
|
4
|
-
import toml from
|
|
5
|
-
import * as yaml from
|
|
6
|
-
import { findPackageJson } from
|
|
7
|
-
import { CloudFormation } from
|
|
8
|
-
import { Logger } from
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { constants } from 'fs';
|
|
4
|
+
import toml from 'toml';
|
|
5
|
+
import * as yaml from 'yaml';
|
|
6
|
+
import { findPackageJson } from '../utils/findPackageJson.mjs';
|
|
7
|
+
import { CloudFormation } from '../cloudFormation.mjs';
|
|
8
|
+
import { Logger } from '../logger.mjs';
|
|
9
9
|
/**
|
|
10
10
|
* Support for AWS SAM framework
|
|
11
11
|
*/
|
|
12
12
|
export class SamFramework {
|
|
13
|
-
samConfigFile =
|
|
14
|
-
samTemplateFile =
|
|
13
|
+
samConfigFile = 'samconfig.toml';
|
|
14
|
+
samTemplateFile = 'template.yaml';
|
|
15
15
|
/**
|
|
16
16
|
* Framework name
|
|
17
17
|
*/
|
|
18
18
|
get name() {
|
|
19
|
-
return
|
|
19
|
+
return 'sam';
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Can this class handle the current project
|
|
@@ -50,20 +50,20 @@ export class SamFramework {
|
|
|
50
50
|
profile: config.profile,
|
|
51
51
|
role: config.role,
|
|
52
52
|
};
|
|
53
|
-
const environment = config.configEnv ??
|
|
54
|
-
const samConfigContent = await fs.readFile(path.resolve(this.samConfigFile),
|
|
53
|
+
const environment = config.configEnv ?? 'default';
|
|
54
|
+
const samConfigContent = await fs.readFile(path.resolve(this.samConfigFile), 'utf-8');
|
|
55
55
|
const samConfig = toml.parse(samConfigContent);
|
|
56
56
|
const stackName = samConfig[environment]?.global?.parameters?.stack_name;
|
|
57
57
|
if (!stackName) {
|
|
58
58
|
throw new Error(`Stack name not found in ${path.resolve(this.samConfigFile)}`);
|
|
59
59
|
}
|
|
60
|
-
const samTemplateContent = await fs.readFile(path.resolve(this.samTemplateFile),
|
|
60
|
+
const samTemplateContent = await fs.readFile(path.resolve(this.samTemplateFile), 'utf-8');
|
|
61
61
|
const template = yaml.parse(samTemplateContent);
|
|
62
62
|
const lambdas = [];
|
|
63
63
|
// get all resources of type AWS::Serverless::Function
|
|
64
64
|
for (const resourceName in template.Resources) {
|
|
65
65
|
const resource = template.Resources[resourceName];
|
|
66
|
-
if (resource.Type ===
|
|
66
|
+
if (resource.Type === 'AWS::Serverless::Function') {
|
|
67
67
|
lambdas.push({
|
|
68
68
|
Name: resourceName,
|
|
69
69
|
...resource,
|
|
@@ -76,8 +76,8 @@ export class SamFramework {
|
|
|
76
76
|
Logger.verbose(`[SAM] Found Lambdas in stack ${stackName}:`, JSON.stringify(lambdasInStack, null, 2));
|
|
77
77
|
// get tags for each Lambda
|
|
78
78
|
for (const func of lambdas) {
|
|
79
|
-
const handlerFull = path.join(func.Properties.CodeUri ??
|
|
80
|
-
const handlerParts = handlerFull.split(
|
|
79
|
+
const handlerFull = path.join(func.Properties.CodeUri ?? '', func.Properties.Handler);
|
|
80
|
+
const handlerParts = handlerFull.split('.');
|
|
81
81
|
const handler = handlerParts[1];
|
|
82
82
|
const functionName = lambdasInStack.find((lambda) => lambda.logicalId === func.Name)?.lambdaName;
|
|
83
83
|
if (!functionName) {
|
|
@@ -85,9 +85,9 @@ export class SamFramework {
|
|
|
85
85
|
}
|
|
86
86
|
let esBuildOptions = undefined;
|
|
87
87
|
let codePath;
|
|
88
|
-
if (func.Metadata?.BuildMethod?.toLowerCase() ===
|
|
88
|
+
if (func.Metadata?.BuildMethod?.toLowerCase() === 'esbuild') {
|
|
89
89
|
if (func.Metadata?.BuildProperties?.EntryPoints?.length > 0) {
|
|
90
|
-
codePath = path.join(func.Properties.CodeUri ??
|
|
90
|
+
codePath = path.join(func.Properties.CodeUri ?? '', func.Metadata?.BuildProperties?.EntryPoints[0]);
|
|
91
91
|
}
|
|
92
92
|
esBuildOptions = {
|
|
93
93
|
external: func.Metadata?.BuildProperties?.External,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EsBuildOptions, LambdaResource } from
|
|
2
|
-
import type Serverless from
|
|
3
|
-
import { IFramework } from
|
|
4
|
-
import { LldConfigBase } from
|
|
1
|
+
import { EsBuildOptions, LambdaResource } from '../types/resourcesDiscovery.js';
|
|
2
|
+
import type Serverless from 'serverless';
|
|
3
|
+
import { IFramework } from './iFrameworks.js';
|
|
4
|
+
import { LldConfigBase } from '../types/lldConfig.js';
|
|
5
5
|
/**
|
|
6
6
|
* Support for Serverless Framework
|
|
7
7
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
3
|
-
import { constants } from
|
|
4
|
-
import { findPackageJson } from
|
|
5
|
-
import { Logger } from
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { constants } from 'fs';
|
|
4
|
+
import { findPackageJson } from '../utils/findPackageJson.mjs';
|
|
5
|
+
import { Logger } from '../logger.mjs';
|
|
6
6
|
/**
|
|
7
7
|
* Support for Serverless Framework
|
|
8
8
|
*/
|
|
@@ -11,7 +11,7 @@ export class SlsFramework {
|
|
|
11
11
|
* Framework name
|
|
12
12
|
*/
|
|
13
13
|
get name() {
|
|
14
|
-
return
|
|
14
|
+
return 'sls';
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Can this class handle the current project
|
|
@@ -19,11 +19,11 @@ export class SlsFramework {
|
|
|
19
19
|
*/
|
|
20
20
|
async canHandle() {
|
|
21
21
|
const serverlessFiles = [
|
|
22
|
-
path.resolve(
|
|
23
|
-
path.resolve(
|
|
24
|
-
path.resolve(
|
|
25
|
-
path.resolve(
|
|
26
|
-
path.resolve(
|
|
22
|
+
path.resolve('serverless.yml'),
|
|
23
|
+
path.resolve('serverless.yaml'),
|
|
24
|
+
path.resolve('serverless.js'),
|
|
25
|
+
path.resolve('serverless.ts'),
|
|
26
|
+
path.resolve('serverless.json'),
|
|
27
27
|
];
|
|
28
28
|
for (const file of serverlessFiles) {
|
|
29
29
|
try {
|
|
@@ -34,7 +34,7 @@ export class SlsFramework {
|
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
Logger.verbose(`[SLS] This is not a Serverless framework project. None of the files found: ${serverlessFiles.join(
|
|
37
|
+
Logger.verbose(`[SLS] This is not a Serverless framework project. None of the files found: ${serverlessFiles.join(', ')}`);
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
@@ -52,15 +52,15 @@ export class SlsFramework {
|
|
|
52
52
|
// lazy load modules
|
|
53
53
|
resolveConfigurationPath = (await import(
|
|
54
54
|
//@ts-ignore
|
|
55
|
-
|
|
55
|
+
'serverless/lib/cli/resolve-configuration-path.js')).default;
|
|
56
56
|
readConfiguration = (await import(
|
|
57
57
|
//@ts-ignore
|
|
58
|
-
|
|
59
|
-
Serverless = (await import(
|
|
58
|
+
'serverless/lib/configuration/read.js')).default;
|
|
59
|
+
Serverless = (await import('serverless')).default;
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
|
-
Logger.error(
|
|
63
|
-
Logger.log(
|
|
62
|
+
Logger.error('Error loading serverless modules', error);
|
|
63
|
+
Logger.log('If you are running Lambda Live Debugger from a global installation, install Serverless Framework globally as well.');
|
|
64
64
|
throw new Error(`Error loading serverless modules. ${error.message}`, {
|
|
65
65
|
cause: error,
|
|
66
66
|
});
|
|
@@ -123,7 +123,7 @@ export class SlsFramework {
|
|
|
123
123
|
for (const func in lambdas) {
|
|
124
124
|
const lambda = lambdas[func];
|
|
125
125
|
const handlerFull = lambda.handler;
|
|
126
|
-
const handlerParts = handlerFull.split(
|
|
126
|
+
const handlerParts = handlerFull.split('.');
|
|
127
127
|
const handler = handlerParts[1];
|
|
128
128
|
const possibleCodePaths = [
|
|
129
129
|
`${handlerParts[0]}.ts`,
|
|
@@ -166,9 +166,9 @@ export class SlsFramework {
|
|
|
166
166
|
// 1) Get from from LLD specific options in custom.lldEsBuild
|
|
167
167
|
let esBuildOptions = serverless.service.custom?.lldEsBuild;
|
|
168
168
|
// 2) Get from serverless-esbuild plugin
|
|
169
|
-
const esBuildPlugin = serverless.service.plugins?.find((p) => p ===
|
|
169
|
+
const esBuildPlugin = serverless.service.plugins?.find((p) => p === 'serverless-esbuild');
|
|
170
170
|
if (esBuildPlugin) {
|
|
171
|
-
Logger.verbose(
|
|
171
|
+
Logger.verbose('[SLS] serverless-esbuild plugin detected');
|
|
172
172
|
const settings = serverless.service.custom?.esbuild;
|
|
173
173
|
if (settings) {
|
|
174
174
|
esBuildOptions = {
|
|
@@ -180,9 +180,9 @@ export class SlsFramework {
|
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
182
|
// 3) Get from serverless-plugin-typescript plugin
|
|
183
|
-
const typeScriptPlugin = serverless.service.plugins?.find((p) => p ===
|
|
183
|
+
const typeScriptPlugin = serverless.service.plugins?.find((p) => p === 'serverless-plugin-typescript');
|
|
184
184
|
if (typeScriptPlugin) {
|
|
185
|
-
Logger.verbose(
|
|
185
|
+
Logger.verbose('[SLS] serverless-plugin-typescript plugin detected');
|
|
186
186
|
const settings = serverless.service.custom?.serverlessPluginTypescript;
|
|
187
187
|
if (settings) {
|
|
188
188
|
esBuildOptions = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { LambdaResource } from
|
|
3
|
-
import { exec } from
|
|
4
|
-
import { IFramework } from
|
|
5
|
-
import { LldConfigBase } from
|
|
2
|
+
import { LambdaResource } from '../types/resourcesDiscovery.js';
|
|
3
|
+
import { exec } from 'child_process';
|
|
4
|
+
import { IFramework } from './iFrameworks.js';
|
|
5
|
+
import { LldConfigBase } from '../types/lldConfig.js';
|
|
6
6
|
export declare const execAsync: typeof exec.__promisify__;
|
|
7
7
|
interface TerraformState {
|
|
8
8
|
resources: Array<{
|