Skip to content

Commit

Permalink
- add onBeforeCompile
Browse files Browse the repository at this point in the history
- update deps
  • Loading branch information
s00d committed Aug 6, 2024
1 parent 7b5c586 commit 0e97e0e
Show file tree
Hide file tree
Showing 10 changed files with 3,062 additions and 2,018 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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).

## [2.3.2] - 2024-08-07
### Changed
- add onBeforeCompile
- update deps

## [2.2.2] - 2021-03-15
### Changed
- add shell control
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = {
* `onBeforeNormalRun`: configuration object for scripts that execute on normal run without --watch option
* `onAfterDone`: configuration object for scripts that execute after done.
* `onFailedBuild`: configuration object for scripts that execute after error.
* `onBeforeCompile`: configuration object for scripts that execute before complite.

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

Expand Down
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class WebpackShellPlugin {
private onDoneWatch;
private onAfterDone;
private onFailedBuild;
private onBeforeCompile;
private env;
private dev;
private shell;
Expand All @@ -38,6 +39,7 @@ export default class WebpackShellPlugin {
private readonly onFailed;
private readonly onBefore;
private readonly onCompilation;
private readonly onBeforeCompileRun;
private readonly onAfterEmit;
private readonly onDone;
private readonly watchRun;
Expand Down
46 changes: 36 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down Expand Up @@ -56,7 +56,7 @@ var WebpackShellPlugin = /** @class */ (function () {
this.safe = false;
this.logging = true;
this.swallowError = false;
this.onBeforeRun = function (compiler, callback) { return __awaiter(_this, void 0, void 0, function () {
this.onBeforeRun = function (_compiler, callback) { return __awaiter(_this, void 0, void 0, function () {
var onBeforeNormalRun;
return __generator(this, function (_a) {
switch (_a.label) {
Expand Down Expand Up @@ -98,7 +98,7 @@ var WebpackShellPlugin = /** @class */ (function () {
}
});
}); };
this.afterCompile = function (compilation, callback) { return __awaiter(_this, void 0, void 0, function () {
this.afterCompile = function (_compilation, callback) { return __awaiter(_this, void 0, void 0, function () {
var onDoneWatch;
return __generator(this, function (_a) {
switch (_a.label) {
Expand Down Expand Up @@ -140,7 +140,7 @@ var WebpackShellPlugin = /** @class */ (function () {
}
});
}); };
this.onBefore = function (compilation) { return __awaiter(_this, void 0, void 0, function () {
this.onBefore = function (_compilation) { return __awaiter(_this, void 0, void 0, function () {
var onBeforeBuild;
return __generator(this, function (_a) {
switch (_a.label) {
Expand Down Expand Up @@ -178,7 +178,30 @@ var WebpackShellPlugin = /** @class */ (function () {
}
});
}); };
this.onAfterEmit = function (compilation, callback) { return __awaiter(_this, void 0, void 0, function () {
this.onBeforeCompileRun = function (_params, callback) { return __awaiter(_this, void 0, void 0, function () {
var onBeforeCompile;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
onBeforeCompile = this.onBeforeCompile;
if (!(onBeforeCompile.scripts && onBeforeCompile.scripts.length > 0)) return [3 /*break*/, 2];
this.log('Executing pre-build scripts');
return [4 /*yield*/, this.executeScripts(onBeforeCompile.scripts, onBeforeCompile.parallel, onBeforeCompile.blocking)];
case 1:
_a.sent();
if (this.dev) {
this.onBuildStart = JSON.parse(JSON.stringify(defaultTask));
}
_a.label = 2;
case 2:
if (callback) {
callback();
}
return [2 /*return*/];
}
});
}); };
this.onAfterEmit = function (_compilation, callback) { return __awaiter(_this, void 0, void 0, function () {
var onBuildEndOption;
return __generator(this, function (_a) {
switch (_a.label) {
Expand Down Expand Up @@ -236,7 +259,7 @@ var WebpackShellPlugin = /** @class */ (function () {
}
});
}); };
this.watchRun = function (compiler, callback) { return __awaiter(_this, void 0, void 0, function () {
this.watchRun = function (_compiler, callback) { return __awaiter(_this, void 0, void 0, function () {
var onWatchRun;
return __generator(this, function (_a) {
switch (_a.label) {
Expand All @@ -260,7 +283,7 @@ var WebpackShellPlugin = /** @class */ (function () {
});
}); };
if (options.verbose) {
this.warn("WebpackShellPlugin [".concat(new Date(), "]: Verbose is being deprecated, please remove."));
this.warn("WebpackShellPluginNext [".concat(new Date(), "]: Verbose is being deprecated, please remove."));
}
this.onBeforeBuild = this.validateEvent(options.onBeforeBuild);
this.onBeforeNormalRun = this.validateEvent(options.onBeforeNormalRun);
Expand All @@ -272,6 +295,7 @@ var WebpackShellPlugin = /** @class */ (function () {
this.onDoneWatch = this.validateEvent(options.onDoneWatch);
this.onAfterDone = this.validateEvent(options.onAfterDone);
this.onFailedBuild = this.validateEvent(options.onFailedBuild);
this.onBeforeCompile = this.validateEvent(options.onBeforeCompile);
if (options.env !== undefined) {
this.env = options.env;
}
Expand All @@ -292,6 +316,7 @@ var WebpackShellPlugin = /** @class */ (function () {
}
this.onCompilation = this.onCompilation.bind(this);
this.onBeforeRun = this.onBeforeRun.bind(this);
this.onBeforeCompileRun = this.onBeforeCompileRun.bind(this);
this.onAfterEmit = this.onAfterEmit.bind(this);
this.onDone = this.onDone.bind(this);
this.afterDone = this.afterDone.bind(this);
Expand All @@ -313,14 +338,14 @@ var WebpackShellPlugin = /** @class */ (function () {
};
WebpackShellPlugin.prototype.putsAsync = function (resolve) {
var _this = this;
return function (error, stdout, stderr) {
return function (error, _stdout, _stderr) {
if (error && !_this.swallowError) {
throw error;
}
resolve(error);
};
};
WebpackShellPlugin.prototype.puts = function (error, stdout, stderr) {
WebpackShellPlugin.prototype.puts = function (error, _stdout, _stderr) {
if (error && !this.swallowError) {
throw error;
}
Expand Down Expand Up @@ -382,7 +407,7 @@ var WebpackShellPlugin = /** @class */ (function () {
return [2 /*return*/];
}
if (blocking && parallel) {
throw new Error("WebpackShellPlugin [".concat(new Date(), "]: Not supported"));
throw new Error("WebpackShellPluginNext [".concat(new Date(), "]: Not supported"));
}
i = 0;
_a.label = 1;
Expand Down Expand Up @@ -424,6 +449,7 @@ var WebpackShellPlugin = /** @class */ (function () {
compiler.hooks.beforeRun.tapAsync('webpack-shell-plugin-next', this.onBeforeRun);
compiler.hooks.failed.tap('webpack-shell-plugin-next', this.onFailed);
compiler.hooks.make.tap('webpack-shell-plugin-next', this.onBefore);
compiler.hooks.beforeCompile.tapAsync('webpack-shell-plugin-next', this.onBeforeCompileRun);
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);
Expand Down
85 changes: 65 additions & 20 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,88 @@
export declare type Task = Function | string;
export declare type Tasks = {
export type Task = Function | string;
export type Tasks = {
scripts?: Task[];
blocking?: boolean;
parallel?: boolean;
};
export declare type Script = {
export type Script = {
command: string;
args: string[];
};
export declare type Options = {
/** Scripts to execute before normal run (without --watch). Defaults to []. */
export type Options = {
/**
* Scripts to execute before a normal run (without --watch).
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onBeforeNormalRun?: Tasks | string | Function;
/** Scripts to execute on the before build. Defaults to []. */
/**
* Scripts to execute before the build process starts.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onBeforeBuild?: Tasks | string | Function;
/** Scripts to execute on the before error. Defaults to []. */
/**
* Scripts to execute when the build fails.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onFailedBuild?: Tasks | string | Function;
/** Scripts to execute on the initial build. Defaults to []. */
/**
* Scripts to execute at the start of the build process.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onBuildStart?: Tasks | string | Function;
/**
* Scripts to execute after files are emitted at the end of the
* compilation. Defaults to [].
* Scripts to execute after files are emitted at the end of the compilation.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onBuildEnd?: Tasks | string | Function;
/** Scripts to execute after Webpack's process completes. Defaults to []. */
/**
* Scripts to execute after Webpack's process completes.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onBuildExit?: Tasks | string | Function;
/** Scripts to execute after Webpack's process Error. Defaults to []. */
/**
* Scripts to execute after a build error occurs.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onBuildError?: Tasks | string | Function;
/** Scripts to execute after onWatchRun. Defaults to []. */
/**
* Scripts to execute before each watch run.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onWatchRun?: Tasks | string | Function;
/** Scripts to execute after files are emitted at the end with watch. Defaults to []. */
/**
* Scripts to execute after files are emitted at the end of each watch cycle.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onDoneWatch?: Tasks | string | Function;
/** Scripts to execute after done. Defaults to []. */
/**
* Scripts to execute after the entire Webpack process is done.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onAfterDone?: Tasks | string | Function;
/**
* Scripts to execute before the compilation process starts.
* Can be a Tasks object, a single script string, or a function.
* Defaults to [].
*/
onBeforeCompile?: Tasks | string | Function;
/**
* Switch for development environments. This causes scripts to execute once.
* Useful for running HMR on webpack-dev-server or webpack watch mode.
* Defaults to true.
*/
dev?: boolean;
/**
* Object with environment variables that will be applied to the executables
* Object with environment variables that will be applied to the executables.
*/
env?: any;
/**
Expand All @@ -48,17 +91,19 @@ export declare type Options = {
*/
safe?: boolean;
/**
* show log message
* Show log messages. Defaults to true.
*/
logging?: boolean;
/**
* ignore script errors (useful in watch mode)
* Ignore script errors (useful in watch mode). Defaults to false.
*/
swallowError?: boolean;
/**
* run command in shell. Default: true
* Run command in shell. Defaults to true.
*/
shell?: boolean;
/** DEPRECATED. Enable for verbose output. Defaults to false. */
/**
* DEPRECATED. Enable for verbose output. Defaults to false.
*/
verbose?: boolean;
};
Loading

0 comments on commit 0e97e0e

Please sign in to comment.