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(cli): Don't strip shebangs from modules #13220

Merged
merged 6 commits into from
Jan 16, 2022

Conversation

andreubotella
Copy link
Contributor

Deno's module loader currently strips a shebang if a module file starts with one. However, this is no longer necessary, since there is a stage-3 TC39 that adds support for shebangs (or "hashbangs") to the language, and V8, tsc and swc all support it.

Furthermore, stripping shebangs causes a correctness bug with JSON modules, since a JSON file with a shebang should not parse as a JSON module, yet it does with this stripping. This change fixes this.

Closes #13129.

Deno's module loader currently strips a shebang if a module file
starts with one. However, this is no longer necessary, since there is
a stage-3 TC39 that adds support for shebangs (or "hashbangs") to the
language (https://github.com/tc39/proposal-hashbang), and V8, `tsc`
and `swc` all support it.

Furthermore, stripping shebangs causes a correctness bug with JSON
modules, since a JSON file with a shebang should not parse as a JSON
module, yet it does with this stripping. This change fixes this.

Closes denoland#13129.
@andreubotella
Copy link
Contributor Author

For the record: this change affects the output of Deno.emit() in that shebangs will be kept in the output modules if the bundle option is not set. This can already happen if a module file has a BOM and a shebang, since the shebang is stripped before the BOM, but this extends it to every case.

@bartlomieju
Copy link
Member

I think this change is desirable, but it will most likely break cached sources once released. We need to be extra careful not to repeat situation in 1.16 when users had to use --reload to get rid if esoteric errors.

@kitsonk WDYT?

@bartlomieju bartlomieju requested a review from kitsonk December 29, 2021 13:29
@andreubotella
Copy link
Contributor Author

I'm not too sure how the cache works, but it seems like the worst case scenario would be errors being off by one line, right?

@bartlomieju
Copy link
Member

I'm not too sure how the cache works, but it seems like the worst case scenario would be errors being off by one line, right?

Not necessarily, I think in the CDP inspector a file might not load at all if source map is broken.

@bartlomieju
Copy link
Member

@kitsonk do you have any objections to landing this PR?

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's land it and keep an eye out on any failures in canary.

@bartlomieju bartlomieju merged commit 9def449 into denoland:main Jan 16, 2022
@andreubotella andreubotella deleted the no-need-to-strip-shebang branch January 16, 2022 15:49
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.

It's no longer necessary to strip shebangs from modules
2 participants