@@ -71,18 +71,31 @@ const validate = createSchemaValidation(
71
71
}
72
72
) ;
73
73
74
+ /**
75
+ * @param {string } str path
76
+ * @returns {string } safe path
77
+ */
74
78
const toSafePath = str =>
75
79
str
76
80
. replace ( / ^ [ ^ a - z A - Z 0 - 9 ] + | [ ^ a - z A - Z 0 - 9 ] + $ / g, "" )
77
81
. replace ( / [ ^ a - z A - Z 0 - 9 . _ - ] + / g, "_" ) ;
78
82
83
+ /**
84
+ * @param {Buffer } content content
85
+ * @returns {string } integrity
86
+ */
79
87
const computeIntegrity = content => {
80
88
const hash = createHash ( "sha512" ) ;
81
89
hash . update ( content ) ;
82
90
const integrity = "sha512-" + hash . digest ( "base64" ) ;
83
91
return integrity ;
84
92
} ;
85
93
94
+ /**
95
+ * @param {Buffer } content content
96
+ * @param {string } integrity integrity
97
+ * @returns {boolean } true, if integrity matches
98
+ */
86
99
const verifyIntegrity = ( content , integrity ) => {
87
100
if ( integrity === "ignore" ) return true ;
88
101
return computeIntegrity ( content ) === integrity ;
@@ -110,6 +123,11 @@ const parseKeyValuePairs = str => {
110
123
return result ;
111
124
} ;
112
125
126
+ /**
127
+ * @param {string | undefined } cacheControl Cache-Control header
128
+ * @param {number } requestTime timestamp of request
129
+ * @returns {{storeCache: boolean, storeLock: boolean, validUntil: number} } Logic for storing in cache and lockfile cache
130
+ */
113
131
const parseCacheControl = ( cacheControl , requestTime ) => {
114
132
// When false resource is not stored in cache
115
133
let storeCache = true ;
@@ -147,6 +165,10 @@ const areLockfileEntriesEqual = (a, b) => {
147
165
) ;
148
166
} ;
149
167
168
+ /**
169
+ * @param {LockfileEntry } entry lockfile entry
170
+ * @returns {`resolved: ${string}, integrity: ${string}, contentType: ${*}` } stringified entry
171
+ */
150
172
const entryToString = entry => {
151
173
return `resolved: ${ entry . resolved } , integrity: ${ entry . integrity } , contentType: ${ entry . contentType } ` ;
152
174
} ;
@@ -158,6 +180,10 @@ class Lockfile {
158
180
this . entries = new Map ( ) ;
159
181
}
160
182
183
+ /**
184
+ * @param {string } content content of the lockfile
185
+ * @returns {Lockfile } lockfile
186
+ */
161
187
static parse ( content ) {
162
188
// TODO handle merge conflicts
163
189
const data = JSON . parse ( content ) ;
@@ -180,6 +206,9 @@ class Lockfile {
180
206
return lockfile ;
181
207
}
182
208
209
+ /**
210
+ * @returns {string } stringified lockfile
211
+ */
183
212
toString ( ) {
184
213
let str = "{\n" ;
185
214
const entries = Array . from ( this . entries ) . sort ( ( [ a ] , [ b ] ) =>
@@ -342,6 +371,7 @@ class HttpUriPlugin {
342
371
const fs = compilation . inputFileSystem ;
343
372
const cache = compilation . getCache ( "webpack.HttpUriPlugin" ) ;
344
373
const logger = compilation . getLogger ( "webpack.HttpUriPlugin" ) ;
374
+ /** @type {string } */
345
375
const lockfileLocation =
346
376
this . _lockfileLocation ||
347
377
join (
@@ -351,6 +381,7 @@ class HttpUriPlugin {
351
381
? `${ toSafePath ( compiler . name ) } .webpack.lock`
352
382
: "webpack.lock"
353
383
) ;
384
+ /** @type {string | false } */
354
385
const cacheLocation =
355
386
this . _cacheLocation !== undefined
356
387
? this . _cacheLocation
@@ -364,6 +395,7 @@ class HttpUriPlugin {
364
395
365
396
let warnedAboutEol = false ;
366
397
398
+ /** @type {Map<string, string> } */
367
399
const cacheKeyCache = new Map ( ) ;
368
400
/**
369
401
* @param {string } url the url
@@ -447,6 +479,12 @@ class HttpUriPlugin {
447
479
448
480
/** @type {Map<string, LockfileEntry | "ignore" | "no-cache"> | undefined } */
449
481
let lockfileUpdates = undefined ;
482
+
483
+ /**
484
+ * @param {Lockfile } lockfile lockfile instance
485
+ * @param {string } url url to store
486
+ * @param {LockfileEntry | "ignore" | "no-cache" } entry lockfile entry
487
+ */
450
488
const storeLockEntry = ( lockfile , url , entry ) => {
451
489
const oldEntry = lockfile . entries . get ( url ) ;
452
490
if ( lockfileUpdates === undefined ) lockfileUpdates = new Map ( ) ;
0 commit comments