Change: convert site scripts and tests to ESM - #61
Merged
Conversation
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>
Import syntax throughout; tests/helpers uses fileURLToPath(import.meta.url) in place of __dirname and keeps loading hexo lazily via dynamic import so tests not using it don't pay for it. Directory import './helpers' becomes the explicit './helpers/index.js' as ESM requires. All 43 tests pass with no snapshot changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Converts the site's own JS to ESM (
"type": "module"), part of the modernization tracked in Aetf/meta#46.lib/(default exportregister(hexo));scripts/keeps one-line CJS stubs going throughlib/esm-bridge.cjs, since hexo runs script files as CJS text in a vm sandbox (Support to load ES module plugin hexojs/hexo#5525). Stubs + bridge can be deleted once feat: support ES module plugins hexojs/hexo#5820 lands.import.meta.urlinstead of__dirnameand keep loading hexo lazily.Verification: 43/43 tests pass with zero snapshot changes. Generated
public/compared against a develop-tip build: byte-identical after normalizing build-time randomness (hexo-prism-plus random element ids,random_xkcdtag id, NexT random author-link bullet color, and hexo-generator-searchdb's unstable entry order — the latter confirmed unstable across two builds of the same commit).🤖 Generated with Claude Code