Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export meilisearch package, and expose created MeiliSearch instance #1271

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
brunoocasali marked this conversation as resolved.
Show resolved Hide resolved
// 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')
brunoocasali marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 can you explain that 😅 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already set as true in the tsconfig.json this config file extends:

},
"include": [
"./**/*"
Expand Down
Loading