@rushstack/heft-webpack5-plugin 1.1.0 → 1.2.0
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/CHANGELOG.json +32 -0
- package/CHANGELOG.md +9 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/Webpack5Plugin.d.ts.map +1 -1
- package/lib/Webpack5Plugin.js +15 -9
- package/lib/Webpack5Plugin.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/heft-webpack5-plugin",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "1.2.0",
|
|
6
|
+
"tag": "@rushstack/heft-webpack5-plugin_v1.2.0",
|
|
7
|
+
"date": "Wed, 08 Oct 2025 00:13:28 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Allow infrastructure logs to be printed."
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "Use project-level webpack dependency when it's installed."
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"dependency": [
|
|
18
|
+
{
|
|
19
|
+
"comment": "Updating dependency \"@rushstack/debug-certificate-manager\" to `1.6.1`"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.17.0`"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `1.1.1`"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"comment": "Updating dependency \"@rushstack/terminal\" to `0.19.1`"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"comment": "Updating dependency \"@rushstack/heft\" from `^1.1.0` to `1.1.1`"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
4
36
|
{
|
|
5
37
|
"version": "1.1.0",
|
|
6
38
|
"tag": "@rushstack/heft-webpack5-plugin_v1.1.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Change Log - @rushstack/heft-webpack5-plugin
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 08 Oct 2025 00:13:28 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 1.2.0
|
|
6
|
+
Wed, 08 Oct 2025 00:13:28 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- Allow infrastructure logs to be printed.
|
|
11
|
+
- Use project-level webpack dependency when it's installed.
|
|
4
12
|
|
|
5
13
|
## 1.1.0
|
|
6
14
|
Fri, 03 Oct 2025 20:09:59 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EAEL,KAAK,sBAAsB,EAE3B,KAAK,2BAA2B,EACjC,MAAM,UAAU,CAAC;AAIlB,MAAM,WAAW,qBAAqB;IACpC,oBAAoB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAOD;;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,CAAoD;IACjF,OAAO,C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,iBAAiB,EACpC,OAAO,GAAE,qBAA0B,GAClC,IAAI;YAwBO,6BAA6B;YAsC7B,iBAAiB;YAoBjB,wBAAwB;YAexB,gBAAgB;YAgDhB,qBAAqB;IAoMnC,OAAO,CAAC,4BAA4B;IAYpC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,aAAa;IAgCrB,OAAO,CAAC,eAAe;CAmCxB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,2BAA2B,CAQlE"}
|
package/lib/Webpack5Plugin.js
CHANGED
|
@@ -90,7 +90,7 @@ class Webpack5Plugin {
|
|
|
90
90
|
heftConfiguration,
|
|
91
91
|
hooks: this.accessor.hooks,
|
|
92
92
|
serveMode: this._isServeMode,
|
|
93
|
-
loadWebpackAsyncFn: this._loadWebpackAsync.bind(this)
|
|
93
|
+
loadWebpackAsyncFn: this._loadWebpackAsync.bind(this, taskSession, heftConfiguration)
|
|
94
94
|
}, options);
|
|
95
95
|
if (webpackConfiguration && requestRun) {
|
|
96
96
|
const overrideWatchFSPlugin = new DeferredWatchFileSystem_1.OverrideNodeWatchFSPlugin(requestRun);
|
|
@@ -110,16 +110,23 @@ class Webpack5Plugin {
|
|
|
110
110
|
}
|
|
111
111
|
return this._webpackConfiguration;
|
|
112
112
|
}
|
|
113
|
-
async _loadWebpackAsync() {
|
|
113
|
+
async _loadWebpackAsync(taskSession, heftConfiguration) {
|
|
114
114
|
if (!this._webpack) {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
try {
|
|
116
|
+
const webpackPackagePath = await heftConfiguration.rigPackageResolver.resolvePackageAsync(WEBPACK_PACKAGE_NAME, taskSession.logger.terminal);
|
|
117
|
+
this._webpack = await Promise.resolve(`${webpackPackagePath}`).then(s => __importStar(require(s)));
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
// Fallback to bundled version if not found in rig.
|
|
121
|
+
this._webpack = await Promise.resolve(`${WEBPACK_PACKAGE_NAME}`).then(s => __importStar(require(s)));
|
|
122
|
+
taskSession.logger.terminal.writeDebugLine(`Using Webpack from built-in "${WEBPACK_PACKAGE_NAME}"`);
|
|
123
|
+
}
|
|
117
124
|
}
|
|
118
125
|
return this._webpack;
|
|
119
126
|
}
|
|
120
|
-
async _getWebpackCompilerAsync(taskSession, webpackConfiguration) {
|
|
127
|
+
async _getWebpackCompilerAsync(taskSession, heftConfiguration, webpackConfiguration) {
|
|
121
128
|
if (!this._webpackCompiler) {
|
|
122
|
-
const webpack = await this._loadWebpackAsync();
|
|
129
|
+
const webpack = await this._loadWebpackAsync(taskSession, heftConfiguration);
|
|
123
130
|
taskSession.logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);
|
|
124
131
|
this._webpackCompiler = Array.isArray(webpackConfiguration)
|
|
125
132
|
? webpack.default(webpackConfiguration) /* (webpack.Compilation[]) => MultiCompiler */
|
|
@@ -138,7 +145,7 @@ class Webpack5Plugin {
|
|
|
138
145
|
if (!webpackConfiguration) {
|
|
139
146
|
return;
|
|
140
147
|
}
|
|
141
|
-
const compiler = await this._getWebpackCompilerAsync(taskSession, webpackConfiguration);
|
|
148
|
+
const compiler = await this._getWebpackCompilerAsync(taskSession, heftConfiguration, webpackConfiguration);
|
|
142
149
|
taskSession.logger.terminal.writeLine('Running Webpack compilation');
|
|
143
150
|
// Run the webpack compiler
|
|
144
151
|
let stats;
|
|
@@ -177,7 +184,7 @@ class Webpack5Plugin {
|
|
|
177
184
|
return;
|
|
178
185
|
}
|
|
179
186
|
// Get the compiler which will be used for both serve and watch mode
|
|
180
|
-
const compiler = await this._getWebpackCompilerAsync(taskSession, webpackConfiguration);
|
|
187
|
+
const compiler = await this._getWebpackCompilerAsync(taskSession, heftConfiguration, webpackConfiguration);
|
|
181
188
|
// Set up the hook to detect when the watcher completes the watcher compilation. We will also log out
|
|
182
189
|
// errors from the compilation if present from the output stats object.
|
|
183
190
|
this._webpackCompilationDonePromise = new Promise((resolve) => {
|
|
@@ -274,7 +281,6 @@ class Webpack5Plugin {
|
|
|
274
281
|
taskSession.logger.emitError(error);
|
|
275
282
|
}
|
|
276
283
|
}
|
|
277
|
-
return true;
|
|
278
284
|
});
|
|
279
285
|
// The webpack-dev-server package has a design flaw, where merely loading its package will set the
|
|
280
286
|
// WEBPACK_DEV_SERVER environment variable -- even if no APIs are accessed. This environment variable
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Webpack5Plugin.js","sourceRoot":"","sources":["../src/Webpack5Plugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0e3D,oDAQC;AA5eD,qCAA4G;AAE5G,oFAA6F;AAC7F,oEAAwF;AAUxF,qCAKkB;AAClB,6EAAgF;AAChF,uEAAoG;AAMpG,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;AAE/F;;GAEG;AACH,MAAqB,cAAc;IAAnC;QAEU,iBAAY,GAAY,KAAK,CAAC;QAG9B,0BAAqB,GAA8C,KAAK,CAAC;QAKzE,cAAS,GAAY,EAAE,CAAC;QACxB,YAAO,GAAY,EAAE,CAAC;IAibhC,CAAC;IA/aC,IAAW,QAAQ;QACjB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG;gBACf,KAAK,EAAE,oBAAoB,EAAE;gBAC7B,UAAU,EAAE;oBACV,WAAW,EAAE,IAAI,CAAC,YAAY;iBAC/B;aACF,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,KAAK,CACV,WAA6B,EAC7B,iBAAoC,EACpC,UAAiC,EAAE;;QAEnC,IAAI,CAAC,YAAY,GAAG,WAAW,C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BACtB,UAAU,GAAG,SAAS,CAAC;oBACzB,CAAC;gBACH,CAAC;gBACD,IAAI,cAAc,EAAE,CAAC;oBACnB,YAAY,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;oBAC5C,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;wBACxB,YAAY,GAAG,SAAS,CAAC;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;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;QACL,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF;AA5bD,iCA4bC;AAED;;GAEG;AACH,SAAgB,oBAAoB;IAClC,OAAO;QACL,mBAAmB,EAAE,IAAI,6BAAmB,EAAE;QAC9C,WAAW,EAAE,IAAI,yBAAe,CAAC,CAAC,sBAAsB,CAAC,CAAC;QAC1D,gBAAgB,EAAE,IAAI,2BAAiB,CAAC,CAAC,sBAAsB,CAAC,CAAC;QACjE,WAAW,EAAE,IAAI,2BAAiB,CAAC,CAAC,cAAc,CAAC,CAAC;QACpD,iBAAiB,EAAE,IAAI,kCAAwB,CAAC,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;KAC1F,CAAC;AACJ,CAAC","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 'node:net';\n\nimport type * as TWebpack from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesWaterfallHook } 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 {\n type IWebpackConfiguration,\n type IWebpackPluginAccessor,\n PLUGIN_NAME,\n type IWebpackPluginAccessorHooks\n} from './shared';\nimport { tryLoadWebpackConfigurationAsync } from './WebpackConfigurationLoader';\nimport { type DeferredWatchFileSystem, OverrideNodeWatchFSPlugin } from './DeferredWatchFileSystem';\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath?: string | undefined;\n configurationPath?: string | undefined;\n}\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';\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 | false = false;\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: _createAccessorHooks(),\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 (this._isServeMode && !taskSession.parameters.watch) {\n throw new Error(\n `The ${JSON.stringify(\n SERVE_PARAMETER_LONG_NAME\n )} parameter is only available when running in watch mode.` +\n ` Try replacing \"${taskSession.parsedCommandLine?.unaliasedCommandName}\" with` +\n ` \"${taskSession.parsedCommandLine?.unaliasedCommandName}-watch\" in your Heft command line.`\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 === false) {\n const webpackConfiguration: IWebpackConfiguration | undefined = await tryLoadWebpackConfigurationAsync(\n {\n taskSession,\n heftConfiguration,\n hooks: this.accessor.hooks,\n serveMode: this._isServeMode,\n loadWebpackAsyncFn: this._loadWebpackAsync.bind(this)\n },\n options\n );\n\n if (webpackConfiguration && 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 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<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 compiler.hooks.infrastructureLog.tap(\n PLUGIN_NAME,\n (name: string, type: string, args: unknown[] | undefined) => {\n if (name === WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME && type === 'error') {\n const error: Error | undefined = args?.[0] as Error | undefined;\n if (error) {\n taskSession.logger.emitError(error);\n }\n }\n return true;\n }\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\n const { onGetWatchOptions } = this.accessor.hooks;\n\n const watchOptions: Parameters<TWebpack.Compiler['watch']>[0] = onGetWatchOptions.isUsed()\n ? await onGetWatchOptions.promise({}, webpackConfiguration)\n : {};\n\n compiler.watch(watchOptions, (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\n/**\n * @internal\n */\nexport function _createAccessorHooks(): IWebpackPluginAccessorHooks {\n return {\n onLoadConfiguration: new AsyncSeriesBailHook(),\n onConfigure: new AsyncSeriesHook(['webpackConfiguration']),\n onAfterConfigure: new AsyncParallelHook(['webpackConfiguration']),\n onEmitStats: new AsyncParallelHook(['webpackStats']),\n onGetWatchOptions: new AsyncSeriesWaterfallHook(['watchOptions', 'webpackConfiguration'])\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Webpack5Plugin.js","sourceRoot":"","sources":["../src/Webpack5Plugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwf3D,oDAQC;AA1fD,qCAA4G;AAE5G,oFAA6F;AAC7F,oEAAwF;AAUxF,qCAKkB;AAClB,6EAAgF;AAChF,uEAAoG;AAMpG,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;AAE/F;;GAEG;AACH,MAAqB,cAAc;IAAnC;QAEU,iBAAY,GAAY,KAAK,CAAC;QAG9B,0BAAqB,GAA8C,KAAK,CAAC;QAKzE,cAAS,GAAY,EAAE,CAAC;QACx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ACpC,aAAa,EAAE,eAAe;gBAC9B,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,YAAY;aACrB,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF;AA1cD,iCA0cC;AAED;;GAEG;AACH,SAAgB,oBAAoB;IAClC,OAAO;QACL,mBAAmB,EAAE,IAAI,6BAAmB,EAAE;QAC9C,WAAW,EAAE,IAAI,yBAAe,CAAC,CAAC,sBAAsB,CAAC,CAAC;QAC1D,gBAAgB,EAAE,IAAI,2BAAiB,CAAC,CAAC,sBAAsB,CAAC,CAAC;QACjE,WAAW,EAAE,IAAI,2BAAiB,CAAC,CAAC,cAAc,CAAC,CAAC;QACpD,iBAAiB,EAAE,IAAI,kCAAwB,CAAC,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;KAC1F,CAAC;AACJ,CAAC","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 'node:net';\n\nimport type * as TWebpack from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesWaterfallHook } 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 {\n type IWebpackConfiguration,\n type IWebpackPluginAccessor,\n PLUGIN_NAME,\n type IWebpackPluginAccessorHooks\n} from './shared';\nimport { tryLoadWebpackConfigurationAsync } from './WebpackConfigurationLoader';\nimport { type DeferredWatchFileSystem, OverrideNodeWatchFSPlugin } from './DeferredWatchFileSystem';\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath?: string | undefined;\n configurationPath?: string | undefined;\n}\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';\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 | false = false;\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: _createAccessorHooks(),\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 (this._isServeMode && !taskSession.parameters.watch) {\n throw new Error(\n `The ${JSON.stringify(\n SERVE_PARAMETER_LONG_NAME\n )} parameter is only available when running in watch mode.` +\n ` Try replacing \"${taskSession.parsedCommandLine?.unaliasedCommandName}\" with` +\n ` \"${taskSession.parsedCommandLine?.unaliasedCommandName}-watch\" in your Heft command line.`\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 === false) {\n const webpackConfiguration: IWebpackConfiguration | undefined = await tryLoadWebpackConfigurationAsync(\n {\n taskSession,\n heftConfiguration,\n hooks: this.accessor.hooks,\n serveMode: this._isServeMode,\n loadWebpackAsyncFn: this._loadWebpackAsync.bind(this, taskSession, heftConfiguration)\n },\n options\n );\n\n if (webpackConfiguration && 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 this._webpackConfiguration = webpackConfiguration;\n }\n\n return this._webpackConfiguration;\n }\n\n private async _loadWebpackAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration\n ): Promise<typeof TWebpack> {\n if (!this._webpack) {\n try {\n const webpackPackagePath: string = await heftConfiguration.rigPackageResolver.resolvePackageAsync(\n WEBPACK_PACKAGE_NAME,\n taskSession.logger.terminal\n );\n this._webpack = await import(webpackPackagePath);\n } catch (e) {\n // Fallback to bundled version if not found in rig.\n this._webpack = await import(WEBPACK_PACKAGE_NAME);\n taskSession.logger.terminal.writeDebugLine(`Using Webpack from built-in \"${WEBPACK_PACKAGE_NAME}\"`);\n }\n }\n return this._webpack!;\n }\n\n private async _getWebpackCompilerAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n webpackConfiguration: IWebpackConfiguration\n ): Promise<TWebpack.Compiler | TWebpack.MultiCompiler> {\n if (!this._webpackCompiler) {\n const webpack: typeof TWebpack = await this._loadWebpackAsync(taskSession, heftConfiguration);\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 heftConfiguration,\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 heftConfiguration,\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 compiler.hooks.infrastructureLog.tap(\n PLUGIN_NAME,\n (name: string, type: string, args: unknown[] | undefined) => {\n if (name === WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME && type === 'error') {\n const error: Error | undefined = args?.[0] as Error | undefined;\n if (error) {\n taskSession.logger.emitError(error);\n }\n }\n }\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\n const { onGetWatchOptions } = this.accessor.hooks;\n\n const watchOptions: Parameters<TWebpack.Compiler['watch']>[0] = onGetWatchOptions.isUsed()\n ? await onGetWatchOptions.promise({}, webpackConfiguration)\n : {};\n\n compiler.watch(watchOptions, (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\n/**\n * @internal\n */\nexport function _createAccessorHooks(): IWebpackPluginAccessorHooks {\n return {\n onLoadConfiguration: new AsyncSeriesBailHook(),\n onConfigure: new AsyncSeriesHook(['webpackConfiguration']),\n onAfterConfigure: new AsyncParallelHook(['webpackConfiguration']),\n onEmitStats: new AsyncParallelHook(['webpackStats']),\n onGetWatchOptions: new AsyncSeriesWaterfallHook(['watchOptions', 'webpackConfiguration'])\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/heft-webpack5-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Heft plugin for Webpack 5",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"types": "dist/heft-webpack5-plugin.d.ts",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@rushstack/heft": "^1.1.
|
|
15
|
+
"@rushstack/heft": "^1.1.1",
|
|
16
16
|
"webpack": "^5.82.1"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"tapable": "1.1.3",
|
|
21
21
|
"watchpack": "2.4.0",
|
|
22
22
|
"webpack-dev-server": "^5.1.0",
|
|
23
|
-
"@rushstack/
|
|
24
|
-
"@rushstack/
|
|
23
|
+
"@rushstack/debug-certificate-manager": "1.6.1",
|
|
24
|
+
"@rushstack/node-core-library": "5.17.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/watchpack": "2.4.0",
|
|
28
28
|
"eslint": "~9.25.1",
|
|
29
29
|
"webpack": "~5.98.0",
|
|
30
|
-
"@rushstack/
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"@rushstack/heft": "1.1.1",
|
|
31
|
+
"@rushstack/terminal": "0.19.1",
|
|
32
|
+
"local-node-rig": "1.0.0"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "heft build --clean",
|