Skip to content

Commit

Permalink
Refactor rollup config, add unit test
Browse files Browse the repository at this point in the history
Also, make multiple rootDirs work in rollup resolution
  • Loading branch information
alexeagle committed Feb 5, 2018
1 parent 7c21107 commit 5307b57
Show file tree
Hide file tree
Showing 14 changed files with 433 additions and 86 deletions.
9 changes: 4 additions & 5 deletions internal/collect_es6_sources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ def collect_es6_sources(ctx):

rerooted_files = []
for file in non_rerooted_files.to_list():
if file.short_path.startswith(".."):
rerooted_path = "/".join(file.short_path.split("/")[1:])
else:
rerooted_path = "/".join([ctx.workspace_name, file.short_path])
path = file.short_path
if (path.startswith("../")):
path = "external/" + path[3:]

rerooted_file = ctx.actions.declare_file(
"%s.es6/%s" % (
ctx.label.name,
# the .closure.js filename is an artifact of the rules_typescript layout
# TODO(mrmeku): pin to end of string, eg. don't match foo.closure.jso.js
rerooted_path.replace(".closure.js", ".js")))
path.replace(".closure.js", ".js")))
# Cheap way to create an action that copies a file
# TODO(alexeagle): discuss with Bazel team how we can do something like
# runfiles to create a re-rooted tree. This has performance implications.
Expand Down
1 change: 1 addition & 0 deletions internal/e2e/rollup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ filegroup(
srcs = glob([
"node_modules/**/*",
]),
visibility = ["//internal:__subpackages__"],
)

load("//:defs.bzl", "rollup_bundle")
Expand Down
20 changes: 0 additions & 20 deletions internal/e2e/rollup/foo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ import {fum} from 'fumlib';

console.log(`Hello, ${name} in ${fum}`);

/** This class should be tree-shaken away */
var ReflectiveInjector = /** @class */ (function () {
function ReflectiveInjector() {
}
return ReflectiveInjector;
}());

/** This class should be tree-shaken away */
var ReflectiveInjector_ = /** @class */ (function () {
function ReflectiveInjector_(_providers, _parent) {}
ReflectiveInjector_.prototype.resolveAndInstantiate =
function (provider) {
return ReflectiveInjector;
};
Object.defineProperty(ReflectiveInjector_, "displayName", "foo");
return ReflectiveInjector_;
}());

ngDevMode && console.log("Should have been tree-shaken");

// Test for sequences = false
class A {
a() { return document.a; }
Expand Down
4 changes: 3 additions & 1 deletion internal/e2e/rollup/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"devDependencies": {
"jasmine": "~2.8.0"
"jasmine": "~2.8.0",
"rollup": "0.52.3",
"rollup-plugin-node-resolve": "3.0.0"
}
}
4 changes: 2 additions & 2 deletions internal/e2e/rollup/rollup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
function read(relativePath) {
// TODO(#32) Can shorten the path if https://github.com/bazelbuild/rules_nodejs/issues/32 is resolved
const path = `build_bazel_rules_nodejs/internal/e2e/rollup/${relativePath}`;
return fs.readFileSync(require.resolve(path), { encoding: 'utf-8' });
return fs.readFileSync(require.resolve(path), { encoding: 'utf-8' }).replace(/\r\n/g, '\n');
}
describe('bundling', () => {
it('should work', () => {
Expand All @@ -12,4 +12,4 @@ describe('bundling', () => {
it('should produce a debug bundle', () => {
expect(read('bundle.min_debug.js')).toEqual(read('bundle-min-debug_golden.js'));
});
});
});
Loading

0 comments on commit 5307b57

Please sign in to comment.