File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env node
2+
3+ // Fetch the version of this package from its package.json
24const 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}
You can’t perform that action at this time.
0 commit comments