@node-minify/core 8.0.5 → 9.0.0
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/LICENSE +1 -1
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +119 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -85
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -17
package/LICENSE
CHANGED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Settings } from '@node-minify/types';
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* node-minify
|
|
5
|
+
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const minify: {
|
|
10
|
+
(settings: Settings): Promise<unknown>;
|
|
11
|
+
default: any;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { minify as default };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,10 +22,68 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
|
|
25
|
-
// src/
|
|
26
|
-
var
|
|
27
|
-
var import_globby = require("globby");
|
|
25
|
+
// src/compress.ts
|
|
26
|
+
var import_node_fs = __toESM(require("fs"));
|
|
28
27
|
var import_utils = require("@node-minify/utils");
|
|
28
|
+
var import_mkdirp = __toESM(require("mkdirp"));
|
|
29
|
+
var compress = (settings) => {
|
|
30
|
+
if (typeof settings.compressor !== "function") {
|
|
31
|
+
throw new Error(
|
|
32
|
+
"compressor should be a function, maybe you forgot to install the compressor"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (settings.output) {
|
|
36
|
+
createDirectory(settings.output);
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(settings.output)) {
|
|
39
|
+
return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);
|
|
40
|
+
}
|
|
41
|
+
return import_utils.utils.compressSingleFile(settings);
|
|
42
|
+
};
|
|
43
|
+
var compressArrayOfFilesSync = (settings) => {
|
|
44
|
+
return Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
45
|
+
const content = import_utils.utils.getContentFromFiles(input);
|
|
46
|
+
return import_utils.utils.runSync({ settings, content, index });
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var compressArrayOfFilesAsync = (settings) => {
|
|
50
|
+
let sequence = Promise.resolve();
|
|
51
|
+
Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
52
|
+
const content = import_utils.utils.getContentFromFiles(input);
|
|
53
|
+
sequence = sequence.then(
|
|
54
|
+
() => import_utils.utils.runAsync({ settings, content, index })
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
return sequence;
|
|
58
|
+
};
|
|
59
|
+
var createDirectory = (file) => {
|
|
60
|
+
if (Array.isArray(file)) {
|
|
61
|
+
file = file[0];
|
|
62
|
+
}
|
|
63
|
+
const dir = file?.substr(0, file.lastIndexOf("/"));
|
|
64
|
+
if (!dir) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!import_node_fs.default.statSync(dir).isDirectory()) {
|
|
68
|
+
import_mkdirp.default.sync(dir);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/compressInMemory.ts
|
|
73
|
+
var import_utils2 = require("@node-minify/utils");
|
|
74
|
+
var compressInMemory = (settings) => {
|
|
75
|
+
if (typeof settings.compressor !== "function") {
|
|
76
|
+
throw new Error(
|
|
77
|
+
"compressor should be a function, maybe you forgot to install the compressor"
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return import_utils2.utils.compressSingleFile(settings);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/setup.ts
|
|
84
|
+
var import_node_path = __toESM(require("path"));
|
|
85
|
+
var import_utils3 = require("@node-minify/utils");
|
|
86
|
+
var import_fast_glob = require("fast-glob");
|
|
29
87
|
var defaultSettings = {
|
|
30
88
|
sync: false,
|
|
31
89
|
options: {},
|
|
@@ -33,31 +91,62 @@ var defaultSettings = {
|
|
|
33
91
|
callback: false
|
|
34
92
|
};
|
|
35
93
|
var setup = (inputSettings) => {
|
|
36
|
-
let settings = Object.assign(
|
|
94
|
+
let settings = Object.assign(
|
|
95
|
+
import_utils3.utils.clone(defaultSettings),
|
|
96
|
+
inputSettings
|
|
97
|
+
);
|
|
37
98
|
if (settings.content) {
|
|
38
99
|
checkMandatoriesMemoryContent(inputSettings);
|
|
39
100
|
return settings;
|
|
40
101
|
}
|
|
41
102
|
checkMandatories(inputSettings);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
103
|
+
if (settings.input) {
|
|
104
|
+
settings = Object.assign(
|
|
105
|
+
settings,
|
|
106
|
+
wildcards(settings.input, settings.publicFolder)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (settings.input && settings.output) {
|
|
110
|
+
settings = Object.assign(
|
|
111
|
+
settings,
|
|
112
|
+
checkOutput(
|
|
113
|
+
settings.input,
|
|
114
|
+
settings.output,
|
|
115
|
+
settings.publicFolder,
|
|
116
|
+
settings.replaceInPlace
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (settings.input && settings.publicFolder) {
|
|
121
|
+
settings = Object.assign(
|
|
122
|
+
settings,
|
|
123
|
+
setPublicFolder(settings.input, settings.publicFolder)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
48
126
|
return settings;
|
|
49
127
|
};
|
|
50
128
|
var checkOutput = (input, output, publicFolder, replaceInPlace) => {
|
|
51
|
-
const reg =
|
|
129
|
+
const reg = /\$1/;
|
|
52
130
|
if (reg.test(output)) {
|
|
53
131
|
if (Array.isArray(input)) {
|
|
54
132
|
const outputMin = input.map(
|
|
55
|
-
(file) =>
|
|
133
|
+
(file) => import_utils3.utils.setFileNameMin(
|
|
134
|
+
file,
|
|
135
|
+
output,
|
|
136
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
137
|
+
replaceInPlace
|
|
138
|
+
)
|
|
56
139
|
);
|
|
57
140
|
return { output: outputMin };
|
|
58
|
-
} else {
|
|
59
|
-
return { output: import_utils.utils.setFileNameMin(input, output, replaceInPlace ? null : publicFolder, replaceInPlace) };
|
|
60
141
|
}
|
|
142
|
+
return {
|
|
143
|
+
output: import_utils3.utils.setFileNameMin(
|
|
144
|
+
input,
|
|
145
|
+
output,
|
|
146
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
147
|
+
replaceInPlace
|
|
148
|
+
)
|
|
149
|
+
};
|
|
61
150
|
}
|
|
62
151
|
};
|
|
63
152
|
var wildcards = (input, publicFolder) => {
|
|
@@ -84,7 +173,7 @@ var wildcardsArray = (input, publicFolder) => {
|
|
|
84
173
|
return (publicFolder || "") + item;
|
|
85
174
|
});
|
|
86
175
|
if (isWildcardsPresent) {
|
|
87
|
-
output.input = (0,
|
|
176
|
+
output.input = (0, import_fast_glob.globSync)(inputWithPublicFolder);
|
|
88
177
|
}
|
|
89
178
|
for (let i = 0; i < output.input.length; i++) {
|
|
90
179
|
if (output.input[i].indexOf("*") > -1) {
|
|
@@ -97,7 +186,7 @@ var wildcardsArray = (input, publicFolder) => {
|
|
|
97
186
|
var getFilesFromWildcards = (input, publicFolder) => {
|
|
98
187
|
let output = [];
|
|
99
188
|
if (input.indexOf("*") > -1) {
|
|
100
|
-
output = (0,
|
|
189
|
+
output = (0, import_fast_glob.globSync)((publicFolder || "") + input);
|
|
101
190
|
}
|
|
102
191
|
return output;
|
|
103
192
|
};
|
|
@@ -106,85 +195,38 @@ var setPublicFolder = (input, publicFolder) => {
|
|
|
106
195
|
if (typeof publicFolder !== "string") {
|
|
107
196
|
return output;
|
|
108
197
|
}
|
|
109
|
-
publicFolder =
|
|
198
|
+
publicFolder = import_node_path.default.normalize(publicFolder);
|
|
110
199
|
if (Array.isArray(input)) {
|
|
111
200
|
output.input = input.map((item) => {
|
|
112
|
-
if (
|
|
201
|
+
if (import_node_path.default.normalize(item).indexOf(publicFolder) > -1) {
|
|
113
202
|
return item;
|
|
114
203
|
}
|
|
115
|
-
return
|
|
204
|
+
return import_node_path.default.normalize(publicFolder + item);
|
|
116
205
|
});
|
|
117
206
|
return output;
|
|
118
207
|
}
|
|
119
|
-
input =
|
|
208
|
+
input = import_node_path.default.normalize(input);
|
|
120
209
|
if (input.indexOf(publicFolder) > -1) {
|
|
121
210
|
output.input = input;
|
|
122
211
|
return output;
|
|
123
212
|
}
|
|
124
|
-
output.input =
|
|
213
|
+
output.input = import_node_path.default.normalize(publicFolder + input);
|
|
125
214
|
return output;
|
|
126
215
|
};
|
|
127
216
|
var checkMandatories = (settings) => {
|
|
128
|
-
["compressor", "input", "output"].forEach(
|
|
217
|
+
["compressor", "input", "output"].forEach(
|
|
218
|
+
(item) => mandatory(item, settings)
|
|
219
|
+
);
|
|
129
220
|
};
|
|
130
221
|
var checkMandatoriesMemoryContent = (settings) => {
|
|
131
|
-
["compressor", "content"].forEach(
|
|
222
|
+
["compressor", "content"].forEach(
|
|
223
|
+
(item) => mandatory(item, settings)
|
|
224
|
+
);
|
|
132
225
|
};
|
|
133
226
|
var mandatory = (setting, settings) => {
|
|
134
227
|
if (!settings[setting]) {
|
|
135
|
-
throw new Error(setting
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// src/compress.ts
|
|
140
|
-
var import_fs = __toESM(require("fs"));
|
|
141
|
-
var import_mkdirp = __toESM(require("mkdirp"));
|
|
142
|
-
var import_utils2 = require("@node-minify/utils");
|
|
143
|
-
var compress = (settings) => {
|
|
144
|
-
if (typeof settings.compressor !== "function") {
|
|
145
|
-
throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
|
|
146
|
-
}
|
|
147
|
-
createDirectory(settings.output);
|
|
148
|
-
if (Array.isArray(settings.output)) {
|
|
149
|
-
return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);
|
|
150
|
-
} else {
|
|
151
|
-
return import_utils2.utils.compressSingleFile(settings);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
var compressArrayOfFilesSync = (settings) => {
|
|
155
|
-
return Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
156
|
-
const content = import_utils2.utils.getContentFromFiles(input);
|
|
157
|
-
return import_utils2.utils.runSync({ settings, content, index });
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
var compressArrayOfFilesAsync = (settings) => {
|
|
161
|
-
let sequence = Promise.resolve();
|
|
162
|
-
Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
163
|
-
const content = import_utils2.utils.getContentFromFiles(input);
|
|
164
|
-
sequence = sequence.then(() => import_utils2.utils.runAsync({ settings, content, index }));
|
|
165
|
-
});
|
|
166
|
-
return sequence;
|
|
167
|
-
};
|
|
168
|
-
var createDirectory = (file) => {
|
|
169
|
-
if (Array.isArray(file)) {
|
|
170
|
-
file = file[0];
|
|
171
|
-
}
|
|
172
|
-
const dir = file && file.substr(0, file.lastIndexOf("/"));
|
|
173
|
-
if (!dir) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (!import_fs.default.statSync(dir).isDirectory()) {
|
|
177
|
-
import_mkdirp.default.sync(dir);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// src/compressInMemory.ts
|
|
182
|
-
var import_utils3 = require("@node-minify/utils");
|
|
183
|
-
var compressInMemory = (settings) => {
|
|
184
|
-
if (typeof settings.compressor !== "function") {
|
|
185
|
-
throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
|
|
228
|
+
throw new Error(`${setting} is mandatory.`);
|
|
186
229
|
}
|
|
187
|
-
return import_utils3.utils.compressSingleFile(settings);
|
|
188
230
|
};
|
|
189
231
|
|
|
190
232
|
// src/index.ts
|
|
@@ -207,7 +249,7 @@ var minify = (settings) => {
|
|
|
207
249
|
} else {
|
|
208
250
|
const minified = method(settings);
|
|
209
251
|
if (settings.callback) {
|
|
210
|
-
settings.callback(null,
|
|
252
|
+
settings.callback(null, minified);
|
|
211
253
|
}
|
|
212
254
|
resolve(minified);
|
|
213
255
|
}
|
|
@@ -217,7 +259,7 @@ minify.default = minify;
|
|
|
217
259
|
module.exports = minify;
|
|
218
260
|
/*!
|
|
219
261
|
* node-minify
|
|
220
|
-
* Copyright(c) 2011-
|
|
262
|
+
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
221
263
|
* MIT Licensed
|
|
222
264
|
*/
|
|
223
265
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/setup.ts","../src/compress.ts","../src/compressInMemory.ts","../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport path from 'path';\nimport { sync } from 'globby';\nimport { utils } from '@node-minify/utils';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Default settings.\n */\nconst defaultSettings = {\n sync: false,\n options: {},\n buffer: 1000 * 1024,\n callback: false\n};\n\n/**\n * Run setup.\n *\n * @param {Object} inputSettings\n * @return {Object}\n */\nconst setup = (inputSettings: object) => {\n let settings: Settings = Object.assign(utils.clone(defaultSettings), inputSettings);\n\n // In memory\n if (settings.content) {\n checkMandatoriesMemoryContent(inputSettings);\n return settings;\n }\n\n checkMandatories(inputSettings);\n\n settings = Object.assign(settings, wildcards(settings.input, settings.publicFolder));\n settings = Object.assign(\n settings,\n checkOutput(settings.input, settings.output, settings.publicFolder, settings.replaceInPlace)\n );\n settings = Object.assign(settings, setPublicFolder(settings.input, settings.publicFolder));\n\n return settings;\n};\n\n/**\n * Check the output path, searching for $1\n * if exist, returns the path remplacing $1 by file name\n *\n * @param {String|Array} input - Path file\n * @param {String} output - Path to the output file\n * @param {String} publicFolder - Path to the public folder\n * @param {Boolean} replaceInPlace - True to replace file in same folder\n * @return {Object}\n */\nconst checkOutput = (input: string | string[], output: string, publicFolder: string, replaceInPlace: boolean) => {\n const reg = new RegExp('\\\\$1');\n if (reg.test(output)) {\n if (Array.isArray(input)) {\n const outputMin = input.map(file =>\n utils.setFileNameMin(file, output, replaceInPlace ? null : publicFolder, replaceInPlace)\n );\n return { output: outputMin };\n } else {\n return { output: utils.setFileNameMin(input, output, replaceInPlace ? null : publicFolder, replaceInPlace) };\n }\n }\n};\n\n/**\n * Handle wildcards in a path, get the real path of each files.\n *\n * @param {String|Array} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst wildcards = (input: string | string[], publicFolder: string) => {\n // If it's a string\n if (!Array.isArray(input)) {\n return wildcardsString(input, publicFolder);\n }\n\n return wildcardsArray(input, publicFolder);\n};\n\n/**\n * Handle wildcards in a path (string only), get the real path of each files.\n *\n * @param {String} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst wildcardsString = (input: string, publicFolder: string) => {\n const output: { input?: string[] } = {};\n\n if (input.indexOf('*') > -1) {\n output.input = getFilesFromWildcards(input, publicFolder);\n }\n\n return output;\n};\n\n/**\n * Handle wildcards in a path (array only), get the real path of each files.\n *\n * @param {Array} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst wildcardsArray = (input: string[], publicFolder: string) => {\n const output: { input?: string[] } = {};\n let isWildcardsPresent = false;\n\n output.input = input;\n\n // Transform all wildcards to path file\n const inputWithPublicFolder = input.map(item => {\n if (item.indexOf('*') > -1) {\n isWildcardsPresent = true;\n }\n return (publicFolder || '') + item;\n });\n\n if (isWildcardsPresent) {\n output.input = sync(inputWithPublicFolder);\n }\n\n // Remove all wildcards from array\n for (let i = 0; i < output.input.length; i++) {\n if (output.input[i].indexOf('*') > -1) {\n output.input.splice(i, 1);\n\n i--;\n }\n }\n\n return output;\n};\n\n/**\n * Get the real path of each files.\n *\n * @param {String} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst getFilesFromWildcards = (input: string, publicFolder: string) => {\n let output: string[] = [];\n\n if (input.indexOf('*') > -1) {\n output = sync((publicFolder || '') + input);\n }\n\n return output;\n};\n\n/**\n * Prepend the public folder to each file.\n *\n * @param {String|Array} input - Path to file(s)\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst setPublicFolder = (input: string | string[], publicFolder: string) => {\n const output: { input?: string | string[] } = {};\n\n if (typeof publicFolder !== 'string') {\n return output;\n }\n\n publicFolder = path.normalize(publicFolder);\n\n if (Array.isArray(input)) {\n output.input = input.map(item => {\n // Check if publicFolder is already in path\n if (path.normalize(item).indexOf(publicFolder) > -1) {\n return item;\n }\n return path.normalize(publicFolder + item);\n });\n return output;\n }\n\n input = path.normalize(input);\n\n // Check if publicFolder is already in path\n if (input.indexOf(publicFolder) > -1) {\n output.input = input;\n return output;\n }\n\n output.input = path.normalize(publicFolder + input);\n\n return output;\n};\n\n/**\n * Check if some settings are here.\n *\n * @param {Object} settings\n */\nconst checkMandatories = (settings: Settings) => {\n ['compressor', 'input', 'output'].forEach((item: string) => mandatory(item, settings));\n};\n\n/**\n * Check if some settings are here for memory content.\n *\n * @param {Object} settings\n */\nconst checkMandatoriesMemoryContent = (settings: Settings) => {\n ['compressor', 'content'].forEach((item: string) => mandatory(item, settings));\n};\n\n/**\n * Check if the setting exist.\n *\n * @param {String} setting\n * @param {Object} settings\n */\nconst mandatory = (setting: string, settings: Settings) => {\n if (!settings[setting]) {\n throw new Error(setting + ' is mandatory.');\n }\n};\n\n/**\n * Expose `setup()`.\n */\nexport { setup };\n","/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport fs from 'fs';\nimport mkdirp from 'mkdirp';\nimport { utils } from '@node-minify/utils';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Run compressor.\n *\n * @param {Object} settings\n */\nconst compress = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== 'function') {\n throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);\n }\n\n createDirectory(settings.output);\n\n if (Array.isArray(settings.output)) {\n return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);\n } else {\n return utils.compressSingleFile(settings);\n }\n};\n\n/**\n * Compress an array of files in sync.\n *\n * @param {Object} settings\n */\nconst compressArrayOfFilesSync = (settings: Settings): any => {\n return (\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n return utils.runSync({ settings, content, index });\n })\n );\n};\n\n/**\n * Compress an array of files in async.\n *\n * @param {Object} settings\n */\nconst compressArrayOfFilesAsync = (settings: Settings): Promise<string | void> => {\n let sequence: Promise<string | void> = Promise.resolve();\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n sequence = sequence.then(() => utils.runAsync({ settings, content, index }));\n });\n return sequence;\n};\n\n/**\n * Create folder of the target file.\n *\n * @param {String} file - Full path of the file\n */\nconst createDirectory = (file: string) => {\n if (Array.isArray(file)) {\n file = file[0];\n }\n const dir = file && file.substr(0, file.lastIndexOf('/'));\n if (!dir) {\n return;\n }\n if (!fs.statSync(dir).isDirectory()) {\n mkdirp.sync(dir);\n }\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compress };\n","/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { utils } from '@node-minify/utils';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Run compressor.\n *\n * @param {Object} settings\n */\nconst compressInMemory = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== 'function') {\n throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);\n }\n\n return utils.compressSingleFile(settings);\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compressInMemory };\n","/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { setup } from './setup';\nimport { compress } from './compress';\nimport { compressInMemory } from './compressInMemory';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Run node-minify.\n *\n * @param {Object} settings - Settings from user input\n */\nconst minify = (settings: Settings) => {\n return new Promise((resolve, reject) => {\n const method: any = settings.content ? compressInMemory : compress;\n settings = setup(settings);\n if (!settings.sync) {\n method(settings)\n .then((minified: string) => {\n if (settings.callback) {\n settings.callback(null, minified);\n }\n resolve(minified);\n })\n .catch((err: Error) => {\n if (settings.callback) {\n settings.callback(err);\n }\n reject(err);\n });\n } else {\n const minified = method(settings);\n if (settings.callback) {\n settings.callback(null, typeof minified === 'string' ? minified : '');\n }\n resolve(minified);\n }\n });\n};\n\n/**\n * Expose `minify()`.\n */\nminify.default = minify;\nexport = minify;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AASA,kBAAiB;AACjB,oBAAqB;AACrB,mBAAsB;AAMtB,IAAM,kBAAkB;AAAA,EACtB,MAAM;AAAA,EACN,SAAS,CAAC;AAAA,EACV,QAAQ,MAAO;AAAA,EACf,UAAU;AACZ;AAQA,IAAM,QAAQ,CAAC,kBAA0B;AACvC,MAAI,WAAqB,OAAO,OAAO,mBAAM,MAAM,eAAe,GAAG,aAAa;AAGlF,MAAI,SAAS,SAAS;AACpB,kCAA8B,aAAa;AAC3C,WAAO;AAAA,EACT;AAEA,mBAAiB,aAAa;AAE9B,aAAW,OAAO,OAAO,UAAU,UAAU,SAAS,OAAO,SAAS,YAAY,CAAC;AACnF,aAAW,OAAO;AAAA,IAChB;AAAA,IACA,YAAY,SAAS,OAAO,SAAS,QAAQ,SAAS,cAAc,SAAS,cAAc;AAAA,EAC7F;AACA,aAAW,OAAO,OAAO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AAE,YAAY,GAAG;AACnC,kBAAAC,QAAO,KAAK,GAAG;AAAA,EACjB;AACF;;;ACtEA,IAAAC,gBAAsB;AAQtB,IAAM,mBAAmB,CAAC,aAAiD;AACzE,MAAI,OAAO,SAAS,eAAe,YAAY;AAC7C,UAAM,IAAI,MAAM,6EAA6E;AAAA,EAC/F;AAEA,SAAO,oBAAM,mBAAmB,QAAQ;AAC1C;;;ACJA,IAAM,SAAS,CAAC,aAAuB;AACrC,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAc,SAAS,UAAU,mBAAmB;AAC1D,eAAW,MAAM,QAAQ;AACzB,QAAI,CAAC,SAAS,MAAM;AAClB,aAAO,QAAQ,EACZ,KAAK,CAAC,aAAqB;AAC1B,YAAI,SAAS,UAAU;AACrB,mBAAS,SAAS,MAAM,QAAQ;AAAA,QAClC;AACA,gBAAQ,QAAQ;AAAA,MAClB,CAAC,EACA,MAAM,CAAC,QAAe;AACrB,YAAI,SAAS,UAAU;AACrB,mBAAS,SAAS,GAAG;AAAA,QACvB;AACA,eAAO,GAAG;AAAA,MACZ,CAAC;AAAA,IACL,OAAO;AACL,YAAM,WAAW,OAAO,QAAQ;AAChC,UAAI,SAAS,UAAU;AACrB,iBAAS,SAAS,MAAM,OAAO,aAAa,WAAW,WAAW,EAAE;AAAA,MACtE;AACA,cAAQ,QAAQ;AAAA,IAClB;AAAA,EACF,CAAC;AACH;AAKA,OAAO,UAAU;AACjB,iBAAS;","names":["path","import_utils","fs","mkdirp","import_utils"]}
|
|
1
|
+
{"version":3,"sources":["../src/compress.ts","../src/compressInMemory.ts","../src/setup.ts","../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport fs from \"node:fs\";\nimport type { Settings } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\nimport mkdirp from \"mkdirp\";\n\n/**\n * Run compressor.\n * @param settings Settings\n */\nconst compress = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== \"function\") {\n throw new Error(\n \"compressor should be a function, maybe you forgot to install the compressor\"\n );\n }\n\n if (settings.output) {\n createDirectory(settings.output);\n }\n\n if (Array.isArray(settings.output)) {\n return settings.sync\n ? compressArrayOfFilesSync(settings)\n : compressArrayOfFilesAsync(settings);\n }\n return utils.compressSingleFile(settings);\n};\n\n/**\n * Compress an array of files in sync.\n * @param settings Settings\n */\nconst compressArrayOfFilesSync = (settings: Settings): any => {\n return (\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n return utils.runSync({ settings, content, index });\n })\n );\n};\n\n/**\n * Compress an array of files in async.\n * @param settings Settings\n */\nconst compressArrayOfFilesAsync = (\n settings: Settings\n): Promise<string | void> => {\n let sequence: Promise<string | void> = Promise.resolve();\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n sequence = sequence.then(() =>\n utils.runAsync({ settings, content, index })\n );\n });\n return sequence;\n};\n\n/**\n * Create folder of the target file.\n * @param file Full path of the file\n */\nconst createDirectory = (file: string) => {\n if (Array.isArray(file)) {\n file = file[0];\n }\n const dir = file?.substr(0, file.lastIndexOf(\"/\"));\n if (!dir) {\n return;\n }\n if (!fs.statSync(dir).isDirectory()) {\n mkdirp.sync(dir);\n }\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compress };\n","/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport type { Settings } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\n\n/**\n * Run compressor.\n * @param settings Settings\n */\nconst compressInMemory = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== \"function\") {\n throw new Error(\n \"compressor should be a function, maybe you forgot to install the compressor\"\n );\n }\n\n return utils.compressSingleFile(settings);\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compressInMemory };\n","/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport path from \"node:path\";\nimport type { Settings } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\nimport { globSync } from \"fast-glob\";\n\n/**\n * Default settings.\n */\nconst defaultSettings = {\n sync: false,\n options: {},\n buffer: 1000 * 1024,\n callback: false,\n};\n\n/**\n * Run setup.\n * @param inputSettings Settings from user input\n */\nconst setup = (inputSettings: Settings) => {\n let settings: Settings = Object.assign(\n utils.clone(defaultSettings),\n inputSettings\n );\n\n // In memory\n if (settings.content) {\n checkMandatoriesMemoryContent(inputSettings);\n return settings;\n }\n\n checkMandatories(inputSettings);\n\n if (settings.input) {\n settings = Object.assign(\n settings,\n wildcards(settings.input, settings.publicFolder)\n );\n }\n if (settings.input && settings.output) {\n settings = Object.assign(\n settings,\n checkOutput(\n settings.input,\n settings.output,\n settings.publicFolder,\n settings.replaceInPlace\n )\n );\n }\n if (settings.input && settings.publicFolder) {\n settings = Object.assign(\n settings,\n setPublicFolder(settings.input, settings.publicFolder)\n );\n }\n\n return settings;\n};\n\n/**\n * Check the output path, searching for $1\n * if exist, returns the path replacing $1 by file name\n * @param input Path file\n * @param output Path to the output file\n * @param publicFolder Path to the public folder\n * @param replaceInPlace True to replace file in same folder\n */\nconst checkOutput = (\n input: string | string[],\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n) => {\n const reg = /\\$1/;\n if (reg.test(output)) {\n if (Array.isArray(input)) {\n const outputMin = input.map((file) =>\n utils.setFileNameMin(\n file,\n output,\n replaceInPlace ? undefined : publicFolder,\n replaceInPlace\n )\n );\n return { output: outputMin };\n }\n return {\n output: utils.setFileNameMin(\n input,\n output,\n replaceInPlace ? undefined : publicFolder,\n replaceInPlace\n ),\n };\n }\n};\n\n/**\n * Handle wildcards in a path, get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst wildcards = (input: string | string[], publicFolder?: string) => {\n // If it's a string\n if (!Array.isArray(input)) {\n return wildcardsString(input, publicFolder);\n }\n\n return wildcardsArray(input, publicFolder);\n};\n\n/**\n * Handle wildcards in a path (string only), get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst wildcardsString = (input: string, publicFolder?: string) => {\n const output: { input?: string[] } = {};\n\n if (input.indexOf(\"*\") > -1) {\n output.input = getFilesFromWildcards(input, publicFolder);\n }\n\n return output;\n};\n\n/**\n * Handle wildcards in a path (array only), get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst wildcardsArray = (input: string[], publicFolder?: string) => {\n const output: { input?: string[] } = {};\n let isWildcardsPresent = false;\n\n output.input = input;\n\n // Transform all wildcards to path file\n const inputWithPublicFolder = input.map((item) => {\n if (item.indexOf(\"*\") > -1) {\n isWildcardsPresent = true;\n }\n return (publicFolder || \"\") + item;\n });\n\n if (isWildcardsPresent) {\n output.input = globSync(inputWithPublicFolder);\n }\n\n // Remove all wildcards from array\n for (let i = 0; i < output.input.length; i++) {\n if (output.input[i].indexOf(\"*\") > -1) {\n output.input.splice(i, 1);\n\n i--;\n }\n }\n\n return output;\n};\n\n/**\n * Get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst getFilesFromWildcards = (input: string, publicFolder?: string) => {\n let output: string[] = [];\n\n if (input.indexOf(\"*\") > -1) {\n output = globSync((publicFolder || \"\") + input);\n }\n\n return output;\n};\n\n/**\n * Prepend the public folder to each file.\n * @param input Path to file(s)\n * @param publicFolder Path to the public folder\n */\nconst setPublicFolder = (input: string | string[], publicFolder: string) => {\n const output: { input?: string | string[] } = {};\n\n if (typeof publicFolder !== \"string\") {\n return output;\n }\n\n publicFolder = path.normalize(publicFolder);\n\n if (Array.isArray(input)) {\n output.input = input.map((item) => {\n // Check if publicFolder is already in path\n if (path.normalize(item).indexOf(publicFolder) > -1) {\n return item;\n }\n return path.normalize(publicFolder + item);\n });\n return output;\n }\n\n input = path.normalize(input);\n\n // Check if publicFolder is already in path\n if (input.indexOf(publicFolder) > -1) {\n output.input = input;\n return output;\n }\n\n output.input = path.normalize(publicFolder + input);\n\n return output;\n};\n\n/**\n * Check if some settings are here.\n * @param settings Settings\n */\nconst checkMandatories = (settings: Settings) => {\n [\"compressor\", \"input\", \"output\"].forEach((item: string) =>\n mandatory(item, settings)\n );\n};\n\n/**\n * Check if some settings are here for memory content.\n * @param settings Settings\n */\nconst checkMandatoriesMemoryContent = (settings: Settings) => {\n [\"compressor\", \"content\"].forEach((item: string) =>\n mandatory(item, settings)\n );\n};\n\n/**\n * Check if the setting exist.\n * @param setting Setting\n * @param settings Settings\n */\nconst mandatory = (setting: string, settings: { [key: string]: any }) => {\n if (!settings[setting]) {\n throw new Error(`${setting} is mandatory.`);\n }\n};\n\n/**\n * Expose `setup()`.\n */\nexport { setup };\n","/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport type { Settings } from \"@node-minify/types\";\nimport { compress } from \"./compress\";\nimport { compressInMemory } from \"./compressInMemory\";\nimport { setup } from \"./setup\";\n\n/**\n * Run node-minify.\n * @param settings Settings from user input\n */\nconst minify = (settings: Settings) => {\n return new Promise((resolve, reject) => {\n const method: any = settings.content ? compressInMemory : compress;\n settings = setup(settings);\n if (!settings.sync) {\n method(settings)\n .then((minified: string) => {\n if (settings.callback) {\n settings.callback(null, minified);\n }\n resolve(minified);\n })\n .catch((err: Error) => {\n if (settings.callback) {\n settings.callback(err);\n }\n reject(err);\n });\n } else {\n const minified: string = method(settings);\n if (settings.callback) {\n settings.callback(null, minified);\n }\n resolve(minified);\n }\n });\n};\n\n/**\n * Expose `minify()`.\n */\nminify.default = minify;\nexport = minify;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AASA,qBAAe;AAEf,mBAAsB;AACtB,oBAAmB;AAMnB,I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AAO,QAAQ,EACV,KAAK,CAAC,aAAqB;AACxB,YAAI,SAAS,UAAU;AACnB,mBAAS,SAAS,MAAM,QAAQ;AAAA,QACpC;AACA,gBAAQ,QAAQ;AAAA,MACpB,CAAC,EACA,MAAM,CAAC,QAAe;AACnB,YAAI,SAAS,UAAU;AACnB,mBAAS,SAAS,GAAG;AAAA,QACzB;AACA,eAAO,GAAG;AAAA,MACd,CAAC;AAAA,IACT,OAAO;AACH,YAAM,WAAmB,OAAO,QAAQ;AACxC,UAAI,SAAS,UAAU;AACnB,iBAAS,SAAS,MAAM,QAAQ;AAAA,MACpC;AACA,cAAQ,QAAQ;AAAA,IACpB;AAAA,EACJ,CAAC;AACL;AAKA,OAAO,UAAU;AACjB,iBAAS;","names":["fs","mkdirp","import_utils","import_utils","path"]}
|
package/dist/index.mjs
CHANGED
|
@@ -6,10 +6,80 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
6
6
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
// src/
|
|
10
|
-
import
|
|
11
|
-
import { sync } from "globby";
|
|
9
|
+
// src/compress.ts
|
|
10
|
+
import fs from "node:fs";
|
|
12
11
|
import { utils } from "@node-minify/utils";
|
|
12
|
+
import mkdirp from "mkdirp";
|
|
13
|
+
var compress, compressArrayOfFilesSync, compressArrayOfFilesAsync, createDirectory;
|
|
14
|
+
var init_compress = __esm({
|
|
15
|
+
"src/compress.ts"() {
|
|
16
|
+
"use strict";
|
|
17
|
+
compress = (settings) => {
|
|
18
|
+
if (typeof settings.compressor !== "function") {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"compressor should be a function, maybe you forgot to install the compressor"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if (settings.output) {
|
|
24
|
+
createDirectory(settings.output);
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(settings.output)) {
|
|
27
|
+
return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);
|
|
28
|
+
}
|
|
29
|
+
return utils.compressSingleFile(settings);
|
|
30
|
+
};
|
|
31
|
+
compressArrayOfFilesSync = (settings) => {
|
|
32
|
+
return Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
33
|
+
const content = utils.getContentFromFiles(input);
|
|
34
|
+
return utils.runSync({ settings, content, index });
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
compressArrayOfFilesAsync = (settings) => {
|
|
38
|
+
let sequence = Promise.resolve();
|
|
39
|
+
Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
40
|
+
const content = utils.getContentFromFiles(input);
|
|
41
|
+
sequence = sequence.then(
|
|
42
|
+
() => utils.runAsync({ settings, content, index })
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
return sequence;
|
|
46
|
+
};
|
|
47
|
+
createDirectory = (file) => {
|
|
48
|
+
if (Array.isArray(file)) {
|
|
49
|
+
file = file[0];
|
|
50
|
+
}
|
|
51
|
+
const dir = file?.substr(0, file.lastIndexOf("/"));
|
|
52
|
+
if (!dir) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!fs.statSync(dir).isDirectory()) {
|
|
56
|
+
mkdirp.sync(dir);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// src/compressInMemory.ts
|
|
63
|
+
import { utils as utils2 } from "@node-minify/utils";
|
|
64
|
+
var compressInMemory;
|
|
65
|
+
var init_compressInMemory = __esm({
|
|
66
|
+
"src/compressInMemory.ts"() {
|
|
67
|
+
"use strict";
|
|
68
|
+
compressInMemory = (settings) => {
|
|
69
|
+
if (typeof settings.compressor !== "function") {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"compressor should be a function, maybe you forgot to install the compressor"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return utils2.compressSingleFile(settings);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// src/setup.ts
|
|
80
|
+
import path from "node:path";
|
|
81
|
+
import { utils as utils3 } from "@node-minify/utils";
|
|
82
|
+
import { globSync } from "fast-glob";
|
|
13
83
|
var defaultSettings, setup, checkOutput, wildcards, wildcardsString, wildcardsArray, getFilesFromWildcards, setPublicFolder, checkMandatories, checkMandatoriesMemoryContent, mandatory;
|
|
14
84
|
var init_setup = __esm({
|
|
15
85
|
"src/setup.ts"() {
|
|
@@ -21,31 +91,62 @@ var init_setup = __esm({
|
|
|
21
91
|
callback: false
|
|
22
92
|
};
|
|
23
93
|
setup = (inputSettings) => {
|
|
24
|
-
let settings = Object.assign(
|
|
94
|
+
let settings = Object.assign(
|
|
95
|
+
utils3.clone(defaultSettings),
|
|
96
|
+
inputSettings
|
|
97
|
+
);
|
|
25
98
|
if (settings.content) {
|
|
26
99
|
checkMandatoriesMemoryContent(inputSettings);
|
|
27
100
|
return settings;
|
|
28
101
|
}
|
|
29
102
|
checkMandatories(inputSettings);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
103
|
+
if (settings.input) {
|
|
104
|
+
settings = Object.assign(
|
|
105
|
+
settings,
|
|
106
|
+
wildcards(settings.input, settings.publicFolder)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (settings.input && settings.output) {
|
|
110
|
+
settings = Object.assign(
|
|
111
|
+
settings,
|
|
112
|
+
checkOutput(
|
|
113
|
+
settings.input,
|
|
114
|
+
settings.output,
|
|
115
|
+
settings.publicFolder,
|
|
116
|
+
settings.replaceInPlace
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (settings.input && settings.publicFolder) {
|
|
121
|
+
settings = Object.assign(
|
|
122
|
+
settings,
|
|
123
|
+
setPublicFolder(settings.input, settings.publicFolder)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
36
126
|
return settings;
|
|
37
127
|
};
|
|
38
128
|
checkOutput = (input, output, publicFolder, replaceInPlace) => {
|
|
39
|
-
const reg =
|
|
129
|
+
const reg = /\$1/;
|
|
40
130
|
if (reg.test(output)) {
|
|
41
131
|
if (Array.isArray(input)) {
|
|
42
132
|
const outputMin = input.map(
|
|
43
|
-
(file) =>
|
|
133
|
+
(file) => utils3.setFileNameMin(
|
|
134
|
+
file,
|
|
135
|
+
output,
|
|
136
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
137
|
+
replaceInPlace
|
|
138
|
+
)
|
|
44
139
|
);
|
|
45
140
|
return { output: outputMin };
|
|
46
|
-
} else {
|
|
47
|
-
return { output: utils.setFileNameMin(input, output, replaceInPlace ? null : publicFolder, replaceInPlace) };
|
|
48
141
|
}
|
|
142
|
+
return {
|
|
143
|
+
output: utils3.setFileNameMin(
|
|
144
|
+
input,
|
|
145
|
+
output,
|
|
146
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
147
|
+
replaceInPlace
|
|
148
|
+
)
|
|
149
|
+
};
|
|
49
150
|
}
|
|
50
151
|
};
|
|
51
152
|
wildcards = (input, publicFolder) => {
|
|
@@ -72,7 +173,7 @@ var init_setup = __esm({
|
|
|
72
173
|
return (publicFolder || "") + item;
|
|
73
174
|
});
|
|
74
175
|
if (isWildcardsPresent) {
|
|
75
|
-
output.input =
|
|
176
|
+
output.input = globSync(inputWithPublicFolder);
|
|
76
177
|
}
|
|
77
178
|
for (let i = 0; i < output.input.length; i++) {
|
|
78
179
|
if (output.input[i].indexOf("*") > -1) {
|
|
@@ -85,7 +186,7 @@ var init_setup = __esm({
|
|
|
85
186
|
getFilesFromWildcards = (input, publicFolder) => {
|
|
86
187
|
let output = [];
|
|
87
188
|
if (input.indexOf("*") > -1) {
|
|
88
|
-
output =
|
|
189
|
+
output = globSync((publicFolder || "") + input);
|
|
89
190
|
}
|
|
90
191
|
return output;
|
|
91
192
|
};
|
|
@@ -113,88 +214,29 @@ var init_setup = __esm({
|
|
|
113
214
|
return output;
|
|
114
215
|
};
|
|
115
216
|
checkMandatories = (settings) => {
|
|
116
|
-
["compressor", "input", "output"].forEach(
|
|
217
|
+
["compressor", "input", "output"].forEach(
|
|
218
|
+
(item) => mandatory(item, settings)
|
|
219
|
+
);
|
|
117
220
|
};
|
|
118
221
|
checkMandatoriesMemoryContent = (settings) => {
|
|
119
|
-
["compressor", "content"].forEach(
|
|
222
|
+
["compressor", "content"].forEach(
|
|
223
|
+
(item) => mandatory(item, settings)
|
|
224
|
+
);
|
|
120
225
|
};
|
|
121
226
|
mandatory = (setting, settings) => {
|
|
122
227
|
if (!settings[setting]) {
|
|
123
|
-
throw new Error(setting
|
|
228
|
+
throw new Error(`${setting} is mandatory.`);
|
|
124
229
|
}
|
|
125
230
|
};
|
|
126
231
|
}
|
|
127
232
|
});
|
|
128
233
|
|
|
129
|
-
// src/compress.ts
|
|
130
|
-
import fs from "fs";
|
|
131
|
-
import mkdirp from "mkdirp";
|
|
132
|
-
import { utils as utils2 } from "@node-minify/utils";
|
|
133
|
-
var compress, compressArrayOfFilesSync, compressArrayOfFilesAsync, createDirectory;
|
|
134
|
-
var init_compress = __esm({
|
|
135
|
-
"src/compress.ts"() {
|
|
136
|
-
"use strict";
|
|
137
|
-
compress = (settings) => {
|
|
138
|
-
if (typeof settings.compressor !== "function") {
|
|
139
|
-
throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
|
|
140
|
-
}
|
|
141
|
-
createDirectory(settings.output);
|
|
142
|
-
if (Array.isArray(settings.output)) {
|
|
143
|
-
return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);
|
|
144
|
-
} else {
|
|
145
|
-
return utils2.compressSingleFile(settings);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
compressArrayOfFilesSync = (settings) => {
|
|
149
|
-
return Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
150
|
-
const content = utils2.getContentFromFiles(input);
|
|
151
|
-
return utils2.runSync({ settings, content, index });
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
compressArrayOfFilesAsync = (settings) => {
|
|
155
|
-
let sequence = Promise.resolve();
|
|
156
|
-
Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
157
|
-
const content = utils2.getContentFromFiles(input);
|
|
158
|
-
sequence = sequence.then(() => utils2.runAsync({ settings, content, index }));
|
|
159
|
-
});
|
|
160
|
-
return sequence;
|
|
161
|
-
};
|
|
162
|
-
createDirectory = (file) => {
|
|
163
|
-
if (Array.isArray(file)) {
|
|
164
|
-
file = file[0];
|
|
165
|
-
}
|
|
166
|
-
const dir = file && file.substr(0, file.lastIndexOf("/"));
|
|
167
|
-
if (!dir) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (!fs.statSync(dir).isDirectory()) {
|
|
171
|
-
mkdirp.sync(dir);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// src/compressInMemory.ts
|
|
178
|
-
import { utils as utils3 } from "@node-minify/utils";
|
|
179
|
-
var compressInMemory;
|
|
180
|
-
var init_compressInMemory = __esm({
|
|
181
|
-
"src/compressInMemory.ts"() {
|
|
182
|
-
"use strict";
|
|
183
|
-
compressInMemory = (settings) => {
|
|
184
|
-
if (typeof settings.compressor !== "function") {
|
|
185
|
-
throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
|
|
186
|
-
}
|
|
187
|
-
return utils3.compressSingleFile(settings);
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
234
|
// src/index.ts
|
|
193
235
|
var require_src = __commonJS({
|
|
194
236
|
"src/index.ts"(exports, module) {
|
|
195
|
-
init_setup();
|
|
196
237
|
init_compress();
|
|
197
238
|
init_compressInMemory();
|
|
239
|
+
init_setup();
|
|
198
240
|
var minify = (settings) => {
|
|
199
241
|
return new Promise((resolve, reject) => {
|
|
200
242
|
const method = settings.content ? compressInMemory : compress;
|
|
@@ -214,7 +256,7 @@ var require_src = __commonJS({
|
|
|
214
256
|
} else {
|
|
215
257
|
const minified = method(settings);
|
|
216
258
|
if (settings.callback) {
|
|
217
|
-
settings.callback(null,
|
|
259
|
+
settings.callback(null, minified);
|
|
218
260
|
}
|
|
219
261
|
resolve(minified);
|
|
220
262
|
}
|
|
@@ -227,7 +269,7 @@ var require_src = __commonJS({
|
|
|
227
269
|
export default require_src();
|
|
228
270
|
/*!
|
|
229
271
|
* node-minify
|
|
230
|
-
* Copyright(c) 2011-
|
|
272
|
+
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
231
273
|
* MIT Licensed
|
|
232
274
|
*/
|
|
233
275
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/setup.ts","../src/compress.ts","../src/compressInMemory.ts","../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport path from 'path';\nimport { sync } from 'globby';\nimport { utils } from '@node-minify/utils';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Default settings.\n */\nconst defaultSettings = {\n sync: false,\n options: {},\n buffer: 1000 * 1024,\n callback: false\n};\n\n/**\n * Run setup.\n *\n * @param {Object} inputSettings\n * @return {Object}\n */\nconst setup = (inputSettings: object) => {\n let settings: Settings = Object.assign(utils.clone(defaultSettings), inputSettings);\n\n // In memory\n if (settings.content) {\n checkMandatoriesMemoryContent(inputSettings);\n return settings;\n }\n\n checkMandatories(inputSettings);\n\n settings = Object.assign(settings, wildcards(settings.input, settings.publicFolder));\n settings = Object.assign(\n settings,\n checkOutput(settings.input, settings.output, settings.publicFolder, settings.replaceInPlace)\n );\n settings = Object.assign(settings, setPublicFolder(settings.input, settings.publicFolder));\n\n return settings;\n};\n\n/**\n * Check the output path, searching for $1\n * if exist, returns the path remplacing $1 by file name\n *\n * @param {String|Array} input - Path file\n * @param {String} output - Path to the output file\n * @param {String} publicFolder - Path to the public folder\n * @param {Boolean} replaceInPlace - True to replace file in same folder\n * @return {Object}\n */\nconst checkOutput = (input: string | string[], output: string, publicFolder: string, replaceInPlace: boolean) => {\n const reg = new RegExp('\\\\$1');\n if (reg.test(output)) {\n if (Array.isArray(input)) {\n const outputMin = input.map(file =>\n utils.setFileNameMin(file, output, replaceInPlace ? null : publicFolder, replaceInPlace)\n );\n return { output: outputMin };\n } else {\n return { output: utils.setFileNameMin(input, output, replaceInPlace ? null : publicFolder, replaceInPlace) };\n }\n }\n};\n\n/**\n * Handle wildcards in a path, get the real path of each files.\n *\n * @param {String|Array} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst wildcards = (input: string | string[], publicFolder: string) => {\n // If it's a string\n if (!Array.isArray(input)) {\n return wildcardsString(input, publicFolder);\n }\n\n return wildcardsArray(input, publicFolder);\n};\n\n/**\n * Handle wildcards in a path (string only), get the real path of each files.\n *\n * @param {String} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst wildcardsString = (input: string, publicFolder: string) => {\n const output: { input?: string[] } = {};\n\n if (input.indexOf('*') > -1) {\n output.input = getFilesFromWildcards(input, publicFolder);\n }\n\n return output;\n};\n\n/**\n * Handle wildcards in a path (array only), get the real path of each files.\n *\n * @param {Array} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst wildcardsArray = (input: string[], publicFolder: string) => {\n const output: { input?: string[] } = {};\n let isWildcardsPresent = false;\n\n output.input = input;\n\n // Transform all wildcards to path file\n const inputWithPublicFolder = input.map(item => {\n if (item.indexOf('*') > -1) {\n isWildcardsPresent = true;\n }\n return (publicFolder || '') + item;\n });\n\n if (isWildcardsPresent) {\n output.input = sync(inputWithPublicFolder);\n }\n\n // Remove all wildcards from array\n for (let i = 0; i < output.input.length; i++) {\n if (output.input[i].indexOf('*') > -1) {\n output.input.splice(i, 1);\n\n i--;\n }\n }\n\n return output;\n};\n\n/**\n * Get the real path of each files.\n *\n * @param {String} input - Path with wildcards\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst getFilesFromWildcards = (input: string, publicFolder: string) => {\n let output: string[] = [];\n\n if (input.indexOf('*') > -1) {\n output = sync((publicFolder || '') + input);\n }\n\n return output;\n};\n\n/**\n * Prepend the public folder to each file.\n *\n * @param {String|Array} input - Path to file(s)\n * @param {String} publicFolder - Path to the public folder\n * @return {Object}\n */\nconst setPublicFolder = (input: string | string[], publicFolder: string) => {\n const output: { input?: string | string[] } = {};\n\n if (typeof publicFolder !== 'string') {\n return output;\n }\n\n publicFolder = path.normalize(publicFolder);\n\n if (Array.isArray(input)) {\n output.input = input.map(item => {\n // Check if publicFolder is already in path\n if (path.normalize(item).indexOf(publicFolder) > -1) {\n return item;\n }\n return path.normalize(publicFolder + item);\n });\n return output;\n }\n\n input = path.normalize(input);\n\n // Check if publicFolder is already in path\n if (input.indexOf(publicFolder) > -1) {\n output.input = input;\n return output;\n }\n\n output.input = path.normalize(publicFolder + input);\n\n return output;\n};\n\n/**\n * Check if some settings are here.\n *\n * @param {Object} settings\n */\nconst checkMandatories = (settings: Settings) => {\n ['compressor', 'input', 'output'].forEach((item: string) => mandatory(item, settings));\n};\n\n/**\n * Check if some settings are here for memory content.\n *\n * @param {Object} settings\n */\nconst checkMandatoriesMemoryContent = (settings: Settings) => {\n ['compressor', 'content'].forEach((item: string) => mandatory(item, settings));\n};\n\n/**\n * Check if the setting exist.\n *\n * @param {String} setting\n * @param {Object} settings\n */\nconst mandatory = (setting: string, settings: Settings) => {\n if (!settings[setting]) {\n throw new Error(setting + ' is mandatory.');\n }\n};\n\n/**\n * Expose `setup()`.\n */\nexport { setup };\n","/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport fs from 'fs';\nimport mkdirp from 'mkdirp';\nimport { utils } from '@node-minify/utils';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Run compressor.\n *\n * @param {Object} settings\n */\nconst compress = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== 'function') {\n throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);\n }\n\n createDirectory(settings.output);\n\n if (Array.isArray(settings.output)) {\n return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);\n } else {\n return utils.compressSingleFile(settings);\n }\n};\n\n/**\n * Compress an array of files in sync.\n *\n * @param {Object} settings\n */\nconst compressArrayOfFilesSync = (settings: Settings): any => {\n return (\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n return utils.runSync({ settings, content, index });\n })\n );\n};\n\n/**\n * Compress an array of files in async.\n *\n * @param {Object} settings\n */\nconst compressArrayOfFilesAsync = (settings: Settings): Promise<string | void> => {\n let sequence: Promise<string | void> = Promise.resolve();\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n sequence = sequence.then(() => utils.runAsync({ settings, content, index }));\n });\n return sequence;\n};\n\n/**\n * Create folder of the target file.\n *\n * @param {String} file - Full path of the file\n */\nconst createDirectory = (file: string) => {\n if (Array.isArray(file)) {\n file = file[0];\n }\n const dir = file && file.substr(0, file.lastIndexOf('/'));\n if (!dir) {\n return;\n }\n if (!fs.statSync(dir).isDirectory()) {\n mkdirp.sync(dir);\n }\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compress };\n","/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { utils } from '@node-minify/utils';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Run compressor.\n *\n * @param {Object} settings\n */\nconst compressInMemory = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== 'function') {\n throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);\n }\n\n return utils.compressSingleFile(settings);\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compressInMemory };\n","/*!\n * node-minify\n * Copyright(c) 2011-2023 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport { setup } from './setup';\nimport { compress } from './compress';\nimport { compressInMemory } from './compressInMemory';\nimport { Settings } from '@node-minify/types';\n\n/**\n * Run node-minify.\n *\n * @param {Object} settings - Settings from user input\n */\nconst minify = (settings: Settings) => {\n return new Promise((resolve, reject) => {\n const method: any = settings.content ? compressInMemory : compress;\n settings = setup(settings);\n if (!settings.sync) {\n method(settings)\n .then((minified: string) => {\n if (settings.callback) {\n settings.callback(null, minified);\n }\n resolve(minified);\n })\n .catch((err: Error) => {\n if (settings.callback) {\n settings.callback(err);\n }\n reject(err);\n });\n } else {\n const minified = method(settings);\n if (settings.callback) {\n settings.callback(null, typeof minified === 'string' ? minified : '');\n }\n resolve(minified);\n }\n });\n};\n\n/**\n * Expose `minify()`.\n */\nminify.default = minify;\nexport = minify;\n"],"mappings":";;;;;;;;;AASA,OAAO,UAAU;AACjB,SAAS,YAAY;AACrB,SAAS,aAAa;AAXtB,IAiBM,iBAaA,OA+BA,aAqBA,WAgBA,iBAiBA,gBAqCA,uBAiBA,iBAsCA,kBASA,+BAUA;AAlON;AAAA;AAAA;AAiBA,IAAM,kBAAkB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS,CAAC;AAAA,MACV,QAAQ,MAAO;AAAA,MACf,UAAU;AAAA,IACZ;AAQA,IAAM,QAAQ,CAAC,kBAA0B;AACvC,UAAI,WAAqB,OAAO,OAAO,MAAM,MAAM,eAAe,GAAG,aAAa;AAGlF,UAAI,SAAS,SAAS;AACpB,sCAA8B,aAAa;AAC3C,eAAO;AAAA,MACT;AAEA,uBAAiB,aAAa;AAE9B,iBAAW,OAAO,OAAO,UAAU,UAAU,SAAS,OAAO,SAAS,YAAY,CAAC;AACnF,iBAAW,OAA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A,WAAO,UAAU;AACjB,qBAAS;AAAA;AAAA;","names":["utils","utils"]}
|
|
1
|
+
{"version":3,"sources":["../src/compress.ts","../src/compressInMemory.ts","../src/setup.ts","../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport fs from \"node:fs\";\nimport type { Settings } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\nimport mkdirp from \"mkdirp\";\n\n/**\n * Run compressor.\n * @param settings Settings\n */\nconst compress = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== \"function\") {\n throw new Error(\n \"compressor should be a function, maybe you forgot to install the compressor\"\n );\n }\n\n if (settings.output) {\n createDirectory(settings.output);\n }\n\n if (Array.isArray(settings.output)) {\n return settings.sync\n ? compressArrayOfFilesSync(settings)\n : compressArrayOfFilesAsync(settings);\n }\n return utils.compressSingleFile(settings);\n};\n\n/**\n * Compress an array of files in sync.\n * @param settings Settings\n */\nconst compressArrayOfFilesSync = (settings: Settings): any => {\n return (\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n return utils.runSync({ settings, content, index });\n })\n );\n};\n\n/**\n * Compress an array of files in async.\n * @param settings Settings\n */\nconst compressArrayOfFilesAsync = (\n settings: Settings\n): Promise<string | void> => {\n let sequence: Promise<string | void> = Promise.resolve();\n Array.isArray(settings.input) &&\n settings.input.forEach((input, index) => {\n const content = utils.getContentFromFiles(input);\n sequence = sequence.then(() =>\n utils.runAsync({ settings, content, index })\n );\n });\n return sequence;\n};\n\n/**\n * Create folder of the target file.\n * @param file Full path of the file\n */\nconst createDirectory = (file: string) => {\n if (Array.isArray(file)) {\n file = file[0];\n }\n const dir = file?.substr(0, file.lastIndexOf(\"/\"));\n if (!dir) {\n return;\n }\n if (!fs.statSync(dir).isDirectory()) {\n mkdirp.sync(dir);\n }\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compress };\n","/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport type { Settings } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\n\n/**\n * Run compressor.\n * @param settings Settings\n */\nconst compressInMemory = (settings: Settings): Promise<string> | string => {\n if (typeof settings.compressor !== \"function\") {\n throw new Error(\n \"compressor should be a function, maybe you forgot to install the compressor\"\n );\n }\n\n return utils.compressSingleFile(settings);\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compressInMemory };\n","/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport path from \"node:path\";\nimport type { Settings } from \"@node-minify/types\";\nimport { utils } from \"@node-minify/utils\";\nimport { globSync } from \"fast-glob\";\n\n/**\n * Default settings.\n */\nconst defaultSettings = {\n sync: false,\n options: {},\n buffer: 1000 * 1024,\n callback: false,\n};\n\n/**\n * Run setup.\n * @param inputSettings Settings from user input\n */\nconst setup = (inputSettings: Settings) => {\n let settings: Settings = Object.assign(\n utils.clone(defaultSettings),\n inputSettings\n );\n\n // In memory\n if (settings.content) {\n checkMandatoriesMemoryContent(inputSettings);\n return settings;\n }\n\n checkMandatories(inputSettings);\n\n if (settings.input) {\n settings = Object.assign(\n settings,\n wildcards(settings.input, settings.publicFolder)\n );\n }\n if (settings.input && settings.output) {\n settings = Object.assign(\n settings,\n checkOutput(\n settings.input,\n settings.output,\n settings.publicFolder,\n settings.replaceInPlace\n )\n );\n }\n if (settings.input && settings.publicFolder) {\n settings = Object.assign(\n settings,\n setPublicFolder(settings.input, settings.publicFolder)\n );\n }\n\n return settings;\n};\n\n/**\n * Check the output path, searching for $1\n * if exist, returns the path replacing $1 by file name\n * @param input Path file\n * @param output Path to the output file\n * @param publicFolder Path to the public folder\n * @param replaceInPlace True to replace file in same folder\n */\nconst checkOutput = (\n input: string | string[],\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n) => {\n const reg = /\\$1/;\n if (reg.test(output)) {\n if (Array.isArray(input)) {\n const outputMin = input.map((file) =>\n utils.setFileNameMin(\n file,\n output,\n replaceInPlace ? undefined : publicFolder,\n replaceInPlace\n )\n );\n return { output: outputMin };\n }\n return {\n output: utils.setFileNameMin(\n input,\n output,\n replaceInPlace ? undefined : publicFolder,\n replaceInPlace\n ),\n };\n }\n};\n\n/**\n * Handle wildcards in a path, get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst wildcards = (input: string | string[], publicFolder?: string) => {\n // If it's a string\n if (!Array.isArray(input)) {\n return wildcardsString(input, publicFolder);\n }\n\n return wildcardsArray(input, publicFolder);\n};\n\n/**\n * Handle wildcards in a path (string only), get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst wildcardsString = (input: string, publicFolder?: string) => {\n const output: { input?: string[] } = {};\n\n if (input.indexOf(\"*\") > -1) {\n output.input = getFilesFromWildcards(input, publicFolder);\n }\n\n return output;\n};\n\n/**\n * Handle wildcards in a path (array only), get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst wildcardsArray = (input: string[], publicFolder?: string) => {\n const output: { input?: string[] } = {};\n let isWildcardsPresent = false;\n\n output.input = input;\n\n // Transform all wildcards to path file\n const inputWithPublicFolder = input.map((item) => {\n if (item.indexOf(\"*\") > -1) {\n isWildcardsPresent = true;\n }\n return (publicFolder || \"\") + item;\n });\n\n if (isWildcardsPresent) {\n output.input = globSync(inputWithPublicFolder);\n }\n\n // Remove all wildcards from array\n for (let i = 0; i < output.input.length; i++) {\n if (output.input[i].indexOf(\"*\") > -1) {\n output.input.splice(i, 1);\n\n i--;\n }\n }\n\n return output;\n};\n\n/**\n * Get the real path of each files.\n * @param input Path with wildcards\n * @param publicFolder Path to the public folder\n */\nconst getFilesFromWildcards = (input: string, publicFolder?: string) => {\n let output: string[] = [];\n\n if (input.indexOf(\"*\") > -1) {\n output = globSync((publicFolder || \"\") + input);\n }\n\n return output;\n};\n\n/**\n * Prepend the public folder to each file.\n * @param input Path to file(s)\n * @param publicFolder Path to the public folder\n */\nconst setPublicFolder = (input: string | string[], publicFolder: string) => {\n const output: { input?: string | string[] } = {};\n\n if (typeof publicFolder !== \"string\") {\n return output;\n }\n\n publicFolder = path.normalize(publicFolder);\n\n if (Array.isArray(input)) {\n output.input = input.map((item) => {\n // Check if publicFolder is already in path\n if (path.normalize(item).indexOf(publicFolder) > -1) {\n return item;\n }\n return path.normalize(publicFolder + item);\n });\n return output;\n }\n\n input = path.normalize(input);\n\n // Check if publicFolder is already in path\n if (input.indexOf(publicFolder) > -1) {\n output.input = input;\n return output;\n }\n\n output.input = path.normalize(publicFolder + input);\n\n return output;\n};\n\n/**\n * Check if some settings are here.\n * @param settings Settings\n */\nconst checkMandatories = (settings: Settings) => {\n [\"compressor\", \"input\", \"output\"].forEach((item: string) =>\n mandatory(item, settings)\n );\n};\n\n/**\n * Check if some settings are here for memory content.\n * @param settings Settings\n */\nconst checkMandatoriesMemoryContent = (settings: Settings) => {\n [\"compressor\", \"content\"].forEach((item: string) =>\n mandatory(item, settings)\n );\n};\n\n/**\n * Check if the setting exist.\n * @param setting Setting\n * @param settings Settings\n */\nconst mandatory = (setting: string, settings: { [key: string]: any }) => {\n if (!settings[setting]) {\n throw new Error(`${setting} is mandatory.`);\n }\n};\n\n/**\n * Expose `setup()`.\n */\nexport { setup };\n","/*!\n * node-minify\n * Copyright(c) 2011-2024 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport type { Settings } from \"@node-minify/types\";\nimport { compress } from \"./compress\";\nimport { compressInMemory } from \"./compressInMemory\";\nimport { setup } from \"./setup\";\n\n/**\n * Run node-minify.\n * @param settings Settings from user input\n */\nconst minify = (settings: Settings) => {\n return new Promise((resolve, reject) => {\n const method: any = settings.content ? compressInMemory : compress;\n settings = setup(settings);\n if (!settings.sync) {\n method(settings)\n .then((minified: string) => {\n if (settings.callback) {\n settings.callback(null, minified);\n }\n resolve(minified);\n })\n .catch((err: Error) => {\n if (settings.callback) {\n settings.callback(err);\n }\n reject(err);\n });\n } else {\n const minified: string = method(settings);\n if (settings.callback) {\n settings.callback(null, minified);\n }\n resolve(minified);\n }\n });\n};\n\n/**\n * Expose `minify()`.\n */\nminify.default = minify;\nexport = minify;\n"],"mappings":";;;;;;;;;AASA,OAAO,QAAQ;AAEf,SAAS,aAAa;AACtB,OAAO,YAAY;AAZnB,IAkBM,UAuBA,0BAcA,2BAkBA;AAzEN;AAAA;AAAA;AAkBA,IAAM,WAAW,CAAC,aAAiD;AAC/D,UAAI,OAAO,SAAS,eAAe,YAAY;AAC3C,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAEA,UAAI,SAAS,QAAQ;AACjB,wBAAgB,SAAS,MAAM;AAAA,MACnC;AAEA,UAAI,MAAM,QAAQ,SAAS,MAAM,GAAG;AAChC,eAAO,SAAS,OACV,yBAAyB,QAAQ,IACjC,0BAA0B,QAAQ;AAAA,MAC5C;AACA,aAAO,MAAM,mBAAmB,QAAQ;AAAA,IAC5C;AAMA,IAAM,2BAA2B,CAAC,aAA4B;AAC1D,aACI,MAAM,QAAQ,SAAS,KAAK,KAC5B,SAAS,MAAM,QAAQ,CAAC,OAAO,UAAU;AACrC,cAAM,UAAU,MAAM,oBAAoB,KAAK;AAC/C,eAAO,MAAM,QAAQ,EAAE,UAAU,SAAS,MAAM,CAAC;AAAA,MACrD,CAAC;AAAA,IAET;AAMA,IAAM,4BAA4B,CAC9B,aACyB;AACzB,UAAI,WAAmC,QAAQ,QAAQ;AACvD,YAAM,QAAQ,SAAS,KAAK,KACxB,SAAS,MAAM,QAAQ,CAAC,OAAO,UAAU;AACrC,cAAM,UAAU,MAAM,oBAAoB,KAAK;AAC/C,mBAAW,SAAS;AAAA,UAAK,MACrB,MAAM,SAAS,EAAE,UAAU,SAAS,MAAM,CAAC;AAA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/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "core of @node-minify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compressor",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"homepage": "https://github.com/srod/node-minify/tree/master/packages/core#readme",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=18.0.0"
|
|
15
15
|
},
|
|
16
16
|
"directories": {
|
|
17
17
|
"lib": "dist",
|
|
@@ -21,9 +21,11 @@
|
|
|
21
21
|
"module": "./dist/index.mjs",
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
23
|
"exports": {
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.mjs",
|
|
27
|
+
"require": "./dist/index.cjs"
|
|
28
|
+
}
|
|
27
29
|
},
|
|
28
30
|
"files": [
|
|
29
31
|
"dist/**/*"
|
|
@@ -38,19 +40,21 @@
|
|
|
38
40
|
"bugs": {
|
|
39
41
|
"url": "https://github.com/srod/node-minify/issues"
|
|
40
42
|
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"clean": "pnpm dlx rimraf dist",
|
|
43
|
-
"build": "pnpm clean && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
|
|
44
|
-
"prepublishOnly": "pnpm build"
|
|
45
|
-
},
|
|
46
43
|
"dependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
44
|
+
"fast-glob": "3.3.2",
|
|
45
|
+
"mkdirp": "3.0.1",
|
|
46
|
+
"@node-minify/utils": "9.0.0"
|
|
50
47
|
},
|
|
51
48
|
"devDependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"@types
|
|
49
|
+
"@types/mkdirp": "^1.0.2",
|
|
50
|
+
"@node-minify/types": "9.0.0"
|
|
54
51
|
},
|
|
55
|
-
"
|
|
56
|
-
|
|
52
|
+
"scripts": {
|
|
53
|
+
"clean": "pnpm dlx rimraf dist",
|
|
54
|
+
"build": "pnpm clean && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
|
|
55
|
+
"lint": "biome lint .",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:ci": "vitest run --coverage",
|
|
58
|
+
"test:watch": "vitest"
|
|
59
|
+
}
|
|
60
|
+
}
|