Skip to content

Commit f1ecbc1

Browse files
authored
fix: Ignore flags not relevant to esbuild (#510)
* Ignore flags not relevant to esbuild * Make code more concise
1 parent 2d2fbae commit f1ecbc1

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

aws_lambda_builders/workflows/nodejs_npm_esbuild/esbuild.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def run(self, args, cwd=None):
101101

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

104+
# Ignore the values below. These are options that Lambda Builders accepts for
105+
# Node.js related workflows, but are not relevant to esbuild itself.
106+
ESBUILD_IGNORE_VALUES = {"use_npm_ci", "entry_points"}
107+
104108

105109
class EsbuildCommandBuilder:
106110
ENTRY_POINTS = "entry_points"
@@ -142,8 +146,7 @@ def build_esbuild_args_from_config(self) -> "EsbuildCommandBuilder":
142146
config_value,
143147
)
144148
continue
145-
if config_key == "entry_points":
146-
# Entry points are a required parameter and are handled by the build_entry_points() method
149+
if config_key in ESBUILD_IGNORE_VALUES:
147150
continue
148151
configuration_type_callback = self._get_config_type_callback(config_value)
149152
LOG.debug("Configuring the parameter '%s=%s'", config_key, config_value)

tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,24 @@ def test_esbuild_can_build_in_source_with_local_dependency(self, runtime):
491491
expected_files = {"included.js"}
492492
output_files = set(os.listdir(self.artifacts_dir))
493493
self.assertEqual(expected_files, output_files)
494+
495+
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",), ("nodejs18.x",)])
496+
def test_builds_javascript_project_ignoring_relevant_flags(self, runtime):
497+
source_dir = os.path.join(self.TEST_DATA_FOLDER, "with-deps-esbuild")
498+
499+
options = {"entry_points": ["included.js"], "use_npm_ci": True}
500+
501+
self.builder.build(
502+
source_dir,
503+
self.artifacts_dir,
504+
self.scratch_dir,
505+
os.path.join(source_dir, "package.json"),
506+
runtime=runtime,
507+
options=options,
508+
experimental_flags=[],
509+
executable_search_paths=[self.binpath],
510+
)
511+
512+
expected_files = {"included.js"}
513+
output_files = set(os.listdir(self.artifacts_dir))
514+
self.assertEqual(expected_files, output_files)

tests/unit/workflows/nodejs_npm_esbuild/test_actions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,30 @@ def test_building_with_skip_deps_fails_if_esbuild_version_less_than_minimum(
329329
with self.assertRaises(ActionFailedError):
330330
action.execute()
331331

332+
def test_packages_javascript_ignoring_non_relevant_flags(self):
333+
action = EsbuildBundleAction(
334+
"source",
335+
"artifacts",
336+
{"entry_points": ["x.js"], "use_npm_ci": True},
337+
self.osutils,
338+
self.subprocess_esbuild,
339+
"package.json",
340+
)
341+
action.execute()
342+
343+
self.subprocess_esbuild.run.assert_called_with(
344+
[
345+
"x.js",
346+
"--bundle",
347+
"--platform=node",
348+
"--outdir=artifacts",
349+
"--target=es2020",
350+
"--format=cjs",
351+
"--minify",
352+
],
353+
cwd="source",
354+
)
355+
332356

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

0 commit comments

Comments
 (0)