Skip to content

Commit

Permalink
Stop using deprecated process.umask() (#28)
Browse files Browse the repository at this point in the history
Fixes #27
  • Loading branch information
coreyfarrell committed Apr 22, 2020
1 parent 960ecf1 commit b5a98ef
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -6,7 +6,7 @@ declare namespace makeDir {
/**
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
@default 0o777 & (~process.umask())
@default 0o777
*/
readonly mode?: number;

Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -23,7 +23,7 @@ const checkPath = pth => {
const processOptions = options => {
// https://github.com/sindresorhus/make-dir/issues/18
const defaults = {
mode: 0o777 & (~process.umask()),
mode: 0o777,
fs
};

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -90,7 +90,7 @@ Type: `object`
##### mode

Type: `integer`\
Default: `0o777 & (~process.umask())`
Default: `0o777`

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

Expand Down
14 changes: 13 additions & 1 deletion test/helpers/util.js
Expand Up @@ -5,7 +5,19 @@ import pathType from 'path-type';

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

export const assertDirectory = (t, directory, mode = 0o777 & (~process.umask())) => {
let lastMask = 0;

function umask() {
// Avoid deprecation warning in v14+
lastMask = process.umask(lastMask);
process.umask(lastMask);
return lastMask;
}

// Get the initial value before any async operations start
umask();

export const assertDirectory = (t, directory, mode = 0o777 & (~umask())) => {
// Setting `mode` on `fs.mkdir` on Windows doesn't seem to work
if (process.platform === 'win32') {
mode = 0o666;
Expand Down
7 changes: 4 additions & 3 deletions test/umask.js
Expand Up @@ -2,18 +2,19 @@ import test from 'ava';
import {getFixture, assertDirectory} from './helpers/util';
import makeDir from '..';

const mask = 0;
test.before(() => {
process.umask(0);
process.umask(mask);
});

test('async', async t => {
const dir = getFixture();
await makeDir(dir);
assertDirectory(t, dir, 0o777 & (~process.umask()));
assertDirectory(t, dir, 0o777 & (~mask));
});

test('sync', t => {
const dir = getFixture();
makeDir.sync(dir);
assertDirectory(t, dir, 0o777 & (~process.umask()));
assertDirectory(t, dir, 0o777 & (~mask));
});

0 comments on commit b5a98ef

Please sign in to comment.