Skip to content

Commit 13415cd

Browse files
committed
use newer Node.js APIs to simplify the code
* events.once() nodejs/node@b1ef279 * fs.promises.mkdir instead of util.promisify()-ed fs.mkdir
1 parent 17509d3 commit 13415cd

File tree

3 files changed

+15
-47
lines changed

3 files changed

+15
-47
lines changed

.github/main.workflow

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
workflow "Test" {
22
on = "push"
3-
resolves = ["Test (latest)", "Test (stable)"]
3+
resolves = ["Test (without Git)", "Test (with Git)"]
44
}
55

66
action "Install" {
@@ -9,16 +9,16 @@ action "Install" {
99
args = "ci"
1010
}
1111

12-
action "Test (latest)" {
12+
action "Test (without Git)" {
1313
uses = "docker://node:alpine"
1414
needs = ["Install"]
1515
runs = "npm"
1616
args = "test"
1717
secrets = ["CODECOV_TOKEN"]
1818
}
1919

20-
action "Test (stable)" {
21-
uses = "docker://node:10"
20+
action "Test (with Git)" {
21+
uses = "docker://node"
2222
needs = ["Install"]
2323
runs = "npm"
2424
args = "test"

appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ platform: x64
33
shallow_clone: true
44
skip_tags: true
55
install:
6-
- ps: Install-Product node '' x64
6+
# https://github.com/appveyor/ci/issues/2921
7+
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild 12) x64
78
- npm ci
89
build: off
910
test_script: node test.js

index.js

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env node
22
'use strict';
33

4-
const {createWriteStream, mkdir} = require('fs');
4+
const {createWriteStream, promises: {mkdir}} = require('fs');
55
const {dirname, extname, join, resolve: resolvePath} = require('path');
6+
const {once} = require('events');
67
const {promisify} = require('util');
78
const {spawn} = require('child_process');
89

@@ -100,41 +101,18 @@ const codecovBashPath = process.platform === 'win32' ? join(cwd, 'coverage', Mat
100101
}
101102

102103
const [code, codecovBash] = await Promise.all([
103-
(async () => {
104-
/*
105-
On Node.js >= 11.3.0, const {once} = require('events') is available
106-
https://nodejs.org/api/events.html#events_events_once_emitter_name
107-
108-
return (await once(spawn(...await prepareArgs, {
109-
cwd,
110-
stdio: 'inherit',
111-
timeout
112-
}), 'exit'))[0];
113-
*/
114-
115-
const args = await prepareArgs;
116-
117-
return new Promise((resolve, reject) => {
118-
spawn(...args, {
119-
cwd,
120-
stdio: 'inherit',
121-
timeout
122-
})
123-
.once('error', reject)
124-
.once('exit', resolve);
125-
});
126-
})(),
104+
(async () => (await once(spawn(...await prepareArgs, {
105+
cwd,
106+
stdio: 'inherit',
107+
timeout
108+
}), 'exit'))[0])(),
127109
(async () => {
128110
try {
129111
// The default shell of Travis CI Windows build is Git BASH
130112
if (!(process.platform === 'win32' && isTravisCi)) {
131113
await Promise.all([promisifiedWhich('bash'), promisifiedWhich('git')]);
132114
}
133115
} catch {
134-
/*
135-
On Node.js >= 11.3.0, const {once} = require('events') is available
136-
https://nodejs.org/api/events.html#events_events_once_emitter_name
137-
138116
await once(spawn('npm', [
139117
'install',
140118
'--no-package-lock',
@@ -145,19 +123,8 @@ const codecovBashPath = process.platform === 'win32' ? join(cwd, 'coverage', Mat
145123
shell: process.platform === 'win32',
146124
timeout
147125
}), 'exit');
148-
*/
149126

150-
return new Promise(resolve => spawn('npm', [
151-
'install',
152-
'--no-audit',
153-
'--no-package-lock',
154-
'--no-save',
155-
'codecov@3'
156-
], {
157-
cwd,
158-
shell: process.platform === 'win32',
159-
timeout
160-
}).once('exit', () => resolve(null)));
127+
return null;
161128
}
162129

163130
const {connect} = require('http2');
@@ -171,7 +138,7 @@ const codecovBashPath = process.platform === 'win32' ? join(cwd, 'coverage', Mat
171138
request.end();
172139

173140
if (codecovBashPath) {
174-
await promisify(mkdir)(dirname(codecovBashPath), {recursive: true});
141+
await mkdir(dirname(codecovBashPath), {recursive: true});
175142
}
176143

177144
await promisify(pipeline)([

0 commit comments

Comments
 (0)