uglify-js-minify-css-allfiles 2.2.1 → 2.2.3
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 +1 -1
- package/dist/module.js +59 -36
- package/logs/log-08-22-2024.log +4 -0
- package/minify.d.ts +49 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,7 @@ 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.2.
|
|
8
|
+
## [2.2.2] - 2024-08-22
|
|
9
9
|
|
|
10
10
|
### Fixed
|
|
11
11
|
|
package/dist/module.js
CHANGED
|
@@ -9,28 +9,50 @@ import path from 'path';
|
|
|
9
9
|
import Logger from './modules/logger.js';
|
|
10
10
|
import { getAllFiles, writeFile } from './modules/fileHandler.js';
|
|
11
11
|
import { minifyJS, minifyCSS } from './modules/minifier.js';
|
|
12
|
+
import { createRequire } from 'module';
|
|
13
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
14
|
+
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
+
const __dirname = path.dirname(__filename);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the path of a module.
|
|
21
|
+
* @param {string} moduleName - The name of the module to resolve.
|
|
22
|
+
* @returns {string} The resolved module path as a URL.
|
|
23
|
+
*/
|
|
24
|
+
function resolveModulePath(moduleName) {
|
|
25
|
+
const modulePath = require.resolve(moduleName, { paths: [__dirname] });
|
|
26
|
+
return pathToFileURL(modulePath).href;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {Object} FileHandlerOptions
|
|
31
|
+
* @property {BabelOptions} [babelOptions] - Babel transformation options.
|
|
32
|
+
* @property {JSMinifyOptions} [jsMinifyOptions] - JavaScript minification options.
|
|
33
|
+
* @property {CSSMinifyOptions} [cssMinifyOptions] - CSS minification options.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @callback FileHandler
|
|
38
|
+
* @param {string} filePath - The path of the file to process.
|
|
39
|
+
* @param {string} content - The content of the file.
|
|
40
|
+
* @param {Logger} logger - The logger instance.
|
|
41
|
+
* @param {FileHandlerOptions} options - Options for processing.
|
|
42
|
+
* @returns {Promise<void>}
|
|
43
|
+
*/
|
|
12
44
|
|
|
13
45
|
/**
|
|
14
46
|
* Object containing handlers for different file types.
|
|
15
|
-
* @type {Object.<string,
|
|
47
|
+
* @type {Object.<string, FileHandler>}
|
|
16
48
|
*/
|
|
17
49
|
const FILE_HANDLERS = {
|
|
18
|
-
/**
|
|
19
|
-
* Handles JavaScript file minification.
|
|
20
|
-
* @async
|
|
21
|
-
* @param {string} filePath - The path of the JavaScript file.
|
|
22
|
-
* @param {string} content - The content of the JavaScript file.
|
|
23
|
-
* @param {Logger} logger - The logger instance.
|
|
24
|
-
* @param {Object} options - Options for processing.
|
|
25
|
-
* @param {Object} [options.babelOptions] - Babel transformation options.
|
|
26
|
-
* @param {Object} [options.jsMinifyOptions] - JavaScript minification options.
|
|
27
|
-
* @returns {Promise<void>}
|
|
28
|
-
*/
|
|
29
50
|
'.js': async (filePath, content, logger, options) => {
|
|
30
51
|
try {
|
|
31
52
|
let transformed = content;
|
|
32
53
|
if (options.babelOptions) {
|
|
33
|
-
const
|
|
54
|
+
const babelCoreUrl = resolveModulePath('@babel/core');
|
|
55
|
+
const { transformSync } = await import(babelCoreUrl);
|
|
34
56
|
transformed = transformSync(content, options.babelOptions).code;
|
|
35
57
|
}
|
|
36
58
|
const result = minifyJS(transformed, options.jsMinifyOptions);
|
|
@@ -39,17 +61,6 @@ const FILE_HANDLERS = {
|
|
|
39
61
|
await logger?.error('JavaScript minification failed', { filePath, error: error.message });
|
|
40
62
|
}
|
|
41
63
|
},
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Handles CSS file minification.
|
|
45
|
-
* @async
|
|
46
|
-
* @param {string} filePath - The path of the CSS file.
|
|
47
|
-
* @param {string} content - The content of the CSS file.
|
|
48
|
-
* @param {Logger} logger - The logger instance.
|
|
49
|
-
* @param {Object} options - Options for processing.
|
|
50
|
-
* @param {Object} [options.cssMinifyOptions] - CSS minification options.
|
|
51
|
-
* @returns {Promise<void>}
|
|
52
|
-
*/
|
|
53
64
|
'.css': async (filePath, content, logger, options) => {
|
|
54
65
|
try {
|
|
55
66
|
const output = await minifyCSS(content, options.cssMinifyOptions);
|
|
@@ -68,7 +79,7 @@ const FILE_HANDLERS = {
|
|
|
68
79
|
* @async
|
|
69
80
|
* @param {string} filePath - The path of the file to process.
|
|
70
81
|
* @param {Logger} logger - The logger instance.
|
|
71
|
-
* @param {
|
|
82
|
+
* @param {FileHandlerOptions} options - Options for processing.
|
|
72
83
|
* @returns {Promise<void>}
|
|
73
84
|
*/
|
|
74
85
|
async function processFile(filePath, logger, options) {
|
|
@@ -89,8 +100,8 @@ async function processFile(filePath, logger, options) {
|
|
|
89
100
|
|
|
90
101
|
/**
|
|
91
102
|
* Resolves Babel options based on the provided configuration.
|
|
92
|
-
* @param {boolean|
|
|
93
|
-
* @returns {
|
|
103
|
+
* @param {boolean|BabelOptions} useBabel - The Babel options object or boolean.
|
|
104
|
+
* @returns {BabelOptions|null} The resolved Babel options or null if no valid options are provided.
|
|
94
105
|
*/
|
|
95
106
|
function resolveBabelOptions(useBabel) {
|
|
96
107
|
if (!useBabel) return null;
|
|
@@ -101,9 +112,8 @@ function resolveBabelOptions(useBabel) {
|
|
|
101
112
|
|
|
102
113
|
/**
|
|
103
114
|
* Options for Babel configuration.
|
|
104
|
-
*
|
|
105
115
|
* @typedef {Object} BabelOptions
|
|
106
|
-
* @property {string|string[]|Object
|
|
116
|
+
* @property {string|string[]|Object.<string, string>} [targets] - Specifies the target environments for the code.
|
|
107
117
|
* @property {'amd'|'umd'|'systemjs'|'commonjs'|'cjs'|'auto'|false} [modules] - Module format to use for the output.
|
|
108
118
|
* @property {boolean} [debug] - Enables or disables debug mode.
|
|
109
119
|
* @property {string[]} [include] - List of plugins or features to include.
|
|
@@ -118,7 +128,6 @@ function resolveBabelOptions(useBabel) {
|
|
|
118
128
|
|
|
119
129
|
/**
|
|
120
130
|
* Options for logging configuration.
|
|
121
|
-
*
|
|
122
131
|
* @typedef {Object} LogOptions
|
|
123
132
|
* @property {string} [logDir] - Specifies the directory for log files.
|
|
124
133
|
* @property {number} [retentionDays] - Number of days to retain log files.
|
|
@@ -129,21 +138,35 @@ function resolveBabelOptions(useBabel) {
|
|
|
129
138
|
* @property {boolean} [logToFile] - Determines if logs should be written to a file.
|
|
130
139
|
*/
|
|
131
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Options for JavaScript minification (UglifyJS options).
|
|
143
|
+
* @typedef {Object} JSMinifyOptions
|
|
144
|
+
* @property {Object} [compress] - Compression options.
|
|
145
|
+
* @property {boolean|Object} [mangle] - Mangling options.
|
|
146
|
+
* @property {Object} [output] - Output format options.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Options for CSS minification (Clean-CSS options).
|
|
151
|
+
* @typedef {Object} CSSMinifyOptions
|
|
152
|
+
* @property {0|1|2|Object} [level] - Optimization level.
|
|
153
|
+
* @property {string|string[]} [compatibility] - Browser compatibility options.
|
|
154
|
+
* @property {string|Object} [format] - Output formatting options.
|
|
155
|
+
*/
|
|
156
|
+
|
|
132
157
|
/**
|
|
133
158
|
* Options for minification configuration.
|
|
134
159
|
* @typedef {Object} MinifyOptions
|
|
135
160
|
* @property {string} [excludeFolder=''] - Folder to exclude from minification.
|
|
136
|
-
* @property {boolean|
|
|
137
|
-
* @property {boolean|
|
|
138
|
-
* @property {
|
|
139
|
-
* @property {
|
|
161
|
+
* @property {boolean|BabelOptions} [useBabel=false] - Whether to use Babel for transformation, and the options for Babel if used.
|
|
162
|
+
* @property {boolean|LogOptions} [useLog=true] - Whether to use logging, and the options for logging if used.
|
|
163
|
+
* @property {JSMinifyOptions} [jsMinifyOptions={}] - Options for JavaScript minification.
|
|
164
|
+
* @property {CSSMinifyOptions} [cssMinifyOptions={}] - Options for CSS minification.
|
|
140
165
|
*/
|
|
141
166
|
|
|
142
167
|
/**
|
|
143
168
|
* Minifies all JavaScript and CSS files in the specified directory and its subdirectories.
|
|
144
169
|
*
|
|
145
|
-
* @async
|
|
146
|
-
* @function minifyAll
|
|
147
170
|
* @param {string} contentPath - The path to the directory containing the files to be minified.
|
|
148
171
|
* @param {MinifyOptions} [options={}] - Options for minification, Babel, and logging.
|
|
149
172
|
* @returns {Promise<void>} A promise that resolves when all files have been processed.
|
package/logs/log-08-22-2024.log
CHANGED
|
@@ -2,3 +2,7 @@
|
|
|
2
2
|
[08/22/2024, 02:34:34] [INFO] Writing file: C:\Users\PEARL\Desktop\uglify-js-minify-css-allfiles\test\test.css
|
|
3
3
|
[08/22/2024, 02:34:35] [INFO] Writing file: C:\Users\PEARL\Desktop\uglify-js-minify-css-allfiles\test\test.js
|
|
4
4
|
[08/22/2024, 02:34:35] [INFO] Processing Summary {"summary":{"totalFilesProcessed":2,"filesWithErrors":0,"errorCount":0,"errorFiles":[]}}
|
|
5
|
+
[08/22/2024, 06:58:25] [INFO] Starting minification process {"contentPath":"./test/","excludeFolder":"lib","useBabel":{"targets":"chrome 40"}}
|
|
6
|
+
[08/22/2024, 06:58:25] [INFO] Writing file: C:\Users\PEARL\Desktop\uglify-js-minify-css-allfiles\test\test.css
|
|
7
|
+
[08/22/2024, 06:58:27] [INFO] Writing file: C:\Users\PEARL\Desktop\uglify-js-minify-css-allfiles\test\test.js
|
|
8
|
+
[08/22/2024, 06:58:27] [INFO] Processing Summary {"summary":{"totalFilesProcessed":2,"filesWithErrors":0,"errorCount":0,"errorFiles":[]}}
|
package/minify.d.ts
CHANGED
|
@@ -105,6 +105,43 @@ declare module 'uglify-js-minify-css-allfiles' {
|
|
|
105
105
|
logToFile?: boolean;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Configuration options for JavaScript minification (UglifyJS options).
|
|
110
|
+
*/
|
|
111
|
+
export interface JSMinifyOptions {
|
|
112
|
+
compress?: {
|
|
113
|
+
dead_code?: boolean;
|
|
114
|
+
drop_debugger?: boolean;
|
|
115
|
+
conditionals?: boolean;
|
|
116
|
+
evaluate?: boolean;
|
|
117
|
+
booleans?: boolean;
|
|
118
|
+
loops?: boolean;
|
|
119
|
+
unused?: boolean;
|
|
120
|
+
hoist_funs?: boolean;
|
|
121
|
+
keep_fargs?: boolean;
|
|
122
|
+
hoist_vars?: boolean;
|
|
123
|
+
if_return?: boolean;
|
|
124
|
+
join_vars?: boolean;
|
|
125
|
+
cascade?: boolean;
|
|
126
|
+
side_effects?: boolean;
|
|
127
|
+
warnings?: boolean;
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
};
|
|
130
|
+
mangle?: boolean | object;
|
|
131
|
+
output?: object;
|
|
132
|
+
[key: string]: any;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Configuration options for CSS minification (Clean-CSS options).
|
|
137
|
+
*/
|
|
138
|
+
export interface CSSMinifyOptions {
|
|
139
|
+
level?: 0 | 1 | 2 | { [key: string]: any };
|
|
140
|
+
compatibility?: string | string[];
|
|
141
|
+
format?: string | object;
|
|
142
|
+
[key: string]: any;
|
|
143
|
+
}
|
|
144
|
+
|
|
108
145
|
/**
|
|
109
146
|
* Configuration options for the minifyAll function.
|
|
110
147
|
*/
|
|
@@ -131,6 +168,18 @@ declare module 'uglify-js-minify-css-allfiles' {
|
|
|
131
168
|
* @default true
|
|
132
169
|
*/
|
|
133
170
|
useLog?: boolean | LogOptions;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Options for JavaScript minification (passed to UglifyJS).
|
|
174
|
+
* @default {}
|
|
175
|
+
*/
|
|
176
|
+
jsMinifyOptions?: JSMinifyOptions;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Options for CSS minification (passed to CleanCSS).
|
|
180
|
+
* @default {}
|
|
181
|
+
*/
|
|
182
|
+
cssMinifyOptions?: CSSMinifyOptions;
|
|
134
183
|
}
|
|
135
184
|
|
|
136
185
|
/**
|