diff --git a/package.json b/package.json index 29053b401..3e41b7937 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,15 @@ "types": "./dist/types/index.d.ts", "jsdelivr": "./dist/bundles/meilisearch.umd.js", "unpkg": "./dist/bundles/meilisearch.umd.js", + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "browser": "./dist/bundles/meilisearch.umd.js", + "import": "./dist/bundles/meilisearch.esm.js", + "require": "./dist/bundles/meilisearch.cjs.js", + "default": "./dist/bundles/meilisearch.umd.js" + } + }, "sideEffects": false, "repository": { "type": "git", @@ -82,6 +91,7 @@ "@types/eslint__js": "^8.42.3", "@vitest/coverage-v8": "2.0.5", "@vitest/eslint-plugin": "^1.1.4", + "@types/node": "^20.16.10", "brotli-size": "^4.0.0", "eslint": "^9.11.1", "eslint-config-prettier": "^9.1.0", diff --git a/rollup.config.js b/rollup.config.js index cb2938190..3f693e76b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,5 @@ const nodeResolve = require("@rollup/plugin-node-resolve"); -const { resolve } = require("path"); +const { resolve } = require("node:path"); const commonjs = require("@rollup/plugin-commonjs"); const json = require("@rollup/plugin-json"); const typescript = require("rollup-plugin-typescript2"); @@ -18,7 +18,7 @@ const PLUGINS = [ typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { - allowJs: false, + compilerOptions: { allowJs: false }, include: ["src"], exclude: ["tests", "examples", "*.js", "scripts"], }, diff --git a/scripts/build.js b/scripts/build.js index 0cb4acfb7..c4e63bfe6 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,7 +1,8 @@ /** This file only purpose is to execute any build related tasks */ -const { resolve, normalize } = require("path"); -const { readFileSync, writeFileSync } = require("fs"); +const { resolve, normalize } = require("node:path"); +const { readFileSync, writeFileSync } = require("node:fs"); + const pkg = require("../package.json"); const ROOT = resolve(__dirname, ".."); diff --git a/scripts/file-size.js b/scripts/file-size.js index d14d8e7ff..56ef339b2 100644 --- a/scripts/file-size.js +++ b/scripts/file-size.js @@ -1,6 +1,6 @@ -const { basename, normalize } = require("path"); -const { readFile: readFileCb } = require("fs"); -const { promisify } = require("util"); +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"); diff --git a/src/token.ts b/src/token.ts index 0690519c9..b8c421798 100644 --- a/src/token.ts +++ b/src/token.ts @@ -19,7 +19,7 @@ async function sign( encodedHeader: string, encodedPayload: string, ) { - const { createHmac } = await import("crypto"); + const { createHmac } = await import("node:crypto"); return createHmac("sha256", apiKey) .update(`${encodedHeader}.${encodedPayload}`) diff --git a/tests/env/esm/webpack.config.js b/tests/env/esm/webpack.config.js index ecda6bb66..61259d571 100644 --- a/tests/env/esm/webpack.config.js +++ b/tests/env/esm/webpack.config.js @@ -1,4 +1,4 @@ -const path = require('path') +const path = require('node:path') module.exports = { entry: './src/index.js', diff --git a/tests/env/nitro-app/tests/client.test.js b/tests/env/nitro-app/tests/client.test.js index 5f0275a67..2d25d84d1 100644 --- a/tests/env/nitro-app/tests/client.test.js +++ b/tests/env/nitro-app/tests/client.test.js @@ -1,4 +1,4 @@ -const { spawn } = require('child_process') +const { spawn } = require('node:child_process') let server diff --git a/tests/env/typescript-browser/webpack.config.js b/tests/env/typescript-browser/webpack.config.js index dccd82975..45f9dc8e2 100644 --- a/tests/env/typescript-browser/webpack.config.js +++ b/tests/env/typescript-browser/webpack.config.js @@ -1,5 +1,5 @@ const webpack = require('webpack') -const path = require('path') +const path = require('node:path') let config = { entry: './src/index.ts', diff --git a/tests/token.test.ts b/tests/token.test.ts index 6cbb5f97c..12f2bef99 100644 --- a/tests/token.test.ts +++ b/tests/token.test.ts @@ -8,7 +8,7 @@ import { config, HOST, } from "./utils/meilisearch-test-utils"; -import { createHmac } from "crypto"; +import { createHmac } from "node:crypto"; import MeiliSearch from "../src"; const HASH_ALGORITHM = "HS256"; diff --git a/yarn.lock b/yarn.lock index 38dabc027..ca3fda796 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,14 +23,7 @@ "@jridgewell/gen-mapping" "^0.3.5" "@jridgewell/trace-mapping" "^0.3.24" -"@babel/code-frame@^7.10.4": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" - integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw== - dependencies: - "@babel/highlight" "^7.10.4" - -"@babel/code-frame@^7.24.7": +"@babel/code-frame@^7.10.4", "@babel/code-frame@^7.24.7": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.24.7.tgz#882fd9e09e8ee324e496bd040401c6f046ef4465" integrity sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA== @@ -220,27 +213,12 @@ "@babel/traverse" "^7.24.7" "@babel/types" "^7.24.7" -"@babel/helper-string-parser@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f" - integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw== - -"@babel/helper-string-parser@^7.24.8": +"@babel/helper-string-parser@^7.22.5", "@babel/helper-string-parser@^7.24.8": version "7.24.8" resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz#5b3329c9a58803d5df425e5785865881a81ca48d" integrity sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ== -"@babel/helper-validator-identifier@^7.10.4": - version "7.10.4" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz#a78c7a7251e01f616512d31b10adcf52ada5e0d2" - integrity sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw== - -"@babel/helper-validator-identifier@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz#9544ef6a33999343c8740fa51350f30eeaaaf193" - integrity sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ== - -"@babel/helper-validator-identifier@^7.24.7": +"@babel/helper-validator-identifier@^7.22.5", "@babel/helper-validator-identifier@^7.24.7": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz#75b889cfaf9e35c2aaf42cf0d72c8e91719251db" integrity sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w== @@ -267,15 +245,6 @@ "@babel/template" "^7.25.0" "@babel/types" "^7.25.6" -"@babel/highlight@^7.10.4": - version "7.10.4" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.10.4.tgz#7d1bdfd65753538fabe6c38596cdb76d9ac60143" - integrity sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA== - dependencies: - "@babel/helper-validator-identifier" "^7.10.4" - chalk "^2.0.0" - js-tokens "^4.0.0" - "@babel/highlight@^7.24.7": version "7.24.7" resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.24.7.tgz#a05ab1df134b286558aae0ed41e6c5f731bf409d" @@ -1005,7 +974,7 @@ "@babel/helper-validator-identifier" "^7.22.5" to-fast-properties "^2.0.0" -"@babel/types@^7.24.0", "@babel/types@^7.25.2": +"@babel/types@^7.24.0": version "7.25.2" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.25.2.tgz#55fb231f7dc958cd69ea141a4c2997e819646125" integrity sha512-YTnYtra7W9e6/oAZEHj0bJehPRUlLH9/fbpT5LfB0NhQXyALCRkRs3zH9v07IYhkgpqX6Z78FnuccZr/l4Fs4Q== @@ -1014,7 +983,7 @@ "@babel/helper-validator-identifier" "^7.24.7" to-fast-properties "^2.0.0" -"@babel/types@^7.24.7", "@babel/types@^7.24.8", "@babel/types@^7.25.0", "@babel/types@^7.25.6": +"@babel/types@^7.24.7", "@babel/types@^7.24.8", "@babel/types@^7.25.0", "@babel/types@^7.25.2", "@babel/types@^7.25.6": version "7.25.6" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.25.6.tgz#893942ddb858f32ae7a004ec9d3a76b3463ef8e6" integrity sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw== @@ -1696,6 +1665,13 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.5.tgz#3d03acd3b3414cf67faf999aed11682ed121f22b" integrity sha512-90hiq6/VqtQgX8Sp0EzeIsv3r+ellbGj4URKj5j30tLlZvRUpnAe9YbYnjl3pJM93GyXU0tghHhvXHq+5rnCKA== +"@types/node@^20.16.10": + version "20.16.10" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.16.10.tgz#0cc3fdd3daf114a4776f54ba19726a01c907ef71" + integrity sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA== + dependencies: + undici-types "~6.19.2" + "@types/resolve@1.20.2": version "1.20.2" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975" @@ -2087,7 +2063,7 @@ chai@^5.1.1: loupe "^3.1.0" pathval "^2.0.0" -chalk@^2.0.0, chalk@^2.4.2: +chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -4402,6 +4378,11 @@ undefsafe@^2.0.5: resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.5.tgz#38733b9327bdcd226db889fb723a6efd162e6e2c" integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA== +undici-types@~6.19.2: + version "6.19.8" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" + integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== + unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz#301acdc525631670d39f6146e0e77ff6bbdebddc"