Skip to content

Commit 5f275bb

Browse files
committed
chore: drop support for very old node versions
1 parent 8530e8d commit 5f275bb

File tree

12 files changed

+290
-244
lines changed

12 files changed

+290
-244
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
### Minimum requirements
2222

23-
- Node v14.17.0+
23+
- Node v18.20.4+
2424
- Serverless 2.0.0+ < 4.0
2525

2626
---
@@ -179,7 +179,7 @@ Invoking with `aws-sdk` Lambda Client requires to set client endpoint to local s
179179
Example:
180180
181181
```js
182-
const { LambdaClient, InvokeCommand } = require("@aws-sdk/client-lambda");
182+
import { LambdaClient, InvokeCommand } from "@aws-sdk/client-lambda";
183183
184184
const client = new LambdaClient({ region: "us-east-1", endpoint: "http://localhost:3000" });
185185
const DryRun = "DryRun";

build.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ const esBuildConfig = {
2626
bundle: true,
2727
minify: !shouldWatch,
2828
platform: "node",
29-
target: "ES6",
29+
target: "node18",
3030
outdir: "dist",
31-
format: "cjs",
3231
plugins: [watchPlugin],
3332
dropLabels: shouldWatch ? [] : ["DEV"],
3433
drop: shouldWatch ? [] : ["debugger"],
@@ -39,7 +38,6 @@ const bundle = shouldWatch ? esbuild.context : esbuild.build;
3938
const buildIndex = bundle.bind(null, {
4039
...esBuildConfig,
4140
entryPoints: [
42-
"./src/index.ts",
4341
"./src/server.ts",
4442
"./src/defineConfig.ts",
4543
"./src/lib/runtime/runners/node/index.ts",
@@ -49,18 +47,20 @@ const buildIndex = bundle.bind(null, {
4947
"./src/plugins/s3/index.ts",
5048
"./src/lambda/body-parser.ts",
5149
],
50+
format: "cjs",
5251
});
5352

5453
const buildRouterESM = bundle.bind(null, {
5554
...esBuildConfig,
5655
entryPoints: [
57-
"./src/lambda/router.ts",
56+
"./src/index.ts",
5857
"./src/server.ts",
59-
"./src/lambda/body-parser.ts",
6058
"./src/defineConfig.ts",
59+
"./src/lambda/router.ts",
6160
"./src/plugins/sns/index.ts",
6261
"./src/plugins/sqs/index.ts",
6362
"./src/plugins/s3/index.ts",
63+
"./src/lambda/body-parser.ts",
6464
],
6565
format: "esm",
6666
outExtension: { ".js": ".mjs" },

package.json

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-aws-lambda",
3-
"version": "4.8.4",
3+
"version": "5.0.0",
44
"description": "AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.",
55
"author": "Inqnuam",
66
"license": "MIT",
@@ -12,56 +12,64 @@
1212
"bugs": {
1313
"url": "https://github.com/inqnuam/serverless-aws-lambda/issues"
1414
},
15-
"main": "./dist/index.js",
15+
"main": "./dist/index.mjs",
1616
"typings": "./dist/config.d.ts",
1717
"exports": {
1818
".": {
19-
"require": "./dist/index.js"
19+
"import": "./dist/index.mjs",
20+
"default": "./dist/index.mjs"
2021
},
2122
"./defineConfig": {
2223
"types": "./dist/defineConfig.d.ts",
2324
"require": "./dist/defineConfig.js",
24-
"import": "./dist/defineConfig.mjs"
25+
"import": "./dist/defineConfig.mjs",
26+
"default": "./dist/defineConfig.mjs"
2527
},
2628
"./router": {
2729
"types": "./dist/lambda/router.d.ts",
2830
"require": "./dist/lambda/router.js",
29-
"import": "./dist/lambda/router.mjs"
31+
"import": "./dist/lambda/router.mjs",
32+
"default": "./dist/lambda/router.mjs"
3033
},
3134
"./body-parser": {
3235
"types": "./dist/lambda/body-parser.d.ts",
3336
"require": "./dist/lambda/body-parser.js",
34-
"import": "./dist/lambda/body-parser.mjs"
37+
"import": "./dist/lambda/body-parser.mjs",
38+
"default": "./dist/lambda/body-parser.mjs"
3539
},
3640
"./server": {
3741
"types": "./dist/server.d.ts",
3842
"require": "./dist/server.js",
39-
"import": "./dist/server.mjs"
43+
"import": "./dist/server.mjs",
44+
"default": "./dist/server.mjs"
4045
},
4146
"./sns": {
4247
"types": "./dist/plugins/sns/index.d.ts",
4348
"require": "./dist/plugins/sns/index.js",
44-
"import": "./dist/plugins/sns/index.mjs"
49+
"import": "./dist/plugins/sns/index.mjs",
50+
"default": "./dist/plugins/sns/index.mjs"
4551
},
4652
"./sqs": {
4753
"types": "./dist/plugins/sqs/index.d.ts",
4854
"require": "./dist/plugins/sqs/index.js",
49-
"import": "./dist/plugins/sqs/index.mjs"
55+
"import": "./dist/plugins/sqs/index.mjs",
56+
"default": "./dist/plugins/sqs/index.mjs"
5057
},
5158
"./s3": {
5259
"types": "./dist/plugins/s3/index.d.ts",
5360
"require": "./dist/plugins/s3/index.js",
54-
"import": "./dist/plugins/s3/index.mjs"
61+
"import": "./dist/plugins/s3/index.mjs",
62+
"default": "./dist/plugins/s3/index.mjs"
5563
}
5664
},
5765
"dependencies": {
58-
"@aws-sdk/client-sqs": "^3.651.1",
59-
"@smithy/eventstream-codec": "^2.2.0",
66+
"@aws-sdk/client-sqs": "^3.682.0",
67+
"@smithy/eventstream-codec": "^3.1.7",
6068
"@types/serverless": "^3.12.22",
61-
"ajv": "^8.16.0",
69+
"ajv": "^8.17.1",
6270
"ajv-formats": "^3.0.1",
6371
"archiver": "^5.3.1",
64-
"esbuild": "0.23.1",
72+
"esbuild": "0.24.0",
6573
"fast-xml-parser": "^4.5.0",
6674
"local-aws-sqs": "^1.0.2",
6775
"serve-static": "^1.15.0"
@@ -70,8 +78,8 @@
7078
"@types/archiver": "^5.3.2",
7179
"@types/node": "^14.14.31",
7280
"@types/serve-static": "^1.15.5",
73-
"typescript": "^5.6.2",
74-
"vitest": "^2.1.1"
81+
"typescript": "^5.6.3",
82+
"vitest": "^2.1.4"
7583
},
7684
"keywords": [
7785
"aws",
@@ -98,6 +106,7 @@
98106
],
99107
"scripts": {
100108
"dev": "DEV=true node ./build.mjs",
101-
"build": "node ./build.mjs"
109+
"build": "node ./build.mjs",
110+
"test": "vitest"
102111
}
103112
}

src/lib/esbuild/buildOptimizer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { Plugin, BuildResult } from "esbuild";
22
import { knownCjs } from "./knownCjs";
3-
3+
import path from "path";
44
const awsSdkV2 = "aws-sdk";
55
const awsSdkV3 = "@aws-sdk/*";
6-
const awslambda = `${__dirname.slice(0, -5)}/src/lib/runtime/awslambda.ts`;
6+
const awslambda = `${path
7+
.dirname(import.meta.url)
8+
.replace("file://", "")
9+
.slice(0, -5)}/src/lib/runtime/awslambda.ts`;
710
const requirePoly = (nodePrefix: "node:" | "") =>
811
`import { createRequire as __crE_ } from "${nodePrefix}module";import { fileURLToPath as __futP_ } from "${nodePrefix}url";import { dirname as __dN_ } from "${nodePrefix}path";global.__filename = __futP_(import.meta.url);global.__dirname = __dN_(__filename);global.require = __crE_(__filename);\n`;
912

src/lib/runtime/runners/node/runner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { WorkerOptions } from "worker_threads";
55
import path from "path";
66
import { log } from "../../../utils/colorize";
77
import { BufferedStreamResponse } from "../../bufferedStreamResponse";
8+
import { fileURLToPath } from "url";
9+
const moduleDirname = fileURLToPath(new URL(".", import.meta.url));
810

911
export class NodeRunner extends EventEmitter implements Runner {
1012
_worker?: Worker;
@@ -138,7 +140,7 @@ export class NodeRunner extends EventEmitter implements Runner {
138140
},
139141
};
140142

141-
this._worker = new Worker(path.resolve(__dirname, "./lib/runtime/runners/node/index.js"), opt);
143+
this._worker = new Worker(path.resolve(moduleDirname, "./lib/runtime/runners/node/index.js"), opt);
142144
this._worker.setMaxListeners(0);
143145

144146
const errorHandler = (err: any) => {

src/lib/runtime/runners/python/runner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import { access } from "fs/promises";
55
import type { Runner } from "../index";
66
import type { ChildProcessWithoutNullStreams } from "child_process";
77
import type { FSWatcher } from "fs";
8+
import { fileURLToPath } from "url";
89

10+
const moduleDirname = fileURLToPath(new URL(".", import.meta.url));
911
const cwd = process.cwd();
12+
1013
export class PythonRunner implements Runner {
1114
invoke: Runner["invoke"];
1215
mount: Runner["mount"];
@@ -28,7 +31,7 @@ export class PythonRunner implements Runner {
2831
filesTime: Map<string, number> = new Map();
2932
watcherListener: (event: "rename" | "change", filename: string | Buffer) => void;
3033
emitRebuild: Function;
31-
static wrapper = __dirname.replace(`${path.sep}dist`, "/src/lib/runtime/runners/python/index.py");
34+
static wrapper = moduleDirname.replace(`${path.sep}dist`, "/src/lib/runtime/runners/python/index.py");
3235
static DELIMITER = "__|response|__";
3336
static DELIMITEREND = "__|responseEnd|__";
3437
static ERR_RESPONSE = "__|error|__";

src/lib/runtime/runners/ruby/runner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { access } from "fs/promises";
55
import type { Runner } from "../index";
66
import type { ChildProcessWithoutNullStreams } from "child_process";
77
import type { FSWatcher } from "fs";
8+
import { fileURLToPath } from "url";
9+
10+
const moduleDirname = fileURLToPath(new URL(".", import.meta.url));
811

912
export class RubyRunner implements Runner {
1013
invoke: Runner["invoke"];
@@ -26,7 +29,7 @@ export class RubyRunner implements Runner {
2629
emitRebuild: Function;
2730
watcherListener: (event: "rename" | "change", filename: string | Buffer) => void;
2831
watchers: FSWatcher[] = [];
29-
static wrapper = __dirname.replace(`${path.sep}dist`, "/src/lib/runtime/runners/ruby/index.rb");
32+
static wrapper = moduleDirname.replace(`${path.sep}dist`, "/src/lib/runtime/runners/ruby/index.rb");
3033
static DELIMITER = "__|response|__";
3134
static ERR_RESPONSE = "__|error|__";
3235
static WATCH = "__|watch|__";

src/lib/utils/readDefineConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const readFromPath = async (sourcefile: string) => {
1717
packages: "external",
1818
platform: "node",
1919
format: "esm",
20-
target: "ES2018",
21-
banner: {
22-
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);const __filename = "${outfile}";const __dirname = "${dir}";`,
23-
},
20+
target: `node${process.versions.node.split(".")[0]}`,
21+
minify: true,
22+
sourcemap: "inline",
23+
sourcesContent: true,
2424
});
2525

2626
try {

templates/simple/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"devDependencies": {
66
"prettier": "3.2.5",
77
"serverless": "^3.38.0",
8-
"serverless-aws-lambda": "^4.8.2",
9-
"serverless-aws-lambda-vitest": "^2.0.0",
10-
"typescript": "^5.5.3"
8+
"serverless-aws-lambda": "^5.0.0",
9+
"serverless-aws-lambda-vitest": "^3.0.2",
10+
"typescript": "^5.6.3"
1111
},
1212
"scripts": {
1313
"sls": "sls",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"declarationDir": "./dist/",
1616
"rootDir": "./src/"
1717
},
18-
"exclude": ["./dist/**/*", "./templates/**/*", "vitest.config.ts"]
18+
"exclude": ["./dist/**/*", "./templates/**/*", "vitest.config.mts"]
1919
}
File renamed without changes.

0 commit comments

Comments
 (0)