From bcf7cb39d7ad085930154017d0fdc96e1162d047 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 27 Nov 2023 15:41:29 +0100 Subject: [PATCH 1/2] 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 --- lib/internal/main/mksnapshot.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/internal/main/mksnapshot.js b/lib/internal/main/mksnapshot.js index 34701716839326..139d38dea18b5d 100644 --- a/lib/internal/main/mksnapshot.js +++ b/lib/internal/main/mksnapshot.js @@ -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,15 @@ 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`); + 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); } } From 3650426ad8f8979f18aba145757a5c418fbd5972 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sun, 3 Dec 2023 17:31:44 +0100 Subject: [PATCH 2/2] fixup! bootstrap: improve snapshot unsupported builtin warnings --- lib/internal/main/mksnapshot.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/main/mksnapshot.js b/lib/internal/main/mksnapshot.js index 139d38dea18b5d..f00bf886153e6e 100644 --- a/lib/internal/main/mksnapshot.js +++ b/lib/internal/main/mksnapshot.js @@ -122,6 +122,9 @@ function requireForUserSnapshot(id) { } if (isBuildingSnapshot() && !supportedInUserSnapshot(normalizedId)) { if (!warnedModules.has(normalizedId)) { + // 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' +