Skip to content

Commit 4cedcde

Browse files
committed
Setup test/lint
1 parent 6d430ed commit 4cedcde

15 files changed

+7077
-0
lines changed

.eslintrc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
ecmaVersion: 2018,
5+
sourceType: 'module',
6+
},
7+
ignorePatterns: [
8+
// break
9+
'index.cjs',
10+
'**/node_modules/**',
11+
'**/dist/**',
12+
'**/generated/**',
13+
],
14+
plugins: [
15+
// break
16+
'prettier',
17+
'codegen',
18+
],
19+
rules: {
20+
'prettier/prettier': ['warn', require('./.prettierrc')],
21+
'codegen/codegen': 'error',
22+
},
23+
}

.github/workflows/main.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
on:
3+
push: {}
4+
pull_request: {}
5+
6+
jobs:
7+
run:
8+
if: github.event_name == 'push' || github.event.pull_request.base.repo.url != github.event.pull_request.head.repo.url
9+
runs-on: ubuntu-latest
10+
services:
11+
postgres:
12+
image: clkao/postgres-plv8:12-2
13+
env:
14+
POSTGRES_USER: postgres
15+
POSTGRES_PASSWORD: postgres
16+
POSTGRES_DB: postgres
17+
options: >-
18+
--health-cmd pg_isready
19+
--health-interval 10s
20+
--health-timeout 5s
21+
--health-retries 5
22+
ports:
23+
- 5434:5432
24+
steps:
25+
- uses: actions/checkout@v2
26+
- run: yarn
27+
- run: yarn ci

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*/*
2+
.*
3+
!.*rc.js
4+
!.*ignore
5+
!.git*
6+
!.github/**
7+
!src/**
8+
!test/**
9+
!scripts/**
10+
!patches/**

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*/*
2+
!dist
3+
!src
4+
!webpack.config.js
5+
!queries

.prettierrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
singleQuote: true,
3+
semi: false,
4+
arrowParens: 'avoid',
5+
tabWidth: 2,
6+
trailingComma: 'all',
7+
bracketSpacing: false,
8+
endOfLine: 'auto',
9+
printWidth: 120,
10+
}

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3'
2+
services:
3+
postgres:
4+
image: clkao/postgres-plv8:12-2
5+
restart: always
6+
ports:
7+
- "5434:5432"
8+
environment:
9+
POSTGRES_USER: postgres
10+
POSTGRES_PASSWORD: postgres
11+
POSTGRES_DB: postgres
12+
volumes:
13+
- postgres:/var/lib/postgresql/data
14+
volumes:
15+
postgres:

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type GitRepo = Record<string, number[]>;
2+
3+
export const gitLog: (repo: GitRepo, depth?: number) => 1

jest.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
globals: {
4+
'ts-jest': {
5+
diagnostics: false,
6+
},
7+
},
8+
collectCoverageFrom: ['**/*.ts', '!**/*.d.ts'],
9+
}

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "plv8-git",
3+
"version": "0.0.1",
4+
"description": "",
5+
"license": "ISC",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"scripts": {
9+
"build": "yarn webpack && yarn generate",
10+
"ci": "yarn lint && yarn test",
11+
"generate": "scripts/generate-queries",
12+
"lint": "eslint .",
13+
"prepare": "patch-package",
14+
"test": "jest",
15+
"webpack": "webpack"
16+
},
17+
"devDependencies": {
18+
"@babel/core": "7.12.3",
19+
"@typescript-eslint/parser": "4.5.0",
20+
"babel-loader": "8.0.6",
21+
"babel-plugin-transform-async-to-promises": "0.8.15",
22+
"eslint": "7.11.0",
23+
"eslint-plugin-codegen": "0.13.3",
24+
"eslint-plugin-prettier": "3.1.4",
25+
"isomorphic-git": "1.7.8",
26+
"jest": "26.6.0",
27+
"memfs": "3.2.0",
28+
"patch-package": "6.2.2",
29+
"prettier": "2.1.2",
30+
"slonik": "23.0.1",
31+
"ts-jest": "26.4.1",
32+
"ts-loader": "8.0.6",
33+
"typescript": "4.0.3",
34+
"webpack": "4.44.2",
35+
"webpack-cli": "3.3.12"
36+
}
37+
}

patches/isomorphic-git+1.7.8.patch

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
diff --git a/node_modules/isomorphic-git/index.cjs b/node_modules/isomorphic-git/index.cjs
2+
index ae4d526..9d9b046 100644
3+
--- a/node_modules/isomorphic-git/index.cjs
4+
+++ b/node_modules/isomorphic-git/index.cjs
5+
@@ -2935,38 +2935,66 @@ async function _readObject({
6+
return result
7+
}
8+
9+
- // BEHOLD! THE ONLY TIME I'VE EVER WANTED TO USE A CASE STATEMENT WITH FOLLOWTHROUGH!
10+
- // eslint-ignore
11+
- /* eslint-disable no-fallthrough */
12+
- switch (result.format) {
13+
- case 'deflated': {
14+
- result.object = Buffer.from(await inflate(result.object));
15+
- result.format = 'wrapped';
16+
- }
17+
- case 'wrapped': {
18+
- if (format === 'wrapped' && result.format === 'wrapped') {
19+
- return result
20+
- }
21+
- const sha = await shasum(result.object);
22+
- if (sha !== oid) {
23+
- throw new InternalError(
24+
- `SHA check failed! Expected ${oid}, computed ${sha}`
25+
- )
26+
- }
27+
- const { object, type } = GitObject.unwrap(result.object);
28+
- result.type = type;
29+
- result.object = object;
30+
- result.format = 'content';
31+
- }
32+
- case 'content': {
33+
- if (format === 'content') return result
34+
- break
35+
+ // // BEHOLD! THE ONLY TIME I'VE EVER WANTED TO USE A CASE STATEMENT WITH FOLLOWTHROUGH!
36+
+ // // eslint-ignore
37+
+ // /* eslint-disable no-fallthrough */
38+
+ // switch (result.format) {
39+
+ // case 'deflated': {
40+
+ // result.object = Buffer.from(await inflate(result.object));
41+
+ // result.format = 'wrapped';
42+
+ // }
43+
+ // case 'wrapped': {
44+
+ // if (format === 'wrapped' && result.format === 'wrapped') {
45+
+ // return result
46+
+ // }
47+
+ // const sha = await shasum(result.object);
48+
+ // if (sha !== oid) {
49+
+ // throw new InternalError(
50+
+ // `SHA check failed! Expected ${oid}, computed ${sha}`
51+
+ // )
52+
+ // }
53+
+ // const { object, type } = GitObject.unwrap(result.object);
54+
+ // result.type = type;
55+
+ // result.object = object;
56+
+ // result.format = 'content';
57+
+ // }
58+
+ // case 'content': {
59+
+ // if (format === 'content') return result
60+
+ // break
61+
+ // }
62+
+ // default: {
63+
+ // throw new InternalError(`invalid format "${result.format}"`)
64+
+ // }
65+
+ // }
66+
+ // /* eslint-enable no-fallthrough */
67+
+
68+
+ /* manually patching https://github.com/isomorphic-git/isomorphic-git/pull/1247 */
69+
+ /* note: this is commonjs export of this package, usually ignored in favour of index.js */
70+
+ if (result.format === 'deflated') {
71+
+ result.object = Buffer.from(await inflate(result.object))
72+
+ result.format = 'wrapped'
73+
+ }
74+
+
75+
+ if (result.format === 'wrapped') {
76+
+ if (format === 'wrapped' && result.format === 'wrapped') {
77+
+ return result
78+
}
79+
- default: {
80+
- throw new InternalError(`invalid format "${result.format}"`)
81+
+ const sha = await shasum(result.object)
82+
+ if (sha !== oid) {
83+
+ throw new InternalError(
84+
+ `SHA check failed! Expected ${oid}, computed ${sha}`
85+
+ )
86+
}
87+
+ const { object, type } = GitObject.unwrap(result.object)
88+
+ result.type = type
89+
+ result.object = object
90+
+ result.format = 'content'
91+
+ }
92+
+
93+
+ if (result.format === 'content') {
94+
+ if (format === 'content') return result
95+
+ return
96+
}
97+
- /* eslint-enable no-fallthrough */
98+
}
99+
100+
class AlreadyExistsError extends BaseError {
101+
@@ -10337,7 +10365,8 @@ async function _log({ fs, cache, gitdir, ref, depth, since }) {
102+
const oid = await GitRefManager.resolve({ fs, gitdir, ref });
103+
const tips = [await _readCommit({ fs, cache, gitdir, oid })];
104+
105+
- while (true) {
106+
+ // https://github.com/isomorphic-git/isomorphic-git/pull/1248
107+
+ while (tips.length > 0) {
108+
const commit = tips.pop();
109+
110+
// Stop the log if we've hit the age limit
111+
diff --git a/node_modules/isomorphic-git/index.js b/node_modules/isomorphic-git/index.js
112+
index 8335d52..6a6ebd4 100644
113+
--- a/node_modules/isomorphic-git/index.js
114+
+++ b/node_modules/isomorphic-git/index.js
115+
@@ -2929,38 +2929,66 @@ async function _readObject({
116+
return result
117+
}
118+
119+
- // BEHOLD! THE ONLY TIME I'VE EVER WANTED TO USE A CASE STATEMENT WITH FOLLOWTHROUGH!
120+
- // eslint-ignore
121+
- /* eslint-disable no-fallthrough */
122+
- switch (result.format) {
123+
- case 'deflated': {
124+
- result.object = Buffer.from(await inflate(result.object));
125+
- result.format = 'wrapped';
126+
- }
127+
- case 'wrapped': {
128+
- if (format === 'wrapped' && result.format === 'wrapped') {
129+
- return result
130+
- }
131+
- const sha = await shasum(result.object);
132+
- if (sha !== oid) {
133+
- throw new InternalError(
134+
- `SHA check failed! Expected ${oid}, computed ${sha}`
135+
- )
136+
- }
137+
- const { object, type } = GitObject.unwrap(result.object);
138+
- result.type = type;
139+
- result.object = object;
140+
- result.format = 'content';
141+
- }
142+
- case 'content': {
143+
- if (format === 'content') return result
144+
- break
145+
+ // // BEHOLD! THE ONLY TIME I'VE EVER WANTED TO USE A CASE STATEMENT WITH FOLLOWTHROUGH!
146+
+ // // eslint-ignore
147+
+ // /* eslint-disable no-fallthrough */
148+
+ // switch (result.format) {
149+
+ // case 'deflated': {
150+
+ // result.object = Buffer.from(await inflate(result.object));
151+
+ // result.format = 'wrapped';
152+
+ // }
153+
+ // case 'wrapped': {
154+
+ // if (format === 'wrapped' && result.format === 'wrapped') {
155+
+ // return result
156+
+ // }
157+
+ // const sha = await shasum(result.object);
158+
+ // if (sha !== oid) {
159+
+ // throw new InternalError(
160+
+ // `SHA check failed! Expected ${oid}, computed ${sha}`
161+
+ // )
162+
+ // }
163+
+ // const { object, type } = GitObject.unwrap(result.object);
164+
+ // result.type = type;
165+
+ // result.object = object;
166+
+ // result.format = 'content';
167+
+ // }
168+
+ // case 'content': {
169+
+ // if (format === 'content') return result
170+
+ // break
171+
+ // }
172+
+ // default: {
173+
+ // throw new InternalError(`invalid format "${result.format}"`)
174+
+ // }
175+
+ // }
176+
+ // /* eslint-enable no-fallthrough */
177+
+
178+
+ /* manually patching https://github.com/isomorphic-git/isomorphic-git/pull/1247 */
179+
+ /* note: this is es module export of this package, usually used instead of index.cjs */
180+
+ if (result.format === 'deflated') {
181+
+ result.object = Buffer.from(await inflate(result.object))
182+
+ result.format = 'wrapped'
183+
+ }
184+
+
185+
+ if (result.format === 'wrapped') {
186+
+ if (format === 'wrapped' && result.format === 'wrapped') {
187+
+ return result
188+
}
189+
- default: {
190+
- throw new InternalError(`invalid format "${result.format}"`)
191+
+ const sha = await shasum(result.object)
192+
+ if (sha !== oid) {
193+
+ throw new InternalError(
194+
+ `SHA check failed! Expected ${oid}, computed ${sha}`
195+
+ )
196+
}
197+
+ const { object, type } = GitObject.unwrap(result.object)
198+
+ result.type = type
199+
+ result.object = object
200+
+ result.format = 'content'
201+
+ }
202+
+
203+
+ if (result.format === 'content') {
204+
+ if (format === 'content') return result
205+
+ return
206+
}
207+
- /* eslint-enable no-fallthrough */
208+
}
209+
210+
class AlreadyExistsError extends BaseError {
211+
@@ -10331,7 +10359,8 @@ async function _log({ fs, cache, gitdir, ref, depth, since }) {
212+
const oid = await GitRefManager.resolve({ fs, gitdir, ref });
213+
const tips = [await _readCommit({ fs, cache, gitdir, oid })];
214+
215+
- while (true) {
216+
+ // https://github.com/isomorphic-git/isomorphic-git/pull/1248
217+
+ while (tips.length > 0) {
218+
const commit = tips.pop();
219+
220+
// Stop the log if we've hit the age limit

0 commit comments

Comments
 (0)