rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

allow_js in ts_project does not contain js files in outputs for jsx inputs

Open noveyak opened this issue 5 years ago β€’ 3 comments

🐞 bug report

Affected Rule

The issue is caused by the rule: ts_project

Is this a regression?

I don't think so

Description

When compiling .jsx files, tsc produces corresponding .js files but these are missing in the output of the rule

πŸ”¬ Minimal Reproduction

I'm hoping this is relatively easy to understand, I can create a small reproduction case but any .jsx input to ts_project with allow_js should reproduce

πŸ”₯ Exception or Error

No error and just no .js output

Looking at the ts_project rule, it seems like the outputs are created here

    if not emit_declaration_only:
        js_outs.extend(_out_paths(srcs, out_dir, root_dir, False, ".js"))
    if source_map and not emit_declaration_only:
        map_outs.extend(_out_paths(srcs, out_dir, root_dir, False, ".js.map"))
    if declaration or composite:
        typings_outs.extend(_out_paths(srcs, typings_out_dir, root_dir, allow_js, ".d.ts"))
    if declaration_map:
        typing_maps_outs.extend(_out_paths(srcs, typings_out_dir, root_dir, allow_js, ".d.ts.map"))

It seems like passing in allow_js instead of False to _out_paths for js_outs is enough to fix this problem but I'm not sure if there are other implications/undesirable effects of this change

🌍 Your Environment

Operating System:

  
ubuntu 16
  

Output of bazel version:

  
bazel 3.7.0
  

Rules_nodejs version:

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

  
3.0
  

Anything else relevant?

noveyak avatar Jan 08 '21 22:01 noveyak

This would be a good issue to contribute if you'd like.

Add a test case under /packages/typescript/test/ts_project and make the code change you suggested, and see if everything else is green. ts_project has good coverage so if it's green it should be safe.

alexeagle avatar Jan 12 '21 20:01 alexeagle

closed with #2398

mattem avatar Jan 25 '21 02:01 mattem

The fix does not completely work - I cannot see the .js files in bazel-out/. It is there in the sandbox, but the jsx syntax is not converted - remains as in source (when using jsx: "react" in the tsconfig.json).

I'm running rules_nodejs version 4.4.5

Relevant tsconfig options:

{
    "compilerOptions": {
        "target": "es5",
        "allowJs": true,
        "skipLibCheck": true,
        "composite": true,
        "lib": [
            "ES2015",
            "DOM"
        ],
        "jsx": "react",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strict": false,
        "forceConsistentCasingInFileNames": true,
        "module": "esnext",
        "moduleResolution": "Node",
    }
}

stefan-dimitrov avatar Nov 12 '21 11:11 stefan-dimitrov