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

CLI: Generate source map when running file directly too #3187

Closed
aseemk opened this issue Sep 29, 2013 · 14 comments
Closed

CLI: Generate source map when running file directly too #3187

aseemk opened this issue Sep 29, 2013 · 14 comments

Comments

@aseemk
Copy link
Contributor

aseemk commented Sep 29, 2013

Really terrific work on source maps so far. I'm finally trying it out for the first time, and it's so cool! =)

I tend to run CoffeeScript mostly on the server-side / with Node.js, rather than in the browser. There exists the equally awesome node-inspector for debugging server-side code, and StrongLoop recently added source maps support to it as well.

However, I tend to run server-side CoffeeScript with the coffee binary directly, rather than compiling it to JS first, and unfortunately CoffeeScript doesn't support outputting a source map file when running code directly right now.

Is this something y'all would be open to supporting? Example use case:

coffee --map --nodejs --debug app.coffee

Thanks for the consideration!

Implementation notes:

Running a file directly means ultimately compiling it on the fly via a require() hook.

CoffeeScript 1.6.3 does/did at least generate a source map on such on-the-fly compiles:

https://github.com/jashkenas/coffee-script/blob/1.6.3/src/coffee-script.coffee#L145-L157

It just didn't output it anywhere.

However, that source map generation was removed after 1.6.3:

3d761e7

So perhaps the best solution would be to keep the latest behavior by default, but support generating and outputting the map if a --map argument was given.

This would, however, necessitate a change in the CLI, which currently only runs the given file if no options are given.

@doublerebel
Copy link

As mentioned in #3166 I too support more command line options for source map compilation (i.e. base64 embedding) , because the CLI compilation sequence is complicated to replicate outside of the Coffee libs. Also, #2882 is a similar request to adjust the map path.

@jashkenas
Copy link
Owner

I don't think that the Coffee binary should be spitting out source maps to disk while executing your file ... but we should try to get the best source map support possible in Node.

Ideally, as that currently means evaluating the compiled JavaScript in-memory (we don't write out temporary JS files to disk either) ... we'd also be able to pass the corresponding source map to Node, alongside the eval. Anyone have any bright ideas?

@startswithaj
Copy link

The current version of cs on NPM (tagged 1.6.3) currently generates source maps by default.

https://github.com/jashkenas/coffee-script/blob/1.6.3/src/coffee-script.coffee#L87

It's been removed in master, is NPM due for an update? Is there another stable release on it's way?

Apologies for the thread highjacking, I didn't want to make another non-issue--issue.

@xixixao
Copy link
Contributor

xixixao commented Dec 9, 2013

@startswithaj http://coffeescript.org/ 1.6.3 is latest, 1.6.4 is coming

https://npmjs.org/package/source-map-support
For example, Meteor keeps all source maps cached in memory to avoid disk access.

So this should be possible?!

@aseemk
Copy link
Contributor Author

aseemk commented Dec 13, 2013

If source maps can indeed be in memory, that'd be killer.

If not, @jashkenas, what would you say to the idea of outputting them into a system temp directory?

@jashkenas
Copy link
Owner

In memory would be much, much preferred. Cross-platform tempfiles are no fun, because Windows.

@technicalpickles
Copy link

Would absolutely 💖 this. I'm working on adding support to hubot for debugging scripts, and currently we only get the compiled javascript. It's better than nothing of course, but would be a game changer for hubot development.

@benjie
Copy link

benjie commented Mar 6, 2014

I've just hacked something together to scratch my itch, I'd also love to see this supported out of the box.

@aseemk
Copy link
Contributor Author

aseemk commented Mar 7, 2014

Nice, @benjie! Thanks. =)

@aseemk
Copy link
Contributor Author

aseemk commented Mar 7, 2014

@benjie: Do you know if this helps with debugging also? E.g. with node-inspector. Perhaps that's a question for the source-map-support module? (cc @evanw)

@benjie
Copy link

benjie commented Mar 7, 2014

@aseemk I haven't tried. Would be awesome if it did though - it would make sense for source-map-support to handle this as you say.

@tonka3000
Copy link

In memory source maps would be cool feature +1

@ben-x9
Copy link

ben-x9 commented Jan 28, 2015

If coffee --map --nodejs --debug app.coffee were to append source maps to the javascript output in base64 then we could see the coffeescript in node inspector.

See: node-inspector/node-inspector#224 (comment)

@GeoffreyBooth GeoffreyBooth changed the title Generate source map when running file directly too CLI: Generate source map when running file directly too May 6, 2017
@GeoffreyBooth
Copy link
Collaborator

This is possible now, via --inline-map.

node --inspect-brk ./bin/coffee --inline-map test.coffee

image

If this is somehow insufficient please comment and I’ll reopen.

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

10 participants