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 f81046c commit 09870d0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 61 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 8
- 6
- 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
55 changes: 23 additions & 32 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
declare const macosRelease: {
/**
Get the name and version of a macOS release from the Darwin version.
/**
Get the name and version of a macOS release from the Darwin version.
@param release - By default, the current operating system is used, but you can supply a custom [Darwin kernel version](https://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history), which is the output of [`os.release()`](https://nodejs.org/api/os.html#os_os_release).
@param release - By default, the current operating system is used, but you can supply a custom [Darwin kernel version](https://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history), which is the output of [`os.release()`](https://nodejs.org/api/os.html#os_os_release).
@example
```
import * as os from 'os';
import macosRelease = require('macos-release');
@example
```
import os from 'node:os';
import macosRelease from 'macos-release';
// On a macOS Sierra system
// On a macOS Sierra system
macosRelease();
//=> {name: 'Sierra', version: '10.12'}
macosRelease();
//=> {name: 'Sierra', version: '10.12'}
os.release();
//=> 13.2.0
// This is the Darwin kernel version
os.release();
//=> 13.2.0
// This is the Darwin kernel version
macosRelease(os.release());
//=> {name: 'Sierra', version: '10.12'}
macosRelease(os.release());
//=> {name: 'Sierra', version: '10.12'}
macosRelease('14.0.0');
//=> {name: 'Yosemite', version: '10.10'}
macosRelease('14.0.0');
//=> {name: 'Yosemite', version: '10.10'}
macosRelease('20.0.0');
//=> {name: 'Big Sur', version: '11'}
```
*/
(): {name: string, version: string}
(release: string): {name: string, version: string} | undefined;

// TODO: remove this in the next major version, refactor the whole definition to:
// declare function macosRelease(release?: string): {name: string, version: string};
// export = macosRelease;
default: typeof macosRelease;
};

export = macosRelease;
macosRelease('20.0.0');
//=> {name: 'Big Sur', version: '11'}
```
*/
export default function macosRelease(): {name: string; version: string};
export default function macosRelease(release: string): {name: string; version: string} | undefined;
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const os = require('os');
import os from 'node:os';

const nameMap = new Map([
[21, ['Monterey', '12']],
Expand All @@ -18,20 +17,19 @@ const nameMap = new Map([
[8, ['Tiger', '10.4']],
[7, ['Panther', '10.3']],
[6, ['Jaguar', '10.2']],
[5, ['Puma', '10.1']]
[5, ['Puma', '10.1']],
]);

const macosRelease = release => {
export default function macosRelease(release) {
release = Number((release || os.release()).split('.')[0]);

const [name, version] = nameMap.get(release);
const [name, version] = nameMap.get(release) || {
name: 'Unknown',
version: '',
};

return {
name,
version
version,
};
};

module.exports = macosRelease;
// TODO: remove this in the next major version
module.exports.default = macosRelease;
}
6 changes: 3 additions & 3 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import macosRelease = require('.');
import macosRelease from './index.js';

expectType<{name: string, version: string}>(macosRelease());
expectType<{name: string, version: string} | undefined>(macosRelease('foo'));
expectType<{name: string; version: string}>(macosRelease());
expectType<{name: string; version: string} | undefined>(macosRelease('foo'));
10 changes: 6 additions & 4 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": ">=6"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -33,8 +35,8 @@
"version"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.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 @@ -12,8 +12,8 @@ $ npm install macos-release
## Usage

```js
const os = require('os');
const macosRelease = require('macos-release');
import os from 'node:os';
import macosRelease from 'macos-release';

// On a macOS Sierra system

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

test('main', t => {
t.deepEqual(macosRelease('13.2.0'), {
name: 'Mavericks',
version: '10.9'
version: '10.9',
});

t.deepEqual(macosRelease('20.0.0'), {
name: 'Big Sur',
version: '11'
version: '11',
});
});

0 comments on commit 09870d0

Please sign in to comment.