@node-minify/core 6.4.0 → 7.1.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/lib/compress.js CHANGED
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.compress = void 0;
7
-
8
7
  var _fs = _interopRequireDefault(require("fs"));
9
-
10
8
  var _mkdirp = _interopRequireDefault(require("mkdirp"));
11
-
12
9
  var _utils = require("@node-minify/utils");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  /*!
17
12
  * node-minify
18
13
  * Copyright(c) 2011-2022 Rodolphe Stoclin
@@ -32,28 +27,23 @@ const compress = settings => {
32
27
  if (typeof settings.compressor !== 'function') {
33
28
  throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
34
29
  }
35
-
36
30
  createDirectory(settings.output);
37
-
38
31
  if (Array.isArray(settings.output)) {
39
32
  return settings.sync ? compressArrayOfFilesSync(settings) : compressArrayOfFilesAsync(settings);
40
33
  } else {
41
34
  return _utils.utils.compressSingleFile(settings);
42
35
  }
43
36
  };
37
+
44
38
  /**
45
39
  * Compress an array of files in sync.
46
40
  *
47
41
  * @param {Object} settings
48
42
  */
49
-
50
-
51
43
  exports.compress = compress;
52
-
53
44
  const compressArrayOfFilesSync = settings => {
54
45
  return settings.input.forEach((input, index) => {
55
46
  const content = _utils.utils.getContentFromFiles(input);
56
-
57
47
  return _utils.utils.runSync({
58
48
  settings,
59
49
  content,
@@ -61,18 +51,16 @@ const compressArrayOfFilesSync = settings => {
61
51
  });
62
52
  });
63
53
  };
54
+
64
55
  /**
65
56
  * Compress an array of files in async.
66
57
  *
67
58
  * @param {Object} settings
68
59
  */
69
-
70
-
71
60
  const compressArrayOfFilesAsync = settings => {
72
61
  let sequence = Promise.resolve();
73
62
  settings.input.forEach((input, index) => {
74
63
  const content = _utils.utils.getContentFromFiles(input);
75
-
76
64
  sequence = sequence.then(() => _utils.utils.runAsync({
77
65
  settings,
78
66
  content,
@@ -81,28 +69,25 @@ const compressArrayOfFilesAsync = settings => {
81
69
  });
82
70
  return sequence;
83
71
  };
72
+
84
73
  /**
85
74
  * Create folder of the target file.
86
75
  *
87
76
  * @param {String} file - Full path of the file
88
77
  */
89
-
90
-
91
78
  const createDirectory = file => {
92
79
  if (Array.isArray(file)) {
93
80
  file = file[0];
94
81
  }
95
-
96
82
  const dir = file && file.substr(0, file.lastIndexOf('/'));
97
-
98
83
  if (!dir) {
99
84
  return;
100
85
  }
101
-
102
86
  if (!_fs.default.statSync(dir).isDirectory()) {
103
87
  _mkdirp.default.sync(dir);
104
88
  }
105
89
  };
90
+
106
91
  /**
107
92
  * Expose `compress()`.
108
93
  */
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.compressInMemory = void 0;
7
-
8
7
  var _utils = require("@node-minify/utils");
9
-
10
8
  /*!
11
9
  * node-minify
12
10
  * Copyright(c) 2011-2022 Rodolphe Stoclin
@@ -26,12 +24,10 @@ const compressInMemory = settings => {
26
24
  if (typeof settings.compressor !== 'function') {
27
25
  throw new Error(`compressor should be a function, maybe you forgot to install the compressor`);
28
26
  }
29
-
30
27
  return _utils.utils.compressSingleFile(settings);
31
28
  };
29
+
32
30
  /**
33
31
  * Expose `compress()`.
34
32
  */
35
-
36
-
37
33
  exports.compressInMemory = compressInMemory;
package/lib/core.js CHANGED
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  var _setup = require("./setup");
4
-
5
4
  var _compress = require("./compress");
6
-
7
5
  var _compressInMemory = require("./compressInMemory");
8
-
9
6
  /*!
10
7
  * node-minify
11
8
  * Copyright(c) 2011-2022 Rodolphe Stoclin
@@ -25,35 +22,29 @@ const minify = settings => {
25
22
  return new Promise((resolve, reject) => {
26
23
  const method = settings.content ? _compressInMemory.compressInMemory : _compress.compress;
27
24
  settings = (0, _setup.setup)(settings);
28
-
29
25
  if (!settings.sync) {
30
26
  method(settings).then(minified => {
31
27
  if (settings.callback) {
32
28
  settings.callback(null, minified);
33
29
  }
34
-
35
30
  resolve(minified);
36
31
  }).catch(err => {
37
32
  if (settings.callback) {
38
33
  settings.callback(err);
39
34
  }
40
-
41
35
  reject(err);
42
36
  });
43
37
  } else {
44
38
  const minified = method(settings);
45
-
46
39
  if (settings.callback) {
47
40
  settings.callback(null, minified);
48
41
  }
49
-
50
42
  resolve(minified);
51
43
  }
52
44
  });
53
45
  };
46
+
54
47
  /**
55
48
  * Expose `minify()`.
56
49
  */
57
-
58
-
59
50
  module.exports = minify;
package/lib/setup.js CHANGED
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.setup = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _globby = _interopRequireDefault(require("globby"));
11
-
12
9
  var _utils = require("@node-minify/utils");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  /*!
17
12
  * node-minify
18
13
  * Copyright(c) 2011-2022 Rodolphe Stoclin
@@ -32,27 +27,28 @@ const defaultSettings = {
32
27
  buffer: 1000 * 1024,
33
28
  callback: false
34
29
  };
30
+
35
31
  /**
36
32
  * Run setup.
37
33
  *
38
34
  * @param {Object} inputSettings
39
35
  * @return {Object}
40
36
  */
41
-
42
37
  const setup = inputSettings => {
43
- let settings = Object.assign(_utils.utils.clone(defaultSettings), inputSettings); // In memory
38
+ let settings = Object.assign(_utils.utils.clone(defaultSettings), inputSettings);
44
39
 
40
+ // In memory
45
41
  if (settings.content) {
46
42
  checkMandatoriesMemoryContent(inputSettings);
47
43
  return settings;
48
44
  }
49
-
50
45
  checkMandatories(inputSettings);
51
46
  settings = Object.assign(settings, wildcards(settings.input, settings.publicFolder));
52
47
  settings = Object.assign(settings, checkOutput(settings.input, settings.output, settings.publicFolder, settings.replaceInPlace));
53
48
  settings = Object.assign(settings, setPublicFolder(settings.input, settings.publicFolder));
54
49
  return settings;
55
50
  };
51
+
56
52
  /**
57
53
  * Check the output path, searching for $1
58
54
  * if exist, returns the path remplacing $1 by file name
@@ -63,13 +59,9 @@ const setup = inputSettings => {
63
59
  * @param {Boolean} replaceInPlace - True to replace file in same folder
64
60
  * @return {Object}
65
61
  */
66
-
67
-
68
62
  exports.setup = setup;
69
-
70
63
  const checkOutput = (input, output, publicFolder, replaceInPlace) => {
71
64
  let reg = new RegExp('\\$1');
72
-
73
65
  if (reg.test(output)) {
74
66
  if (Array.isArray(input)) {
75
67
  const outputMin = input.map(file => _utils.utils.setFileNameMin(file, output, replaceInPlace ? null : publicFolder, replaceInPlace));
@@ -83,6 +75,7 @@ const checkOutput = (input, output, publicFolder, replaceInPlace) => {
83
75
  }
84
76
  }
85
77
  };
78
+
86
79
  /**
87
80
  * Handle wildcards in a path, get the real path of each files.
88
81
  *
@@ -90,16 +83,14 @@ const checkOutput = (input, output, publicFolder, replaceInPlace) => {
90
83
  * @param {String} publicFolder - Path to the public folder
91
84
  * @return {Object}
92
85
  */
93
-
94
-
95
86
  const wildcards = (input, publicFolder) => {
96
87
  // If it's a string
97
88
  if (!Array.isArray(input)) {
98
89
  return wildcardsString(input, publicFolder);
99
90
  }
100
-
101
91
  return wildcardsArray(input, publicFolder);
102
92
  };
93
+
103
94
  /**
104
95
  * Handle wildcards in a path (string only), get the real path of each files.
105
96
  *
@@ -107,17 +98,14 @@ const wildcards = (input, publicFolder) => {
107
98
  * @param {String} publicFolder - Path to the public folder
108
99
  * @return {Object}
109
100
  */
110
-
111
-
112
101
  const wildcardsString = (input, publicFolder) => {
113
102
  const output = {};
114
-
115
103
  if (input.indexOf('*') > -1) {
116
104
  output.input = getFilesFromWildcards(input, publicFolder);
117
105
  }
118
-
119
106
  return output;
120
107
  };
108
+
121
109
  /**
122
110
  * Handle wildcards in a path (array only), get the real path of each files.
123
111
  *
@@ -125,35 +113,32 @@ const wildcardsString = (input, publicFolder) => {
125
113
  * @param {String} publicFolder - Path to the public folder
126
114
  * @return {Object}
127
115
  */
128
-
129
-
130
116
  const wildcardsArray = (input, publicFolder) => {
131
117
  let output = {};
132
118
  let isWildcardsPresent = false;
133
- output.input = input; // Transform all wildcards to path file
119
+ output.input = input;
134
120
 
121
+ // Transform all wildcards to path file
135
122
  const inputWithPublicFolder = input.map(item => {
136
123
  if (item.indexOf('*') > -1) {
137
124
  isWildcardsPresent = true;
138
125
  }
139
-
140
126
  return (publicFolder || '') + item;
141
127
  });
142
-
143
128
  if (isWildcardsPresent) {
144
129
  output.input = _globby.default.sync(inputWithPublicFolder);
145
- } // Remove all wildcards from array
146
-
130
+ }
147
131
 
132
+ // Remove all wildcards from array
148
133
  for (let i = 0; i < output.input.length; i++) {
149
134
  if (output.input[i].indexOf('*') > -1) {
150
135
  output.input.splice(i, 1);
151
136
  i--;
152
137
  }
153
138
  }
154
-
155
139
  return output;
156
140
  };
141
+
157
142
  /**
158
143
  * Get the real path of each files.
159
144
  *
@@ -161,17 +146,14 @@ const wildcardsArray = (input, publicFolder) => {
161
146
  * @param {String} publicFolder - Path to the public folder
162
147
  * @return {Object}
163
148
  */
164
-
165
-
166
149
  const getFilesFromWildcards = (input, publicFolder) => {
167
150
  let output = [];
168
-
169
151
  if (input.indexOf('*') > -1) {
170
152
  output = _globby.default.sync((publicFolder || '') + input);
171
153
  }
172
-
173
154
  return output;
174
155
  };
156
+
175
157
  /**
176
158
  * Prepend the public folder to each file.
177
159
  *
@@ -179,72 +161,63 @@ const getFilesFromWildcards = (input, publicFolder) => {
179
161
  * @param {String} publicFolder - Path to the public folder
180
162
  * @return {Object}
181
163
  */
182
-
183
-
184
164
  const setPublicFolder = (input, publicFolder) => {
185
165
  let output = {};
186
-
187
166
  if (typeof publicFolder !== 'string') {
188
167
  return output;
189
168
  }
190
-
191
169
  publicFolder = _path.default.normalize(publicFolder);
192
-
193
170
  if (Array.isArray(input)) {
194
171
  output.input = input.map(item => {
195
172
  // Check if publicFolder is already in path
196
173
  if (_path.default.normalize(item).indexOf(publicFolder) > -1) {
197
174
  return item;
198
175
  }
199
-
200
176
  return _path.default.normalize(publicFolder + item);
201
177
  });
202
178
  return output;
203
179
  }
180
+ input = _path.default.normalize(input);
204
181
 
205
- input = _path.default.normalize(input); // Check if publicFolder is already in path
206
-
182
+ // Check if publicFolder is already in path
207
183
  if (input.indexOf(publicFolder) > -1) {
208
184
  output.input = input;
209
185
  return output;
210
186
  }
211
-
212
187
  output.input = _path.default.normalize(publicFolder + input);
213
188
  return output;
214
189
  };
190
+
215
191
  /**
216
192
  * Check if some settings are here.
217
193
  *
218
194
  * @param {Object} settings
219
195
  */
220
-
221
-
222
196
  const checkMandatories = settings => {
223
197
  ['compressor', 'input', 'output'].forEach(item => mandatory(item, settings));
224
198
  };
199
+
225
200
  /**
226
201
  * Check if some settings are here for memory content.
227
202
  *
228
203
  * @param {Object} settings
229
204
  */
230
-
231
-
232
205
  const checkMandatoriesMemoryContent = settings => {
233
206
  ['compressor', 'content'].forEach(item => mandatory(item, settings));
234
207
  };
208
+
235
209
  /**
236
210
  * Check if the setting exist.
237
211
  *
238
212
  * @param {String} setting
239
213
  * @param {Object} settings
240
214
  */
241
-
242
-
243
215
  const mandatory = (setting, settings) => {
244
216
  if (!settings[setting]) {
245
217
  throw new Error(setting + ' is mandatory.');
246
218
  }
247
219
  };
220
+
248
221
  /**
249
222
  * Expose `setup()`.
250
223
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/core",
3
- "version": "6.4.0",
3
+ "version": "7.1.0",
4
4
  "description": "core of @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -12,7 +12,7 @@
12
12
  "license": "MIT",
13
13
  "main": "lib/core.js",
14
14
  "engines": {
15
- "node": ">=12.0.0"
15
+ "node": ">=14.0.0"
16
16
  },
17
17
  "directories": {
18
18
  "lib": "lib",
@@ -32,9 +32,9 @@
32
32
  "url": "https://github.com/srod/node-minify/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@node-minify/utils": "^6.4.0",
35
+ "@node-minify/utils": "^7.1.0",
36
36
  "globby": "11.0.4",
37
37
  "mkdirp": "1.0.4"
38
38
  },
39
- "gitHead": "d529747a661487597e9be510d3d9e2df1bc0f556"
39
+ "gitHead": "94cef2d5d653c3bddc3e603b4e25c135b0b6f4b3"
40
40
  }