refactor(linter/plugins): remove require(esm)#15866
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the plugin loading mechanism to replace require(esm) with dynamic import(), eliminating a hacky workaround and improving type safety. The change enables better TypeScript integration and broadens Node.js version compatibility for JS plugins.
Key Changes
- Removed dual-entry build configuration in TSDown, simplifying to a single entry point
- Replaced synchronous
require()with asynchronousimport()for lazy-loading plugin code - Improved type checking by allowing TypeScript to "see into" the import statement
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/oxlint/tsdown.config.ts | Simplified build configuration from dual entries (cli and plugins) to single entry (cli) |
| apps/oxlint/src-js/cli.ts | Replaced require(esm) with dynamic import() for plugin loading, updated import path from ./plugins.js to ./plugins/index.js |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
`loadPlugin` is already async, so we don't need to use `require(esm)` for lazy-loading the JS plugins-related code. Use `import` instead.
This has 3 advantages:
1. Removes the hacky workaround of a separate entry point for TSDown, and hard-coded path in `require('./plugins.js')`, which is only correct if TSDown config remains unchanged.
2. TypeScript can "see into" the `import` -> better type safety.
3. Support versions of NodeJS which don't support `require(esm)`.
On the last one, it's not strictly necessary, as `oxlint` requires a version of NodeJS with `require(esm)` support:
https://github.com/oxc-project/oxc/blob/b622ef87adf1bbed1e76ba0f610b653acb93e72b/apps/oxlint/package.json#L19-L21
But if user *is* on an older version of NodeJS, JS plugins should now work.
03bd005 to
dd28d82
Compare
|
Note: |
|
yep this was just a local sanity check to make sure we were going to be including everything that was needed in the published packages |
`loadPlugin` is already async, so we don't need to use `require(esm)` for lazy-loading the JS plugins-related code. Use `import` instead.
This has 3 advantages:
1. Removes the hacky workaround of a separate entry point for TSDown, and hard-coded path in `require('./plugins.js')`, which is only correct if TSDown config remains unchanged.
2. TypeScript can "see into" the `import` -> better type safety.
3. Support versions of NodeJS which don't support `require(esm)`.
On the last one, it's not strictly necessary, as `oxlint` requires a version of NodeJS with `require(esm)` support:
https://github.com/oxc-project/oxc/blob/b622ef87adf1bbed1e76ba0f610b653acb93e72b/apps/oxlint/package.json#L19-L21
But if user *is* on an older version of NodeJS, JS plugins should now work.
oxc-project#15876) Follow-on after oxc-project#15866. Don't include hashes in filenames in `dist`. They're unnecessary and ugly, and Oxlint is not a front-end package, so hashes are not useful for caching.

loadPluginis already async, so we don't need to userequire(esm)for lazy-loading the JS plugins-related code. Useimportinstead.This has 3 advantages:
require('./plugins.js'), which is only correct if TSDown config remains unchanged.import-> better type safety.require(esm).On the last one, it's not strictly necessary, as
oxlintrequires a version of NodeJS withrequire(esm)support:oxc/apps/oxlint/package.json
Lines 19 to 21 in b622ef8
But if user is on an older version of NodeJS, JS plugins should now work.