Skip to content

Commit bf5ff91

Browse files
authored
Merge pull request #28 from 1337programming/bugfix/spawn-execution
Deprecate verbose and introduce safe variable to resolve spawn issues.
2 parents ea5153f + dbb07ab commit bf5ff91

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ Once the build finishes, a child process is spawned firing both a python and nod
7373
* `onBuildEnd`: array of scripts to execute after files are emitted at the end of the compilation. **Default: [ ]**
7474
* `onBuildExit`: array of scripts to execute after webpack's process is complete. **Default: [ ]**
7575
* `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**
76-
* `verbose`: enable for verbose output. **Default: false**
76+
* `safe`: switches script execution process from spawn to exec. If running into problems with spawn, turn this setting on. **Default: false**
77+
* `verbose`: **DEPRECATED** enable for verbose output. **Default: false**
7778

7879
### Developing
7980

lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ var defaultOptions = {
150150
onBuildEnd: [],
151151
onBuildExit: [],
152152
dev: true,
153-
verbose: false
153+
verbose: false,
154+
safe: false
154155
};
155156

156157
var WebpackShellPlugin = function () {
@@ -192,7 +193,7 @@ var WebpackShellPlugin = function () {
192193
}, {
193194
key: 'handleScript',
194195
value: function handleScript(script) {
195-
if (os.platform() === 'win32') {
196+
if (os.platform() === 'win32' || this.options.safe) {
196197
this.spreadStdoutAndStdErr(exec(script, this.puts));
197198
} else {
198199
var _serializeScript = this.serializeScript(script),
@@ -235,6 +236,7 @@ var WebpackShellPlugin = function () {
235236
compiler.plugin('compilation', function (compilation) {
236237
if (_this.options.verbose) {
237238
console.log('Report compilation: ' + compilation);
239+
console.warn('WebpackShellPlugin [' + new Date() + ']: Verbose is being deprecated, please remove.');
238240
}
239241
if (_this.options.onBuildStart.length) {
240242
console.log('Executing pre-build scripts');

src/webpack-shell-plugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const defaultOptions = {
77
onBuildEnd: [],
88
onBuildExit: [],
99
dev: true,
10-
verbose: false
10+
verbose: false,
11+
safe: false
1112
};
1213

13-
1414
export default class WebpackShellPlugin {
1515
constructor(options) {
1616
this.options = this.validateInput(this.mergeOptions(options, defaultOptions));
@@ -37,7 +37,7 @@ export default class WebpackShellPlugin {
3737
}
3838

3939
handleScript(script) {
40-
if (os.platform() === 'win32') {
40+
if (os.platform() === 'win32' || this.options.safe) {
4141
this.spreadStdoutAndStdErr(exec(script, this.puts));
4242
} else {
4343
const {command, args} = this.serializeScript(script);
@@ -73,6 +73,7 @@ export default class WebpackShellPlugin {
7373
compiler.plugin('compilation', (compilation) => {
7474
if (this.options.verbose) {
7575
console.log(`Report compilation: ${compilation}`);
76+
console.warn(`WebpackShellPlugin [${new Date()}]: Verbose is being deprecated, please remove.`);
7677
}
7778
if (this.options.onBuildStart.length) {
7879
console.log('Executing pre-build scripts');

test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const chalk = require('chalk');
2+
const log = console.log;
3+
4+
// combine styled and normal strings
5+
log(chalk.blue('Hello') + 'World' + chalk.red('!'));
6+
7+
// compose multiple styles using the chainable API
8+
log(chalk.blue.bgRed.bold('Hello world!'));
9+
10+
// pass in multiple arguments
11+
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
12+
13+
// nest styles
14+
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
15+
16+
// nest styles of the same type even (color, underline, background)
17+
log(chalk.green(
18+
'I am a green line ' +
19+
chalk.blue.underline.bold('with a blue substring') +
20+
' that becomes green again!'
21+
));
22+
23+
// ES2015 template literal
24+
log(`
25+
CPU: ${chalk.red('90%')}
26+
RAM: ${chalk.green('40%')}
27+
DISK: ${chalk.yellow('70%')}
28+
`);

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const webpack = require('webpack');
33

4-
var WebpackShellPlugin = require('./lib');
4+
const WebpackShellPlugin = require('./lib');
55

66
module.exports = {
77
watch: true,
@@ -19,7 +19,7 @@ module.exports = {
1919
]
2020
},
2121
plugins: [
22-
new WebpackShellPlugin({onBuildStart:['echo "Webpack Start"'], onBuildEnd:['echo "Webpack End"']}),
22+
new WebpackShellPlugin({onBuildStart:['node test.js'], onBuildEnd:['echo "Webpack End"'], safe: true, verbose: true}),
2323
new webpack.HotModuleReplacementPlugin()
2424
]
2525
};

0 commit comments

Comments
 (0)