Skip to content

Commit b5a98ef

Browse files
authored
Stop using deprecated process.umask() (#28)
Fixes #27
1 parent 960ecf1 commit b5a98ef

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare namespace makeDir {
66
/**
77
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
88
9-
@default 0o777 & (~process.umask())
9+
@default 0o777
1010
*/
1111
readonly mode?: number;
1212

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const checkPath = pth => {
2323
const processOptions = options => {
2424
// https://github.com/sindresorhus/make-dir/issues/18
2525
const defaults = {
26-
mode: 0o777 & (~process.umask()),
26+
mode: 0o777,
2727
fs
2828
};
2929

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Type: `object`
9090
##### mode
9191

9292
Type: `integer`\
93-
Default: `0o777 & (~process.umask())`
93+
Default: `0o777`
9494

9595
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
9696

test/helpers/util.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ import pathType from 'path-type';
55

66
export const getFixture = () => path.join(tempy.directory(), 'a/b/c/unicorn_unicorn_unicorn/d/e/f/g/h');
77

8-
export const assertDirectory = (t, directory, mode = 0o777 & (~process.umask())) => {
8+
let lastMask = 0;
9+
10+
function umask() {
11+
// Avoid deprecation warning in v14+
12+
lastMask = process.umask(lastMask);
13+
process.umask(lastMask);
14+
return lastMask;
15+
}
16+
17+
// Get the initial value before any async operations start
18+
umask();
19+
20+
export const assertDirectory = (t, directory, mode = 0o777 & (~umask())) => {
921
// Setting `mode` on `fs.mkdir` on Windows doesn't seem to work
1022
if (process.platform === 'win32') {
1123
mode = 0o666;

test/umask.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import test from 'ava';
22
import {getFixture, assertDirectory} from './helpers/util';
33
import makeDir from '..';
44

5+
const mask = 0;
56
test.before(() => {
6-
process.umask(0);
7+
process.umask(mask);
78
});
89

910
test('async', async t => {
1011
const dir = getFixture();
1112
await makeDir(dir);
12-
assertDirectory(t, dir, 0o777 & (~process.umask()));
13+
assertDirectory(t, dir, 0o777 & (~mask));
1314
});
1415

1516
test('sync', t => {
1617
const dir = getFixture();
1718
makeDir.sync(dir);
18-
assertDirectory(t, dir, 0o777 & (~process.umask()));
19+
assertDirectory(t, dir, 0o777 & (~mask));
1920
});

0 commit comments

Comments
 (0)