@rushstack/webpack4-module-minifier-plugin 0.14.14 → 0.15.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/CHANGELOG.json +46 -0
- package/CHANGELOG.md +15 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib-esm/AsyncImportCompressionPlugin.js +206 -0
- package/lib-esm/AsyncImportCompressionPlugin.js.map +1 -0
- package/lib-esm/Constants.js +30 -0
- package/lib-esm/Constants.js.map +1 -0
- package/lib-esm/GenerateLicenseFileForAsset.js +52 -0
- package/lib-esm/GenerateLicenseFileForAsset.js.map +1 -0
- package/lib-esm/ModuleMinifierPlugin.js +432 -0
- package/lib-esm/ModuleMinifierPlugin.js.map +1 -0
- package/lib-esm/ModuleMinifierPlugin.types.js +4 -0
- package/lib-esm/ModuleMinifierPlugin.types.js.map +1 -0
- package/lib-esm/OverrideWebpackIdentifierAllocation.js +7 -0
- package/lib-esm/OverrideWebpackIdentifierAllocation.js.map +1 -0
- package/lib-esm/ParallelCompiler.js +90 -0
- package/lib-esm/ParallelCompiler.js.map +1 -0
- package/lib-esm/PortableMinifierIdsPlugin.js +123 -0
- package/lib-esm/PortableMinifierIdsPlugin.js.map +1 -0
- package/lib-esm/RehydrateAsset.js +169 -0
- package/lib-esm/RehydrateAsset.js.map +1 -0
- package/lib-esm/index.js +9 -0
- package/lib-esm/index.js.map +1 -0
- package/lib-esm/workerPool/WebpackWorker.js +78 -0
- package/lib-esm/workerPool/WebpackWorker.js.map +1 -0
- package/package.json +32 -8
- /package/{lib → lib-commonjs}/AsyncImportCompressionPlugin.js +0 -0
- /package/{lib → lib-commonjs}/AsyncImportCompressionPlugin.js.map +0 -0
- /package/{lib → lib-commonjs}/Constants.js +0 -0
- /package/{lib → lib-commonjs}/Constants.js.map +0 -0
- /package/{lib → lib-commonjs}/GenerateLicenseFileForAsset.js +0 -0
- /package/{lib → lib-commonjs}/GenerateLicenseFileForAsset.js.map +0 -0
- /package/{lib → lib-commonjs}/ModuleMinifierPlugin.js +0 -0
- /package/{lib → lib-commonjs}/ModuleMinifierPlugin.js.map +0 -0
- /package/{lib → lib-commonjs}/ModuleMinifierPlugin.types.js +0 -0
- /package/{lib → lib-commonjs}/ModuleMinifierPlugin.types.js.map +0 -0
- /package/{lib → lib-commonjs}/OverrideWebpackIdentifierAllocation.js +0 -0
- /package/{lib → lib-commonjs}/OverrideWebpackIdentifierAllocation.js.map +0 -0
- /package/{lib → lib-commonjs}/ParallelCompiler.js +0 -0
- /package/{lib → lib-commonjs}/ParallelCompiler.js.map +0 -0
- /package/{lib → lib-commonjs}/PortableMinifierIdsPlugin.js +0 -0
- /package/{lib → lib-commonjs}/PortableMinifierIdsPlugin.js.map +0 -0
- /package/{lib → lib-commonjs}/RehydrateAsset.js +0 -0
- /package/{lib → lib-commonjs}/RehydrateAsset.js.map +0 -0
- /package/{lib → lib-commonjs}/index.js +0 -0
- /package/{lib → lib-commonjs}/index.js.map +0 -0
- /package/{lib → lib-commonjs}/workerPool/WebpackWorker.js +0 -0
- /package/{lib → lib-commonjs}/workerPool/WebpackWorker.js.map +0 -0
- /package/{lib → lib-dts}/AsyncImportCompressionPlugin.d.ts +0 -0
- /package/{lib → lib-dts}/AsyncImportCompressionPlugin.d.ts.map +0 -0
- /package/{lib → lib-dts}/Constants.d.ts +0 -0
- /package/{lib → lib-dts}/Constants.d.ts.map +0 -0
- /package/{lib → lib-dts}/GenerateLicenseFileForAsset.d.ts +0 -0
- /package/{lib → lib-dts}/GenerateLicenseFileForAsset.d.ts.map +0 -0
- /package/{lib → lib-dts}/ModuleMinifierPlugin.d.ts +0 -0
- /package/{lib → lib-dts}/ModuleMinifierPlugin.d.ts.map +0 -0
- /package/{lib → lib-dts}/ModuleMinifierPlugin.types.d.ts +0 -0
- /package/{lib → lib-dts}/ModuleMinifierPlugin.types.d.ts.map +0 -0
- /package/{lib → lib-dts}/OverrideWebpackIdentifierAllocation.d.ts +0 -0
- /package/{lib → lib-dts}/OverrideWebpackIdentifierAllocation.d.ts.map +0 -0
- /package/{lib → lib-dts}/ParallelCompiler.d.ts +0 -0
- /package/{lib → lib-dts}/ParallelCompiler.d.ts.map +0 -0
- /package/{lib → lib-dts}/PortableMinifierIdsPlugin.d.ts +0 -0
- /package/{lib → lib-dts}/PortableMinifierIdsPlugin.d.ts.map +0 -0
- /package/{lib → lib-dts}/RehydrateAsset.d.ts +0 -0
- /package/{lib → lib-dts}/RehydrateAsset.d.ts.map +0 -0
- /package/{lib → lib-dts}/index.d.ts +0 -0
- /package/{lib → lib-dts}/index.d.ts.map +0 -0
- /package/{lib → lib-dts}/workerPool/WebpackWorker.d.ts +0 -0
- /package/{lib → lib-dts}/workerPool/WebpackWorker.d.ts.map +0 -0
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/webpack4-module-minifier-plugin",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.15.1",
|
|
6
|
+
"tag": "@rushstack/webpack4-module-minifier-plugin_v0.15.1",
|
|
7
|
+
"date": "Fri, 20 Feb 2026 00:15:04 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Add `\"node\"` condition before `\"import\"` in the `\"exports\"` map so that Node.js uses the CJS output (which handles extensionless imports), while bundlers still use ESM via `\"import\"`. Fixes https://github.com/microsoft/rushstack/issues/5644."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@rushstack/module-minifier\" to `0.9.1`"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"comment": "Updating dependency \"@rushstack/worker-pool\" to `0.7.1`"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `1.2.1`"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"version": "0.15.0",
|
|
29
|
+
"tag": "@rushstack/webpack4-module-minifier-plugin_v0.15.0",
|
|
30
|
+
"date": "Thu, 19 Feb 2026 00:04:53 GMT",
|
|
31
|
+
"comments": {
|
|
32
|
+
"minor": [
|
|
33
|
+
{
|
|
34
|
+
"comment": "Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `\"exports\"` field in `package.json`."
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"dependency": [
|
|
38
|
+
{
|
|
39
|
+
"comment": "Updating dependency \"@rushstack/module-minifier\" to `0.9.0`"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"comment": "Updating dependency \"@rushstack/worker-pool\" to `0.7.0`"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `1.2.0`"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
},
|
|
4
50
|
{
|
|
5
51
|
"version": "0.14.14",
|
|
6
52
|
"tag": "@rushstack/webpack4-module-minifier-plugin_v0.14.14",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Change Log - @rushstack/webpack4-module-minifier-plugin
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 20 Feb 2026 00:15:04 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.15.1
|
|
6
|
+
Fri, 20 Feb 2026 00:15:04 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Add `"node"` condition before `"import"` in the `"exports"` map so that Node.js uses the CJS output (which handles extensionless imports), while bundlers still use ESM via `"import"`. Fixes https://github.com/microsoft/rushstack/issues/5644.
|
|
11
|
+
|
|
12
|
+
## 0.15.0
|
|
13
|
+
Thu, 19 Feb 2026 00:04:53 GMT
|
|
14
|
+
|
|
15
|
+
### Minor changes
|
|
16
|
+
|
|
17
|
+
- Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `"exports"` field in `package.json`.
|
|
4
18
|
|
|
5
19
|
## 0.14.14
|
|
6
20
|
Sat, 07 Feb 2026 01:13:26 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import webpack from 'webpack';
|
|
4
|
+
const { Template } = webpack;
|
|
5
|
+
import { STAGE_AFTER } from './Constants';
|
|
6
|
+
const PLUGIN_NAME = 'AsyncImportCompressionPlugin';
|
|
7
|
+
const TAP_AFTER = {
|
|
8
|
+
name: PLUGIN_NAME,
|
|
9
|
+
stage: STAGE_AFTER
|
|
10
|
+
};
|
|
11
|
+
const ASYNC_IMPORT_PREFIX = '__IMPORT_ASYNC';
|
|
12
|
+
const ASYNC_IMPORT_REGEX = /__IMPORT_ASYNC[^\)]+/g;
|
|
13
|
+
function getImportDependency(compilation) {
|
|
14
|
+
for (const key of compilation.dependencyTemplates.keys()) {
|
|
15
|
+
if (key.name === 'ImportDependency') {
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Could not find ImportDependency!`);
|
|
20
|
+
}
|
|
21
|
+
function getImportTypeExpression(module, originModule) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const exportsType = (_a = module.buildMeta) === null || _a === void 0 ? void 0 : _a.exportsType;
|
|
24
|
+
const strict = (_b = originModule.buildMeta) === null || _b === void 0 ? void 0 : _b.strictHarmonyModule;
|
|
25
|
+
// Logic translated from:
|
|
26
|
+
// https://github.com/webpack/webpack/blob/3956274f1eada621e105208dcab4608883cdfdb2/lib/RuntimeTemplate.js#L110-L122
|
|
27
|
+
if (exportsType === 'namespace') {
|
|
28
|
+
// Use the raw module directly
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
else if (exportsType === 'named') {
|
|
32
|
+
// Create a new namespace object and forward all exports
|
|
33
|
+
return ',3';
|
|
34
|
+
}
|
|
35
|
+
else if (strict) {
|
|
36
|
+
// Synthetic default export
|
|
37
|
+
return ',1';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// If modules is marked __esModule, return raw module, otherwise create a new namespace object and forward all exports
|
|
41
|
+
return ',7';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function needChunkOnDemandLoadingCode(chunk) {
|
|
45
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
|
46
|
+
if (chunkGroup.getNumberOfChildren() > 0) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Plugin that replaces `Promise.all([__webpack_require__.e(1), __webpack_require__.e(12)]).then(__webpack_require__.t.bind(123,7))`
|
|
54
|
+
* with more concise expressions like `__webpack_require__.ee([1,12],123,7)`, etc.
|
|
55
|
+
*
|
|
56
|
+
* Also ensures that the code seen by the minifier does not contain chunk ids, and is therefore portable across chunks/compilations.
|
|
57
|
+
*/
|
|
58
|
+
export class AsyncImportCompressionPlugin {
|
|
59
|
+
constructor(minifierHooks) {
|
|
60
|
+
this._minifierHooks = minifierHooks;
|
|
61
|
+
}
|
|
62
|
+
apply(compiler) {
|
|
63
|
+
const asyncImportMap = new Map();
|
|
64
|
+
const asyncImportGroups = new Map();
|
|
65
|
+
let rankedImportGroups;
|
|
66
|
+
this._minifierHooks.postProcessCodeFragment.tap({
|
|
67
|
+
name: PLUGIN_NAME,
|
|
68
|
+
stage: -1
|
|
69
|
+
}, (source, context) => {
|
|
70
|
+
const code = source.original().source();
|
|
71
|
+
let localImports;
|
|
72
|
+
ASYNC_IMPORT_REGEX.lastIndex = -1;
|
|
73
|
+
// RegExp.exec uses null or an array as the return type, explicitly
|
|
74
|
+
let match = null;
|
|
75
|
+
while ((match = ASYNC_IMPORT_REGEX.exec(code))) {
|
|
76
|
+
const token = match[0];
|
|
77
|
+
if (!localImports) {
|
|
78
|
+
if (!context.module) {
|
|
79
|
+
context.compilation.errors.push(new Error(`Unexpected async import ${token} in non-module context ${context.loggingName}`));
|
|
80
|
+
return source;
|
|
81
|
+
}
|
|
82
|
+
localImports = asyncImportMap.get(context.module);
|
|
83
|
+
if (!localImports) {
|
|
84
|
+
context.compilation.errors.push(new Error(`Unexpected async import ${token} in module ${context.loggingName}`));
|
|
85
|
+
return source;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const localImport = localImports.get(token);
|
|
89
|
+
if (!localImport) {
|
|
90
|
+
context.compilation.errors.push(new Error(`Missing metadata for ${token} in module ${context.loggingName}`));
|
|
91
|
+
return source;
|
|
92
|
+
}
|
|
93
|
+
const { meta, module } = localImport;
|
|
94
|
+
const chunkExpression = meta.index < 0 ? JSON.stringify(meta.chunkIds) : `${meta.index}`;
|
|
95
|
+
const mapped = this._minifierHooks.finalModuleId.call(module.id, context.compilation);
|
|
96
|
+
const idExpr = mapped === undefined ? module.id : mapped;
|
|
97
|
+
// Replace with a reference or array of ideas, the target module id, and the type of import
|
|
98
|
+
source.replace(match.index, ASYNC_IMPORT_REGEX.lastIndex - 1, `${chunkExpression},${JSON.stringify(idExpr)}${getImportTypeExpression(module, context.module)}`);
|
|
99
|
+
}
|
|
100
|
+
return source;
|
|
101
|
+
});
|
|
102
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
103
|
+
asyncImportMap.clear();
|
|
104
|
+
asyncImportGroups.clear();
|
|
105
|
+
compilation.hooks.beforeChunkAssets.tap(TAP_AFTER, () => {
|
|
106
|
+
const ImportDependency = getImportDependency(compilation);
|
|
107
|
+
for (const module of compilation.modules) {
|
|
108
|
+
const toProcess = module.modules || [module];
|
|
109
|
+
for (const child of toProcess) {
|
|
110
|
+
child.hasDependencies((dep) => {
|
|
111
|
+
if (dep instanceof ImportDependency) {
|
|
112
|
+
const { module: targetModule } = dep;
|
|
113
|
+
if (targetModule) {
|
|
114
|
+
let localAsyncImports = asyncImportMap.get(module);
|
|
115
|
+
if (!localAsyncImports) {
|
|
116
|
+
asyncImportMap.set(module, (localAsyncImports = new Map()));
|
|
117
|
+
}
|
|
118
|
+
const chunkGroup = dep.block.chunkGroup;
|
|
119
|
+
const chunkIds = chunkGroup
|
|
120
|
+
? chunkGroup.chunks.map((chunk) => chunk.id).sort()
|
|
121
|
+
: [];
|
|
122
|
+
const idString = chunkIds.join(';');
|
|
123
|
+
let meta = asyncImportGroups.get(idString);
|
|
124
|
+
if (!meta) {
|
|
125
|
+
asyncImportGroups.set(idString, (meta = {
|
|
126
|
+
chunkCount: chunkIds.length,
|
|
127
|
+
chunkIds: chunkIds,
|
|
128
|
+
count: 0,
|
|
129
|
+
index: -1
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
meta.count++;
|
|
133
|
+
const stringKey = `${targetModule.id}`.replace(/[^A-Za-z0-9_$]/g, '_');
|
|
134
|
+
const key = `${ASYNC_IMPORT_PREFIX}${stringKey}`;
|
|
135
|
+
localAsyncImports.set(key, {
|
|
136
|
+
meta,
|
|
137
|
+
module: targetModule
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const rankedImports = [...asyncImportGroups]
|
|
145
|
+
.filter((x) => x[1].count > 1)
|
|
146
|
+
.sort((x, y) => {
|
|
147
|
+
let diff = y[1].count - x[1].count;
|
|
148
|
+
if (!diff) {
|
|
149
|
+
diff = y[1].chunkCount - x[1].chunkCount;
|
|
150
|
+
}
|
|
151
|
+
if (!diff) {
|
|
152
|
+
diff = x[0] > y[0] ? 1 : x[0] < y[0] ? -1 : 0;
|
|
153
|
+
}
|
|
154
|
+
return diff;
|
|
155
|
+
});
|
|
156
|
+
for (let i = 0, len = rankedImports.length; i < len; i++) {
|
|
157
|
+
rankedImports[i][1].index = i;
|
|
158
|
+
// console.log(rankedImports[i]);
|
|
159
|
+
}
|
|
160
|
+
rankedImportGroups = rankedImports.map((x) => x[1]);
|
|
161
|
+
const { dependencyTemplates } = compilation;
|
|
162
|
+
const defaultImplementation = dependencyTemplates.get(ImportDependency);
|
|
163
|
+
if (!defaultImplementation) {
|
|
164
|
+
compilation.errors.push(new Error(`Could not find ImportDependencyTemplate`));
|
|
165
|
+
}
|
|
166
|
+
const customTemplate = {
|
|
167
|
+
apply(dep, source, runtime) {
|
|
168
|
+
if (dep.module) {
|
|
169
|
+
const stringKey = `${dep.module.id}`.replace(/[^A-Za-z0-9_$]/g, '_');
|
|
170
|
+
const key = `${ASYNC_IMPORT_PREFIX}${stringKey}`;
|
|
171
|
+
const content = `__webpack_require__.ee(${key})`;
|
|
172
|
+
source.replace(dep.block.range[0], dep.block.range[1] - 1, content);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
defaultImplementation === null || defaultImplementation === void 0 ? void 0 : defaultImplementation.apply(dep, source, runtime);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
// Have to do this after the official plugin in order to override
|
|
180
|
+
// Typings in webpack are incorrect. This is a DependencyTemplate object
|
|
181
|
+
dependencyTemplates.set(ImportDependency, customTemplate);
|
|
182
|
+
});
|
|
183
|
+
compilation.mainTemplate.hooks.requireExtensions.tap(PLUGIN_NAME, (source, chunk) => {
|
|
184
|
+
if (!needChunkOnDemandLoadingCode(chunk)) {
|
|
185
|
+
return source;
|
|
186
|
+
}
|
|
187
|
+
const { requireFn } = compilation.mainTemplate;
|
|
188
|
+
return Template.asString([
|
|
189
|
+
`var asyncImportChunkGroups = [`,
|
|
190
|
+
rankedImportGroups
|
|
191
|
+
? rankedImportGroups.map((x) => Template.indent(JSON.stringify(x.chunkIds))).join(',\n')
|
|
192
|
+
: '',
|
|
193
|
+
`];`,
|
|
194
|
+
`${requireFn}.ee = function (groupOrId, moduleId, importType) {`,
|
|
195
|
+
Template.indent([
|
|
196
|
+
`return Promise.all((Array.isArray(groupOrId) ? groupOrId : asyncImportChunkGroups[groupOrId]).map(function (x) { return ${requireFn}.e(x); }))`,
|
|
197
|
+
`.then(importType ? ${requireFn}.t.bind(0,moduleId,importType) : ${requireFn}.bind(0,moduleId));`
|
|
198
|
+
]),
|
|
199
|
+
`};`,
|
|
200
|
+
source
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=AsyncImportCompressionPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncImportCompressionPlugin.js","sourceRoot":"","sources":["../src/AsyncImportCompressionPlugin.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,OAAuC,MAAM,SAAS,CAAC;AAI9D,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO1C,MAAM,WAAW,GAAmC,8BAA8B,CAAC;AAEnF,MAAM,SAAS,GAAuB;IACpC,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,WAAW;CACnB,CAAC;AAEF,MAAM,mBAAmB,GAAqB,gBAAgB,CAAC;AAC/D,MAAM,kBAAkB,GAAW,uBAAuB,CAAC;AA8B3D,SAAS,mBAAmB,CAAC,WAA4C;IACvE,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC;QACzD,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YACpC,OAAO,GAAgD,CAAC;QAC1D,CAAC;IACH,CAAC;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AAgB,EAAE,cAAoC,CAAC,CAAC;YAClF,CAAC,CAAC,CAAC;YAEH,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAClD,WAAW,EACX,CAAC,MAAc,EAAE,KAAgC,EAAE,EAAE;gBACnD,IAAI,CAAC,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzC,OAAO,MAAM,CAAC;gBAChB,CAAC;gBAED,MAAM,EAAE,SAAS,EAAE,GAAG,WAAW,CAAC,YAAY,CAAC;gBAC/C,OAAO,QAAQ,CAAC,QAAQ,CAAC;oBACvB,gCAAgC;oBAChC,kBAAkB;wBAChB,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;wBACxF,CAAC,CAAC,EAAE;oBACN,IAAI;oBACJ,GAAG,SAAS,oDAAoD;oBAChE,QAAQ,CAAC,MAAM,CAAC;wBACd,2HAA2H,SAAS,YAAY;wBAChJ,sBAAsB,SAAS,oCAAoC,SAAS,qBAAqB;qBAClG,CAAC;oBACF,IAAI;oBACJ,MAAM;iBACP,CAAC,CAAC;YACL,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF","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 webpack, { type Compiler, type Plugin } from 'webpack';\nimport type { ReplaceSource } from 'webpack-sources';\nimport type { Tapable, TapOptions } from 'tapable';\n\nconst { Template } = webpack;\n\nimport { STAGE_AFTER } from './Constants';\nimport type {\n IExtendedModule,\n IModuleMinifierPluginHooks,\n IPostProcessFragmentContext\n} from './ModuleMinifierPlugin.types';\n\nconst PLUGIN_NAME: 'AsyncImportCompressionPlugin' = 'AsyncImportCompressionPlugin';\n\nconst TAP_AFTER: TapOptions<'sync'> = {\n name: PLUGIN_NAME,\n stage: STAGE_AFTER\n};\n\nconst ASYNC_IMPORT_PREFIX: '__IMPORT_ASYNC' = '__IMPORT_ASYNC';\nconst ASYNC_IMPORT_REGEX: RegExp = /__IMPORT_ASYNC[^\\)]+/g;\n\ndeclare class WebpackImportDependency extends webpack.compilation.Dependency {\n public module: webpack.compilation.Module;\n public block: {\n chunkGroup: webpack.compilation.ChunkGroup;\n range: [number, number];\n };\n}\n\ninterface IImportDependencyTemplate {\n apply(\n dependency: WebpackImportDependency,\n source: ReplaceSource,\n runtime: webpack.compilation.RuntimeTemplate\n ): void;\n}\n\ninterface IAsyncImportMetadata {\n chunkCount: number;\n chunkIds: number[];\n count: number;\n index: number;\n}\n\ninterface ILocalImportMetadata {\n meta: IAsyncImportMetadata;\n module: webpack.compilation.Module;\n}\n\nfunction getImportDependency(compilation: webpack.compilation.Compilation): typeof WebpackImportDependency {\n for (const key of compilation.dependencyTemplates.keys()) {\n if (key.name === 'ImportDependency') {\n return key as unknown as typeof WebpackImportDependency;\n }\n }\n\n throw new Error(`Could not find ImportDependency!`);\n}\n\nfunction getImportTypeExpression(\n module: webpack.compilation.Module,\n originModule: webpack.compilation.Module\n): string {\n const exportsType: string | undefined = module.buildMeta?.exportsType;\n const strict: boolean | undefined = originModule.buildMeta?.strictHarmonyModule;\n\n // Logic translated from:\n // https://github.com/webpack/webpack/blob/3956274f1eada621e105208dcab4608883cdfdb2/lib/RuntimeTemplate.js#L110-L122\n if (exportsType === 'namespace') {\n // Use the raw module directly\n return '';\n } else if (exportsType === 'named') {\n // Create a new namespace object and forward all exports\n return ',3';\n } else if (strict) {\n // Synthetic default export\n return ',1';\n } else {\n // If modules is marked __esModule, return raw module, otherwise create a new namespace object and forward all exports\n return ',7';\n }\n}\n\nfunction needChunkOnDemandLoadingCode(chunk: webpack.compilation.Chunk): boolean {\n for (const chunkGroup of chunk.groupsIterable) {\n if (chunkGroup.getNumberOfChildren() > 0) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Plugin that replaces `Promise.all([__webpack_require__.e(1), __webpack_require__.e(12)]).then(__webpack_require__.t.bind(123,7))`\n * with more concise expressions like `__webpack_require__.ee([1,12],123,7)`, etc.\n *\n * Also ensures that the code seen by the minifier does not contain chunk ids, and is therefore portable across chunks/compilations.\n */\nexport class AsyncImportCompressionPlugin implements Plugin {\n private readonly _minifierHooks: IModuleMinifierPluginHooks;\n\n public constructor(minifierHooks: IModuleMinifierPluginHooks) {\n this._minifierHooks = minifierHooks;\n }\n\n public apply(compiler: Compiler): void {\n const asyncImportMap: Map<webpack.compilation.Module, Map<string, ILocalImportMetadata>> = new Map();\n const asyncImportGroups: Map<string, IAsyncImportMetadata> = new Map();\n let rankedImportGroups: IAsyncImportMetadata[] | undefined;\n\n this._minifierHooks.postProcessCodeFragment.tap(\n {\n name: PLUGIN_NAME,\n stage: -1\n },\n (source: ReplaceSource, context: IPostProcessFragmentContext) => {\n const code: string = source.original().source() as string;\n\n let localImports: Map<string, ILocalImportMetadata> | undefined;\n\n ASYNC_IMPORT_REGEX.lastIndex = -1;\n // RegExp.exec uses null or an array as the return type, explicitly\n let match: RegExpExecArray | null = null;\n while ((match = ASYNC_IMPORT_REGEX.exec(code))) {\n const token: string = match[0];\n\n if (!localImports) {\n if (!context.module) {\n context.compilation.errors.push(\n new Error(`Unexpected async import ${token} in non-module context ${context.loggingName}`)\n );\n return source;\n }\n\n localImports = asyncImportMap.get(context.module);\n if (!localImports) {\n context.compilation.errors.push(\n new Error(`Unexpected async import ${token} in module ${context.loggingName}`)\n );\n return source;\n }\n }\n\n const localImport: ILocalImportMetadata | undefined = localImports.get(token);\n if (!localImport) {\n context.compilation.errors.push(\n new Error(`Missing metadata for ${token} in module ${context.loggingName}`)\n );\n return source;\n }\n const { meta, module } = localImport;\n\n const chunkExpression: string = meta.index < 0 ? JSON.stringify(meta.chunkIds) : `${meta.index}`;\n\n const mapped: string | number | undefined = this._minifierHooks.finalModuleId.call(\n module.id!,\n context.compilation\n );\n const idExpr: string | number = mapped === undefined ? module.id! : mapped;\n\n // Replace with a reference or array of ideas, the target module id, and the type of import\n source.replace(\n match.index,\n ASYNC_IMPORT_REGEX.lastIndex - 1,\n `${chunkExpression},${JSON.stringify(idExpr)}${getImportTypeExpression(module, context.module!)}`\n );\n }\n\n return source;\n }\n );\n\n compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation: webpack.compilation.Compilation) => {\n asyncImportMap.clear();\n asyncImportGroups.clear();\n\n compilation.hooks.beforeChunkAssets.tap(TAP_AFTER, () => {\n const ImportDependency: typeof WebpackImportDependency = getImportDependency(compilation);\n\n for (const module of compilation.modules) {\n const toProcess: IExtendedModule[] = module.modules || [module];\n\n for (const child of toProcess) {\n child.hasDependencies((dep: webpack.compilation.Dependency) => {\n if (dep instanceof ImportDependency) {\n const { module: targetModule } = dep;\n\n if (targetModule) {\n let localAsyncImports: Map<string, ILocalImportMetadata> | undefined =\n asyncImportMap.get(module);\n if (!localAsyncImports) {\n asyncImportMap.set(module, (localAsyncImports = new Map()));\n }\n\n const chunkGroup: webpack.compilation.ChunkGroup = dep.block.chunkGroup;\n const chunkIds: number[] = chunkGroup\n ? chunkGroup.chunks.map((chunk) => chunk.id!).sort()\n : [];\n const idString: string = chunkIds.join(';');\n\n let meta: IAsyncImportMetadata | undefined = asyncImportGroups.get(idString);\n if (!meta) {\n asyncImportGroups.set(\n idString,\n (meta = {\n chunkCount: chunkIds.length,\n chunkIds: chunkIds,\n count: 0,\n index: -1\n })\n );\n }\n meta.count++;\n\n const stringKey: string = `${targetModule.id}`.replace(/[^A-Za-z0-9_$]/g, '_');\n\n const key: string = `${ASYNC_IMPORT_PREFIX}${stringKey}`;\n localAsyncImports.set(key, {\n meta,\n module: targetModule\n });\n }\n }\n });\n }\n }\n\n const rankedImports: [string, IAsyncImportMetadata][] = [...asyncImportGroups]\n .filter((x) => x[1].count > 1)\n .sort((x, y) => {\n let diff: number = y[1].count - x[1].count;\n if (!diff) {\n diff = y[1].chunkCount - x[1].chunkCount;\n }\n\n if (!diff) {\n diff = x[0] > y[0] ? 1 : x[0] < y[0] ? -1 : 0;\n }\n\n return diff;\n });\n\n for (let i: number = 0, len: number = rankedImports.length; i < len; i++) {\n rankedImports[i][1].index = i;\n // console.log(rankedImports[i]);\n }\n\n rankedImportGroups = rankedImports.map((x) => x[1]);\n\n const { dependencyTemplates } = compilation;\n\n const defaultImplementation: IImportDependencyTemplate | undefined = dependencyTemplates.get(\n ImportDependency\n ) as unknown as IImportDependencyTemplate;\n if (!defaultImplementation) {\n compilation.errors.push(new Error(`Could not find ImportDependencyTemplate`));\n }\n\n const customTemplate: IImportDependencyTemplate = {\n apply(\n dep: WebpackImportDependency,\n source: ReplaceSource,\n runtime: webpack.compilation.RuntimeTemplate\n ): void {\n if (dep.module) {\n const stringKey: string = `${dep.module.id}`.replace(/[^A-Za-z0-9_$]/g, '_');\n const key: string = `${ASYNC_IMPORT_PREFIX}${stringKey}`;\n const content: string = `__webpack_require__.ee(${key})`;\n source.replace(dep.block.range[0], dep.block.range[1] - 1, content);\n } else {\n defaultImplementation?.apply(dep, source, runtime);\n }\n }\n };\n\n // Have to do this after the official plugin in order to override\n // Typings in webpack are incorrect. This is a DependencyTemplate object\n dependencyTemplates.set(ImportDependency, customTemplate as unknown as Tapable);\n });\n\n compilation.mainTemplate.hooks.requireExtensions.tap(\n PLUGIN_NAME,\n (source: string, chunk: webpack.compilation.Chunk) => {\n if (!needChunkOnDemandLoadingCode(chunk)) {\n return source;\n }\n\n const { requireFn } = compilation.mainTemplate;\n return Template.asString([\n `var asyncImportChunkGroups = [`,\n rankedImportGroups\n ? rankedImportGroups.map((x) => Template.indent(JSON.stringify(x.chunkIds))).join(',\\n')\n : '',\n `];`,\n `${requireFn}.ee = function (groupOrId, moduleId, importType) {`,\n Template.indent([\n `return Promise.all((Array.isArray(groupOrId) ? groupOrId : asyncImportChunkGroups[groupOrId]).map(function (x) { return ${requireFn}.e(x); }))`,\n `.then(importType ? ${requireFn}.t.bind(0,moduleId,importType) : ${requireFn}.bind(0,moduleId));`\n ]),\n `};`,\n source\n ]);\n }\n );\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
/**
|
|
4
|
+
* Prefix to wrap `function (module, __webpack_exports__, __webpack_require__) { ... }` so that the minifier doesn't delete it.
|
|
5
|
+
* Public because alternate Minifier implementations may wish to know about it.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export const MODULE_WRAPPER_PREFIX = '__MINIFY_MODULE__(';
|
|
9
|
+
/**
|
|
10
|
+
* Suffix to wrap `function (module, __webpack_exports__, __webpack_require__) { ... }` so that the minifier doesn't delete it.
|
|
11
|
+
* Public because alternate Minifier implementations may wish to know about it.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export const MODULE_WRAPPER_SUFFIX = ');';
|
|
15
|
+
/**
|
|
16
|
+
* Token to replace the object or array of module definitions so that the minifier can operate on the Webpack runtime or chunk boilerplate in isolation
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export const CHUNK_MODULES_TOKEN = '__WEBPACK_CHUNK_MODULES__';
|
|
20
|
+
/**
|
|
21
|
+
* Stage # to use when this should be the first tap in the hook
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const STAGE_BEFORE = -100;
|
|
25
|
+
/**
|
|
26
|
+
* Stage # to use when this should be the last tap in the hook
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export const STAGE_AFTER = 100;
|
|
30
|
+
//# sourceMappingURL=Constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAyB,oBAAoB,CAAC;AAChF;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAS,IAAI,CAAC;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAgC,2BAA2B,CAAC;AAE5F;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAS,CAAC,GAAG,CAAC;AACvC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAQ,GAAG,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\n/**\n * Prefix to wrap `function (module, __webpack_exports__, __webpack_require__) { ... }` so that the minifier doesn't delete it.\n * Public because alternate Minifier implementations may wish to know about it.\n * @public\n */\nexport const MODULE_WRAPPER_PREFIX: '__MINIFY_MODULE__(' = '__MINIFY_MODULE__(';\n/**\n * Suffix to wrap `function (module, __webpack_exports__, __webpack_require__) { ... }` so that the minifier doesn't delete it.\n * Public because alternate Minifier implementations may wish to know about it.\n * @public\n */\nexport const MODULE_WRAPPER_SUFFIX: ');' = ');';\n\n/**\n * Token to replace the object or array of module definitions so that the minifier can operate on the Webpack runtime or chunk boilerplate in isolation\n * @public\n */\nexport const CHUNK_MODULES_TOKEN: '__WEBPACK_CHUNK_MODULES__' = '__WEBPACK_CHUNK_MODULES__';\n\n/**\n * Stage # to use when this should be the first tap in the hook\n * @public\n */\nexport const STAGE_BEFORE: -100 = -100;\n/**\n * Stage # to use when this should be the last tap in the hook\n * @public\n */\nexport const STAGE_AFTER: 100 = 100;\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { ConcatSource } from 'webpack-sources';
|
|
5
|
+
function getAllComments(moduleIds, minifiedModules) {
|
|
6
|
+
const allComments = new Set();
|
|
7
|
+
for (const moduleId of moduleIds) {
|
|
8
|
+
const mod = minifiedModules.get(moduleId);
|
|
9
|
+
if (!mod) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const { module: webpackModule } = mod;
|
|
13
|
+
const modules = webpackModule.modules || [webpackModule];
|
|
14
|
+
for (const submodule of modules) {
|
|
15
|
+
const { comments: subModuleComments } = submodule.factoryMeta;
|
|
16
|
+
if (subModuleComments) {
|
|
17
|
+
for (const comment of subModuleComments) {
|
|
18
|
+
const value = comment.type === 'Line' ? `//${comment.value}\n` : `/*${comment.value}*/\n`;
|
|
19
|
+
allComments.add(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return allComments;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates a companion asset containing all extracted comments. If it is non-empty, returns a banner comment directing users to said companion asset.
|
|
28
|
+
*
|
|
29
|
+
* @param compilation - The webpack compilation
|
|
30
|
+
* @param asset - The asset to process
|
|
31
|
+
* @param minifiedModules - The minified modules to pull comments from
|
|
32
|
+
* @param assetName - The name of the asset
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export function generateLicenseFileForAsset(compilation, asset, minifiedModules) {
|
|
36
|
+
// Extracted comments from the modules.
|
|
37
|
+
const comments = getAllComments(asset.modules, minifiedModules);
|
|
38
|
+
const assetName = asset.fileName;
|
|
39
|
+
let banner = '';
|
|
40
|
+
if (comments.size) {
|
|
41
|
+
// There are license comments in this chunk, so generate the companion file and inject a banner
|
|
42
|
+
const licenseSource = new ConcatSource();
|
|
43
|
+
comments.forEach((comment) => {
|
|
44
|
+
licenseSource.add(comment);
|
|
45
|
+
});
|
|
46
|
+
const licenseFileName = `${assetName}.LICENSE.txt`;
|
|
47
|
+
compilation.assets[licenseFileName] = licenseSource;
|
|
48
|
+
banner = `/*! For license information please see ${path.basename(licenseFileName)} */\n`;
|
|
49
|
+
}
|
|
50
|
+
return banner;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=GenerateLicenseFileForAsset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateLicenseFileForAsset.js","sourceRoot":"","sources":["../src/GenerateLicenseFileForAsset.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,SAAS,cAAc,CAAC,SAA8B,EAAE,eAA2B;IACjF,MAAM,WAAW,GAAgB,IAAI,GAAG,EAAE,CAAC;IAE3C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,GAAG,GAA4B,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACnE,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,SAAS;QACX,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC;QACtC,MAAM,OAAO,GAAsB,aAAa,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;QAC5E,KAAK,MAAM,SAAS,IAAI,OAAO,EAAE,CAAC;YAChC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,SAAS,CAAC,WAEjD,CAAC;YACF,IAAI,iBAAiB,EAAE,CAAC;gBACtB,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE,CAAC;oBACxC,MAAM,KAAK,GAAW,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,KAAK,MAAM,CAAC;oBAClG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CACzC,WAA4C,EAC5C,KAAiB,EACjB,eAA2B;IAE3B,uCAAuC;IACvC,MAAM,QAAQ,GAAgB,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAE7E,MAAM,SAAS,GAAW,KAAK,CAAC,QAAQ,CAAC;IAEzC,IAAI,MAAM,GAAW,EAAE,CAAC;IAExB,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClB,+FAA+F;QAC/F,MAAM,aAAa,GAAiB,IAAI,YAAY,EAAE,CAAC;QACvD,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,MAAM,eAAe,GAAW,GAAG,SAAS,cAAc,CAAC;QAC3D,WAAW,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,aAAa,CAAC;QACpD,MAAM,GAAG,0CAA0C,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC;IAC3F,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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 'node:path';\n\nimport type * as webpack from 'webpack';\nimport { ConcatSource } from 'webpack-sources';\n\nimport type {\n IAssetInfo,\n IModuleMap,\n IModuleInfo,\n IExtendedModule,\n _IAcornComment\n} from './ModuleMinifierPlugin.types';\n\nfunction getAllComments(moduleIds: (string | number)[], minifiedModules: IModuleMap): Set<string> {\n const allComments: Set<string> = new Set();\n\n for (const moduleId of moduleIds) {\n const mod: IModuleInfo | undefined = minifiedModules.get(moduleId);\n if (!mod) {\n continue;\n }\n\n const { module: webpackModule } = mod;\n const modules: IExtendedModule[] = webpackModule.modules || [webpackModule];\n for (const submodule of modules) {\n const { comments: subModuleComments } = submodule.factoryMeta as {\n comments?: Set<_IAcornComment>;\n };\n if (subModuleComments) {\n for (const comment of subModuleComments) {\n const value: string = comment.type === 'Line' ? `//${comment.value}\\n` : `/*${comment.value}*/\\n`;\n allComments.add(value);\n }\n }\n }\n }\n\n return allComments;\n}\n\n/**\n * Generates a companion asset containing all extracted comments. If it is non-empty, returns a banner comment directing users to said companion asset.\n *\n * @param compilation - The webpack compilation\n * @param asset - The asset to process\n * @param minifiedModules - The minified modules to pull comments from\n * @param assetName - The name of the asset\n * @public\n */\nexport function generateLicenseFileForAsset(\n compilation: webpack.compilation.Compilation,\n asset: IAssetInfo,\n minifiedModules: IModuleMap\n): string {\n // Extracted comments from the modules.\n const comments: Set<string> = getAllComments(asset.modules, minifiedModules);\n\n const assetName: string = asset.fileName;\n\n let banner: string = '';\n\n if (comments.size) {\n // There are license comments in this chunk, so generate the companion file and inject a banner\n const licenseSource: ConcatSource = new ConcatSource();\n comments.forEach((comment) => {\n licenseSource.add(comment);\n });\n const licenseFileName: string = `${assetName}.LICENSE.txt`;\n compilation.assets[licenseFileName] = licenseSource;\n banner = `/*! For license information please see ${path.basename(licenseFileName)} */\\n`;\n }\n\n return banner;\n}\n"]}
|