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

Support sourceRoot from SourceMapBuilder #50

Closed
kdy1 opened this issue Aug 30, 2022 · 4 comments · Fixed by #51
Closed

Support sourceRoot from SourceMapBuilder #50

kdy1 opened this issue Aug 30, 2022 · 4 comments · Fixed by #51

Comments

@kdy1
Copy link
Contributor

kdy1 commented Aug 30, 2022

Related: swc-project/swc#2362

I want to generate sourcemap like

{
  "version": 3,
  "sourceRoot": "/Users/pbadenski/workspace/project/",
  "sources": [
    "test.ts"
  ],
}

but I found that SourceMapBuilder does not provide a way to generate a sourcemap with sourceRoot

@kdy1 kdy1 changed the title Support sourceRoot Support sourceRoot from SourceMapBuilder Aug 30, 2022
@kamilogorek
Copy link
Contributor

kamilogorek commented Sep 22, 2022

Processed SourceMap struct, has sourceRoot already resolved, and all sources are correctly mapped to appropriate paths.

We could potentially add the extract_source_root option to RewriteOptions, which could then be used like so:

let sm = SourceMap::from_reader(input)?;
let processed_sm = sm.rewrite(&RewriteOptions {
    extract_source_root: true,
    ..Default::default()
})?;
processed_sm.to_writer(output)?;

extract_source_root would use a simple find common path algorithm for that.

wdyt @Swatinem @loewenheim?

@Swatinem
Copy link
Member

The raw sourcemaps should have support for parsing/serializing from raw json, and also read/write when constructing with minimal validation.

While resolving sourceRoot at parse time might be the right choice for sentry, I think the swc usecase would rather have the raw values.

Using a default "find common path prefix" sounds interesting, but I think having a more explicit option is the better idea.

@kdy1
Copy link
Contributor Author

kdy1 commented Sep 29, 2022

Thank you!

@kamilogorek
Copy link
Contributor

Published in 6.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants