Skip to content

Commit 52b7ccc

Browse files
committed
build: don't put .node_modules/bin on the path
Since Yarn 0.25 (yarnpkg/yarn#3310), Yarn transitively symlinks binaries into node_modules/.bin. (Previously, it would only sync top-level binaries--i.e., binaries that we directly depend on.) The new behavior results in adding all sorts of junk to the path--notably, a JavaScript which reimplementation that shadows the system-provided which. Ew. Avoid putting node_modules/.bin on the PATH by using full paths to the binaries within, or using `yarn run` if within pkg/ui.
1 parent 22a2b5f commit 52b7ccc

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

build/common.mk

+1-8
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ GO_INSTALL := GOBIN='$(LOCAL_BIN)' $(GO) install
4848

4949
# Prefer tools we've installed with go install and Yarn to those elsewhere on
5050
# the PATH.
51-
#
52-
# Usually, we could use the yarn run command to avoid changing the PATH
53-
# globally. Unfortunately, yarn run must be executed in or beneath UI_ROOT, but
54-
# protobuf.mk, which depends on Yarn-installed executables, needs to execute in
55-
# ORG_ROOT. It's much simpler to add the Yarn executable-installation directory
56-
# to the PATH than have protobuf.mk adjust its paths to work in both ORG_ROOT
57-
# and UI_ROOT.
58-
export PATH := $(LOCAL_BIN):$(UI_ROOT)/node_modules/.bin:$(PATH)
51+
export PATH := $(LOCAL_BIN):$(PATH)
5952

6053
# HACK: Make has a fast path and a slow path for command execution,
6154
# but the fast path uses the PATH variable from when make was started,

build/protobuf.mk

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ GW_SOURCES := $(GW_PROTOS:%.proto=%.pb.gw.go)
5151
GO_PROTOS := $(addprefix $(REPO_ROOT)/, $(sort $(shell git -C $(REPO_ROOT) ls-files --exclude-standard --cached --others -- '*.proto')))
5252
GO_SOURCES := $(GO_PROTOS:%.proto=%.pb.go)
5353

54+
PBJS := $(UI_ROOT)/node_modules/.bin/pbjs
55+
PBTS := $(UI_ROOT)/node_modules/.bin/pbts
56+
5457
UI_JS := $(UI_ROOT)/src/js/protos.js
5558
UI_TS := $(UI_ROOT)/src/js/protos.d.ts
5659
UI_SOURCES := $(UI_JS) $(UI_TS)
@@ -101,15 +104,15 @@ $(CPP_SOURCES_TARGET): $(PROTOC) $(CPP_PROTOS)
101104
$(UI_JS): $(GO_PROTOS) $(COREOS_RAFT_PROTOS) $(YARN_INSTALLED_TARGET)
102105
# Add comment recognized by reviewable.
103106
echo '// GENERATED FILE DO NOT EDIT' > $@
104-
pbjs -t static-module -w es6 --strict-long --keep-case --path $(ORG_ROOT) --path $(GOGO_PROTOBUF_PATH) --path $(COREOS_PATH) --path $(GRPC_GATEWAY_GOOGLEAPIS_PATH) $(GW_PROTOS) >> $@
107+
$(PBJS) -t static-module -w es6 --strict-long --keep-case --path $(ORG_ROOT) --path $(GOGO_PROTOBUF_PATH) --path $(COREOS_PATH) --path $(GRPC_GATEWAY_GOOGLEAPIS_PATH) $(GW_PROTOS) >> $@
105108

106109
$(UI_TS): $(UI_JS) $(YARN_INSTALLED_TARGET)
107110
# Install a known-good version of jsdoc; see
108111
# https://github.com/dcodeIO/protobuf.js/issues/716.
109112
(cd $(UI_ROOT)/node_modules/protobufjs/cli && npm install --silent jsdoc@3.4.3)
110113
# Add comment recognized by reviewable.
111114
echo '// GENERATED FILE DO NOT EDIT' > $@
112-
pbts $(UI_JS) >> $@
115+
$(PBTS) $(UI_JS) >> $@
113116

114117
.DEFAULT_GOAL := protos
115118
.PHONY: protos

pkg/ui/Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ generate: $(GOBINDATA_TARGET)
3232

3333
.PHONY: lint
3434
lint: $(YARN_INSTALLED_TARGET) | protos
35-
stylint -c .stylintrc styl
36-
tslint -c tslint.json -p tsconfig.json --type-check
35+
yarn run -- stylint -c .stylintrc styl
36+
yarn run -- tslint -c tslint.json -p tsconfig.json --type-check
3737

3838
.PHONY: test
3939
test: $(YARN_INSTALLED_TARGET) | protos
40-
karma start
40+
yarn run -- karma start
4141

4242
.PHONY: test-watch
4343
test-watch: $(YARN_INSTALLED_TARGET) | protos
44-
karma start --no-single-run --auto-watch
44+
yarn run -- karma start --no-single-run --auto-watch
4545

4646
$(GOBINDATA_TARGET): $(YARN_INSTALLED_TARGET) $(shell git ls-files | grep -vF $(GOBINDATA_TARGET)) | protos
4747
rm -rf dist
48-
webpack -p
48+
yarn run -- webpack -p
4949
go-bindata -nometadata -pkg ui -o $@ -prefix dist dist/...
5050
# Add comment recognized by reviewable.
5151
echo '// GENERATED FILE DO NOT EDIT' >> $@

0 commit comments

Comments
 (0)