Skip to content

Commit 211c6a7

Browse files
authored
Fix knex#5184, ensure Typescript developer experience doesn't influence user experience (knex#5185)
1 parent a4df3e3 commit 211c6a7

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

.github/workflows/integration-tests.yml

+22
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,25 @@ jobs:
9191
--file "scripts/docker-compose.yml" \
9292
down
9393
if: matrix.database-type != 'sqlite3' && matrix.database-type != 'better-sqlite3'
94+
95+
user_experience:
96+
runs-on: ${{ matrix.os }}
97+
name: Test user experience
98+
strategy:
99+
matrix:
100+
node-version: [18.x, 16.x, 14.x, 12.x]
101+
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
102+
steps:
103+
- name: Checkout Repository
104+
uses: actions/checkout@v3
105+
with: { fetch-depth: 1 }
106+
107+
- name: Setup Node ${{ matrix.node-version }}
108+
uses: actions/setup-node@v3
109+
with:
110+
always-auth: false
111+
node-version: ${{ matrix.node-version }}
112+
113+
- run: npm install
114+
- run: npm pack
115+
- run: npm install -g

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
test.sqlite3
1212
npm-debug.log
1313
tmp
14+
knex-*.tgz
1415

1516
# Testing for the knex cli:
1617
bin/migrations-folder

.husky/post-checkout

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run clean && npm run build

.husky/pre-commit

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
33

44
npx lint-staged

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ psql -h localhost -U postgres -d knex_test
171171
172172
## Typescript source files
173173
174-
> 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.
174+
> 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.
175175
176176
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.
177177
178-
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.
178+
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.
179179
180180
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.
181181

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"build": "npm run build:gitignore && npm run build:ts",
1212
"clean": "git clean -f -X lib/",
1313
"build:ts": "tsc",
14-
"build:gitignore": "./scripts/update_gitignore_for_tsc_output.js run",
14+
"build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run",
1515
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
1616
"debug:test": "mocha --inspect-brk --exit -t 0 test/all-tests-suite.js",
1717
"debug:tape": "node --inspect-brk test/tape/index.js",
@@ -56,9 +56,7 @@
5656
"stress:init": "docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
5757
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
5858
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
59-
"prepare": "husky install",
60-
"prepublishOnly": "npm run clean && npm run build",
61-
"postinstall": "npm run clean && npm run build"
59+
"prepare": "husky install && npm run clean && npm run build"
6260
},
6361
"dependencies": {
6462
"colorette": "2.0.16",
@@ -120,7 +118,7 @@
120118
"eslint-config-prettier": "^8.5.0",
121119
"eslint-plugin-import": "^2.26.0",
122120
"eslint-plugin-mocha-no-only": "^1.1.1",
123-
"husky": "^7.0.4",
121+
"husky": "^8.0.1",
124122
"jake": "^10.8.5",
125123
"JSONStream": "^1.3.5",
126124
"lint-staged": "^12.3.7",
@@ -221,7 +219,8 @@
221219
},
222220
"files": [
223221
"bin/*",
224-
"lib/*",
222+
"lib/",
223+
"lib/**/*.js",
225224
"!lib/**/*.ts",
226225
"!lib/**/*.d.ts",
227226
"!lib/**/*.js.map",

0 commit comments

Comments
 (0)