Skip to content

Commit a9c7f6d

Browse files
bors[bot]bidoubiwa
andauthored
Merge #249
249: Typescript first r=bidoubiwa a=bidoubiwa # Typescript conversion ## Types update Types have been improved and are compatible with instant search types. ## Linting update All envs and playgrounds are linted based on the root eslint config file. ## Jest updates as in meilisearch-js meilisearch/meilisearch-js#760 the jest jsdom had to be updated for the tests to succeed in node 10. #255 ## Testing Add build before tests for env tests using jest to succeed. Add build of playgrounds in CI to determine if they correctly extract instant-meilisearch. Add instantsearch.js as a dev dependency as it is used for testing purposes Add some nodejs tests that tries instantsearch compatibility with instant-meilisearch Add a typescript ## Playgrounds - Update playgrounds so that hot-reload also works on typescript files - Remove sub-dir eslint configs as everything is handled by root eslint config file ## Naming Methods inside instant-meilisearch function have been renamed for more clarity Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 0df20f0 + adf0d18 commit a9c7f6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8758
-8342
lines changed

.eslintignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
node_modules
22
dist
3-
examples
4-
scripts
5-
tests/env
63
build
74

8-
# temporary fix
9-
playgrounds/vanilla-js
5+
.cache

.eslintrc.js

Lines changed: 160 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,165 @@
11
module.exports = {
2-
env: {
3-
browser: true,
4-
es2020: true,
5-
'jest/globals': true,
6-
},
7-
globals: {
8-
page: true, // for jest/puppeteer tests in examples/express
9-
browser: true, // for jest/puppeteer tests in examples/express
10-
context: true, // for jest/puppeteer tests in examples/express
11-
jestPuppeteer: true, // for jest/puppeteer tests in examples/express
12-
},
13-
extends: [
14-
'standard',
15-
'plugin:@typescript-eslint/recommended',
16-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
17-
'plugin:prettier/recommended',
18-
'prettier/@typescript-eslint',
19-
],
20-
parser: '@typescript-eslint/parser',
21-
parserOptions: {
22-
ecmaVersion: 2020,
23-
sourceType: 'module',
24-
project: ['tsconfig.eslint.json'],
25-
projectFolderIgnoreList: ['dist'],
26-
},
27-
plugins: ['jsdoc', '@typescript-eslint', 'prettier', 'jest'],
28-
rules: {
29-
'no-dupe-class-members': 'off', // Off due to conflict with typescript overload functions
30-
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
31-
'@typescript-eslint/array-type': ['warn', { default: 'array-simple' }],
32-
'@typescript-eslint/return-await': 'off',
33-
'jsdoc/check-alignment': 'error',
34-
'jsdoc/check-indentation': 'error',
35-
'@typescript-eslint/space-before-function-paren': 0,
36-
'@typescript-eslint/no-explicit-any': 'off',
37-
'@typescript-eslint/explicit-function-return-type': 'off',
38-
'@typescript-eslint/no-throw-literal': 'off',
39-
'@typescript-eslint/no-non-null-assertion': 'off',
40-
'@typescript-eslint/no-unsafe-assignment': 'off',
41-
'@typescript-eslint/no-unsafe-call': 'off',
42-
'@typescript-eslint/no-unsafe-return': 'off',
43-
'@typescript-eslint/no-unsafe-module-boundary-types': 'off',
44-
'@typescript-eslint/prefer-regexp-exec': 'off',
45-
'@typescript-eslint/explicit-module-boundary-types': 'off',
46-
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
47-
'@typescript-eslint/no-unsafe-member-access': 'off',
48-
'@typescript-eslint/ban-types': 'off',
49-
'@typescript-eslint/member-delimiter-style': [
50-
'error',
51-
{
52-
multiline: {
53-
delimiter: 'none', // 'none' or 'semi' or 'comma'
54-
requireLast: true,
2+
root: true,
3+
overrides: [
4+
{
5+
/*
6+
* REACT
7+
*/
8+
files: ['playgrounds/react/**/*.js'],
9+
env: {
10+
es2020: true,
11+
commonjs: true, // Needed to avoid import is reserved error
12+
node: true,
13+
browser: true,
14+
jest: true,
15+
},
16+
parser: 'babel-eslint',
17+
extends: ['eslint:recommended', 'plugin:react/recommended'],
18+
plugins: ['react', 'import', 'react-hooks'],
19+
parserOptions: {
20+
ecmaFeatures: {
21+
jsx: true,
5522
},
56-
singleline: {
57-
delimiter: 'semi', // 'semi' or 'comma'
58-
requireLast: false,
23+
ecmaVersion: 2020,
24+
sourceType: 'module',
25+
},
26+
rules: {
27+
'react/prop-types': 0,
28+
},
29+
settings: {
30+
react: {
31+
version: 'latest',
5932
},
6033
},
61-
],
62-
'comma-dangle': 'off',
63-
},
34+
},
35+
{
36+
/*
37+
* JS
38+
*/
39+
files: ['**/*.js'],
40+
env: {
41+
browser: true,
42+
es2020: true,
43+
'jest/globals': true,
44+
node: true,
45+
},
46+
globals: {
47+
instantsearch: true,
48+
instantMeiliSearch: true,
49+
page: true, // for jest/puppeteer tests in examples/express
50+
browser: true, // for jest/puppeteer tests in examples/express
51+
context: true, // for jest/puppeteer tests in examples/express
52+
jestPuppeteer: true, // for jest/puppeteer tests in examples/express
53+
},
54+
extends: [
55+
'standard',
56+
'plugin:prettier/recommended',
57+
'eslint:recommended',
58+
],
59+
plugins: ['jest'],
60+
parserOptions: {
61+
ecmaVersion: 2020,
62+
},
63+
rules: {},
64+
},
65+
{
66+
/*
67+
* VUE FILES
68+
*/
69+
70+
files: ['playgrounds/vue/**/*.vue'],
71+
env: {
72+
browser: true,
73+
commonjs: true,
74+
es6: true,
75+
},
76+
extends: [
77+
'plugin:prettier/recommended',
78+
'prettier/vue',
79+
'plugin:vue/essential',
80+
'plugin:vue/base',
81+
],
82+
parser: 'vue-eslint-parser',
83+
parserOptions: {
84+
parser: 'babel-eslint',
85+
ecmaVersion: 2020,
86+
sourceType: 'module',
87+
ecmaFeatures: {
88+
jsx: true,
89+
},
90+
},
91+
plugins: ['vue', 'prettier', 'jsdoc'],
92+
rules: {},
93+
},
94+
{
95+
/*
96+
* TYPESCRIPT
97+
*/
98+
files: ['*.ts'],
99+
env: {
100+
browser: true,
101+
es2020: true,
102+
'jest/globals': true,
103+
},
104+
globals: {
105+
page: true, // for jest/puppeteer tests in examples/express
106+
browser: true, // for jest/puppeteer tests in examples/express
107+
context: true, // for jest/puppeteer tests in examples/express
108+
jestPuppeteer: true, // for jest/puppeteer tests in examples/express
109+
},
110+
extends: [
111+
'standard',
112+
'plugin:@typescript-eslint/recommended',
113+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
114+
'plugin:prettier/recommended',
115+
'prettier/@typescript-eslint',
116+
],
117+
parser: '@typescript-eslint/parser',
118+
parserOptions: {
119+
ecmaVersion: 2020,
120+
sourceType: 'module',
121+
project: ['tsconfig.eslint.json'],
122+
projectFolderIgnoreList: ['dist'],
123+
},
124+
125+
plugins: ['jsdoc', '@typescript-eslint', 'prettier', 'jest'],
126+
rules: {
127+
'@typescript-eslint/no-empty-interface': 'off', // Due to vue-instantsearch not having typings
128+
'no-dupe-class-members': 'off', // Off due to conflict with typescript overload functions
129+
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
130+
'@typescript-eslint/array-type': ['warn', { default: 'array-simple' }],
131+
'@typescript-eslint/return-await': 'off',
132+
'jsdoc/check-alignment': 'error',
133+
'jsdoc/check-indentation': 'error',
134+
'@typescript-eslint/space-before-function-paren': 0,
135+
'@typescript-eslint/no-explicit-any': 'off',
136+
'@typescript-eslint/explicit-function-return-type': 'off',
137+
'@typescript-eslint/no-throw-literal': 'off',
138+
'@typescript-eslint/no-non-null-assertion': 'off',
139+
'@typescript-eslint/no-unsafe-assignment': 'off',
140+
'@typescript-eslint/no-unsafe-call': 'off',
141+
'@typescript-eslint/no-unsafe-return': 'off',
142+
'@typescript-eslint/no-unsafe-module-boundary-types': 'off',
143+
'@typescript-eslint/prefer-regexp-exec': 'off',
144+
'@typescript-eslint/explicit-module-boundary-types': 'off',
145+
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
146+
'@typescript-eslint/no-unsafe-member-access': 'off',
147+
'@typescript-eslint/ban-types': 'off',
148+
'@typescript-eslint/member-delimiter-style': [
149+
'error',
150+
{
151+
multiline: {
152+
delimiter: 'none', // 'none' or 'semi' or 'comma'
153+
requireLast: true,
154+
},
155+
singleline: {
156+
delimiter: 'semi', // 'semi' or 'comma'
157+
requireLast: false,
158+
},
159+
},
160+
],
161+
'comma-dangle': 'off',
162+
},
163+
},
164+
],
64165
}

jest.config.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
module.exports = {
22
verbose: true,
3-
modulePathIgnorePatterns: ['<rootDir>/tests/env'],
4-
testMatch: ['<rootDir>/tests/**/*.ts?(x)'],
5-
preset: 'ts-jest',
3+
projects: [
4+
{
5+
preset: 'ts-jest',
6+
displayName: 'dom',
7+
// We are using jest-environment-jsdom 25 until we stop supporting node 10
8+
// jest-environment-jsdom 25 uses jsdom 15 which still supports node 10
9+
testEnvironment: 'jest-environment-jsdom',
10+
testPathIgnorePatterns: ['<rootDir>/tests/env/express'],
11+
},
12+
{
13+
preset: 'ts-jest',
14+
displayName: 'node',
15+
testEnvironment: 'node',
16+
testPathIgnorePatterns: ['<rootDir>/tests/env/express'],
17+
},
18+
],
619
}

package.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"description": "The search client to use MeiliSearch with InstantSearch.",
66
"scripts": {
77
"cleanup": "shx rm -rf dist/",
8-
"test": "jest",
9-
"test:all": "yarn test && yarn test:env && test:playgrounds",
10-
"test:env": "yarn build && yarn test:env:browser && yarn test:env:nodejs && yarn test:env:esm",
8+
"test": "yarn build && jest",
9+
"test:all": "yarn test && yarn test:env && yarn test:playgrounds",
10+
"test:env": "yarn build && yarn test:env:browser && yarn test:env:nodejs && yarn test:env:esm && yarn test:env:ts",
1111
"test:env:browser": "yarn --cwd tests/env/express && yarn --cwd tests/env/express test",
1212
"test:env:nodejs": "node tests/env/node/index.js",
1313
"test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start",
14-
"test:playgrounds": "yarn build && yarn build:playground:vue && yarn build:playground:react && yarn build:playground:javascript && yarn build:playground:html",
14+
"test:env:ts": "yarn --cwd tests/env/typescript-node && yarn --cwd tests/env/typescript-node start",
15+
"test:playgrounds": "yarn build:playground:vue && yarn build:playground:react && yarn build:playground:javascript && yarn build:playground:html",
1516
"build:playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue build",
1617
"build:playground:react": "yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react build",
1718
"build:playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript build",
@@ -23,9 +24,9 @@
2324
"postbuild": "yarn typingsheader",
2425
"typingsheader": "node scripts/build.js",
2526
"build": "yarn cleanup && rollup -c rollup.config.js && rollup --environment NODE_ENV:production -c rollup.config.js ",
27+
"dev": "rollup -c rollup.config.js --watch",
2628
"lint": "eslint --ext .js,.ts,.tsx,.vue .",
27-
"lint:fix": "eslint --ext .js,.ts,.tsx,.vue --fix .",
28-
29+
"lint:fix": "eslint --ext .js,.ts,.tsx,.vue --fix ."
2930
},
3031
"main": "./dist/instant-meilisearch.umd.js",
3132
"module": "./dist/instant-meilisearch.esm.js",
@@ -59,18 +60,19 @@
5960
},
6061
"devDependencies": {
6162
"@babel/cli": "^7.10.5",
62-
"@babel/core": "^7.0.0",
63+
"@babel/core": "^7.0.0-0",
6364
"@babel/preset-env": "^7.10.4",
6465
"@rollup/plugin-commonjs": "^17.1.0",
6566
"@rollup/plugin-node-resolve": "^11.0.0",
6667
"@typescript-eslint/eslint-plugin": "^4.14.0",
6768
"@typescript-eslint/parser": "^4.14.0",
69+
"@vue/eslint-config-typescript": "^7.0.0",
70+
"@vue/eslint-plugin": "^4.2.0",
6871
"babel-eslint": "^10.1.0",
6972
"babel-jest": "^26.1.0",
7073
"cssnano": "^4.1.10",
7174
"eslint": "^7.19.0",
7275
"eslint-config-prettier": "^7.2.0",
73-
"eslint-config-react-app": "^6.0.0",
7476
"eslint-config-standard": "^16.0.0",
7577
"eslint-plugin-flowtype": "^5.2.0",
7678
"eslint-plugin-import": "^2.22.0",
@@ -80,11 +82,13 @@
8082
"eslint-plugin-node": "^11.1.0",
8183
"eslint-plugin-prettier": "^3.1.4",
8284
"eslint-plugin-promise": "^4.2.1",
83-
"eslint-plugin-react": "^7.21.5",
85+
"eslint-plugin-react": "^7.22.0",
8486
"eslint-plugin-react-hooks": "^4.2.0",
8587
"eslint-plugin-standard": "^5.0.0",
8688
"eslint-plugin-vue": "^7.5.0",
87-
"jest": "^26.1.0",
89+
"instantsearch.js": "^4.14.0",
90+
"jest": "^26.6.3",
91+
"jest-environment-jsdom": "25.5",
8892
"jest-watch-typeahead": "^0.6.0",
8993
"prettier": "^2.0.0",
9094
"regenerator-runtime": "^0.13.7",

playgrounds/html/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $ yarn install
2121

2222
### Compile and hot-reload for development
2323
```
24-
yarn serve
24+
yarn start
2525
```
2626

2727
### Compile and minify for production

playgrounds/html/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
87
"start": "parcel serve ./public/index.html --global instantMeiliSearch --open",
98
"build": "parcel build ./public/index.html --global instantMeiliSearch"
109
},

playgrounds/html/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
To use this browser build, please change the following script tag with this CDN
1818
<script src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js"></script>
1919
-->
20-
<script src="../../../src/index.js"></script>
20+
<script src="../../../src/index.ts"></script>
2121
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
2222
<script>
2323
// This is due to parcel not accepting globals on html files.

playgrounds/javascript/.eslintrc.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

playgrounds/react/.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-react"],
3+
"plugins": ["@babel/plugin-syntax-jsx"]
4+
}

playgrounds/react/.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)