Repository navigation
[*] Breaking change: Publish ESM only to npm and keep the CommonJS build for www - #9127
Merged
Merged
Conversation
…ild for www
## Description
`scripts/build.mjs` built every public package twice for npm, as
CommonJS (`dist/<Name>{,.dev,.prod}.js`) and as ESM
(`dist/<Name>{,.dev,.prod,.node}.mjs`), and `scripts/updateVersion.mjs`
wrote an exports map with separate `import` and `require` blocks plus a
`main` pointing at the CommonJS file. Meta's www build (`--www`) only
ever consumed the CommonJS variants.
The npm packages are now ESM only. The build emits `dist/*.mjs` (and
`.d.ts`, `.mjs.flow`) for npm and still emits the CommonJS
`dist/*.{dev,prod}.js` for `--www`, which `prepare-www` consolidates as
before. A CommonJS consumer gets the same `.mjs` files through Node's
`require(esm)` (every supported Node.js, 20.19+, has it), so:
- The exports map is flat: `source`, `types@<min>`, `types`,
`development`, `production`, `default` (with a `browser` block in
front for entries that have a `.browser.ts`). The `import`/`require`
split is gone because both would have named the same files, and
`main`/`module` point at the `.mjs` fork module.
- The `node` condition and its `<Name>.node.mjs` fork are gone. That
fork chose a single variant with top-level await, and Node refuses to
`require()` any ESM graph containing one, which broke `require()` of
every package whose build statically imports another Lexical package
(`@lexical/utils`, `@lexical/headless`, ...). The remaining
`<Name>.mjs` fork imports both variants and picks at runtime; a Node
consumer that wants one variant can run with `--conditions=production`
(or `development`).
- A module whose only export is its default (`@lexical/eslint-plugin`)
additionally exports it under the `"module.exports"` name, so
`require()` returns the plugin object itself the way the CommonJS
build's `module.exports` did. ESLint 8 legacy configs and CommonJS
`eslint.config.js` files keep working unchanged.
- Flow stubs are copied into `dist/` as `<Name>.mjs.flow` so Flow finds
them next to the `<Name>.mjs` that `main` names.
- Readers of the exports map in the monorepo
(`scripts/vite/viteModuleResolution.ts`, the website's
`docusaurus.config.ts`, the internal `no-imports-from-self` lint rule,
the tree-shaking integration test) read the flat conditions, and a new
package.json audit in `scripts/__tests__/unit/build.test.ts` fails if a
published entry ever references a `.js` build or an
`import`/`require`/`node` condition again.
- Docs and the `@lexical/headless` README describe the ESM-only layout
and the `require(esm)` path for CommonJS projects.
## Test plan
### Before
```
$ pnpm run build && ls packages/lexical/dist | grep -v d.ts
Lexical.dev.js
Lexical.dev.mjs
Lexical.js
Lexical.mjs
Lexical.node.mjs
Lexical.js.flow
```
With the CommonJS build simply dropped (and `require` pointed at the
ESM fork), `require()` of a dependent package failed on the `node` fork:
```
$ cd packages/lexical-headless && node -e "require('@lexical/headless')"
Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead.
Requiring /home/user/lexical/packages/lexical-headless/dist/LexicalHeadless.mjs
```
### After
```
$ pnpm run build --prod --release && ls packages/lexical/dist | grep -v d.ts
Lexical.dev.mjs
Lexical.mjs
Lexical.mjs.flow
Lexical.prod.mjs
$ cd packages/lexical-headless && node -e "const h = require('@lexical/headless'); const d = require('@lexical/headless/dom'); console.log(typeof h.createHeadlessEditor, Object.keys(d))"
function [ 'withDOM' ]
$ NODE_ENV=production node -e "console.log(typeof require('@lexical/headless').createHeadlessEditor)"
function
$ node --conditions=production --input-type=module -e "console.log(import.meta.resolve('lexical'))"
file:///home/user/lexical/packages/lexical/dist/Lexical.prod.mjs
$ cd packages/lexical-playground && node -e "console.log(Object.keys(require('@lexical/eslint-plugin').rules))"
[ 'no-document-in-dom-methods', 'rules-of-lexical' ]
$ pnpm run build-www && ls packages/lexical/dist packages/lexical-eslint-plugin/dist
packages/lexical-eslint-plugin/dist:
LexicalEslintPlugin.dev.js
LexicalEslintPlugin.prod.js
packages/lexical/dist:
Lexical.dev.js
Lexical.prod.js
Lexical.js.flow (via prepare-www)
$ pnpm run test-eslint-integration
Total tests: 6
Passed: 6
✓ All tests passed!
$ pnpm exec vitest --project scripts-unit --no-watch
Test Files 7 passed (7)
Tests 2171 passed (2171)
$ node scripts/npm/prepare-release.mjs
[@lexical/yjs] OK (0.50.0) # every package OK
$ pnpm exec vitest --project integration --no-watch scripts/__tests__/integration/{tree-shaking,ascii-only,internal-inlined,compiler}.test.mjs
Test Files 4 passed (4)
Tests 307 passed (307)
$ pnpm run --filter @lexical/website build
[SUCCESS] Generated static files in "build".
$ pnpm run ci-check
(tsc, tsc-scripts, tsc-extension, tsc-website, flow, prettier, lint all pass)
```
Flow resolves the renamed stub through `main`: a scratch project with
`node_modules/lexical/{package.json,dist/Lexical.mjs,dist/Lexical.mjs.flow}`
and `const e: number = createEditor()` reports the expected type error
referencing `dist/Lexical.mjs.flow`.
The example-project integration tests (`prepare-release.test.mjs`) were
not run locally; they install every example from the registry.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…heck Metro and nodenext consumers
## Description
The previous commit on this branch dropped the CommonJS build from npm
but still named the ESM `dist/*.mjs` and left the packages without a
`"type"`. Every public package now declares `"type": "module"`, so its
build is plain `.js` (`dist/<Name>{,.dev,.prod}.js`, `<Name>.js.flow`)
and its exports map, `main`, and `module` point at those. The ESM
extension is decided per package by the new
`PackageMetadata#getEsmExtension`: `@lexical/eslint-plugin` opts out with
a hand-written `"type": "commonjs"` because its own sources are CommonJS
`.js` files, so it keeps `.mjs` builds and everything else stays as it
was for it.
Two things follow from being an ES module package:
- A `.d.ts` in such a package is an ES module declaration, and
TypeScript's `nodenext` resolution does not resolve the extensionless
relative imports tsc emits (`from './LexicalEditor'`) in one. A
consumer with `skipLibCheck` (the usual default) got no error and
silently typed every Lexical export as `any`. The build now rewrites
those imports in the copied declarations with an explicit `.js`
extension (`./X.js` resolves to `X.d.ts` under every resolution mode;
a directory import becomes `./X/index.js`). A new integration test,
`scripts/__tests__/integration/declaration-resolution.test.mjs`, links
every public package into a temporary `nodenext` project, imports every
entry point, and fails on any relative import inside the declarations
that does not resolve.
- `require()` of the ESLint plugin's ESM build returns the module
namespace (the `"module.exports"` interop that would hand back the
plugin itself only exists in Node.js 22.12+, not 20.19), so
`src/index.ts` re-exports `configs`, `meta`, and `rules` as named
exports and ESLint accepts the namespace as the plugin on every
supported Node.js. The published build reads them off the CommonJS
plugin object at module scope, so the plugin is registered as a known
exception in the published-build tree-shaking test.
React Native was the open question. Metro bundles the packages as-is
(package exports on, and through `main` with exports off), but it does
not set the `development`/`production` conditions and does not drop the
build the `default` fork module leaves unused, so a release bundle ships
both. The website FAQ gains a "Which module formats are published?"
section that documents this, the `require(esm)` and `--conditions`
behaviour on Node.js, and a `resolveRequest` for `metro.config.js` that
adds the matching condition for the Lexical packages. A new integration
fixture, `scripts/__tests__/integration/fixtures/lexical-metro-headless`,
bundles `@lexical/headless` with Metro in dev and release mode, with
Metro's defaults and with that resolver, executes the four bundles, and
checks that the resolver leaves exactly one build in each.
Also updates the playground's ESM importmap, the dev-examples build, and
the maintainer docs for the `.js` names.
## Test plan
### Before
With `"type": "module"` added to the published `lexical` and nothing
else, a `nodenext` consumer:
```
$ cat src/a.ts
import {createEditor, LexicalEditor} from "lexical";
const e: LexicalEditor = createEditor();
const n: number = e;
$ tsc -p tsconfig.json # moduleResolution nodenext, skipLibCheck true
(no errors: every import typed as any)
$ tsc -p tsconfig.json # skipLibCheck false
node_modules/lexical/dist/index.d.ts(8,371): error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'.
```
`require('@lexical/eslint-plugin')` on Node.js 20.19 returned a
namespace with only `default` on it, which ESLint 8 cannot use.
### After
```
$ pnpm run build --prod --release && ls packages/lexical/dist | grep -v d.ts
Lexical.dev.js
Lexical.js
Lexical.js.flow
Lexical.prod.js
$ grep -ho "from '\./[^']*'" packages/lexical/dist/index.d.ts | head -2
from './LexicalCommands.js'
from './LexicalConstants.js'
$ tsc -p tsconfig.json # nodenext, skipLibCheck true and false; bundler; a CommonJS consumer
src/a.ts(3,7): error TS2322: Type 'LexicalEditor' is not assignable to type 'number'.
$ cd packages/lexical-headless && node -e "console.log(typeof require('@lexical/headless').createHeadlessEditor, require.resolve('lexical'))"
function /home/user/lexical/packages/lexical/dist/Lexical.js
$ cd packages/lexical-playground && node --input-type=module -e "import * as ns from '@lexical/eslint-plugin'; console.log(Object.keys(ns))"
[ 'configs', 'default', 'meta', 'rules' ]
$ pnpm exec vitest --project integration --no-watch scripts/__tests__/integration/declaration-resolution.test.mjs
Tests 103 passed (103)
# and, with `from './index.js'` in dist/LexicalListNode.d.ts changed back to `from '.'`:
+ "../../home/user/lexical/packages/lexical-list/dist/LexicalListNode.d.ts: TS2307: Cannot find module '.' or its corresponding type declarations.",
Tests 1 failed | 102 passed (103)
$ pnpm exec vitest --project integration --no-watch scripts/__tests__/integration/prepare-release.test.mjs -t lexical-metro-headless
default-dev: METRO_OK development Hello Metro
default-release: METRO_OK production Hello Metro
single-dev: METRO_OK development Hello Metro
single-release: METRO_OK production Hello Metro
Tests 3 passed | 92 skipped (95)
# bundle sizes: default-release 445 KB (both builds), single-release 208 KB (production only)
$ pnpm run test-eslint-integration
Total tests: 6
Passed: 6
$ pnpm exec vitest --project scripts-unit --no-watch
Tests 2240 passed (2240)
$ pnpm exec vitest --project integration --no-watch scripts/__tests__/integration/{ascii-only,internal-inlined,compiler,declaration-resolution,tree-shaking}.test.mjs
Tests 410 passed (410)
$ node scripts/npm/prepare-release.mjs | grep -c OK
34
$ pnpm run build-www && ls packages/lexical/dist
Lexical.dev.js Lexical.js.flow Lexical.prod.js
$ pnpm run ci-check
exit=0
$ pnpm run --filter @lexical/website build
[SUCCESS] Generated static files in "build".
```
The remaining example-project integration tests install every example
from the registry and were not run locally.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…plugin's mixed exports
## Description
`pnpm run build-www` failed on `@lexical/eslint-plugin` with Rollup's
MIXED_EXPORTS warning, which the build treats as fatal: the www
CommonJS build used `output.exports: 'auto'` for that package so that
`module.exports` was the plugin itself, and that only works while the
default export is the module's only export. The previous commit added
`rules`, `configs`, and `meta` as named exports (so that `require()` of
the ESM build works as an ESLint plugin on Node.js 20.19), which made the
exports mixed.
The www build now uses `exports: 'named'` for every package. The
plugin's CommonJS output is `exports.default` plus `rules`, `configs`,
and `meta`, which ESLint accepts as a plugin the same way.
## Test plan
### Before
```
$ pnpm run build --www
{
code: 'MIXED_EXPORTS',
id: '.../packages/lexical-eslint-plugin/src/index.ts',
message: 'Entry module "packages/lexical-eslint-plugin/src/index.ts" is using named and default exports together. ...'
}
[ELIFECYCLE] Command failed with exit code 1.
```
### After
```
$ pnpm run build-www
$ node scripts/build.mjs --www
$ node scripts/build.mjs --www --prod
$ node scripts/www/rewriteImports.mjs
exit=0
$ cd packages/lexical-eslint-plugin/dist && node -e "const p = require('./LexicalEslintPlugin.dev.js'); console.log(Object.keys(p), Object.keys(p.rules))"
[ 'configs', 'default', 'meta', 'rules' ] [ 'no-document-in-dom-methods', 'rules-of-lexical' ]
$ pnpm exec vitest --project scripts-unit --no-watch
Tests 2240 passed (2240)
```
Co-Authored-By: Claude Fable 5.1 <[email protected]>
## Description
`@lexical/eslint-plugin` was the one package whose own sources were
CommonJS (`src/LexicalEslintPlugin.js`, its rules, and its utilities
used `require` and `module.exports`, "for bootstrapping reasons"), so it
opted out of `"type": "module"` with a hand-written `"type": "commonjs"`
and its ESM build was `.mjs` while every other package's is `.js`.
The plugin's sources are ES modules now, and the package is a
`"type": "module"` package like the rest: its build is
`dist/LexicalEslintPlugin{,.dev,.prod}.js`, and the per-package ESM
extension (`PackageMetadata#getEsmExtension`) is gone along with the
opt-out, so `scripts/build.mjs` and `scripts/updateVersion.mjs` deal in
`.js` alone again. Nothing needs compiling to use the plugin from this
checkout: the monorepo's `eslint.config.mjs` imports the ESM source
directly.
- The plugin module exports `rules`, `meta`, and `configs` by name and
the plugin object as its default. The objects are assembled inside
functions declared `@__NO_SIDE_EFFECTS__` and called once at module
scope, instead of by module-scope property reads and mutations, so a
bare import of the module retains nothing. The published-build
tree-shaking exception the previous commit added for the plugin is
removed, since the test now passes without it.
- `meta.name`/`meta.version` came from `require('../package.json')`.
A JSON import attribute would need every parser in the tool chain
configured for it, so the version comes from a generated
`src/version.js` that `scripts/updateVersion.mjs` rewrites with the
monorepo version (as it already does for `@lexical/internal`), with
the build's `process.env.LEXICAL_VERSION` replacement taking precedence
and its `+dev.esm`-style build metadata stripped, so `meta.version`
stays the package version. The name is not written as a single string
literal because the www build rewrites quoted npm package names to www
module names, and `meta.name` was the npm name there too.
- The root www stub `LexicalEslintPlugin.js` requires the www build in
`dist/` like every other package's stub, rather than the source, which
is no longer CommonJS.
## Test plan
### Before
```
$ cat packages/lexical-eslint-plugin/package.json | grep '"type"'
"type": "commonjs",
$ ls packages/lexical-eslint-plugin/dist | grep -v d.ts
LexicalEslintPlugin.dev.mjs
LexicalEslintPlugin.mjs
LexicalEslintPlugin.mjs.flow
LexicalEslintPlugin.prod.mjs
```
### After
```
$ grep '"type"' packages/lexical-eslint-plugin/package.json
"type": "module"
$ pnpm run build && ls packages/lexical-eslint-plugin/dist | grep -v d.ts
LexicalEslintPlugin.dev.js
LexicalEslintPlugin.js
LexicalEslintPlugin.js.flow
$ cd packages/lexical-playground && node -e "const p = require('@lexical/eslint-plugin'); console.log(Object.keys(p), p.meta, Object.keys(p.rules))"
[ '__esModule', 'configs', 'default', 'meta', 'rules' ] { name: '@lexical/eslint-plugin', version: '0.50.0' } [ 'no-document-in-dom-methods', 'rules-of-lexical' ]
$ node --input-type=module -e "import plugin, {rules} from '@lexical/eslint-plugin'; console.log(Object.keys(plugin), plugin.rules === rules)"
[ 'configs', 'meta', 'rules' ] true
$ pnpm run test-eslint-integration
Total tests: 6
Passed: 6
$ pnpm exec vitest --project unit --no-watch packages/lexical-eslint-plugin
Test Files 4 passed (4)
Tests 18 passed (18)
$ pnpm exec vitest --project scripts-unit --no-watch
Tests 2240 passed (2240)
$ pnpm run build --prod --release && pnpm exec vitest --project integration --no-watch scripts/__tests__/integration/{tree-shaking,declaration-resolution,ascii-only,internal-inlined,compiler}.test.mjs
Tests 410 passed (410)
$ node scripts/npm/prepare-release.mjs | grep -c OK
34
$ pnpm run build-www # then, loaded from a CommonJS context:
$ node -e "const p = require('./www-plugin.cjs'); console.log(Object.keys(p), p.meta, Object.keys(p.rules))"
[ 'configs', 'default', 'meta', 'rules' ] { name: '@lexical/eslint-plugin', version: '0.50.0' } [ 'no-document-in-dom-methods', 'rules-of-lexical' ]
$ pnpm run ci-check # lint loads the plugin from its ESM source
exit=0
```
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…-only-auqthv # Conflicts: # packages/lexical-website/docs/faq.md
…them as CommonJS
## Description
The previous commit pointed `packages/lexical-eslint-plugin/LexicalEslintPlugin.js`,
the www stub at the package root, at the www build in `dist/` instead of
the plugin's source. www consumes those stubs as they are, so this
restores it to `require('./src/LexicalEslintPlugin.js')` as it was.
The stubs are CommonJS `.js` files and stay that way whatever the
packages' `"type": "module"` says, since www does not read package.json.
Every tsconfig already excludes them; the ESLint config now says
explicitly that `packages/*/*.js` is CommonJS instead of relying on the
base configuration's `script` default.
## Test plan
### Before
```
$ git show HEAD~1 -- packages/lexical-eslint-plugin/LexicalEslintPlugin.js | grep require
-module.exports = require('./src/LexicalEslintPlugin.js');
+module.exports = require('./dist/LexicalEslintPlugin.js');
```
### After
```
$ tail -1 packages/lexical-eslint-plugin/LexicalEslintPlugin.js
module.exports = require('./src/LexicalEslintPlugin.js');
$ pnpm exec eslint --print-config packages/lexical/Lexical.js | grep sourceType
"sourceType": "commonjs",
$ pnpm run lint
(no errors, no warnings)
```
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…and the legacy config format
## Description
`@lexical/eslint-plugin` supported ESLint 7-8 through legacy `.eslintrc`
configs: `configs.recommended` and `configs.all` were the legacy-format
configs (also exposed as `legacy-recommended` and `legacy-all`), and the
flat configs for ESLint 9+ lived under `flat/recommended` and
`flat/all`, with the README promising that `recommended` and `all` would
move to flat config in a future version.
That version is this one. The legacy configs are gone, the `eslint` peer
dependency is `>=9.0.0`, and `configs.recommended` and `configs.all` are
the flat configs. `flat/recommended` and `flat/all` stay as aliases so an
existing flat-config consumer keeps working. The `LegacyConfig` type is
removed and `Plugin['configs']` lists only the four flat entries.
The integration test drops the two ESLint 8 fixtures and runs the same
flat `eslint.config.js` (now using `configs.recommended`) against ESLint
9 and 10, so every supported major is covered. The README and the
integration README describe the supported versions and the aliases.
## Test plan
### Before
```
$ node -e "const p = require('@lexical/eslint-plugin'); console.log(Object.keys(p.configs), p.configs.recommended)"
[ 'all', 'flat/all', 'flat/recommended', 'legacy-all', 'legacy-recommended', 'recommended' ] { plugins: [ '@lexical' ], rules: { '@lexical/rules-of-lexical': 'warn' } }
```
### After
```
$ node -e "const p = require('@lexical/eslint-plugin'); console.log(Object.keys(p.configs), p.configs.recommended === p.configs['flat/recommended'], Object.keys(p.configs.recommended.plugins))"
[ 'all', 'flat/all', 'flat/recommended', 'recommended' ] true [ '@lexical' ]
$ pnpm run test-eslint-integration
Testing ESLint 9 (Flat Config)
✓ ESLint 9 - valid.js (should pass)
✓ ESLint 9 - invalid.js (should fail)
Testing ESLint 10 (Flat Config)
✓ ESLint 10 - valid.js (should pass)
✓ ESLint 10 - invalid.js (should fail)
Passed: 4
$ pnpm exec vitest --project unit --no-watch packages/lexical-eslint-plugin
Tests 18 passed (18)
$ pnpm exec vitest --project scripts-unit --no-watch
Tests 2241 passed (2241)
$ pnpm run tsc && pnpm exec eslint packages/lexical-eslint-plugin eslint.config.mjs
(clean)
$ pnpm install --frozen-lockfile
Lockfile is up to date, resolution step is skipped
```
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ery declaration import under nodenext and document the require(esm) caveat
## Description
Two gaps found in review of the ESM-only build:
1. The declaration rewrite only gave relative imports an extension.
`@lexical/code-prism/dist/FacadePrism.d.ts` also carries the
side-effect imports `import 'prismjs/components/prism-clike'` and so
on; prismjs has no exports map, so under `nodenext` those are file
paths that need `.js` (which the JavaScript build already adds through
`resolveExternalEsm`). A consumer with `noUncheckedSideEffectImports`
got 17 TS2882 errors. Bare specifiers in declarations now go through
`resolveExternalEsm` too.
2. The strengthened test then also found `@lexical/mdast`'s declarations
referring to `import("@lexical/html/src/types").RenderStateConfig`,
a subpath the `@lexical/html` exports map does not expose, because
`RenderStateConfig` was not re-exported from `@lexical/html` and tsc
inlined the path. `@lexical/html` now exports the type (its Flow stub
already had it), and the mdast declarations refer to
`import("@lexical/html").RenderStateConfig`.
`scripts/__tests__/integration/declaration-resolution.test.mjs` now
checks side-effect imports (`noUncheckedSideEffectImports`) and treats
a bare specifier that fails to resolve as a failure whenever the owning
package declares that dependency, since it is then installed next to
the package and only the specifier can be at fault; an undeclared
transitive one (`@preact/signals-core` from `@lexical/a11y`) stays out
of scope.
The FAQ and the headless README also state what `require(esm)` does not
give a CommonJS application: Lexical's builds import their dependencies
as ES modules, so a dependency the application also loads with
`require()` (yjs, @preact/signals-core) exists twice, once per module
system, and objects from the CommonJS copy cannot be handed to Lexical.
Such dependencies have to be loaded as ES modules as well.
## Test plan
### Before
```
$ pnpm exec vitest --project integration --no-watch scripts/__tests__/integration/declaration-resolution.test.mjs
+ "../../home/user/lexical/packages/lexical-code-prism/dist/FacadePrism.d.ts: TS2882: Cannot find module or type declarations for side-effect import of 'prismjs/components/prism-typescript'.",
+ "../../home/user/lexical/packages/lexical-mdast/dist/MdastExport.d.ts: TS2307: Cannot find module '@lexical/html/src/types' or its corresponding type declarations.",
Tests 1 failed | 102 passed (103)
```
### After
```
$ pnpm run build && grep -n "prism-clike\|@lexical/html" packages/lexical-code-prism/dist/FacadePrism.d.ts packages/lexical-mdast/dist/MdastExport.d.ts
packages/lexical-code-prism/dist/FacadePrism.d.ts:10:import 'prismjs/components/prism-clike.js';
packages/lexical-mdast/dist/MdastExport.d.ts:26:export declare const RenderContextMarkdownSelection: import("@lexical/html").RenderStateConfig<BaseSelection | null>;
$ pnpm exec vitest --project integration --no-watch scripts/__tests__/integration/declaration-resolution.test.mjs
Tests 103 passed (103)
$ pnpm run tsc && pnpm exec vitest --project scripts-unit --no-watch
Tests 2241 passed (2241)
```
Co-Authored-By: Claude Fable 5.1 <[email protected]>
etrepum
marked this pull request as ready for review
September 8, 2026 17:35
etrepum
requested review from
acywatson,
fantactuka,
ivailop7 and
zurfyx
as code owners
September 8, 2026 17:35
…-only-auqthv # Conflicts: # pnpm-lock.yaml
zurfyx
approved these changes
Sep 9, 2026
ZedingZhang
added a commit
to ZedingZhang/lexical
that referenced
this pull request
Sep 10, 2026
…sted update lint to ESM ## Description The nested-update rule and its shared utilities still used CommonJS after the plugin sources moved to ESM in meta#9127. Export those modules as ESM, verify the rule through both the default plugin and its module namespace, and check the current flat presets and their aliases instead of the removed legacy preset. Update the configuration documentation and rename two newly added upstream test helpers that open their own editor updates, preserving their discrete updates and history tags. ## Test plan ### Before ```text $ node -e "import('./packages/lexical-eslint-plugin/src/LexicalEslintPlugin.js')" SyntaxError: The requested module '../util/ruleOptions.js' does not provide an export named 'DEFAULT_DOLLAR_FUNCTION_MATCHER' $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-eslint-plugin/src/__tests__/unit TypeError: Cannot read properties of undefined (reading 'rules') Test Files 1 failed | 3 passed (4) Tests 1 failed | 19 passed (20) ``` ### After ```text $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-eslint-plugin/src/__tests__/unit packages/lexical-playground/__tests__/unit/FindReplace.test.ts packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx packages/lexical-list/src/__tests__/unit/checkList.test.tsx packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx Test Files 9 passed (9) Tests 204 passed (204) $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-extension/src/__tests__/unit/HMRExtension.test.ts packages/lexical/src/__tests__/unit/Issue4815Repro.test.ts Test Files 2 passed (2) Tests 65 passed (65) $ node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/treeShakingSource.test.ts Test Files 1 passed (1) Tests 102 passed (102) $ pnpm run test-eslint-integration Total tests: 4 Passed: 4 $ pnpm run ci-check No errors! (exit 0) $ pnpm run build (exit 0) ``` The built package also passed smoke assertions for its ESM default export, named exports, and Node require(esm) namespace. Browser-mode and E2E matrices were not run locally.
ZedingZhang
added a commit
to ZedingZhang/lexical
that referenced
this pull request
Sep 10, 2026
…sted update lint to ESM ## Description The nested-update rule and its shared utilities still used CommonJS after the plugin sources moved to ESM in meta#9127. Export those modules as ESM, verify the rule through both the default plugin and its module namespace, and check the current flat presets and their aliases instead of the removed legacy preset. Update the configuration documentation and rename two newly added upstream test helpers that open their own editor updates, preserving their discrete updates and history tags. ## Test plan ### Before ```text $ node -e "import('./packages/lexical-eslint-plugin/src/LexicalEslintPlugin.js')" SyntaxError: The requested module '../util/ruleOptions.js' does not provide an export named 'DEFAULT_DOLLAR_FUNCTION_MATCHER' $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-eslint-plugin/src/__tests__/unit TypeError: Cannot read properties of undefined (reading 'rules') Test Files 1 failed | 3 passed (4) Tests 1 failed | 19 passed (20) ``` ### After ```text $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-eslint-plugin/src/__tests__/unit packages/lexical-playground/__tests__/unit/FindReplace.test.ts packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx packages/lexical-list/src/__tests__/unit/checkList.test.tsx packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx Test Files 9 passed (9) Tests 204 passed (204) $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-extension/src/__tests__/unit/HMRExtension.test.ts packages/lexical/src/__tests__/unit/Issue4815Repro.test.ts Test Files 2 passed (2) Tests 65 passed (65) $ node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/treeShakingSource.test.ts Test Files 1 passed (1) Tests 102 passed (102) $ pnpm run test-eslint-integration Total tests: 4 Passed: 4 $ pnpm run ci-check No errors! (exit 0) $ pnpm run build (exit 0) ``` The built package also passed smoke assertions for its ESM default export, named exports, and Node require(esm) namespace. Browser-mode and E2E matrices were not run locally.
ZedingZhang
added a commit
to ZedingZhang/lexical
that referenced
this pull request
Sep 17, 2026
…g Fix: adapt nested update lint to ESM ## Description The nested-update rule and its shared utilities still used CommonJS after the plugin sources moved to ESM in meta#9127. Export those modules as ESM, verify the rule through both the default plugin and its module namespace, and check the current flat presets and their aliases instead of the removed legacy preset. Update the configuration documentation and rename three newly added upstream test helpers that open their own editor updates, preserving their discrete updates and history tags. ## Test plan ### Before ```text $ node -e "import('./packages/lexical-eslint-plugin/src/LexicalEslintPlugin.js')" SyntaxError: The requested module '../util/ruleOptions.js' does not provide an export named 'DEFAULT_DOLLAR_FUNCTION_MATCHER' $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-eslint-plugin/src/__tests__/unit TypeError: Cannot read properties of undefined (reading 'rules') Test Files 1 failed | 3 passed (4) Tests 1 failed | 19 passed (20) ``` After rebasing onto the latest main, the newly added table test helper also failed the enabled rule: ```text $ corepack pnpm lint packages/lexical-table/src/__tests__/unit/TableFieldAccessors.test.ts 74:3 error $withEditor is named as a Lexical $function but calls editor.update @lexical/no-nested-editor-updates ✖ 1 problem (1 error, 0 warnings) ``` ### After ```text $ corepack pnpm vitest --project unit --no-watch packages/lexical-eslint-plugin/src/__tests__/unit packages/lexical-clipboard/src/__tests__/unit/ClipboardImportExtension.test.ts packages/lexical-playground/__tests__/unit/FindReplace.test.ts packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx packages/lexical-list/src/__tests__/unit/checkList.test.tsx packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx packages/lexical-extension/src/__tests__/unit/HMRExtension.test.ts packages/lexical-table/src/__tests__/unit/TableFieldAccessors.test.ts packages/lexical/src/__tests__/unit/Issue4815Repro.test.ts Test Files 13 passed (13) Tests 283 passed (283) ``` ```text $ corepack pnpm lint $ corepack pnpm tsc $ corepack pnpm tsc-scripts $ corepack pnpm tsc-extension $ corepack pnpm tsc-website $ corepack pnpm prettier $ corepack pnpm build All commands exited successfully. ``` The ESLint integration script could not be rerun on native Windows because it launches `/bin/bash`; the refreshed GitHub Actions workflow covers it. Browser-mode and E2E suites were not run locally and are also covered by the pull request CI matrix.
Merged
12 tasks
ZedingZhang
added a commit
to ZedingZhang/lexical
that referenced
this pull request
Sep 29, 2026
…g Fix: adapt nested update lint to ESM ## Description The nested-update rule and its shared utilities still used CommonJS after the plugin sources moved to ESM in meta#9127. Export those modules as ESM, verify the rule through both the default plugin and its module namespace, and check the current flat presets and their aliases instead of the removed legacy preset. Update the configuration documentation and rename three newly added upstream test helpers that open their own editor updates, preserving their discrete updates and history tags. ## Test plan ### Before ```text $ node -e "import('./packages/lexical-eslint-plugin/src/LexicalEslintPlugin.js')" SyntaxError: The requested module '../util/ruleOptions.js' does not provide an export named 'DEFAULT_DOLLAR_FUNCTION_MATCHER' $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-eslint-plugin/src/__tests__/unit TypeError: Cannot read properties of undefined (reading 'rules') Test Files 1 failed | 3 passed (4) Tests 1 failed | 19 passed (20) ``` After rebasing onto the latest main, the newly added table test helper also failed the enabled rule: ```text $ corepack pnpm lint packages/lexical-table/src/__tests__/unit/TableFieldAccessors.test.ts 74:3 error $withEditor is named as a Lexical $function but calls editor.update @lexical/no-nested-editor-updates ✖ 1 problem (1 error, 0 warnings) ``` ### After ```text $ corepack pnpm vitest --project unit --no-watch packages/lexical-eslint-plugin/src/__tests__/unit packages/lexical-clipboard/src/__tests__/unit/ClipboardImportExtension.test.ts packages/lexical-playground/__tests__/unit/FindReplace.test.ts packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx packages/lexical-list/src/__tests__/unit/checkList.test.tsx packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx packages/lexical-extension/src/__tests__/unit/HMRExtension.test.ts packages/lexical-table/src/__tests__/unit/TableFieldAccessors.test.ts packages/lexical/src/__tests__/unit/Issue4815Repro.test.ts Test Files 13 passed (13) Tests 283 passed (283) ``` ```text $ corepack pnpm lint $ corepack pnpm tsc $ corepack pnpm tsc-scripts $ corepack pnpm tsc-extension $ corepack pnpm tsc-website $ corepack pnpm prettier $ corepack pnpm build All commands exited successfully. ``` The ESLint integration script could not be rerun on native Windows because it launches `/bin/bash`; the refreshed GitHub Actions workflow covers it. Browser-mode and E2E suites were not run locally and are also covered by the pull request CI matrix.
This was referenced Sep 29, 2026
Merged
AlessioGr
added a commit
to payloadcms/payload
that referenced
this pull request
Sep 30, 2026
…18397) _Written with AI_ Upgrades `lexical` and every installed `@lexical/*` package from `0.50.0` to `0.52.0` for Payload 4.x (`main`), and pinned `tsx` dependencies from `4.22.4` to `4.23.15`. Removes the native-loader workaround no longer needed with the new tsx version. Also fixes duplicate image uploads triggered by repeated node transforms in Lexical 0.52. CI fixes update the keyboard-navigation expectation and correct an existing auth-test parameter error that blocked integration tests. Fixes #17757 3.x counterpart: #18398. ## Why this fixes the CLI failure With Payload 3.90.1 on Node 22.22.0, importing a config that included `lexicalEditor()` could leave CLI startup pending before the config or target script was evaluated. The process then exited 0 with no output and left a pending PostgreSQL migration unapplied. Previously, Payload started the CLI with `void start()`, and an unresolved promise alone does not keep Node's event loop alive. Lexical 0.50's Node entry points select their build with top-level `await import(...)`, which is probably what caused it. Lexical has shipped ESM-only packages since **0.51**, using static imports instead of those asynchronous Node wrappers. Upgrading to 0.52 fixes this issue. Also removes the `module.registerHooks = undefined` workaround for #16949. tsx 4.23.15 [excludes bare built-ins from namespace inheritance](privatenumber/tsx@38e1588), following its [Node 24 `tsImport` bridge fix](privatenumber/tsx@6e5236b). ## CLI exit codes CLI startup is now awaited at the top level in all three loader paths: tsx, SWC, and disabled transpilation. If an import never settles and Node runs out of work, Node reports an unsettled top-level await and exits 13. Successful commands still exit 0, and command-specific failure codes are preserved. ## Breaking changes Rich-text data keeps its existing format. No database migration is needed. Payload's built-in features have been updated, but your own TypeScript code or custom features may need changes: - **Generic types:** `SerializedEditorState<T>`, `SerializedElementNode<T>`, and `SerializedRootNode<T>` no longer accept `<T>`. Remove it if the base node type is enough, or use Payload's `TypedEditorState<T>` for documents with your own node types. Without `<T>`, children are still `SerializedLexicalNode[]`. - **Export types:** `ReturnType<Node['exportJSON']>` can now make fields such as `version` and `url` optional. Use the node's explicit serialized type, such as `SerializedLinkNode`, when you need the full format. Normal `node.exportJSON()` calls still return full JSON. - **Selection listeners:** `SELECTION_CHANGE_COMMAND` now fires before the DOM is updated. If your custom listener reads the DOM, defer that work with `$onUpdate(() => editor.read('latest', callback))`. - **Saved node references:** If you keep a node reference across an editor update, call `node.getLatest().exportJSON()` to export its current values. The type changes also affect imports through `@payloadcms/richtext-lexical/lexical` and its subpaths. Payload's `TypedEditorState<T>` and its own serialized node types keep their generic APIs for this upgrade. Keep importing Lexical through Payload's re-exports; do not install a separate Lexical version. See the [custom feature documentation](https://payloadcms.com/docs/rich-text/custom-features). The table below also lists removed APIs that may affect custom features. `LexicalComposer` is deprecated but still available. ## Breaking changes and Payload migrations Reviewed [0.51.0](https://github.com/facebook/lexical/releases/tag/v0.51.0) and [0.52.0](https://github.com/facebook/lexical/releases/tag/v0.52.0), including the serialization declarations. **Yes** means Payload code needed adaptation; **No** means no Payload migration was required. | Release | Breaking change | Required migration in Payload | Changes made | | ------- | --------------- | ----------------------------- | ------------ | | 0.51 | [npm packages are ESM only](meta/lexical#9127); older CommonJS consumers must use dynamic imports. | No | Payload already uses ESM. This removes the asynchronous Lexical wrapper involved in the CLI reproducer. | | 0.51 | [Serialization schemas and compact export](meta/lexical#8602) add `exportJSON` overloads and remove the `SerializedEditorState`, `SerializedElementNode`, and `SerializedRootNode` generics. `ReturnType` can now infer compact, partial JSON. | Yes | Infer the full-format overload for node hooks, validation and population while preserving custom nodes' literal `type` discriminants. Update `hasText` to the non-generic editor-state type. | | 0.51 | [`exportJSON` can serialize a retained instance without calling `getLatest()`](meta/lexical#8602). | No | Audited Payload's clipboard and Markdown call sites: they serialize nodes obtained from the current selection/tree, without an intervening mutation. Custom callers holding stale references should use `node.getLatest().exportJSON()`. | | 0.51 | [Deprecated Prism re-exports are removed from `@lexical/code`](meta/lexical#9141). | No | Payload does not consume the removed exports. | | 0.52 | [`SELECTION_CHANGE_COMMAND` runs before DOM reconciliation](meta/lexical#9219), including node and table selections. | Yes | Defer link popup, inline toolbar and decorator DOM work with `$onUpdate` and `editor.read('latest', ...)`. Keep nested decorator updates with their own editor. The table menu already defers DOM reads. | | 0.52 | [Default HTML export honors `DOMRenderExtension` `$createDOM` overrides](meta/lexical#9231). | No | Payload does not configure these extension overrides; existing converter tests pass. | | 0.52 | [`LexicalNode.getCommonAncestor` is removed](meta/lexical#9238). | No | No Payload call sites. Custom consumers can use `$getCommonAncestor`, accounting for its different handling of non-element nodes. | React package entry points were compared against 0.50.0; no Payload proxy exports need adding or removing. ## Previous Lexical upgrades - [#18149](#18149) — 0.48.0 → 0.50.0 - [#17554](#17554) — 0.45.0 → 0.48.0 - [#17064](#17064) — 0.41.0 → 0.45.0
ZedingZhang
added a commit
to ZedingZhang/lexical
that referenced
this pull request
Nov 5, 2026
…g Fix: adapt nested update lint to ESM ## Description The nested-update rule and its shared utilities still used CommonJS after the plugin sources moved to ESM in meta#9127. Export those modules as ESM, verify the rule through both the default plugin and its module namespace, and check the current flat presets and their aliases instead of the removed legacy preset. Update the configuration documentation and rename three newly added upstream test helpers that open their own editor updates, preserving their discrete updates and history tags. ## Test plan ### Before ```text $ node -e "import('./packages/lexical-eslint-plugin/src/LexicalEslintPlugin.js')" SyntaxError: The requested module '../util/ruleOptions.js' does not provide an export named 'DEFAULT_DOLLAR_FUNCTION_MATCHER' $ node node_modules/vitest/vitest.mjs run --project unit packages/lexical-eslint-plugin/src/__tests__/unit TypeError: Cannot read properties of undefined (reading 'rules') Test Files 1 failed | 3 passed (4) Tests 1 failed | 19 passed (20) ``` After rebasing onto the latest main, the newly added table test helper also failed the enabled rule: ```text $ corepack pnpm lint packages/lexical-table/src/__tests__/unit/TableFieldAccessors.test.ts 74:3 error $withEditor is named as a Lexical $function but calls editor.update @lexical/no-nested-editor-updates ✖ 1 problem (1 error, 0 warnings) ``` ### After ```text $ corepack pnpm vitest --project unit --no-watch packages/lexical-eslint-plugin/src/__tests__/unit packages/lexical-clipboard/src/__tests__/unit/ClipboardImportExtension.test.ts packages/lexical-playground/__tests__/unit/FindReplace.test.ts packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx packages/lexical-list/src/__tests__/unit/checkList.test.tsx packages/lexical-react/src/__tests__/unit/LexicalCollaborationPlugin.test.tsx packages/lexical-extension/src/__tests__/unit/HMRExtension.test.ts packages/lexical-table/src/__tests__/unit/TableFieldAccessors.test.ts packages/lexical/src/__tests__/unit/Issue4815Repro.test.ts Test Files 13 passed (13) Tests 283 passed (283) ``` ```text $ corepack pnpm lint $ corepack pnpm tsc $ corepack pnpm tsc-scripts $ corepack pnpm tsc-extension $ corepack pnpm tsc-website $ corepack pnpm prettier $ corepack pnpm build All commands exited successfully. ``` The ESLint integration script could not be rerun on native Windows because it launches `/bin/bash`; the refreshed GitHub Actions workflow covers it. Browser-mode and E2E suites were not run locally and are also covered by the pull request CI matrix.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Every public package was built twice for npm, as CommonJS (
dist/<Name>{,.dev,.prod}.js) and as ESM (dist/<Name>{,.dev,.prod,.node}.mjs), with an exports map split intoimport/requireblocks andmainpointing at the CommonJS file. Meta's www build (--www) only ever consumed the CommonJS variants.The npm packages are now ESM only, and every public package is a
"type": "module"package. The build emitsdist/<Name>{,.dev,.prod}.js(plus.d.tsand.js.flow) for npm, and still emits the CommonJSdist/<Name>.{dev,prod}.jsfor--www, whichprepare-wwwconsolidates as before. The www stubs at each package root are untouched.CommonJS consumers
A CommonJS consumer gets the same
.jsfiles through Node'srequire(esm), which every supported Node.js has (20.19+, 22.12+). That works only when nothing in the module graph uses top-levelawait, so:source,types@<min>,types,development,production,default(with abrowserblock first for entries that have a.browser.ts). Theimport/requiresplit is gone because both would name the same files;mainandmodulepoint at the fork module.nodecondition and its<Name>.node.mjsfork are gone. That fork picked one variant with top-levelawait, and Node refuses torequire()any graph containing one, which brokerequire()of every package whose build imports another Lexical package (@lexical/utils,@lexical/headless, ...). The remaining fork imports both variants and picks at runtime fromNODE_ENV; a Node consumer that wants one variant runs with--conditions=production(ordevelopment). The measured cost of loading both is under 1 MB of heap and a few tens of milliseconds for a typical headless import set.output.exports: 'named'for every package; theautospecial case for the ESLint plugin only worked while its default export was its only export."type": "module"and declarationsA
.d.tsin a"type": "module"package is an ES module declaration, and TypeScript'snodenextresolution does not resolve the extensionless relative imports tsc emits (from './LexicalEditor') in one. A consumer withskipLibCheck(the usual default) got no error and silently typed every Lexical export asany. The build now rewrites those imports in the copied declarations with explicit.jsextensions (./X.jsresolves toX.d.tsunder every resolution mode; a directory import becomes./X/index.js). A new integration test,scripts/__tests__/integration/declaration-resolution.test.mjs, links every public package into a temporarynodenextproject, imports every entry point, and fails on any relative import inside the declarations that does not resolve.@lexical/eslint-pluginThe plugin was the one package whose own sources were CommonJS. They are ES modules now, so the package is
"type": "module"like the rest and the build scripts deal in.jsalone:rules,meta, andconfigsare named exports next to the default export, so the namespace thatrequire()returns is itself usable as an ESLint plugin on every supported Node.js (the"module.exports"interop that would return the default export exists only in 22.12+). The ESLint 8 legacy-config and ESLint 10 CommonJS flat-config fixtures pass unchanged.@__NO_SIDE_EFFECTS__rather than by module-scope reads and mutations, so a bare import retains nothing and the plugin needs no tree-shaking exception.meta.versioncomes from a generatedsrc/version.jsthatupdate-versionrewrites (as it already does for@lexical/internal), with the build'sLEXICAL_VERSIONreplacement taking precedence and its build metadata stripped.meta.nameis not spelled as one string literal because the www build rewrites quoted npm package names to www module names../src/LexicalEslintPlugin.js; the ESLint config now declarespackages/*/*.jsas CommonJS explicitly, since www does not read package.json and the stubs stay CommonJS.Metro / React Native
Metro bundles the packages as-is, with package exports on (the default since React Native 0.79) and through
mainwith exports off. It sets neither thedevelopmentnor theproductioncondition and does not drop the variant the fork leaves unused, so a release bundle carries both (445 KB versus 208 KB for a headless bundle). That was already the case before this PR. The website FAQ gains a "Which module formats are published?" section covering Node.js,require(),--conditions, and aresolveRequestformetro.config.jsthat adds the matching condition for the Lexical packages. A new fixture,scripts/__tests__/integration/fixtures/lexical-metro-headless, bundles@lexical/headlesswith Metro in dev and release mode, with and without that resolver, executes the bundles, and asserts the resolver leaves exactly one variant.Also
no-imports-from-selflint rule, the tree-shaking tests) read the flat conditions, and a package.json audit inscripts/__tests__/unit/build.test.tsfails if a published entry ever references arequire,import, ornodecondition or a non-.jsbuild again..jsnames.Test plan
Before
After
Flow resolves the shipped stub through
main: a scratch project withnode_modules/lexical/{package.json,dist/Lexical.js,dist/Lexical.js.flow}reports the expected type error againstdist/Lexical.js.flow.The example-project integration tests, which install every example from the registry, were not run locally; CI covers them.