Skip to content

Commit 8f70f58

Browse files
committedApr 16, 2021
Require Node.js 12 and move to ESM
1 parent a326009 commit 8f70f58

File tree

9 files changed

+31
-38
lines changed

9 files changed

+31
-38
lines changed
 

‎.github/workflows/main.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
1615
steps:
1716
- uses: actions/checkout@v2
18-
- uses: actions/setup-node@v1
17+
- uses: actions/setup-node@v2
1918
with:
2019
node-version: ${{ matrix.node-version }}
2120
- run: npm install

‎index.d.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="node"/>
2-
31
declare const getStdin: {
42
/**
53
Get [`stdin`](https://nodejs.org/api/process.html#process_process_stdin) as a `string`.
@@ -9,12 +7,10 @@ declare const getStdin: {
97
@example
108
```
119
// example.ts
12-
import getStdin = require('get-stdin');
10+
import getStdin from 'get-stdin';
1311
14-
(async () => {
15-
console.log(await getStdin());
16-
//=> 'unicorns'
17-
})
12+
console.log(await getStdin());
13+
//=> 'unicorns'
1814
1915
// $ echo unicorns | ts-node example.ts
2016
// unicorns
@@ -30,4 +26,4 @@ declare const getStdin: {
3026
buffer(): Promise<Buffer>;
3127
};
3228

33-
export = getStdin;
29+
export default getStdin;

‎index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
'use strict';
21
const {stdin} = process;
32

4-
module.exports = async () => {
3+
export default async function getStdin() {
54
let result = '';
65

76
if (stdin.isTTY) {
@@ -15,9 +14,9 @@ module.exports = async () => {
1514
}
1615

1716
return result;
18-
};
17+
}
1918

20-
module.exports.buffer = async () => {
19+
getStdin.buffer = async () => {
2120
const result = [];
2221
let length = 0;
2322

‎index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expectType} from 'tsd';
2-
import getStdin = require('.');
2+
import getStdin from './index.js';
33

44
expectType<Promise<string>>(getStdin());
55
expectType<Promise<Buffer>>(getStdin.buffer());

‎package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"email": "sindresorhus@gmail.com",
1111
"url": "https://sindresorhus.com"
1212
},
13+
"type": "module",
14+
"exports": "./index.js",
1315
"engines": {
14-
"node": ">=10"
16+
"node": ">=12"
1517
},
1618
"scripts": {
1719
"test": "xo && ava test.js test-buffer.js && echo unicorns | node test-real.js && tsd"
@@ -31,10 +33,10 @@
3133
"read"
3234
],
3335
"devDependencies": {
34-
"@types/node": "^13.13.5",
35-
"ava": "^2.4.0",
36-
"delay": "^4.2.0",
37-
"tsd": "^0.11.0",
38-
"xo": "^0.24.0"
36+
"@types/node": "^14.14.41",
37+
"ava": "^3.15.0",
38+
"delay": "^5.0.0",
39+
"tsd": "^0.14.0",
40+
"xo": "^0.38.2"
3941
}
4042
}

‎readme.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ $ npm install get-stdin
1212

1313
```js
1414
// example.js
15-
const getStdin = require('get-stdin');
15+
import getStdin from 'get-stdin';
1616

17-
(async () => {
18-
console.log(await getStdin());
19-
//=> 'unicorns'
20-
})();
17+
console.log(await getStdin());
18+
//=> 'unicorns'
2119
```
2220

2321
```

‎test-buffer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {serial as test} from 'ava';
1+
import test from 'ava';
22
import delay from 'delay';
3-
import getStdin from '.';
3+
import getStdin from './index.js';
44

5-
test('get stdin', async t => {
5+
test.serial('get stdin', async t => {
66
process.stdin.isTTY = false;
77

88
const promise = getStdin.buffer();
99
process.stdin.push(Buffer.from('uni'));
10-
process.stdin.push(Buffer.from('corns'));
10+
process.stdin.push(Buffer.from('corns')); // eslint-disable-line unicorn/no-array-push-push
1111
await delay(1);
1212
process.stdin.emit('end');
1313

@@ -16,7 +16,7 @@ test('get stdin', async t => {
1616
t.is(data.toString(), 'unicorns');
1717
});
1818

19-
test('get empty buffer when no stdin', async t => {
19+
test.serial('get empty buffer when no stdin', async t => {
2020
process.stdin.isTTY = true;
2121
t.true((await getStdin.buffer()).equals(Buffer.from('')));
2222
});

‎test-real.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
'use strict';
2-
const getStdin = require('.');
1+
import getStdin from './index.js';
32

43
(async () => {
54
const stdin = await getStdin();

‎test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import {serial as test} from 'ava';
1+
import test from 'ava';
22
import delay from 'delay';
3-
import getStdin from '.';
3+
import getStdin from './index.js';
44

5-
test('get stdin', async t => {
5+
test.serial('get stdin', async t => {
66
process.stdin.isTTY = false;
77
const promise = getStdin();
88

99
process.stdin.push('uni');
10-
process.stdin.push('corns');
10+
process.stdin.push('corns'); // eslint-disable-line unicorn/no-array-push-push
1111
await delay(1);
1212
process.stdin.emit('end');
1313

1414
t.is((await promise).trim(), 'unicorns');
1515
});
1616

17-
test('get empty string when no stdin', async t => {
17+
test.serial('get empty string when no stdin', async t => {
1818
process.stdin.isTTY = true;
1919
t.is(await getStdin(), '');
2020
});

0 commit comments

Comments
 (0)
Please sign in to comment.