@rushstack/heft-webpack4-plugin 0.6.9 → 0.7.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.
@@ -70,9 +70,9 @@ export declare interface IWebpackPluginAccessor {
70
70
  export declare interface IWebpackPluginAccessorHooks {
71
71
  /**
72
72
  * A hook that allows for loading custom configurations used by the Webpack
73
- * plugin. If a webpack configuration is provided, this will be populated automatically
74
- * with the exports of the config file. If a webpack configuration is not provided,
75
- * one will be loaded by the Webpack plugin.
73
+ * plugin. If a tap returns a value other than `undefined` before stage {@link STAGE_LOAD_LOCAL_CONFIG},
74
+ * it will suppress loading from the webpack config file. To provide a fallback behavior in the
75
+ * absence of a local config file, tap this hook with a `stage` value greater than {@link STAGE_LOAD_LOCAL_CONFIG}.
76
76
  *
77
77
  * @remarks
78
78
  * Tapable event handlers can return `false` instead of `undefined` to suppress
@@ -111,4 +111,11 @@ export declare interface IWebpackPluginAccessorParameters {
111
111
  */
112
112
  export declare const PluginName: 'webpack4-plugin';
113
113
 
114
+ /**
115
+ * The stage in the `onLoadConfiguration` hook at which the config will be loaded from the local
116
+ * webpack config file.
117
+ * @public
118
+ */
119
+ export declare const STAGE_LOAD_LOCAL_CONFIG: 1000;
120
+
114
121
  export { }
@@ -1,13 +1,9 @@
1
1
  import type { HeftConfiguration, IHeftTaskSession, IHeftTaskPlugin } from '@rushstack/heft';
2
- import type { IWebpackPluginAccessor } from './shared';
2
+ import { type IWebpackPluginAccessor, type IWebpackPluginAccessorHooks } from './shared';
3
3
  export interface IWebpackPluginOptions {
4
- devConfigurationPath: string | undefined;
5
- configurationPath: string | undefined;
4
+ devConfigurationPath?: string | undefined;
5
+ configurationPath?: string | undefined;
6
6
  }
7
- /**
8
- * @public
9
- */
10
- export declare const PLUGIN_NAME: 'webpack4-plugin';
11
7
  /**
12
8
  * @internal
13
9
  */
@@ -23,7 +19,7 @@ export default class Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOpt
23
19
  private _warnings;
24
20
  private _errors;
25
21
  get accessor(): IWebpackPluginAccessor;
26
- apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration, options: IWebpackPluginOptions): void;
22
+ apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration, options?: IWebpackPluginOptions): void;
27
23
  private _getWebpackConfigurationAsync;
28
24
  private _loadWebpackAsync;
29
25
  private _getWebpackCompilerAsync;
@@ -33,4 +29,8 @@ export default class Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOpt
33
29
  private _emitErrors;
34
30
  private _recordErrors;
35
31
  }
32
+ /**
33
+ * @internal
34
+ */
35
+ export declare function _createAccessorHooks(): IWebpackPluginAccessorHooks;
36
36
  //# sourceMappingURL=Webpack4Plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Webpack4Plugin.d.ts","sourceRoot":"","sources":["../src/Webpack4Plugin.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAyB,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAoC9E,MAAM,WAAW,qBAAqB;IACpC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,iBAAqC,CAAC;AAQhE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,eAAe,CAAC,qBAAqB,CAAC;IACnF,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,gBAAgB,CAAuD;IAC/E,OAAO,CAAC,qBAAqB,CAA2E;IACxG,OAAO,CAAC,8BAA8B,CAA4B;IAClE,OAAO,CAAC,uCAAuC,CAA2B;IAC1E,OAAO,C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U5C;IAEM,KAAK,CACV,WAAW,EAAE,gBAAgB,EAC7B,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,GAAE,qBAA0B,GAClC,IAAI;YAsBO,6BAA6B;YAsC7B,iBAAiB;YAQjB,wBAAwB;YAgBxB,gBAAgB;YA8ChB,qBAAqB;IA0LnC,OAAO,CAAC,4BAA4B;IAYpC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,aAAa;CAwBtB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,2BAA2B,CAOlE"}
@@ -25,41 +25,32 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  return result;
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.PLUGIN_NAME = void 0;
28
+ exports._createAccessorHooks = void 0;
29
29
  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
+ const shared_1 = require("./shared");
32
33
  const WebpackConfigurationLoader_1 = require("./WebpackConfigurationLoader");
33
34
  const DeferredWatchFileSystem_1 = require("./DeferredWatchFileSystem");
34
- /**
35
- * @public
36
- */
37
- exports.PLUGIN_NAME = 'webpack4-plugin';
38
35
  const SERVE_PARAMETER_LONG_NAME = '--serve';
39
36
  const WEBPACK_PACKAGE_NAME = 'webpack';
40
37
  const WEBPACK_DEV_SERVER_PACKAGE_NAME = 'webpack-dev-server';
41
38
  const WEBPACK_DEV_SERVER_ENV_VAR_NAME = 'WEBPACK_DEV_SERVER';
42
39
  const WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME = 'webpack-dev-middleware';
43
- const UNINITIALIZED = 'UNINITIALIZED';
44
40
  /**
45
41
  * @internal
46
42
  */
47
43
  class Webpack4Plugin {
48
44
  constructor() {
49
45
  this._isServeMode = false;
50
- this._webpackConfiguration = UNINITIALIZED;
46
+ this._webpackConfiguration = false;
51
47
  this._warnings = [];
52
48
  this._errors = [];
53
49
  }
54
50
  get accessor() {
55
51
  if (!this._accessor) {
56
52
  this._accessor = {
57
- hooks: {
58
- onLoadConfiguration: new tapable_1.AsyncSeriesBailHook(),
59
- onConfigure: new tapable_1.AsyncSeriesHook(['webpackConfiguration']),
60
- onAfterConfigure: new tapable_1.AsyncParallelHook(['webpackConfiguration']),
61
- onEmitStats: new tapable_1.AsyncParallelHook(['webpackStats'])
62
- },
53
+ hooks: _createAccessorHooks(),
63
54
  parameters: {
64
55
  isServeMode: this._isServeMode
65
56
  }
@@ -67,64 +58,42 @@ class Webpack4Plugin {
67
58
  }
68
59
  return this._accessor;
69
60
  }
70
- apply(taskSession, heftConfiguration, options) {
61
+ apply(taskSession, heftConfiguration, options = {}) {
71
62
  this._isServeMode = taskSession.parameters.getFlagParameter(SERVE_PARAMETER_LONG_NAME).value;
72
63
  if (!taskSession.parameters.watch && this._isServeMode) {
73
64
  throw new Error(`The ${JSON.stringify(SERVE_PARAMETER_LONG_NAME)} parameter is only available when running in watch mode.`);
74
65
  }
75
- taskSession.hooks.run.tapPromise(exports.PLUGIN_NAME, async (runOptions) => {
66
+ taskSession.hooks.run.tapPromise(shared_1.PLUGIN_NAME, async (runOptions) => {
76
67
  await this._runWebpackAsync(taskSession, heftConfiguration, options);
77
68
  });
78
- taskSession.hooks.runIncremental.tapPromise(exports.PLUGIN_NAME, async (runOptions) => {
69
+ taskSession.hooks.runIncremental.tapPromise(shared_1.PLUGIN_NAME, async (runOptions) => {
79
70
  await this._runWebpackWatchAsync(taskSession, heftConfiguration, options, runOptions.requestRun);
80
71
  });
81
72
  }
82
73
  async _getWebpackConfigurationAsync(taskSession, heftConfiguration, options, requestRun) {
83
- if (this._webpackConfiguration === UNINITIALIZED) {
84
- // Obtain the webpack configuration by calling into the hook. If undefined
85
- // is returned, load the default Webpack configuration.
86
- taskSession.logger.terminal.writeVerboseLine('Attempting to load Webpack configuration via external plugins');
87
- let webpackConfiguration = await this.accessor.hooks.onLoadConfiguration.promise();
88
- if (webpackConfiguration === undefined) {
89
- taskSession.logger.terminal.writeVerboseLine('Attempt to load the default Webpack configuration');
90
- const configurationLoader = new WebpackConfigurationLoader_1.WebpackConfigurationLoader(taskSession.logger, taskSession.parameters.production, taskSession.parameters.watch && this._isServeMode);
91
- webpackConfiguration = await configurationLoader.tryLoadWebpackConfigurationAsync(Object.assign(Object.assign({}, options), { taskSession,
92
- heftConfiguration, loadWebpackAsyncFn: this._loadWebpackAsync.bind(this) }));
93
- }
94
- if (webpackConfiguration === false) {
95
- taskSession.logger.terminal.writeLine('Webpack disabled by external plugin');
96
- this._webpackConfiguration = undefined;
97
- }
98
- else if (webpackConfiguration === undefined ||
99
- (Array.isArray(webpackConfiguration) && webpackConfiguration.length === 0)) {
100
- taskSession.logger.terminal.writeLine('No Webpack configuration found');
101
- this._webpackConfiguration = undefined;
102
- }
103
- else {
104
- if (this.accessor.hooks.onConfigure.isUsed()) {
105
- // Allow for plugins to customise the configuration
106
- await this.accessor.hooks.onConfigure.promise(webpackConfiguration);
107
- }
108
- if (this.accessor.hooks.onAfterConfigure.isUsed()) {
109
- // Provide the finalized configuration
110
- await this.accessor.hooks.onAfterConfigure.promise(webpackConfiguration);
111
- }
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
- }
74
+ if (this._webpackConfiguration === false) {
75
+ const webpackConfiguration = await (0, WebpackConfigurationLoader_1.tryLoadWebpackConfigurationAsync)({
76
+ taskSession,
77
+ heftConfiguration,
78
+ hooks: this.accessor.hooks,
79
+ serveMode: this._isServeMode,
80
+ loadWebpackAsyncFn: this._loadWebpackAsync.bind(this)
81
+ }, options);
82
+ if (webpackConfiguration && requestRun) {
83
+ const overrideWatchFSPlugin = new DeferredWatchFileSystem_1.OverrideNodeWatchFSPlugin(requestRun);
84
+ this._watchFileSystems = overrideWatchFSPlugin.fileSystems;
85
+ for (const config of Array.isArray(webpackConfiguration)
86
+ ? webpackConfiguration
87
+ : [webpackConfiguration]) {
88
+ if (!config.plugins) {
89
+ config.plugins = [overrideWatchFSPlugin];
90
+ }
91
+ else {
92
+ config.plugins.unshift(overrideWatchFSPlugin);
125
93
  }
126
94
  }
127
95
  }
96
+ this._webpackConfiguration = webpackConfiguration;
128
97
  }
129
98
  return this._webpackConfiguration;
130
99
  }
@@ -201,7 +170,7 @@ class Webpack4Plugin {
201
170
  this._webpackCompilationDonePromiseResolveFn = resolve;
202
171
  });
203
172
  webpackCompilationDonePromise = this._webpackCompilationDonePromise;
204
- compiler.hooks.done.tap(exports.PLUGIN_NAME, (stats) => {
173
+ compiler.hooks.done.tap(shared_1.PLUGIN_NAME, (stats) => {
205
174
  this._webpackCompilationDonePromiseResolveFn();
206
175
  this._webpackCompilationDonePromise = new Promise((resolve) => {
207
176
  this._webpackCompilationDonePromiseResolveFn = resolve;
@@ -279,7 +248,7 @@ class Webpack4Plugin {
279
248
  // Since the webpack-dev-server does not return infrastructure errors via a callback like
280
249
  // compiler.watch(...), we will need to intercept them and log them ourselves.
281
250
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
282
- compiler.hooks.infrastructureLog.tap(exports.PLUGIN_NAME, (name, type, args) => {
251
+ compiler.hooks.infrastructureLog.tap(shared_1.PLUGIN_NAME, (name, type, args) => {
283
252
  if (name === WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME && type === 'error') {
284
253
  const error = args[0];
285
254
  if (error) {
@@ -364,4 +333,16 @@ class Webpack4Plugin {
364
333
  }
365
334
  }
366
335
  exports.default = Webpack4Plugin;
336
+ /**
337
+ * @internal
338
+ */
339
+ function _createAccessorHooks() {
340
+ return {
341
+ onLoadConfiguration: new tapable_1.AsyncSeriesBailHook(),
342
+ onConfigure: new tapable_1.AsyncSeriesHook(['webpackConfiguration']),
343
+ onAfterConfigure: new tapable_1.AsyncParallelHook(['webpackConfiguration']),
344
+ onEmitStats: new tapable_1.AsyncParallelHook(['webpackStats'])
345
+ };
346
+ }
347
+ exports._createAccessorHooks = _createAccessorHooks;
367
348
  //# sourceMappingURL=Webpack4Plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Webpack4Plugin.js","sourceRoot":"","sources":["../src/Webpack4Plugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAK3D,qCAAqG;AACrG,oFAA6F;AAC7F,oEAA6E;AAW7E,6EAA0E;AAC1E,uEAImC;AAmCnC;;GAEG;AACU,QAAA,WAAW,GAAsB,iBAAiB,CAAC;AAChE,MAAM,yBAAyB,GAAc,SAAS,CAAC;AACvD,MAAM,oBAAoB,GAAc,SAAS,CAAC;AAClD,MAAM,+BAA+B,GAAyB,oBAAoB,CAAC;AACnF,MAAM,+BAA+B,GAAyB,oBAAoB,CAAC;AACnF,MAAM,mCAAmC,GAA6B,wBAAwB,CAAC;AAC/F,MAAM,aAAa,GAAoB,eAAe,CAAC;AAEvD;;GAEG;AACH,MAAqB,cAAc;IAAnC;QAEU,iBAAY,GAAY,KAAK,CAAC;QAG9B,0BAAqB,GAA6D,aAAa,CAAC;QAKhG,cAAS,GAAY,EAAE,CAAC;QACxB,YAAO,GAAY,EAAE,CAAC;IA6ZhC,CAAC;IA3ZC,IAAW,QAAQ;QACjB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG;gBACf,KAAK,EAAE;oBACL,mBAAmB,EAAE,IAAI,6BAAmB,EAAE;oBAC9C,WAAW,EAAE,IAAI,yBAAe,CAAC,CAAC,sBAAsB,CAAC,CAAC;oBAC1D,gBAAgB,EAAE,IAAI,2BAA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zB;IACH,CAAC;IAEO,aAAa,CAAC,KAAuD;QAC3E,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAE1B,IAAI,KAAK,CAAC,SAAS,EAAE,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE;YAC5C,MAAM,eAAe,GAAkC,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;YAEzF,KAAK,MAAM,gBAAgB,IAAI,eAAe,EAAE;gBAC9C,KAAK,MAAM,OAAO,IAAI,gBAAgB,CAAC,QAA8B,EAAE;oBACrE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC9E;gBAED,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,MAA4B,EAAE;oBACjE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;iBACtE;gBAED,IAAI,gBAAgB,CAAC,QAAQ,EAAE;oBAC7B,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,QAAQ,EAAE;wBAC7C,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBAC7B;iBACF;aACF;SACF;IACH,CAAC;CACF;AAxaD,iCAwaC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { AddressInfo } from 'net';\nimport type * as TWebpack from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, type SyncBailHook } from 'tapable';\nimport { CertificateManager, type ICertificate } from '@rushstack/debug-certificate-manager';\nimport { InternalError, LegacyAdapters } from '@rushstack/node-core-library';\nimport type {\n HeftConfiguration,\n IHeftTaskSession,\n IHeftTaskPlugin,\n IHeftTaskRunHookOptions,\n IScopedLogger,\n IHeftTaskRunIncrementalHookOptions\n} from '@rushstack/heft';\n\nimport type { IWebpackConfiguration, IWebpackPluginAccessor } from './shared';\nimport { WebpackConfigurationLoader } from './WebpackConfigurationLoader';\nimport {\n DeferredWatchFileSystem,\n type IWatchFileSystem,\n OverrideNodeWatchFSPlugin\n} from './DeferredWatchFileSystem';\n\ntype ExtendedWatching = TWebpack.Watching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedMultiWatching = TWebpack.MultiWatching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedCompiler = TWebpack.Compiler & {\n hooks: TWebpack.Compiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedWatching;\n watchFileSystem: IWatchFileSystem;\n};\n\ntype ExtendedMultiCompiler = TWebpack.MultiCompiler & {\n compilers: ExtendedCompiler[];\n hooks: TWebpack.MultiCompiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedMultiWatching;\n};\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath: string | undefined;\n configurationPath: string | undefined;\n}\n\n/**\n * @public\n */\nexport const PLUGIN_NAME: 'webpack4-plugin' = 'webpack4-plugin';\nconst SERVE_PARAMETER_LONG_NAME: '--serve' = '--serve';\nconst WEBPACK_PACKAGE_NAME: 'webpack' = 'webpack';\nconst WEBPACK_DEV_SERVER_PACKAGE_NAME: 'webpack-dev-server' = 'webpack-dev-server';\nconst WEBPACK_DEV_SERVER_ENV_VAR_NAME: 'WEBPACK_DEV_SERVER' = 'WEBPACK_DEV_SERVER';\nconst WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME: 'webpack-dev-middleware' = 'webpack-dev-middleware';\nconst UNINITIALIZED: 'UNINITIALIZED' = 'UNINITIALIZED';\n\n/**\n * @internal\n */\nexport default class Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOptions> {\n private _accessor: IWebpackPluginAccessor | undefined;\n private _isServeMode: boolean = false;\n private _webpack: typeof TWebpack | undefined;\n private _webpackCompiler: ExtendedCompiler | ExtendedMultiCompiler | undefined;\n private _webpackConfiguration: IWebpackConfiguration | undefined | typeof UNINITIALIZED = UNINITIALIZED;\n private _webpackCompilationDonePromise: Promise<void> | undefined;\n private _webpackCompilationDonePromiseResolveFn: (() => void) | undefined;\n private _watchFileSystems: Set<DeferredWatchFileSystem> | undefined;\n\n private _warnings: Error[] = [];\n private _errors: Error[] = [];\n\n public get accessor(): IWebpackPluginAccessor {\n if (!this._accessor) {\n this._accessor = {\n hooks: {\n onLoadConfiguration: new AsyncSeriesBailHook(),\n onConfigure: new AsyncSeriesHook(['webpackConfiguration']),\n onAfterConfigure: new AsyncParallelHook(['webpackConfiguration']),\n onEmitStats: new AsyncParallelHook(['webpackStats'])\n },\n parameters: {\n isServeMode: this._isServeMode\n }\n };\n }\n return this._accessor;\n }\n\n public apply(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): void {\n this._isServeMode = taskSession.parameters.getFlagParameter(SERVE_PARAMETER_LONG_NAME).value;\n if (!taskSession.parameters.watch && this._isServeMode) {\n throw new Error(\n `The ${JSON.stringify(\n SERVE_PARAMETER_LONG_NAME\n )} parameter is only available when running in watch mode.`\n );\n }\n\n taskSession.hooks.run.tapPromise(PLUGIN_NAME, async (runOptions: IHeftTaskRunHookOptions) => {\n await this._runWebpackAsync(taskSession, heftConfiguration, options);\n });\n\n taskSession.hooks.runIncremental.tapPromise(\n PLUGIN_NAME,\n async (runOptions: IHeftTaskRunIncrementalHookOptions) => {\n await this._runWebpackWatchAsync(taskSession, heftConfiguration, options, runOptions.requestRun);\n }\n );\n }\n\n private async _getWebpackConfigurationAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions,\n requestRun?: () => void\n ): Promise<IWebpackConfiguration | undefined> {\n if (this._webpackConfiguration === UNINITIALIZED) {\n // Obtain the webpack configuration by calling into the hook. If undefined\n // is returned, load the default Webpack configuration.\n taskSession.logger.terminal.writeVerboseLine(\n 'Attempting to load Webpack configuration via external plugins'\n );\n let webpackConfiguration: IWebpackConfiguration | false | undefined =\n await this.accessor.hooks.onLoadConfiguration.promise();\n if (webpackConfiguration === undefined) {\n taskSession.logger.terminal.writeVerboseLine('Attempt to load the default Webpack configuration');\n const configurationLoader: WebpackConfigurationLoader = new WebpackConfigurationLoader(\n taskSession.logger,\n taskSession.parameters.production,\n taskSession.parameters.watch && this._isServeMode\n );\n webpackConfiguration = await configurationLoader.tryLoadWebpackConfigurationAsync({\n ...options,\n taskSession,\n heftConfiguration,\n loadWebpackAsyncFn: this._loadWebpackAsync.bind(this)\n });\n }\n\n if (webpackConfiguration === false) {\n taskSession.logger.terminal.writeLine('Webpack disabled by external plugin');\n this._webpackConfiguration = undefined;\n } else if (\n webpackConfiguration === undefined ||\n (Array.isArray(webpackConfiguration) && webpackConfiguration.length === 0)\n ) {\n taskSession.logger.terminal.writeLine('No Webpack configuration found');\n this._webpackConfiguration = undefined;\n } else {\n if (this.accessor.hooks.onConfigure.isUsed()) {\n // Allow for plugins to customise the configuration\n await this.accessor.hooks.onConfigure.promise(webpackConfiguration);\n }\n if (this.accessor.hooks.onAfterConfigure.isUsed()) {\n // Provide the finalized configuration\n await this.accessor.hooks.onAfterConfigure.promise(webpackConfiguration);\n }\n this._webpackConfiguration = webpackConfiguration;\n\n if (requestRun) {\n const overrideWatchFSPlugin: OverrideNodeWatchFSPlugin = new OverrideNodeWatchFSPlugin(requestRun);\n this._watchFileSystems = overrideWatchFSPlugin.fileSystems;\n for (const config of Array.isArray(webpackConfiguration)\n ? webpackConfiguration\n : [webpackConfiguration]) {\n if (!config.plugins) {\n config.plugins = [overrideWatchFSPlugin];\n } else {\n config.plugins.unshift(overrideWatchFSPlugin);\n }\n }\n }\n }\n }\n return this._webpackConfiguration;\n }\n\n private async _loadWebpackAsync(): Promise<typeof TWebpack> {\n if (!this._webpack) {\n // Allow this to fail if webpack is not installed\n this._webpack = await import(WEBPACK_PACKAGE_NAME);\n }\n return this._webpack!;\n }\n\n private async _getWebpackCompilerAsync(\n taskSession: IHeftTaskSession,\n webpackConfiguration: IWebpackConfiguration\n ): Promise<ExtendedCompiler | ExtendedMultiCompiler> {\n if (!this._webpackCompiler) {\n const webpack: typeof TWebpack = await this._loadWebpackAsync();\n taskSession.logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);\n this._webpackCompiler = Array.isArray(webpackConfiguration)\n ? (webpack.default(\n webpackConfiguration\n ) as ExtendedMultiCompiler) /* (webpack.Compilation[]) => MultiCompiler */\n : (webpack.default(webpackConfiguration) as ExtendedCompiler); /* (webpack.Compilation) => Compiler */\n }\n return this._webpackCompiler;\n }\n\n private async _runWebpackAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): Promise<void> {\n this._validateEnvironmentVariable(taskSession);\n if (taskSession.parameters.watch || this._isServeMode) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in compilation mode when watch mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined = await this._getWebpackConfigurationAsync(\n taskSession,\n heftConfiguration,\n options\n );\n if (!webpackConfiguration) {\n return;\n }\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n taskSession.logger.terminal.writeLine('Running Webpack compilation');\n\n // Run the webpack compiler\n let stats: TWebpack.Stats | TWebpack.MultiStats | undefined;\n try {\n stats = await LegacyAdapters.convertCallbackToPromise(\n (compiler as TWebpack.Compiler).run.bind(compiler)\n );\n } catch (e) {\n taskSession.logger.emitError(e as Error);\n }\n\n // Emit the errors from the stats object, if present\n if (stats) {\n this._recordErrors(stats);\n if (this.accessor.hooks.onEmitStats.isUsed()) {\n await this.accessor.hooks.onEmitStats.promise(stats);\n }\n this._emitErrors(taskSession.logger);\n }\n }\n\n private async _runWebpackWatchAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions,\n requestRun: () => void\n ): Promise<void> {\n // Save a handle to the original promise, since the this-scoped promise will be replaced whenever\n // the compilation completes.\n let webpackCompilationDonePromise: Promise<void> | undefined = this._webpackCompilationDonePromise;\n\n let isInitial: boolean = false;\n\n if (!this._webpackCompiler) {\n isInitial = true;\n this._validateEnvironmentVariable(taskSession);\n if (!taskSession.parameters.watch) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in watch mode when compilation mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined =\n await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options, requestRun);\n if (!webpackConfiguration) {\n return;\n }\n\n // Get the compiler which will be used for both serve and watch mode\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n\n // Set up the hook to detect when the watcher completes the watcher compilation. We will also log out\n // errors from the compilation if present from the output stats object.\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n webpackCompilationDonePromise = this._webpackCompilationDonePromise;\n compiler.hooks.done.tap(PLUGIN_NAME, (stats?: TWebpack.Stats | TWebpack.MultiStats) => {\n this._webpackCompilationDonePromiseResolveFn!();\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n if (stats) {\n this._recordErrors(stats);\n }\n });\n\n // Determine how we will run the compiler. When serving, we will run the compiler\n // via the webpack-dev-server. Otherwise, we will run the compiler directly.\n if (this._isServeMode) {\n const defaultDevServerOptions: TWebpackDevServer.Configuration = {\n host: 'localhost',\n devMiddleware: {\n publicPath: '/',\n stats: {\n cached: false,\n cachedAssets: false,\n colors: heftConfiguration.terminalProvider.supportsColor\n }\n },\n client: {\n logging: 'info',\n webSocketURL: {\n port: 8080\n }\n },\n port: 8080,\n onListening: (server: TWebpackDevServer) => {\n const addressInfo: AddressInfo | string | undefined = server.server?.address() as AddressInfo;\n if (addressInfo) {\n const address: string =\n typeof addressInfo === 'string' ? addressInfo : `${addressInfo.address}:${addressInfo.port}`;\n taskSession.logger.terminal.writeLine(`Started Webpack Dev Server at https://${address}`);\n }\n }\n };\n\n // Obtain the devServerOptions from the webpack configuration, and combine with the default options\n let devServerOptions: TWebpackDevServer.Configuration;\n if (Array.isArray(webpackConfiguration)) {\n const filteredDevServerOptions: TWebpackDevServer.Configuration[] = webpackConfiguration\n .map((configuration) => configuration.devServer)\n .filter((devServer): devServer is TWebpackDevServer.Configuration => !!devServer);\n if (filteredDevServerOptions.length > 1) {\n taskSession.logger.emitWarning(\n new Error(`Detected multiple webpack devServer configurations, using the first one.`)\n );\n }\n devServerOptions = { ...defaultDevServerOptions, ...filteredDevServerOptions[0] };\n } else {\n devServerOptions = { ...defaultDevServerOptions, ...webpackConfiguration.devServer };\n }\n\n // Add the certificate and key to the devServerOptions if these fields don't already have values\n if (!devServerOptions.server) {\n const certificateManager: CertificateManager = new CertificateManager();\n const certificate: ICertificate = await certificateManager.ensureCertificateAsync(\n true,\n taskSession.logger.terminal\n );\n\n // Update the web socket URL to use the hostname provided by the certificate\n const clientConfiguration: TWebpackDevServer.Configuration['client'] = devServerOptions.client;\n const hostname: string | undefined = certificate.subjectAltNames?.[0];\n if (hostname && typeof clientConfiguration === 'object') {\n const { webSocketURL } = clientConfiguration;\n if (typeof webSocketURL === 'object') {\n clientConfiguration.webSocketURL = {\n ...webSocketURL,\n hostname\n };\n }\n }\n\n devServerOptions = {\n ...devServerOptions,\n server: {\n type: 'https',\n options: {\n minVersion: 'TLSv1.3',\n key: certificate.pemKey,\n cert: certificate.pemCertificate,\n ca: certificate.pemCaCertificate\n }\n }\n };\n }\n\n // Since the webpack-dev-server does not return infrastructure errors via a callback like\n // compiler.watch(...), we will need to intercept them and log them ourselves.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n compiler.hooks.infrastructureLog.tap(PLUGIN_NAME, (name: string, type: string, args: any[]) => {\n if (name === WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME && type === 'error') {\n const error: Error | undefined = args[0];\n if (error) {\n taskSession.logger.emitError(error);\n }\n }\n return true;\n });\n\n // The webpack-dev-server package has a design flaw, where merely loading its package will set the\n // WEBPACK_DEV_SERVER environment variable -- even if no APIs are accessed. This environment variable\n // causes incorrect behavior if Heft is not running in serve mode. Thus, we need to be careful to call\n // require() only if Heft is in serve mode.\n taskSession.logger.terminal.writeLine('Starting webpack-dev-server');\n const WebpackDevServer: typeof TWebpackDevServer = (await import(WEBPACK_DEV_SERVER_PACKAGE_NAME))\n .default;\n const webpackDevServer: TWebpackDevServer = new WebpackDevServer(devServerOptions, compiler);\n await webpackDevServer.start();\n } else {\n // Create the watcher. Compilation will start immediately after invoking watch().\n taskSession.logger.terminal.writeLine('Starting Webpack watcher');\n compiler.watch({}, (error?: Error | null) => {\n if (error) {\n taskSession.logger.emitError(error);\n }\n });\n }\n }\n\n let hasChanges: boolean = true;\n if (!isInitial && this._watchFileSystems) {\n hasChanges = false;\n for (const watchFileSystem of this._watchFileSystems) {\n hasChanges = watchFileSystem.flush() || hasChanges;\n }\n }\n\n // Resume the compilation, wait for the compilation to complete, then suspend the watchers until the\n // next iteration. Even if there are no changes, the promise should resolve since resuming from a\n // suspended state invalidates the state of the watcher.\n if (hasChanges) {\n taskSession.logger.terminal.writeLine('Running incremental Webpack compilation');\n await webpackCompilationDonePromise;\n } else {\n taskSession.logger.terminal.writeLine(\n 'Webpack has not detected changes. Listing previous diagnostics.'\n );\n }\n\n this._emitErrors(taskSession.logger);\n }\n\n private _validateEnvironmentVariable(taskSession: IHeftTaskSession): void {\n if (!this._isServeMode && process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {\n taskSession.logger.emitWarning(\n new Error(\n `The \"${WEBPACK_DEV_SERVER_ENV_VAR_NAME}\" environment variable is set, ` +\n 'which will cause problems when webpack is not running in serve mode. ' +\n `(Did a dependency inadvertently load the \"${WEBPACK_DEV_SERVER_PACKAGE_NAME}\" package?)`\n )\n );\n }\n }\n\n private _emitErrors(logger: IScopedLogger): void {\n for (const warning of this._warnings) {\n logger.emitWarning(warning);\n }\n for (const error of this._errors) {\n logger.emitError(error);\n }\n }\n\n private _recordErrors(stats: TWebpack.Stats | TWebpack.compilation.MultiStats): void {\n this._errors.length = 0;\n this._warnings.length = 0;\n\n if (stats.hasErrors() || stats.hasWarnings()) {\n const serializedStats: TWebpack.Stats.ToJsonOutput[] = [stats.toJson('errors-warnings')];\n\n for (const compilationStats of serializedStats) {\n for (const warning of compilationStats.warnings as (string | Error)[]) {\n this._warnings.push(warning instanceof Error ? warning : new Error(warning));\n }\n\n for (const error of compilationStats.errors as (string | Error)[]) {\n this._errors.push(error instanceof Error ? error : new Error(error));\n }\n\n if (compilationStats.children) {\n for (const child of compilationStats.children) {\n serializedStats.push(child);\n }\n }\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Webpack4Plugin.js","sourceRoot":"","sources":["../src/Webpack4Plugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAK3D,qCAAqG;AACrG,oFAA6F;AAC7F,oEAA6E;AAU7E,qCAKkB;AAClB,6EAAgF;AAChF,uEAImC;AAmCnC,MAAM,yBAAyB,GAAc,SAAS,CAAC;AACvD,MAAM,oBAAoB,GAAc,SAAS,CAAC;AAClD,MAAM,+BAA+B,GAAyB,oBAAoB,CAAC;AACnF,MAAM,+BAA+B,GAAyB,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C;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;KACrD,CAAC;AACJ,CAAC;AAPD,oDAOC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { AddressInfo } from 'net';\nimport type * as TWebpack from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, type SyncBailHook } from 'tapable';\nimport { CertificateManager, type ICertificate } from '@rushstack/debug-certificate-manager';\nimport { InternalError, LegacyAdapters } from '@rushstack/node-core-library';\nimport type {\n HeftConfiguration,\n IHeftTaskSession,\n IHeftTaskPlugin,\n IHeftTaskRunHookOptions,\n IScopedLogger,\n IHeftTaskRunIncrementalHookOptions\n} from '@rushstack/heft';\n\nimport {\n PLUGIN_NAME,\n type IWebpackConfiguration,\n type IWebpackPluginAccessor,\n type IWebpackPluginAccessorHooks\n} from './shared';\nimport { tryLoadWebpackConfigurationAsync } from './WebpackConfigurationLoader';\nimport {\n DeferredWatchFileSystem,\n type IWatchFileSystem,\n OverrideNodeWatchFSPlugin\n} from './DeferredWatchFileSystem';\n\ntype ExtendedWatching = TWebpack.Watching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedMultiWatching = TWebpack.MultiWatching & {\n resume: () => void;\n suspend: () => void;\n};\n\ntype ExtendedCompiler = TWebpack.Compiler & {\n hooks: TWebpack.Compiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedWatching;\n watchFileSystem: IWatchFileSystem;\n};\n\ntype ExtendedMultiCompiler = TWebpack.MultiCompiler & {\n compilers: ExtendedCompiler[];\n hooks: TWebpack.MultiCompiler['hooks'] & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n infrastructureLog: SyncBailHook<string, string, any[]>;\n };\n watching: ExtendedMultiWatching;\n};\n\nexport interface IWebpackPluginOptions {\n devConfigurationPath?: string | undefined;\n configurationPath?: string | undefined;\n}\n\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 Webpack4Plugin implements IHeftTaskPlugin<IWebpackPluginOptions> {\n private _accessor: IWebpackPluginAccessor | undefined;\n private _isServeMode: boolean = false;\n private _webpack: typeof TWebpack | undefined;\n private _webpackCompiler: ExtendedCompiler | ExtendedMultiCompiler | undefined;\n private _webpackConfiguration: IWebpackConfiguration | undefined | 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 (!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 === 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<ExtendedCompiler | ExtendedMultiCompiler> {\n if (!this._webpackCompiler) {\n const webpack: typeof TWebpack = await this._loadWebpackAsync();\n taskSession.logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);\n this._webpackCompiler = Array.isArray(webpackConfiguration)\n ? (webpack.default(\n webpackConfiguration\n ) as ExtendedMultiCompiler) /* (webpack.Compilation[]) => MultiCompiler */\n : (webpack.default(webpackConfiguration) as ExtendedCompiler); /* (webpack.Compilation) => Compiler */\n }\n return this._webpackCompiler;\n }\n\n private async _runWebpackAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions\n ): Promise<void> {\n this._validateEnvironmentVariable(taskSession);\n if (taskSession.parameters.watch || this._isServeMode) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in compilation mode when watch mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined = await this._getWebpackConfigurationAsync(\n taskSession,\n heftConfiguration,\n options\n );\n if (!webpackConfiguration) {\n return;\n }\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n taskSession.logger.terminal.writeLine('Running Webpack compilation');\n\n // Run the webpack compiler\n let stats: TWebpack.Stats | TWebpack.MultiStats | undefined;\n try {\n stats = await LegacyAdapters.convertCallbackToPromise(\n (compiler as TWebpack.Compiler).run.bind(compiler)\n );\n } catch (e) {\n taskSession.logger.emitError(e as Error);\n }\n\n // Emit the errors from the stats object, if present\n if (stats) {\n this._recordErrors(stats);\n if (this.accessor.hooks.onEmitStats.isUsed()) {\n await this.accessor.hooks.onEmitStats.promise(stats);\n }\n this._emitErrors(taskSession.logger);\n }\n }\n\n private async _runWebpackWatchAsync(\n taskSession: IHeftTaskSession,\n heftConfiguration: HeftConfiguration,\n options: IWebpackPluginOptions,\n requestRun: () => void\n ): Promise<void> {\n // Save a handle to the original promise, since the this-scoped promise will be replaced whenever\n // the compilation completes.\n let webpackCompilationDonePromise: Promise<void> | undefined = this._webpackCompilationDonePromise;\n\n let isInitial: boolean = false;\n\n if (!this._webpackCompiler) {\n isInitial = true;\n this._validateEnvironmentVariable(taskSession);\n if (!taskSession.parameters.watch) {\n // Should never happen, but just in case\n throw new InternalError('Cannot run Webpack in watch mode when compilation mode is enabled');\n }\n\n // Load the config and compiler, and return if there is no config found\n const webpackConfiguration: IWebpackConfiguration | undefined =\n await this._getWebpackConfigurationAsync(taskSession, heftConfiguration, options, requestRun);\n if (!webpackConfiguration) {\n return;\n }\n\n // Get the compiler which will be used for both serve and watch mode\n const compiler: ExtendedCompiler | ExtendedMultiCompiler = await this._getWebpackCompilerAsync(\n taskSession,\n webpackConfiguration\n );\n\n // Set up the hook to detect when the watcher completes the watcher compilation. We will also log out\n // errors from the compilation if present from the output stats object.\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n webpackCompilationDonePromise = this._webpackCompilationDonePromise;\n compiler.hooks.done.tap(PLUGIN_NAME, (stats?: TWebpack.Stats | TWebpack.MultiStats) => {\n this._webpackCompilationDonePromiseResolveFn!();\n this._webpackCompilationDonePromise = new Promise((resolve: () => void) => {\n this._webpackCompilationDonePromiseResolveFn = resolve;\n });\n if (stats) {\n this._recordErrors(stats);\n }\n });\n\n // Determine how we will run the compiler. When serving, we will run the compiler\n // via the webpack-dev-server. Otherwise, we will run the compiler directly.\n if (this._isServeMode) {\n const defaultDevServerOptions: TWebpackDevServer.Configuration = {\n host: 'localhost',\n devMiddleware: {\n publicPath: '/',\n stats: {\n cached: false,\n cachedAssets: false,\n colors: heftConfiguration.terminalProvider.supportsColor\n }\n },\n client: {\n logging: 'info',\n webSocketURL: {\n port: 8080\n }\n },\n port: 8080,\n onListening: (server: TWebpackDevServer) => {\n const addressInfo: AddressInfo | string | undefined = server.server?.address() as AddressInfo;\n if (addressInfo) {\n const address: string =\n typeof addressInfo === 'string' ? addressInfo : `${addressInfo.address}:${addressInfo.port}`;\n taskSession.logger.terminal.writeLine(`Started Webpack Dev Server at https://${address}`);\n }\n }\n };\n\n // Obtain the devServerOptions from the webpack configuration, and combine with the default options\n let devServerOptions: TWebpackDevServer.Configuration;\n if (Array.isArray(webpackConfiguration)) {\n const filteredDevServerOptions: TWebpackDevServer.Configuration[] = webpackConfiguration\n .map((configuration) => configuration.devServer)\n .filter((devServer): devServer is TWebpackDevServer.Configuration => !!devServer);\n if (filteredDevServerOptions.length > 1) {\n taskSession.logger.emitWarning(\n new Error(`Detected multiple webpack devServer configurations, using the first one.`)\n );\n }\n devServerOptions = { ...defaultDevServerOptions, ...filteredDevServerOptions[0] };\n } else {\n devServerOptions = { ...defaultDevServerOptions, ...webpackConfiguration.devServer };\n }\n\n // Add the certificate and key to the devServerOptions if these fields don't already have values\n if (!devServerOptions.server) {\n const certificateManager: CertificateManager = new CertificateManager();\n const certificate: ICertificate = await certificateManager.ensureCertificateAsync(\n true,\n taskSession.logger.terminal\n );\n\n // Update the web socket URL to use the hostname provided by the certificate\n const clientConfiguration: TWebpackDevServer.Configuration['client'] = devServerOptions.client;\n const hostname: string | undefined = certificate.subjectAltNames?.[0];\n if (hostname && typeof clientConfiguration === 'object') {\n const { webSocketURL } = clientConfiguration;\n if (typeof webSocketURL === 'object') {\n clientConfiguration.webSocketURL = {\n ...webSocketURL,\n hostname\n };\n }\n }\n\n devServerOptions = {\n ...devServerOptions,\n server: {\n type: 'https',\n options: {\n minVersion: 'TLSv1.3',\n key: certificate.pemKey,\n cert: certificate.pemCertificate,\n ca: certificate.pemCaCertificate\n }\n }\n };\n }\n\n // Since the webpack-dev-server does not return infrastructure errors via a callback like\n // compiler.watch(...), we will need to intercept them and log them ourselves.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n compiler.hooks.infrastructureLog.tap(PLUGIN_NAME, (name: string, type: string, args: any[]) => {\n if (name === WEBPACK_DEV_MIDDLEWARE_PACKAGE_NAME && type === 'error') {\n const error: Error | undefined = args[0];\n if (error) {\n taskSession.logger.emitError(error);\n }\n }\n return true;\n });\n\n // The webpack-dev-server package has a design flaw, where merely loading its package will set the\n // WEBPACK_DEV_SERVER environment variable -- even if no APIs are accessed. This environment variable\n // causes incorrect behavior if Heft is not running in serve mode. Thus, we need to be careful to call\n // require() only if Heft is in serve mode.\n taskSession.logger.terminal.writeLine('Starting webpack-dev-server');\n const WebpackDevServer: typeof TWebpackDevServer = (await import(WEBPACK_DEV_SERVER_PACKAGE_NAME))\n .default;\n const webpackDevServer: TWebpackDevServer = new WebpackDevServer(devServerOptions, compiler);\n await webpackDevServer.start();\n } else {\n // Create the watcher. Compilation will start immediately after invoking watch().\n taskSession.logger.terminal.writeLine('Starting Webpack watcher');\n compiler.watch({}, (error?: Error | null) => {\n if (error) {\n taskSession.logger.emitError(error);\n }\n });\n }\n }\n\n let hasChanges: boolean = true;\n if (!isInitial && this._watchFileSystems) {\n hasChanges = false;\n for (const watchFileSystem of this._watchFileSystems) {\n hasChanges = watchFileSystem.flush() || hasChanges;\n }\n }\n\n // Resume the compilation, wait for the compilation to complete, then suspend the watchers until the\n // next iteration. Even if there are no changes, the promise should resolve since resuming from a\n // suspended state invalidates the state of the watcher.\n if (hasChanges) {\n taskSession.logger.terminal.writeLine('Running incremental Webpack compilation');\n await webpackCompilationDonePromise;\n } else {\n taskSession.logger.terminal.writeLine(\n 'Webpack has not detected changes. Listing previous diagnostics.'\n );\n }\n\n this._emitErrors(taskSession.logger);\n }\n\n private _validateEnvironmentVariable(taskSession: IHeftTaskSession): void {\n if (!this._isServeMode && process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {\n taskSession.logger.emitWarning(\n new Error(\n `The \"${WEBPACK_DEV_SERVER_ENV_VAR_NAME}\" environment variable is set, ` +\n 'which will cause problems when webpack is not running in serve mode. ' +\n `(Did a dependency inadvertently load the \"${WEBPACK_DEV_SERVER_PACKAGE_NAME}\" package?)`\n )\n );\n }\n }\n\n private _emitErrors(logger: IScopedLogger): void {\n for (const warning of this._warnings) {\n logger.emitWarning(warning);\n }\n for (const error of this._errors) {\n logger.emitError(error);\n }\n }\n\n private _recordErrors(stats: TWebpack.Stats | TWebpack.compilation.MultiStats): void {\n this._errors.length = 0;\n this._warnings.length = 0;\n\n if (stats.hasErrors() || stats.hasWarnings()) {\n const serializedStats: TWebpack.Stats.ToJsonOutput[] = [stats.toJson('errors-warnings')];\n\n for (const compilationStats of serializedStats) {\n for (const warning of compilationStats.warnings as (string | Error)[]) {\n this._warnings.push(warning instanceof Error ? warning : new Error(warning));\n }\n\n for (const error of compilationStats.errors as (string | Error)[]) {\n this._errors.push(error instanceof Error ? error : new Error(error));\n }\n\n if (compilationStats.children) {\n for (const child of compilationStats.children) {\n serializedStats.push(child);\n }\n }\n }\n }\n }\n}\n\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 };\n}\n"]}
@@ -1,19 +1,33 @@
1
1
  import type * as TWebpack from 'webpack';
2
- import type { IScopedLogger, IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';
2
+ import type { IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';
3
3
  import type { IWebpackPluginOptions } from './Webpack4Plugin';
4
- import type { IWebpackConfiguration } from './shared';
5
- interface ILoadWebpackConfigurationOptions extends IWebpackPluginOptions {
4
+ import { type IWebpackConfiguration, type IWebpackConfigurationFnEnvironment, type IWebpackPluginAccessorHooks } from './shared';
5
+ type IWebpackConfigJsExport = TWebpack.Configuration | TWebpack.Configuration[] | Promise<TWebpack.Configuration> | Promise<TWebpack.Configuration[]> | ((env: IWebpackConfigurationFnEnvironment) => TWebpack.Configuration | TWebpack.Configuration[]) | ((env: IWebpackConfigurationFnEnvironment) => Promise<TWebpack.Configuration | TWebpack.Configuration[]>);
6
+ type IWebpackConfigJs = IWebpackConfigJsExport | {
7
+ default: IWebpackConfigJsExport;
8
+ };
9
+ /**
10
+ * @internal
11
+ */
12
+ export interface ILoadWebpackConfigurationOptions {
6
13
  taskSession: IHeftTaskSession;
7
14
  heftConfiguration: HeftConfiguration;
15
+ serveMode: boolean;
8
16
  loadWebpackAsyncFn: () => Promise<typeof TWebpack>;
17
+ hooks: Pick<IWebpackPluginAccessorHooks, 'onLoadConfiguration' | 'onConfigure' | 'onAfterConfigure'>;
18
+ _tryLoadConfigFileAsync?: typeof tryLoadWebpackConfigurationFileAsync;
9
19
  }
10
- export declare class WebpackConfigurationLoader {
11
- private readonly _logger;
12
- private readonly _production;
13
- private readonly _serveMode;
14
- constructor(logger: IScopedLogger, production: boolean, serveMode: boolean);
15
- tryLoadWebpackConfigurationAsync(options: ILoadWebpackConfigurationOptions): Promise<IWebpackConfiguration | undefined>;
16
- private _tryLoadWebpackConfigurationInnerAsync;
17
- }
20
+ /**
21
+ * @internal
22
+ */
23
+ export declare function tryLoadWebpackConfigurationAsync(options: ILoadWebpackConfigurationOptions, pluginOptions: IWebpackPluginOptions): Promise<IWebpackConfiguration | undefined>;
24
+ /**
25
+ * @internal
26
+ */
27
+ export declare function tryLoadWebpackConfigurationFileAsync(options: ILoadWebpackConfigurationOptions, pluginOptions: IWebpackPluginOptions): Promise<IWebpackConfiguration | undefined>;
28
+ /**
29
+ * @internal
30
+ */
31
+ export declare function _tryLoadWebpackConfigurationFileInnerAsync(configurationPath: string): Promise<IWebpackConfigJs | undefined>;
18
32
  export {};
19
33
  //# sourceMappingURL=WebpackConfigurationLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebpackConfigurationLoader.d.ts","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,QAAQ,MAAM,SAAS,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,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CAAC,GACjC,CAAC,CAAC,GAAG,EAAE,kCAAkC,KAAK,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC,GAChG,CAAC,CAAC,GAAG,EAAE,kCAAkC,KAAK,OAAO,CAAC,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;AAC9G,KAAK,gBAAgB,GAAG,sBAAsB,GAAG;IAAE,OAAO,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAErF;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,WAAW,EAAE,gBAAgB,CAAC;IAC9B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,kBAAkB,EAAE,MAAM,OAAO,CAAC,OAAO,QAAQ,CAAC,CAAC;IACnD,KAAK,EAAE,IAAI,CAAC,2BAA2B,EAAE,qBAAqB,GAAG,aAAa,GAAG,kBAAkB,CAAC,CAAC;IAErG,uBAAuB,CAAC,EAAE,OAAO,oCAAoC,CAAC;CACvE;AAKD;;GAEG;AACH,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,gCAAgC,EACzC,aAAa,EAAE,qBAAqB,GACnC,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAqD5C;AAED;;GAEG;AACH,wBAAsB,oCAAoC,CACxD,OAAO,EAAE,gCAAgC,EACzC,aAAa,EAAE,qBAAqB,GACnC,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAuD5C;AAED;;GAEG;AACH,wBAAsB,0CAA0C,CAC9D,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAgBvC"}
@@ -25,77 +25,127 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  return result;
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.WebpackConfigurationLoader = void 0;
28
+ exports._tryLoadWebpackConfigurationFileInnerAsync = exports.tryLoadWebpackConfigurationFileAsync = exports.tryLoadWebpackConfigurationAsync = void 0;
29
29
  const path = __importStar(require("path"));
30
30
  const node_core_library_1 = require("@rushstack/node-core-library");
31
+ const shared_1 = require("./shared");
31
32
  const DEFAULT_WEBPACK_CONFIG_PATH = './webpack.config.js';
32
33
  const DEFAULT_WEBPACK_DEV_CONFIG_PATH = './webpack.dev.config.js';
33
- class WebpackConfigurationLoader {
34
- constructor(logger, production, serveMode) {
35
- this._logger = logger;
36
- this._production = production;
37
- this._serveMode = serveMode;
34
+ /**
35
+ * @internal
36
+ */
37
+ async function tryLoadWebpackConfigurationAsync(options, pluginOptions) {
38
+ const { taskSession, hooks, _tryLoadConfigFileAsync = tryLoadWebpackConfigurationFileAsync } = options;
39
+ const { logger } = taskSession;
40
+ const { terminal } = logger;
41
+ // Apply default behavior. Due to the state of `this._webpackConfiguration`, this code
42
+ // will execute exactly once.
43
+ hooks.onLoadConfiguration.tapPromise({
44
+ name: shared_1.PLUGIN_NAME,
45
+ stage: shared_1.STAGE_LOAD_LOCAL_CONFIG
46
+ }, async () => {
47
+ terminal.writeVerboseLine(`Attempting to load Webpack configuration from local file`);
48
+ const webpackConfiguration = await _tryLoadConfigFileAsync(options, pluginOptions);
49
+ if (webpackConfiguration) {
50
+ terminal.writeVerboseLine(`Loaded Webpack configuration from local file.`);
51
+ }
52
+ return webpackConfiguration;
53
+ });
54
+ // Obtain the webpack configuration by calling into the hook.
55
+ // The local configuration is loaded at STAGE_LOAD_LOCAL_CONFIG
56
+ terminal.writeVerboseLine('Attempting to load Webpack configuration');
57
+ let webpackConfiguration = await hooks.onLoadConfiguration.promise();
58
+ if (webpackConfiguration === false) {
59
+ terminal.writeLine('Webpack disabled by external plugin');
60
+ webpackConfiguration = undefined;
38
61
  }
39
- async tryLoadWebpackConfigurationAsync(options) {
40
- // TODO: Eventually replace this custom logic with a call to this utility in in webpack-cli:
41
- // https://github.com/webpack/webpack-cli/blob/next/packages/webpack-cli/lib/groups/ConfigGroup.js
42
- const { taskSession, heftConfiguration, configurationPath, devConfigurationPath, loadWebpackAsyncFn } = options;
43
- let webpackConfigJs;
44
- try {
45
- const buildFolderPath = heftConfiguration.buildFolderPath;
46
- if (this._serveMode) {
47
- const devConfigPath = path.resolve(buildFolderPath, devConfigurationPath || DEFAULT_WEBPACK_DEV_CONFIG_PATH);
48
- this._logger.terminal.writeVerboseLine(`Attempting to load webpack configuration from "${devConfigPath}".`);
49
- webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(devConfigPath);
50
- }
51
- if (!webpackConfigJs) {
52
- const configPath = path.resolve(buildFolderPath, configurationPath || DEFAULT_WEBPACK_CONFIG_PATH);
53
- this._logger.terminal.writeVerboseLine(`Attempting to load webpack configuration from "${configPath}".`);
54
- webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(configPath);
55
- }
62
+ else if (webpackConfiguration === undefined ||
63
+ (Array.isArray(webpackConfiguration) && webpackConfiguration.length === 0)) {
64
+ terminal.writeLine('No Webpack configuration found');
65
+ webpackConfiguration = undefined;
66
+ }
67
+ else {
68
+ if (hooks.onConfigure.isUsed()) {
69
+ // Allow for plugins to customise the configuration
70
+ await hooks.onConfigure.promise(webpackConfiguration);
56
71
  }
57
- catch (error) {
58
- this._logger.emitError(error);
72
+ if (hooks.onAfterConfigure.isUsed()) {
73
+ // Provide the finalized configuration
74
+ await hooks.onAfterConfigure.promise(webpackConfiguration);
59
75
  }
60
- if (webpackConfigJs) {
61
- const webpackConfig = webpackConfigJs.default || webpackConfigJs;
62
- if (typeof webpackConfig === 'function') {
63
- // Defer loading of webpack until we know for sure that we will need it
64
- return webpackConfig({
65
- prod: this._production,
66
- production: this._production,
67
- taskSession,
68
- heftConfiguration,
69
- webpack: await loadWebpackAsyncFn()
70
- });
71
- }
72
- else {
73
- return webpackConfig;
74
- }
76
+ }
77
+ return webpackConfiguration;
78
+ }
79
+ exports.tryLoadWebpackConfigurationAsync = tryLoadWebpackConfigurationAsync;
80
+ /**
81
+ * @internal
82
+ */
83
+ async function tryLoadWebpackConfigurationFileAsync(options, pluginOptions) {
84
+ // TODO: Eventually replace this custom logic with a call to this utility in in webpack-cli:
85
+ // https://github.com/webpack/webpack-cli/blob/next/packages/webpack-cli/lib/groups/ConfigGroup.js
86
+ const { taskSession, heftConfiguration, loadWebpackAsyncFn, serveMode } = options;
87
+ const { logger, parameters: { production } } = taskSession;
88
+ const { terminal } = logger;
89
+ const { configurationPath, devConfigurationPath } = pluginOptions;
90
+ let webpackConfigJs;
91
+ try {
92
+ const buildFolderPath = heftConfiguration.buildFolderPath;
93
+ if (serveMode) {
94
+ const devConfigPath = path.resolve(buildFolderPath, devConfigurationPath || DEFAULT_WEBPACK_DEV_CONFIG_PATH);
95
+ terminal.writeVerboseLine(`Attempting to load webpack configuration from "${devConfigPath}".`);
96
+ webpackConfigJs = await _tryLoadWebpackConfigurationFileInnerAsync(devConfigPath);
75
97
  }
76
- else {
77
- return undefined;
98
+ if (!webpackConfigJs) {
99
+ const configPath = path.resolve(buildFolderPath, configurationPath || DEFAULT_WEBPACK_CONFIG_PATH);
100
+ terminal.writeVerboseLine(`Attempting to load webpack configuration from "${configPath}".`);
101
+ webpackConfigJs = await _tryLoadWebpackConfigurationFileInnerAsync(configPath);
78
102
  }
79
103
  }
80
- async _tryLoadWebpackConfigurationInnerAsync(configurationPath) {
81
- const configExists = await node_core_library_1.FileSystem.existsAsync(configurationPath);
82
- if (configExists) {
83
- try {
84
- return await Promise.resolve(`${configurationPath}`).then(s => __importStar(require(s)));
85
- }
86
- catch (e) {
87
- const error = e;
88
- if (error.code === 'ERR_MODULE_NOT_FOUND') {
89
- // No configuration found, return undefined.
90
- return undefined;
91
- }
92
- throw new Error(`Error loading webpack configuration at "${configurationPath}": ${e}`);
93
- }
104
+ catch (error) {
105
+ logger.emitError(error);
106
+ }
107
+ if (webpackConfigJs) {
108
+ const webpackConfig = webpackConfigJs.default || webpackConfigJs;
109
+ if (typeof webpackConfig === 'function') {
110
+ // Defer loading of webpack until we know for sure that we will need it
111
+ return webpackConfig({
112
+ prod: production,
113
+ production,
114
+ taskSession,
115
+ heftConfiguration,
116
+ webpack: await loadWebpackAsyncFn()
117
+ });
94
118
  }
95
119
  else {
96
- return undefined;
120
+ return webpackConfig;
121
+ }
122
+ }
123
+ else {
124
+ return undefined;
125
+ }
126
+ }
127
+ exports.tryLoadWebpackConfigurationFileAsync = tryLoadWebpackConfigurationFileAsync;
128
+ /**
129
+ * @internal
130
+ */
131
+ async function _tryLoadWebpackConfigurationFileInnerAsync(configurationPath) {
132
+ const configExists = await node_core_library_1.FileSystem.existsAsync(configurationPath);
133
+ if (configExists) {
134
+ try {
135
+ return await Promise.resolve(`${configurationPath}`).then(s => __importStar(require(s)));
97
136
  }
137
+ catch (e) {
138
+ const error = e;
139
+ if (error.code === 'ERR_MODULE_NOT_FOUND') {
140
+ // No configuration found, return undefined.
141
+ return undefined;
142
+ }
143
+ throw new Error(`Error loading webpack configuration at "${configurationPath}": ${e}`);
144
+ }
145
+ }
146
+ else {
147
+ return undefined;
98
148
  }
99
149
  }
100
- exports.WebpackConfigurationLoader = WebpackConfigurationLoader;
150
+ exports._tryLoadWebpackConfigurationFileInnerAsync = _tryLoadWebpackConfigurationFileInnerAsync;
101
151
  //# sourceMappingURL=WebpackConfigurationLoader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebpackConfigurationLoader.js","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAE7B,oEAA0D;AAqB1D,MAAM,2BAA2B,GAA0B,qBAAqB,CAAC;AACjF,MAAM,+BAA+B,GAA8B,yBAAyB,CAAC;AAE7F,MAAa,0BAA0B;IAKrC,YAAmB,MAAqB,EAAE,UAAmB,EAAE,SAAkB;QAC/E,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAA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EAAE,IAAI,CAAC,WAAW;oBAC5B,WAAW;oBACX,iBAAiB;oBACjB,OAAO,EAAE,MAAM,kBAAkB,EAAE;iBACpC,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,aAAa,CAAC;aACtB;SACF;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;IAEO,KAAK,CAAC,sCAAsC,CAClD,iBAAyB;QAEzB,MAAM,YAAY,GAAY,MAAM,8BAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QAC9E,IAAI,YAAY,EAAE;YAChB,IAAI;gBACF,OAAO,yBAAa,iBAAiB,uCAAC,CAAC;aACxC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,KAAK,GAA0B,CAA0B,CAAC;gBAChE,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE;oBACzC,4CAA4C;oBAC5C,OAAO,SAAS,CAAC;iBAClB;gBACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,iBAAiB,MAAM,CAAC,EAAE,CAAC,CAAC;aACxF;SACF;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;CACF;AAxFD,gEAwFC","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 * as path from 'path';\nimport type * as TWebpack from 'webpack';\nimport { FileSystem } from '@rushstack/node-core-library';\nimport type { IScopedLogger, IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';\n\nimport type { IWebpackPluginOptions } from './Webpack4Plugin';\nimport type { IWebpackConfiguration, IWebpackConfigurationFnEnvironment } from './shared';\n\ntype IWebpackConfigJsExport =\n | TWebpack.Configuration\n | TWebpack.Configuration[]\n | Promise<TWebpack.Configuration>\n | Promise<TWebpack.Configuration[]>\n | ((env: IWebpackConfigurationFnEnvironment) => TWebpack.Configuration | TWebpack.Configuration[])\n | ((env: IWebpackConfigurationFnEnvironment) => Promise<TWebpack.Configuration | TWebpack.Configuration[]>);\ntype IWebpackConfigJs = IWebpackConfigJsExport | { default: IWebpackConfigJsExport };\n\ninterface ILoadWebpackConfigurationOptions extends IWebpackPluginOptions {\n taskSession: IHeftTaskSession;\n heftConfiguration: HeftConfiguration;\n loadWebpackAsyncFn: () => Promise<typeof TWebpack>;\n}\n\nconst DEFAULT_WEBPACK_CONFIG_PATH: './webpack.config.js' = './webpack.config.js';\nconst DEFAULT_WEBPACK_DEV_CONFIG_PATH: './webpack.dev.config.js' = './webpack.dev.config.js';\n\nexport class WebpackConfigurationLoader {\n private readonly _logger: IScopedLogger;\n private readonly _production: boolean;\n private readonly _serveMode: boolean;\n\n public constructor(logger: IScopedLogger, production: boolean, serveMode: boolean) {\n this._logger = logger;\n this._production = production;\n this._serveMode = serveMode;\n }\n\n public async tryLoadWebpackConfigurationAsync(\n options: ILoadWebpackConfigurationOptions\n ): Promise<IWebpackConfiguration | undefined> {\n // TODO: Eventually replace this custom logic with a call to this utility in in webpack-cli:\n // https://github.com/webpack/webpack-cli/blob/next/packages/webpack-cli/lib/groups/ConfigGroup.js\n\n const { taskSession, heftConfiguration, configurationPath, devConfigurationPath, loadWebpackAsyncFn } =\n options;\n let webpackConfigJs: IWebpackConfigJs | undefined;\n\n try {\n const buildFolderPath: string = heftConfiguration.buildFolderPath;\n if (this._serveMode) {\n const devConfigPath: string = path.resolve(\n buildFolderPath,\n devConfigurationPath || DEFAULT_WEBPACK_DEV_CONFIG_PATH\n );\n this._logger.terminal.writeVerboseLine(\n `Attempting to load webpack configuration from \"${devConfigPath}\".`\n );\n webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(devConfigPath);\n }\n\n if (!webpackConfigJs) {\n const configPath: string = path.resolve(\n buildFolderPath,\n configurationPath || DEFAULT_WEBPACK_CONFIG_PATH\n );\n this._logger.terminal.writeVerboseLine(\n `Attempting to load webpack configuration from \"${configPath}\".`\n );\n webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(configPath);\n }\n } catch (error) {\n this._logger.emitError(error as Error);\n }\n\n if (webpackConfigJs) {\n const webpackConfig: IWebpackConfigJsExport =\n (webpackConfigJs as { default: IWebpackConfigJsExport }).default || webpackConfigJs;\n\n if (typeof webpackConfig === 'function') {\n // Defer loading of webpack until we know for sure that we will need it\n return webpackConfig({\n prod: this._production,\n production: this._production,\n taskSession,\n heftConfiguration,\n webpack: await loadWebpackAsyncFn()\n });\n } else {\n return webpackConfig;\n }\n } else {\n return undefined;\n }\n }\n\n private async _tryLoadWebpackConfigurationInnerAsync(\n configurationPath: string\n ): Promise<IWebpackConfigJs | undefined> {\n const configExists: boolean = await FileSystem.existsAsync(configurationPath);\n if (configExists) {\n try {\n return await import(configurationPath);\n } catch (e) {\n const error: NodeJS.ErrnoException = e as NodeJS.ErrnoException;\n if (error.code === 'ERR_MODULE_NOT_FOUND') {\n // No configuration found, return undefined.\n return undefined;\n }\n throw new Error(`Error loading webpack configuration at \"${configurationPath}\": ${e}`);\n }\n } else {\n return undefined;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"WebpackConfigurationLoader.js","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAE7B,oEAA0D;AAI1D,qCAMkB;AAwBlB,MAAM,2BAA2B,GAA0B,qBAAqB,CAAC;AACjF,MAAM,+BAA+B,GAA8B,yBAAyB,CAAC;AAE7F;;GAEG;AACI,KAAK,UAAU,gCAAgC,CACpD,OAAyC,EACzC,aAAoC;IAEpC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,uBAAuB,GAAG,oCAAoC,EAAE,GAAG,OAAO,CAAC;IACvG,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC;IAC/B,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE5B,sFAAsF;IACtF,6BAA6B;IAC7B,KAAK,CAAC,mBAAmB,CAAC,UAAU,CACl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BAChB,UAAU;gBACV,WAAW;gBACX,iBAAiB;gBACjB,OAAO,EAAE,MAAM,kBAAkB,EAAE;aACpC,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,aAAa,CAAC;SACtB;KACF;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AA1DD,oFA0DC;AAED;;GAEG;AACI,KAAK,UAAU,0CAA0C,CAC9D,iBAAyB;IAEzB,MAAM,YAAY,GAAY,MAAM,8BAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC9E,IAAI,YAAY,EAAE;QAChB,IAAI;YACF,OAAO,yBAAa,iBAAiB,uCAAC,CAAC;SACxC;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,KAAK,GAA0B,CAA0B,CAAC;YAChE,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE;gBACzC,4CAA4C;gBAC5C,OAAO,SAAS,CAAC;aAClB;YACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,iBAAiB,MAAM,CAAC,EAAE,CAAC,CAAC;SACxF;KACF;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAlBD,gGAkBC","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 * as path from 'path';\nimport type * as TWebpack from 'webpack';\nimport { FileSystem } from '@rushstack/node-core-library';\nimport type { IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';\n\nimport type { IWebpackPluginOptions } from './Webpack4Plugin';\nimport {\n PLUGIN_NAME,\n STAGE_LOAD_LOCAL_CONFIG,\n type IWebpackConfiguration,\n type IWebpackConfigurationFnEnvironment,\n type IWebpackPluginAccessorHooks\n} from './shared';\n\ntype IWebpackConfigJsExport =\n | TWebpack.Configuration\n | TWebpack.Configuration[]\n | Promise<TWebpack.Configuration>\n | Promise<TWebpack.Configuration[]>\n | ((env: IWebpackConfigurationFnEnvironment) => TWebpack.Configuration | TWebpack.Configuration[])\n | ((env: IWebpackConfigurationFnEnvironment) => Promise<TWebpack.Configuration | TWebpack.Configuration[]>);\ntype IWebpackConfigJs = IWebpackConfigJsExport | { default: IWebpackConfigJsExport };\n\n/**\n * @internal\n */\nexport interface ILoadWebpackConfigurationOptions {\n taskSession: IHeftTaskSession;\n heftConfiguration: HeftConfiguration;\n serveMode: boolean;\n loadWebpackAsyncFn: () => Promise<typeof TWebpack>;\n hooks: Pick<IWebpackPluginAccessorHooks, 'onLoadConfiguration' | 'onConfigure' | 'onAfterConfigure'>;\n\n _tryLoadConfigFileAsync?: typeof tryLoadWebpackConfigurationFileAsync;\n}\n\nconst DEFAULT_WEBPACK_CONFIG_PATH: './webpack.config.js' = './webpack.config.js';\nconst DEFAULT_WEBPACK_DEV_CONFIG_PATH: './webpack.dev.config.js' = './webpack.dev.config.js';\n\n/**\n * @internal\n */\nexport async function tryLoadWebpackConfigurationAsync(\n options: ILoadWebpackConfigurationOptions,\n pluginOptions: IWebpackPluginOptions\n): Promise<IWebpackConfiguration | undefined> {\n const { taskSession, hooks, _tryLoadConfigFileAsync = tryLoadWebpackConfigurationFileAsync } = options;\n const { logger } = taskSession;\n const { terminal } = logger;\n\n // Apply default behavior. Due to the state of `this._webpackConfiguration`, this code\n // will execute exactly once.\n hooks.onLoadConfiguration.tapPromise(\n {\n name: PLUGIN_NAME,\n stage: STAGE_LOAD_LOCAL_CONFIG\n },\n async () => {\n terminal.writeVerboseLine(`Attempting to load Webpack configuration from local file`);\n const webpackConfiguration: IWebpackConfiguration | undefined = await _tryLoadConfigFileAsync(\n options,\n pluginOptions\n );\n\n if (webpackConfiguration) {\n terminal.writeVerboseLine(`Loaded Webpack configuration from local file.`);\n }\n\n return webpackConfiguration;\n }\n );\n\n // Obtain the webpack configuration by calling into the hook.\n // The local configuration is loaded at STAGE_LOAD_LOCAL_CONFIG\n terminal.writeVerboseLine('Attempting to load Webpack configuration');\n let webpackConfiguration: IWebpackConfiguration | false | undefined =\n await hooks.onLoadConfiguration.promise();\n\n if (webpackConfiguration === false) {\n terminal.writeLine('Webpack disabled by external plugin');\n webpackConfiguration = undefined;\n } else if (\n webpackConfiguration === undefined ||\n (Array.isArray(webpackConfiguration) && webpackConfiguration.length === 0)\n ) {\n terminal.writeLine('No Webpack configuration found');\n webpackConfiguration = undefined;\n } else {\n if (hooks.onConfigure.isUsed()) {\n // Allow for plugins to customise the configuration\n await hooks.onConfigure.promise(webpackConfiguration);\n }\n if (hooks.onAfterConfigure.isUsed()) {\n // Provide the finalized configuration\n await hooks.onAfterConfigure.promise(webpackConfiguration);\n }\n }\n return webpackConfiguration;\n}\n\n/**\n * @internal\n */\nexport async function tryLoadWebpackConfigurationFileAsync(\n options: ILoadWebpackConfigurationOptions,\n pluginOptions: IWebpackPluginOptions\n): Promise<IWebpackConfiguration | undefined> {\n // TODO: Eventually replace this custom logic with a call to this utility in in webpack-cli:\n // https://github.com/webpack/webpack-cli/blob/next/packages/webpack-cli/lib/groups/ConfigGroup.js\n\n const { taskSession, heftConfiguration, loadWebpackAsyncFn, serveMode } = options;\n const {\n logger,\n parameters: { production }\n } = taskSession;\n const { terminal } = logger;\n const { configurationPath, devConfigurationPath } = pluginOptions;\n let webpackConfigJs: IWebpackConfigJs | undefined;\n\n try {\n const buildFolderPath: string = heftConfiguration.buildFolderPath;\n if (serveMode) {\n const devConfigPath: string = path.resolve(\n buildFolderPath,\n devConfigurationPath || DEFAULT_WEBPACK_DEV_CONFIG_PATH\n );\n terminal.writeVerboseLine(`Attempting to load webpack configuration from \"${devConfigPath}\".`);\n webpackConfigJs = await _tryLoadWebpackConfigurationFileInnerAsync(devConfigPath);\n }\n\n if (!webpackConfigJs) {\n const configPath: string = path.resolve(\n buildFolderPath,\n configurationPath || DEFAULT_WEBPACK_CONFIG_PATH\n );\n terminal.writeVerboseLine(`Attempting to load webpack configuration from \"${configPath}\".`);\n webpackConfigJs = await _tryLoadWebpackConfigurationFileInnerAsync(configPath);\n }\n } catch (error) {\n logger.emitError(error as Error);\n }\n\n if (webpackConfigJs) {\n const webpackConfig: IWebpackConfigJsExport =\n (webpackConfigJs as { default: IWebpackConfigJsExport }).default || webpackConfigJs;\n\n if (typeof webpackConfig === 'function') {\n // Defer loading of webpack until we know for sure that we will need it\n return webpackConfig({\n prod: production,\n production,\n taskSession,\n heftConfiguration,\n webpack: await loadWebpackAsyncFn()\n });\n } else {\n return webpackConfig;\n }\n } else {\n return undefined;\n }\n}\n\n/**\n * @internal\n */\nexport async function _tryLoadWebpackConfigurationFileInnerAsync(\n configurationPath: string\n): Promise<IWebpackConfigJs | undefined> {\n const configExists: boolean = await FileSystem.existsAsync(configurationPath);\n if (configExists) {\n try {\n return await import(configurationPath);\n } catch (e) {\n const error: NodeJS.ErrnoException = e as NodeJS.ErrnoException;\n if (error.code === 'ERR_MODULE_NOT_FOUND') {\n // No configuration found, return undefined.\n return undefined;\n }\n throw new Error(`Error loading webpack configuration at \"${configurationPath}\": ${e}`);\n }\n } else {\n return undefined;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=WebpackConfigurationLoader.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebpackConfigurationLoader.test.d.ts","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebpackConfigurationLoader.test.js","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.test.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;AAG3D,mGAAgG;AAChG,oEAAsG;AAEtG,yFAA2E;AAC3E,qDAAwD;AACxD,qCAA+E;AAS/E,QAAQ,CAAC,0BAA0B,CAAC,gCAAgC,CAAC,IAAI,EAAE,GAAG,EAAE;IAC9E,SAAS,aAAa,CAAC,UAAmB,EAAE,SAAkB;QAC5D,MAAM,gBAAgB,GAAiC,IAAI,gDAA4B,CAAC,KAAK,CAAC,C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,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACrD,MAAM,CAAC,gBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,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 { HeftConfiguration, IHeftParameters, IHeftTaskSession, IScopedLogger } from '@rushstack/heft';\nimport { MockScopedLogger } from '@rushstack/heft/lib/pluginFramework/logging/MockScopedLogger';\nimport { type ITerminal, StringBufferTerminalProvider, Terminal } from '@rushstack/node-core-library';\n\nimport * as WebpackConfigurationLoader from './WebpackConfigurationLoader';\nimport { _createAccessorHooks } from './Webpack4Plugin';\nimport { type IWebpackConfiguration, STAGE_LOAD_LOCAL_CONFIG } from './shared';\n\ninterface IMockLoadWebpackConfigurationOptions\n extends WebpackConfigurationLoader.ILoadWebpackConfigurationOptions {\n loadWebpackAsyncFn: jest.Mock;\n _terminalProvider: StringBufferTerminalProvider;\n _tryLoadConfigFileAsync: jest.Mock;\n}\n\ndescribe(WebpackConfigurationLoader.tryLoadWebpackConfigurationAsync.name, () => {\n function createOptions(production: boolean, serveMode: boolean): IMockLoadWebpackConfigurationOptions {\n const terminalProvider: StringBufferTerminalProvider = new StringBufferTerminalProvider(false);\n const terminal: ITerminal = new Terminal(terminalProvider);\n const logger: IScopedLogger = new MockScopedLogger(terminal);\n const buildFolderPath: string = __dirname;\n\n const parameters: Partial<IHeftParameters> = {\n production\n };\n\n const taskSession: IHeftTaskSession = {\n logger,\n parameters: parameters as unknown as IHeftParameters,\n // Other values unused during these tests\n hooks: undefined!,\n parsedCommandLine: undefined!,\n requestAccessToPluginByName: undefined!,\n taskName: 'webpack',\n tempFolderPath: `${__dirname}/temp`\n };\n\n const heftConfiguration: Partial<HeftConfiguration> = {\n buildFolderPath\n };\n\n return {\n taskSession,\n heftConfiguration: heftConfiguration as unknown as HeftConfiguration,\n hooks: _createAccessorHooks(),\n loadWebpackAsyncFn: jest.fn(),\n serveMode,\n\n _terminalProvider: terminalProvider,\n _tryLoadConfigFileAsync: jest.fn()\n };\n }\n\n it(`onLoadConfiguration can return false`, async () => {\n const options: IMockLoadWebpackConfigurationOptions = createOptions(false, false);\n\n const onLoadConfiguration: jest.Mock = jest.fn();\n const onConfigure: jest.Mock = jest.fn();\n const onAfterConfigure: jest.Mock = jest.fn();\n\n options.hooks.onLoadConfiguration.tap('test', onLoadConfiguration);\n options.hooks.onConfigure.tap('test', onConfigure);\n options.hooks.onAfterConfigure.tap('test', onAfterConfigure);\n\n onLoadConfiguration.mockReturnValue(false);\n\n const config: IWebpackConfiguration | undefined =\n await WebpackConfigurationLoader.tryLoadWebpackConfigurationAsync(options, {});\n expect(config).toBeUndefined();\n expect(onLoadConfiguration).toHaveBeenCalledTimes(1);\n expect(options._tryLoadConfigFileAsync).toHaveBeenCalledTimes(0);\n expect(onConfigure).toHaveBeenCalledTimes(0);\n expect(onAfterConfigure).toHaveBeenCalledTimes(0);\n });\n\n it(`calls tryLoadWebpackConfigurationFileAsync`, async () => {\n const options: IMockLoadWebpackConfigurationOptions = createOptions(false, false);\n\n const onConfigure: jest.Mock = jest.fn();\n const onAfterConfigure: jest.Mock = jest.fn();\n\n options.hooks.onConfigure.tap('test', onConfigure);\n options.hooks.onAfterConfigure.tap('test', onAfterConfigure);\n\n options._tryLoadConfigFileAsync.mockReturnValue(Promise.resolve(undefined));\n\n const config: IWebpackConfiguration | undefined =\n await WebpackConfigurationLoader.tryLoadWebpackConfigurationAsync(options, {});\n expect(config).toBeUndefined();\n expect(options._tryLoadConfigFileAsync).toHaveBeenCalledTimes(1);\n expect(onConfigure).toHaveBeenCalledTimes(0);\n expect(onAfterConfigure).toHaveBeenCalledTimes(0);\n });\n\n it(`can fall back`, async () => {\n const options: IMockLoadWebpackConfigurationOptions = createOptions(false, false);\n\n const onLoadConfiguration: jest.Mock = jest.fn();\n const onConfigure: jest.Mock = jest.fn();\n const onAfterConfigure: jest.Mock = jest.fn();\n\n options.hooks.onLoadConfiguration.tap(\n { name: 'test', stage: STAGE_LOAD_LOCAL_CONFIG + 1 },\n onLoadConfiguration\n );\n options.hooks.onConfigure.tap('test', onConfigure);\n options.hooks.onAfterConfigure.tap('test', onAfterConfigure);\n\n options._tryLoadConfigFileAsync.mockReturnValue(Promise.resolve(undefined));\n\n const mockConfig: IWebpackConfiguration = {};\n onLoadConfiguration.mockReturnValue(mockConfig);\n\n const config: IWebpackConfiguration | undefined =\n await WebpackConfigurationLoader.tryLoadWebpackConfigurationAsync(options, {});\n expect(config).toBe(mockConfig);\n\n expect(options._tryLoadConfigFileAsync).toHaveBeenCalledTimes(1);\n expect(onLoadConfiguration).toHaveBeenCalledTimes(1);\n expect(onConfigure).toHaveBeenCalledTimes(1);\n expect(onAfterConfigure).toHaveBeenCalledTimes(1);\n\n expect(onConfigure).toHaveBeenCalledWith(mockConfig);\n expect(onAfterConfigure).toHaveBeenCalledWith(mockConfig);\n });\n\n it(`respects hook order`, async () => {\n const options: IMockLoadWebpackConfigurationOptions = createOptions(false, false);\n\n const onConfigure: jest.Mock = jest.fn();\n const onAfterConfigure: jest.Mock = jest.fn();\n\n options.hooks.onConfigure.tap('test', onConfigure);\n options.hooks.onAfterConfigure.tap('test', onAfterConfigure);\n\n const mockConfig: IWebpackConfiguration = {};\n\n options._tryLoadConfigFileAsync.mockReturnValue(Promise.resolve(mockConfig));\n\n const config: IWebpackConfiguration | undefined =\n await WebpackConfigurationLoader.tryLoadWebpackConfigurationAsync(options, {});\n expect(config).toBe(mockConfig);\n expect(options._tryLoadConfigFileAsync).toHaveBeenCalledTimes(1);\n expect(onConfigure).toHaveBeenCalledTimes(1);\n expect(onConfigure).toHaveBeenCalledWith(mockConfig);\n expect(onAfterConfigure).toHaveBeenCalledTimes(1);\n expect(onAfterConfigure).toHaveBeenCalledWith(mockConfig);\n });\n});\n"]}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { PLUGIN_NAME as PluginName } from './Webpack4Plugin';
1
+ export { PLUGIN_NAME as PluginName, STAGE_LOAD_LOCAL_CONFIG } from './shared';
2
2
  export type { IWebpackConfigurationWithDevServer, IWebpackConfiguration, IWebpackConfigurationFnEnvironment, IWebpackPluginAccessor, IWebpackPluginAccessorHooks, IWebpackPluginAccessorParameters } from './shared';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE7D,YAAY,EACV,kCAAkC,EAClC,qBAAqB,EACrB,kCAAkC,EAClC,sBAAsB,EACtB,2BAA2B,EAC3B,gCAAgC,EACjC,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,IAAI,UAAU,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAE9E,YAAY,EACV,kCAAkC,EAClC,qBAAqB,EACrB,kCAAkC,EAClC,sBAAsB,EACtB,2BAA2B,EAC3B,gCAAgC,EACjC,MAAM,UAAU,CAAC"}
package/lib/index.js CHANGED
@@ -2,7 +2,8 @@
2
2
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.PluginName = void 0;
6
- var Webpack4Plugin_1 = require("./Webpack4Plugin");
7
- Object.defineProperty(exports, "PluginName", { enumerable: true, get: function () { return Webpack4Plugin_1.PLUGIN_NAME; } });
5
+ exports.STAGE_LOAD_LOCAL_CONFIG = exports.PluginName = void 0;
6
+ var shared_1 = require("./shared");
7
+ Object.defineProperty(exports, "PluginName", { enumerable: true, get: function () { return shared_1.PLUGIN_NAME; } });
8
+ Object.defineProperty(exports, "STAGE_LOAD_LOCAL_CONFIG", { enumerable: true, get: function () { return shared_1.STAGE_LOAD_LOCAL_CONFIG; } });
8
9
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,mDAA6D;AAApD,4GAAA,WAAW,OAAc","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport { PLUGIN_NAME as PluginName } from './Webpack4Plugin';\n\nexport type {\n IWebpackConfigurationWithDevServer,\n IWebpackConfiguration,\n IWebpackConfigurationFnEnvironment,\n IWebpackPluginAccessor,\n IWebpackPluginAccessorHooks,\n IWebpackPluginAccessorParameters\n} from './shared';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,mCAA8E;AAArE,oGAAA,WAAW,OAAc;AAAE,iHAAA,uBAAuB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport { PLUGIN_NAME as PluginName, STAGE_LOAD_LOCAL_CONFIG } from './shared';\n\nexport type {\n IWebpackConfigurationWithDevServer,\n IWebpackConfiguration,\n IWebpackConfigurationFnEnvironment,\n IWebpackPluginAccessor,\n IWebpackPluginAccessorHooks,\n IWebpackPluginAccessorParameters\n} from './shared';\n"]}
package/lib/shared.d.ts CHANGED
@@ -57,9 +57,9 @@ export type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpac
57
57
  export interface IWebpackPluginAccessorHooks {
58
58
  /**
59
59
  * A hook that allows for loading custom configurations used by the Webpack
60
- * plugin. If a webpack configuration is provided, this will be populated automatically
61
- * with the exports of the config file. If a webpack configuration is not provided,
62
- * one will be loaded by the Webpack plugin.
60
+ * plugin. If a tap returns a value other than `undefined` before stage {@link STAGE_LOAD_LOCAL_CONFIG},
61
+ * it will suppress loading from the webpack config file. To provide a fallback behavior in the
62
+ * absence of a local config file, tap this hook with a `stage` value greater than {@link STAGE_LOAD_LOCAL_CONFIG}.
63
63
  *
64
64
  * @remarks
65
65
  * Tapable event handlers can return `false` instead of `undefined` to suppress
@@ -104,4 +104,14 @@ export interface IWebpackPluginAccessor {
104
104
  */
105
105
  readonly parameters: IWebpackPluginAccessorParameters;
106
106
  }
107
+ /**
108
+ * The stage in the `onLoadConfiguration` hook at which the config will be loaded from the local
109
+ * webpack config file.
110
+ * @public
111
+ */
112
+ export declare const STAGE_LOAD_LOCAL_CONFIG: 1000;
113
+ /**
114
+ * @public
115
+ */
116
+ export declare const PLUGIN_NAME: 'webpack4-plugin';
107
117
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,QAAQ,MAAM,SAAS,CAAC;AAEzC,OAAO,QAAQ,SAAS,CAAC;IACvB,KAAY,UAAU,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC;IACzD,KAAY,YAAY,GAAG,OAAO,CAAC;IACnC,KAAY,gBAAgB,GAAG,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC;IAGhE,UAAiB,QAAQ;QACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;CACF;AACD,OAAO,KAAK,EAAE,aAAa,IAAI,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,KA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OASG;IACH,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,GAAG,KAAK,CAAC,CAAC;IACtG;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC3E;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClF;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CACzG;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,2BAA2B,CAAC;IAC5C;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,gCAAgC,CAAC;CACvD;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,IAAW,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,iBAAqC,CAAC"}
package/lib/shared.js CHANGED
@@ -2,4 +2,15 @@
2
2
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.PLUGIN_NAME = exports.STAGE_LOAD_LOCAL_CONFIG = void 0;
6
+ /**
7
+ * The stage in the `onLoadConfiguration` hook at which the config will be loaded from the local
8
+ * webpack config file.
9
+ * @public
10
+ */
11
+ exports.STAGE_LOAD_LOCAL_CONFIG = 1000;
12
+ /**
13
+ * @public
14
+ */
15
+ exports.PLUGIN_NAME = 'webpack4-plugin';
5
16
  //# sourceMappingURL=shared.js.map
package/lib/shared.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 * as TWebpack from 'webpack';\n// Compensate for webpack-dev-server referencing constructs from webpack 5\ndeclare module 'webpack' {\n export type MultiStats = TWebpack.compilation.MultiStats;\n export type StatsOptions = unknown;\n export type StatsCompilation = TWebpack.compilation.Compilation;\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n export interface Compiler {\n watching?: unknown;\n }\n}\nimport type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';\nimport type { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook } from 'tapable';\nimport type { IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';\n\n/**\n * The environment passed into the Webpack configuration function. Loosely based\n * on the default Webpack environment options, specified here:\n * https://webpack.js.org/api/cli/#environment-options\n *\n * @public\n */\nexport interface IWebpackConfigurationFnEnvironment {\n /**\n * Whether or not the run is in production mode. Synonym of\n * IWebpackConfigurationFnEnvironment.production.\n */\n prod: boolean;\n /**\n * Whether or not the run is in production mode. Synonym of\n * IWebpackConfigurationFnEnvironment.prod.\n */\n production: boolean;\n\n // Non-standard environment options\n /**\n * The task session provided to the plugin.\n */\n taskSession: IHeftTaskSession;\n /**\n * The Heft configuration provided to the plugin.\n */\n heftConfiguration: HeftConfiguration;\n /**\n * The resolved Webpack package.\n */\n webpack: typeof TWebpack;\n}\n\n/**\n * @public\n */\nexport interface IWebpackConfigurationWithDevServer extends TWebpack.Configuration {\n devServer?: WebpackDevServerConfiguration;\n}\n\n/**\n * @public\n */\nexport type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[];\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessorHooks {\n /**\n * A hook that allows for loading custom configurations used by the Webpack\n * plugin. If a webpack configuration is provided, this will be populated automatically\n * with the exports of the config file. If a webpack configuration is not provided,\n * one will be loaded by the Webpack plugin.\n *\n * @remarks\n * Tapable event handlers can return `false` instead of `undefined` to suppress\n * other handlers from creating a configuration object, and prevent webpack from running.\n */\n readonly onLoadConfiguration: AsyncSeriesBailHook<never, never, never, IWebpackConfiguration | false>;\n /**\n * A hook that allows for modification of the loaded configuration used by the Webpack\n * plugin. If no configuration was loaded, this hook will not be called.\n */\n readonly onConfigure: AsyncSeriesHook<IWebpackConfiguration, never, never>;\n /**\n * A hook that provides the finalized configuration that will be used by Webpack.\n * If no configuration was loaded, this hook will not be called.\n */\n readonly onAfterConfigure: AsyncParallelHook<IWebpackConfiguration, never, never>;\n /**\n * A hook that provides the stats output from Webpack. If no configuration is loaded,\n * this hook will not be called.\n */\n readonly onEmitStats: AsyncParallelHook<TWebpack.Stats | TWebpack.compilation.MultiStats, never, never>;\n}\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessorParameters {\n /**\n * Whether or not serve mode was enabled by passing the `--serve` flag.\n */\n readonly isServeMode: boolean;\n}\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessor {\n /**\n * Hooks that are called at various points in the Webpack plugin lifecycle.\n */\n readonly hooks: IWebpackPluginAccessorHooks;\n /**\n * Parameters that are provided by the Webpack plugin.\n */\n readonly parameters: IWebpackPluginAccessorParameters;\n}\n"]}
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAwH3D;;;;GAIG;AACU,QAAA,uBAAuB,GAAS,IAAI,CAAC;AAElD;;GAEG;AACU,QAAA,WAAW,GAAsB,iBAAiB,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 * as TWebpack from 'webpack';\n// Compensate for webpack-dev-server referencing constructs from webpack 5\ndeclare module 'webpack' {\n export type MultiStats = TWebpack.compilation.MultiStats;\n export type StatsOptions = unknown;\n export type StatsCompilation = TWebpack.compilation.Compilation;\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n export interface Compiler {\n watching?: unknown;\n }\n}\nimport type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';\nimport type { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook } from 'tapable';\nimport type { IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';\n\n/**\n * The environment passed into the Webpack configuration function. Loosely based\n * on the default Webpack environment options, specified here:\n * https://webpack.js.org/api/cli/#environment-options\n *\n * @public\n */\nexport interface IWebpackConfigurationFnEnvironment {\n /**\n * Whether or not the run is in production mode. Synonym of\n * IWebpackConfigurationFnEnvironment.production.\n */\n prod: boolean;\n /**\n * Whether or not the run is in production mode. Synonym of\n * IWebpackConfigurationFnEnvironment.prod.\n */\n production: boolean;\n\n // Non-standard environment options\n /**\n * The task session provided to the plugin.\n */\n taskSession: IHeftTaskSession;\n /**\n * The Heft configuration provided to the plugin.\n */\n heftConfiguration: HeftConfiguration;\n /**\n * The resolved Webpack package.\n */\n webpack: typeof TWebpack;\n}\n\n/**\n * @public\n */\nexport interface IWebpackConfigurationWithDevServer extends TWebpack.Configuration {\n devServer?: WebpackDevServerConfiguration;\n}\n\n/**\n * @public\n */\nexport type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[];\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessorHooks {\n /**\n * A hook that allows for loading custom configurations used by the Webpack\n * plugin. If a tap returns a value other than `undefined` before stage {@link STAGE_LOAD_LOCAL_CONFIG},\n * it will suppress loading from the webpack config file. To provide a fallback behavior in the\n * absence of a local config file, tap this hook with a `stage` value greater than {@link STAGE_LOAD_LOCAL_CONFIG}.\n *\n * @remarks\n * Tapable event handlers can return `false` instead of `undefined` to suppress\n * other handlers from creating a configuration object, and prevent webpack from running.\n */\n readonly onLoadConfiguration: AsyncSeriesBailHook<never, never, never, IWebpackConfiguration | false>;\n /**\n * A hook that allows for modification of the loaded configuration used by the Webpack\n * plugin. If no configuration was loaded, this hook will not be called.\n */\n readonly onConfigure: AsyncSeriesHook<IWebpackConfiguration, never, never>;\n /**\n * A hook that provides the finalized configuration that will be used by Webpack.\n * If no configuration was loaded, this hook will not be called.\n */\n readonly onAfterConfigure: AsyncParallelHook<IWebpackConfiguration, never, never>;\n /**\n * A hook that provides the stats output from Webpack. If no configuration is loaded,\n * this hook will not be called.\n */\n readonly onEmitStats: AsyncParallelHook<TWebpack.Stats | TWebpack.compilation.MultiStats, never, never>;\n}\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessorParameters {\n /**\n * Whether or not serve mode was enabled by passing the `--serve` flag.\n */\n readonly isServeMode: boolean;\n}\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessor {\n /**\n * Hooks that are called at various points in the Webpack plugin lifecycle.\n */\n readonly hooks: IWebpackPluginAccessorHooks;\n /**\n * Parameters that are provided by the Webpack plugin.\n */\n readonly parameters: IWebpackPluginAccessorParameters;\n}\n\n/**\n * The stage in the `onLoadConfiguration` hook at which the config will be loaded from the local\n * webpack config file.\n * @public\n */\nexport const STAGE_LOAD_LOCAL_CONFIG: 1000 = 1000;\n\n/**\n * @public\n */\nexport const PLUGIN_NAME: 'webpack4-plugin' = 'webpack4-plugin';\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.35.2"
8
+ "packageVersion": "7.35.3"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/heft-webpack4-plugin",
3
- "version": "0.6.9",
3
+ "version": "0.7.0",
4
4
  "description": "Heft plugin for Webpack 4",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  }
18
18
  },
19
19
  "peerDependencies": {
20
- "@rushstack/heft": "^0.54.0",
20
+ "@rushstack/heft": "^0.55.1",
21
21
  "@types/webpack": "^4",
22
22
  "webpack": "~4.44.2"
23
23
  },
@@ -26,7 +26,7 @@
26
26
  "tapable": "1.1.3",
27
27
  "watchpack": "2.4.0",
28
28
  "webpack-dev-server": "~4.9.3",
29
- "@rushstack/debug-certificate-manager": "1.2.39",
29
+ "@rushstack/debug-certificate-manager": "1.2.41",
30
30
  "@rushstack/node-core-library": "3.59.3"
31
31
  },
32
32
  "devDependencies": {
@@ -35,8 +35,8 @@
35
35
  "@types/webpack": "4.41.32",
36
36
  "webpack": "~4.44.2",
37
37
  "@rushstack/eslint-config": "3.3.1",
38
- "@rushstack/heft-node-rig": "2.2.6",
39
- "@rushstack/heft": "0.54.0"
38
+ "@rushstack/heft-node-rig": "2.2.8",
39
+ "@rushstack/heft": "0.55.1"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "heft build --clean",