Is there a way I can add `"*.jsx"` as a default o...
# general
l
Is there a way I can add
"*.jsx"
as a default option to the
javascript_sources.sources
field? I'm imagining setting this default in pants.toml somehow.
c
N.b. that when the field value is provided this way, the behavior changes for globs that doesn’t match any files..
s
If you added
*.jsx
would dependency parsing still work? Actually even if you call them
js
files, does dependency parsing still work for JSX? I've been assuming it wouldn't
Huh TIL
Copy code
import * as React from 'react';

export default function App() {
    return (
        <div>
            <h1>Hello, world!</h1>
        </div>
    );
}
Copy code
╰❱ pants dependencies index.js 
//:0#react
I'd also be interested in
jsx
. I'm having a hard time following the example in the "Extending field defaults". Just to clarify, when doing something like
Copy code
javascript_sources(
  name="support-jsx",
  sources=["index.jsx"]
)
running
pants dependencies :support-jsx
produces
Copy code
InvalidFieldException: BUILD:1: Invalid field value for 'sources' in target //:support-jsx: The 'sources' field in target //:support-jsx can only contain files that end in one of ['.cjs', '.js', '.mjs'], but it had these files: ['index.jsx'].
This can be sidestepped by overriding defaults?
n
I don't believe jsx is currently supported.
c
> This can be sidestepped by overriding defaults? No, the defaults provide field values, but if the field value provided is invalid--that won't change regardless of where the value came from. The error message says it all. The
javascript_sources
target only accepts .cjs, .js and .mjs files.
l
What all would be involved with supporting jsx? So far I've tried building a
jsx_sources
target in a custom plugin:
Copy code
from pants.engine.target import (
    COMMON_TARGET_FIELDS,
    Dependencies,
    MultipleSourcesField,
    StringField,
    Target,
)
class JsxSourcesField(MultipleSourcesField):
    alias = "sources"
    expected_file_extensions = ("*.jsx", "*.js")


class JsxSourcesTarget(Target):
    alias = "jsx_sources"
    core_fields = (
        *COMMON_TARGET_FIELDS,
        Dependencies,
        JsxSourcesField,
    )