Skip to content

Commit 3a14a32

Browse files
authored
chore: bump packages (#20)
* chore: bump packages * fix: mismatched supabase versions * ci: combine workflows
1 parent a7ebeb9 commit 3a14a32

File tree

18 files changed

+3004
-1059
lines changed

18 files changed

+3004
-1059
lines changed

.config/.commitlintrc

-3
This file was deleted.

.config/husky/commit-msg

-4
This file was deleted.

.config/husky/pre-commit

-4
This file was deleted.

.eslintrc

+14-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"allowImportExportEverywhere": true
1212
},
13-
"plugins": ["@typescript-eslint", "import", "testing-library"],
13+
"plugins": ["@typescript-eslint", "import", "react", "testing-library"],
1414
"extends": [
1515
"eslint:recommended",
1616
"plugin:@typescript-eslint/recommended",
@@ -55,7 +55,19 @@
5555
],
5656
// `eslint-plugin-react`
5757
// https://github.com/yannickcr/eslint-plugin-react
58-
"react/prop-types": "off"
58+
"react/display-name": "off",
59+
"react/jsx-boolean-value": ["warn", "never"],
60+
"react/jsx-sort-props": [
61+
"error",
62+
{
63+
"callbacksLast": true
64+
}
65+
],
66+
"react/jsx-wrap-multilines": "error",
67+
"react/no-array-index-key": "error",
68+
"react/no-multi-comp": "off",
69+
"react/prop-types": "off",
70+
"react/self-closing-comp": "warn"
5971
},
6072
"settings": {
6173
"import/parsers": {

.github/workflows/lint.yaml renamed to .github/workflows/main.yaml

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint
1+
name: Main
22

33
on:
44
pull_request:
@@ -13,7 +13,7 @@ jobs:
1313
matrix:
1414
node-version: [14]
1515
steps:
16-
- name: Checkout
16+
- name: Check out
1717
uses: actions/checkout@v2
1818

1919
- name: Set up Node ${{ matrix.node-version }}
@@ -41,3 +41,33 @@ jobs:
4141

4242
- name: Format other files
4343
run: yarn lint:format --check
44+
45+
test:
46+
name: Test
47+
runs-on: ubuntu-latest
48+
strategy:
49+
matrix:
50+
node-version: [14]
51+
steps:
52+
- name: Check out
53+
uses: actions/checkout@v2
54+
55+
- name: Set up Node ${{ matrix.node-version }}
56+
uses: actions/setup-node@v2
57+
with:
58+
node-version: ${{ matrix.node-version }}
59+
60+
- name: Load yarn cache
61+
uses: actions/[email protected]
62+
id: yarn-cache
63+
with:
64+
path: ./node_modules
65+
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('**/yarn.lock') }}
66+
restore-keys: ${{ runner.os }}-yarn-cache-
67+
68+
- name: Install dependencies
69+
if: steps.yarn-cache.outputs.cache-hit != 'true'
70+
run: yarn --frozen-lockfile
71+
72+
- name: Run tests
73+
run: yarn test

.github/workflows/size.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Size
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
size:
8+
name: Size
9+
runs-on: ubuntu-latest
10+
env:
11+
CI_JOB_NUMBER: 1
12+
steps:
13+
- name: Check out
14+
uses: actions/checkout@v2
15+
16+
- uses: andresz1/[email protected]
17+
with:
18+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yaml

-37
This file was deleted.
File renamed without changes.

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint-staged
File renamed without changes.

.size-limit.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"path": "dist/index.cjs.js",
4+
"limit": "5 KB"
5+
},
6+
{
7+
"path": "dist/index.es.js",
8+
"limit": "5 KB"
9+
}
10+
]

docs/pages/documentation/data/use-select.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ import { useFilter, useSelect } from 'react-supabase'
6666

6767
function Page() {
6868
const [username, setUsername] = useState(null)
69-
const filter = useFilter((query) => query.eq('username', username), [
70-
username,
71-
])
69+
const filter = useFilter(
70+
(query) => query.eq('username', username),
71+
[username],
72+
)
7273
const [result, reexecute] = useSelect('users', {
7374
filter,
7475
pause: !username,
+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
module.exports = {
1+
import type { Config } from '@jest/types'
2+
3+
const config: Config.InitialOptions = {
24
preset: 'ts-jest',
35
testRegex: '.*\\.test\\.(ts|tsx)$',
46
watchPlugins: [
57
'jest-watch-typeahead/filename',
68
'jest-watch-typeahead/testname',
79
],
810
}
11+
12+
export default config

package.json

+15-9
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55
"main": "./dist/index.cjs.js",
66
"module": "./dist/index.es.js",
77
"types": "./dist/types/index.d.ts",
8+
"exports": {
9+
"import": "./dist/index.es.js",
10+
"require": "./dist/index.cjs.js"
11+
},
12+
"sideEffects": false,
813
"files": [
914
"dist/**"
1015
],
1116
"repository": "tmm/react-supabase",
1217
"homepage": "https://react-supabase.vercel.app",
1318
"license": "MIT",
1419
"scripts": {
15-
"build": "vite build && tsc --emitDeclarationOnly",
16-
"build:watch": "concurrently \"vite build --watch\" \"tsc --emitDeclarationOnly --watch\"",
20+
"build": "vite build",
1721
"clean": "rimraf dist",
1822
"lint": "eslint . --cache",
1923
"lint:fix": "yarn lint --fix",
2024
"lint:format": "prettier --write .",
2125
"lint:types": "tsc --noEmit",
22-
"prepare": "husky install .config/husky",
26+
"prepare": "husky install",
2327
"prepublishOnly": "yarn clean && yarn build",
28+
"size": "size-limit",
2429
"test": "jest"
2530
},
2631
"peerDependencies": {
@@ -29,17 +34,15 @@
2934
},
3035
"dependencies": {},
3136
"devDependencies": {
32-
"@commitlint/config-conventional": "^12.1.1",
33-
"@supabase/postgrest-js": "^0.28.1",
34-
"@supabase/supabase-js": "^1.11.6",
37+
"@size-limit/preset-small-lib": "^4.12.0",
38+
"@supabase/postgrest-js": "0.28.4",
39+
"@supabase/supabase-js": "1.11.6",
3540
"@testing-library/react-hooks": "^5.1.1",
3641
"@types/jest": "^26.0.22",
3742
"@types/node": "^14.14.41",
3843
"@types/react": "^17.0.3",
3944
"@typescript-eslint/eslint-plugin": "^4.22.0",
4045
"@typescript-eslint/parser": "^4.22.0",
41-
"commitlint": "^12.1.1",
42-
"concurrently": "^6.0.2",
4346
"eslint": "^7.24.0",
4447
"eslint-config-prettier": "^8.2.0",
4548
"eslint-import-resolver-typescript": "^2.4.0",
@@ -57,8 +60,11 @@
5760
"react": "^17.0.2",
5861
"react-dom": "^17.0.2",
5962
"rimraf": "^3.0.2",
63+
"size-limit": "^4.12.0",
6064
"ts-jest": "^26.5.5",
65+
"ts-node": "^10.0.0",
6166
"typescript": "^4.2.4",
62-
"vite": "^2.2.1"
67+
"vite": "^2.2.1",
68+
"vite-plugin-dts": "^0.5.1"
6369
}
6470
}

src/hooks/realtime/use-realtime.ts

+44-48
Original file line numberDiff line numberDiff line change
@@ -57,54 +57,50 @@ export function useRealtime<Data = any>(
5757
return [state, reexecute]
5858
}
5959

60-
const reducer = <Data = any>(compareFn: UseRealtimeCompareFn) => (
61-
state: UseRealtimeState<Data>,
62-
action: UseRealtimeAction<Data>,
63-
): UseRealtimeState<Data> => {
64-
const old = state.data
65-
switch (action.type) {
66-
case 'FETCH':
67-
return { ...state, old, ...action.payload }
68-
case 'SUBSCRIPTION':
69-
switch (action.payload.eventType) {
70-
case 'DELETE':
71-
return {
72-
...state,
73-
data: state.data?.filter(
74-
(x) => !compareFn(x, action.payload.old),
75-
),
76-
fetching: false,
77-
old,
78-
}
79-
case 'INSERT':
80-
return {
81-
...state,
82-
data: [...(old ?? []), action.payload.new],
83-
fetching: false,
84-
old,
85-
}
86-
case 'UPDATE': {
87-
const data = old ?? []
88-
const index = data.findIndex((x) =>
89-
compareFn(x, action.payload.new),
90-
)
91-
return {
92-
...state,
93-
data: [
94-
...data.slice(0, index),
95-
action.payload.new,
96-
...data.slice(index + 1),
97-
],
98-
fetching: false,
99-
old,
60+
const reducer =
61+
<Data = any>(compareFn: UseRealtimeCompareFn) =>
62+
(
63+
state: UseRealtimeState<Data>,
64+
action: UseRealtimeAction<Data>,
65+
): UseRealtimeState<Data> => {
66+
const old = state.data
67+
switch (action.type) {
68+
case 'FETCH':
69+
return { ...state, old, ...action.payload }
70+
case 'SUBSCRIPTION':
71+
switch (action.payload.eventType) {
72+
case 'DELETE':
73+
return {
74+
...state,
75+
data: state.data?.filter(
76+
(x) => !compareFn(x, action.payload.old),
77+
),
78+
fetching: false,
79+
old,
80+
}
81+
case 'INSERT':
82+
return {
83+
...state,
84+
data: [...(old ?? []), action.payload.new],
85+
fetching: false,
86+
old,
87+
}
88+
case 'UPDATE': {
89+
const data = old ?? []
90+
const index = data.findIndex((x) =>
91+
compareFn(x, action.payload.new),
92+
)
93+
return {
94+
...state,
95+
data: [
96+
...data.slice(0, index),
97+
action.payload.new,
98+
...data.slice(index + 1),
99+
],
100+
fetching: false,
101+
old,
102+
}
100103
}
101104
}
102-
default:
103-
throw Error(
104-
`eventType "${action.payload.eventType}" does not exist.`,
105-
)
106-
}
107-
default:
108-
throw Error('Action type does not exist.')
105+
}
109106
}
110-
}

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"resolveJsonModule": true,
1919
"skipLibCheck": false,
2020
"strict": true,
21-
"target": "es5",
22-
"types": ["node", "jest", "vite/client"]
21+
"target": "esnext",
22+
"types": ["node", "jest"]
2323
},
2424
"include": ["src/**/*"],
2525
"watchOptions": {

vite.config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'vite'
2+
import dts from 'vite-plugin-dts'
23

34
import pkg from './package.json'
45

@@ -16,4 +17,18 @@ export default defineConfig({
1617
],
1718
},
1819
},
20+
plugins: [
21+
dts({
22+
exclude: ['src/**test.ts*'],
23+
beforeWriteFile: (filePath, content) => ({
24+
content,
25+
filePath: filePath.replace('src', ''),
26+
}),
27+
compilerOptions: {
28+
emitDeclarationOnly: true,
29+
noEmit: false,
30+
},
31+
outputDir: 'dist/types',
32+
}),
33+
],
1934
})

0 commit comments

Comments
 (0)