Skip to content

Commit 0312800

Browse files
JaredNeilalexeagle
authored andcommitted
fix: invalidate installed npm repositories correctly (#1200) (#1205)
1 parent 893f61e commit 0312800

4 files changed

Lines changed: 17 additions & 19 deletions

File tree

internal/copy_repository/copy_repository.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def _copy_repository_impl(rctx):
3434
copy_repository = repository_rule(
3535
implementation = _copy_repository_impl,
3636
attrs = {
37-
"lock_file": attr.label(
38-
allow_single_file = True,
39-
doc = "Though unused, this attribute is necessary to cause this rule to be re-executed anytime the node_modules changes.",
40-
),
4137
"marker_file": attr.label(allow_single_file = True),
4238
},
4339
)

internal/npm_install/generate_build_file.js

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/npm_install/generate_build_file.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import * as fs from 'fs';
4444
import * as path from 'path';
45+
import * as crypto from 'crypto';
4546

4647
function log_verbose(...m: any[]) {
4748
if (!!process.env['VERBOSE_LOGS']) console.error('[generate_build_file.js]', ...m);
@@ -59,7 +60,7 @@ const args = process.argv.slice(2);
5960
const WORKSPACE = args[0];
6061
const RULE_TYPE = args[1];
6162
const ERROR_ON_BAZEL_FILES = parseInt(args[2]);
62-
const LOCK_FILE_LABEL = args[3];
63+
const LOCK_FILE_PATH = args[3];
6364
const INCLUDED_FILES = args[4] ? args[4].split(',') : [];
6465
const DYNAMIC_DEPS = JSON.parse(args[5] || '{}');
6566

@@ -333,17 +334,17 @@ def _maybe(repo_rule, name, **kwargs):
333334
path.posix.join(workspaceSourcePath, 'BUILD.bazel'),
334335
'# Marker file that this directory is a bazel package');
335336
}
337+
const sha256sum = crypto.createHash('sha256');
338+
sha256sum.update(fs.readFileSync(LOCK_FILE_PATH, {encoding: 'utf8'}));
336339
writeFileSync(
337340
path.posix.join(workspaceSourcePath, '_bazel_workspace_marker'),
338-
'# Marker file to used by custom copy_repository rule');
341+
`# Marker file to used by custom copy_repository rule\n${sha256sum.digest('hex')}`);
339342

340343
bzlFile += `def install_${workspace}():
341344
_maybe(
342345
copy_repository,
343346
name = "${workspace}",
344347
marker_file = "@${WORKSPACE}//_workspaces/${workspace}:_bazel_workspace_marker",
345-
# Ensure that changes to the node_modules cause the copy to re-execute
346-
lock_file = "@${WORKSPACE}${LOCK_FILE_LABEL}",
347348
)
348349
`;
349350

internal/npm_install/npm_install.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ load("//internal/node:node_labels.bzl", "get_node_label", "get_npm_label", "get_
2828
COMMON_ATTRIBUTES = dict(dict(), **{
2929
"always_hide_bazel_files": attr.bool(
3030
doc = """Always hide Bazel build files such as `BUILD` and BUILD.bazel` by prefixing them with `_`.
31-
31+
3232
Defaults to False, in which case Bazel files are _not_ hidden when `symlink_node_modules`
3333
is True. In this case, the rule will report an error when there are Bazel files detected
3434
in npm packages.
@@ -78,7 +78,7 @@ Note that the pattern used by many packages, which have plugins in the form pkg-
7878
added as implicit dependencies. Thus for example, `rollup` will automatically get `rollup-plugin-json` included in its
7979
dependencies without needing to use this attribute.
8080
81-
The keys in the dict are npm package names, and the value may be a particular package, or a prefix ending with *.
81+
The keys in the dict are npm package names, and the value may be a particular package, or a prefix ending with *.
8282
For example, `dynamic_deps = {"@bazel/typescript": "tsickle", "karma": "my-karma-plugin-*"}`
8383
8484
Note, this may sound like "optionalDependencies" but that field in package.json actually means real dependencies
@@ -134,7 +134,7 @@ fine grained npm dependencies.
134134
),
135135
"symlink_node_modules": attr.bool(
136136
doc = """Turn symlinking of node_modules on
137-
137+
138138
This requires the use of Bazel 0.26.0 and the experimental
139139
managed_directories feature.
140140
@@ -163,7 +163,7 @@ def _create_build_files(repository_ctx, rule_type, node, lock_file):
163163
repository_ctx.attr.name,
164164
rule_type,
165165
"1" if error_on_build_files else "0",
166-
str(lock_file),
166+
repository_ctx.path(lock_file),
167167
",".join(repository_ctx.attr.included_files),
168168
str(repository_ctx.attr.dynamic_deps),
169169
])
@@ -413,7 +413,7 @@ yarn_install = repository_rule(
413413
"frozen_lockfile": attr.bool(
414414
default = False,
415415
doc = """Passes the --frozen-lockfile flag to prevent updating yarn.lock.
416-
416+
417417
Note that enabling this option will require that you run yarn outside of Bazel
418418
when making changes to package.json.
419419
""",

0 commit comments

Comments
 (0)