Skip to content

Commit 2d0bc1b

Browse files
authored
feat: Changed Sourcemap default value to false (#375)
* Changed Sourcemap default to false * Changed source map DESIGN line to reflect default false change * Fixed integ tests for esbuild * Undo change to test exclude sourcemap
1 parent 64f478f commit 2d0bc1b

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

aws_lambda_builders/workflows/nodejs_npm_esbuild/DESIGN.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,23 @@ testing flow before invoking `sam build`. For additional typescript caveats with
117117

118118
#### Configuring the bundler
119119

120-
The Lambda builder invokes `esbuild` with sensible defaults that will work for the majority of cases. Importantly, the following three parameters are set by default
120+
The Lambda builder invokes `esbuild` with sensible defaults that will work for the majority of cases. Importantly, the following parameters are set by default
121121

122122
* `--minify`, as it [produces a smaller runtime package](https://esbuild.github.io/api/#minify)
123-
* `--sourcemap`, as it generates a [source map that allows for correct stack trace reporting](https://esbuild.github.io/api/#sourcemap) in case of errors (see the [Error reporting](#error-reporting) section above)
124123
* `--target es2020`, as it allows for javascript features present in Node 14
125124

126125
Users might want to tweak some of these runtime arguments for a specific project, for example not including the source map to further reduce the package size, or restricting javascript features to an older version. The Lambda builder allows this with optional sub-properties of the `aws_sam` configuration property.
127126

128127
* `target`: string, corresponding to a supported [esbuild target](https://esbuild.github.io/api/#target) property
129128
* `minify`: boolean, defaulting to `true`
130-
* `sourcemap`: boolean, defaulting to `true`
129+
* `sourcemap`: boolean, defaulting to `false`
131130

132-
Here is an example that deactivates minification and source maps, and supports JavaScript features compatible with Node.js version 10.
131+
Here is an example that deactivates minification, enables source maps, and supports JavaScript features compatible with Node.js version 10.
133132

134133
```json
135134
{
136135
"entry_points": ["included.ts"],
137136
"target": "node10",
138137
"minify": false,
139-
"sourcemap": false
138+
"sourcemap": true
140139
}

aws_lambda_builders/workflows/nodejs_npm_esbuild/esbuild.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ def build_default_values(self) -> "EsbuildCommandBuilder":
202202
if "minify" not in self._bundler_config:
203203
args.append("--minify")
204204

205-
if "sourcemap" not in self._bundler_config:
206-
args.append("--sourcemap")
207-
208205
LOG.debug("Using the following default args: %s", str(args))
209206

210207
self._command.extend(args)

tests/integration/workflows/nodejs_npm_esbuild/test_nodejs_npm_with_esbuild.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_builds_javascript_project_with_dependencies(self, runtime):
6161
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
6262
)
6363

64-
expected_files = {"included.js", "included.js.map"}
64+
expected_files = {"included.js"}
6565
output_files = set(os.listdir(self.artifacts_dir))
6666
self.assertEqual(expected_files, output_files)
6767

@@ -81,7 +81,7 @@ def test_builds_javascript_project_with_multiple_entrypoints(self, runtime):
8181
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
8282
)
8383

84-
expected_files = {"included.js", "included.js.map", "included2.js", "included2.js.map"}
84+
expected_files = {"included.js", "included2.js"}
8585
output_files = set(os.listdir(self.artifacts_dir))
8686
self.assertEqual(expected_files, output_files)
8787

@@ -101,7 +101,7 @@ def test_builds_typescript_projects(self, runtime):
101101
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
102102
)
103103

104-
expected_files = {"included.js", "included.js.map"}
104+
expected_files = {"included.js"}
105105
output_files = set(os.listdir(self.artifacts_dir))
106106
self.assertEqual(expected_files, output_files)
107107

@@ -129,7 +129,7 @@ def test_builds_with_external_esbuild(self, runtime):
129129
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
130130
)
131131

132-
expected_files = {"included.js", "included.js.map"}
132+
expected_files = {"included.js"}
133133
output_files = set(os.listdir(self.artifacts_dir))
134134
self.assertEqual(expected_files, output_files)
135135

@@ -165,7 +165,7 @@ def test_bundle_with_implicit_file_types(self, runtime):
165165
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
166166
)
167167

168-
expected_files = {"included.js.map", "implicit.js.map", "implicit.js", "included.js"}
168+
expected_files = {"implicit.js", "included.js"}
169169
output_files = set(os.listdir(self.artifacts_dir))
170170
self.assertEqual(expected_files, output_files)
171171

@@ -191,7 +191,7 @@ def test_bundles_project_without_dependencies(self, runtime):
191191
executable_search_paths=[binpath],
192192
)
193193

194-
expected_files = {"included.js.map", "included.js"}
194+
expected_files = {"included.js"}
195195
output_files = set(os.listdir(self.artifacts_dir))
196196
self.assertEqual(expected_files, output_files)
197197

@@ -219,7 +219,7 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
219219
executable_search_paths=[binpath],
220220
)
221221

222-
expected_files = {"included.js.map", "included.js"}
222+
expected_files = {"included.js"}
223223
output_files = set(os.listdir(self.artifacts_dir))
224224
self.assertEqual(expected_files, output_files)
225225

@@ -240,7 +240,7 @@ def test_builds_project_with_remote_dependencies_with_download_dependencies_and_
240240
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
241241
)
242242

243-
expected_files = {"included.js.map", "included.js"}
243+
expected_files = {"included.js"}
244244
output_files = set(os.listdir(self.artifacts_dir))
245245
self.assertEqual(expected_files, output_files)
246246

@@ -290,7 +290,7 @@ def test_builds_project_without_combine_dependencies(self, runtime):
290290
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
291291
)
292292

293-
expected_files = {"included.js.map", "included.js"}
293+
expected_files = {"included.js"}
294294
output_files = set(os.listdir(self.artifacts_dir))
295295
self.assertEqual(expected_files, output_files)
296296

@@ -318,7 +318,7 @@ def test_builds_javascript_project_with_external(self, runtime):
318318
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
319319
)
320320

321-
expected_files = {"included.js", "included.js.map"}
321+
expected_files = {"included.js"}
322322
output_files = set(os.listdir(self.artifacts_dir))
323323
self.assertEqual(expected_files, output_files)
324324
with open(str(os.path.join(self.artifacts_dir, "included.js"))) as f:
@@ -343,7 +343,7 @@ def test_builds_javascript_project_with_loader(self, runtime):
343343
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
344344
)
345345

346-
expected_files = {"included.js", "included.js.map"}
346+
expected_files = {"included.js"}
347347
output_files = set(os.listdir(self.artifacts_dir))
348348
self.assertEqual(expected_files, output_files)
349349

@@ -366,3 +366,23 @@ def test_builds_javascript_project_with_loader(self, runtime):
366366
"\turania: astronomy and astrology"
367367
),
368368
)
369+
370+
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
371+
def test_includes_sourcemap_if_requested(self, runtime):
372+
source_dir = os.path.join(self.TEST_DATA_FOLDER, "with-deps-esbuild")
373+
374+
options = {"entry_points": ["included.js"], "sourcemap": True}
375+
376+
self.builder.build(
377+
source_dir,
378+
self.artifacts_dir,
379+
self.scratch_dir,
380+
os.path.join(source_dir, "package.json"),
381+
runtime=runtime,
382+
options=options,
383+
experimental_flags=[EXPERIMENTAL_FLAG_ESBUILD],
384+
)
385+
386+
expected_files = {"included.js", "included.js.map"}
387+
output_files = set(os.listdir(self.artifacts_dir))
388+
self.assertEqual(expected_files, output_files)

tests/unit/workflows/nodejs_npm_esbuild/test_actions.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ def test_raises_error_if_entrypoints_empty_list(self):
6060

6161
def test_packages_javascript_with_minification_and_sourcemap(self):
6262
action = EsbuildBundleAction(
63-
"source", "artifacts", {"entry_points": ["x.js"]}, self.osutils, self.subprocess_esbuild, "package.json"
63+
"source",
64+
"artifacts",
65+
{"entry_points": ["x.js"], "sourcemap": True},
66+
self.osutils,
67+
self.subprocess_esbuild,
68+
"package.json",
6469
)
6570
action.execute()
6671

@@ -97,7 +102,6 @@ def test_packages_with_externals(self):
97102
"--target=es2020",
98103
"--format=cjs",
99104
"--minify",
100-
"--sourcemap",
101105
"--external:fetch",
102106
"--external:aws-sdk",
103107
],
@@ -123,7 +127,6 @@ def test_packages_with_custom_loaders(self):
123127
"--target=es2020",
124128
"--format=cjs",
125129
"--minify",
126-
"--sourcemap",
127130
"--loader:.proto=text",
128131
"--loader:.json=js",
129132
],
@@ -206,7 +209,6 @@ def test_does_not_minify_if_requested(self):
206209
"--outdir=artifacts",
207210
"--target=es2020",
208211
"--format=cjs",
209-
"--sourcemap",
210212
],
211213
cwd="source",
212214
)
@@ -229,7 +231,6 @@ def test_uses_specified_target(self):
229231
"--outdir=artifacts",
230232
"--format=cjs",
231233
"--minify",
232-
"--sourcemap",
233234
"--target=node14",
234235
],
235236
cwd="source",
@@ -254,7 +255,6 @@ def test_includes_multiple_entry_points_if_requested(self):
254255
"--outdir=artifacts",
255256
"--format=cjs",
256257
"--minify",
257-
"--sourcemap",
258258
"--target=node14",
259259
],
260260
cwd="source",
@@ -287,7 +287,6 @@ def test_includes_building_with_external_dependencies(self, osutils_mock):
287287
"--outdir=artifacts",
288288
"--format=cjs",
289289
"--minify",
290-
"--sourcemap",
291290
"--target=node14",
292291
],
293292
cwd="source",

tests/unit/workflows/nodejs_npm_esbuild/test_esbuild.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def test_builds_default_values(self, osutils_mock):
152152
"--target=es2020",
153153
"--format=cjs",
154154
"--minify",
155-
"--sourcemap",
156155
],
157156
)
158157

@@ -180,7 +179,6 @@ def test_combined_builder_exclude_all_dependencies(self, osutils_mock):
180179
"--target=es2020",
181180
"--format=cjs",
182181
"--minify",
183-
"--sourcemap",
184182
"--loader:.proto=text",
185183
"--loader:.json=js",
186184
"--external:@faker-js/faker",
@@ -237,7 +235,6 @@ def test_combined_builder_with_dependencies(self, osutils_mock):
237235
"--outdir=artifacts",
238236
"--target=es2020",
239237
"--minify",
240-
"--sourcemap",
241238
"--format=esm",
242239
"--loader:.proto=text",
243240
"--loader:.json=js",

0 commit comments

Comments
 (0)