Skip to content

Commit 717e0ab

Browse files
meili-bors[bot]flevi29brunoocasali
authored
Merge #1271
1271: Re-export `meilisearch` package, and expose created `MeiliSearch` instance r=brunoocasali a=flevi29 # Pull Request ## Related issue Fixes #1260 ## What does this PR do? - exposed created `MeiliSearch` instance - re-exported all of `"meilisearch"` package These improvements make it so that no separate `"meilisearch"` package has to be installed in order to use its exports directly. This way a single `MeiliSearch` instance can be re-used, and we can potentially save on bundle size by avoiding a separate different version installation of `"meilisearch"`. ```typescript import { instantMeiliSearch, meilisearch } from '`@meilisearch/instant-meilisearch'` // re-exported "meilisearch" ^ const { meiliSearchInstance, // ^ re-usable MeiliSearch instance searchClient } = instantMeiliSearch(/*...*/) ``` Co-authored-by: F. Levi <[email protected]> Co-authored-by: Bruno Casali <[email protected]>
2 parents 8bf9016 + ad3c63b commit 717e0ab

File tree

11 files changed

+55
-19
lines changed

11 files changed

+55
-19
lines changed

.changeset/sharp-beds-lie.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
"@meilisearch/instant-meilisearch": minor
3+
---
4+
5+
- exposed created `MeiliSearch` instance
6+
- re-exported all of `"meilisearch"` package
7+
8+
These improvements make it so that no separate `"meilisearch"` package
9+
has to be installed in order to use its exports directly. This
10+
way a single `MeiliSearch` instance can be re-used, and we can potentially
11+
save on bundle size by avoiding a separate different version installation of
12+
`"meilisearch"`.
13+
14+
```typescript
15+
import { instantMeiliSearch, meilisearch } from '@meilisearch/instant-meilisearch'
16+
// re-exported "meilisearch" ^
17+
18+
const {
19+
meiliSearchInstance,
20+
// ^ re-usable MeiliSearch instance
21+
searchClient
22+
} = instantMeiliSearch(/*...*/)
23+
```

packages/autocomplete-client/rollup.config.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { resolve } from 'node:path'
12
import commonjs from '@rollup/plugin-commonjs'
23
import nodeResolve from '@rollup/plugin-node-resolve'
3-
import { resolve } from 'path'
44
import babel from 'rollup-plugin-babel'
55
import { terser } from 'rollup-plugin-terser'
66
import typescript from 'rollup-plugin-typescript2'
@@ -14,7 +14,8 @@ const env = process.env.NODE_ENV || 'development'
1414
const ROOT = resolve(__dirname, '.')
1515
const INPUT = 'src/index.ts'
1616

17-
const PLUGINS = [
17+
/** @type {import('rollup').Plugin[]} */
18+
const COMMON_PLUGINS = [
1819
typescript({
1920
useTsconfigDeclarationDir: true,
2021
tsconfigOverride: {
@@ -31,7 +32,9 @@ const PLUGINS = [
3132
},
3233
}),
3334
]
34-
module.exports = [
35+
36+
/** @type {import('rollup').RollupOptions[]} */
37+
const ROLLUP_OPTIONS = [
3538
// browser-friendly IIFE build
3639
{
3740
input: INPUT, // directory to transpilation of typescript
@@ -47,7 +50,7 @@ module.exports = [
4750
sourcemap: env === 'production', // create sourcemap for error reporting in production mode
4851
},
4952
plugins: [
50-
...PLUGINS,
53+
...COMMON_PLUGINS,
5154
nodeResolve({
5255
mainFields: ['jsnext', 'browser', 'main'],
5356
preferBuiltins: true,
@@ -84,7 +87,9 @@ module.exports = [
8487
],
8588
plugins: [
8689
env === 'production' ? terser() : {}, // will minify the file in production mode
87-
...PLUGINS,
90+
...COMMON_PLUGINS,
8891
],
8992
},
9093
]
94+
95+
module.exports = ROLLUP_OPTIONS

packages/autocomplete-client/scripts/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* This file only purpose is to execute any build related tasks
33
*/
44

5-
const { resolve, normalize } = require('path')
6-
const { readFileSync, writeFileSync } = require('fs')
5+
const { resolve, normalize } = require('node:path')
6+
const { readFileSync, writeFileSync } = require('node:fs')
77
const pkg = require('../package.json')
88

99
const ROOT = resolve(__dirname, '..')

packages/autocomplete-client/scripts/update_version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const pkg = require('../package.json')
2-
const fs = require('fs')
3-
const path = require('path')
2+
const fs = require('node:fs')
3+
const path = require('node:path')
44

55
const version = pkg.version
66
const fileContents = `export const PACKAGE_VERSION = '${version}'

packages/instant-meilisearch/rollup.config.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { resolve } from 'node:path'
12
import commonjs from '@rollup/plugin-commonjs'
23
import nodeResolve from '@rollup/plugin-node-resolve'
3-
import { resolve } from 'path'
44
import babel from 'rollup-plugin-babel'
55
import { terser } from 'rollup-plugin-terser'
66
import typescript from 'rollup-plugin-typescript2'
@@ -14,7 +14,8 @@ const env = process.env.NODE_ENV || 'development'
1414
const ROOT = resolve(__dirname, '.')
1515
const INPUT = 'src/index.ts'
1616

17-
const PLUGINS = [
17+
/** @type {import('rollup').Plugin[]} */
18+
const COMMON_PLUGINS = [
1819
typescript({
1920
useTsconfigDeclarationDir: true,
2021
tsconfigOverride: {
@@ -31,7 +32,9 @@ const PLUGINS = [
3132
},
3233
}),
3334
]
34-
module.exports = [
35+
36+
/** @type {import('rollup').RollupOptions[]} */
37+
const ROLLUP_OPTIONS = [
3538
// browser-friendly IIFE build
3639
{
3740
input: INPUT, // directory to transpilation of typescript
@@ -51,7 +54,7 @@ module.exports = [
5154
},
5255
},
5356
plugins: [
54-
...PLUGINS,
57+
...COMMON_PLUGINS,
5558
nodeResolve({
5659
mainFields: ['jsnext', 'browser', 'main'],
5760
preferBuiltins: true,
@@ -89,7 +92,9 @@ module.exports = [
8992
],
9093
plugins: [
9194
env === 'production' ? terser() : {}, // will minify the file in production mode
92-
...PLUGINS,
95+
...COMMON_PLUGINS,
9396
],
9497
},
9598
]
99+
100+
module.exports = ROLLUP_OPTIONS

packages/instant-meilisearch/scripts/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* This file only purpose is to execute any build related tasks
33
*/
44

5-
const { resolve, normalize } = require('path')
6-
const { readFileSync, writeFileSync } = require('fs')
5+
const { resolve, normalize } = require('node:path')
6+
const { readFileSync, writeFileSync } = require('node:fs')
77
const pkg = require('../package.json')
88

99
const ROOT = resolve(__dirname, '..')

packages/instant-meilisearch/scripts/update_version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const pkg = require('../package.json')
2-
const fs = require('fs')
3-
const path = require('path')
2+
const fs = require('node:fs')
3+
const path = require('node:path')
44

55
const version = pkg.version
66
const fileContents = `export const PACKAGE_VERSION = '${version}'

packages/instant-meilisearch/src/client/instant-meilisearch-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export function instantMeiliSearch(
8181
)
8282

8383
return {
84+
meiliSearchInstance: meilisearchClient,
8485
setMeiliSearchParams: (params): void => {
8586
const { meiliSearchParams } = instantMeiliSearchOptions
8687

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './client'
22
export * from './types'
3+
export * as meilisearch from 'meilisearch'

packages/instant-meilisearch/src/types/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
MultiSearchQuery as MeiliSearchMultiSearchParams,
88
MultiSearchResult,
99
Config as MeilisearchConfig,
10+
MeiliSearch,
1011
} from 'meilisearch'
1112

1213
// Turns readonly types into mutable ones
@@ -128,6 +129,7 @@ export type InstantMeiliSearchInstance = SearchClient & {
128129
}
129130

130131
export type InstantMeiliSearchObject = {
132+
meiliSearchInstance: MeiliSearch
131133
setMeiliSearchParams: (params: OverridableMeiliSearchSearchParameters) => void
132134
searchClient: InstantMeiliSearchInstance
133135
}

0 commit comments

Comments
 (0)