Skip to content

Commit

Permalink
Merge branch 'main' into feature/errors-warnings-space
Browse files Browse the repository at this point in the history
# Conflicts:
#	schemas/WebpackOptions.check.js
  • Loading branch information
vankop committed Feb 28, 2022
2 parents 55f0535 + d77b8dd commit 022cabe
Show file tree
Hide file tree
Showing 34 changed files with 545 additions and 92 deletions.
6 changes: 5 additions & 1 deletion declarations/WebpackOptions.d.ts
Expand Up @@ -681,7 +681,7 @@ export type AssetGeneratorDataUrl =
| AssetGeneratorDataUrlOptions
| AssetGeneratorDataUrlFunction;
/**
* Function that executes for module and should return an DataUrl string.
* Function that executes for module and should return an DataUrl string. It can have a string as 'ident' property which contributes to the module hash.
*/
export type AssetGeneratorDataUrlFunction = (
source: string | Buffer,
Expand Down Expand Up @@ -2908,6 +2908,10 @@ export interface HttpUriOptions {
* Location of the lockfile.
*/
lockfileLocation?: string;
/**
* Proxy configuration, which can be used to specify a proxy server to use for HTTP requests.
*/
proxy?: string;
/**
* When set, resources of existing lockfile entries will be fetched and entries will be upgraded when resource content has changed.
*/
Expand Down
4 changes: 4 additions & 0 deletions declarations/plugins/schemes/HttpUriPlugin.d.ts
Expand Up @@ -34,6 +34,10 @@ export interface HttpUriOptions {
* Location of the lockfile.
*/
lockfileLocation?: string;
/**
* Proxy configuration, which can be used to specify a proxy server to use for HTTP requests.
*/
proxy?: string;
/**
* When set, resources of existing lockfile entries will be fetched and entries will be upgraded when resource content has changed.
*/
Expand Down
58 changes: 41 additions & 17 deletions lib/Compilation.js
Expand Up @@ -43,6 +43,7 @@ const Module = require("./Module");
const ModuleDependencyError = require("./ModuleDependencyError");
const ModuleDependencyWarning = require("./ModuleDependencyWarning");
const ModuleGraph = require("./ModuleGraph");
const ModuleHashingError = require("./ModuleHashingError");
const ModuleNotFoundError = require("./ModuleNotFoundError");
const ModuleProfile = require("./ModuleProfile");
const ModuleRestoreError = require("./ModuleRestoreError");
Expand Down Expand Up @@ -3883,6 +3884,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
let statModulesFromCache = 0;
const { chunkGraph, runtimeTemplate, moduleMemCaches2 } = this;
const { hashFunction, hashDigest, hashDigestLength } = this.outputOptions;
const errors = [];
for (const module of this.modules) {
const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
for (const runtime of chunkGraph.getModuleRuntimes(module)) {
Expand All @@ -3907,13 +3909,20 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
hashFunction,
runtimeTemplate,
hashDigest,
hashDigestLength
hashDigestLength,
errors
);
if (memCache) {
memCache.set(`moduleHash-${getRuntimeKey(runtime)}`, digest);
}
}
}
if (errors.length > 0) {
errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
for (const error of errors) {
this.errors.push(error);
}
}
this.logger.log(
`${statModulesHashed} modules hashed, ${statModulesFromCache} from cache (${
Math.round(
Expand All @@ -3930,17 +3939,22 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
hashFunction,
runtimeTemplate,
hashDigest,
hashDigestLength
hashDigestLength,
errors
) {
const moduleHash = createHash(hashFunction);
module.updateHash(moduleHash, {
chunkGraph,
runtime,
runtimeTemplate
});
const moduleHashDigest = /** @type {string} */ (
moduleHash.digest(hashDigest)
);
let moduleHashDigest;
try {
const moduleHash = createHash(hashFunction);
module.updateHash(moduleHash, {
chunkGraph,
runtime,
runtimeTemplate
});
moduleHashDigest = /** @type {string} */ (moduleHash.digest(hashDigest));
} catch (err) {
errors.push(new ModuleHashingError(module, err));
moduleHashDigest = "XXXXXX";
}
chunkGraph.setModuleHashes(
module,
runtime,
Expand Down Expand Up @@ -4091,6 +4105,7 @@ This prevents using hashes of each other and should be avoided.`);
const codeGenerationJobs = [];
/** @type {Map<string, Map<Module, {module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}>>} */
const codeGenerationJobsMap = new Map();
const errors = [];

const processChunk = chunk => {
// Last minute module hash generation for modules that depend on chunk hashes
Expand All @@ -4105,7 +4120,8 @@ This prevents using hashes of each other and should be avoided.`);
hashFunction,
runtimeTemplate,
hashDigest,
hashDigestLength
hashDigestLength,
errors
);
let hashMap = codeGenerationJobsMap.get(hash);
if (hashMap) {
Expand All @@ -4129,9 +4145,9 @@ This prevents using hashes of each other and should be avoided.`);
}
}
this.logger.timeAggregate("hashing: hash runtime modules");
this.logger.time("hashing: hash chunks");
const chunkHash = createHash(hashFunction);
try {
this.logger.time("hashing: hash chunks");
const chunkHash = createHash(hashFunction);
if (outputOptions.hashSalt) {
chunkHash.update(outputOptions.hashSalt);
}
Expand Down Expand Up @@ -4162,6 +4178,12 @@ This prevents using hashes of each other and should be avoided.`);
};
otherChunks.forEach(processChunk);
for (const chunk of runtimeChunks) processChunk(chunk);
if (errors.length > 0) {
errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
for (const error of errors) {
this.errors.push(error);
}
}

this.logger.timeAggregateEnd("hashing: hash runtime modules");
this.logger.timeAggregateEnd("hashing: hash chunks");
Expand Down Expand Up @@ -4801,6 +4823,9 @@ This prevents using hashes of each other and should be avoided.`);
chunkGraph.connectChunkAndModule(chunk, module);
}

/** @type {WebpackError[]} */
const errors = [];

// Hash modules
for (const module of modules) {
this._createModuleHash(
Expand All @@ -4810,15 +4835,14 @@ This prevents using hashes of each other and should be avoided.`);
hashFunction,
runtimeTemplate,
hashDigest,
hashDigestLength
hashDigestLength,
errors
);
}

const codeGenerationResults = new CodeGenerationResults(
this.outputOptions.hashFunction
);
/** @type {WebpackError[]} */
const errors = [];
/**
* @param {Module} module the module
* @param {Callback} callback callback
Expand Down
1 change: 1 addition & 0 deletions lib/Generator.js
Expand Up @@ -38,6 +38,7 @@
* @property {NormalModule} module the module
* @property {ChunkGraph} chunkGraph
* @property {RuntimeSpec} runtime
* @property {RuntimeTemplate=} runtimeTemplate
*/

/**
Expand Down
29 changes: 29 additions & 0 deletions lib/ModuleHashingError.js
@@ -0,0 +1,29 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/

"use strict";

const WebpackError = require("./WebpackError");

/** @typedef {import("./Module")} Module */

class ModuleHashingError extends WebpackError {
/**
* Create a new ModuleHashingError
* @param {Module} module related module
* @param {Error} error Original error
*/
constructor(module, error) {
super();

this.name = "ModuleHashingError";
this.error = error;
this.message = error.message;
this.details = error.stack;
this.module = module;
}
}

module.exports = ModuleHashingError;
7 changes: 3 additions & 4 deletions lib/ProgressPlugin.js
Expand Up @@ -531,15 +531,14 @@ class ProgressPlugin {
}
});
interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
compiler.hooks.initialize.intercept({
compiler.hooks.beforeRun.intercept({
name: "ProgressPlugin",
call() {
handler(0, "");
}
});
interceptHook(compiler.hooks.initialize, 0.01, "setup", "initialize");
interceptHook(compiler.hooks.beforeRun, 0.02, "setup", "before run");
interceptHook(compiler.hooks.run, 0.03, "setup", "run");
interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run");
interceptHook(compiler.hooks.run, 0.02, "setup", "run");
interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");
interceptHook(
compiler.hooks.normalModuleFactory,
Expand Down
1 change: 1 addition & 0 deletions lib/RuntimeTemplate.js
Expand Up @@ -83,6 +83,7 @@ class RuntimeTemplate {
this.outputOptions = outputOptions || {};
this.requestShortener = requestShortener;
this.globalObject = getGlobalObject(outputOptions.globalObject);
this.contentHashReplacement = "X".repeat(outputOptions.hashDigestLength);
}

isIIFE() {
Expand Down

0 comments on commit 022cabe

Please sign in to comment.