Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: option swallowError #42

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Once the build finishes, a child process is spawned firing both a python and nod
* `dev`: switch for development environments. This causes scripts to execute once. Useful for running HMR on webpack-dev-server or webpack watch mode. **Default: true**
* `safe`: switches script execution process from spawn to exec. If running into problems with spawn, turn this setting on. **Default: false**
* `verbose`: **DEPRECATED** enable for verbose output. **Default: false**
* `swallowError`: ignore script errors (useful in watch mode) **Default: false**

### Developing

Expand Down
172 changes: 49 additions & 123 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,5 @@
'use strict';

var asyncGenerator = function () {
function AwaitValue(value) {
this.value = value;
}

function AsyncGenerator(gen) {
var front, back;

function send(key, arg) {
return new Promise(function (resolve, reject) {
var request = {
key: key,
arg: arg,
resolve: resolve,
reject: reject,
next: null
};

if (back) {
back = back.next = request;
} else {
front = back = request;
resume(key, arg);
}
});
}

function resume(key, arg) {
try {
var result = gen[key](arg);
var value = result.value;

if (value instanceof AwaitValue) {
Promise.resolve(value.value).then(function (arg) {
resume("next", arg);
}, function (arg) {
resume("throw", arg);
});
} else {
settle(result.done ? "return" : "normal", result.value);
}
} catch (err) {
settle("throw", err);
}
}

function settle(type, value) {
switch (type) {
case "return":
front.resolve({
value: value,
done: true
});
break;

case "throw":
front.reject(value);
break;

default:
front.resolve({
value: value,
done: false
});
break;
}

front = front.next;

if (front) {
resume(front.key, front.arg);
} else {
back = null;
}
}

this._invoke = send;

if (typeof gen.return !== "function") {
this.return = undefined;
}
}

if (typeof Symbol === "function" && Symbol.asyncIterator) {
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
return this;
};
}

AsyncGenerator.prototype.next = function (arg) {
return this._invoke("next", arg);
};

AsyncGenerator.prototype.throw = function (arg) {
return this._invoke("throw", arg);
};

AsyncGenerator.prototype.return = function (arg) {
return this._invoke("return", arg);
};

return {
wrap: function (fn) {
return function () {
return new AsyncGenerator(fn.apply(this, arguments));
};
},
await: function (value) {
return new AwaitValue(value);
}
};
}();

var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
Expand All @@ -137,6 +24,44 @@ var createClass = function () {
};
}();







































var toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
Expand All @@ -151,7 +76,8 @@ var defaultOptions = {
onBuildExit: [],
dev: true,
verbose: false,
safe: false
safe: false,
swallowError: false
};

var WebpackShellPlugin = function () {
Expand All @@ -163,8 +89,8 @@ var WebpackShellPlugin = function () {

createClass(WebpackShellPlugin, [{
key: 'puts',
value: function puts(error, stdout, stderr) {
if (error) {
value: function puts(error) {
if (error && !this.options.swallowError) {
throw error;
}
}
Expand Down Expand Up @@ -194,14 +120,14 @@ var WebpackShellPlugin = function () {
key: 'handleScript',
value: function handleScript(script) {
if (os.platform() === 'win32' || this.options.safe) {
this.spreadStdoutAndStdErr(exec(script, this.puts));
this.spreadStdoutAndStdErr(exec(script, this.puts.bind(this)));
} else {
var _serializeScript = this.serializeScript(script),
command = _serializeScript.command,
args = _serializeScript.args;

var proc = spawn(command, args, { stdio: 'inherit' });
proc.on('close', this.puts);
proc.on('close', this.puts.bind(this));
}
}
}, {
Expand All @@ -220,13 +146,13 @@ var WebpackShellPlugin = function () {
}
}, {
key: 'mergeOptions',
value: function mergeOptions(options, defaults) {
for (var key in defaults) {
value: function mergeOptions(options, defaults$$1) {
for (var key in defaults$$1) {
if (options.hasOwnProperty(key)) {
defaults[key] = options[key];
defaults$$1[key] = options[key];
}
}
return defaults;
return defaults$$1;
}
}, {
key: 'apply',
Expand Down Expand Up @@ -275,4 +201,4 @@ var WebpackShellPlugin = function () {
return WebpackShellPlugin;
}();

module.exports = WebpackShellPlugin;
module.exports = WebpackShellPlugin;
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-shell-plugin",
"version": "0.5.0",
"version": "0.6.0",
"description": "Run shell commands before and after webpack builds",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -35,12 +35,12 @@
"homepage": "https://github.com/1337programming/webpack-shell-plugin",
"devDependencies": {
"babel-core": "^6.7.6",
"babel-preset-es2015-rollup": "^1.1.1",
"css-loader": "^0.23.1",
"eslint": "^2.7.0",
"rollup": "^0.25.8",
"babel-preset-es2015-rollup": "^3.0.0",
"css-loader": "^0.28.0",
"eslint": "^3.19.0",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.4.0",
"style-loader": "^0.13.1",
"webpack": "^1.13.1"
"style-loader": "^0.16.1",
"webpack": "^2.4.1"
}
}
11 changes: 6 additions & 5 deletions src/webpack-shell-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ const defaultOptions = {
onBuildExit: [],
dev: true,
verbose: false,
safe: false
safe: false,
swallowError: false
};

export default class WebpackShellPlugin {
constructor(options) {
this.options = this.validateInput(this.mergeOptions(options, defaultOptions));
}

puts(error, stdout, stderr) {
if (error) {
puts(error) {
if (error && !this.options.swallowError) {
throw error;
}
}
Expand All @@ -38,11 +39,11 @@ export default class WebpackShellPlugin {

handleScript(script) {
if (os.platform() === 'win32' || this.options.safe) {
this.spreadStdoutAndStdErr(exec(script, this.puts));
this.spreadStdoutAndStdErr(exec(script, this.puts.bind(this)));
} else {
const {command, args} = this.serializeScript(script);
const proc = spawn(command, args, {stdio: 'inherit'});
proc.on('close', this.puts);
proc.on('close', this.puts.bind(this));
}
}

Expand Down