lambda-live-debugger 0.0.113 → 0.0.115
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 +91 -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 +764 -255
- package/dist/extension/nodejs/node_modules/interceptor.js.map +4 -4
- package/dist/fileWatcher.mjs +11 -11
- package/dist/frameworks/cdkFramework.d.ts +5 -5
- package/dist/frameworks/cdkFramework.mjs +41 -41
- package/dist/frameworks/cdkFrameworkWorker.mjs +13 -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 +15 -15
- package/dist/lldebugger.mjs +23 -24
- package/dist/logger.d.ts +28 -7
- package/dist/logger.mjs +46 -8
- 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 +4 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AwsCredentials } from
|
|
2
|
-
import { Configuration } from
|
|
3
|
-
import { IoTService } from
|
|
4
|
-
import { Logger } from
|
|
5
|
-
import { NodeHandler } from
|
|
1
|
+
import { AwsCredentials } from './awsCredentials.mjs';
|
|
2
|
+
import { Configuration } from './configuration.mjs';
|
|
3
|
+
import { IoTService } from './ioTService.mjs';
|
|
4
|
+
import { Logger } from './logger.mjs';
|
|
5
|
+
import { NodeHandler } from './nodeHandler.mjs';
|
|
6
6
|
let ioTServiceConnection;
|
|
7
7
|
let topic;
|
|
8
8
|
const lambdasProcessingObservableMode = new Set();
|
|
@@ -30,7 +30,7 @@ async function onMessageFromLambda(message) {
|
|
|
30
30
|
if (!Configuration.config.observable) {
|
|
31
31
|
//immediately respond to the ping message to confirm the local debugging is alive
|
|
32
32
|
await ioTServiceConnection.publish({
|
|
33
|
-
type:
|
|
33
|
+
type: 'PING',
|
|
34
34
|
data: {
|
|
35
35
|
workerId: message.data.workerId,
|
|
36
36
|
requestId: message.data.requestId,
|
|
@@ -38,7 +38,7 @@ async function onMessageFromLambda(message) {
|
|
|
38
38
|
},
|
|
39
39
|
}, `${topic}/${message.data.workerId}`);
|
|
40
40
|
}
|
|
41
|
-
if (message.type !==
|
|
41
|
+
if (message.type !== 'INVOKE') {
|
|
42
42
|
throw new Error(`Unexpected message type: ${message.type}`);
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
@@ -58,32 +58,32 @@ async function onMessageFromLambda(message) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
if (Configuration.config.verbose) {
|
|
61
|
-
Logger.
|
|
61
|
+
Logger.log(`[Function ${message.data.functionId}] Response: `, JSON.stringify(message.data, null, 2));
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
64
|
// first 50 characters of the response
|
|
65
65
|
const requestPretty = message.data
|
|
66
66
|
? JSON.stringify(message.data).substring(0, 100)
|
|
67
|
-
:
|
|
68
|
-
Logger.log(`[Function ${message.data.functionId}] Request: ${requestPretty}${requestPretty.length < 50 ?
|
|
67
|
+
: '';
|
|
68
|
+
Logger.log(`[Function ${message.data.functionId}] Request: ${requestPretty}${requestPretty.length < 50 ? '' : '...'}`);
|
|
69
69
|
}
|
|
70
70
|
const response = await NodeHandler.invokeLambda(message.data);
|
|
71
71
|
if (Configuration.config.verbose) {
|
|
72
|
-
Logger.
|
|
72
|
+
Logger.log(`[Function ${message.data.functionId}] Response: `, JSON.stringify(response, null, 2));
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
75
|
// first 50 characters of the response
|
|
76
76
|
const responsePretty = response
|
|
77
77
|
? JSON.stringify(response).substring(0, 100)
|
|
78
|
-
:
|
|
79
|
-
Logger.log(`[Function ${message.data.functionId}] Response: ${responsePretty}${responsePretty.length < 50 ?
|
|
78
|
+
: '';
|
|
79
|
+
Logger.log(`[Function ${message.data.functionId}] Response: ${responsePretty}${responsePretty.length < 50 ? '' : '...'}`);
|
|
80
80
|
}
|
|
81
81
|
if (Configuration.config.observable) {
|
|
82
82
|
// if we are in observable mode, mark the worker as processed
|
|
83
83
|
lambdasProcessingObservableMode.delete(message.data.functionId);
|
|
84
84
|
}
|
|
85
85
|
const payload = {
|
|
86
|
-
type:
|
|
86
|
+
type: 'SUCCESS',
|
|
87
87
|
data: {
|
|
88
88
|
functionId: message.data.functionId,
|
|
89
89
|
requestId: message.data.requestId,
|
|
@@ -98,7 +98,7 @@ async function onMessageFromLambda(message) {
|
|
|
98
98
|
catch (e) {
|
|
99
99
|
Logger.error(`[Function ${message.data.functionId}] Error: `, e);
|
|
100
100
|
const payload = {
|
|
101
|
-
type:
|
|
101
|
+
type: 'ERROR',
|
|
102
102
|
data: {
|
|
103
103
|
functionId: message.data.functionId,
|
|
104
104
|
requestId: message.data.requestId,
|
package/dist/lldebugger.mjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// ****** support require in for CJS modules ******
|
|
3
|
-
import { createRequire } from
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
const require = createRequire(import.meta.url);
|
|
6
6
|
global.require = require;
|
|
7
|
-
import { InfraDeploy } from
|
|
8
|
-
import { getVersion } from
|
|
9
|
-
import { Configuration } from
|
|
10
|
-
import { FileWatcher } from
|
|
11
|
-
import { GitIgnore } from
|
|
12
|
-
import { VsCode } from
|
|
13
|
-
import path from
|
|
14
|
-
import { getRootFolder } from
|
|
15
|
-
import fs from
|
|
16
|
-
import { Logger } from
|
|
17
|
-
import { getModuleDirname, getProjectDirname } from
|
|
18
|
-
import { LambdaConnection } from
|
|
7
|
+
import { InfraDeploy } from './infraDeploy.mjs';
|
|
8
|
+
import { getVersion } from './version.mjs';
|
|
9
|
+
import { Configuration } from './configuration.mjs';
|
|
10
|
+
import { FileWatcher } from './fileWatcher.mjs';
|
|
11
|
+
import { GitIgnore } from './gitignore.mjs';
|
|
12
|
+
import { VsCode } from './vsCode.mjs';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import { getRootFolder } from './utils/getRootFolder.mjs';
|
|
15
|
+
import fs from 'fs/promises';
|
|
16
|
+
import { Logger } from './logger.mjs';
|
|
17
|
+
import { getModuleDirname, getProjectDirname } from './getDirname.mjs';
|
|
18
|
+
import { LambdaConnection } from './lambdaConnection.mjs';
|
|
19
19
|
/**
|
|
20
20
|
* Start the Lambda Live Debugger
|
|
21
21
|
*/
|
|
22
22
|
async function run() {
|
|
23
23
|
const version = await getVersion();
|
|
24
24
|
Logger.log(`Welcome to Lambda Live Debugger 🐞 version ${version}.`);
|
|
25
|
-
Logger.
|
|
25
|
+
Logger.important('To keep the project moving forward, please fill out the feedback form at https://forms.gle/v6ekZtuB45Rv3EyW9. Your input is greatly appreciated!');
|
|
26
26
|
await Configuration.readConfig();
|
|
27
27
|
Logger.setVerbose(Configuration.config.verbose === true);
|
|
28
28
|
Logger.verbose(`Parameters: \n${Object.entries(Configuration.config)
|
|
29
29
|
.map(([key, value]) => ` - ${key}=${value}`)
|
|
30
|
-
.join(
|
|
30
|
+
.join('\n')}`);
|
|
31
31
|
Logger.verbose(`NPM module folder: ${getModuleDirname()}`);
|
|
32
32
|
Logger.verbose(`Project folder: ${getProjectDirname()}`);
|
|
33
33
|
if (Configuration.config.gitignore) {
|
|
@@ -40,9 +40,8 @@ async function run() {
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
Logger.log(`Starting the debugger ${Configuration.config.observable
|
|
43
|
-
?
|
|
44
|
-
: `(ID ${Configuration.config.debuggerId})`}
|
|
45
|
-
...`);
|
|
43
|
+
? 'in observable mode'
|
|
44
|
+
: `(ID ${Configuration.config.debuggerId})`}...`);
|
|
46
45
|
if (Configuration.config.subfolder) {
|
|
47
46
|
// change the current working directory to the subfolder for monorepos
|
|
48
47
|
const newCurrentFolder = path.resolve(Configuration.config.subfolder);
|
|
@@ -51,28 +50,28 @@ async function run() {
|
|
|
51
50
|
}
|
|
52
51
|
await Configuration.discoverLambdas();
|
|
53
52
|
if (Configuration.config.remove) {
|
|
54
|
-
Logger.log(`Removing Lambda Live Debugger${Configuration.config.remove ===
|
|
53
|
+
Logger.log(`Removing Lambda Live Debugger${Configuration.config.remove === 'all' ? ' including layer' : ''}...`);
|
|
55
54
|
await InfraDeploy.removeInfrastructure();
|
|
56
55
|
// await GitIgnore.removeFromGitIgnore();
|
|
57
56
|
// delete folder .lldebugger
|
|
58
|
-
const folder = path.join(getProjectDirname(),
|
|
57
|
+
const folder = path.join(getProjectDirname(), '.lldebugger');
|
|
59
58
|
Logger.verbose(`Removing ${folder} folder...`);
|
|
60
59
|
await fs.rm(folder, { recursive: true });
|
|
61
|
-
if (Configuration.config.remove ===
|
|
60
|
+
if (Configuration.config.remove === 'all') {
|
|
62
61
|
await InfraDeploy.deleteLayer();
|
|
63
62
|
}
|
|
64
|
-
Logger.log(
|
|
63
|
+
Logger.log('Lambda Live Debugger removed!');
|
|
65
64
|
return;
|
|
66
65
|
}
|
|
67
66
|
await InfraDeploy.deployInfrastructure();
|
|
68
67
|
const folders = [
|
|
69
|
-
path.resolve(
|
|
68
|
+
path.resolve('.'),
|
|
70
69
|
...Configuration.getLambdas().map((l) => l.codePath),
|
|
71
70
|
];
|
|
72
71
|
// get the uppermost folder of all lambdas or the project root to watch for changes
|
|
73
72
|
const rootFolderForWarchingChanges = getRootFolder(folders);
|
|
74
73
|
FileWatcher.watchForFileChanges(rootFolderForWarchingChanges);
|
|
75
74
|
await LambdaConnection.connect();
|
|
76
|
-
Logger.log(
|
|
75
|
+
Logger.log('Debugger started!');
|
|
77
76
|
}
|
|
78
77
|
run().catch(Logger.error);
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Log
|
|
3
|
-
* @param args
|
|
2
|
+
* Log a message
|
|
3
|
+
* @param args The arguments to log
|
|
4
|
+
*/
|
|
5
|
+
declare function log(...args: any[]): void;
|
|
6
|
+
/**
|
|
7
|
+
* Log an important message
|
|
8
|
+
* @param args The arguments to log
|
|
9
|
+
*/
|
|
10
|
+
declare function important(...args: any[]): void;
|
|
11
|
+
/**
|
|
12
|
+
* Log an error message in red
|
|
13
|
+
* @param args The arguments to log
|
|
14
|
+
*/
|
|
15
|
+
declare function error(...args: any[]): void;
|
|
16
|
+
/**
|
|
17
|
+
* Log a warning message in orange
|
|
18
|
+
* @param args The arguments to log
|
|
19
|
+
*/
|
|
20
|
+
declare function warn(...args: any[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Log a verbose message if verbose is enabled. Log the message in grey.
|
|
23
|
+
* @param args The arguments to log
|
|
4
24
|
*/
|
|
5
25
|
declare function verbose(...args: any[]): void;
|
|
6
26
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param enabled
|
|
27
|
+
* Set the verbosity of logging
|
|
28
|
+
* @param enabled Whether verbose logging should be enabled
|
|
9
29
|
*/
|
|
10
30
|
declare function setVerbose(enabled: boolean): void;
|
|
11
31
|
export declare const Logger: {
|
|
12
|
-
log:
|
|
13
|
-
error:
|
|
14
|
-
warn:
|
|
32
|
+
log: typeof log;
|
|
33
|
+
error: typeof error;
|
|
34
|
+
warn: typeof warn;
|
|
35
|
+
important: typeof important;
|
|
15
36
|
verbose: typeof verbose;
|
|
16
37
|
setVerbose: typeof setVerbose;
|
|
17
38
|
};
|
package/dist/logger.mjs
CHANGED
|
@@ -1,24 +1,62 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
const orange = '#D24E01';
|
|
1
3
|
let verboseEnabled = false;
|
|
2
4
|
/**
|
|
3
|
-
* Log
|
|
4
|
-
* @param args
|
|
5
|
+
* Log a message
|
|
6
|
+
* @param args The arguments to log
|
|
7
|
+
*/
|
|
8
|
+
function log(...args) {
|
|
9
|
+
args = args.map((arg) => {
|
|
10
|
+
if (typeof arg === 'string') {
|
|
11
|
+
// Regular expression to find text within square brackets
|
|
12
|
+
return arg.replace(/\[(.*?)\]/g, (match) => chalk.gray(match)); // Colorizes the entire bracketed content
|
|
13
|
+
}
|
|
14
|
+
return arg;
|
|
15
|
+
});
|
|
16
|
+
console.log(...args);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Log an important message
|
|
20
|
+
* @param args The arguments to log
|
|
21
|
+
*/
|
|
22
|
+
function important(...args) {
|
|
23
|
+
console.log(chalk.hex(orange)(...args));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Log an error message in red
|
|
27
|
+
* @param args The arguments to log
|
|
28
|
+
*/
|
|
29
|
+
function error(...args) {
|
|
30
|
+
console.error(chalk.red(...args));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Log a warning message in orange
|
|
34
|
+
* @param args The arguments to log
|
|
35
|
+
*/
|
|
36
|
+
function warn(...args) {
|
|
37
|
+
console.warn(chalk.hex(orange)(...args));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Log a verbose message if verbose is enabled. Log the message in grey.
|
|
41
|
+
* @param args The arguments to log
|
|
5
42
|
*/
|
|
6
43
|
function verbose(...args) {
|
|
7
44
|
if (verboseEnabled) {
|
|
8
|
-
console.info(...args);
|
|
45
|
+
console.info(chalk.grey(...args));
|
|
9
46
|
}
|
|
10
47
|
}
|
|
11
48
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param enabled
|
|
49
|
+
* Set the verbosity of logging
|
|
50
|
+
* @param enabled Whether verbose logging should be enabled
|
|
14
51
|
*/
|
|
15
52
|
function setVerbose(enabled) {
|
|
16
53
|
verboseEnabled = enabled;
|
|
17
54
|
}
|
|
18
55
|
export const Logger = {
|
|
19
|
-
log
|
|
20
|
-
error
|
|
21
|
-
warn
|
|
56
|
+
log,
|
|
57
|
+
error,
|
|
58
|
+
warn,
|
|
59
|
+
important,
|
|
22
60
|
verbose,
|
|
23
61
|
setVerbose,
|
|
24
62
|
};
|
package/dist/nodeEsBuild.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import * as path from
|
|
2
|
-
import * as fs from
|
|
3
|
-
import * as esbuild from
|
|
4
|
-
import { Configuration } from
|
|
5
|
-
import { Logger } from
|
|
6
|
-
import { getProjectDirname } from
|
|
7
|
-
import { outputFolder } from
|
|
8
|
-
import { combineArray } from
|
|
9
|
-
import { combineObject } from
|
|
10
|
-
import { combineObjectStrings } from
|
|
11
|
-
import { removeUndefinedProperties } from
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
|
+
import * as esbuild from 'esbuild';
|
|
4
|
+
import { Configuration } from './configuration.mjs';
|
|
5
|
+
import { Logger } from './logger.mjs';
|
|
6
|
+
import { getProjectDirname } from './getDirname.mjs';
|
|
7
|
+
import { outputFolder } from './constants.mjs';
|
|
8
|
+
import { combineArray } from './utils/combineArray.mjs';
|
|
9
|
+
import { combineObject } from './utils/combineObject.mjs';
|
|
10
|
+
import { combineObjectStrings } from './utils/combineObjectStrings.mjs';
|
|
11
|
+
import { removeUndefinedProperties } from './utils/removeUndefinedProperties.mjs';
|
|
12
12
|
const buildCache = {};
|
|
13
13
|
/**
|
|
14
14
|
* Get the build for the function
|
|
@@ -20,9 +20,9 @@ async function getBuild(functionId) {
|
|
|
20
20
|
let newBuild = false;
|
|
21
21
|
const func = await Configuration.getLambda(functionId);
|
|
22
22
|
// if handler is a JavaScript file and not force bundle, just return the file
|
|
23
|
-
if ((func.codePath.endsWith(
|
|
24
|
-
func.codePath.endsWith(
|
|
25
|
-
func.codePath.endsWith(
|
|
23
|
+
if ((func.codePath.endsWith('.js') ||
|
|
24
|
+
func.codePath.endsWith('.mjs') ||
|
|
25
|
+
func.codePath.endsWith('.cjs')) &&
|
|
26
26
|
!func.forceBundle) {
|
|
27
27
|
return func.codePath;
|
|
28
28
|
}
|
|
@@ -54,7 +54,7 @@ async function getBuild(functionId) {
|
|
|
54
54
|
if (newBuild) {
|
|
55
55
|
Logger.verbose(`[Function ${functionId}] Build complete`);
|
|
56
56
|
}
|
|
57
|
-
const artifactFile = Object.keys(result.metafile.outputs).find((key) => key.endsWith(
|
|
57
|
+
const artifactFile = Object.keys(result.metafile.outputs).find((key) => key.endsWith('.js'));
|
|
58
58
|
if (!artifactFile) {
|
|
59
59
|
throw new Error(`Artifact file not found for function ${functionId}`);
|
|
60
60
|
}
|
|
@@ -81,15 +81,15 @@ async function build(input) {
|
|
|
81
81
|
const packageJsonPath = input.function.packageJsonPath;
|
|
82
82
|
let isESMFromPackageJson = false;
|
|
83
83
|
if (packageJsonPath) {
|
|
84
|
-
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding:
|
|
85
|
-
isESMFromPackageJson = packageJson.type ===
|
|
84
|
+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: 'utf-8' }));
|
|
85
|
+
isESMFromPackageJson = packageJson.type === 'module';
|
|
86
86
|
}
|
|
87
|
-
const isESMFromBundling = esbuildOptions?.format ===
|
|
87
|
+
const isESMFromBundling = esbuildOptions?.format === 'esm' ? true : undefined;
|
|
88
88
|
let isESM;
|
|
89
89
|
if (isESMFromPackageJson !== undefined &&
|
|
90
90
|
isESMFromBundling !== undefined &&
|
|
91
91
|
isESMFromPackageJson !== isESMFromBundling) {
|
|
92
|
-
Logger.warn(`WARNING! Mismatch module type between package.json and bundling options for ${handlerCodePath}. Package.json: ${isESMFromPackageJson ?
|
|
92
|
+
Logger.warn(`WARNING! Mismatch module type between package.json and bundling options for ${handlerCodePath}. Package.json: ${isESMFromPackageJson ? 'ESM' : 'CJS'}, bundling options: ${isESMFromBundling ? 'ESM' : 'CJS'}. Using ${isESMFromBundling ? 'ESM' : 'CJS'} from bunding otions.`);
|
|
93
93
|
isESM = isESMFromBundling;
|
|
94
94
|
}
|
|
95
95
|
else if (isESMFromPackageJson !== undefined) {
|
|
@@ -102,35 +102,35 @@ async function build(input) {
|
|
|
102
102
|
isESM = false;
|
|
103
103
|
}
|
|
104
104
|
let ctx = input.oldCtx;
|
|
105
|
-
Logger.verbose(`[Function ${input.functionId}] Module type: ${isESM ?
|
|
105
|
+
Logger.verbose(`[Function ${input.functionId}] Module type: ${isESM ? 'ESM' : 'CJS'})`);
|
|
106
106
|
if (!ctx) {
|
|
107
107
|
const optionsDefault = {
|
|
108
108
|
entryPoints: [handlerCodePath],
|
|
109
|
-
platform:
|
|
109
|
+
platform: 'node',
|
|
110
110
|
keepNames: true,
|
|
111
111
|
bundle: true,
|
|
112
|
-
logLevel:
|
|
112
|
+
logLevel: 'silent',
|
|
113
113
|
metafile: true,
|
|
114
114
|
...(isESM
|
|
115
115
|
? {
|
|
116
|
-
format:
|
|
117
|
-
target:
|
|
118
|
-
mainFields: [
|
|
116
|
+
format: 'esm',
|
|
117
|
+
target: 'esnext',
|
|
118
|
+
mainFields: ['module', 'main'],
|
|
119
119
|
banner: {
|
|
120
120
|
js: [
|
|
121
121
|
`import { createRequire as topLevelCreateRequire } from 'module';`,
|
|
122
122
|
`global.require = global.require ?? topLevelCreateRequire(import.meta.url);`,
|
|
123
123
|
`import { fileURLToPath as topLevelFileUrlToPath, URL as topLevelURL } from "url"`,
|
|
124
124
|
`global.__dirname = global.__dirname ?? topLevelFileUrlToPath(new topLevelURL(".", import.meta.url))`,
|
|
125
|
-
].join(
|
|
125
|
+
].join('\n'),
|
|
126
126
|
},
|
|
127
127
|
}
|
|
128
128
|
: {
|
|
129
|
-
format:
|
|
130
|
-
target:
|
|
129
|
+
format: 'cjs',
|
|
130
|
+
target: 'node14',
|
|
131
131
|
}),
|
|
132
132
|
outdir: targetFolder,
|
|
133
|
-
sourcemap:
|
|
133
|
+
sourcemap: 'linked',
|
|
134
134
|
};
|
|
135
135
|
const options = {
|
|
136
136
|
...optionsDefault,
|
|
@@ -161,7 +161,7 @@ async function build(input) {
|
|
|
161
161
|
if (input.function.packageJsonPath) {
|
|
162
162
|
const from = path.resolve(input.function.packageJsonPath);
|
|
163
163
|
Logger.verbose(`[Function ${input.functionId}] package.json: ${from}`);
|
|
164
|
-
const to = path.resolve(path.join(targetFolder,
|
|
164
|
+
const to = path.resolve(path.join(targetFolder, 'package.json'));
|
|
165
165
|
await fs.copyFile(from, to);
|
|
166
166
|
}
|
|
167
167
|
else {
|
package/dist/nodeHandler.d.ts
CHANGED
package/dist/nodeHandler.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as path from
|
|
2
|
-
import * as fs from
|
|
3
|
-
import { NodeEsBuild } from
|
|
4
|
-
import { NodeWorker } from
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
|
+
import { NodeEsBuild } from './nodeEsBuild.mjs';
|
|
4
|
+
import { NodeWorker } from './nodeWorker.mjs';
|
|
5
5
|
/**
|
|
6
6
|
* Build the Lambda function
|
|
7
7
|
* @param functionId
|
package/dist/nodeWorker.d.ts
CHANGED
package/dist/nodeWorker.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Worker } from
|
|
2
|
-
import * as path from
|
|
3
|
-
import { Configuration } from
|
|
4
|
-
import { getModuleDirname, getProjectDirname } from
|
|
5
|
-
import { Logger } from
|
|
1
|
+
import { Worker } from 'node:worker_threads';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { Configuration } from './configuration.mjs';
|
|
4
|
+
import { getModuleDirname, getProjectDirname } from './getDirname.mjs';
|
|
5
|
+
import { Logger } from './logger.mjs';
|
|
6
6
|
const workers = new Map();
|
|
7
7
|
/**
|
|
8
8
|
* Run the function in a Node.js Worker Thread
|
|
@@ -15,7 +15,7 @@ async function runInWorker(input) {
|
|
|
15
15
|
let worker = workers.get(input.fuctionRequest.workerId);
|
|
16
16
|
if (!worker) {
|
|
17
17
|
worker = startWorker({
|
|
18
|
-
handler: func.handler ??
|
|
18
|
+
handler: func.handler ?? 'handler',
|
|
19
19
|
artifactFile: input.artifactFile,
|
|
20
20
|
workerId: input.fuctionRequest.workerId,
|
|
21
21
|
functionId: input.fuctionRequest.functionId,
|
|
@@ -26,7 +26,7 @@ async function runInWorker(input) {
|
|
|
26
26
|
else {
|
|
27
27
|
Logger.verbose(`[Function ${input.fuctionRequest.functionId}] [Worker ${input.fuctionRequest.workerId}] Reusing worker`);
|
|
28
28
|
}
|
|
29
|
-
worker.on(
|
|
29
|
+
worker.on('message', (msg) => {
|
|
30
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);
|
|
@@ -35,7 +35,7 @@ async function runInWorker(input) {
|
|
|
35
35
|
resolve(msg);
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
worker.on(
|
|
38
|
+
worker.on('error', (err) => {
|
|
39
39
|
Logger.error(`[Function ${input.fuctionRequest.functionId}] [Worker ${input.fuctionRequest.workerId}] Error`, err);
|
|
40
40
|
reject(err);
|
|
41
41
|
});
|
|
@@ -57,23 +57,23 @@ function startWorker(input) {
|
|
|
57
57
|
const worker = new Worker(path.resolve(path.join(getModuleDirname(), `./nodeWorkerRunner.mjs`)), {
|
|
58
58
|
env: {
|
|
59
59
|
...input.environment,
|
|
60
|
-
IS_LOCAL:
|
|
60
|
+
IS_LOCAL: 'true',
|
|
61
61
|
LOCAL_PROJECT_DIR: localProjectDir,
|
|
62
62
|
},
|
|
63
|
-
execArgv: [
|
|
63
|
+
execArgv: ['--enable-source-maps'],
|
|
64
64
|
workerData: input,
|
|
65
65
|
stderr: true,
|
|
66
66
|
stdin: true,
|
|
67
67
|
stdout: true,
|
|
68
68
|
//type: "module",
|
|
69
69
|
});
|
|
70
|
-
worker.stdout.on(
|
|
70
|
+
worker.stdout.on('data', (data) => {
|
|
71
71
|
Logger.verbose(`[Function ${input.functionId}] [Worker ${input.workerId}] `, data.toString());
|
|
72
72
|
});
|
|
73
|
-
worker.stderr.on(
|
|
73
|
+
worker.stderr.on('data', (data) => {
|
|
74
74
|
Logger.verbose(`[Function ${input.functionId}] [Worker ${input.workerId}] `, data.toString());
|
|
75
75
|
});
|
|
76
|
-
worker.on(
|
|
76
|
+
worker.on('exit', () => {
|
|
77
77
|
Logger.verbose(`[Function ${input.functionId}] [Worker ${input.workerId}] Worker exited`);
|
|
78
78
|
workers.delete(input.workerId);
|
|
79
79
|
});
|
|
@@ -84,7 +84,7 @@ function startWorker(input) {
|
|
|
84
84
|
* Stop all Node.js Worker Threads
|
|
85
85
|
*/
|
|
86
86
|
async function stopAllWorkers() {
|
|
87
|
-
Logger.verbose(
|
|
87
|
+
Logger.verbose('Stopping all workers');
|
|
88
88
|
const promises = [];
|
|
89
89
|
for (const worker of workers.values()) {
|
|
90
90
|
promises.push(worker.terminate());
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { createRequire as topLevelCreateRequire } from
|
|
1
|
+
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
3
|
const require = topLevelCreateRequire(import.meta.url);
|
|
4
4
|
|
|
5
|
-
import { workerData, parentPort } from
|
|
6
|
-
import { Logger } from
|
|
5
|
+
import { workerData, parentPort } from 'node:worker_threads';
|
|
6
|
+
import { Logger } from './logger.mjs';
|
|
7
7
|
|
|
8
8
|
Logger.setVerbose(workerData.verbose);
|
|
9
9
|
Logger.verbose(
|
|
10
10
|
`[Function ${workerData.functionId}] [Worker ${workerData.workerId}] Worker started.`,
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
-
parentPort.on(
|
|
13
|
+
parentPort.on('message', async (data) => {
|
|
14
14
|
Logger.verbose(`[Worker ${workerData.workerId}] Received message`, data);
|
|
15
15
|
const mod = await import(workerData.artifactFile);
|
|
16
16
|
const fn = mod[workerData.handler];
|
|
@@ -21,17 +21,17 @@ parentPort.on("message", async (data) => {
|
|
|
21
21
|
getRemainingTimeInMillis: () => 2147483647, // Max 32-bit signed integer
|
|
22
22
|
done() {
|
|
23
23
|
throw new Error(
|
|
24
|
-
|
|
24
|
+
'`done` function on lambda Context is not implemented in Lambda Live Debugger.',
|
|
25
25
|
);
|
|
26
26
|
},
|
|
27
27
|
fail() {
|
|
28
28
|
throw new Error(
|
|
29
|
-
|
|
29
|
+
'`fail` function on lambda Context is not implemented in Lambda Live Debugger.',
|
|
30
30
|
);
|
|
31
31
|
},
|
|
32
32
|
succeed() {
|
|
33
33
|
throw new Error(
|
|
34
|
-
|
|
34
|
+
'`succeed` function on lambda Context is not implemented in Lambda Live Debugger.',
|
|
35
35
|
);
|
|
36
36
|
},
|
|
37
37
|
};
|
|
@@ -47,7 +47,7 @@ parentPort.on("message", async (data) => {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
process.on(
|
|
50
|
+
process.on('unhandledRejection', (error) => {
|
|
51
51
|
Logger.error(
|
|
52
52
|
`[Function ${workerData.functionId}] [Worker ${workerData.workerId}] Unhandled Rejection`,
|
|
53
53
|
error,
|
|
@@ -57,7 +57,7 @@ process.on("unhandledRejection", (error) => {
|
|
|
57
57
|
|
|
58
58
|
function handleError(error) {
|
|
59
59
|
parentPort.postMessage({
|
|
60
|
-
errorType: error.name ??
|
|
60
|
+
errorType: error.name ?? 'Error',
|
|
61
61
|
errorMessage: error.message,
|
|
62
62
|
trace: error.stack,
|
|
63
63
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { cdkFramework } from
|
|
2
|
-
import { slsFramework } from
|
|
3
|
-
import { samFramework } from
|
|
4
|
-
import { terraformFramework } from
|
|
5
|
-
import { Logger } from
|
|
6
|
-
import path from
|
|
1
|
+
import { cdkFramework } from './frameworks/cdkFramework.mjs';
|
|
2
|
+
import { slsFramework } from './frameworks/slsFramework.mjs';
|
|
3
|
+
import { samFramework } from './frameworks/samFramework.mjs';
|
|
4
|
+
import { terraformFramework } from './frameworks/terraformFramework.mjs';
|
|
5
|
+
import { Logger } from './logger.mjs';
|
|
6
|
+
import path from 'node:path';
|
|
7
7
|
/**
|
|
8
8
|
* List of supported frameworks
|
|
9
9
|
*/
|
|
@@ -30,7 +30,7 @@ async function getLambdas(config) {
|
|
|
30
30
|
let resources = undefined;
|
|
31
31
|
let frameworks = [...frameworksSupported];
|
|
32
32
|
if (config.framework) {
|
|
33
|
-
if (config.framework ===
|
|
33
|
+
if (config.framework === 'none') {
|
|
34
34
|
frameworks = [];
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
@@ -46,7 +46,7 @@ async function getLambdas(config) {
|
|
|
46
46
|
resources = resources.filter(
|
|
47
47
|
// filter by function name, can use * as wildcard
|
|
48
48
|
(l) => l.functionName === functionNameFilter ||
|
|
49
|
-
new RegExp(
|
|
49
|
+
new RegExp('^' + functionNameFilter.split('*').join('.*') + '$').test(l.functionName));
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
else {
|