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

Running nodejs_test with a output from ts_library fails when using TSX #1351

Closed
joeljeske opened this issue Nov 14, 2019 · 3 comments
Closed
Labels

Comments

@joeljeske
Copy link
Contributor

🐞 bug report

Affected Rule

The issue is caused by the rule:

nodejs_test using output from ts_library

Is this a regression?

Not sure, probably not.

Description

I want to compile TSX files into JS for executing tests in NodeJS. Using the output from ts_library as input to nodejs_test. What is interesting is that if the file was just .ts instead of .tsx then the test would properly find the file.

🔬 Minimal Reproduction

# BUILD.bazel

load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
    name = "compile_tests",
    srcs = glob(["some.test.tsx"]),
)

load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
nodejs_test(
    name = "run_tests",
    entry_point = "some.test.tsx",
    data = ["compile_tests"]
)

🔥 Exception or Error


Error: Cannot find module 'some.test.tsx'. Please verify that the package.json has a valid "main" entry
/// stack trace

🌍 Your Environment

Operating System:

  
macOS 10.14.6
  

Output of bazel version:

  
Build label: 1.1.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Oct 21 08:47:13 2019 (1571647633)
Build timestamp: 1571647633
Build timestamp as int: 1571647633
  

Rules version (SHA):

  
3d7296d834208792fa3b2ded8ec04e75068e3de172fae79db217615bd75a6ff7
  

Anything else relevant?

@joeljeske
Copy link
Contributor Author

It would seem as though it works with TS files is because of

https://github.com/bazelbuild/rules_nodejs/blob/cc11b202e3fc70e0dab5e02a701a453510fdab6c/internal/node/node.bzl#L101

This seems a bit fragile to me and special cased. Is there a better way that "aliases" or "transforms" could be specified so the translated file could be derived from the request?

@alexeagle
Copy link
Collaborator

Thanks for tracking down the root cause.

A simple answer is that if the rule which transpiles to JS were to give a label to the outputs, you could just do entry_point = "some.test.jsx" and we wouldn't need this logic in node.bzl. But ts_library currently doesn't give labels for its outputs.

I think there are few enough cases of transpile-to-JS languages that we can just add missing cases here. Sending a PR...

@alexeagle alexeagle added the bug label Nov 18, 2019
alexeagle added a commit to alexeagle/rules_nodejs that referenced this issue Nov 18, 2019
@joeljeske
Copy link
Contributor Author

@alexeagle Thanks for the reply. I have left a comment on that commit with a question regarding the changing of TSX to JSX.

313d484#commitcomment-36012644

Essentially, I am worried that your change assumes that TSC is outputting JSX as opposed to JS. tsconfig.json can be configured to preserve the XML or to transform it.

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

2 participants