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

Improve debugging experience by publishing source files to npm #335

Closed
justingrant opened this issue Mar 17, 2019 · 15 comments
Closed

Improve debugging experience by publishing source files to npm #335

justingrant opened this issue Mar 17, 2019 · 15 comments

Comments

@justingrant
Copy link
Contributor

immer doesn't publish its source code files to npm. This makes debugging harder because the pre-compilation source code isn't available (e.g. to set breakpoints) unless the app is running. It can also cause breakpoint locations to shift around from one debugging session to another. The original source is present in the inline sourcemaps (good!) but also having source files would definitely improve the debug experience.

Usually missing source is caused by the source folder being included in .npmignore, but I didn't see an .npmignore file in the immer repo so I'm not sure why the source isn't being published.

@justingrant
Copy link
Contributor Author

Oops, meant to make this a feature request, not a bug report!

@mweststrate
Copy link
Collaborator

mweststrate commented Mar 17, 2019 via email

@aleclarson aleclarson added proposal and removed bug labels Mar 17, 2019
@aleclarson
Copy link
Member

Usually missing source is caused by the source folder being included in .npmignore, but I didn't see an .npmignore file in the immer repo so I'm not sure why the source isn't being published.

See here:

https://github.com/mweststrate/immer/blob/8b33b9882e3c0981e04ee3cd1edd7a9d774612e7/package.json#L41-L43

This makes debugging harder because the pre-compilation source code isn't available (e.g. to set breakpoints) unless the app is running.

You can set the breakpoints in dist/immer.js and your debugger should carry those over to the virtual source files created from the source map. I've never had issues with this.

It can also cause breakpoint locations to shift around from one debugging session to another.

Not sure why that would happen, but I don't think I've ever experienced this.

@justingrant
Copy link
Contributor Author

Can you explain how source files are going to help? they won't be picked up
by the browser so you can't set breakpoints in them.

@mweststrate - the main case where this matters is IDEs like VS Code which operate primarily with offline files. You can set a breakpoint in the original source and it will work at runtime... but only if the original source is there! Although I've never used it, I believe that Chrome also has a file-based mode too (this allows devs to edit their code directly in Chrome) which would be impacted too, but I don't think that mode is used much compared with the IDE case.

I'd be happy to send a PR for this if you think it'd be useful (now that @aleclarson showed me how to do it!)

It can also cause breakpoint locations to shift around from one debugging session to another.

Not sure why that would happen, but I don't think I've ever experienced this.

@aleclarson - I see this frequently. I think that the culprit may be hot reloading combined with limitations in Chrome DevTools and/or VS Code, but the impact is that breakpoints stick to the "old" locations which, if the breakpoint was in transpiled code, may not correspond to the same place in the original source after it's been modified and hot-reloaded. I suspect this is made worse by build pipelines that have multiple transpilation steps, but I have no proof of that theory. ;-)

I also see cases where there are ghost breakpoints that were removed from the original source earlier in the debug session but, again due to changes in transpilation and/or hot reloading, aren't removed from the transpiled code. The effect is annoying: execution stops in the IDE and some random line of code is highlighted, and then you have to go hunting through the breakpoints list to find the culprit.

These issues may be less common in library code (because it's not being changed alot if you're not actually building the library yourself), but I don't fully understand the problem so can't be sure.

You can set the breakpoints in dist/immer.js and your debugger should carry those over to the virtual source files created from the source map. I've never had issues with this.

Yep, this works as a backup but I do find it easier with transpiled libraries to work with the original source. That said, Immer is much less of a problem than libraries that use a lot of newer ES features like async/await where the transpiled code is really hard to follow.

@aleclarson
Copy link
Member

... much less of a problem than libraries that use a lot of newer ES features like async/await where the transpiled code is really hard to follow.

😆 The transpiled async/await generators kill me every time..

I'd be happy to send a PR for this if you think it'd be useful

I say go for it. 🚀

Let's get sourcesContent removed if we can, to reduce impact on tarball size.

@mweststrate
Copy link
Collaborator

@justingrant when creating a PR, could you record a screencast on how it improves things? I'm pretty curious on how these tools would pick up arbitrary source files

@aleclarson
Copy link
Member

aleclarson commented Mar 18, 2019

@mweststrate In the case of VS Code, you would open the source file by navigating (via the file tree) into node_modules/immer/src and then set a breakpoint there.

@mweststrate
Copy link
Collaborator

mweststrate commented Mar 18, 2019 via email

@aleclarson
Copy link
Member

The magic of source maps ;)

@mweststrate
Copy link
Collaborator

mweststrate commented Mar 18, 2019 via email

@aleclarson
Copy link
Member

If by "self-containing" you mean the source maps contain the source code (via the sourcesContent array), then yes. The sources array also exists, which is used to find the external source files. The proposal here is to (1) publish the external source files and (2) remove the sourcesContent array from the source maps (to avoid increased tarball size).

@aleclarson
Copy link
Member

@egoist How can we tell Bili to exclude sourcesContent from the generated source maps?

@egoist
Copy link
Contributor

egoist commented Mar 19, 2019

@aleclarson starting from bili 4.6.0 you can use --map-exclude-sources flag or set output: { sourceMapExcludeSources: true } in config file.

@justingrant
Copy link
Contributor Author

Thanks @aleclarson you beat me to it! ;-)

@aleclarson
Copy link
Member

🎉 This issue has been resolved in version 2.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

4 participants