Skip to content

Commit e3ca901

Browse files
committed
Release v1.4.0
1 parent 8cb7998 commit e3ca901

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

dist/rev-web-assets.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
//! rev-web-assets v1.3.5 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License
1+
//! rev-web-assets v1.4.0 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License
22

33
export type Settings = {
44
cd: string | null;
55
force: boolean;
66
metaContentBase: string | null;
77
saveManifest: boolean;
8+
skip: string | null;
89
};
910
export type ManifestDetail = {
1011
origin: string;
@@ -20,6 +21,7 @@ export type ManifestDetail = {
2021
destPath: string | null;
2122
usedIn: string[] | null;
2223
references: number | null;
24+
skipped: boolean;
2325
};
2426
export type Manifest = ManifestDetail[];
2527
export type Results = {
@@ -33,9 +35,9 @@ export type ReporterSettings = {
3335
summaryOnly: boolean;
3436
};
3537
declare const revWebAssets: {
36-
manifest(source: string, target: string): ManifestDetail[];
38+
manifest(source: string, target: string, skip: string | null): ManifestDetail[];
3739
hashFilename(filename: string, hash: string | null): string;
38-
removeHash(filename: string): string;
40+
stripHash(filename: string): string;
3941
calcAssetHash(detail: ManifestDetail): ManifestDetail;
4042
hashAssetPath(manifest: ManifestDetail[], detail: ManifestDetail, settings: Settings): (matched: string, pre: string, uri: string, post: string) => string;
4143
processHtml(manifest: ManifestDetail[], settings: Settings): void;

dist/rev-web-assets.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! rev-web-assets v1.3.5 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License
1+
//! rev-web-assets v1.4.0 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License
22

33
import chalk from 'chalk';
44
import crypto from 'crypto';
@@ -7,7 +7,7 @@ import log from 'fancy-log';
77
import path from 'path';
88
import slash from 'slash';
99
const revWebAssets = {
10-
manifest(source, target) {
10+
manifest(source, target, skip) {
1111
const files = fs.readdirSync(source, { recursive: true })
1212
.map(file => slash(path.join(source, file.toString())))
1313
.filter(file => fs.statSync(file).isFile())
@@ -33,6 +33,7 @@ const revWebAssets = {
3333
destPath: null,
3434
usedIn: isHtml ? null : [],
3535
references: isHtml ? null : 0,
36+
skipped: !isHtml && !!skip && file.includes(skip),
3637
};
3738
};
3839
const manifest = files.map(process);
@@ -42,7 +43,7 @@ const revWebAssets = {
4243
const lastDot = /\.(?=[^.]*$)/;
4344
return slash(path.normalize(!hash ? filename : filename.replace(lastDot, '.' + hash + '.')));
4445
},
45-
removeHash(filename) {
46+
stripHash(filename) {
4647
return filename.replace(/[.][0-9a-f]{8}[.]/, '.');
4748
},
4849
calcAssetHash(detail) {
@@ -56,13 +57,15 @@ const revWebAssets = {
5657
return detail;
5758
},
5859
hashAssetPath(manifest, detail, settings) {
60+
const webPages = ['.html', '.htm', '.php'];
5961
const replacer = (matched, pre, uri, post) => {
6062
const ext = path.extname(uri);
61-
const doNotHash = uri.includes(':') || ['.html', '.htm', '.php'].includes(ext) || ext.length < 2;
63+
const doNotHash = uri.includes(':') || webPages.includes(ext) || ext.length < 2;
6264
const canonicalPath = detail.canonicalFolder ? detail.canonicalFolder + '/' : '';
6365
const canonical = slash(path.normalize(canonicalPath + uri));
6466
const assetDetail = doNotHash ? null : manifest.find(detail => detail.canonical === canonical);
65-
if (assetDetail && !assetDetail.hash)
67+
const skipAsset = !!settings.skip && uri.includes(settings.skip);
68+
if (assetDetail && !assetDetail.hash && !skipAsset)
6669
revWebAssets.calcAssetHash(assetDetail);
6770
if (assetDetail)
6871
assetDetail.references++;
@@ -121,6 +124,7 @@ const revWebAssets = {
121124
force: false,
122125
metaContentBase: null,
123126
saveManifest: false,
127+
skip: null,
124128
};
125129
const settings = { ...defaults, ...options };
126130
const startTime = Date.now();
@@ -139,10 +143,10 @@ const revWebAssets = {
139143
null;
140144
if (errorMessage)
141145
throw Error('[rev-web-assets] ' + errorMessage);
142-
const manifest = revWebAssets.manifest(source, target);
146+
const manifest = revWebAssets.manifest(source, target, settings.skip);
143147
revWebAssets.processHtml(manifest, settings);
144148
revWebAssets.processCss(manifest, settings);
145-
const hashUnusedAsset = (detail) => !detail.hash && !detail.isHtml && revWebAssets.calcAssetHash(detail);
149+
const hashUnusedAsset = (detail) => !detail.hash && !detail.isHtml && !detail.skipped && revWebAssets.calcAssetHash(detail);
146150
if (settings.force)
147151
manifest.forEach(hashUnusedAsset);
148152
revWebAssets.copyAssets(manifest);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rev-web-assets",
3-
"version": "1.3.5",
3+
"version": "1.4.0",
44
"description": "Revision web asset filenames with cache busting content hash fingerprints",
55
"license": "MIT",
66
"type": "module",

0 commit comments

Comments
 (0)