question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set as executable files that are intended to be binaries

See original GitHub issue

Search Terms

  • mode
  • binary
  • executable
  • package.json bin

Suggestion

Currently, the TypeScript compiler always generates files with the 644 mode. But some files are meant to be executable: they may start with #!/usr/bin/env node; they may be marked as bin in package.json; they may have an executable mode set on the .ts source; and so forth.

It’d be great if the TypeScript compiler would take any of the hints I mentioned above, figure that the file should be executable, and create the .js as so.

At least the TypeScript compiler doesn’t change the mode of existing .js files when overwriting them, so I can chmod once, and as long as never delete the file, it’ll have the right mode.

Use Cases

This is mostly for development and running the binary from the command-line directly. Once you install the package, npm puts the binary in the node_modules/.bin folder, npx picks it up, and all is good.

Examples

You’re working on a project that should provide a binary: src/my-binary.ts. You do one of the things I mentioned to indicate that the file should be executable. You run tsc, and the generated file at lib/my-binary.js is marked as +x. Then you can call the binary with lib/my-binary.js from the command-line and it works.

Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
leafaccommented, Mar 25, 2020

Some reasons for you to ponder:

  1. Convention over configuration. It’s more ergonomic to have the TypeScript compiler produce files with the appropriate executable mode by default than to configure some other part of a larger build system do the job.
  2. Some folks, like me, aren’t using larger build systems. We just call tsc and that’s it.
  3. The change I’m proposing shouldn’t break anything for anyone.
1reaction
gustavohenkecommented, Dec 31, 2021

Explicitly +1ing as this hasn’t seen much action for a couple of months.

I agree with @leafac, tsc is the one build tool that I need. I can have a postbuild script do chmod +x on the compiled file, but it wouldn’t work with --watch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Executable Binary File - an overview | ScienceDirect Topics
A host program's executable binary file is divided up into segments. One segment holds the instructions the program will run, another holds space...
Read more >
What is a binary file and how does it work? - TechTarget
A binary file is a file whose content is in a binary format consisting of a series of sequential bytes, each of which...
Read more >
Are executables (EXE format) binary? If yes, why can't ... - Quora
The simplest answer is: EXE files don't run on other operating systems because it's a Windows-specific format for executable files. As background info,...
Read more >
Converting Code into Binary Executable Files is a Common ...
IDEs are one of several types of tools that allow to run and convert code to binary files, making them ready to run...
Read more >
Why do people call an executable file (.exe) a binary file?
A binary file can contain executable code or data - the data is just not readable in an text editor, in other words...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found