MCPcopy
hub / github.com/webpack/webpack / getLocalIdent

Function getLocalIdent

lib/dependencies/CssIcssExportDependency.js:101–197  ·  view source on GitHub ↗
(local, module, chunkGraph, runtimeTemplate)

Source from the content-addressed store, hash-verified

99 * @returns {string} local ident
100 */
101const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
102 const generator = /** @type {CssGenerator} */ (module.generator);
103 const localIdentName =
104 /** @type {CssGeneratorLocalIdentName} */
105 (generator.options.localIdentName);
106 const relativeResourcePath = makePathsRelative(
107 /** @type {string} */
108 (runtimeTemplate.compilation.compiler.context),
109 /** @type {string} */
110 (module.getResource()),
111 runtimeTemplate.compilation.compiler.root
112 );
113 const { uniqueName } = runtimeTemplate.outputOptions;
114
115 let localIdentHash = "";
116 let localIdentHashFull = "";
117
118 if (generator._localIdentNeedsHash) {
119 const hashSalt = generator.options.localIdentHashSalt;
120 const hashDigest =
121 /** @type {string} */
122 (generator.options.localIdentHashDigest);
123 const hashDigestLength = generator.options.localIdentHashDigestLength;
124 const hashFunction =
125 /** @type {HashFunction} */
126 (generator.options.localIdentHashFunction);
127
128 const hash = createHash(hashFunction);
129
130 if (hashSalt) {
131 hash.update(hashSalt);
132 }
133
134 if (uniqueName) {
135 hash.update(uniqueName);
136 }
137
138 hash.update(relativeResourcePath);
139 hash.update(local);
140
141 // Keep the untruncated digest so an inline `[fullhash:<digest>]` re-encodes
142 // with full entropy (see the `fullHash`/`fullHashDigest` passed below).
143 localIdentHashFull = hash.digest(hashDigest);
144 localIdentHash = localIdentHashFull.slice(0, hashDigestLength);
145 }
146
147 let contentHash = "";
148
149 if (generator._localIdentNeedsContentHash) {
150 const hash = createHash(runtimeTemplate.outputOptions.hashFunction);
151 const source = module.originalSource();
152
153 if (source) {
154 updateHashFromSource(hash, source);
155 }
156
157 if (module.error) {
158 hash.update(module.error.toString());

Callers 1

Calls 11

createHashFunction · 0.85
updateHashFromSourceFunction · 0.85
digestNonNumericOnlyFunction · 0.85
interpolateFunction · 0.85
getResourceMethod · 0.80
sliceMethod · 0.80
updateMethod · 0.45
digestMethod · 0.45
originalSourceMethod · 0.45
toStringMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected