@@ -17,22 +17,26 @@ export type Settings = {
17
17
saveManifest : boolean , //output the list of files to manifest.json in the target folder
18
18
skip : string | null , //do not revision (hash) asset files with paths containing given string.
19
19
} ;
20
+ export type MissingAsset = {
21
+ ext : string , //filename extension of the asset file not found
22
+ line : string , //html line referencing the asset file not found
23
+ } ;
20
24
export type ManifestDetail = {
21
- origin : string , //source path of asset file
22
- filename : string , //source filename of asset file
23
- canonical : string , //normalized path used to lookup asset in manifest
24
- canonicalFolder : string , //directory of the normalized path of the asset file
25
- isHtml : boolean , //asset file is HTML
26
- isCss : boolean , //asset file is CSS
27
- bytes : number | null , //asset file size
28
- hash : string | null , //eight-digit cache busting hex humber that changes if the asset changes
29
- hashedFilename : string | null , //filename of the asset with hash inserted before the file extension
30
- destFolder : string , //directory of the target asset
31
- destPath : string | null , //folder and filename of the target asset
32
- usedIn : string [ ] | null , //files that references the asset
33
- references : number | null , //number of times the asset is referenced
34
- skipped : boolean , //asset file is configured to not be hashed
35
- missing : string [ ] | null , //html lines of asset files referenced but not found
25
+ origin : string , //source path of asset file
26
+ filename : string , //source filename of asset file
27
+ canonical : string , //normalized path used to lookup asset in manifest
28
+ canonicalFolder : string , //directory of the normalized path of the asset file
29
+ isHtml : boolean , //asset file is HTML
30
+ isCss : boolean , //asset file is CSS
31
+ bytes : number | null , //asset file size
32
+ hash : string | null , //eight-digit cache busting hex humber that changes if the asset changes
33
+ hashedFilename : string | null , //filename of the asset with hash inserted before the file extension
34
+ destFolder : string , //directory of the target asset
35
+ destPath : string | null , //folder and filename of the target asset
36
+ usedIn : string [ ] | null , //files that references the asset
37
+ references : number | null , //number of times the asset is referenced
38
+ skipped : boolean , //asset file is configured to not be hashed
39
+ missing : MissingAsset [ ] | null , //asset files referenced but not found (404)
36
40
} ;
37
41
export type Manifest = ManifestDetail [ ] ; //list of assets
38
42
export type Results = {
@@ -122,6 +126,7 @@ const revWebAssets = {
122
126
const replacer = ( matched : string , pre : string , url : string , post : string ) : string => {
123
127
// Example matched broken into 3 parts:
124
128
// '<img src=logo.png alt=Logo>' ==> '<img src=', 'logo.png', ' alt=Logo>'
129
+ const line = matched . replace ( / \s + / g, ' ' ) ;
125
130
const uri = url . replace ( / [ # ? ] .* / , '' ) ; //strip off trailing query string and hash fragment
126
131
const ext = path . extname ( uri ) ;
127
132
const doNotHash = uri . includes ( ':' ) || webPages . includes ( ext ) || ext . length < 2 ;
@@ -137,7 +142,7 @@ const revWebAssets = {
137
142
if ( assetDetail && ! assetDetail . usedIn ! . includes ( detail . canonical ) )
138
143
assetDetail . usedIn ! . push ( detail . canonical ) ;
139
144
if ( ! doNotHash && ! skipAsset && ! assetDetail )
140
- detail . missing ! . push ( matched . replace ( / \s + / g , ' ' ) ) ;
145
+ detail . missing ! . push ( { ext , line } ) ;
141
146
const trailingSlashes = / \/ * $ / ;
142
147
const metaContentBase = settings . metaContentBase ?. replace ( trailingSlashes , '/' ) ;
143
148
const absoluteUrl = ( ) =>
@@ -259,15 +264,15 @@ const revWebAssets = {
259
264
const arrow = { big : chalk . gray . bold ( ' ⟹ ' ) , little : chalk . gray . bold ( '→' ) } ;
260
265
const infoColor = results . count ? chalk . white : chalk . red . bold ;
261
266
const info = infoColor ( `(files: ${ results . count } , ${ results . duration } ms)` ) ;
262
- const warning = chalk . red . bold ( 'missing asset in' ) ;
263
267
log ( name , source , arrow . big , target , info ) ;
264
268
const logDetail = ( detail : ManifestDetail ) => {
265
- const origin = chalk . white ( detail . origin . substring ( results . source . length + 1 ) ) ;
266
- const dest = chalk . green ( detail . destPath ! . substring ( results . target . length + 1 ) ) ;
267
- const file = chalk . blue . bold ( detail . origin ) ;
269
+ const origin = chalk . white ( detail . origin . substring ( results . source . length + 1 ) ) ;
270
+ const dest = chalk . green ( detail . destPath ! . substring ( results . target . length + 1 ) ) ;
271
+ const file = chalk . blue . bold ( detail . origin ) ;
272
+ const warning = ( ext : string ) => chalk . red . bold ( `missing ${ ext } asset in` ) ;
268
273
log ( name , origin , arrow . little , dest ) ;
269
- const logMissingAsset = ( assetLine : string ) =>
270
- log ( name , warning , file , arrow . little , chalk . green ( assetLine ) ) ;
274
+ const logMissingAsset = ( missing : MissingAsset ) =>
275
+ log ( name , warning ( missing . ext ) , file , arrow . little , chalk . green ( missing . line ) ) ;
271
276
if ( ! settings . hide404s && detail . missing )
272
277
detail . missing . forEach ( logMissingAsset ) ;
273
278
} ;
0 commit comments