@rushstack/heft-webpack4-plugin 0.6.0-rc.2 → 0.6.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ import Watchpack, { type WatchOptions } from 'watchpack';
2
+ import type { Compiler, Plugin } from 'webpack';
3
+ export interface IPurgeable {
4
+ purge?: (changes: string[]) => void;
5
+ }
6
+ export interface IWatchCallback {
7
+ (err: Error | undefined, files: string[], dirs: string[], missing: string[], fileTimes: Map<string, number>, dirTimes: Map<string, number>, removals: Set<string>): void;
8
+ }
9
+ export interface IWatchUndelayedCallback {
10
+ (path: string, mtime: number): void;
11
+ }
12
+ export interface IWatch {
13
+ close(): void;
14
+ pause(): void;
15
+ getFileTimestamps(): Map<string, number>;
16
+ getContextTimestamps(): Map<string, number>;
17
+ }
18
+ export interface IWatchFileSystem {
19
+ watch(files: string[], directories: string[], missing: string[], startTime: number, options: WatchOptions, callback: IWatchCallback, callbackUndelayed: IWatchUndelayedCallback): IWatch;
20
+ }
21
+ export declare class DeferredWatchFileSystem implements IWatchFileSystem {
22
+ readonly inputFileSystem: IPurgeable;
23
+ readonly watcherOptions: WatchOptions;
24
+ watcher: Watchpack | undefined;
25
+ private readonly _onChange;
26
+ private _state;
27
+ constructor(inputFileSystem: IPurgeable, onChange: () => void);
28
+ flush(): boolean;
29
+ watch(files: string[], directories: string[], missing: string[], startTime: number, options: WatchOptions, callback: IWatchCallback, callbackUndelayed: IWatchUndelayedCallback): IWatch;
30
+ }
31
+ export declare class OverrideNodeWatchFSPlugin implements Plugin {
32
+ readonly fileSystems: Set<DeferredWatchFileSystem>;
33
+ private readonly _onChange;
34
+ constructor(onChange: () => void);
35
+ apply(compiler: Compiler): void;
36
+ }
37
+ //# sourceMappingURL=DeferredWatchFileSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeferredWatchFileSystem.d.ts","sourceRoot":"","sources":["../src/DeferredWatchFileS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;IAC5C,SAAgB,cAAc,EAAE,YAAY,CAAC;IACtC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAEtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,MAAM,CAA0B;gBAErB,eAAe,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI;IAS7D,KAAK,IAAI,OAAO;IA0ChB,KAAK,CACV,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,cAAc,EACxB,iBAAiB,EAAE,uBAAuB,GACzC,MAAM;CAiEV;AAED,qBAAa,yBAA0B,YAAW,MAAM;IACtD,SAAgB,WAAW,EAAE,GAAG,CAAC,uBAAuB,CAAC,CAAa;IACtE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;gBAEpB,QAAQ,EAAE,MAAM,IAAI;IAIhC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAQvC"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.OverrideNodeWatchFSPlugin = exports.DeferredWatchFileSystem = void 0;
9
+ const watchpack_1 = __importDefault(require("watchpack"));
10
+ function* contains(source, collection) {
11
+ for (const item of source) {
12
+ if (collection.has(item)) {
13
+ yield item;
14
+ }
15
+ }
16
+ }
17
+ class DeferredWatchFileSystem {
18
+ constructor(inputFileSystem, onChange) {
19
+ this.inputFileSystem = inputFileSystem;
20
+ this.watcherOptions = {
21
+ aggregateTimeout: 0
22
+ };
23
+ this.watcher = new watchpack_1.default(this.watcherOptions);
24
+ this._onChange = onChange;
25
+ }
26
+ flush() {
27
+ var _a, _b;
28
+ const state = this._state;
29
+ if (!state) {
30
+ return false;
31
+ }
32
+ const { files, dirs, missing, changes, removals, callback } = state;
33
+ const { changes: aggregatedChanges, removals: aggregatedRemovals } = this.watcher.getAggregated();
34
+ // Webpack 4 treats changes as a superset of removals
35
+ for (const removal of aggregatedRemovals) {
36
+ changes.add(removal);
37
+ removals.add(removal);
38
+ }
39
+ for (const change of aggregatedChanges) {
40
+ removals.delete(change);
41
+ changes.add(change);
42
+ }
43
+ if (changes.size > 0) {
44
+ (_b = (_a = this.inputFileSystem).purge) === null || _b === void 0 ? void 0 : _b.call(_a, Array.from(changes));
45
+ const filteredRemovals = new Set(contains(removals, files));
46
+ const changedFiles = Array.from(contains(changes, files)).sort();
47
+ const changedDirs = Array.from(contains(changes, dirs)).sort();
48
+ const changedMissing = Array.from(contains(changes, missing)).sort();
49
+ const times = new Map(Object.entries(this.watcher.getTimes()));
50
+ callback(undefined, changedFiles, changedDirs, changedMissing, times, times, filteredRemovals);
51
+ changes.clear();
52
+ removals.clear();
53
+ return true;
54
+ }
55
+ return false;
56
+ }
57
+ watch(files, directories, missing, startTime, options, callback, callbackUndelayed) {
58
+ const oldWatcher = this.watcher;
59
+ const watcher = (this.watcher = new watchpack_1.default(options));
60
+ const changes = new Set();
61
+ const removals = new Set();
62
+ this._state = {
63
+ files: new Set(files),
64
+ dirs: new Set(directories),
65
+ missing: new Set(missing),
66
+ changes,
67
+ removals,
68
+ callback
69
+ };
70
+ watcher.once('aggregated', (newChanges, newRemovals) => {
71
+ watcher.pause();
72
+ for (const change of newChanges) {
73
+ changes.add(change);
74
+ }
75
+ for (const removal of newRemovals) {
76
+ changes.add(removal);
77
+ removals.add(removal);
78
+ }
79
+ this._onChange();
80
+ });
81
+ watcher.watch({
82
+ files,
83
+ directories,
84
+ missing,
85
+ startTime
86
+ });
87
+ if (oldWatcher) {
88
+ oldWatcher.close();
89
+ }
90
+ return {
91
+ close: () => {
92
+ if (this.watcher) {
93
+ this.watcher.close();
94
+ this.watcher = undefined;
95
+ }
96
+ },
97
+ pause: () => {
98
+ if (this.watcher) {
99
+ this.watcher.pause();
100
+ }
101
+ },
102
+ getFileTimestamps: () => {
103
+ var _a;
104
+ const timestamps = (_a = this.watcher) === null || _a === void 0 ? void 0 : _a.getTimes();
105
+ return timestamps ? new Map(Object.entries(timestamps)) : new Map();
106
+ },
107
+ getContextTimestamps: () => {
108
+ var _a;
109
+ const timestamps = (_a = this.watcher) === null || _a === void 0 ? void 0 : _a.getTimes();
110
+ return timestamps ? new Map(Object.entries(timestamps)) : new Map();
111
+ }
112
+ };
113
+ }
114
+ }
115
+ exports.DeferredWatchFileSystem = DeferredWatchFileSystem;
116
+ class OverrideNodeWatchFSPlugin {
117
+ constructor(onChange) {
118
+ this.fileSystems = new Set();
119
+ this._onChange = onChange;
120
+ }
121
+ apply(compiler) {
122
+ const watchFileSystem = new DeferredWatchFileSystem(compiler.inputFileSystem, this._onChange);
123
+ this.fileSystems.add(watchFileSystem);
124
+ compiler.watchFileSystem = watchFileSystem;
125
+ }
126
+ }
127
+ exports.OverrideNodeWatchFSPlugin = OverrideNodeWatchFSPlugin;
128
+ //# sourceMappingURL=DeferredWatchFileSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeferredWatchFileSystem.js","sourceRoot":"","sources":["../src/DeferredWatchFileSystem.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DAAyD;AA8BzD,QAAQ,CAAC,CAAC,QAAQ,CAAI,MAAmB,EAAE,UAA0B;IACnE,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACxB,MAAM,IAAI,CAAC;SACZ;KACF;AACH,CAAC;AAyBD,MAAa,uBAAuB;IAQlC,YAAmB,eAA2B,EAAE,QAAoB;QAClE,IAAI,CAAC,eA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,CAAC;gBAChF,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;YACtE,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AApID,0DAoIC;AAED,MAAa,yBAAyB;IAIpC,YAAmB,QAAoB;QAHvB,gBAAW,GAAiC,IAAI,GAAG,EAAE,CAAC;QAIpE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,QAAkB;QAC7B,MAAM,eAAe,GAA4B,IAAI,uBAAuB,CAC1E,QAAQ,CAAC,eAAe,EACxB,IAAI,CAAC,SAAS,CACf,CAAC;QACF,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACrC,QAAmD,CAAC,eAAe,GAAG,eAAe,CAAC;IACzF,CAAC;CACF;AAhBD,8DAgBC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport Watchpack, { type WatchOptions } from 'watchpack';\nimport type { Compiler, Plugin } from 'webpack';\n\nexport interface IPurgeable {\n purge?: (changes: string[]) => void;\n}\n\nexport interface IWatchCallback {\n (\n err: Error | undefined,\n files: string[],\n dirs: string[],\n missing: string[],\n fileTimes: Map<string, number>,\n dirTimes: Map<string, number>,\n removals: Set<string>\n ): void;\n}\n\nexport interface IWatchUndelayedCallback {\n (path: string, mtime: number): void;\n}\n\nexport interface IWatch {\n close(): void;\n pause(): void;\n getFileTimestamps(): Map<string, number>;\n getContextTimestamps(): Map<string, number>;\n}\n\nfunction* contains<T>(source: Iterable<T>, collection: ReadonlySet<T>): IterableIterator<T> {\n for (const item of source) {\n if (collection.has(item)) {\n yield item;\n }\n }\n}\n\ninterface IWatchState {\n files: Set<string>;\n dirs: Set<string>;\n missing: Set<string>;\n\n changes: Set<string>;\n removals: Set<string>;\n\n callback: IWatchCallback;\n}\n\nexport interface IWatchFileSystem {\n watch(\n files: string[],\n directories: string[],\n missing: string[],\n startTime: number,\n options: WatchOptions,\n callback: IWatchCallback,\n callbackUndelayed: IWatchUndelayedCallback\n ): IWatch;\n}\n\nexport class DeferredWatchFileSystem implements IWatchFileSystem {\n public readonly inputFileSystem: IPurgeable;\n public readonly watcherOptions: WatchOptions;\n public watcher: Watchpack | undefined;\n\n private readonly _onChange: () => void;\n private _state: IWatchState | undefined;\n\n public constructor(inputFileSystem: IPurgeable, onChange: () => void) {\n this.inputFileSystem = inputFileSystem;\n this.watcherOptions = {\n aggregateTimeout: 0\n };\n this.watcher = new Watchpack(this.watcherOptions);\n this._onChange = onChange;\n }\n\n public flush(): boolean {\n const state: IWatchState | undefined = this._state;\n\n if (!state) {\n return false;\n }\n\n const { files, dirs, missing, changes, removals, callback } = state;\n\n const { changes: aggregatedChanges, removals: aggregatedRemovals } = this.watcher!.getAggregated();\n\n // Webpack 4 treats changes as a superset of removals\n for (const removal of aggregatedRemovals) {\n changes.add(removal);\n removals.add(removal);\n }\n for (const change of aggregatedChanges) {\n removals.delete(change);\n changes.add(change);\n }\n\n if (changes.size > 0) {\n this.inputFileSystem.purge?.(Array.from(changes));\n\n const filteredRemovals: Set<string> = new Set(contains(removals, files));\n const changedFiles: string[] = Array.from(contains(changes, files)).sort();\n const changedDirs: string[] = Array.from(contains(changes, dirs)).sort();\n const changedMissing: string[] = Array.from(contains(changes, missing)).sort();\n\n const times: Map<string, number> = new Map(Object.entries(this.watcher!.getTimes()));\n\n callback(undefined, changedFiles, changedDirs, changedMissing, times, times, filteredRemovals);\n\n changes.clear();\n removals.clear();\n\n return true;\n }\n\n return false;\n }\n\n public watch(\n files: string[],\n directories: string[],\n missing: string[],\n startTime: number,\n options: WatchOptions,\n callback: IWatchCallback,\n callbackUndelayed: IWatchUndelayedCallback\n ): IWatch {\n const oldWatcher: Watchpack | undefined = this.watcher;\n const watcher: Watchpack = (this.watcher = new Watchpack(options));\n\n const changes: Set<string> = new Set();\n const removals: Set<string> = new Set();\n\n this._state = {\n files: new Set(files),\n dirs: new Set(directories),\n missing: new Set(missing),\n\n changes,\n removals,\n\n callback\n };\n\n watcher.once('aggregated', (newChanges: Set<string>, newRemovals: Set<string>) => {\n watcher.pause();\n\n for (const change of newChanges) {\n changes.add(change);\n }\n for (const removal of newRemovals) {\n changes.add(removal);\n removals.add(removal);\n }\n\n this._onChange();\n });\n\n watcher.watch({\n files,\n directories,\n missing,\n startTime\n });\n\n if (oldWatcher) {\n oldWatcher.close();\n }\n\n return {\n close: () => {\n if (this.watcher) {\n this.watcher.close();\n this.watcher = undefined;\n }\n },\n pause: () => {\n if (this.watcher) {\n this.watcher.pause();\n }\n },\n getFileTimestamps: () => {\n const timestamps: Record<string, number> | undefined = this.watcher?.getTimes();\n return timestamps ? new Map(Object.entries(timestamps)) : new Map();\n },\n getContextTimestamps: () => {\n const timestamps: Record<string, number> | undefined = this.watcher?.getTimes();\n return timestamps ? new Map(Object.entries(timestamps)) : new Map();\n }\n };\n }\n}\n\nexport class OverrideNodeWatchFSPlugin implements Plugin {\n public readonly fileSystems: Set<DeferredWatchFileSystem> = new Set();\n private readonly _onChange: () => void;\n\n public constructor(onChange: () => void) {\n this._onChange = onChange;\n }\n\n public apply(compiler: Compiler): void {\n const watchFileSystem: DeferredWatchFileSystem = new DeferredWatchFileSystem(\n compiler.inputFileSystem,\n this._onChange\n );\n this.fileSystems.add(watchFileSystem);\n (compiler as { watchFileSystem?: IWatchFileSystem }).watchFileSystem = watchFileSystem;\n }\n}\n"]}
@@ -17,9 +17,11 @@ export default class Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOpt
17
17
  private _webpack;
18
18
  private _webpackCompiler;
19
19
  private _webpackConfiguration;
20
- private _webpackWatchers;
21
20
  private _webpackCompilationDonePromise;
22
21
  private _webpackCompilationDonePromiseResolveFn;
22
+ private _watchFileSystems;
23
+ private _warnings;
24
+ private _errors;
23
25
  get accessor(): IWebpackPluginAccessor;
24
26
  apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration, options: IWebpackPluginOptions): void;
25
27
  private _getWebpackConfigurationAsync;
@@ -29,5 +31,6 @@ export default class Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOpt
29
31
  private _runWebpackWatchAsync;
30
32
  private _validateEnvironmentVariable;
31
33
  private _emitErrors;
34
+ private _recordErrors;
32
35
  }
33
36
  //# sourceMappingURL=Webpack4Plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Webpack4Plugin.d.ts","sourceRoot":"","sources":["../src/Webpack4Plugin.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAyB,sBAAsB,EAAE,MAAM,UAAU,CAAC;AA8B9E,MAAM,WAAW,qBAAqB;IACpC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,iBAAqC,CAAC;AAQhE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,eAAe,CAAC,qBAAqB,CAAC;IACnF,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,gBAAgB,CAAuD;IAC/E,OAAO,CAAC,qBAAqB,CAA2E;IACxG,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,8BAA8B,CAA4B;IAClE,OAAO,CAAC,uCAAuC,CAA2B;IAE1E,IAAW,QAAQ,IAAI,sBAAsB,CAe5C;IAEM,KAAK,CACV,WAAW,EAAE,gBAAgB,EAC7B,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,EAAE,qBAAqB,GAC7B,IAAI;YAsBO,6B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AAW;IASnB,OAAO,CAAC,aAAa;CAwBtB"}
@@ -30,6 +30,7 @@ const tapable_1 = require("tapable");
30
30
  const debug_certificate_manager_1 = require("@rushstack/debug-certificate-manager");
31
31
  const node_core_library_1 = require("@rushstack/node-core-library");
32
32
  const WebpackConfigurationLoader_1 = require("./WebpackConfigurationLoader");
33
+ const DeferredWatchFileSystem_1 = require("./DeferredWatchFileSystem");
33
34
  /**
34
35
  * @public
35
36
  */
@@ -47,6 +48,8 @@ class Webpack4Plugin {
47
48
  constructor() {
48
49
  this._isServeMode = false;
49
50
  this._webpackConfiguration = UNINITIALIZED;
51
+ this._warnings = [];
52
+ this._errors = [];
50
53
  }
51
54
  get accessor() {
52
55
  if (!this._accessor) {
@@ -73,10 +76,10 @@ class Webpack4Plugin {
73
76
  await this._runWebpackAsync(taskSession, heftConfiguration, options);
74
77
  });
75
78
  taskSession.hooks.runIncremental.tapPromise(exports.PLUGIN_NAME, async (runOptions) => {
76
- await this._runWebpackWatchAsync(taskSession, heftConfiguration, options);
79
+ await this._runWebpackWatchAsync(taskSession, heftConfiguration, options, runOptions.requestRun);
77
80
  });
78
81
  }
79
- async _getWebpackConfigurationAsync(taskSession, heftConfiguration, options) {
82
+ async _getWebpackConfigurationAsync(taskSession, heftConfiguration, options, requestRun) {
80
83
  if (this._webpackConfiguration === UNINITIALIZED) {
81
84
  // Obtain the webpack configuration by calling into the hook. If undefined
82
85
  // is returned, load the default Webpack configuration.
@@ -107,6 +110,20 @@ class Webpack4Plugin {
107
110
  await this.accessor.hooks.onAfterConfigure.promise(webpackConfiguration);
108
111
  }
109
112
  this._webpackConfiguration = webpackConfiguration;
113
+ if (requestRun) {
114
+ const overrideWatchFSPlugin = new DeferredWatchFileSystem_1.OverrideNodeWatchFSPlugin(requestRun);
115
+ this._watchFileSystems = overrideWatchFSPlugin.fileSystems;
116
+ for (const config of Array.isArray(webpackConfiguration)
117
+ ? webpackConfiguration
118
+ : [webpackConfiguration]) {
119
+ if (!config.plugins) {
120
+ config.plugins = [overrideWatchFSPlugin];
121
+ }
122
+ else {
123
+ config.plugins.unshift(overrideWatchFSPlugin);
124
+ }
125
+ }
126
+ }
110
127
  }
111
128
  }
112
129
  return this._webpackConfiguration;
@@ -151,25 +168,28 @@ class Webpack4Plugin {
151
168
  }
152
169
  // Emit the errors from the stats object, if present
153
170
  if (stats) {
154
- this._emitErrors(taskSession.logger, stats);
171
+ this._recordErrors(stats);
155
172
  if (this.accessor.hooks.onEmitStats.isUsed()) {
156
173
  await this.accessor.hooks.onEmitStats.promise(stats);
157
174
  }
175
+ this._emitErrors(taskSession.logger);
158
176
  }
159
177
  }
160
- async _runWebpackWatchAsync(taskSession, heftConfiguration, options) {
161
- var _a, _b;
178
+ async _runWebpackWatchAsync(taskSession, heftConfiguration, options, requestRun) {
179
+ var _a;
162
180
  // Save a handle to the original promise, since the this-scoped promise will be replaced whenever
163
181
  // the compilation completes.
164
182
  let webpackCompilationDonePromise = this._webpackCompilationDonePromise;
165
- if (!this._webpackWatchers) {
183
+ let isInitial = false;
184
+ if (!this._webpackCompiler) {
185
+ isInitial = true;
166
186
  this._validateEnvironmentVariable(taskSession);
167
187
  if (!taskSession.parameters.watch) {
168
188
  // Should never happen, but just in case
169
189
  throw new node_core_library_1.InternalError('Cannot run Webpack in watch mode when compilation mode is enabled');
170
190
  }
171
191
  // Load the config and compiler, and return if there is no config found
172
- const webpackConfiguration = await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options);
192
+ const webpackConfiguration = await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options, requestRun);
173
193
  if (!webpackConfiguration) {
174
194
  return;
175
195
  }
@@ -187,17 +207,9 @@ class Webpack4Plugin {
187
207
  this._webpackCompilationDonePromiseResolveFn = resolve;
188
208
  });
189
209
  if (stats) {
190
- this._emitErrors(taskSession.logger, stats);
210
+ this._recordErrors(stats);
191
211
  }
192
212
  });
193
- // TWebpack.Compiler and TWebpack.MultiCompiler in Webpack 4 do not allow you to access the running
194
- // watcher, so we need to patch the method to set the watcher on the parent object.
195
- const originalWatch = compiler.watch.bind(compiler);
196
- compiler.watch = (watchOptions, handler) => {
197
- const watcher = originalWatch(watchOptions, handler);
198
- compiler.watching = watcher;
199
- return watcher;
200
- };
201
213
  // Determine how we will run the compiler. When serving, we will run the compiler
202
214
  // via the webpack-dev-server. Otherwise, we will run the compiler directly.
203
215
  if (this._isServeMode) {
@@ -295,20 +307,25 @@ class Webpack4Plugin {
295
307
  }
296
308
  });
297
309
  }
298
- // Store the watchers to be used for suspend/resume
299
- this._webpackWatchers = ((_b = compiler.compilers) !== null && _b !== void 0 ? _b : [compiler]).map((compiler) => compiler.watching);
310
+ }
311
+ let hasChanges = true;
312
+ if (!isInitial && this._watchFileSystems) {
313
+ hasChanges = false;
314
+ for (const watchFileSystem of this._watchFileSystems) {
315
+ hasChanges = watchFileSystem.flush() || hasChanges;
316
+ }
300
317
  }
301
318
  // Resume the compilation, wait for the compilation to complete, then suspend the watchers until the
302
319
  // next iteration. Even if there are no changes, the promise should resolve since resuming from a
303
320
  // suspended state invalidates the state of the watcher.
304
- taskSession.logger.terminal.writeLine('Running incremental Webpack compilation');
305
- for (const watcher of this._webpackWatchers) {
306
- watcher.resume();
321
+ if (hasChanges) {
322
+ taskSession.logger.terminal.writeLine('Running incremental Webpack compilation');
323
+ await webpackCompilationDonePromise;
307
324
  }
308
- await webpackCompilationDonePromise;
309
- for (const watcher of this._webpackWatchers) {
310
- watcher.suspend();
325
+ else {
326
+ taskSession.logger.terminal.writeLine('Webpack has not detected changes. Listing previous diagnostics.');
311
327
  }
328
+ this._emitErrors(taskSession.logger);
312
329
  }
313
330
  _validateEnvironmentVariable(taskSession) {
314
331
  if (!this._isServeMode && process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {
@@ -317,14 +334,31 @@ class Webpack4Plugin {
317
334
  `(Did a dependency inadvertently load the "${WEBPACK_DEV_SERVER_PACKAGE_NAME}" package?)`));
318
335
  }
319
336
  }
320
- _emitErrors(logger, stats) {
337
+ _emitErrors(logger) {
338
+ for (const warning of this._warnings) {
339
+ logger.emitWarning(warning);
340
+ }
341
+ for (const error of this._errors) {
342
+ logger.emitError(error);
343
+ }
344
+ }
345
+ _recordErrors(stats) {
346
+ this._errors.length = 0;
347
+ this._warnings.length = 0;
321
348
  if (stats.hasErrors() || stats.hasWarnings()) {
322
- const serializedStats = stats.toJson('errors-warnings');
323
- for (const warning of serializedStats.warnings) {
324
- logger.emitWarning(warning instanceof Error ? warning : new Error(warning));
325
- }
326
- for (const error of serializedStats.errors) {
327
- logger.emitError(error instanceof Error ? error : new Error(error));
349
+ const serializedStats = [stats.toJson('errors-warnings')];
350
+ for (const compilationStats of serializedStats) {
351
+ for (const warning of compilationStats.warnings) {
352
+ this._warnings.push(warning instanceof Error ? warning : new Error(warning));
353
+ }
354
+ for (const error of compilationStats.errors) {
355
+ this._errors.push(error instanceof Error ? error : new Error(error));
356
+ }
357
+ if (compilationStats.children) {
358
+ for (const child of compilationStats.children) {
359
+ serializedStats.push(child);
360
+ }
361
+ }
328
362
  }
329
363
  }
330
364
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Webpack4Plugin.js","sourceRoot":"","sources":["../src/Webpack4Plugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAK3D,qCAAqG;AACrG,oFAA6F;AAC7F,oEAA6E;AAW7E,6EAA0E;AAkC1E;;GAEG;AACU,QAAA,WAAW,GAAsB,iBAAiB,CAAC;AAChE,MAAM,yBAAyB,GAAc,SAAS,CAAC;AACvD,MAAM,oBAAoB,GAAc,SAAS,CAAC;AAClD,MAAM,+BAA+B,GAAyB,oBAAoB,CAAC;AACnF,MAAM,+BAA+B,GAAyB,oBAAoB,CAAC;AACnF,MAAM,mCAAmC,GAA6B,wBAAwB,CAAC;AAC/F,MAAM,aAAa,GAAoB,eAAe,CAAC;AAEvD;;GAEG;AACH,MAAqB,cAAc;IAAnC;QAEU,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M,CAAC,WAAW,CAAC,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;aAC7E;YAED,KAAK,MAAM,KAAK,IAAI,eAAe,CAAC,MAA4B,EAAE;gBAChE,MAAM,CAAC,SAAS,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;aACrE;SACF;IACH,CAAC;CACF;AAvYD,iCAuYC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { AddressInfo } from 'net';\nimport type * as TWebpack from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, type SyncBailHook } from 'tapable';\nimport { CertificateManager, type ICertificate } from '@rushstack/debug-certificate-manager';\nimport { InternalError, LegacyAdapters } from '@rushstack/node-core-library';\nimport type {\n HeftConfiguration,\n IHeftTaskSession,\n IHeftTaskPlugin,\n IHeftTaskRunHookOptions,\n IScopedLogger,\n IHeftTaskRunIncrementalHookOptions\n} from '@rushstack/heft';\n\nimport type { IWebpackConfiguration, IWebpackPluginAccessor } from './shared';\nimport { WebpackConfigurationLoader } from './WebpackConfigurationLoader';\n\ntype ExtendedWatching = TWebpack.Watching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedMultiWatching = TWebpack.MultiWatching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedCompiler = TWebpack.Compiler & {\n hooks: TWebpack.Compiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedWatching;\n};\n\ntype ExtendedMultiCompiler = TWebpack.MultiCompiler & {\n compilers: ExtendedCompiler[];\n hooks: TWebpack.MultiCompiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedMultiWatching;\n};\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath: string | undefined;\n configurationPath: string | undefined;\n}\n\n/**\n * @public\n */\nexport const PLUGIN_NAME: 'webpack4-plugin' = 'webpack4-plugin';\nconst SERVE_PARAMETER_LONG_NAME: '--serve' = '--serve';\nconst WEBPACK_PACKAGE_NAME: 'webpack' = 'webpack';\nconst WEBPACK_DEV_SERVER_PACKAGE_NAME: 'webpack-dev-server' = 'webpack-dev-server';\nconst WEBPACK_DEV_SERVER_ENV_VAR_NAME: 'WEBPACK_DEV_SERVER' = 'WEBPACK_DEV_SERVER';\nconst WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME: 'webpack-dev-middleware' = 'webpack-dev-middleware';\nconst UNINITIALIZED: 'UNINITIALIZED' = 'UNINITIALIZED';\n\n/**\n * @internal\n */\nexport default class Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOptions> {\n private _accessor: IWebpackPluginAccessor | undefined;\n private _isServeMode: boolean = false;\n private _webpack: typeof TWebpack | undefined;\n private _webpackCompiler: ExtendedCompiler | ExtendedMultiCompiler | undefined;\n private _webpackConfiguration: IWebpackConfiguration | undefined | typeof UNINITIALIZED = UNINITIALIZED;\n private _webpackWatchers: ExtendedWatching[] | undefined;\n private _webpackCompilationDonePromise: Promise<void> | undefined;\n private _webpackCompilationDonePromiseResolveFn: (() => void) | undefined;\n\n public get accessor(): IWebpackPluginAccessor {\n if (!this._accessor) {\n this._accessor = {\n hooks: {\n onLoadConfiguration: new AsyncSeriesBailHook(),\n onConfigure: new AsyncSeriesHook(['webpackConfiguration']),\n onAfterConfigure: new AsyncParallelHook(['webpackConfiguration']),\n onEmitStats: new AsyncParallelHook(['webpackStats'])\n },\n parameters: {\n isServeMode: this._isServeMode\n }\n };\n }\n return this._accessor;\n }\n\n public apply(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): void {\n this._isServeMode = taskSession.parameters.getFlagParameter(SERVE_PARAMETER_LONG_NAME).value;\n if (!taskSession.parameters.watch && this._isServeMode) {\n throw new Error(\n `The ${JSON.stringify(\n SERVE_PARAMETER_LONG_NAME\n )} parameter is only available when running in watch mode.`\n );\n }\n\n taskSession.hooks.run.tapPromise(PLUGIN_NAME, async (runOptions: IHeftTaskRunHookOptions) => {\n await this._runWebpackAsync(taskSession, heftConfiguration, options);\n });\n\n taskSession.hooks.runIncremental.tapPromise(\n PLUGIN_NAME,\n async (runOptions: IHeftTaskRunIncrementalHookOptions) => {\n await this._runWebpackWatchAsync(taskSession, heftConfiguration, options);\n }\n );\n }\n\n private async _getWebpackConfigurationAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): Promise<IWebpackConfiguration | undefined> {\n if (this._webpackConfiguration === UNINITIALIZED) {\n // Obtain the webpack configuration by calling into the hook. If undefined\n // is returned, load the default Webpack configuration.\n taskSession.logger.terminal.writeVerboseLine(\n 'Attempting to load Webpack configuration via external plugins'\n );\n let webpackConfiguration: IWebpackConfiguration | false | undefined =\n await this.accessor.hooks.onLoadConfiguration.promise();\n if (webpackConfiguration === undefined) {\n taskSession.logger.terminal.writeVerboseLine('Attempt to load the default Webpack configuration');\n const configurationLoader: WebpackConfigurationLoader = new WebpackConfigurationLoader(\n taskSession.logger,\n taskSession.parameters.production,\n taskSession.parameters.watch && this._isServeMode\n );\n webpackConfiguration = await configurationLoader.tryLoadWebpackConfigurationAsync({\n ...options,\n taskSession,\n heftConfiguration,\n loadWebpackAsyncFn: this._loadWebpackAsync.bind(this)\n });\n }\n\n if (webpackConfiguration === false) {\n taskSession.logger.terminal.writeLine('Webpack disabled by external plugin');\n this._webpackConfiguration = undefined;\n } else if (\n webpackConfiguration === undefined ||\n (Array.isArray(webpackConfiguration) && webpackConfiguration.length === 0)\n ) {\n taskSession.logger.terminal.writeLine('No Webpack configuration found');\n this._webpackConfiguration = undefined;\n } else {\n if (this.accessor.hooks.onConfigure.isUsed()) {\n // Allow for plugins to customise the configuration\n await this.accessor.hooks.onConfigure.promise(webpackConfiguration);\n }\n if (this.accessor.hooks.onAfterConfigure.isUsed()) {\n // Provide the finalized configuration\n await this.accessor.hooks.onAfterConfigure.promise(webpackConfiguration);\n }\n this._webpackConfiguration = webpackConfiguration;\n }\n }\n return this._webpackConfiguration;\n }\n\n private async _loadWebpackAsync(): Promise<typeof TWebpack> {\n if (!this._webpack) {\n // Allow this to fail if webpack is not installed\n this._webpack = await import(WEBPACK_PACKAGE_NAME);\n }\n return this._webpack!;\n }\n\n private async _getWebpackCompilerAsync(\n taskSession: IHeftTaskSession,\n webpackConfiguration: IWebpackConfiguration\n ): Promise<ExtendedCompiler | ExtendedMultiCompiler> {\n if (!this._webpackCompiler) {\n const webpack: typeof TWebpack = await this._loadWebpackAsync();\n taskSession.logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);\n this._webpackCompiler = Array.isArray(webpackConfiguration)\n ? (webpack.default(\n webpackConfiguration\n ) as ExtendedMultiCompiler) /* (webpack.Compilation[]) => MultiCompiler */\n : (webpack.default(webpackConfiguration) as ExtendedCompiler); /* (webpack.Compilation) => Compiler */\n }\n return this._webpackCompiler;\n }\n\n private async _runWebpackAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): Promise<void> {\n this._validateEnvironmentVariable(taskSession);\n if (taskSession.parameters.watch || this._isServeMode) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in compilation mode when watch mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined = await this._getWebpackConfigurationAsync(\n taskSession,\n heftConfiguration,\n options\n );\n if (!webpackConfiguration) {\n return;\n }\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n taskSession.logger.terminal.writeLine('Running Webpack compilation');\n\n // Run the webpack compiler\n let stats: TWebpack.Stats | TWebpack.MultiStats | undefined;\n try {\n stats = await LegacyAdapters.convertCallbackToPromise(\n (compiler as TWebpack.Compiler).run.bind(compiler)\n );\n } catch (e) {\n taskSession.logger.emitError(e as Error);\n }\n\n // Emit the errors from the stats object, if present\n if (stats) {\n this._emitErrors(taskSession.logger, stats);\n if (this.accessor.hooks.onEmitStats.isUsed()) {\n await this.accessor.hooks.onEmitStats.promise(stats);\n }\n }\n }\n\n private async _runWebpackWatchAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): Promise<void> {\n // Save a handle to the original promise, since the this-scoped promise will be replaced whenever\n // the compilation completes.\n let webpackCompilationDonePromise: Promise<void> | undefined = this._webpackCompilationDonePromise;\n\n if (!this._webpackWatchers) {\n this._validateEnvironmentVariable(taskSession);\n if (!taskSession.parameters.watch) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in watch mode when compilation mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined =\n await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options);\n if (!webpackConfiguration) {\n return;\n }\n\n // Get the compiler which will be used for both serve and watch mode\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n\n // Set up the hook to detect when the watcher completes the watcher compilation. We will also log out\n // errors from the compilation if present from the output stats object.\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n webpackCompilationDonePromise = this._webpackCompilationDonePromise;\n compiler.hooks.done.tap(PLUGIN_NAME, (stats?: TWebpack.Stats | TWebpack.MultiStats) => {\n this._webpackCompilationDonePromiseResolveFn!();\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n if (stats) {\n this._emitErrors(taskSession.logger, stats);\n }\n });\n\n // TWebpack.Compiler and TWebpack.MultiCompiler in Webpack 4 do not allow you to access the running\n // watcher, so we need to patch the method to set the watcher on the parent object.\n const originalWatch: TWebpack.Compiler['watch'] | TWebpack.MultiCompiler['watch'] =\n compiler.watch.bind(compiler);\n compiler.watch = (\n watchOptions: TWebpack.ICompiler.WatchOptions,\n handler: TWebpack.ICompiler.Handler & TWebpack.ICompiler.MultiHandler\n ) => {\n const watcher: ExtendedWatching | ExtendedMultiWatching = originalWatch(watchOptions, handler) as\n | ExtendedWatching\n | ExtendedMultiWatching;\n compiler.watching = watcher;\n return watcher;\n };\n\n // Determine how we will run the compiler. When serving, we will run the compiler\n // via the webpack-dev-server. Otherwise, we will run the compiler directly.\n if (this._isServeMode) {\n const defaultDevServerOptions: TWebpackDevServer.Configuration = {\n host: 'localhost',\n devMiddleware: {\n publicPath: '/',\n stats: {\n cached: false,\n cachedAssets: false,\n colors: heftConfiguration.terminalProvider.supportsColor\n }\n },\n client: {\n logging: 'info',\n webSocketURL: {\n port: 8080\n }\n },\n port: 8080,\n onListening: (server: TWebpackDevServer) => {\n const addressInfo: AddressInfo | string | undefined = server.server?.address() as AddressInfo;\n if (addressInfo) {\n const address: string =\n typeof addressInfo === 'string' ? addressInfo : `${addressInfo.address}:${addressInfo.port}`;\n taskSession.logger.terminal.writeLine(`Started Webpack Dev Server at https://${address}`);\n }\n }\n };\n\n // Obtain the devServerOptions from the webpack configuration, and combine with the default options\n let devServerOptions: TWebpackDevServer.Configuration;\n if (Array.isArray(webpackConfiguration)) {\n const filteredDevServerOptions: TWebpackDevServer.Configuration[] = webpackConfiguration\n .map((configuration) => configuration.devServer)\n .filter((devServer): devServer is TWebpackDevServer.Configuration => !!devServer);\n if (filteredDevServerOptions.length > 1) {\n taskSession.logger.emitWarning(\n new Error(`Detected multiple webpack devServer configurations, using the first one.`)\n );\n }\n devServerOptions = { ...defaultDevServerOptions, ...filteredDevServerOptions[0] };\n } else {\n devServerOptions = { ...defaultDevServerOptions, ...webpackConfiguration.devServer };\n }\n\n // Add the certificate and key to the devServerOptions if these fields don't already have values\n if (!devServerOptions.server) {\n const certificateManager: CertificateManager = new CertificateManager();\n const certificate: ICertificate = await certificateManager.ensureCertificateAsync(\n true,\n taskSession.logger.terminal\n );\n\n // Update the web socket URL to use the hostname provided by the certificate\n const clientConfiguration: TWebpackDevServer.Configuration['client'] = devServerOptions.client;\n const hostname: string | undefined = certificate.subjectAltNames?.[0];\n if (hostname && typeof clientConfiguration === 'object') {\n const { webSocketURL } = clientConfiguration;\n if (typeof webSocketURL === 'object') {\n clientConfiguration.webSocketURL = {\n ...webSocketURL,\n hostname\n };\n }\n }\n\n devServerOptions = {\n ...devServerOptions,\n server: {\n type: 'https',\n options: {\n minVersion: 'TLSv1.3',\n key: certificate.pemKey,\n cert: certificate.pemCertificate,\n ca: certificate.pemCaCertificate\n }\n }\n };\n }\n\n // Since the webpack-dev-server does not return infrastructure errors via a callback like\n // compiler.watch(...), we will need to intercept them and log them ourselves.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n compiler.hooks.infrastructureLog.tap(PLUGIN_NAME, (name: string, type: string, args: any[]) => {\n if (name === WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME && type === 'error') {\n const error: Error | undefined = args[0];\n if (error) {\n taskSession.logger.emitError(error);\n }\n }\n return true;\n });\n\n // The webpack-dev-server package has a design flaw, where merely loading its package will set the\n // WEBPACK_DEV_SERVER environment variable -- even if no APIs are accessed. This environment variable\n // causes incorrect behavior if Heft is not running in serve mode. Thus, we need to be careful to call\n // require() only if Heft is in serve mode.\n taskSession.logger.terminal.writeLine('Starting webpack-dev-server');\n const WebpackDevServer: typeof TWebpackDevServer = (await import(WEBPACK_DEV_SERVER_PACKAGE_NAME))\n .default;\n const webpackDevServer: TWebpackDevServer = new WebpackDevServer(devServerOptions, compiler);\n await webpackDevServer.start();\n } else {\n // Create the watcher. Compilation will start immediately after invoking watch().\n taskSession.logger.terminal.writeLine('Starting Webpack watcher');\n compiler.watch({}, (error?: Error | null) => {\n if (error) {\n taskSession.logger.emitError(error);\n }\n });\n }\n\n // Store the watchers to be used for suspend/resume\n this._webpackWatchers = (\n (compiler as ExtendedMultiCompiler).compilers ?? [compiler as ExtendedCompiler]\n ).map((compiler: ExtendedCompiler) => compiler.watching);\n }\n\n // Resume the compilation, wait for the compilation to complete, then suspend the watchers until the\n // next iteration. Even if there are no changes, the promise should resolve since resuming from a\n // suspended state invalidates the state of the watcher.\n taskSession.logger.terminal.writeLine('Running incremental Webpack compilation');\n for (const watcher of this._webpackWatchers) {\n watcher.resume();\n }\n await webpackCompilationDonePromise;\n for (const watcher of this._webpackWatchers) {\n watcher.suspend();\n }\n }\n\n private _validateEnvironmentVariable(taskSession: IHeftTaskSession): void {\n if (!this._isServeMode && process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {\n taskSession.logger.emitWarning(\n new Error(\n `The \"${WEBPACK_DEV_SERVER_ENV_VAR_NAME}\" environment variable is set, ` +\n 'which will cause problems when webpack is not running in serve mode. ' +\n `(Did a dependency inadvertently load the \"${WEBPACK_DEV_SERVER_PACKAGE_NAME}\" package?)`\n )\n );\n }\n }\n\n private _emitErrors(logger: IScopedLogger, stats: TWebpack.Stats | TWebpack.compilation.MultiStats): void {\n if (stats.hasErrors() || stats.hasWarnings()) {\n const serializedStats: TWebpack.Stats.ToJsonOutput = stats.toJson('errors-warnings');\n\n for (const warning of serializedStats.warnings as (string | Error)[]) {\n logger.emitWarning(warning instanceof Error ? warning : new Error(warning));\n }\n\n for (const error of serializedStats.errors as (string | Error)[]) {\n logger.emitError(error instanceof Error ? error : new Error(error));\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Webpack4Plugin.js","sourceRoot":"","sources":["../src/Webpack4Plugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;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I,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC9E;gBAED,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,MAA4B,EAAE;oBACjE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;iBACtE;gBAED,IAAI,gBAAgB,CAAC,QAAQ,EAAE;oBAC7B,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,QAAQ,EAAE;wBAC7C,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBAC7B;iBACF;aACF;SACF;IACH,CAAC;CACF;AAxaD,iCAwaC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { AddressInfo } from 'net';\nimport type * as TWebpack from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, type SyncBailHook } from 'tapable';\nimport { CertificateManager, type ICertificate } from '@rushstack/debug-certificate-manager';\nimport { InternalError, LegacyAdapters } from '@rushstack/node-core-library';\nimport type {\n HeftConfiguration,\n IHeftTaskSession,\n IHeftTaskPlugin,\n IHeftTaskRunHookOptions,\n IScopedLogger,\n IHeftTaskRunIncrementalHookOptions\n} from '@rushstack/heft';\n\nimport type { IWebpackConfiguration, IWebpackPluginAccessor } from './shared';\nimport { WebpackConfigurationLoader } from './WebpackConfigurationLoader';\nimport {\n DeferredWatchFileSystem,\n type IWatchFileSystem,\n OverrideNodeWatchFSPlugin\n} from './DeferredWatchFileSystem';\n\ntype ExtendedWatching = TWebpack.Watching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedMultiWatching = TWebpack.MultiWatching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedCompiler = TWebpack.Compiler & {\n hooks: TWebpack.Compiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedWatching;\n watchFileSystem: IWatchFileSystem;\n};\n\ntype ExtendedMultiCompiler = TWebpack.MultiCompiler & {\n compilers: ExtendedCompiler[];\n hooks: TWebpack.MultiCompiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedMultiWatching;\n};\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath: string | undefined;\n configurationPath: string | undefined;\n}\n\n/**\n * @public\n */\nexport const PLUGIN_NAME: 'webpack4-plugin' = 'webpack4-plugin';\nconst SERVE_PARAMETER_LONG_NAME: '--serve' = '--serve';\nconst WEBPACK_PACKAGE_NAME: 'webpack' = 'webpack';\nconst WEBPACK_DEV_SERVER_PACKAGE_NAME: 'webpack-dev-server' = 'webpack-dev-server';\nconst WEBPACK_DEV_SERVER_ENV_VAR_NAME: 'WEBPACK_DEV_SERVER' = 'WEBPACK_DEV_SERVER';\nconst WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME: 'webpack-dev-middleware' = 'webpack-dev-middleware';\nconst UNINITIALIZED: 'UNINITIALIZED' = 'UNINITIALIZED';\n\n/**\n * @internal\n */\nexport default class Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOptions> {\n private _accessor: IWebpackPluginAccessor | undefined;\n private _isServeMode: boolean = false;\n private _webpack: typeof TWebpack | undefined;\n private _webpackCompiler: ExtendedCompiler | ExtendedMultiCompiler | undefined;\n private _webpackConfiguration: IWebpackConfiguration | undefined | typeof UNINITIALIZED = UNINITIALIZED;\n private _webpackCompilationDonePromise: Promise<void> | undefined;\n private _webpackCompilationDonePromiseResolveFn: (() => void) | undefined;\n private _watchFileSystems: Set<DeferredWatchFileSystem> | undefined;\n\n private _warnings: Error[] = [];\n private _errors: Error[] = [];\n\n public get accessor(): IWebpackPluginAccessor {\n if (!this._accessor) {\n this._accessor = {\n hooks: {\n onLoadConfiguration: new AsyncSeriesBailHook(),\n onConfigure: new AsyncSeriesHook(['webpackConfiguration']),\n onAfterConfigure: new AsyncParallelHook(['webpackConfiguration']),\n onEmitStats: new AsyncParallelHook(['webpackStats'])\n },\n parameters: {\n isServeMode: this._isServeMode\n }\n };\n }\n return this._accessor;\n }\n\n public apply(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): void {\n this._isServeMode = taskSession.parameters.getFlagParameter(SERVE_PARAMETER_LONG_NAME).value;\n if (!taskSession.parameters.watch && this._isServeMode) {\n throw new Error(\n `The ${JSON.stringify(\n SERVE_PARAMETER_LONG_NAME\n )} parameter is only available when running in watch mode.`\n );\n }\n\n taskSession.hooks.run.tapPromise(PLUGIN_NAME, async (runOptions: IHeftTaskRunHookOptions) => {\n await this._runWebpackAsync(taskSession, heftConfiguration, options);\n });\n\n taskSession.hooks.runIncremental.tapPromise(\n PLUGIN_NAME,\n async (runOptions: IHeftTaskRunIncrementalHookOptions) => {\n await this._runWebpackWatchAsync(taskSession, heftConfiguration, options, runOptions.requestRun);\n }\n );\n }\n\n private async _getWebpackConfigurationAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions,\n requestRun?: () => void\n ): Promise<IWebpackConfiguration | undefined> {\n if (this._webpackConfiguration === UNINITIALIZED) {\n // Obtain the webpack configuration by calling into the hook. If undefined\n // is returned, load the default Webpack configuration.\n taskSession.logger.terminal.writeVerboseLine(\n 'Attempting to load Webpack configuration via external plugins'\n );\n let webpackConfiguration: IWebpackConfiguration | false | undefined =\n await this.accessor.hooks.onLoadConfiguration.promise();\n if (webpackConfiguration === undefined) {\n taskSession.logger.terminal.writeVerboseLine('Attempt to load the default Webpack configuration');\n const configurationLoader: WebpackConfigurationLoader = new WebpackConfigurationLoader(\n taskSession.logger,\n taskSession.parameters.production,\n taskSession.parameters.watch && this._isServeMode\n );\n webpackConfiguration = await configurationLoader.tryLoadWebpackConfigurationAsync({\n ...options,\n taskSession,\n heftConfiguration,\n loadWebpackAsyncFn: this._loadWebpackAsync.bind(this)\n });\n }\n\n if (webpackConfiguration === false) {\n taskSession.logger.terminal.writeLine('Webpack disabled by external plugin');\n this._webpackConfiguration = undefined;\n } else if (\n webpackConfiguration === undefined ||\n (Array.isArray(webpackConfiguration) && webpackConfiguration.length === 0)\n ) {\n taskSession.logger.terminal.writeLine('No Webpack configuration found');\n this._webpackConfiguration = undefined;\n } else {\n if (this.accessor.hooks.onConfigure.isUsed()) {\n // Allow for plugins to customise the configuration\n await this.accessor.hooks.onConfigure.promise(webpackConfiguration);\n }\n if (this.accessor.hooks.onAfterConfigure.isUsed()) {\n // Provide the finalized configuration\n await this.accessor.hooks.onAfterConfigure.promise(webpackConfiguration);\n }\n this._webpackConfiguration = webpackConfiguration;\n\n if (requestRun) {\n const overrideWatchFSPlugin: OverrideNodeWatchFSPlugin = new OverrideNodeWatchFSPlugin(requestRun);\n this._watchFileSystems = overrideWatchFSPlugin.fileSystems;\n for (const config of Array.isArray(webpackConfiguration)\n ? webpackConfiguration\n : [webpackConfiguration]) {\n if (!config.plugins) {\n config.plugins = [overrideWatchFSPlugin];\n } else {\n config.plugins.unshift(overrideWatchFSPlugin);\n }\n }\n }\n }\n }\n return this._webpackConfiguration;\n }\n\n private async _loadWebpackAsync(): Promise<typeof TWebpack> {\n if (!this._webpack) {\n // Allow this to fail if webpack is not installed\n this._webpack = await import(WEBPACK_PACKAGE_NAME);\n }\n return this._webpack!;\n }\n\n private async _getWebpackCompilerAsync(\n taskSession: IHeftTaskSession,\n webpackConfiguration: IWebpackConfiguration\n ): Promise<ExtendedCompiler | ExtendedMultiCompiler> {\n if (!this._webpackCompiler) {\n const webpack: typeof TWebpack = await this._loadWebpackAsync();\n taskSession.logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);\n this._webpackCompiler = Array.isArray(webpackConfiguration)\n ? (webpack.default(\n webpackConfiguration\n ) as ExtendedMultiCompiler) /* (webpack.Compilation[]) => MultiCompiler */\n : (webpack.default(webpackConfiguration) as ExtendedCompiler); /* (webpack.Compilation) => Compiler */\n }\n return this._webpackCompiler;\n }\n\n private async _runWebpackAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): Promise<void> {\n this._validateEnvironmentVariable(taskSession);\n if (taskSession.parameters.watch || this._isServeMode) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in compilation mode when watch mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined = await this._getWebpackConfigurationAsync(\n taskSession,\n heftConfiguration,\n options\n );\n if (!webpackConfiguration) {\n return;\n }\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n taskSession.logger.terminal.writeLine('Running Webpack compilation');\n\n // Run the webpack compiler\n let stats: TWebpack.Stats | TWebpack.MultiStats | undefined;\n try {\n stats = await LegacyAdapters.convertCallbackToPromise(\n (compiler as TWebpack.Compiler).run.bind(compiler)\n );\n } catch (e) {\n taskSession.logger.emitError(e as Error);\n }\n\n // Emit the errors from the stats object, if present\n if (stats) {\n this._recordErrors(stats);\n if (this.accessor.hooks.onEmitStats.isUsed()) {\n await this.accessor.hooks.onEmitStats.promise(stats);\n }\n this._emitErrors(taskSession.logger);\n }\n }\n\n private async _runWebpackWatchAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions,\n requestRun: () => void\n ): Promise<void> {\n // Save a handle to the original promise, since the this-scoped promise will be replaced whenever\n // the compilation completes.\n let webpackCompilationDonePromise: Promise<void> | undefined = this._webpackCompilationDonePromise;\n\n let isInitial: boolean = false;\n\n if (!this._webpackCompiler) {\n isInitial = true;\n this._validateEnvironmentVariable(taskSession);\n if (!taskSession.parameters.watch) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in watch mode when compilation mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined =\n await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options, requestRun);\n if (!webpackConfiguration) {\n return;\n }\n\n // Get the compiler which will be used for both serve and watch mode\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n\n // Set up the hook to detect when the watcher completes the watcher compilation. We will also log out\n // errors from the compilation if present from the output stats object.\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n webpackCompilationDonePromise = this._webpackCompilationDonePromise;\n compiler.hooks.done.tap(PLUGIN_NAME, (stats?: TWebpack.Stats | TWebpack.MultiStats) => {\n this._webpackCompilationDonePromiseResolveFn!();\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n if (stats) {\n this._recordErrors(stats);\n }\n });\n\n // Determine how we will run the compiler. When serving, we will run the compiler\n // via the webpack-dev-server. Otherwise, we will run the compiler directly.\n if (this._isServeMode) {\n const defaultDevServerOptions: TWebpackDevServer.Configuration = {\n host: 'localhost',\n devMiddleware: {\n publicPath: '/',\n stats: {\n cached: false,\n cachedAssets: false,\n colors: heftConfiguration.terminalProvider.supportsColor\n }\n },\n client: {\n logging: 'info',\n webSocketURL: {\n port: 8080\n }\n },\n port: 8080,\n onListening: (server: TWebpackDevServer) => {\n const addressInfo: AddressInfo | string | undefined = server.server?.address() as AddressInfo;\n if (addressInfo) {\n const address: string =\n typeof addressInfo === 'string' ? addressInfo : `${addressInfo.address}:${addressInfo.port}`;\n taskSession.logger.terminal.writeLine(`Started Webpack Dev Server at https://${address}`);\n }\n }\n };\n\n // Obtain the devServerOptions from the webpack configuration, and combine with the default options\n let devServerOptions: TWebpackDevServer.Configuration;\n if (Array.isArray(webpackConfiguration)) {\n const filteredDevServerOptions: TWebpackDevServer.Configuration[] = webpackConfiguration\n .map((configuration) => configuration.devServer)\n .filter((devServer): devServer is TWebpackDevServer.Configuration => !!devServer);\n if (filteredDevServerOptions.length > 1) {\n taskSession.logger.emitWarning(\n new Error(`Detected multiple webpack devServer configurations, using the first one.`)\n );\n }\n devServerOptions = { ...defaultDevServerOptions, ...filteredDevServerOptions[0] };\n } else {\n devServerOptions = { ...defaultDevServerOptions, ...webpackConfiguration.devServer };\n }\n\n // Add the certificate and key to the devServerOptions if these fields don't already have values\n if (!devServerOptions.server) {\n const certificateManager: CertificateManager = new CertificateManager();\n const certificate: ICertificate = await certificateManager.ensureCertificateAsync(\n true,\n taskSession.logger.terminal\n );\n\n // Update the web socket URL to use the hostname provided by the certificate\n const clientConfiguration: TWebpackDevServer.Configuration['client'] = devServerOptions.client;\n const hostname: string | undefined = certificate.subjectAltNames?.[0];\n if (hostname && typeof clientConfiguration === 'object') {\n const { webSocketURL } = clientConfiguration;\n if (typeof webSocketURL === 'object') {\n clientConfiguration.webSocketURL = {\n ...webSocketURL,\n hostname\n };\n }\n }\n\n devServerOptions = {\n ...devServerOptions,\n server: {\n type: 'https',\n options: {\n minVersion: 'TLSv1.3',\n key: certificate.pemKey,\n cert: certificate.pemCertificate,\n ca: certificate.pemCaCertificate\n }\n }\n };\n }\n\n // Since the webpack-dev-server does not return infrastructure errors via a callback like\n // compiler.watch(...), we will need to intercept them and log them ourselves.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n compiler.hooks.infrastructureLog.tap(PLUGIN_NAME, (name: string, type: string, args: any[]) => {\n if (name === WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME && type === 'error') {\n const error: Error | undefined = args[0];\n if (error) {\n taskSession.logger.emitError(error);\n }\n }\n return true;\n });\n\n // The webpack-dev-server package has a design flaw, where merely loading its package will set the\n // WEBPACK_DEV_SERVER environment variable -- even if no APIs are accessed. This environment variable\n // causes incorrect behavior if Heft is not running in serve mode. Thus, we need to be careful to call\n // require() only if Heft is in serve mode.\n taskSession.logger.terminal.writeLine('Starting webpack-dev-server');\n const WebpackDevServer: typeof TWebpackDevServer = (await import(WEBPACK_DEV_SERVER_PACKAGE_NAME))\n .default;\n const webpackDevServer: TWebpackDevServer = new WebpackDevServer(devServerOptions, compiler);\n await webpackDevServer.start();\n } else {\n // Create the watcher. Compilation will start immediately after invoking watch().\n taskSession.logger.terminal.writeLine('Starting Webpack watcher');\n compiler.watch({}, (error?: Error | null) => {\n if (error) {\n taskSession.logger.emitError(error);\n }\n });\n }\n }\n\n let hasChanges: boolean = true;\n if (!isInitial && this._watchFileSystems) {\n hasChanges = false;\n for (const watchFileSystem of this._watchFileSystems) {\n hasChanges = watchFileSystem.flush() || hasChanges;\n }\n }\n\n // Resume the compilation, wait for the compilation to complete, then suspend the watchers until the\n // next iteration. Even if there are no changes, the promise should resolve since resuming from a\n // suspended state invalidates the state of the watcher.\n if (hasChanges) {\n taskSession.logger.terminal.writeLine('Running incremental Webpack compilation');\n await webpackCompilationDonePromise;\n } else {\n taskSession.logger.terminal.writeLine(\n 'Webpack has not detected changes. Listing previous diagnostics.'\n );\n }\n\n this._emitErrors(taskSession.logger);\n }\n\n private _validateEnvironmentVariable(taskSession: IHeftTaskSession): void {\n if (!this._isServeMode && process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {\n taskSession.logger.emitWarning(\n new Error(\n `The \"${WEBPACK_DEV_SERVER_ENV_VAR_NAME}\" environment variable is set, ` +\n 'which will cause problems when webpack is not running in serve mode. ' +\n `(Did a dependency inadvertently load the \"${WEBPACK_DEV_SERVER_PACKAGE_NAME}\" package?)`\n )\n );\n }\n }\n\n private _emitErrors(logger: IScopedLogger): void {\n for (const warning of this._warnings) {\n logger.emitWarning(warning);\n }\n for (const error of this._errors) {\n logger.emitError(error);\n }\n }\n\n private _recordErrors(stats: TWebpack.Stats | TWebpack.compilation.MultiStats): void {\n this._errors.length = 0;\n this._warnings.length = 0;\n\n if (stats.hasErrors() || stats.hasWarnings()) {\n const serializedStats: TWebpack.Stats.ToJsonOutput[] = [stats.toJson('errors-warnings')];\n\n for (const compilationStats of serializedStats) {\n for (const warning of compilationStats.warnings as (string | Error)[]) {\n this._warnings.push(warning instanceof Error ? warning : new Error(warning));\n }\n\n for (const error of compilationStats.errors as (string | Error)[]) {\n this._errors.push(error instanceof Error ? error : new Error(error));\n }\n\n if (compilationStats.children) {\n for (const child of compilationStats.children) {\n serializedStats.push(child);\n }\n }\n }\n }\n }\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.33.6"
8
+ "packageVersion": "7.33.7"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/heft-webpack4-plugin",
3
- "version": "0.6.0-rc.2",
3
+ "version": "0.6.0-rc.4",
4
4
  "description": "Heft plugin for Webpack 4",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,22 +17,24 @@
17
17
  }
18
18
  },
19
19
  "peerDependencies": {
20
- "@rushstack/heft": "^0.49.0-rc.2",
20
+ "@rushstack/heft": "0.50.0-rc.4",
21
21
  "@types/webpack": "^4",
22
22
  "webpack": "~4.44.2"
23
23
  },
24
24
  "dependencies": {
25
- "@rushstack/debug-certificate-manager": "1.2.4",
26
- "@rushstack/node-core-library": "3.53.2",
25
+ "@rushstack/debug-certificate-manager": "1.2.8",
26
+ "@rushstack/node-core-library": "3.53.3",
27
27
  "@types/tapable": "1.0.6",
28
28
  "tapable": "1.1.3",
29
+ "watchpack": "2.4.0",
29
30
  "webpack-dev-server": "~4.9.3"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@rushstack/eslint-config": "3.1.1",
33
- "@rushstack/heft-node-rig": "1.12.0-rc.2",
34
- "@rushstack/heft": "0.49.0-rc.2",
34
+ "@rushstack/heft-node-rig": "1.12.0-rc.4",
35
+ "@rushstack/heft": "0.50.0-rc.4",
35
36
  "@types/node": "12.20.24",
37
+ "@types/watchpack": "2.4.0",
36
38
  "@types/webpack": "4.41.32",
37
39
  "webpack": "~4.44.2"
38
40
  },