uglify-js-minify-css-allfiles 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +0 -3
- package/dist/module.js +14 -8
- package/dist/modules/imageUtils.js +1 -1
- package/logs/log-02-13-2025.log +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.3.2] - 2025-02-14
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fixed JS image versioning to handle existing versions and use global hash
|
|
13
|
+
|
|
8
14
|
## [2.3.1] - 2025-02-13
|
|
9
15
|
|
|
10
16
|
### Fixed
|
package/README.md
CHANGED
|
@@ -124,9 +124,6 @@ Automatic versioning for image references in JS and CSS files:
|
|
|
124
124
|
- Random hash generation for JS image references
|
|
125
125
|
- Support for multiple image formats (PNG, JPEG, GIF, SVG, WebP, etc.)
|
|
126
126
|
- Handles various image path formats:
|
|
127
|
-
- Absolute and relative paths
|
|
128
|
-
- Data URIs
|
|
129
|
-
- HTTP/HTTPS URLs
|
|
130
127
|
- Complex CSS background declarations
|
|
131
128
|
- image-set() syntax support
|
|
132
129
|
|
package/dist/module.js
CHANGED
|
@@ -28,27 +28,31 @@ import { resolveImagePath, resolveModulePath, makeRelativePath, containsFolder,
|
|
|
28
28
|
* @param {Logger} logger - Logger instance for tracking changes
|
|
29
29
|
* @param {HashManager} hashManager - Manages content-based hashing for images
|
|
30
30
|
* @param {string[]} targetExtensions - List of image extensions to process (e.g., ['.png', '.jpg'])
|
|
31
|
+
* @param {string} jsHashVersion - JS hash version string.
|
|
31
32
|
* @returns {Promise<{content: string, modified: boolean}>} Modified content and whether changes were made
|
|
32
33
|
*/
|
|
33
|
-
async function processPattern(pattern, content, fileExt, filePath, logger, hashManager, targetExtensions) {
|
|
34
|
+
async function processPattern(pattern, content, fileExt, filePath, logger, hashManager, targetExtensions, jsHashVersion) {
|
|
34
35
|
const promises = [];
|
|
35
36
|
let newContent = content;
|
|
36
37
|
let modified = false;
|
|
37
38
|
|
|
38
39
|
if (fileExt === '.js') {
|
|
39
|
-
const newHash =
|
|
40
|
+
const newHash = jsHashVersion;
|
|
40
41
|
|
|
41
|
-
newContent = content.replace(pattern, (match,
|
|
42
|
+
newContent = content.replace(pattern, (match, quote, imagePath, endQuote) => {
|
|
42
43
|
if (imagePath.startsWith('data:') || imagePath.startsWith('http://') || imagePath.startsWith('https://')) {
|
|
43
44
|
return match;
|
|
44
45
|
}
|
|
46
|
+
|
|
47
|
+
const cleanPath = imagePath.split('?')[0];
|
|
48
|
+
|
|
45
49
|
modified = true;
|
|
46
50
|
logger?.info('Updated JS image version', {
|
|
47
51
|
file: filePath,
|
|
48
|
-
image:
|
|
52
|
+
image: cleanPath,
|
|
49
53
|
newHash,
|
|
50
54
|
});
|
|
51
|
-
return `${
|
|
55
|
+
return `${quote}${cleanPath}?v=${newHash}${endQuote}`;
|
|
52
56
|
});
|
|
53
57
|
return { content: newContent, modified };
|
|
54
58
|
}
|
|
@@ -107,9 +111,10 @@ async function processPattern(pattern, content, fileExt, filePath, logger, hashM
|
|
|
107
111
|
* @param {string[]} [versioningOptions.extensions] - List of file extensions to version.
|
|
108
112
|
* @param {Logger} logger - Logger instance.
|
|
109
113
|
* @param {HashManager} hashManager - Hash manager instance.
|
|
114
|
+
* @param {string} jsHashVersion - JS hash version string.
|
|
110
115
|
* @returns {Promise<void>}
|
|
111
116
|
*/
|
|
112
|
-
async function updateImageReferences(filePath, versioningOptions, logger, hashManager) {
|
|
117
|
+
async function updateImageReferences(filePath, versioningOptions, logger, hashManager, jsHashVersion) {
|
|
113
118
|
const { extensions } = versioningOptions;
|
|
114
119
|
const targetExtensions =
|
|
115
120
|
extensions || DEFAULT_IMAGE_EXTENSIONS.map((ext) => (ext === 'jpe?g' ? ['.jpg', '.jpeg'] : ['.' + ext.replace('?', '')])).flat();
|
|
@@ -122,7 +127,7 @@ async function updateImageReferences(filePath, versioningOptions, logger, hashMa
|
|
|
122
127
|
let modified = false;
|
|
123
128
|
|
|
124
129
|
for (const pattern of patterns) {
|
|
125
|
-
const result = await processPattern(pattern, content, fileExt, filePath, logger, hashManager, targetExtensions);
|
|
130
|
+
const result = await processPattern(pattern, content, fileExt, filePath, logger, hashManager, targetExtensions, jsHashVersion);
|
|
126
131
|
content = result.content;
|
|
127
132
|
modified = modified || result.modified;
|
|
128
133
|
}
|
|
@@ -286,6 +291,7 @@ export default async function minifyAll(contentPath, options = {}) {
|
|
|
286
291
|
const rootDir = resolvePath(contentPath || '');
|
|
287
292
|
const babelOptions = await resolveBabelOptions(useBabel);
|
|
288
293
|
const hashManager = useVersioning ? new HashManager(rootDir) : null;
|
|
294
|
+
const jsHashVersion = useVersioning ? crypto.randomBytes(16).toString('hex').substring(0, 8) : '';
|
|
289
295
|
|
|
290
296
|
if (hashManager) {
|
|
291
297
|
await hashManager.initialize();
|
|
@@ -309,7 +315,7 @@ export default async function minifyAll(contentPath, options = {}) {
|
|
|
309
315
|
|
|
310
316
|
// Apply versioning after successful processing if enabled
|
|
311
317
|
if (useVersioning && hashManager) {
|
|
312
|
-
await updateImageReferences(filePath, useVersioning, logger, hashManager);
|
|
318
|
+
await updateImageReferences(filePath, useVersioning, logger, hashManager, jsHashVersion);
|
|
313
319
|
}
|
|
314
320
|
|
|
315
321
|
logger?.incrementProcessedFiles(filePath);
|
|
@@ -24,7 +24,7 @@ export const IMAGE_PATTERNS = {
|
|
|
24
24
|
],
|
|
25
25
|
js: [
|
|
26
26
|
// Basic extension-based pattern for all quotes
|
|
27
|
-
new RegExp(`(['"\`])([^'"\`]*?\\.(?:${IMAGE_EXT_PATTERN}))(['"\`])`, 'gi'),
|
|
27
|
+
new RegExp(`(['"\`])([^'"\`]*?\\.(?:${IMAGE_EXT_PATTERN}))(?:\\?v=[^'"\`]*)?(['"\`])`, 'gi'),
|
|
28
28
|
],
|
|
29
29
|
};
|
|
30
30
|
|
package/logs/log-02-13-2025.log
CHANGED
|
@@ -315,3 +315,16 @@
|
|
|
315
315
|
[02/13/2025, 13:10:41] [INFO] Writing file: C:\Users\PEARL\Desktop\_code\minify_contents\test\test.css
|
|
316
316
|
[02/13/2025, 13:10:41] [INFO] Writing file: C:\Users\PEARL\Desktop\_code\minify_contents\test\test.js
|
|
317
317
|
[02/13/2025, 13:10:41] [INFO] Processing Summary {"summary":{"totalFilesProcessed":5,"filesWithErrors":0,"errorCount":0,"errorFiles":[]}}
|
|
318
|
+
[02/13/2025, 13:21:29] [INFO] Starting minification process {"contentPath":"./test/","excludeFolder":"lib","useBabel":{"targets":"chrome 40"},"useVersioning":true}
|
|
319
|
+
[02/13/2025, 13:21:29] [INFO] Writing file: C:\Users\PEARL\Desktop\_code\minify_contents\test\test.css
|
|
320
|
+
[02/13/2025, 13:21:29] [INFO] Updated CSS image version {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.css","image":"img/sample.jpg","oldHash":"64d54047","newHash":"64d54047"}
|
|
321
|
+
[02/13/2025, 13:21:29] [INFO] Updated CSS image version {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.css","image":"img/samples.svg","oldHash":"5e25d61b","newHash":"5e25d61b"}
|
|
322
|
+
[02/13/2025, 13:21:29] [INFO] Updated file with versioned image references {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.css"}
|
|
323
|
+
[02/13/2025, 13:21:30] [INFO] Writing file: C:\Users\PEARL\Desktop\_code\minify_contents\test\test.js
|
|
324
|
+
[02/13/2025, 13:21:30] [INFO] Updated JS image version {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.js","image":"\"./img/sample.jpg./img/samples.svg","newHash":"1744e876"}
|
|
325
|
+
[02/13/2025, 13:21:30] [INFO] Updated JS image version {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.js","image":"\"./img/sample.jpg","newHash":"1744e876"}
|
|
326
|
+
[02/13/2025, 13:21:30] [INFO] Updated JS image version {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.js","image":"\"./img/samples.svg","newHash":"1744e876"}
|
|
327
|
+
[02/13/2025, 13:21:30] [INFO] Updated JS image version {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.js","image":"\"./img/sample.jpg","newHash":"1744e876"}
|
|
328
|
+
[02/13/2025, 13:21:30] [INFO] Updated JS image version {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.js","image":"\"./img/samples.svg","newHash":"1744e876"}
|
|
329
|
+
[02/13/2025, 13:21:30] [INFO] Updated file with versioned image references {"file":"C:\\Users\\PEARL\\Desktop\\_code\\minify_contents\\test\\test.js"}
|
|
330
|
+
[02/13/2025, 13:21:30] [INFO] Processing Summary {"summary":{"totalFilesProcessed":5,"filesWithErrors":0,"errorCount":0,"errorFiles":[]}}
|