Page MenuHomePhabricator

Migrate cxserver code from CommonJS to ESM / ECMAScript
Closed, ResolvedPublic4 Estimated Story PointsBUG REPORT

Description

ECMAScript or ESM modules are the official way of developing JavaScript software today and many projects and libraries are moving towards this format to leverage its advantages.
Support for CommonJS, which was the de facto standard for NodeJS projects so far, is even being dropped by some famous libs

Following are some of the advantages

  1. Performance Improvement:
    • Static Resolution: ESM modules are resolved statically at compile time(parsing time), improving performance compared to CommonJS's dynamic resolution.
    • Top-Level Await: ESM allows you to use await at the top level of a module, enabling asynchronous operations without the need for callbacks or promises.
  2. Cleaner Syntax:
    • Import/Export Statements: ESM uses cleaner and more readable import and export statements, eliminating the need for module.exports and require().
    • Default Exports: ESM supports default exports, simplifying module usage.
  3. Native Support for Tree Shaking:
    • Eliminate Unused Code: ESM natively supports tree shaking, a process that removes unused code from your final bundle, resulting in smaller and faster applications.
  4. Better Interoperability:
    • Web Compatibility: ESM is aligned with the web's module system, making it easier to share code between Node.js and the browser.
  5. Future-Proof:
    • ECMA Standard: ESM is an official ECMA standard, ensuring its long-term support and adoption in the JavaScript ecosystem.
  6. Enhanced Tooling:
    • Bundlers and Linter: ESM is better supported by modern bundlers and linters, providing better developer experience and tooling capabilities.

Migration is not expected to be complex as IDEs like VSCode automatically converts the imports. Since cxserver has fairly good unit test coverage, we can verify too.

Event Timeline

Nikerabbit triaged this task as Medium priority.Nov 11 2024, 9:40 AM
Nikerabbit set the point value for this task to 16.
Nikerabbit lowered the priority of this task from Medium to Low.Nov 12 2024, 8:45 AM
abi_ renamed this task from Migrate cxserver code CommonJS to ESM / ECMAScript to Migrate cxserver code from CommonJS to ESM / ECMAScript.Nov 12 2024, 1:53 PM
Nikerabbit removed the point value 16 for this task.Nov 19 2024, 2:48 PM
Nikerabbit added a project: Epic.
Nikerabbit subscribed.

On a second thought, maybe this should be an epic with subtask for a handful of files each and other steps.

@santhosh Can you expand what concretely needs to be done. Maybe an example patch? Is it just updating the JavaScript files to newer syntax, or do we need to update any build configuration?

Change #1093813 had a related patch set uploaded (by Santhosh; author: Santhosh):

[mediawiki/services/cxserver@master] Migrate from CommonJS to ESM / ECMAScript

https://gerrit.wikimedia.org/r/1093813

@santhosh Can you expand what concretely needs to be done. Maybe an example patch? Is it just updating the JavaScript files to newer syntax, or do we need to update any build configuration?

@Nikerabbit Please take a look at https://gerrit.wikimedia.org/r/c/mediawiki/services/cxserver/+/1093813

This is mostly the full migration to ESM. Since it is code syntax change, I don't think we can do this in small steps. Changes are mostly in how files are imported, adding extension to all files. IDEs can help with this change. But there are some places where the files are dynamically imported. That require manual changes. And then __dirname and a few other things not available in ESM.

abi_ set the point value for this task to 4.

The patch related to this task has been reviewed but since this is a major refactoring, we want to avoid deploying it before the holidays. Will merge the patch in, in early Jan, 2025.

Nikerabbit changed the task status from Open to Stalled.Dec 12 2024, 12:42 PM

Change #1093813 merged by jenkins-bot:

[mediawiki/services/cxserver@master] Migrate from CommonJS to ESM

https://gerrit.wikimedia.org/r/1093813

Change #1108544 had a related patch set uploaded (by KartikMistry; author: KartikMistry):

[operations/deployment-charts@master] Update cxserver to 2025-01-07-045930-production

https://gerrit.wikimedia.org/r/1108544

abi_ changed the task status from Stalled to In Progress.Jan 7 2025, 1:48 PM

Change #1108544 merged by jenkins-bot:

[operations/deployment-charts@master] Update cxserver to 2025-01-07-045930-production

https://gerrit.wikimedia.org/r/1108544

Mentioned in SAL (#wikimedia-operations) [2025-01-09T06:53:34Z] <kart_> Updated cxserver to 2025-01-07-045930-production (T377966, T377813, T381379)

QA Note

We have tested this after deployment and it looks stable.

We will keep an eye on the logs in the coming days to ensure that everything is working as expected.

No additional QA is needed.

Change #1112081 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/services/cxserver@master] suggestTargetTitle: Wait for async function when requesting MT client

https://gerrit.wikimedia.org/r/1112081

Change #1112081 merged by jenkins-bot:

[mediawiki/services/cxserver@master] suggestTargetTitle: Wait for async function when requesting MT client

https://gerrit.wikimedia.org/r/1112081

Change #1112125 had a related patch set uploaded (by KartikMistry; author: KartikMistry):

[operations/deployment-charts@master] Update cxserver to 2025-01-17-043010-production

https://gerrit.wikimedia.org/r/1112125

Change #1112125 merged by jenkins-bot:

[operations/deployment-charts@master] Update cxserver to 2025-01-17-043010-production

https://gerrit.wikimedia.org/r/1112125

Change #1112774 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/services/cxserver@master] SourceSuggester: Wait for mtProviderFactory to return a MTClient

https://gerrit.wikimedia.org/r/1112774

Change #1112774 merged by jenkins-bot:

[mediawiki/services/cxserver@master] SourceSuggester: Wait for mtProviderFactory to return a MTClient

https://gerrit.wikimedia.org/r/1112774

Change #1112871 had a related patch set uploaded (by KartikMistry; author: KartikMistry):

[operations/deployment-charts@master] Update cxserver to 2025-01-20-172318-production

https://gerrit.wikimedia.org/r/1112871

Change #1112871 merged by jenkins-bot:

[operations/deployment-charts@master] Update cxserver to 2025-01-20-172318-production

https://gerrit.wikimedia.org/r/1112871

Mentioned in SAL (#wikimedia-operations) [2025-01-21T12:15:53Z] <kart_> Updated cxserver to 2025-01-20-172318-production (T377966, T377813)