diff --git a/.changeset/sharp-beds-lie.md b/.changeset/sharp-beds-lie.md new file mode 100644 index 00000000..4d3ac5f6 --- /dev/null +++ b/.changeset/sharp-beds-lie.md @@ -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(/*...*/) +``` diff --git a/packages/autocomplete-client/rollup.config.js b/packages/autocomplete-client/rollup.config.js index b910faa4..cdbd8447 100644 --- a/packages/autocomplete-client/rollup.config.js +++ b/packages/autocomplete-client/rollup.config.js @@ -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' @@ -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: { @@ -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 @@ -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, @@ -84,7 +87,9 @@ module.exports = [ ], plugins: [ env === 'production' ? terser() : {}, // will minify the file in production mode - ...PLUGINS, + ...COMMON_PLUGINS, ], }, ] + +module.exports = ROLLUP_OPTIONS diff --git a/packages/autocomplete-client/scripts/build.js b/packages/autocomplete-client/scripts/build.js index ae50a4b8..1df0f396 100644 --- a/packages/autocomplete-client/scripts/build.js +++ b/packages/autocomplete-client/scripts/build.js @@ -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, '..') diff --git a/packages/autocomplete-client/scripts/update_version.js b/packages/autocomplete-client/scripts/update_version.js index c3387635..e184d592 100644 --- a/packages/autocomplete-client/scripts/update_version.js +++ b/packages/autocomplete-client/scripts/update_version.js @@ -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}' diff --git a/packages/instant-meilisearch/rollup.config.js b/packages/instant-meilisearch/rollup.config.js index 0cd596ea..b11ddc4d 100644 --- a/packages/instant-meilisearch/rollup.config.js +++ b/packages/instant-meilisearch/rollup.config.js @@ -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' @@ -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: { @@ -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 @@ -51,7 +54,7 @@ module.exports = [ }, }, plugins: [ - ...PLUGINS, + ...COMMON_PLUGINS, nodeResolve({ mainFields: ['jsnext', 'browser', 'main'], preferBuiltins: true, @@ -89,7 +92,9 @@ module.exports = [ ], plugins: [ env === 'production' ? terser() : {}, // will minify the file in production mode - ...PLUGINS, + ...COMMON_PLUGINS, ], }, ] + +module.exports = ROLLUP_OPTIONS diff --git a/packages/instant-meilisearch/scripts/build.js b/packages/instant-meilisearch/scripts/build.js index ae50a4b8..1df0f396 100644 --- a/packages/instant-meilisearch/scripts/build.js +++ b/packages/instant-meilisearch/scripts/build.js @@ -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, '..') diff --git a/packages/instant-meilisearch/scripts/update_version.js b/packages/instant-meilisearch/scripts/update_version.js index c3387635..e184d592 100644 --- a/packages/instant-meilisearch/scripts/update_version.js +++ b/packages/instant-meilisearch/scripts/update_version.js @@ -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}' diff --git a/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts index 1db62faa..e64a89f0 100644 --- a/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts +++ b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts @@ -81,6 +81,7 @@ export function instantMeiliSearch( ) return { + meiliSearchInstance: meilisearchClient, setMeiliSearchParams: (params): void => { const { meiliSearchParams } = instantMeiliSearchOptions diff --git a/packages/instant-meilisearch/src/index.ts b/packages/instant-meilisearch/src/index.ts index edfed4a6..2b1d1a7a 100644 --- a/packages/instant-meilisearch/src/index.ts +++ b/packages/instant-meilisearch/src/index.ts @@ -1,2 +1,3 @@ export * from './client' export * from './types' +export * as meilisearch from 'meilisearch' diff --git a/packages/instant-meilisearch/src/types/types.ts b/packages/instant-meilisearch/src/types/types.ts index 2f24d581..114638a1 100644 --- a/packages/instant-meilisearch/src/types/types.ts +++ b/packages/instant-meilisearch/src/types/types.ts @@ -7,6 +7,7 @@ import type { MultiSearchQuery as MeiliSearchMultiSearchParams, MultiSearchResult, Config as MeilisearchConfig, + MeiliSearch, } from 'meilisearch' // Turns readonly types into mutable ones @@ -128,6 +129,7 @@ export type InstantMeiliSearchInstance = SearchClient & { } export type InstantMeiliSearchObject = { + meiliSearchInstance: MeiliSearch setMeiliSearchParams: (params: OverridableMeiliSearchSearchParameters) => void searchClient: InstantMeiliSearchInstance } diff --git a/packages/instant-meilisearch/tsconfig.test.json b/packages/instant-meilisearch/tsconfig.test.json index 07da0c60..0ace77c3 100644 --- a/packages/instant-meilisearch/tsconfig.test.json +++ b/packages/instant-meilisearch/tsconfig.test.json @@ -2,7 +2,6 @@ "extends": "./tsconfig.json", "compilerOptions": { "suppressImplicitAnyIndexErrors": true, - "resolveJsonModule": true }, "include": [ "./**/*"