Skip to content

Commit

Permalink
feat: Add nodejs22.x runtime support (#7624)
Browse files Browse the repository at this point in the history
* feat: Add nodejs22.x support

* update schema.json

* Fix failing error
  • Loading branch information
hnnasit authored Nov 21, 2024
1 parent fca6969 commit ba91737
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
ruby-version: "3.3"
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
- uses: actions/setup-java@v4
with:
distribution: 'corretto'
Expand Down
1 change: 1 addition & 0 deletions samcli/commands/_utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Runtime.nodejs16x.value,
Runtime.nodejs18x.value,
Runtime.nodejs20x.value,
Runtime.nodejs22x.value,
"Makefile",
"esbuild",
]
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
Supported Runtimes
------------------
1. Python 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 using PIP\n
2. Nodejs 20.x, 18.x, 16.x, 14.x, 12.x using NPM\n
2. Nodejs 22.x, Nodejs 20.x, 18.x, 16.x, 14.x, 12.x using NPM\n
3. Ruby 3.2, 3.3 using Bundler\n
4. Java 8, Java 11, Java 17, Java 21 using Gradle and Maven\n
5. Dotnet8, Dotnet6 using Dotnet CLI\n
Expand Down
2 changes: 2 additions & 0 deletions samcli/lib/build/workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def get_layer_subfolder(build_workflow: str) -> str:
"nodejs16.x": "nodejs",
"nodejs18.x": "nodejs",
"nodejs20.x": "nodejs",
"nodejs22.x": "nodejs",
"ruby3.2": "ruby/lib",
"ruby3.3": "ruby/lib",
"java11": "java",
Expand Down Expand Up @@ -163,6 +164,7 @@ def get_workflow_config(
"nodejs16.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs18.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs20.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs22.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"ruby3.2": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"ruby3.3": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"dotnet6": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
Expand Down
10 changes: 10 additions & 0 deletions samcli/lib/init/local_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
"useCaseName": "Hello World Example"
}
],
"nodejs22.x": [
{
"directory": "template/cookiecutter-aws-sam-hello-nodejs",
"displayName": "Hello World Example",
"dependencyManager": "npm",
"appTemplate": "hello-world",
"packageType": "Zip",
"useCaseName": "Hello World Example"
}
],
"nodejs20.x": [
{
"directory": "template/cookiecutter-aws-sam-hello-nodejs",
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/utils/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"nodejs16.x": [ARM64, X86_64],
"nodejs18.x": [ARM64, X86_64],
"nodejs20.x": [ARM64, X86_64],
"nodejs22.x": [ARM64, X86_64],
"python3.8": [ARM64, X86_64],
"python3.9": [ARM64, X86_64],
"python3.10": [ARM64, X86_64],
Expand Down
4 changes: 3 additions & 1 deletion samcli/local/common/runtime_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"nodejs": [
{
"runtimes": ["nodejs20.x", "nodejs18.x", "nodejs16.x"],
"runtimes": ["nodejs22.x", "nodejs20.x", "nodejs18.x", "nodejs16.x"],
"dependency_manager": "npm",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-nodejs"),
"build": True,
Expand Down Expand Up @@ -109,6 +109,7 @@ def get_local_lambda_images_location(mapping, runtime):
"java11",
"java8.al2",
# nodejs runtimes in descending order
"nodejs22.x",
"nodejs20.x",
"nodejs18.x",
"nodejs16.x",
Expand Down Expand Up @@ -139,6 +140,7 @@ def get_local_lambda_images_location(mapping, runtime):
"java17": "amazon/java17-base",
"java11": "amazon/java11-base",
"java8.al2": "amazon/java8.al2-base",
"nodejs22.x": "amazon/nodejs22.x-base",
"nodejs20.x": "amazon/nodejs20.x-base",
"nodejs18.x": "amazon/nodejs18.x-base",
"nodejs16.x": "amazon/nodejs16.x-base",
Expand Down
14 changes: 14 additions & 0 deletions samcli/local/docker/lambda_debug_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ def get_debug_settings(debug_port, debug_args_list, _container_env_vars, runtime
**_container_env_vars,
},
),
Runtime.nodejs22x.value: lambda: DebugSettings(
entry
+ ["/var/lang/bin/node"]
+ debug_args_list
+ ["--no-lazy", "--expose-gc"]
+ ["/var/runtime/index.mjs"],
container_env_vars={
"NODE_PATH": "/opt/nodejs/node_modules:/opt/nodejs/node22/node_modules:/var/runtime/node_modules:"
"/var/runtime:/var/task",
"NODE_OPTIONS": f"--inspect-brk=0.0.0.0:{str(debug_port)} --max-http-header-size 81920",
"AWS_EXECUTION_ENV": "AWS_Lambda_nodejs22.x",
**_container_env_vars,
},
),
Runtime.python38.value: lambda: DebugSettings(
entry + ["/var/lang/bin/python3.8"] + debug_args_list + ["/var/runtime/bootstrap.py"],
container_env_vars=_container_env_vars,
Expand Down
1 change: 1 addition & 0 deletions samcli/local/docker/lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Runtime(Enum):
nodejs16x = "nodejs16.x"
nodejs18x = "nodejs18.x"
nodejs20x = "nodejs20.x"
nodejs22x = "nodejs22.x"
python38 = "python3.8"
python39 = "python3.9"
python310 = "python3.10"
Expand Down
16 changes: 9 additions & 7 deletions schema/samcli.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions tests/integration/buildcmd/test_build_cmd_arm64.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class TestBuildCommand_EsbuildFunctions_With_External_Manifest_arm64(BuildIntegE
"main.lambdaHandler",
False,
),
(
"nodejs22.x",
"Esbuild/Node_without_manifest",
{"main.js", "main.js.map"},
"main.lambdaHandler",
False,
),
(
"nodejs16.x",
"Esbuild/TypeScript_without_manifest",
Expand All @@ -134,6 +141,13 @@ class TestBuildCommand_EsbuildFunctions_With_External_Manifest_arm64(BuildIntegE
"app.lambdaHandler",
False,
),
(
"nodejs22.x",
"Esbuild/TypeScript_without_manifest",
{"app.js", "app.js.map"},
"app.lambdaHandler",
False,
),
]
)
def test_building_default_package_json(self, runtime, code_uri, expected_files, handler, use_container):
Expand All @@ -149,6 +163,7 @@ class TestBuildCommand_NodeFunctions_With_Specified_Architecture_arm64(BuildInte
("nodejs16.x", False),
("nodejs18.x", False),
("nodejs20.x", False),
("nodejs22.x", False),
("nodejs16.x", "use_container"),
("nodejs18.x", "use_container"),
]
Expand All @@ -159,6 +174,7 @@ def test_building_default_package_json(self, runtime, use_container):
@parameterized.expand(
[
("nodejs20.x", "use_container"),
("nodejs22.x", "use_container"),
]
)
@pytest.mark.al2023
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/buildcmd/test_build_cmd_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_building_default_package_json(self, runtime):
@parameterized.expand(
[
("nodejs20.x",),
("nodejs22.x",),
]
)
@pytest.mark.al2023
Expand Down Expand Up @@ -170,6 +171,7 @@ class TestBuildCommand_NodeFunctions_With_Specified_Architecture(BuildIntegNodeB
("nodejs16.x", "use_container", "x86_64"),
("nodejs18.x", "use_container", "x86_64"),
("nodejs20.x", False, "x86_64"),
("nodejs22.x", False, "x86_64"),
]
)
def test_building_default_package_json(self, runtime, use_container, architecture):
Expand Down
1 change: 1 addition & 0 deletions tests/integration/validate/test_validate_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_lint_supported_runtimes(self):
"java8.al2",
"nodejs18.x",
"nodejs20.x",
"nodejs22.x",
"provided.al2",
"provided.al2023",
"python3.9",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/commands/init/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_init_cli_node(self, generate_project_patch, git_repo_clone_mock):
location=self.location,
pt_explicit=self.pt_explicit,
package_type=self.package_type,
runtime="nodejs20.x",
runtime="nodejs22.x",
architecture=X86_64,
base_image=self.base_image,
dependency_manager="npm",
Expand All @@ -170,12 +170,12 @@ def test_init_cli_node(self, generate_project_patch, git_repo_clone_mock):
# need to change the location validation check
ANY,
ZIP,
"nodejs20.x",
"nodejs22.x",
"npm",
self.output_dir,
self.name,
True,
{"runtime": "nodejs20.x", "project_name": "testing project", "architectures": {"value": ["x86_64"]}},
{"runtime": "nodejs22.x", "project_name": "testing project", "architectures": {"value": ["x86_64"]}},
False,
False,
False,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/build_module/test_workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_must_work_for_python(self, runtime):
self.assertIn(Event("BuildWorkflowUsed", "python-pip"), EventTracker.get_tracked_events())
self.assertFalse(result.must_mount_with_write_in_container)

@parameterized.expand([("nodejs16.x",), ("nodejs18.x",), ("nodejs20.x",)])
@parameterized.expand([("nodejs16.x",), ("nodejs18.x",), ("nodejs20.x",), ("nodejs22.x",)])
def test_must_work_for_nodejs(self, runtime):
result = get_workflow_config(runtime, self.code_dir, self.project_dir)
self.assertEqual(result.language, "nodejs")
Expand Down
1 change: 1 addition & 0 deletions tests/unit/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Runtime.nodejs16x.value,
Runtime.nodejs18x.value,
Runtime.nodejs20x.value,
Runtime.nodejs22x.value,
Runtime.python38.value,
Runtime.python39.value,
Runtime.python310.value,
Expand Down
1 change: 1 addition & 0 deletions tests/unit/local/docker/test_lambda_debug_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Runtime.nodejs16x,
Runtime.nodejs18x,
Runtime.nodejs20x,
Runtime.nodejs22x,
Runtime.python38,
Runtime.python39,
Runtime.python310,
Expand Down
1 change: 1 addition & 0 deletions tests/unit/local/docker/test_lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TestRuntime(TestCase):
("nodejs16.x", "nodejs:16-x86_64"),
("nodejs18.x", "nodejs:18-x86_64"),
("nodejs20.x", "nodejs:20-x86_64"),
("nodejs22.x", "nodejs:22-x86_64"),
("python3.8", "python:3.8-x86_64"),
("python3.9", "python:3.9-x86_64"),
("ruby3.2", "ruby:3.2-x86_64"),
Expand Down

0 comments on commit ba91737

Please sign in to comment.