Skip to content

Commit

Permalink
Use an absolute path to bazel-out in the .pack and .publish verbs of …
Browse files Browse the repository at this point in the history
…npm_package

Fixes #187
  • Loading branch information
alexeagle committed Nov 30, 2018
1 parent c19ce36 commit 587b48e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions internal/npm_package/npm_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def create_package(ctx, devmode_sources, nested_packages):
inputs = inputs,
outputs = [package_dir, ctx.outputs.pack, ctx.outputs.publish],
arguments = [args],
execution_requirements = {
# Never schedule this action remotely because it's not computationally expensive.
# It just copies files into a directory; it's not worth copying inputs and outputs to a remote worker.
# Also don't run it in a sandbox, because it resolves an absolute path to the bazel-out directory
# allowing the .pack and .publish runnables to work with no symlink_prefix
# See https://github.com/bazelbuild/rules_nodejs/issues/187
"local": "1"
},
)
return package_dir

Expand Down
5 changes: 3 additions & 2 deletions internal/npm_package/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ function main(args) {

const npmTemplate =
fs.readFileSync(require.resolve('nodejs/run_npm.sh.template'), {encoding: 'utf-8'});
fs.writeFileSync(packPath, npmTemplate.replace('TMPL_args', `pack ${outDir}`));
fs.writeFileSync(publishPath, npmTemplate.replace('TMPL_args', `publish ${outDir}`));
// Resolve the outDir to an absolute path so it doesn't depend on Bazel's bazel-out symlink
fs.writeFileSync(packPath, npmTemplate.replace('TMPL_args', `pack "${path.resolve(outDir)}"`));
fs.writeFileSync(publishPath, npmTemplate.replace('TMPL_args', `publish "${path.resolve(outDir)}"`));
}

if (require.main === module) {
Expand Down
5 changes: 4 additions & 1 deletion internal/npm_package/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ npm_package(

npm_package(
name = "test_pkg",
srcs = ["some_file"],
srcs = [
"package.json",
"some_file",
],
packages = [":dependent_pkg"],
replacements = {"replace_me": "replaced"},
deps = [
Expand Down
5 changes: 5 additions & 0 deletions internal/npm_package/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "test-pkg",
"private": true,
"version": "0.0.0-PLACEHOLDER"
}

0 comments on commit 587b48e

Please sign in to comment.