Skip to content

Commit

Permalink
Merge #1611
Browse files Browse the repository at this point in the history
1611: Add `package.json` `"exports"` field r=curquiza a=flevi29

# Pull Request

I am aiming to slowly try to update and simplify this repository, and maybe learn a thing or two along the way.

## What does this PR do?
- add `"exports"` field to `package.json`
  - It is the new way of defining your exported files, instead of just relying on one single [`"main"`](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#main) export for Node.js
  - This way Node.js can conditionally determine which exported file to import based on the fact that `require` or `import` was used, previously Node.js even in ESM mode always imported the commonjs version of this package, but now it can import the ESM version
  - https://webpack.js.org/guides/package-exports/
  - [subpath-exports](https://nodejs.org/docs/latest-v20.x/api/packages.html#subpath-exports)
  - [conditional-exports](https://nodejs.org/docs/latest-v20.x/api/packages.html#conditional-exports)
- add `node:` specifiers to Node.js built-in module imports/requires
- add missing ``@types/node`` type definitions development dependency
- because older versions of `jest` test runner doesn't support `node:` specifiers, update `jest` (#1622)
- ~~because newer versions of `jest` doesn't include anymore `"jest-environment-jsdom"`, add it as development dependency~~
- ~~because newer versions of `jest` simplified snapshots, update them accordingly~~
  - ~~this means replacing `Object {` with `{` and `Array [` with `[`~~

> [!CAUTION]
> This is a breaking change for anyone who was importing anything other than what we have in the `"exports"` package.json field. From now on only files from the `package.json` `"exports"` field can be imported.

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: F. Levi <55688616+flevi29@users.noreply.github.com>
  • Loading branch information
meili-bors[bot] and flevi29 authored Oct 3, 2024
2 parents f4bbd5a + d75ec0c commit 7c6a3e3
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 49 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -18,7 +18,7 @@ const PLUGINS = [
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
allowJs: false,
compilerOptions: { allowJs: false },
include: ["src"],
exclude: ["tests", "examples", "*.js", "scripts"],
},
Expand Down
5 changes: 3 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -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, "..");
Expand Down
6 changes: 3 additions & 3 deletions scripts/file-size.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion tests/env/esm/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')

module.exports = {
entry: './src/index.js',
Expand Down
2 changes: 1 addition & 1 deletion tests/env/nitro-app/tests/client.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { spawn } = require('child_process')
const { spawn } = require('node:child_process')

let server

Expand Down
2 changes: 1 addition & 1 deletion tests/env/typescript-browser/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const webpack = require('webpack')
const path = require('path')
const path = require('node:path')

let config = {
entry: './src/index.ts',
Expand Down
2 changes: 1 addition & 1 deletion tests/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
55 changes: 18 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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==
Expand All @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7c6a3e3

Please sign in to comment.