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

docs(ADR/TDOPS-6075): Add support to ESM #5273

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions docs/adr-2024-04-add-support-to-esm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ADR: Add support to ECMAScript Modules (ESM)

## Context

Our build and bundling setup currently uses CommonJS modules along with webpack and the dynamic-cdn-webpack-plugin.

To streamline our development workflow and reduce complexity, we are transitioning from yarn to pnpm.

However, it has been identified that pnpm is not compatible with dynamic-cdn-webpack-plugin. This incompatibility, along with the decision to remove the plugin, has resulted in a degradation of the developer experience, primarily through increased build times.

At the same time, the entire frontend world is moving towards ECMAScript Modules (ESM).

Modern browsers that our customers use now support ESM natively.

All existing frameworks are now relying on Vite for the build process, which, under the hood, relies on ESM.

Therefore, having to configure a complex toolchain is becoming obsolete. Given this changing context, we can reevaluate our decisions around the "talend-scripts build\*" toolchain.

## Problem

The transition from yarn to pnpm has uncovered an incompatibility with dynamic-cdn-webpack-plugin, exacerbating the decision to discontinue using this plugin.

This has adversely impacted the developer experience by elongating the build times, a significant concern as it can hinder our overall productivity and agility.

## Decision

Our packages must export ESM to be futur proof and let us use modern tooling like vite or parcel.

## Alternatives Considered

- **Sticking with webpack and dynamic-cdn-webpack-plugin**: This was initially considered to maintain our current setup and avoid the complexities associated with migration. However, given the incompatibility with pnpm and the underlying issues related to complexity and inefficiency in build times, this option was deemed unsuitable.

- **Switching to another build tool without adopting ESM**: Several other build tools could potentially improve build times. However, without addressing the fundamental shift towards ESM in the JavaScript ecosystem, this would be a short-term fix rather than a long-term solution.

- **Migrating to Vite while keeping our packages in CommonJS**: This alternative involves moving to Vite for its development speed advantages but not converting our packages to ESM. While this approach could reduce the immediate workload and avoid potential issues with third-party CommonJS dependencies, it would limit our ability to fully leverage Vite’s capabilities. Vite is optimized for ESM, and using CommonJS may result in suboptimal build performance and hinder live module reloading, affecting developer experience and potentially leading to more complex configurations.

## Consequences

- **Positive**: Moving to ESM and adopting Vite is expected to reduce build times, enhancing developer experience and productivity. It aligns our development practices with the modern JavaScript ecosystem's move towards ESM.
- **Negative**: The migration from CommonJS to ESM syntax could require significant effort. It might also temporarily disrupt our development workflow and necessitate additional training for developers not yet familiar with ESM or Vite.
- **Risks**: There is a risk of encountering third-party libraries not yet compatible with ESM, which could complicate the migration process.
Loading