Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should compiled JavaScript files be committed to Git repo? [closed]

New to TypeScript here and just wondering what the community views as best practice.

When I compile for production, I use the webpack loader. However, when I run my tests, I need to run tsc && ava. This generates a .js equivalent file in the same location as their .ts counterparts. Should these by committed to the repo alongside the .ts files? My first assumption is no because they should be re-compiled each time before a process e.g. starting your server or executing tests is run. However, I'd just like to get the community's opinion on this.

like image 789
Clement Avatar asked Jun 11 '18 11:06

Clement


People also ask

Should I commit compiled typescript?

There's a caveat, if you are building a npm package with typescript and using git to host a private npm registry you will definitely want to commit the compiled . js files and their type definitions.

What files should not be stored in git?

You shouldn't store credentials like usernames, passwords, API keys and API secrets. If someone else steals your credentials, they can do nasty things with it.


1 Answers

Your assumption is absolutely correct - build artefacts and outputs shouldn't be added to your repository. The main reason for this is that it's easy to end up in a situation where the source .ts file has changed but the compiled .js file differs because it's not been committed at the same time.

You also add complexity to your pull-requests/merge reviews, as there will be a large amount of generated code that isn't really part of the review but is in the changeset.

Finally, merging changes becomes a bit of a pain, because you need to recompile the .js files for every merge you do.

If you only use .ts files in your source directory, you can add /**/*.js to your .gitignore to prevent files from being added accidentally.

like image 178
spikeheap Avatar answered Nov 02 '22 18:11

spikeheap