@rushstack/webpack-plugin-utilities 0.1.57 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/webpack-plugin-utilities.d.ts +64 -0
- package/lib/Testing.d.ts +55 -0
- package/lib/Testing.d.ts.map +1 -0
- package/lib/Testing.js +119 -0
- package/lib/Testing.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/package.json +5 -1
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 getTestingWebpackCompiler(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
|
+
getTestingWebpackCompiler
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export { Testing }
|
|
94
|
+
|
|
31
95
|
declare namespace VersionDetection {
|
|
32
96
|
export {
|
|
33
97
|
isWebpack3OrEarlier,
|
package/lib/Testing.d.ts
ADDED
|
@@ -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 getTestingWebpackCompiler(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;AAMxD,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAwB,MAAM,SAAS,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,MAAM,EACb,gBAAgB,GAAE,aAAkB,EACpC,KAAK,GAAE,GAAsC,GAC5C,OAAO,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,SAAS,CAAC,CAoB3C"}
|
package/lib/Testing.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getTestingWebpackCompiler = void 0;
|
|
9
|
+
const memfs_1 = require("memfs");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
12
|
+
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
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
|
+
async function getTestingWebpackCompiler(entry, additionalConfig = {}, memFs = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume())) {
|
|
65
|
+
const compilerOptions = (0, webpack_merge_1.default)(_defaultWebpackConfig(entry), additionalConfig);
|
|
66
|
+
const compiler = (0, webpack_1.default)(compilerOptions);
|
|
67
|
+
compiler.outputFileSystem = memFs;
|
|
68
|
+
compiler.outputFileSystem.join = path_1.default.join.bind(path_1.default);
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
compiler.run((err, stats) => {
|
|
71
|
+
compiler.close(() => {
|
|
72
|
+
if (err) {
|
|
73
|
+
return reject(err);
|
|
74
|
+
}
|
|
75
|
+
_processAndHandleStatsErrorsAndWarnings(stats, reject);
|
|
76
|
+
resolve(stats);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.getTestingWebpackCompiler = getTestingWebpackCompiler;
|
|
82
|
+
function _processAndHandleStatsErrorsAndWarnings(stats, reject) {
|
|
83
|
+
if ((stats === null || stats === void 0 ? void 0 : stats.hasErrors()) || (stats === null || stats === void 0 ? void 0 : stats.hasWarnings())) {
|
|
84
|
+
const serializedStats = [stats === null || stats === void 0 ? void 0 : stats.toJson('errors-warnings')];
|
|
85
|
+
const errors = [];
|
|
86
|
+
const warnings = [];
|
|
87
|
+
for (const compilationStats of serializedStats) {
|
|
88
|
+
if (compilationStats.warnings) {
|
|
89
|
+
for (const warning of compilationStats.warnings) {
|
|
90
|
+
warnings.push(warning);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (compilationStats.errors) {
|
|
94
|
+
for (const error of compilationStats.errors) {
|
|
95
|
+
errors.push(error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (compilationStats.children) {
|
|
99
|
+
for (const child of compilationStats.children) {
|
|
100
|
+
serializedStats.push(child);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
reject([...errors, ...warnings]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function _defaultWebpackConfig(entry = './src') {
|
|
108
|
+
return {
|
|
109
|
+
// We don't want to have eval source maps, nor minification
|
|
110
|
+
// so we set mode to 'none' to disable both. Default is 'production'
|
|
111
|
+
mode: 'none',
|
|
112
|
+
context: __dirname,
|
|
113
|
+
entry,
|
|
114
|
+
output: {
|
|
115
|
+
filename: 'test-bundle.js'
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=Testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Testing.js","sourceRoot":"","sources":["../src/Testing.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,iCAAwD;AACxD,gDAAwB;AACxB,sDAA8B;AAE9B,kEAAyC;AAIzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACI,KAAK,UAAU,yBAAyB,CAC7C,KAAa,EACb,mBAAkC,EAAE,EACpC,QAAa,IAAA,0BAAkB,EAAC,IAAI,cAAM,EAAE,CAAC;IAE7C,MAAM,eAAe,GAAkB,IAAA,uBAAY,EAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC,CAAC;IACpG,MAAM,QAAQ,GAAa,IAAA,iBAAO,EAAC,eAAe,CAAC,CAAC;IAEpD,QAAQ,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAClC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAI,CAAC,CAAC;IAEtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAC1B,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE;gBAClB,IAAI,GAAG,EAAE;oBACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;iBACpB;gBAED,uCAAuC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAEvD,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAxBD,8DAwBC;AAED,SAAS,uCAAuC,CAC9C,KAAqC,EACrC,MAAiC;IAEjC,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,EAAE,MAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,EAAE,CAAA,EAAE;QAC9C,MAAM,eAAe,GAA8B,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAEtF,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAiB,EAAE,CAAC;QAElC,KAAK,MAAM,gBAAgB,IAAI,eAAe,EAAE;YAC9C,IAAI,gBAAgB,CAAC,QAAQ,EAAE;gBAC7B,KAAK,MAAM,OAAO,IAAI,gBAAgB,CAAC,QAAQ,EAAE;oBAC/C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;iBACxB;aACF;YAED,IAAI,gBAAgB,CAAC,MAAM,EAAE;gBAC3B,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,MAAM,EAAE;oBAC3C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACpB;aACF;YAED,IAAI,gBAAgB,CAAC,QAAQ,EAAE;gBAC7B,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,QAAQ,EAAE;oBAC7C,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC7B;aACF;SACF;QAED,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;KAClC;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB,OAAO;IACpD,OAAO;QACL,2DAA2D;QAC3D,oEAAoE;QACpE,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,SAAS;QAClB,KAAK;QACL,MAAM,EAAE;YACN,QAAQ,EAAE,gBAAgB;SAC3B;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { createFsFromVolume, Volume, IFs } from 'memfs';\nimport path from 'path';\nimport webpack from 'webpack';\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 getTestingWebpackCompiler(\n entry: string,\n additionalConfig: Configuration = {},\n memFs: IFs = createFsFromVolume(new Volume())\n): Promise<(Stats | MultiStats) | undefined> {\n const compilerOptions: Configuration = webpackMerge(_defaultWebpackConfig(entry), additionalConfig);\n const compiler: Compiler = webpack(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
package/lib/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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.
|
|
3
|
+
"version": "0.2.0",
|
|
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"
|