From 9fc5b6510cd60f5aafe4c7270a8103c8e7b6f0a9 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sat, 7 Nov 2020 11:27:07 -0800 Subject: [PATCH] fix(std/node): only define Node.js globals when loading std/node/global (#8281) --- std/node/buffer.ts | 7 ------- std/node/global.ts | 25 +++++++++++++++++++++++++ std/node/process.ts | 14 -------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/std/node/buffer.ts b/std/node/buffer.ts index 6d307b6df5..16cf3abc0a 100644 --- a/std/node/buffer.ts +++ b/std/node/buffer.ts @@ -599,10 +599,3 @@ export default class Buffer extends Uint8Array { } export { Buffer }; - -Object.defineProperty(globalThis, "Buffer", { - value: Buffer, - enumerable: false, - writable: true, - configurable: true, -}); diff --git a/std/node/global.ts b/std/node/global.ts index 3037cf23ee..b102edddc4 100644 --- a/std/node/global.ts +++ b/std/node/global.ts @@ -1,4 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import process from "./process.ts"; +import { Buffer as buffer } from "./buffer.ts"; Object.defineProperty(globalThis, Symbol.toStringTag, { value: "global", @@ -10,4 +12,27 @@ Object.defineProperty(globalThis, Symbol.toStringTag, { // deno-lint-ignore no-explicit-any (globalThis as any)["global"] = globalThis; +// Define the type for the global declration +type Process = typeof process; +type Buffer = typeof buffer; + +Object.defineProperty(globalThis, "process", { + value: process, + enumerable: false, + writable: true, + configurable: true, +}); + +declare global { + const process: Process; + const Buffer: Buffer; +} + +Object.defineProperty(globalThis, "Buffer", { + value: buffer, + enumerable: false, + writable: true, + configurable: true, +}); + export {}; diff --git a/std/node/process.ts b/std/node/process.ts index 0a93a09287..a47140f150 100644 --- a/std/node/process.ts +++ b/std/node/process.ts @@ -142,23 +142,9 @@ export const env = new Proxy(process.env, {}); // import process from './std/node/process.ts' export default process; -// Define the type for the global declration -type Process = typeof process; - Object.defineProperty(process, Symbol.toStringTag, { enumerable: false, writable: true, configurable: false, value: "process", }); - -Object.defineProperty(globalThis, "process", { - value: process, - enumerable: false, - writable: true, - configurable: true, -}); - -declare global { - const process: Process; -}