Skip to content

🛠 Repo: Switch from CJS to ESM internally #5400

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Tooling Suggestion Checklist

Overview

Mocha's source code is written in a legacy CommonJS (CJS) style right now. That means 'use strict' in source files, const ... = require(...), module.exports, etc.

Moving to ECMAScript Modules (ESM) would allow the code to integrate better with more modern dev tooling. Static analysis tools such as ESLint and TypeScript are better able to analyze ESM, for example: which will help with #4154 and #4228.

Also I find ESM to be a cleaner syntax. It's more semantically precise! 🙂

Suggestion: let's migrate internally from CJS to ESM?

Additional Info

This is blocked on #5358: bumping the minimum Node.js version to one that supports require(esm).

I suspect this should land as a part of Mocha 12 (#5357). Although it shouldn't be a breaking change on its own, it's very likely some users out there are depending on some internal structuring quirk. Having this be part of the 12 beta for a while will help test it out. And having it be part of a major will help shield us from protests of semver breakage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: repository toolingconcerning ease of contributionstatus: in triagea maintainer should (re-)triage (review) this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions