Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional forceExclude of aws-sdk based on runtime version #366

Merged
merged 17 commits into from
Nov 30, 2023
Merged
Prev Previous commit
Next Next commit
conditionally exclude aws-sdk
  • Loading branch information
cnuss committed Nov 24, 2023
commit 1e3183c1430a84abcdc9ca6f291d89e80a2a81db
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down