Skip to content

[*] Chore: Refactor CommonJS scripts to ESM modules#8355

Merged
etrepum merged 13 commits intofacebook:mainfrom
etrepum:claude/refactor-commonjs-to-esm-9xGeJ
Apr 17, 2026
Merged

[*] Chore: Refactor CommonJS scripts to ESM modules#8355
etrepum merged 13 commits intofacebook:mainfrom
etrepum:claude/refactor-commonjs-to-esm-9xGeJ

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Apr 14, 2026

Description

Convert all remaining CommonJS scripts (.js) to ESM modules (.mjs):

  • scripts/shared/ (packagesManager, PackageMetadata, childProcess, etc.)
  • scripts/error-codes/ (transform-error-messages, ErrorMap, evalToString, etc.)
  • scripts/www/ (npmToWwwName, rewriteImports, transformFlowFileContents)
  • scripts/npm/ (release, prepare-release, increment-version, etc.)
  • Root-level scripts (clean, build-types, flow, lint-flow, etc.)
  • Root config files (babel.config.js -> .mjs, playwright.config.js -> .mjs)
  • packages/lexical-website/docusaurus.config.js -> .mjs
  • packages/lexical-website/plugins/package-docs/index.js -> .mjs

Replace require()/module.exports with import/export, __dirname with import.meta.dirname, __filename with import.meta.filename. Update all cross-references in build.mjs, vite configs, wxt config, eslint config, package.json scripts, CI workflows, and AGENTS.md.

Test plan

All of the tests/infrastructure/etc. should be changed to work with the new file extensions

Convert all remaining CommonJS scripts (.js) to ESM modules (.mjs):
- scripts/shared/ (packagesManager, PackageMetadata, childProcess, etc.)
- scripts/error-codes/ (transform-error-messages, ErrorMap, evalToString, etc.)
- scripts/www/ (npmToWwwName, rewriteImports, transformFlowFileContents)
- scripts/npm/ (release, prepare-release, increment-version, etc.)
- Root-level scripts (clean, build-types, flow, lint-flow, etc.)
- Root config files (babel.config.js -> .mjs, playwright.config.js -> .mjs)
- packages/lexical-website/docusaurus.config.js -> .mjs
- packages/lexical-website/plugins/package-docs/index.js -> .mjs

Replace require()/module.exports with import/export, __dirname with
import.meta.dirname, __filename with import.meta.filename. Update all
cross-references in build.mjs, vite configs, wxt config, eslint config,
package.json scripts, CI workflows, and AGENTS.md.

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Apr 14, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 14, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 15, 2026 2:42pm
lexical-playground Ready Ready Preview, Comment Apr 15, 2026 2:42pm

Request Review

Update import paths from .js to .mjs in files that were already ESM
but still referenced the old filenames:
- scripts/update-tsconfig.mjs
- scripts/update-examples.mjs
- scripts/build.mjs (JSDoc type import)
- scripts/__tests__/integration/setup.mjs
- scripts/__tests__/integration/utils.mjs
- scripts/__tests__/integration/ascii-only.test.mjs
- scripts/__tests__/integration/prepare-release.test.mjs

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
jiti v1 (used by Docusaurus to load configs) crashes on import.meta
syntax. Fix by:
- Keeping docusaurus.config.js as CJS (jiti resolves extensionless
  require() to .mjs files and transpiles them)
- Removing import.meta.dirname from packagesManager.mjs, using
  process.cwd()-relative path.resolve() instead (scripts always run
  from repo root)
- PackageMetadata.mjs and npmToWwwName.mjs never used import.meta,
  so they work under jiti as-is

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
import.meta.dirname is a Node 20.11+ addition that jiti v1 doesn't
transform. Use the classic fileURLToPath(import.meta.url) polyfill
instead, which jiti does handle. This ensures packagesManager works
correctly regardless of cwd (e.g. when loaded via viteModuleResolution
from packages/lexical-playground).

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
Keep package-docs plugin as ESM (.mjs) and use the explicit path
'./plugins/package-docs/index.mjs' in docusaurus config so that
Docusaurus's plugin resolver (which only looks for .js by default)
can find it. jiti transpiles the ESM import/export to CJS.

Verified with `pnpm run --filter @lexical/website build`.

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
Replace findMonorepoRoot() + dynamic import() with a simple static
import from the known relative path to PackageMetadata.mjs.

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
The file is already excluded from the root tsconfig. Remove
@ts-nocheck, redundant JSDoc type annotations, and the unnecessary
_pm alias for packagesManager (it's always imported).

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
Add @docusaurus/types and @docusaurus/plugin-content-docs as devDeps
and use their exported types (Config, SidebarItemsGenerator,
NormalizedSidebarItem, ParseFrontMatter) instead of any. Remove all
eslint-disable comments for no-explicit-any.

https://claude.ai/code/session_01XHQmKstRXm1aqpPi9Zg9jE
@etrepum etrepum added this pull request to the merge queue Apr 17, 2026
Merged via the queue into facebook:main with commit 4d24cc3 Apr 17, 2026
41 checks passed
etrepum pushed a commit to etrepum/lexical that referenced this pull request Apr 19, 2026
…ePostCss synchronous

Docusaurus calls `configurePostCss` synchronously and does not await the
return value (see applyConfigurePostCss in
packages/docusaurus/src/webpack/configure.ts), so an async hook returns a
Promise that is assigned to `postcssOptions` and the Tailwind plugin
never makes it into the PostCSS pipeline. This regressed when the config
was refactored to ESM in facebook#8355.

Switch to a top-level `import` of `@tailwindcss/postcss` and drop the
`async`/`await` from the hook.

https://claude.ai/code/session_01SoJjmweDQQhEvnFepoP4X5
@etrepum etrepum deleted the claude/refactor-commonjs-to-esm-9xGeJ branch April 19, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants