From 234d6994a9589e278e5a726e8381e2a149fc9c1e Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sun, 17 Dec 2023 14:35:42 +0200 Subject: [PATCH 1/2] Exposed created MeiliSearch instance, re-exported all of "meilisearch" package. --- .changeset/sharp-beds-lie.md | 23 +++++++++++++++++++ .../src/client/instant-meilisearch-client.ts | 2 ++ packages/instant-meilisearch/src/index.ts | 1 + .../instant-meilisearch/src/types/types.ts | 2 ++ 4 files changed, 28 insertions(+) create mode 100644 .changeset/sharp-beds-lie.md 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/instant-meilisearch/src/client/instant-meilisearch-client.ts b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts index fa864daa..0d1e44a0 100644 --- a/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts +++ b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts @@ -79,7 +79,9 @@ export function instantMeiliSearch( const instantMeilisearchConfig = getInstantMeilisearchConfig( instantMeiliSearchOptions ) + return { + meiliSearchInstance: meilisearchClient, setMeiliSearchParams: (params): void => { const { meiliSearchParams } = instantMeiliSearchOptions instantMeiliSearchOptions.meiliSearchParams = 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 22bdeffc..4aea43d2 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 @@ -127,6 +128,7 @@ export type InstantMeiliSearchInstance = SearchClient & { } export type InstantMeiliSearchObject = { + meiliSearchInstance: MeiliSearch setMeiliSearchParams: (params: OverridableMeiliSearchSearchParameters) => void searchClient: InstantMeiliSearchInstance } From 1cd081ed218300ef6e94755e12a555530e294dc7 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sun, 17 Dec 2023 14:39:24 +0200 Subject: [PATCH 2/2] Removed redundant "resolveJsonModule" in tsconfig.test.json, as it's already in tsconfig.json which it extends, marked node module imports as explicit ("node:(...)"), added types to some scripts for IDE hints. --- packages/autocomplete-client/rollup.config.js | 15 ++++++++++----- packages/autocomplete-client/scripts/build.js | 4 ++-- .../autocomplete-client/scripts/update_version.js | 4 ++-- packages/instant-meilisearch/rollup.config.js | 15 ++++++++++----- packages/instant-meilisearch/scripts/build.js | 4 ++-- .../instant-meilisearch/scripts/update_version.js | 4 ++-- packages/instant-meilisearch/tsconfig.test.json | 1 - 7 files changed, 28 insertions(+), 19 deletions(-) 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/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": [ "./**/*"