@rushstack/heft-webpack5-plugin 0.6.0-rc.1 → 0.6.0-rc.3
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.
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/DeferredWatchFileSystem.d.ts +27 -0
- package/lib/DeferredWatchFileSystem.d.ts.map +1 -0
- package/lib/DeferredWatchFileSystem.js +151 -0
- package/lib/DeferredWatchFileSystem.js.map +1 -0
- package/lib/Webpack5Plugin.d.ts +4 -1
- package/lib/Webpack5Plugin.d.ts.map +1 -1
- package/lib/Webpack5Plugin.js +69 -25
- package/lib/Webpack5Plugin.js.map +1 -1
- package/package.json +8 -6
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Watchpack, { type WatchOptions } from 'watchpack';
|
|
2
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
3
|
+
export declare type InputFileSystem = Compiler['inputFileSystem'];
|
|
4
|
+
export declare type WatchFileSystem = Compiler['watchFileSystem'];
|
|
5
|
+
export declare type WatchCallback = Parameters<WatchFileSystem['watch']>[5];
|
|
6
|
+
export declare type WatchUndelayedCallback = Parameters<WatchFileSystem['watch']>[6];
|
|
7
|
+
export declare type Watcher = ReturnType<WatchFileSystem['watch']>;
|
|
8
|
+
export declare type WatcherInfo = ReturnType<Required<Watcher>['getInfo']>;
|
|
9
|
+
export declare class DeferredWatchFileSystem implements WatchFileSystem {
|
|
10
|
+
readonly inputFileSystem: InputFileSystem;
|
|
11
|
+
readonly watcherOptions: WatchOptions;
|
|
12
|
+
watcher: Watchpack | undefined;
|
|
13
|
+
private readonly _onChange;
|
|
14
|
+
private _state;
|
|
15
|
+
constructor(inputFileSystem: InputFileSystem, onChange: () => void);
|
|
16
|
+
flush(): boolean;
|
|
17
|
+
watch(files: Iterable<string>, directories: Iterable<string>, missing: Iterable<string>, startTime: number, options: WatchOptions, callback: WatchCallback, callbackUndelayed: WatchUndelayedCallback): Watcher;
|
|
18
|
+
private _fetchTimeInfo;
|
|
19
|
+
private _purge;
|
|
20
|
+
}
|
|
21
|
+
export declare class OverrideNodeWatchFSPlugin implements WebpackPluginInstance {
|
|
22
|
+
readonly fileSystems: Set<DeferredWatchFileSystem>;
|
|
23
|
+
private readonly _onChange;
|
|
24
|
+
constructor(onChange: () => void);
|
|
25
|
+
apply(compiler: Compiler): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=DeferredWatchFileSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeferredWatchFileSystem.d.ts","sourceRoot":"","sources":["../src/DeferredWatchFileSystem.ts"],"names":[],"mappings":"AAGA,OAAO,SAAS,EAAE,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE/D,oBAAY,eAAe,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAC1D,oBAAY,eAAe,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAC1D,oBAAY,aAAa,GAAG,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,oBAAY,sBAAsB,GAAG,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,oBAAY,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3D,oBAAY,WAAW,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AAsBnE,qBAAa,uBAAwB,YAAW,eAAe;IAC7D,SAAgB,eAAe,EAAE,eAAe,CAAC;IACjD,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,eAAe,EAAE,QAAQ,EAAE,MAAM,IAAI;IASlE,KAAK,IAAI,OAAO;IA0ChB,KAAK,CACV,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,EACzB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,aAAa,EACvB,iBAAiB,EAAE,sBAAsB,GACxC,OAAO;IAyEV,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,MAAM;CAef;AAED,qBAAa,yBAA0B,YAAW,qBAAqB;IACrE,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,151 @@
|
|
|
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
|
+
class DeferredWatchFileSystem {
|
|
11
|
+
constructor(inputFileSystem, onChange) {
|
|
12
|
+
this.inputFileSystem = inputFileSystem;
|
|
13
|
+
this.watcherOptions = {
|
|
14
|
+
aggregateTimeout: 0
|
|
15
|
+
};
|
|
16
|
+
this.watcher = new watchpack_1.default(this.watcherOptions);
|
|
17
|
+
this._onChange = onChange;
|
|
18
|
+
}
|
|
19
|
+
flush() {
|
|
20
|
+
const state = this._state;
|
|
21
|
+
if (!state) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const { changes, removals, callback } = state;
|
|
25
|
+
// Force flush the aggregation callback
|
|
26
|
+
const { changes: newChanges, removals: newRemovals } = this.watcher.getAggregated();
|
|
27
|
+
// Webpack 5 treats changes and removals as separate things
|
|
28
|
+
if (newRemovals) {
|
|
29
|
+
for (const removal of newRemovals) {
|
|
30
|
+
changes.delete(removal);
|
|
31
|
+
removals.add(removal);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (newChanges) {
|
|
35
|
+
for (const change of newChanges) {
|
|
36
|
+
removals.delete(change);
|
|
37
|
+
changes.add(change);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (changes.size > 0 || removals.size > 0) {
|
|
41
|
+
this._purge(removals, changes);
|
|
42
|
+
const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();
|
|
43
|
+
callback(undefined, fileTimeInfoEntries, contextTimeInfoEntries, changes, removals);
|
|
44
|
+
changes.clear();
|
|
45
|
+
removals.clear();
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
watch(files, directories, missing, startTime, options, callback, callbackUndelayed) {
|
|
51
|
+
const oldWatcher = this.watcher;
|
|
52
|
+
this.watcher = new watchpack_1.default(options);
|
|
53
|
+
const changes = new Set();
|
|
54
|
+
const removals = new Set();
|
|
55
|
+
this._state = {
|
|
56
|
+
changes,
|
|
57
|
+
removals,
|
|
58
|
+
callback
|
|
59
|
+
};
|
|
60
|
+
this.watcher.on('aggregated', (newChanges, newRemovals) => {
|
|
61
|
+
for (const change of newChanges) {
|
|
62
|
+
removals.delete(change);
|
|
63
|
+
changes.add(change);
|
|
64
|
+
}
|
|
65
|
+
for (const removal of newRemovals) {
|
|
66
|
+
changes.delete(removal);
|
|
67
|
+
removals.add(removal);
|
|
68
|
+
}
|
|
69
|
+
this._onChange();
|
|
70
|
+
});
|
|
71
|
+
this.watcher.watch({
|
|
72
|
+
files,
|
|
73
|
+
directories,
|
|
74
|
+
missing,
|
|
75
|
+
startTime
|
|
76
|
+
});
|
|
77
|
+
if (oldWatcher) {
|
|
78
|
+
oldWatcher.close();
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
close: () => {
|
|
82
|
+
if (this.watcher) {
|
|
83
|
+
this.watcher.close();
|
|
84
|
+
this.watcher = undefined;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
pause: () => {
|
|
88
|
+
if (this.watcher) {
|
|
89
|
+
this.watcher.pause();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
getInfo: () => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const newRemovals = (_a = this.watcher) === null || _a === void 0 ? void 0 : _a.aggregatedRemovals;
|
|
95
|
+
const newChanges = (_b = this.watcher) === null || _b === void 0 ? void 0 : _b.aggregatedChanges;
|
|
96
|
+
this._purge(newRemovals, newChanges);
|
|
97
|
+
const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();
|
|
98
|
+
return {
|
|
99
|
+
changes: newChanges,
|
|
100
|
+
removals: newRemovals,
|
|
101
|
+
fileTimeInfoEntries,
|
|
102
|
+
contextTimeInfoEntries
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
getContextTimeInfoEntries: () => {
|
|
106
|
+
const { contextTimeInfoEntries } = this._fetchTimeInfo();
|
|
107
|
+
return contextTimeInfoEntries;
|
|
108
|
+
},
|
|
109
|
+
getFileTimeInfoEntries: () => {
|
|
110
|
+
const { fileTimeInfoEntries } = this._fetchTimeInfo();
|
|
111
|
+
return fileTimeInfoEntries;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
_fetchTimeInfo() {
|
|
116
|
+
var _a;
|
|
117
|
+
const fileTimeInfoEntries = new Map();
|
|
118
|
+
const contextTimeInfoEntries = new Map();
|
|
119
|
+
(_a = this.watcher) === null || _a === void 0 ? void 0 : _a.collectTimeInfoEntries(fileTimeInfoEntries, contextTimeInfoEntries);
|
|
120
|
+
return { fileTimeInfoEntries, contextTimeInfoEntries };
|
|
121
|
+
}
|
|
122
|
+
_purge(removals, changes) {
|
|
123
|
+
const fs = this.inputFileSystem;
|
|
124
|
+
if (fs.purge) {
|
|
125
|
+
if (removals) {
|
|
126
|
+
for (const removal of removals) {
|
|
127
|
+
fs.purge(removal);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (changes) {
|
|
131
|
+
for (const change of changes) {
|
|
132
|
+
fs.purge(change);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.DeferredWatchFileSystem = DeferredWatchFileSystem;
|
|
139
|
+
class OverrideNodeWatchFSPlugin {
|
|
140
|
+
constructor(onChange) {
|
|
141
|
+
this.fileSystems = new Set();
|
|
142
|
+
this._onChange = onChange;
|
|
143
|
+
}
|
|
144
|
+
apply(compiler) {
|
|
145
|
+
const watchFileSystem = new DeferredWatchFileSystem(compiler.inputFileSystem, this._onChange);
|
|
146
|
+
this.fileSystems.add(watchFileSystem);
|
|
147
|
+
compiler.watchFileSystem = watchFileSystem;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.OverrideNodeWatchFSPlugin = OverrideNodeWatchFSPlugin;
|
|
151
|
+
//# 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,MAAa,uBAAuB;IAQlC,YAAmB,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AsB,CAAC,CAAC;QAClF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;IACzD,CAAC;IAEO,MAAM,CAAC,QAAiC,EAAE,OAAgC;QAChF,MAAM,EAAE,GAAoB,IAAI,CAAC,eAAe,CAAC;QACjD,IAAI,EAAE,CAAC,KAAK,EAAE;YACZ,IAAI,QAAQ,EAAE;gBACZ,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;oBAC9B,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;iBACnB;aACF;YACD,IAAI,OAAO,EAAE;gBACX,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;oBAC5B,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;iBAClB;aACF;SACF;IACH,CAAC;CACF;AAlKD,0DAkKC;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;QACtC,QAAQ,CAAC,eAAe,GAAG,eAAe,CAAC;IAC7C,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, WebpackPluginInstance } from 'webpack';\n\nexport type InputFileSystem = Compiler['inputFileSystem'];\nexport type WatchFileSystem = Compiler['watchFileSystem'];\nexport type WatchCallback = Parameters<WatchFileSystem['watch']>[5];\nexport type WatchUndelayedCallback = Parameters<WatchFileSystem['watch']>[6];\nexport type Watcher = ReturnType<WatchFileSystem['watch']>;\nexport type WatcherInfo = ReturnType<Required<Watcher>['getInfo']>;\ntype FileSystemMap = ReturnType<Watcher['getFileTimeInfoEntries']>;\n\ninterface IWatchState {\n changes: Set<string>;\n removals: Set<string>;\n\n callback: WatchCallback;\n}\n\ninterface ITimeEntry {\n timestamp: number;\n safeTime: number;\n}\n\ntype IRawFileSystemMap = Map<string, ITimeEntry>;\n\ninterface ITimeInfoEntries {\n fileTimeInfoEntries: FileSystemMap;\n contextTimeInfoEntries: FileSystemMap;\n}\n\nexport class DeferredWatchFileSystem implements WatchFileSystem {\n public readonly inputFileSystem: InputFileSystem;\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: InputFileSystem, 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 { changes, removals, callback } = state;\n\n // Force flush the aggregation callback\n const { changes: newChanges, removals: newRemovals } = this.watcher!.getAggregated();\n\n // Webpack 5 treats changes and removals as separate things\n if (newRemovals) {\n for (const removal of newRemovals) {\n changes.delete(removal);\n removals.add(removal);\n }\n }\n if (newChanges) {\n for (const change of newChanges) {\n removals.delete(change);\n changes.add(change);\n }\n }\n\n if (changes.size > 0 || removals.size > 0) {\n this._purge(removals, changes);\n\n const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();\n\n callback(undefined, fileTimeInfoEntries, contextTimeInfoEntries, changes, removals);\n\n changes.clear();\n removals.clear();\n\n return true;\n }\n\n return false;\n }\n\n public watch(\n files: Iterable<string>,\n directories: Iterable<string>,\n missing: Iterable<string>,\n startTime: number,\n options: WatchOptions,\n callback: WatchCallback,\n callbackUndelayed: WatchUndelayedCallback\n ): Watcher {\n const oldWatcher: Watchpack | undefined = this.watcher;\n 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 changes,\n removals,\n\n callback\n };\n\n this.watcher.on('aggregated', (newChanges: Set<string>, newRemovals: Set<string>) => {\n for (const change of newChanges) {\n removals.delete(change);\n changes.add(change);\n }\n for (const removal of newRemovals) {\n changes.delete(removal);\n removals.add(removal);\n }\n\n this._onChange();\n });\n\n this.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 getInfo: () => {\n const newRemovals: Set<string> | undefined = this.watcher?.aggregatedRemovals;\n const newChanges: Set<string> | undefined = this.watcher?.aggregatedChanges;\n this._purge(newRemovals, newChanges);\n const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();\n return {\n changes: newChanges!,\n removals: newRemovals!,\n fileTimeInfoEntries,\n contextTimeInfoEntries\n };\n },\n getContextTimeInfoEntries: () => {\n const { contextTimeInfoEntries } = this._fetchTimeInfo();\n return contextTimeInfoEntries;\n },\n getFileTimeInfoEntries: () => {\n const { fileTimeInfoEntries } = this._fetchTimeInfo();\n return fileTimeInfoEntries;\n }\n };\n }\n\n private _fetchTimeInfo(): ITimeInfoEntries {\n const fileTimeInfoEntries: IRawFileSystemMap = new Map();\n const contextTimeInfoEntries: IRawFileSystemMap = new Map();\n this.watcher?.collectTimeInfoEntries(fileTimeInfoEntries, contextTimeInfoEntries);\n return { fileTimeInfoEntries, contextTimeInfoEntries };\n }\n\n private _purge(removals: Set<string> | undefined, changes: Set<string> | undefined): void {\n const fs: InputFileSystem = this.inputFileSystem;\n if (fs.purge) {\n if (removals) {\n for (const removal of removals) {\n fs.purge(removal);\n }\n }\n if (changes) {\n for (const change of changes) {\n fs.purge(change);\n }\n }\n }\n }\n}\n\nexport class OverrideNodeWatchFSPlugin implements WebpackPluginInstance {\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.watchFileSystem = watchFileSystem;\n }\n}\n"]}
|
package/lib/Webpack5Plugin.d.ts
CHANGED
|
@@ -17,9 +17,11 @@ export default class Webpack5Plugin 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,6 +31,7 @@ export default class Webpack5Plugin implements IHeftTaskPlugin<IWebpackPluginOpt
|
|
|
29
31
|
private _runWebpackWatchAsync;
|
|
30
32
|
private _validateEnvironmentVariable;
|
|
31
33
|
private _emitErrors;
|
|
34
|
+
private _recordErrors;
|
|
32
35
|
private _normalizeError;
|
|
33
36
|
}
|
|
34
37
|
//# sourceMappingURL=Webpack5Plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Webpack5Plugin.d.ts","sourceRoot":"","sources":["../src/Webpack5Plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Webpack5Plugin.d.ts","sourceRoot":"","sources":["../src/Webpack5Plugin.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAyB,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAI9E,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,CAAyD;IACjF,OAAO,CAAC,qBAAqB,CAA2E;IACxG,OAAO,CAAC,8BAA8B,CAA4B;IAClE,OAAO,CAAC,uCAAuC,CAA2B;IAC1E,OAAO,CAAC,iBAAiB,CAA2C;IAEpE,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,OAAO,CAAe;IAE9B,IAAW,QAAQ,IAAI,sBAAsB,CAe5C;IAEM,KAAK,CACV,WAAW,EAAE,gBAAgB,EAC7B,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,EAAE,qBAAqB,GAC7B,IAAI;YAsBO,6BAA6B;YAmE7B,iBAAiB;YAQjB,wBAAwB;YAcxB,gBAAgB;YA+ChB,qBAAqB;IA2LnC,OAAO,CAAC,4BAA4B;IAYpC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,aAAa;IAgCrB,OAAO,CAAC,eAAe;CAmCxB"}
|
package/lib/Webpack5Plugin.js
CHANGED
|
@@ -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 Webpack5Plugin {
|
|
|
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 Webpack5Plugin {
|
|
|
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 Webpack5Plugin {
|
|
|
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;
|
|
@@ -152,25 +169,28 @@ class Webpack5Plugin {
|
|
|
152
169
|
}
|
|
153
170
|
// Emit the errors from the stats object, if present
|
|
154
171
|
if (stats) {
|
|
155
|
-
this.
|
|
172
|
+
this._recordErrors(stats, heftConfiguration.buildFolderPath);
|
|
173
|
+
this._emitErrors(taskSession.logger);
|
|
156
174
|
if (this.accessor.hooks.onEmitStats.isUsed()) {
|
|
157
175
|
await this.accessor.hooks.onEmitStats.promise(stats);
|
|
158
176
|
}
|
|
159
177
|
}
|
|
160
178
|
}
|
|
161
|
-
async _runWebpackWatchAsync(taskSession, heftConfiguration, options) {
|
|
162
|
-
var _a
|
|
179
|
+
async _runWebpackWatchAsync(taskSession, heftConfiguration, options, requestRun) {
|
|
180
|
+
var _a;
|
|
163
181
|
// Save a handle to the original promise, since the this-scoped promise will be replaced whenever
|
|
164
182
|
// the compilation completes.
|
|
165
183
|
let webpackCompilationDonePromise = this._webpackCompilationDonePromise;
|
|
166
|
-
|
|
184
|
+
let isInitial = false;
|
|
185
|
+
if (!this._webpackCompiler) {
|
|
186
|
+
isInitial = true;
|
|
167
187
|
this._validateEnvironmentVariable(taskSession);
|
|
168
188
|
if (!taskSession.parameters.watch) {
|
|
169
189
|
// Should never happen, but just in case
|
|
170
190
|
throw new node_core_library_1.InternalError('Cannot run Webpack in watch mode when compilation mode is enabled');
|
|
171
191
|
}
|
|
172
192
|
// Load the config and compiler, and return if there is no config found
|
|
173
|
-
const webpackConfiguration = await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options);
|
|
193
|
+
const webpackConfiguration = await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options, requestRun);
|
|
174
194
|
if (!webpackConfiguration) {
|
|
175
195
|
return;
|
|
176
196
|
}
|
|
@@ -188,7 +208,7 @@ class Webpack5Plugin {
|
|
|
188
208
|
this._webpackCompilationDonePromiseResolveFn = resolve;
|
|
189
209
|
});
|
|
190
210
|
if (stats) {
|
|
191
|
-
this.
|
|
211
|
+
this._recordErrors(stats, heftConfiguration.buildFolderPath);
|
|
192
212
|
}
|
|
193
213
|
});
|
|
194
214
|
// Determine how we will run the compiler. When serving, we will run the compiler
|
|
@@ -288,20 +308,25 @@ class Webpack5Plugin {
|
|
|
288
308
|
}
|
|
289
309
|
});
|
|
290
310
|
}
|
|
291
|
-
|
|
292
|
-
|
|
311
|
+
}
|
|
312
|
+
let hasChanges = true;
|
|
313
|
+
if (!isInitial && this._watchFileSystems) {
|
|
314
|
+
hasChanges = false;
|
|
315
|
+
for (const watchFileSystem of this._watchFileSystems) {
|
|
316
|
+
hasChanges = watchFileSystem.flush() || hasChanges;
|
|
317
|
+
}
|
|
293
318
|
}
|
|
294
319
|
// Resume the compilation, wait for the compilation to complete, then suspend the watchers until the
|
|
295
320
|
// next iteration. Even if there are no changes, the promise should resolve since resuming from a
|
|
296
321
|
// suspended state invalidates the state of the watcher.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
322
|
+
if (hasChanges) {
|
|
323
|
+
taskSession.logger.terminal.writeLine('Running incremental Webpack compilation');
|
|
324
|
+
await webpackCompilationDonePromise;
|
|
300
325
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
watcher.suspend();
|
|
326
|
+
else {
|
|
327
|
+
taskSession.logger.terminal.writeLine('Webpack has not detected changes. Listing previous diagnostics.');
|
|
304
328
|
}
|
|
329
|
+
this._emitErrors(taskSession.logger);
|
|
305
330
|
}
|
|
306
331
|
_validateEnvironmentVariable(taskSession) {
|
|
307
332
|
if (!this._isServeMode && process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {
|
|
@@ -310,17 +335,36 @@ class Webpack5Plugin {
|
|
|
310
335
|
`(Did a dependency inadvertently load the "${WEBPACK_DEV_SERVER_PACKAGE_NAME}" package?)`));
|
|
311
336
|
}
|
|
312
337
|
}
|
|
313
|
-
_emitErrors(logger
|
|
338
|
+
_emitErrors(logger) {
|
|
339
|
+
for (const warning of this._warnings) {
|
|
340
|
+
logger.emitWarning(warning);
|
|
341
|
+
}
|
|
342
|
+
for (const error of this._errors) {
|
|
343
|
+
logger.emitError(error);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
_recordErrors(stats, buildFolderPath) {
|
|
347
|
+
const errors = this._errors;
|
|
348
|
+
const warnings = this._warnings;
|
|
349
|
+
errors.length = 0;
|
|
350
|
+
warnings.length = 0;
|
|
314
351
|
if (stats.hasErrors() || stats.hasWarnings()) {
|
|
315
|
-
const serializedStats = stats.toJson('errors-warnings');
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
352
|
+
const serializedStats = [stats.toJson('errors-warnings')];
|
|
353
|
+
for (const compilationStats of serializedStats) {
|
|
354
|
+
if (compilationStats.warnings) {
|
|
355
|
+
for (const warning of compilationStats.warnings) {
|
|
356
|
+
warnings.push(this._normalizeError(buildFolderPath, warning));
|
|
357
|
+
}
|
|
319
358
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
359
|
+
if (compilationStats.errors) {
|
|
360
|
+
for (const error of compilationStats.errors) {
|
|
361
|
+
errors.push(this._normalizeError(buildFolderPath, error));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (compilationStats.children) {
|
|
365
|
+
for (const child of compilationStats.children) {
|
|
366
|
+
serializedStats.push(child);
|
|
367
|
+
}
|
|
324
368
|
}
|
|
325
369
|
}
|
|
326
370
|
}
|
|
@@ -1 +1 @@
|
|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AAa,EAAE,EAAE,CAAC,CAAC;oBACzC,IAAI,KAAK,CAAC,UAAU,CAAC,EAAE;wBACrB,UAAU,GAAG,SAAS,CAAC;qBACxB;iBACF;gBACD,IAAI,cAAc,EAAE;oBAClB,YAAY,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;oBAC5C,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE;wBACvB,YAAY,GAAG,SAAS,CAAC;qBAC1B;iBACF;aACF;YAED,OAAO,IAAI,6BAAS,CAAC,KAAK,CAAC,OAAO,EAAE;gBAClC,YAAY,EAAE,KAAK,CAAC,gBAAgB;gBACpC,aAAa,EAAE,eAAe;gBAC9B,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,YAAY;aACrB,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SACjC;IACH,CAAC;CACF;AAnaD,iCAmaC","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 } from 'tapable';\nimport { CertificateManager, type ICertificate } from '@rushstack/debug-certificate-manager';\nimport { FileError, 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 ExtendedCompiler = TWebpack.Compiler & { watching: TWebpack.Watching };\ntype ExtendedMultiCompiler = TWebpack.MultiCompiler & { compilers: ExtendedCompiler[] };\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath: string | undefined;\n configurationPath: string | undefined;\n}\n\n/**\n * @public\n */\nexport const PLUGIN_NAME: 'webpack5-plugin' = 'webpack5-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 Webpack5Plugin 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: TWebpack.Watching[] | 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(webpackConfiguration) /* (webpack.Compilation[]) => MultiCompiler */\n : webpack.default(webpackConfiguration); /* (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 ExtendedCompiler).run.bind(compiler)\n );\n await LegacyAdapters.convertCallbackToPromise(compiler.close.bind(compiler));\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, heftConfiguration.buildFolderPath);\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, heftConfiguration.buildFolderPath);\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 // 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(\n logger: IScopedLogger,\n stats: TWebpack.Stats | TWebpack.MultiStats,\n buildFolderPath: string\n ): void {\n if (stats.hasErrors() || stats.hasWarnings()) {\n const serializedStats: TWebpack.StatsCompilation = stats.toJson('errors-warnings');\n\n if (serializedStats.warnings) {\n for (const warning of serializedStats.warnings) {\n logger.emitWarning(this._normalizeError(buildFolderPath, warning));\n }\n }\n\n if (serializedStats.errors) {\n for (const error of serializedStats.errors) {\n logger.emitError(this._normalizeError(buildFolderPath, error));\n }\n }\n }\n }\n\n private _normalizeError(buildFolderPath: string, error: TWebpack.StatsError): Error {\n if (error instanceof Error) {\n return error;\n } else if (error.moduleIdentifier) {\n let lineNumber: number | undefined;\n let columnNumber: number | undefined;\n if (error.loc) {\n // Format of \"<line>:<columnStart>-<columnEnd>\"\n // https://webpack.js.org/api/stats/#errors-and-warnings\n const [lineNumberRaw, columnRangeRaw] = error.loc.split(':');\n const [startColumnRaw] = columnRangeRaw.split('-');\n if (lineNumberRaw) {\n lineNumber = parseInt(lineNumberRaw, 10);\n if (isNaN(lineNumber)) {\n lineNumber = undefined;\n }\n }\n if (startColumnRaw) {\n columnNumber = parseInt(startColumnRaw, 10);\n if (isNaN(columnNumber)) {\n columnNumber = undefined;\n }\n }\n }\n\n return new FileError(error.message, {\n absolutePath: error.moduleIdentifier,\n projectFolder: buildFolderPath,\n line: lineNumber,\n column: columnNumber\n });\n } else {\n return new Error(error.message);\n }\n }\n}\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AAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC7D,MAAM,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnD,IAAI,aAAa,EAAE;oBACjB,UAAU,GAAG,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;oBACzC,IAAI,KAAK,CAAC,UAAU,CAAC,EAAE;wBACrB,UAAU,GAAG,SAAS,CAAC;qBACxB;iBACF;gBACD,IAAI,cAAc,EAAE;oBAClB,YAAY,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;oBAC5C,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE;wBACvB,YAAY,GAAG,SAAS,CAAC;qBAC1B;iBACF;aACF;YAED,OAAO,IAAI,6BAAS,CAAC,KAAK,CAAC,OAAO,EAAE;gBAClC,YAAY,EAAE,KAAK,CAAC,gBAAgB;gBACpC,aAAa,EAAE,eAAe;gBAC9B,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,YAAY;aACrB,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SACjC;IACH,CAAC;CACF;AAndD,iCAmdC","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';\n\nimport type * as TWebpack from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook } from 'tapable';\n\nimport { CertificateManager, type ICertificate } from '@rushstack/debug-certificate-manager';\nimport { FileError, 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 { DeferredWatchFileSystem, OverrideNodeWatchFSPlugin } from './DeferredWatchFileSystem';\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath: string | undefined;\n configurationPath: string | undefined;\n}\n\n/**\n * @public\n */\nexport const PLUGIN_NAME: 'webpack5-plugin' = 'webpack5-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 Webpack5Plugin implements IHeftTaskPlugin<IWebpackPluginOptions> {\n private _accessor: IWebpackPluginAccessor | undefined;\n private _isServeMode: boolean = false;\n private _webpack: typeof TWebpack | undefined;\n private _webpackCompiler: TWebpack.Compiler | TWebpack.MultiCompiler | 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<TWebpack.Compiler | TWebpack.MultiCompiler> {\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(webpackConfiguration) /* (webpack.Compilation[]) => MultiCompiler */\n : webpack.default(webpackConfiguration); /* (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: TWebpack.Compiler | TWebpack.MultiCompiler = 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 await LegacyAdapters.convertCallbackToPromise(compiler.close.bind(compiler));\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, heftConfiguration.buildFolderPath);\n this._emitErrors(taskSession.logger);\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 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: TWebpack.Compiler | TWebpack.MultiCompiler = 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\n if (stats) {\n this._recordErrors(stats, heftConfiguration.buildFolderPath);\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.MultiStats, buildFolderPath: string): void {\n const errors: Error[] = this._errors;\n const warnings: Error[] = this._warnings;\n\n errors.length = 0;\n warnings.length = 0;\n\n if (stats.hasErrors() || stats.hasWarnings()) {\n const serializedStats: TWebpack.StatsCompilation[] = [stats.toJson('errors-warnings')];\n\n for (const compilationStats of serializedStats) {\n if (compilationStats.warnings) {\n for (const warning of compilationStats.warnings) {\n warnings.push(this._normalizeError(buildFolderPath, warning));\n }\n }\n\n if (compilationStats.errors) {\n for (const error of compilationStats.errors) {\n errors.push(this._normalizeError(buildFolderPath, error));\n }\n }\n\n if (compilationStats.children) {\n for (const child of compilationStats.children) {\n serializedStats.push(child);\n }\n }\n }\n }\n }\n\n private _normalizeError(buildFolderPath: string, error: TWebpack.StatsError): Error {\n if (error instanceof Error) {\n return error;\n } else if (error.moduleIdentifier) {\n let lineNumber: number | undefined;\n let columnNumber: number | undefined;\n if (error.loc) {\n // Format of \"<line>:<columnStart>-<columnEnd>\"\n // https://webpack.js.org/api/stats/#errors-and-warnings\n const [lineNumberRaw, columnRangeRaw] = error.loc.split(':');\n const [startColumnRaw] = columnRangeRaw.split('-');\n if (lineNumberRaw) {\n lineNumber = parseInt(lineNumberRaw, 10);\n if (isNaN(lineNumber)) {\n lineNumber = undefined;\n }\n }\n if (startColumnRaw) {\n columnNumber = parseInt(startColumnRaw, 10);\n if (isNaN(columnNumber)) {\n columnNumber = undefined;\n }\n }\n }\n\n return new FileError(error.message, {\n absolutePath: error.moduleIdentifier,\n projectFolder: buildFolderPath,\n line: lineNumber,\n column: columnNumber\n });\n } else {\n return new Error(error.message);\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/heft-webpack5-plugin",
|
|
3
|
-
"version": "0.6.0-rc.
|
|
3
|
+
"version": "0.6.0-rc.3",
|
|
4
4
|
"description": "Heft plugin for Webpack 5",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,21 +12,23 @@
|
|
|
12
12
|
"types": "dist/heft-webpack5-plugin.d.ts",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@rushstack/heft": "
|
|
15
|
+
"@rushstack/heft": "0.50.0-rc.3",
|
|
16
16
|
"webpack": "~5.68.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@rushstack/debug-certificate-manager": "1.2.
|
|
20
|
-
"@rushstack/node-core-library": "3.53.
|
|
19
|
+
"@rushstack/debug-certificate-manager": "1.2.8",
|
|
20
|
+
"@rushstack/node-core-library": "3.53.3",
|
|
21
21
|
"@types/tapable": "1.0.6",
|
|
22
22
|
"tapable": "1.1.3",
|
|
23
|
+
"watchpack": "2.4.0",
|
|
23
24
|
"webpack-dev-server": "~4.9.3"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@rushstack/eslint-config": "3.1.1",
|
|
27
|
-
"@rushstack/heft": "0.
|
|
28
|
-
"@rushstack/heft-node-rig": "1.12.0-rc.
|
|
28
|
+
"@rushstack/heft": "0.50.0-rc.3",
|
|
29
|
+
"@rushstack/heft-node-rig": "1.12.0-rc.3",
|
|
29
30
|
"@types/node": "12.20.24",
|
|
31
|
+
"@types/watchpack": "2.4.0",
|
|
30
32
|
"webpack": "~5.68.0"
|
|
31
33
|
},
|
|
32
34
|
"scripts": {
|