Skip to content

feat: support ES module plugins - #5820

Open
stevenjoezhang wants to merge 1 commit into
masterfrom
agent/support-esm-plugins
Open

feat: support ES module plugins#5820
stevenjoezhang wants to merge 1 commit into
masterfrom
agent/support-esm-plugins

Conversation

@stevenjoezhang

Copy link
Copy Markdown
Member

What does it do?

Adds native ES module plugin loading for .mjs entries and .js entries in packages with "type": "module".

ES module plugins export a default initializer that receives the Hexo instance:

export default async function initialize(hexo) {
  // register extensions
}

The existing CommonJS vm loading path remains unchanged.

Closes #5525.

Validation:

  • Loader tests pass on Node.js 20.19.0 (19 passing).
  • ESLint passes for the changed files.
  • TypeScript build passes.

Screenshots

Not applicable.

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@github-actions

Copy link
Copy Markdown

How to test

git clone -b agent/support-esm-plugins https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test

@stevenjoezhang
stevenjoezhang marked this pull request as ready for review August 12, 2026 18:45
Aetf added a commit to Aetf/Aetf.github.io that referenced this pull request Aug 21, 2026
Set "type": "module" and move the real logic of all four hexo scripts
to ESM modules under lib/, taking the hexo instance as an explicit
parameter instead of the vm-injected global.

Hexo still runs files under scripts/ as CJS text in a vm sandbox where
ESM syntax and dynamic import() are unavailable (hexojs/hexo#5525), so
each script is now a one-line CJS stub going through lib/esm-bridge.cjs,
which lives outside the vm and can import() the real module. The stubs
and the bridge can be deleted once hexo loads ESM scripts natively
(hexojs/hexo#5820).

Rendered output is unchanged (verified: data-zoom-src rewriting,
post_link anchors, xkcd_infos payload, open-sidebar links all present
in the generated site; no script load errors).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Aetf added a commit to Aetf/hexo-next-publist that referenced this pull request Aug 21, 2026
Switch the package to type: module. Hexo cannot load an ESM plugin entry
yet (it wraps the entry file text in an async vm function, see
hexojs/hexo#5820), so main now points at a two-level CJS shim:
index.cjs runs inside the vm and defers to bridge.cjs via the real
require; bridge.cjs then dynamic-imports the ESM src/index.js. Both
shims can be dropped once hexo supports ESM entries natively.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support to load ES module plugin

1 participant