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

Cannot use plain JS sources with TypeScript targets #1657

Closed
sgammon opened this issue Feb 20, 2020 · 11 comments
Closed

Cannot use plain JS sources with TypeScript targets #1657

sgammon opened this issue Feb 20, 2020 · 11 comments
Labels
Can Close? We will close this in 30 days if there is no further activity enhancement

Comments

@sgammon
Copy link
Contributor

sgammon commented Feb 20, 2020

🐞 bug report

Affected Rule

ts_library

Is this a regression?

I don't think so, no

Description

There should be an ability to use JS sources with the ts_library rule, so that one might use the TypeScript compiler to check JS files (via the allowJs/checkJs compiler flags to tsc). Currently, though, trying to use *.js sources with ts_library yields the error:

ERROR: /.../src/BUILD.bazel:9:1: in srcs attribute of ts_library rule //samples/node_mvc/src:JavaScriptController: '//samples/node_mvc/src:JavaScriptController.js' does not produce any ts_library srcs files (expected .ts or .tsx). Since this rule was created by the macro...

This is because the ts_library rule implementation forbids sources with extensions other than ts, tsx for ts_library.

🔬 Minimal Reproduction

SomeFile.js:

// (anything)

tsconfig.json:

{
    "compilerOptions": {
         "allowJs": true,
         "checkJs": true
    }
}

BUILD.bazel:

load("@npm_bazel_typescript//:index.bzl", "ts_library")

ts_library(
  name = "SomeFile",
  srcs = ["SomeFile.js"],
)

Then:

echo "2.1.0" > .bazelversion && bazelisk build //:SomeFile

🔥 Exception or Error


ERROR: /.../src/BUILD.bazel:9:1: in srcs attribute of ts_library rule //samples/node_mvc/src:JavaScriptController: '//samples/node_mvc/src:JavaScriptController.js' does not produce any ts_library srcs files (expected .ts or .tsx). Since this rule was created by the macro...

🌍 Your Environment

Operating System:

  
    macOS Catalina (10.15.2)
  

Output of bazel version:

  
Bazelisk version: development
Build label: 2.1.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Feb 7 13:04:00 2020 (1581080640)
Build timestamp: 1581080640
Build timestamp as int: 1581080640
  

Rules_nodejs version:

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

  
{
    "devDependencies": {
      "@bazel/bazel": "2.1.0",
      "@bazel/buildifier": "latest",
      "@bazel/ibazel": "^0.12.0",
      "@bazel/jasmine": "^1.2.4",
      "@bazel/karma": "^1.2.4",
      "@bazel/source-map-support": "latest",
      "@bazel/terser": "^1.2.4",
      "@bazel/typescript": "^1.2.4"
    }
}
  

rules_nodejs version: 1.3.0

@Toxicable
Copy link

While I agree that ts_library should take all inputs that normal tsc can there are a couple of constraints on it at the moment.
If you need this feature asap then you can actually use the native tsc directly like so: https://bazelbuild.github.io/rules_nodejs/TypeScript.html#alternatives

@joeljeske
Copy link
Contributor

This is tricky since JS and MJS files are generated at the same output path as the source file. It would seem that even manual use of TSC might encounter conflicts noticed by bazel.

I have run into this issue myself when I want to perform multiple transformation steps on an input file; you have to ensure distinct output paths.

@Toxicable are you aware of any plans to somehow make output files distinct from source files, perhaps with a different file extension?

@sgammon
Copy link
Contributor Author

sgammon commented Feb 28, 2020

@joeljeske good point, perhaps a .source.js or something?

mostly my goal here is checking existing js, but compiling ts with js would be nice. checking JS might not need to create files at all

@alexeagle
Copy link
Collaborator

I think the problem of input artifacts having the same path as output artifacts is orthogonal to the question here which is simply about the restriction we placed on which files are allowed in the srcs of ts_library. I agree it should be relaxed, though we'll need to take care with that change since it wouldn't be desirable in google-internal (they use closure compiler to check .js files and wouldn't want them allowed as srcs of ts_library)

FWIW I should adjust my ts_project prototype to allow these inputs https://github.com/alexeagle/ts_composite/blob/master/ts_project.bzl#L10

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

@github-actions github-actions bot added the Can Close? We will close this in 30 days if there is no further activity label Sep 15, 2020
@github-actions
Copy link

github-actions bot commented Oct 3, 2020

This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

@github-actions github-actions bot closed this as completed Oct 3, 2020
@henrysecond1
Copy link

henrysecond1 commented Oct 6, 2020

Any updates on this issue? I'm suffering from the same issue...

@alexeagle
Copy link
Collaborator

I think this works with ts_project. ts_library is kinda stuck until we resolve whether to fork from Google-internal #2120

@alexeagle alexeagle reopened this Oct 7, 2020
@github-actions github-actions bot removed the Can Close? We will close this in 30 days if there is no further activity label Jan 23, 2021
@ecunal
Copy link

ecunal commented Jan 28, 2021

Hey, looks like #2120 is resolved, is there a chance to support JS files with ts_library now?

@github-actions
Copy link

github-actions bot commented May 1, 2021

This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

@github-actions github-actions bot added the Can Close? We will close this in 30 days if there is no further activity label May 1, 2021
@alexeagle
Copy link
Collaborator

Sorry I don't think anyone has time or interest to dive into ts_library to add features like this. If you just want to typecheck .js files, ts_project works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Can Close? We will close this in 30 days if there is no further activity enhancement
Projects
None yet
Development

No branches or pull requests

6 participants