Skip to content

Commit f712377

Browse files
authored
fix: yarn_install failure if yarn is a dependency (#1581)
This fixes a regression in 1.2.0 where the repository rule generated shell script `yarn` in the root of the external repository created by yarn_install conflicts with the npm package `yarn` directory that generate_build_files.js wants to create. The error observed was: ``` Error: ENOTDIR: not a directory, mkdir 'yarn/bin' at Object.mkdirSync (fs.js:823:3) at mkdirp (/private/var/tmp/_bazel_pryan/7a08068b62d3caa281adb87aa0ce207a/external/npm/generate_build_file.js:81:16) at writeFileSync (/private/var/tmp/_bazel_pryan/7a08068b62d3caa281adb87aa0ce207a/external/npm/generate_build_file.js:89:9) at generatePackageBuildFiles ``` Also fixes the same potential problem with the repository rule generated `npm` shell script.
1 parent 0b4ef06 commit f712377

File tree

3 files changed

+1765
-49
lines changed

3 files changed

+1765
-49
lines changed

internal/npm_install/npm_install.bzl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ def _npm_install_impl(repository_ctx):
219219

220220
# The entry points for npm install for osx/linux and windows
221221
if not is_windows_host:
222+
# Prefix filenames with _ so they don't conflict with the npm package `npm`
222223
repository_ctx.file(
223-
"npm",
224+
"_npm.sh",
224225
content = """#!/usr/bin/env bash
225226
# Immediately exit if any command fails.
226227
set -e
@@ -234,7 +235,7 @@ set -e
234235
)
235236
else:
236237
repository_ctx.file(
237-
"npm.cmd",
238+
"_npm.cmd",
238239
content = """@echo off
239240
cd "{root}" && "{npm}" {npm_args}
240241
""".format(
@@ -264,7 +265,7 @@ cd "{root}" && "{npm}" {npm_args}
264265

265266
repository_ctx.report_progress("Running npm install on %s" % repository_ctx.attr.package_json)
266267
result = repository_ctx.execute(
267-
[repository_ctx.path("npm.cmd" if is_windows_host else "npm")],
268+
[repository_ctx.path("_npm.cmd" if is_windows_host else "_npm.sh")],
268269
timeout = repository_ctx.attr.timeout,
269270
quiet = repository_ctx.attr.quiet,
270271
)
@@ -338,8 +339,9 @@ def _yarn_install_impl(repository_ctx):
338339

339340
# The entry points for npm install for osx/linux and windows
340341
if not is_windows_host:
342+
# Prefix filenames with _ so they don't conflict with the npm packages
341343
repository_ctx.file(
342-
"yarn",
344+
"_yarn.sh",
343345
content = """#!/usr/bin/env bash
344346
# Immediately exit if any command fails.
345347
set -e
@@ -353,7 +355,7 @@ set -e
353355
)
354356
else:
355357
repository_ctx.file(
356-
"yarn.cmd",
358+
"_yarn.cmd",
357359
content = """@echo off
358360
cd "{root}" && "{yarn}" {yarn_args}
359361
""".format(
@@ -383,7 +385,7 @@ cd "{root}" && "{yarn}" {yarn_args}
383385

384386
repository_ctx.report_progress("Running yarn install on %s" % repository_ctx.attr.package_json)
385387
result = repository_ctx.execute(
386-
[repository_ctx.path("yarn.cmd" if is_windows_host else "yarn")],
388+
[repository_ctx.path("_yarn.cmd" if is_windows_host else "_yarn.sh")],
387389
timeout = repository_ctx.attr.timeout,
388390
quiet = repository_ctx.attr.quiet,
389391
)

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"node_resolve_main": "file:./tools/npm_packages/node_resolve_main",
5050
"node_resolve_main_2": "file:./tools/npm_packages/node_resolve_main_2",
5151
"node_resolve_nested_main": "file:./tools/npm_packages/node_resolve_nested_main",
52+
"npm": "6.13.7",
5253
"parse5": "5.1.0",
5354
"protobufjs": "6.8.8",
5455
"protractor": "^5.4.2",
@@ -74,6 +75,7 @@
7475
"typescript": "3.1.6",
7576
"unidiff": "1.0.1",
7677
"v8-coverage": "1.0.9",
78+
"yarn": "1.21.1",
7779
"zone.js": "0.8.29"
7880
},
7981
"scripts": {

0 commit comments

Comments
 (0)