Skip to content

Commit afabe89

Browse files
authored
fix(builtin): fix npm_version_check.js when running outside of bazel (#1802)
1 parent 1667d50 commit afabe89

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

internal/npm_version_check.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
#!/usr/bin/env node
2+
3+
// Fetch the version of this package from its package.json
24
const pkg = require('./package.json');
3-
const pkgVersion = pkg.version;
4-
const rules_nodejsVersion = process.env['BUILD_BAZEL_RULES_NODEJS_VERSION'];
5+
const pkgVersion = pkg.version || '0.0.0';
6+
7+
// BUILD_BAZEL_RULES_NODEJS_VERSION is only set when within the bazel context
8+
const rulesVersion = process.env['BUILD_BAZEL_RULES_NODEJS_VERSION'] || '0.0.0';
59

6-
const getMajor = versionString => versionString.split('.')[0];
10+
const getMajor = versionString => versionString ? versionString.split('.')[0] : '';
711

8-
// special case the version 0.0.0 so that we don't have to stamp builds
9-
// for dev and testing
10-
if (pkgVersion !== '0.0.0' && getMajor(pkgVersion) !== getMajor(rules_nodejsVersion)) {
12+
// Special cases when either version is 0.0.0.
13+
// rulesVersion will be 0.0.0 when outside of bazel
14+
// pkgVersion may be 0.0.0 for dev builds that are not stamped
15+
if (rulesVersion !== '0.0.0' && pkgVersion !== '0.0.0' &&
16+
getMajor(pkgVersion) !== getMajor(rulesVersion)) {
1117
throw new Error(`Expected package major version to equal @build_bazel_rules_nodejs major version
1218
${pkg.name} - ${pkgVersion}
13-
@build_bazel_rules_nodejs - ${rules_nodejsVersion}
19+
@build_bazel_rules_nodejs - ${rulesVersion}
1420
See https://github.com/bazelbuild/rules_nodejs/wiki/Avoiding-version-skew`);
1521
}

0 commit comments

Comments
 (0)