Skip to content

Commit 77e3d23

Browse files
authored
fix: Copy over shrinkwrap if it exists (#411)
* fix: Copy over shrinkwrap if it exists * Fix tests * Black reformat
1 parent 419bdee commit 77e3d23

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

aws_lambda_builders/workflows/nodejs_npm/actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class NodejsNpmrcAndLockfileCopyAction(BaseAction):
165165
"""
166166

167167
NAME = "CopyNpmrcAndLockfile"
168-
DESCRIPTION = "Copying configuration from .npmrc and dependencies from lockfile"
168+
DESCRIPTION = "Copying configuration from .npmrc and dependencies from lockfile/shrinkwrap"
169169
PURPOSE = Purpose.COPY_SOURCE
170170

171171
def __init__(self, artifacts_dir, source_dir, osutils):
@@ -194,7 +194,7 @@ def execute(self):
194194
"""
195195

196196
try:
197-
for filename in [".npmrc", "package-lock.json"]:
197+
for filename in [".npmrc", "package-lock.json", "npm-shrinkwrap.json"]:
198198
file_path = self.osutils.joinpath(self.source_dir, filename)
199199
if self.osutils.file_exists(file_path):
200200
LOG.debug("%s copying in: %s", filename, self.artifacts_dir)

tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import shutil
33
import tempfile
4+
from pathlib import Path
45
from unittest import TestCase
56
from unittest.mock import patch
67

@@ -32,7 +33,8 @@ def _set_esbuild_binary_path(self):
3233
npm = SubprocessNpm(self.osutils)
3334
esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary")
3435
npm.run(["ci"], cwd=esbuild_dir)
35-
self.binpath = npm.run(["bin"], cwd=esbuild_dir)
36+
self.root_path = npm.run(["root"], cwd=esbuild_dir)
37+
self.binpath = Path(self.root_path, ".bin")
3638

3739
def tearDown(self):
3840
shutil.rmtree(self.artifacts_dir)
@@ -168,7 +170,7 @@ def test_bundles_project_without_dependencies(self, runtime):
168170
npm = SubprocessNpm(osutils)
169171
esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary")
170172
npm.run(["ci"], cwd=esbuild_dir)
171-
binpath = npm.run(["bin"], cwd=esbuild_dir)
173+
binpath = Path(npm.run(["root"], cwd=esbuild_dir), ".bin")
172174

173175
self.builder.build(
174176
source_dir,
@@ -194,7 +196,7 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
194196
npm = SubprocessNpm(osutils)
195197
esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary")
196198
npm.run(["ci"], cwd=esbuild_dir)
197-
binpath = npm.run(["bin"], cwd=esbuild_dir)
199+
binpath = Path(npm.run(["root"], cwd=esbuild_dir), ".bin")
198200

199201
self.builder.build(
200202
source_dir,

tests/unit/workflows/nodejs_npm/test_actions.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
from unittest import TestCase
23
from mock import patch, call
34
from parameterized import parameterized
@@ -111,26 +112,22 @@ def test_raises_action_failed_when_npm_fails(self, SubprocessNpmMock):
111112

112113

113114
class TestNodejsNpmrcAndLockfileCopyAction(TestCase):
114-
@parameterized.expand(
115-
[
116-
[False, False],
117-
[True, False],
118-
[False, True],
119-
[True, True],
120-
]
121-
)
115+
@parameterized.expand(itertools.product([True, False], [True, False], [True, False]))
122116
@patch("aws_lambda_builders.workflows.nodejs_npm.utils.OSUtils")
123-
def test_copies_into_a_project_if_file_exists(self, npmrc_exists, package_lock_exists, OSUtilMock):
117+
def test_copies_into_a_project_if_file_exists(
118+
self, npmrc_exists, package_lock_exists, shrinkwrap_exists, OSUtilMock
119+
):
124120
osutils = OSUtilMock.return_value
125121
osutils.joinpath.side_effect = lambda a, b: "{}/{}".format(a, b)
126122

127123
action = NodejsNpmrcAndLockfileCopyAction("artifacts", "source", osutils=osutils)
128-
osutils.file_exists.side_effect = [npmrc_exists, package_lock_exists]
124+
osutils.file_exists.side_effect = [npmrc_exists, package_lock_exists, shrinkwrap_exists]
129125
action.execute()
130126

131127
filename_exists = {
132128
".npmrc": npmrc_exists,
133129
"package-lock.json": package_lock_exists,
130+
"npm-shrinkwrap.json": shrinkwrap_exists,
134131
}
135132
file_exists_calls = [call("source/{}".format(filename)) for filename in filename_exists]
136133
copy_file_calls = [

0 commit comments

Comments
 (0)