Skip to content

Migrate build system to esbuild #261

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

Open
wants to merge 46 commits into
base: master
Choose a base branch
from

Conversation

tharropoulos
Copy link
Collaborator

Change Summary

What is this?

This change modernizes the build system by migrating from webpack to tsup (powered by esbuild) for improved bundle generation. It enhances package exports configuration to better support both CommonJS and ESM environments while ensuring proper browser polyfills and type definitions.

Changes

Build System Updates:

  1. Migrated to tsup:
    • Replaced webpack with tsup for faster and more efficient builds
    • Added tsup.config.ts with configurations for browser and Node.js targets
    • Configured dual ESM/CJS output with .mjs/.js extensions
    • Set up source maps and minification

Package Configuration:

  1. Updated Package Exports:
    • Added exports field with conditional exports for CJS/ESM
    • Updated main, module, and types fields
    • Configured browser polyfills for crypto, http, and https

Dependencies:

  1. Removed Dependencies:
    • Removed @babel/runtime peer dependency
  2. Added Dependencies:
    • Added browserslist and browserslist-to-esbuild for browser targeting
    • Added esbuild-plugins-node-modules-polyfill for Node.js built-ins
    • Added tsup for build system

Type System Improvements:

  1. In src/Typesense.ts:
    • Added explicit type exports for all modules
    • Improved module export structure
    • Added comprehensive type definitions

Code Improvements:

  1. In src/Typesense/Configuration.ts:
    • Fixed logger import to avoid UMD module issues
    • Improved type handling for logger configuration

Context

This modernization effort improves the package's compatibility with modern JavaScript tooling while maintaining support for older environments. The migration to tsup provides faster builds and better tree-shaking capabilities, resulting in smaller bundle sizes.

PR Checklist

Modernize build system and package configuration

- Migrate from webpack to tsup for improved build process.
- Update package.json with new exports configuration and dependencies.
- Add tsup.config.ts for flexible bundling options.
- Target both cjs and esm.
- Use minified versions of bundle by default.
- `loglevel` is written as a UMD module and has to be handled
  differently from axios
- add type exports for all modules via `export type *`
- fix browser polyfills by using `empty` modules for node builtins
- fix output directories by swapping `lib` and `dist` outputs
- update mainFields to prioritize browser field
Copy link
Member

@jasonbosco jasonbosco left a comment

Choose a reason for hiding this comment

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

  1. Could you remove the typesense data dir from this commit:

Screenshot 2025-02-05 at 2 07 48 PM

  1. Looks like the individual JS files, source maps and type files inside the lib directory are missing now. Could we add those back, so we don't break apps where users might be directly importing these individual files?
    Screenshot 2025-02-05 at 2 08 23 PM

  2. Could we also add the unminimized Typesense.js file back into lib?

  3. Could we keep the file names consistent with before (all lower case) inside the dist directory and also add back the unminified version as well?
    Screenshot 2025-02-05 at 2 08 31 PM

- add `Stemming`, `StemmingDictionaries`, and `StemmingDictionary` classes
- implement dictionary CRUD operations with `upsert` and `retrieve` methods
- add stemming property to main client class
- add tests for stemming functionality
- refactor `StemmingDictionaryCreateSchema` to use single word-root pairs
- update `upsert` method to handle JSONL format for dictionaries
- fix typo in `StemmingDictionary` class name
- change endpoint path from `/stemming/dictionary` to `/dictionaries`
- add JSONL conversion for array inputs and string handling
tharropoulos and others added 18 commits February 6, 2025 16:58
- run `tsc` before `tsup` in `build` script
- remove duplicate browser configuration from `tsup.config.ts`
- simplify build process while maintaining browser compatibility
- update `.` export to use correct `import` and `require` fields
- add `default` field for compatibiliy with typescript imports
- rename `browser.ts` entry point to support module resolution
- update build configuration to use new entry point
- split `tsconfig.json` into base, cjs and esm variants
- update `build` script to use dedicated cjs config
- simplify main tsconfig by extending from base config
- configure tsup to use esm config for browser builds
- merge `browser.ts` exports into main `Typesense.ts` file
- update tsup config to use single entry point
- simplify export pattern for core modules
- streamline type exports
- add explicit `treeshake` flag in tsup config
- set browser-specific mainFields for module resolution
- consolidate build optimization settings
- add `src` directory to published files in `package.json`
- remove redundant browser file cleanup step
- expand package export configuration in `package.json` to include
  unminified versions of the browser bundle
- add documentation for `SearchClient` browser usage
- clarify commonjs and esm bundle formats
- update build tool information from browserify to tsup
- avoid module resolution failures from parcel not respecting the
`exports` field
- add test for empty array input
- add test for empty string input
- add test for null input
- add test for undefined input
@tharropoulos
Copy link
Collaborator Author

Looks like the individual JS files, source maps and type files inside the lib directory are missing now. Could we add those back, so we don't break apps where users might be directly importing these individual files?

Done in bfdfee0, opted to use tsc for node-specific builds targeting CommonJS

Could we also add the unminimized Typesense.js file back into lib?

The unminified bundle is now in ae7de6c. Users can access it by using the absolute node_modules path when importing. By default, it will use the minified version.

Could we keep the file names consistent with before (all lower case) inside the dist directory and also add back the unminified version as well?

Changed the entrypoint name altogether in e5aaf4b, to address problems with module resolutions in bundlers like parcel. By default, parcel resolves paths in absolutely, so importing by "typesense/dist" doesn't work currently, as there isn't a "typesense/dist.js" file inside the "dist" bundle. It would only work with "typesense/dist/typesense".

@tharropoulos
Copy link
Collaborator Author

@jasonbosco I think we need to merge this in order to tackle #288.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants