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

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Oct 5, 2024

Pull Request

Related issue

Fixes #1626
Waiting on #1739

What does this PR do?

  • switches bundler from rollup to vite, which internally uses rollup, but makes things a lot shorter and simpler
    • removes the need for separate vitest.config.js
    • removes the need for scripts/file-size.js, packages kleur, pretty-bytes, brotli-size, gzip-size, as it prints sizes by default
    • removes the need for all of the rollup plugins and dependencies (@rollup/plugin-terser, @babel/core, @babel/preset-env, @rollup/plugin-babel, @rollup/plugin-commonjs, @rollup/plugin-json, @rollup/plugin-node-resolve, rollup-plugin-typescript2)
    • removes the need for shx package, and cleanup script, as it clears dist itself
  • switches from CJS to ESM ("type": "module")
    • every .js project file now needs to be written in ESM syntax, the web standard syntax
    • TypeScript files were already written in ESM syntax, so this just makes things more consistent
  • updates TypeScript and makes some changes to tsconfig.json according to https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#im-writing-a-library
    • is now used to transpile ESM version of this package
    • most importantly sets module to node16 and verbatimModuleSyntax to true, this requires changes to all TypeScript files so they may be compatible with the web standard ESM
      • all imported files now require a .js extension
      • there is no more support for index directory imports, as that is only a Node.js thing, the web doesn't support it
      • when importing types, we need to explicitly specify that we're doing so with the type keyword

Caution

  • BREAKING: UMD bundle no longer extends window/global/globalThis/self with the exports, instead it extends it with property meilisearch which contains the exports

Old

<script>
  const client = new MeiliSearch(/* ... */);
</script>

New

<script>
  const client = new meilisearch.MeiliSearch(/* ... */);
</script>

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@flevi29 flevi29 added the breaking-change The related changes are breaking for the users label Oct 5, 2024
Copy link

codecov bot commented Oct 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.80%. Comparing base (0736f38) to head (bb95a1c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1740      +/-   ##
==========================================
- Coverage   97.81%   97.80%   -0.01%     
==========================================
  Files          17       16       -1     
  Lines        1465     1461       -4     
  Branches      307      306       -1     
==========================================
- Hits         1433     1429       -4     
  Misses         32       32              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines -21 to -22
"typings": "./dist/types/index.d.ts",
"types": "./dist/types/index.d.ts",
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.

Comment on lines -19 to -20
"main": "./dist/bundles/meilisearch.cjs",
"module": "./dist/bundles/meilisearch.mjs",
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update bundling, transpiling process, move to ESM, change Jest to Vitest
1 participant