Skip to content

Commit ba74431

Browse files
author
evilebottnawi
committed
chore: prepare 1.0.2 release
1 parent a3a7cfe commit ba74431

7 files changed

Lines changed: 367 additions & 364 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
This project adheres to [Semantic Versioning](http://semver.org).
66

7+
## 1.0.2 - 2018-01-11
8+
9+
* Chore: simplify error handling.
10+
* Tests: improve code coverage.
11+
712
## 1.0.1 - 2017-12-22
813

914
* Fixed: remove unnecessary output `stdout:` and `stderr:`.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 itgalaxy inc.
3+
Copyright (c) 2017-2018 itgalaxy inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ module.exports = {
141141

142142
## Thanks
143143

144-
* [execa](https://github.com/sindresorhus/execa) - api.
144+
* [execa](https://github.com/sindresorhus/execa) - API.
145145

146146
## [Changelog](CHANGELOG.md)
147147

__tests__/index.test.js

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ describe("execa-webpack-plugin", () => {
8080
});
8181
});
8282

83+
it("should works with `onBuildStart` and `dev` is `false` option", () => {
84+
mkdirSyncSafe(dir);
85+
86+
expect(fs.statSync(dir).isDirectory()).toBe(true);
87+
88+
return run({
89+
dev: false,
90+
onBuildStart: [
91+
{
92+
args: [dir],
93+
cmd: "del"
94+
}
95+
]
96+
}).then(() => {
97+
expect(() => fs.statSync(dir)).toThrow();
98+
99+
unlinkSyncSafe(dir);
100+
101+
return Promise.resolve();
102+
});
103+
});
104+
83105
it("should works with `onBuildEnd` option", () => {
84106
mkdirSyncSafe(dir);
85107

@@ -101,6 +123,28 @@ describe("execa-webpack-plugin", () => {
101123
});
102124
});
103125

126+
it("should works with `onBuildEnd` and `dev` is `false` options", () => {
127+
mkdirSyncSafe(dir);
128+
129+
expect(fs.statSync(dir).isDirectory()).toBe(true);
130+
131+
return run({
132+
dev: false,
133+
onBuildEnd: [
134+
{
135+
args: [dir],
136+
cmd: "del"
137+
}
138+
]
139+
}).then(() => {
140+
expect(() => fs.statSync(dir)).toThrow();
141+
142+
unlinkSyncSafe(dir);
143+
144+
return Promise.resolve();
145+
});
146+
});
147+
104148
it("should works with `onBuildExit` option", () => {
105149
mkdirSyncSafe(dir);
106150

@@ -122,6 +166,28 @@ describe("execa-webpack-plugin", () => {
122166
});
123167
});
124168

169+
it("should works with `onBuildExit` and `dev` is `false` options", () => {
170+
mkdirSyncSafe(dir);
171+
172+
expect(fs.statSync(dir).isDirectory()).toBe(true);
173+
174+
return run({
175+
dev: false,
176+
onBuildExit: [
177+
{
178+
args: [dir],
179+
cmd: "del"
180+
}
181+
]
182+
}).then(() => {
183+
expect(() => fs.statSync(dir)).toThrow();
184+
185+
unlinkSyncSafe(dir);
186+
187+
return Promise.resolve();
188+
});
189+
});
190+
125191
it("should throw error with `bail: true` option", () => {
126192
let catchError = null;
127193

@@ -185,37 +251,6 @@ describe("execa-webpack-plugin", () => {
185251
});
186252
});
187253

188-
it("should throw error when nested commands return nothing", () => {
189-
let catchError = null;
190-
191-
return run({
192-
bail: true,
193-
logLevel: "silent",
194-
onBuildStart: [
195-
{
196-
args: [
197-
{
198-
args: [path.join(resourcesDir, "nothing.js")],
199-
cmd: "node"
200-
}
201-
],
202-
cmd: "del"
203-
}
204-
]
205-
})
206-
.catch(error => {
207-
catchError = error;
208-
209-
return Promise.resolve();
210-
})
211-
.then(() => {
212-
expect(catchError).toBeInstanceOf(Error);
213-
expect(catchError).not.toBeNull();
214-
215-
return Promise.resolve();
216-
});
217-
});
218-
219254
it("should works when nested commands return nothing and 'bail: false'", () => {
220255
let catchError = null;
221256

index.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,8 @@ class ChildProcessWebpackPlugin {
4949
const nestedResults = this.execute([arg]);
5050
const [result] = nestedResults;
5151

52-
if (!result.stdout) {
52+
if (!result || !result.stdout) {
5353
hasFailedNestedChildProcess = true;
54-
55-
const error = new Error(
56-
`Nested process "${arg.cmd} ${arg.args.join(
57-
" "
58-
)}" did not return anything`
59-
);
60-
61-
this.log.error(error);
62-
63-
if (this.options.bail) {
64-
throw error;
65-
}
6654
} else {
6755
args[index] = result.stdout;
6856
}
@@ -90,21 +78,29 @@ class ChildProcessWebpackPlugin {
9078
try {
9179
result = execa.sync(cmd, args, opts);
9280
} catch (error) {
93-
this.log.error(error);
81+
this.log.error(
82+
new Error(
83+
`Process "${cmd}${
84+
args.length > 0 ? ` ${args.join(" ")}` : ""
85+
}" return ${error.message}`
86+
)
87+
);
9488

9589
if (this.options.bail) {
9690
throw error;
9791
}
9892
}
9993

100-
const { stdout, stderr } = result;
94+
if (result) {
95+
const { stdout, stderr } = result;
10196

102-
if (stdout) {
103-
this.log.info(result.stdout);
104-
}
97+
if (stdout) {
98+
this.log.info(result.stdout);
99+
}
105100

106-
if (stderr) {
107-
this.log.warn(result.stderr);
101+
if (stderr) {
102+
this.log.warn(result.stderr);
103+
}
108104
}
109105

110106
results.push(result);

0 commit comments

Comments
 (0)