From 87ba71cfc171cff6b2546be5f2c21c4edd44cb17 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:55:57 +0300 Subject: [PATCH 01/26] Switch from rollup to vite, from cjs to esm --- .prettierrc.js | 2 +- eslint.config.js | 18 +- package.json | 55 +- rollup.config.js | 125 -- scripts/build.js | 12 +- scripts/file-size.js | 76 - src/enqueued-task.ts | 2 +- src/errors/index.ts | 10 +- src/errors/meilisearch-api-error.ts | 4 +- src/errors/meilisearch-request-error.ts | 2 +- src/errors/meilisearch-timeout-error.ts | 2 +- src/http-requests.ts | 8 +- src/index.ts | 13 +- src/indexes.ts | 14 +- src/meilisearch.ts | 14 +- src/task.ts | 14 +- src/token.ts | 17 +- src/types/index.ts | 2 +- src/types/types.ts | 2 +- tests/client.test.ts | 13 +- tests/dictionary.test.ts | 4 +- tests/displayed_attributes.test.ts | 4 +- tests/distinct_attribute.test.ts | 4 +- tests/documents.test.ts | 6 +- tests/dump.test.ts | 4 +- tests/embedders.test.ts | 6 +- tests/env/browser/index.html | 2 +- tests/env/express/public/headers.html | 2 +- tests/env/express/public/index.html | 2 +- tests/errors.test.ts | 6 +- tests/facet_search.test.ts | 2 +- tests/faceting.test.ts | 4 +- tests/filterable_attributes.test.ts | 4 +- tests/get_search.test.ts | 6 +- tests/index.test.ts | 4 +- tests/keys.test.ts | 6 +- tests/localized_attributes.test.ts | 4 +- tests/non_separator_tokens.test.ts | 4 +- tests/pagination.test.ts | 4 +- tests/proximity_precision.test.ts | 4 +- tests/ranking_rules.test.ts | 6 +- tests/raw_document.test.ts | 4 +- tests/search.test.ts | 6 +- tests/search_cutoff_ms.test.ts | 4 +- tests/searchable_attributes.test.ts | 4 +- tests/separator_tokens.test.ts | 4 +- tests/settings.test.ts | 4 +- tests/snapshots.test.ts | 4 +- tests/sortable_attributes.test.ts | 4 +- tests/stop_words.test.ts | 6 +- tests/synonyms.test.ts | 4 +- tests/task.test.ts | 6 +- tests/token.test.ts | 32 +- tests/typed_search.test.ts | 6 +- tests/typo_tolerance.test.ts | 4 +- tests/unit.test.ts | 2 +- tests/utils/meilisearch-test-utils.ts | 4 +- tests/wait_for_task.test.ts | 4 +- tsconfig.build.json | 4 + tsconfig.eslint.json | 15 - tsconfig.json | 22 +- vite.config.js | 50 + vitest.config.js | 11 - yarn.lock | 2097 ++++------------------- 64 files changed, 581 insertions(+), 2213 deletions(-) delete mode 100644 rollup.config.js delete mode 100644 scripts/file-size.js create mode 100644 tsconfig.build.json delete mode 100644 tsconfig.eslint.json create mode 100644 vite.config.js delete mode 100644 vitest.config.js diff --git a/.prettierrc.js b/.prettierrc.js index c491be0fc..9a75c3a09 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,6 +1,6 @@ // https://prettier.io/docs/en/options.html -module.exports = { +export default { plugins: ["./node_modules/prettier-plugin-jsdoc/dist/index.js"], // https://github.com/hosseinmd/prettier-plugin-jsdoc#tsdoc tsdoc: true, diff --git a/eslint.config.js b/eslint.config.js index c1072689b..4f07c0942 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,19 +1,19 @@ -const eslint = require("@eslint/js"); -const tseslint = require("typescript-eslint"); -const tsdoc = require("eslint-plugin-tsdoc"); -const vitest = require("@vitest/eslint-plugin"); -const globals = require("globals"); -const prettier = require("eslint-config-prettier"); +import eslint from "@eslint/js"; +import tseslint from "typescript-eslint"; +import tsdoc from "eslint-plugin-tsdoc"; +import vitest from "@vitest/eslint-plugin"; +import globals from "globals"; +import prettier from "eslint-config-prettier"; /** @type {import("eslint").Linter.Config[]} */ -module.exports = [ +export default [ { ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"], }, // Standard linting for js files { files: ["**/*.js"], - languageOptions: { sourceType: "script", globals: globals.node }, + languageOptions: { sourceType: "module", globals: globals.node }, plugins: { eslint }, rules: eslint.configs.recommended.rules, }, @@ -26,7 +26,7 @@ module.exports = [ globals: { ...config.languageOptions?.globals, ...globals.node }, parserOptions: { ...config.languageOptions?.parserOptions, - project: "tsconfig.eslint.json", + project: "tsconfig.json", }, }, plugins: { ...config.plugins, tsdoc }, diff --git a/package.json b/package.json index 798f07bf3..b84d2693e 100644 --- a/package.json +++ b/package.json @@ -16,23 +16,21 @@ "qdequele " ], "license": "MIT", - "main": "./dist/bundles/meilisearch.cjs", - "module": "./dist/bundles/meilisearch.mjs", - "typings": "./dist/types/index.d.ts", - "types": "./dist/types/index.d.ts", - "jsdelivr": "./dist/bundles/meilisearch.umd.js", - "unpkg": "./dist/bundles/meilisearch.umd.js", + "type": "module", + "main": "./dist/bundles/index.cjs", + "module": "./dist/esm/index.js", + "jsdelivr": "./dist/bundles/index.umd.min.js", + "unpkg": "./dist/bundles/index.umd.min.js", "exports": { ".": { "types": "./dist/types/index.d.ts", - "browser": "./dist/bundles/meilisearch.umd.js", - "import": "./dist/bundles/meilisearch.mjs", - "require": "./dist/bundles/meilisearch.cjs", - "default": "./dist/bundles/meilisearch.umd.js" + "import": "./dist/esm/index.js", + "require": "./dist/bundles/index.cjs", + "default": "./dist/bundles/index.umd.min.js" }, "./token": { "types": "./dist/types/token.d.ts", - "import": "./dist/bundles/token.mjs", + "import": "./dist/esm/token.js", "require": "./dist/bundles/token.cjs", "default": "./dist/bundles/token.cjs" } @@ -44,11 +42,10 @@ }, "scripts": { "playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start", - "cleanup": "shx rm -rf dist/", - "build": "yarn cleanup && rollup -c && rollup -c --environment NODE_ENV:production", + "build": "vite build && tsc -p tsconfig.build.json && vite --mode production-cjs build", + "postbuild": "node scripts/build.js", "build:docs": "typedoc", "watch": "yarn cleanup && rollup -c --watch", - "postbuild": "yarn size && yarn typingsheader", "test": "vitest run --coverage", "types:watch": "nodemon --config nodemon.json", "types": "yarn tsc", @@ -61,14 +58,12 @@ "test:env:nodejs": "yarn build && node tests/env/node/index.js && node tests/env/node/getting_started.js", "test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start", "test:env:nitro-app": "yarn build && yarn --cwd tests/env/nitro-app test", - "size": "node scripts/file-size ./dist/bundles/meilisearch.mjs ./dist/bundles/meilisearch.umd.min.js", "style": "yarn fmt && yarn lint", "style:fix": "yarn fmt:fix && yarn lint:fix", "fmt": "prettier -c ./**/*.{js,ts}", "fmt:fix": "prettier -w ./**/*.{js,ts}", "lint": "eslint .", - "lint:fix": "eslint --fix .", - "typingsheader": "node scripts/build.js" + "lint:fix": "eslint --fix ." }, "files": [ "src", @@ -86,37 +81,25 @@ ] }, "devDependencies": { - "@rollup/plugin-terser": "^0.4.4", - "@babel/core": "^7.25.2", - "@babel/preset-env": "^7.25.4", "@eslint/js": "^9.16.0", - "@rollup/plugin-babel": "^6.0.4", - "@rollup/plugin-commonjs": "28.0.0", - "@rollup/plugin-json": "^6.1.0", - "@rollup/plugin-node-resolve": "15.3.0", "@types/eslint__js": "^8.42.3", "@vitest/coverage-v8": "2.0.5", - "@vitest/eslint-plugin": "^1.1.4", "@types/node": "^22.10.1", - "brotli-size": "^4.0.0", "eslint": "^9.16.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-tsdoc": "^0.3.0", + "eslint-plugin-tsdoc": "^0.4.0", "globals": "^15.12.0", - "gzip-size": "^6.0.0", - "kleur": "^4.1.5", + "@vitest/eslint-plugin": "^1.1.13", + "eslint-config-prettier": "^9.1.0", "lint-staged": "15.2.10", "nodemon": "^3.1.7", "prettier": "^3.4.1", "prettier-plugin-jsdoc": "^1.3.0", - "pretty-bytes": "^5.6.0", - "rollup": "^4.22.5", - "rollup-plugin-typescript2": "^0.36.0", - "shx": "^0.3.2", "typedoc": "^0.27.2", - "typescript": "^5.4.5", "typescript-eslint": "^8.16.0", - "vitest": "2.0.5" + "vitest": "2.0.5", + "typescript": "^5.7.2", + "vite": "^6.0.1", + "@typescript-eslint/utils": "^8.16.0" }, "packageManager": "yarn@1.22.22" } diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 88e3b4221..000000000 --- a/rollup.config.js +++ /dev/null @@ -1,125 +0,0 @@ -const nodeResolve = require("@rollup/plugin-node-resolve"); -const { resolve } = require("node:path"); -const commonjs = require("@rollup/plugin-commonjs"); -const json = require("@rollup/plugin-json"); -const typescript = require("rollup-plugin-typescript2"); -const pkg = require("./package.json"); -const terser = require("@rollup/plugin-terser"); -const { babel } = require("@rollup/plugin-babel"); - -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 PLUGINS = [ - typescript({ - useTsconfigDeclarationDir: true, - tsconfigOverride: { - compilerOptions: { allowJs: false }, - include: ["src"], - exclude: ["tests", "examples", "*.js", "scripts"], - }, - }), -]; - -const INDEX_INPUT = "src/index.ts"; -const TOKEN_INPUT = "src/token.ts"; - -const INDEX_EXPORTS = pkg.exports["."]; -const TOKEN_EXPORTS = pkg.exports["./token"]; - -module.exports = [ - // Index - { - input: INDEX_INPUT, - output: { - name: "window", - extend: true, - file: getOutputFileName( - // will add .min. in filename if in production env - resolve(ROOT, INDEX_EXPORTS.browser), - env === "production", - ), - format: "umd", - sourcemap: env === "production", // create sourcemap for error reporting in production mode - }, - plugins: [ - ...PLUGINS, - babel({ - babelrc: false, - extensions: [".ts"], - presets: [ - [ - "@babel/preset-env", - { - modules: false, - targets: { - browsers: ["last 2 versions", "ie >= 11"], - }, - }, - ], - ], - }), - nodeResolve({ - mainFields: ["jsnext", "main"], - preferBuiltins: true, - browser: true, - }), - commonjs({ - include: ["node_modules/**"], - }), - // nodePolyfills - json(), - env === "production" ? terser() : {}, - ], - }, - { - input: INDEX_INPUT, - output: [ - { - file: INDEX_EXPORTS.import, - exports: "named", - format: "es", - sourcemap: env === "production", - }, - ], - plugins: PLUGINS, - }, - { - input: INDEX_INPUT, - output: { - file: INDEX_EXPORTS.require, - exports: "named", - format: "cjs", - sourcemap: env === "production", - }, - plugins: PLUGINS, - }, - - // Token - { - input: TOKEN_INPUT, - output: [ - { - file: TOKEN_EXPORTS.import, - exports: "named", - format: "es", - sourcemap: env === "production", - }, - ], - plugins: PLUGINS, - }, - { - input: TOKEN_INPUT, - output: { - file: TOKEN_EXPORTS.require, - exports: "named", - format: "cjs", - sourcemap: env === "production", // create sourcemap for error reporting in production mode - }, - plugins: PLUGINS, - }, -]; diff --git a/scripts/build.js b/scripts/build.js index c4e63bfe6..08cfd4645 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,12 +1,14 @@ /** This file only purpose is to execute any build related tasks */ -const { resolve, normalize } = require("node:path"); -const { readFileSync, writeFileSync } = require("node:fs"); +import { resolve, normalize } from "node:path"; +import { fileURLToPath } from "node:url"; +import { readFileSync, writeFileSync } from "node:fs"; +import { createRequire } from "node:module"; -const pkg = require("../package.json"); +const pkg = createRequire(import.meta.url)("../package.json"); -const ROOT = resolve(__dirname, ".."); -const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.typings)); +const ROOT = fileURLToPath(new URL("..", import.meta.url)); +const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.exports["."].types)); main(); diff --git a/scripts/file-size.js b/scripts/file-size.js deleted file mode 100644 index 56ef339b2..000000000 --- a/scripts/file-size.js +++ /dev/null @@ -1,76 +0,0 @@ -const { basename, normalize } = require("node:path"); -const { readFile: readFileCb } = require("node:fs"); -const { promisify } = require("node:util"); -const readFile = promisify(readFileCb); - -const kolor = require("kleur"); -const prettyBytes = require("pretty-bytes"); -const brotliSize = require("brotli-size"); -const gzipSize = require("gzip-size"); -const { log } = console; -const pkg = require("../package.json"); - -main(); - -async function main() { - const args = process.argv.splice(2); - const filePaths = [...args.map(normalize)]; - const fileMetadata = await Promise.all( - filePaths.map(async (filePath) => { - return { - path: filePath, - blob: await readFile(filePath, { encoding: "utf8" }), - }; - }), - ); - - const output = await Promise.all( - fileMetadata.map((metadata) => getSizeInfo(metadata.blob, metadata.path)), - ); - - log(getFormatedOutput(pkg.name, output)); -} - -/** - * @param {string} pkgName - * @param {string[]} filesOutput - */ -function getFormatedOutput(pkgName, filesOutput) { - const MAGIC_INDENTATION = 3; - const WHITE_SPACE = " ".repeat(MAGIC_INDENTATION); - - return ( - kolor.blue(`${pkgName} bundle sizes: 📦`) + - `\n${WHITE_SPACE}` + - readFile.name + - filesOutput.join(`\n${WHITE_SPACE}`) - ); -} - -/** - * @param {number} size - * @param {string} filename - * @param {"br" | "gz"} type - * @param {boolean} raw - */ -function formatSize(size, filename, type, raw) { - const pretty = raw ? `${size} B` : prettyBytes(size); - const color = size < 5000 ? "green" : size > 40000 ? "red" : "yellow"; - const MAGIC_INDENTATION = type === "br" ? 13 : 10; - - return `${" ".repeat(MAGIC_INDENTATION - pretty.length)}${kolor[color]( - pretty, - )}: ${kolor.white(basename(filename))}.${type}`; -} - -/** - * @param {string} code - * @param {string} filename - * @param {boolean} [raw=false] Default is `false` - */ -async function getSizeInfo(code, filename, raw = false) { - const isRaw = raw || code.length < 5000; - const gzip = formatSize(await gzipSize(code), filename, "gz", isRaw); - const brotli = formatSize(await brotliSize.sync(code), filename, "br", isRaw); - return gzip + "\n" + brotli; -} diff --git a/src/enqueued-task.ts b/src/enqueued-task.ts index 76d0e5abb..dce0512d5 100644 --- a/src/enqueued-task.ts +++ b/src/enqueued-task.ts @@ -1,4 +1,4 @@ -import { EnqueuedTaskObject } from "./types"; +import type { EnqueuedTaskObject } from "./types/index.js"; class EnqueuedTask { taskUid: EnqueuedTaskObject["taskUid"]; diff --git a/src/errors/index.ts b/src/errors/index.ts index 79e2c7748..a28f0a8e4 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -1,5 +1,5 @@ -export * from "./meilisearch-api-error"; -export * from "./meilisearch-request-error"; -export * from "./meilisearch-error"; -export * from "./meilisearch-timeout-error"; -export * from "./version-hint-message"; +export * from "./meilisearch-api-error.js"; +export * from "./meilisearch-request-error.js"; +export * from "./meilisearch-error.js"; +export * from "./meilisearch-timeout-error.js"; +export * from "./version-hint-message.js"; diff --git a/src/errors/meilisearch-api-error.ts b/src/errors/meilisearch-api-error.ts index 27442b40d..aeb1dd0cb 100644 --- a/src/errors/meilisearch-api-error.ts +++ b/src/errors/meilisearch-api-error.ts @@ -1,5 +1,5 @@ -import { MeiliSearchErrorResponse } from "../types"; -import { MeiliSearchError } from "./meilisearch-error"; +import type { MeiliSearchErrorResponse } from "../types/index.js"; +import { MeiliSearchError } from "./meilisearch-error.js"; export class MeiliSearchApiError extends MeiliSearchError { override name = "MeiliSearchApiError"; diff --git a/src/errors/meilisearch-request-error.ts b/src/errors/meilisearch-request-error.ts index 5d420db14..996a06d96 100644 --- a/src/errors/meilisearch-request-error.ts +++ b/src/errors/meilisearch-request-error.ts @@ -1,4 +1,4 @@ -import { MeiliSearchError } from "./meilisearch-error"; +import { MeiliSearchError } from "./meilisearch-error.js"; export class MeiliSearchRequestError extends MeiliSearchError { override name = "MeiliSearchRequestError"; diff --git a/src/errors/meilisearch-timeout-error.ts b/src/errors/meilisearch-timeout-error.ts index c2516155f..2dbbc0286 100644 --- a/src/errors/meilisearch-timeout-error.ts +++ b/src/errors/meilisearch-timeout-error.ts @@ -1,4 +1,4 @@ -import { MeiliSearchError } from "./meilisearch-error"; +import { MeiliSearchError } from "./meilisearch-error.js"; export class MeiliSearchTimeOutError extends MeiliSearchError { override name = "MeiliSearchTimeOutError"; diff --git a/src/http-requests.ts b/src/http-requests.ts index 971c2df11..b91e64ab9 100644 --- a/src/http-requests.ts +++ b/src/http-requests.ts @@ -1,13 +1,13 @@ -import { Config, EnqueuedTaskObject } from "./types"; -import { PACKAGE_VERSION } from "./package-version"; +import type { Config, EnqueuedTaskObject } from "./types/index.js"; +import { PACKAGE_VERSION } from "./package-version.js"; import { MeiliSearchError, MeiliSearchApiError, MeiliSearchRequestError, -} from "./errors"; +} from "./errors/index.js"; -import { addTrailingSlash, addProtocolIfNotPresent } from "./utils"; +import { addTrailingSlash, addProtocolIfNotPresent } from "./utils.js"; type queryParams = { [key in keyof T]: string }; diff --git a/src/index.ts b/src/index.ts index 101f8f14d..5db17807a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,8 @@ -export * from "./types"; -export * from "./errors"; -export * from "./indexes"; -export * from "./enqueued-task"; -export * from "./task"; -import { MeiliSearch } from "./meilisearch"; +export * from "./types/index.js"; +export * from "./errors/index.js"; +export * from "./indexes.js"; +export * from "./enqueued-task.js"; +export * from "./task.js"; +import { MeiliSearch } from "./meilisearch.js"; export { MeiliSearch, MeiliSearch as Meilisearch }; -export default MeiliSearch; diff --git a/src/indexes.ts b/src/indexes.ts index f965706b9..fbe3be1cd 100644 --- a/src/indexes.ts +++ b/src/indexes.ts @@ -12,8 +12,8 @@ import { MeiliSearchRequestError, versionErrorHintMessage, MeiliSearchApiError, -} from "./errors"; -import { +} from "./errors/index.js"; +import type { Config, SearchResponse, SearchParams, @@ -56,11 +56,11 @@ import { SearchSimilarDocumentsParams, LocalizedAttributes, UpdateDocumentsByFunctionOptions, -} from "./types"; -import { removeUndefinedFromObject } from "./utils"; -import { HttpRequests } from "./http-requests"; -import { Task, TaskClient } from "./task"; -import { EnqueuedTask } from "./enqueued-task"; +} from "./types/index.js"; +import { removeUndefinedFromObject } from "./utils.js"; +import { HttpRequests } from "./http-requests.js"; +import { Task, TaskClient } from "./task.js"; +import { EnqueuedTask } from "./enqueued-task.js"; class Index = Record> { uid: string; diff --git a/src/meilisearch.ts b/src/meilisearch.ts index be82720d5..e62f94c46 100644 --- a/src/meilisearch.ts +++ b/src/meilisearch.ts @@ -5,8 +5,8 @@ * Copyright: 2019, MeiliSearch */ -import { Index } from "./indexes"; -import { +import { Index } from "./indexes.js"; +import type { KeyCreation, Config, IndexOptions, @@ -15,7 +15,6 @@ import { Health, Stats, Version, - ErrorStatusCode, TasksQuery, WaitOptions, KeyUpdate, @@ -31,10 +30,11 @@ import { MultiSearchParams, FederatedMultiSearchParams, MultiSearchResponseOrSearchResponse, -} from "./types"; -import { HttpRequests } from "./http-requests"; -import { TaskClient, Task } from "./task"; -import { EnqueuedTask } from "./enqueued-task"; +} from "./types/index.js"; +import { ErrorStatusCode } from "./types/index.js"; +import { HttpRequests } from "./http-requests.js"; +import { TaskClient, Task } from "./task.js"; +import { EnqueuedTask } from "./enqueued-task.js"; export class MeiliSearch { config: Config; diff --git a/src/task.ts b/src/task.ts index de3388add..f56d83100 100644 --- a/src/task.ts +++ b/src/task.ts @@ -1,18 +1,18 @@ -import { MeiliSearchTimeOutError } from "./errors"; -import { +import { MeiliSearchTimeOutError } from "./errors/index.js"; +import type { Config, WaitOptions, - TaskStatus, TasksQuery, TasksResults, TaskObject, CancelTasksQuery, TasksResultsObject, DeleteTasksQuery, -} from "./types"; -import { HttpRequests, toQueryParams } from "./http-requests"; -import { sleep } from "./utils"; -import { EnqueuedTask } from "./enqueued-task"; +} from "./types/index.js"; +import { TaskStatus } from "./types/index.js"; +import { HttpRequests, toQueryParams } from "./http-requests.js"; +import { sleep } from "./utils.js"; +import { EnqueuedTask } from "./enqueued-task.js"; class Task { indexUid: TaskObject["indexUid"]; diff --git a/src/token.ts b/src/token.ts index 4ed29e8f6..a3ad348f4 100644 --- a/src/token.ts +++ b/src/token.ts @@ -1,6 +1,7 @@ -import { TokenSearchRules, TokenOptions } from "./types"; -import { MeiliSearchError } from "./errors"; -import { validateUuid4 } from "./utils"; +import type { TokenSearchRules, TokenOptions } from "./types/index.js"; +import { createHmac } from "node:crypto"; +import { MeiliSearchError } from "./errors/index.js"; +import { validateUuid4 } from "./utils.js"; function encode64(data: any) { return Buffer.from(JSON.stringify(data)).toString("base64"); @@ -14,13 +15,11 @@ function encode64(data: any) { * @param encodedPayload - Payload of the token in base64. * @returns The signature of the token in base64. */ -async function sign( +function sign( apiKey: string, encodedHeader: string, encodedPayload: string, ) { - const { createHmac } = await import("node:crypto"); - return createHmac("sha256", apiKey) .update(`${encodedHeader}.${encodedPayload}`) .digest("base64") @@ -127,11 +126,11 @@ function createPayload({ * @param options - Token options to customize some aspect of the token. * @returns The token in JWT format. */ -export async function generateTenantToken( +export function generateTenantToken( apiKeyUid: string, searchRules: TokenSearchRules, { apiKey, expiresAt }: TokenOptions, -): Promise { +): string { validateTokenParameters({ apiKeyUid, expiresAt, searchRules }); const encodedHeader = createHeader(); @@ -140,7 +139,7 @@ export async function generateTenantToken( apiKeyUid, expiresAt, }); - const signature = await sign(apiKey, encodedHeader, encodedPayload); + const signature = sign(apiKey, encodedHeader, encodedPayload); return `${encodedHeader}.${encodedPayload}.${signature}`; } diff --git a/src/types/index.ts b/src/types/index.ts index eea524d65..a0c4ebf25 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1 +1 @@ -export * from "./types"; +export * from "./types.js"; diff --git a/src/types/types.ts b/src/types/types.ts index d1844ccbd..ab6bc82b5 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/meilisearch/meilisearch-js // TypeScript Version: ^3.8.3 -import { Task } from "../task"; +import { Task } from "../task.js"; export type Config = { host: string; diff --git a/tests/client.test.ts b/tests/client.test.ts index 09693d124..24b69531a 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -1,6 +1,7 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode, Health, Version, Stats, TaskTypes } from "../src"; -import { PACKAGE_VERSION } from "../src/package-version"; +import type { Health, Version, Stats } from "../src/index.js"; +import { ErrorStatusCode, TaskTypes } from "../src/index.js"; +import { PACKAGE_VERSION } from "../src/package-version.js"; import { clearAllIndexes, getKey, @@ -9,7 +10,7 @@ import { MeiliSearch, BAD_HOST, HOST, -} from "./utils/meilisearch-test-utils"; +} from "./utils/meilisearch-test-utils.js"; const indexNoPk = { uid: "movies_test", @@ -228,8 +229,8 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( const client = new MeiliSearch({ ...config, apiKey: key, - async httpClient(url, init) { - const result = await fetch(url, init); + async httpClient(...params: Parameters) { + const result = await fetch(...params); return result.json(); }, }); @@ -346,7 +347,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])( await client.waitForTask(taskUid); const { results } = await client.getRawIndexes(); - const indexes = results.map((index) => index.uid); + const indexes = results.map((index: any) => index.uid); expect(indexes).toEqual(expect.arrayContaining([indexPk.uid])); expect(indexes.length).toEqual(1); }); diff --git a/tests/dictionary.test.ts b/tests/dictionary.test.ts index 1215eedba..b063d93af 100644 --- a/tests/dictionary.test.ts +++ b/tests/dictionary.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { EnqueuedTask } from "../src/enqueued-task"; +import { EnqueuedTask } from "../src/enqueued-task.js"; import { clearAllIndexes, config, @@ -7,7 +7,7 @@ import { MeiliSearch, getClient, dataset, -} from "./utils/meilisearch-test-utils"; +} from "./utils/meilisearch-test-utils.js"; const index = { uid: "movies_test", diff --git a/tests/displayed_attributes.test.ts b/tests/displayed_attributes.test.ts index 6837f320d..39e399997 100644 --- a/tests/displayed_attributes.test.ts +++ b/tests/displayed_attributes.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types"; +import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -7,7 +7,7 @@ import { MeiliSearch, getClient, dataset, -} from "./utils/meilisearch-test-utils"; +} from "./utils/meilisearch-test-utils.js"; const index = { uid: "movies_test", diff --git a/tests/distinct_attribute.test.ts b/tests/distinct_attribute.test.ts index 911fbc10d..427558f2d 100644 --- a/tests/distinct_attribute.test.ts +++ b/tests/distinct_attribute.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types"; +import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -7,7 +7,7 @@ import { MeiliSearch, getClient, dataset, -} from "./utils/meilisearch-test-utils"; +} from "./utils/meilisearch-test-utils.js"; const index = { uid: "movies_test", diff --git a/tests/documents.test.ts b/tests/documents.test.ts index 61f44d033..d17e86394 100644 --- a/tests/documents.test.ts +++ b/tests/documents.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode, TaskStatus, TaskTypes } from "../src/types"; +import { ErrorStatusCode, TaskStatus, TaskTypes } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -7,10 +7,10 @@ import { MeiliSearch, getClient, dataset, - Book, + type Book, getKey, HOST, -} from "./utils/meilisearch-test-utils"; +} from "./utils/meilisearch-test-utils.js"; const indexNoPk = { uid: "movies_test", diff --git a/tests/dump.test.ts b/tests/dump.test.ts index 0a3acd677..c2258fecb 100644 --- a/tests/dump.test.ts +++ b/tests/dump.test.ts @@ -1,12 +1,12 @@ import { expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode, TaskStatus } from "../src/types"; +import { ErrorStatusCode, TaskStatus } from "../src/types/index.js"; import { clearAllIndexes, config, MeiliSearch, BAD_HOST, getClient, -} from "./utils/meilisearch-test-utils"; +} from "./utils/meilisearch-test-utils.js"; beforeEach(async () => { await clearAllIndexes(config); diff --git a/tests/embedders.test.ts b/tests/embedders.test.ts index e0506a26a..90ad7c08a 100644 --- a/tests/embedders.test.ts +++ b/tests/embedders.test.ts @@ -1,6 +1,6 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { EnqueuedTask } from "../src/enqueued-task"; -import { Embedders } from "../src/types"; +import { EnqueuedTask } from "../src/enqueued-task.js"; +import type { Embedders } from "../src/types/index.js"; import { clearAllIndexes, config, @@ -9,7 +9,7 @@ import { MeiliSearch, getClient, getKey, -} from "./utils/meilisearch-test-utils"; +} from "./utils/meilisearch-test-utils.js"; const index = { uid: "movies_test", diff --git a/tests/env/browser/index.html b/tests/env/browser/index.html index 092a96469..5d5ffed03 100644 --- a/tests/env/browser/index.html +++ b/tests/env/browser/index.html @@ -12,7 +12,7 @@ - + + + diff --git a/tests/env/express/.gitignore b/tests/env/express/.gitignore index 3c3629e64..8bc648947 100644 --- a/tests/env/express/.gitignore +++ b/tests/env/express/.gitignore @@ -1 +1,2 @@ node_modules +public/index.umd.min.js diff --git a/tests/env/express/public/headers.html b/tests/env/express/public/headers.html index 2414d3762..1dab2435f 100644 --- a/tests/env/express/public/headers.html +++ b/tests/env/express/public/headers.html @@ -13,10 +13,10 @@ - + + diff --git a/tests/env/express/public/meilisearch.umd.js b/tests/env/express/public/meilisearch.umd.js deleted file mode 120000 index 05a391a12..000000000 --- a/tests/env/express/public/meilisearch.umd.js +++ /dev/null @@ -1 +0,0 @@ -../../../../dist/bundles/meilisearch.umd.js \ No newline at end of file diff --git a/tests/env/typescript-node/src/index.ts b/tests/env/typescript-node/src/index.ts index 0ff282d4c..62c15b807 100644 --- a/tests/env/typescript-node/src/index.ts +++ b/tests/env/typescript-node/src/index.ts @@ -5,7 +5,7 @@ import { Hits, Hit, SearchParams, -} from '../../../../src' +} from '../../../../src/index' import { generateTenantToken } from '../../../../src/token' const config = { diff --git a/tests/env/typescript-node/tsconfig.json b/tests/env/typescript-node/tsconfig.json index 74d6d24d2..811d2c482 100644 --- a/tests/env/typescript-node/tsconfig.json +++ b/tests/env/typescript-node/tsconfig.json @@ -5,7 +5,8 @@ "noEmitOnError": true, "moduleResolution": "node", "module": "commonjs", - "outDir": "./dist" + "outDir": "./dist", + "verbatimModuleSyntax": false }, "include": ["src/index.ts"] } From 1e6e56956c3bb18522000b079cfb7fb85a603962 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:23:22 +0300 Subject: [PATCH 03/26] Fix format issues --- src/token.ts | 6 +----- tests/keys.test.ts | 2 +- tests/localized_attributes.test.ts | 5 ++++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/token.ts b/src/token.ts index a3ad348f4..11f4b5725 100644 --- a/src/token.ts +++ b/src/token.ts @@ -15,11 +15,7 @@ function encode64(data: any) { * @param encodedPayload - Payload of the token in base64. * @returns The signature of the token in base64. */ -function sign( - apiKey: string, - encodedHeader: string, - encodedPayload: string, -) { +function sign(apiKey: string, encodedHeader: string, encodedPayload: string) { return createHmac("sha256", apiKey) .update(`${encodedHeader}.${encodedPayload}`) .digest("base64") diff --git a/tests/keys.test.ts b/tests/keys.test.ts index 8c3e63d4a..30792cb0c 100644 --- a/tests/keys.test.ts +++ b/tests/keys.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; -import {MeiliSearch} from "../src/index.js"; +import { MeiliSearch } from "../src/index.js"; import { ErrorStatusCode } from "../src/types/index.js"; import { clearAllIndexes, diff --git a/tests/localized_attributes.test.ts b/tests/localized_attributes.test.ts index cf4d1a2f8..b400adfce 100644 --- a/tests/localized_attributes.test.ts +++ b/tests/localized_attributes.test.ts @@ -6,7 +6,10 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode, type LocalizedAttributes } from "../src/types/index.js"; +import { + ErrorStatusCode, + type LocalizedAttributes, +} from "../src/types/index.js"; import { clearAllIndexes, config, From 4bff8742114eb45187a5d23ff3698560c282ff99 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:26:50 +0300 Subject: [PATCH 04/26] Fix 'types' script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3d3cf25d..a742f0cfb 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "watch": "yarn cleanup && rollup -c --watch", "test": "vitest run --coverage", "types:watch": "nodemon --config nodemon.json", - "types": "yarn tsc", + "types": "tsc -p tsconfig.build.json --noEmit", "test:env:browser": "node scripts/copy-umd-file.js -to ./tests/env/express/public && yarn build && yarn --cwd tests/env/express && yarn --cwd tests/env/express test", "test:watch": "vitest watch", "test:coverage": "yarn test", From df0a3eb726b5d86d095d0b777da8a334499b121c Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:34:30 +0300 Subject: [PATCH 05/26] Fix token test --- tests/token.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/token.test.ts b/tests/token.test.ts index a2533f3bf..648659d54 100644 --- a/tests/token.test.ts +++ b/tests/token.test.ts @@ -176,9 +176,9 @@ describe.each([{ permission: "Admin" }])( const { uid } = await client.getKey(apiKey); const date = new Date("December 17, 2000 03:24:00"); - await expect( + expect(() => generateTenantToken(uid, ["*"], { apiKey, expiresAt: date }), - ).rejects.toThrow( + ).toThrowError( `Meilisearch: The expiresAt field must be a date in the future.`, ); }); @@ -255,9 +255,9 @@ describe.each([{ permission: "Admin" }])( const { uid } = await client.getKey(apiKey); const date = new Date("December 17, 2000 03:24:00"); - await expect( + expect(() => generateTenantToken(uid, {}, { apiKey, expiresAt: date }), - ).rejects.toThrow( + ).toThrowError( `Meilisearch: The expiresAt field must be a date in the future.`, ); }); From 805c88ba32c4da346710fb09e609f131578311ac Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:43:55 +0300 Subject: [PATCH 06/26] Fix env esm test --- tests/env/esm/src/index.js | 8 +++----- tests/env/node/README.md | 2 +- .../env/node/{getting_started.js => getting_started.cjs} | 0 tests/env/node/{index.js => index.cjs} | 6 ++---- tests/env/node/{search_example.js => search_example.cjs} | 0 5 files changed, 6 insertions(+), 10 deletions(-) rename tests/env/node/{getting_started.js => getting_started.cjs} (100%) rename tests/env/node/{index.js => index.cjs} (50%) rename tests/env/node/{search_example.js => search_example.cjs} (100%) diff --git a/tests/env/esm/src/index.js b/tests/env/esm/src/index.js index daf03c008..adea3a2fa 100644 --- a/tests/env/esm/src/index.js +++ b/tests/env/esm/src/index.js @@ -1,8 +1,6 @@ -import { MeiliSearch } from '../../../../' -import * as DefaultMeiliSearch from '../../../../' -import { generateTenantToken } from '../../../../dist/bundles/token.mjs' +import { MeiliSearch } from '../../../../dist/esm/index.js' +import { generateTenantToken } from '../../../../dist/esm/token.js' const client = new MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) -const defaultClient = new DefaultMeiliSearch.MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) const token = generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [], { apiKey: 'masterKey' }) -console.log({ client, token, defaultClient }) +console.log({ client, token }) diff --git a/tests/env/node/README.md b/tests/env/node/README.md index a447f0434..46fe2d9c9 100644 --- a/tests/env/node/README.md +++ b/tests/env/node/README.md @@ -21,5 +21,5 @@ To try it out you just need to execute the script that you want to try out. For example: ``` -node search_example.js +node search_example.cjs ``` diff --git a/tests/env/node/getting_started.js b/tests/env/node/getting_started.cjs similarity index 100% rename from tests/env/node/getting_started.js rename to tests/env/node/getting_started.cjs diff --git a/tests/env/node/index.js b/tests/env/node/index.cjs similarity index 50% rename from tests/env/node/index.js rename to tests/env/node/index.cjs index b98be85f0..72196d65c 100644 --- a/tests/env/node/index.js +++ b/tests/env/node/index.cjs @@ -1,10 +1,8 @@ -const { MeiliSearch } = require('../../../') -const DefaultMeiliSearch = require('../../../') +const { MeiliSearch } = require('../../../dist/bundles/index.cjs') const { generateTenantToken } = require('../../../dist/bundles/token.cjs') const CJStest = new MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) -const DefaultCJSTest = new DefaultMeiliSearch.MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [], { apiKey: 'masterKey' }) -console.log({ CJStest, DefaultCJSTest }) +console.log({ CJStest }) diff --git a/tests/env/node/search_example.js b/tests/env/node/search_example.cjs similarity index 100% rename from tests/env/node/search_example.js rename to tests/env/node/search_example.cjs From 5dc0a245ad37f1d4bc5e63dd6cf0c2891b38571d Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:50:04 +0300 Subject: [PATCH 07/26] Fix env nodejs test --- package.json | 2 +- tests/env/node/getting_started.cjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a742f0cfb..298dc8c8f 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "test:ci": "yarn test", "test:env": "yarn build && yarn test:env:nodejs && yarn test:env:esm && yarn test:env:node-ts", "test:env:node-ts": "yarn --cwd tests/env/typescript-node start", - "test:env:nodejs": "yarn build && node tests/env/node/index.js && node tests/env/node/getting_started.js", + "test:env:nodejs": "yarn build && node tests/env/node/index.cjs && node tests/env/node/getting_started.cjs", "test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start", "test:env:nitro-app": "yarn build && yarn --cwd tests/env/nitro-app test", "style": "yarn fmt && yarn lint", diff --git a/tests/env/node/getting_started.cjs b/tests/env/node/getting_started.cjs index bf9802985..d36cea73e 100644 --- a/tests/env/node/getting_started.cjs +++ b/tests/env/node/getting_started.cjs @@ -1,4 +1,4 @@ -const { MeiliSearch } = require('../../../dist/bundles/meilisearch.umd.js') +const { MeiliSearch } = require('../../../dist/bundles/index.cjs') ;(async () => { const client = new MeiliSearch({ From ec7d4e98265eb28d9a665b01e169e99e43c2439c Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:53:09 +0300 Subject: [PATCH 08/26] Fix env browser test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 298dc8c8f..f49af056b 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "test": "vitest run --coverage", "types:watch": "nodemon --config nodemon.json", "types": "tsc -p tsconfig.build.json --noEmit", - "test:env:browser": "node scripts/copy-umd-file.js -to ./tests/env/express/public && yarn build && yarn --cwd tests/env/express && yarn --cwd tests/env/express test", + "test:env:browser": "node scripts/copy-umd-file.js --to ./tests/env/express/public && yarn build && yarn --cwd tests/env/express && yarn --cwd tests/env/express test", "test:watch": "vitest watch", "test:coverage": "yarn test", "test:ci": "yarn test", From bd7212b1cbef0f9f696fe7169341888d0955b929 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sun, 6 Oct 2024 11:06:33 +0300 Subject: [PATCH 09/26] Remove unnecessary index file, misc --- package.json | 5 ++--- src/enqueued-task.ts | 2 +- src/errors/meilisearch-api-error.ts | 2 +- src/http-requests.ts | 2 +- src/index.ts | 2 +- src/indexes.ts | 4 +--- src/meilisearch.ts | 4 ++-- src/task.ts | 4 ++-- src/token.ts | 2 +- src/types/index.ts | 1 - tests/displayed_attributes.test.ts | 2 +- tests/distinct_attribute.test.ts | 2 +- tests/documents.test.ts | 2 +- tests/dump.test.ts | 2 +- tests/embedders.test.ts | 2 +- tests/faceting.test.ts | 2 +- tests/filterable_attributes.test.ts | 2 +- tests/get_search.test.ts | 2 +- tests/index.test.ts | 2 +- tests/keys.test.ts | 2 +- tests/localized_attributes.test.ts | 2 +- tests/pagination.test.ts | 2 +- tests/ranking_rules.test.ts | 2 +- tests/raw_document.test.ts | 2 +- tests/search.test.ts | 2 +- tests/search_cutoff_ms.test.ts | 2 +- tests/searchable_attributes.test.ts | 2 +- tests/settings.test.ts | 2 +- tests/snapshots.test.ts | 2 +- tests/sortable_attributes.test.ts | 2 +- tests/stop_words.test.ts | 2 +- tests/synonyms.test.ts | 2 +- tests/task.test.ts | 2 +- tests/typed_search.test.ts | 2 +- tests/typo_tolerance.test.ts | 2 +- tests/utils/meilisearch-test-utils.ts | 2 +- tsconfig.build.json | 1 + tsconfig.json | 5 +++-- vite.config.js | 6 +++--- yarn.lock | 23 ++++++++++++++++------- 40 files changed, 61 insertions(+), 54 deletions(-) delete mode 100644 src/types/index.ts diff --git a/package.json b/package.json index f49af056b..25a0d6dec 100644 --- a/package.json +++ b/package.json @@ -42,13 +42,12 @@ }, "scripts": { "playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start", + "build:docs": "typedoc", "build": "vite build && tsc -p tsconfig.build.json && vite --mode production-cjs build", "postbuild": "node scripts/build.js", - "build:docs": "typedoc", - "watch": "yarn cleanup && rollup -c --watch", "test": "vitest run --coverage", - "types:watch": "nodemon --config nodemon.json", "types": "tsc -p tsconfig.build.json --noEmit", + "types:watch": "yarn types --watch", "test:env:browser": "node scripts/copy-umd-file.js --to ./tests/env/express/public && yarn build && yarn --cwd tests/env/express && yarn --cwd tests/env/express test", "test:watch": "vitest watch", "test:coverage": "yarn test", diff --git a/src/enqueued-task.ts b/src/enqueued-task.ts index dce0512d5..95d6efdbf 100644 --- a/src/enqueued-task.ts +++ b/src/enqueued-task.ts @@ -1,4 +1,4 @@ -import type { EnqueuedTaskObject } from "./types/index.js"; +import type { EnqueuedTaskObject } from "./types/types.js"; class EnqueuedTask { taskUid: EnqueuedTaskObject["taskUid"]; diff --git a/src/errors/meilisearch-api-error.ts b/src/errors/meilisearch-api-error.ts index aeb1dd0cb..f663dd76e 100644 --- a/src/errors/meilisearch-api-error.ts +++ b/src/errors/meilisearch-api-error.ts @@ -1,4 +1,4 @@ -import type { MeiliSearchErrorResponse } from "../types/index.js"; +import type { MeiliSearchErrorResponse } from "../types/types.js"; import { MeiliSearchError } from "./meilisearch-error.js"; export class MeiliSearchApiError extends MeiliSearchError { diff --git a/src/http-requests.ts b/src/http-requests.ts index b91e64ab9..b8f78d7f2 100644 --- a/src/http-requests.ts +++ b/src/http-requests.ts @@ -1,4 +1,4 @@ -import type { Config, EnqueuedTaskObject } from "./types/index.js"; +import type { Config, EnqueuedTaskObject } from "./types/types.js"; import { PACKAGE_VERSION } from "./package-version.js"; import { diff --git a/src/index.ts b/src/index.ts index 5db17807a..511e6f585 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export * from "./types/index.js"; +export * from "./types/types.js"; export * from "./errors/index.js"; export * from "./indexes.js"; export * from "./enqueued-task.js"; diff --git a/src/indexes.ts b/src/indexes.ts index fbe3be1cd..de7ef8bf9 100644 --- a/src/indexes.ts +++ b/src/indexes.ts @@ -5,8 +5,6 @@ * Copyright: 2019, MeiliSearch */ -"use strict"; - import { MeiliSearchError, MeiliSearchRequestError, @@ -56,7 +54,7 @@ import type { SearchSimilarDocumentsParams, LocalizedAttributes, UpdateDocumentsByFunctionOptions, -} from "./types/index.js"; +} from "./types/types.js"; import { removeUndefinedFromObject } from "./utils.js"; import { HttpRequests } from "./http-requests.js"; import { Task, TaskClient } from "./task.js"; diff --git a/src/meilisearch.ts b/src/meilisearch.ts index e62f94c46..0a9a0aa76 100644 --- a/src/meilisearch.ts +++ b/src/meilisearch.ts @@ -30,8 +30,8 @@ import type { MultiSearchParams, FederatedMultiSearchParams, MultiSearchResponseOrSearchResponse, -} from "./types/index.js"; -import { ErrorStatusCode } from "./types/index.js"; +} from "./types/types.js"; +import { ErrorStatusCode } from "./types/types.js"; import { HttpRequests } from "./http-requests.js"; import { TaskClient, Task } from "./task.js"; import { EnqueuedTask } from "./enqueued-task.js"; diff --git a/src/task.ts b/src/task.ts index f56d83100..a6f08f0a8 100644 --- a/src/task.ts +++ b/src/task.ts @@ -8,8 +8,8 @@ import type { CancelTasksQuery, TasksResultsObject, DeleteTasksQuery, -} from "./types/index.js"; -import { TaskStatus } from "./types/index.js"; +} from "./types/types.js"; +import { TaskStatus } from "./types/types.js"; import { HttpRequests, toQueryParams } from "./http-requests.js"; import { sleep } from "./utils.js"; import { EnqueuedTask } from "./enqueued-task.js"; diff --git a/src/token.ts b/src/token.ts index 11f4b5725..478ae972c 100644 --- a/src/token.ts +++ b/src/token.ts @@ -1,4 +1,4 @@ -import type { TokenSearchRules, TokenOptions } from "./types/index.js"; +import type { TokenSearchRules, TokenOptions } from "./types/types.js"; import { createHmac } from "node:crypto"; import { MeiliSearchError } from "./errors/index.js"; import { validateUuid4 } from "./utils.js"; diff --git a/src/types/index.ts b/src/types/index.ts deleted file mode 100644 index a0c4ebf25..000000000 --- a/src/types/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./types.js"; diff --git a/tests/displayed_attributes.test.ts b/tests/displayed_attributes.test.ts index 39e399997..0d26d4c2c 100644 --- a/tests/displayed_attributes.test.ts +++ b/tests/displayed_attributes.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/distinct_attribute.test.ts b/tests/distinct_attribute.test.ts index 427558f2d..f9f0dc4fb 100644 --- a/tests/distinct_attribute.test.ts +++ b/tests/distinct_attribute.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/documents.test.ts b/tests/documents.test.ts index d17e86394..aaf65bca5 100644 --- a/tests/documents.test.ts +++ b/tests/documents.test.ts @@ -1,5 +1,5 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode, TaskStatus, TaskTypes } from "../src/types/index.js"; +import { ErrorStatusCode, TaskStatus, TaskTypes } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/dump.test.ts b/tests/dump.test.ts index c2258fecb..7232ccf2b 100644 --- a/tests/dump.test.ts +++ b/tests/dump.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe, beforeEach } from "vitest"; -import { ErrorStatusCode, TaskStatus } from "../src/types/index.js"; +import { ErrorStatusCode, TaskStatus } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/embedders.test.ts b/tests/embedders.test.ts index 90ad7c08a..0f5da3e1a 100644 --- a/tests/embedders.test.ts +++ b/tests/embedders.test.ts @@ -1,6 +1,6 @@ import { afterAll, expect, test, describe, beforeEach } from "vitest"; import { EnqueuedTask } from "../src/enqueued-task.js"; -import type { Embedders } from "../src/types/index.js"; +import type { Embedders } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/faceting.test.ts b/tests/faceting.test.ts index 46ae8c98a..f674f16a3 100644 --- a/tests/faceting.test.ts +++ b/tests/faceting.test.ts @@ -6,7 +6,7 @@ import { afterAll, beforeAll, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/filterable_attributes.test.ts b/tests/filterable_attributes.test.ts index d2540623e..4bfa16b13 100644 --- a/tests/filterable_attributes.test.ts +++ b/tests/filterable_attributes.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/get_search.test.ts b/tests/get_search.test.ts index 454439875..56b57a1aa 100644 --- a/tests/get_search.test.ts +++ b/tests/get_search.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe, afterAll, beforeAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { EnqueuedTask } from "../src/enqueued-task.js"; import { clearAllIndexes, diff --git a/tests/index.test.ts b/tests/index.test.ts index 14f58936f..5a9b1c1b3 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/keys.test.ts b/tests/keys.test.ts index 30792cb0c..95198f066 100644 --- a/tests/keys.test.ts +++ b/tests/keys.test.ts @@ -1,6 +1,6 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; import { MeiliSearch } from "../src/index.js"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/localized_attributes.test.ts b/tests/localized_attributes.test.ts index b400adfce..d5cbaf1fe 100644 --- a/tests/localized_attributes.test.ts +++ b/tests/localized_attributes.test.ts @@ -9,7 +9,7 @@ import { import { ErrorStatusCode, type LocalizedAttributes, -} from "../src/types/index.js"; +} from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/pagination.test.ts b/tests/pagination.test.ts index ea0547a55..ac992e5e1 100644 --- a/tests/pagination.test.ts +++ b/tests/pagination.test.ts @@ -6,7 +6,7 @@ afterAll, beforeAll, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/ranking_rules.test.ts b/tests/ranking_rules.test.ts index 6db04d1e0..1e3fe0dad 100644 --- a/tests/ranking_rules.test.ts +++ b/tests/ranking_rules.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe, beforeEach, afterAll } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { EnqueuedTask } from "../src/enqueued-task.js"; import { clearAllIndexes, diff --git a/tests/raw_document.test.ts b/tests/raw_document.test.ts index bb11d67c1..f23f3e8ef 100644 --- a/tests/raw_document.test.ts +++ b/tests/raw_document.test.ts @@ -4,7 +4,7 @@ import { config, getClient, } from "./utils/meilisearch-test-utils.js"; -import { TaskStatus, ContentTypeEnum } from "../src/types/index.js"; +import { TaskStatus, ContentTypeEnum } from "../src/types/types.js"; beforeEach(async () => { await clearAllIndexes(config); diff --git a/tests/search.test.ts b/tests/search.test.ts index c07e4b93e..35d4f6d3a 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -6,7 +6,7 @@ import { afterAll, beforeAll, } from "vitest"; -import { ErrorStatusCode, MatchingStrategies } from "../src/types/index.js"; +import { ErrorStatusCode, MatchingStrategies } from "../src/types/types.js"; import { EnqueuedTask } from "../src/enqueued-task.js"; import { clearAllIndexes, diff --git a/tests/search_cutoff_ms.test.ts b/tests/search_cutoff_ms.test.ts index fc1418279..08763bc05 100644 --- a/tests/search_cutoff_ms.test.ts +++ b/tests/search_cutoff_ms.test.ts @@ -6,7 +6,7 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/searchable_attributes.test.ts b/tests/searchable_attributes.test.ts index c88e3e50f..bb292a893 100644 --- a/tests/searchable_attributes.test.ts +++ b/tests/searchable_attributes.test.ts @@ -6,7 +6,7 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/settings.test.ts b/tests/settings.test.ts index 106c8c608..f058a0133 100644 --- a/tests/settings.test.ts +++ b/tests/settings.test.ts @@ -1,5 +1,5 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode, type Settings } from "../src/types/index.js"; +import { ErrorStatusCode, type Settings } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/snapshots.test.ts b/tests/snapshots.test.ts index 8561af3cb..2908cab8e 100644 --- a/tests/snapshots.test.ts +++ b/tests/snapshots.test.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode, TaskStatus } from "../src/types/index.js"; +import { ErrorStatusCode, TaskStatus } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/sortable_attributes.test.ts b/tests/sortable_attributes.test.ts index babdf695f..970213add 100644 --- a/tests/sortable_attributes.test.ts +++ b/tests/sortable_attributes.test.ts @@ -6,7 +6,7 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/stop_words.test.ts b/tests/stop_words.test.ts index bf5f3787c..7521bf033 100644 --- a/tests/stop_words.test.ts +++ b/tests/stop_words.test.ts @@ -1,5 +1,5 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { EnqueuedTask } from "../src/enqueued-task.js"; import { clearAllIndexes, diff --git a/tests/synonyms.test.ts b/tests/synonyms.test.ts index a246c55cf..a2d9456f2 100644 --- a/tests/synonyms.test.ts +++ b/tests/synonyms.test.ts @@ -1,5 +1,5 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/task.test.ts b/tests/task.test.ts index d2353c2cc..aefab1ada 100644 --- a/tests/task.test.ts +++ b/tests/task.test.ts @@ -1,5 +1,5 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode, TaskTypes, TaskStatus } from "../src/types/index.js"; +import { ErrorStatusCode, TaskTypes, TaskStatus } from "../src/types/types.js"; import { sleep } from "../src/utils.js"; import { clearAllIndexes, diff --git a/tests/typed_search.test.ts b/tests/typed_search.test.ts index 1b93904f3..8184a0d04 100644 --- a/tests/typed_search.test.ts +++ b/tests/typed_search.test.ts @@ -6,7 +6,7 @@ import { expect, test, } from "vitest"; -import { ErrorStatusCode, type SearchResponse } from "../src/types/index.js"; +import { ErrorStatusCode, type SearchResponse } from "../src/types/types.js"; import { EnqueuedTask } from "../src/enqueued-task.js"; import { clearAllIndexes, diff --git a/tests/typo_tolerance.test.ts b/tests/typo_tolerance.test.ts index 8a3dc77fa..f4c11f9af 100644 --- a/tests/typo_tolerance.test.ts +++ b/tests/typo_tolerance.test.ts @@ -1,5 +1,5 @@ import { afterAll, beforeEach, describe, expect, test } from "vitest"; -import { ErrorStatusCode } from "../src/types/index.js"; +import { ErrorStatusCode } from "../src/types/types.js"; import { clearAllIndexes, config, diff --git a/tests/utils/meilisearch-test-utils.ts b/tests/utils/meilisearch-test-utils.ts index ad55b9165..1943caca3 100644 --- a/tests/utils/meilisearch-test-utils.ts +++ b/tests/utils/meilisearch-test-utils.ts @@ -1,5 +1,5 @@ import { MeiliSearch, Index } from "../../src/index.js"; -import type { Config } from "../../src/types/index.js"; +import type { Config } from "../../src/types/types.js"; // testing const MASTER_KEY = "masterKey"; diff --git a/tsconfig.build.json b/tsconfig.build.json index 9db49faab..1012fbd96 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,4 +1,5 @@ { "extends": "./tsconfig.json", + "compilerOptions": { "outDir": "./dist/esm" }, "include": ["src/**/*.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 5c36c46e4..25935128d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,5 @@ +// @TODO: This should be used to type check whole project with script `types` +// but for now because of tests/env this is not possible { "compilerOptions": { // We don't want to check node_modules @@ -10,7 +12,6 @@ "target": "es2022", "lib": ["ESNext", "dom"], "strict": true, - "verbatimModuleSyntax": true, - "outDir": "./dist/esm" + "verbatimModuleSyntax": true } } diff --git a/vite.config.js b/vite.config.js index 9c34d0f29..ee36fb2c1 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,7 +1,7 @@ import { defineConfig } from "vite"; -const INDEX_INPUT = "src/index.ts"; -const TOKEN_INPUT = "src/token.ts"; +const indexInput = "src/index.ts"; +const tokenInput = "src/token.ts"; export default defineConfig(({ mode }) => { const isUMDBuild = mode === "production"; @@ -18,7 +18,7 @@ export default defineConfig(({ mode }) => { target: isUMDBuild ? "es6" : "es2022", lib: { // leave out token from UMD build - entry: isUMDBuild ? INDEX_INPUT : [INDEX_INPUT, TOKEN_INPUT], + entry: isUMDBuild ? indexInput : [indexInput, tokenInput], name: isUMDBuild ? "meilisearch" : undefined, formats: isUMDBuild ? ["umd"] : ["cjs"], fileName: (format, entryName) => { diff --git a/yarn.lock b/yarn.lock index a05c6db4c..7c44b953a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -357,10 +357,10 @@ "@shikijs/types" "^1.24.0" "@shikijs/vscode-textmate" "^9.3.0" -"@humanfs/core@^0.19.1": - version "0.19.1" - resolved "https://registry.yarnpkg.com/@humanfs/core/-/core-0.19.1.tgz#17c55ca7d426733fe3c561906b8173c336b40a77" - integrity sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA== +"@humanfs/core@^0.19.0": + version "0.19.0" + resolved "https://registry.yarnpkg.com/@humanfs/core/-/core-0.19.0.tgz#08db7a8c73bb07673d9ebd925f2dad746411fcec" + integrity sha512-2cbWIHbZVEweE853g8jymffCA+NCMiuqeECeBBLm8dg2oFdjuGJhgN4UAbI+6v0CKbbhvtXA4qV8YR5Ji86nmw== "@humanfs/node@^0.16.6": version "0.16.6" @@ -921,7 +921,7 @@ acorn-jsx@^5.3.2: resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ== -acorn@^8.14.0: +acorn@^8.12.0: version "8.14.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.14.0.tgz#063e2c70cac5fb4f6467f0b11152e04c682795b0" integrity sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA== @@ -1325,7 +1325,7 @@ eslint-visitor-keys@^3.3.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== -eslint-visitor-keys@^4.2.0: +eslint-visitor-keys@^4.0.0, eslint-visitor-keys@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz#687bacb2af884fcdda8a6e7d65c606f46a14cd45" integrity sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw== @@ -1370,7 +1370,16 @@ eslint@^9.16.0: natural-compare "^1.4.0" optionator "^0.9.3" -espree@^10.0.1, espree@^10.3.0: +espree@^10.0.1: + version "10.1.0" + resolved "https://registry.yarnpkg.com/espree/-/espree-10.1.0.tgz#8788dae611574c0f070691f522e4116c5a11fc56" + integrity sha512-M1M6CpiE6ffoigIOWYO9UDP8TMUw9kqb21tf+08IgDYjCsOvCuDt4jQcZmoYxx+w7zlKw9/N0KXfto+I8/FrXA== + dependencies: + acorn "^8.12.0" + acorn-jsx "^5.3.2" + eslint-visitor-keys "^4.0.0" + +espree@^10.3.0: version "10.3.0" resolved "https://registry.yarnpkg.com/espree/-/espree-10.3.0.tgz#29267cf5b0cb98735b65e64ba07e0ed49d1eed8a" integrity sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg== From 0b48a0f969dae2c4dec9954c400bf133f77c9ff8 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:34:12 +0300 Subject: [PATCH 10/26] Remove outdated entries from package.json, misc --- package.json | 21 +++++++++----------- tests/env/node/getting_started.cjs | 2 +- tests/env/node/index.cjs | 4 ++-- vite.config.js | 32 ++++++++++++++---------------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 25a0d6dec..7ba7f22cb 100644 --- a/package.json +++ b/package.json @@ -17,22 +17,19 @@ ], "license": "MIT", "type": "module", - "main": "./dist/bundles/index.cjs", - "module": "./dist/esm/index.js", - "jsdelivr": "./dist/bundles/index.umd.min.js", - "unpkg": "./dist/bundles/index.umd.min.js", + "jsdelivr": "./dist/umd/index.min.js", "exports": { ".": { "types": "./dist/types/index.d.ts", "import": "./dist/esm/index.js", - "require": "./dist/bundles/index.cjs", - "default": "./dist/bundles/index.umd.min.js" + "require": "./dist/cjs/index.cjs", + "default": "./dist/umd/index.min.js" }, "./token": { "types": "./dist/types/token.d.ts", "import": "./dist/esm/token.js", - "require": "./dist/bundles/token.cjs", - "default": "./dist/bundles/token.cjs" + "require": "./dist/cjs/token.cjs", + "default": "./dist/cjs/token.cjs" } }, "sideEffects": false, @@ -43,7 +40,7 @@ "scripts": { "playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start", "build:docs": "typedoc", - "build": "vite build && tsc -p tsconfig.build.json && vite --mode production-cjs build", + "build": "vite build && tsc -p tsconfig.build.json && vite --mode production-umd build", "postbuild": "node scripts/build.js", "test": "vitest run --coverage", "types": "tsc -p tsconfig.build.json --noEmit", @@ -57,12 +54,12 @@ "test:env:nodejs": "yarn build && node tests/env/node/index.cjs && node tests/env/node/getting_started.cjs", "test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start", "test:env:nitro-app": "yarn build && yarn --cwd tests/env/nitro-app test", - "style": "yarn fmt && yarn lint", - "style:fix": "yarn fmt:fix && yarn lint:fix", "fmt": "prettier -c ./**/*.{js,ts}", "fmt:fix": "prettier -w ./**/*.{js,ts}", "lint": "eslint .", - "lint:fix": "eslint --fix ." + "lint:fix": "eslint --fix .", + "style": "yarn fmt && yarn lint", + "style:fix": "yarn fmt:fix && yarn lint:fix" }, "files": [ "src", diff --git a/tests/env/node/getting_started.cjs b/tests/env/node/getting_started.cjs index d36cea73e..651101b27 100644 --- a/tests/env/node/getting_started.cjs +++ b/tests/env/node/getting_started.cjs @@ -1,4 +1,4 @@ -const { MeiliSearch } = require('../../../dist/bundles/index.cjs') +const { MeiliSearch } = require('../../../dist/cjs/index.cjs') ;(async () => { const client = new MeiliSearch({ diff --git a/tests/env/node/index.cjs b/tests/env/node/index.cjs index 72196d65c..708d4f7f6 100644 --- a/tests/env/node/index.cjs +++ b/tests/env/node/index.cjs @@ -1,5 +1,5 @@ -const { MeiliSearch } = require('../../../dist/bundles/index.cjs') -const { generateTenantToken } = require('../../../dist/bundles/token.cjs') +const { MeiliSearch } = require('../../../dist/cjs/index.cjs') +const { generateTenantToken } = require('../../../dist/cjs/token.cjs') const CJStest = new MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey' }) diff --git a/vite.config.js b/vite.config.js index ee36fb2c1..b2b6406df 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,40 +4,38 @@ const indexInput = "src/index.ts"; const tokenInput = "src/token.ts"; export default defineConfig(({ mode }) => { - const isUMDBuild = mode === "production"; + const isCJSBuild = mode === "production"; return { build: { - // for CJS build we do not want to empty directory, so previous builds stay intact - emptyOutDir: isUMDBuild, - // it only makes sense to minify the UMD build - minify: isUMDBuild, - // there's no point in generating source maps for UMD bundle @TODO: Is this true? - sourcemap: !isUMDBuild, + // for UMD build we do not want to empty directory, so previous builds stay intact + emptyOutDir: isCJSBuild, + minify: true, + sourcemap: true, // UMD build targets lower level ES, while CJS the lowest Node.js LTS version - target: isUMDBuild ? "es6" : "es2022", + target: isCJSBuild ? "es2022" : "es6", lib: { // leave out token from UMD build - entry: isUMDBuild ? indexInput : [indexInput, tokenInput], - name: isUMDBuild ? "meilisearch" : undefined, - formats: isUMDBuild ? ["umd"] : ["cjs"], + entry: isCJSBuild ? [indexInput, tokenInput] : indexInput, + name: isCJSBuild ? undefined : "meilisearch", + formats: isCJSBuild ? ["cjs"] : ["umd"], fileName: (format, entryName) => { switch (format) { case "umd": - return `bundles/${entryName}.umd.min.js`; + return `umd/${entryName}.min.js`; case "cjs": - return `bundles/${entryName}.cjs`; + return `cjs/${entryName}.cjs`; default: throw new Error(`unsupported format ${format}`); } }, }, - rollupOptions: isUMDBuild - ? undefined - : { + rollupOptions: isCJSBuild + ? { // make sure external imports that should not be bundled are listed here for CJS build external: ["node:crypto"], - }, + } + : undefined, }, test: { include: "tests/**/*.test.ts", From 7b440ed8aad263d1b4265d2a79ff8bb928a0e580 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:43:04 +0300 Subject: [PATCH 11/26] Fix env test --- package.json | 2 +- tests/env/express/.gitignore | 2 +- tests/env/express/public/headers.html | 2 +- tests/env/express/public/index.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7ba7f22cb..0e9d1bb54 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "test": "vitest run --coverage", "types": "tsc -p tsconfig.build.json --noEmit", "types:watch": "yarn types --watch", - "test:env:browser": "node scripts/copy-umd-file.js --to ./tests/env/express/public && yarn build && yarn --cwd tests/env/express && yarn --cwd tests/env/express test", + "test:env:browser": "yarn build && node scripts/copy-umd-file.js --to ./tests/env/express/public && yarn --cwd tests/env/express && yarn --cwd tests/env/express test", "test:watch": "vitest watch", "test:coverage": "yarn test", "test:ci": "yarn test", diff --git a/tests/env/express/.gitignore b/tests/env/express/.gitignore index 8bc648947..4e1a38b5a 100644 --- a/tests/env/express/.gitignore +++ b/tests/env/express/.gitignore @@ -1,2 +1,2 @@ node_modules -public/index.umd.min.js +public/index.min.js diff --git a/tests/env/express/public/headers.html b/tests/env/express/public/headers.html index 1dab2435f..8ea4cb005 100644 --- a/tests/env/express/public/headers.html +++ b/tests/env/express/public/headers.html @@ -13,7 +13,7 @@ - + +