Skip to content

Commit

Permalink
Merge pull request #380 from streamich/fix/374
Browse files Browse the repository at this point in the history
fix: 🐛 mocks process.emitWarning for browser compatibility
  • Loading branch information
streamich committed Jun 1, 2019
2 parents 21bf3ef + e3456b2 commit ca3ce8a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -39,7 +39,7 @@
"husky": "1.3.1",
"jest": "24.8.0",
"prettier": "1.17.1",
"pretty-quick": "1.10.0",
"pretty-quick": "1.11.0",
"rimraf": "2.6.3",
"semantic-release": "15.13.12",
"ts-jest": "24.0.2",
Expand Down
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
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -5356,10 +5356,10 @@ pretty-format@^24.8.0:
ansi-styles "^3.2.0"
react-is "^16.8.4"

pretty-quick@1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/pretty-quick/-/pretty-quick-1.10.0.tgz#d86cc46fe92ed8cfcfba6a082ec5949c53858198"
integrity sha512-uNvm2N3UWmnZRZrClyQI45hIbV20f5BpSyZY51Spbvn4APp9+XLyX4bCjWRGT3fGyVyQ/2/iw7dbQq1UUaq7SQ==
pretty-quick@1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/pretty-quick/-/pretty-quick-1.11.0.tgz#d0bf997f3eb7de3d1bac5ffeb9c335f404d844c8"
integrity sha512-hy0yOSnqVykrgoHcCcB72p3B5ERQJcjQI6ExeSGSTFE2cDrPwCQtFb3kXA1F+jUPrbt7orra8U+fjS/Emjgpuw==
dependencies:
chalk "^2.3.0"
execa "^0.8.0"
Expand Down

0 comments on commit ca3ce8a

Please sign in to comment.