aspect-build / aspect-build/rules_js
[Bug]: __dirname is not hermetic
- Dominant language
- Starlark
- Stars
- 378
- Forks
- 183
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 32
Description
### What happened?
In some scenarios, the path pointed by `__dirname` is not in runfiles.
### Version
Development (host) and target OS/architectures:
Output of `bazel --version`: 7.1.1
Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: 1.41.0
Language(s) and/or frameworks involved: js
### How to reproduce
```shell
https://github.com/hunshcn/vitets_alias_broken
bazel run //portal:vite
see output of
```js
console.log(path.resolve('src/'))
console.log(path.resolve(__dirname, 'src/'))
```
```
/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/portal/vite.sh.runfiles/_main/portal/src
/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/portal/src
```
This will lead to some strange problems, such as built twice https://github.com/aspect-build/rules_js/issues/1645
Vite is used in this example (because it is found in production). The problem should be reproduced in a smaller way. But because I am not proficient in js, to be honest, I don't even know how cjs/mjs/ts work together directly. I only tried pure cjs without this problem.
### Any other information?
_No response_
Contributor guide
Research direction
Start with the linked vitets_alias_broken reproduction and run `bazel run //portal:vite`. Compare `path.resolve('src/')` with `path.resolve(__dirname, 'src/')` under the reported Bazel 7.1.1 and rules version 1.41.0 setup. Done means the `__dirname`-based path is in runfiles and the duplicate-build behavior no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, vite
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100