forked from bazel-contrib/rules_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web_package): normalize root paths consistently with ts_devserver
Fixes bazel-contrib#728
- Loading branch information
Jason Bedard
committed
Apr 30, 2019
1 parent
f18986b
commit 97e1593
Showing
15 changed files
with
147 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
EXTS = [ | ||
"js", | ||
"css", | ||
] | ||
|
||
[ | ||
genrule( | ||
name = "bin-" + e, | ||
outs = ["bin." + e], | ||
cmd = "echo '' > $@", | ||
output_to_bindir = True, | ||
) | ||
for e in EXTS | ||
] | ||
|
||
[ | ||
genrule( | ||
name = "gen-" + e, | ||
outs = ["gen." + e], | ||
cmd = "echo '' > $@", | ||
output_to_bindir = False, | ||
) | ||
for e in EXTS | ||
] | ||
|
||
exports_files([ | ||
"file.css", | ||
"file.js", | ||
]) |
Empty file.
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
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,46 @@ | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test", "rollup_bundle") | ||
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package") | ||
|
||
rollup_bundle( | ||
name = "local_bundle", | ||
srcs = glob(["*.js"]), | ||
entry_point = "internal/web_package/test2/script.js", | ||
) | ||
|
||
# Same exts as //internal/web_package/test-exports, //internal/web_package/test2/rel-exports | ||
EXTS = [ | ||
"js", | ||
"css", | ||
] | ||
|
||
web_package( | ||
name = "pkg", | ||
assets = [ | ||
# a bundle from a different directory | ||
"//internal/web_package/test:bundle", | ||
# a bundle in the current path | ||
":local_bundle", | ||
] + | ||
# bin + gen + exported files from a different directory | ||
["//internal/web_package/test-exports:bin-" + e for e in EXTS] + | ||
["//internal/web_package/test-exports:gen-" + e for e in EXTS] + | ||
["//internal/web_package/test-exports:file." + e for e in EXTS] + | ||
# bin + gen + exported files from a sub directory | ||
["//internal/web_package/test2/rel-exports:rel-bin-" + e for e in EXTS] + | ||
["//internal/web_package/test2/rel-exports:rel-gen-" + e for e in EXTS] + | ||
["//internal/web_package/test2/rel-exports:rel-file." + e for e in EXTS], | ||
index_html = "index.html", | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = ["spec.js"], | ||
data = [ | ||
"index_golden.html_", | ||
":pkg", | ||
], | ||
node_modules = "@build_bazel_rules_nodejs_web_package_deps//:node_modules", | ||
tags = [ | ||
"fix-windows", | ||
], | ||
) |
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 @@ | ||
<html></html> |
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,2 @@ | ||
<html><head><link rel="stylesheet" href="/internal/web_package/test-exports/bin.css?v=123"><link rel="stylesheet" href="/internal/web_package/test-exports/gen.css?v=123"><link rel="stylesheet" href="/internal/web_package/test-exports/file.css?v=123"><link rel="stylesheet" href="/rel-exports/rel-bin.css?v=123"><link rel="stylesheet" href="/rel-exports/rel-gen.css?v=123"><link rel="stylesheet" href="/rel-exports/rel-file.css?v=123"></head><body> | ||
<script src="/internal/web_package/test/bundle.min.js?v=123"></script><script src="/local_bundle.min.js?v=123"></script><script src="/internal/web_package/test-exports/bin.js?v=123"></script><script src="/internal/web_package/test-exports/gen.js?v=123"></script><script src="/internal/web_package/test-exports/file.js?v=123"></script><script src="/rel-exports/rel-bin.js?v=123"></script><script src="/rel-exports/rel-gen.js?v=123"></script><script src="/rel-exports/rel-file.js?v=123"></script></body></html> |
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,31 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
EXTS = [ | ||
"js", | ||
"css", | ||
] | ||
|
||
[ | ||
genrule( | ||
name = "rel-bin-" + e, | ||
outs = ["rel-bin." + e], | ||
cmd = "echo '' > $@", | ||
output_to_bindir = True, | ||
) | ||
for e in EXTS | ||
] | ||
|
||
[ | ||
genrule( | ||
name = "rel-gen-" + e, | ||
outs = ["rel-gen." + e], | ||
cmd = "echo '' > $@", | ||
output_to_bindir = False, | ||
) | ||
for e in EXTS | ||
] | ||
|
||
exports_files([ | ||
"rel-file.css", | ||
"rel-file.js", | ||
]) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const el = document.createElement('div'); | ||
el.innerText = 'Hello, World'; | ||
document.body.appendChild(el); |
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,15 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
process.chdir(path.join(process.env['TEST_SRCDIR'], 'build_bazel_rules_nodejs')); | ||
console.error(fs.readdirSync('.')); | ||
describe('web_package paths', () => { | ||
it('should match the golden file', () => { | ||
const output = 'build_bazel_rules_nodejs/internal/web_package/test2/pkg/index.html'; | ||
const golden = 'build_bazel_rules_nodejs/internal/web_package/test2/index_golden.html_'; | ||
const actual = fs.readFileSync(require.resolve(output), {encoding: 'utf-8'}); | ||
const expected = fs.readFileSync(require.resolve(golden), {encoding: 'utf-8'}); | ||
// make the input hermetic by replacing the cache-buster timestamp | ||
expect(actual.replace(/\?v=\d+/g, '?v=123')).toBe(expected); | ||
}); | ||
}); |
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