|
1 |
| -//! rev-web-assets v1.5.1 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License |
| 1 | +//! rev-web-assets v1.5.3 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License |
2 | 2 |
|
3 | 3 | import { EOL } from 'node:os';
|
4 | 4 | import chalk from 'chalk';
|
@@ -62,22 +62,24 @@ const revWebAssets = {
|
62 | 62 | hashAssetPath(manifest, detail, settings) {
|
63 | 63 | const webPages = ['.html', '.htm', '.php'];
|
64 | 64 | const replacer = (matched, pre, url, post) => {
|
| 65 | + const line = matched.replace(/\s+/g, ' '); |
65 | 66 | const uri = url.replace(/[#?].*/, '');
|
66 | 67 | const ext = path.extname(uri);
|
67 |
| - const doNotHash = uri.includes(':') || webPages.includes(ext) || ext.length < 2; |
| 68 | + const isTemplate = /{.*}|<.*>|~~.*~~/.test(uri); |
| 69 | + const unhashable = uri.includes(':') || webPages.includes(ext) || ext.length < 2; |
68 | 70 | const canonicalPath = detail.canonicalFolder ? detail.canonicalFolder + '/' : '';
|
69 | 71 | const canonical = slash(path.normalize(canonicalPath + uri));
|
70 | 72 | const isAssetDetail = (detail) => detail.canonical === canonical;
|
71 |
| - const assetDetail = doNotHash ? null : manifest.find(isAssetDetail); |
| 73 | + const assetDetail = isTemplate || unhashable ? null : manifest.find(isAssetDetail); |
72 | 74 | const skipAsset = !!settings.skip && uri.includes(settings.skip);
|
73 | 75 | if (assetDetail && !assetDetail.hash && !skipAsset)
|
74 | 76 | revWebAssets.calcAssetHash(assetDetail);
|
75 | 77 | if (assetDetail)
|
76 | 78 | assetDetail.references++;
|
77 | 79 | if (assetDetail && !assetDetail.usedIn.includes(detail.canonical))
|
78 | 80 | assetDetail.usedIn.push(detail.canonical);
|
79 |
| - if (!doNotHash && !skipAsset && !assetDetail) |
80 |
| - detail.missing.push(matched.replace(/\s+/g, ' ')); |
| 81 | + if (!isTemplate && !unhashable && !skipAsset && !assetDetail) |
| 82 | + detail.missing.push({ ext, line }); |
81 | 83 | const trailingSlashes = /\/*$/;
|
82 | 84 | const metaContentBase = settings.metaContentBase?.replace(trailingSlashes, '/');
|
83 | 85 | const absoluteUrl = () => `${metaContentBase}${assetDetail?.canonicalFolder}/${assetDetail?.hashedFilename}`;
|
@@ -185,14 +187,14 @@ const revWebAssets = {
|
185 | 187 | const arrow = { big: chalk.gray.bold(' ⟹ '), little: chalk.gray.bold('→') };
|
186 | 188 | const infoColor = results.count ? chalk.white : chalk.red.bold;
|
187 | 189 | const info = infoColor(`(files: ${results.count}, ${results.duration}ms)`);
|
188 |
| - const warning = chalk.red.bold('missing asset in'); |
189 | 190 | log(name, source, arrow.big, target, info);
|
190 | 191 | const logDetail = (detail) => {
|
191 | 192 | const origin = chalk.white(detail.origin.substring(results.source.length + 1));
|
192 | 193 | const dest = chalk.green(detail.destPath.substring(results.target.length + 1));
|
193 | 194 | const file = chalk.blue.bold(detail.origin);
|
| 195 | + const warning = (ext) => chalk.red.bold(`missing ${ext} asset in`); |
194 | 196 | log(name, origin, arrow.little, dest);
|
195 |
| - const logMissingAsset = (assetLine) => log(name, warning, file, arrow.little, chalk.green(assetLine)); |
| 197 | + const logMissingAsset = (missing) => log(name, warning(missing.ext), file, arrow.little, chalk.green(missing.line)); |
196 | 198 | if (!settings.hide404s && detail.missing)
|
197 | 199 | detail.missing.forEach(logMissingAsset);
|
198 | 200 | };
|
|
0 commit comments