From e17e5b99d486d79cb4d21d61f12fc694089a7f11 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Sun, 21 Apr 2019 12:51:51 -0700 Subject: [PATCH] Update to buildifier 0.22.0 and fix new lint warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t check no-effect warning since doc is not a valid attribute for repository_rule() and using a doc attribute in a rule() also causes a build error in Ubuntu 14.04 only. Tracked in https://github.com/bazelbuild/buildtools/issues/471. --- e2e/ts_devserver/genrule/BUILD.bazel | 2 - internal/common/node_module_info.bzl | 2 + internal/node/node.bzl | 10 ++ internal/node/node_repositories.bzl | 9 -- internal/npm_install/node_module_library.bzl | 3 + internal/npm_install/npm_install.bzl | 6 + internal/npm_package/npm_package.bzl | 10 ++ internal/rollup/rollup_bundle.bzl | 13 +- internal/web_package/web_package.bzl | 53 ++++++- package.json | 12 +- packages/jasmine/index.bzl | 17 +++ packages/karma/karma_web_test.bzl | 2 +- packages/karma/ts_web_test.bzl | 2 +- packages/labs/webpack/index.bzl | 17 +++ packages/labs/webpack/src/webpack_bundle.bzl | 19 +++ packages/typescript/defs.bzl | 4 +- packages/typescript/index.bzl | 4 +- packages/typescript/index.docs.bzl | 26 +++- packages/typescript/internal/build_defs.bzl | 144 +++++++++--------- .../internal/devserver/ts_devserver.bzl | 4 +- .../internal/internal_ts_repositories.bzl | 17 +++ .../internal/protobufjs/ts_proto_library.bzl | 96 ++++++------ packages/typescript/internal/ts_config.bzl | 10 +- yarn.lock | 32 ++-- 24 files changed, 341 insertions(+), 173 deletions(-) diff --git a/e2e/ts_devserver/genrule/BUILD.bazel b/e2e/ts_devserver/genrule/BUILD.bazel index 1086ed418a..66ae2f843f 100644 --- a/e2e/ts_devserver/genrule/BUILD.bazel +++ b/e2e/ts_devserver/genrule/BUILD.bazel @@ -54,8 +54,6 @@ ts_devserver( deps = [":app"], ) -"" - genrule( name = "say-hello", outs = ["say-hello.js"], diff --git a/internal/common/node_module_info.bzl b/internal/common/node_module_info.bzl index 884050402a..044daed558 100644 --- a/internal/common/node_module_info.bzl +++ b/internal/common/node_module_info.bzl @@ -38,6 +38,8 @@ NodeModuleInfo = provider( # NodeModuleSources provider is provided by targets that are npm dependencies by the # `node_module_library` rule as well as other targets that have direct or transitive deps on # `node_module_library` targets via the `collect_node_modules_aspect` below. +# TODO: rename to NodeModuleSourcesInfo so name doesn't trigger name-conventions warning +# buildozer: disable=name-conventions NodeModuleSources = provider( doc = "Provides sources for npm dependencies installed with yarn_install and npm_install rules", fields = { diff --git a/internal/node/node.bzl b/internal/node/node.bzl index ababd6a880..9a7831c262 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -378,6 +378,16 @@ Now you can add `--config=debug` to any `bazel test` command line. The runtime will pause before executing the program, allowing you to connect a remote debugger. """ +# Adding the above nodejs_test & nodejs_binary docstrings as `doc` attributes +# causes a build error but ONLY on Ubuntu 14.04 on BazelCI. +# ``` +# File "internal/node/node.bzl", line 378, in +# outputs = _NODEJS_EXECUTABLE_OUTPUTS, +# TypeError: rule() got an unexpected keyword argument 'doc' +# ``` +# This error does not occur on any other platform on BazelCI including Ubuntu 16.04. +# TOOD(gregmagolan): Figure out why and/or file a bug to Bazel +# See https://github.com/bazelbuild/buildtools/issues/471#issuecomment-485283200 def nodejs_binary_macro(name, data = [], args = [], visibility = None, tags = [], testonly = 0, **kwargs): """This macro exists only to wrap the nodejs_binary as an .exe for Windows. diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index 61523e4d37..f5a811410e 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -513,23 +513,14 @@ def node_repositories( when you manually run the package manager, e.g. with `bazel run @nodejs//:yarn` or `bazel run @nodejs//:npm install`. If you use bazel-managed dependencies, you can omit this attribute. - node_version: optional; the specific version of NodeJS to install. - yarn_version: optional; the specific version of Yarn to install. - vendored_node: optional; the local path to a pre-installed NodeJS runtime. - vendored_yarn: optional; the local path to a pre-installed yarn tool. - node_repositories: optional; custom list of node repositories to use. - yarn_repositories: optional; custom list of yarn repositories to use. - node_urls: optional; custom list of URLs to use to download NodeJS. - yarn_urls: optional; custom list of URLs to use to download Yarn. - preserve_symlinks: Turn on --node_options=--preserve-symlinks for nodejs_binary and nodejs_test rules. The default for this is currently True but the options is deprecated and will be removed in the future. When this option is turned on, node will preserve the symlinked path for resolves instead of the default diff --git a/internal/npm_install/node_module_library.bzl b/internal/npm_install/node_module_library.bzl index 848b81874c..775686fa39 100644 --- a/internal/npm_install/node_module_library.bzl +++ b/internal/npm_install/node_module_library.bzl @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Contains the node_module_library which is used by yarn_install & npm_install. +""" + load("@build_bazel_rules_nodejs//internal/common:node_module_info.bzl", "NodeModuleInfo", "NodeModuleSources") def _node_module_library_impl(ctx): diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl index 9287b5cfa0..eea4369e89 100644 --- a/internal/npm_install/npm_install.bzl +++ b/internal/npm_install/npm_install.bzl @@ -226,6 +226,9 @@ npm_install = repository_rule( implementation = _npm_install_impl, ) """Runs npm install during workspace setup.""" +# Adding the above docstring as `doc` attribute causes a build +# error since `doc` is not a valid attribute of repository_rule. +# See https://github.com/bazelbuild/buildtools/issues/471#issuecomment-485278689. def _yarn_install_impl(repository_ctx): """Core implementation of yarn_install.""" @@ -321,3 +324,6 @@ yarn_install = repository_rule( implementation = _yarn_install_impl, ) """Runs yarn install during workspace setup.""" +# Adding the above docstring as `doc` attribute causes a build +# error since `doc` is not a valid attribute of repository_rule. +# See https://github.com/bazelbuild/buildtools/issues/471#issuecomment-485278689. diff --git a/internal/npm_package/npm_package.bzl b/internal/npm_package/npm_package.bzl index c4494a9c2a..4ece0b42a9 100644 --- a/internal/npm_package/npm_package.bzl +++ b/internal/npm_package/npm_package.bzl @@ -220,3 +220,13 @@ $ bazel run :my_package.publish You can pass arguments to npm by escaping them from Bazel using a double-hyphen `bazel run my_package.publish -- --tag=next` """ +# Adding the above docstring as `doc` attribute +# causes a build error but ONLY on Ubuntu 14.04 on BazelCI. +# ``` +# File "internal/npm_package/npm_package.bzl", line 221, in +# outputs = NPM_PACKAGE_OUTPUTS, +# TypeError: rule() got an unexpected keyword argument 'doc' +# ``` +# This error does not occur on any other platform on BazelCI including Ubuntu 16.04. +# TOOD(gregmagolan): Figure out why and/or file a bug to Bazel +# See https://github.com/bazelbuild/buildtools/issues/471#issuecomment-485283200 diff --git a/internal/rollup/rollup_bundle.bzl b/internal/rollup/rollup_bundle.bzl index 556f759dfb..82d13a3ce6 100644 --- a/internal/rollup/rollup_bundle.bzl +++ b/internal/rollup/rollup_bundle.bzl @@ -718,7 +718,8 @@ rollup_bundle = rule( attrs = ROLLUP_ATTRS, outputs = ROLLUP_OUTPUTS, ) -"""Produces several bundled JavaScript files using Rollup and terser. +""" +Produces several bundled JavaScript files using Rollup and terser. Load it with `load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")` @@ -748,3 +749,13 @@ For debugging, note that the `rollup.config.js` and `terser.config.json` files c An example usage can be found in https://github.com/bazelbuild/rules_nodejs/tree/master/internal/e2e/rollup """ +# Adding the above docstring as `doc` attribute +# causes a build error but ONLY on Ubuntu 14.04 on BazelCI. +# ``` +# File "internal/npm_package/npm_package.bzl", line 221, in +# outputs = NPM_PACKAGE_OUTPUTS, +# TypeError: rule() got an unexpected keyword argument 'doc' +# ``` +# This error does not occur on any other platform on BazelCI including Ubuntu 16.04. +# TOOD(gregmagolan): Figure out why and/or file a bug to Bazel +# See https://github.com/bazelbuild/buildtools/issues/471#issuecomment-485283200 diff --git a/internal/web_package/web_package.bzl b/internal/web_package/web_package.bzl index 1449ddbd8f..73b0d87fda 100644 --- a/internal/web_package/web_package.bzl +++ b/internal/web_package/web_package.bzl @@ -1,8 +1,38 @@ -def html_asset_inject(index_html, action_factory, injector, rootDirs, assets, output): +# Copyright 2019 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. + +"""Contains the web_package rule. +""" + +def html_asset_inject(index_html, action_factory, injector, root_dirs, assets, output): + """Injects JS and CSS resources into the index.html. + + Args: + index_html: the input html file + action_factory: TODO + injector: TODO + root_dirs: TODO + assets: TODO + output: the output html file + + Returns: + The output html file + """ args = action_factory.args() args.add(output.path) args.add(index_html.path) - args.add_all(rootDirs) + args.add_all(root_dirs) args.add("--assets") args.add_all(assets) args.use_param_file("%s", use_always = True) @@ -15,6 +45,18 @@ def html_asset_inject(index_html, action_factory, injector, rootDirs, assets, ou return output def move_files(output_name, files, action_factory, assembler, root_paths): + """Moves files into an output directory + + Args: + output_name: the name of the output directory + files: the files to move + action_factory: TODO + assembler: TODO + root_paths: TODO + + Returns: + The output directory tree-artifact + """ www_dir = action_factory.declare_directory(output_name) args = action_factory.args() args.add(www_dir.path) @@ -91,9 +133,8 @@ web_package = rule( cfg = "host", ), }, - doc = """ -Assembles a web application from source files. + doc = """Assembles a web application from source files. -Injects JS and CSS resources into the index.html. -""", + Injects JS and CSS resources into the index.html. + """, ) diff --git a/package.json b/package.json index 8ea4b54f31..0e70b731ec 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "devDependencies": { "@bazel/bazel": "0.23.0", - "@bazel/buildifier": "^0.20.0", + "@bazel/buildifier": "0.22.0", "@bazel/ibazel": "^0.9.1", "@bazel/typescript": "0.23.2", "clang-format": "1.2.2", @@ -49,7 +49,15 @@ "test_legacy_e2e": "./scripts/test_legacy_e2e.sh", "test_packages_all": "./scripts/test_packages_all.sh", "test_packages": "./scripts/test_packages.sh", - "bazel:format": "find . -type f \\( -name \"*.bzl\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" ! -path \"./dist/*\" ! -path \"./third_party/*\" | xargs buildifier -v --warnings=args-order,attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,constant-glob,ctx-actions,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,git-repository,http-archive,integer-division,load,load-on-top,native-build,native-package,out-of-order-load,output-group,package-name,package-on-top,positional-args,redefined-variable,repository-name,same-origin-load,string-iteration,unsorted-dict-items,unused-variable", + "// Unchecked warnings": "The following warnings are not checked as disabling them locally is broken", + "// rule-impl-return": "./internal/common/typescript_mock_lib.bzl:29: rule-impl-return: Avoid using the legacy provider syntax. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#rule-impl-return)", + "// rule-impl-return(2)": "./packages/typescript/internal/protobufjs/ts_proto_library.bzl:105: rule-impl-return: Avoid using the legacy provider syntax. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#rule-impl-return)", + "// uninitialized": "./internal/node/node.bzl:95: uninitialized: Variable 'd' may not have been initialized. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#uninitialized)", + "// uninitialized(2)": "./internal/node/node.bzl:95: uninitialized: Variable 'd' may not have been initialized. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#uninitialized)", + "// uninitialized(3)": "./packages/typescript/internal/build_defs.bzl:95: uninitialized: Variable 'output' may not have been initialized. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#uninitialized)", + "// no-effect": "./internal/npm_install/npm_install.bzl:228: no-effect: Expression result is not used. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#no-effect)", + "// no-effect(2)": "./internal/npm_install/npm_install.bzl:325: no-effect: Expression result is not used. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#no-effect)", + "bazel:format": "find . -type f \\( -name \"*.bzl\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" ! -path \"./dist/*\" ! -path \"./third_party/*\" | xargs buildifier -v --warnings=attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,confusing-name,constant-glob,ctx-actions,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,function-docstring,git-repository,http-archive,integer-division,load,load-on-top,module-docstring,name-conventions,native-build,native-package,out-of-order-load,output-group,package-name,package-on-top,positional-args,redefined-variable,repository-name,return-value,same-origin-load,string-iteration,unreachable,unsorted-dict-items,unused-variable", "bazel:lint": "yarn bazel:format --lint=warn", "bazel:lint-fix": "yarn bazel:format --lint=fix", "format": "git-clang-format", diff --git a/packages/jasmine/index.bzl b/packages/jasmine/index.bzl index f028e77df2..9d4cc58057 100644 --- a/packages/jasmine/index.bzl +++ b/packages/jasmine/index.bzl @@ -1,3 +1,20 @@ +# Copyright 2019 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. + +""" Public API surface is re-exported here. +""" + # Public API surface re-exports # Users shouldn't import under src/ diff --git a/packages/karma/karma_web_test.bzl b/packages/karma/karma_web_test.bzl index 9d58220d82..77beed4f7e 100644 --- a/packages/karma/karma_web_test.bzl +++ b/packages/karma/karma_web_test.bzl @@ -16,8 +16,8 @@ load("@build_bazel_rules_nodejs//internal/common:expand_into_runfiles.bzl", "expand_path_into_runfiles") load("@build_bazel_rules_nodejs//internal/common:sources_aspect.bzl", "sources_aspect") load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "write_amd_names_shim") -load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") load("@io_bazel_rules_webtesting//web:web.bzl", "web_test_suite") +load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") load(":web_test.bzl", "COMMON_WEB_TEST_ATTRS") _CONF_TMPL = "//:karma.conf.js" diff --git a/packages/karma/ts_web_test.bzl b/packages/karma/ts_web_test.bzl index ab5329b29a..28f796bf51 100644 --- a/packages/karma/ts_web_test.bzl +++ b/packages/karma/ts_web_test.bzl @@ -13,8 +13,8 @@ # limitations under the License. "Unit testing in a browser" -load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") load("@io_bazel_rules_webtesting//web:web.bzl", "web_test_suite") +load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") load(":karma_web_test.bzl", "KARMA_GENERIC_WEB_TEST_ATTRS", "run_karma_web_test") # Using generic karma_web_test attributes under the hood diff --git a/packages/labs/webpack/index.bzl b/packages/labs/webpack/index.bzl index ffdd75362e..6d068bce80 100644 --- a/packages/labs/webpack/index.bzl +++ b/packages/labs/webpack/index.bzl @@ -1,3 +1,20 @@ +# Copyright 2019 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. + +""" Public API surface is re-exported here. +""" + # Public API surface re-exports # Users shouldn't import under src/ diff --git a/packages/labs/webpack/src/webpack_bundle.bzl b/packages/labs/webpack/src/webpack_bundle.bzl index d95d32458b..a6410435e5 100644 --- a/packages/labs/webpack/src/webpack_bundle.bzl +++ b/packages/labs/webpack/src/webpack_bundle.bzl @@ -1,3 +1,22 @@ +# Copyright 2019 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. + +"""Contains the webpack_bundle rule + +This rule is experimental, as part of Angular Labs! There may be breaking changes. +""" + WEBPACK_BUNDLE_ATTRS = { "srcs": attr.label_list(allow_files = True), "entry_point": attr.label(allow_single_file = True, mandatory = True), diff --git a/packages/typescript/defs.bzl b/packages/typescript/defs.bzl index 07fc9c941c..1fcace1a85 100644 --- a/packages/typescript/defs.bzl +++ b/packages/typescript/defs.bzl @@ -19,11 +19,11 @@ New rules will be added to index.bzl. """ load("//:version.bzl", _check_rules_typescript_version = "check_rules_typescript_version") -load("//internal/devserver:ts_devserver.bzl", _ts_devserver = "ts_devserver_macro") -load("//internal/protobufjs:ts_proto_library.bzl", _ts_proto_library = "ts_proto_library") load("//internal:build_defs.bzl", _ts_library = "ts_library_macro") load("//internal:ts_config.bzl", _ts_config = "ts_config") load("//internal:ts_repositories.bzl", _ts_setup_workspace = "ts_setup_workspace") +load("//internal/devserver:ts_devserver.bzl", _ts_devserver = "ts_devserver_macro") +load("//internal/protobufjs:ts_proto_library.bzl", _ts_proto_library = "ts_proto_library") check_rules_typescript_version = _check_rules_typescript_version ts_setup_workspace = _ts_setup_workspace diff --git a/packages/typescript/index.bzl b/packages/typescript/index.bzl index 924219962a..60058ff5b7 100644 --- a/packages/typescript/index.bzl +++ b/packages/typescript/index.bzl @@ -18,11 +18,11 @@ Users should not load files under "/internal" """ load("//:version.bzl", _check_rules_typescript_version = "check_rules_typescript_version") -load("//internal/devserver:ts_devserver.bzl", _ts_devserver = "ts_devserver_macro") -load("//internal/protobufjs:ts_proto_library.bzl", _ts_proto_library = "ts_proto_library") load("//internal:build_defs.bzl", _ts_library = "ts_library_macro") load("//internal:ts_config.bzl", _ts_config = "ts_config") load("//internal:ts_repositories.bzl", _ts_setup_workspace = "ts_setup_workspace") +load("//internal/devserver:ts_devserver.bzl", _ts_devserver = "ts_devserver_macro") +load("//internal/protobufjs:ts_proto_library.bzl", _ts_proto_library = "ts_proto_library") check_rules_typescript_version = _check_rules_typescript_version ts_setup_workspace = _ts_setup_workspace diff --git a/packages/typescript/index.docs.bzl b/packages/typescript/index.docs.bzl index cd9828d5f9..401a7fc96e 100644 --- a/packages/typescript/index.docs.bzl +++ b/packages/typescript/index.docs.bzl @@ -1,13 +1,29 @@ -# This contains references to the symbols we want documented. -# We can't point stardoc to the top-level index.bzl since then it will see macros rather than the rules they wrap. -# So this is a copy of index.bzl with macro indirection removed. +# Copyright 2019 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. + +"""This contains references to the symbols we want documented. + +We can't point stardoc to the top-level index.bzl since then it will see macros rather than the rules they wrap. +So this is a copy of index.bzl with macro indirection removed. +""" load("//:version.bzl", _check_rules_typescript_version = "check_rules_typescript_version") -load("//internal/devserver:ts_devserver.bzl", _ts_devserver = "ts_devserver") -load("//internal/protobufjs:ts_proto_library.bzl", _ts_proto_library = "ts_proto_library") load("//internal:build_defs.bzl", _ts_library = "ts_library") load("//internal:ts_config.bzl", _ts_config = "ts_config") load("//internal:ts_repositories.bzl", _ts_setup_workspace = "ts_setup_workspace") +load("//internal/devserver:ts_devserver.bzl", _ts_devserver = "ts_devserver") +load("//internal/protobufjs:ts_proto_library.bzl", _ts_proto_library = "ts_proto_library") check_rules_typescript_version = _check_rules_typescript_version ts_setup_workspace = _ts_setup_workspace diff --git a/packages/typescript/internal/build_defs.bzl b/packages/typescript/internal/build_defs.bzl index 29b98914ac..dac9f22a8c 100644 --- a/packages/typescript/internal/build_defs.bzl +++ b/packages/typescript/internal/build_defs.bzl @@ -178,6 +178,9 @@ def tsc_wrapped_tsconfig( devmode_manifest: path to the manifest file to write for --target=es5 jsx_factory: the setting for tsconfig.json compilerOptions.jsxFactory **kwargs: remaining args to pass to the create_tsconfig helper + + Returns: + The generated tsconfig.json as an object """ # The location of tsconfig.json is interpreted as the root of the project @@ -275,15 +278,15 @@ ts_library = rule( ), "compiler": attr.label( doc = """Sets a different TypeScript compiler binary to use for this library. -For example, we use the vanilla TypeScript tsc.js for bootstrapping, -and Angular compilations can replace this with `ngc`. - -The default ts_library compiler depends on the `@npm//@bazel/typescript` -target which is setup for projects that use bazel managed npm deps that -fetch the @bazel/typescript npm package. It is recommended that you use -the workspace name `@npm` for bazel managed deps so the default -compiler works out of the box. Otherwise, you'll have to override -the compiler attribute manually. + For example, we use the vanilla TypeScript tsc.js for bootstrapping, + and Angular compilations can replace this with `ngc`. + + The default ts_library compiler depends on the `@npm//@bazel/typescript` + target which is setup for projects that use bazel managed npm deps that + fetch the @bazel/typescript npm package. It is recommended that you use + the workspace name `@npm` for bazel managed deps so the default + compiler works out of the box. Otherwise, you'll have to override + the compiler attribute manually. """, default = Label(_DEFAULT_COMPILER), allow_files = True, @@ -294,63 +297,63 @@ the compiler attribute manually. "node_modules": attr.label( doc = """The npm packages which should be available during the compile. -The default value is `@npm//typescript:typescript__typings` is setup -for projects that use bazel managed npm deps that. It is recommended -that you use the workspace name `@npm` for bazel managed deps so the -default node_modules works out of the box. Otherwise, you'll have to -override the node_modules attribute manually. This default is in place -since ts_library will always depend on at least the typescript -default libs which are provided by `@npm//typescript:typescript__typings`. - -This attribute is DEPRECATED. As of version 0.18.0 the recommended -approach to npm dependencies is to use fine grained npm dependencies -which are setup with the `yarn_install` or `npm_install` rules. - -For example, in targets that used a `//:node_modules` filegroup, - -``` -ts_library( - name = "my_lib", - ... - node_modules = "//:node_modules", -) -``` - -which specifies all files within the `//:node_modules` filegroup -to be inputs to the `my_lib`. Using fine grained npm dependencies, -`my_lib` is defined with only the npm dependencies that are -needed: - -``` -ts_library( - name = "my_lib", - ... - deps = [ - "@npm//@types/foo", - "@npm//@types/bar", - "@npm//foo", - "@npm//bar", - ... - ], -) -``` - -In this case, only the listed npm packages and their -transitive deps are includes as inputs to the `my_lib` target -which reduces the time required to setup the runfiles for this -target (see https://github.com/bazelbuild/bazel/issues/5153). -The default typescript libs are also available via the node_modules -default in this case. - -The @npm external repository and the fine grained npm package -targets are setup using the `yarn_install` or `npm_install` rule -in your WORKSPACE file: - -yarn_install( - name = "npm", - package_json = "//:package.json", - yarn_lock = "//:yarn.lock", -) + The default value is `@npm//typescript:typescript__typings` is setup + for projects that use bazel managed npm deps that. It is recommended + that you use the workspace name `@npm` for bazel managed deps so the + default node_modules works out of the box. Otherwise, you'll have to + override the node_modules attribute manually. This default is in place + since ts_library will always depend on at least the typescript + default libs which are provided by `@npm//typescript:typescript__typings`. + + This attribute is DEPRECATED. As of version 0.18.0 the recommended + approach to npm dependencies is to use fine grained npm dependencies + which are setup with the `yarn_install` or `npm_install` rules. + + For example, in targets that used a `//:node_modules` filegroup, + + ``` + ts_library( + name = "my_lib", + ... + node_modules = "//:node_modules", + ) + ``` + + which specifies all files within the `//:node_modules` filegroup + to be inputs to the `my_lib`. Using fine grained npm dependencies, + `my_lib` is defined with only the npm dependencies that are + needed: + + ``` + ts_library( + name = "my_lib", + ... + deps = [ + "@npm//@types/foo", + "@npm//@types/bar", + "@npm//foo", + "@npm//bar", + ... + ], + ) + ``` + + In this case, only the listed npm packages and their + transitive deps are includes as inputs to the `my_lib` target + which reduces the time required to setup the runfiles for this + target (see https://github.com/bazelbuild/bazel/issues/5153). + The default typescript libs are also available via the node_modules + default in this case. + + The @npm external repository and the fine grained npm package + targets are setup using the `yarn_install` or `npm_install` rule + in your WORKSPACE file: + + yarn_install( + name = "npm", + package_json = "//:package.json", + yarn_lock = "//:yarn.lock", + ) """, default = Label("@npm//typescript:typescript__typings"), ), @@ -392,12 +395,11 @@ either: outputs = { "tsconfig": "%{name}_tsconfig.json", }, - doc = """ -`ts_library` type-checks and compiles a set of TypeScript sources to JavaScript. + doc = """`ts_library` type-checks and compiles a set of TypeScript sources to JavaScript. -It produces declarations files (`.d.ts`) which are used for compiling downstream -TypeScript targets and JavaScript for the browser and Closure compiler. -""", + It produces declarations files (`.d.ts`) which are used for compiling downstream + TypeScript targets and JavaScript for the browser and Closure compiler. + """, ) def ts_library_macro(tsconfig = None, **kwargs): diff --git a/packages/typescript/internal/devserver/ts_devserver.bzl b/packages/typescript/internal/devserver/ts_devserver.bzl index 9d2ec991e3..58fdb0ea0e 100644 --- a/packages/typescript/internal/devserver/ts_devserver.bzl +++ b/packages/typescript/internal/devserver/ts_devserver.bzl @@ -217,8 +217,8 @@ ts_devserver = rule( }, doc = """ts_devserver is a simple development server intended for a quick "getting started" experience. -Additional documentation at https://github.com/alexeagle/angular-bazel-example/wiki/Running-a-devserver-under-Bazel -""", + Additional documentation at https://github.com/alexeagle/angular-bazel-example/wiki/Running-a-devserver-under-Bazel + """, ) def ts_devserver_macro(name, data = [], args = [], visibility = None, tags = [], testonly = 0, **kwargs): diff --git a/packages/typescript/internal/internal_ts_repositories.bzl b/packages/typescript/internal/internal_ts_repositories.bzl index 74f554aa4a..e0e21d9905 100644 --- a/packages/typescript/internal/internal_ts_repositories.bzl +++ b/packages/typescript/internal/internal_ts_repositories.bzl @@ -1,3 +1,20 @@ +# Copyright 2019 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 @npm_bazel_typescript dev dependencies. +""" + load("@bazel_gazelle//:deps.bzl", "go_repository") def ts_setup_dev_workspace(): diff --git a/packages/typescript/internal/protobufjs/ts_proto_library.bzl b/packages/typescript/internal/protobufjs/ts_proto_library.bzl index 4d6af28731..8635fbcb69 100644 --- a/packages/typescript/internal/protobufjs/ts_proto_library.bzl +++ b/packages/typescript/internal/protobufjs/ts_proto_library.bzl @@ -136,57 +136,57 @@ ts_proto_library = rule( }, doc = """Wraps https://github.com/dcodeIO/protobuf.js for use in Bazel. -`ts_proto_library` has identical outputs to `ts_library`, so it can be used anywhere -a `ts_library` can appear, such as in the `deps[]` of another `ts_library`. + `ts_proto_library` has identical outputs to `ts_library`, so it can be used anywhere + a `ts_library` can appear, such as in the `deps[]` of another `ts_library`. -Example: + Example: -```python -load("@npm_bazel_typescript//:index.bzl", "ts_library", "ts_proto_library") + ```python + load("@npm_bazel_typescript//:index.bzl", "ts_library", "ts_proto_library") -proto_library( - name = "car_proto", - srcs = ["car.proto"], -) + proto_library( + name = "car_proto", + srcs = ["car.proto"], + ) -ts_proto_library( - name = "car", - deps = [":car_proto"], -) + ts_proto_library( + name = "car", + deps = [":car_proto"], + ) -ts_library( - name = "test_lib", - testonly = True, - srcs = ["car.spec.ts"], - deps = [":car"], -) -``` - -Note in this example we named the `ts_proto_library` rule `car` so that the -result will be `car.d.ts`. This means our TypeScript code can just -`import {symbols} from './car'`. Use the `output_name` attribute if you want to -name the rule differently from the output file. - -The JavaScript produced by protobuf.js has a runtime dependency on a support library. -Under devmode (e.g. `ts_devserver`, `ts_web_test_suite`) you'll need to include these scripts -in the `bootstrap` phase (before Require.js loads). You can use the label -`@npm_bazel_typescript//:protobufjs_bootstrap_scripts` to reference these scripts -in the `bootstrap` attribute of `ts_web_test_suite` or `ts_devserver`. - -To complete the example above, you could write a `ts_web_test_suite`: - -```python -load("@npm_bazel_karma//:index.bzl", "ts_web_test_suite") - -ts_web_test_suite( - name = "test", - deps = ["test_lib"], - bootstrap = ["@npm_bazel_typescript//:protobufjs_bootstrap_scripts"], - browsers = [ - "@io_bazel_rules_webtesting//browsers:chromium-local", - "@io_bazel_rules_webtesting//browsers:firefox-local", - ], -) -``` -""", + ts_library( + name = "test_lib", + testonly = True, + srcs = ["car.spec.ts"], + deps = [":car"], + ) + ``` + + Note in this example we named the `ts_proto_library` rule `car` so that the + result will be `car.d.ts`. This means our TypeScript code can just + `import {symbols} from './car'`. Use the `output_name` attribute if you want to + name the rule differently from the output file. + + The JavaScript produced by protobuf.js has a runtime dependency on a support library. + Under devmode (e.g. `ts_devserver`, `ts_web_test_suite`) you'll need to include these scripts + in the `bootstrap` phase (before Require.js loads). You can use the label + `@npm_bazel_typescript//:protobufjs_bootstrap_scripts` to reference these scripts + in the `bootstrap` attribute of `ts_web_test_suite` or `ts_devserver`. + + To complete the example above, you could write a `ts_web_test_suite`: + + ```python + load("@npm_bazel_karma//:index.bzl", "ts_web_test_suite") + + ts_web_test_suite( + name = "test", + deps = ["test_lib"], + bootstrap = ["@npm_bazel_typescript//:protobufjs_bootstrap_scripts"], + browsers = [ + "@io_bazel_rules_webtesting//browsers:chromium-local", + "@io_bazel_rules_webtesting//browsers:firefox-local", + ], + ) + ``` + """, ) diff --git a/packages/typescript/internal/ts_config.bzl b/packages/typescript/internal/ts_config.bzl index bd3777551d..bd06f980e1 100644 --- a/packages/typescript/internal/ts_config.bzl +++ b/packages/typescript/internal/ts_config.bzl @@ -36,9 +36,9 @@ ts_config = rule( }, doc = """Allows a tsconfig.json file to extend another file. -Normally, you just give a single `tsconfig.json` file as the tsconfig attribute -of a `ts_library` rule. However, if your `tsconfig.json` uses the `extends` -feature from TypeScript, then the Bazel implementation needs to know about that -extended configuration file as well, to pass them both to the TypeScript compiler. -""", + Normally, you just give a single `tsconfig.json` file as the tsconfig attribute + of a `ts_library` rule. However, if your `tsconfig.json` uses the `extends` + feature from TypeScript, then the Bazel implementation needs to know about that + extended configuration file as well, to pass them both to the TypeScript compiler. + """, ) diff --git a/yarn.lock b/yarn.lock index 9a2df8d4ad..4cbc5a79d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26,23 +26,23 @@ "@bazel/bazel-linux_x64" "0.23.0" "@bazel/bazel-win32_x64" "0.23.0" -"@bazel/buildifier-darwin_x64@0.20.0": - version "0.20.0" - resolved "https://registry.yarnpkg.com/@bazel/buildifier-darwin_x64/-/buildifier-darwin_x64-0.20.0.tgz#1aeceb5a1a57a62eef6415377dbe95091781a7d4" - integrity sha512-yV7niwbdpDDPUw1vgyk1wIjPl3+YOM4o5FPgFmnFgzf48JUqrF3PK6Blg95Z8SqGOVoJAOChRC1GvopzEUzwZA== - -"@bazel/buildifier-linux_x64@0.20.0": - version "0.20.0" - resolved "https://registry.yarnpkg.com/@bazel/buildifier-linux_x64/-/buildifier-linux_x64-0.20.0.tgz#8cb6c8f999dbd8a9ee183906f202b698571d771b" - integrity sha512-djbBtcacgERWZoxjEm8lGmMyEaOYB3moiz0kioHTQc2F96wNLfm6Cikd4Ojrcj5VNQCMW9oy3YFTu+c5mIrCcA== - -"@bazel/buildifier@^0.20.0": - version "0.20.0" - resolved "https://registry.yarnpkg.com/@bazel/buildifier/-/buildifier-0.20.0.tgz#24a10e485fe65dbd75ef812cf37635df1fb91d0d" - integrity sha512-dahQRtE1KEp+efUV23q/JtOCSbQEk5C/+H3J33g8wP5roxMUa8mfDto85eloJ+gRPW7yOybxknuRYc4KSpgT7w== +"@bazel/buildifier-darwin_x64@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@bazel/buildifier-darwin_x64/-/buildifier-darwin_x64-0.22.0.tgz#00dde7ce03be8c550b3908dd91cf1fc0baef7ff7" + integrity sha512-tpJ6w3mmh8wBm/k5AidAZvjWm3Hge3ipSjGtxTfq/xgUCacAtGt219nwyAMs0CwLPuABLbcINQmmKtG5VpxK9A== + +"@bazel/buildifier-linux_x64@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@bazel/buildifier-linux_x64/-/buildifier-linux_x64-0.22.0.tgz#146c44bafbb1e4711725414582a49835d04b8618" + integrity sha512-qaE7QF2YHKOXFBk2QcwOBfA3Ipm08vP9ZK9Vxtubbq9O0MM5tWvfKI48VkfX6pg8QNXDJ+sBndznxQSSWstsWQ== + +"@bazel/buildifier@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@bazel/buildifier/-/buildifier-0.22.0.tgz#d1abc2ce4317ba71351276c6b1b9e1533abf8e3d" + integrity sha512-S+mrUwanR8HMcp92iEDk4D1oOLsVhCM42Hx0rqL1eVmXPwLYL+F/sIjeGTw/6BgxMEHVSl2M3CcTFAS0b60BTQ== optionalDependencies: - "@bazel/buildifier-darwin_x64" "0.20.0" - "@bazel/buildifier-linux_x64" "0.20.0" + "@bazel/buildifier-darwin_x64" "0.22.0" + "@bazel/buildifier-linux_x64" "0.22.0" "@bazel/ibazel@^0.9.1": version "0.9.1"