Skip to content

Commit 1c19e87

Browse files
authored
fix: dont patch getuid and getgid on process anymore (#847)
1 parent 1a1e18e commit 1c19e87

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/__tests__/process.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe('process', () => {
77
expect(typeof _process).toBe('object');
88
});
99
it('.getuid() and .getgid()', () => {
10-
expect(typeof proc.getuid()).toBe('number');
11-
expect(typeof proc.getgid()).toBe('number');
10+
expect(typeof proc.getuid?.() ?? 0).toBe('number');
11+
expect(typeof proc.getgid?.() ?? 0).toBe('number');
1212
});
1313
it('.cwd()', () => {
1414
expect(typeof proc.cwd()).toBe('string');

src/node.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { EventEmitter } from 'events';
66
import Stats from './Stats';
77

88
const { S_IFMT, S_IFDIR, S_IFREG, S_IFLNK, O_APPEND } = constants;
9+
const getuid = (): number => process.getuid?.() ?? 0;
10+
const getgid = (): number => process.getgid?.() ?? 0;
911

1012
export const SEP = '/';
1113

@@ -17,8 +19,8 @@ export class Node extends EventEmitter {
1719
ino: number;
1820

1921
// User ID and group ID.
20-
uid: number = process.getuid();
21-
gid: number = process.getgid();
22+
uid: number = getuid();
23+
gid: number = getgid();
2224

2325
atime = new Date();
2426
mtime = new Date();
@@ -167,7 +169,7 @@ export class Node extends EventEmitter {
167169
this.emit('change', this);
168170
}
169171

170-
canRead(uid: number = process.getuid(), gid: number = process.getgid()): boolean {
172+
canRead(uid: number = getuid(), gid: number = getgid()): boolean {
171173
if (this.perm & S.IROTH) {
172174
return true;
173175
}
@@ -187,7 +189,7 @@ export class Node extends EventEmitter {
187189
return false;
188190
}
189191

190-
canWrite(uid: number = process.getuid(), gid: number = process.getgid()): boolean {
192+
canWrite(uid: number = getuid(), gid: number = getgid()): boolean {
191193
if (this.perm & S.IWOTH) {
192194
return true;
193195
}

src/process.ts

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

33
export interface IProcess {
4-
getuid(): number;
4+
getuid?(): number;
55

6-
getgid(): number;
6+
getgid?(): number;
77

88
cwd(): string;
99

@@ -38,8 +38,6 @@ const maybeReturnProcess = (): IProcess | undefined => {
3838
export function createProcess(): IProcess {
3939
const p: IProcess = maybeReturnProcess() || ({} as IProcess);
4040

41-
if (!p.getuid) p.getuid = () => 0;
42-
if (!p.getgid) p.getgid = () => 0;
4341
if (!p.cwd) p.cwd = () => '/';
4442
if (!p.nextTick) p.nextTick = require('./setImmediate').default;
4543
if (!p.emitWarning)

0 commit comments

Comments
 (0)