Skip to content

Commit

Permalink
Fix #5184, ensure Typescript developer experience doesn't influence u…
Browse files Browse the repository at this point in the history
…ser experience (#5185)
  • Loading branch information
code-ape committed May 17, 2022
1 parent a4df3e3 commit 211c6a7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,25 @@ jobs:
--file "scripts/docker-compose.yml" \
down
if: matrix.database-type != 'sqlite3' && matrix.database-type != 'better-sqlite3'

user_experience:
runs-on: ${{ matrix.os }}
name: Test user experience
strategy:
matrix:
node-version: [18.x, 16.x, 14.x, 12.x]
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with: { fetch-depth: 1 }

- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
always-auth: false
node-version: ${{ matrix.node-version }}

- run: npm install
- run: npm pack
- run: npm install -g
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
test.sqlite3
npm-debug.log
tmp
knex-*.tgz

# Testing for the knex cli:
bin/migrations-folder
Expand Down
4 changes: 4 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run clean && npm run build
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 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.
> 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` or checkout a new Git branch 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` 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.
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 script command `"prepare"` whenever you run `npm install` and Git hook for `post-checkout` (added by Husky) which executes when you run commands like `git checkout` , 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.
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"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",
"build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run",
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
"debug:test": "mocha --inspect-brk --exit -t 0 test/all-tests-suite.js",
"debug:tape": "node --inspect-brk test/tape/index.js",
Expand Down Expand Up @@ -56,9 +56,7 @@
"stress:init": "docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
"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 clean && npm run build",
"postinstall": "npm run clean && npm run build"
"prepare": "husky install && npm run clean && npm run build"
},
"dependencies": {
"colorette": "2.0.16",
Expand Down Expand Up @@ -120,7 +118,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-mocha-no-only": "^1.1.1",
"husky": "^7.0.4",
"husky": "^8.0.1",
"jake": "^10.8.5",
"JSONStream": "^1.3.5",
"lint-staged": "^12.3.7",
Expand Down Expand Up @@ -221,7 +219,8 @@
},
"files": [
"bin/*",
"lib/*",
"lib/",
"lib/**/*.js",
"!lib/**/*.ts",
"!lib/**/*.d.ts",
"!lib/**/*.js.map",
Expand Down

0 comments on commit 211c6a7

Please sign in to comment.