@e-mc/module 0.8.6 → 0.8.8
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 +3 -7
- package/README.md +9 -9
- package/index.js +129 -60
- package/package.json +4 -3
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/module
|
|
2
2
|
|
|
3
3
|
* NodeJS 14
|
|
4
|
-
*
|
|
4
|
+
* ES2019
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -213,8 +213,8 @@ interface ModuleConstructor {
|
|
|
213
213
|
getMemUsage(format: true): string;
|
|
214
214
|
getMemUsage(format?: boolean): number;
|
|
215
215
|
formatCpuMem(start: CpuUsage, all?: boolean): string;
|
|
216
|
-
getPackageVersion(name: string | [string, string], startDir: string): string;
|
|
217
|
-
getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string): string;
|
|
216
|
+
getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
|
|
217
|
+
getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
|
|
218
218
|
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
219
219
|
checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
|
|
220
220
|
checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
|
|
@@ -232,11 +232,11 @@ interface ModuleConstructor {
|
|
|
232
232
|
|
|
233
233
|
## References
|
|
234
234
|
|
|
235
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
238
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/core.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/logger.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/module.d.ts
|
|
238
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/node.d.ts
|
|
239
239
|
|
|
240
240
|
## LICENSE
|
|
241
241
|
|
|
242
|
-
|
|
242
|
+
MIT
|
package/index.js
CHANGED
|
@@ -132,36 +132,94 @@ const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:to
|
|
|
132
132
|
let LOG_NEWLINE = true;
|
|
133
133
|
let LOG_EMPTYLINE = false;
|
|
134
134
|
let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
let PNPM_VER;
|
|
136
|
+
let YARN_VER;
|
|
137
|
+
function parseYaml(pathname) {
|
|
138
|
+
return require('js-yaml').load(fs.readFileSync(pathname, 'utf-8'));
|
|
139
|
+
}
|
|
140
|
+
function setPnpmVer() {
|
|
141
|
+
if (PNPM_VER === undefined) {
|
|
142
|
+
PNPM_VER = false;
|
|
143
|
+
const items = [];
|
|
144
|
+
let baseDir;
|
|
145
|
+
try {
|
|
146
|
+
let pathname = path.resolve("node_modules/.modules.yaml"), config;
|
|
147
|
+
if (fs.existsSync(pathname) && (0, types_1.isPlainObject)(config = parseYaml(pathname))) {
|
|
148
|
+
if (config.nodeLinker === 'hoisted') {
|
|
149
|
+
return PNPM_VER = true;
|
|
150
|
+
}
|
|
151
|
+
if (config.nodeLinker === 'pnp') {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
const addPackage = (value) => {
|
|
155
|
+
let index = value.indexOf('(');
|
|
156
|
+
if (index !== -1) {
|
|
157
|
+
value = value.substring(0, index);
|
|
158
|
+
}
|
|
159
|
+
index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
|
|
160
|
+
const name = value.substring(1, index);
|
|
161
|
+
const version = value.substring(index + 1);
|
|
162
|
+
if (!items.find(item => item[0] === name && item[1] === version)) {
|
|
163
|
+
items.push([name, version]);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
for (const name in config.hoistedDependencies) {
|
|
167
|
+
addPackage(name);
|
|
168
|
+
}
|
|
169
|
+
if (!path.isAbsolute(baseDir = config.virtualStoreDir)) {
|
|
170
|
+
baseDir = path.resolve('node_modules', baseDir);
|
|
171
|
+
}
|
|
172
|
+
if (!fs.existsSync(pathname = path.resolve(baseDir, "lock.yaml"))) {
|
|
173
|
+
baseDir = undefined;
|
|
174
|
+
}
|
|
175
|
+
else if ((0, types_1.isPlainObject)(config = parseYaml(pathname))) {
|
|
176
|
+
for (const name in config.packages) {
|
|
177
|
+
addPackage(name);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
140
181
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
})();
|
|
146
|
-
const YARN_VER = (function () {
|
|
147
|
-
try {
|
|
148
|
-
const pathname = path.resolve('./.pnp.cjs');
|
|
149
|
-
if (fs.existsSync(pathname)) {
|
|
150
|
-
return require(pathname);
|
|
182
|
+
catch {
|
|
183
|
+
}
|
|
184
|
+
if (items.length) {
|
|
185
|
+
PNPM_VER = { baseDir, items };
|
|
151
186
|
}
|
|
152
187
|
}
|
|
153
|
-
|
|
188
|
+
return PNPM_VER;
|
|
189
|
+
}
|
|
190
|
+
function setYarnVer() {
|
|
191
|
+
if (YARN_VER === undefined) {
|
|
192
|
+
YARN_VER = false;
|
|
193
|
+
try {
|
|
194
|
+
const pathname = path.resolve(".yarnrc.yml");
|
|
195
|
+
let config;
|
|
196
|
+
if (fs.existsSync(pathname) && (0, types_1.isPlainObject)(config = parseYaml(pathname)) && config.nodeLinker === 'node-modules') {
|
|
197
|
+
return YARN_VER = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const pathname = path.resolve(".pnp.cjs");
|
|
204
|
+
if (fs.existsSync(pathname)) {
|
|
205
|
+
return YARN_VER = require(pathname);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
}
|
|
154
210
|
}
|
|
155
|
-
return
|
|
156
|
-
}
|
|
211
|
+
return YARN_VER;
|
|
212
|
+
}
|
|
157
213
|
function applyStyle(options, style) {
|
|
158
214
|
var _h;
|
|
215
|
+
var _j;
|
|
159
216
|
for (const attr in style) {
|
|
160
|
-
(_h = options)[attr]
|
|
217
|
+
(_h = (_j = options)[attr]) !== null && _h !== void 0 ? _h : (_j[attr] = style[attr]);
|
|
161
218
|
}
|
|
162
219
|
return options;
|
|
163
220
|
}
|
|
164
221
|
function checkColorOptions(type, settings, options) {
|
|
222
|
+
var _h, _j, _k, _l;
|
|
165
223
|
if (typeof settings !== 'object') {
|
|
166
224
|
return false;
|
|
167
225
|
}
|
|
@@ -175,7 +233,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
175
233
|
result = true;
|
|
176
234
|
}
|
|
177
235
|
if (typeof settings.valueBold === 'boolean') {
|
|
178
|
-
options.valueBold
|
|
236
|
+
(_h = options.valueBold) !== null && _h !== void 0 ? _h : (options.valueBold = settings.valueBold);
|
|
179
237
|
}
|
|
180
238
|
if (settings.hintColor) {
|
|
181
239
|
options.hintColor || (options.hintColor = settings.hintColor);
|
|
@@ -186,7 +244,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
186
244
|
result = true;
|
|
187
245
|
}
|
|
188
246
|
if (typeof settings.hintBold === 'boolean') {
|
|
189
|
-
options.hintBold
|
|
247
|
+
(_j = options.hintBold) !== null && _j !== void 0 ? _j : (options.hintBold = settings.hintBold);
|
|
190
248
|
}
|
|
191
249
|
if (type & types_1.LOG_TYPE.FAIL) {
|
|
192
250
|
return result;
|
|
@@ -200,7 +258,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
200
258
|
result = true;
|
|
201
259
|
}
|
|
202
260
|
if (typeof settings.titleBold === 'boolean') {
|
|
203
|
-
options.titleBold
|
|
261
|
+
(_k = options.titleBold) !== null && _k !== void 0 ? _k : (options.titleBold = settings.titleBold);
|
|
204
262
|
}
|
|
205
263
|
if (settings.messageColor) {
|
|
206
264
|
options.messageColor || (options.messageColor = settings.messageColor);
|
|
@@ -211,7 +269,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
211
269
|
result = true;
|
|
212
270
|
}
|
|
213
271
|
if (typeof settings.messageBold === 'boolean') {
|
|
214
|
-
options.messageBold
|
|
272
|
+
(_l = options.messageBold) !== null && _l !== void 0 ? _l : (options.messageBold = settings.messageBold);
|
|
215
273
|
}
|
|
216
274
|
return result;
|
|
217
275
|
}
|
|
@@ -452,6 +510,7 @@ function getCacheItem(map, key) {
|
|
|
452
510
|
return item[1];
|
|
453
511
|
}
|
|
454
512
|
function addCacheItem(map, key, data, cache) {
|
|
513
|
+
var _h;
|
|
455
514
|
const length = Buffer.byteLength(data);
|
|
456
515
|
if (length < MEMORY_CACHE_DISK.min_size || length > MEMORY_CACHE_DISK.max_size) {
|
|
457
516
|
return;
|
|
@@ -467,7 +526,7 @@ function addCacheItem(map, key, data, cache) {
|
|
|
467
526
|
cache = true;
|
|
468
527
|
}
|
|
469
528
|
}
|
|
470
|
-
if (!(cache && MEMORY_CACHE_DISK.exclude
|
|
529
|
+
if (!(cache && ((_h = MEMORY_CACHE_DISK.exclude) === null || _h === void 0 ? void 0 : _h.some(value => pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') }))))) {
|
|
471
530
|
if (!map.has(key)) {
|
|
472
531
|
++CACHE_TOTAL;
|
|
473
532
|
}
|
|
@@ -483,7 +542,7 @@ function checkFunction(value) {
|
|
|
483
542
|
}
|
|
484
543
|
function encryptMessage(data, cipher, algorithm) {
|
|
485
544
|
var _h;
|
|
486
|
-
if (cipher
|
|
545
|
+
if ((cipher === null || cipher === void 0 ? void 0 : cipher.key) && cipher.iv) {
|
|
487
546
|
algorithm || (algorithm = cipher.algorithm || 'aes-256-gcm');
|
|
488
547
|
const result = (0, types_1.encryptUTF8)(algorithm, cipher.key, cipher.iv, data);
|
|
489
548
|
if (result) {
|
|
@@ -545,7 +604,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
545
604
|
}
|
|
546
605
|
else if (options.hostPermissionOnly) {
|
|
547
606
|
const host = this.host;
|
|
548
|
-
if (host
|
|
607
|
+
if ((host === null || host === void 0 ? void 0 : host.permission) && !host[method](result)) {
|
|
549
608
|
if (options.throwsPermission) {
|
|
550
609
|
throw errorPermission(result);
|
|
551
610
|
}
|
|
@@ -561,7 +620,8 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
561
620
|
return result;
|
|
562
621
|
}
|
|
563
622
|
function applyLogId(options) {
|
|
564
|
-
|
|
623
|
+
var _h;
|
|
624
|
+
(_h = options.sessionId) !== null && _h !== void 0 ? _h : (options.sessionId = this.sessionId);
|
|
565
625
|
let value = options.broadcastId;
|
|
566
626
|
if (value === undefined) {
|
|
567
627
|
if (value = this.broadcastId) {
|
|
@@ -627,7 +687,7 @@ class Module extends EventEmitter {
|
|
|
627
687
|
this[_f] = new AbortController();
|
|
628
688
|
this[_g] = null;
|
|
629
689
|
}
|
|
630
|
-
static get VERSION() { return "0.8.
|
|
690
|
+
static get VERSION() { return "0.8.8"; }
|
|
631
691
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
632
692
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
633
693
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -708,6 +768,7 @@ class Module extends EventEmitter {
|
|
|
708
768
|
return true;
|
|
709
769
|
}
|
|
710
770
|
static formatMessage(type, title, value, message, options = {}) {
|
|
771
|
+
var _h, _j, _k, _l;
|
|
711
772
|
const error = !!message && message instanceof Error;
|
|
712
773
|
if (error && hideAbort(message)) {
|
|
713
774
|
return;
|
|
@@ -751,7 +812,7 @@ class Module extends EventEmitter {
|
|
|
751
812
|
const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
|
|
752
813
|
let output, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
|
|
753
814
|
if (Array.isArray(value)) {
|
|
754
|
-
hint = value[1]
|
|
815
|
+
hint = (_h = value[1]) !== null && _h !== void 0 ? _h : '';
|
|
755
816
|
value = value[0];
|
|
756
817
|
}
|
|
757
818
|
if (error) {
|
|
@@ -900,7 +961,7 @@ class Module extends EventEmitter {
|
|
|
900
961
|
}
|
|
901
962
|
}
|
|
902
963
|
if (bold) {
|
|
903
|
-
options.messageBold
|
|
964
|
+
(_j = options.messageBold) !== null && _j !== void 0 ? _j : (options.messageBold = true);
|
|
904
965
|
}
|
|
905
966
|
}
|
|
906
967
|
}
|
|
@@ -918,7 +979,7 @@ class Module extends EventEmitter {
|
|
|
918
979
|
}
|
|
919
980
|
if (!hintColor && !hintBgColor) {
|
|
920
981
|
({ color: hintColor, bgColor: hintBgColor } = formatHint);
|
|
921
|
-
hintBold
|
|
982
|
+
hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
|
|
922
983
|
}
|
|
923
984
|
value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
|
|
924
985
|
}
|
|
@@ -934,7 +995,7 @@ class Module extends EventEmitter {
|
|
|
934
995
|
}
|
|
935
996
|
if (!valueColor && !valueBgColor) {
|
|
936
997
|
({ color: valueColor, bgColor: valueBgColor } = formatValue);
|
|
937
|
-
valueBold
|
|
998
|
+
valueBold !== null && valueBold !== void 0 ? valueBold : (valueBold = formatValue.bold);
|
|
938
999
|
}
|
|
939
1000
|
try {
|
|
940
1001
|
let v = value, i = id, m = message;
|
|
@@ -950,9 +1011,9 @@ class Module extends EventEmitter {
|
|
|
950
1011
|
const formatMessage = format.message;
|
|
951
1012
|
if (!messageColor && !messageBgColor) {
|
|
952
1013
|
({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
|
|
953
|
-
messageBold
|
|
1014
|
+
messageBold !== null && messageBold !== void 0 ? messageBold : (messageBold = formatMessage.bold);
|
|
954
1015
|
}
|
|
955
|
-
messageWidth
|
|
1016
|
+
messageWidth !== null && messageWidth !== void 0 ? messageWidth : (messageWidth = formatMessage.width);
|
|
956
1017
|
let u = unit;
|
|
957
1018
|
if (u) {
|
|
958
1019
|
if ((0, types_1.isObject)(SETTINGS.time_process)) {
|
|
@@ -973,13 +1034,13 @@ class Module extends EventEmitter {
|
|
|
973
1034
|
}
|
|
974
1035
|
m = '';
|
|
975
1036
|
}
|
|
976
|
-
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold)
|
|
1037
|
+
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
|
|
977
1038
|
}
|
|
978
1039
|
catch {
|
|
979
1040
|
}
|
|
980
1041
|
}
|
|
981
1042
|
if (!output) {
|
|
982
|
-
const m = truncateStart(this.asString(message), options.messageWidth
|
|
1043
|
+
const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
|
|
983
1044
|
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
984
1045
|
}
|
|
985
1046
|
if (broadcastId) {
|
|
@@ -1191,7 +1252,7 @@ class Module extends EventEmitter {
|
|
|
1191
1252
|
}
|
|
1192
1253
|
}
|
|
1193
1254
|
catch (err) {
|
|
1194
|
-
if (err
|
|
1255
|
+
if (this.isErrorCode(err, 'ENOENT')) {
|
|
1195
1256
|
throw err;
|
|
1196
1257
|
}
|
|
1197
1258
|
}
|
|
@@ -1515,7 +1576,7 @@ class Module extends EventEmitter {
|
|
|
1515
1576
|
}
|
|
1516
1577
|
}
|
|
1517
1578
|
if (isFile) {
|
|
1518
|
-
if (ignoreFile
|
|
1579
|
+
if (ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.test(name)) {
|
|
1519
1580
|
return ignore();
|
|
1520
1581
|
}
|
|
1521
1582
|
if (overwrite === false) {
|
|
@@ -1540,7 +1601,7 @@ class Module extends EventEmitter {
|
|
|
1540
1601
|
}));
|
|
1541
1602
|
}
|
|
1542
1603
|
else if (depth > 0 && (isDir || file.isDirectory())) {
|
|
1543
|
-
if (ignoreDir
|
|
1604
|
+
if (ignoreDir === null || ignoreDir === void 0 ? void 0 : ignoreDir.test(name)) {
|
|
1544
1605
|
return ignore();
|
|
1545
1606
|
}
|
|
1546
1607
|
recurse.call(this, paths.concat(name), depth - 1);
|
|
@@ -1811,8 +1872,11 @@ class Module extends EventEmitter {
|
|
|
1811
1872
|
}
|
|
1812
1873
|
return result;
|
|
1813
1874
|
}
|
|
1814
|
-
static getPackageVersion(value, unstable, startDir) {
|
|
1875
|
+
static getPackageVersion(value, unstable, startDir, baseDir) {
|
|
1815
1876
|
if (typeof unstable === 'string') {
|
|
1877
|
+
if (typeof startDir === 'string') {
|
|
1878
|
+
baseDir = startDir;
|
|
1879
|
+
}
|
|
1816
1880
|
startDir = unstable;
|
|
1817
1881
|
unstable = false;
|
|
1818
1882
|
}
|
|
@@ -1834,7 +1898,10 @@ class Module extends EventEmitter {
|
|
|
1834
1898
|
folders.push(startDir);
|
|
1835
1899
|
folders.reverse();
|
|
1836
1900
|
}
|
|
1837
|
-
for (
|
|
1901
|
+
for (let folder of folders) {
|
|
1902
|
+
if (baseDir) {
|
|
1903
|
+
folder = path.join(baseDir, folder.substring(PROCESS_CWD.length));
|
|
1904
|
+
}
|
|
1838
1905
|
try {
|
|
1839
1906
|
const pkg = path.join(folder, `node_modules/${value}/package.json`);
|
|
1840
1907
|
if (fs.existsSync(pkg)) {
|
|
@@ -1887,18 +1954,18 @@ class Module extends EventEmitter {
|
|
|
1887
1954
|
}
|
|
1888
1955
|
return result[0];
|
|
1889
1956
|
};
|
|
1890
|
-
if (
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
result.
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1957
|
+
if (setPnpmVer()) {
|
|
1958
|
+
if ((0, types_1.isObject)(PNPM_VER)) {
|
|
1959
|
+
if (startDir && !baseDir) {
|
|
1960
|
+
return this.getPackageVersion(value, unstable, startDir, PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm'));
|
|
1961
|
+
}
|
|
1962
|
+
const result = PNPM_VER.items.filter(item => item[0] === value).map(item => item[1]);
|
|
1963
|
+
if (result.length) {
|
|
1964
|
+
return latest(result);
|
|
1965
|
+
}
|
|
1899
1966
|
}
|
|
1900
1967
|
}
|
|
1901
|
-
if (YARN_VER) {
|
|
1968
|
+
else if (setYarnVer() && (0, types_1.isObject)(YARN_VER)) {
|
|
1902
1969
|
folders.forEach((folder, index) => {
|
|
1903
1970
|
folder = ensureDir(folder).replace(path.sep + 'node_modules' + path.sep, path.sep + 'packages' + path.sep);
|
|
1904
1971
|
folders[index] = PLATFORM_WIN32 ? folder.toLowerCase() : folder;
|
|
@@ -2110,6 +2177,7 @@ class Module extends EventEmitter {
|
|
|
2110
2177
|
}
|
|
2111
2178
|
static loadSettings(settings, password) {
|
|
2112
2179
|
var _h;
|
|
2180
|
+
var _j;
|
|
2113
2181
|
const current = VALUES["process.password"];
|
|
2114
2182
|
if (current) {
|
|
2115
2183
|
const proc = settings.process || {};
|
|
@@ -2125,7 +2193,7 @@ class Module extends EventEmitter {
|
|
|
2125
2193
|
}
|
|
2126
2194
|
}
|
|
2127
2195
|
else if ((0, types_1.isString)(password)) {
|
|
2128
|
-
VALUES["process.password"] = encryptMessage(password, settings.process
|
|
2196
|
+
VALUES["process.password"] = encryptMessage(password, (_h = settings.process) === null || _h === void 0 ? void 0 : _h.cipher);
|
|
2129
2197
|
}
|
|
2130
2198
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
2131
2199
|
if ((0, types_1.isPlainObject)(node)) {
|
|
@@ -2171,10 +2239,10 @@ class Module extends EventEmitter {
|
|
|
2171
2239
|
VALUES["process.env.apply"] = env.apply;
|
|
2172
2240
|
}
|
|
2173
2241
|
if ((0, types_1.isString)(pwd)) {
|
|
2174
|
-
VALUES[
|
|
2242
|
+
VALUES[_j = "process.password"] || (VALUES[_j] = encryptMessage(pwd, cipher));
|
|
2175
2243
|
}
|
|
2176
2244
|
}
|
|
2177
|
-
if ((0, types_1.isPlainObject)(memory
|
|
2245
|
+
if ((0, types_1.isPlainObject)(memory === null || memory === void 0 ? void 0 : memory.settings)) {
|
|
2178
2246
|
const { users, cache_disk } = memory.settings;
|
|
2179
2247
|
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2180
2248
|
VALUES["memory.settings.users"] = users;
|
|
@@ -2353,7 +2421,7 @@ class Module extends EventEmitter {
|
|
|
2353
2421
|
}
|
|
2354
2422
|
}
|
|
2355
2423
|
}
|
|
2356
|
-
if (broadcast
|
|
2424
|
+
if (broadcast === null || broadcast === void 0 ? void 0 : broadcast.out) {
|
|
2357
2425
|
VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true });
|
|
2358
2426
|
}
|
|
2359
2427
|
if (stack_trace && stack_trace !== true && +stack_trace > 0) {
|
|
@@ -2448,7 +2516,7 @@ class Module extends EventEmitter {
|
|
|
2448
2516
|
}
|
|
2449
2517
|
const host = this.host;
|
|
2450
2518
|
const item = this[kSupports][name];
|
|
2451
|
-
return host && !item
|
|
2519
|
+
return host && !(item === null || item === void 0 ? void 0 : item.modified) ? host.supports(name) : (item === null || item === void 0 ? void 0 : item.value) === true;
|
|
2452
2520
|
}
|
|
2453
2521
|
getTempDir(pathname, filename, createDir) {
|
|
2454
2522
|
let increment = 0, moduleDir, uuidDir;
|
|
@@ -2472,11 +2540,11 @@ class Module extends EventEmitter {
|
|
|
2472
2540
|
let result;
|
|
2473
2541
|
if ((0, types_1.isString)(pathname)) {
|
|
2474
2542
|
leading.push(pathname);
|
|
2475
|
-
createDir
|
|
2543
|
+
createDir !== null && createDir !== void 0 ? createDir : (createDir = true);
|
|
2476
2544
|
}
|
|
2477
2545
|
if (uuidDir) {
|
|
2478
2546
|
leading.push((0, types_1.generateUUID)());
|
|
2479
|
-
createDir
|
|
2547
|
+
createDir !== null && createDir !== void 0 ? createDir : (createDir = true);
|
|
2480
2548
|
}
|
|
2481
2549
|
if ((createDir || increment > 0) && !Module.isDir(result = path.join(...leading))) {
|
|
2482
2550
|
const [output] = tryIncrementDir(result, increment);
|
|
@@ -3434,8 +3502,9 @@ class Module extends EventEmitter {
|
|
|
3434
3502
|
return !!this[kPermission];
|
|
3435
3503
|
}
|
|
3436
3504
|
isFatal(err) {
|
|
3437
|
-
|
|
3438
|
-
|
|
3505
|
+
var _h, _j;
|
|
3506
|
+
const fatal = (_j = (_h = this.host) === null || _h === void 0 ? void 0 : _h.config.error) === null || _j === void 0 ? void 0 : _j.fatal;
|
|
3507
|
+
return fatal !== null && fatal !== void 0 ? fatal : VALUES["error.fatal"];
|
|
3439
3508
|
}
|
|
3440
3509
|
get moduleName() {
|
|
3441
3510
|
return this._moduleName;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.8",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,14 +17,15 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/types": "0.8.8",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|
|
27
27
|
"file-type": "16.5.4",
|
|
28
|
+
"js-yaml": "^4.1.0",
|
|
28
29
|
"mime-types": "^2.1.35",
|
|
29
30
|
"picomatch": "^3.0.1",
|
|
30
31
|
"strip-ansi": "6.0.1"
|