Skip to content
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

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
872cff9
js_library poc to work with ts_devserver.
Globegitter May 28, 2018
9ad52e3
Smaller fixes and add devserver example.
Jun 11, 2018
0c5226c
path fixes.
Jun 11, 2018
57eaf37
pairing on js_library
alexeagle Jun 11, 2018
14f58c1
Some smaller improvements and fixes.
Jun 19, 2018
5aac4c8
Remove prints.
Jun 19, 2018
c1cca5e
Ignore config file.
Jun 19, 2018
159ec9b
Fix linting.
Jul 7, 2018
c35f780
More work on module_name.
Jul 8, 2018
2010dfc
Manual merge.
Jul 8, 2018
8976d0e
Build devserver_example.
Jul 8, 2018
62a7d3c
Manual merge latest master.
Aug 23, 2018
ebff561
Fix module_name mapping in rollup_bundle, add own babel-wrapper for b…
Aug 23, 2018
963716f
Ran buildifier.
Aug 23, 2018
5588507
Ensure rule has deps attr.
Aug 23, 2018
ee09e12
Remove whitespace.
Aug 24, 2018
99e24a2
Fix example workspace dependencies.
Aug 26, 2018
e42b523
Fix example workspace dependencies.
Aug 26, 2018
9bd01c4
Add comment about entry_point in rollup_bundle example.
Aug 26, 2018
1ad41eb
Add missing file.
Aug 26, 2018
545a867
Cleanup and get everything working again.
Aug 27, 2018
ae3476f
Run buildifier.
Aug 27, 2018
389eabc
Merge branch 'master' into js-library-poc
Aug 27, 2018
4d4227b
Combine es5 and umd conversion.
Aug 27, 2018
d9d5fed
Put converted files into an es5 dir.
Aug 27, 2018
de43be1
Rever expand_location change.
Sep 22, 2018
09475c0
Manually merge latest master.
Sep 22, 2018
bb5da4f
Update deps.
Sep 22, 2018
f9b4f4a
Remove es5 outputdir and add nodejs_binary example.
Sep 22, 2018
3939553
Buildifier fixes.
Sep 22, 2018
2506f8c
first pass
an-kumar Sep 26, 2018
6334389
add execution requirements
an-kumar Sep 27, 2018
ed5ba77
babelrc
an-kumar Sep 29, 2018
6150ac8
examples
an-kumar Oct 2, 2018
8b96afc
diff module root
an-kumar Oct 2, 2018
696856f
remove deps in package
an-kumar Oct 19, 2018
524642a
remove from internal packagejson
an-kumar Oct 19, 2018
b8e8dc5
trim
an-kumar Oct 19, 2018
8a74cd6
Small refactor of example workspace and _get_path function.
Oct 20, 2018
1feb942
Merge pull request #2 from kitofans/js-library-changes
Globegitter Oct 20, 2018
1b79257
Merge branch 'pr-2' into js-library-poc
Oct 20, 2018
f7294e8
Merge branch 'master' into js-library-poc
Oct 20, 2018
389cb54
Run buildifier.
Oct 20, 2018
3acac7a
Fix package reference.
Oct 20, 2018
496d72f
Update rules typescript for working devserver.
Oct 20, 2018
b185342
Test new examples.
Oct 20, 2018
cfdcd96
Manually merge master.
Oct 25, 2018
a96fa2a
Fix package.bzl.
Oct 25, 2018
6ddea2e
Remove todo and unwanted deps.
Oct 25, 2018
a95cf69
Add mock ts_devserver.
Oct 25, 2018
ccd352a
Improve docs.
Oct 25, 2018
13f9016
Revert formatting changes.
Oct 25, 2018
e2ffd00
Write a mock executable file.
Oct 25, 2018
67f12eb
Renamed js_library to babel_library and progress on idiomatic install.
Oct 26, 2018
6d68f1e
Install package locally.
Oct 26, 2018
e03eb4f
Update node and yarn to latest version and change defaults.
Oct 26, 2018
3c72130
Take correct shas.
Oct 26, 2018
7d5fc4c
Merge branch 'node-yarn-update' into js-library-poc
Oct 26, 2018
1503c1d
Updated examples further.
Oct 26, 2018
cf0a405
Fix nodejs_binary examples.
Oct 26, 2018
982ee03
Fix docstring.
Oct 26, 2018
86301dd
Run buildifier.
Oct 26, 2018
99cf1f3
Manually merge latest master.
Nov 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ jobs:
- run: bazel run //internal/node/test:has_deps
- run: bazel run //internal/node/test:has_deps_hybrid
- run: bazel run @fine_grained_deps_yarn//typescript/bin:tsc
- run: bazel run @nodejs_binary_example//:index

# We should also be able to test targets in a different workspace
- run: bazel test @program_example//...
- run: bazel test @packages_example//...
- run: bazel build @devserver_example//...
- run: bazel build @nodejs_binary_example//...


- save_cache:
key: *cache_key
Expand Down
30 changes: 28 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ local_repository(
path = "examples/packages",
)

local_repository(
name = "devserver_example",
path = "examples/devserver",
)

local_repository(
name = "nodejs_binary_example",
path = "examples/nodejs_binary",
)

local_repository(
name = "bazel_managed_deps_example",
path = "examples/bazel_managed_deps",
Expand Down Expand Up @@ -84,9 +94,14 @@ node_repositories(
# bazel run @nodejs//:npm

load("@packages_example//:setup_workspace.bzl", "packages_example_setup_workspace")

packages_example_setup_workspace()

load("@devserver_example//:setup_workspace.bzl", "devserver_example_setup_workspace")
devserver_example_setup_workspace()

load("@nodejs_binary_example//:setup_workspace.bzl", "nodejs_binary_example_setup_workspace")
nodejs_binary_example_setup_workspace()

# Dependencies to run skydoc
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")
sass_repositories()
Expand All @@ -96,10 +111,21 @@ skydoc_repositories()

# Dependencies to run buildifier and skylint
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()

#
# Install npm dependencies for tests
#
Expand Down
4 changes: 4 additions & 0 deletions examples/devserver/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> 0.5%
last 2 versions
Firefox ESR
not dead
1 change: 1 addition & 0 deletions examples/devserver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files([".browserslistrc"])
77 changes: 77 additions & 0 deletions examples/devserver/WORKSPACE
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()
5 changes: 5 additions & 0 deletions examples/devserver/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"jsesc": "~1.2.0"
}
}
28 changes: 28 additions & 0 deletions examples/devserver/setup_workspace.bzl
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",
)

51 changes: 51 additions & 0 deletions examples/devserver/src/BUILD.bazel
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

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".

data = [
"//:.browserslistrc",
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@Globegitter Globegitter Oct 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand that comment. Yeah so the added .browserslistrc can change how babel transpiles the output js file - but you mean that instead of the js_library deciding on that the root target should do that? While I do like the idea I am not sure how that would be possible.

],
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",
],
)
7 changes: 7 additions & 0 deletions examples/devserver/src/dir/BUILD.bazel
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__"],
)
1 change: 1 addition & 0 deletions examples/devserver/src/dir/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'and';
1 change: 1 addition & 0 deletions examples/devserver/src/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'JS dev workflow';
8 changes: 8 additions & 0 deletions examples/devserver/src/my_lib_folder/BUILD.bazel
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__"],
)
1 change: 1 addition & 0 deletions examples/devserver/src/my_lib_folder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'bazel module';
8 changes: 8 additions & 0 deletions examples/devserver/src/test.js
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);
7 changes: 7 additions & 0 deletions examples/devserver/yarn.lock
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"
71 changes: 71 additions & 0 deletions examples/nodejs_binary/BUILD.bazel
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,
)
15 changes: 15 additions & 0 deletions examples/nodejs_binary/WORKSPACE
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()
12 changes: 12 additions & 0 deletions examples/nodejs_binary/flowLibrary/flow.babelrc
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;
7 changes: 7 additions & 0 deletions examples/nodejs_binary/flowLibrary/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @flow

import internalFileFlow from './internalFile';

export {
internalFileFlow,
};
3 changes: 3 additions & 0 deletions examples/nodejs_binary/flowLibrary/internalFile.js
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;
Loading