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:
Search Terms
modebinaryexecutablepackage.json binSuggestion
Currently, the TypeScript compiler always generates files with the
644mode. But some files are meant to be executable: they may start with#!/usr/bin/env node; they may be marked asbininpackage.json; they may have an executable mode set on the.tssource; 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
.jsas so.At least the TypeScript compiler doesn’t change the mode of existing
.jsfiles when overwriting them, so I canchmodonce, 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/.binfolder,npxpicks 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 runtsc, and the generated file atlib/my-binary.jsis marked as+x. Then you can call the binary withlib/my-binary.jsfrom the command-line and it works.Checklist
My suggestion meets these guidelines: