diff --git a/.changeset/bright-rabbits-juggle.md b/.changeset/bright-rabbits-juggle.md new file mode 100644 index 00000000..354b9a0f --- /dev/null +++ b/.changeset/bright-rabbits-juggle.md @@ -0,0 +1,7 @@ +--- +"@meilisearch/autocomplete-client": minor +"@meilisearch/instant-meilisearch": minor +"eslint-config-meilisearch": patch +--- + +Change tester from Jest to Vitest. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b1c854d4..146a1623 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ yarn --dev Each PR should pass the tests and the linter to be accepted. ```bash -# Tests with Jest +# Tests with Vitest docker pull getmeili/meilisearch:latest # Fetch the latest version of Meilisearch image from Docker Hub docker run -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics # Integration tests diff --git a/package.json b/package.json index db1c148b..d79360e3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,4 @@ { - "name": "root", "private": true, "license": "MIT", "repository": { @@ -10,43 +9,45 @@ "packages/*", "playgrounds/*" ], + "type": "module", "scripts": { - "playground:geosearch": "turbo run dev --filter=@meilisearch/geo-playground --parallel", - "playground:vanilla": "turbo run dev --filter=@meilisearch/vanilla-playground --parallel", - "playground:vue3": "turbo run dev --filter=@meilisearch/vue3-ts-playground --parallel", - "playground:react": "turbo run dev --filter=@meilisearch/react-playground --parallel", - "playground:local-react": "turbo run dev --filter=@meilisearch/local-react-playground --parallel", - "playground:node": "turbo run dev --filter=@meilisearch/node-playground --parallel", - "playground:autocomplete": "turbo run dev --filter=@meilisearch/autocomplete-playground --parallel", - "test:e2e": "turbo run test:e2e", - "test:e2e:watch": "turbo run test:e2e:watch", + "playground:geosearch": "turbo @meilisearch/geo-playground#dev", + "playground:vanilla": "turbo @meilisearch/vanilla-playground#dev", + "playground:vue3": "turbo @meilisearch/vue3-ts-playground#dev", + "playground:react": "turbo @meilisearch/react-playground#dev", + "playground:local-react": "turbo @meilisearch/local-react-playground#dev", + "playground:node": "turbo @meilisearch/node-playground#dev", + "playground:autocomplete": "turbo @meilisearch/autocomplete-playground#dev", + "test:e2e": "turbo test:e2e", + "test:e2e:watch": "turbo test:e2e:watch", "lint": "turbo lint", "lint:fix": "turbo lint:fix", - "build": "turbo run build", - "test": "turbo test", - "test:watch": "turbo run test:watch", - "instant-meilisearch:test:watch": "yarn --cwd ./packages/instant-meilisearch test:watch", - "autocomplete:test:watch": "yarn --cwd ./packages/autocomplete-client test:watch", - "test:types": "turbo run test:types", + "build": "turbo build", + "test": "yarn build && vitest run", + "test:watch": "yarn build && vitest", + "instant-meilisearch:test:watch": "vitest --project \"@meilisearch/instant-meilisearch\"", + "autocomplete:test:watch": "vitest --project \"@meilisearch/autocomplete-client\"", + "test:types": "yarn build && tsc --noEmit", "version-packages": "changeset version && turbo version", "release": "yarn build && changeset publish" }, - "devDependencies": { - "@testing-library/dom": "^9.2.0", - "@testing-library/jest-dom": "^5.16.5", - "@types/jest": "^29.5.1", - "@types/jest-diff": "^24.3.0", - "parcel": "^2.12.0", - "turbo": "^2.1.3" - }, "dependencies": { - "@changesets/cli": "^2.26.1", - "instantsearch.css": "^8.0.0" + "instantsearch.css": "^8.5.1" }, - "alias": { - "node:crypto": false, - "node:buffer": false, - "node:process": false + "devDependencies": { + "prettier": "^3.4.2", + "vite": "^6.0.9", + "@vitest/coverage-v8": "^3.0.2", + "concurrently": "^9.1.2", + "vitest": "^3.0.2", + "cypress": "^8.6.0", + "turbo": "^2.3.3", + "algoliasearch-helper": "^3.23.0", + "@changesets/cli": "^2.26.1", + "typescript": "^5.7.3", + "@algolia/client-search": "^5.19.0", + "algoliasearch": "^5.19.0", + "search-insights": "^2.17.3" }, "packageManager": "yarn@1.22.22" } diff --git a/packages/autocomplete-client/.babelrc b/packages/autocomplete-client/.babelrc deleted file mode 100644 index 394c5435..00000000 --- a/packages/autocomplete-client/.babelrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "targets": { - "node": "current" - } - } - ] - ] -} diff --git a/packages/autocomplete-client/.eslintrc.js b/packages/autocomplete-client/.eslintrc.cjs similarity index 100% rename from packages/autocomplete-client/.eslintrc.js rename to packages/autocomplete-client/.eslintrc.cjs diff --git a/packages/autocomplete-client/__tests__/test.utils.ts b/packages/autocomplete-client/__tests__/test.utils.ts index 1a306b4d..0e89a762 100644 --- a/packages/autocomplete-client/__tests__/test.utils.ts +++ b/packages/autocomplete-client/__tests__/test.utils.ts @@ -1,4 +1,4 @@ -import { meilisearchAutocompleteClient } from '../src' +import { meilisearchAutocompleteClient } from '../src/index.js' import { MeiliSearch } from 'meilisearch' const dataset = [ diff --git a/packages/autocomplete-client/jest.config.js b/packages/autocomplete-client/jest.config.js deleted file mode 100644 index b1b505bb..00000000 --- a/packages/autocomplete-client/jest.config.js +++ /dev/null @@ -1,34 +0,0 @@ -const ignoreFiles = ['(/.*)*/assets', 'test.utils'] - -module.exports = { - verbose: true, - watchPlugins: [ - 'jest-watch-typeahead/filename', - 'jest-watch-typeahead/testname', - ], - collectCoverage: true, - setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'], - projects: [ - { - globals: { - 'ts-jest': { tsconfig: 'tsconfig.test.json' }, - fetch: globalThis.fetch, - }, - preset: 'ts-jest', - displayName: 'dom', - testPathIgnorePatterns: [...ignoreFiles], - coveragePathIgnorePatterns: ['(/.*)*/assets/'], - }, - { - globals: { - 'ts-jest': { tsconfig: 'tsconfig.test.json' }, - fetch: globalThis.fetch, - }, - preset: 'ts-jest', - displayName: 'node', - testEnvironment: 'node', - coveragePathIgnorePatterns: ['(/.*)*/assets/'], - testPathIgnorePatterns: [...ignoreFiles], - }, - ], -} diff --git a/packages/autocomplete-client/package.json b/packages/autocomplete-client/package.json index 6f247aca..949dc58a 100644 --- a/packages/autocomplete-client/package.json +++ b/packages/autocomplete-client/package.json @@ -1,31 +1,27 @@ { "name": "@meilisearch/autocomplete-client", "version": "0.5.0", - "private": false, "description": "The search client to use Meilisearch with autocomplete.js.", "homepage": "https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/autocomplete-client", "publishConfig": { "access": "public" }, "scripts": { - "clear_jest": "jest --clearCache", - "cleanup": "shx rm -rf dist/", - "test:watch": "yarn test --watchAll", - "test": "jest --runInBand --selectProjects dom --selectProjects node", - "build": "yarn cleanup && rollup -c rollup.config.js && rollup --environment NODE_ENV:production -c rollup.config.js", - "dev": "rollup -c rollup.config.js --watch", + "build": "vite build && tsc -p tsconfig.json", "lint": "eslint --ext .js,.ts,.tsx .", "lint:fix": "eslint --ext .js,.ts,.tsx . --fix", - "test:types": "yarn tsc", - "version": "node scripts/update_version.js" + "version": "node scripts/update_version.cjs" }, - "main": "./dist/autocomplete-client.umd.js", - "module": "./dist/autocomplete-client.esm.js", - "browser": "./dist/autocomplete-client.umd.js", - "cjs": "./dist/autocomplete-client.cjs.js", - "source": "src/index.ts", - "typings": "./dist/types/index.d.ts", + "type": "module", "types": "./dist/types/index.d.ts", + "main": "./dist/umd/index.min.js", + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "default": "./dist/umd/index.min.js" + } + }, "sideEffects": false, "bugs": { "url": "https://github.com/meilisearch/meilisearch-js-plugins/issues" @@ -51,28 +47,8 @@ }, "devDependencies": { "@algolia/autocomplete-js": "^1.7.4", - "@babel/cli": "^7.22.9", - "@babel/core": "^7.20.5", - "@babel/preset-env": "^7.20.2", - "@rollup/plugin-commonjs": "^17.1.0", - "@rollup/plugin-node-resolve": "^11.2.0", - "@types/jest": "^27.0.2", - "babel-jest": "^27.2.2", - "concurrently": "^7.1.0", "cssnano": "^4.1.10", "eslint-config-meilisearch": "*", - "instantsearch.js": "^4.56.2", - "jest": "^27.2.2", - "jest-watch-typeahead": "^0.6.3", - "regenerator-runtime": "^0.13.7", - "rollup": "^2.79.2", - "rollup-plugin-babel": "^4.4.0", - "rollup-plugin-node-polyfills": "^0.2.1", - "rollup-plugin-terser": "^7.0.0", - "rollup-plugin-typescript2": "^0.32.1", - "shx": "^0.3.4", - "ts-jest": "^27.0.7", - "tslib": "^2.6.1", - "typescript": "^4.9.3" + "instantsearch.js": "^4.56.2" } } diff --git a/packages/autocomplete-client/rollup.config.js b/packages/autocomplete-client/rollup.config.js deleted file mode 100644 index 55b2bd5d..00000000 --- a/packages/autocomplete-client/rollup.config.js +++ /dev/null @@ -1,91 +0,0 @@ -import { resolve } from 'node:path' -import commonjs from '@rollup/plugin-commonjs' -import nodeResolve from '@rollup/plugin-node-resolve' -import babel from 'rollup-plugin-babel' -import { terser } from 'rollup-plugin-terser' -import typescript from 'rollup-plugin-typescript2' -import pkg from './package.json' - -function getOutputFileName(fileName, isProd = false) { - return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName -} - -const env = process.env.NODE_ENV || 'development' -const ROOT = resolve(__dirname, '.') -const INPUT = 'src/index.ts' - -/** @type {import('rollup').Plugin[]} */ -const COMMON_PLUGINS = [ - typescript({ - useTsconfigDeclarationDir: true, - tsconfigOverride: { - includes: ['src'], - exclude: [ - 'tests', - '*.js', - 'scripts', - '**/__tests__/*.ts', - 'playgrounds', - 'dist', - ], - esModuleInterop: true, - }, - }), -] - -/** @type {import('rollup').RollupOptions[]} */ -const ROLLUP_OPTIONS = [ - // browser-friendly IIFE build - { - input: INPUT, // directory to transpilation of typescript - output: { - name: '@meilisearch/autocomplete-client', - extend: true, - file: getOutputFileName( - // will add .min. in filename if in production env - resolve(ROOT, pkg.browser), - env === 'production' - ), - format: 'umd', - sourcemap: env === 'production', // create sourcemap for error reporting in production mode - }, - plugins: [ - ...COMMON_PLUGINS, - nodeResolve({ exportConditions: ['browser'] }), - commonjs(), - babel(), - env === 'production' ? terser() : {}, // will minify the file in production mode - ], - }, - { - input: INPUT, - external: ['@meilisearch/instant-meilisearch'], - output: [ - { - file: getOutputFileName( - // will add .min. in filename if in production env - resolve(ROOT, pkg.cjs), - env === 'production' - ), - exports: 'named', - format: 'cjs', - sourcemap: env === 'production', // create sourcemap for error reporting in production mode - }, - { - file: getOutputFileName( - resolve(ROOT, pkg.module), - env === 'production' - ), - exports: 'named', - format: 'es', - sourcemap: env === 'production', // create sourcemap for error reporting in production mode - }, - ], - plugins: [ - env === 'production' ? terser() : {}, // will minify the file in production mode - ...COMMON_PLUGINS, - ], - }, -] - -module.exports = ROLLUP_OPTIONS diff --git a/packages/autocomplete-client/scripts/build.js b/packages/autocomplete-client/scripts/build.js deleted file mode 100644 index 1df0f396..00000000 --- a/packages/autocomplete-client/scripts/build.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * This file only purpose is to execute any build related tasks - */ - -const { resolve, normalize } = require('node:path') -const { readFileSync, writeFileSync } = require('node:fs') -const pkg = require('../package.json') - -const ROOT = resolve(__dirname, '..') -const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.typings)) - -main() - -function main() { - writeDtsHeader() -} - -function writeDtsHeader() { - const dtsHeader = getDtsHeader( - pkg.name, - pkg.version, - pkg.author, - pkg.repository.url, - pkg.devDependencies.typescript - ) - - prependFileSync(TYPES_ROOT_FILE, dtsHeader) -} - -/** - * - * @param {string} pkgName - * @param {string} version - * @param {string} author - * @param {string} repoUrl - * @param {string} tsVersion - */ -function getDtsHeader(pkgName, version, author, repoUrl, tsVersion) { - const extractUserName = repoUrl.match(/\.com\/([\w-]+)\/\w+/i) - const githubUserUrl = extractUserName ? extractUserName[1] : 'Unknown' - - return ` -// Type definitions for ${pkgName} ${version} -// Project: ${repoUrl} -// Definitions by: ${author} -// Definitions: ${repoUrl} -// TypeScript Version: ${tsVersion} -`.replace(/^\s+/gm, '') -} - -/** - * - * @param {string} path - * @param {string | Blob} data - */ -function prependFileSync(path, data) { - const existingFileContent = readFileSync(path, { - encoding: 'utf8', - }) - const newFileContent = [data, existingFileContent].join('\n') - writeFileSync(path, newFileContent, { - flag: 'w+', - encoding: 'utf8', - }) -} diff --git a/packages/autocomplete-client/scripts/update_version.js b/packages/autocomplete-client/scripts/update_version.cjs similarity index 100% rename from packages/autocomplete-client/scripts/update_version.js rename to packages/autocomplete-client/scripts/update_version.cjs diff --git a/packages/autocomplete-client/src/client/autocompleteSearchClient.ts b/packages/autocomplete-client/src/client/autocompleteSearchClient.ts index 37910598..9edbd2be 100644 --- a/packages/autocomplete-client/src/client/autocompleteSearchClient.ts +++ b/packages/autocomplete-client/src/client/autocompleteSearchClient.ts @@ -1,5 +1,5 @@ -import { PACKAGE_VERSION } from '../package-version' -import { createSearchClient } from './createSearchClient' +import { PACKAGE_VERSION } from '../package-version.js' +import { createSearchClient } from './createSearchClient.js' /** * Create searchClient instance for autocomplete diff --git a/packages/autocomplete-client/src/client/createSearchClient.ts b/packages/autocomplete-client/src/client/createSearchClient.ts index 9536d300..e1d2bce8 100644 --- a/packages/autocomplete-client/src/client/createSearchClient.ts +++ b/packages/autocomplete-client/src/client/createSearchClient.ts @@ -1,6 +1,6 @@ import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' -import { SearchClient } from '../types/SearchClient' -import { ClientConfig } from '../types/ClientConfig' +import type { SearchClient } from '../types/SearchClient.js' +import type { ClientConfig } from '../types/ClientConfig.js' export const concatUserAgents = (clientAgents: string[]): string[] => { return clientAgents.concat(clientAgents.filter((agent) => agent)) diff --git a/packages/autocomplete-client/src/client/index.ts b/packages/autocomplete-client/src/client/index.ts index 779c9999..2e0eb511 100644 --- a/packages/autocomplete-client/src/client/index.ts +++ b/packages/autocomplete-client/src/client/index.ts @@ -1,2 +1,2 @@ -export * from './autocompleteSearchClient' -export * from './createSearchClient' +export * from './autocompleteSearchClient.js' +export * from './createSearchClient.js' diff --git a/packages/autocomplete-client/src/index.ts b/packages/autocomplete-client/src/index.ts index 73d7aba3..98779a84 100644 --- a/packages/autocomplete-client/src/index.ts +++ b/packages/autocomplete-client/src/index.ts @@ -1,4 +1,4 @@ export * from '@meilisearch/instant-meilisearch' -export * from './client' -export * from './requesters' -export * from './search' +export * from './client/index.js' +export * from './requesters/index.js' +export * from './search/index.js' diff --git a/packages/autocomplete-client/src/requesters/__tests__/getmeilisearchResults.test.ts b/packages/autocomplete-client/src/requesters/__tests__/getmeilisearchResults.test.ts index 0583be3b..7e26e2e4 100644 --- a/packages/autocomplete-client/src/requesters/__tests__/getmeilisearchResults.test.ts +++ b/packages/autocomplete-client/src/requesters/__tests__/getmeilisearchResults.test.ts @@ -1,5 +1,6 @@ -import { getMeilisearchResults } from '../' -import { searchClient } from '../../../__tests__/test.utils' +import { describe, test, expect } from 'vitest' +import { getMeilisearchResults } from '../index.js' +import { searchClient } from '../../../__tests__/test.utils.js' describe('getMeilisearchResults', () => { test('the the fields in the returned description object', () => { diff --git a/packages/autocomplete-client/src/requesters/createMeilisearchRequester.ts b/packages/autocomplete-client/src/requesters/createMeilisearchRequester.ts index c6f0a348..de906960 100644 --- a/packages/autocomplete-client/src/requesters/createMeilisearchRequester.ts +++ b/packages/autocomplete-client/src/requesters/createMeilisearchRequester.ts @@ -1,6 +1,6 @@ -import { fetchMeilisearchResults } from '../search' +import { fetchMeilisearchResults } from '../search/index.js' -import { createRequester } from './createRequester' +import { createRequester } from './createRequester.js' export const createMeilisearchRequester = createRequester( (params) => fetchMeilisearchResults(params), diff --git a/packages/autocomplete-client/src/requesters/createRequester.ts b/packages/autocomplete-client/src/requesters/createRequester.ts index 2b09b324..1e2b75af 100644 --- a/packages/autocomplete-client/src/requesters/createRequester.ts +++ b/packages/autocomplete-client/src/requesters/createRequester.ts @@ -1,10 +1,10 @@ -import { fetchMeilisearchResults } from '../search' -import { +import { fetchMeilisearchResults } from '../search/index.js' +import type { AlgoliaMultipleQueriesQuery, AlgoliaSearchResponse, AlgoliaSearchForFacetValuesResponse, } from '@meilisearch/instant-meilisearch' -import { SearchClient as MeilisearchClient } from '../types/SearchClient' +import type { SearchClient as MeilisearchClient } from '../types/SearchClient.js' // All types copied from: autocomplete/packages/autocomplete-preset-algolia/src/requester/createRequester.ts // As most of the types are not exported and we need to be able to provide our own Fetcher diff --git a/packages/autocomplete-client/src/requesters/getMeilisearchResults.ts b/packages/autocomplete-client/src/requesters/getMeilisearchResults.ts index 4b6ad7f9..be8217b6 100644 --- a/packages/autocomplete-client/src/requesters/getMeilisearchResults.ts +++ b/packages/autocomplete-client/src/requesters/getMeilisearchResults.ts @@ -1,4 +1,4 @@ -import { createMeilisearchRequester } from './createMeilisearchRequester' +import { createMeilisearchRequester } from './createMeilisearchRequester.js' /** * Retrieves Meilisearch results from multiple indexes. diff --git a/packages/autocomplete-client/src/requesters/index.ts b/packages/autocomplete-client/src/requesters/index.ts index b4170707..d555c430 100644 --- a/packages/autocomplete-client/src/requesters/index.ts +++ b/packages/autocomplete-client/src/requesters/index.ts @@ -1,3 +1,3 @@ -export * from './createMeilisearchRequester' -export * from './createRequester' -export * from './getMeilisearchResults' +export * from './createMeilisearchRequester.js' +export * from './createRequester.js' +export * from './getMeilisearchResults.js' diff --git a/packages/autocomplete-client/src/search/__tests__/fetchMeilisearchResults.test.ts b/packages/autocomplete-client/src/search/__tests__/fetchMeilisearchResults.test.ts index 8ced9f1a..1a409711 100644 --- a/packages/autocomplete-client/src/search/__tests__/fetchMeilisearchResults.test.ts +++ b/packages/autocomplete-client/src/search/__tests__/fetchMeilisearchResults.test.ts @@ -1,9 +1,10 @@ -import { fetchMeilisearchResults } from '../fetchMeilisearchResults' +import { describe, beforeAll, test, expect, afterAll } from 'vitest' +import { fetchMeilisearchResults } from '../fetchMeilisearchResults.js' import { searchClient, MOVIES, meilisearchClient, -} from '../../../__tests__/test.utils' +} from '../../../__tests__/test.utils.js' type Movie = (typeof MOVIES)[number] diff --git a/packages/autocomplete-client/src/search/fetchMeilisearchResults.ts b/packages/autocomplete-client/src/search/fetchMeilisearchResults.ts index ebb7751e..31f776d1 100644 --- a/packages/autocomplete-client/src/search/fetchMeilisearchResults.ts +++ b/packages/autocomplete-client/src/search/fetchMeilisearchResults.ts @@ -1,4 +1,4 @@ -import { +import type { AlgoliaMultipleQueriesQuery, AlgoliaSearchResponse, } from '@meilisearch/instant-meilisearch' @@ -6,9 +6,9 @@ import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG, HITS_PER_PAGE, -} from '../constants' -import { SearchClient as MeilisearchSearchClient } from '../types/SearchClient' -import { HighlightResult } from 'instantsearch.js/es/types/algoliasearch' +} from '../constants/index.js' +import type { SearchClient as MeilisearchSearchClient } from '../types/SearchClient.js' +import type { HighlightResult } from 'algoliasearch-helper/types/algoliasearch.js' interface SearchParams { /** diff --git a/packages/autocomplete-client/src/search/index.ts b/packages/autocomplete-client/src/search/index.ts index d12778d9..258c2cda 100644 --- a/packages/autocomplete-client/src/search/index.ts +++ b/packages/autocomplete-client/src/search/index.ts @@ -1 +1 @@ -export * from './fetchMeilisearchResults' +export * from './fetchMeilisearchResults.js' diff --git a/packages/autocomplete-client/src/types/ClientConfig.ts b/packages/autocomplete-client/src/types/ClientConfig.ts index 899d5daf..43672916 100644 --- a/packages/autocomplete-client/src/types/ClientConfig.ts +++ b/packages/autocomplete-client/src/types/ClientConfig.ts @@ -1,5 +1,5 @@ import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' -import { MeilisearchOptions } from './MeilisearchOptions' +import type { MeilisearchOptions } from './MeilisearchOptions.js' export type InstantMeilisearch = typeof instantMeiliSearch export type MeilisearchURL = Parameters[0] diff --git a/packages/autocomplete-client/src/types/MeilisearchOptions.ts b/packages/autocomplete-client/src/types/MeilisearchOptions.ts index 8f872a87..3eca86e7 100644 --- a/packages/autocomplete-client/src/types/MeilisearchOptions.ts +++ b/packages/autocomplete-client/src/types/MeilisearchOptions.ts @@ -1,3 +1,3 @@ -import { InstantMeiliSearchOptions } from '@meilisearch/instant-meilisearch' +import type { InstantMeiliSearchOptions } from '@meilisearch/instant-meilisearch' export type MeilisearchOptions = InstantMeiliSearchOptions diff --git a/packages/autocomplete-client/src/types/SearchClient.ts b/packages/autocomplete-client/src/types/SearchClient.ts index 4ceda0d9..3056136a 100644 --- a/packages/autocomplete-client/src/types/SearchClient.ts +++ b/packages/autocomplete-client/src/types/SearchClient.ts @@ -1,3 +1,3 @@ -import { InstantMeiliSearchInstance } from '@meilisearch/instant-meilisearch' +import type { InstantMeiliSearchInstance } from '@meilisearch/instant-meilisearch' export type SearchClient = InstantMeiliSearchInstance diff --git a/packages/autocomplete-client/tsconfig.eslint.json b/packages/autocomplete-client/tsconfig.eslint.json deleted file mode 100644 index ab3c206a..00000000 --- a/packages/autocomplete-client/tsconfig.eslint.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["**/*.ts", "**/*.js"] -} diff --git a/packages/autocomplete-client/tsconfig.json b/packages/autocomplete-client/tsconfig.json index 653db3e5..f8e515ca 100644 --- a/packages/autocomplete-client/tsconfig.json +++ b/packages/autocomplete-client/tsconfig.json @@ -1,28 +1,9 @@ { + "extends": "../../tsconfig.json", "compilerOptions": { - "module": "esnext", - "noEmit": true, - "allowJs": false, - "removeComments": false, - "declaration": true, - "declarationMap": true, - "declarationDir": "./dist/types", - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "moduleResolution": "node", - "lib": [ - "ES2019", - "ESNext", - "dom" - ], - "importHelpers": true, - // Enforced typing rules - "strict": true, - "alwaysStrict": true, - "noImplicitReturns": true, - "forceConsistentCasingInFileNames": true, - "noUnusedParameters": true, - "isolatedModules": true + "outDir": "./dist/esm", + "declarationDir": "dist/types" }, - "include": ["src/**/*.ts", "src/**/*.d.ts"], + "include": ["src/**/*.ts"], + "exclude": ["src/**/*.test.ts"] } diff --git a/packages/autocomplete-client/tsconfig.test.json b/packages/autocomplete-client/tsconfig.test.json deleted file mode 100644 index 2b8cc371..00000000 --- a/packages/autocomplete-client/tsconfig.test.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "suppressImplicitAnyIndexErrors": true, - "resolveJsonModule": true - }, - "include": [ - "./**/*" - ] -} diff --git a/packages/autocomplete-client/vite.config.ts b/packages/autocomplete-client/vite.config.ts new file mode 100644 index 00000000..ed53a3e3 --- /dev/null +++ b/packages/autocomplete-client/vite.config.ts @@ -0,0 +1,43 @@ +import { defineProject } from 'vitest/config'; +import pkg from './package.json' with { type: 'json' }; + +const globalVarName = pkg.name + .substring(pkg.name.lastIndexOf('/') + 1) + .replace(/-./g, (x) => x[1].toUpperCase()); + +export default defineProject({ + build: { + sourcemap: true, + target: 'es6', + lib: { + entry: 'src/index.ts', + name: globalVarName, + formats: ['umd'], + fileName: (format, entryName) => { + switch (format) { + case 'umd': + return `umd/${entryName}.min.js`; + default: + throw new Error(`unsupported format ${format}`); + } + }, + }, + // the following code enables Vite in UMD mode to extend the global object with all of + // the exports, and not just a property of it ( https://github.com/vitejs/vite/issues/11624 ) + rollupOptions: { + output: { + footer: `(function () { + if (typeof self !== "undefined") { + var clonedGlobal = Object.assign({}, self.${globalVarName}); + delete clonedGlobal.default; + Object.assign(self, clonedGlobal); + } + })();`, + }, + }, + }, + test: { + include: ['{src,__tests__}/**/*.test.ts'], + testTimeout: 100_000, // 100 seconds + }, +}); diff --git a/packages/eslint-config-meilisearch/.eslintrc.js b/packages/eslint-config-meilisearch/.eslintrc.cjs similarity index 100% rename from packages/eslint-config-meilisearch/.eslintrc.js rename to packages/eslint-config-meilisearch/.eslintrc.cjs diff --git a/packages/eslint-config-meilisearch/index.js b/packages/eslint-config-meilisearch/index.cjs similarity index 84% rename from packages/eslint-config-meilisearch/index.js rename to packages/eslint-config-meilisearch/index.cjs index 086c38c6..7f7e3fc0 100644 --- a/packages/eslint-config-meilisearch/index.js +++ b/packages/eslint-config-meilisearch/index.cjs @@ -12,7 +12,6 @@ module.exports = { commonjs: true, // Needed to avoid import is reserved error node: true, browser: true, - jest: true, }, parser: 'babel-eslint', extends: [ @@ -46,17 +45,11 @@ module.exports = { env: { browser: true, es2020: true, - 'jest/globals': true, node: true, - jasmine: true, }, globals: { instantsearch: true, instantMeiliSearch: true, - page: true, // for jest/puppeteer tests in tests/env/express - browser: true, // for jest/puppeteer tests in tests/env/express - context: true, // for jest/puppeteer tests in tests/env/express - jestPuppeteer: true, // for jest/puppeteer tests in tests/env/express }, extends: [ 'standard', @@ -64,7 +57,6 @@ module.exports = { 'eslint:recommended', 'plugin:cypress/recommended', ], - plugins: ['jest'], parserOptions: { ecmaVersion: 2020, }, @@ -111,14 +103,6 @@ module.exports = { env: { browser: true, es2020: true, - 'jest/globals': true, - jasmine: true, - }, - globals: { - page: true, // for jest/puppeteer tests in tests/env/express - browser: true, // for jest/puppeteer tests in tests/env/express - context: true, // for jest/puppeteer tests in tests/env/express - jestPuppeteer: true, // for jest/puppeteer tests in tests/env/express }, extends: [ 'standard', @@ -134,7 +118,7 @@ module.exports = { projectFolderIgnoreList: ['dist'], }, - plugins: ['jsdoc', '@typescript-eslint', 'jest'], + plugins: ['jsdoc', '@typescript-eslint'], rules: { '@typescript-eslint/no-empty-interface': 'off', // Due to vue-instantsearch not having typings 'no-dupe-class-members': 'off', // Off due to conflict with typescript overload functions diff --git a/packages/eslint-config-meilisearch/package.json b/packages/eslint-config-meilisearch/package.json index 7729a1bb..9b01e484 100644 --- a/packages/eslint-config-meilisearch/package.json +++ b/packages/eslint-config-meilisearch/package.json @@ -4,6 +4,7 @@ "main": "index.js", "license": "MIT", "private": true, + "type": "module", "scripts": { "lint": "eslint --ext .js ." }, @@ -18,15 +19,12 @@ "eslint-config-standard": "^17.0.0", "eslint-plugin-cypress": "^2.11.3", "eslint-plugin-import": "^2.27.5", - "eslint-plugin-jest": "^24.1.5", "eslint-plugin-jsdoc": "^32.2.0", "eslint-plugin-n": "^15.6.1", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-promise": "^6.1.1", "eslint-plugin-react": "^7.22.0", "eslint-plugin-standard": "^5.0.0", - "eslint-plugin-vue": "^7.7.0", - "prettier": "^2.8.3", - "typescript": "^4.9.5" + "eslint-plugin-vue": "^7.7.0" } } diff --git a/packages/eslint-config-meilisearch/prettier.js b/packages/eslint-config-meilisearch/prettier.js index 9ddcd86a..1633d03e 100644 --- a/packages/eslint-config-meilisearch/prettier.js +++ b/packages/eslint-config-meilisearch/prettier.js @@ -1,4 +1,4 @@ -module.exports = { +export default { singleQuote: true, arrowParens: 'always', semi: false, diff --git a/packages/instant-meilisearch/.babelrc b/packages/instant-meilisearch/.babelrc deleted file mode 100644 index 394c5435..00000000 --- a/packages/instant-meilisearch/.babelrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "targets": { - "node": "current" - } - } - ] - ] -} diff --git a/packages/instant-meilisearch/.eslintrc.js b/packages/instant-meilisearch/.eslintrc.cjs similarity index 100% rename from packages/instant-meilisearch/.eslintrc.js rename to packages/instant-meilisearch/.eslintrc.cjs diff --git a/packages/instant-meilisearch/__tests__/assets/utils.ts b/packages/instant-meilisearch/__tests__/assets/utils.ts index 4edbc541..5e952a12 100644 --- a/packages/instant-meilisearch/__tests__/assets/utils.ts +++ b/packages/instant-meilisearch/__tests__/assets/utils.ts @@ -1,4 +1,4 @@ -import { instantMeiliSearch } from '../../src' +import { instantMeiliSearch } from '../../src/index.js' import { MeiliSearch } from 'meilisearch' const HOST = 'http://localhost:7700' diff --git a/packages/instant-meilisearch/__tests__/configure.attributes-to-retrieve.test.ts b/packages/instant-meilisearch/__tests__/configure.attributes-to-retrieve.test.ts index 99726cf7..c6fb5adc 100644 --- a/packages/instant-meilisearch/__tests__/configure.attributes-to-retrieve.test.ts +++ b/packages/instant-meilisearch/__tests__/configure.attributes-to-retrieve.test.ts @@ -1,9 +1,10 @@ +import { describe, beforeAll, test, expect } from 'vitest' import { searchClient, dataset, - Movies, + type Movies, meilisearchClient, -} from './assets/utils' +} from './assets/utils.js' describe('Instant Meilisearch Browser test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/custom-http-client.test.ts b/packages/instant-meilisearch/__tests__/custom-http-client.test.ts index d6487190..abc386ba 100644 --- a/packages/instant-meilisearch/__tests__/custom-http-client.test.ts +++ b/packages/instant-meilisearch/__tests__/custom-http-client.test.ts @@ -1,5 +1,6 @@ -import { instantMeiliSearch } from '../src' -import { meilisearchClient, dataset } from './assets/utils' +import { describe, beforeAll, test, expect, vi } from 'vitest' +import { instantMeiliSearch } from '../src/index.js' +import { meilisearchClient, dataset } from './assets/utils.js' describe('Custom HTTP client tests', () => { beforeAll(async () => { @@ -13,7 +14,7 @@ describe('Custom HTTP client tests', () => { }) test('a custom HTTP client', async () => { - const httpClient = jest.fn(async (url: string, init?: RequestInit) => { + const httpClient = vi.fn(async (url: string, init?: RequestInit) => { const result = await fetch(url, init) return await result.json() }) diff --git a/packages/instant-meilisearch/__tests__/disjunctive-facet-search.test.ts b/packages/instant-meilisearch/__tests__/disjunctive-facet-search.test.ts index b83bd9a3..d9260b43 100644 --- a/packages/instant-meilisearch/__tests__/disjunctive-facet-search.test.ts +++ b/packages/instant-meilisearch/__tests__/disjunctive-facet-search.test.ts @@ -1,7 +1,8 @@ -import { instantMeiliSearch } from '../src' -import { Movies, meilisearchClient } from './assets/utils' -import movies from './assets/movies.json' -import games from './assets/games.json' +import { describe, beforeAll, test, expect } from 'vitest' +import { instantMeiliSearch } from '../src/index.js' +import { type Movies, meilisearchClient } from './assets/utils.js' +import movies from './assets/movies.json' with {type:"json"} +import games from './assets/games.json'with {type:"json"} // TODO: re-read for review diff --git a/packages/instant-meilisearch/__tests__/facet-stats.test.ts b/packages/instant-meilisearch/__tests__/facet-stats.test.ts index 7d366d1a..7429d65a 100644 --- a/packages/instant-meilisearch/__tests__/facet-stats.test.ts +++ b/packages/instant-meilisearch/__tests__/facet-stats.test.ts @@ -1,4 +1,5 @@ -import { searchClient, dataset, meilisearchClient } from './assets/utils' +import { describe, beforeAll, test, expect } from 'vitest' +import { searchClient, dataset, meilisearchClient } from './assets/utils.js' describe('Facet stats tests', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/facets-distribution.test.ts b/packages/instant-meilisearch/__tests__/facets-distribution.test.ts index 4a312a39..67417e17 100644 --- a/packages/instant-meilisearch/__tests__/facets-distribution.test.ts +++ b/packages/instant-meilisearch/__tests__/facets-distribution.test.ts @@ -1,4 +1,5 @@ -import { searchClient, dataset, meilisearchClient } from './assets/utils' +import { describe, beforeAll, test, expect } from 'vitest' +import { searchClient, dataset, meilisearchClient } from './assets/utils.js' describe('Instant Meilisearch Browser test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/filter.test.ts b/packages/instant-meilisearch/__tests__/filter.test.ts index b7a97d46..4e2b24fb 100644 --- a/packages/instant-meilisearch/__tests__/filter.test.ts +++ b/packages/instant-meilisearch/__tests__/filter.test.ts @@ -1,9 +1,10 @@ +import { describe, beforeAll, test, expect } from 'vitest' import { searchClient, dataset, - Movies, + type Movies, meilisearchClient, -} from './assets/utils' +} from './assets/utils.js' describe('Instant Meilisearch Browser test', () => { beforeAll(async () => { @@ -164,8 +165,8 @@ describe('Instant Meilisearch Browser test', () => { }, ]) expectArrayEquivalence( - response1.results.flatMap((result) => - result.hits.map((hit) => hit.numberField) + response1.results.flatMap((result: any) => + result.hits.map((hit: any) => hit.numberField) ), [5, 10, 15] ) @@ -180,8 +181,8 @@ describe('Instant Meilisearch Browser test', () => { }, ]) expectArrayEquivalence( - response2.results.flatMap((result) => - result.hits.map((hit) => hit.numberField) + response2.results.flatMap((result: any) => + result.hits.map((hit: any) => hit.numberField) ), [10] ) @@ -196,8 +197,8 @@ describe('Instant Meilisearch Browser test', () => { }, ]) expectArrayEquivalence( - response3.results.flatMap((result) => - result.hits.map((hit) => hit.numberField) + response3.results.flatMap((result: any) => + result.hits.map((hit: any) => hit.numberField) ), [5, 10, 15] ) @@ -212,8 +213,8 @@ describe('Instant Meilisearch Browser test', () => { }, ]) expectArrayEquivalence( - response4.results.flatMap((result) => - result.hits.map((hit) => hit.numberField) + response4.results.flatMap((result: any) => + result.hits.map((hit: any) => hit.numberField) ), [5] ) @@ -228,8 +229,8 @@ describe('Instant Meilisearch Browser test', () => { }, ]) expectArrayEquivalence( - response5.results.flatMap((result) => - result.hits.map((hit) => hit.numberField).filter((v) => v !== undefined) + response5.results.flatMap((result: any) => + result.hits.map((hit: any) => hit.numberField).filter((v: any) => v !== undefined) ), [10, 15] ) diff --git a/packages/instant-meilisearch/__tests__/first-facets-distribution.test.ts b/packages/instant-meilisearch/__tests__/first-facets-distribution.test.ts index 4fba777c..45b46327 100644 --- a/packages/instant-meilisearch/__tests__/first-facets-distribution.test.ts +++ b/packages/instant-meilisearch/__tests__/first-facets-distribution.test.ts @@ -1,5 +1,6 @@ -import { dataset, meilisearchClient, HOST, API_KEY } from './assets/utils' -import { instantMeiliSearch } from '../src' +import { describe, beforeAll, test, expect } from 'vitest' +import { dataset, meilisearchClient, HOST, API_KEY } from './assets/utils.js' +import { instantMeiliSearch } from '../src/index.js' describe('Default facet distribution', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/geosearch.test.ts b/packages/instant-meilisearch/__tests__/geosearch.test.ts index 76d8b233..1f2f9c81 100644 --- a/packages/instant-meilisearch/__tests__/geosearch.test.ts +++ b/packages/instant-meilisearch/__tests__/geosearch.test.ts @@ -1,9 +1,10 @@ +import { describe, beforeAll, test, expect } from 'vitest' import { searchClient, geoDataset, - City, + type City, meilisearchClient, -} from './assets/utils' +} from './assets/utils.js' describe('Instant Meilisearch Browser test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/highlight.test.ts b/packages/instant-meilisearch/__tests__/highlight.test.ts index b0e2e131..7bc32824 100644 --- a/packages/instant-meilisearch/__tests__/highlight.test.ts +++ b/packages/instant-meilisearch/__tests__/highlight.test.ts @@ -1,9 +1,10 @@ +import { describe, beforeAll, test, expect } from 'vitest' import { searchClient, dataset, - Movies, + type Movies, meilisearchClient, -} from './assets/utils' +} from './assets/utils.js' describe('Highlight Browser test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/instantiation.test.ts b/packages/instant-meilisearch/__tests__/instantiation.test.ts index 5689ea1d..05277173 100644 --- a/packages/instant-meilisearch/__tests__/instantiation.test.ts +++ b/packages/instant-meilisearch/__tests__/instantiation.test.ts @@ -1,4 +1,5 @@ -import { instantMeiliSearch } from '../src' +import { describe, test, expect } from 'vitest' +import { instantMeiliSearch } from '../src/index.js' describe('InstantMeiliSearch instantiation', () => { test('instantiation with required params returns InstantMeiliSearchInstance', () => { diff --git a/packages/instant-meilisearch/__tests__/multi-index-search.test.ts b/packages/instant-meilisearch/__tests__/multi-index-search.test.ts index 44a38a06..cf971688 100644 --- a/packages/instant-meilisearch/__tests__/multi-index-search.test.ts +++ b/packages/instant-meilisearch/__tests__/multi-index-search.test.ts @@ -1,7 +1,8 @@ -import { instantMeiliSearch } from '../src' -import { Movies, meilisearchClient } from './assets/utils' -import movies from './assets/movies.json' -import games from './assets/games.json' +import { describe, beforeAll, test, expect } from 'vitest' +import { instantMeiliSearch } from '../src/index.js' +import { type Movies, meilisearchClient } from './assets/utils.js' +import movies from './assets/movies.json' with { type: "json" } +import games from './assets/games.json' with { type: "json" } describe('Multi-index search test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/overridden-meilisearch-parameters.test.ts b/packages/instant-meilisearch/__tests__/overridden-meilisearch-parameters.test.ts index 7ad9e1f2..af9fc73f 100644 --- a/packages/instant-meilisearch/__tests__/overridden-meilisearch-parameters.test.ts +++ b/packages/instant-meilisearch/__tests__/overridden-meilisearch-parameters.test.ts @@ -1,5 +1,6 @@ -import { instantMeiliSearch } from '../src' -import { dataset, meilisearchClient, Movies } from './assets/utils' +import { describe, beforeAll, test, expect } from 'vitest' +import { instantMeiliSearch } from '../src/index.js' +import { dataset, meilisearchClient, type Movies } from './assets/utils.js' describe('InstantMeiliSearch overridden parameters', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/pagination.test.ts b/packages/instant-meilisearch/__tests__/pagination.test.ts index 8bbffa76..a696a0c3 100644 --- a/packages/instant-meilisearch/__tests__/pagination.test.ts +++ b/packages/instant-meilisearch/__tests__/pagination.test.ts @@ -1,9 +1,10 @@ +import { describe, beforeAll, test, expect } from 'vitest' import { searchClient, dataset, - Movies, + type Movies, meilisearchClient, -} from './assets/utils' +} from './assets/utils.js' describe('Pagination browser test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/placeholder-search.test.ts b/packages/instant-meilisearch/__tests__/placeholder-search.test.ts index 5131c023..ce17a14c 100644 --- a/packages/instant-meilisearch/__tests__/placeholder-search.test.ts +++ b/packages/instant-meilisearch/__tests__/placeholder-search.test.ts @@ -1,5 +1,6 @@ -import { instantMeiliSearch } from '../src' -import { dataset, Movies, meilisearchClient } from './assets/utils' +import { describe, beforeAll, test, expect } from 'vitest' +import { instantMeiliSearch } from '../src/index.js' +import { dataset, type Movies, meilisearchClient } from './assets/utils.js' describe('Pagination browser test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/search-resolver.test.ts b/packages/instant-meilisearch/__tests__/search-resolver.test.ts index 2a85f2a8..3e684300 100644 --- a/packages/instant-meilisearch/__tests__/search-resolver.test.ts +++ b/packages/instant-meilisearch/__tests__/search-resolver.test.ts @@ -1,11 +1,9 @@ -import { Movies } from './assets/utils' -import { instantMeiliSearch } from '../src' +import { describe, afterEach, test, expect, vi } from 'vitest' +import type { Movies } from './assets/utils.js' +import { instantMeiliSearch } from '../src/index.js' import { MeiliSearch } from 'meilisearch' -import { mocked } from 'ts-jest/utils' -import { PACKAGE_VERSION } from '../src/package-version' -import { MeiliSearchMultiSearchParams } from '../src/types' - -jest.mock('meilisearch') +import { PACKAGE_VERSION } from '../src/package-version.js' +import type { MeiliSearchMultiSearchParams } from '../src/types/index.js' export const searchResponse = { hits: [], @@ -17,9 +15,11 @@ export const searchResponse = { exhaustiveNbHits: false, } +vi.mock('meilisearch') + // Mocking of Meilisearch package -const mockedMeilisearch = mocked(MeiliSearch, true) -const mockedMultiSearch = jest.fn((request) => { +const mockedMeilisearch = vi.mocked(MeiliSearch, true) +const mockedMultiSearch = vi.fn((request) => { const response = request.queries.map((req: MeiliSearchMultiSearchParams) => ({ ...searchResponse, indexUid: req.indexUid, @@ -36,7 +36,7 @@ mockedMeilisearch.mockReturnValue({ describe('Cached search tests', () => { afterEach(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) test('the same search parameters twice', async () => { diff --git a/packages/instant-meilisearch/__tests__/snippets.test.ts b/packages/instant-meilisearch/__tests__/snippets.test.ts index e263bcb5..c285781c 100644 --- a/packages/instant-meilisearch/__tests__/snippets.test.ts +++ b/packages/instant-meilisearch/__tests__/snippets.test.ts @@ -1,9 +1,10 @@ +import { describe, beforeAll, test, expect } from 'vitest' import { searchClient, dataset, - Movies, + type Movies, meilisearchClient, -} from './assets/utils' +} from './assets/utils.js' describe('Snippet Browser test', () => { beforeAll(async () => { diff --git a/packages/instant-meilisearch/__tests__/sort.test.ts b/packages/instant-meilisearch/__tests__/sort.test.ts index 6a2e7fc1..b2065720 100644 --- a/packages/instant-meilisearch/__tests__/sort.test.ts +++ b/packages/instant-meilisearch/__tests__/sort.test.ts @@ -1,11 +1,12 @@ +import { describe, beforeAll, test, expect } from 'vitest' import { searchClient, dataset, - Movies, + type Movies, meilisearchClient, -} from './assets/utils' +} from './assets/utils.js' -import { splitSortString } from '../src/contexts/sort-context' +import { splitSortString } from '../src/contexts/sort-context.js' describe('Sort browser test', () => { beforeAll(async () => { @@ -81,7 +82,7 @@ describe('Sort browser test', () => { expect(sortRules).toEqual(['_geoPoint(37.8153, -122.4784):asc']) }) - test.only('split no sorting rule', () => { + test('split no sorting rule', () => { const sortRules = splitSortString('') expect(sortRules).toEqual([]) diff --git a/packages/instant-meilisearch/__tests__/tsconfig.json b/packages/instant-meilisearch/__tests__/tsconfig.json deleted file mode 100644 index 38ca0b13..00000000 --- a/packages/instant-meilisearch/__tests__/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../tsconfig.test.json" -} diff --git a/packages/instant-meilisearch/jest.config.js b/packages/instant-meilisearch/jest.config.js deleted file mode 100644 index 1802e209..00000000 --- a/packages/instant-meilisearch/jest.config.js +++ /dev/null @@ -1,35 +0,0 @@ -const ignoreFiles = ['(/.*)*/assets'] - -module.exports = { - verbose: true, - watchPlugins: [ - 'jest-watch-typeahead/filename', - 'jest-watch-typeahead/testname', - ], - collectCoverage: true, - projects: [ - { - globals: { - 'ts-jest': { tsconfig: 'tsconfig.test.json' }, - fetch: globalThis.fetch, - }, - preset: 'ts-jest', - displayName: 'dom', - testPathIgnorePatterns: [...ignoreFiles], - coveragePathIgnorePatterns: ['(/.*)*/assets/'], - setupFilesAfterEnv: ['/scripts/jest_teardown.js'], - }, - { - globals: { - 'ts-jest': { tsconfig: 'tsconfig.test.json' }, - fetch: globalThis.fetch, - }, - preset: 'ts-jest', - displayName: 'node', - testEnvironment: 'node', - testPathIgnorePatterns: [...ignoreFiles], - coveragePathIgnorePatterns: ['(/.*)*/assets/'], - setupFilesAfterEnv: ['/scripts/jest_teardown.js'], - }, - ], -} diff --git a/packages/instant-meilisearch/package.json b/packages/instant-meilisearch/package.json index 97a782ec..81420f4f 100644 --- a/packages/instant-meilisearch/package.json +++ b/packages/instant-meilisearch/package.json @@ -1,7 +1,6 @@ { "name": "@meilisearch/instant-meilisearch", "version": "0.23.0", - "private": false, "description": "The search client to use Meilisearch with InstantSearch.", "homepage": "https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/instant-meilisearch", "license": "MIT", @@ -25,24 +24,21 @@ "client" ], "scripts": { - "clear_jest": "jest --clearCache", - "cleanup": "shx rm -rf dist/", - "test:watch": "yarn test --watchAll", - "test": "jest --runInBand --selectProjects dom --selectProjects node", - "build": "yarn cleanup && rollup -c rollup.config.js && rollup --environment NODE_ENV:production -c rollup.config.js", - "dev": "rollup -c rollup.config.js --watch", + "build": "vite build && tsc -p tsconfig.json", "lint": "eslint --ext .js,.ts,.tsx .", "lint:fix": "eslint --ext .js,.ts,.tsx . --fix", - "test:types": "yarn tsc", - "version": "node scripts/update_version.js" + "version": "node scripts/update_version.cjs" }, - "main": "./dist/instant-meilisearch.umd.js", - "module": "./dist/instant-meilisearch.esm.js", - "browser": "./dist/instant-meilisearch.umd.js", - "cjs": "./dist/instant-meilisearch.cjs.js", - "source": "src/index.ts", - "typings": "./dist/types/index.d.ts", + "type": "module", "types": "./dist/types/index.d.ts", + "main": "./dist/umd/index.min.js", + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "default": "./dist/umd/index.min.js" + } + }, "sideEffects": false, "files": [ "dist", @@ -50,32 +46,13 @@ "templates" ], "dependencies": { - "meilisearch": "^0.47.0" + "meilisearch": "^0.48.2" }, "devDependencies": { - "@babel/cli": "^7.22.9", - "@babel/core": "^7.20.12", - "@babel/preset-env": "^7.21.4", - "@rollup/plugin-commonjs": "^17.1.0", - "@rollup/plugin-node-resolve": "^11.2.0", - "@types/jest": "^27.0.2", "algoliasearch": "^4.17.2", - "babel-jest": "^27.2.2", "concurrently": "^7.1.0", "cssnano": "^4.1.10", "eslint-config-meilisearch": "*", - "instantsearch.js": "^4.56.2", - "jest": "^27.2.2", - "jest-watch-typeahead": "^0.6.3", - "regenerator-runtime": "^0.13.7", - "rollup": "^2.79.2", - "rollup-plugin-babel": "^4.4.0", - "rollup-plugin-node-polyfills": "^0.2.1", - "rollup-plugin-terser": "^7.0.0", - "rollup-plugin-typescript2": "^0.32.1", - "shx": "^0.3.4", - "ts-jest": "^27.0.7", - "tslib": "^2.6.1", - "typescript": "^4.9.5" + "instantsearch.js": "^4.56.2" } } diff --git a/packages/instant-meilisearch/rollup.config.js b/packages/instant-meilisearch/rollup.config.js deleted file mode 100644 index 41d121ac..00000000 --- a/packages/instant-meilisearch/rollup.config.js +++ /dev/null @@ -1,95 +0,0 @@ -import { resolve } from 'node:path' -import commonjs from '@rollup/plugin-commonjs' -import nodeResolve from '@rollup/plugin-node-resolve' -import babel from 'rollup-plugin-babel' -import { terser } from 'rollup-plugin-terser' -import typescript from 'rollup-plugin-typescript2' -import pkg from './package.json' - -function getOutputFileName(fileName, isProd = false) { - return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName -} - -const env = process.env.NODE_ENV || 'development' -const ROOT = resolve(__dirname, '.') -const INPUT = 'src/index.ts' - -/** @type {import('rollup').Plugin[]} */ -const COMMON_PLUGINS = [ - typescript({ - useTsconfigDeclarationDir: true, - tsconfigOverride: { - includes: ['src'], - exclude: [ - 'tests', - '*.js', - 'scripts', - '**/__tests__/*.ts', - 'playgrounds', - 'dist', - ], - esModuleInterop: true, - }, - }), -] - -/** @type {import('rollup').RollupOptions[]} */ -const ROLLUP_OPTIONS = [ - // browser-friendly IIFE build - { - input: INPUT, // directory to transpilation of typescript - output: { - name: 'window', - extend: true, - file: getOutputFileName( - // will add .min. in filename if in production env - resolve(ROOT, pkg.browser), - env === 'production' - ), - format: 'umd', - sourcemap: env === 'production', // create sourcemap for error reporting in production mode - globals: { - meilisearch: 'meilisearch', - }, - }, - plugins: [ - ...COMMON_PLUGINS, - nodeResolve({ exportConditions: ['browser'] }), - commonjs(), - babel(), - // json(), - env === 'production' ? terser() : {}, // will minify the file in production mode - ], - }, - { - input: INPUT, - external: ['meilisearch'], - output: [ - { - file: getOutputFileName( - // will add .min. in filename if in production env - resolve(ROOT, pkg.cjs), - env === 'production' - ), - exports: 'named', - format: 'cjs', - sourcemap: env === 'production', // create sourcemap for error reporting in production mode - }, - { - file: getOutputFileName( - resolve(ROOT, pkg.module), - env === 'production' - ), - exports: 'named', - format: 'es', - sourcemap: env === 'production', // create sourcemap for error reporting in production mode - }, - ], - plugins: [ - env === 'production' ? terser() : {}, // will minify the file in production mode - ...COMMON_PLUGINS, - ], - }, -] - -module.exports = ROLLUP_OPTIONS diff --git a/packages/instant-meilisearch/scripts/build.js b/packages/instant-meilisearch/scripts/build.js deleted file mode 100644 index 1df0f396..00000000 --- a/packages/instant-meilisearch/scripts/build.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * This file only purpose is to execute any build related tasks - */ - -const { resolve, normalize } = require('node:path') -const { readFileSync, writeFileSync } = require('node:fs') -const pkg = require('../package.json') - -const ROOT = resolve(__dirname, '..') -const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.typings)) - -main() - -function main() { - writeDtsHeader() -} - -function writeDtsHeader() { - const dtsHeader = getDtsHeader( - pkg.name, - pkg.version, - pkg.author, - pkg.repository.url, - pkg.devDependencies.typescript - ) - - prependFileSync(TYPES_ROOT_FILE, dtsHeader) -} - -/** - * - * @param {string} pkgName - * @param {string} version - * @param {string} author - * @param {string} repoUrl - * @param {string} tsVersion - */ -function getDtsHeader(pkgName, version, author, repoUrl, tsVersion) { - const extractUserName = repoUrl.match(/\.com\/([\w-]+)\/\w+/i) - const githubUserUrl = extractUserName ? extractUserName[1] : 'Unknown' - - return ` -// Type definitions for ${pkgName} ${version} -// Project: ${repoUrl} -// Definitions by: ${author} -// Definitions: ${repoUrl} -// TypeScript Version: ${tsVersion} -`.replace(/^\s+/gm, '') -} - -/** - * - * @param {string} path - * @param {string | Blob} data - */ -function prependFileSync(path, data) { - const existingFileContent = readFileSync(path, { - encoding: 'utf8', - }) - const newFileContent = [data, existingFileContent].join('\n') - writeFileSync(path, newFileContent, { - flag: 'w+', - encoding: 'utf8', - }) -} diff --git a/packages/instant-meilisearch/scripts/jest_teardown.js b/packages/instant-meilisearch/scripts/jest_teardown.js deleted file mode 100644 index 132068ac..00000000 --- a/packages/instant-meilisearch/scripts/jest_teardown.js +++ /dev/null @@ -1,12 +0,0 @@ -const { MeiliSearch } = require('meilisearch') - -const HOST = 'http://localhost:7700' -const API_KEY = 'masterKey' - -afterAll(async () => { - const client = new MeiliSearch({ host: HOST, apiKey: API_KEY }) - await client.deleteIndex('movies') - const task = await client.deleteIndex('games') - - await client.waitForTask(task.taskUid) -}) diff --git a/packages/instant-meilisearch/scripts/update_version.js b/packages/instant-meilisearch/scripts/update_version.cjs similarity index 100% rename from packages/instant-meilisearch/scripts/update_version.js rename to packages/instant-meilisearch/scripts/update_version.cjs diff --git a/packages/instant-meilisearch/src/adapter/index.ts b/packages/instant-meilisearch/src/adapter/index.ts index ea566b4a..4392b32a 100644 --- a/packages/instant-meilisearch/src/adapter/index.ts +++ b/packages/instant-meilisearch/src/adapter/index.ts @@ -1,2 +1,2 @@ -export * from './search-request-adapter' -export * from './search-response-adapter' +export * from './search-request-adapter/index.js' +export * from './search-response-adapter/index.js' diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/geo-rules.test.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/geo-rules.test.ts index 2f0693b7..3e21d266 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/geo-rules.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/geo-rules.test.ts @@ -1,4 +1,5 @@ -import { adaptGeoSearch } from '../geo-rules-adapter' +import { test, expect } from 'vitest' +import { adaptGeoSearch } from '../geo-rules-adapter.js' test('Adapt instantsearch geo parameters to meilisearch filters without a boundingBox', () => { const filter = adaptGeoSearch({}) diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts index 57eae476..eaee1fa0 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts @@ -1,9 +1,10 @@ +import { describe, test, expect } from 'vitest' import { MatchingStrategies } from 'meilisearch' -import { adaptSearchParams } from '../search-params-adapter' -import { +import { adaptSearchParams } from '../search-params-adapter.js' +import type { OverridableMeiliSearchSearchParameters, SearchContext, -} from '../../../types' +} from '../../../types/index.js' const DEFAULT_CONTEXT: SearchContext = { indexUid: 'test', diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/filter-adapter.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/filter-adapter.ts index a077c2df..2e6f31f1 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/filter-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/filter-adapter.ts @@ -1,4 +1,4 @@ -import type { Filter, SearchContext } from '../../types' +import type { Filter, SearchContext } from '../../types/index.js' const filterEscapeRegExp = /([\\"])/g diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/geo-rules-adapter.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/geo-rules-adapter.ts index b8f20088..16c1edf3 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/geo-rules-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/geo-rules-adapter.ts @@ -1,4 +1,4 @@ -import { InstantSearchGeoParams } from '../../types' +import type { InstantSearchGeoParams } from '../../types/index.js' export function adaptGeoSearch({ insideBoundingBox, diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/index.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/index.ts index 4d77cda1..e49fa244 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/index.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/index.ts @@ -1,2 +1,2 @@ -export * from './search-resolver' -export * from './search-params-adapter' +export * from './search-resolver.js' +export * from './search-params-adapter.js' diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts index 0dc2930e..a8addf16 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts @@ -4,10 +4,10 @@ import type { PaginationState, MeiliSearchMultiSearchParams, Mutable, -} from '../../types' +} from '../../types/index.js' -import { adaptGeoSearch } from './geo-rules-adapter' -import { adaptFilters } from './filter-adapter' +import { adaptGeoSearch } from './geo-rules-adapter.js' +import { adaptFilters } from './filter-adapter.js' function isPaginationRequired( filter: Filter, diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-resolver.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-resolver.ts index 7e176217..c1920b1e 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-resolver.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-resolver.ts @@ -1,10 +1,10 @@ -import { +import type { MeiliSearch, SearchCacheInterface, MeiliSearchMultiSearchParams, MeilisearchMultiSearchResult, PaginationState, -} from '../../types' +} from '../../types/index.js' /** * @param {ResponseCacher} cache diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/facet-distribution.test.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/facet-distribution.test.ts index e8ccc3b2..06ec4af7 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/facet-distribution.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/facet-distribution.test.ts @@ -1,4 +1,5 @@ -import { adaptFacetDistribution } from '../facet-distribution-adapter' +import { describe, test, expect } from 'vitest' +import { adaptFacetDistribution } from '../facet-distribution-adapter.js' const initialFacetDistribution = { movie: { diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/geo-adapter.test.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/geo-adapter.test.ts index 87aaa193..cf698e38 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/geo-adapter.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/geo-adapter.test.ts @@ -1,4 +1,5 @@ -import { adaptGeoResponse } from '../geo-reponse-adapter' +import { describe, test, expect } from 'vitest' +import { adaptGeoResponse } from '../geo-reponse-adapter.js' describe('Geopoint adapter', () => { test('_geoloc field should be created in hit object with _geo fields', () => { diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/hit-adapter.test.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/hit-adapter.test.ts index 6017053b..9ab88f26 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/hit-adapter.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/hit-adapter.test.ts @@ -1,4 +1,5 @@ -import { adaptHits } from '../hits-adapter' +import { describe, test, expect } from 'vitest' +import { adaptHits } from '../hits-adapter.js' const searchResponsePositionMatchesFalse = { indexUid: 'steam-video-games', diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/pagination-adapter.test.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/pagination-adapter.test.ts index f4c4b3a5..ea68c039 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/pagination-adapter.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/__tests__/pagination-adapter.test.ts @@ -1,5 +1,6 @@ -import { adaptPaginationParameters } from '../pagination-adapter' -import { ceiledDivision } from './../__tests__/assets/number' +import { describe, expect, it } from 'vitest' +import { adaptPaginationParameters } from '../pagination-adapter.js' +import { ceiledDivision } from './../__tests__/assets/number.js' const numberPagesTestParameters = [ { diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/adapt-facet-stats.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/adapt-facet-stats.ts index 590ff816..34026be3 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/adapt-facet-stats.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/adapt-facet-stats.ts @@ -1,8 +1,8 @@ -import { +import type { AlgoliaSearchResponse, MeiliFacetStats, AlgoliaFacetStats, -} from '../../types' +} from '../../types/index.js' export function adaptFacetStats( meiliFacetStats: MeiliFacetStats diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/facet-distribution-adapter.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/facet-distribution-adapter.ts index 1aa65632..c3028bdc 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/facet-distribution-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/facet-distribution-adapter.ts @@ -1,4 +1,4 @@ -import { FacetDistribution, SearchContext } from '../../types' +import type { FacetDistribution, SearchContext } from '../../types/index.js' function getFacetNames( facets: SearchContext['facets'] | string diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/format-adapter.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/format-adapter.ts index 7d3c656d..e9bf8212 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/format-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/format-adapter.ts @@ -1,4 +1,4 @@ -import { isPureObject } from '../../../utils' +import { isPureObject } from '../../../utils/index.js' /** * Stringify values following instantsearch practices. diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/index.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/index.ts index 9b22120c..879ff5fe 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/index.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/format-adapter/index.ts @@ -1 +1 @@ -export * from './format-adapter' +export * from './format-adapter.js' diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/hits-adapter.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/hits-adapter.ts index f34ac1ec..70f33bfc 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/hits-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/hits-adapter.ts @@ -2,9 +2,9 @@ import type { PaginationState, MeilisearchMultiSearchResult, InstantMeiliSearchConfig, -} from '../../types' -import { adaptFormattedFields } from './format-adapter' -import { adaptGeoResponse } from './geo-reponse-adapter' +} from '../../types/index.js' +import { adaptFormattedFields } from './format-adapter/index.js' +import { adaptGeoResponse } from './geo-reponse-adapter.js' /** * @param {MeilisearchMultiSearchResult} searchResult diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/index.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/index.ts index e1584f52..f11192f5 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/index.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/index.ts @@ -1 +1 @@ -export * from './search-response-adapter' +export * from './search-response-adapter.js' diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/pagination-adapter.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/pagination-adapter.ts index e57af64e..32424bee 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/pagination-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/pagination-adapter.ts @@ -2,7 +2,7 @@ import type { MultiSearchResult, InstantSearchPagination, PaginationState, -} from '../../types' +} from '../../types/index.js' function adaptNbPages( searchResponse: MultiSearchResult>, diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/search-response-adapter.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/search-response-adapter.ts index 1c097dac..f42c5e17 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/search-response-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/search-response-adapter.ts @@ -3,12 +3,12 @@ import type { FacetDistribution, InstantMeiliSearchConfig, MeilisearchMultiSearchResult, -} from '../../types' -import { adaptHits } from './hits-adapter' -import { adaptTotalHits } from './total-hits-adapter' -import { adaptPaginationParameters } from './pagination-adapter' -import { adaptFacetDistribution } from './facet-distribution-adapter' -import { adaptFacetStats } from './adapt-facet-stats' +} from '../../types/index.js' +import { adaptHits } from './hits-adapter.js' +import { adaptTotalHits } from './total-hits-adapter.js' +import { adaptPaginationParameters } from './pagination-adapter.js' +import { adaptFacetDistribution } from './facet-distribution-adapter.js' +import { adaptFacetStats } from './adapt-facet-stats.js' /** * Adapt multiple search results from Meilisearch diff --git a/packages/instant-meilisearch/src/adapter/search-response-adapter/total-hits-adapter.ts b/packages/instant-meilisearch/src/adapter/search-response-adapter/total-hits-adapter.ts index 350a3919..ac75a6c4 100644 --- a/packages/instant-meilisearch/src/adapter/search-response-adapter/total-hits-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-response-adapter/total-hits-adapter.ts @@ -1,4 +1,4 @@ -import type { MultiSearchResult } from '../../types' +import type { MultiSearchResult } from '../../types/index.js' export function adaptTotalHits( searchResponse: MultiSearchResult> diff --git a/packages/instant-meilisearch/src/cache/__tests__/fill-missing-facets.test.ts b/packages/instant-meilisearch/src/cache/__tests__/fill-missing-facets.test.ts index 3618688b..31c38f34 100644 --- a/packages/instant-meilisearch/src/cache/__tests__/fill-missing-facets.test.ts +++ b/packages/instant-meilisearch/src/cache/__tests__/fill-missing-facets.test.ts @@ -1,4 +1,5 @@ -import { fillMissingFacets } from '../init-facets-distribution' +import { describe, it, expect } from 'vitest' +import { fillMissingFacets } from '../init-facets-distribution.js' describe('Fill missing facets', () => { it('should fill missing facets without changing the results', () => { diff --git a/packages/instant-meilisearch/src/cache/__tests__/search-cache.test.ts b/packages/instant-meilisearch/src/cache/__tests__/search-cache.test.ts index a87ffa36..4acac2ad 100644 --- a/packages/instant-meilisearch/src/cache/__tests__/search-cache.test.ts +++ b/packages/instant-meilisearch/src/cache/__tests__/search-cache.test.ts @@ -1,5 +1,6 @@ -import { SearchCache } from '../search-cache' -import { searchResponse } from './assets/utils' +import { describe, test, expect } from 'vitest' +import { SearchCache } from '../search-cache.js' +import { searchResponse } from './assets/utils.js' describe('Entries in the cache', () => { test('to getEntry on empty cache', () => { diff --git a/packages/instant-meilisearch/src/cache/index.ts b/packages/instant-meilisearch/src/cache/index.ts index 35ae2121..e2bd2158 100644 --- a/packages/instant-meilisearch/src/cache/index.ts +++ b/packages/instant-meilisearch/src/cache/index.ts @@ -1,2 +1,2 @@ -export * from './search-cache' -export * from './init-facets-distribution' +export * from './search-cache.js' +export * from './init-facets-distribution.js' diff --git a/packages/instant-meilisearch/src/cache/init-facets-distribution.ts b/packages/instant-meilisearch/src/cache/init-facets-distribution.ts index c37c74a9..6fefd6c7 100644 --- a/packages/instant-meilisearch/src/cache/init-facets-distribution.ts +++ b/packages/instant-meilisearch/src/cache/init-facets-distribution.ts @@ -1,12 +1,12 @@ -import { +import type { FacetDistribution, SearchContext, MeiliSearchMultiSearchParams, MultiSearchResolver, MeilisearchMultiSearchResult, -} from '../types' -import { MeiliParamsCreator } from '../adapter' -import { removeDuplicate } from '../utils' +} from '../types/index.js' +import { MeiliParamsCreator } from '../adapter/index.js' +import { removeDuplicate } from '../utils/index.js' export function getParametersWithoutFilters( searchContext: SearchContext diff --git a/packages/instant-meilisearch/src/cache/search-cache.ts b/packages/instant-meilisearch/src/cache/search-cache.ts index 8506b5c5..849ec401 100644 --- a/packages/instant-meilisearch/src/cache/search-cache.ts +++ b/packages/instant-meilisearch/src/cache/search-cache.ts @@ -1,5 +1,5 @@ -import { SearchCacheInterface } from '../types' -import { stringifyArray } from '../utils' +import type { SearchCacheInterface } from '../types/index.js' +import { stringifyArray } from '../utils/index.js' /** * @param {Record } -export type InstantMeiliSearchInstance = SearchClient & { +export type InstantMeiliSearchInstance = ReturnType & { clearCache: () => void } diff --git a/packages/instant-meilisearch/src/utils/index.ts b/packages/instant-meilisearch/src/utils/index.ts index 29679e42..82ad0d31 100644 --- a/packages/instant-meilisearch/src/utils/index.ts +++ b/packages/instant-meilisearch/src/utils/index.ts @@ -1,3 +1,3 @@ -export * from './array' -export * from './string' -export * from './object' +export * from './array.js' +export * from './string.js' +export * from './object.js' diff --git a/packages/instant-meilisearch/tsconfig.eslint.json b/packages/instant-meilisearch/tsconfig.eslint.json deleted file mode 100644 index ab3c206a..00000000 --- a/packages/instant-meilisearch/tsconfig.eslint.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["**/*.ts", "**/*.js"] -} diff --git a/packages/instant-meilisearch/tsconfig.json b/packages/instant-meilisearch/tsconfig.json index 1d550f77..09060517 100644 --- a/packages/instant-meilisearch/tsconfig.json +++ b/packages/instant-meilisearch/tsconfig.json @@ -1,29 +1,9 @@ { + "extends": "../../tsconfig.json", "compilerOptions": { - "module": "esnext", - "noEmit": true, - "allowJs": false, - "removeComments": false, - "declaration": true, - "declarationMap": true, - "declarationDir": "./dist/types", - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "moduleResolution": "node", - "lib": [ - "ES2019", - "ESNext", - "dom" - ], - "importHelpers": true, - // Enforced typing rules - "strict": true, - "alwaysStrict": true, - "noImplicitReturns": true, - "forceConsistentCasingInFileNames": true, - "noUnusedParameters": true, - "isolatedModules": true, - "resolveJsonModule": true + "outDir": "./dist/esm", + "declarationDir": "dist/types" }, - "include": ["src/**/*.ts", "src/**/*.d.ts"] + "include": ["./src/**/*.ts"], + "exclude": ["src/**/*.test.ts"] } diff --git a/packages/instant-meilisearch/tsconfig.test.json b/packages/instant-meilisearch/tsconfig.test.json deleted file mode 100644 index 67e610cc..00000000 --- a/packages/instant-meilisearch/tsconfig.test.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "suppressImplicitAnyIndexErrors": true - }, - "include": [ - "./**/*" - ] -} diff --git a/packages/instant-meilisearch/vite.config.ts b/packages/instant-meilisearch/vite.config.ts new file mode 100644 index 00000000..ed53a3e3 --- /dev/null +++ b/packages/instant-meilisearch/vite.config.ts @@ -0,0 +1,43 @@ +import { defineProject } from 'vitest/config'; +import pkg from './package.json' with { type: 'json' }; + +const globalVarName = pkg.name + .substring(pkg.name.lastIndexOf('/') + 1) + .replace(/-./g, (x) => x[1].toUpperCase()); + +export default defineProject({ + build: { + sourcemap: true, + target: 'es6', + lib: { + entry: 'src/index.ts', + name: globalVarName, + formats: ['umd'], + fileName: (format, entryName) => { + switch (format) { + case 'umd': + return `umd/${entryName}.min.js`; + default: + throw new Error(`unsupported format ${format}`); + } + }, + }, + // the following code enables Vite in UMD mode to extend the global object with all of + // the exports, and not just a property of it ( https://github.com/vitejs/vite/issues/11624 ) + rollupOptions: { + output: { + footer: `(function () { + if (typeof self !== "undefined") { + var clonedGlobal = Object.assign({}, self.${globalVarName}); + delete clonedGlobal.default; + Object.assign(self, clonedGlobal); + } + })();`, + }, + }, + }, + test: { + include: ['{src,__tests__}/**/*.test.ts'], + testTimeout: 100_000, // 100 seconds + }, +}); diff --git a/playgrounds/autocomplete/.babelrc b/playgrounds/autocomplete/.babelrc deleted file mode 100644 index f8ff4351..00000000 --- a/playgrounds/autocomplete/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "presets": ["@babel/preset-react"], - "plugins": ["@babel/plugin-syntax-jsx"] -} diff --git a/playgrounds/autocomplete/cypress.env.json b/playgrounds/autocomplete/cypress.env.json index 53053351..d2d43089 100644 --- a/playgrounds/autocomplete/cypress.env.json +++ b/playgrounds/autocomplete/cypress.env.json @@ -1,5 +1,5 @@ { "local": { - "host": "http://localhost:7777" + "host": "http://localhost:5173" } } diff --git a/playgrounds/autocomplete/package.json b/playgrounds/autocomplete/package.json index 86226aa1..3c25d164 100644 --- a/playgrounds/autocomplete/package.json +++ b/playgrounds/autocomplete/package.json @@ -4,10 +4,9 @@ "private": true, "description": "Javascript playground for autocomplete", "scripts": { - "predev": "node setup.cjs", - "dev": "parcel serve index.html --open --port 7777", - "build": "parcel build index.html", - "setup": "node setup.cjs", + "predev": "node setup.mjs", + "dev": "vite", + "setup": "node setup.mjs", "lint": "eslint --ext .jsx,.js .", "lint:fix": "eslint --ext .jsx,.js --fix .", "test:e2e": "concurrently --kill-others -s first \"yarn dev\" \"cypress run --env playground=local\"", @@ -22,15 +21,13 @@ "author": "", "license": "ISC", "dependencies": { - "@algolia/autocomplete-core": "1.7.4", - "@algolia/autocomplete-plugin-query-suggestions": "^1.9.3", - "@algolia/autocomplete-plugin-tags": "^1.10.0", - "@algolia/autocomplete-theme-classic": "^1.10.0", + "@algolia/autocomplete-core": "1.17.9", + "@algolia/autocomplete-plugin-query-suggestions": "^1.17.9", + "@algolia/autocomplete-plugin-tags": "^1.17.9", + "@algolia/autocomplete-theme-classic": "^1.17.9", "@meilisearch/autocomplete-client": "*" }, "devDependencies": { - "@babel/core": "^7.13.1", - "eslint-config-meilisearch": "*", - "parcel": "^2.12.0" + "eslint-config-meilisearch": "*" } } diff --git a/playgrounds/autocomplete/setup.cjs b/playgrounds/autocomplete/setup.cjs deleted file mode 100644 index 95120701..00000000 --- a/playgrounds/autocomplete/setup.cjs +++ /dev/null @@ -1,12 +0,0 @@ -const { MeiliSearch } = require('meilisearch') -const games = require('./assets/games.json') - -;(async () => { - const client = new MeiliSearch({ - host: 'http://localhost:7700', - apiKey: 'masterKey', - }) - await client.index('steam-video-games').delete() - const task = await client.index('steam-video-games').addDocuments(games) - await client.waitForTask(task.taskUid) -})() diff --git a/playgrounds/autocomplete/setup.mjs b/playgrounds/autocomplete/setup.mjs new file mode 100644 index 00000000..f3118bae --- /dev/null +++ b/playgrounds/autocomplete/setup.mjs @@ -0,0 +1,10 @@ +import { MeiliSearch } from "meilisearch"; +import games from "./assets/games.json" with { type: "json" }; + +const client = new MeiliSearch({ + host: "http://localhost:7700", + apiKey: "masterKey", +}); +await client.index("steam-video-games").delete(); +const task = await client.index("steam-video-games").addDocuments(games); +await client.waitForTask(task.taskUid); diff --git a/playgrounds/autocomplete/vite.config.ts b/playgrounds/autocomplete/vite.config.ts new file mode 100644 index 00000000..65affe5e --- /dev/null +++ b/playgrounds/autocomplete/vite.config.ts @@ -0,0 +1,6 @@ +const { defineConfig } = require('vite'); + +// https://vite.dev/config/ +module.exports = defineConfig({ + server: { strictPort: true }, +}); diff --git a/playgrounds/geo-javascript/package.json b/playgrounds/geo-javascript/package.json index 73c0e805..0ebda667 100644 --- a/playgrounds/geo-javascript/package.json +++ b/playgrounds/geo-javascript/package.json @@ -3,9 +3,9 @@ "version": "0.0.0", "private": true, "description": "Instant-meilisearch playground focussed on GeoSearch written with vanilla javascript", + "type": "module", "scripts": { - "dev": "parcel serve index.html --open", - "build": "parcel build index.html", + "dev": "vite", "lint": "eslint --ext .js .", "lint:fix": "eslint --ext .js --fix ." }, diff --git a/playgrounds/javascript/package.json b/playgrounds/javascript/package.json index 351418df..0c458533 100644 --- a/playgrounds/javascript/package.json +++ b/playgrounds/javascript/package.json @@ -3,9 +3,9 @@ "version": "0.0.0", "private": true, "description": "Instant-meilisearch playground written with vanilla javascript", + "type": "module", "scripts": { - "dev": "parcel serve index.html --open --port 2222", - "build": "parcel build index.html", + "dev": "vite", "lint": "eslint --ext .js ." }, "devDependencies": { diff --git a/playgrounds/local-react/.babelrc b/playgrounds/local-react/.babelrc deleted file mode 100644 index f45ffb89..00000000 --- a/playgrounds/local-react/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "presets": ["@babel/preset-react"], - "plugins": ["@babel/plugin-syntax-jsx", "@babel/plugin-transform-runtime"] -} diff --git a/playgrounds/local-react/cypress.env.json b/playgrounds/local-react/cypress.env.json index fb34cb6a..ed8622d3 100644 --- a/playgrounds/local-react/cypress.env.json +++ b/playgrounds/local-react/cypress.env.json @@ -1,5 +1,5 @@ { "local": { - "host": "http://localhost:9999" + "host": "http://localhost:5174" } } diff --git a/playgrounds/local-react/cypress/integration/search-ui.spec.js b/playgrounds/local-react/cypress/integration/search-ui.spec.js index a0972d0b..8bf7cbc9 100644 --- a/playgrounds/local-react/cypress/integration/search-ui.spec.js +++ b/playgrounds/local-react/cypress/integration/search-ui.spec.js @@ -19,8 +19,8 @@ describe(`${playground} playground test`, () => { cy.contains('15 results') }) - it('Contains filter clear', () => { - cy.contains('Clear all filters') + it('Contains refinements clear', () => { + cy.contains('Clear refinements') }) it('Contains Genres', () => { diff --git a/playgrounds/local-react/package.json b/playgrounds/local-react/package.json index 23e743e7..51e292bf 100644 --- a/playgrounds/local-react/package.json +++ b/playgrounds/local-react/package.json @@ -4,10 +4,9 @@ "private": true, "description": "React playground for instant-meilisearch", "scripts": { - "predev": "node setup.js", - "dev": "parcel serve index.html --open --port 9999", - "build": "parcel build index.html", - "setup": "node setup.js", + "predev": "node setup.mjs", + "dev": "vite", + "setup": "node setup.mjs", "lint": "eslint --ext .jsx,.js .", "lint:fix": "eslint --ext .jsx,.js --fix .", "test:e2e": "concurrently --kill-others -s first \"yarn dev\" \"cypress run --env playground=local\"", @@ -22,20 +21,14 @@ ], "author": "", "license": "ISC", - "dependencies": { - "@meilisearch/instant-meilisearch": "0.23.0", - "instantsearch.css": "^8.0.0", - "react": "^17.0.1", - "react-dom": "^17.0.1", - "react-instantsearch-dom": "^6.40.4", - "react-router-dom": "^6.14.2" - }, "devDependencies": { - "@babel/core": "^7.20.5", - "@babel/plugin-syntax-jsx": "^7.22.5", - "@babel/plugin-transform-runtime": "^7.22.5", - "@babel/preset-react": "^7.22.5", - "cypress": "^8.6.0", + "@meilisearch/instant-meilisearch": "*", + "instantsearch.css": "^8.5.1", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "@vitejs/plugin-react": "^4.3.4", + "react-instantsearch": "^7.15.0", + "react-router-dom": "^6.28.2", "eslint-config-meilisearch": "*" } -} \ No newline at end of file +} diff --git a/playgrounds/local-react/setup.js b/playgrounds/local-react/setup.js deleted file mode 100644 index 117ee797..00000000 --- a/playgrounds/local-react/setup.js +++ /dev/null @@ -1,33 +0,0 @@ -const { MeiliSearch } = require('meilisearch') -const movies = require('./assets/movies.json') -const games = require('./assets/games.json') - -;(async () => { - const client = new MeiliSearch({ - host: 'http://127.0.0.1:7700', - apiKey: 'masterKey', - }) - - const moviesIndex = client.index('movies') - const gamesIndex = client.index('games') - - await moviesIndex.delete() - await gamesIndex.delete() - - await moviesIndex.updateSettings({ - filterableAttributes: ['genres', 'color', 'platforms'], - }) - await gamesIndex.updateSettings({ - filterableAttributes: ['genres', 'color', 'platforms', 'misc', 'players'], - searchableAttributes: ['name', 'description'], - sortableAttributes: ['recommendationCount'], - }) - - const moviesRes = await moviesIndex.addDocuments(movies) - const gamesRes = await gamesIndex.addDocuments(games) - - const moviesTask = await client.waitForTask(moviesRes.taskUid) - const gamesTask = await client.waitForTask(gamesRes.taskUid) - console.log(moviesTask) - console.log(gamesTask) -})() diff --git a/playgrounds/local-react/setup.mjs b/playgrounds/local-react/setup.mjs new file mode 100644 index 00000000..4fd4da1d --- /dev/null +++ b/playgrounds/local-react/setup.mjs @@ -0,0 +1,31 @@ +import { MeiliSearch } from "meilisearch"; +import movies from "./assets/movies.json" with { type: "json" }; +import games from "./assets/games.json" with { type: "json" }; + +const client = new MeiliSearch({ + host: "http://127.0.0.1:7700", + apiKey: "masterKey", +}); + +const moviesIndex = client.index("movies"); +const gamesIndex = client.index("games"); + +await moviesIndex.delete(); +await gamesIndex.delete(); + +await moviesIndex.updateSettings({ + filterableAttributes: ["genres", "color", "platforms"], +}); +await gamesIndex.updateSettings({ + filterableAttributes: ["genres", "color", "platforms", "misc", "players"], + searchableAttributes: ["name", "description"], + sortableAttributes: ["recommendationCount"], +}); + +const moviesRes = await moviesIndex.addDocuments(movies); +const gamesRes = await gamesIndex.addDocuments(games); + +const moviesTask = await client.waitForTask(moviesRes.taskUid); +const gamesTask = await client.waitForTask(gamesRes.taskUid); +console.log(moviesTask); +console.log(gamesTask); diff --git a/playgrounds/local-react/src/App.jsx b/playgrounds/local-react/src/App.jsx index efd234b2..61736c06 100644 --- a/playgrounds/local-react/src/App.jsx +++ b/playgrounds/local-react/src/App.jsx @@ -1,22 +1,18 @@ -import React from 'react' -import { Routes, Route, Outlet } from 'react-router-dom' -import SingleIndex from './components/SingleIndex' -import MultiIndex from './components/MultiIndex' -import SingleMovieIndex from './components/SingleMovieIndex' +import { Routes, Route, Outlet } from "react-router-dom"; +import SingleIndex from "./components/SingleIndex"; +import MultiIndex from "./components/MultiIndex"; +import SingleMovieIndex from "./components/SingleMovieIndex"; +import "./App.css"; -import './App.css' +const App = () => ( +
+ + } /> + } /> + } /> + + +
+); -const App = () => { - return ( -
- - } /> - } /> - } /> - - -
- ) -} - -export default App +export default App; diff --git a/playgrounds/local-react/src/components/MultiIndex.jsx b/playgrounds/local-react/src/components/MultiIndex.jsx index 49b11a05..19239d50 100644 --- a/playgrounds/local-react/src/components/MultiIndex.jsx +++ b/playgrounds/local-react/src/components/MultiIndex.jsx @@ -1,5 +1,4 @@ import 'instantsearch.css/themes/algolia-min.css' -import React from 'react' import { InstantSearch, SearchBox, diff --git a/playgrounds/local-react/src/components/SingleIndex.jsx b/playgrounds/local-react/src/components/SingleIndex.jsx index a2bef323..20509fda 100644 --- a/playgrounds/local-react/src/components/SingleIndex.jsx +++ b/playgrounds/local-react/src/components/SingleIndex.jsx @@ -1,5 +1,4 @@ import 'instantsearch.css/themes/algolia-min.css' -import React from 'react' import { InstantSearch, InfiniteHits, @@ -11,7 +10,7 @@ import { Configure, SortBy, Snippet, -} from 'react-instantsearch-dom' +} from 'react-instantsearch' import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' const { searchClient } = instantMeiliSearch( diff --git a/playgrounds/local-react/src/components/SingleMovieIndex.jsx b/playgrounds/local-react/src/components/SingleMovieIndex.jsx index af56942a..653464b2 100644 --- a/playgrounds/local-react/src/components/SingleMovieIndex.jsx +++ b/playgrounds/local-react/src/components/SingleMovieIndex.jsx @@ -1,5 +1,4 @@ import 'instantsearch.css/themes/algolia-min.css' -import React from 'react' import { InstantSearch, InfiniteHits, diff --git a/playgrounds/local-react/src/index.jsx b/playgrounds/local-react/src/index.jsx index 8fb1e050..d31789de 100644 --- a/playgrounds/local-react/src/index.jsx +++ b/playgrounds/local-react/src/index.jsx @@ -1,15 +1,13 @@ -import 'regenerator-runtime' +import { StrictMode } from 'react' +import { createRoot } from 'react-dom/client' +import { BrowserRouter } from 'react-router-dom' import './index.css' -import React from 'react' -import ReactDOM from 'react-dom' import App from './App' -import { BrowserRouter } from 'react-router-dom' -ReactDOM.render( - +createRoot(document.getElementById('app')).render( + - , - document.getElementById('app') + , ) diff --git a/playgrounds/local-react/vite.config.ts b/playgrounds/local-react/vite.config.ts new file mode 100644 index 00000000..98ae5908 --- /dev/null +++ b/playgrounds/local-react/vite.config.ts @@ -0,0 +1,8 @@ +const { defineConfig } = require('vite'); +const react = require('@vitejs/plugin-react'); + +// https://vite.dev/config/ +module.exports = defineConfig({ + server: { port: 5174, strictPort: true }, + plugins: [react()], +}); diff --git a/playgrounds/node-env/index.js b/playgrounds/node-env/index.js index 7342608d..734f45b9 100644 --- a/playgrounds/node-env/index.js +++ b/playgrounds/node-env/index.js @@ -1,29 +1,33 @@ -const { instantMeiliSearch } = require('@meilisearch/instant-meilisearch') -const { MeiliSearch } = require('meilisearch') +import { instantMeiliSearch } from '@meilisearch/instant-meilisearch'; +import { MeiliSearch } from 'meilisearch'; +const { searchClient } = instantMeiliSearch( + 'http://localhost:7700', + 'masterKey', + {}, +); +const msClient = new MeiliSearch({ + host: 'http://localhost:7700', + apiKey: 'masterKey', +}); -const { searchClient } = instantMeiliSearch('http://localhost:7700', 'masterKey', {}) -const msClient = new MeiliSearch({ host: 'http://localhost:7700', apiKey: 'masterKey'}) +try { + const task1 = await msClient.index('node_test').addDocuments([]); + await msClient.waitForTask(task1.taskUid); + await searchClient.search([ + { + indexName: 'node_test', + params: { + query: '', + }, + }, + ]); -;(async() => { - try { - const task1 = await msClient.index('node_test').addDocuments([]) - await msClient.waitForTask(task1.taskUid) - await searchClient.search([ - { - indexName: 'node_test', - params: { - query: '', - }, - } - ]) - - const task2 = await msClient.index('node_test').delete() - await msClient.waitForTask(task2.taskUid) - process.exit(0) - } catch(e) { - console.log(e) - console.error('Could not run the `umd` build in a node environment') - process.exit(1) - } -})() + const task2 = await msClient.index('node_test').delete(); + await msClient.waitForTask(task2.taskUid); + process.exit(0); +} catch (e) { + console.log(e); + console.error('Could not run the `umd` build in a node environment'); + process.exit(1); +} diff --git a/playgrounds/node-env/package.json b/playgrounds/node-env/package.json index 0d365ce0..cd142a54 100644 --- a/playgrounds/node-env/package.json +++ b/playgrounds/node-env/package.json @@ -3,7 +3,10 @@ "version": "0.0.0", "private": true, "description": "Instant-meilisearch playground written in node", - "main": "index.js", + "type": "module", + "exports": { + ".": "./index.js" + }, "scripts": { "dev": "node index.js" }, diff --git a/playgrounds/react/.babelrc b/playgrounds/react/.babelrc deleted file mode 100644 index f8ff4351..00000000 --- a/playgrounds/react/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "presets": ["@babel/preset-react"], - "plugins": ["@babel/plugin-syntax-jsx"] -} diff --git a/playgrounds/react/package.json b/playgrounds/react/package.json index 12a8760b..e1cce92c 100644 --- a/playgrounds/react/package.json +++ b/playgrounds/react/package.json @@ -3,9 +3,9 @@ "version": "0.0.0", "private": true, "description": "React playground for instant-meilisearch", + "type": "module", "scripts": { - "dev": "parcel serve index.html --open --port 1111", - "build": "parcel build index.html", + "dev": "vite", "lint": "eslint --ext .jsx,.js .", "lint:fix": "eslint --ext .jsx,.js --fix ." }, @@ -18,16 +18,11 @@ ], "author": "", "license": "ISC", - "dependencies": { - "react": "^17.0.1", - "react-dom": "^17.0.1", - "react-instantsearch": "^7.1.0", - "@meilisearch/instant-meilisearch": "0.23.0" - }, "devDependencies": { - "@babel/core": "^7.13.1", - "@babel/plugin-syntax-jsx": "^7.22.5", - "@babel/preset-react": "^7.22.5", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-instantsearch": "^7.15.0", + "@meilisearch/instant-meilisearch": "*", "eslint-config-meilisearch": "*" } } \ No newline at end of file diff --git a/playgrounds/react/src/App.jsx b/playgrounds/react/src/App.jsx index 7b45316d..3f1a14a0 100644 --- a/playgrounds/react/src/App.jsx +++ b/playgrounds/react/src/App.jsx @@ -1,5 +1,4 @@ -import 'instantsearch.css/themes/algolia-min.css' -import React from 'react' +import "instantsearch.css/themes/algolia-min.css"; import { InstantSearch, InfiniteHits, @@ -11,24 +10,24 @@ import { Configure, SortBy, Snippet, -} from 'react-instantsearch-dom' +} from "react-instantsearch"; -import './App.css' -import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' +import "./App.css"; +import { instantMeiliSearch } from "@meilisearch/instant-meilisearch"; const { searchClient } = instantMeiliSearch( - 'https://ms-adf78ae33284-106.lon.meilisearch.io', - 'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303', + "https://ms-adf78ae33284-106.lon.meilisearch.io", + "a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303", { - primaryKey: 'id', - } -) + primaryKey: "id", + }, +); const App = () => (

Meilisearch + React InstantSearch

- Search in Steam video games{' '} + Search in Steam video games{" "} 🎮 @@ -44,14 +43,14 @@ const App = () => ( @@ -65,8 +64,8 @@ const App = () => (

@@ -75,7 +74,7 @@ const App = () => (
-) +); const Hit = ({ hit }) => { return ( @@ -100,7 +99,7 @@ const Hit = ({ hit }) => { Recommended: {hit.recommendationCount} - ) -} + ); +}; -export default App +export default App; diff --git a/playgrounds/react/src/index.jsx b/playgrounds/react/src/index.jsx index 97ffa576..ffb44428 100644 --- a/playgrounds/react/src/index.jsx +++ b/playgrounds/react/src/index.jsx @@ -1,11 +1,10 @@ -import React from 'react' -import ReactDOM from 'react-dom' -import './index.css' -import App from './App' +import { StrictMode } from "react"; +import { createRoot } from "react-dom/client"; +import "./index.css"; +import App from "./App"; -ReactDOM.render( - +createRoot(document.getElementById("app")).render( + - , - document.getElementById('app') -) + , +); diff --git a/playgrounds/react/vite.config.ts b/playgrounds/react/vite.config.ts new file mode 100644 index 00000000..4a5def4c --- /dev/null +++ b/playgrounds/react/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [react()], +}); diff --git a/playgrounds/vue3-ts/index.html b/playgrounds/vue3-ts/index.html index 17f28835..8388c4bb 100644 --- a/playgrounds/vue3-ts/index.html +++ b/playgrounds/vue3-ts/index.html @@ -1,16 +1,13 @@ - + - - - - - - Vite + Vue + TS - - - -
- - - + + + + + Vite + Vue + + +
+ + diff --git a/playgrounds/vue3-ts/package.json b/playgrounds/vue3-ts/package.json index 61a5b592..4681093b 100644 --- a/playgrounds/vue3-ts/package.json +++ b/playgrounds/vue3-ts/package.json @@ -4,23 +4,16 @@ "private": true, "type": "module", "scripts": { - "dev": "vite --open", - "build": "vue-tsc && vite build", + "dev": "vite", "preview": "vite preview", "lint": "eslint --ext .ts,.vue,.js,.cjs .", - "lint:fix": "eslint --ext .ts,.vue,.js,.cjs --fix .", - "test:types": "yarn tsc" - }, - "dependencies": { - "@meilisearch/instant-meilisearch": "0.23.0", - "vue": "^3.2.45", - "vue-instantsearch": "^4.10.8" + "lint:fix": "eslint --ext .ts,.vue,.js,.cjs --fix ." }, "devDependencies": { - "@vitejs/plugin-vue": "^4.0.0", - "typescript": "^4.9.5", - "vite": "^4.5.5", - "vue-tsc": "^1.0.11", + "vue-instantsearch": "^4.10.8", + "@meilisearch/instant-meilisearch": "*", + "vue": "^3.5.13", + "@vitejs/plugin-vue": "^5.2.1", "eslint-config-meilisearch": "*" } -} \ No newline at end of file +} diff --git a/playgrounds/vue3-ts/src/App.vue b/playgrounds/vue3-ts/src/App.vue index 62adb442..f0c23941 100644 --- a/playgrounds/vue3-ts/src/App.vue +++ b/playgrounds/vue3-ts/src/App.vue @@ -51,7 +51,7 @@ -