Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel authored Jan 27, 2021
1 parent a7b4b93 commit 24e52d3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
os:
- macos-latest
- ubuntu-latest
Expand Down
17 changes: 8 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const {promisify} = require('util');
const fs = require('fs');
import {promisify} from 'util';
import fs from 'fs';

async function isType(fsStatType, statsMethodName, filePath) {
if (typeof filePath !== 'string') {
Expand Down Expand Up @@ -35,9 +34,9 @@ function isTypeSync(fsStatType, statsMethodName, filePath) {
}
}

exports.isFile = isType.bind(null, 'stat', 'isFile');
exports.isDirectory = isType.bind(null, 'stat', 'isDirectory');
exports.isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink');
exports.isFileSync = isTypeSync.bind(null, 'statSync', 'isFile');
exports.isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory');
exports.isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink');
export const isFile = isType.bind(null, 'stat', 'isFile');
export const isDirectory = isType.bind(null, 'stat', 'isDirectory');
export const isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink');
export const isFileSync = isTypeSync.bind(null, 'statSync', 'isFile');
export const isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory');
export const isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink');
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {expectType} from 'tsd-check';
import {expectType} from 'tsd';
import {
isFile,
isDirectory,
isSymlink,
isFileSync,
isDirectorySync,
isSymlinkSync
} from '.';
} from './index.js';

expectType<Promise<boolean>>(isFile('package.json'));
expectType<Promise<boolean>>(isDirectory('package.json'));
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
"email": "[email protected]",
"url": "sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && nyc ava && tsd-check"
"test": "xo && nyc ava && tsd"
},
"files": [
"index.js",
Expand All @@ -37,9 +39,9 @@
"filesystem"
],
"devDependencies": {
"ava": "^1.3.1",
"ava": "^3.15.0",
"nyc": "^13.3.0",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
"tsd": "^0.14.0",
"xo": "^0.37.1"
}
}
6 changes: 3 additions & 3 deletions test/eacces.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import test from 'ava';
import pathType from '..';
import {isFile, isFileSync} from '../index.js';

function fakeError(fp) {
const error = new Error(`EACCES: permission denied, stat '${fp}'`);
Expand All @@ -22,9 +22,9 @@ Object.defineProperties(fs, {
});

test('throws on EACCES error - async', async t => {
await t.throwsAsync(pathType.isFile('/root/private'));
await t.throwsAsync(isFile('/root/private'));
});

test('throws on EACCES error - sync', t => {
t.throws(() => pathType.isFileSync('/root/private'));
t.throws(() => isFileSync('/root/private'));
});
28 changes: 14 additions & 14 deletions test/nominal.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import test from 'ava';
import pathType from '..';
import {isDirectory, isDirectorySync, isFile, isFileSync, isSymlink, isSymlinkSync} from '../index.js';

test('.file()', async t => {
t.true(await pathType.isFile('package.json'));
await t.throwsAsync(pathType.isFile(false));
t.true(await isFile('package.json'));
await t.throwsAsync(isFile(false));
});

test('.dir()', async t => {
t.true(await pathType.isDirectory('.'));
await t.throwsAsync(pathType.isDirectory(false));
t.true(await isDirectory('.'));
await t.throwsAsync(isDirectory(false));
});

if (process.platform !== 'win32') {
test('.symlink()', async t => {
t.true(await pathType.isSymlink('symlink'));
await t.throwsAsync(pathType.isSymlink(false));
t.true(await isSymlink('symlink'));
await t.throwsAsync(isSymlink(false));
});
}

test('.fileSync()', t => {
t.true(pathType.isFileSync('package.json'));
t.true(isFileSync('package.json'));
});

test('.dirSync()', t => {
t.true(pathType.isDirectorySync('.'));
t.true(isDirectorySync('.'));
});

if (process.platform !== 'win32') {
test('.symlinkSync()', t => {
t.true(pathType.isSymlinkSync('symlink'));
t.true(isSymlinkSync('symlink'));
});
}

test('return false if path doesn\'t exist - async', async t => {
t.false(await pathType.isFile('unicorn'));
t.false(await isFile('unicorn'));
});

test('return false if path doesn\'t exist - sync', t => {
t.false(pathType.isFileSync('unicorn'));
t.false(isFileSync('unicorn'));
});

test('throws invalid argument - async', async t => {
await t.throwsAsync(pathType.isFile(false));
await t.throwsAsync(isFile(false));
});

test('throws on invalid argument - sync', t => {
t.throws(() => pathType.isFileSync(false));
t.throws(() => isFileSync(false));
});

0 comments on commit 24e52d3

Please sign in to comment.