Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Node.js 12 and move to ESM #8

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 19 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,20 @@ 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');

const pathType = {
isFile,
isDirectory,
isSymlink,
isFileSync,
isDirectorySync,
isSymlinkSync
};

export default pathType;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no default export

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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation

},
"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"
}
}
2 changes: 1 addition & 1 deletion 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 pathType from '../index.js';

function fakeError(fp) {
const error = new Error(`EACCES: permission denied, stat '${fp}'`);
Expand Down
2 changes: 1 addition & 1 deletion test/nominal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import pathType from '..';
import pathType from '../index.js';

test('.file()', async t => {
t.true(await pathType.isFile('package.json'));
Expand Down