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

Shebang in .ts (TypeScript) file causes it to render with .js (JavaScript) icon #606

Closed
sompylasar opened this issue May 29, 2017 · 8 comments
Labels
enhancement Feature requests or suggested improvements.

Comments

@sompylasar
Copy link

typescript with shebang renders javascript icon

typescript without shebang renders typescript icon

@Alhadis
Copy link
Member

Alhadis commented May 29, 2017

Well... yeah, that's the expected behaviour.

Are you saying Node can directly execute TypeScript files without precompilation?

@sompylasar
Copy link
Author

No, it cannot, but the shebang string gets propagated from the TS source to the JS compiled with tsc. If I omit it in the source, it won't appear in the output JS.

@Alhadis
Copy link
Member

Alhadis commented May 29, 2017

Ahhh, I see. Do you know if TypeScript-generated Node executables are common?

If not, I'd prefer to leave it as-is, and you can use one of the following solutions to override the icon locally:

1. Use your stylesheet

.icon[data-name$=".ts"]::before{
	font-family: file-icons;
	content: "\2a6";
	color: #6a9fb5;
}

2. Disable shebang recognition

Go to: SettingsPackagesfile-iconsMatch strategies and uncheck the second option:

Figure 1

3. Add a modeline

#!/usr/local/bin/node      # -*- TypeScript -*-

This works because modelines take priority over shebangs when determining which icon to use.

I actually don't recommend the third solution, since it's essentially a hack.

@sompylasar
Copy link
Author

Match strategies looks the right way to go.

@sompylasar
Copy link
Author

Do you know if TypeScript-generated Node executables are common?

TypeScript isn't yet common, so no, they aren't yet.

@Alhadis
Copy link
Member

Alhadis commented May 29, 2017

I see. Well, thanks for bringing this up. The package currently lacks heuristic support for icon-assignment (e.g., exceptions to the usual matching methods), but it may be worth adding in future. I'm sure there are other precompiled languages which work the same way as what you've described.

BTW, the hashbang will also affect the file's language classification on GitHub. You can actually fix it both here and in Atom by adding a .gitattributes file to your project:

integration-test.ts linguist-language=TypeScript

I actually recommend this instead, which I forgot about while writing out all that crap above...

@Alhadis Alhadis closed this as completed May 29, 2017
Alhadis added a commit that referenced this issue May 29, 2017
* TypeScript executables no longer display a JavaScript icon (#606)
* `tsc` and `ts-node` are now recognised as TypeScript interpreters
@Alhadis
Copy link
Member

Alhadis commented May 29, 2017

@sompylasar I've made a unique exception for TypeScript files. This isn't something we normally do, but I've been unable to push this issue out of my head. Specifically, how ridiculous the workarounds are, and how common this scenario might become in future.

I should add that the reason I"m being conservative with icon-matching logic is because the routines responsible for mapping icons potentially run many thousands of times at once... the code needs to be as performant as possible. Hence why I've implemented this as an ad-hoc rule, instead of revising the config structure to accommodate precompilers.

@Alhadis Alhadis added the enhancement Feature requests or suggested improvements. label May 29, 2017
@sompylasar
Copy link
Author

@Alhadis Wow! Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests or suggested improvements.
Projects
None yet
Development

No branches or pull requests

2 participants