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 a0264df commit c15d858
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 33 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
10 changes: 4 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ By default, the name of the current operating system is returned.
@example
```
import * as os fron 'os';
import osName = require('os-name');
import os from 'node:os';
import osName from 'os-name';
// On a macOS Sierra system
Expand All @@ -29,7 +29,5 @@ osName('win32', '6.3.9600');
//=> 'Windows 8.1'
```
*/
declare function osName(): string;
declare function osName(platform: NodeJS.Platform, release: string): string;

export = osName;
export default function osName(): string;
export default function osName(platform: NodeJS.Platform, release: string): string;
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';
const os = require('os');
const macosRelease = require('macos-release');
const winRelease = require('windows-release');
import os from 'node:os';
import macosRelease from 'macos-release';
import windowsRelease from 'windows-release';

const osName = (platform, release) => {
export default function osName(platform, release) {
if (!platform && release) {
throw new Error('You can\'t specify a `release` without specifying `platform`');
}
Expand Down Expand Up @@ -40,11 +39,9 @@ const osName = (platform, release) => {
release = os.release();
}

id = release ? winRelease(release) : '';
id = release ? windowsRelease(release) : '';
return 'Windows' + (id ? ' ' + id : '');
}

return platform;
};

module.exports = osName;
}
6 changes: 3 additions & 3 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os from 'node:os';
import {expectType} from 'tsd';
import * as os from 'os';
import osName = require('.');
import osName from './index.js';

expectType<string>(osName());
expectType<string>(osName(os.platform(), os.release()));
expectType<string>(osName(os.platform(), os.release())); // eslint-disable-line @typescript-eslint/no-unsafe-member-access
expectType<string>(osName('darwin', '14.0.0'));
expectType<string>(osName('linux', '3.13.0-24-generic'));
expectType<string>(osName('win32', '6.3.9600'));
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"email": "sindresorhus@gmail.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 @@ -34,13 +36,13 @@
"linux"
],
"dependencies": {
"macos-release": "^2.5.0",
"windows-release": "^4.0.0"
"macos-release": "^3.0.0",
"windows-release": "^5.0.0"
},
"devDependencies": {
"@types/node": "^14.6.2",
"ava": "^2.4.0",
"tsd": "^0.13.1",
"xo": "^0.33.0"
"@types/node": "^16.6.0",
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ $ npm install os-name
## Usage

```js
const os = require('os');
const osName = require('os-name');
import os from 'node:os';
import osName from 'os-name';

// On a macOS Sierra system

Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'os';
import os from 'node:os';
import test from 'ava';
import osName from '.';
import osName from './index.js';

test('main', t => {
t.true(osName().length > 0);
Expand Down

0 comments on commit c15d858

Please sign in to comment.