Skip to content

Commit 7fcdbba

Browse files
authored
Convert project to TypeScript (#139)
* Convert project to TypeScript * Fix vue playground * Fix react playground * Build typescript before playgrounds * Add checking playgrounds to contributing PR checks * Use new version of meilisearch-js * Add attibutesToRetrieve from ae950fb * Use SearchParams to define Params * Ignore dist in eslint of vue playground * Revert CONTRIBUTING back to (current) master * Add missing comma The disadvantages of the GH web editor. Sorry 😬 * Make linter pass
1 parent ea49507 commit 7fcdbba

File tree

17 files changed

+571
-113
lines changed

17 files changed

+571
-113
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
node_modules
22
dist
3+
examples
4+
scripts
5+
tests/env
36
build
7+
8+
# temporary fix
9+
playgrounds/vanilla-js

.eslintrc.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,55 @@ module.exports = {
1010
context: true, // for jest/puppeteer tests in examples/express
1111
jestPuppeteer: true, // for jest/puppeteer tests in examples/express
1212
},
13-
extends: ['standard', 'plugin:prettier/recommended'],
14-
plugins: ['jest'],
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',
1521
parserOptions: {
16-
ecmaVersion: 11,
22+
ecmaVersion: 2020,
1723
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,
55+
},
56+
singleline: {
57+
delimiter: 'semi', // 'semi' or 'comma'
58+
requireLast: false,
59+
},
60+
},
61+
],
62+
'comma-dangle': 'off',
1863
},
19-
rules: {},
2064
}

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module.exports = {
22
verbose: true,
33
modulePathIgnorePatterns: ['<rootDir>/examples'],
4+
testMatch: ['<rootDir>/tests/**/*.ts?(x)'],
5+
preset: 'ts-jest',
46
}

package.json

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,36 @@
44
"private": false,
55
"description": "The search client to use MeiliSearch with InstantSearch.",
66
"scripts": {
7+
"cleanup": "shx rm -rf dist/",
78
"test": "jest",
89
"test:demo": "yarn build && yarn test:demo:browser && yarn test:demo:nodejs && yarn test:demo:esm",
910
"test:demo:browser": "yarn --cwd examples/express && yarn --cwd examples/express test",
1011
"test:demo:nodejs": "node examples/node/index.js",
1112
"test:demo:esm": "yarn --cwd examples/esm && yarn --cwd examples/esm start",
12-
"build:playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue build",
13-
"build:playground:react": "yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react build",
14-
"build:playground:vanilla-js": "yarn --cwd ./playgrounds/vanilla-js && yarn --cwd ./playgrounds/vanilla-js build",
13+
"build:playground:vue": "yarn build && yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue build",
14+
"build:playground:react": "yarn build && yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react build",
15+
"build:playground:vanilla-js": "yarn build && yarn --cwd ./playgrounds/vanilla-js && yarn --cwd ./playgrounds/vanilla-js build",
1516
"test:all": "yarn test && yarn test:demo",
1617
"lint": "eslint --ext .js,.ts,.tsx,.vue .",
1718
"lint:fix": "eslint --ext .js,.ts,.tsx,.vue --fix .",
18-
"build": "rollup -c rollup.config.js && rollup --environment NODE_ENV:production -c rollup.config.js ",
19-
"playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue serve",
20-
"playground:react": "yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react start",
21-
"playground:vanilla-js": "yarn --cwd ./playgrounds/vanilla-js && yarn --cwd ./playgrounds/vanilla-js start"
19+
"build": "yarn cleanup && rollup -c rollup.config.js && rollup --environment NODE_ENV:production -c rollup.config.js ",
20+
"postbuild": "yarn typingsheader",
21+
"playground:vue": "yarn build && yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue serve",
22+
"playground:react": "yarn build && yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react start",
23+
"playground:vanilla-js": "yarn build && yarn --cwd ./playgrounds/vanilla-js && yarn --cwd ./playgrounds/vanilla-js start",
24+
"typingsheader": "node scripts/build.js"
2225
},
2326
"main": "./dist/instant-meilisearch.umd.js",
2427
"module": "./dist/instant-meilisearch.esm.js",
2528
"browser": "./dist/instant-meilisearch.umd.js",
2629
"cjs": "./dist/instant-meilisearch.cjs.js",
30+
"source": "src/index.ts",
31+
"typings": "./dist/types/index.d.ts",
32+
"types": "./dist/types/index.d.ts",
33+
"sideEffects": false,
34+
"bugs": {
35+
"url": "https://github.com/meilisearch/instant-meilisearch/issues"
36+
},
2737
"files": [
2838
"dist",
2939
"src"
@@ -40,7 +50,7 @@
4050
"url": "https://github.com/meilisearch/instant-meilisearch.git"
4151
},
4252
"dependencies": {
43-
"meilisearch": "^0.16.0"
53+
"meilisearch": "^0.16.1"
4454
},
4555
"devDependencies": {
4656
"@babel/cli": "^7.10.5",
@@ -59,6 +69,7 @@
5969
"eslint-plugin-flowtype": "^5.2.0",
6070
"eslint-plugin-import": "^2.22.0",
6171
"eslint-plugin-jest": "^24.0.0",
72+
"eslint-plugin-jsdoc": "^30.7.7",
6273
"eslint-plugin-jsx-a11y": "^6.4.1",
6374
"eslint-plugin-node": "^11.1.0",
6475
"eslint-plugin-prettier": "^3.1.4",
@@ -74,6 +85,9 @@
7485
"rollup": "^2.23.0",
7586
"rollup-plugin-babel": "^4.4.0",
7687
"rollup-plugin-terser": "^7.0.0",
88+
"rollup-plugin-typescript2": "^0.29.0",
89+
"shx": "^0.3.3",
90+
"ts-jest": "^26.4.4",
7791
"typescript": "^4.0.0"
7892
}
7993
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../src/index.js
1+
../../../dist/instant-meilisearch.esm.js

playgrounds/vue/.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
examples
4+
scripts
5+
tests/env

playgrounds/vue/src/App.vue

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,43 @@
55
<p class="header-subtitle">Search in Steam video games 🎮</p>
66
</header>
77
<p class="disclaimer">
8-
This is not the official Steam dataset but only for demo purpose.
9-
Enjoy searching with MeiliSearch!
8+
This is not the official Steam dataset but only for demo purpose. Enjoy
9+
searching with MeiliSearch!
1010
</p>
1111
<div class="container">
12-
<ais-instant-search :search-client="searchClient" index-name="steam-video-games">
12+
<ais-instant-search
13+
:search-client="searchClient"
14+
index-name="steam-video-games"
15+
>
1316
<div class="search-panel__filters">
1417
<ais-clear-refinements>
1518
<span slot="resetLabel">Clear all filters</span>
1619
</ais-clear-refinements>
1720
<h2>Genres</h2>
18-
<ais-refinement-list attribute="genres"/>
21+
<ais-refinement-list attribute="genres" />
1922
<h2>Players</h2>
20-
<ais-refinement-list attribute="players"/>
23+
<ais-refinement-list attribute="players" />
2124
<h2>Platforms</h2>
22-
<ais-refinement-list attribute="platforms"/>
25+
<ais-refinement-list attribute="platforms" />
2326
<h2>Misc</h2>
24-
<ais-refinement-list attribute="misc"/>
27+
<ais-refinement-list attribute="misc" />
2528
</div>
2629

2730
<div class="search-panel__results">
28-
<ais-search-box placeholder="Search here…"/>
31+
<ais-search-box placeholder="Search here…" />
2932

3033
<ais-hits>
3134
<template slot="item" slot-scope="{ item }">
3235
<div>
3336
<div class="hit-name">
34-
<ais-highlight :hit="item" attribute="name"/>
37+
<ais-highlight :hit="item" attribute="name" />
3538
</div>
36-
<img :src="item.image" align="left" :alt="item.image">
39+
<img :src="item.image" align="left" :alt="item.image" />
3740
<div class="hit-description">
38-
<ais-snippet :hit="item" attribute="description"/>
41+
<ais-snippet :hit="item" attribute="description" />
3942
</div>
40-
<div class="hit-info">price: {{item.price}}</div>
41-
<div class="hit-info">release date: {{item.releaseDate}}</div>
43+
<div class="hit-info">price: {{ item.price }}</div>
44+
<div class="hit-info">release date: {{ item.releaseDate }}</div>
4245
</div>
4346
</template>
4447
</ais-hits>
@@ -57,19 +60,19 @@
5760
</template>
5861

5962
<script>
60-
import "instantsearch.css/themes/algolia-min.css";
61-
import instantMeiliSearch from "../../../src/index.js";
63+
import 'instantsearch.css/themes/algolia-min.css'
64+
import instantMeiliSearch from '../../../dist/instant-meilisearch.cjs.js'
6265
6366
export default {
6467
data() {
6568
return {
6669
searchClient: instantMeiliSearch(
67-
"https://demos.meilisearch.com",
68-
"dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25"
69-
)
70-
};
71-
}
72-
};
70+
'https://demos.meilisearch.com',
71+
'dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25'
72+
),
73+
}
74+
},
75+
}
7376
</script>
7477

7578
<style>
@@ -80,8 +83,8 @@ h1 {
8083
}
8184
8285
body {
83-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
84-
Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
86+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
87+
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
8588
}
8689
8790
.ais-Hits-item {
@@ -96,7 +99,8 @@ body {
9699
margin-bottom: 0.5em;
97100
}
98101
99-
.ais-Highlight-highlighted, .ais-Snippet-highlighted {
102+
.ais-Highlight-highlighted,
103+
.ais-Snippet-highlighted {
100104
background: cyan;
101105
font-style: normal;
102106
}
@@ -135,7 +139,7 @@ body {
135139
}
136140
137141
.header-title::after {
138-
content: "";
142+
content: '';
139143
padding: 0 0.5rem;
140144
}
141145

rollup.config.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import commonjs from '@rollup/plugin-commonjs'
12
import nodeResolve from '@rollup/plugin-node-resolve'
23
import { resolve } from 'path'
3-
import commonjs from '@rollup/plugin-commonjs'
44
import babel from 'rollup-plugin-babel'
5-
import pkg from './package.json'
65
import { terser } from 'rollup-plugin-terser'
6+
import typescript from 'rollup-plugin-typescript2'
7+
8+
import pkg from './package.json'
79

810
function getOutputFileName(fileName, isProd = false) {
911
return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName
@@ -13,10 +15,21 @@ const env = process.env.NODE_ENV || 'development'
1315
const LIB_NAME = 'instantMeiliSearch'
1416
const ROOT = resolve(__dirname, '.')
1517

18+
const PLUGINS = [
19+
typescript({
20+
useTsconfigDeclarationDir: true,
21+
tsconfigOverride: {
22+
allowJs: false,
23+
includes: ['src'],
24+
exclude: ['tests', 'examples', '*.js', 'scripts'],
25+
esModuleInterop: true,
26+
},
27+
}),
28+
]
1629
module.exports = [
1730
// browser-friendly IIFE build
1831
{
19-
input: 'src/index.js', // directory to transpilation of typescript
32+
input: 'src/index.ts', // directory to transpilation of typescript
2033
output: {
2134
name: LIB_NAME,
2235
file: getOutputFileName(
@@ -31,6 +44,7 @@ module.exports = [
3144
},
3245
},
3346
plugins: [
47+
...PLUGINS,
3448
nodeResolve({
3549
mainFields: ['jsnext', 'browser', 'main'],
3650
preferBuiltins: true,
@@ -43,7 +57,7 @@ module.exports = [
4357
],
4458
},
4559
{
46-
input: 'src/index.js',
60+
input: 'src/index.ts',
4761
external: ['meilisearch'],
4862
output: [
4963
{
@@ -68,6 +82,7 @@ module.exports = [
6882
],
6983
plugins: [
7084
env === 'production' ? terser() : {}, // will minify the file in production mode
85+
...PLUGINS,
7186
],
7287
},
7388
]

0 commit comments

Comments
 (0)