Skip to content

Commit

Permalink
Merge #1271
Browse files Browse the repository at this point in the history
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 <55688616+flevi29@users.noreply.github.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
  • Loading branch information
3 people committed Feb 27, 2024
2 parents 8bf9016 + ad3c63b commit 717e0ab
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 19 deletions.
23 changes: 23 additions & 0 deletions .changeset/sharp-beds-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@meilisearch/instant-meilisearch": minor
---

- 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(/*...*/)
```
15 changes: 10 additions & 5 deletions packages/autocomplete-client/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path'
import commonjs from '@rollup/plugin-commonjs'
import nodeResolve from '@rollup/plugin-node-resolve'
import { resolve } from 'path'
import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import typescript from 'rollup-plugin-typescript2'
Expand All @@ -14,7 +14,8 @@ const env = process.env.NODE_ENV || 'development'
const ROOT = resolve(__dirname, '.')
const INPUT = 'src/index.ts'

const PLUGINS = [
/** @type {import('rollup').Plugin[]} */
const COMMON_PLUGINS = [
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
Expand All @@ -31,7 +32,9 @@ const PLUGINS = [
},
}),
]
module.exports = [

/** @type {import('rollup').RollupOptions[]} */
const ROLLUP_OPTIONS = [
// browser-friendly IIFE build
{
input: INPUT, // directory to transpilation of typescript
Expand All @@ -47,7 +50,7 @@ module.exports = [
sourcemap: env === 'production', // create sourcemap for error reporting in production mode
},
plugins: [
...PLUGINS,
...COMMON_PLUGINS,
nodeResolve({
mainFields: ['jsnext', 'browser', 'main'],
preferBuiltins: true,
Expand Down Expand Up @@ -84,7 +87,9 @@ module.exports = [
],
plugins: [
env === 'production' ? terser() : {}, // will minify the file in production mode
...PLUGINS,
...COMMON_PLUGINS,
],
},
]

module.exports = ROLLUP_OPTIONS
4 changes: 2 additions & 2 deletions packages/autocomplete-client/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This file only purpose is to execute any build related tasks
*/

const { resolve, normalize } = require('path')
const { readFileSync, writeFileSync } = require('fs')
const { resolve, normalize } = require('node:path')
const { readFileSync, writeFileSync } = require('node:fs')
const pkg = require('../package.json')

const ROOT = resolve(__dirname, '..')
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-client/scripts/update_version.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const pkg = require('../package.json')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

const version = pkg.version
const fileContents = `export const PACKAGE_VERSION = '${version}'
Expand Down
15 changes: 10 additions & 5 deletions packages/instant-meilisearch/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path'
import commonjs from '@rollup/plugin-commonjs'
import nodeResolve from '@rollup/plugin-node-resolve'
import { resolve } from 'path'
import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import typescript from 'rollup-plugin-typescript2'
Expand All @@ -14,7 +14,8 @@ const env = process.env.NODE_ENV || 'development'
const ROOT = resolve(__dirname, '.')
const INPUT = 'src/index.ts'

const PLUGINS = [
/** @type {import('rollup').Plugin[]} */
const COMMON_PLUGINS = [
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
Expand All @@ -31,7 +32,9 @@ const PLUGINS = [
},
}),
]
module.exports = [

/** @type {import('rollup').RollupOptions[]} */
const ROLLUP_OPTIONS = [
// browser-friendly IIFE build
{
input: INPUT, // directory to transpilation of typescript
Expand All @@ -51,7 +54,7 @@ module.exports = [
},
},
plugins: [
...PLUGINS,
...COMMON_PLUGINS,
nodeResolve({
mainFields: ['jsnext', 'browser', 'main'],
preferBuiltins: true,
Expand Down Expand Up @@ -89,7 +92,9 @@ module.exports = [
],
plugins: [
env === 'production' ? terser() : {}, // will minify the file in production mode
...PLUGINS,
...COMMON_PLUGINS,
],
},
]

module.exports = ROLLUP_OPTIONS
4 changes: 2 additions & 2 deletions packages/instant-meilisearch/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This file only purpose is to execute any build related tasks
*/

const { resolve, normalize } = require('path')
const { readFileSync, writeFileSync } = require('fs')
const { resolve, normalize } = require('node:path')
const { readFileSync, writeFileSync } = require('node:fs')
const pkg = require('../package.json')

const ROOT = resolve(__dirname, '..')
Expand Down
4 changes: 2 additions & 2 deletions packages/instant-meilisearch/scripts/update_version.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const pkg = require('../package.json')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

const version = pkg.version
const fileContents = `export const PACKAGE_VERSION = '${version}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function instantMeiliSearch(
)

return {
meiliSearchInstance: meilisearchClient,
setMeiliSearchParams: (params): void => {
const { meiliSearchParams } = instantMeiliSearchOptions

Expand Down
1 change: 1 addition & 0 deletions packages/instant-meilisearch/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './client'
export * from './types'
export * as meilisearch from 'meilisearch'
2 changes: 2 additions & 0 deletions packages/instant-meilisearch/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
MultiSearchQuery as MeiliSearchMultiSearchParams,
MultiSearchResult,
Config as MeilisearchConfig,
MeiliSearch,
} from 'meilisearch'

// Turns readonly types into mutable ones
Expand Down Expand Up @@ -128,6 +129,7 @@ export type InstantMeiliSearchInstance = SearchClient & {
}

export type InstantMeiliSearchObject = {
meiliSearchInstance: MeiliSearch
setMeiliSearchParams: (params: OverridableMeiliSearchSearchParameters) => void
searchClient: InstantMeiliSearchInstance
}
Expand Down
1 change: 0 additions & 1 deletion packages/instant-meilisearch/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"suppressImplicitAnyIndexErrors": true,
"resolveJsonModule": true
},
"include": [
"./**/*"
Expand Down

0 comments on commit 717e0ab

Please sign in to comment.