Skip to content

Commit

Permalink
- added onDoneWatch
Browse files Browse the repository at this point in the history
- Dependencies update
  • Loading branch information
s00d committed Apr 20, 2020
1 parent d9116ea commit 5b01643
Show file tree
Hide file tree
Showing 10 changed files with 419 additions and 449 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.8] - 2019-12-09

### Changed
- added onDoneWatch
- Dependencies update

## [1.1.5] - 2019-12-09

### Changed
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ module.exports = {

***Default: ```{scripts: [],blocking: false,parallel: false}```***

* `onDoneWatch`: configuration object for scripts that execute after files are emitted at the end of the compilation with watch.

***Default: ```{scripts: [],blocking: false,parallel: false}```***

* `blocking (onBeforeBuild, onBuildStart, onBuildEnd, onBuildExit, onBuildExit, onWatchRun)`: block webpack until scripts finish execution.
* `parallel (onBeforeBuild, onBuildStart, onBuildEnd, onBuildExit, onBuildExit, onWatchRun)`: execute scripts in parallel, otherwise execute scripts in the order in which they are specified in the scripts array.
Expand Down
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class WebpackShellPlugin {
private onBuildExit;
private onBuildError;
private onWatchRun;
private onDoneWatch;
private env;
private dev;
private safe;
Expand All @@ -27,6 +28,7 @@ export default class WebpackShellPlugin {
private handleScriptAsync;
private executeScripts;
apply(compiler: webpack.Compiler): void;
private readonly afterCompile;
private readonly onInvalid;
private readonly onCompilation;
private readonly onAfterEmit;
Expand Down
28 changes: 27 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ var WebpackShellPlugin = /** @class */ (function () {
this.safe = false;
this.logging = true;
this.swallowError = false;
this.afterCompile = function (compilation, callback) { return __awaiter(_this, void 0, void 0, function () {
var onDoneWatch;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onDoneWatch = this.onDoneWatch;
if (!(onDoneWatch.scripts && onDoneWatch.scripts.length > 0)) return [3 /*break*/, 2];
this.log('Executing additional scripts before exit');
return [4 /*yield*/, this.executeScripts(onDoneWatch.scripts, onDoneWatch.parallel, onDoneWatch.blocking)];
case 1:
_a.sent();
if (this.dev) {
this.onBuildExit = JSON.parse(JSON.stringify(defaultTask));
}
_a.label = 2;
case 2:
if (callback) {
callback();
}
return [2 /*return*/];
}
});
}); };
this.onInvalid = function (compilation) { return __awaiter(_this, void 0, void 0, function () {
var onBeforeBuild;
return __generator(this, function (_a) {
Expand Down Expand Up @@ -191,7 +214,8 @@ var WebpackShellPlugin = /** @class */ (function () {
this.onBuildExit = this.validateEvent(options.onBuildExit);
this.onBuildError = this.validateEvent(options.onBuildError);
this.onWatchRun = this.validateEvent(options.onWatchRun);
if (options.hasOwnProperty('env')) {
this.onDoneWatch = this.validateEvent(options.onDoneWatch);
if (options.env !== undefined) {
this.env = options.env;
}
if (options.dev !== undefined) {
Expand Down Expand Up @@ -332,13 +356,15 @@ var WebpackShellPlugin = /** @class */ (function () {
compiler.hooks.compilation.tap('webpack-shell-plugin-next', this.onCompilation);
compiler.hooks.afterEmit.tapAsync('webpack-shell-plugin-next', this.onAfterEmit);
compiler.hooks.done.tapAsync('webpack-shell-plugin-next', this.onDone);
compiler.hooks.afterCompile.tapAsync('webpack-shell-plugin-next', this.afterCompile);
compiler.hooks.watchRun.tapAsync('webpack-shell-plugin-next', this.watchRun);
}
else {
compiler.plugin('invalid', this.onInvalid);
compiler.plugin('compilation', this.onCompilation);
compiler.plugin('after-emit', this.onAfterEmit);
compiler.plugin('done', this.onDone);
compiler.plugin('after-compile', this.afterCompile);
compiler.plugin('watch-run', this.watchRun);
}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export declare type Options = {
onBuildError?: Tasks | string;
/** Scripts to execute after onWatchRun. Defaults to []. */
onWatchRun?: Tasks | string;
/** Scripts to execute after files are emitted at the end with watch. Defaults to []. */
onDoneWatch?: Tasks | string;
/**
* Switch for development environments. This causes scripts to execute once.
* Useful for running HMR on webpack-dev-server or webpack watch mode.
Expand Down
Loading

0 comments on commit 5b01643

Please sign in to comment.