Skip to content

Commit 0d7ee32

Browse files
author
evilebottnawi
committed
chore: prepare 2.1.0
1 parent 5b98884 commit 0d7ee32

File tree

7 files changed

+82
-15
lines changed

7 files changed

+82
-15
lines changed

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+
## 2.1.0 - 2018-04-26
8+
9+
* Feature: support options for commands.
10+
* Fix: don't crash when `bail: true` in sync event.
11+
712
## 2.0.1 - 2018-04-19
813

914
* Fix: don't crash when argument is empty (string/array/object).

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ module.exports = {
2727
onBeforeRun: [
2828
{
2929
args: ["build"],
30-
cmd: "del"
30+
cmd: "del",
31+
options: {
32+
cwd: process.cwd()
33+
}
3134
}
3235
]
3336
})
3437
]
3538
};
3639
```
3740

41+
Note: [list of command options](https://github.com/sindresorhus/execa#options).
42+
3843
## Options
3944

4045
| Name | Type | Default | Description |

__tests__/index.test.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ function mkdirSyncSafe(dir) {
4646

4747
function unlinkSyncSafe(dir) {
4848
try {
49-
fs.unlinkSync(dir);
49+
fs.rmdirSync(dir);
5050
} catch (ignoreError) {
5151
// Nothing
5252
}
5353
}
5454

5555
describe("execa-webpack-plugin", () => {
5656
const dir = path.join(__dirname, "dir");
57+
const nestedDir = path.join(dir, "nested");
5758
const otherDir = path.join(__dirname, "other-dir");
5859

5960
it("should throw error on `on*` options are empty (no events)", () =>
@@ -755,4 +756,60 @@ describe("execa-webpack-plugin", () => {
755756
return Promise.resolve();
756757
});
757758
});
759+
760+
it("should works with options (sync event)", () => {
761+
expect.assertions(3);
762+
763+
mkdirSyncSafe(dir);
764+
mkdirSyncSafe(nestedDir);
765+
766+
expect(fs.statSync(dir).isDirectory()).toBe(true);
767+
expect(fs.statSync(nestedDir).isDirectory()).toBe(true);
768+
769+
return run({
770+
onCompile: [
771+
{
772+
args: [nestedDir],
773+
cmd: "del",
774+
options: {
775+
cwd: dir
776+
}
777+
}
778+
]
779+
}).then(() => {
780+
expect(() => fs.statSync(nestedDir)).toThrow();
781+
782+
unlinkSyncSafe(dir);
783+
784+
return Promise.resolve();
785+
});
786+
});
787+
788+
it("should works with options (async event)", () => {
789+
expect.assertions(3);
790+
791+
mkdirSyncSafe(dir);
792+
mkdirSyncSafe(nestedDir);
793+
794+
expect(fs.statSync(dir).isDirectory()).toBe(true);
795+
expect(fs.statSync(nestedDir).isDirectory()).toBe(true);
796+
797+
return run({
798+
onDone: [
799+
{
800+
args: [nestedDir],
801+
cmd: "del",
802+
options: {
803+
cwd: dir
804+
}
805+
}
806+
]
807+
}).then(() => {
808+
expect(() => fs.statSync(nestedDir)).toThrow();
809+
810+
unlinkSyncSafe(dir);
811+
812+
return Promise.resolve();
813+
});
814+
});
758815
});

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "execa-webpack-plugin",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "A better `child_process` for `webpack`",
55
"keywords": [
66
"exec",

src/CommandRunner.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ class CommandRunner {
4747
}
4848

4949
run(command, async) {
50-
const { cmd, args = [], opts = {} } = command;
50+
const { cmd, args = [], options = {} } = command;
5151

52-
opts.stdio = ["ignore", "pipe", "pipe"];
52+
options.stdio = ["ignore", "pipe", "pipe"];
5353

5454
this.log.info(
5555
`Run command "${cmd}${args.length > 0 ? ` ${args.join(" ")}` : ""}"`
5656
);
5757

5858
if (async) {
59-
return execa(cmd, args, opts)
59+
return execa(cmd, args, options)
6060
.then(asyncResult => {
6161
this.handleResult(asyncResult);
6262

@@ -70,7 +70,7 @@ class CommandRunner {
7070
let result = null;
7171

7272
try {
73-
result = execa.sync(cmd, args, opts);
73+
result = execa.sync(cmd, args, options);
7474
} catch (error) {
7575
this.handleError(error, command);
7676
}

src/ExecaWebpackPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ExecaWebpackPlugin {
6161

6262
execute(commands, async) {
6363
const results = [];
64-
const runCommandRunner = command => {
64+
const runCommand = command => {
6565
if (async) {
6666
return Promise.all(command.args).then(resolvedArgs => {
6767
command.args = resolvedArgs.map(
@@ -96,7 +96,7 @@ class ExecaWebpackPlugin {
9696
command.args = [];
9797
}
9898

99-
results.push(runCommandRunner(command));
99+
results.push(runCommand(command));
100100
});
101101

102102
return async ? Promise.all(results) : results;

0 commit comments

Comments
 (0)