Skip to content

chore: drop core-js, melonJS now has no runtime dependencies - #1618

Merged
obiot merged 1 commit into
masterfrom
chore/drop-core-js
Aug 30, 2026
Merged

obiot merged 1 commit into
masterfrom
chore/drop-core-js

Conversation

@obiot

@obiot obiot commented Aug 30, 2026

Copy link
Copy Markdown
Member

core-js provided exactly three language polyfills:

import "core-js/proposals/global-this";
import "core-js/es/string/trim-start";
import "core-js/es/string/trim-end";

All three are ES2019/ES2020 features, and the published bundle targets
ES2022 — so every browser able to parse it already has them. They were
no-ops in every environment the engine supports.

Why globalThis was there, and why it no longer needs to be

It was added for Node — #1092,
where importing melonjs threw because it touched window. But Node has had
globalThis natively since version 12 (2019), and engines.node requires
24. What actually fixed that issue was the engine using globalThis in
place of window — 191 references — not core-js providing the identifier.

Verified by importing the built bundle under Node 24 with the dependency gone:
152 exports, no throw, globalThis native.

Why a library should not ship language polyfills

Beyond 15.6 kB in the bundle and 1.3 MB per install, import "core-js/es/string/trim-start" patches String.prototype for the whole
application
. The consumer picks the target; we don't. One that needs pre-2018
browsers needs a whole-app polyfill strategy, not a fragment shipped by a
dependency — and possibly conflicting with their own.

Transpiling and polyfilling are also separate concerns, which is easy to
conflate: a bundler's target setting rewrites syntax and never adds
built-in methods. A consumer following the README's Vite advice would not have
got our polyfill's benefit anyway.

This matches the field — three.js ships no dependencies, Phaser ships one
(eventemitter3), and Pixi deliberately removed its own bundled polyfills in
v8 for the same reason.

What stays

The Canvas and DOM shims: ellipse(), roundRect() and the console guard.
Those are engine capability rather than language level, they are
feature-detected, and the consumer has no way to know they are needed —
roundRect in particular is recent enough to be plausibly above our browser
floor.

Also in this PR

The vendored audio backend used window directly, unlike the rest of the
engine. Several of those were unguarded — window.AudioContext raises a
ReferenceError where window does not exist, rather than evaluating to
undefined — so the backend would have thrown in Node the moment audio was
touched. Now converted to globalThis throughout.

Plus one leftover: the README still said "Built with ES6 classes", the last of
the ES6 claims corrected in #1617.

Result

melonjs now declares no runtime dependencies at all.

core-js provided exactly three language polyfills: `globalThis`,
`String.trimStart` and `String.trimEnd`. All three are ES2019/ES2020 features,
and the published bundle targets ES2022 — so every browser able to parse it
already has them, and they were no-ops in every environment the engine
supports.

`globalThis` was the one with a live-looking rationale. It was added for Node
(#1092: importing melonjs threw because it touched `window`), but Node has had
`globalThis` natively since version 12 in 2019 and the engine requires 24. What
actually fixed that issue was the engine using `globalThis` in place of
`window`, not core-js providing the identifier.

Beyond the 15.6 kB in the bundle and 1.3 MB per install, `import
"core-js/es/string/trim-start"` patches `String.prototype` for the whole
application. That is not a library's call to make: the consumer picks the
target, and one that needs pre-2018 browsers needs a whole-app polyfill
strategy rather than a fragment shipped by a dependency. Transpiling and
polyfilling are also separate concerns — a bundler's `target` setting rewrites
syntax and never adds built-in methods, so our polyfill would not have helped
such a consumer anyway.

The Canvas and DOM shims stay. `ellipse()`, `roundRect()` and the `console`
guard are engine capability rather than language level, feature-detected, and
the consumer has no way to know they are needed.

Also converts the vendored audio backend from `window` to `globalThis`, which
the rest of the engine already used in 191 places. Several of those were
unguarded: `window.AudioContext` raises a ReferenceError where `window` does
not exist rather than evaluating to undefined, so the backend would have thrown
in Node the moment audio was touched. Verified by importing the built bundle
under Node 24.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Aa37KGXZcnVrbn1yG4j1N
Copilot AI lite review requested due to automatic review settings August 30, 2026 03:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@obiot
obiot merged commit e55796e into master Aug 30, 2026
6 checks passed
@obiot
obiot deleted the chore/drop-core-js branch August 30, 2026 06:20
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.

2 participants