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 {
14
14
ImportModuleOptions
15
15
} from "../lib/dependencies/LoaderPlugin" ;
16
16
import 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" ;
18
24
19
25
type ResolveCallback = Parameters < Resolver [ "resolve" ] > [ 4 ] ;
20
26
type Schema = Parameters < typeof validate > [ 0 ] ;
@@ -49,6 +55,10 @@ export interface NormalModuleLoaderContext<OptionsType> {
49
55
sourceMap ?: boolean ;
50
56
mode : "development" | "production" | "none" ;
51
57
webpack ?: boolean ;
58
+ hashFunction : HashFunction ,
59
+ hashDigest : HashDigest ,
60
+ hashDigestLength : HashDigestLength ,
61
+ hashSalt : HashSalt ,
52
62
_module ?: NormalModule ;
53
63
_compilation ?: Compilation ;
54
64
_compiler ?: Compiler ;
Original file line number Diff line number Diff line change @@ -777,6 +777,10 @@ class NormalModule extends Module {
777
777
webpack : true ,
778
778
sourceMap : Boolean ( this . useSourceMap ) ,
779
779
mode : options . mode || "production" ,
780
+ hashFunction : options . output . hashFunction ,
781
+ hashDigest : options . output . hashDigest ,
782
+ hashDigestLength : options . output . hashDigestLength ,
783
+ hashSalt : options . output . hashSalt ,
780
784
_module : this ,
781
785
_compilation : compilation ,
782
786
_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 {
5205
5205
*/
5206
5206
digest ( encoding ?: string ) : string | Buffer ;
5207
5207
}
5208
+ type HashFunction = string | typeof Hash ;
5208
5209
declare interface HashableObject {
5209
5210
updateHash : ( arg0 : Hash ) => void ;
5210
5211
}
@@ -9380,6 +9381,10 @@ declare interface NormalModuleLoaderContext<OptionsType> {
9380
9381
sourceMap ?: boolean ;
9381
9382
mode : "none" | "development" | "production" ;
9382
9383
webpack ?: boolean ;
9384
+ hashFunction : HashFunction ;
9385
+ hashDigest : string ;
9386
+ hashDigestLength : number ;
9387
+ hashSalt : string ;
9383
9388
_module ?: NormalModule ;
9384
9389
_compilation ?: Compilation ;
9385
9390
_compiler ?: Compiler ;
You can’t perform that action at this time.
0 commit comments