@node-minify/core 8.0.6 → 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 +109 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -81
- 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_glob = require("glob");
|
|
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,37 +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
103
|
if (settings.input) {
|
|
43
|
-
settings = Object.assign(
|
|
104
|
+
settings = Object.assign(
|
|
105
|
+
settings,
|
|
106
|
+
wildcards(settings.input, settings.publicFolder)
|
|
107
|
+
);
|
|
44
108
|
}
|
|
45
109
|
if (settings.input && settings.output) {
|
|
46
110
|
settings = Object.assign(
|
|
47
111
|
settings,
|
|
48
|
-
checkOutput(
|
|
112
|
+
checkOutput(
|
|
113
|
+
settings.input,
|
|
114
|
+
settings.output,
|
|
115
|
+
settings.publicFolder,
|
|
116
|
+
settings.replaceInPlace
|
|
117
|
+
)
|
|
49
118
|
);
|
|
50
119
|
}
|
|
51
120
|
if (settings.input && settings.publicFolder) {
|
|
52
|
-
settings = Object.assign(
|
|
121
|
+
settings = Object.assign(
|
|
122
|
+
settings,
|
|
123
|
+
setPublicFolder(settings.input, settings.publicFolder)
|
|
124
|
+
);
|
|
53
125
|
}
|
|
54
126
|
return settings;
|
|
55
127
|
};
|
|
56
128
|
var checkOutput = (input, output, publicFolder, replaceInPlace) => {
|
|
57
|
-
const reg =
|
|
129
|
+
const reg = /\$1/;
|
|
58
130
|
if (reg.test(output)) {
|
|
59
131
|
if (Array.isArray(input)) {
|
|
60
132
|
const outputMin = input.map(
|
|
61
|
-
(file) =>
|
|
133
|
+
(file) => import_utils3.utils.setFileNameMin(
|
|
134
|
+
file,
|
|
135
|
+
output,
|
|
136
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
137
|
+
replaceInPlace
|
|
138
|
+
)
|
|
62
139
|
);
|
|
63
140
|
return { output: outputMin };
|
|
64
|
-
} else {
|
|
65
|
-
return { output: import_utils.utils.setFileNameMin(input, output, replaceInPlace ? void 0 : publicFolder, replaceInPlace) };
|
|
66
141
|
}
|
|
142
|
+
return {
|
|
143
|
+
output: import_utils3.utils.setFileNameMin(
|
|
144
|
+
input,
|
|
145
|
+
output,
|
|
146
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
147
|
+
replaceInPlace
|
|
148
|
+
)
|
|
149
|
+
};
|
|
67
150
|
}
|
|
68
151
|
};
|
|
69
152
|
var wildcards = (input, publicFolder) => {
|
|
@@ -90,7 +173,7 @@ var wildcardsArray = (input, publicFolder) => {
|
|
|
90
173
|
return (publicFolder || "") + item;
|
|
91
174
|
});
|
|
92
175
|
if (isWildcardsPresent) {
|
|
93
|
-
output.input = (0,
|
|
176
|
+
output.input = (0, import_fast_glob.globSync)(inputWithPublicFolder);
|
|
94
177
|
}
|
|
95
178
|
for (let i = 0; i < output.input.length; i++) {
|
|
96
179
|
if (output.input[i].indexOf("*") > -1) {
|
|
@@ -103,7 +186,7 @@ var wildcardsArray = (input, publicFolder) => {
|
|
|
103
186
|
var getFilesFromWildcards = (input, publicFolder) => {
|
|
104
187
|
let output = [];
|
|
105
188
|
if (input.indexOf("*") > -1) {
|
|
106
|
-
output = (0,
|
|
189
|
+
output = (0, import_fast_glob.globSync)((publicFolder || "") + input);
|
|
107
190
|
}
|
|
108
191
|
return output;
|
|
109
192
|
};
|
|
@@ -112,87 +195,38 @@ var setPublicFolder = (input, publicFolder) => {
|
|
|
112
195
|
if (typeof publicFolder !== "string") {
|
|
113
196
|
return output;
|
|
114
197
|
}
|
|
115
|
-
publicFolder =
|
|
198
|
+
publicFolder = import_node_path.default.normalize(publicFolder);
|
|
116
199
|
if (Array.isArray(input)) {
|
|
117
200
|
output.input = input.map((item) => {
|
|
118
|
-
if (
|
|
201
|
+
if (import_node_path.default.normalize(item).indexOf(publicFolder) > -1) {
|
|
119
202
|
return item;
|
|
120
203
|
}
|
|
121
|
-
return
|
|
204
|
+
return import_node_path.default.normalize(publicFolder + item);
|
|
122
205
|
});
|
|
123
206
|
return output;
|
|
124
207
|
}
|
|
125
|
-
input =
|
|
208
|
+
input = import_node_path.default.normalize(input);
|
|
126
209
|
if (input.indexOf(publicFolder) > -1) {
|
|
127
210
|
output.input = input;
|
|
128
211
|
return output;
|
|
129
212
|
}
|
|
130
|
-
output.input =
|
|
213
|
+
output.input = import_node_path.default.normalize(publicFolder + input);
|
|
131
214
|
return output;
|
|
132
215
|
};
|
|
133
216
|
var checkMandatories = (settings) => {
|
|
134
|
-
["compressor", "input", "output"].forEach(
|
|
217
|
+
["compressor", "input", "output"].forEach(
|
|
218
|
+
(item) => mandatory(item, settings)
|
|
219
|
+
);
|
|
135
220
|
};
|
|
136
221
|
var checkMandatoriesMemoryContent = (settings) => {
|
|
137
|
-
["compressor", "content"].forEach(
|
|
222
|
+
["compressor", "content"].forEach(
|
|
223
|
+
(item) => mandatory(item, settings)
|
|
224
|
+
);
|
|
138
225
|
};
|
|
139
226
|
var mandatory = (setting, settings) => {
|
|
140
227
|
if (!settings[setting]) {
|
|
141
|
-
throw new Error(setting
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// src/compress.ts
|
|
146
|
-
var import_fs = __toESM(require("fs"));
|
|
147
|
-
var import_mkdirp = __toESM(require("mkdirp"));
|
|
148
|
-
var import_utils2 = require("@node-minify/utils");
|
|
149
|
-
var compress = (settings) => {
|
|
150
|
-
if (typeof settings.compressor !== "function") {
|
|
151
|
-
throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
|
|
152
|
-
}
|
|
153
|
-
if (settings.output) {
|
|
154
|
-
createDirectory(settings.output);
|
|
155
|
-
}
|
|
156
|
-
if (Array.isArray(settings.output)) {
|
|
157
|
-
return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);
|
|
158
|
-
} else {
|
|
159
|
-
return import_utils2.utils.compressSingleFile(settings);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
var compressArrayOfFilesSync = (settings) => {
|
|
163
|
-
return Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
164
|
-
const content = import_utils2.utils.getContentFromFiles(input);
|
|
165
|
-
return import_utils2.utils.runSync({ settings, content, index });
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
var compressArrayOfFilesAsync = (settings) => {
|
|
169
|
-
let sequence = Promise.resolve();
|
|
170
|
-
Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
171
|
-
const content = import_utils2.utils.getContentFromFiles(input);
|
|
172
|
-
sequence = sequence.then(() => import_utils2.utils.runAsync({ settings, content, index }));
|
|
173
|
-
});
|
|
174
|
-
return sequence;
|
|
175
|
-
};
|
|
176
|
-
var createDirectory = (file) => {
|
|
177
|
-
if (Array.isArray(file)) {
|
|
178
|
-
file = file[0];
|
|
179
|
-
}
|
|
180
|
-
const dir = file && file.substr(0, file.lastIndexOf("/"));
|
|
181
|
-
if (!dir) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (!import_fs.default.statSync(dir).isDirectory()) {
|
|
185
|
-
import_mkdirp.default.sync(dir);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// src/compressInMemory.ts
|
|
190
|
-
var import_utils3 = require("@node-minify/utils");
|
|
191
|
-
var compressInMemory = (settings) => {
|
|
192
|
-
if (typeof settings.compressor !== "function") {
|
|
193
|
-
throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
|
|
228
|
+
throw new Error(`${setting} is mandatory.`);
|
|
194
229
|
}
|
|
195
|
-
return import_utils3.utils.compressSingleFile(settings);
|
|
196
230
|
};
|
|
197
231
|
|
|
198
232
|
// src/index.ts
|
|
@@ -225,7 +259,7 @@ minify.default = minify;
|
|
|
225
259
|
module.exports = minify;
|
|
226
260
|
/*!
|
|
227
261
|
* node-minify
|
|
228
|
-
* Copyright(c) 2011-
|
|
262
|
+
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
229
263
|
* MIT Licensed
|
|
230
264
|
*/
|
|
231
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 { globSync } from 'glob';\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: Settings) => {\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 if (settings.input) {\n settings = Object.assign(settings, wildcards(settings.input, settings.publicFolder));\n }\n if (settings.input && settings.output) {\n settings = Object.assign(\n settings,\n checkOutput(settings.input, settings.output, settings.publicFolder, settings.replaceInPlace)\n );\n }\n if (settings.input && settings.publicFolder) {\n settings = Object.assign(settings, setPublicFolder(settings.input, settings.publicFolder));\n }\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 ? undefined : publicFolder, replaceInPlace)\n );\n return { output: outputMin };\n } else {\n return { output: utils.setFileNameMin(input, output, replaceInPlace ? undefined : 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 = 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 *\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 = globSync((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: { [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-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 if (settings.output) {\n createDirectory(settings.output);\n }\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: 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,kBAAiB;AACjB,kBAAyB;AACzB,mBAAsB;AAMtB,IAAM,kBAAkB;AAAA,EACtB,MAAM;AAAA,EACN,SAAS,CAAC;AAAA,EACV,QAAQ,MAAO;AAAA,EACf,UAAU;AACZ;AAQA,IAAM,QAAQ,CAAC,kBAA4B;AACzC,MAAI,WAAqB,OAAO,OAAO,mBAAM,MAAM,eAAe,GAAG,aAAa;AAGlF,MAAI,SAAS,SAAS;AACpB,kCAA8B,aAAa;AAC3C,WAAO;AAAA,EACT;AAEA,mBAAiB,aAAa;AAE9B,MAAI,SAAS,OAAO;AAClB,eAAW,OAAO,OAAO,UAAU,UAAU,SAAS,OAAO,SAAS,YAAY,CAAC;AAAA,EACrF;AACA,MAAI,SAAS,SAAS,SAAS,QAAQ;AACrC,eAAW,OAAO;AAAA,MAChB;AAAA,MACA,YAAY,SAAS,OAAO,SAAS,QAAQ,SAAS,cAAc,SAAS,cAAc;AAAA,IAC7F;AAAA,EACF;AACA,MAAI,SAAS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AC;AACxD,MAAI,CAAC,KAAK;AACR;AAAA,EACF;AACA,MAAI,CAAC,UAAAC,QAAG,SAAS,GAAG,EAAE,YAAY,GAAG;AACnC,kBAAAC,QAAO,KAAK,GAAG;AAAA,EACjB;AACF;;;ACxEA,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,WAAmB,OAAO,QAAQ;AACxC,UAAI,SAAS,UAAU;AACrB,iBAAS,SAAS,MAAM,QAAQ;AAAA,MAClC;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":";;;;;;;;;;;;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;AAC1D,eAAW,MAAM,QAAQ;AACzB,QAAI,CAAC,SAAS,MAAM;AAChB,aAAO,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 { globSync } from "glob";
|
|
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,37 +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
103
|
if (settings.input) {
|
|
31
|
-
settings = Object.assign(
|
|
104
|
+
settings = Object.assign(
|
|
105
|
+
settings,
|
|
106
|
+
wildcards(settings.input, settings.publicFolder)
|
|
107
|
+
);
|
|
32
108
|
}
|
|
33
109
|
if (settings.input && settings.output) {
|
|
34
110
|
settings = Object.assign(
|
|
35
111
|
settings,
|
|
36
|
-
checkOutput(
|
|
112
|
+
checkOutput(
|
|
113
|
+
settings.input,
|
|
114
|
+
settings.output,
|
|
115
|
+
settings.publicFolder,
|
|
116
|
+
settings.replaceInPlace
|
|
117
|
+
)
|
|
37
118
|
);
|
|
38
119
|
}
|
|
39
120
|
if (settings.input && settings.publicFolder) {
|
|
40
|
-
settings = Object.assign(
|
|
121
|
+
settings = Object.assign(
|
|
122
|
+
settings,
|
|
123
|
+
setPublicFolder(settings.input, settings.publicFolder)
|
|
124
|
+
);
|
|
41
125
|
}
|
|
42
126
|
return settings;
|
|
43
127
|
};
|
|
44
128
|
checkOutput = (input, output, publicFolder, replaceInPlace) => {
|
|
45
|
-
const reg =
|
|
129
|
+
const reg = /\$1/;
|
|
46
130
|
if (reg.test(output)) {
|
|
47
131
|
if (Array.isArray(input)) {
|
|
48
132
|
const outputMin = input.map(
|
|
49
|
-
(file) =>
|
|
133
|
+
(file) => utils3.setFileNameMin(
|
|
134
|
+
file,
|
|
135
|
+
output,
|
|
136
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
137
|
+
replaceInPlace
|
|
138
|
+
)
|
|
50
139
|
);
|
|
51
140
|
return { output: outputMin };
|
|
52
|
-
} else {
|
|
53
|
-
return { output: utils.setFileNameMin(input, output, replaceInPlace ? void 0 : publicFolder, replaceInPlace) };
|
|
54
141
|
}
|
|
142
|
+
return {
|
|
143
|
+
output: utils3.setFileNameMin(
|
|
144
|
+
input,
|
|
145
|
+
output,
|
|
146
|
+
replaceInPlace ? void 0 : publicFolder,
|
|
147
|
+
replaceInPlace
|
|
148
|
+
)
|
|
149
|
+
};
|
|
55
150
|
}
|
|
56
151
|
};
|
|
57
152
|
wildcards = (input, publicFolder) => {
|
|
@@ -119,90 +214,29 @@ var init_setup = __esm({
|
|
|
119
214
|
return output;
|
|
120
215
|
};
|
|
121
216
|
checkMandatories = (settings) => {
|
|
122
|
-
["compressor", "input", "output"].forEach(
|
|
217
|
+
["compressor", "input", "output"].forEach(
|
|
218
|
+
(item) => mandatory(item, settings)
|
|
219
|
+
);
|
|
123
220
|
};
|
|
124
221
|
checkMandatoriesMemoryContent = (settings) => {
|
|
125
|
-
["compressor", "content"].forEach(
|
|
222
|
+
["compressor", "content"].forEach(
|
|
223
|
+
(item) => mandatory(item, settings)
|
|
224
|
+
);
|
|
126
225
|
};
|
|
127
226
|
mandatory = (setting, settings) => {
|
|
128
227
|
if (!settings[setting]) {
|
|
129
|
-
throw new Error(setting
|
|
228
|
+
throw new Error(`${setting} is mandatory.`);
|
|
130
229
|
}
|
|
131
230
|
};
|
|
132
231
|
}
|
|
133
232
|
});
|
|
134
233
|
|
|
135
|
-
// src/compress.ts
|
|
136
|
-
import fs from "fs";
|
|
137
|
-
import mkdirp from "mkdirp";
|
|
138
|
-
import { utils as utils2 } from "@node-minify/utils";
|
|
139
|
-
var compress, compressArrayOfFilesSync, compressArrayOfFilesAsync, createDirectory;
|
|
140
|
-
var init_compress = __esm({
|
|
141
|
-
"src/compress.ts"() {
|
|
142
|
-
"use strict";
|
|
143
|
-
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
|
-
if (settings.output) {
|
|
148
|
-
createDirectory(settings.output);
|
|
149
|
-
}
|
|
150
|
-
if (Array.isArray(settings.output)) {
|
|
151
|
-
return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);
|
|
152
|
-
} else {
|
|
153
|
-
return utils2.compressSingleFile(settings);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
compressArrayOfFilesSync = (settings) => {
|
|
157
|
-
return Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
158
|
-
const content = utils2.getContentFromFiles(input);
|
|
159
|
-
return utils2.runSync({ settings, content, index });
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
compressArrayOfFilesAsync = (settings) => {
|
|
163
|
-
let sequence = Promise.resolve();
|
|
164
|
-
Array.isArray(settings.input) && settings.input.forEach((input, index) => {
|
|
165
|
-
const content = utils2.getContentFromFiles(input);
|
|
166
|
-
sequence = sequence.then(() => utils2.runAsync({ settings, content, index }));
|
|
167
|
-
});
|
|
168
|
-
return sequence;
|
|
169
|
-
};
|
|
170
|
-
createDirectory = (file) => {
|
|
171
|
-
if (Array.isArray(file)) {
|
|
172
|
-
file = file[0];
|
|
173
|
-
}
|
|
174
|
-
const dir = file && file.substr(0, file.lastIndexOf("/"));
|
|
175
|
-
if (!dir) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (!fs.statSync(dir).isDirectory()) {
|
|
179
|
-
mkdirp.sync(dir);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// src/compressInMemory.ts
|
|
186
|
-
import { utils as utils3 } from "@node-minify/utils";
|
|
187
|
-
var compressInMemory;
|
|
188
|
-
var init_compressInMemory = __esm({
|
|
189
|
-
"src/compressInMemory.ts"() {
|
|
190
|
-
"use strict";
|
|
191
|
-
compressInMemory = (settings) => {
|
|
192
|
-
if (typeof settings.compressor !== "function") {
|
|
193
|
-
throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
|
|
194
|
-
}
|
|
195
|
-
return utils3.compressSingleFile(settings);
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
|
|
200
234
|
// src/index.ts
|
|
201
235
|
var require_src = __commonJS({
|
|
202
236
|
"src/index.ts"(exports, module) {
|
|
203
|
-
init_setup();
|
|
204
237
|
init_compress();
|
|
205
238
|
init_compressInMemory();
|
|
239
|
+
init_setup();
|
|
206
240
|
var minify = (settings) => {
|
|
207
241
|
return new Promise((resolve, reject) => {
|
|
208
242
|
const method = settings.content ? compressInMemory : compress;
|
|
@@ -235,7 +269,7 @@ var require_src = __commonJS({
|
|
|
235
269
|
export default require_src();
|
|
236
270
|
/*!
|
|
237
271
|
* node-minify
|
|
238
|
-
* Copyright(c) 2011-
|
|
272
|
+
* Copyright(c) 2011-2024 Rodolphe Stoclin
|
|
239
273
|
* MIT Licensed
|
|
240
274
|
*/
|
|
241
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 { globSync } from 'glob';\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: Settings) => {\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 if (settings.input) {\n settings = Object.assign(settings, wildcards(settings.input, settings.publicFolder));\n }\n if (settings.input && settings.output) {\n settings = Object.assign(\n settings,\n checkOutput(settings.input, settings.output, settings.publicFolder, settings.replaceInPlace)\n );\n }\n if (settings.input && settings.publicFolder) {\n settings = Object.assign(settings, setPublicFolder(settings.input, settings.publicFolder));\n }\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 ? undefined : publicFolder, replaceInPlace)\n );\n return { output: outputMin };\n } else {\n return { output: utils.setFileNameMin(input, output, replaceInPlace ? undefined : 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 = 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 *\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 = globSync((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: { [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-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 if (settings.output) {\n createDirectory(settings.output);\n }\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: 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,UAAU;AACjB,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAXtB,IAiBM,iBAaA,OAqCA,aAqBA,WAgBA,iBAiBA,gBAqCA,uBAiBA,iBAsCA,kBASA,+BAUA;AAxON;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,kBAA4B;AACzC,UAAI,WAAqB,OAAO,OAAO,MAAM,MAAM,eAAe,GAAG,aAAa;AAGlF,UAAI,SAAS,SAAS;AACpB,sCAA8B,aAAa;AAC3C,eAAO;AAAA,MACT;AAEA,uBAAiB,aAAa;AAE9B,UAAI,SAAS,OAAO;AAClB,mBAAW,OAAO,OAAO,UAAU,UAAU,SAAS,OAAO,SAAS,YAAY,CAAC;AAAA,MACrF;AACA,UAAI,SAAS,SAAS,SAAS,QAAQ;AACrC,mBAAW,OAAO;AAAA,UAChB;AAAA,UACA,YAAY,SAAS,OAAO,SAAS,QAAQ,SAAS,cAAc,SAAS,cAAc;AAAA,QAC7F;AAAA,MACF;AACA,UAAI,SAAS,SAAS,SAAS,cAAc;AAC3C,mBAAW,OAAO,OAAO,UAAU,gBAAgB,SAAS,OAAO,SAAS,YAAY,CAAC;AAAA,MAC3F;AAEA,aAAO;AAAA,IACT;AAYA,IAAM,cAAc,CAAC,OAA0B,QAAgB,cAAuB,mBAA6B;AACjH,YAAM,MAAM,IAAI,OAAO,MAAM;AAC7B,UAAI,IAAI,KAAK,MAAM,GAAG;AACpB,YAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,g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,SAAAC,cAAa;AATtB,IAiBM;AAjBN;AAAA;AAAA;AAiBA,IAAM,mBAAmB,CAAC,aAAiD;AACzE,UAAI,OAAO,SAAS,eAAe,YAAY;AAC7C,cAAM,IAAI,MAAM,6EAA6E;AAAA,MAC/F;AAEA,aAAOA,OAAM,mBAAmB,QAAQ;AAAA,IAC1C;AAAA;AAAA;;;ACvBA;AAAA;AASA;AACA;AACA;AAQA,QAAM,SAAS,CAAC,aAAuB;AACrC,aAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,cAAM,SAAc,SAAS,UAAU,mBAAmB;AAC1D,mBAAW,MAAM,QAAQ;AACzB,YAAI,CAAC,SAAS,MAAM;AAClB,iBAAO,QAAQ,EACZ,KAAK,CAAC,aAAqB;AAC1B,gBAAI,SAAS,UAAU;AACrB,uBAAS,SAAS,MAAM,QAAQ;AAAA,YAClC;AACA,oBAAQ,QAAQ;AAAA,UAClB,CAAC,EACA,MAAM,CAAC,QAAe;AACrB,gBAAI,SAAS,UAAU;AACrB,uBAAS,SAAS,GAAG;AAAA,YACvB;AACA,mBAAO,GAAG;AAAA,UACZ,CAAC;AAAA,QACL,OAAO;AACL,gBAAM,WAAmB,OAAO,QAAQ;AACxC,cAAI,SAAS,UAAU;AACrB,qBAAS,SAAS,MAAM,QAAQ;AAAA,UAClC;AACA,kBAAQ,QAAQ;AAAA,QAClB;AAAA,MACF,CAAC;AAAA,IACH;AAKA,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,0BAc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AAO,GAAG;AACpB,cAAM,IAAI,MAAM,GAAG,OAAO,gBAAgB;AAAA,MAC9C;AAAA,IACJ;AAAA;AAAA;;;AC7PA;AAAA;AAUA;AACA;AACA;AAMA,QAAM,SAAS,CAAC,aAAuB;AACnC,aAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACpC,cAAM,SAAc,SAAS,UAAU,mBAAmB;AAC1D,mBAAW,MAAM,QAAQ;AACzB,YAAI,CAAC,SAAS,MAAM;AAChB,iBAAO,QAAQ,EACV,KAAK,CAAC,aAAqB;AACxB,gBAAI,SAAS,UAAU;AACnB,uBAAS,SAAS,MAAM,QAAQ;AAAA,YACpC;AACA,oBAAQ,QAAQ;AAAA,UACpB,CAAC,EACA,MAAM,CAAC,QAAe;AACnB,gBAAI,SAAS,UAAU;AACnB,uBAAS,SAAS,GAAG;AAAA,YACzB;AACA,mBAAO,GAAG;AAAA,UACd,CAAC;AAAA,QACT,OAAO;AACH,gBAAM,WAAmB,OAAO,QAAQ;AACxC,cAAI,SAAS,UAAU;AACnB,qBAAS,SAAS,MAAM,QAAQ;AAAA,UACpC;AACA,kBAAQ,QAAQ;AAAA,QACpB;AAAA,MACJ,CAAC;AAAA,IACL;AAKA,WAAO,UAAU;AACjB,qBAAS;AAAA;AAAA;","names":["utils","utils"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/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
|
+
}
|