Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from rollup to vite, from commonjs to ecmascript modules #1740

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ authorization_header_1: |-
const client = new MeiliSearch({ host: 'http://localhost:7700', apiKey: 'masterKey' })
client.getKeys()
tenant_token_guide_generate_sdk_1: |-
import { generateTenantToken } from 'meilisearch/token'

const searchRules = {
patient_medical_records: {
filter: 'user_id = 1'
Expand All @@ -709,7 +711,7 @@ tenant_token_guide_generate_sdk_1: |-
const apiKeyUid = '85c3c2f9-bdd6-41f1-abd8-11fcf80e0f76'
const expiresAt = new Date('2025-12-20') // optional

const token = await client.generateTenantToken(apiKeyUid, searchRules, {
const token = await generateTenantToken(apiKeyUid, searchRules, {
apiKey: apiKey,
expiresAt: expiresAt,
})
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
18 changes: 9 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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,
},
Expand All @@ -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 },
Expand Down
59 changes: 24 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
"qdequele <[email protected]>"
],
"license": "MIT",
"main": "./dist/bundles/meilisearch.cjs",
"module": "./dist/bundles/meilisearch.mjs",
"typings": "./dist/types/index.d.ts",
"types": "./dist/types/index.d.ts",
Comment on lines -21 to -22
Copy link
Collaborator Author

@flevi29 flevi29 Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EXPLAINER: These are no longer required, as exports below contains the types, and TypeScript primarily looks there.

"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/esm/token.js",
"require": "./dist/bundles/token.cjs",
"default": "./dist/bundles/token.cjs"
}
},
"sideEffects": false,
Expand All @@ -38,31 +42,28 @@
},
"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",
"test:env:browser": "yarn build && yarn --cwd tests/env/express && yarn --cwd tests/env/express test",
"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",
"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",
"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",
Expand All @@ -80,37 +81,25 @@
]
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@eslint/js": "^9.11.1",
"@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": "^20.16.10",
"brotli-size": "^4.0.0",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-tsdoc": "^0.3.0",
"globals": "^15.9.0",
"gzip-size": "^6.0.0",
"kleur": "^4.1.5",
"lint-staged": "15.2.10",
"nodemon": "^3.1.7",
"prettier": "^3.3.3",
"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.26.7",
"typescript": "^5.4.5",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.0",
"vitest": "2.0.5"
"vitest": "2.0.5",
"vite": "^5.4.8",
"@typescript-eslint/utils": "^8.8.0"
},
"packageManager": "[email protected]"
}
106 changes: 0 additions & 106 deletions rollup.config.js

This file was deleted.

12 changes: 7 additions & 5 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
21 changes: 21 additions & 0 deletions scripts/copy-umd-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { parseArgs } from "node:util";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
import { resolve, dirname, join, basename } from "node:path";
import { copyFile } from "node:fs/promises";

const {
values: { to },
} = parseArgs({ options: { to: { type: "string" } } });

if (to === undefined) {
throw new Error("required argument `to` missing");
}

const pkg = createRequire(import.meta.url)("../package.json");
const umdAbsolutePath = resolve(
dirname(fileURLToPath(import.meta.url)),
join("..", pkg.jsdelivr),
);

await copyFile(umdAbsolutePath, join(to, basename(pkg.jsdelivr)));
Loading