-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
babel_library for babel support and compatibility with ts_devserver #217
Changes from 46 commits
872cff9
9ad52e3
0c5226c
57eaf37
14f58c1
5aac4c8
c1cca5e
159ec9b
c35f780
2010dfc
8976d0e
62a7d3c
ebff561
963716f
5588507
ee09e12
99e24a2
e42b523
9bd01c4
1ad41eb
545a867
ae3476f
389eabc
4d4227b
d9d5fed
de43be1
09475c0
bb5da4f
f9b4f4a
3939553
2506f8c
6334389
ed5ba77
6150ac8
8b96afc
696856f
524642a
b8e8dc5
8a74cd6
1feb942
1b79257
f7294e8
389cb54
3acac7a
496d72f
b185342
cfdcd96
a96fa2a
6ddea2e
a95cf69
ccd352a
13f9016
e2ffd00
67f12eb
6d68f1e
e03eb4f
3c72130
7d5fc4c
1503c1d
cf0a405
982ee03
86301dd
99cf1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
> 0.5% | ||
last 2 versions | ||
Firefox ESR | ||
not dead |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports_files([".browserslistrc"]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
workspace(name = "devserver_example") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "bazel_skylib", | ||
url = "https://github.com/bazelbuild/bazel-skylib/archive/0.3.1.zip", | ||
strip_prefix = "bazel-skylib-0.3.1", | ||
sha256 = "95518adafc9a2b656667bbf517a952e54ce7f350779d0dd95133db4eb5c27fb1", | ||
) | ||
|
||
local_repository( | ||
name = "build_bazel_rules_nodejs", | ||
path = "../..", | ||
) | ||
|
||
http_archive( | ||
name = "io_bazel_rules_webtesting", | ||
url = "https://github.com/bazelbuild/rules_webtesting/archive/0.2.1.zip", | ||
strip_prefix = "rules_webtesting-0.2.1", | ||
sha256 = "7d490aadff9b5262e5251fa69427ab2ffd1548422467cb9f9e1d110e2c36f0fa", | ||
) | ||
|
||
http_archive( | ||
name = "io_bazel_rules_go", | ||
url = "https://github.com/bazelbuild/rules_go/releases/download/0.14.0/rules_go-0.14.0.tar.gz", | ||
sha256 = "5756a4ad75b3703eb68249d50e23f5d64eaf1593e886b9aa931aa6e938c4e301", | ||
) | ||
|
||
http_archive( | ||
name = "bazel_gazelle", | ||
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.14.0/bazel-gazelle-0.14.0.tar.gz"], | ||
sha256 = "c0a5739d12c6d05b6c1ad56f2200cb0b57c5a70e03ebd2f7b87ce88cabf09c7b", | ||
) | ||
|
||
http_archive( | ||
name = "build_bazel_rules_typescript", | ||
url = "https://github.com/bazelbuild/rules_typescript/archive/0.20.3.zip", | ||
strip_prefix = "rules_typescript-0.20.3", | ||
sha256 = "2a03b23c30c5109ab0863cfa60acce73ceb56337d41efc2dd67f8455a1c1d5f3", | ||
) | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories") | ||
|
||
# Install a hermetic version of node. | ||
# After this is run, these labels will be available: | ||
# - NodeJS: | ||
# @nodejs//:node | ||
# - NPM: | ||
# @nodejs//:npm | ||
# - The yarn package manager: | ||
# @nodejs//:yarn | ||
node_repositories(package_json = ["//:package.json"], node_version = "8.11.1", yarn_version = "1.6.0") | ||
|
||
# Now the user must run either | ||
# bazel run @nodejs//:yarn | ||
# or | ||
# bazel run @nodejs//:npm | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains") | ||
go_rules_dependencies() | ||
go_register_toolchains() | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
gazelle_dependencies() | ||
|
||
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories", "web_test_repositories") | ||
web_test_repositories() | ||
browser_repositories( | ||
chromium = True, | ||
) | ||
|
||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace") | ||
ts_setup_workspace() | ||
|
||
load("//:setup_workspace.bzl", "devserver_example_setup_workspace") | ||
devserver_example_setup_workspace() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"jsesc": "~1.2.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2017 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. | ||
|
||
"""Helper function to setup @package_example workspace. | ||
""" | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install") | ||
|
||
def devserver_example_setup_workspace(): | ||
"""Node repositories for @devserver_examples | ||
""" | ||
yarn_install( | ||
name = "devserver_example_yarn_install", | ||
package_json = "@devserver_example//:package.json", | ||
yarn_lock = "@devserver_example//:yarn.lock", | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# For the notes in this file see: | ||
# https://github.com/bazelbuild/rules_nodejs/issues/84 | ||
# https://github.com/bazelbuild/bazel/issues/1262 | ||
# https://docs.google.com/document/d/1qPOUeoqDA3eWFFXS1shWX1FT3e4BQB8yuSMrfQL4QrA | ||
|
||
load("@build_bazel_rules_nodejs//internal/js_library/v2:js_library.bzl", "js_library") | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle") | ||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") | ||
|
||
js_library( | ||
name = "module", | ||
srcs = ["module.js"], | ||
) | ||
|
||
js_library( | ||
name = "test", | ||
srcs = ["test.js"], | ||
# Note: This rc file will only be found by babel when run in the devserver_example workspace | ||
# but not in the top-level one, due to how bazel currently handels pathing | ||
data = [ | ||
"//:.browserslistrc", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks like a design flaw to me if my js_library is depended on by two different root targets that provide binaries for two different platforms, how will those targets select the right outputs? The user would have to have parallel js_library trees right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand that comment. Yeah so the added |
||
], | ||
deps = [ | ||
":module", | ||
"//src/dir:module", | ||
"//src/my_lib_folder:my_lib", | ||
], | ||
) | ||
|
||
ts_devserver( | ||
name = "devserver", | ||
# Note: This will only work now when called from the top-level workspace, otherwise it would | ||
# just be src/test | ||
entry_module = "external/devserver_example/src/test", | ||
port = 8080, | ||
serving_path = "/bundle.js", | ||
deps = [ | ||
":test", | ||
], | ||
) | ||
|
||
rollup_bundle( | ||
name = "bundle", | ||
# Note: This will only work now when called from the top-level workspace, otherwise it would | ||
# just be src/test.js | ||
entry_point = "external/devserver_example/src/test.js", | ||
node_modules = "@devserver_example_yarn_install//:node_modules", | ||
deps = [ | ||
":test", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
load("@build_bazel_rules_nodejs//internal/js_library/v2:js_library.bzl", "js_library") | ||
|
||
js_library( | ||
name = "module", | ||
srcs = ["module.js"], | ||
visibility = ["//src:__subpackages__"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'and'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'JS dev workflow'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@build_bazel_rules_nodejs//internal/js_library/v2:js_library.bzl", "js_library") | ||
|
||
js_library( | ||
name = "my_lib", | ||
srcs = ["index.js"], | ||
module_name = "my-lib", | ||
visibility = ["//src:__subpackages__"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'bazel module'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import m from 'my-lib'; | ||
import com from './dir/module'; | ||
import comment from './module'; | ||
|
||
const el = document.createElement('div'); | ||
el.innerText = `Hello, ${comment} ${com} ${m}`; | ||
el.className = 'js'; | ||
document.body.appendChild(el); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
jsesc@~1.2.0: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.2.1.tgz#2c905f923eefcd3d75438f18287aa582527e18b8" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") | ||
load("@build_bazel_rules_nodejs//internal/js_library/v2:js_library.bzl", "js_library") | ||
|
||
js_library( | ||
name = "msg", | ||
srcs = ["msg.js"], | ||
) | ||
|
||
js_library( | ||
name = "lib", | ||
srcs = ["lib.js"], | ||
deps = [ | ||
":msg", | ||
], | ||
) | ||
|
||
js_library( | ||
name = "index_lib", | ||
srcs = ["index.js"], | ||
deps = [ | ||
":lib", | ||
], | ||
) | ||
|
||
js_library( | ||
name = "someLibrary", | ||
srcs = [ | ||
"someLibrary/index.js", | ||
"someLibrary/internalFile.js", | ||
], | ||
module_name = "someLibrary", | ||
module_root = "someLibrary", | ||
) | ||
|
||
nodejs_binary( | ||
name = "flowBabel", | ||
data = [ | ||
"@build_bazel_rules_nodejs//internal/js_library/v2:babel.js", | ||
"@nodejs_binary_example_yarn_install//@babel/core", | ||
"@nodejs_binary_example_yarn_install//@babel/preset-env", | ||
"@nodejs_binary_example_yarn_install//babel-plugin-transform-es2015-modules-commonjs", | ||
"@nodejs_binary_example_yarn_install//babel-plugin-transform-flow-strip-types", | ||
"@nodejs_binary_example_yarn_install//commander", | ||
"@nodejs_binary_example_yarn_install//mkdirp", | ||
], | ||
entry_point = "build_bazel_rules_nodejs/internal/js_library/v2/babel.js", | ||
install_source_map_support = False, | ||
) | ||
|
||
js_library( | ||
name = "flowLibrary", | ||
srcs = [ | ||
"flowLibrary/index.js", | ||
"flowLibrary/internalFile.js", | ||
], | ||
babel = ":flowBabel", | ||
babelrc = "flowLibrary/flow.babelrc", | ||
module_name = "flowLibrary", | ||
module_root = "flowLibrary", | ||
) | ||
|
||
nodejs_binary( | ||
name = "index", | ||
data = [ | ||
":flowLibrary", | ||
":index_lib", | ||
":someLibrary", | ||
], | ||
entry_point = "nodejs_binary_example/index.js", | ||
install_source_map_support = False, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
workspace(name = "nodejs_binary_example") | ||
|
||
local_repository( | ||
name = "build_bazel_rules_nodejs", | ||
path = "../..", | ||
) | ||
load("@build_bazel_rules_nodejs//:package.bzl", "check_rules_nodejs_version", "rules_nodejs_dependencies") | ||
rules_nodejs_dependencies() | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install") | ||
|
||
node_repositories(package_json = ["//:package.json"]) | ||
|
||
load("//:setup_workspace.bzl", "nodejs_binary_example_setup_workspace") | ||
nodejs_binary_example_setup_workspace() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const flowStripTypes = require('babel-plugin-transform-flow-strip-types'); | ||
const commonjs = require('babel-plugin-transform-es2015-modules-commonjs'); | ||
|
||
|
||
const babelConfig = { | ||
plugins: [ | ||
flowStripTypes, | ||
commonjs, | ||
] | ||
}; | ||
|
||
module.exports = babelConfig; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// @flow | ||
|
||
import internalFileFlow from './internalFile'; | ||
|
||
export { | ||
internalFileFlow, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @flow | ||
const message: string = 'hello from internalFile in flowLibrary'; | ||
export default message; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be "handles".