Skip to content

Commit

Permalink
fix: 🐛 mocks process.emitWarning for browser compatibility
Browse files Browse the repository at this point in the history
closes #374
  • Loading branch information
pizzafroide committed May 21, 2019
1 parent c6a3a17 commit e3456b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/process.ts
Expand Up @@ -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;
};
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/volume.ts
Expand Up @@ -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;
Expand Down

0 comments on commit e3456b2

Please sign in to comment.