Skip to content

Commit e3456b2

Browse files
committed
fix: 🐛 mocks process.emitWarning for browser compatibility
closes #374
1 parent c6a3a17 commit e3456b2

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/process.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IProcess {
66
cwd(): string;
77
platform: string;
88
nextTick: (callback: (...args) => void, ...args) => void;
9+
emitWarning: (message: string, type: string) => void;
910
env: {
1011
MEMFS_DONT_WARN?: boolean;
1112
};
@@ -23,6 +24,11 @@ export function createProcess(p: IProcess = process): IProcess {
2324
if (!p.getgid) p.getgid = () => 0;
2425
if (!p.cwd) p.cwd = () => '/';
2526
if (!p.nextTick) p.nextTick = require('./setImmediate').default;
27+
if (!p.emitWarning)
28+
p.emitWarning = (message, type) => {
29+
// tslint:disable-next-line:no-console
30+
console.warn(`${type}${type ? ': ' : ''}${message}`);
31+
};
2632
if (!p.env) p.env = {};
2733
return p;
2834
}

src/volume.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ export class Volume {
582582
get promises() {
583583
if (promisesWarn) {
584584
promisesWarn = false;
585-
require('process').emitWarning('The fs.promises API is experimental', 'ExperimentalWarning');
585+
process.emitWarning('The fs.promises API is experimental', 'ExperimentalWarning');
586586
}
587587
if (this.promisesApi === null) throw new Error('Promise is not supported in this environment.');
588588
return this.promisesApi;

0 commit comments

Comments
 (0)