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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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
67 changes: 23 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,20 @@
"qdequele <[email protected]>"
],
"license": "MIT",
"main": "./dist/bundles/meilisearch.cjs",
"module": "./dist/bundles/meilisearch.mjs",
Comment on lines -19 to -20
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EXPLAINER: "exports" is the replacement for these and we no longer officially support Node.js versions prior to 18, so we do not need the backwards compatibility.

"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",
"jsdelivr": "./dist/umd/index.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/cjs/index.cjs",
"default": "./dist/umd/index.min.js"
},
"./token": {
"types": "./dist/types/token.d.ts",
"import": "./dist/bundles/token.mjs",
"require": "./dist/bundles/token.cjs",
"default": "./dist/bundles/token.cjs"
"import": "./dist/esm/token.js",
"require": "./dist/cjs/token.cjs",
"default": "./dist/cjs/token.cjs"
}
},
"sideEffects": false,
Expand All @@ -44,31 +39,27 @@
},
"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:docs": "typedoc",
"watch": "yarn cleanup && rollup -c --watch",
"postbuild": "yarn size && yarn typingsheader",
"build": "vite build && tsc -p tsconfig.build.json && vite --mode production-umd build",
"postbuild": "node scripts/build.js",
"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",
"types:watch": "yarn types --watch",
"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",
"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"
"style": "yarn fmt && yarn lint",
"style:fix": "yarn fmt:fix && yarn lint:fix"
},
"files": [
"src",
Expand All @@ -86,37 +77,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",
"@eslint/js": "^9.13.0",
"@types/eslint__js": "^8.42.3",
"@vitest/coverage-v8": "2.0.5",
"@vitest/eslint-plugin": "^1.1.4",
"@vitest/eslint-plugin": "^1.1.7",
"@types/node": "^22.8.6",
"brotli-size": "^4.0.0",
"eslint": "^9.13.0",
"globals": "^15.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-tsdoc": "^0.3.0",
"globals": "^15.11.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.10",
"typescript": "^5.4.5",
"typescript-eslint": "^8.12.2",
"vitest": "2.0.5"
"typescript": "^5.6.3",
"vitest": "2.0.5",
"vite": "^5.4.10",
"@typescript-eslint/utils": "^8.12.2"
},
"packageManager": "[email protected]"
}
125 changes: 0 additions & 125 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