bootstrap: improve snapshot unsupported builtin warnings

- Only emit warning when the snapshot is built. In general built-ins
  loaded after the snapshot is built should work as usual.
- Clarify what the warning means

PR-URL: https://github.com/nodejs/node/pull/50944
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Joyee Cheung authored and Richard Lau committed 2024-03-25 17:28:26 +00:00
1 parent 358793e28e
commit 03b19cbd2a
1 file changed
+13 -4
+13 -4
View File
@@ -19,7 +19,7 @@ const {
const { isExperimentalSeaWarningNeeded } = internalBinding('sea');
const { emitExperimentalWarning } = require('internal/util');
const { emitWarningSync } = require('internal/process/warning');
const {
getOptionValue,
} = require('internal/options');
@@ -29,6 +29,7 @@ const {
namespace: {
addSerializeCallback,
addDeserializeCallback,
isBuildingSnapshot,
},
} = require('internal/v8/startup_snapshot');
@@ -119,10 +120,18 @@ function requireForUserSnapshot(id) {
err.code = 'MODULE_NOT_FOUND';
throw err;
}
if (!supportedInUserSnapshot(normalizedId)) {
if (isBuildingSnapshot() && !supportedInUserSnapshot(normalizedId)) {
if (!warnedModules.has(normalizedId)) {
process.emitWarning(
`built-in module ${id} is not yet supported in user snapshots`);
// Emit the warning synchronously in case we don't get to process
// the tick and print it before the unsupported built-in causes a
// crash.
emitWarningSync(
`It's not yet fully verified whether built-in module "${id}" ` +
'works in user snapshot builder scripts.\n' +
'It may still work in some cases, but in other cases certain ' +
'run-time states may be out-of-sync after snapshot deserialization.\n' +
'To request support for the module, use the Node.js issue tracker: ' +
'https://github.com/nodejs/node/issues');
warnedModules.add(normalizedId);
}
}