Skip to content

Commit e6b6d0a

Browse files
author
Richard Samuelsson
committed
feat(volume): add env variable to suppress fs.promise api warnings
To suppress experimental fs.promise api warnings the SUPRESS_EXPERIMENTAL_PROMISE_WARNINGS env variable can be set to a truthy value
1 parent d7d99bc commit e6b6d0a

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

docs/reference.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,11 @@ you get from `require('fs')`. Here are some things this function does:
139139
```
140140

141141
- Adds constants `fs.constants`, `fs.F_OK`, etc.
142+
143+
## Experimental fs.promise api warnings
144+
145+
Supress warnings when using the promise api of fs by setting
146+
147+
```js
148+
process.env['SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS'] = true;
149+
```

src/__tests__/process.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _process, { createProcess } from '../process';
1+
import _process, { createProcess, SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS } from '../process';
22

33
describe('process', () => {
44
describe('createProcess', () => {
@@ -17,5 +17,15 @@ describe('process', () => {
1717
expect(typeof proc.nextTick).toBe('function');
1818
proc.nextTick(done);
1919
});
20+
it('.env', () => {
21+
expect(typeof proc.env).toBe('object');
22+
expect(!!proc.env[SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS]).toBe(false);
23+
});
24+
});
25+
test('createProcess with env variable', () => {
26+
process.env[SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS] = 'true';
27+
const proc = createProcess();
28+
expect(!!proc.env[SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS]).toBe(true);
29+
delete process.env[SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS];
2030
});
2131
});

src/process.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// Here we mock the global `process` variable in case we are not in Node's environment.
22

3+
export type SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS = 'SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS';
4+
export const SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS: SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS =
5+
'SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS';
6+
37
export interface IProcess {
48
getuid(): number;
59
getgid(): number;
610
cwd(): string;
711
platform: string;
812
nextTick: (callback: (...args) => void, ...args) => void;
13+
env: {
14+
[SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS]?: boolean;
15+
};
916
}
1017

1118
export function createProcess(p: IProcess = process): IProcess {
@@ -20,6 +27,7 @@ export function createProcess(p: IProcess = process): IProcess {
2027
if (!p.getgid) p.getgid = () => 0;
2128
if (!p.cwd) p.cwd = () => '/';
2229
if (!p.nextTick) p.nextTick = require('./setImmediate').default;
30+
if (!p.env) p.env = {};
2331
return p;
2432
}
2533

src/volume.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Stats, { TStatNumber } from './Stats';
44
import Dirent from './Dirent';
55
import { Buffer } from 'buffer';
66
import setImmediate from './setImmediate';
7-
import process from './process';
7+
import process, { SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS } from './process';
88
import setTimeoutUnref, { TSetTimeout } from './setTimeoutUnref';
99
import { Readable, Writable } from 'stream';
1010
import { constants } from './constants';
@@ -516,7 +516,7 @@ function validateGid(gid: number) {
516516

517517
// ---------------------------------------- Volume
518518

519-
let promisesWarn = true;
519+
let promisesWarn = process[SUPPRESS_EXPERIMENTAL_PROMISE_WARNINGS] ? false : true;
520520

521521
/**
522522
* `Volume` represents a file system.

0 commit comments

Comments
 (0)