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.

Preserve executable file permission when generating from executable .ts file

See original GitHub issue

As many libraries ship executable files to help with testing or administration it is convenient to be able to keep the executable permission on UNIX like systems while generating .js files from .ts files. The creator of the library can provide a build script or manually keep the proper permissions in distributed generated library but this is sub-optimal

TypeScript Version: 2.9.2 Search Terms: file permissions executable

Expected behavior:

$ ll lib/jem_cli.ts 
-rwxr-xr-x 1 omg omg 5.9K 30 Jul 12,58 lib/jem_cli.ts
$ tsc 
TSFILE: ..../jem_cli.js
$ ll jem_cli.js 
-rwxr-xr-x 1 omg omg 8.2K 30 Jul 13,23 jem_cli.js

Actual behavior:

$ ll lib/jem_cli.ts 
-rwxr-xr-x 1 omg omg 5.9K 30 Jul 12,58 lib/jem_cli.ts
$ tsc 
TSFILE: ..../jem_cli.js
$ ll jem_cli.js 
-rw-r--r-- 1 omg omg 8.2K 30 Jul 13,23 jem_cli.js

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:12
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jcollumcommented, Oct 8, 2021

I agree with @sdrsdr: changing the flags on emitted files is a violation of POLA: I would not expect the flags to be changed after compilation.

This is what I get after running tsc and sending output to dist folder:

$ ll src
total 4
-rw-r--r--  1 justin.collum  NWEA\Domain Users   2.1K Oct  8 11:13 index.ts
$ ll dist
total 11552
-rw-------   1 justin.collum  NWEA\Domain Users   3.5K Oct  8 11:13 index.js
drwxr-xr-x  32 justin.collum  NWEA\Domain Users   1.0K Oct  8 11:13 node_modules/

Definitely not what I expected. tsc seems to be emitting a file with the least amount of permissions. I’m uploading this file to Lambda and the Lambda executor can’t access the code:

"EACCES: permission denied, open '/var/task/index.js'",

I can workaround this. However it is a violation of POLA in my opinion.

0reactions
sdrsdrcommented, Aug 6, 2018

This is a bit more complicated: A single compilation host is used for complete compilation task. You can track all source and output files, but there is no one to one relation. You can make a map out of input files and their permissions and match in it the output filenames and act accordingly. This might lead to some performance degradation in huge projects, so I was thinking about adding an compiler option to enable this behavior and keeping it off by default. Also to keep the map small I’m thinking about “remembering” only the executable input files. This will bring the lookup time to almost zero, yet you have to lookup file permissions for every input file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preserve executable file permission when generating ... - GitHub
As many libraries ship executable files to help with testing or administration it is convenient to be able to keep the executable permission...
Read more >
node.js - TypeScripts transpiles files which are non-executable
Changing file's permissions isn't typescript responsibility. Solution 1. Use a separate step in the build process in your package.json.
Read more >
Deno nuggets: Run TypeScript file as executable script
Learn how to run TypeScript file as an executable script. ... First, change the permissions by adding execute permissions: $ chmod 744 app....
Read more >
Getting Started with Executing TypeScript files in ts-node
1. Create a script called hello.ts, and populate the hello. · 2. Next, run the below command to make the script executable (...
Read more >
How to manage/preserve file privileges during an online file ...
Is there a way (there is, the man of the link is able to do it) to send a bash script with executable...
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