Repository navigation
chore: drop core-js, melonJS now has no runtime dependencies - #1618
Merged
Merged
Conversation
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
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.
core-jsprovided exactly three language polyfills: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
globalThiswas there, and why it no longer needs to beIt was added for Node — #1092,
where importing melonjs threw because it touched
window. But Node has hadglobalThisnatively since version 12 (2019), andengines.noderequires24. What actually fixed that issue was the engine using
globalThisinplace 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,
globalThisnative.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"patchesString.prototypefor the wholeapplication. 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
targetsetting rewrites syntax and never addsbuilt-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 inv8 for the same reason.
What stays
The Canvas and DOM shims:
ellipse(),roundRect()and theconsoleguard.Those are engine capability rather than language level, they are
feature-detected, and the consumer has no way to know they are needed —
roundRectin particular is recent enough to be plausibly above our browserfloor.
Also in this PR
The vendored audio backend used
windowdirectly, unlike the rest of theengine. Several of those were unguarded —
window.AudioContextraises aReferenceErrorwherewindowdoes not exist, rather than evaluating toundefined— so the backend would have thrown in Node the moment audio wastouched. Now converted to
globalThisthroughout.Plus one leftover: the README still said "Built with ES6 classes", the last of
the ES6 claims corrected in #1617.
Result
melonjsnow declares no runtime dependencies at all.