@rushstack/webpack-plugin-utilities 0.1.57 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,6 +10,8 @@ This is a collection of utilities for writing webpack plugins
10
10
 
11
11
  # Usage
12
12
 
13
+ ## VersionDetection
14
+
13
15
  ```JavaScript
14
16
  import { VersionDetection } from "@rushstack/webpack-plugin-utilities"
15
17
 
@@ -38,6 +40,66 @@ class MyExampleWebpackPlugin {
38
40
  }
39
41
  ```
40
42
 
43
+ ## Testing
44
+
45
+ ### `getTestingWebpackCompiler`
46
+
47
+ ```typescript
48
+
49
+ import { getTestingWebpackCompiler } from "@rushstack/webpack-plugin-utilities"
50
+
51
+ describe("MyPlugin", () => {
52
+ it("should run", async () => {
53
+ const stats = await getTestingWebpackCompiler("./src/index.ts");
54
+
55
+ expect(stats).toBeDefined();
56
+ });
57
+ });
58
+ ```
59
+
60
+ ### `getTestingWebpackCompiler` with additional configuration
61
+
62
+ If you want to pass in additional configuration to the webpack compiler, you can pass it in as the second parameter to `getTestingWebpackCompiler`.
63
+
64
+ ```typescript
65
+ import { getTestingWebpackCompiler } from "@rushstack/webpack-plugin-utilities"
66
+
67
+ describe("MyPlugin", () => {
68
+ it("should run", async () => {
69
+ const stats = await getTestingWebpackCompiler("./src/index.ts", {
70
+ mode: "production",
71
+ });
72
+
73
+ expect(stats).toBeDefined();
74
+ });
75
+ });
76
+ ```
77
+
78
+ ### `getTestingWebpackCompiler` with virtual filesystem
79
+
80
+ If you want to be able to read, analyze, access the files written to the memory filesystem,
81
+ you can pass in a memory filesystem instance to the `memFs` parameter.
82
+
83
+ ```typescript
84
+ import { getTestingWebpackCompiler } from "@rushstack/webpack-plugin-utilities"
85
+ import { createFsFromVolume, Volume, IFs } from "memfs"
86
+ import path from "path"
87
+
88
+ describe("MyPlugin", () => {
89
+ it("should run", async () => {
90
+ const virtualFileSystem: IFs = createFsFromVolume(new Volume());
91
+ const stats = await getTestingWebpackCompiler(
92
+ `./src/index.ts`,
93
+ {},
94
+ virtualFileSystem
95
+ );
96
+
97
+ expect(stats).toBeDefined();
98
+ expect(virtualFileSystem.existsSync(path.join(__dirname, "dist", "index.js"))).toBe(true);
99
+ });
100
+ });
101
+ ```
102
+
41
103
  ## Links
42
104
 
43
105
  - [CHANGELOG.md](
@@ -4,8 +4,65 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
 
7
+ import type { Configuration } from 'webpack';
8
+ import { IFs } from 'memfs';
9
+ import type { MultiStats } from 'webpack';
10
+ import type { Stats } from 'webpack';
7
11
  import type * as Webpack from 'webpack';
8
12
 
13
+ /**
14
+ * @public
15
+ * This function generates a webpack compiler with default configuration and the output filesystem mapped to
16
+ * a memory filesystem. This is useful for testing webpack plugins/loaders where we do not need to write to disk (which can be costly).
17
+ * @param entry - The entry point for the webpack compiler
18
+ * @param additionalConfig - Any additional configuration that should be merged with the default configuration
19
+ * @param memFs - The memory filesystem to use for the output filesystem. Use this option if you want to _inspect_, analyze, or read the output
20
+ * files generated by the webpack compiler. If you do not need to do this, you can omit this parameter and the output files.
21
+ *
22
+ * @returns - A webpack compiler with the output filesystem mapped to a memory filesystem
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import Testing from '@rushstack/webpack-plugin-utilities';
27
+ *
28
+ * describe('MyPlugin', () => {
29
+ it('should run', async () => {
30
+ const stats = await Testing.getTestingWebpackCompiler(
31
+ `./src/index.ts`,
32
+ );
33
+
34
+ expect(stats).toBeDefined();
35
+ });
36
+ * });
37
+ * ```
38
+ *
39
+ * @remarks
40
+ * If you want to be able to read, analyze, access the files written to the memory filesystem,
41
+ * you can pass in a memory filesystem instance to the `memFs` parameter.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import Testing from '@rushstack/webpack-plugin-utilities';
46
+ * import { createFsFromVolume, Volume, IFs } from 'memfs';
47
+ * import path from 'path';
48
+ *
49
+ * describe('MyPlugin', () => {
50
+ * it('should run', async () => {
51
+ * const virtualFileSystem: IFs = createFsFromVolume(new Volume());
52
+ * const stats = await Testing.getTestingWebpackCompiler(
53
+ * `./src/index.ts`,
54
+ * {},
55
+ * virtualFileSystem
56
+ * );
57
+ *
58
+ * expect(stats).toBeDefined();
59
+ * expect(virtualFileSystem.existsSync(path.join(__dirname, 'dist', 'index.js'))).toBe(true);
60
+ * });
61
+ * });
62
+ * ```
63
+ */
64
+ declare function getTestingWebpackCompilerAsync(entry: string, additionalConfig?: Configuration, memFs?: IFs): Promise<(Stats | MultiStats) | undefined>;
65
+
9
66
  /**
10
67
  * We do not have quality API detection between webpack major versions 1-3.
11
68
  * We can detect the absence of hooks which was a version 3 feature.
@@ -28,6 +85,13 @@ declare function isWebpack4(compiler: Webpack.Compiler): boolean;
28
85
  */
29
86
  declare function isWebpack5(compiler: Webpack.Compiler): boolean;
30
87
 
88
+ declare namespace Testing {
89
+ export {
90
+ getTestingWebpackCompilerAsync
91
+ }
92
+ }
93
+ export { Testing }
94
+
31
95
  declare namespace VersionDetection {
32
96
  export {
33
97
  isWebpack3OrEarlier,
@@ -0,0 +1,55 @@
1
+ import { IFs } from 'memfs';
2
+ import type { MultiStats, Stats, Configuration } from 'webpack';
3
+ /**
4
+ * @public
5
+ * This function generates a webpack compiler with default configuration and the output filesystem mapped to
6
+ * a memory filesystem. This is useful for testing webpack plugins/loaders where we do not need to write to disk (which can be costly).
7
+ * @param entry - The entry point for the webpack compiler
8
+ * @param additionalConfig - Any additional configuration that should be merged with the default configuration
9
+ * @param memFs - The memory filesystem to use for the output filesystem. Use this option if you want to _inspect_, analyze, or read the output
10
+ * files generated by the webpack compiler. If you do not need to do this, you can omit this parameter and the output files.
11
+ *
12
+ * @returns - A webpack compiler with the output filesystem mapped to a memory filesystem
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import Testing from '@rushstack/webpack-plugin-utilities';
17
+ *
18
+ * describe('MyPlugin', () => {
19
+ it('should run', async () => {
20
+ const stats = await Testing.getTestingWebpackCompiler(
21
+ `./src/index.ts`,
22
+ );
23
+
24
+ expect(stats).toBeDefined();
25
+ });
26
+ * });
27
+ * ```
28
+ *
29
+ * @remarks
30
+ * If you want to be able to read, analyze, access the files written to the memory filesystem,
31
+ * you can pass in a memory filesystem instance to the `memFs` parameter.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import Testing from '@rushstack/webpack-plugin-utilities';
36
+ * import { createFsFromVolume, Volume, IFs } from 'memfs';
37
+ * import path from 'path';
38
+ *
39
+ * describe('MyPlugin', () => {
40
+ * it('should run', async () => {
41
+ * const virtualFileSystem: IFs = createFsFromVolume(new Volume());
42
+ * const stats = await Testing.getTestingWebpackCompiler(
43
+ * `./src/index.ts`,
44
+ * {},
45
+ * virtualFileSystem
46
+ * );
47
+ *
48
+ * expect(stats).toBeDefined();
49
+ * expect(virtualFileSystem.existsSync(path.join(__dirname, 'dist', 'index.js'))).toBe(true);
50
+ * });
51
+ * });
52
+ * ```
53
+ */
54
+ export declare function getTestingWebpackCompilerAsync(entry: string, additionalConfig?: Configuration, memFs?: IFs): Promise<(Stats | MultiStats) | undefined>;
55
+ //# sourceMappingURL=Testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Testing.d.ts","sourceRoot":"","sources":["../src/Testing.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,GAAG,EAAE,MAAM,OAAO,CAAC;AAKxD,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAwB,MAAM,SAAS,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAsB,8BAA8B,CAClD,KAAK,EAAE,MAAM,EACb,gBAAgB,GAAE,aAAkB,EACpC,KAAK,GAAE,GAAsC,GAC5C,OAAO,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,SAAS,CAAC,CA+B3C"}
package/lib/Testing.js ADDED
@@ -0,0 +1,150 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
28
+ return (mod && mod.__esModule) ? mod : { "default": mod };
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.getTestingWebpackCompilerAsync = void 0;
32
+ const memfs_1 = require("memfs");
33
+ const path_1 = __importDefault(require("path"));
34
+ const webpack_merge_1 = __importDefault(require("webpack-merge"));
35
+ /**
36
+ * @public
37
+ * This function generates a webpack compiler with default configuration and the output filesystem mapped to
38
+ * a memory filesystem. This is useful for testing webpack plugins/loaders where we do not need to write to disk (which can be costly).
39
+ * @param entry - The entry point for the webpack compiler
40
+ * @param additionalConfig - Any additional configuration that should be merged with the default configuration
41
+ * @param memFs - The memory filesystem to use for the output filesystem. Use this option if you want to _inspect_, analyze, or read the output
42
+ * files generated by the webpack compiler. If you do not need to do this, you can omit this parameter and the output files.
43
+ *
44
+ * @returns - A webpack compiler with the output filesystem mapped to a memory filesystem
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * import Testing from '@rushstack/webpack-plugin-utilities';
49
+ *
50
+ * describe('MyPlugin', () => {
51
+ it('should run', async () => {
52
+ const stats = await Testing.getTestingWebpackCompiler(
53
+ `./src/index.ts`,
54
+ );
55
+
56
+ expect(stats).toBeDefined();
57
+ });
58
+ * });
59
+ * ```
60
+ *
61
+ * @remarks
62
+ * If you want to be able to read, analyze, access the files written to the memory filesystem,
63
+ * you can pass in a memory filesystem instance to the `memFs` parameter.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import Testing from '@rushstack/webpack-plugin-utilities';
68
+ * import { createFsFromVolume, Volume, IFs } from 'memfs';
69
+ * import path from 'path';
70
+ *
71
+ * describe('MyPlugin', () => {
72
+ * it('should run', async () => {
73
+ * const virtualFileSystem: IFs = createFsFromVolume(new Volume());
74
+ * const stats = await Testing.getTestingWebpackCompiler(
75
+ * `./src/index.ts`,
76
+ * {},
77
+ * virtualFileSystem
78
+ * );
79
+ *
80
+ * expect(stats).toBeDefined();
81
+ * expect(virtualFileSystem.existsSync(path.join(__dirname, 'dist', 'index.js'))).toBe(true);
82
+ * });
83
+ * });
84
+ * ```
85
+ */
86
+ async function getTestingWebpackCompilerAsync(entry, additionalConfig = {}, memFs = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume())) {
87
+ let webpackModule;
88
+ try {
89
+ webpackModule = (await Promise.resolve().then(() => __importStar(require('webpack')))).default;
90
+ }
91
+ catch (e) {
92
+ throw new Error('Unable to load module "webpack". The @rushstack/webpack-plugin-utilities package declares "webpack" as ' +
93
+ 'an optional peer dependency, but a function was invoked on it that requires webpack. Make sure ' +
94
+ `the peer dependency on "webpack" is fulfilled. Inner error: ${e}`);
95
+ }
96
+ const compilerOptions = (0, webpack_merge_1.default)(_defaultWebpackConfig(entry), additionalConfig);
97
+ const compiler = webpackModule(compilerOptions);
98
+ compiler.outputFileSystem = memFs;
99
+ compiler.outputFileSystem.join = path_1.default.join.bind(path_1.default);
100
+ return new Promise((resolve, reject) => {
101
+ compiler.run((err, stats) => {
102
+ compiler.close(() => {
103
+ if (err) {
104
+ return reject(err);
105
+ }
106
+ _processAndHandleStatsErrorsAndWarnings(stats, reject);
107
+ resolve(stats);
108
+ });
109
+ });
110
+ });
111
+ }
112
+ exports.getTestingWebpackCompilerAsync = getTestingWebpackCompilerAsync;
113
+ function _processAndHandleStatsErrorsAndWarnings(stats, reject) {
114
+ if ((stats === null || stats === void 0 ? void 0 : stats.hasErrors()) || (stats === null || stats === void 0 ? void 0 : stats.hasWarnings())) {
115
+ const serializedStats = [stats === null || stats === void 0 ? void 0 : stats.toJson('errors-warnings')];
116
+ const errors = [];
117
+ const warnings = [];
118
+ for (const compilationStats of serializedStats) {
119
+ if (compilationStats.warnings) {
120
+ for (const warning of compilationStats.warnings) {
121
+ warnings.push(warning);
122
+ }
123
+ }
124
+ if (compilationStats.errors) {
125
+ for (const error of compilationStats.errors) {
126
+ errors.push(error);
127
+ }
128
+ }
129
+ if (compilationStats.children) {
130
+ for (const child of compilationStats.children) {
131
+ serializedStats.push(child);
132
+ }
133
+ }
134
+ }
135
+ reject([...errors, ...warnings]);
136
+ }
137
+ }
138
+ function _defaultWebpackConfig(entry = './src') {
139
+ return {
140
+ // We don't want to have eval source maps, nor minification
141
+ // so we set mode to 'none' to disable both. Default is 'production'
142
+ mode: 'none',
143
+ context: __dirname,
144
+ entry,
145
+ output: {
146
+ filename: 'test-bundle.js'
147
+ }
148
+ };
149
+ }
150
+ //# sourceMappingURL=Testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Testing.js","sourceRoot":"","sources":["../src/Testing.ts"],"names":[],"mappings":"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","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 { createFsFromVolume, Volume, IFs } from 'memfs';\nimport path from 'path';\nimport type { StatsCompilation as WebpackStatsCompilation } from 'webpack';\nimport webpackMerge from 'webpack-merge';\n\nimport type { MultiStats, Stats, Configuration, Compiler, StatsError } from 'webpack';\n\n/**\n * @public\n * This function generates a webpack compiler with default configuration and the output filesystem mapped to\n * a memory filesystem. This is useful for testing webpack plugins/loaders where we do not need to write to disk (which can be costly).\n * @param entry - The entry point for the webpack compiler\n * @param additionalConfig - Any additional configuration that should be merged with the default configuration\n * @param memFs - The memory filesystem to use for the output filesystem. Use this option if you want to _inspect_, analyze, or read the output\n * files generated by the webpack compiler. If you do not need to do this, you can omit this parameter and the output files.\n *\n * @returns - A webpack compiler with the output filesystem mapped to a memory filesystem\n *\n * @example\n * ```typescript\n * import Testing from '@rushstack/webpack-plugin-utilities';\n *\n * describe('MyPlugin', () => {\n it('should run', async () => {\n const stats = await Testing.getTestingWebpackCompiler(\n `./src/index.ts`,\n );\n\n expect(stats).toBeDefined();\n });\n * });\n * ```\n *\n * @remarks\n * If you want to be able to read, analyze, access the files written to the memory filesystem,\n * you can pass in a memory filesystem instance to the `memFs` parameter.\n *\n * @example\n * ```typescript\n * import Testing from '@rushstack/webpack-plugin-utilities';\n * import { createFsFromVolume, Volume, IFs } from 'memfs';\n * import path from 'path';\n *\n * describe('MyPlugin', () => {\n * it('should run', async () => {\n * const virtualFileSystem: IFs = createFsFromVolume(new Volume());\n * const stats = await Testing.getTestingWebpackCompiler(\n * `./src/index.ts`,\n * {},\n * virtualFileSystem\n * );\n *\n * expect(stats).toBeDefined();\n * expect(virtualFileSystem.existsSync(path.join(__dirname, 'dist', 'index.js'))).toBe(true);\n * });\n * });\n * ```\n */\nexport async function getTestingWebpackCompilerAsync(\n entry: string,\n additionalConfig: Configuration = {},\n memFs: IFs = createFsFromVolume(new Volume())\n): Promise<(Stats | MultiStats) | undefined> {\n let webpackModule: typeof import('webpack');\n try {\n webpackModule = (await import('webpack')).default;\n } catch (e) {\n throw new Error(\n 'Unable to load module \"webpack\". The @rushstack/webpack-plugin-utilities package declares \"webpack\" as ' +\n 'an optional peer dependency, but a function was invoked on it that requires webpack. Make sure ' +\n `the peer dependency on \"webpack\" is fulfilled. Inner error: ${e}`\n );\n }\n\n const compilerOptions: Configuration = webpackMerge(_defaultWebpackConfig(entry), additionalConfig);\n const compiler: Compiler = webpackModule(compilerOptions);\n\n compiler.outputFileSystem = memFs;\n compiler.outputFileSystem.join = path.join.bind(path);\n\n return new Promise((resolve, reject) => {\n compiler.run((err, stats) => {\n compiler.close(() => {\n if (err) {\n return reject(err);\n }\n\n _processAndHandleStatsErrorsAndWarnings(stats, reject);\n\n resolve(stats);\n });\n });\n });\n}\n\nfunction _processAndHandleStatsErrorsAndWarnings(\n stats: Stats | MultiStats | undefined,\n reject: (reason: unknown) => void\n): void {\n if (stats?.hasErrors() || stats?.hasWarnings()) {\n const serializedStats: WebpackStatsCompilation[] = [stats?.toJson('errors-warnings')];\n\n const errors: StatsError[] = [];\n const warnings: StatsError[] = [];\n\n for (const compilationStats of serializedStats) {\n if (compilationStats.warnings) {\n for (const warning of compilationStats.warnings) {\n warnings.push(warning);\n }\n }\n\n if (compilationStats.errors) {\n for (const error of compilationStats.errors) {\n errors.push(error);\n }\n }\n\n if (compilationStats.children) {\n for (const child of compilationStats.children) {\n serializedStats.push(child);\n }\n }\n }\n\n reject([...errors, ...warnings]);\n }\n}\n\nfunction _defaultWebpackConfig(entry: string = './src'): Configuration {\n return {\n // We don't want to have eval source maps, nor minification\n // so we set mode to 'none' to disable both. Default is 'production'\n mode: 'none',\n context: __dirname,\n entry,\n output: {\n filename: 'test-bundle.js'\n }\n };\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -4,5 +4,6 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
  import * as VersionDetection from './DetectWebpackVersion';
7
- export { VersionDetection };
7
+ import * as Testing from './Testing';
8
+ export { VersionDetection, Testing };
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,gBAAgB,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,gBAAgB,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC"}
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  return result;
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.VersionDetection = void 0;
28
+ exports.Testing = exports.VersionDetection = void 0;
29
29
  /**
30
30
  * Utility package which provides a set of tools for working in
31
31
  * webpack plugins, loaders, and other integrations.
@@ -33,4 +33,6 @@ exports.VersionDetection = void 0;
33
33
  */
34
34
  const VersionDetection = __importStar(require("./DetectWebpackVersion"));
35
35
  exports.VersionDetection = VersionDetection;
36
+ const Testing = __importStar(require("./Testing"));
37
+ exports.Testing = Testing;
36
38
  //# 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;;;;GAIG;AAEH,yEAA2D;AAClD,4CAAgB","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * Utility package which provides a set of tools for working in\n * webpack plugins, loaders, and other integrations.\n * @packageDocumentation\n */\n\nimport * as VersionDetection from './DetectWebpackVersion';\nexport { VersionDetection };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D;;;;GAIG;AAEH,yEAA2D;AAElD,4CAAgB;AADzB,mDAAqC;AACV,0BAAO","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * Utility package which provides a set of tools for working in\n * webpack plugins, loaders, and other integrations.\n * @packageDocumentation\n */\n\nimport * as VersionDetection from './DetectWebpackVersion';\nimport * as Testing from './Testing';\nexport { VersionDetection, Testing };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/webpack-plugin-utilities",
3
- "version": "0.1.57",
3
+ "version": "0.2.1",
4
4
  "description": "This plugin sets the webpack public path at runtime.",
5
5
  "main": "lib/index.js",
6
6
  "typings": "dist/webpack-plugin-utilities.d.ts",
@@ -10,6 +10,10 @@
10
10
  "url": "https://github.com/microsoft/rushstack.git",
11
11
  "directory": "webpack/webpack-plugin-utilities"
12
12
  },
13
+ "dependencies": {
14
+ "webpack-merge": "~5.8.0",
15
+ "memfs": "3.4.3"
16
+ },
13
17
  "peerDependencies": {
14
18
  "@types/webpack": "^4.39.8",
15
19
  "webpack": "^5.35.1"