@serwist/webpack-plugin 9.0.0-preview.1 → 9.0.0-preview.11
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/dist/index.internal.js +7 -2
- package/dist/index.js +14 -12
- package/dist/inject-manifest.d.ts +9 -16
- package/dist/inject-manifest.d.ts.map +1 -1
- package/dist/lib/child-compilation-plugin.d.ts +21 -4
- package/dist/lib/child-compilation-plugin.d.ts.map +1 -1
- package/dist/lib/get-manifest-entries-from-compilation.d.ts.map +1 -1
- package/package.json +7 -4
- package/src/inject-manifest.ts +28 -30
- package/src/lib/child-compilation-plugin.ts +28 -6
- package/src/lib/get-manifest-entries-from-compilation.ts +1 -2
package/dist/index.internal.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import webpack from 'webpack';
|
|
2
1
|
import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js';
|
|
3
2
|
import 'upath';
|
|
4
3
|
|
|
@@ -6,12 +5,18 @@ class ChildCompilationPlugin {
|
|
|
6
5
|
src;
|
|
7
6
|
dest;
|
|
8
7
|
plugins;
|
|
8
|
+
webpack;
|
|
9
9
|
constructor({ src, dest, plugins }){
|
|
10
10
|
this.src = src;
|
|
11
11
|
this.dest = dest;
|
|
12
12
|
this.plugins = plugins;
|
|
13
|
+
this.webpack = null;
|
|
14
|
+
}
|
|
15
|
+
propagateWebpackConfig(compiler) {
|
|
16
|
+
this.webpack = compiler.webpack;
|
|
13
17
|
}
|
|
14
18
|
apply(compiler) {
|
|
19
|
+
this.propagateWebpackConfig(compiler);
|
|
15
20
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.performChildCompilation(compilation, compiler).catch((error)=>{
|
|
16
21
|
compilation.errors.push(error);
|
|
17
22
|
}));
|
|
@@ -30,7 +35,7 @@ class ChildCompilationPlugin {
|
|
|
30
35
|
plugin?.apply(childCompiler);
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
|
-
new webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
38
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
34
39
|
await new Promise((resolve, reject)=>{
|
|
35
40
|
childCompiler.runAsChild((error, _entries, childCompilation)=>{
|
|
36
41
|
if (error) {
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { transformManifest, getSourceMapURL, validateWebpackInjectManifestOption
|
|
|
2
2
|
import stringify from 'fast-json-stable-stringify';
|
|
3
3
|
import prettyBytes from 'pretty-bytes';
|
|
4
4
|
import upath from 'upath';
|
|
5
|
-
import webpack from 'webpack';
|
|
6
5
|
import crypto from 'crypto';
|
|
7
6
|
import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js';
|
|
8
7
|
|
|
@@ -31,7 +30,7 @@ const checkConditions = (asset, compilation, conditions = [])=>{
|
|
|
31
30
|
compilation
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
|
-
if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
33
|
+
if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
35
34
|
return true;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
@@ -151,16 +150,19 @@ const _generatedAssetNames = new Set();
|
|
|
151
150
|
class InjectManifest {
|
|
152
151
|
config;
|
|
153
152
|
alreadyCalled;
|
|
153
|
+
webpack;
|
|
154
154
|
constructor(config){
|
|
155
155
|
this.config = config;
|
|
156
156
|
this.alreadyCalled = false;
|
|
157
|
+
this.webpack = null;
|
|
157
158
|
}
|
|
158
159
|
propagateWebpackConfig(compiler) {
|
|
160
|
+
this.webpack = compiler.webpack;
|
|
159
161
|
const parsedSwSrc = upath.parse(this.config.swSrc);
|
|
160
|
-
this.config =
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
162
|
+
this.config = {
|
|
163
|
+
swDest: `${parsedSwSrc.name}.js`,
|
|
164
|
+
...this.config
|
|
165
|
+
};
|
|
164
166
|
}
|
|
165
167
|
async getManifestEntries(compilation, config) {
|
|
166
168
|
if (config.disablePrecacheManifest) {
|
|
@@ -195,7 +197,7 @@ class InjectManifest {
|
|
|
195
197
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.handleMake(compilation, compiler).catch((error)=>{
|
|
196
198
|
compilation.errors.push(error);
|
|
197
199
|
}));
|
|
198
|
-
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation;
|
|
200
|
+
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;
|
|
199
201
|
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation)=>{
|
|
200
202
|
compilation.hooks.processAssets.tapPromise({
|
|
201
203
|
name: this.constructor.name,
|
|
@@ -218,7 +220,7 @@ class InjectManifest {
|
|
|
218
220
|
plugin.apply(childCompiler);
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
|
-
new webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
223
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
222
224
|
await new Promise((resolve, reject)=>{
|
|
223
225
|
childCompiler.runAsChild((error, _entries, childCompilation)=>{
|
|
224
226
|
if (error) {
|
|
@@ -233,7 +235,7 @@ class InjectManifest {
|
|
|
233
235
|
}
|
|
234
236
|
addSrcToAssets(compilation, parentCompiler) {
|
|
235
237
|
const source = parentCompiler.inputFileSystem.readFileSync(this.config.swSrc);
|
|
236
|
-
compilation.emitAsset(this.config.swDest, new webpack.sources.RawSource(source));
|
|
238
|
+
compilation.emitAsset(this.config.swDest, new this.webpack.sources.RawSource(source));
|
|
237
239
|
}
|
|
238
240
|
async handleMake(compilation, parentCompiler) {
|
|
239
241
|
this.config = await validateWebpackInjectManifestOptions(this.config);
|
|
@@ -274,10 +276,10 @@ class InjectManifest {
|
|
|
274
276
|
replaceString: manifestString,
|
|
275
277
|
searchString: config.injectionPoint
|
|
276
278
|
});
|
|
277
|
-
compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
|
|
278
|
-
compilation.updateAsset(config.swDest, new webpack.sources.RawSource(source));
|
|
279
|
+
compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map));
|
|
280
|
+
compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(source));
|
|
279
281
|
} else {
|
|
280
|
-
compilation.updateAsset(config.swDest, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));
|
|
282
|
+
compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));
|
|
281
283
|
}
|
|
282
284
|
if (compilation.getLogger) {
|
|
283
285
|
const logger = compilation.getLogger(this.constructor.name);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WebpackInjectManifestOptions } from "@serwist/build";
|
|
2
|
-
import
|
|
2
|
+
import type { Compiler } from "webpack";
|
|
3
3
|
/**
|
|
4
4
|
* This class supports compiling a service worker file provided via `swSrc`,
|
|
5
5
|
* and injecting into that service worker a list of URLs and revision
|
|
@@ -25,6 +25,7 @@ import webpack from "webpack";
|
|
|
25
25
|
export declare class InjectManifest {
|
|
26
26
|
protected config: WebpackInjectManifestOptions;
|
|
27
27
|
private alreadyCalled;
|
|
28
|
+
private webpack;
|
|
28
29
|
/**
|
|
29
30
|
* Creates an instance of InjectManifest.
|
|
30
31
|
*/
|
|
@@ -34,53 +35,45 @@ export declare class InjectManifest {
|
|
|
34
35
|
*
|
|
35
36
|
* @private
|
|
36
37
|
*/
|
|
37
|
-
propagateWebpackConfig
|
|
38
|
+
private propagateWebpackConfig;
|
|
38
39
|
/**
|
|
39
40
|
* `getManifestEntriesFromCompilation` with a few additional checks.
|
|
40
41
|
*
|
|
41
42
|
* @private
|
|
42
43
|
*/
|
|
43
|
-
getManifestEntries
|
|
44
|
-
size: number;
|
|
45
|
-
sortedEntries: {
|
|
46
|
-
revision: string | null;
|
|
47
|
-
url: string;
|
|
48
|
-
integrity?: string | undefined;
|
|
49
|
-
}[] | undefined;
|
|
50
|
-
manifestString: string;
|
|
51
|
-
}>;
|
|
44
|
+
private getManifestEntries;
|
|
52
45
|
/**
|
|
53
46
|
* @param compiler default compiler object passed from webpack
|
|
54
47
|
*
|
|
55
48
|
* @private
|
|
56
49
|
*/
|
|
57
|
-
apply(compiler:
|
|
50
|
+
apply(compiler: Compiler): void;
|
|
58
51
|
/**
|
|
59
52
|
* @param compilation The webpack compilation.
|
|
60
53
|
* @param parentCompiler The webpack parent compiler.
|
|
61
54
|
*
|
|
62
55
|
* @private
|
|
63
56
|
*/
|
|
64
|
-
performChildCompilation
|
|
57
|
+
private performChildCompilation;
|
|
65
58
|
/**
|
|
66
59
|
* @param compilation The webpack compilation.
|
|
67
60
|
* @param parentCompiler The webpack parent compiler.
|
|
68
61
|
*
|
|
69
62
|
* @private
|
|
70
63
|
*/
|
|
71
|
-
addSrcToAssets
|
|
64
|
+
private addSrcToAssets;
|
|
72
65
|
/**
|
|
73
66
|
* @param compilation The webpack compilation.
|
|
74
67
|
* @param parentCompiler The webpack parent compiler.
|
|
75
68
|
*
|
|
76
69
|
* @private
|
|
77
70
|
*/
|
|
78
|
-
handleMake
|
|
71
|
+
private handleMake;
|
|
79
72
|
/**
|
|
80
73
|
* @param compilation The webpack compilation.
|
|
81
74
|
*
|
|
82
75
|
* @private
|
|
83
76
|
*/
|
|
84
|
-
addAssets
|
|
77
|
+
private addAssets;
|
|
85
78
|
}
|
|
86
79
|
//# sourceMappingURL=inject-manifest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAKnE,OAAO,KAAK,EAAe,QAAQ,EAAoC,MAAM,SAAS,CAAC;AAUvF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,cAAc;IACzB,SAAS,CAAC,MAAM,EAAE,4BAA4B,CAAC;IAC/C,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,OAAO,CAAiB;IAEhC;;OAEG;gBACS,MAAM,EAAE,4BAA4B;IAMhD;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAa9B;;;;OAIG;YACW,kBAAkB;IAwChC;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IA6B/B;;;;;OAKG;YACW,uBAAuB;IAiCrC;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAKtB;;;;;OAKG;YACW,UAAU;IAiBxB;;;;OAIG;YACW,SAAS;CAmDxB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { WebpackPluginInstance } from "webpack";
|
|
2
|
-
import webpack from "webpack";
|
|
1
|
+
import type { Compiler, WebpackPluginInstance, default as Webpack } from "webpack";
|
|
3
2
|
export interface ChildCompilationPluginOptions {
|
|
4
3
|
src: string;
|
|
5
4
|
dest: string;
|
|
@@ -14,8 +13,26 @@ export declare class ChildCompilationPlugin implements WebpackPluginInstance {
|
|
|
14
13
|
src: string;
|
|
15
14
|
dest: string;
|
|
16
15
|
plugins: WebpackPluginInstance[] | undefined;
|
|
16
|
+
webpack: typeof Webpack;
|
|
17
17
|
constructor({ src, dest, plugins }: ChildCompilationPluginOptions);
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @param compiler default compiler object passed from webpack
|
|
20
|
+
*
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private propagateWebpackConfig;
|
|
24
|
+
/**
|
|
25
|
+
* @param compiler default compiler object passed from webpack
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
apply(compiler: Compiler): void;
|
|
30
|
+
/**
|
|
31
|
+
* @param compilation The webpack compilation.
|
|
32
|
+
* @param parentCompiler The webpack parent compiler.
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
private performChildCompilation;
|
|
20
37
|
}
|
|
21
38
|
//# sourceMappingURL=child-compilation-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child-compilation-plugin.d.ts","sourceRoot":"","sources":["../../src/lib/child-compilation-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"child-compilation-plugin.d.ts","sourceRoot":"","sources":["../../src/lib/child-compilation-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,QAAQ,EAAgB,qBAAqB,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAI9G,MAAM,WAAW,6BAA6B;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACnC;AAED;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,qBAAqB,EAAE,GAAG,SAAS,CAAC;IAC7C,OAAO,EAAE,OAAO,OAAO,CAAC;gBACZ,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,6BAA6B;IAMjE;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAG9B;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;IASxB;;;;;OAKG;YACW,uBAAuB;CAiCtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-manifest-entries-from-compilation.d.ts","sourceRoot":"","sources":["../../src/lib/get-manifest-entries-from-compilation.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAe,aAAa,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAE/F,OAAO,KAAK,EAAgB,WAAW,EAAgB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"get-manifest-entries-from-compilation.d.ts","sourceRoot":"","sources":["../../src/lib/get-manifest-entries-from-compilation.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAe,aAAa,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAE/F,OAAO,KAAK,EAAgB,WAAW,EAAgB,MAAM,SAAS,CAAC;AAuKvE,eAAO,MAAM,iCAAiC,gBAC/B,WAAW,UAChB,4BAA4B;UACnB,MAAM;mBAAiB,aAAa,EAAE,GAAG,SAAS;EAgCpE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/webpack-plugin",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A plugin for your Webpack build process, helping you generate a manifest of local files that should be precached.",
|
|
6
6
|
"files": [
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"fast-json-stable-stringify": "2.1.0",
|
|
50
50
|
"pretty-bytes": "6.1.1",
|
|
51
51
|
"upath": "2.0.1",
|
|
52
|
-
"@serwist/build": "9.0.0-preview.
|
|
52
|
+
"@serwist/build": "9.0.0-preview.11"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "20.11.16",
|
|
56
56
|
"@types/webpack": "5.28.5",
|
|
57
57
|
"rollup": "4.9.6",
|
|
58
|
-
"typescript": "5.4.0-dev.
|
|
58
|
+
"typescript": "5.4.0-dev.20240206",
|
|
59
59
|
"webpack": "5.90.1",
|
|
60
|
-
"@serwist/constants": "9.0.0-preview.
|
|
60
|
+
"@serwist/constants": "9.0.0-preview.11"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"typescript": ">=5.0.0",
|
|
@@ -66,6 +66,9 @@
|
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"typescript": {
|
|
68
68
|
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"webpack": {
|
|
71
|
+
"optional": true
|
|
69
72
|
}
|
|
70
73
|
},
|
|
71
74
|
"scripts": {
|
package/src/inject-manifest.ts
CHANGED
|
@@ -10,8 +10,7 @@ import { escapeRegExp, replaceAndUpdateSourceMap, validateWebpackInjectManifestO
|
|
|
10
10
|
import stringify from "fast-json-stable-stringify";
|
|
11
11
|
import prettyBytes from "pretty-bytes";
|
|
12
12
|
import upath from "upath";
|
|
13
|
-
import type { Compilation } from "webpack";
|
|
14
|
-
import webpack from "webpack";
|
|
13
|
+
import type { Compilation, Compiler, WebpackError, default as Webpack } from "webpack";
|
|
15
14
|
|
|
16
15
|
import { getManifestEntriesFromCompilation } from "./lib/get-manifest-entries-from-compilation.js";
|
|
17
16
|
import { getSourcemapAssetName } from "./lib/get-sourcemap-asset-name.js";
|
|
@@ -46,6 +45,7 @@ const _generatedAssetNames = new Set<string>();
|
|
|
46
45
|
export class InjectManifest {
|
|
47
46
|
protected config: WebpackInjectManifestOptions;
|
|
48
47
|
private alreadyCalled: boolean;
|
|
48
|
+
private webpack: typeof Webpack;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Creates an instance of InjectManifest.
|
|
@@ -53,6 +53,7 @@ export class InjectManifest {
|
|
|
53
53
|
constructor(config: WebpackInjectManifestOptions) {
|
|
54
54
|
this.config = config;
|
|
55
55
|
this.alreadyCalled = false;
|
|
56
|
+
this.webpack = null!;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
/**
|
|
@@ -60,18 +61,17 @@ export class InjectManifest {
|
|
|
60
61
|
*
|
|
61
62
|
* @private
|
|
62
63
|
*/
|
|
63
|
-
propagateWebpackConfig(compiler:
|
|
64
|
+
private propagateWebpackConfig(compiler: Compiler): void {
|
|
65
|
+
this.webpack = compiler.webpack;
|
|
66
|
+
|
|
64
67
|
const parsedSwSrc = upath.parse(this.config.swSrc);
|
|
65
68
|
// Because this.config is listed last, properties that are already set
|
|
66
69
|
// there take precedence over derived properties from the compiler.
|
|
67
|
-
this.config =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
this.config,
|
|
74
|
-
);
|
|
70
|
+
this.config = {
|
|
71
|
+
// Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file.
|
|
72
|
+
swDest: `${parsedSwSrc.name}.js`,
|
|
73
|
+
...this.config,
|
|
74
|
+
};
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -79,7 +79,7 @@ export class InjectManifest {
|
|
|
79
79
|
*
|
|
80
80
|
* @private
|
|
81
81
|
*/
|
|
82
|
-
async getManifestEntries(compilation:
|
|
82
|
+
private async getManifestEntries(compilation: Compilation, config: WebpackInjectManifestOptions) {
|
|
83
83
|
if (config.disablePrecacheManifest) {
|
|
84
84
|
return {
|
|
85
85
|
size: 0,
|
|
@@ -93,7 +93,7 @@ export class InjectManifest {
|
|
|
93
93
|
const warningMessage = `${this.constructor.name} has been called multiple times, perhaps due to running webpack in --watch mode. The precache manifest generated after the first call may be inaccurate! Please see https://github.com/GoogleChrome/workbox/issues/1790 for more information.`;
|
|
94
94
|
|
|
95
95
|
if (!compilation.warnings.some((warning) => warning instanceof Error && warning.message === warningMessage)) {
|
|
96
|
-
compilation.warnings.push(new Error(warningMessage) as
|
|
96
|
+
compilation.warnings.push(new Error(warningMessage) as WebpackError);
|
|
97
97
|
}
|
|
98
98
|
} else {
|
|
99
99
|
this.alreadyCalled = true;
|
|
@@ -124,16 +124,17 @@ export class InjectManifest {
|
|
|
124
124
|
*
|
|
125
125
|
* @private
|
|
126
126
|
*/
|
|
127
|
-
apply(compiler:
|
|
127
|
+
apply(compiler: Compiler): void {
|
|
128
128
|
this.propagateWebpackConfig(compiler);
|
|
129
129
|
|
|
130
130
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
|
|
131
|
-
this.handleMake(compilation, compiler).catch((error:
|
|
131
|
+
this.handleMake(compilation, compiler).catch((error: WebpackError) => {
|
|
132
132
|
compilation.errors.push(error);
|
|
133
133
|
}),
|
|
134
134
|
);
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
// webpack should not be null at this point.
|
|
137
|
+
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;
|
|
137
138
|
// Specifically hook into thisCompilation, as per
|
|
138
139
|
// https://github.com/webpack/webpack/issues/11425#issuecomment-690547848
|
|
139
140
|
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
|
|
@@ -145,7 +146,7 @@ export class InjectManifest {
|
|
|
145
146
|
stage: PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 10,
|
|
146
147
|
},
|
|
147
148
|
() =>
|
|
148
|
-
this.addAssets(compilation).catch((error:
|
|
149
|
+
this.addAssets(compilation).catch((error: WebpackError) => {
|
|
149
150
|
compilation.errors.push(error);
|
|
150
151
|
}),
|
|
151
152
|
);
|
|
@@ -158,7 +159,7 @@ export class InjectManifest {
|
|
|
158
159
|
*
|
|
159
160
|
* @private
|
|
160
161
|
*/
|
|
161
|
-
async performChildCompilation(compilation:
|
|
162
|
+
private async performChildCompilation(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
|
|
162
163
|
const outputOptions: Parameters<Compilation["createChildCompiler"]>["1"] = {
|
|
163
164
|
filename: this.config.swDest,
|
|
164
165
|
};
|
|
@@ -175,7 +176,7 @@ export class InjectManifest {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
new webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
179
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
179
180
|
|
|
180
181
|
await new Promise<void>((resolve, reject) => {
|
|
181
182
|
childCompiler.runAsChild((error, _entries, childCompilation) => {
|
|
@@ -197,10 +198,9 @@ export class InjectManifest {
|
|
|
197
198
|
*
|
|
198
199
|
* @private
|
|
199
200
|
*/
|
|
200
|
-
addSrcToAssets(compilation:
|
|
201
|
-
// eslint-disable-next-line
|
|
201
|
+
private addSrcToAssets(compilation: Compilation, parentCompiler: Compiler): void {
|
|
202
202
|
const source = (parentCompiler.inputFileSystem as any).readFileSync(this.config.swSrc);
|
|
203
|
-
compilation.emitAsset(this.config.swDest!, new webpack.sources.RawSource(source));
|
|
203
|
+
compilation.emitAsset(this.config.swDest!, new this.webpack.sources.RawSource(source));
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
/**
|
|
@@ -209,7 +209,7 @@ export class InjectManifest {
|
|
|
209
209
|
*
|
|
210
210
|
* @private
|
|
211
211
|
*/
|
|
212
|
-
async handleMake(compilation:
|
|
212
|
+
private async handleMake(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
|
|
213
213
|
this.config = await validateWebpackInjectManifestOptions(this.config);
|
|
214
214
|
this.config.swDest = relativeToOutputPath(compilation, this.config.swDest!);
|
|
215
215
|
_generatedAssetNames.add(this.config.swDest);
|
|
@@ -221,9 +221,7 @@ export class InjectManifest {
|
|
|
221
221
|
// This used to be a fatal error, but just warn at runtime because we
|
|
222
222
|
// can't validate it easily.
|
|
223
223
|
if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) {
|
|
224
|
-
compilation.warnings.push(
|
|
225
|
-
new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored.") as webpack.WebpackError,
|
|
226
|
-
);
|
|
224
|
+
compilation.warnings.push(new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored.") as WebpackError);
|
|
227
225
|
}
|
|
228
226
|
}
|
|
229
227
|
}
|
|
@@ -233,7 +231,7 @@ export class InjectManifest {
|
|
|
233
231
|
*
|
|
234
232
|
* @private
|
|
235
233
|
*/
|
|
236
|
-
async addAssets(compilation:
|
|
234
|
+
private async addAssets(compilation: Compilation): Promise<void> {
|
|
237
235
|
const config = Object.assign({}, this.config);
|
|
238
236
|
|
|
239
237
|
const { size, sortedEntries, manifestString } = await this.getManifestEntries(compilation, config);
|
|
@@ -271,12 +269,12 @@ export class InjectManifest {
|
|
|
271
269
|
searchString: config.injectionPoint!,
|
|
272
270
|
});
|
|
273
271
|
|
|
274
|
-
compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
|
|
275
|
-
compilation.updateAsset(config.swDest!, new webpack.sources.RawSource(source));
|
|
272
|
+
compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map));
|
|
273
|
+
compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(source));
|
|
276
274
|
} else {
|
|
277
275
|
// If there's no sourcemap associated with swDest, a simple string
|
|
278
276
|
// replacement will suffice.
|
|
279
|
-
compilation.updateAsset(config.swDest!, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint!, manifestString)));
|
|
277
|
+
compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint!, manifestString)));
|
|
280
278
|
}
|
|
281
279
|
|
|
282
280
|
if (compilation.getLogger) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Compilation, WebpackPluginInstance } from "webpack";
|
|
2
|
-
import webpack from "webpack";
|
|
1
|
+
import type { Compilation, Compiler, WebpackError, WebpackPluginInstance, default as Webpack } from "webpack";
|
|
3
2
|
|
|
4
3
|
import { relativeToOutputPath } from "./relative-to-output-path.js";
|
|
5
4
|
|
|
@@ -18,19 +17,42 @@ export class ChildCompilationPlugin implements WebpackPluginInstance {
|
|
|
18
17
|
src: string;
|
|
19
18
|
dest: string;
|
|
20
19
|
plugins: WebpackPluginInstance[] | undefined;
|
|
20
|
+
webpack: typeof Webpack;
|
|
21
21
|
constructor({ src, dest, plugins }: ChildCompilationPluginOptions) {
|
|
22
22
|
this.src = src;
|
|
23
23
|
this.dest = dest;
|
|
24
24
|
this.plugins = plugins;
|
|
25
|
+
this.webpack = null!;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @param compiler default compiler object passed from webpack
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
private propagateWebpackConfig(compiler: Compiler): void {
|
|
33
|
+
this.webpack = compiler.webpack;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @param compiler default compiler object passed from webpack
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
apply(compiler: Compiler) {
|
|
41
|
+
this.propagateWebpackConfig(compiler);
|
|
42
|
+
|
|
27
43
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
|
|
28
|
-
this.performChildCompilation(compilation, compiler).catch((error:
|
|
44
|
+
this.performChildCompilation(compilation, compiler).catch((error: WebpackError) => {
|
|
29
45
|
compilation.errors.push(error);
|
|
30
46
|
}),
|
|
31
47
|
);
|
|
32
48
|
}
|
|
33
|
-
|
|
49
|
+
/**
|
|
50
|
+
* @param compilation The webpack compilation.
|
|
51
|
+
* @param parentCompiler The webpack parent compiler.
|
|
52
|
+
*
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
private async performChildCompilation(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
|
|
34
56
|
const resolvedDest = relativeToOutputPath(compilation, this.dest);
|
|
35
57
|
const outputOptions: Parameters<Compilation["createChildCompiler"]>["1"] = {
|
|
36
58
|
filename: resolvedDest,
|
|
@@ -48,7 +70,7 @@ export class ChildCompilationPlugin implements WebpackPluginInstance {
|
|
|
48
70
|
}
|
|
49
71
|
}
|
|
50
72
|
|
|
51
|
-
new webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
73
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
52
74
|
|
|
53
75
|
await new Promise<void>((resolve, reject) => {
|
|
54
76
|
childCompiler.runAsChild((error, _entries, childCompilation) => {
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
import type { FileDetails, ManifestEntry, WebpackInjectManifestOptions } from "@serwist/build";
|
|
10
10
|
import { transformManifest } from "@serwist/build";
|
|
11
11
|
import type { Asset, Chunk, Compilation, WebpackError } from "webpack";
|
|
12
|
-
import webpack from "webpack";
|
|
13
12
|
|
|
14
13
|
import { getAssetHash } from "./get-asset-hash.js";
|
|
15
14
|
import { resolveWebpackURL } from "./resolve-webpack-url.js";
|
|
@@ -36,7 +35,7 @@ const checkConditions = (
|
|
|
36
35
|
return condition({ asset, compilation });
|
|
37
36
|
//return compilation !== null;
|
|
38
37
|
}
|
|
39
|
-
if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
38
|
+
if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
40
39
|
return true;
|
|
41
40
|
}
|
|
42
41
|
}
|