From 2d7d7cbe5c2a9c599df298efb4215cf48361c77d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 26 Jul 2024 12:24:15 +0200 Subject: [PATCH] Require Node.js 18 Closes #11 --- .github/workflows/main.yml | 9 +++++---- index.js | 15 ++++++++------- index.test-d.ts | 2 +- package.json | 16 ++++++++++------ readme.md | 16 ++-------------- test/eacces.js | 12 ++++++------ test/nominal.js | 10 +++++++++- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7a5af0c..217493a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/index.js b/index.js index b43688d..772598b 100644 --- a/index.js +++ b/index.js @@ -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') { @@ -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'); diff --git a/index.test-d.ts b/index.test-d.ts index e433f44..d3cc196 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -5,7 +5,7 @@ import { isSymlink, isFileSync, isDirectorySync, - isSymlinkSync + isSymlinkSync, } from './index.js'; expectType>(isFile('package.json')); diff --git a/package.json b/package.json index 15b59fd..0b52643 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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" } } diff --git a/readme.md b/readme.md index 85c5129..d4c0f4d 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,8 @@ ## Install -``` -$ npm install path-type +```sh +npm install path-type ``` ## Usage @@ -60,15 +60,3 @@ Returns a `boolean`. Synchronously check whether the passed `path` is a symlink. Returns a `boolean`. - ---- - -
- - Get professional support for this package with a Tidelift subscription - -
- - Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. -
-
diff --git a/test/eacces.js b/test/eacces.js index fd2520f..eeca442 100644 --- a/test/eacces.js +++ b/test/eacces.js @@ -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'; @@ -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 => { diff --git a/test/nominal.js b/test/nominal.js index def0e73..d4f1442 100644 --- a/test/nominal.js +++ b/test/nominal.js @@ -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'));