Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions aws_lambda_builders/workflows/nodejs_npm_esbuild/esbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def run(self, args, cwd=None):

NON_CONFIGURABLE_VALUES = {"bundle", "platform", "outdir"}

# Ignore the values below. These are options that Lambda Builders accepts for
# Node.js related workflows, but are not relevant to esbuild itself.
ESBUILD_IGNORE_VALUES = {"use_npm_ci", "entry_points"}
Copy link
Contributor Author

@mildaniel mildaniel Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explored other ways of ignoring these types of unrelated values, however didn't find anything reliable (e.g. there's no API to use, and parsing the esbuild help text is very complicated). We can go with this solution for now as it fixes the immediate issue, and look for ways of making this more reliable moving forward.



class EsbuildCommandBuilder:
ENTRY_POINTS = "entry_points"
Expand Down Expand Up @@ -142,8 +146,7 @@ def build_esbuild_args_from_config(self) -> "EsbuildCommandBuilder":
config_value,
)
continue
if config_key == "entry_points":
# Entry points are a required parameter and are handled by the build_entry_points() method
if config_key in ESBUILD_IGNORE_VALUES:
continue
configuration_type_callback = self._get_config_type_callback(config_value)
LOG.debug("Configuring the parameter '%s=%s'", config_key, config_value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,24 @@ def test_esbuild_can_build_in_source_with_local_dependency(self, runtime):
expected_files = {"included.js"}
output_files = set(os.listdir(self.artifacts_dir))
self.assertEqual(expected_files, output_files)

@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",), ("nodejs18.x",)])
def test_builds_javascript_project_ignoring_relevant_flags(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "with-deps-esbuild")

options = {"entry_points": ["included.js"], "use_npm_ci": True}

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=runtime,
options=options,
experimental_flags=[],
executable_search_paths=[self.binpath],
)

expected_files = {"included.js"}
output_files = set(os.listdir(self.artifacts_dir))
self.assertEqual(expected_files, output_files)
24 changes: 24 additions & 0 deletions tests/unit/workflows/nodejs_npm_esbuild/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,30 @@ def test_building_with_skip_deps_fails_if_esbuild_version_less_than_minimum(
with self.assertRaises(ActionFailedError):
action.execute()

def test_packages_javascript_ignoring_non_relevant_flags(self):
action = EsbuildBundleAction(
"source",
"artifacts",
{"entry_points": ["x.js"], "use_npm_ci": True},
self.osutils,
self.subprocess_esbuild,
"package.json",
)
action.execute()

self.subprocess_esbuild.run.assert_called_with(
[
"x.js",
"--bundle",
"--platform=node",
"--outdir=artifacts",
"--target=es2020",
"--format=cjs",
"--minify",
],
cwd="source",
)


class TestEsbuildVersionChecker(TestCase):
@parameterized.expand(["0.14.0", "0.0.0", "0.14.12"])
Expand Down