From e3456b289da1f0f5a847c724a602dbcec57b5adc Mon Sep 17 00:00:00 2001 From: pizzafroide Date: Tue, 21 May 2019 16:36:03 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20mocks=20process.emitWarni?= =?UTF-8?q?ng=20for=20browser=20compatibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #374 --- src/process.ts | 6 ++++++ src/volume.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/process.ts b/src/process.ts index 5656227f..b43e74ff 100644 --- a/src/process.ts +++ b/src/process.ts @@ -6,6 +6,7 @@ export interface IProcess { cwd(): string; platform: string; nextTick: (callback: (...args) => void, ...args) => void; + emitWarning: (message: string, type: string) => void; env: { MEMFS_DONT_WARN?: boolean; }; @@ -23,6 +24,11 @@ export function createProcess(p: IProcess = process): IProcess { if (!p.getgid) p.getgid = () => 0; if (!p.cwd) p.cwd = () => '/'; if (!p.nextTick) p.nextTick = require('./setImmediate').default; + if (!p.emitWarning) + p.emitWarning = (message, type) => { + // tslint:disable-next-line:no-console + console.warn(`${type}${type ? ': ' : ''}${message}`); + }; if (!p.env) p.env = {}; return p; } diff --git a/src/volume.ts b/src/volume.ts index 3c377c5f..0f41091f 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -582,7 +582,7 @@ export class Volume { get promises() { if (promisesWarn) { promisesWarn = false; - require('process').emitWarning('The fs.promises API is experimental', 'ExperimentalWarning'); + process.emitWarning('The fs.promises API is experimental', 'ExperimentalWarning'); } if (this.promisesApi === null) throw new Error('Promise is not supported in this environment.'); return this.promisesApi;