From 53ebd3311d4e0ef184a062b2f657ac69dc8a7acf Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sun, 24 Mar 2019 01:00:07 +0200 Subject: process: global.process, global.Buffer getters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/26882 Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Ruben Bridgewater --- lib/internal/bootstrap/pre_execution.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/internal/bootstrap/pre_execution.js') diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index c38822bd89..233ab4f879 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -1,6 +1,7 @@ 'use strict'; const { getOptionValue } = require('internal/options'); +const { Buffer } = require('buffer'); function prepareMainThreadExecution() { // Patch the process object with legacy properties and normalizations @@ -221,6 +222,33 @@ function initializeDeprecations() { 'process.binding() is deprecated. ' + 'Please use public APIs instead.', 'DEP0111'); } + + // Create global.process and global.Buffer as getters so that we have a + // deprecation path for these in ES Modules. + // See https://github.com/nodejs/node/pull/26334. + let _process = process; + Object.defineProperty(global, 'process', { + get() { + return _process; + }, + set(value) { + _process = value; + }, + enumerable: false, + configurable: true + }); + + let _Buffer = Buffer; + Object.defineProperty(global, 'Buffer', { + get() { + return _Buffer; + }, + set(value) { + _Buffer = value; + }, + enumerable: false, + configurable: true + }); } function setupChildProcessIpcChannel() { -- cgit v1.2.3