(local, module, chunkGraph, runtimeTemplate)
| 99 | * @returns {string} local ident |
| 100 | */ |
| 101 | const 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()); |
no test coverage detected