Improving Typescript developer experience (#5151)

This commit is contained in:
Ferris 2022-05-06 04:36:23 -04:00 committed by GitHub
parent 2670c2f8b5
commit 3eec52ea25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -171,11 +171,11 @@ psql -h localhost -U postgres -d knex_test
## Typescript source files
> TL;DR: Starting with release 2.0.0 Knex is adding support for Typescript source files. Thus to develop in this repo you will need to run `npm run build` to generate the resulting `.js` files, even when developing in Javascript. It is encouraged that new functionality and sources be written in Typescript but this is not required.
> TL;DR: Starting with release 2.0.0 Knex is adding support for Typescript source files. Thus to develop in this repo you will need to run `npm run build` each time you edit `.ts` files to generate the resulting `.js` files. This is automatically run whenever you run `npm install` so when developing in Javascript you don't have to worry about it. It is encouraged that new functionality and sources be written in Typescript but this is not required.
Starting with release 2.0.0, Knex is support source additions in Typescript! This allows for better safety in the code added. However, pre-2.0.0 Knex was always written in pure Javascript and thus a "hybrid" approach is being used for 2.0.0 to allow for the new `.ts` files to exist along `.js` files that make up the majority of this repository.
To develop in this repository use the `npm run build` command. If you wish to have the `tsc` compiled watch and recompile on changes then run `npm run build:ts -- --watch`. Note that for easy integration with Javascript the outputted files are done in a "side-by-side" manner meaning that `lib/foo/bar.ts` will result in `lib/foo/bar.js`.
To develop in this repository use the `npm run build` and `npm run clean` commands to compile and delete the `.js` and related files from `.ts` files. If you wish to have the `tsc` compiled watch and recompile on changes then run `npm run build:ts -- --watch`. Note that for easy integration with Javascript the outputted files are done in a "side-by-side" manner meaning that `lib/foo/bar.ts` will result in `lib/foo/bar.js`. This is done automatically via the npm `postinstall` script trigger which executes when you run commands like `npm install` or `npm ci`, thus making it easier to not have to worry about this if you're working in pure Javascript.
The script file `./scripts/update_gitignore_for_tsc_output.js` file is called as part of the `npm run build` command which will update the `lib/.gitignore` file which is used to ensure generated `.js` and related files from `tsc` compilation are not checked into the git repo.

View File

@ -9,6 +9,7 @@
},
"scripts": {
"build": "npm run build:gitignore && npm run build:ts",
"clean": "git clean -f -X lib/",
"build:ts": "tsc",
"build:gitignore": "./scripts/update_gitignore_for_tsc_output.js run",
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
@ -56,7 +57,8 @@
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
"prepare": "husky install",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run clean && npm run build",
"postinstall": "npm run clean && npm run build"
},
"dependencies": {
"colorette": "2.0.16",