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

Do not extend window with all of the exports in UMD bundle, rather just a property of window #1806

Open
flevi29 opened this issue Dec 29, 2024 · 0 comments
Labels
breaking-change The related changes are breaking for the users

Comments

@flevi29
Copy link
Collaborator

flevi29 commented Dec 29, 2024

In our current Rollup setup, we're extending window with all of the exports as is. This is a bad practice, and can introduce property name conflicts. In #1740 Vite doesn't even support extending just the bare window, it only allows us to specify the property name on which it will insert all of the exports (I had to introduce a hacky footer code to allow for this deprecation instead of a breaking change).

@flevi29 flevi29 added the breaking-change The related changes are breaking for the users label Dec 29, 2024
meili-bors bot added a commit that referenced this issue Jan 8, 2025
1740: Switch from rollup to vite, from commonjs to ecmascript modules r=Strift a=flevi29

# Pull Request

## Related issue
Fixes #1626
~~Waiting on #1739~~

## What does this PR do?
- switches bundler from [`rollup`](https://rollupjs.org/) to [`vite`](https://vite.dev/), 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`](https://github.com/meilisearch/meilisearch-js/blob/main/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"`](https://nodejs.org/api/packages.html#type))
  - 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]
> - DEPRECATE default export #1789
> - DEPRECATION: UMD bundle will no longer extend `window` with the exports in the future, instead it will only extend it with property `meilisearch` which contains the exports #1806
> ### Old
> ```html
> <script>
>   const client = new MeiliSearch(/* ... */);
> </script>
> ```
> ### New
> ```html
> <script>
>   const client = new meilisearch.MeiliSearch(/* ... */);
> </script>
> ```

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: F. Levi <[email protected]>
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

No branches or pull requests

1 participant