webpack-subresource-integrity
Version:
Webpack plugin for enabling Subresource Integrity
126 lines • 4.41 kB
JavaScript
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Reporter = void 0;
const globals_1 = require("./globals");
const util_1 = require("./util");
function errorMessage(error) {
if (typeof error === "object" &&
error !== null &&
(0, util_1.hasOwnProperty)(error, "message")) {
return error.message;
}
return String(error);
}
class Reporter {
/**
* @internal
*/
constructor(compilation) {
/**
* @internal
*/
this.emittedMessages = new Set();
this.compilation = compilation;
}
/**
* @internal
*/
emitMessage(messages, message) {
messages.push(new Error(`${globals_1.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: " +
globals_1.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`);
}
}
exports.Reporter = Reporter;
//# sourceMappingURL=reporter.js.map
;