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

Paths are not transformed in dts files #9548

Closed
kishieel opened this issue Sep 11, 2024 · 5 comments · Fixed by #9577
Closed

Paths are not transformed in dts files #9548

kishieel opened this issue Sep 11, 2024 · 5 comments · Fixed by #9577
Assignees
Labels
Milestone

Comments

@kishieel
Copy link

kishieel commented Sep 11, 2024

Describe the bug

I am using the "paths" option in "jsc". The paths are correctly rewritten in the output *.js files, but remain untouched in the *.d.ts files. I would expect them to be rewritten the same way in both types of files.

Input code

export * from "@lib/example";

Config

{
    "$schema": "https://swc.rs/schema.json",
    "sourceMaps": true,
    "jsc": {
      "parser": {
        "syntax": "typescript",
        "decorators": true,
        "dynamicImport": true,
        "dts": true
      },
      "target": "es5",
      "baseUrl": "./",
      "preserveAllComments": false,
      "experimental": {
        "emitIsolatedDts": true
      },
      "paths": {
        "@lib/*": ["src/*"],
        "@tests/*": ["tests/*"]
      }
    },
    "module": {
        "type": "commonjs",
        "strict": true,
        "strictMode": true,
        "lazy": false,
        "noInterop": false
    },
    "minify": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.24&code=H4sIAAAAAAAAA0utKMgvKlHQUkgrys9VUHfIyUzST61IzC3ISVW3BgCTcYWLHQAAAA%3D%3D&config=H4sIAAAAAAAAA21RsXLCMAzd%2BQrO16nXI1MXJnrtwsDYqcdgHNGYsy2fpLSkHP9eOwlpUuJJfk960pMui2V66oFNBV6r9VJVIpHXRcHfZkVcdMTqxBjUU5fMWJOBnY6c8oVq6PETmwRc2k%2F6Rk0MNEJyaRNEn3MbaSKwIRull235EgySFqSpdMc1QXtrtj4iyQwtMzXCudlRO4YevN5YJZo%2BIQsp4OdhCHXQDO%2FkMr4q%2FuBIkNx8wYtzr%2Bg9hLZdqzzkwDkC2cxpN%2FUN3sqW0WmB8m0Y9G6kqKXiaeXG2UPxmLAPxWRStB%2FZ2wiwcE%2Ff4v2drENkmOyh55THsnYw7Zgvk92bZBPDicf3YSFrZpbf4Tss4Z5z%2Bqf5v6oEB9wGAcI4P5gN9jiULa6%2Ft7hwB6gCAAA%3D&strip-types=

SWC Info output

Operating System:
    Platform: linux
    Arch: x64
    Machine Type: x86_64

Binaries:
    Node: 18.17.0
    npm: 9.6.7
    Yarn: 1.22.22
    pnpm: N/A

Relevant Packages:
    @swc/core: 1.7.26
    @swc/helpers: N/A
    @swc/types: 0.1.12
    typescript: 5.6.2

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

main.d.ts looks like:

export * from "./src/example";

Actual behavior

main.d.ts looks like:

export * from "@lib/example";

Version

@swc/cli: 0.4.0 @swc/core: 1.7.26

Additional context

No response

@kishieel kishieel added the C-bug label Sep 11, 2024
@kostnerek
Copy link

I also stumbled upon this issue, would like to see it resolved!

@kdy1 kdy1 added this to the Planned milestone Sep 11, 2024
@robpalme
Copy link

TypeScript does not do specifier rewriting today, so this feature would be SWC-specific behavior.

@kdy1 kdy1 self-assigned this Sep 15, 2024
@CPunisher
Copy link
Contributor

CPunisher commented Sep 21, 2024

swc emits type declarations before does transformation.

let dts_code = if emit_dts && program.is_module() {

@kdy1 So shoud we disable the rewriting (may be breaking change) or do an isolated rewriting ahead of time?

@kdy1
Copy link
Member

kdy1 commented Sep 21, 2024

I think we should apply path_rewriter (or similar name, but in swc_ecma_transforms_module) to the cloned dts module

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 24, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

6 participants