aspect-build / aspect-build/rules_swc
[Bug]: paths do not resolve correctly without /*
- Dominant language
- Starlark
- Stars
- 49
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
### What happened?
`paths` resolution does not work for entries in `.swcrc` with keys not ending in `/*`. That is,
such setup works
```json
{
"jsc": {
"paths": {
"@modules/*": [
"./modules/*"
]
}
}
}
```
while this one does not
```json
{
"jsc": {
"paths": {
"@modules/moduleB": [
"./modules/moduleB"
]
}
}
}
```
Interestingly enough, pure `swc` compiler resolves such paths correctly.
### Version
Development (host) and target OS/architectures: Ubuntu 20, x86_64
Output of `bazel --version`: bazel 6.2.1
Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: just clone the rules_swc repo
Language(s) and/or frameworks involved:
- typescript
### How to reproduce
```shell
1. `git clone https://github.com/aspect-build/rules_swc.git`
2. `cd rules_swc/examples/`
3. `npm i @swc/cli @swc/core@1.3.42`
4. add `"scripts": {"swc": "swc paths/"}` to `examples/package.json`
5. change the content of `examples/paths/.swcrc` to
{
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2021",
"baseUrl": "./src",
"paths": {
"@modules/moduleB": [
"./modules/moduleB"
],
"@modules/moduleA": [
"./modules/moduleA"
]
}
},
"module": {
"type": "commonjs"
},
"sourceMaps": true
}
6. `npm run swc` (see the output, it works correctly, e.g. `const _moduleB = require("../moduleB")`)
7. `cd ../` (now you should be in `rules_swc`)
8. `curl -L https://github.com/bazelbuild/bazel/releases/download/6.2.1/bazel-6.2.1-linux-x86_64 -o bazel`
9. `chmod +x bazel`
10. `./bazel build //examples/paths:compile`
11. `cat bazel-bin/examples/paths/src/modules/moduleA/index.js`
You can see `const _moduleB = require("@modules/moduleB");` in the output
```
### Any other information?
_No response_
Contributor guide
Research direction
Start with the reproduction in examples/paths/.swcrc and the //examples/paths:compile target. Compare the Bazel-built output with the pure SWC result for path keys without /*, especially examples/paths/src/modules/moduleA/index.js. Done means the Bazel output resolves @modules/moduleB to the relative module path, matching the standalone SWC behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100