From ec788e5fae3beb84bcacd704faeaed13e1ad6087 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 10:50:48 -0500 Subject: [PATCH 01/17] enable workflow_dispatch --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 942ae4aa..5bc1a116 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,7 @@ name: CI on: + workflow_dispatch: {} push: branches: [ master ] pull_request: From 3534659f4dfb10023ff5d17ceb547c57140dddfb Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 11:03:25 -0500 Subject: [PATCH 02/17] enable additional node versions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bc1a116..6856eaa3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [10.x, 12.x, 14.x, 15.x] + node-version: [10.x, 12.x, 14.x, 15.x, 16.x, 18.x, 20.x] runs-on: ${{ matrix.os }} From 1e3183c1430a84abcdc9ca6f291d89e80a2a81db Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 11:19:57 -0500 Subject: [PATCH 03/17] conditionally exclude aws-sdk --- .github/workflows/ci.yml | 2 +- index.js | 13 ++++++++----- src/config.js | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6856eaa3..5bc1a116 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [10.x, 12.x, 14.x, 15.x, 16.x, 18.x, 20.x] + node-version: [10.x, 12.x, 14.x, 15.x] runs-on: ${{ matrix.os }} diff --git a/index.js b/index.js index cbe5466a..7c63b388 100644 --- a/index.js +++ b/index.js @@ -43,11 +43,16 @@ function applyWebpackOptions(custom, config) { function applyUserConfig(config, userConfig, servicePath, runtime) { config.servicePath = servicePath; + // Default to Node 12 if no runtime found + const runtimeVersion = + Number.parseInt((runtime || "").replace("nodejs", ""), 10) || 12; + // Concat forceExclude if provided if (userConfig.forceExclude) { - userConfig.forceExclude = config.options.forceExclude.concat( - userConfig.forceExclude + const forceExclude = config.options.forceExclude.filter( + (item) => !(runtimeVersion >= 18 && item === "aws-sdk") ); + userConfig.forceExclude = forceExclude.concat(userConfig.forceExclude); } // Concat externals if a list of packages are provided @@ -66,9 +71,7 @@ function applyUserConfig(config, userConfig, servicePath, runtime) { Object.assign(config.options, userConfig); - // Default to Node 12 if no runtime found - config.nodeVersion = - Number.parseInt((runtime || "").replace("nodejs", ""), 10) || 12; + config.nodeVersion = runtimeVersion; } class ServerlessPlugin extends ServerlessWebpack { diff --git a/src/config.js b/src/config.js index 9e8e4d88..09e90a22 100644 --- a/src/config.js +++ b/src/config.js @@ -20,7 +20,7 @@ module.exports = { packagerOptions: {}, generateStatsFiles: false, tsConfig: "tsconfig.json", - // Exclude aws-sdk since it's available in the Lambda runtime + // Exclude aws-sdk since it's available in the Lambda runtime (for <= nodejs16.x) forceExclude: ["aws-sdk"], disableForkTsChecker: false, // Set non Webpack compatible packages as externals From 7a060eb992340126538ee9c4ad3495f55e07f544 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 11:27:13 -0500 Subject: [PATCH 04/17] add a node18 test --- tests/with-node18/.gitignore | 6 ++++++ tests/with-node18/handler.js | 26 ++++++++++++++++++++++++++ tests/with-node18/serverless.yml | 12 ++++++++++++ tests/with-node18/with-node18.test.js | 15 +++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 tests/with-node18/.gitignore create mode 100644 tests/with-node18/handler.js create mode 100644 tests/with-node18/serverless.yml create mode 100644 tests/with-node18/with-node18.test.js diff --git a/tests/with-node18/.gitignore b/tests/with-node18/.gitignore new file mode 100644 index 00000000..2b48c8bd --- /dev/null +++ b/tests/with-node18/.gitignore @@ -0,0 +1,6 @@ +# package directories +node_modules +jspm_packages + +# Serverless directories +.serverless \ No newline at end of file diff --git a/tests/with-node18/handler.js b/tests/with-node18/handler.js new file mode 100644 index 00000000..6e26a81e --- /dev/null +++ b/tests/with-node18/handler.js @@ -0,0 +1,26 @@ +class User { + constructor() { + this.counter = 0; + } + + increment() { + this.counter++; + } + + get count() { + return this.counter; + } +} + +const user = new User(); + +export const hello = async (event) => { + user.increment(); + return { + statusCode: 200, + body: JSON.stringify({ + message: `Go Serverless v1.0! Your function executed successfully! Count is ${user.count}`, + input: event, + }), + }; +}; diff --git a/tests/with-node18/serverless.yml b/tests/with-node18/serverless.yml new file mode 100644 index 00000000..41460842 --- /dev/null +++ b/tests/with-node18/serverless.yml @@ -0,0 +1,12 @@ +service: my-service + +plugins: + - '../../index' + +provider: + name: aws + runtime: nodejs14.x + +functions: + hello: + handler: handler.hello diff --git a/tests/with-node18/with-node18.test.js b/tests/with-node18/with-node18.test.js new file mode 100644 index 00000000..1a0821eb --- /dev/null +++ b/tests/with-node18/with-node18.test.js @@ -0,0 +1,15 @@ +const { runSlsCommand, clearNpmCache, errorRegex } = require("../helpers"); + +beforeEach(async () => { + await clearNpmCache(__dirname); +}); + +afterAll(async () => { + await clearNpmCache(__dirname); +}); + +test("node 14", async () => { + const result = await runSlsCommand(__dirname); + + expect(result).not.toMatch(errorRegex); +}); From 6193120779c18344c9a3c2da1d4145f43df40635 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 11:39:35 -0500 Subject: [PATCH 05/17] require aws-sdk --- tests/with-node18/handler.js | 1 + tests/with-node18/with-node18.test.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/with-node18/handler.js b/tests/with-node18/handler.js index 6e26a81e..6b3b3c6e 100644 --- a/tests/with-node18/handler.js +++ b/tests/with-node18/handler.js @@ -15,6 +15,7 @@ class User { const user = new User(); export const hello = async (event) => { + require("aws-sdk"); user.increment(); return { statusCode: 200, diff --git a/tests/with-node18/with-node18.test.js b/tests/with-node18/with-node18.test.js index 1a0821eb..0e8ae79a 100644 --- a/tests/with-node18/with-node18.test.js +++ b/tests/with-node18/with-node18.test.js @@ -8,7 +8,7 @@ afterAll(async () => { await clearNpmCache(__dirname); }); -test("node 14", async () => { +test("node 18", async () => { const result = await runSlsCommand(__dirname); expect(result).not.toMatch(errorRegex); From 71bdd44f59fdecd24c0d42f3a449554932dab00b Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 11:54:59 -0500 Subject: [PATCH 06/17] update force-exclude test --- tests/force-exclude/force-exclude.test.js | 7 ++++++ tests/force-exclude/handler.js | 10 ++++++--- tests/force-exclude/package.json | 1 + tests/with-node18/.gitignore | 6 ----- tests/with-node18/handler.js | 27 ----------------------- tests/with-node18/serverless.yml | 12 ---------- tests/with-node18/with-node18.test.js | 15 ------------- 7 files changed, 15 insertions(+), 63 deletions(-) delete mode 100644 tests/with-node18/.gitignore delete mode 100644 tests/with-node18/handler.js delete mode 100644 tests/with-node18/serverless.yml delete mode 100644 tests/with-node18/with-node18.test.js diff --git a/tests/force-exclude/force-exclude.test.js b/tests/force-exclude/force-exclude.test.js index 8173b5d5..9d2dc77a 100644 --- a/tests/force-exclude/force-exclude.test.js +++ b/tests/force-exclude/force-exclude.test.js @@ -12,4 +12,11 @@ test("force-exclude", async () => { const result = await runSlsCommand(__dirname); expect(result).not.toMatch(errorRegex); + + /* + Ensure that is-sorted and aws-sdk is excluded + */ + expect(result).toMatch( + /Excluding external modules: is-sorted@\^[\d\\.]+, aws-sdk@\^[\d\\.]+/ + ); }); diff --git a/tests/force-exclude/handler.js b/tests/force-exclude/handler.js index b62bcc70..306d86cd 100644 --- a/tests/force-exclude/handler.js +++ b/tests/force-exclude/handler.js @@ -1,12 +1,16 @@ import sorted from "is-sorted"; +import AWS from "aws-sdk"; -export const hello = async (event, context) => { +export const hello = async (event) => { + AWS.config.update({ + region: "us-east-1", + }); sorted([1, 2, 3]); return { statusCode: 200, body: JSON.stringify({ message: "Go Serverless v1.0! Your function executed successfully!", - input: event - }) + input: event, + }), }; }; diff --git a/tests/force-exclude/package.json b/tests/force-exclude/package.json index 3aaa60fa..8f41be8b 100644 --- a/tests/force-exclude/package.json +++ b/tests/force-exclude/package.json @@ -10,6 +10,7 @@ "author": "", "license": "ISC", "dependencies": { + "aws-sdk": "^2.1502.0", "is-sorted": "^1.0.5" } } diff --git a/tests/with-node18/.gitignore b/tests/with-node18/.gitignore deleted file mode 100644 index 2b48c8bd..00000000 --- a/tests/with-node18/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# package directories -node_modules -jspm_packages - -# Serverless directories -.serverless \ No newline at end of file diff --git a/tests/with-node18/handler.js b/tests/with-node18/handler.js deleted file mode 100644 index 6b3b3c6e..00000000 --- a/tests/with-node18/handler.js +++ /dev/null @@ -1,27 +0,0 @@ -class User { - constructor() { - this.counter = 0; - } - - increment() { - this.counter++; - } - - get count() { - return this.counter; - } -} - -const user = new User(); - -export const hello = async (event) => { - require("aws-sdk"); - user.increment(); - return { - statusCode: 200, - body: JSON.stringify({ - message: `Go Serverless v1.0! Your function executed successfully! Count is ${user.count}`, - input: event, - }), - }; -}; diff --git a/tests/with-node18/serverless.yml b/tests/with-node18/serverless.yml deleted file mode 100644 index 41460842..00000000 --- a/tests/with-node18/serverless.yml +++ /dev/null @@ -1,12 +0,0 @@ -service: my-service - -plugins: - - '../../index' - -provider: - name: aws - runtime: nodejs14.x - -functions: - hello: - handler: handler.hello diff --git a/tests/with-node18/with-node18.test.js b/tests/with-node18/with-node18.test.js deleted file mode 100644 index 0e8ae79a..00000000 --- a/tests/with-node18/with-node18.test.js +++ /dev/null @@ -1,15 +0,0 @@ -const { runSlsCommand, clearNpmCache, errorRegex } = require("../helpers"); - -beforeEach(async () => { - await clearNpmCache(__dirname); -}); - -afterAll(async () => { - await clearNpmCache(__dirname); -}); - -test("node 18", async () => { - const result = await runSlsCommand(__dirname); - - expect(result).not.toMatch(errorRegex); -}); From aa3600d1268491e7f674607cfb6177983c031b95 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:02:00 -0500 Subject: [PATCH 07/17] update with package command --- tests/force-exclude/force-exclude.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/force-exclude/force-exclude.test.js b/tests/force-exclude/force-exclude.test.js index 9d2dc77a..b4502491 100644 --- a/tests/force-exclude/force-exclude.test.js +++ b/tests/force-exclude/force-exclude.test.js @@ -12,6 +12,12 @@ test("force-exclude", async () => { const result = await runSlsCommand(__dirname); expect(result).not.toMatch(errorRegex); +}); + +test("force-exclude package", async () => { + const result = await runSlsCommand(__dirname, "package"); + + expect(result).not.toMatch(errorRegex); /* Ensure that is-sorted and aws-sdk is excluded From fb6ebd8cbb534a65862c1af8917d06bd99b11562 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:08:44 -0500 Subject: [PATCH 08/17] add a node18 test --- tests/force-exclude/force-exclude.test.js | 18 ++++++++++++++++-- tests/force-exclude/serverless.node18.yml | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/force-exclude/serverless.node18.yml diff --git a/tests/force-exclude/force-exclude.test.js b/tests/force-exclude/force-exclude.test.js index b4502491..c06666c4 100644 --- a/tests/force-exclude/force-exclude.test.js +++ b/tests/force-exclude/force-exclude.test.js @@ -15,7 +15,7 @@ test("force-exclude", async () => { }); test("force-exclude package", async () => { - const result = await runSlsCommand(__dirname, "package"); + const result = await runSlsCommand(__dirname, "package -c serverless.yml"); expect(result).not.toMatch(errorRegex); @@ -23,6 +23,20 @@ test("force-exclude package", async () => { Ensure that is-sorted and aws-sdk is excluded */ expect(result).toMatch( - /Excluding external modules: is-sorted@\^[\d\\.]+, aws-sdk@\^[\d\\.]+/ + /Excluding external modules: is-sorted@\^[\d\\.]+, aws-sdk@\^[\d\\.]+\n/ ); }); + +test("force-exclude package (node18)", async () => { + const result = await runSlsCommand( + __dirname, + "package -c serverless.node18.yml" + ); + + expect(result).not.toMatch(errorRegex); + + /* + Ensure that is-sorted and aws-sdk is excluded + */ + expect(result).toMatch(/Excluding external modules: is-sorted@\^[\d\\.]+\n/); +}); diff --git a/tests/force-exclude/serverless.node18.yml b/tests/force-exclude/serverless.node18.yml new file mode 100644 index 00000000..884aa5fb --- /dev/null +++ b/tests/force-exclude/serverless.node18.yml @@ -0,0 +1,17 @@ +service: my-service + +plugins: + - '../../index' + +custom: + bundle: + forceExclude: + - "is-sorted" + +provider: + name: aws + runtime: nodejs18.x + +functions: + hello: + handler: handler.hello From fae8b908a57b115b0e9a1f09cc83830ede389c74 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:17:02 -0500 Subject: [PATCH 09/17] update readme and comments --- README.md | 2 +- tests/force-exclude/force-exclude.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b03febdd..7f3355bc 100644 --- a/README.md +++ b/README.md @@ -449,7 +449,7 @@ The three options (`externals`, `forceExclude`, and `excludeFiles`) look similar - `forceExclude` - These packages are available in the Lambda runtime. Either by default (in the case of `aws-sdk`) or through a Lambda layer that you might be using. So these are not included in the Lambda package. And they are also marked as `externals`. Meaning that packages that are in `forceExclude` are automatically added to the `externals` list as well. By default, `aws-sdk` is listed in the `forceExclude`. + These packages are available in the Lambda runtime. Either by default (in the case of `aws-sdk`) or through a Lambda layer that you might be using. So these are not included in the Lambda package. And they are also marked as `externals`. Meaning that packages that are in `forceExclude` are automatically added to the `externals` list as well. By default, `aws-sdk` is listed in the `forceExclude` when `runtime` is lower than `nodejs18.x`. - `excludeFiles` diff --git a/tests/force-exclude/force-exclude.test.js b/tests/force-exclude/force-exclude.test.js index c06666c4..27a84844 100644 --- a/tests/force-exclude/force-exclude.test.js +++ b/tests/force-exclude/force-exclude.test.js @@ -36,7 +36,7 @@ test("force-exclude package (node18)", async () => { expect(result).not.toMatch(errorRegex); /* - Ensure that is-sorted and aws-sdk is excluded + Ensure that is-sorted is excluded */ expect(result).toMatch(/Excluding external modules: is-sorted@\^[\d\\.]+\n/); }); From 1003b923821be421002acc63f1d2a4d847f075ac Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:20:14 -0500 Subject: [PATCH 10/17] remove formatting change --- tests/force-exclude/handler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/force-exclude/handler.js b/tests/force-exclude/handler.js index 306d86cd..67ff1c0b 100644 --- a/tests/force-exclude/handler.js +++ b/tests/force-exclude/handler.js @@ -10,7 +10,7 @@ export const hello = async (event) => { statusCode: 200, body: JSON.stringify({ message: "Go Serverless v1.0! Your function executed successfully!", - input: event, - }), + input: event + }) }; }; From 14dba075cce130110bca85a19e3846bcb1b26f66 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:21:05 -0500 Subject: [PATCH 11/17] update comment --- src/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.js b/src/config.js index 09e90a22..bd3a99ea 100644 --- a/src/config.js +++ b/src/config.js @@ -20,7 +20,7 @@ module.exports = { packagerOptions: {}, generateStatsFiles: false, tsConfig: "tsconfig.json", - // Exclude aws-sdk since it's available in the Lambda runtime (for <= nodejs16.x) + // Exclude aws-sdk since it's available in the Lambda runtime (< nodejs18.x) forceExclude: ["aws-sdk"], disableForkTsChecker: false, // Set non Webpack compatible packages as externals From bb03a977f013e28b164e664a56af6d954840b434 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:35:39 -0500 Subject: [PATCH 12/17] add comment --- tests/force-exclude/handler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/force-exclude/handler.js b/tests/force-exclude/handler.js index 67ff1c0b..62072545 100644 --- a/tests/force-exclude/handler.js +++ b/tests/force-exclude/handler.js @@ -2,6 +2,7 @@ import sorted from "is-sorted"; import AWS from "aws-sdk"; export const hello = async (event) => { + // Include a dummy AWS SDK call to ensure webpack attempts to bundle it AWS.config.update({ region: "us-east-1", }); @@ -10,7 +11,7 @@ export const hello = async (event) => { statusCode: 200, body: JSON.stringify({ message: "Go Serverless v1.0! Your function executed successfully!", - input: event - }) + input: event, + }), }; }; From 7238948829eef2329c58fda3586637f9c61bd588 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:39:23 -0500 Subject: [PATCH 13/17] update logic for De Morgan's laws --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7c63b388..3d192f17 100644 --- a/index.js +++ b/index.js @@ -49,10 +49,9 @@ function applyUserConfig(config, userConfig, servicePath, runtime) { // Concat forceExclude if provided if (userConfig.forceExclude) { - const forceExclude = config.options.forceExclude.filter( - (item) => !(runtimeVersion >= 18 && item === "aws-sdk") - ); - userConfig.forceExclude = forceExclude.concat(userConfig.forceExclude); + userConfig.forceExclude = config.options.forceExclude + .filter((item) => runtimeVersion < 18 || item !== "aws-sdk") + .concat(userConfig.forceExclude); } // Concat externals if a list of packages are provided From cbf07dd9ef0d7ecf0b6491ed3d37e0041ee1f85a Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:43:33 -0500 Subject: [PATCH 14/17] remove formatting change --- tests/force-exclude/handler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/force-exclude/handler.js b/tests/force-exclude/handler.js index 62072545..8ed22d08 100644 --- a/tests/force-exclude/handler.js +++ b/tests/force-exclude/handler.js @@ -11,7 +11,7 @@ export const hello = async (event) => { statusCode: 200, body: JSON.stringify({ message: "Go Serverless v1.0! Your function executed successfully!", - input: event, - }), + input: event + }) }; }; From 6d4f167a3253b2bcd4acccf8311beaee94d95b9b Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 12:49:04 -0500 Subject: [PATCH 15/17] go back to original logic, it reads better --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3d192f17..25006c7c 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ function applyUserConfig(config, userConfig, servicePath, runtime) { // Concat forceExclude if provided if (userConfig.forceExclude) { userConfig.forceExclude = config.options.forceExclude - .filter((item) => runtimeVersion < 18 || item !== "aws-sdk") + .filter((item) => !(runtimeVersion >= 18 && item === "aws-sdk")) .concat(userConfig.forceExclude); } From 6a2ee207d2b74a7083cf8ffb3b049ce139866972 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 13:23:44 -0500 Subject: [PATCH 16/17] always have a default force exclude --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 25006c7c..ae0ea28c 100644 --- a/index.js +++ b/index.js @@ -47,11 +47,16 @@ function applyUserConfig(config, userConfig, servicePath, runtime) { const runtimeVersion = Number.parseInt((runtime || "").replace("nodejs", ""), 10) || 12; + // Exclude aws-sdk from default if runtime >= 18 + const forceExclude = config.options.forceExclude.filter( + (item) => !(runtimeVersion >= 18 && item === "aws-sdk") + ); + // Concat forceExclude if provided if (userConfig.forceExclude) { - userConfig.forceExclude = config.options.forceExclude - .filter((item) => !(runtimeVersion >= 18 && item === "aws-sdk")) - .concat(userConfig.forceExclude); + userConfig.forceExclude = forceExclude.concat(userConfig.forceExclude); + } else { + userConfig.forceExclude = forceExclude; } // Concat externals if a list of packages are provided From b1fc98cf593541f16cacf2b8437397a3f659ff7f Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Fri, 24 Nov 2023 13:36:39 -0500 Subject: [PATCH 17/17] remove aws-sdk from default config --- index.js | 14 +++++++------- src/config.js | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index ae0ea28c..92ea856f 100644 --- a/index.js +++ b/index.js @@ -47,16 +47,16 @@ function applyUserConfig(config, userConfig, servicePath, runtime) { const runtimeVersion = Number.parseInt((runtime || "").replace("nodejs", ""), 10) || 12; - // Exclude aws-sdk from default if runtime >= 18 - const forceExclude = config.options.forceExclude.filter( - (item) => !(runtimeVersion >= 18 && item === "aws-sdk") - ); + // Force exclude aws-sdk for versions below Node 18 + if (runtimeVersion < 18) { + config.options.forceExclude.push("aws-sdk"); + } // Concat forceExclude if provided if (userConfig.forceExclude) { - userConfig.forceExclude = forceExclude.concat(userConfig.forceExclude); - } else { - userConfig.forceExclude = forceExclude; + userConfig.forceExclude = config.options.forceExclude.concat( + userConfig.forceExclude + ); } // Concat externals if a list of packages are provided diff --git a/src/config.js b/src/config.js index bd3a99ea..9f6df374 100644 --- a/src/config.js +++ b/src/config.js @@ -20,8 +20,7 @@ module.exports = { packagerOptions: {}, generateStatsFiles: false, tsConfig: "tsconfig.json", - // Exclude aws-sdk since it's available in the Lambda runtime (< nodejs18.x) - forceExclude: ["aws-sdk"], + forceExclude: [], disableForkTsChecker: false, // Set non Webpack compatible packages as externals // Or if we want to exclude all packages in the node_modules: