does anyone have a BUILD file they could share for...
# general
l
does anyone have a BUILD file they could share for a typescript next app, or a react app? I've been trying to use the javascript repository, and have come up with the something like:
Copy code
javascript_sources(
    name="frontend-javascript-files",
    sources=["src/**/*.js", "src/**/*.jsx"],  # Add explicit patterns
)

typescript_sources(
    name="frontend-typescript-files",
    sources=["src/**/*.ts"],  # Add explicit patterns
)

tsx_sources(
    name="frontend-tsx-files",
    sources=["src/**/*.tsx"],  # Add explicit patterns
)

package_json(
    name="frontend-package",
    source="package.json",
    scripts = [
    node_build_script(
            entry_point="build",
            output_directories=[".next"],
            extra_env_vars=[
                # "NODE_ENV=production",
                "NEXT_TELEMETRY_DISABLED=1",  # optional: disables telemetry
            ],
        ),
        node_test_script(
            entry_point="lint",  # assuming you're using `next lint`
        ),
    ],
    dependencies = [
        ":frontend-javascript-files",
        ":frontend-typescript-files",
        ":frontend-tsx-files",
    ]

)

docker_image(
    name="frontend-docker-image",
    dependencies=[
        ":frontend-package"
    ]
But have not been able to get the
src
folder and the files in it actually part of the build. It looks like having them explicitly defined in the dependencies doesn't mean that they are actually available at build time I was going to try next using
files
but that seems like an anti pattern
w
@worried-painter-31382 might be a good person to ask
l
So I have been able to get it working by using:
Copy code
files(
    name="static_src",
    sources=["**/*", "!node_modules/**/*"],
)
but again, it does not feel quite right to do this. @worried-painter-31382 some help would be appreciated!
f
@late-breakfast-42820: Is Pants inferring the correct dependencies for your project? Use
pants dependencies
,
pants dependents
, (or for a massive data dump
pants peek
)
And what have you set your source roots to?
A copy of your
pants.toml
would be useful to understand that.
l
okay interesting, I have two python apps that are resolving well
Copy code
[GLOBAL]
pants_version = "2.26.0"

backend_packages = [
  "pants.backend.python",
  "pants.backend.experimental.typescript",
  "pants.backend.experimental.javascript",
  "pants.backend.docker",     # Docker support
  "pants.backend.shell",

  "pants.backend.experimental.helm",


]
build_file_prelude_globs = []
pants_ignore = [
  ".next",
  "venv/",
  "__pycache__/",
  "node_modules/",
]
[source]
marker_filenames = ["pyproject.toml"]

[python]
interpreter_constraints = ['==3.11.*']

[docker]
use_buildx=true

[dockerfile-parser]
use_rust_parser=true

[anonymous-telemetry]
enabled = false
f
You may need to set https://www.pantsbuild.org/2.26/reference/subsystems/source#root_patterns then to reflect the "top-level" directories for your Javascript and Typescript.
(If
src
is not the top-level directory.)
n
You would need to use files() I think as typescript build isn't natively supported by the backend yet.
☝️ 1
w
If you feel adventorous the >=2.28.0.dev3 series supports ts, js, jsx and tsx dep inference correctly
I also suggest placing a package.json at repo root and allocate your subpackage package.json in w/e package manager workspace configuration it provides