rev-web-assets
Advanced tools
Comparing version 1.3.5 to 1.4.0
@@ -27,6 +27,7 @@ #!/usr/bin/env node | ||
// Parameters and flags | ||
const validFlags = ['cd', 'force', 'manifest', 'meta-content-base', 'note', 'quiet', 'summary']; | ||
const cli = cliArgvUtil.parse(validFlags); | ||
const source = cli.params[0]; | ||
const target = cli.params[1]; | ||
const validFlags = | ||
['cd', 'force', 'manifest', 'meta-content-base', 'note', 'quiet', 'skip', 'summary']; | ||
const cli = cliArgvUtil.parse(validFlags); | ||
const source = cli.params[0]; | ||
const target = cli.params[1]; | ||
@@ -47,2 +48,3 @@ // Revision Web Assets | ||
saveManifest: cli.flagOn.manifest, | ||
skip: cli.flagMap.skip ?? null, | ||
}; | ||
@@ -49,0 +51,0 @@ const results = revWebAssets.revision(source, target, options); |
@@ -1,2 +0,2 @@ | ||
//! rev-web-assets v1.3.5 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License | ||
//! rev-web-assets v1.4.0 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License | ||
@@ -8,2 +8,3 @@ export type Settings = { | ||
saveManifest: boolean; | ||
skip: string | null; | ||
}; | ||
@@ -24,2 +25,3 @@ export type ManifestDetail = { | ||
references: number | null; | ||
skipped: boolean; | ||
}; | ||
@@ -38,5 +40,5 @@ export type Manifest = ManifestDetail[]; | ||
declare const revWebAssets: { | ||
manifest(source: string, target: string): ManifestDetail[]; | ||
manifest(source: string, target: string, skip: string | null): ManifestDetail[]; | ||
hashFilename(filename: string, hash: string | null): string; | ||
removeHash(filename: string): string; | ||
stripHash(filename: string): string; | ||
calcAssetHash(detail: ManifestDetail): ManifestDetail; | ||
@@ -43,0 +45,0 @@ hashAssetPath(manifest: ManifestDetail[], detail: ManifestDetail, settings: Settings): (matched: string, pre: string, uri: string, post: string) => string; |
@@ -1,2 +0,2 @@ | ||
//! rev-web-assets v1.3.5 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License | ||
//! rev-web-assets v1.4.0 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License | ||
@@ -10,3 +10,3 @@ import chalk from 'chalk'; | ||
const revWebAssets = { | ||
manifest(source, target) { | ||
manifest(source, target, skip) { | ||
const files = fs.readdirSync(source, { recursive: true }) | ||
@@ -37,2 +37,3 @@ .map(file => slash(path.join(source, file.toString()))) | ||
references: isHtml ? null : 0, | ||
skipped: !isHtml && !!skip && file.includes(skip), | ||
}; | ||
@@ -47,3 +48,3 @@ }; | ||
}, | ||
removeHash(filename) { | ||
stripHash(filename) { | ||
return filename.replace(/[.][0-9a-f]{8}[.]/, '.'); | ||
@@ -62,9 +63,11 @@ }, | ||
hashAssetPath(manifest, detail, settings) { | ||
const webPages = ['.html', '.htm', '.php']; | ||
const replacer = (matched, pre, uri, post) => { | ||
const ext = path.extname(uri); | ||
const doNotHash = uri.includes(':') || ['.html', '.htm', '.php'].includes(ext) || ext.length < 2; | ||
const doNotHash = uri.includes(':') || webPages.includes(ext) || ext.length < 2; | ||
const canonicalPath = detail.canonicalFolder ? detail.canonicalFolder + '/' : ''; | ||
const canonical = slash(path.normalize(canonicalPath + uri)); | ||
const assetDetail = doNotHash ? null : manifest.find(detail => detail.canonical === canonical); | ||
if (assetDetail && !assetDetail.hash) | ||
const skipAsset = !!settings.skip && uri.includes(settings.skip); | ||
if (assetDetail && !assetDetail.hash && !skipAsset) | ||
revWebAssets.calcAssetHash(assetDetail); | ||
@@ -128,2 +131,3 @@ if (assetDetail) | ||
saveManifest: false, | ||
skip: null, | ||
}; | ||
@@ -147,6 +151,6 @@ const settings = { ...defaults, ...options }; | ||
throw Error('[rev-web-assets] ' + errorMessage); | ||
const manifest = revWebAssets.manifest(source, target); | ||
const manifest = revWebAssets.manifest(source, target, settings.skip); | ||
revWebAssets.processHtml(manifest, settings); | ||
revWebAssets.processCss(manifest, settings); | ||
const hashUnusedAsset = (detail) => !detail.hash && !detail.isHtml && revWebAssets.calcAssetHash(detail); | ||
const hashUnusedAsset = (detail) => !detail.hash && !detail.isHtml && !detail.skipped && revWebAssets.calcAssetHash(detail); | ||
if (settings.force) | ||
@@ -153,0 +157,0 @@ manifest.forEach(hashUnusedAsset); |
{ | ||
"name": "rev-web-assets", | ||
"version": "1.3.5", | ||
"version": "1.4.0", | ||
"description": "Revision web asset filenames with cache busting content hash fingerprints", | ||
@@ -82,6 +82,5 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@eslint/js": "~9.7", | ||
"@types/fancy-log": "~2.0", | ||
"@types/node": "~20.12", | ||
"@typescript-eslint/eslint-plugin": "~7.7", | ||
"@typescript-eslint/parser": "~7.7", | ||
"@types/node": "~20.14", | ||
"add-dist-header": "~1.4", | ||
@@ -92,8 +91,9 @@ "assert-deep-strict-equal": "~1.2", | ||
"jshint": "~2.13", | ||
"mocha": "~10.4", | ||
"rimraf": "~5.0", | ||
"mocha": "~10.6", | ||
"rimraf": "~6.0", | ||
"run-scripts-util": "~1.2", | ||
"typescript": "~5.4", | ||
"typescript": "~5.5", | ||
"typescript-eslint": "~7.16", | ||
"w3c-html-validator": "~1.8" | ||
} | ||
} |
@@ -47,11 +47,12 @@ # rev-web-assets | ||
Command-line flags: | ||
| Flag | Description | Value | | ||
| --------------------- | ------------------------------------------------------- | ---------- | | ||
| `--cd` | Change working directory before starting starting. | **string** | | ||
| `--force` | Revision (hash) all asset files even if not referenced. | N/A | | ||
| `--manifest` | Output the list of files to: **manifest.json** | N/A | | ||
| `--meta-content-base` | Make meta URLs, like "og:image", absolute. | **string** | | ||
| `--note` | Place to add a comment only for humans. | **string** | | ||
| `--quiet` | Suppress informational messages. | N/A | | ||
| `--summary` | Only print out the single line summary message. | N/A | | ||
| Flag | Description | Value | | ||
| --------------------- | ---------------------------------------------------------------------- | ---------- | | ||
| `--cd` | Change working directory before starting starting. | **string** | | ||
| `--force` | Revision (hash) all asset files even if not referenced. | N/A | | ||
| `--manifest` | Output the list of files to: **manifest.json** | N/A | | ||
| `--meta-content-base` | Make meta URLs, like "og:image", absolute. | **string** | | ||
| `--note` | Place to add a comment only for humans. | **string** | | ||
| `--quiet` | Suppress informational messages. | N/A | | ||
| `--skip` | Do not revision (hash) asset files with paths containing given string. | **string** | | ||
| `--summary` | Only print out the single line summary message. | N/A | | ||
@@ -77,3 +78,4 @@ Examples: | ||
_**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._ | ||
_**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the | ||
errors often encountered on Microsoft Windows._ | ||
@@ -97,4 +99,4 @@ URLs in `<meta>` tag `content` attributes generally need to be absolute URLs. | ||
canonicalFolder: string, //directory of the normalized path of the asset file | ||
isHtml: boolean, //true if the asset file is HTML | ||
isCss: boolean, //true if the asset file is CSS | ||
isHtml: boolean, //asset file is HTML | ||
isCss: boolean, //asset file is CSS | ||
bytes: number | null, //asset file size | ||
@@ -107,2 +109,3 @@ hash: string | null, //eight-digit cache busting hex humber that changes if the asset changes | ||
references: number | null, //number of times the asset is referenced | ||
skipped: boolean, //asset file is configured to not be hashed | ||
}; | ||
@@ -109,0 +112,0 @@ ``` |
24063
281
163