@serwist/webpack-plugin 9.0.0-preview.10 → 9.0.0-preview.12

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.
@@ -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,15 +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
- propagateWebpackConfig() {
159
+ propagateWebpackConfig(compiler) {
160
+ this.webpack = compiler.webpack;
159
161
  const parsedSwSrc = upath.parse(this.config.swSrc);
160
- this.config = Object.assign({
161
- swDest: `${parsedSwSrc.name}.js`
162
- }, this.config);
162
+ this.config = {
163
+ swDest: `${parsedSwSrc.name}.js`,
164
+ ...this.config
165
+ };
163
166
  }
164
167
  async getManifestEntries(compilation, config) {
165
168
  if (config.disablePrecacheManifest) {
@@ -190,11 +193,11 @@ class InjectManifest {
190
193
  };
191
194
  }
192
195
  apply(compiler) {
193
- this.propagateWebpackConfig();
196
+ this.propagateWebpackConfig(compiler);
194
197
  compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.handleMake(compilation, compiler).catch((error)=>{
195
198
  compilation.errors.push(error);
196
199
  }));
197
- const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation;
200
+ const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;
198
201
  compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation)=>{
199
202
  compilation.hooks.processAssets.tapPromise({
200
203
  name: this.constructor.name,
@@ -217,7 +220,7 @@ class InjectManifest {
217
220
  plugin.apply(childCompiler);
218
221
  }
219
222
  }
220
- 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);
221
224
  await new Promise((resolve, reject)=>{
222
225
  childCompiler.runAsChild((error, _entries, childCompilation)=>{
223
226
  if (error) {
@@ -232,7 +235,7 @@ class InjectManifest {
232
235
  }
233
236
  addSrcToAssets(compilation, parentCompiler) {
234
237
  const source = parentCompiler.inputFileSystem.readFileSync(this.config.swSrc);
235
- compilation.emitAsset(this.config.swDest, new webpack.sources.RawSource(source));
238
+ compilation.emitAsset(this.config.swDest, new this.webpack.sources.RawSource(source));
236
239
  }
237
240
  async handleMake(compilation, parentCompiler) {
238
241
  this.config = await validateWebpackInjectManifestOptions(this.config);
@@ -273,10 +276,10 @@ class InjectManifest {
273
276
  replaceString: manifestString,
274
277
  searchString: config.injectionPoint
275
278
  });
276
- compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
277
- 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));
278
281
  } else {
279
- 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)));
280
283
  }
281
284
  if (compilation.getLogger) {
282
285
  const logger = compilation.getLogger(this.constructor.name);
@@ -1,5 +1,5 @@
1
1
  import type { WebpackInjectManifestOptions } from "@serwist/build";
2
- import webpack from "webpack";
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(): void;
38
+ private propagateWebpackConfig;
38
39
  /**
39
40
  * `getManifestEntriesFromCompilation` with a few additional checks.
40
41
  *
41
42
  * @private
42
43
  */
43
- getManifestEntries(compilation: webpack.Compilation, config: WebpackInjectManifestOptions): Promise<{
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: webpack.Compiler): void;
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(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>;
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(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): void;
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(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>;
71
+ private handleMake;
79
72
  /**
80
73
  * @param compilation The webpack compilation.
81
74
  *
82
75
  * @private
83
76
  */
84
- addAssets(compilation: webpack.Compilation): Promise<void>;
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;AAMnE,OAAO,OAAO,MAAM,SAAS,CAAC;AAU9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,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,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
- apply(compiler: webpack.Compiler): void;
19
- performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>;
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,MAAM,SAAS,CAAC;AAClE,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,MAAM,W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AuB;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;AAwKvE,eAAO,MAAM,iCAAiC,gBAC/B,WAAW,UAChB,4BAA4B;UACnB,MAAM;mBAAiB,aAAa,EAAE,GAAG,SAAS;EAgCpE,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.10",
3
+ "version": "9.0.0-preview.12",
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,7 +49,7 @@
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.10"
52
+ "@serwist/build": "9.0.0-preview.12"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "20.11.16",
@@ -57,7 +57,7 @@
57
57
  "rollup": "4.9.6",
58
58
  "typescript": "5.4.0-dev.20240206",
59
59
  "webpack": "5.90.1",
60
- "@serwist/constants": "9.0.0-preview.10"
60
+ "@serwist/constants": "9.0.0-preview.12"
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": {
@@ -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,17 +61,17 @@ export class InjectManifest {
60
61
  *
61
62
  * @private
62
63
  */
63
- propagateWebpackConfig(): void {
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 = Object.assign(
68
- {
69
- // Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file.
70
- swDest: `${parsedSwSrc.name}.js`,
71
- },
72
- this.config,
73
- );
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
+ };
74
75
  }
75
76
 
76
77
  /**
@@ -78,7 +79,7 @@ export class InjectManifest {
78
79
  *
79
80
  * @private
80
81
  */
81
- async getManifestEntries(compilation: webpack.Compilation, config: WebpackInjectManifestOptions) {
82
+ private async getManifestEntries(compilation: Compilation, config: WebpackInjectManifestOptions) {
82
83
  if (config.disablePrecacheManifest) {
83
84
  return {
84
85
  size: 0,
@@ -92,7 +93,7 @@ export class InjectManifest {
92
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.`;
93
94
 
94
95
  if (!compilation.warnings.some((warning) => warning instanceof Error && warning.message === warningMessage)) {
95
- compilation.warnings.push(new Error(warningMessage) as webpack.WebpackError);
96
+ compilation.warnings.push(new Error(warningMessage) as WebpackError);
96
97
  }
97
98
  } else {
98
99
  this.alreadyCalled = true;
@@ -123,16 +124,17 @@ export class InjectManifest {
123
124
  *
124
125
  * @private
125
126
  */
126
- apply(compiler: webpack.Compiler): void {
127
- this.propagateWebpackConfig();
127
+ apply(compiler: Compiler): void {
128
+ this.propagateWebpackConfig(compiler);
128
129
 
129
130
  compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
130
- this.handleMake(compilation, compiler).catch((error: webpack.WebpackError) => {
131
+ this.handleMake(compilation, compiler).catch((error: WebpackError) => {
131
132
  compilation.errors.push(error);
132
133
  }),
133
134
  );
134
135
 
135
- const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation;
136
+ // webpack should not be null at this point.
137
+ const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;
136
138
  // Specifically hook into thisCompilation, as per
137
139
  // https://github.com/webpack/webpack/issues/11425#issuecomment-690547848
138
140
  compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
@@ -144,7 +146,7 @@ export class InjectManifest {
144
146
  stage: PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 10,
145
147
  },
146
148
  () =>
147
- this.addAssets(compilation).catch((error: webpack.WebpackError) => {
149
+ this.addAssets(compilation).catch((error: WebpackError) => {
148
150
  compilation.errors.push(error);
149
151
  }),
150
152
  );
@@ -157,7 +159,7 @@ export class InjectManifest {
157
159
  *
158
160
  * @private
159
161
  */
160
- async performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void> {
162
+ private async performChildCompilation(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
161
163
  const outputOptions: Parameters<Compilation["createChildCompiler"]>["1"] = {
162
164
  filename: this.config.swDest,
163
165
  };
@@ -174,7 +176,7 @@ export class InjectManifest {
174
176
  }
175
177
  }
176
178
 
177
- 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);
178
180
 
179
181
  await new Promise<void>((resolve, reject) => {
180
182
  childCompiler.runAsChild((error, _entries, childCompilation) => {
@@ -196,10 +198,9 @@ export class InjectManifest {
196
198
  *
197
199
  * @private
198
200
  */
199
- addSrcToAssets(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): void {
200
- // eslint-disable-next-line
201
+ private addSrcToAssets(compilation: Compilation, parentCompiler: Compiler): void {
201
202
  const source = (parentCompiler.inputFileSystem as any).readFileSync(this.config.swSrc);
202
- compilation.emitAsset(this.config.swDest!, new webpack.sources.RawSource(source));
203
+ compilation.emitAsset(this.config.swDest!, new this.webpack.sources.RawSource(source));
203
204
  }
204
205
 
205
206
  /**
@@ -208,7 +209,7 @@ export class InjectManifest {
208
209
  *
209
210
  * @private
210
211
  */
211
- async handleMake(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void> {
212
+ private async handleMake(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
212
213
  this.config = await validateWebpackInjectManifestOptions(this.config);
213
214
  this.config.swDest = relativeToOutputPath(compilation, this.config.swDest!);
214
215
  _generatedAssetNames.add(this.config.swDest);
@@ -220,9 +221,7 @@ export class InjectManifest {
220
221
  // This used to be a fatal error, but just warn at runtime because we
221
222
  // can't validate it easily.
222
223
  if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) {
223
- compilation.warnings.push(
224
- new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored.") as webpack.WebpackError,
225
- );
224
+ compilation.warnings.push(new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored.") as WebpackError);
226
225
  }
227
226
  }
228
227
  }
@@ -232,7 +231,7 @@ export class InjectManifest {
232
231
  *
233
232
  * @private
234
233
  */
235
- async addAssets(compilation: webpack.Compilation): Promise<void> {
234
+ private async addAssets(compilation: Compilation): Promise<void> {
236
235
  const config = Object.assign({}, this.config);
237
236
 
238
237
  const { size, sortedEntries, manifestString } = await this.getManifestEntries(compilation, config);
@@ -270,12 +269,12 @@ export class InjectManifest {
270
269
  searchString: config.injectionPoint!,
271
270
  });
272
271
 
273
- compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
274
- 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));
275
274
  } else {
276
275
  // If there's no sourcemap associated with swDest, a simple string
277
276
  // replacement will suffice.
278
- 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)));
279
278
  }
280
279
 
281
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
- apply(compiler: webpack.Compiler) {
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: webpack.WebpackError) => {
44
+ this.performChildCompilation(compilation, compiler).catch((error: WebpackError) => {
29
45
  compilation.errors.push(error);
30
46
  }),
31
47
  );
32
48
  }
33
- async performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void> {
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
  }