Skip to content

Change: convert site scripts and tests to ESM - #61

Merged
Aetf merged 2 commits into
developfrom
chore/esm-conversion
Aug 21, 2026
Merged

Change: convert site scripts and tests to ESM#61
Aetf merged 2 commits into
developfrom
chore/esm-conversion

Conversation

@Aetf

@Aetf Aetf commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Converts the site's own JS to ESM ("type": "module"), part of the modernization tracked in Aetf/meta#46.

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_xkcd tag 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

Aetf and others added 2 commits August 21, 2026 13:29
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>
@Aetf
Aetf merged commit a8427f6 into develop Aug 21, 2026
1 check passed
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.

1 participant