Skip to content

Commit d85db79

Browse files
committed
Produce native ES modules in rollup es2015 mode
Change the names of the chunk directories. Having dots in the names make users assume these are files, not directories. Also the 'cs' extension isn't as obvious as 'chunks'. It seems wrong that the test has to change to grab the default export. Need to figure out still.
1 parent 2be3c7a commit d85db79

4 files changed

Lines changed: 52 additions & 46 deletions

File tree

‎internal/e2e/rollup_code_splitting/additional_entry.spec.js‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,43 @@ describe('bundling additional entry point', () => {
88
check(path, 'bundle.min.js', 'bundle-min_golden.js_');
99
});
1010

11-
it('bundle.cs.es6 should work', () => {
11+
// Disabled because native ESModules can't be loaded in current nodejs
12+
xit('bundle_chunks_es6 should work', () => {
1213
const additional_entry = require(
13-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.es6/additional_entry.js')
14+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_es6/additional_entry.js');
15+
console.error(additional_entry)
1416
const actual = (new additional_entry()).test();
1517
expect(actual).toEqual(expected);
1618
});
1719

18-
it('bundle.cs should work', () => {
19-
const additional_entry = require(
20-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs/additional_entry.js')
21-
const actual = (new additional_entry()).test();
20+
it('bundle_chunks should work', () => {
21+
const additional_entry =
22+
require(
23+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks/additional_entry.js')
24+
.default const actual = (new additional_entry()).test();
2225
expect(actual).toEqual(expected);
2326
});
2427

25-
it('bundle.cs.min should work', () => {
26-
const additional_entry = require(
27-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.min/additional_entry.js')
28-
const actual = (new additional_entry()).test();
28+
it('bundle_chunks_min should work', () => {
29+
const additional_entry =
30+
require(
31+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/additional_entry.js')
32+
.default const actual = (new additional_entry()).test();
2933
expect(actual).toEqual(expected);
3034
});
3135

32-
it('bundle.cs.min_debug should work', () => {
33-
const additional_entry = require(
34-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.min_debug/additional_entry.js')
35-
const actual = (new additional_entry()).test();
36+
it('bundle_chunks_min_debug should work', () => {
37+
const additional_entry =
38+
require(
39+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/additional_entry.js')
40+
.default const actual = (new additional_entry()).test();
3641
expect(actual).toEqual(expected);
3742
});
3843

3944
it('should have a license header', () => {
4045
const content = fs.readFileSync(
4146
require.resolve(
42-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.min_debug/additional_entry.js'),
47+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/additional_entry.js'),
4348
{encoding: 'utf-8'});
4449
expect(content).toContain('dummy license banner');
4550
});

‎internal/e2e/rollup_code_splitting/bundle-min_golden.js_‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(function(global) {
44
System.config({
55
packages: {
6-
'': {map: {"./main1.js": "bundle.cs.min/main1.js", "./additional_entry.js": "bundle.cs.min/additional_entry.js"}, defaultExtension: 'js'},
6+
'': {map: {"./main1.js": "bundle_chunks_min/main1.js", "./additional_entry.js": "bundle_chunks_min/additional_entry.js"}, defaultExtension: 'js'},
77
}
88
});
99
System.import('main1.js').catch(function(err) {

‎internal/e2e/rollup_code_splitting/main1.spec.js‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@ const exportedTest1 = 'dep1 fn,lib2 fn,dep2 fn';
33
const exportedTest2 = 'dep4 fn';
44

55
describe('bundling main entry point', () => {
6-
it('bundle.cs.es6 should work', async () => {
6+
// Disabled since native ESModules can't be loaded in nodejs yet
7+
xit('bundle_chunks_es6 should work', async () => {
78
const main1 = require(
8-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.es6/main1.js')
9+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_es6/main1.js')
910
expect(main1.test()).toEqual(exportedTest1);
1011
const actualTest2 = await main1.test2();
1112
expect(actualTest2).toEqual(exportedTest2);
1213
});
1314

14-
it('bundle.cs should work', async () => {
15-
const main1 =
16-
require('build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs/main1.js')
15+
it('bundle_chunks should work', async () => {
16+
const main1 = require(
17+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks/main1.js')
1718
expect(main1.test()).toEqual(exportedTest1);
1819
const actualTest2 = await main1.test2();
1920
expect(actualTest2).toEqual(exportedTest2);
2021
});
2122

22-
it('bundle.cs.min should work', async () => {
23+
it('bundle_chunks_min should work', async () => {
2324
const main1 = require(
24-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.min/main1.js')
25+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/main1.js')
2526
expect(main1.test()).toEqual(exportedTest1);
2627
const actualTest2 = await main1.test2();
2728
expect(actualTest2).toEqual(exportedTest2);
2829
});
2930

30-
it('bundle.cs.min_debug should work', async () => {
31+
it('bundle_chunks_min_debug should work', async () => {
3132
const main1 = require(
32-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.min_debug/main1.js')
33+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min_debug/main1.js')
3334
expect(main1.test()).toEqual(exportedTest1);
3435
const actualTest2 = await main1.test2();
3536
expect(actualTest2).toEqual(exportedTest2);
@@ -38,7 +39,7 @@ describe('bundling main entry point', () => {
3839
it('should have a license header', () => {
3940
const content = fs.readFileSync(
4041
require.resolve(
41-
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle.cs.min/main1.js'),
42+
'build_bazel_rules_nodejs/internal/e2e/rollup_code_splitting/bundle_chunks_min/main1.js'),
4243
{encoding: 'utf-8'});
4344
expect(content).toContain('dummy license banner');
4445
});

‎internal/rollup/rollup_bundle.bzl‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,17 @@ def _generate_code_split_entry(ctx, bundles_folder, output):
354354
355355
In this case, the main_entry_point_dirname will evaluate to
356356
`src/` and this will be stripped from the entry points for
357-
the map. If folder is `bundle.cs`, the generated SystemJS
357+
the map. If folder is `bundle_chunks`, the generated SystemJS
358358
boilerplate/entry point file will look like:
359359
360360
```
361361
(function(global) {
362362
System.config({
363363
packages: {
364364
'': {map: {
365-
"./main.prod": "bundle.cs/main.prod",
366-
"./hello-world/hello-world.module.ngfactory": "bundle.cs/hello-world.module.ngfactory",
367-
"./todos/todos.module.ngfactory": "bundle.cs/todos.module.ngfactory"},
365+
"./main.prod": "bundle_chunks/main.prod",
366+
"./hello-world/hello-world.module.ngfactory": "bundle_chunks/hello-world.module.ngfactory",
367+
"./todos/todos.module.ngfactory": "bundle_chunks/todos.module.ngfactory"},
368368
defaultExtension: 'js'},
369369
}
370370
});
@@ -399,27 +399,27 @@ def _rollup_bundle(ctx):
399399
if ctx.attr.additional_entry_points:
400400
# Generate code split bundles if additional entry points have been specified.
401401
# See doc for additional_entry_points for more information.
402-
# Note: ".cs" is needed on the output folders since ctx.label.name + ".es6" is already
402+
# Note: "_chunks" is needed on the output folders since ctx.label.name + ".es6" is already
403403
# a folder that contains the re-rooted es6 sources
404-
rollup_config = write_rollup_config(ctx, output_format = "cjs", additional_entry_points = ctx.attr.additional_entry_points)
405-
code_split_es6_output_dir = ctx.actions.declare_directory(ctx.label.name + ".cs.es6")
404+
rollup_config = write_rollup_config(ctx, output_format = "es", additional_entry_points = ctx.attr.additional_entry_points)
405+
code_split_es6_output_dir = ctx.actions.declare_directory(ctx.label.name + "_chunks_es6")
406406
_run_rollup(ctx, collect_es6_sources(ctx), rollup_config, code_split_es6_output_dir)
407-
code_split_es5_output_dir = ctx.actions.declare_directory(ctx.label.name + ".cs")
407+
code_split_es5_output_dir = ctx.actions.declare_directory(ctx.label.name + "_chunks")
408408
_run_tsc_on_directory(ctx, code_split_es6_output_dir, code_split_es5_output_dir)
409-
code_split_es5_min_output_dir = ctx.actions.declare_directory(ctx.label.name + ".cs.min")
409+
code_split_es5_min_output_dir = ctx.actions.declare_directory(ctx.label.name + "_chunks_min")
410410
_run_uglify(ctx, code_split_es5_output_dir, code_split_es5_min_output_dir, None)
411-
code_split_es5_min_debug_output_dir = ctx.actions.declare_directory(ctx.label.name + ".cs.min_debug")
411+
code_split_es5_min_debug_output_dir = ctx.actions.declare_directory(ctx.label.name + "_chunks_min_debug")
412412
_run_uglify(ctx, code_split_es5_output_dir, code_split_es5_min_debug_output_dir, None, debug = True)
413413

414414
# Generate the SystemJS boilerplate/entry point files
415-
_generate_code_split_entry(ctx, ctx.label.name + ".cs.es6", ctx.outputs.build_es6)
416-
_generate_code_split_entry(ctx, ctx.label.name + ".cs", ctx.outputs.build_es5)
417-
_generate_code_split_entry(ctx, ctx.label.name + ".cs.min", ctx.outputs.build_es5_min)
418-
_generate_code_split_entry(ctx, ctx.label.name + ".cs.min_debug", ctx.outputs.build_es5_min_debug)
415+
_generate_code_split_entry(ctx, ctx.label.name + "_chunks_es6", ctx.outputs.build_es6)
416+
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_es5)
417+
_generate_code_split_entry(ctx, ctx.label.name + "_chunks_min", ctx.outputs.build_es5_min)
418+
_generate_code_split_entry(ctx, ctx.label.name + "_chunks_min_debug", ctx.outputs.build_es5_min_debug)
419419

420420
# There is no UMD/CJS bundle when code-splitting but we still need to satisfy the output
421-
_generate_code_split_entry(ctx, ctx.label.name + ".cs", ctx.outputs.build_umd)
422-
_generate_code_split_entry(ctx, ctx.label.name + ".cs", ctx.outputs.build_cjs)
421+
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_umd)
422+
_generate_code_split_entry(ctx, ctx.label.name + "_chunks", ctx.outputs.build_cjs)
423423

424424
# There is no source map explorer output when code-splitting but we still need to satisfy the output
425425
ctx.actions.expand_template(
@@ -483,10 +483,10 @@ ROLLUP_ATTRS = {
483483
bundled.
484484
485485
Entry points and chunks will be outputted to folders:
486-
- <label-name>.cs.es6 // es6
487-
- <label-name>.cs // es5
488-
- <label-name>.cs.min // es5 minified
489-
- <label-name>.cs.min_debug // es5 minified debug
486+
- <label-name>_chunks_es6 // es6
487+
- <label-name>_chunks // es5
488+
- <label-name>_chunks_min // es5 minified
489+
- <label-name>_chunks_min_debug // es5 minified debug
490490
491491
The following files will be outputted that contain the
492492
SystemJS boilerplate to map the entry points to their file

0 commit comments

Comments
 (0)