Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 12, 2021
1 parent 82516fa commit 3e66105
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
47 changes: 25 additions & 22 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
declare const pathExists: {
/**
Check if a path exists.
/**
Check if a path exists.
@returns Whether the path exists.
@returns Whether the path exists.
@example
```
// foo.ts
import pathExists = require('path-exists');
@example
```
// foo.ts
import {pathExists} from 'path-exists';
(async () => {
console.log(await pathExists('foo.ts'));
//=> true
})();
```
*/
(path: string): Promise<boolean>;
console.log(await pathExists('foo.ts'));
//=> true
```
*/
export function pathExists(path: string): Promise<boolean>;

/**
Synchronously check if a path exists.
/**
Synchronously check if a path exists.
@returns Whether the path exists.
*/
sync(path: string): boolean;
};
@returns Whether the path exists.
export = pathExists;
@example
```
// foo.ts
import {pathExistsSync} from 'path-exists';
console.log(pathExistsSync('foo.ts'));
//=> true
```
*/
export function pathExistsSync(path: string): boolean;
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
'use strict';
const fs = require('fs');
import fs, {promises as fsPromises} from 'node:fs';

module.exports = async path => {
export async function pathExists(path) {
try {
await fs.promises.access(path);
await fsPromises.access(path);
return true;
} catch {
return false;
}
};
}

module.exports.sync = path => {
export function pathExistsSync(path) {
try {
fs.accessSync(path);
return true;
} catch {
return false;
}
};
}
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import pathExists = require('.');
import {pathExists, pathExistsSync} from './index.js';

expectType<Promise<boolean>>(pathExists('foo.ts'));
expectType<boolean>(pathExists.sync('foo.ts'));
expectType<boolean>(pathExistsSync('foo.ts'));
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -32,8 +34,8 @@
"stat"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
}
}
10 changes: 4 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ $ npm install path-exists

```js
// foo.js
const pathExists = require('path-exists');
import {pathExists} from 'path-exists';

(async () => {
console.log(await pathExists('foo.js'));
//=> true
})();
console.log(await pathExists('foo.js'));
//=> true
```

## API
Expand All @@ -32,7 +30,7 @@ const pathExists = require('path-exists');

Returns a `Promise<boolean>` of whether the path exists.

### pathExists.sync(path)
### pathExistsSync(path)

Returns a `boolean` of whether the path exists.

Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import test from 'ava';
import pathExists from '.';
import {pathExists, pathExistsSync} from './index.js';

test('async', async t => {
t.true(await pathExists('test.js'));
t.false(await pathExists('fail'));
});

test('sync', t => {
t.true(pathExists.sync('test.js'));
t.false(pathExists.sync('fail'));
t.true(pathExistsSync('test.js'));
t.false(pathExistsSync('fail'));
});

0 comments on commit 3e66105

Please sign in to comment.