UNPKG

webpack-subresource-integrity

Version:
126 lines 4.32 kB
/** * Copyright (c) 2015-present, Waysact Pty Ltd * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import { thisPluginName, standardHashFuncNames } from "./globals"; import { hasOwnProperty } from "./util"; function errorMessage(error) { if (typeof error === "object" && error !== null && hasOwnProperty(error, "message")) { return error.message; } return String(error); } export class Reporter { /** * @internal */ compilation; /** * @internal */ emittedMessages = new Set(); /** * @internal */ constructor(compilation) { this.compilation = compilation; } /** * @internal */ emitMessage(messages, message) { messages.push(new Error(`${thisPluginName}: ${message}`)); } /** * @internal */ emitMessageOnce(messages, message) { if (!this.emittedMessages.has(message)) { this.emittedMessages.add(message); this.emitMessage(messages, message); } } /** * @internal */ warnOnce(message) { this.emitMessageOnce(this.compilation.warnings, message); } /** * @internal */ errorOnce(message) { this.emitMessageOnce(this.compilation.errors, message); } /** * @internal */ error(message) { this.emitMessage(this.compilation.errors, message); } warnHotReloading() { this.warnOnce("webpack-subresource-integrity may interfere with hot reloading. " + "Consider disabling this plugin in development mode."); } warnContentHash() { this.warnOnce("Using [hash], [fullhash], [modulehash], or [chunkhash] is dangerous \ with SRI. The same is true for [contenthash] when realContentHash is disabled. \ Use [contenthash] and ensure realContentHash is enabled. See the README for \ more information."); } warnNoAssetsFound(sourcePath, assetNames) { this.warnOnce(`No asset found for source path '${sourcePath}', options are ${assetNames.join(", ")}`); } errorCrossOriginLoadingNotSet() { this.errorOnce("webpack option output.crossOriginLoading not set, code splitting will not work!"); } warnStandardHashFuncs() { this.warnOnce("It is recommended that at least one hash function is part of the set " + "for which support is mandated by the specification. " + "These are: " + standardHashFuncNames.join(", ") + ". " + "See http://www.w3.org/TR/SRI/#cryptographic-hash-functions for more information."); } errorInvalidHashLoading(hashLoading, supportedHashLoadingOptions) { const optionsStr = supportedHashLoadingOptions .map((opt) => `'${opt}'`) .join(", "); this.error(`options.hashLoading must be one of ${optionsStr}, instead got '${hashLoading}'`); } warnCrossOriginPolicy() { this.warnOnce('SRI requires a cross-origin policy, defaulting to "anonymous". ' + "Set webpack option output.crossOriginLoading to a value other than false " + "to make this warning go away. " + "See https://w3c.github.io/webappsec-subresource-integrity/#cross-origin-data-leakage"); } errorNonStringHashFunc(hashFuncName) { this.error("options.hashFuncNames must be an array of hash function names, " + "but contained " + hashFuncName + "."); } errorUnusableHashFunc(hashFuncName, error) { this.error("Cannot use hash function '" + hashFuncName + "': " + errorMessage(error)); } errorHashFuncsNonArray(hashFuncNames) { this.error("options.hashFuncNames must be an array of hash function names, " + "instead got '" + hashFuncNames + "'."); } errorHashFuncsEmpty() { this.error("Must specify at least one hash function name."); } warnNonWeb() { this.warnOnce("This plugin is not useful for non-web targets."); } errorUnresolvedIntegrity(chunkFile) { this.errorOnce(`Asset ${chunkFile} contains unresolved integrity placeholders`); } } //# sourceMappingURL=reporter.js.map