diff --git a/WORKSPACE b/WORKSPACE index 3d5e2af48b..2b0cb886f6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -19,9 +19,6 @@ workspace( "@cypress_deps": ["packages/cypress/test/node_modules"], "@internal_npm_install_test_patches_npm_symlinked": ["internal/npm_install/test/patches_npm_symlinked/node_modules"], "@internal_npm_install_test_patches_yarn_symlinked": ["internal/npm_install/test/patches_yarn_symlinked/node_modules"], - "@internal_test_multi_linker_sub_deps": ["internal/linker/test/multi_linker/sub/node_modules"], - "@npm": ["node_modules"], - "@npm_node_patches": ["packages/node-patches/node_modules"], }, ) diff --git a/docs/Built-ins.md b/docs/Built-ins.md index 8683f41739..5944b4fbc4 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -899,6 +899,14 @@ Defaults to `True` (*Boolean*): Turn symlinking of node_modules on +When False, the package manager will run in the external repository +created by this rule. +This requires that any files required for it to run should be listed in the +`data` attribute. These files would include things like patch files that are +read by a postinstall lifecycle hook such as the `patch-package` package uses. +`package.json` and the lock file are already specified in dedicated attributes +of this rule and do not need to be included in the `data`. + When True, we run the package manager (npm or yarn) with the working directory set in your source tree, in the folder containing the package.json file. The resulting `node_modules` folder in the source tree will be symlinked to the @@ -930,15 +938,7 @@ Using managed_directories will mean that 2. if the `node_modules` folder is deleted from the source tree, Bazel will re-run the repository rule that creates it again on the next run. -When False, the package manager will run in the external repository -created by this rule. -This requires that any files required for it to run should be listed in the -`data` attribute. These files would include things like patch files that are -read by a postinstall lifecycle hook such as the `patch-package` package uses. -`package.json` and the lock file are already specified in dedicated attributes -of this rule and do not need to be included in the `data`. - -Defaults to `True` +Defaults to `False`

timeout

@@ -1586,6 +1586,14 @@ Defaults to `True` (*Boolean*): Turn symlinking of node_modules on +When False, the package manager will run in the external repository +created by this rule. +This requires that any files required for it to run should be listed in the +`data` attribute. These files would include things like patch files that are +read by a postinstall lifecycle hook such as the `patch-package` package uses. +`package.json` and the lock file are already specified in dedicated attributes +of this rule and do not need to be included in the `data`. + When True, we run the package manager (npm or yarn) with the working directory set in your source tree, in the folder containing the package.json file. The resulting `node_modules` folder in the source tree will be symlinked to the @@ -1617,15 +1625,7 @@ Using managed_directories will mean that 2. if the `node_modules` folder is deleted from the source tree, Bazel will re-run the repository rule that creates it again on the next run. -When False, the package manager will run in the external repository -created by this rule. -This requires that any files required for it to run should be listed in the -`data` attribute. These files would include things like patch files that are -read by a postinstall lifecycle hook such as the `patch-package` package uses. -`package.json` and the lock file are already specified in dedicated attributes -of this rule and do not need to be included in the `data`. - -Defaults to `True` +Defaults to `False`

timeout

diff --git a/docs/dependencies.md b/docs/dependencies.md index 582e5cb3b3..85a26f6fd1 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -29,9 +29,6 @@ This approach also allows you to use the generated fine-grained npm package depe which can significantly reduce the number of inputs to actions, making Bazel sand-boxing and remote-execution faster if there are a large number of files under `node_modules`. -> Note that as of Bazel 0.26, and with the recommended `managed_directories` attribute on the `workspace` rule in `/WORKSPACE`, -> the Bazel-managed `node_modules` directory is placed in your workspace root in the standard location used by npm or yarn. - ## Using Bazel-managed dependencies To have Bazel manage its own copy of `node_modules`, which is useful to avoid @@ -65,8 +62,28 @@ npm_install( > If you don't need to pass any arguments to `node_repositories`, you can skip calling that function. `yarn_install` and `npm_install` will do it by default. -You should now add the `@npm` workspace to the `managed_directories` option in the `workspace` rule at the top of the file. This tells Bazel that the `node_modules` directory is special and is managed by the package manager. -Add the `workspace` rule if it isn't already in your `/WORKSPACE` file. +### symlink_node_modules and managed_directories + +Set `symlink_node_modules` to `True` to configure `npm_install` and +`yarn_install` to install `node_modules` inside the user workspace and have +Bazel use the `node_modules` folder in the user workspace for the build via a +symlink into the external repository it creates. + +```python +load("@build_bazel_rules_nodejs//:index.bzl", "npm_install") + +npm_install( + name = "npm", + package_json = "//:package.json", + package_lock_json = "//:package-lock.json", + symlink_node_modules = True, +) +``` + +You should now add the `@npm` workspace to the `managed_directories` option in +the `workspace` rule at the top of the file. This tells Bazel that the +`node_modules` directory is special and is managed by the package manager. Add +the `workspace` rule if it isn't already in your `/WORKSPACE` file. ```python workspace( @@ -75,7 +92,18 @@ workspace( ) ``` -As of Bazel 0.26 this feature is still experimental, so also add this line to the `.bazelrc` to opt-in: +As of rules_nodejs 5.0, `symlink_node_modules` defaults to `False` and using +`managed_directories` is not recommended. We've found that the benefits of using +`symlink_node_modules`, which allows bazel to use a `node_modules` directory +that is in the user workspace, do not outweigh the downsides of the repository +rules not defining all of their input and of having to re-run the repository +rule if the user's `node_modules` folder is deleted. On persistent CI machines +that will run clean the state of the clone between jobs the repository rule will +run for every job with `symlink_node_modules` enabled. With it disabled, the +repository rule will only re-run if any of its inputs changes between jobs. + +NB: On older versions of Bazel you may have to add the following flag to your +`.bazelrc` to enable managed directories. ``` common --experimental_allow_incremental_repository_updates @@ -131,13 +159,7 @@ and npm deps, `yarn_install` (or `npm_install`) can be called separately for each. ```python -workspace( - name = "my_wksp", - managed_directories = { - "@app1_npm": ["app1/node_modules"], - "@app2_npm": ["app2/node_modules"], - }, -) +workspace(name = "my_wksp") yarn_install( name = "app1_npm", diff --git a/e2e/bazel_managed_deps/WORKSPACE b/e2e/bazel_managed_deps/WORKSPACE index c2d500e422..ecef8a4d91 100644 --- a/e2e/bazel_managed_deps/WORKSPACE +++ b/e2e/bazel_managed_deps/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "e2e_bazel_managed_deps", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_bazel_managed_deps") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/concatjs_devserver/WORKSPACE b/e2e/concatjs_devserver/WORKSPACE index d37ae3625a..52bd2427fa 100644 --- a/e2e/concatjs_devserver/WORKSPACE +++ b/e2e/concatjs_devserver/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "e2e_concatjs_devserver", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_concatjs_devserver") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/coverage/WORKSPACE b/e2e/coverage/WORKSPACE index 798a79fc5c..744d678389 100644 --- a/e2e/coverage/WORKSPACE +++ b/e2e/coverage/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "e2e_coverage", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_coverage") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/fine_grained_symlinks/WORKSPACE b/e2e/fine_grained_symlinks/WORKSPACE index 7bd4ddb684..c224da27fb 100644 --- a/e2e/fine_grained_symlinks/WORKSPACE +++ b/e2e/fine_grained_symlinks/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "e2e_fine_grained_symlinks", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_fine_grained_symlinks") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/jasmine/WORKSPACE b/e2e/jasmine/WORKSPACE index 5b85d75958..c7ce371b44 100644 --- a/e2e/jasmine/WORKSPACE +++ b/e2e/jasmine/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "e2e_jasmine", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_jasmine") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/node_loader_no_preserve_symlinks/.bazelrc b/e2e/node_loader_no_preserve_symlinks/.bazelrc index 3431057af6..f05d3ad5b2 100644 --- a/e2e/node_loader_no_preserve_symlinks/.bazelrc +++ b/e2e/node_loader_no_preserve_symlinks/.bazelrc @@ -1 +1,3 @@ import %workspace%/../../common.bazelrc + +build --@build_bazel_rules_nodejs//nodejs:default_args="" diff --git a/e2e/node_loader_no_preserve_symlinks/BUILD.bazel b/e2e/node_loader_no_preserve_symlinks/BUILD.bazel index 26d3bb8155..a50c3b926e 100644 --- a/e2e/node_loader_no_preserve_symlinks/BUILD.bazel +++ b/e2e/node_loader_no_preserve_symlinks/BUILD.bazel @@ -9,5 +9,4 @@ nodejs_test( "@npm//:node_modules", ], entry_point = ":node_loader_test.spec.js", - templated_args = ["--nobazel_node_patches"], ) diff --git a/e2e/node_loader_no_preserve_symlinks/WORKSPACE b/e2e/node_loader_no_preserve_symlinks/WORKSPACE index 727d656cd3..c5aed8bebb 100644 --- a/e2e/node_loader_no_preserve_symlinks/WORKSPACE +++ b/e2e/node_loader_no_preserve_symlinks/WORKSPACE @@ -1,9 +1,4 @@ -workspace( - name = "e2e_node_loader_no_preserve_symlinks", - managed_directories = { - "@npm": ["node_modules"], - }, -) +workspace(name = "e2e_node_loader_no_preserve_symlinks") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/node_loader_preserve_symlinks/WORKSPACE b/e2e/node_loader_preserve_symlinks/WORKSPACE index a46a3fb55a..bb3c12994d 100644 --- a/e2e/node_loader_preserve_symlinks/WORKSPACE +++ b/e2e/node_loader_preserve_symlinks/WORKSPACE @@ -1,9 +1,4 @@ -workspace( - name = "e2e_node_loader_preserve_symlinks", - managed_directories = { - "@npm": ["node_modules"], - }, -) +workspace(name = "e2e_node_loader_preserve_symlinks") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/nodejs_image/WORKSPACE b/e2e/nodejs_image/WORKSPACE index c9ff712e6c..df42aa9b0f 100644 --- a/e2e/nodejs_image/WORKSPACE +++ b/e2e/nodejs_image/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "e2e_nodejs_image", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_nodejs_image") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/nodejs_repository/WORKSPACE b/e2e/nodejs_repository/WORKSPACE index 452e4eee08..66b919f84f 100644 --- a/e2e/nodejs_repository/WORKSPACE +++ b/e2e/nodejs_repository/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "nodejs_repository", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "nodejs_repository") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/packages/WORKSPACE b/e2e/packages/WORKSPACE index 157c9487da..5fa76cf1e5 100644 --- a/e2e/packages/WORKSPACE +++ b/e2e/packages/WORKSPACE @@ -25,7 +25,6 @@ npm_install( data = ["//:postinstall.js"], package_json = "//:npm1/package.json", package_lock_json = "//:npm1/package-lock.json", - symlink_node_modules = False, ) npm_install( @@ -34,7 +33,6 @@ npm_install( data = ["//:postinstall.js"], package_json = "//:npm2/package.json", package_lock_json = "//:npm2/package-lock.json", - symlink_node_modules = False, ) yarn_install( @@ -42,7 +40,6 @@ yarn_install( args = ["--prod"], data = ["//:postinstall.js"], package_json = "//:yarn1/package.json", - symlink_node_modules = False, yarn_lock = "//:yarn1/yarn.lock", ) @@ -51,6 +48,5 @@ yarn_install( args = ["--prod"], data = ["//:postinstall.js"], package_json = "//:yarn2/package.json", - symlink_node_modules = False, yarn_lock = "//:yarn2/yarn.lock", ) diff --git a/e2e/symlinked_node_modules_npm/WORKSPACE b/e2e/symlinked_node_modules_npm/WORKSPACE index c01174a247..c00cc3ec9b 100644 --- a/e2e/symlinked_node_modules_npm/WORKSPACE +++ b/e2e/symlinked_node_modules_npm/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "e2e_symlinked_node_modules_yarn", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_symlinked_node_modules_yarn") # There are some assertions that can only by made by running tests from within # this nested repository folder. These assertions are run in CI so we use diff --git a/e2e/symlinked_node_modules_yarn/WORKSPACE b/e2e/symlinked_node_modules_yarn/WORKSPACE index 3c5bea3c8c..42c918df38 100644 --- a/e2e/symlinked_node_modules_yarn/WORKSPACE +++ b/e2e/symlinked_node_modules_yarn/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "e2e_symlinked_node_modules_yarn", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_symlinked_node_modules_yarn") # There are some assertions that can only by made by running tests from within # this nested repository folder. These assertions are run in CI so we use diff --git a/e2e/typescript/WORKSPACE b/e2e/typescript/WORKSPACE index 0e5fcf9310..077d2e17b7 100644 --- a/e2e/typescript/WORKSPACE +++ b/e2e/typescript/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "e2e_typescript", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_typescript") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/e2e/webapp/WORKSPACE b/e2e/webapp/WORKSPACE index 0248a6598d..f7f861c369 100644 --- a/e2e/webapp/WORKSPACE +++ b/e2e/webapp/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "e2e_webapp", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "e2e_webapp") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/angular/WORKSPACE b/examples/angular/WORKSPACE index 856222d3dc..cdc3e863c3 100644 --- a/examples/angular/WORKSPACE +++ b/examples/angular/WORKSPACE @@ -5,10 +5,7 @@ # ESModule imports (and TypeScript imports) can be absolute starting with the workspace name. # The name of the workspace should match the npm package where we publish, so that these # imports also make sense when referencing the published package. -workspace( - name = "examples_angular", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_angular") # These rules are built-into Bazel but we need to load them first to download more rules load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/angular_bazel_architect/WORKSPACE b/examples/angular_bazel_architect/WORKSPACE index 08e0288df9..f4bd5bdd97 100644 --- a/examples/angular_bazel_architect/WORKSPACE +++ b/examples/angular_bazel_architect/WORKSPACE @@ -29,11 +29,6 @@ yarn_install( name = "npm", data = ["//:patches/@angular-devkit+architect-cli+0.1102.2.patch"], package_json = "//:package.json", - # Turn off symlink_node_modules here as it causes extreme flakiness on buildkite - # macos CI with missing files in node_modules. - # TODO: track down the root cause of the flakiness; it may be something to - # do with how the Bazel team has setup their macos virtualization. - symlink_node_modules = False, yarn_lock = "//:yarn.lock", ) diff --git a/examples/app/WORKSPACE b/examples/app/WORKSPACE index 9f93f14c38..e5c47f0cde 100644 --- a/examples/app/WORKSPACE +++ b/examples/app/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_app", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_app") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/closure/WORKSPACE b/examples/closure/WORKSPACE index e15e186d2a..5559d4a804 100644 --- a/examples/closure/WORKSPACE +++ b/examples/closure/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_closure", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_closure") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/create-react-app/WORKSPACE b/examples/create-react-app/WORKSPACE index c76630299d..6846b57f96 100644 --- a/examples/create-react-app/WORKSPACE +++ b/examples/create-react-app/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "create_react_app", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "create_react_app") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") @@ -20,6 +17,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install") yarn_install( # Name this npm so that Bazel Label references look like @npm//package name = "npm", + data = ["//:patches/jest-haste-map+26.6.2.patch"], exports_directories_only = True, package_json = "//:package.json", yarn_lock = "//:yarn.lock", diff --git a/examples/cypress/BUILD.bazel b/examples/cypress/BUILD.bazel index 6ea386e723..5d7c406eb2 100644 --- a/examples/cypress/BUILD.bazel +++ b/examples/cypress/BUILD.bazel @@ -47,7 +47,10 @@ cypress_web_test( # A cypress config file is required config_file = "cypress.json", # Any runtime dependencies you need to boot your server or run your tests - data = ["@yarn//rxjs"], + data = [ + "@yarn//express", + "@yarn//rxjs", + ], # Your cypress plugin used to configure cypress and boot your server plugin_file = ":plugin_file", ) diff --git a/examples/cypress/WORKSPACE b/examples/cypress/WORKSPACE index ea88eaa7e3..114e9d2c17 100644 --- a/examples/cypress/WORKSPACE +++ b/examples/cypress/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_cypress", - managed_directories = {"@yarn": ["node_modules"]}, -) +workspace(name = "examples_cypress") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/esbuild/WORKSPACE b/examples/esbuild/WORKSPACE index 09457996f7..a79273ede1 100644 --- a/examples/esbuild/WORKSPACE +++ b/examples/esbuild/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_esbuild", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_esbuild") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/from_source/WORKSPACE b/examples/from_source/WORKSPACE index 33761c7ea8..24fc85742b 100644 --- a/examples/from_source/WORKSPACE +++ b/examples/from_source/WORKSPACE @@ -43,6 +43,5 @@ yarn_install( exports_directories_only = True, package_json = "//:package.json", strict_visibility = True, - symlink_node_modules = False, yarn_lock = "//:yarn.lock", ) diff --git a/examples/jest/WORKSPACE b/examples/jest/WORKSPACE index 8fd543a687..346b2bc031 100644 --- a/examples/jest/WORKSPACE +++ b/examples/jest/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_jest", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_jest") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/kotlin/WORKSPACE b/examples/kotlin/WORKSPACE index f62bb5bb73..7c003a7275 100644 --- a/examples/kotlin/WORKSPACE +++ b/examples/kotlin/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "kotlin_example", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "kotlin_example") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/nestjs/WORKSPACE b/examples/nestjs/WORKSPACE index 62a171bb88..a4c08ced12 100644 --- a/examples/nestjs/WORKSPACE +++ b/examples/nestjs/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_nestjs", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_nestjs") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/parcel/WORKSPACE b/examples/parcel/WORKSPACE index 128a070861..58c4c7338a 100644 --- a/examples/parcel/WORKSPACE +++ b/examples/parcel/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_parcel", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_parcel") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/protobufjs/WORKSPACE b/examples/protobufjs/WORKSPACE index 40788e0107..ecccd245de 100644 --- a/examples/protobufjs/WORKSPACE +++ b/examples/protobufjs/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_protobufjs", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_protobufjs") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/react_webpack/WORKSPACE b/examples/react_webpack/WORKSPACE index 03c4afe696..1c224adb28 100644 --- a/examples/react_webpack/WORKSPACE +++ b/examples/react_webpack/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "react_webpack", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "react_webpack") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/vendored_node/WORKSPACE b/examples/vendored_node/WORKSPACE index a60c07c5b7..5397699d6b 100644 --- a/examples/vendored_node/WORKSPACE +++ b/examples/vendored_node/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_vendored_node", - managed_directories = {"@npm": ["npm/node_modules"]}, -) +workspace(name = "examples_vendored_node") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/vendored_node_and_yarn/WORKSPACE b/examples/vendored_node_and_yarn/WORKSPACE index f81e2e1904..ae9129a194 100644 --- a/examples/vendored_node_and_yarn/WORKSPACE +++ b/examples/vendored_node_and_yarn/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_vendored_node_and_yarn", - managed_directories = {"@npm": ["npm/node_modules"]}, -) +workspace(name = "examples_vendored_node_and_yarn") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/vue/WORKSPACE b/examples/vue/WORKSPACE index cac8e79226..eaf65f0b7d 100644 --- a/examples/vue/WORKSPACE +++ b/examples/vue/WORKSPACE @@ -1,7 +1,4 @@ -workspace( - name = "vue_example", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "vue_example") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/web_testing/WORKSPACE b/examples/web_testing/WORKSPACE index 6e1e4c87c8..0ec8f2a979 100644 --- a/examples/web_testing/WORKSPACE +++ b/examples/web_testing/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_webtesting", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_webtesting") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/webapp/WORKSPACE b/examples/webapp/WORKSPACE index 33518e875d..58bc7611b3 100644 --- a/examples/webapp/WORKSPACE +++ b/examples/webapp/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_webapp", - managed_directories = {"@npm_deps": ["node_modules"]}, -) +workspace(name = "examples_webapp") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/examples/worker/WORKSPACE b/examples/worker/WORKSPACE index 58d383d8df..3f05790da4 100644 --- a/examples/worker/WORKSPACE +++ b/examples/worker/WORKSPACE @@ -12,10 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -workspace( - name = "examples_worker", - managed_directories = {"@npm": ["node_modules"]}, -) +workspace(name = "examples_worker") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl index 4f6e109e42..fb4a92669e 100644 --- a/internal/npm_install/npm_install.bzl +++ b/internal/npm_install/npm_install.bzl @@ -335,6 +335,14 @@ to the source `package.json`.""", "symlink_node_modules": attr.bool( doc = """Turn symlinking of node_modules on +When False, the package manager will run in the external repository +created by this rule. +This requires that any files required for it to run should be listed in the +`data` attribute. These files would include things like patch files that are +read by a postinstall lifecycle hook such as the `patch-package` package uses. +`package.json` and the lock file are already specified in dedicated attributes +of this rule and do not need to be included in the `data`. + When True, we run the package manager (npm or yarn) with the working directory set in your source tree, in the folder containing the package.json file. The resulting `node_modules` folder in the source tree will be symlinked to the @@ -365,16 +373,8 @@ Using managed_directories will mean that in the external repository folder, and 2. if the `node_modules` folder is deleted from the source tree, Bazel will re-run the repository rule that creates it again on the next run. - -When False, the package manager will run in the external repository -created by this rule. -This requires that any files required for it to run should be listed in the -`data` attribute. These files would include things like patch files that are -read by a postinstall lifecycle hook such as the `patch-package` package uses. -`package.json` and the lock file are already specified in dedicated attributes -of this rule and do not need to be included in the `data`. """, - default = True, + default = False, ), "timeout": attr.int( default = 3600, diff --git a/npm_deps.bzl b/npm_deps.bzl index 31632c3113..617ac69949 100644 --- a/npm_deps.bzl +++ b/npm_deps.bzl @@ -117,7 +117,6 @@ js_library( "@test_multi_linker/lib-d": "@build_bazel_rules_nodejs//internal/linker/test/multi_linker/lib_d", "@test_multi_linker/lib-d2": "@build_bazel_rules_nodejs//internal/linker/test/multi_linker/lib_d", }, - symlink_node_modules = False, exports_directories_only = True, package_json = "//:package.json", yarn_lock = "//:yarn.lock", @@ -137,7 +136,6 @@ js_library( }, package_json = "//internal/linker/test/multi_linker:package.json", package_path = "internal/linker/test/multi_linker", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker:yarn.lock", ) @@ -155,7 +153,6 @@ js_library( }, package_json = "//internal/linker/test/multi_linker/test_a:package.json", package_path = "internal/linker/test/multi_linker/test_a", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/test_a:yarn.lock", ) @@ -163,7 +160,6 @@ js_library( name = "internal_test_multi_linker_test_b_deps", package_json = "//internal/linker/test/multi_linker/test_b:package.json", package_path = "internal/linker/test/multi_linker/test_b", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/test_b:yarn.lock", ) @@ -171,7 +167,6 @@ js_library( name = "internal_test_multi_linker_test_c_deps", package_json = "//internal/linker/test/multi_linker/test_c:package.json", package_path = "internal/linker/test/multi_linker/test_c", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/test_c:yarn.lock", ) @@ -179,7 +174,6 @@ js_library( name = "internal_test_multi_linker_test_d_deps", package_json = "//internal/linker/test/multi_linker/test_d:package.json", package_path = "internal/linker/test/multi_linker/test_d", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/test_d:yarn.lock", ) @@ -189,7 +183,6 @@ js_library( args = ["--production"], package_json = "//internal/linker/test/multi_linker/lib_b:package.json", package_path = "internal/linker/test/multi_linker/lib_b", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/lib_b:yarn.lock", ) @@ -199,7 +192,6 @@ js_library( args = ["--production"], package_json = "//internal/linker/test/multi_linker/lib_c:lib/package.json", package_path = "internal/linker/test/multi_linker/lib_c/lib", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/lib_c:lib/yarn.lock", ) @@ -217,7 +209,6 @@ js_library( }, package_json = "//internal/linker/test/multi_linker/sub:package.json", package_path = "internal/linker/test/multi_linker/sub/dev", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/sub:yarn.lock", ) @@ -246,7 +237,6 @@ js_library( args = ["--production"], package_json = "//internal/linker/test/multi_linker/onep_a:package.json", package_path = "internal/linker/test/multi_linker/onep_a", - symlink_node_modules = False, yarn_lock = "//internal/linker/test/multi_linker/onep_a:yarn.lock", ) @@ -270,7 +260,6 @@ js_library( ".proto", ], package_json = "//:tools/fine_grained_deps_yarn/package.json", - symlink_node_modules = False, yarn_lock = "//:tools/fine_grained_deps_yarn/yarn.lock", ) @@ -296,7 +285,6 @@ js_library( npm_command = "install", package_json = "//:tools/fine_grained_deps_npm/package.json", package_lock_json = "//:tools/fine_grained_deps_npm/package-lock.json", - symlink_node_modules = False, ) yarn_install( @@ -311,7 +299,6 @@ js_library( }, exports_directories_only = True, package_json = "//:tools/fine_grained_deps_yarn/package.json", - symlink_node_modules = False, yarn_lock = "//:tools/fine_grained_deps_yarn/yarn.lock", ) @@ -329,13 +316,11 @@ js_library( npm_command = "install", package_json = "//:tools/fine_grained_deps_npm/package.json", package_lock_json = "//:tools/fine_grained_deps_npm/package-lock.json", - symlink_node_modules = False, ) yarn_install( name = "fine_grained_no_bin", package_json = "//:tools/fine_grained_no_bin/package.json", - symlink_node_modules = False, yarn_lock = "//:tools/fine_grained_no_bin/yarn.lock", ) @@ -384,7 +369,6 @@ filegroup( ], )""", package_json = "//:tools/fine_grained_goldens/package.json", - symlink_node_modules = False, yarn_lock = "//:tools/fine_grained_goldens/yarn.lock", ) @@ -424,7 +408,6 @@ filegroup( )""", exports_directories_only = True, package_json = "//:tools/fine_grained_goldens/package.json", - symlink_node_modules = False, yarn_lock = "//:tools/fine_grained_goldens/yarn.lock", ) @@ -448,7 +431,6 @@ filegroup( # add scripts.new "scripts.new": "added", }, - symlink_node_modules = False, yarn_lock = "//internal/npm_install/test/patches_yarn:yarn.lock", quiet = False, manual_build_file_contents = """exports_files(["_/internal/npm_install/test/patches_yarn/package.json"])""", @@ -475,7 +457,6 @@ filegroup( # add scripts.new "scripts.new": "added", }, - symlink_node_modules = False, quiet = False, manual_build_file_contents = """exports_files(["_/internal/npm_install/test/patches_npm/package.json"])""", ) @@ -550,7 +531,6 @@ filegroup( )""", package_json = "//:tools/fine_grained_goldens/package.json", package_path = "tools/fine_grained_goldens", - symlink_node_modules = False, yarn_lock = "//:tools/fine_grained_goldens/yarn.lock", ) @@ -564,12 +544,12 @@ filegroup( name = "cypress_deps", package_json = "//packages/cypress/test:package.json", yarn_lock = "//packages/cypress/test:yarn.lock", + symlink_node_modules = True, ) yarn_install( name = "rollup_test_multi_linker_deps", package_json = "//packages/rollup/test/multi_linker:package.json", package_path = "packages/rollup/test/multi_linker", - symlink_node_modules = False, yarn_lock = "//packages/rollup/test/multi_linker:yarn.lock", ) diff --git a/packages/create/index.js b/packages/create/index.js index f67806f1b3..8c3e7a584c 100644 --- a/packages/create/index.js +++ b/packages/create/index.js @@ -167,9 +167,6 @@ def fetch_dependencies(): workspace( # How this workspace would be referenced with absolute labels from another workspace name = "${wkspName}", - # Map the @npm bazel workspace to the node_modules directory. - # This lets Bazel use the same node_modules as other local tooling. - managed_directories = {"@npm": ["node_modules"]}, ) load("//tools:bazel_deps.bzl", "fetch_dependencies") diff --git a/toolchains/esbuild/esbuild_repositories.bzl b/toolchains/esbuild/esbuild_repositories.bzl index bcdadf712c..c2f5aaa15d 100644 --- a/toolchains/esbuild/esbuild_repositories.bzl +++ b/toolchains/esbuild/esbuild_repositories.bzl @@ -77,6 +77,5 @@ def esbuild_repositories(name = "", npm_repository = "npm", npm_args = []): # Disable scripts as we don't need the javascript shim replaced wit the binary. "--ignore-scripts", ] + npm_args, - symlink_node_modules = False, package_path = package_path, )