Skip to content

Commit

Permalink
Release v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Jul 14, 2024
1 parent 8cb7998 commit e3ca901
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions dist/rev-web-assets.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! 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

export type Settings = {
cd: string | null;
force: boolean;
metaContentBase: string | null;
saveManifest: boolean;
skip: string | null;
};
export type ManifestDetail = {
origin: string;
Expand All @@ -20,6 +21,7 @@ export type ManifestDetail = {
destPath: string | null;
usedIn: string[] | null;
references: number | null;
skipped: boolean;
};
export type Manifest = ManifestDetail[];
export type Results = {
Expand All @@ -33,9 +35,9 @@ export type ReporterSettings = {
summaryOnly: boolean;
};
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;
hashAssetPath(manifest: ManifestDetail[], detail: ManifestDetail, settings: Settings): (matched: string, pre: string, uri: string, post: string) => string;
processHtml(manifest: ManifestDetail[], settings: Settings): void;
Expand Down
18 changes: 11 additions & 7 deletions dist/rev-web-assets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! 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

import chalk from 'chalk';
import crypto from 'crypto';
Expand All @@ -7,7 +7,7 @@ import log from 'fancy-log';
import path from 'path';
import slash from 'slash';
const revWebAssets = {
manifest(source, target) {
manifest(source, target, skip) {
const files = fs.readdirSync(source, { recursive: true })
.map(file => slash(path.join(source, file.toString())))
.filter(file => fs.statSync(file).isFile())
Expand All @@ -33,6 +33,7 @@ const revWebAssets = {
destPath: null,
usedIn: isHtml ? null : [],
references: isHtml ? null : 0,
skipped: !isHtml && !!skip && file.includes(skip),
};
};
const manifest = files.map(process);
Expand All @@ -42,7 +43,7 @@ const revWebAssets = {
const lastDot = /\.(?=[^.]*$)/;
return slash(path.normalize(!hash ? filename : filename.replace(lastDot, '.' + hash + '.')));
},
removeHash(filename) {
stripHash(filename) {
return filename.replace(/[.][0-9a-f]{8}[.]/, '.');
},
calcAssetHash(detail) {
Expand All @@ -56,13 +57,15 @@ const revWebAssets = {
return detail;
},
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);
if (assetDetail)
assetDetail.references++;
Expand Down Expand Up @@ -121,6 +124,7 @@ const revWebAssets = {
force: false,
metaContentBase: null,
saveManifest: false,
skip: null,
};
const settings = { ...defaults, ...options };
const startTime = Date.now();
Expand All @@ -139,10 +143,10 @@ const revWebAssets = {
null;
if (errorMessage)
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)
manifest.forEach(hashUnusedAsset);
revWebAssets.copyAssets(manifest);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rev-web-assets",
"version": "1.3.5",
"version": "1.4.0",
"description": "Revision web asset filenames with cache busting content hash fingerprints",
"license": "MIT",
"type": "module",
Expand Down

0 comments on commit e3ca901

Please sign in to comment.