Skip to content

Commit

Permalink
fix: yarn_install failure if yarn is a dependency (#1581)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gregmagolan authored Jan 29, 2020
1 parent 0b4ef06 commit f712377
Show file tree
Hide file tree
Showing 3 changed files with 1,765 additions and 49 deletions.
14 changes: 8 additions & 6 deletions internal/npm_install/npm_install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ def _npm_install_impl(repository_ctx):

# The entry points for npm install for osx/linux and windows
if not is_windows_host:
# Prefix filenames with _ so they don't conflict with the npm package `npm`
repository_ctx.file(
"npm",
"_npm.sh",
content = """#!/usr/bin/env bash
# Immediately exit if any command fails.
set -e
Expand All @@ -234,7 +235,7 @@ set -e
)
else:
repository_ctx.file(
"npm.cmd",
"_npm.cmd",
content = """@echo off
cd "{root}" && "{npm}" {npm_args}
""".format(
Expand Down Expand Up @@ -264,7 +265,7 @@ cd "{root}" && "{npm}" {npm_args}

repository_ctx.report_progress("Running npm install on %s" % repository_ctx.attr.package_json)
result = repository_ctx.execute(
[repository_ctx.path("npm.cmd" if is_windows_host else "npm")],
[repository_ctx.path("_npm.cmd" if is_windows_host else "_npm.sh")],
timeout = repository_ctx.attr.timeout,
quiet = repository_ctx.attr.quiet,
)
Expand Down Expand Up @@ -338,8 +339,9 @@ def _yarn_install_impl(repository_ctx):

# The entry points for npm install for osx/linux and windows
if not is_windows_host:
# Prefix filenames with _ so they don't conflict with the npm packages
repository_ctx.file(
"yarn",
"_yarn.sh",
content = """#!/usr/bin/env bash
# Immediately exit if any command fails.
set -e
Expand All @@ -353,7 +355,7 @@ set -e
)
else:
repository_ctx.file(
"yarn.cmd",
"_yarn.cmd",
content = """@echo off
cd "{root}" && "{yarn}" {yarn_args}
""".format(
Expand Down Expand Up @@ -383,7 +385,7 @@ cd "{root}" && "{yarn}" {yarn_args}

repository_ctx.report_progress("Running yarn install on %s" % repository_ctx.attr.package_json)
result = repository_ctx.execute(
[repository_ctx.path("yarn.cmd" if is_windows_host else "yarn")],
[repository_ctx.path("_yarn.cmd" if is_windows_host else "_yarn.sh")],
timeout = repository_ctx.attr.timeout,
quiet = repository_ctx.attr.quiet,
)
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"node_resolve_main": "file:./tools/npm_packages/node_resolve_main",
"node_resolve_main_2": "file:./tools/npm_packages/node_resolve_main_2",
"node_resolve_nested_main": "file:./tools/npm_packages/node_resolve_nested_main",
"npm": "6.13.7",
"parse5": "5.1.0",
"protobufjs": "6.8.8",
"protractor": "^5.4.2",
Expand All @@ -74,6 +75,7 @@
"typescript": "3.1.6",
"unidiff": "1.0.1",
"v8-coverage": "1.0.9",
"yarn": "1.21.1",
"zone.js": "0.8.29"
},
"scripts": {
Expand Down
Loading

0 comments on commit f712377

Please sign in to comment.