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 25 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

Warning

Warning

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 98.21%. Comparing base (896b5c0) to head (e1ca1ab).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1740   +/-   ##
=======================================
  Coverage   98.20%   98.21%           
=======================================
  Files          18       17    -1     
  Lines        1562     1565    +3     
  Branches      333      333           
=======================================
+ Hits         1534     1537    +3     
  Misses         28       28           

☔ 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.

@flevi29 flevi29 force-pushed the rollup-to-esm-vite branch from bb95a1c to 7b440ed Compare December 1, 2024 11:40
@flevi29
Copy link
Collaborator Author

flevi29 commented Dec 1, 2024

Hey @brunoocasali, it's been a while. Please, can you take a look at this PR? It would unblock me from contributing even more, for instance using vite to greatly improve the live demo test.

@Strift
Copy link
Collaborator

Strift commented Dec 2, 2024

I support this change too 👍 However, I would recommend making this non-breaking for users.

For the exports: I would add information in the documentation to explain that default export is deprecated, will be removed one day, and named export should be preferred.

For the UMD bundle: is there a way to approach it in the same way? Via documentation, and roll out the breaking change in the future.

@flevi29
Copy link
Collaborator Author

flevi29 commented Dec 2, 2024

Thanks for the feedback, I'll try to do just that.

@flevi29
Copy link
Collaborator Author

flevi29 commented Dec 3, 2024

Hey @Strift, I've reverted the default export change, and deprecated it instead. However I couldn't find a solution for the second breaking change. At least not a straight forward one, I don't think it's worth hacking around with it though too much. That one's either extending window with all the exports, or a property (meilisearch) which has all the exports, doesn't really do both.

@flevi29
Copy link
Collaborator Author

flevi29 commented Dec 9, 2024

@brunoocasali @Strift No good?

@flevi29 flevi29 requested a review from Strift December 27, 2024 10:58
@flevi29 flevi29 added enhancement New feature or request maintenance Issue about maintenance (CI, tests, refacto...) and removed breaking-change The related changes are breaking for the users labels Dec 29, 2024
@flevi29
Copy link
Collaborator Author

flevi29 commented Dec 29, 2024

@brunoocasali @Strift Hey, I managed to make this a non breaking change.

Comment on lines +75 to +77
> [!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).
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this fine here? Or should it just be in the release notes? If it's fine should I also mention the window deprecation as well here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maintenance Issue about maintenance (CI, tests, refacto...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update bundling, transpiling process, move to ESM, change Jest to Vitest
2 participants