Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg_npm not compatible with output from rollup_bundle(output_dir = True) #1567

Closed
joeljeske opened this issue Jan 21, 2020 · 5 comments
Closed
Labels

Comments

@joeljeske
Copy link
Contributor

🐞 bug report

Affected Rule

The issue is caused by the rule:

pkg_npm

Is this a regression?

I do not think so

Description

A clear and concise description of the problem...

pkg_npm is unable to make an archive using outputs that are directories. This might typically happen when using rollup_bundle(output_dir = True) to create a bundle with multiple chunks, however rollup_bundle declares a directory rather than the individual files. This results in an output that cannot be added to a pkg_npm archive.

🔬 Minimal Reproduction

ts_library(
  name = "compile",
  srcs = glob(["*.ts"]),
  tsconfig = '//:tsconfig.json',
)

rollup_bundle(
   name = "bundle",
   entry_point = "index.ts"
   deps = ["compile"],
   format = "esm",
   output_dir = True
)

pkg_npm(
  name = "npm",
  srcs = ["package.json"],
  deps = ["bundle"],
)

🔥 Exception or Error


Error: Path provided was not a file!
    at isStatFile (/private/var/tmp/_bazel_user/abc123/sandbox/darwin-sandbox/1/execroot/project/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/pkg_npm/packager.sh.runfiles/build_bazel_rules_nodejs/third_party/github.com/gjtorikian/isBinaryFile/src/index.js:257:11)
    at isBinaryFileSync (/private/var/tmp/_bazel_user/abc123/sandbox/darwin-sandbox/1/execroot/project/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/pkg_npm/packager.sh.runfiles/build_bazel_rules_nodejs/third_party/github.com/gjtorikian/isBinaryFile/src/index.js:167:5)
    at copyWithReplace (/private/var/tmp/_bazel_user/abc123/sandbox/darwin-sandbox/1/execroot/project/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/pkg_npm/packager.sh.runfiles/build_bazel_rules_nodejs/internal/pkg_npm/packager.js:34:8)
    at main (/private/var/tmp/_bazel_user/abc123/sandbox/darwin-sandbox/1/execroot/project/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/pkg_npm/packager.sh.runfiles/build_bazel_rules_nodejs/internal/pkg_npm/packager.js:143:7)
    at Object. (/private/var/tmp/_bazel_user/abc123/sandbox/darwin-sandbox/1/execroot/project/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/pkg_npm/packager.sh.runfiles/build_bazel_rules_nodejs/internal/pkg_npm/packager.js:185:22)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Object. (/private/var/tmp/ca38e9361951c2708a9402d836e79bb6/sandbox/darwin-sandbox/1/execroot/project/bazel-out/host/bin/external/build_bazel_rules_nodejs/internal/pkg_npm/packager.sh.runfiles/build_bazel_rules_nodejs/internal/pkg_npm/packager_loader.js:32:24)

🌍 Your Environment

Operating System:

  
macOS 10.14.6
  

Output of bazel version:

  
Build label: 1.2.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Nov 20 15:08:12 2019 (1574262492)
Build timestamp: 1574262492
Build timestamp as int: 1574262492
  

Rules_nodejs version:

(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)

  
1.1.0
c97bf38546c220fa250ff2cc052c1a9eac977c662c1fc23eda797b0ce8e70a43
  

Anything else relevant?

@marcus-sa
Copy link

marcus-sa commented Jan 21, 2020

It might be because of your typos:

ts_library(
  name = "compile",
  srcs = glob(["*.ts"]),
  tsconfig = '//:tsconfig.json',
)

rollup_bundle(
   name = "bundle",
   entry_point = "index.ts"
   deps = [":compile"],
   format = "esm",
   output_dir = True
)

pkg_npm(
  name = "npm",
  srcs = ["package.json"],
  deps = [":bundle"],
)

dependencies should be referenced by their target label, in your case by prefixing with :

@joeljeske
Copy link
Contributor Author

Colons are optional and only a matter of convention
https://docs.bazel.build/versions/master/build-ref.html#labels

Within a BUILD file, the package-name part of label may be omitted, and optionally the colon too. So within the BUILD file for package my/app (i.e. //my/app:BUILD), the following "relative" labels are all equivalent:

//my/app:app
//my/app
:app
app

(It is a matter of convention that the colon is omitted for files, but retained for rules, but it is not otherwise significant.)

However, I did write up the example build code quickly for this ticket, it is not exactly from my codebase, but it gives the general idea.

@joeljeske
Copy link
Contributor Author

I am currently using this patch to check for directories and copy their contents into the npm archive.

rules_nodejs-1.1.0-c97bf38546c220fa250ff2cc052c1a9eac977c662c1fc23eda797b0ce8e70a43.patch.txt

It seems using directories is frowned upon in Bazel, but I am not sure what any better way would be since Rollup is deciding where to chunk modules, and not something that is necessarily obvious or statically analyzable.

@nickbehrens
Copy link
Contributor

@joeljeske would you mind turning your patch into a PR? I agree we should be special casing directories in this code.

joeljeske pushed a commit to joeljeske/rules_nodejs that referenced this issue Jan 30, 2020
…nto mirrored structure in the npm archive.
joeljeske added a commit to joeljeske/rules_nodejs that referenced this issue Jan 30, 2020
…nto mirrored structure in the npm archive.
@joeljeske
Copy link
Contributor Author

@nickbehrens thanks for the invitation! I just finished posting a PR for the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants