Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: paths do not resolve correctly without /* #202

Open
mksmtn opened this issue Jun 13, 2023 · 1 comment
Open

[Bug]: paths do not resolve correctly without /* #202

mksmtn opened this issue Jun 13, 2023 · 1 comment
Labels
bug Something isn't working more info needed More info needed to proceed further

Comments

@mksmtn
Copy link

mksmtn commented Jun 13, 2023

What happened?

paths resolution does not work for entries in .swcrc with keys not ending in /*. That is,
such setup works

{
  "jsc": {
    "paths": {
      "@modules/*": [
        "./modules/*"
      ]
    }
  }
}

while this one does not

{
  "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

1. `git clone https://github.com/aspect-build/rules_swc.git`
2. `cd rules_swc/examples/`
3. `npm i @swc/cli @swc/[email protected]`
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

@mksmtn mksmtn added the bug Something isn't working label Jun 13, 2023
@github-actions github-actions bot added the untriaged Requires traige label Jun 13, 2023
@alexeagle
Copy link
Member

Hi @mksmtn - could you try reproducing this with the swcx binary, which is the one that has no NodeJS involved? From your repro, I can't tell if it's a bug here in rules_swc, or a problem with the pure-Rust swcx program we spawn.

@alexeagle alexeagle added more info needed More info needed to proceed further and removed untriaged Requires traige labels Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working more info needed More info needed to proceed further
Projects
Status: No status
Development

No branches or pull requests

2 participants