From fc83c29b09710376a9f9260a6c0d77982acc29ed Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 8 May 2018 12:02:27 -0400 Subject: [PATCH] Define Buffer globally if buffer built-in module installed. --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 209db5ae63..bc65e30aa0 100644 --- a/index.js +++ b/index.js @@ -24,3 +24,18 @@ if (typeof meteorInstall === "function") { } }); } + +// If Buffer is not defined globally, but the "buffer" built-in stub is +// installed and can be imported, use it to define global.Buffer so that +// modules like core-util-is/lib/util.js can refer to Buffer without +// crashing application startup. +if (typeof global.Buffer !== "function") { + try { + // Use (0, require)(...) to avoid registering a dependency on the + // "buffer" stub, in case it is not otherwise bundled. + global.Buffer = (0, require)("buffer"); + } catch (ok) { + // Failure to import "buffer" is fine as long as the Buffer global + // variable is not used. + } +}