MCPcopy
hub / github.com/webpack/webpack / needBuild

Method needBuild

lib/NormalModule.js:2140–2192  ·  lib/NormalModule.js::NormalModule.needBuild

* Checks whether the module needs to be rebuilt for the current build state. * @param {NeedBuildContext} context context info * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void}

(context, callback)

Source from the content-addressed store, hash-verified

2138 * @returns {void}
2139 */
2140 needBuild(context, callback) {
2141 const { fileSystemInfo, compilation, valueCacheVersions } = context;
2142 class="cm">// build if enforced
2143 if (this._forceBuild) return callback(null, true);
2144
2145 class="cm">// always try to build in case of an error
2146 if (this.error) return callback(null, true);
2147
2148 const { cacheable, snapshot, valueDependencies } =
2149 /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
2150
2151 class="cm">// always build when module is not cacheable
2152 if (!cacheable) return callback(null, true);
2153
2154 class="cm">// build when there is no snapshot to check
2155 if (!snapshot) return callback(null, true);
2156
2157 class="cm">// build when valueDependencies have changed
2158 if (valueDependencies) {
2159 if (!valueCacheVersions) return callback(null, true);
2160 for (const [key, value] of valueDependencies) {
2161 if (value === undefined) return callback(null, true);
2162 const current = valueCacheVersions.get(key);
2163 if (
2164 value !== current &&
2165 (typeof value === class="st">"string" ||
2166 typeof current === class="st">"string" ||
2167 current === undefined ||
2168 !isSubset(value, current))
2169 ) {
2170 return callback(null, true);
2171 }
2172 }
2173 }
2174
2175 class="cm">// check snapshot for validity
2176 fileSystemInfo.checkSnapshotValid(snapshot, (err, valid) => {
2177 if (err) return callback(err);
2178 if (!valid) return callback(null, true);
2179 const hooks = NormalModule.getCompilationHooks(compilation);
2180 hooks.needBuild.callAsync(this, context, (err, needBuild) => {
2181 if (err) {
2182 return callback(
2183 HookWebpackError.makeWebpackError(
2184 err,
2185 class="st">"NormalModule.getCompilationHooks().needBuild"
2186 )
2187 );
2188 }
2189 callback(null, Boolean(needBuild));
2190 });
2191 });
2192 }
2193
2194 /**
2195 * Returns the estimated size for the requested source type.

Callers

nothing calls this directly

Calls 5

isSubsetFunction · 0.85
checkSnapshotValidMethod · 0.80
callbackFunction · 0.50
getMethod · 0.45
getCompilationHooksMethod · 0.45

Tested by

no test coverage detected