Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
Closes #11
  • Loading branch information
sindresorhus committed Jul 26, 2024
1 parent 8085369 commit 2d7d7cb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 22
- 20
- 18
os:
- macos-latest
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs, {promises as fsPromises} from 'fs';
import fs from 'node:fs';
import fsPromises from 'node:fs/promises';

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

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');
export const isFile = isType.bind(undefined, 'stat', 'isFile');
export const isDirectory = isType.bind(undefined, 'stat', 'isDirectory');
export const isSymlink = isType.bind(undefined, 'lstat', 'isSymbolicLink');
export const isFileSync = isTypeSync.bind(undefined, 'statSync', 'isFile');
export const isDirectorySync = isTypeSync.bind(undefined, 'statSync', 'isDirectory');
export const isSymlinkSync = isTypeSync.bind(undefined, 'lstatSync', 'isSymbolicLink');
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
isSymlink,
isFileSync,
isDirectorySync,
isSymlinkSync
isSymlinkSync,
} from './index.js';

expectType<Promise<boolean>>(isFile('package.json'));
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=12"
"node": ">=18"
},
"scripts": {
"test": "xo && nyc ava && tsd"
Expand All @@ -39,9 +43,9 @@
"filesystem"
],
"devDependencies": {
"ava": "^3.15.0",
"nyc": "^15.1.0",
"tsd": "^0.14.0",
"xo": "^0.37.1"
"ava": "^6.1.3",
"nyc": "^17.0.0",
"tsd": "^0.31.1",
"xo": "^0.59.2"
}
}
16 changes: 2 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
## Install

```
$ npm install path-type
```sh
npm install path-type
```

## Usage
Expand Down Expand Up @@ -60,15 +60,3 @@ Returns a `boolean`.
Synchronously check whether the passed `path` is a symlink.

Returns a `boolean`.

---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-path-type?utm_source=npm-path-type&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
12 changes: 6 additions & 6 deletions test/eacces.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs, {promises as fsPromises} from 'fs';
import fs, {promises as fsPromises} from 'node:fs';
import test from 'ava';
import {isFile, isFileSync} from '../index.js';

Expand All @@ -12,21 +12,21 @@ Object.defineProperties(fsPromises, {
stat: {
value(filePath, callback) {
callback(fakeError(filePath));
}
}
},
},
});

Object.defineProperties(fs, {
stat: {
value(filePath, callback) {
callback(fakeError(filePath));
}
},
},
statSync: {
value(filePath) {
throw fakeError(filePath);
}
}
},
},
});

test('throws on EACCES error - async', async t => {
Expand Down
10 changes: 9 additions & 1 deletion test/nominal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import process from 'node:process';
import test from 'ava';
import {isDirectory, isDirectorySync, isFile, isFileSync, isSymlink, isSymlinkSync} from '../index.js';
import {
isDirectory,
isDirectorySync,
isFile,
isFileSync,
isSymlink,
isSymlinkSync,
} from '../index.js';

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

0 comments on commit 2d7d7cb

Please sign in to comment.