@@ -23,7 +23,7 @@ See discussion in the README.
2323
2424load ("//:version.bzl" , "VERSION" )
2525load ("//internal/common:check_bazel_version.bzl" , "check_bazel_version" )
26- load ("//internal/common:os_name.bzl" , "is_windows_os" )
26+ load ("//internal/common:os_name.bzl" , "is_windows_os" , "os_name" )
2727load ("//internal/node:node_labels.bzl" , "get_node_label" , "get_npm_label" , "get_yarn_label" )
2828
2929COMMON_ATTRIBUTES = dict (dict (), ** {
@@ -34,8 +34,14 @@ COMMON_ATTRIBUTES = dict(dict(), **{
3434 "data" : attr .label_list (
3535 doc = """Data files required by this rule.
3636
37- If symlink_node_modules is True, this attribute is ignored since
38- the dependency manager will run in the package.json location.
37+ If symlink_node_modules is True, this attribute is optional since the package manager
38+ will run in your workspace folder. It is recommended, however, that all files that the
39+ package manager depends on, such as `.rc` files or files used in `postinstall`, are added
40+ symlink_node_modules is True so that the repository rule is rerun when any of these files
41+ change.
42+
43+ If symlink_node_modules is False, the package manager is run in the bazel external
44+ repository so all files that the package manager depends on must be listed.
3945""" ,
4046 ),
4147 "environment" : attr .string_dict (
@@ -148,6 +154,18 @@ def _add_data_dependencies(repository_ctx):
148154 # files as npm file:// packages
149155 repository_ctx .template ("/" .join (to ), f , {})
150156
157+ def _add_node_repositories_info_deps (repository_ctx ):
158+ # Add a dep to the node_info & yarn_info files from node_repositories
159+ # so that if the node or yarn versions change we re-run the repository rule
160+ repository_ctx .symlink (
161+ Label ("@nodejs_%s//:node_info" % os_name (repository_ctx )),
162+ repository_ctx .path ("_node_info" ),
163+ )
164+ repository_ctx .symlink (
165+ Label ("@nodejs_%s//:yarn_info" % os_name (repository_ctx )),
166+ repository_ctx .path ("_yarn_info" ),
167+ )
168+
151169def _symlink_node_modules (repository_ctx ):
152170 package_json_dir = repository_ctx .path (repository_ctx .attr .package_json ).dirname
153171 repository_ctx .symlink (repository_ctx .path (str (package_json_dir ) + "/node_modules" ), repository_ctx .path ("node_modules" ))
@@ -216,15 +234,14 @@ cd /D "{root}" && "{npm}" {npm_args}
216234 executable = True ,
217235 )
218236
219- if not repository_ctx .attr .symlink_node_modules :
220- repository_ctx .symlink (
221- repository_ctx .attr .package_lock_json ,
222- repository_ctx .path ("package-lock.json" ),
223- )
224- _add_package_json (repository_ctx )
225- _add_data_dependencies (repository_ctx )
226-
237+ repository_ctx .symlink (
238+ repository_ctx .attr .package_lock_json ,
239+ repository_ctx .path ("package-lock.json" ),
240+ )
241+ _add_package_json (repository_ctx )
242+ _add_data_dependencies (repository_ctx )
227243 _add_scripts (repository_ctx )
244+ _add_node_repositories_info_deps (repository_ctx )
228245
229246 result = repository_ctx .execute (
230247 [node , "pre_process_package_json.js" , repository_ctx .path (repository_ctx .attr .package_json ), "npm" ],
@@ -354,15 +371,14 @@ cd /D "{root}" && "{yarn}" {yarn_args}
354371 executable = True ,
355372 )
356373
357- if not repository_ctx .attr .symlink_node_modules :
358- repository_ctx .symlink (
359- repository_ctx .attr .yarn_lock ,
360- repository_ctx .path ("yarn.lock" ),
361- )
362- _add_package_json (repository_ctx )
363- _add_data_dependencies (repository_ctx )
364-
374+ repository_ctx .symlink (
375+ repository_ctx .attr .yarn_lock ,
376+ repository_ctx .path ("yarn.lock" ),
377+ )
378+ _add_package_json (repository_ctx )
379+ _add_data_dependencies (repository_ctx )
365380 _add_scripts (repository_ctx )
381+ _add_node_repositories_info_deps (repository_ctx )
366382
367383 result = repository_ctx .execute (
368384 [node , "pre_process_package_json.js" , repository_ctx .path (repository_ctx .attr .package_json ), "yarn" ],
0 commit comments