Skip to content

Commit e27f62f

Browse files
author
Jason Bedard
committed
feat(rollup): provide sourcemaps for all output types
1 parent 3b5fa13 commit e27f62f

11 files changed

+108
-15
lines changed

internal/e2e/check.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ function read(readPath) {
99
.replace(/\r\n/g, '\n')
1010
.replace(/\\\\/g, '/')
1111
// In the sourcemap, CRLF is turned into a string encoding
12-
.replace(/\\r\\n/g, '\\n');
12+
.replace(/\\r\\n/g, '\\n')
13+
// Replace platform specific directories in paths
14+
.replace(/\/\w+-fastbuild\//g, '/__platform__-fastbuild/')
15+
;
1316
}
1417

1518
// These keys are arbitrary and local to this test.

internal/e2e/rollup/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ jasmine_node_test(
2525
"*_golden.js.map",
2626
]) + [
2727
":bundle",
28+
":bundle.es2015.js",
29+
":bundle.es2015.js.map",
30+
":bundle.min.es2015.js",
31+
":bundle.min.es2015.js.map",
2832
":bundle.cjs.js",
33+
":bundle.cjs.js.map",
2934
":bundle.umd.js",
35+
":bundle.umd.js.map",
3036
":bundle.min_debug.js",
37+
":bundle.min_debug.js.map",
3138
],
3239
deps = [
3340
"//internal/e2e:check_lib",

internal/e2e/rollup/bundle-cjs_golden.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/e2e/rollup/bundle-es2015_golden.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license A dummy license banner that goes at the top of the file.
3+
* This is version v1.2.3
4+
*/
5+
6+
var bundle = (function (exports, some_global_var) {
7+
'use strict';
8+
9+
const fum = 'Wonderland';
10+
11+
var hello = 'Hello';
12+
13+
const name = 'Alice';
14+
15+
console.log(`${hello}, ${name} in ${fum}`);
16+
17+
// Test for sequences = false
18+
class A {
19+
a() {
20+
return document.a;
21+
}
22+
}
23+
function inline_me() {
24+
return 'abc';
25+
}
26+
console.error(new A().a(), inline_me(), some_global_var.thing);
27+
28+
exports.A = A;
29+
30+
return exports;
31+
32+
}({}, runtime_name_of_global_var));
33+
//# sourceMappingURL=bundle.es2015.js.map

internal/e2e/rollup/bundle-min-debug_golden.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/e2e/rollup/bundle-min-es2015_golden.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @license A dummy license banner that goes at the top of the file.
3+
* This is version v1.2.3
4+
*/
5+
var bundle=function(n,e){"use strict";console.log("Hello, Alice in Wonderland");class o{a(){return document.a}}return console.error((new o).a(),"abc",e.thing),n.A=o,n}({},runtime_name_of_global_var);

internal/e2e/rollup/bundle-umd_golden.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/e2e/rollup/rollup.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ describe('bundling', () => {
55
it('should work', () => {
66
check(path, 'bundle.min.js', 'bundle-min_golden.js_');
77
});
8-
it('should produce a sourcemap', () => {
8+
it('should produce sourcemaps', () => {
99
// TODO(alexeagle): the right assertion is to load up the source-map library
1010
// and assert that the sourcemap actually maps back to the sources
1111
check(path, 'bundle.min.js.map', 'bundle-min_golden.js.map');
12+
check(path, 'bundle.min_debug.js.map', 'bundle-min-debug_golden.js.map');
13+
check(path, 'bundle.min.es2015.js.map', 'bundle-min-es2015_golden.js.map');
14+
check(path, 'bundle.es2015.js.map', 'bundle-es2015_golden.js.map');
15+
check(path, 'bundle.cjs.js.map', 'bundle-cjs_golden.js.map');
16+
check(path, 'bundle.umd.js.map', 'bundle-umd_golden.js.map');
1217
});
1318
it('should produce a debug bundle', () => {
1419
check(path, 'bundle.min_debug.js', 'bundle-min-debug_golden.js_');

internal/rollup/rollup_bundle.bzl

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,25 @@ def _rollup_bundle(ctx):
441441
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_umd)
442442
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_cjs)
443443

444-
# There is no source map explorer output when code-splitting but we still need to satisfy the output
445-
ctx.actions.expand_template(
446-
output = ctx.outputs.explore_html,
447-
template = ctx.file._no_explore_html,
448-
substitutions = {},
449-
)
444+
# There is no source map or explorer output when code-splitting but we still need to satisfy the output
445+
[
446+
ctx.actions.expand_template(
447+
output = output,
448+
template = ctx.file._no_explore_html,
449+
substitutions = {},
450+
)
451+
for output in [
452+
ctx.outputs.explore_html,
453+
ctx.outputs.build_es2015_map,
454+
ctx.outputs.build_es2015_min_map,
455+
ctx.outputs.build_es2015_min_debug_map,
456+
ctx.outputs.build_es5_min_map,
457+
ctx.outputs.build_es5_min_debug_map,
458+
ctx.outputs.build_umd_map,
459+
ctx.outputs.build_cjs_map,
460+
]
461+
]
462+
450463
files = [
451464
ctx.outputs.build_es2015,
452465
ctx.outputs.build_es2015_min,
@@ -465,18 +478,31 @@ def _rollup_bundle(ctx):
465478
else:
466479
# Generate the bundles
467480
rollup_config = write_rollup_config(ctx)
468-
run_rollup(ctx, _collect_es2015_sources(ctx), rollup_config, ctx.outputs.build_es2015)
469-
run_terser(ctx, ctx.outputs.build_es2015, ctx.outputs.build_es2015_min, config_name = ctx.label.name + "es2015_min")
470-
run_terser(ctx, ctx.outputs.build_es2015, ctx.outputs.build_es2015_min_debug, debug = True, config_name = ctx.label.name + "es2015_min_debug")
481+
482+
# es2015
483+
source_map_es2015 = run_rollup(ctx, _collect_es2015_sources(ctx), rollup_config, ctx.outputs.build_es2015)
484+
run_terser(ctx, ctx.outputs.build_es2015, ctx.outputs.build_es2015_min, config_name = ctx.label.name + "es2015_min", in_source_map = source_map_es2015)
485+
run_terser(ctx, ctx.outputs.build_es2015, ctx.outputs.build_es2015_min_debug, debug = True, config_name = ctx.label.name + "es2015_min_debug", in_source_map = source_map_es2015)
486+
487+
# es5
488+
# TODO: tsc should produce a source map from the build_es2015 + source_map_es2015 inputs
489+
# See: https://github.com/bazelbuild/rules_nodejs/issues/175
471490
_run_tsc(ctx, ctx.outputs.build_es2015, ctx.outputs.build_es5)
472-
source_map = run_terser(ctx, ctx.outputs.build_es5, ctx.outputs.build_es5_min)
473-
run_terser(ctx, ctx.outputs.build_es5, ctx.outputs.build_es5_min_debug, debug = True)
491+
source_map_min = run_terser(ctx, ctx.outputs.build_es5, ctx.outputs.build_es5_min)
492+
run_terser(ctx, ctx.outputs.build_es5, ctx.outputs.build_es5_min_debug, debug = True, in_source_map = source_map_min)
493+
494+
# cjs
474495
cjs_rollup_config = write_rollup_config(ctx, filename = "_%s_cjs.rollup.conf.js", output_format = "cjs")
475496
run_rollup(ctx, _collect_es2015_sources(ctx), cjs_rollup_config, ctx.outputs.build_cjs)
497+
498+
# umd
476499
umd_rollup_config = write_rollup_config(ctx, filename = "_%s_umd.rollup.conf.js", output_format = "umd")
477500
run_rollup(ctx, _collect_es2015_sources(ctx), umd_rollup_config, ctx.outputs.build_umd)
478-
run_sourcemapexplorer(ctx, ctx.outputs.build_es5_min, source_map, ctx.outputs.explore_html)
479-
files = [ctx.outputs.build_es5_min, source_map]
501+
502+
# TODO: ?
503+
run_sourcemapexplorer(ctx, ctx.outputs.build_es5_min, source_map_min, ctx.outputs.explore_html)
504+
505+
files = [ctx.outputs.build_es5_min, source_map_min]
480506

481507
return DefaultInfo(files = depset(files), runfiles = ctx.runfiles(files))
482508

@@ -664,13 +690,22 @@ ROLLUP_ATTRS = {
664690

665691
ROLLUP_OUTPUTS = {
666692
"build_cjs": "%{name}.cjs.js",
693+
"build_cjs_map": "%{name}.cjs.js.map",
667694
"build_es2015": "%{name}.es2015.js",
695+
"build_es2015_map": "%{name}.es2015.js.map",
668696
"build_es2015_min": "%{name}.min.es2015.js",
669697
"build_es2015_min_debug": "%{name}.min_debug.es2015.js",
698+
"build_es2015_min_debug_map": "%{name}.min_debug.es2015.js.map",
699+
"build_es2015_min_map": "%{name}.min.es2015.js.map",
670700
"build_es5": "%{name}.js",
701+
# Disabled due to https://github.com/bazelbuild/rules_nodejs/issues/175
702+
# "build_es5_map": "%{name}.js.map",
671703
"build_es5_min": "%{name}.min.js",
672704
"build_es5_min_debug": "%{name}.min_debug.js",
705+
"build_es5_min_debug_map": "%{name}.min_debug.js.map",
706+
"build_es5_min_map": "%{name}.min.js.map",
673707
"build_umd": "%{name}.umd.js",
708+
"build_umd_map": "%{name}.umd.js.map",
674709
"explore_html": "%{name}.explore.html",
675710
}
676711

0 commit comments

Comments
 (0)