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 10, 2021
1 parent b51fc97 commit da94ae4
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 49 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 8
- 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
4 changes: 2 additions & 2 deletions fixture.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
'use strict';
const isAdmin = require('.');
import process from 'node:process';
import isAdmin from './index.js';

(async () => {
const admin = await isAdmin();
Expand Down
16 changes: 6 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/**
Check if the process is running as Administrator on Windows.
Check if the process is running as administrator on Windows.
@returns Whether the process is running as Administrator.
@returns Whether the process is running as administrator.
@example
```
import isAdmin = require('is-admin');
import isAdmin from 'is-admin';
(async () => {
console.log(await isAdmin());
//=> false
})();
console.log(await isAdmin());
//=> false
```
*/
declare function isAdmin(): Promise<boolean>;

export = isAdmin;
export default function isAdmin(): Promise<boolean>;
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
'use strict';
const execa = require('execa');
import process from 'node:process';
import execa from 'execa';

// https://stackoverflow.com/a/28268802
async function testFltmc() {
try {
await execa('fltmc');
return true;
} catch (_) {
} catch {
return false;
}
}

module.exports = async () => {
export default async function isAdmin() {
if (process.platform !== 'win32') {
return false;
}

try {
// TODO: Convert this to not use `.shell` as it's slighly faster
// https://stackoverflow.com/a/21295806/1641422
await execa.shell('fsutil dirty query %systemdrive%');
await execa('fsutil', ['dirty', 'query', process.env.systemdrive]);
return true;
} catch (error) {
if (error.code === 'ENOENT') {
Expand All @@ -28,4 +27,4 @@ module.exports = async () => {

return false;
}
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import isAdmin = require('.');
import isAdmin from './index.js';

expectType<Promise<boolean>>(isAdmin());
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 <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (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
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"name": "is-admin",
"version": "3.0.0",
"description": "Check if the process is running as Administrator on Windows",
"description": "Check if the process is running as administrator on Windows",
"license": "MIT",
"repository": "sindresorhus/is-admin",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -35,11 +38,11 @@
"root"
],
"dependencies": {
"execa": "^1.0.0"
"execa": "^5.1.1"
},
"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"
}
}
21 changes: 5 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
# is-admin

> Check if the process is running as Administrator on Windows
> Check if the process is running as administrator on Windows
## Install

```
$ npm install is-admin
```


## Usage

```js
const isAdmin = require('is-admin');
import isAdmin from 'is-admin';

(async () => {
console.log(await isAdmin());
//=> false
})();
console.log(await isAdmin());
//=> false
```


## API

### isAdmin()

Returns a `Promise<boolean>` indicating whether the process is running as Administrator.

Returns a `Promise<boolean>` indicating whether the process is running as administrator.

## Related

- [is-elevated](https://github.com/sindresorhus/is-elevated) - Check if the process is running with elevated privileges *(cross-platform)*


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process';
import test from 'ava';
import execa from 'execa';

Expand Down

0 comments on commit da94ae4

Please sign in to comment.