@serwist/webpack-plugin
Advanced tools
Comparing version 9.0.0-preview.10 to 9.0.0-preview.11
@@ -1,2 +0,1 @@ | ||
import webpack from 'webpack'; | ||
import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js'; | ||
@@ -9,2 +8,3 @@ import 'upath'; | ||
plugins; | ||
webpack; | ||
constructor({ src, dest, plugins }){ | ||
@@ -14,4 +14,9 @@ this.src = src; | ||
this.plugins = plugins; | ||
this.webpack = null; | ||
} | ||
propagateWebpackConfig(compiler) { | ||
this.webpack = compiler.webpack; | ||
} | ||
apply(compiler) { | ||
this.propagateWebpackConfig(compiler); | ||
compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.performChildCompilation(compilation, compiler).catch((error)=>{ | ||
@@ -35,3 +40,3 @@ compilation.errors.push(error); | ||
} | ||
new webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler); | ||
new this.webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler); | ||
await new Promise((resolve, reject)=>{ | ||
@@ -38,0 +43,0 @@ childCompiler.runAsChild((error, _entries, childCompilation)=>{ |
@@ -5,3 +5,2 @@ import { transformManifest, getSourceMapURL, validateWebpackInjectManifestOptions, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build'; | ||
import upath from 'upath'; | ||
import webpack from 'webpack'; | ||
import crypto from 'crypto'; | ||
@@ -35,3 +34,3 @@ import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js'; | ||
} | ||
if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) { | ||
if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) { | ||
return true; | ||
@@ -156,11 +155,15 @@ } | ||
alreadyCalled; | ||
webpack; | ||
constructor(config){ | ||
this.config = config; | ||
this.alreadyCalled = false; | ||
this.webpack = null; | ||
} | ||
propagateWebpackConfig() { | ||
propagateWebpackConfig(compiler) { | ||
this.webpack = compiler.webpack; | ||
const parsedSwSrc = upath.parse(this.config.swSrc); | ||
this.config = Object.assign({ | ||
swDest: `${parsedSwSrc.name}.js` | ||
}, this.config); | ||
this.config = { | ||
swDest: `${parsedSwSrc.name}.js`, | ||
...this.config | ||
}; | ||
} | ||
@@ -196,7 +199,7 @@ async getManifestEntries(compilation, config) { | ||
apply(compiler) { | ||
this.propagateWebpackConfig(); | ||
this.propagateWebpackConfig(compiler); | ||
compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.handleMake(compilation, compiler).catch((error)=>{ | ||
compilation.errors.push(error); | ||
})); | ||
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation; | ||
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation; | ||
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation)=>{ | ||
@@ -224,3 +227,3 @@ compilation.hooks.processAssets.tapPromise({ | ||
} | ||
new webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler); | ||
new this.webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler); | ||
await new Promise((resolve, reject)=>{ | ||
@@ -240,3 +243,3 @@ childCompiler.runAsChild((error, _entries, childCompilation)=>{ | ||
const source = parentCompiler.inputFileSystem.readFileSync(this.config.swSrc); | ||
compilation.emitAsset(this.config.swDest, new webpack.sources.RawSource(source)); | ||
compilation.emitAsset(this.config.swDest, new this.webpack.sources.RawSource(source)); | ||
} | ||
@@ -282,6 +285,6 @@ async handleMake(compilation, parentCompiler) { | ||
}); | ||
compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map)); | ||
compilation.updateAsset(config.swDest, new webpack.sources.RawSource(source)); | ||
compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map)); | ||
compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(source)); | ||
} else { | ||
compilation.updateAsset(config.swDest, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString))); | ||
compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString))); | ||
} | ||
@@ -288,0 +291,0 @@ if (compilation.getLogger) { |
import type { WebpackInjectManifestOptions } from "@serwist/build"; | ||
import webpack from "webpack"; | ||
import type { Compiler } from "webpack"; | ||
/** | ||
@@ -28,2 +28,3 @@ * This class supports compiling a service worker file provided via `swSrc`, | ||
private alreadyCalled; | ||
private webpack; | ||
/** | ||
@@ -38,3 +39,3 @@ * Creates an instance of InjectManifest. | ||
*/ | ||
propagateWebpackConfig(): void; | ||
private propagateWebpackConfig; | ||
/** | ||
@@ -45,11 +46,3 @@ * `getManifestEntriesFromCompilation` with a few additional checks. | ||
*/ | ||
getManifestEntries(compilation: webpack.Compilation, config: WebpackInjectManifestOptions): Promise<{ | ||
size: number; | ||
sortedEntries: { | ||
revision: string | null; | ||
url: string; | ||
integrity?: string | undefined; | ||
}[] | undefined; | ||
manifestString: string; | ||
}>; | ||
private getManifestEntries; | ||
/** | ||
@@ -60,3 +53,3 @@ * @param compiler default compiler object passed from webpack | ||
*/ | ||
apply(compiler: webpack.Compiler): void; | ||
apply(compiler: Compiler): void; | ||
/** | ||
@@ -68,3 +61,3 @@ * @param compilation The webpack compilation. | ||
*/ | ||
performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>; | ||
private performChildCompilation; | ||
/** | ||
@@ -76,3 +69,3 @@ * @param compilation The webpack compilation. | ||
*/ | ||
addSrcToAssets(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): void; | ||
private addSrcToAssets; | ||
/** | ||
@@ -84,3 +77,3 @@ * @param compilation The webpack compilation. | ||
*/ | ||
handleMake(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>; | ||
private handleMake; | ||
/** | ||
@@ -91,4 +84,4 @@ * @param compilation The webpack compilation. | ||
*/ | ||
addAssets(compilation: webpack.Compilation): Promise<void>; | ||
private addAssets; | ||
} | ||
//# sourceMappingURL=inject-manifest.d.ts.map |
@@ -1,3 +0,2 @@ | ||
import type { WebpackPluginInstance } from "webpack"; | ||
import webpack from "webpack"; | ||
import type { Compiler, WebpackPluginInstance, default as Webpack } from "webpack"; | ||
export interface ChildCompilationPluginOptions { | ||
@@ -17,6 +16,24 @@ src: string; | ||
plugins: WebpackPluginInstance[] | undefined; | ||
webpack: typeof Webpack; | ||
constructor({ src, dest, plugins }: ChildCompilationPluginOptions); | ||
apply(compiler: webpack.Compiler): void; | ||
performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>; | ||
/** | ||
* @param compiler default compiler object passed from webpack | ||
* | ||
* @private | ||
*/ | ||
private propagateWebpackConfig; | ||
/** | ||
* @param compiler default compiler object passed from webpack | ||
* | ||
* @private | ||
*/ | ||
apply(compiler: Compiler): void; | ||
/** | ||
* @param compilation The webpack compilation. | ||
* @param parentCompiler The webpack parent compiler. | ||
* | ||
* @private | ||
*/ | ||
private performChildCompilation; | ||
} | ||
//# sourceMappingURL=child-compilation-plugin.d.ts.map |
{ | ||
"name": "@serwist/webpack-plugin", | ||
"version": "9.0.0-preview.10", | ||
"version": "9.0.0-preview.11", | ||
"type": "module", | ||
@@ -52,3 +52,3 @@ "description": "A plugin for your Webpack build process, helping you generate a manifest of local files that should be precached.", | ||
"upath": "2.0.1", | ||
"@serwist/build": "9.0.0-preview.10" | ||
"@serwist/build": "9.0.0-preview.11" | ||
}, | ||
@@ -61,3 +61,3 @@ "devDependencies": { | ||
"webpack": "5.90.1", | ||
"@serwist/constants": "9.0.0-preview.10" | ||
"@serwist/constants": "9.0.0-preview.11" | ||
}, | ||
@@ -71,2 +71,5 @@ "peerDependencies": { | ||
"optional": true | ||
}, | ||
"webpack": { | ||
"optional": true | ||
} | ||
@@ -73,0 +76,0 @@ }, |
@@ -13,4 +13,3 @@ /* | ||
import upath from "upath"; | ||
import type { Compilation } from "webpack"; | ||
import webpack from "webpack"; | ||
import type { Compilation, Compiler, WebpackError, default as Webpack } from "webpack"; | ||
@@ -50,2 +49,3 @@ import { getManifestEntriesFromCompilation } from "./lib/get-manifest-entries-from-compilation.js"; | ||
private alreadyCalled: boolean; | ||
private webpack: typeof Webpack; | ||
@@ -58,2 +58,3 @@ /** | ||
this.alreadyCalled = false; | ||
this.webpack = null!; | ||
} | ||
@@ -66,13 +67,13 @@ | ||
*/ | ||
propagateWebpackConfig(): void { | ||
private propagateWebpackConfig(compiler: Compiler): void { | ||
this.webpack = compiler.webpack; | ||
const parsedSwSrc = upath.parse(this.config.swSrc); | ||
// Because this.config is listed last, properties that are already set | ||
// there take precedence over derived properties from the compiler. | ||
this.config = Object.assign( | ||
{ | ||
// Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file. | ||
swDest: `${parsedSwSrc.name}.js`, | ||
}, | ||
this.config, | ||
); | ||
this.config = { | ||
// Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file. | ||
swDest: `${parsedSwSrc.name}.js`, | ||
...this.config, | ||
}; | ||
} | ||
@@ -85,3 +86,3 @@ | ||
*/ | ||
async getManifestEntries(compilation: webpack.Compilation, config: WebpackInjectManifestOptions) { | ||
private async getManifestEntries(compilation: Compilation, config: WebpackInjectManifestOptions) { | ||
if (config.disablePrecacheManifest) { | ||
@@ -100,3 +101,3 @@ return { | ||
if (!compilation.warnings.some((warning) => warning instanceof Error && warning.message === warningMessage)) { | ||
compilation.warnings.push(new Error(warningMessage) as webpack.WebpackError); | ||
compilation.warnings.push(new Error(warningMessage) as WebpackError); | ||
} | ||
@@ -132,7 +133,7 @@ } else { | ||
*/ | ||
apply(compiler: webpack.Compiler): void { | ||
this.propagateWebpackConfig(); | ||
apply(compiler: Compiler): void { | ||
this.propagateWebpackConfig(compiler); | ||
compiler.hooks.make.tapPromise(this.constructor.name, (compilation) => | ||
this.handleMake(compilation, compiler).catch((error: webpack.WebpackError) => { | ||
this.handleMake(compilation, compiler).catch((error: WebpackError) => { | ||
compilation.errors.push(error); | ||
@@ -142,3 +143,4 @@ }), | ||
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation; | ||
// webpack should not be null at this point. | ||
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation; | ||
// Specifically hook into thisCompilation, as per | ||
@@ -155,3 +157,3 @@ // https://github.com/webpack/webpack/issues/11425#issuecomment-690547848 | ||
() => | ||
this.addAssets(compilation).catch((error: webpack.WebpackError) => { | ||
this.addAssets(compilation).catch((error: WebpackError) => { | ||
compilation.errors.push(error); | ||
@@ -169,3 +171,3 @@ }), | ||
*/ | ||
async performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void> { | ||
private async performChildCompilation(compilation: Compilation, parentCompiler: Compiler): Promise<void> { | ||
const outputOptions: Parameters<Compilation["createChildCompiler"]>["1"] = { | ||
@@ -187,3 +189,3 @@ filename: this.config.swDest, | ||
new webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler); | ||
new this.webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler); | ||
@@ -210,6 +212,5 @@ await new Promise<void>((resolve, reject) => { | ||
*/ | ||
addSrcToAssets(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): void { | ||
// eslint-disable-next-line | ||
private addSrcToAssets(compilation: Compilation, parentCompiler: Compiler): void { | ||
const source = (parentCompiler.inputFileSystem as any).readFileSync(this.config.swSrc); | ||
compilation.emitAsset(this.config.swDest!, new webpack.sources.RawSource(source)); | ||
compilation.emitAsset(this.config.swDest!, new this.webpack.sources.RawSource(source)); | ||
} | ||
@@ -223,3 +224,3 @@ | ||
*/ | ||
async handleMake(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void> { | ||
private async handleMake(compilation: Compilation, parentCompiler: Compiler): Promise<void> { | ||
this.config = await validateWebpackInjectManifestOptions(this.config); | ||
@@ -236,5 +237,3 @@ this.config.swDest = relativeToOutputPath(compilation, this.config.swDest!); | ||
if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) { | ||
compilation.warnings.push( | ||
new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored.") as webpack.WebpackError, | ||
); | ||
compilation.warnings.push(new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored.") as WebpackError); | ||
} | ||
@@ -249,3 +248,3 @@ } | ||
*/ | ||
async addAssets(compilation: webpack.Compilation): Promise<void> { | ||
private async addAssets(compilation: Compilation): Promise<void> { | ||
const config = Object.assign({}, this.config); | ||
@@ -288,8 +287,8 @@ | ||
compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map)); | ||
compilation.updateAsset(config.swDest!, new webpack.sources.RawSource(source)); | ||
compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map)); | ||
compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(source)); | ||
} else { | ||
// If there's no sourcemap associated with swDest, a simple string | ||
// replacement will suffice. | ||
compilation.updateAsset(config.swDest!, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint!, manifestString))); | ||
compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint!, manifestString))); | ||
} | ||
@@ -296,0 +295,0 @@ |
@@ -1,3 +0,2 @@ | ||
import type { Compilation, WebpackPluginInstance } from "webpack"; | ||
import webpack from "webpack"; | ||
import type { Compilation, Compiler, WebpackError, WebpackPluginInstance, default as Webpack } from "webpack"; | ||
@@ -21,2 +20,3 @@ import { relativeToOutputPath } from "./relative-to-output-path.js"; | ||
plugins: WebpackPluginInstance[] | undefined; | ||
webpack: typeof Webpack; | ||
constructor({ src, dest, plugins }: ChildCompilationPluginOptions) { | ||
@@ -26,6 +26,22 @@ this.src = src; | ||
this.plugins = plugins; | ||
this.webpack = null!; | ||
} | ||
apply(compiler: webpack.Compiler) { | ||
/** | ||
* @param compiler default compiler object passed from webpack | ||
* | ||
* @private | ||
*/ | ||
private propagateWebpackConfig(compiler: Compiler): void { | ||
this.webpack = compiler.webpack; | ||
} | ||
/** | ||
* @param compiler default compiler object passed from webpack | ||
* | ||
* @private | ||
*/ | ||
apply(compiler: Compiler) { | ||
this.propagateWebpackConfig(compiler); | ||
compiler.hooks.make.tapPromise(this.constructor.name, (compilation) => | ||
this.performChildCompilation(compilation, compiler).catch((error: webpack.WebpackError) => { | ||
this.performChildCompilation(compilation, compiler).catch((error: WebpackError) => { | ||
compilation.errors.push(error); | ||
@@ -35,3 +51,9 @@ }), | ||
} | ||
async performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void> { | ||
/** | ||
* @param compilation The webpack compilation. | ||
* @param parentCompiler The webpack parent compiler. | ||
* | ||
* @private | ||
*/ | ||
private async performChildCompilation(compilation: Compilation, parentCompiler: Compiler): Promise<void> { | ||
const resolvedDest = relativeToOutputPath(compilation, this.dest); | ||
@@ -54,3 +76,3 @@ const outputOptions: Parameters<Compilation["createChildCompiler"]>["1"] = { | ||
new webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler); | ||
new this.webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler); | ||
@@ -57,0 +79,0 @@ await new Promise<void>((resolve, reject) => { |
@@ -12,3 +12,2 @@ /* | ||
import type { Asset, Chunk, Compilation, WebpackError } from "webpack"; | ||
import webpack from "webpack"; | ||
@@ -40,3 +39,3 @@ import { getAssetHash } from "./get-asset-hash.js"; | ||
} | ||
if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) { | ||
if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) { | ||
return true; | ||
@@ -43,0 +42,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54996
1190
+ Added@serwist/background-sync@9.0.0-preview.11(transitive)
+ Added@serwist/broadcast-update@9.0.0-preview.11(transitive)
+ Added@serwist/build@9.0.0-preview.11(transitive)
+ Added@serwist/cacheable-response@9.0.0-preview.11(transitive)
+ Added@serwist/core@9.0.0-preview.11(transitive)
+ Added@serwist/expiration@9.0.0-preview.11(transitive)
+ Added@serwist/google-analytics@9.0.0-preview.11(transitive)
+ Added@serwist/precaching@9.0.0-preview.11(transitive)
+ Added@serwist/routing@9.0.0-preview.11(transitive)
+ Added@serwist/strategies@9.0.0-preview.11(transitive)
- Removed@serwist/background-sync@9.0.0-preview.10(transitive)
- Removed@serwist/broadcast-update@9.0.0-preview.10(transitive)
- Removed@serwist/build@9.0.0-preview.10(transitive)
- Removed@serwist/cacheable-response@9.0.0-preview.10(transitive)
- Removed@serwist/core@9.0.0-preview.10(transitive)
- Removed@serwist/expiration@9.0.0-preview.10(transitive)
- Removed@serwist/google-analytics@9.0.0-preview.10(transitive)
- Removed@serwist/precaching@9.0.0-preview.10(transitive)
- Removed@serwist/routing@9.0.0-preview.10(transitive)
- Removed@serwist/strategies@9.0.0-preview.10(transitive)