Skip to content

Commit 7a275d0

Browse files
authored
feat: move to vite for bundling (#81)
fix: path to JS entrypoint fix: use string litterals as alternatives for visibility build!: use vitejs and move to @tanstack/react-query fix: move AppDataVisibility to types fix: allow functions as passthrough fix: update packages fix: add auto-tag workflows fix: update node-ci workflow
1 parent 10e2a3d commit 7a275d0

33 files changed

+5507
-4948
lines changed

.github/workflows/auto-tag.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Auto Tag
2+
3+
on:
4+
issues:
5+
types:
6+
- reopened
7+
- closed
8+
pull_request:
9+
types:
10+
- closed
11+
12+
jobs:
13+
auto-tag:
14+
name: Auto tag issues and PRs
15+
uses: graasp/graasp-deploy/.github/workflows/auto-tag.yml@v1

.github/workflows/release-please.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ jobs:
1818

1919
- name: Tag major and minor versions
2020
uses: jacobsvante/[email protected]
21-
if: ${{ steps.release.outputs.release_created }}
21+
if: ${{ steps.release.outputs.releases_created }}
2222
with:
2323
major: ${{ steps.release.outputs.major }}
2424
minor: ${{ steps.release.outputs.minor }}
2525

26-
# -------------------------------------------------------------------------
27-
# This section is useful only if you plan on publishing your package to NPM
28-
# Remove it if you do not plan to publish to NPM
26+
- name: Auto Tag
27+
uses: graasp/graasp-deploy/.github/actions/auto-tag-after-release@v1
28+
with:
29+
releases_created: ${{ steps.release.outputs.releases_created }}
30+
tag_name: ${{ steps.release.outputs.tag_name }}
31+
2932
- name: Publish to NPM
3033
uses: graasp/graasp-deploy/.github/actions/publish-to-npm@v1
3134
with:
3235
npm-token: ${{ secrets.NPM_TOKEN }}
33-
if: ${{ steps.release.outputs.release_created }}
34-
# -------------------------------------------------------------------------
36+
if: ${{ steps.release.outputs.releases_created }}

.github/workflows/test.yml

+11-16
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
11+
1112
- name: Use Node.js 16.x
1213
uses: actions/setup-node@v1
1314
with:
1415
node-version: 16.x
15-
- name: Get npm cache directory
16-
id: npm-cache
17-
run: |
18-
echo "::set-output name=dir::$(npm config get cache)"
19-
- uses: actions/cache@v2
20-
with:
21-
path: ${{ steps.npm-cache.outputs.dir }}
22-
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
23-
restore-keys: |
24-
${{ runner.os }}-node-
25-
- name: yarn install, build, and test
26-
run: |
27-
yarn
28-
yarn build
29-
yarn test
16+
17+
- name: Yarn Install and Cache
18+
uses: graasp/graasp-deploy/.github/actions/yarn-install-and-cache@v1
19+
20+
- name: Build
21+
run: yarn build
22+
23+
- name: Test
24+
run: yarn test

.yarn/releases/yarn-3.3.0.cjs

-807
This file was deleted.

.yarn/releases/yarn-3.5.0.cjs

+873
Large diffs are not rendered by default.

.yarnrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ plugins:
88
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
99
spec: "@yarnpkg/plugin-interactive-tools"
1010

11-
yarnPath: .yarn/releases/yarn-3.3.0.cjs
11+
yarnPath: .yarn/releases/yarn-3.5.0.cjs

example/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
},
1212
"dependencies": {
1313
"@graasp/apps-query-client": "link:..",
14-
"@material-ui/core": "4.12.4",
15-
"@material-ui/icons": "4.11.3",
14+
"@mui/icons-material": "5.11.11",
15+
"@mui/material": "5.11.14",
16+
"@tanstack/react-query": "4.28.0",
1617
"@testing-library/jest-dom": "5.16.4",
1718
"@testing-library/react": "13.3.0",
1819
"@testing-library/user-event": "14.2.1",
@@ -22,7 +23,6 @@
2223
"@types/react-dom": "18.0.5",
2324
"react": "18.2.0",
2425
"react-dom": "18.2.0",
25-
"react-query": "4.0.0-beta.23",
2626
"react-scripts": "5.0.1",
2727
"typescript": "4.9.4"
2828
},

jest.config.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ export default {
7474
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'],
7575

7676
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
77-
moduleNameMapper: {
78-
'^react$': '<rootDir>/example/node_modules/react',
79-
'^react-dom$': '<rootDir>/example/node_modules/react-dom',
80-
'^react-dom/(.*)': '<rootDir>/example/node_modules/react-dom/$1',
81-
},
77+
// moduleNameMapper: {
78+
// '^react$': '<rootDir>/example/node_modules/react',
79+
// '^react-dom$': '<rootDir>/example/node_modules/react-dom',
80+
// '^react-dom/(.*)': '<rootDir>/example/node_modules/react-dom/$1',
81+
// },
8282

8383
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
8484
// modulePathIgnorePatterns: [],

package.json

+47-43
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "@graasp/apps-query-client",
33
"version": "0.4.2",
44
"description": "Query client repository for Graasp apps",
5-
"main": "dist/index.js",
6-
"module": "dist/index.modern.js",
7-
"source": "src/index.ts",
8-
"types": "dist/index.d.ts",
5+
"main": "./dist/index.cjs.js",
6+
"module": "./dist/index.es.js",
7+
"source": "./src/index.ts",
8+
"types": "./dist/index.d.ts",
99
"repository": "[email protected]:graasp/graasp-apps-query-client.git",
1010
"author": "Graasp",
1111
"contributors": [
@@ -16,72 +16,76 @@
1616
"example"
1717
],
1818
"license": "AGPL3.0-only",
19+
"scripts": {
20+
"dev": "vite",
21+
"build": "tsc && vite build",
22+
"deploy": "gh-pages -d example/build",
23+
"commit-msg": "commitlint --edit $1",
24+
"hooks:uninstall": "husky uninstall",
25+
"hooks:install": "husky install",
26+
"lint": "eslint .",
27+
"prettier:check": "prettier --check \"{src,test}/**/*.ts\"",
28+
"prettier:write": "prettier --write \"{src,test}/**/*.ts\"",
29+
"type-check": "tsc --noEmit",
30+
"check": "yarn lint && yarn prettier:check && yarn type-check",
31+
"pre-commit": "yarn prettier:check && yarn lint",
32+
"predeploy": "cd example && yarn install && yarn run build",
33+
"prepare": "yarn build",
34+
"prepack": "yarn build",
35+
"post-commit": "git status",
36+
"start:example": "yarn workspace graasp-query-client-example start",
37+
"test": "jest --forceExit --coverage --verbose --silent",
38+
"test:watch": "yarn test --watchAll",
39+
"test:ci": "yarn && cd example && yarn && cd .. && yarn test"
40+
},
1941
"dependencies": {
20-
"@graasp/sdk": "github:graasp/graasp-sdk",
42+
"@graasp/sdk": "0.11.0",
2143
"axios": "0.27.2",
2244
"http-status-codes": "2.2.0",
23-
"immutable": "4.1.0",
45+
"immutable": "4.3.0",
2446
"miragejs": "0.1.46",
2547
"qs": "6.11.0",
26-
"react-query": "4.0.0-beta.23",
27-
"standard-version": "9.5.0",
28-
"tsc": "2.0.4",
2948
"uuid": "9.0.0"
3049
},
3150
"devDependencies": {
3251
"@commitlint/cli": "17.3.0",
3352
"@commitlint/config-conventional": "17.3.0",
53+
"@tanstack/react-query": "4.28.0",
54+
"@tanstack/react-query-devtools": "4.28.0",
3455
"@testing-library/react-hooks": "8.0.0",
3556
"@types/jest": "28.1.2",
3657
"@types/node": "17.0.45",
3758
"@types/qs": "6.9.7",
38-
"@types/react": "18.0.14",
39-
"@types/uuid": "8.3.4",
40-
"@typescript-eslint/eslint-plugin": "5.28.0",
41-
"@typescript-eslint/parser": "5.28.0",
59+
"@types/react": "18.0.28",
60+
"@types/react-dom": "18.0.11",
61+
"@types/uuid": "9.0.1",
62+
"@typescript-eslint/eslint-plugin": "5.56.0",
63+
"@typescript-eslint/parser": "5.56.0",
64+
"@vitejs/plugin-react": "3.1.0",
4265
"eslint": "8.29.0",
4366
"eslint-config-prettier": "8.5.0",
4467
"husky": "8.0.2",
4568
"jest": "28.1.3",
46-
"microbundle": "0.15.1",
4769
"nock": "13.2.9",
4870
"prettier": "2.8.1",
71+
"react": "18.2.0",
72+
"react-dom": "18.2.0",
4973
"react-test-renderer": "18.2.0",
5074
"ts-jest": "28.0.5",
5175
"ts-node": "10.8.1",
52-
"typescript": "4.9.4"
53-
},
54-
"scripts": {
55-
"build": "microbundle --no-compress --format modern,cjs --jsx React.createElement",
56-
"commit-msg": "commitlint --edit $1",
57-
"deploy": "gh-pages -d example/build",
58-
"hooks:uninstall": "husky uninstall",
59-
"hooks:install": "husky install",
60-
"lint": "eslint .",
61-
"pre-commit": "yarn prettier:check && yarn lint",
62-
"predeploy": "cd example && yarn install && yarn run build",
63-
"prepare": "yarn build",
64-
"prepack": "yarn build",
65-
"prettier:check": "prettier --check \"{src,test}/**/*.ts\"",
66-
"prettier:write": "prettier --write \"{src,test}/**/*.ts\"",
67-
"post-commit": "git status",
68-
"release": "git fetch --tags && git add CHANGELOG.md && standard-version -a",
69-
"release:first": "git fetch --tags && git add CHANGELOG.md && standard-version -a --first-release",
70-
"start": "microbundle-crl watch --no-compress --format modern,cjs",
71-
"start:example": "yarn workspace graasp-query-client-example start",
72-
"test": "jest --forceExit --coverage --verbose --silent",
73-
"test:watch": "yarn test --watchAll",
74-
"test:ci": "yarn && cd example && yarn && cd .. && yarn test"
76+
"typescript": "4.9.4",
77+
"vite": "4.2.1",
78+
"vite-plugin-checker": "0.5.6",
79+
"vite-plugin-dts": "2.1.0"
7580
},
7681
"peerDependencies": {
77-
"react": "^17.0.0 || ^18.0.0"
78-
},
79-
"localDependencies": {
80-
"react": "./example/node_modules/react",
81-
"react-dom": "./example/node_modules/react-dom"
82+
"@tanstack/react-query": "^4.28.0",
83+
"@tanstack/react-query-devtools": "^4.28.0",
84+
"react": "^18.0.0",
85+
"react-dom": "^18.0.0"
8286
},
8387
"files": [
8488
"dist"
8589
],
86-
"packageManager": "yarn@3.3.0"
90+
"packageManager": "yarn@3.5.0"
8791
}

src/components/withContext.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RecordOf } from 'immutable';
22
import qs from 'qs';
33
import React, { createContext, FC, useContext } from 'react';
4-
import { UseQueryResult } from 'react-query';
4+
import { UseQueryResult } from '@tanstack/react-query';
55
import { buildMockLocalContext } from '../mockServer/fixtures';
66
import { LocalContext, LocalContextRecord } from '../types';
77
import { AutoResizer } from './AutoResizer';

src/components/withToken.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { createContext, FC } from 'react';
22
import qs from 'qs';
3-
import { UseQueryResult } from 'react-query';
3+
import { UseQueryResult } from '@tanstack/react-query';
44
import { Token } from '../types';
55

66
// mock token, necessary for first renders

src/config/constants.ts

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ export const DEFAULT_THUMBNAIL_SIZES = THUMBNAIL_SIZES.SMALL;
2424

2525
export const DEFAULT_PERMISSION = PermissionLevel.Read;
2626

27-
// Has to match with https://github.com/graasp/graasp-apps/blob/main/src/interfaces/app-details.ts
28-
export enum AppDataVisibility {
29-
ITEM = 'item',
30-
MEMBER = 'member',
31-
}
32-
3327
export const DEFAULT_CONTEXT = 'standalone';
3428
export const DEFAULT_LANG = 'en';
3529
export const MOCK_TOKEN = 'mock-token';

src/config/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryClient } from 'react-query';
1+
import { QueryClient } from '@tanstack/react-query';
22
import { Record } from 'immutable';
33
import { LocalContext, QueryClientConfig } from '../types';
44
import { AUTH_TOKEN_KEY, LOCAL_CONTEXT_KEY } from './keys';

src/hooks/appAction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { List } from 'immutable';
2-
import { QueryClient, useQuery } from 'react-query';
2+
import { QueryClient, useQuery } from '@tanstack/react-query';
33
import * as Api from '../api';
44
import { buildAppActionsKey } from '../config/keys';
55
import { getApiHost, getDataOrThrow } from '../config/utils';

src/hooks/appData.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { List, RecordOf } from 'immutable';
2-
import { QueryClient, useQuery } from 'react-query';
2+
import { QueryClient, useQuery } from '@tanstack/react-query';
33
import * as Api from '../api';
44
import { MissingFileIdError } from '../config/errors';
55
import { buildAppContextKey, buildAppDataKey, buildFileContentKey } from '../config/keys';

src/hooks/appSetting.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { List } from 'immutable';
2-
import { QueryClient, useQuery } from 'react-query';
2+
import { QueryClient, useQuery } from '@tanstack/react-query';
33
import * as Api from '../api';
44
import { MissingFileIdError } from '../config/errors';
55
import { buildAppSettingFileContentKey, buildAppSettingsKey } from '../config/keys';

src/hooks/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryClient } from 'react-query';
1+
import { QueryClient } from '@tanstack/react-query';
22
import { QueryClientConfig } from '../types';
33
import configureAppsHooks from './appData';
44
import configureAppSettingHooks from './appSetting';

src/hooks/postMessage.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ describe('PostMessage Hooks', () => {
167167
postMessage: () => {
168168
/*do nothing*/
169169
},
170+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
170171
onmessage: (_event: unknown) => {
171172
/*do nothing*/
172173
},
@@ -266,6 +267,7 @@ describe('PostMessage Hooks', () => {
266267
// mock window height
267268
global.document = {
268269
body: { scrollHeight: 420 },
270+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
269271
} as any;
270272

271273
renderHook(() => hooks.useAutoResize(mockItemId));

src/hooks/postMessage.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { RecordOf } from 'immutable';
77
import { useEffect } from 'react';
8-
import { QueryClient, useQuery } from 'react-query';
8+
import { QueryClient, useQuery } from '@tanstack/react-query';
99
import { DEFAULT_CONTEXT, DEFAULT_LANG, DEFAULT_PERMISSION } from '../config/constants';
1010
import { MissingMessageChannelPortError } from '../config/errors';
1111
import { AUTH_TOKEN_KEY, buildPostMessageKeys, LOCAL_CONTEXT_KEY } from '../config/keys';
@@ -74,22 +74,24 @@ const configurePostMessageHooks = (_queryClient: QueryClient, queryConfig: Query
7474
resolve: (value: A) => void;
7575
reject: (reason?: unknown) => void;
7676
},
77+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7778
formatResolvedValue?: (data: { payload: any; event: MessageEvent }) => A,
7879
) =>
7980
(event: MessageEvent) => {
8081
try {
8182
const { type, payload } = JSON.parse(event.data) || {};
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8284
const format = formatResolvedValue ?? ((data: { payload: any }) => data.payload);
8385
// get init message getting the Message Channel port
8486
if (type === successType) {
8587
resolve(format({ payload, event }));
8688
} else if (type === errorType) {
8789
reject({ payload, event });
8890
} else {
89-
reject('the type is not recognised');
91+
reject('the type is not recognized');
9092
}
9193
} catch (e) {
92-
reject('an error occured');
94+
reject('an error occurred');
9395
}
9496
};
9597

0 commit comments

Comments
 (0)