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

Merged
merged 37 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
87ba71c
Switch from rollup to vite, from cjs to esm
flevi29 Oct 5, 2024
c16a161
Fix env test
flevi29 Oct 5, 2024
1e6e569
Fix format issues
flevi29 Oct 5, 2024
4bff874
Fix 'types' script
flevi29 Oct 5, 2024
df0a3eb
Fix token test
flevi29 Oct 5, 2024
805c88b
Fix env esm test
flevi29 Oct 5, 2024
5dc0a24
Fix env nodejs test
flevi29 Oct 5, 2024
ec7d4e9
Fix env browser test
flevi29 Oct 5, 2024
bd7212b
Remove unnecessary index file, misc
flevi29 Oct 6, 2024
0b48a0f
Remove outdated entries from package.json, misc
flevi29 Oct 6, 2024
7b440ed
Fix env test
flevi29 Oct 6, 2024
88ec1c8
Merge branch 'main' into rollup-to-esm-vite
flevi29 Dec 1, 2024
f54c66c
Merge branch 'main' into rollup-to-esm-vite
flevi29 Dec 2, 2024
b668981
Restore and deprecate default export
flevi29 Dec 3, 2024
9b8b4ad
Update README.md with script import changes
flevi29 Dec 3, 2024
459816a
Merge with branch main
flevi29 Dec 23, 2024
97ad6fa
Adapt new code from main
flevi29 Dec 23, 2024
974477f
Merge branch 'main' into rollup-to-esm-vite
flevi29 Dec 27, 2024
3d564fa
Merge with main and adapt code
flevi29 Dec 27, 2024
36e457b
Fix eslint config
flevi29 Dec 27, 2024
092457f
Merge with main and adapt code
flevi29 Dec 27, 2024
e73e313
Fix bad esm test
flevi29 Dec 27, 2024
e01fe9f
Fix bad esm test re-attempt
flevi29 Dec 27, 2024
d5dd136
Fix bad node test
flevi29 Dec 27, 2024
e1ca1ab
Revert breaking change
flevi29 Dec 29, 2024
d9a42a4
Merge with main
flevi29 Jan 2, 2025
4f136b0
Merge branch 'main' into rollup-to-esm-vite
flevi29 Jan 3, 2025
b9c7f5d
Merge branch 'main' into rollup-to-esm-vite
flevi29 Jan 5, 2025
f001b2d
Use package name from package.json as the global name for UMD
flevi29 Jan 5, 2025
f06e392
Merge branch 'rollup-to-esm-vite' of github.com:flevi29/meilisearch-j…
flevi29 Jan 5, 2025
b95202c
Merge branch 'main' into rollup-to-esm-vite
flevi29 Jan 5, 2025
af2be86
Fix script
flevi29 Jan 5, 2025
0165a5f
Make requested changes
flevi29 Jan 5, 2025
4794c85
Fix failing test, rename types file
flevi29 Jan 5, 2025
d3006e2
Fix formatting
flevi29 Jan 5, 2025
ce1e53f
Adjust README
flevi29 Jan 5, 2025
12c0df8
Adjust code and README
flevi29 Jan 8, 2025
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Instead of using a package manager, you may also import the library directly int

After installing `meilisearch-js`, you must import it into your application. There are many ways of doing that depending on your development environment.

> [!WARNING]
> [Default export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export) is deprecated and will be removed in a future version. [Issue](https://github.com/meilisearch/meilisearch-js/issues/1789).

Strift marked this conversation as resolved.
Show resolved Hide resolved
#### `import` syntax <!-- omit in toc -->

Usage in an ES module environment:
Expand All @@ -89,6 +92,7 @@ Usage in an HTML (or alike) file:
```html
<script src='https://cdn.jsdelivr.net/npm/meilisearch@latest/dist/bundles/meilisearch.umd.js'></script>
<script>
// also works with window.MeiliSearch, meilisearch.MeiliSearch, window.meilisearch.MeiliSearch
Copy link
Collaborator

@Strift Strift Jan 8, 2025

Choose a reason for hiding this comment

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

Can you remove the comment and only use the recommended way?

const client = new MeiliSearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
meilisearch:
image: getmeili/meilisearch:latest
ports:
- "7700"
- "7700:7700"
environment:
- MEILI_MASTER_KEY=masterKey
- MEILI_NO_ANALYTICS=true
18 changes: 9 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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";

module.exports = tseslint.config([
export default tseslint.config([
{ ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"] },
eslint.configs.recommended,
{
files: ["**/*.js"],
languageOptions: { sourceType: "commonjs", globals: globals.node },
languageOptions: { globals: globals.node },
},
// TSDoc
{
Expand All @@ -25,7 +25,7 @@ module.exports = tseslint.config([
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
Expand Down
65 changes: 22 additions & 43 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",
Strift marked this conversation as resolved.
Show resolved Hide resolved
"typings": "./dist/types/index.d.ts",
"types": "./dist/types/index.d.ts",
Strift marked this conversation as resolved.
Show resolved Hide resolved
"jsdelivr": "./dist/bundles/meilisearch.umd.js",
"unpkg": "./dist/bundles/meilisearch.umd.js",
Strift marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -43,32 +38,28 @@
"url": "https://github.com/meilisearch/meilisearch-js"
},
"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",
"playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript dev",
"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.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,35 +77,23 @@
]
},
"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-plugin-tsdoc": "^0.4.0",
"@vitest/eslint-plugin": "^1.1.23",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-tsdoc": "^0.3.0",
"typescript": "^5.7.2",
"vite": "^6.0.7",
"@typescript-eslint/utils": "^8.19.0",
"globals": "^15.14.0",
"gzip-size": "^6.0.0",
"kleur": "^4.1.5",
"lint-staged": "15.3.0",
"nodemon": "^3.1.9",
"prettier": "^3.4.2",
"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.6",
"typescript": "^5.4.5",
"typescript-eslint": "^8.19.0",
"vitest": "2.0.5"
},
Expand Down
125 changes: 0 additions & 125 deletions rollup.config.js

This file was deleted.

12 changes: 6 additions & 6 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/** 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 pkg from "../package.json" with { type: "json" };

const pkg = require("../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
20 changes: 20 additions & 0 deletions scripts/copy-umd-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { parseArgs } from "node:util";
import pkg from "../package.json" with { type: "json" };
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 umdAbsolutePath = resolve(
dirname(fileURLToPath(import.meta.url)),
join("..", pkg.jsdelivr),
);

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