@@ -71,18 +71,31 @@ const validate = createSchemaValidation(
7171 }
7272) ;
7373
74+ /**
75+ * @param {string } str path
76+ * @returns {string } safe path
77+ */
7478const toSafePath = str =>
7579 str
7680 . replace ( / ^ [ ^ a - z A - Z 0 - 9 ] + | [ ^ a - z A - Z 0 - 9 ] + $ / g, "" )
7781 . replace ( / [ ^ a - z A - Z 0 - 9 . _ - ] + / g, "_" ) ;
7882
83+ /**
84+ * @param {Buffer } content content
85+ * @returns {string } integrity
86+ */
7987const computeIntegrity = content => {
8088 const hash = createHash ( "sha512" ) ;
8189 hash . update ( content ) ;
8290 const integrity = "sha512-" + hash . digest ( "base64" ) ;
8391 return integrity ;
8492} ;
8593
94+ /**
95+ * @param {Buffer } content content
96+ * @param {string } integrity integrity
97+ * @returns {boolean } true, if integrity matches
98+ */
8699const verifyIntegrity = ( content , integrity ) => {
87100 if ( integrity === "ignore" ) return true ;
88101 return computeIntegrity ( content ) === integrity ;
@@ -110,6 +123,11 @@ const parseKeyValuePairs = str => {
110123 return result ;
111124} ;
112125
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+ */
113131const parseCacheControl = ( cacheControl , requestTime ) => {
114132 // When false resource is not stored in cache
115133 let storeCache = true ;
@@ -147,6 +165,10 @@ const areLockfileEntriesEqual = (a, b) => {
147165 ) ;
148166} ;
149167
168+ /**
169+ * @param {LockfileEntry } entry lockfile entry
170+ * @returns {`resolved: ${string}, integrity: ${string}, contentType: ${*}` } stringified entry
171+ */
150172const entryToString = entry => {
151173 return `resolved: ${ entry . resolved } , integrity: ${ entry . integrity } , contentType: ${ entry . contentType } ` ;
152174} ;
@@ -158,6 +180,10 @@ class Lockfile {
158180 this . entries = new Map ( ) ;
159181 }
160182
183+ /**
184+ * @param {string } content content of the lockfile
185+ * @returns {Lockfile } lockfile
186+ */
161187 static parse ( content ) {
162188 // TODO handle merge conflicts
163189 const data = JSON . parse ( content ) ;
@@ -180,6 +206,9 @@ class Lockfile {
180206 return lockfile ;
181207 }
182208
209+ /**
210+ * @returns {string } stringified lockfile
211+ */
183212 toString ( ) {
184213 let str = "{\n" ;
185214 const entries = Array . from ( this . entries ) . sort ( ( [ a ] , [ b ] ) =>
@@ -342,6 +371,7 @@ class HttpUriPlugin {
342371 const fs = compilation . inputFileSystem ;
343372 const cache = compilation . getCache ( "webpack.HttpUriPlugin" ) ;
344373 const logger = compilation . getLogger ( "webpack.HttpUriPlugin" ) ;
374+ /** @type {string } */
345375 const lockfileLocation =
346376 this . _lockfileLocation ||
347377 join (
@@ -351,6 +381,7 @@ class HttpUriPlugin {
351381 ? `${ toSafePath ( compiler . name ) } .webpack.lock`
352382 : "webpack.lock"
353383 ) ;
384+ /** @type {string | false } */
354385 const cacheLocation =
355386 this . _cacheLocation !== undefined
356387 ? this . _cacheLocation
@@ -364,6 +395,7 @@ class HttpUriPlugin {
364395
365396 let warnedAboutEol = false ;
366397
398+ /** @type {Map<string, string> } */
367399 const cacheKeyCache = new Map ( ) ;
368400 /**
369401 * @param {string } url the url
@@ -447,6 +479,12 @@ class HttpUriPlugin {
447479
448480 /** @type {Map<string, LockfileEntry | "ignore" | "no-cache"> | undefined } */
449481 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+ */
450488 const storeLockEntry = ( lockfile , url , entry ) => {
451489 const oldEntry = lockfile . entries . get ( url ) ;
452490 if ( lockfileUpdates === undefined ) lockfileUpdates = new Map ( ) ;
0 commit comments