-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Generalize existing Node.js development-time version check #25414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juj
merged 11 commits into
emscripten-core:main
from
juj:verify_min_runtime_environments
Sep 29, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
408aa55
Generalize existing Node.js development-time version check into commo…
juj 1864034
Fix check for Firefox 65
juj d832a06
Fix check
juj 65e7b91
Add eslint ignore
juj 33ad9b8
Move previous unsupported shell check to minimum_runtime_check.js
juj d45dd7c
Review, and fix -sENVIRONMENT=worker directive.
juj fe8283a
code size
juj 4b0b770
Optimize code size
juj 4d0c988
Merge remote-tracking branch 'origin/main' into verify_min_runtime_en…
juj 1813863
Code size
juj 9f0f75a
Fix semicolon that prevented IIFE from executing.
juj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 The Emscripten Authors | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#if ASSERTIONS | ||
|
||
(function() { | ||
// "30.0.0" -> 300000 | ||
function humanReadableVersionToPacked(str) { | ||
str = str.split('-')[0]; // Remove any trailing part from e.g. "12.53.3-alpha" | ||
var vers = str.split('.').slice(0, 3); | ||
while(vers.length < 3) vers.push('00'); | ||
vers = vers.map((n, i, arr) => n.padStart(2, '0')); | ||
return vers.join(''); | ||
} | ||
// 300000 -> "30.0.0" | ||
var packedVersionToHumanReadable = n => [n / 10000 | 0, (n / 100 | 0) % 100, n % 100].join('.'); | ||
|
||
var TARGET_NOT_SUPPORTED = {{{ TARGET_NOT_SUPPORTED }}}; | ||
|
||
var currentNodeVersion = typeof process !== 'undefined' && process?.versions?.node ? humanReadableVersionToPacked(process.versions.node) : TARGET_NOT_SUPPORTED; | ||
#if MIN_NODE_VERSION == TARGET_NOT_SUPPORTED | ||
if (currentNodeVersion < TARGET_NOT_SUPPORTED) { | ||
throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)'); | ||
} | ||
#endif | ||
if (currentNodeVersion < {{{ MIN_NODE_VERSION }}}) { | ||
throw new Error(`This emscripten-generated code requires node v${ packedVersionToHumanReadable({{{ MIN_NODE_VERSION }}}) } (detected v${packedVersionToHumanReadable(currentNodeVersion)})`); | ||
} | ||
|
||
var currentSafariVersion = typeof navigator !== 'undefined' && navigator?.userAgent?.includes("Safari/") && navigator.userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/) ? humanReadableVersionToPacked(navigator.userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/)[1]) : TARGET_NOT_SUPPORTED; | ||
#if MIN_SAFARI_VERSION == TARGET_NOT_SUPPORTED | ||
if (currentSafariVersion < TARGET_NOT_SUPPORTED) { | ||
throw new Error(`This page was compiled without support for Safari browser. Pass -sMIN_SAFARI_VERSION=${currentSafariVersion} or lower to enable support for this browser.`); | ||
} | ||
#endif | ||
if (currentSafariVersion < {{{ MIN_SAFARI_VERSION }}}) { | ||
throw new Error(`This emscripten-generated code requires Safari v${ packedVersionToHumanReadable({{{ MIN_SAFARI_VERSION }}}) } (detected v${currentSafariVersion})`); | ||
} | ||
|
||
var currentFirefoxVersion = typeof navigator !== 'undefined' && navigator?.userAgent?.match(/Firefox\/(\d+(?:\.\d+)?)/) ? parseFloat(navigator.userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED; | ||
#if MIN_FIREFOX_VERSION == TARGET_NOT_SUPPORTED | ||
if (currentFirefoxVersion < TARGET_NOT_SUPPORTED) { | ||
throw new Error(`This page was compiled without support for Firefox browser. Pass -sMIN_FIREFOX_VERSION=${currentFirefoxVersion} or lower to enable support for this browser.`); | ||
} | ||
#endif | ||
if (currentFirefoxVersion < {{{ MIN_FIREFOX_VERSION }}}) { | ||
throw new Error(`This emscripten-generated code requires Firefox v{{{ MIN_FIREFOX_VERSION }}} (detected v${currentFirefoxVersion})`); | ||
} | ||
|
||
var currentChromeVersion = typeof navigator !== 'undefined' && navigator?.userAgent?.match(/Chrome\/(\d+(?:\.\d+)?)/) ? parseFloat(navigator.userAgent.match(/Chrome\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED; | ||
#if MIN_CHROME_VERSION == TARGET_NOT_SUPPORTED | ||
if (currentChromeVersion < TARGET_NOT_SUPPORTED) { | ||
throw new Error(`This page was compiled without support for Chrome browser. Pass -sMIN_CHROME_VERSION=${currentChromeVersion} or lower to enable support for this browser.`); | ||
} | ||
#endif | ||
if (currentChromeVersion < {{{ MIN_CHROME_VERSION }}}) { | ||
throw new Error(`This emscripten-generated code requires Chrome v{{{ MIN_CHROME_VERSION }}} (detected v${currentChromeVersion})`); | ||
} | ||
})(); | ||
|
||
#endif |
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
{ | ||
"hello_world.js": 54133, | ||
"hello_world.js.gz": 17091, | ||
"hello_world.js": 55560, | ||
"hello_world.js.gz": 17522, | ||
"hello_world.wasm": 15127, | ||
"hello_world.wasm.gz": 7450, | ||
"no_asserts.js": 26513, | ||
"no_asserts.js.gz": 8864, | ||
"no_asserts.js": 26591, | ||
"no_asserts.js.gz": 8875, | ||
"no_asserts.wasm": 12227, | ||
"no_asserts.wasm.gz": 6010, | ||
"strict.js": 52171, | ||
"strict.js.gz": 16426, | ||
"strict.js": 53598, | ||
"strict.js.gz": 16856, | ||
"strict.wasm": 15127, | ||
"strict.wasm.gz": 7447, | ||
"total": 175298, | ||
"total_gz": 63288 | ||
"total": 178230, | ||
"total_gz": 64160 | ||
} |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just add this to
runtime_common.js
which is already included in both runtime modes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I made a separate file is that this code would be run as the very first thing in the generated .js.
If we put the code somewhere in the middle, we risk already attempting to execute some code that might require a new feature (e.g. ES6 Modules or some language syntax keyword, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes that makes sense.