File tree Expand file tree Collapse file tree 6 files changed +52
-1
lines changed
test/configCases/loaders/hash-in-context Expand file tree Collapse file tree 6 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,13 @@ import type {
1414 ImportModuleOptions
1515} from "../lib/dependencies/LoaderPlugin" ;
1616import type { Resolver } from "enhanced-resolve" ;
17- import type { Environment } from "./WebpackOptions" ;
17+ import type {
18+ Environment ,
19+ HashDigestLength ,
20+ HashSalt ,
21+ HashDigest ,
22+ HashFunction
23+ } from "./WebpackOptions" ;
1824
1925type ResolveCallback = Parameters < Resolver [ "resolve" ] > [ 4 ] ;
2026type Schema = Parameters < typeof validate > [ 0 ] ;
@@ -49,6 +55,10 @@ export interface NormalModuleLoaderContext<OptionsType> {
4955 sourceMap ?: boolean ;
5056 mode : "development" | "production" | "none" ;
5157 webpack ?: boolean ;
58+ hashFunction : HashFunction ,
59+ hashDigest : HashDigest ,
60+ hashDigestLength : HashDigestLength ,
61+ hashSalt : HashSalt ,
5262 _module ?: NormalModule ;
5363 _compilation ?: Compilation ;
5464 _compiler ?: Compiler ;
Original file line number Diff line number Diff line change @@ -777,6 +777,10 @@ class NormalModule extends Module {
777777 webpack : true ,
778778 sourceMap : Boolean ( this . useSourceMap ) ,
779779 mode : options . mode || "production" ,
780+ hashFunction : options . output . hashFunction ,
781+ hashDigest : options . output . hashDigest ,
782+ hashDigestLength : options . output . hashDigestLength ,
783+ hashSalt : options . output . hashSalt ,
780784 _module : this ,
781785 _compilation : compilation ,
782786 _compiler : compilation . compiler ,
Original file line number Diff line number Diff line change 1+ it ( "should have hmr flag in loader context" , function ( ) {
2+ expect ( require ( "./loader!" ) ) . toMatchObject ( {
3+ digest : "a0fdc3d2f3863f64d95950fc06af72f7" ,
4+ digestWithLength : "a0fdc3d2f3863f64d959" ,
5+ hashFunction : "md4" ,
6+ hashDigest : "hex" ,
7+ hashDigestLength : 20 ,
8+ hashSalt : "salt" ,
9+ } ) ;
10+ } ) ;
Original file line number Diff line number Diff line change 1+ /** @type {import("../../../../").LoaderDefinition }} */
2+ module . exports = function ( ) {
3+ const hashValue = this . utils . createHash ( this . hashFunction ) ;
4+ hashValue . update ( this . hashSalt ) ;
5+ hashValue . update ( "test" ) ;
6+ const digest = hashValue . digest ( this . hashDigest ) ;
7+
8+ return `module.exports = ${ JSON . stringify ( {
9+ digest,
10+ digestWithLength : digest . slice ( 0 , this . hashDigestLength ) ,
11+ hashFunction : this . hashFunction ,
12+ hashDigest : this . hashDigest ,
13+ hashDigestLength : this . hashDigestLength ,
14+ hashSalt : this . hashSalt
15+ } ) } ;`;
16+ } ;
Original file line number Diff line number Diff line change 1+ /** @type {import("../../../../").Configuration[] } */
2+ module . exports = {
3+ output : {
4+ hashSalt : "salt"
5+ }
6+ } ;
Original file line number Diff line number Diff line change @@ -5205,6 +5205,7 @@ declare class Hash {
52055205 */
52065206 digest ( encoding ?: string ) : string | Buffer ;
52075207}
5208+ type HashFunction = string | typeof Hash ;
52085209declare interface HashableObject {
52095210 updateHash : ( arg0 : Hash ) => void ;
52105211}
@@ -9380,6 +9381,10 @@ declare interface NormalModuleLoaderContext<OptionsType> {
93809381 sourceMap ?: boolean ;
93819382 mode : "none" | "development" | "production" ;
93829383 webpack ?: boolean ;
9384+ hashFunction : HashFunction ;
9385+ hashDigest : string ;
9386+ hashDigestLength : number ;
9387+ hashSalt : string ;
93839388 _module ?: NormalModule ;
93849389 _compilation ?: Compilation ;
93859390 _compiler ?: Compiler ;
You can’t perform that action at this time.
0 commit comments