diff --git a/aws_lambda_builders/workflows/nodejs_npm/actions.py b/aws_lambda_builders/workflows/nodejs_npm/actions.py index 9aefcc079..dd4a8d07e 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/actions.py +++ b/aws_lambda_builders/workflows/nodejs_npm/actions.py @@ -165,7 +165,7 @@ class NodejsNpmrcAndLockfileCopyAction(BaseAction): """ NAME = "CopyNpmrcAndLockfile" - DESCRIPTION = "Copying configuration from .npmrc and dependencies from lockfile" + DESCRIPTION = "Copying configuration from .npmrc and dependencies from lockfile/shrinkwrap" PURPOSE = Purpose.COPY_SOURCE def __init__(self, artifacts_dir, source_dir, osutils): @@ -194,7 +194,7 @@ def execute(self): """ try: - for filename in [".npmrc", "package-lock.json"]: + for filename in [".npmrc", "package-lock.json", "npm-shrinkwrap.json"]: file_path = self.osutils.joinpath(self.source_dir, filename) if self.osutils.file_exists(file_path): LOG.debug("%s copying in: %s", filename, self.artifacts_dir) diff --git a/tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py b/tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py index ed7242675..39e3e7a6a 100644 --- a/tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py +++ b/tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py @@ -1,6 +1,7 @@ import os import shutil import tempfile +from pathlib import Path from unittest import TestCase from unittest.mock import patch @@ -32,7 +33,8 @@ def _set_esbuild_binary_path(self): npm = SubprocessNpm(self.osutils) esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary") npm.run(["ci"], cwd=esbuild_dir) - self.binpath = npm.run(["bin"], cwd=esbuild_dir) + self.root_path = npm.run(["root"], cwd=esbuild_dir) + self.binpath = Path(self.root_path, ".bin") def tearDown(self): shutil.rmtree(self.artifacts_dir) @@ -168,7 +170,7 @@ def test_bundles_project_without_dependencies(self, runtime): npm = SubprocessNpm(osutils) esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary") npm.run(["ci"], cwd=esbuild_dir) - binpath = npm.run(["bin"], cwd=esbuild_dir) + binpath = Path(npm.run(["root"], cwd=esbuild_dir), ".bin") self.builder.build( source_dir, @@ -194,7 +196,7 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w npm = SubprocessNpm(osutils) esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary") npm.run(["ci"], cwd=esbuild_dir) - binpath = npm.run(["bin"], cwd=esbuild_dir) + binpath = Path(npm.run(["root"], cwd=esbuild_dir), ".bin") self.builder.build( source_dir, diff --git a/tests/unit/workflows/nodejs_npm/test_actions.py b/tests/unit/workflows/nodejs_npm/test_actions.py index d6a795640..0b2bf998e 100644 --- a/tests/unit/workflows/nodejs_npm/test_actions.py +++ b/tests/unit/workflows/nodejs_npm/test_actions.py @@ -1,3 +1,4 @@ +import itertools from unittest import TestCase from mock import patch, call from parameterized import parameterized @@ -111,26 +112,22 @@ def test_raises_action_failed_when_npm_fails(self, SubprocessNpmMock): class TestNodejsNpmrcAndLockfileCopyAction(TestCase): - @parameterized.expand( - [ - [False, False], - [True, False], - [False, True], - [True, True], - ] - ) + @parameterized.expand(itertools.product([True, False], [True, False], [True, False])) @patch("aws_lambda_builders.workflows.nodejs_npm.utils.OSUtils") - def test_copies_into_a_project_if_file_exists(self, npmrc_exists, package_lock_exists, OSUtilMock): + def test_copies_into_a_project_if_file_exists( + self, npmrc_exists, package_lock_exists, shrinkwrap_exists, OSUtilMock + ): osutils = OSUtilMock.return_value osutils.joinpath.side_effect = lambda a, b: "{}/{}".format(a, b) action = NodejsNpmrcAndLockfileCopyAction("artifacts", "source", osutils=osutils) - osutils.file_exists.side_effect = [npmrc_exists, package_lock_exists] + osutils.file_exists.side_effect = [npmrc_exists, package_lock_exists, shrinkwrap_exists] action.execute() filename_exists = { ".npmrc": npmrc_exists, "package-lock.json": package_lock_exists, + "npm-shrinkwrap.json": shrinkwrap_exists, } file_exists_calls = [call("source/{}".format(filename)) for filename in filename_exists] copy_file_calls = [