-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add opt-in exports_directories_only mode to yarn_install and np…
…m_install (defaults to False) When `True`, `yarn_install` and `npm_install` export only top-level package directory artifacts from node_modules. Turning this on will decrease the time it takes for Bazel to setup runfiles and sandboxing when there are a large number of npm dependencies as inputs to an action. This breaks compatabilty for label that reference files within npm packages such as `@npm//:node_modules/prettier/bin-prettier.js`. To reference files within npm packages, you can use the `directory_file_path` rule and/or `DirectoryFilePathInfo` provider. Note, some rules still need upgrading to support consuming `DirectoryFilePathInfo` where needed. NB: This feature requires runfiles be enabled due to an issue in Bazel which we are still investigating. On Windows runfiles are off by default and must be enabled with the `--enable_runfiles` flag when using this feature. NB: `ts_library` does not support directory artifact npm deps due to internal dependency on having all input sources files explicitly specified NB: `karma_web_test` and `karma_web_test_suite` do not yet support directory artifact npm deps as they require `node_modules/requirejs/require.js` & `node_modules/karma-requirejs/lib/adapter.js` explicit source files in deps For the `nodejs_binary` & `nodejs_test` `entry_point` attribute (which often needs to reference a file within an npm package) you can set the entry_point to a dict with a single entry, where the key corresponds to the directory artifact label and the value corresponds to the path within that directory to the entry point. For example, ``` nodejs_binary( name = "prettier", data = ["@npm//prettier"], entry_point = "@npm//:node_modules/prettier/bin-prettier.js", ) ``` becomes, ``` nodejs_binary( name = "prettier", data = ["@npm//prettier"], entry_point = { "@npm//:node_modules/prettier": "bin-prettier.js" }, ) ``` For other labels that are passed to `$(rootpath)`, `$(execpath)`, or `$(location)` you can simply break these apart into the directory artifact label that gets passed to the expander & path part to follows it. For example, ``` $(rootpath @npm//:node_modules/prettier/bin-prettier.js") ``` becomes, ``` $(rootpath @npm//:node_modules/prettier)/bin-prettier.js ```
- Loading branch information
Showing
93 changed files
with
3,386 additions
and
135 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
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
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 @@ | ||
node_modules |
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,85 @@ | ||
# 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. | ||
|
||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library") | ||
load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle") | ||
load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver") | ||
load("@npm//@bazel/protractor:index.bzl", "protractor_web_test_suite") | ||
load("@npm//@bazel/typescript:index.bzl", "ts_project") | ||
|
||
exports_files([ | ||
"red-body-style.css", | ||
"tsconfig.json", | ||
"protractor.on-prepare.js", | ||
]) | ||
|
||
ts_project( | ||
name = "compile", | ||
srcs = [ | ||
"app.ts", | ||
"app_e2e-spec.ts", | ||
], | ||
declaration = True, | ||
tsconfig = ":tsconfig.json", | ||
validate = False, | ||
deps = [ | ||
"@npm//@types", | ||
"@npm//date-fns", | ||
"@npm//protractor", | ||
"@npm//rxjs", | ||
"@npm//typeorm", | ||
], | ||
) | ||
|
||
js_library( | ||
name = "lib", | ||
named_module_srcs = [":compile"], | ||
deps = [":compile"], | ||
) | ||
|
||
# typeorm is a special case for npm_umd_bundle as we need to excluded | ||
# the `react-native-sqlite-storage` dynamic require from the umd bundle | ||
npm_umd_bundle( | ||
name = "typeorm_umd", | ||
package_name = "typeorm", | ||
entry_point = {"@npm//:node_modules/typeorm": "browser/index.js"}, | ||
excluded = ["react-native-sqlite-storage"], | ||
package = "@npm//typeorm", | ||
) | ||
|
||
concatjs_devserver( | ||
name = "devserver", | ||
entry_module = "concatjs_devserver_directory_artifacts/app", | ||
scripts = [ | ||
"@npm//date-fns:date-fns.umd.js", | ||
"@npm//rxjs:rxjs.umd.js", | ||
":typeorm.umd.js", | ||
], | ||
# We'll collect all the devmode JS sources from these TypeScript libraries | ||
deps = [":lib"], | ||
) | ||
|
||
protractor_web_test_suite( | ||
name = "devserver_test", | ||
on_prepare = ":protractor.on-prepare.js", | ||
protractor_entry_point = {"@npm//:node_modules/protractor": "bin/protractor"}, | ||
server = ":devserver", | ||
deps = [":lib"], | ||
) | ||
|
||
# Just a dummy test so that we have a test target for //... on certain bazelci platforms with bazel_integration_test | ||
sh_test( | ||
name = "dummy_test", | ||
srcs = ["dummy_test.sh"], | ||
) |
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,51 @@ | ||
# 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. | ||
|
||
workspace( | ||
name = "concatjs_devserver_directory_artifacts", | ||
managed_directories = {"@npm": ["node_modules"]}, | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "build_bazel_rules_nodejs", | ||
sha256 = "4a5d654a4ccd4a4c24eca5d319d85a88a650edf119601550c95bf400c8cc897e", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.5.1/rules_nodejs-3.5.1.tar.gz"], | ||
) | ||
|
||
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install") | ||
|
||
yarn_install( | ||
name = "npm", | ||
exports_directories_only = True, | ||
package_json = "//:package.json", | ||
yarn_lock = "//:yarn.lock", | ||
) | ||
|
||
load("@npm//@bazel/protractor:package.bzl", "npm_bazel_protractor_dependencies") | ||
|
||
npm_bazel_protractor_dependencies() | ||
|
||
# Setup the rules_webtesting toolchain | ||
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") | ||
|
||
web_test_repositories() | ||
|
||
load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories") | ||
|
||
browser_repositories( | ||
chromium = True, | ||
firefox = True, | ||
) |
Oops, something went wrong.