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

cwd, source_root, and source_file_name options do not have any effect #1388

Closed
kherock opened this issue Feb 9, 2021 · 4 comments
Closed
Labels
Milestone

Comments

@kherock
Copy link

kherock commented Feb 9, 2021

Describe the bug
I was trying to figure out why certain options in the CLI weren't working but it looks like the transform functions simply don't do anything with the options listed in the PR title.

Input code

> swc = require('@swc/core');
> swc.transformSync('var foo = 1;\nexport { foo };\n', { sourceMaps: true, sourceRoot: '..', sourceFileName: 'foo'  })
{
  code: 'var foo = 1;\nexport { foo };\n',
  map: '{"version":3,"sources":["<anon>"],"sourcesContent":["var foo = 1;\\nexport { foo };\\n"],"names":[],"mappings":"IAAA,GAAA,GAAA,CAAA;SACA,GAAA"}'
}

> swc.transformFileSync('fixtures/amd.js', { sourceMaps: true, cwd: 'out', sourceRoot: '..' })
{
  code: 'var foo = 1;\nexport { foo };\n',
  map: '{"version":3,"sources":["fixtures/amd.js"],"sourcesContent":["\\nconst foo = 1;\\nexport { foo };"],"names":[],"mappings":"IACA,GAAA,GAAA,CAAA;SACA,GAAA"}'
}
> swc.transformFileSync('../fixtures/amd.js', { sourceMaps: true, cwd: 'out' })
thread '<unnamed>' panicked at 'failed to load file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', native/src/transform.rs:158:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Config

{
    "jsc": {
        "parser": {
            "syntax": "typescript"
        }
    },
    "module": {
        "type": "commonjs"
    }
}

Expected behavior
Here, I'd expect "sources" to not have an anonymous filename, and "sourceRoot" should be set to "..". When a cwd is passed to transformFileSync, the source file in the sibling directory should resolve with a path relative to cwd.

Version
The version of @swc/core: 1.2.47

Additional context
I'm currently fighting this when trying to use @swc/cli as a drop-in replacement for tsc, TypeScript generates its maps using paths relative to the output directory, but currently the only way to achieve the same effect with swc is by starting the process from the output directory itself.

@realtimetodie
Copy link
Contributor

realtimetodie commented Jan 28, 2023

@realtimetodie
Copy link
Contributor

@kdy1 This can be marked as resolved.

@kdy1
Copy link
Member

kdy1 commented Feb 27, 2023

Thank you!

@kdy1 kdy1 closed this as completed Feb 27, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.37 Feb 27, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Mar 30, 2023

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 Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants