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

fix: node_modules relative paths in sourcemaps #5146

Merged
merged 3 commits into from
Mar 3, 2022

Conversation

zachkirsch
Copy link
Contributor

@zachkirsch zachkirsch commented Feb 27, 2022

Fixes #3500

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

Taking a stab at fixing #3500.

The source maps published with blueprint are incorrect. For example:

app/node_modules/@blueprintjs/select/lib/css/blueprint-select.css.map
{
    "version":3,
    "sources":[
        "../../src/components/omnibar/_omnibar.scss",
        "../../../../node_modules/@blueprintjs/core/src/common/_react-transition.scss",
        ...

The resolved path of that second source is app/node_modules/node_modules/@blueprintjs/core/src/common/_react-transition.scss (notice the double node_modules). This leads to webpack errors like:

Failed to parse source map from '/Users/zachkirsch/Dropbox/Mac/Documents/trace-app/node_modules/node_modules/@blueprintjs/core/src/common/_react-transition.scss' file: Error: ENOENT: no such file or directory, open '/Users/zachkirsch/Dropbox/Mac/Documents/trace-app/node_modules/node_modules/@blueprintjs/core/src/common/_react-transition.scss'

Where does "../../../../node_modules come from?

When the sass is compiled, the path "~@blueprintjs/core/src/common/react-transition" is resolved to "node_modules/@blueprintjs/core/src/common/_react-transition.scss", and node_modules is 4 directories up, hence the final result of ../../../../node_modules/@blueprintjs/core/src/common/_react-transition.scss. Ideally node-sass-chokidar could resolve/follow the symlink to figure out that there's a more direct route to that file (../../../core/src/common/_react-transition.scss), but it doesn't seem like that's possible.

I tried moving to dart-sass since node-sass-chokidar is deprecated, but it looks like the source maps have the same issue (paths going through node_modules).

So this PR is a "cheap" solution - after writing the source maps files, convert the "roundabout" node_modules paths to more direct paths:

{
	"version": 3,
	"sources": [
		"../../src/components/omnibar/_omnibar.scss",
		"../../../core/src/common/_react-transition.scss",

Reviewers should focus on:

Is there a place I can add tests?

Screenshot

@adidahiya
Copy link
Contributor

seems to work fine, I can view the remapped files in dev tools and set a debug breakpoint:

image

@adidahiya adidahiya changed the title In css source maps, replace paths through node_modules with direct paths fix: node_modules relative paths in sourcemaps Mar 3, 2022
@adidahiya adidahiya merged commit 4da3e1e into palantir:develop Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect paths for @blueprintjs source maps that produce multiple warnings on project compilation
2 participants