@rushstack/heft-webpack5-plugin 0.6.6 → 0.7.0-rc.5
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 +2 -1
- package/dist/heft-webpack5-plugin.d.ts +85 -20
- package/dist/tsdoc-metadata.json +1 -1
- package/heft-plugin.json +20 -0
- package/lib/DeferredWatchFileSystem.d.ts +27 -0
- package/lib/DeferredWatchFileSystem.d.ts.map +1 -0
- package/lib/DeferredWatchFileSystem.js +151 -0
- package/lib/DeferredWatchFileSystem.js.map +1 -0
- package/lib/Webpack5Plugin.d.ts +37 -0
- package/lib/Webpack5Plugin.d.ts.map +1 -0
- package/lib/Webpack5Plugin.js +410 -0
- package/lib/Webpack5Plugin.js.map +1 -0
- package/lib/WebpackConfigurationLoader.d.ts +16 -4
- package/lib/WebpackConfigurationLoader.d.ts.map +1 -1
- package/lib/WebpackConfigurationLoader.js +37 -47
- package/lib/WebpackConfigurationLoader.js.map +1 -1
- package/lib/index.d.ts +2 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/schemas/heft-webpack5-plugin.schema.json +25 -0
- package/lib/shared.d.ts +77 -14
- package/lib/shared.d.ts.map +1 -1
- package/lib/shared.js.map +1 -1
- package/package.json +11 -6
- package/lib/WebpackPlugin.d.ts +0 -14
- package/lib/WebpackPlugin.d.ts.map +0 -1
- package/lib/WebpackPlugin.js +0 -266
- package/lib/WebpackPlugin.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# @rushstack/heft-webpack5-plugin
|
|
2
2
|
|
|
3
|
-
This is a Heft plugin for using Webpack 5
|
|
3
|
+
This is a Heft plugin for using Webpack 5.
|
|
4
4
|
|
|
5
5
|
## Links
|
|
6
6
|
|
|
7
7
|
- [CHANGELOG.md](
|
|
8
8
|
https://github.com/microsoft/rushstack/blob/main/heft-plugins/heft-webpack5-plugin/CHANGELOG.md) - Find
|
|
9
9
|
out what's new in the latest version
|
|
10
|
+
- [@rushstack/heft](https://www.npmjs.com/package/@rushstack/heft) - Heft is a config-driven toolchain that invokes popular tools such as TypeScript, ESLint, Jest, Webpack, and API Extractor.
|
|
10
11
|
|
|
11
12
|
Heft is part of the [Rush Stack](https://rushstack.io/) family of projects.
|
|
@@ -1,49 +1,114 @@
|
|
|
1
|
+
import type { AsyncParallelHook } from 'tapable';
|
|
2
|
+
import type { AsyncSeriesBailHook } from 'tapable';
|
|
3
|
+
import type { AsyncSeriesHook } from 'tapable';
|
|
1
4
|
import type { Configuration } from 'webpack-dev-server';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type
|
|
5
|
-
import type * as webpack from 'webpack';
|
|
5
|
+
import type { HeftConfiguration } from '@rushstack/heft';
|
|
6
|
+
import type { IHeftTaskSession } from '@rushstack/heft';
|
|
7
|
+
import type * as TWebpack from 'webpack';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @public
|
|
9
11
|
*/
|
|
10
|
-
declare
|
|
11
|
-
export default _default;
|
|
12
|
+
export declare type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[];
|
|
12
13
|
|
|
13
14
|
/**
|
|
15
|
+
* The environment passed into the Webpack configuration function. Loosely based
|
|
16
|
+
* on the default Webpack environment options, specified here:
|
|
17
|
+
* https://webpack.js.org/api/cli/#environment-options
|
|
18
|
+
*
|
|
14
19
|
* @public
|
|
15
20
|
*/
|
|
16
|
-
export declare interface
|
|
17
|
-
|
|
21
|
+
export declare interface IWebpackConfigurationFnEnvironment {
|
|
22
|
+
/**
|
|
23
|
+
* Whether or not the run is in production mode. Synonym of
|
|
24
|
+
* IWebpackConfigurationFnEnvironment.production.
|
|
25
|
+
*/
|
|
26
|
+
prod: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether or not the run is in production mode. Synonym of
|
|
29
|
+
* IWebpackConfigurationFnEnvironment.prod.
|
|
30
|
+
*/
|
|
31
|
+
production: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The task session provided to the plugin.
|
|
34
|
+
*/
|
|
35
|
+
taskSession: IHeftTaskSession;
|
|
36
|
+
/**
|
|
37
|
+
* The Heft configuration provided to the plugin.
|
|
38
|
+
*/
|
|
39
|
+
heftConfiguration: HeftConfiguration;
|
|
40
|
+
/**
|
|
41
|
+
* The resolved Webpack package.
|
|
42
|
+
*/
|
|
43
|
+
webpack: typeof TWebpack;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare interface IWebpackConfigurationWithDevServer extends TWebpack.Configuration {
|
|
50
|
+
devServer?: Configuration;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export declare interface IWebpackPluginAccessor {
|
|
57
|
+
/**
|
|
58
|
+
* Hooks that are called at various points in the Webpack plugin lifecycle.
|
|
59
|
+
*/
|
|
60
|
+
readonly hooks: IWebpackPluginAccessorHooks;
|
|
61
|
+
/**
|
|
62
|
+
* Parameters that are provided by the Webpack plugin.
|
|
63
|
+
*/
|
|
64
|
+
readonly parameters: IWebpackPluginAccessorParameters;
|
|
18
65
|
}
|
|
19
66
|
|
|
20
67
|
/**
|
|
21
68
|
* @public
|
|
22
69
|
*/
|
|
23
|
-
export declare interface
|
|
70
|
+
export declare interface IWebpackPluginAccessorHooks {
|
|
24
71
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
72
|
+
* A hook that allows for loading custom configurations used by the Webpack
|
|
73
|
+
* plugin. If a webpack configuration is provided, this will be populated automatically
|
|
74
|
+
* with the exports of the config file. If a webpack configuration is not provided,
|
|
75
|
+
* one will be loaded by the Webpack plugin.
|
|
29
76
|
*
|
|
30
77
|
* @remarks
|
|
31
|
-
* Tapable event handlers can return `
|
|
32
|
-
* other handlers from creating a configuration object.
|
|
78
|
+
* Tapable event handlers can return `false` instead of `undefined` to suppress
|
|
79
|
+
* other handlers from creating a configuration object, and prevent webpack from running.
|
|
80
|
+
*/
|
|
81
|
+
readonly onLoadConfiguration: AsyncSeriesBailHook<never, never, never, IWebpackConfiguration | false>;
|
|
82
|
+
/**
|
|
83
|
+
* A hook that allows for modification of the loaded configuration used by the Webpack
|
|
84
|
+
* plugin. If no configuration was loaded, this hook will not be called.
|
|
33
85
|
*/
|
|
34
|
-
|
|
86
|
+
readonly onConfigure: AsyncSeriesHook<IWebpackConfiguration, never, never>;
|
|
87
|
+
/**
|
|
88
|
+
* A hook that provides the finalized configuration that will be used by Webpack.
|
|
89
|
+
* If no configuration was loaded, this hook will not be called.
|
|
90
|
+
*/
|
|
91
|
+
readonly onAfterConfigure: AsyncParallelHook<IWebpackConfiguration, never, never>;
|
|
92
|
+
/**
|
|
93
|
+
* A hook that provides the stats output from Webpack. If no configuration is loaded,
|
|
94
|
+
* this hook will not be called.
|
|
95
|
+
*/
|
|
96
|
+
readonly onEmitStats: AsyncParallelHook<TWebpack.Stats | TWebpack.MultiStats, never, never>;
|
|
35
97
|
}
|
|
36
98
|
|
|
37
99
|
/**
|
|
38
100
|
* @public
|
|
39
101
|
*/
|
|
40
|
-
export declare
|
|
102
|
+
export declare interface IWebpackPluginAccessorParameters {
|
|
103
|
+
/**
|
|
104
|
+
* Whether or not serve mode was enabled by passing the `--serve` flag.
|
|
105
|
+
*/
|
|
106
|
+
readonly isServeMode: boolean;
|
|
107
|
+
}
|
|
41
108
|
|
|
42
109
|
/**
|
|
43
110
|
* @public
|
|
44
111
|
*/
|
|
45
|
-
export declare
|
|
46
|
-
devServer?: Configuration;
|
|
47
|
-
}
|
|
112
|
+
export declare const PluginName: 'webpack5-plugin';
|
|
48
113
|
|
|
49
114
|
export { }
|
package/dist/tsdoc-metadata.json
CHANGED
package/heft-plugin.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/heft/heft-plugin.schema.json",
|
|
3
|
+
|
|
4
|
+
"taskPlugins": [
|
|
5
|
+
{
|
|
6
|
+
"pluginName": "webpack5-plugin",
|
|
7
|
+
"entryPoint": "./lib/Webpack5Plugin",
|
|
8
|
+
"optionsSchema": "./lib/schemas/heft-webpack5-plugin.schema.json",
|
|
9
|
+
|
|
10
|
+
"parameterScope": "webpack5",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"longName": "--serve",
|
|
14
|
+
"parameterKind": "flag",
|
|
15
|
+
"description": "Start a local web server for testing purposes using webpack-dev-server. This parameter is only available when running in watch mode."
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Watchpack, { type WatchOptions } from 'watchpack';
|
|
2
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
3
|
+
export declare type InputFileSystem = Compiler['inputFileSystem'];
|
|
4
|
+
export declare type WatchFileSystem = Compiler['watchFileSystem'];
|
|
5
|
+
export declare type WatchCallback = Parameters<WatchFileSystem['watch']>[5];
|
|
6
|
+
export declare type WatchUndelayedCallback = Parameters<WatchFileSystem['watch']>[6];
|
|
7
|
+
export declare type Watcher = ReturnType<WatchFileSystem['watch']>;
|
|
8
|
+
export declare type WatcherInfo = ReturnType<Required<Watcher>['getInfo']>;
|
|
9
|
+
export declare class DeferredWatchFileSystem implements WatchFileSystem {
|
|
10
|
+
readonly inputFileSystem: InputFileSystem;
|
|
11
|
+
readonly watcherOptions: WatchOptions;
|
|
12
|
+
watcher: Watchpack | undefined;
|
|
13
|
+
private readonly _onChange;
|
|
14
|
+
private _state;
|
|
15
|
+
constructor(inputFileSystem: InputFileSystem, onChange: () => void);
|
|
16
|
+
flush(): boolean;
|
|
17
|
+
watch(files: Iterable<string>, directories: Iterable<string>, missing: Iterable<string>, startTime: number, options: WatchOptions, callback: WatchCallback, callbackUndelayed: WatchUndelayedCallback): Watcher;
|
|
18
|
+
private _fetchTimeInfo;
|
|
19
|
+
private _purge;
|
|
20
|
+
}
|
|
21
|
+
export declare class OverrideNodeWatchFSPlugin implements WebpackPluginInstance {
|
|
22
|
+
readonly fileSystems: Set<DeferredWatchFileSystem>;
|
|
23
|
+
private readonly _onChange;
|
|
24
|
+
constructor(onChange: () => void);
|
|
25
|
+
apply(compiler: Compiler): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=DeferredWatchFileSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeferredWatchFileSystem.d.ts","sourceRoot":"","sources":["../src/DeferredWatchFileSystem.ts"],"names":[],"mappings":"AAGA,OAAO,SAAS,EAAE,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE/D,oBAAY,eAAe,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAC1D,oBAAY,eAAe,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAC1D,oBAAY,aAAa,GAAG,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,oBAAY,sBAAsB,GAAG,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,oBAAY,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3D,oBAAY,WAAW,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AAsBnE,qBAAa,uBAAwB,YAAW,eAAe;IAC7D,SAAgB,eAAe,EAAE,eAAe,CAAC;IACjD,SAAgB,cAAc,EAAE,YAAY,CAAC;IACtC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAEtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,MAAM,CAA0B;gBAErB,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,IAAI;IASlE,KAAK,IAAI,OAAO;IA0ChB,KAAK,CACV,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,EACzB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,aAAa,EACvB,iBAAiB,EAAE,sBAAsB,GACxC,OAAO;IAyEV,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,MAAM;CAef;AAED,qBAAa,yBAA0B,YAAW,qBAAqB;IACrE,SAAgB,WAAW,EAAE,GAAG,CAAC,uBAAuB,CAAC,CAAa;IACtE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;gBAEpB,QAAQ,EAAE,MAAM,IAAI;IAIhC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAQvC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
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.OverrideNodeWatchFSPlugin = exports.DeferredWatchFileSystem = void 0;
|
|
9
|
+
const watchpack_1 = __importDefault(require("watchpack"));
|
|
10
|
+
class DeferredWatchFileSystem {
|
|
11
|
+
constructor(inputFileSystem, onChange) {
|
|
12
|
+
this.inputFileSystem = inputFileSystem;
|
|
13
|
+
this.watcherOptions = {
|
|
14
|
+
aggregateTimeout: 0
|
|
15
|
+
};
|
|
16
|
+
this.watcher = new watchpack_1.default(this.watcherOptions);
|
|
17
|
+
this._onChange = onChange;
|
|
18
|
+
}
|
|
19
|
+
flush() {
|
|
20
|
+
const state = this._state;
|
|
21
|
+
if (!state) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const { changes, removals, callback } = state;
|
|
25
|
+
// Force flush the aggregation callback
|
|
26
|
+
const { changes: newChanges, removals: newRemovals } = this.watcher.getAggregated();
|
|
27
|
+
// Webpack 5 treats changes and removals as separate things
|
|
28
|
+
if (newRemovals) {
|
|
29
|
+
for (const removal of newRemovals) {
|
|
30
|
+
changes.delete(removal);
|
|
31
|
+
removals.add(removal);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (newChanges) {
|
|
35
|
+
for (const change of newChanges) {
|
|
36
|
+
removals.delete(change);
|
|
37
|
+
changes.add(change);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (changes.size > 0 || removals.size > 0) {
|
|
41
|
+
this._purge(removals, changes);
|
|
42
|
+
const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();
|
|
43
|
+
callback(undefined, fileTimeInfoEntries, contextTimeInfoEntries, changes, removals);
|
|
44
|
+
changes.clear();
|
|
45
|
+
removals.clear();
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
watch(files, directories, missing, startTime, options, callback, callbackUndelayed) {
|
|
51
|
+
const oldWatcher = this.watcher;
|
|
52
|
+
this.watcher = new watchpack_1.default(options);
|
|
53
|
+
const changes = new Set();
|
|
54
|
+
const removals = new Set();
|
|
55
|
+
this._state = {
|
|
56
|
+
changes,
|
|
57
|
+
removals,
|
|
58
|
+
callback
|
|
59
|
+
};
|
|
60
|
+
this.watcher.on('aggregated', (newChanges, newRemovals) => {
|
|
61
|
+
for (const change of newChanges) {
|
|
62
|
+
removals.delete(change);
|
|
63
|
+
changes.add(change);
|
|
64
|
+
}
|
|
65
|
+
for (const removal of newRemovals) {
|
|
66
|
+
changes.delete(removal);
|
|
67
|
+
removals.add(removal);
|
|
68
|
+
}
|
|
69
|
+
this._onChange();
|
|
70
|
+
});
|
|
71
|
+
this.watcher.watch({
|
|
72
|
+
files,
|
|
73
|
+
directories,
|
|
74
|
+
missing,
|
|
75
|
+
startTime
|
|
76
|
+
});
|
|
77
|
+
if (oldWatcher) {
|
|
78
|
+
oldWatcher.close();
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
close: () => {
|
|
82
|
+
if (this.watcher) {
|
|
83
|
+
this.watcher.close();
|
|
84
|
+
this.watcher = undefined;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
pause: () => {
|
|
88
|
+
if (this.watcher) {
|
|
89
|
+
this.watcher.pause();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
getInfo: () => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const newRemovals = (_a = this.watcher) === null || _a === void 0 ? void 0 : _a.aggregatedRemovals;
|
|
95
|
+
const newChanges = (_b = this.watcher) === null || _b === void 0 ? void 0 : _b.aggregatedChanges;
|
|
96
|
+
this._purge(newRemovals, newChanges);
|
|
97
|
+
const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();
|
|
98
|
+
return {
|
|
99
|
+
changes: newChanges,
|
|
100
|
+
removals: newRemovals,
|
|
101
|
+
fileTimeInfoEntries,
|
|
102
|
+
contextTimeInfoEntries
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
getContextTimeInfoEntries: () => {
|
|
106
|
+
const { contextTimeInfoEntries } = this._fetchTimeInfo();
|
|
107
|
+
return contextTimeInfoEntries;
|
|
108
|
+
},
|
|
109
|
+
getFileTimeInfoEntries: () => {
|
|
110
|
+
const { fileTimeInfoEntries } = this._fetchTimeInfo();
|
|
111
|
+
return fileTimeInfoEntries;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
_fetchTimeInfo() {
|
|
116
|
+
var _a;
|
|
117
|
+
const fileTimeInfoEntries = new Map();
|
|
118
|
+
const contextTimeInfoEntries = new Map();
|
|
119
|
+
(_a = this.watcher) === null || _a === void 0 ? void 0 : _a.collectTimeInfoEntries(fileTimeInfoEntries, contextTimeInfoEntries);
|
|
120
|
+
return { fileTimeInfoEntries, contextTimeInfoEntries };
|
|
121
|
+
}
|
|
122
|
+
_purge(removals, changes) {
|
|
123
|
+
const fs = this.inputFileSystem;
|
|
124
|
+
if (fs.purge) {
|
|
125
|
+
if (removals) {
|
|
126
|
+
for (const removal of removals) {
|
|
127
|
+
fs.purge(removal);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (changes) {
|
|
131
|
+
for (const change of changes) {
|
|
132
|
+
fs.purge(change);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.DeferredWatchFileSystem = DeferredWatchFileSystem;
|
|
139
|
+
class OverrideNodeWatchFSPlugin {
|
|
140
|
+
constructor(onChange) {
|
|
141
|
+
this.fileSystems = new Set();
|
|
142
|
+
this._onChange = onChange;
|
|
143
|
+
}
|
|
144
|
+
apply(compiler) {
|
|
145
|
+
const watchFileSystem = new DeferredWatchFileSystem(compiler.inputFileSystem, this._onChange);
|
|
146
|
+
this.fileSystems.add(watchFileSystem);
|
|
147
|
+
compiler.watchFileSystem = watchFileSystem;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.OverrideNodeWatchFSPlugin = OverrideNodeWatchFSPlugin;
|
|
151
|
+
//# sourceMappingURL=DeferredWatchFileSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeferredWatchFileSystem.js","sourceRoot":"","sources":["../src/DeferredWatchFileSystem.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DA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O,0CAAE,sBAAsB,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,CAAC;QAClF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;IACzD,CAAC;IAEO,MAAM,CAAC,QAAiC,EAAE,OAAgC;QAChF,MAAM,EAAE,GAAoB,IAAI,CAAC,eAAe,CAAC;QACjD,IAAI,EAAE,CAAC,KAAK,EAAE;YACZ,IAAI,QAAQ,EAAE;gBACZ,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;oBAC9B,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;iBACnB;aACF;YACD,IAAI,OAAO,EAAE;gBACX,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;oBAC5B,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;iBAClB;aACF;SACF;IACH,CAAC;CACF;AAlKD,0DAkKC;AAED,MAAa,yBAAyB;IAIpC,YAAmB,QAAoB;QAHvB,gBAAW,GAAiC,IAAI,GAAG,EAAE,CAAC;QAIpE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,QAAkB;QAC7B,MAAM,eAAe,GAA4B,IAAI,uBAAuB,CAC1E,QAAQ,CAAC,eAAe,EACxB,IAAI,CAAC,SAAS,CACf,CAAC;QACF,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACtC,QAAQ,CAAC,eAAe,GAAG,eAAe,CAAC;IAC7C,CAAC;CACF;AAhBD,8DAgBC","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 Watchpack, { type WatchOptions } from 'watchpack';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\n\nexport type InputFileSystem = Compiler['inputFileSystem'];\nexport type WatchFileSystem = Compiler['watchFileSystem'];\nexport type WatchCallback = Parameters<WatchFileSystem['watch']>[5];\nexport type WatchUndelayedCallback = Parameters<WatchFileSystem['watch']>[6];\nexport type Watcher = ReturnType<WatchFileSystem['watch']>;\nexport type WatcherInfo = ReturnType<Required<Watcher>['getInfo']>;\ntype FileSystemMap = ReturnType<Watcher['getFileTimeInfoEntries']>;\n\ninterface IWatchState {\n changes: Set<string>;\n removals: Set<string>;\n\n callback: WatchCallback;\n}\n\ninterface ITimeEntry {\n timestamp: number;\n safeTime: number;\n}\n\ntype IRawFileSystemMap = Map<string, ITimeEntry>;\n\ninterface ITimeInfoEntries {\n fileTimeInfoEntries: FileSystemMap;\n contextTimeInfoEntries: FileSystemMap;\n}\n\nexport class DeferredWatchFileSystem implements WatchFileSystem {\n public readonly inputFileSystem: InputFileSystem;\n public readonly watcherOptions: WatchOptions;\n public watcher: Watchpack | undefined;\n\n private readonly _onChange: () => void;\n private _state: IWatchState | undefined;\n\n public constructor(inputFileSystem: InputFileSystem, onChange: () => void) {\n this.inputFileSystem = inputFileSystem;\n this.watcherOptions = {\n aggregateTimeout: 0\n };\n this.watcher = new Watchpack(this.watcherOptions);\n this._onChange = onChange;\n }\n\n public flush(): boolean {\n const state: IWatchState | undefined = this._state;\n\n if (!state) {\n return false;\n }\n\n const { changes, removals, callback } = state;\n\n // Force flush the aggregation callback\n const { changes: newChanges, removals: newRemovals } = this.watcher!.getAggregated();\n\n // Webpack 5 treats changes and removals as separate things\n if (newRemovals) {\n for (const removal of newRemovals) {\n changes.delete(removal);\n removals.add(removal);\n }\n }\n if (newChanges) {\n for (const change of newChanges) {\n removals.delete(change);\n changes.add(change);\n }\n }\n\n if (changes.size > 0 || removals.size > 0) {\n this._purge(removals, changes);\n\n const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();\n\n callback(undefined, fileTimeInfoEntries, contextTimeInfoEntries, changes, removals);\n\n changes.clear();\n removals.clear();\n\n return true;\n }\n\n return false;\n }\n\n public watch(\n files: Iterable<string>,\n directories: Iterable<string>,\n missing: Iterable<string>,\n startTime: number,\n options: WatchOptions,\n callback: WatchCallback,\n callbackUndelayed: WatchUndelayedCallback\n ): Watcher {\n const oldWatcher: Watchpack | undefined = this.watcher;\n this.watcher = new Watchpack(options);\n\n const changes: Set<string> = new Set();\n const removals: Set<string> = new Set();\n\n this._state = {\n changes,\n removals,\n\n callback\n };\n\n this.watcher.on('aggregated', (newChanges: Set<string>, newRemovals: Set<string>) => {\n for (const change of newChanges) {\n removals.delete(change);\n changes.add(change);\n }\n for (const removal of newRemovals) {\n changes.delete(removal);\n removals.add(removal);\n }\n\n this._onChange();\n });\n\n this.watcher.watch({\n files,\n directories,\n missing,\n startTime\n });\n\n if (oldWatcher) {\n oldWatcher.close();\n }\n\n return {\n close: () => {\n if (this.watcher) {\n this.watcher.close();\n this.watcher = undefined;\n }\n },\n pause: () => {\n if (this.watcher) {\n this.watcher.pause();\n }\n },\n getInfo: () => {\n const newRemovals: Set<string> | undefined = this.watcher?.aggregatedRemovals;\n const newChanges: Set<string> | undefined = this.watcher?.aggregatedChanges;\n this._purge(newRemovals, newChanges);\n const { fileTimeInfoEntries, contextTimeInfoEntries } = this._fetchTimeInfo();\n return {\n changes: newChanges!,\n removals: newRemovals!,\n fileTimeInfoEntries,\n contextTimeInfoEntries\n };\n },\n getContextTimeInfoEntries: () => {\n const { contextTimeInfoEntries } = this._fetchTimeInfo();\n return contextTimeInfoEntries;\n },\n getFileTimeInfoEntries: () => {\n const { fileTimeInfoEntries } = this._fetchTimeInfo();\n return fileTimeInfoEntries;\n }\n };\n }\n\n private _fetchTimeInfo(): ITimeInfoEntries {\n const fileTimeInfoEntries: IRawFileSystemMap = new Map();\n const contextTimeInfoEntries: IRawFileSystemMap = new Map();\n this.watcher?.collectTimeInfoEntries(fileTimeInfoEntries, contextTimeInfoEntries);\n return { fileTimeInfoEntries, contextTimeInfoEntries };\n }\n\n private _purge(removals: Set<string> | undefined, changes: Set<string> | undefined): void {\n const fs: InputFileSystem = this.inputFileSystem;\n if (fs.purge) {\n if (removals) {\n for (const removal of removals) {\n fs.purge(removal);\n }\n }\n if (changes) {\n for (const change of changes) {\n fs.purge(change);\n }\n }\n }\n }\n}\n\nexport class OverrideNodeWatchFSPlugin implements WebpackPluginInstance {\n public readonly fileSystems: Set<DeferredWatchFileSystem> = new Set();\n private readonly _onChange: () => void;\n\n public constructor(onChange: () => void) {\n this._onChange = onChange;\n }\n\n public apply(compiler: Compiler): void {\n const watchFileSystem: DeferredWatchFileSystem = new DeferredWatchFileSystem(\n compiler.inputFileSystem,\n this._onChange\n );\n this.fileSystems.add(watchFileSystem);\n compiler.watchFileSystem = watchFileSystem;\n }\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { HeftConfiguration, IHeftTaskSession, IHeftTaskPlugin } from '@rushstack/heft';
|
|
2
|
+
import type { IWebpackPluginAccessor } from './shared';
|
|
3
|
+
export interface IWebpackPluginOptions {
|
|
4
|
+
devConfigurationPath: string | undefined;
|
|
5
|
+
configurationPath: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare const PLUGIN_NAME: 'webpack5-plugin';
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export default class Webpack5Plugin implements IHeftTaskPlugin<IWebpackPluginOptions> {
|
|
15
|
+
private _accessor;
|
|
16
|
+
private _isServeMode;
|
|
17
|
+
private _webpack;
|
|
18
|
+
private _webpackCompiler;
|
|
19
|
+
private _webpackConfiguration;
|
|
20
|
+
private _webpackCompilationDonePromise;
|
|
21
|
+
private _webpackCompilationDonePromiseResolveFn;
|
|
22
|
+
private _watchFileSystems;
|
|
23
|
+
private _warnings;
|
|
24
|
+
private _errors;
|
|
25
|
+
get accessor(): IWebpackPluginAccessor;
|
|
26
|
+
apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration, options: IWebpackPluginOptions): void;
|
|
27
|
+
private _getWebpackConfigurationAsync;
|
|
28
|
+
private _loadWebpackAsync;
|
|
29
|
+
private _getWebpackCompilerAsync;
|
|
30
|
+
private _runWebpackAsync;
|
|
31
|
+
private _runWebpackWatchAsync;
|
|
32
|
+
private _validateEnvironmentVariable;
|
|
33
|
+
private _emitErrors;
|
|
34
|
+
private _recordErrors;
|
|
35
|
+
private _normalizeError;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=Webpack5Plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Webpack5Plugin.d.ts","sourceRoot":"","sources":["../src/Webpack5Plugin.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAyB,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAI9E,MAAM,WAAW,qBAAqB;IACpC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,iBAAqC,CAAC;AAQhE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,eAAe,CAAC,qBAAqB,CAAC;IACnF,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,gBAAgB,CAAyD;IACjF,OAAO,CAAC,qBAAqB,CAA2E;IACxG,OAAO,CAAC,8BAA8B,CAA4B;IAClE,OAAO,CAAC,uCAAuC,CAA2B;IAC1E,OAAO,CAAC,iBAAiB,CAA2C;IAEpE,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,OAAO,CAAe;IAE9B,IAAW,QAAQ,IAAI,sBAAsB,CAe5C;IAEM,KAAK,CACV,WAAW,EAAE,gBAAgB,EAC7B,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,EAAE,qBAAqB,GAC7B,IAAI;YAsB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