@rushstack/heft-webpack5-plugin 0.6.12 → 0.7.0-rc.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"WebpackConfigurationLoader.js","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,oEAA2E;AA2B3E,MAAa,0BAA0B;IAC9B,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAC3C,MAAoB,EACpB,WAAmB,EACnB,eAAsC;QAEtC,4FAA4F;QAC5F,kGAAkG;QAElG,MAAM,kBAAkB,GAAwC,MAAM,sBAAsB,CAAC,WAAW,CAAC,CAAC;QAC1G,MAAM,wBAAwB,GAAuB,kBAAkB,CAAC,GAAG,CAAC;QAC5E,MAAM,qBAAqB,GAAuB,kBAAkB,CAAC,IAAI,CAAC;QAE1E,IAAI,eAA6C,CAAC;QAElD,IAAI;YACF,IAAI,eAAe,CAAC,SAAS,IAAI,wBAAwB,EAAE;gBACzD,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAC9B,kDAAkD,wBAAwB,IAAI,CAC/E,CAAC;gBACF,eAAe,GAAG,0BAA0B,CAAC,4BAA4B,CACvE,WAAW,EACX,wBAAwB,CACzB,CAAC;aACH;YAED,IAAI,CAAC,eAAe,IAAI,qBAAqB,EAAE;gBAC7C,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAC9B,kDAAkD,qBAAqB,IAAI,CAC5E,CAAC;gBACF,eAAe,GAAG,0BAA0B,CAAC,4BAA4B,CACvE,WAAW,EACX,qBAAqB,CACtB,CAAC;aACH;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,SAAS,CAAC,KAAc,CAAC,CAAC;SAClC;QAED,IAAI,eAAe,EAAE;YACnB,MAAM,aAAa,GAChB,eAAu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AC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;iBAC5B;aACF;SACF;QAED,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;SAC/E;aAAM,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;QAED,OAAO;YACL,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YACX,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;SACd,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,EAAE,CAAC,CAAC;KAC9D;AACH,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 * as path from 'path';\nimport { type FolderItem, FileSystem } from '@rushstack/node-core-library';\nimport type * as webpack from 'webpack';\nimport type { IBuildStageProperties, ScopedLogger } from '@rushstack/heft';\n\nimport { IWebpackConfiguration } from './shared';\n\n/**\n * See https://webpack.js.org/api/cli/#environment-options\n */\ninterface IWebpackConfigFunctionEnv {\n prod: boolean;\n production: boolean;\n}\ntype IWebpackConfigJsExport =\n | webpack.Configuration\n | webpack.Configuration[]\n | Promise<webpack.Configuration>\n | Promise<webpack.Configuration[]>\n | ((env: IWebpackConfigFunctionEnv) => webpack.Configuration | webpack.Configuration[])\n | ((env: IWebpackConfigFunctionEnv) => Promise<webpack.Configuration | webpack.Configuration[]>);\ntype IWebpackConfigJs = IWebpackConfigJsExport | { default: IWebpackConfigJsExport };\n\ninterface IWebpackConfigFileNames {\n dev: string | undefined;\n prod: string | undefined;\n}\n\nexport class WebpackConfigurationLoader {\n public static async tryLoadWebpackConfigAsync(\n logger: ScopedLogger,\n buildFolder: string,\n buildProperties: IBuildStageProperties\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 webpackConfigFiles: IWebpackConfigFileNames | undefined = await findWebpackConfigAsync(buildFolder);\n const webpackDevConfigFilename: string | undefined = webpackConfigFiles.dev;\n const webpackConfigFilename: string | undefined = webpackConfigFiles.prod;\n\n let webpackConfigJs: IWebpackConfigJs | undefined;\n\n try {\n if (buildProperties.serveMode && webpackDevConfigFilename) {\n logger.terminal.writeVerboseLine(\n `Attempting to load webpack configuration from \"${webpackDevConfigFilename}\".`\n );\n webpackConfigJs = WebpackConfigurationLoader._tryLoadWebpackConfiguration(\n buildFolder,\n webpackDevConfigFilename\n );\n }\n\n if (!webpackConfigJs && webpackConfigFilename) {\n logger.terminal.writeVerboseLine(\n `Attempting to load webpack configuration from \"${webpackConfigFilename}\".`\n );\n webpackConfigJs = WebpackConfigurationLoader._tryLoadWebpackConfiguration(\n buildFolder,\n webpackConfigFilename\n );\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 return webpackConfig({ prod: buildProperties.production, production: buildProperties.production });\n } else {\n return webpackConfig;\n }\n } else {\n return undefined;\n }\n }\n\n private static _tryLoadWebpackConfiguration(\n buildFolder: string,\n configurationFilename: string\n ): IWebpackConfigJs | undefined {\n const fullWebpackConfigPath: string = path.join(buildFolder, configurationFilename);\n if (FileSystem.exists(fullWebpackConfigPath)) {\n try {\n return require(fullWebpackConfigPath);\n } catch (e) {\n throw new Error(`Error loading webpack configuration at \"${fullWebpackConfigPath}\": ${e}`);\n }\n } else {\n return undefined;\n }\n }\n}\n\nasync function findWebpackConfigAsync(buildFolder: string): Promise<IWebpackConfigFileNames> {\n try {\n const folderItems: FolderItem[] = await FileSystem.readFolderItemsAsync(buildFolder);\n const dev: string[] = [];\n const prod: string[] = [];\n\n for (const folderItem of folderItems) {\n if (folderItem.isFile()) {\n if (folderItem.name.match(/^webpack.dev.config\\.(cjs|js|mjs)$/)) {\n dev.push(folderItem.name);\n } else if (folderItem.name.match(/^webpack.config\\.(cjs|js|mjs)$/)) {\n prod.push(folderItem.name);\n }\n }\n }\n\n if (dev.length > 1) {\n throw new Error(`Error: Found more than one dev webpack configuration file.`);\n } else if (prod.length > 1) {\n throw new Error(`Error: Found more than one non-dev webpack configuration file.`);\n }\n\n return {\n dev: dev[0],\n prod: prod[0]\n };\n } catch (e) {\n throw new Error(`Error finding webpack configuration: ${e}`);\n }\n}\n"]}
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,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,gCAAgC,CAC3C,OAAyC;QAEzC,4FAA4F;QAC5F,kGAAkG;QAElG,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,GACnG,OAAO,CAAC;QACV,IAAI,eAA6C,CAAC;QAElD,IAAI;YACF,MAAM,eAAe,GAAW,iBAAiB,CAAC,eAAe,CAAC;YAClE,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,MAAM,aAAa,GAAW,IAAI,CA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xC;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 './Webpack5Plugin';\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"]}
package/lib/index.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- import type { IHeftPlugin } from '@rushstack/heft';
2
- export { IWebpackConfigurationWithDevServer, IWebpackConfiguration, IWebpackBuildStageProperties, IWebpackBundleSubstageProperties } from './shared';
3
- /**
4
- * @public
5
- */
6
- declare const _default: IHeftPlugin<void>;
7
- export default _default;
1
+ export { PLUGIN_NAME as PluginName } from './Webpack5Plugin';
2
+ export type { IWebpackConfigurationWithDevServer, IWebpackConfiguration, IWebpackConfigurationFnEnvironment, IWebpackPluginAccessor, IWebpackPluginAccessorHooks, IWebpackPluginAccessorParameters } from './shared';
8
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,OAAO,EACL,kCAAkC,EAClC,qBAAqB,EACrB,4BAA4B,EAC5B,gCAAgC,EACjC,MAAM,UAAU,CAAC;AAElB;;GAEG;;AACH,wBAAkD"}
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"}
package/lib/index.js CHANGED
@@ -2,9 +2,7 @@
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
- const WebpackPlugin_1 = require("./WebpackPlugin");
6
- /**
7
- * @public
8
- */
9
- exports.default = new WebpackPlugin_1.WebpackPlugin();
5
+ exports.PluginName = void 0;
6
+ var Webpack5Plugin_1 = require("./Webpack5Plugin");
7
+ Object.defineProperty(exports, "PluginName", { enumerable: true, get: function () { return Webpack5Plugin_1.PLUGIN_NAME; } });
10
8
  //# 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;;AAI3D,mDAAgD;AAShD;;GAEG;AACH,kBAAe,IAAI,6BAAa,EAAiB,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 { IHeftPlugin } from '@rushstack/heft';\n\nimport { WebpackPlugin } from './WebpackPlugin';\n\nexport {\n IWebpackConfigurationWithDevServer,\n IWebpackConfiguration,\n IWebpackBuildStageProperties,\n IWebpackBundleSubstageProperties\n} from './shared';\n\n/**\n * @public\n */\nexport default new WebpackPlugin() as IHeftPlugin;\n"]}
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 './Webpack5Plugin';\n\nexport type {\n IWebpackConfigurationWithDevServer,\n IWebpackConfiguration,\n IWebpackConfigurationFnEnvironment,\n IWebpackPluginAccessor,\n IWebpackPluginAccessorHooks,\n IWebpackPluginAccessorParameters\n} from './shared';\n"]}
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "title": "Webpack 5 Plugin Configuration",
4
+ "description": "Defines options for Webpack 5 plugin execution.",
5
+ "type": "object",
6
+
7
+ "additionalProperties": false,
8
+
9
+ "properties": {
10
+ "$schema": {
11
+ "description": "Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.",
12
+ "type": "string"
13
+ },
14
+
15
+ "devConfigurationPath": {
16
+ "description": "Specifies a relative path to the Webpack dev configuration, which is used in \"serve\" mode. The default value is \"./webpack.dev.config.js\".",
17
+ "type": "string"
18
+ },
19
+
20
+ "configurationPath": {
21
+ "description": "Specifies a relative path to the Webpack configuration. The default value is \"./webpack.config.js\".",
22
+ "type": "string"
23
+ }
24
+ }
25
+ }
package/lib/shared.d.ts CHANGED
@@ -1,36 +1,99 @@
1
+ import type * as TWebpack from 'webpack';
1
2
  import type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
2
- import type * as webpack from 'webpack';
3
- import type { IBuildStageProperties, IBundleSubstageProperties } from '@rushstack/heft';
3
+ import type { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook } from 'tapable';
4
+ import type { IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';
4
5
  /**
6
+ * The environment passed into the Webpack configuration function. Loosely based
7
+ * on the default Webpack environment options, specified here:
8
+ * https://webpack.js.org/api/cli/#environment-options
9
+ *
5
10
  * @public
6
11
  */
7
- export interface IWebpackConfigurationWithDevServer extends webpack.Configuration {
12
+ export interface IWebpackConfigurationFnEnvironment {
13
+ /**
14
+ * Whether or not the run is in production mode. Synonym of
15
+ * IWebpackConfigurationFnEnvironment.production.
16
+ */
17
+ prod: boolean;
18
+ /**
19
+ * Whether or not the run is in production mode. Synonym of
20
+ * IWebpackConfigurationFnEnvironment.prod.
21
+ */
22
+ production: boolean;
23
+ /**
24
+ * The task session provided to the plugin.
25
+ */
26
+ taskSession: IHeftTaskSession;
27
+ /**
28
+ * The Heft configuration provided to the plugin.
29
+ */
30
+ heftConfiguration: HeftConfiguration;
31
+ /**
32
+ * The resolved Webpack package.
33
+ */
34
+ webpack: typeof TWebpack;
35
+ }
36
+ /**
37
+ * @public
38
+ */
39
+ export interface IWebpackConfigurationWithDevServer extends TWebpack.Configuration {
8
40
  devServer?: WebpackDevServerConfiguration;
9
41
  }
10
42
  /**
11
43
  * @public
12
44
  */
13
- export type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[] | undefined;
45
+ export type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[];
14
46
  /**
15
47
  * @public
16
48
  */
17
- export interface IWebpackBundleSubstageProperties extends IBundleSubstageProperties {
49
+ export interface IWebpackPluginAccessorHooks {
18
50
  /**
19
- * The configuration used by the Webpack plugin. This must be populated
20
- * for Webpack to run. If webpackConfigFilePath is specified,
21
- * this will be populated automatically with the exports of the
22
- * config file referenced in that property.
51
+ * A hook that allows for loading custom configurations used by the Webpack
52
+ * plugin. If a webpack configuration is provided, this will be populated automatically
53
+ * with the exports of the config file. If a webpack configuration is not provided,
54
+ * one will be loaded by the Webpack plugin.
23
55
  *
24
56
  * @remarks
25
- * Tapable event handlers can return `null` instead of `undefined` to suppress
26
- * other handlers from creating a configuration object.
57
+ * Tapable event handlers can return `false` instead of `undefined` to suppress
58
+ * other handlers from creating a configuration object, and prevent webpack from running.
59
+ */
60
+ readonly onLoadConfiguration: AsyncSeriesBailHook<never, never, never, IWebpackConfiguration | false>;
61
+ /**
62
+ * A hook that allows for modification of the loaded configuration used by the Webpack
63
+ * plugin. If no configuration was loaded, this hook will not be called.
64
+ */
65
+ readonly onConfigure: AsyncSeriesHook<IWebpackConfiguration, never, never>;
66
+ /**
67
+ * A hook that provides the finalized configuration that will be used by Webpack.
68
+ * If no configuration was loaded, this hook will not be called.
69
+ */
70
+ readonly onAfterConfigure: AsyncParallelHook<IWebpackConfiguration, never, never>;
71
+ /**
72
+ * A hook that provides the stats output from Webpack. If no configuration is loaded,
73
+ * this hook will not be called.
27
74
  */
28
- webpackConfiguration?: webpack.Configuration | webpack.Configuration[] | null;
75
+ readonly onEmitStats: AsyncParallelHook<TWebpack.Stats | TWebpack.MultiStats, never, never>;
29
76
  }
30
77
  /**
31
78
  * @public
32
79
  */
33
- export interface IWebpackBuildStageProperties extends IBuildStageProperties {
34
- webpackStats?: webpack.Stats | webpack.MultiStats;
80
+ export interface IWebpackPluginAccessorParameters {
81
+ /**
82
+ * Whether or not serve mode was enabled by passing the `--serve` flag.
83
+ */
84
+ readonly isServeMode: boolean;
85
+ }
86
+ /**
87
+ * @public
88
+ */
89
+ export interface IWebpackPluginAccessor {
90
+ /**
91
+ * Hooks that are called at various points in the Webpack plugin lifecycle.
92
+ */
93
+ readonly hooks: IWebpackPluginAccessorHooks;
94
+ /**
95
+ * Parameters that are provided by the Webpack plugin.
96
+ */
97
+ readonly parameters: IWebpackPluginAccessorParameters;
35
98
  }
36
99
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,IAAI,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,kCAAmC,SAAQ,OAAO,CAAC,aAAa;IAC/E,SAAS,CAAC,EAAE,6BAA6B,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC7B,kCAAkC,GAClC,kCAAkC,EAAE,GACpC,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,gCAAiC,SAAQ,yBAAyB;IACjF;;;;;;;;;OASG;IAGH,oBAAoB,CAAC,EAAE,OAAO,CAAC,aAAa,GAAG,OAAO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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,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CAC7F;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"}
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 { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';\nimport type * as webpack from 'webpack';\nimport type { IBuildStageProperties, IBundleSubstageProperties } from '@rushstack/heft';\n\n/**\n * @public\n */\nexport interface IWebpackConfigurationWithDevServer extends webpack.Configuration {\n devServer?: WebpackDevServerConfiguration;\n}\n\n/**\n * @public\n */\nexport type IWebpackConfiguration =\n | IWebpackConfigurationWithDevServer\n | IWebpackConfigurationWithDevServer[]\n | undefined;\n\n/**\n * @public\n */\nexport interface IWebpackBundleSubstageProperties extends IBundleSubstageProperties {\n /**\n * The configuration used by the Webpack plugin. This must be populated\n * for Webpack to run. If webpackConfigFilePath is specified,\n * this will be populated automatically with the exports of the\n * config file referenced in that property.\n *\n * @remarks\n * Tapable event handlers can return `null` instead of `undefined` to suppress\n * other handlers from creating a configuration object.\n */\n // We are inheriting this problem from Tapable's API\n // eslint-disable-next-line @rushstack/no-new-null\n webpackConfiguration?: webpack.Configuration | webpack.Configuration[] | null;\n}\n\n/**\n * @public\n */\nexport interface IWebpackBuildStageProperties extends IBuildStageProperties {\n webpackStats?: webpack.Stats | webpack.MultiStats;\n}\n"]}
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';\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.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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/heft-webpack5-plugin",
3
- "version": "0.6.12",
3
+ "version": "0.7.0-rc.6",
4
4
  "description": "Heft plugin for Webpack 5",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,24 +12,29 @@
12
12
  "types": "dist/heft-webpack5-plugin.d.ts",
13
13
  "license": "MIT",
14
14
  "peerDependencies": {
15
- "@rushstack/heft": "^0.50.7",
15
+ "@rushstack/heft": "^0.50.6",
16
16
  "webpack": "~5.80.0"
17
17
  },
18
18
  "dependencies": {
19
+ "@types/tapable": "1.0.6",
20
+ "tapable": "1.1.3",
21
+ "watchpack": "2.4.0",
19
22
  "webpack-dev-server": "~4.9.3",
20
- "@rushstack/node-core-library": "3.59.2"
23
+ "@rushstack/debug-certificate-manager": "1.2.27",
24
+ "@rushstack/node-core-library": "3.59.1"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@types/node": "14.18.36",
28
+ "@types/watchpack": "2.4.0",
24
29
  "webpack": "~5.80.0",
25
- "@rushstack/heft": "0.50.7",
26
- "@rushstack/heft-node-rig": "1.13.1",
27
- "@rushstack/eslint-config": "3.3.0"
30
+ "@rushstack/eslint-config": "3.3.0",
31
+ "@rushstack/heft": "0.51.0-rc.6",
32
+ "@rushstack/heft-node-rig": "1.14.0-rc.6"
28
33
  },
29
34
  "scripts": {
30
35
  "build": "heft build --clean",
31
36
  "start": "heft test --clean --watch",
32
- "_phase:build": "heft build --clean",
33
- "_phase:test": "heft test --no-build"
37
+ "_phase:build": "heft run --only build -- --clean",
38
+ "_phase:test": "heft run --only test -- --clean"
34
39
  }
35
40
  }
@@ -1,14 +0,0 @@
1
- import type { HeftConfiguration, HeftSession, IHeftPlugin } from '@rushstack/heft';
2
- /**
3
- * @internal
4
- */
5
- export declare class WebpackPlugin implements IHeftPlugin {
6
- readonly pluginName: string;
7
- private static _webpackVersions;
8
- private static _getWebpackVersions;
9
- apply(heftSession: HeftSession, heftConfiguration: HeftConfiguration): void;
10
- private _runWebpackAsync;
11
- private _emitErrors;
12
- private _normalizeError;
13
- }
14
- //# sourceMappingURL=WebpackPlugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebpackPlugin.d.ts","sourceRoot":"","sources":["../src/WebpackPlugin.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EAIX,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AAmBzB;;GAEG;AACH,qBAAa,aAAc,YAAW,WAAW;IAC/C,SAAgB,UAAU,EAAE,MAAM,CAAe;IAEjD,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA+B;IAC9D,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkB3B,KAAK,CAAC,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,IAAI;YA2CpE,gBAAgB;IAoK9B,OAAO,CAAC,WAAW;IAyCnB,OAAO,CAAC,eAAe;CAqBxB"}
@@ -1,266 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
- // See LICENSE in the project root for license information.
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v });
17
- }) : function(o, v) {
18
- o["default"] = v;
19
- });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.WebpackPlugin = void 0;
29
- const nodePath = __importStar(require("path"));
30
- const node_core_library_1 = require("@rushstack/node-core-library");
31
- const WebpackConfigurationLoader_1 = require("./WebpackConfigurationLoader");
32
- const webpack = node_core_library_1.Import.lazy('webpack', require);
33
- const PLUGIN_NAME = 'WebpackPlugin';
34
- const WEBPACK_DEV_SERVER_PACKAGE_NAME = 'webpack-dev-server';
35
- const WEBPACK_DEV_SERVER_ENV_VAR_NAME = 'WEBPACK_DEV_SERVER';
36
- /**
37
- * @internal
38
- */
39
- class WebpackPlugin {
40
- constructor() {
41
- this.pluginName = PLUGIN_NAME;
42
- }
43
- static _getWebpackVersions() {
44
- if (!WebpackPlugin._webpackVersions) {
45
- const webpackDevServerPackageJsonPath = node_core_library_1.Import.resolveModule({
46
- modulePath: 'webpack-dev-server/package.json',
47
- baseFolderPath: __dirname
48
- });
49
- const webpackDevServerPackageJson = node_core_library_1.PackageJsonLookup.instance.loadPackageJson(webpackDevServerPackageJsonPath);
50
- WebpackPlugin._webpackVersions = {
51
- webpackVersion: webpack.version,
52
- webpackDevServerVersion: webpackDevServerPackageJson.version
53
- };
54
- }
55
- return WebpackPlugin._webpackVersions;
56
- }
57
- apply(heftSession, heftConfiguration) {
58
- heftSession.hooks.build.tap(PLUGIN_NAME, (build) => {
59
- build.hooks.bundle.tap(PLUGIN_NAME, (bundle) => {
60
- bundle.hooks.configureWebpack.tap({ name: PLUGIN_NAME, stage: Number.MIN_SAFE_INTEGER }, (webpackConfiguration) => {
61
- const webpackVersions = WebpackPlugin._getWebpackVersions();
62
- bundle.properties.webpackVersion = webpack.version;
63
- bundle.properties.webpackDevServerVersion = webpackVersions.webpackDevServerVersion;
64
- return webpackConfiguration;
65
- });
66
- bundle.hooks.configureWebpack.tapPromise(PLUGIN_NAME, async (existingConfiguration) => {
67
- const logger = heftSession.requestScopedLogger('configure-webpack');
68
- if (existingConfiguration) {
69
- logger.terminal.writeVerboseLine('Skipping loading webpack config file because the webpack config has already been set.');
70
- return existingConfiguration;
71
- }
72
- else {
73
- return await WebpackConfigurationLoader_1.WebpackConfigurationLoader.tryLoadWebpackConfigAsync(logger, heftConfiguration.buildFolder, build.properties);
74
- }
75
- });
76
- bundle.hooks.run.tapPromise(PLUGIN_NAME, async () => {
77
- await this._runWebpackAsync(heftSession, heftConfiguration, bundle.properties, build.properties, heftConfiguration.terminalProvider.supportsColor);
78
- });
79
- });
80
- });
81
- }
82
- async _runWebpackAsync(heftSession, heftConfiguration, bundleSubstageProperties, buildProperties, supportsColor) {
83
- const webpackConfiguration = bundleSubstageProperties.webpackConfiguration;
84
- if (!webpackConfiguration) {
85
- return;
86
- }
87
- const logger = heftSession.requestScopedLogger('webpack');
88
- const webpackVersions = WebpackPlugin._getWebpackVersions();
89
- if (bundleSubstageProperties.webpackVersion !== webpackVersions.webpackVersion) {
90
- logger.emitError(new Error(`The Webpack plugin expected to be configured with Webpack version ${webpackVersions.webpackVersion}, ` +
91
- `but the configuration specifies version ${bundleSubstageProperties.webpackVersion}. ` +
92
- 'Are multiple versions of the Webpack plugin present?'));
93
- }
94
- if (bundleSubstageProperties.webpackDevServerVersion !== webpackVersions.webpackDevServerVersion) {
95
- logger.emitError(new Error(`The Webpack plugin expected to be configured with webpack-dev-server version ${webpackVersions.webpackDevServerVersion}, ` +
96
- `but the configuration specifies version ${bundleSubstageProperties.webpackDevServerVersion}. ` +
97
- 'Are multiple versions of the Webpack plugin present?'));
98
- }
99
- logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);
100
- let compiler;
101
- if (Array.isArray(webpackConfiguration)) {
102
- if (webpackConfiguration.length === 0) {
103
- logger.terminal.writeLine('The webpack configuration is an empty array - nothing to do.');
104
- return;
105
- }
106
- else {
107
- compiler = webpack(webpackConfiguration); /* (webpack.Compilation[]) => MultiCompiler */
108
- }
109
- }
110
- else {
111
- compiler = webpack(webpackConfiguration); /* (webpack.Compilation) => Compiler */
112
- }
113
- if (buildProperties.serveMode) {
114
- const defaultDevServerOptions = {
115
- host: 'localhost',
116
- devMiddleware: {
117
- publicPath: '/',
118
- stats: {
119
- cached: false,
120
- cachedAssets: false,
121
- colors: supportsColor
122
- }
123
- },
124
- client: {
125
- logging: 'info',
126
- webSocketURL: {
127
- port: 8080
128
- }
129
- },
130
- port: 8080
131
- };
132
- let options;
133
- if (Array.isArray(webpackConfiguration)) {
134
- const devServerOptions = webpackConfiguration
135
- .map((configuration) => configuration.devServer)
136
- .filter((devServer) => !!devServer);
137
- if (devServerOptions.length > 1) {
138
- logger.emitWarning(new Error(`Detected multiple webpack devServer configurations, using the first one.`));
139
- }
140
- if (devServerOptions.length > 0) {
141
- options = Object.assign(Object.assign({}, defaultDevServerOptions), devServerOptions[0]);
142
- }
143
- else {
144
- options = defaultDevServerOptions;
145
- }
146
- }
147
- else {
148
- options = Object.assign(Object.assign({}, defaultDevServerOptions), webpackConfiguration.devServer);
149
- }
150
- // Register a plugin to callback after webpack is done with the first compilation
151
- // so we can move on to post-build
152
- let firstCompilationDoneCallback;
153
- const originalBeforeCallback = options.setupMiddlewares;
154
- options.setupMiddlewares = (middlewares, devServer) => {
155
- compiler.hooks.done.tap('heft-webpack-plugin', () => {
156
- if (firstCompilationDoneCallback) {
157
- firstCompilationDoneCallback();
158
- firstCompilationDoneCallback = undefined;
159
- }
160
- });
161
- if (originalBeforeCallback) {
162
- return originalBeforeCallback(middlewares, devServer);
163
- }
164
- return middlewares;
165
- };
166
- // The webpack-dev-server package has a design flaw, where merely loading its package will set the
167
- // WEBPACK_DEV_SERVER environment variable -- even if no APIs are accessed. This environment variable
168
- // causes incorrect behavior if Heft is not running in serve mode. Thus, we need to be careful to call require()
169
- // only if Heft is in serve mode.
170
- const WebpackDevServer = require(WEBPACK_DEV_SERVER_PACKAGE_NAME);
171
- // TODO: the WebpackDevServer accepts a third parameter for a logger. We should make
172
- // use of that to make logging cleaner
173
- const webpackDevServer = new WebpackDevServer(options, compiler);
174
- await new Promise((resolve, reject) => {
175
- firstCompilationDoneCallback = resolve;
176
- // Wrap in promise.resolve due to small issue in the type declaration, return type should be
177
- // webpackDevServer.start(): Promise<void>;
178
- Promise.resolve(webpackDevServer.start()).catch(reject);
179
- });
180
- }
181
- else {
182
- if (process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {
183
- logger.emitWarning(new Error(`The "${WEBPACK_DEV_SERVER_ENV_VAR_NAME}" environment variable is set, ` +
184
- 'which will cause problems when webpack is not running in serve mode. ' +
185
- `(Did a dependency inadvertently load the "${WEBPACK_DEV_SERVER_PACKAGE_NAME}" package?)`));
186
- }
187
- let stats;
188
- if (buildProperties.watchMode) {
189
- try {
190
- stats = await node_core_library_1.LegacyAdapters.convertCallbackToPromise(compiler.watch.bind(compiler), {});
191
- }
192
- catch (e) {
193
- logger.emitError(e);
194
- }
195
- }
196
- else {
197
- try {
198
- stats = await node_core_library_1.LegacyAdapters.convertCallbackToPromise(compiler.run.bind(compiler));
199
- await node_core_library_1.LegacyAdapters.convertCallbackToPromise(compiler.close.bind(compiler));
200
- }
201
- catch (e) {
202
- logger.emitError(e);
203
- }
204
- }
205
- if (stats) {
206
- // eslint-disable-next-line require-atomic-updates
207
- buildProperties.webpackStats = stats;
208
- this._emitErrors(logger, heftConfiguration.buildFolder, stats);
209
- }
210
- }
211
- }
212
- _emitErrors(logger, buildFolder, stats) {
213
- if (stats.hasErrors() || stats.hasWarnings()) {
214
- const serializedStats = [stats.toJson('errors-warnings')];
215
- const errors = [];
216
- const warnings = [];
217
- for (const compilationStats of serializedStats) {
218
- if (compilationStats.warnings) {
219
- for (const warning of compilationStats.warnings) {
220
- warnings.push(this._normalizeError(buildFolder, warning));
221
- }
222
- }
223
- if (compilationStats.errors) {
224
- for (const error of compilationStats.errors) {
225
- errors.push(this._normalizeError(buildFolder, error));
226
- }
227
- }
228
- if (compilationStats.children) {
229
- for (const child of compilationStats.children) {
230
- serializedStats.push(child);
231
- }
232
- }
233
- }
234
- for (const warning of warnings) {
235
- logger.emitWarning(warning);
236
- }
237
- for (const error of errors) {
238
- logger.emitError(error);
239
- }
240
- }
241
- }
242
- _normalizeError(buildFolder, error) {
243
- if (error instanceof Error) {
244
- return error;
245
- }
246
- else {
247
- let moduleName = error.moduleName;
248
- if (!moduleName && error.moduleIdentifier) {
249
- moduleName = node_core_library_1.Path.convertToSlashes(nodePath.relative(buildFolder, error.moduleIdentifier));
250
- }
251
- let formattedError;
252
- if (error.loc && moduleName) {
253
- formattedError = `${moduleName}:${error.loc} - ${error.message}`;
254
- }
255
- else if (moduleName) {
256
- formattedError = `${moduleName} - ${error.message}`;
257
- }
258
- else {
259
- formattedError = error.message;
260
- }
261
- return new Error(formattedError);
262
- }
263
- }
264
- }
265
- exports.WebpackPlugin = WebpackPlugin;
266
- //# sourceMappingURL=WebpackPlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebpackPlugin.js","sourceRoot":"","sources":["../src/WebpackPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+CAAiC;AAUjC,oEAA6G;AAe7G,6EAA0E;AAE1E,MAAM,OAAO,GAA6B,0BAAM,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAE1E,MAAM,WAAW,GAAW,eAAe,CAAC;AAC5C,MAAM,+BAA+B,GAAW,oBAAoB,CAAC;AACrE,MAAM,+BAA+B,GAAW,oBAAoB,CAAC;AAOrE;;GAEG;AACH,MAAa,aAAa;IAA1B;QACkB,eAAU,GAAW,WAAW,CAAC;IAkSnD,CAAC;IA/RS,MAAM,CAAC,mBAAmB;QAChC,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE;YACnC,MAAM,+BAA+B,GAAW,0BAAM,CAAC,aAAa,CAAC;gBACnE,UAAU,EAAE,iCAAiC;gBAC7C,cAAc,EAAE,SAAS;aAC1B,CAAC,CAAC;YACH,MAAM,2BAA2B,GAAiB,qCAAiB,CAAC,QAAQ,CAAC,eAAe,CAC1F,+BAA+B,CAChC,CAAC;YACF,aAAa,CAAC,gBAAgB,GAAG;gBAC/B,cAAc,EAAE,OAAO,CAAC,OAAQ;gBAChC,uBAAuB,EAAE,2BAA2B,CAAC,OAAO;aAC7D,CAAC;SACH;QAED,OAAO,aAAa,CAAC,gBAAgB,CAAC;IACxC,CAAC;IAEM,KAAK,CAAC,WAAwB,EAAE,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EAAE;gBACrB,cAAc,GAAG,GAAG,UAAU,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;aACrD;iBAAM;gBACL,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC;aAChC;YAED,OAAO,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;SAClC;IACH,CAAC;CACF;AAnSD,sCAmSC","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 nodePath from 'path';\nimport type {\n Compiler as WebpackCompiler,\n MultiCompiler as WebpackMultiCompiler,\n Stats as WebpackStats,\n MultiStats as WebpackMultiStats,\n StatsCompilation as WebpackStatsCompilation,\n StatsError as WebpackStatsError\n} from 'webpack';\nimport type TWebpackDevServer from 'webpack-dev-server';\nimport { LegacyAdapters, Path, Import, IPackageJson, PackageJsonLookup } from '@rushstack/node-core-library';\nimport type {\n HeftConfiguration,\n HeftSession,\n IBuildStageContext,\n IBuildStageProperties,\n IBundleSubstage,\n IHeftPlugin,\n ScopedLogger\n} from '@rushstack/heft';\nimport type {\n IWebpackConfiguration,\n IWebpackBundleSubstageProperties,\n IWebpackBuildStageProperties\n} from './shared';\nimport { WebpackConfigurationLoader } from './WebpackConfigurationLoader';\n\nconst webpack: typeof import('webpack') = Import.lazy('webpack', require);\n\nconst PLUGIN_NAME: string = 'WebpackPlugin';\nconst WEBPACK_DEV_SERVER_PACKAGE_NAME: string = 'webpack-dev-server';\nconst WEBPACK_DEV_SERVER_ENV_VAR_NAME: string = 'WEBPACK_DEV_SERVER';\n\ninterface IWebpackVersions {\n webpackVersion: string;\n webpackDevServerVersion: string;\n}\n\n/**\n * @internal\n */\nexport class WebpackPlugin implements IHeftPlugin {\n public readonly pluginName: string = PLUGIN_NAME;\n\n private static _webpackVersions: IWebpackVersions | undefined;\n private static _getWebpackVersions(): IWebpackVersions {\n if (!WebpackPlugin._webpackVersions) {\n const webpackDevServerPackageJsonPath: string = Import.resolveModule({\n modulePath: 'webpack-dev-server/package.json',\n baseFolderPath: __dirname\n });\n const webpackDevServerPackageJson: IPackageJson = PackageJsonLookup.instance.loadPackageJson(\n webpackDevServerPackageJsonPath\n );\n WebpackPlugin._webpackVersions = {\n webpackVersion: webpack.version!,\n webpackDevServerVersion: webpackDevServerPackageJson.version\n };\n }\n\n return WebpackPlugin._webpackVersions;\n }\n\n public apply(heftSession: HeftSession, heftConfiguration: HeftConfiguration): void {\n heftSession.hooks.build.tap(PLUGIN_NAME, (build: IBuildStageContext) => {\n build.hooks.bundle.tap(PLUGIN_NAME, (bundle: IBundleSubstage) => {\n bundle.hooks.configureWebpack.tap(\n { name: PLUGIN_NAME, stage: Number.MIN_SAFE_INTEGER },\n (webpackConfiguration: unknown) => {\n const webpackVersions: IWebpackVersions = WebpackPlugin._getWebpackVersions();\n bundle.properties.webpackVersion = webpack.version;\n bundle.properties.webpackDevServerVersion = webpackVersions.webpackDevServerVersion;\n\n return webpackConfiguration;\n }\n );\n\n bundle.hooks.configureWebpack.tapPromise(PLUGIN_NAME, async (existingConfiguration: unknown) => {\n const logger: ScopedLogger = heftSession.requestScopedLogger('configure-webpack');\n if (existingConfiguration) {\n logger.terminal.writeVerboseLine(\n 'Skipping loading webpack config file because the webpack config has already been set.'\n );\n return existingConfiguration;\n } else {\n return await WebpackConfigurationLoader.tryLoadWebpackConfigAsync(\n logger,\n heftConfiguration.buildFolder,\n build.properties\n );\n }\n });\n\n bundle.hooks.run.tapPromise(PLUGIN_NAME, async () => {\n await this._runWebpackAsync(\n heftSession,\n heftConfiguration,\n bundle.properties as IWebpackBundleSubstageProperties,\n build.properties,\n heftConfiguration.terminalProvider.supportsColor\n );\n });\n });\n });\n }\n\n private async _runWebpackAsync(\n heftSession: HeftSession,\n heftConfiguration: HeftConfiguration,\n bundleSubstageProperties: IWebpackBundleSubstageProperties,\n buildProperties: IBuildStageProperties,\n supportsColor: boolean\n ): Promise<void> {\n const webpackConfiguration: IWebpackConfiguration | undefined | null =\n bundleSubstageProperties.webpackConfiguration;\n if (!webpackConfiguration) {\n return;\n }\n\n const logger: ScopedLogger = heftSession.requestScopedLogger('webpack');\n const webpackVersions: IWebpackVersions = WebpackPlugin._getWebpackVersions();\n if (bundleSubstageProperties.webpackVersion !== webpackVersions.webpackVersion) {\n logger.emitError(\n new Error(\n `The Webpack plugin expected to be configured with Webpack version ${webpackVersions.webpackVersion}, ` +\n `but the configuration specifies version ${bundleSubstageProperties.webpackVersion}. ` +\n 'Are multiple versions of the Webpack plugin present?'\n )\n );\n }\n\n if (bundleSubstageProperties.webpackDevServerVersion !== webpackVersions.webpackDevServerVersion) {\n logger.emitError(\n new Error(\n `The Webpack plugin expected to be configured with webpack-dev-server version ${webpackVersions.webpackDevServerVersion}, ` +\n `but the configuration specifies version ${bundleSubstageProperties.webpackDevServerVersion}. ` +\n 'Are multiple versions of the Webpack plugin present?'\n )\n );\n }\n\n logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);\n\n let compiler: WebpackCompiler | WebpackMultiCompiler;\n if (Array.isArray(webpackConfiguration)) {\n if (webpackConfiguration.length === 0) {\n logger.terminal.writeLine('The webpack configuration is an empty array - nothing to do.');\n return;\n } else {\n compiler = webpack(webpackConfiguration); /* (webpack.Compilation[]) => MultiCompiler */\n }\n } else {\n compiler = webpack(webpackConfiguration); /* (webpack.Compilation) => Compiler */\n }\n\n if (buildProperties.serveMode) {\n const defaultDevServerOptions: TWebpackDevServer.Configuration = {\n host: 'localhost',\n devMiddleware: {\n publicPath: '/',\n stats: {\n cached: false,\n cachedAssets: false,\n colors: supportsColor\n }\n },\n client: {\n logging: 'info',\n webSocketURL: {\n port: 8080\n }\n },\n port: 8080\n };\n\n let options: TWebpackDevServer.Configuration;\n if (Array.isArray(webpackConfiguration)) {\n const devServerOptions: TWebpackDevServer.Configuration[] = webpackConfiguration\n .map((configuration) => configuration.devServer)\n .filter((devServer): devServer is TWebpackDevServer.Configuration => !!devServer);\n if (devServerOptions.length > 1) {\n logger.emitWarning(\n new Error(`Detected multiple webpack devServer configurations, using the first one.`)\n );\n }\n\n if (devServerOptions.length > 0) {\n options = { ...defaultDevServerOptions, ...devServerOptions[0] };\n } else {\n options = defaultDevServerOptions;\n }\n } else {\n options = { ...defaultDevServerOptions, ...webpackConfiguration.devServer };\n }\n\n // Register a plugin to callback after webpack is done with the first compilation\n // so we can move on to post-build\n let firstCompilationDoneCallback: (() => void) | undefined;\n const originalBeforeCallback: typeof options.setupMiddlewares | undefined = options.setupMiddlewares;\n options.setupMiddlewares = (middlewares, devServer) => {\n compiler.hooks.done.tap('heft-webpack-plugin', () => {\n if (firstCompilationDoneCallback) {\n firstCompilationDoneCallback();\n firstCompilationDoneCallback = undefined;\n }\n });\n\n if (originalBeforeCallback) {\n return originalBeforeCallback(middlewares, devServer);\n }\n return middlewares;\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 require()\n // only if Heft is in serve mode.\n const WebpackDevServer: typeof TWebpackDevServer = require(WEBPACK_DEV_SERVER_PACKAGE_NAME);\n // TODO: the WebpackDevServer accepts a third parameter for a logger. We should make\n // use of that to make logging cleaner\n const webpackDevServer: TWebpackDevServer = new WebpackDevServer(options, compiler);\n\n await new Promise<void>((resolve: () => void, reject: (error: Error) => void) => {\n firstCompilationDoneCallback = resolve;\n\n // Wrap in promise.resolve due to small issue in the type declaration, return type should be\n // webpackDevServer.start(): Promise<void>;\n Promise.resolve(webpackDevServer.start()).catch(reject);\n });\n } else {\n if (process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {\n 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 let stats: WebpackStats | WebpackMultiStats | undefined;\n if (buildProperties.watchMode) {\n try {\n stats = await LegacyAdapters.convertCallbackToPromise(\n (compiler as WebpackCompiler).watch.bind(compiler),\n {}\n );\n } catch (e) {\n logger.emitError(e as Error);\n }\n } else {\n try {\n stats = await LegacyAdapters.convertCallbackToPromise(\n (compiler as WebpackCompiler).run.bind(compiler)\n );\n await LegacyAdapters.convertCallbackToPromise(compiler.close.bind(compiler));\n } catch (e) {\n logger.emitError(e as Error);\n }\n }\n\n if (stats) {\n // eslint-disable-next-line require-atomic-updates\n (buildProperties as IWebpackBuildStageProperties).webpackStats = stats;\n\n this._emitErrors(logger, heftConfiguration.buildFolder, stats);\n }\n }\n }\n\n private _emitErrors(\n logger: ScopedLogger,\n buildFolder: string,\n stats: WebpackStats | WebpackMultiStats\n ): void {\n if (stats.hasErrors() || stats.hasWarnings()) {\n const serializedStats: WebpackStatsCompilation[] = [stats.toJson('errors-warnings')];\n\n const errors: Error[] = [];\n const warnings: Error[] = [];\n\n for (const compilationStats of serializedStats) {\n if (compilationStats.warnings) {\n for (const warning of compilationStats.warnings) {\n warnings.push(this._normalizeError(buildFolder, warning));\n }\n }\n\n if (compilationStats.errors) {\n for (const error of compilationStats.errors) {\n errors.push(this._normalizeError(buildFolder, error));\n }\n }\n\n if (compilationStats.children) {\n for (const child of compilationStats.children) {\n serializedStats.push(child);\n }\n }\n }\n\n for (const warning of warnings) {\n logger.emitWarning(warning);\n }\n\n for (const error of errors) {\n logger.emitError(error);\n }\n }\n }\n\n private _normalizeError(buildFolder: string, error: WebpackStatsError): Error {\n if (error instanceof Error) {\n return error;\n } else {\n let moduleName: string | undefined = error.moduleName;\n if (!moduleName && error.moduleIdentifier) {\n moduleName = Path.convertToSlashes(nodePath.relative(buildFolder, error.moduleIdentifier));\n }\n\n let formattedError: string;\n if (error.loc && moduleName) {\n formattedError = `${moduleName}:${error.loc} - ${error.message}`;\n } else if (moduleName) {\n formattedError = `${moduleName} - ${error.message}`;\n } else {\n formattedError = error.message;\n }\n\n return new Error(formattedError);\n }\n }\n}\n"]}