-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rollup): tests and docs for new rollup_bundle
- Loading branch information
Showing
46 changed files
with
458 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import %workspace%/../../common.bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test") | ||
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle") | ||
|
||
rollup_bundle( | ||
name = "bundle", | ||
srcs = ["msg.js"], | ||
entry_point = "input.js", | ||
) | ||
|
||
golden_file_test( | ||
name = "test", | ||
actual = "bundle/input.js", | ||
golden = "golden.js_", | ||
) | ||
|
||
# For testing from the root workspace of this repository with bazel_integration_test. | ||
filegroup( | ||
name = "all_files", | ||
srcs = glob( | ||
include = ["**/*"], | ||
exclude = [ | ||
"bazel-out/**/*", | ||
"dist/**/*", | ||
"node_modules/**/*", | ||
], | ||
), | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
workspace( | ||
name = "e2e_rollup", | ||
managed_directories = {"@npm": ["node_modules"]}, | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "build_bazel_rules_nodejs", | ||
sha256 = "da72ea53fa1cb8ab5ef7781ba06b97259b7d579a431ce480476266bc81bdf21d", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.36.2/rules_nodejs-0.36.2.tar.gz"], | ||
) | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install") | ||
|
||
yarn_install( | ||
name = "npm", | ||
package_json = "//:package.json", | ||
yarn_lock = "//:yarn.lock", | ||
) | ||
|
||
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies") | ||
|
||
install_bazel_dependencies() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function hello(place) { | ||
return `Hello, ${place}`; | ||
} | ||
|
||
console.log(hello('world')); | ||
//# sourceMappingURL=input.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {hello} from './msg'; | ||
|
||
console.log(hello('world')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function hello(place) { | ||
return `Hello, ${place}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "e2e-rollup", | ||
"private": true, | ||
"devDependencies": { | ||
"@bazel/rollup": "latest", | ||
"rollup": "1.20.3", | ||
"unidiff": "1.0.1" | ||
}, | ||
"scripts": { | ||
"test": "bazel test ..." | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
exports_files(["bin.js"]) | ||
|
||
filegroup( | ||
name = "package_contents", | ||
srcs = glob(["*"]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test") | ||
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle") | ||
|
||
rollup_bundle( | ||
name = "bundle", | ||
srcs = ["strings.js"], | ||
config_file = "rollup.config.js", | ||
entry_point = "input.js", | ||
# TODO: if this isn't here, the error is | ||
# [!] Error: You must set output.dir instead of output.file when generating multiple chunks. | ||
# which will confuse users because it references output.dir instead of output_dir | ||
output_dir = "chunks", | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = ["spec.js"], | ||
data = ["@npm//source-map"], | ||
deps = [":bundle"], | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
output: { | ||
// make chunk filenames predictable | ||
chunkFileNames: '[name].js', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const fs = require('fs'); | ||
|
||
describe('rollup code splitting', () => { | ||
it('should produce a chunk for lazy loaded code', () => { | ||
expect(fs.existsSync(require.resolve(__dirname + '/chunks/bundle.js'))).toBeTruthy(); | ||
expect(fs.existsSync(require.resolve(__dirname + '/chunks/chunk.js'))).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function hello() { | ||
return 'Hello World'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test") | ||
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle") | ||
|
||
rollup_bundle( | ||
name = "bundle", | ||
entry_point = "input.js", | ||
format = "umd", | ||
globals = {"some_global_var": "runtime_name_of_global_var"}, | ||
sourcemap = False, | ||
) | ||
|
||
golden_file_test( | ||
name = "test", | ||
actual = "bundle/input.js", | ||
golden = "golden.js_", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('some_global_var')) : | ||
typeof define === 'function' && define.amd ? define(['some_global_var'], factory) : | ||
(global = global || self, factory(global.runtime_name_of_global_var)); | ||
}(this, function (some_global_var) { 'use strict'; | ||
|
||
console.error(some_global_var.thing); | ||
|
||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {thing} from 'some_global_var'; | ||
|
||
console.error(thing); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test") | ||
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle") | ||
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified") | ||
|
||
[ | ||
rollup_bundle( | ||
name = "bundle.%s" % format, | ||
srcs = ["bar.js"], | ||
config_file = "rollup.config.js", | ||
entry_point = "foo.js", | ||
format = format, | ||
globals = {"some_global_var": "runtime_name_of_global_var"}, | ||
deps = [ | ||
"//%s/fum:fumlib" % package_name(), | ||
"@npm//hello", | ||
], | ||
) | ||
for format in [ | ||
"cjs", | ||
"umd", | ||
] | ||
] | ||
|
||
# Adapt the sourcemap line | ||
# In the prior golden test the output was called bundle.umd.js | ||
# so the sourcemap included that filename | ||
|
||
[ | ||
genrule( | ||
name = "fix_%s_sourcemap" % format, | ||
srcs = ["//internal/rollup/test/rollup:bundle-%s_golden.js_" % format], | ||
outs = ["%s_golden.js_" % format], | ||
cmd = "sed s/bundle.%s.js.map/foo.js.map/ $< > $@" % format, | ||
) | ||
for format in [ | ||
"cjs", | ||
"umd", | ||
] | ||
] | ||
|
||
[ | ||
golden_file_test( | ||
name = "test_%s" % format, | ||
actual = "bundle.%s/foo.js" % format, | ||
golden = "%s_golden.js_" % format, | ||
) | ||
for format in [ | ||
"cjs", | ||
"umd", | ||
] | ||
] | ||
|
||
terser_minified( | ||
name = "bundle.debug.min", | ||
src = "bundle.umd/foo.js", | ||
debug = True, | ||
) | ||
|
||
golden_file_test( | ||
name = "bundle-min-debug", | ||
actual = "bundle.debug.min.js", | ||
golden = "//internal/rollup/test/rollup:bundle-min-debug_golden.js_", | ||
tags = ["manual"], # not working yet, needs something to do transpilation to es5 | ||
) | ||
|
||
# TODO(alexeagle): verify against remaining golden files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const name = 'Alice'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** | ||
* @fileoverview Description of this file. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {fum} from 'fumlib'; | ||
import hello from 'hello'; | ||
import {thing} from 'some_global_var'; | ||
|
||
import {name} from './bar'; | ||
|
||
console.log(`${hello}, ${name} in ${fum}`); | ||
|
||
// Tests for @PURE annotations | ||
/*@__PURE__*/ | ||
console.log('side-effect'); | ||
|
||
class Impure { | ||
constructor() { | ||
console.log('side-effect') | ||
} | ||
} | ||
|
||
/*@__PURE__*/ new Impure(); | ||
|
||
// Test for sequences = false | ||
export class A { | ||
a() { | ||
return document.a; | ||
} | ||
} | ||
function inline_me() { | ||
return 'abc'; | ||
} | ||
console.error(new A().a(), inline_me(), thing, ngDevMode, ngI18nClosureMode); | ||
ngDevMode && console.log('ngDevMode is truthy'); | ||
ngI18nClosureMode && console.log('ngI18nClosureMode is truthy'); |
12 changes: 12 additions & 0 deletions
12
packages/rollup/test/integration_e2e_rollup/fum/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//internal/js_library:js_library.bzl", "js_library") | ||
|
||
package(default_visibility = ["//packages/rollup:__subpackages__"]) | ||
|
||
js_library( | ||
name = "fumlib", | ||
srcs = ["index.js"], | ||
module_name = "fumlib", | ||
# Don't allow deep imports under here, | ||
# and give it the AMD name "fumlib", not "fumlib/index" | ||
module_root = "index.d.ts", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const fum = 'Wonderland'; |
Oops, something went wrong.