locter 0.5.0 → 0.5.2
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/dist/index.cjs.js +131 -51
- package/dist/index.esm.js +131 -52
- package/dist/types/loader/file-type/script/async.d.ts +2 -2
- package/dist/types/loader/file-type/script/sync.d.ts +2 -2
- package/dist/types/loader/file-type/script/type.d.ts +4 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/object.d.ts +1 -0
- package/package.json +3 -4
package/dist/index.cjs.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var isFileEsm = require('is-file-esm');
|
|
4
3
|
var url = require('url');
|
|
5
4
|
var glob = require('glob');
|
|
6
5
|
var util = require('util');
|
|
7
6
|
var path = require('path');
|
|
8
7
|
var fs = require('fs');
|
|
9
8
|
|
|
9
|
+
function ownKeys(object, enumerableOnly) {
|
|
10
|
+
var keys = Object.keys(object);
|
|
11
|
+
if (Object.getOwnPropertySymbols) {
|
|
12
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
13
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
14
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
15
|
+
})), keys.push.apply(keys, symbols);
|
|
16
|
+
}
|
|
17
|
+
return keys;
|
|
18
|
+
}
|
|
19
|
+
function _objectSpread2(target) {
|
|
20
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
21
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
22
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
23
|
+
_defineProperty(target, key, source[key]);
|
|
24
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
25
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return target;
|
|
29
|
+
}
|
|
10
30
|
function _regeneratorRuntime() {
|
|
11
31
|
_regeneratorRuntime = function () {
|
|
12
32
|
return exports;
|
|
@@ -347,6 +367,34 @@ function _asyncToGenerator(fn) {
|
|
|
347
367
|
});
|
|
348
368
|
};
|
|
349
369
|
}
|
|
370
|
+
function _defineProperty(obj, key, value) {
|
|
371
|
+
key = _toPropertyKey(key);
|
|
372
|
+
if (key in obj) {
|
|
373
|
+
Object.defineProperty(obj, key, {
|
|
374
|
+
value: value,
|
|
375
|
+
enumerable: true,
|
|
376
|
+
configurable: true,
|
|
377
|
+
writable: true
|
|
378
|
+
});
|
|
379
|
+
} else {
|
|
380
|
+
obj[key] = value;
|
|
381
|
+
}
|
|
382
|
+
return obj;
|
|
383
|
+
}
|
|
384
|
+
function _toPrimitive(input, hint) {
|
|
385
|
+
if (typeof input !== "object" || input === null) return input;
|
|
386
|
+
var prim = input[Symbol.toPrimitive];
|
|
387
|
+
if (prim !== undefined) {
|
|
388
|
+
var res = prim.call(input, hint || "default");
|
|
389
|
+
if (typeof res !== "object") return res;
|
|
390
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
391
|
+
}
|
|
392
|
+
return (hint === "string" ? String : Number)(input);
|
|
393
|
+
}
|
|
394
|
+
function _toPropertyKey(arg) {
|
|
395
|
+
var key = _toPrimitive(arg, "string");
|
|
396
|
+
return typeof key === "symbol" ? key : String(key);
|
|
397
|
+
}
|
|
350
398
|
|
|
351
399
|
/*
|
|
352
400
|
* Copyright (c) 2022.
|
|
@@ -395,8 +443,8 @@ function hasOwnProperty(obj, prop) {
|
|
|
395
443
|
* view the LICENSE file that was distributed with this source code.
|
|
396
444
|
*/
|
|
397
445
|
|
|
398
|
-
function
|
|
399
|
-
return
|
|
446
|
+
function isObject(item) {
|
|
447
|
+
return !!item && _typeof(item) === 'object' && !Array.isArray(item);
|
|
400
448
|
}
|
|
401
449
|
|
|
402
450
|
/*
|
|
@@ -405,26 +453,9 @@ function toArray(input) {
|
|
|
405
453
|
* For the full copyright and license information,
|
|
406
454
|
* view the LICENSE file that was distributed with this source code.
|
|
407
455
|
*/
|
|
408
|
-
function getExportItem(data, filterFn) {
|
|
409
|
-
if (filterFn) {
|
|
410
|
-
var keys = Object.keys(data);
|
|
411
|
-
for (var i = 0; i < keys.length; i++) {
|
|
412
|
-
if (filterFn(keys[i], data[keys[i]])) {
|
|
413
|
-
return {
|
|
414
|
-
key: keys[i],
|
|
415
|
-
value: data[keys[i]]
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
} else {
|
|
420
|
-
return {
|
|
421
|
-
key: 'default',
|
|
422
|
-
value: hasOwnProperty(data, 'default') ? data["default"] : data
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
456
|
|
|
426
|
-
|
|
427
|
-
return
|
|
457
|
+
function toArray(input) {
|
|
458
|
+
return Array.isArray(input) ? input : [input];
|
|
428
459
|
}
|
|
429
460
|
|
|
430
461
|
function buildLocatorOptions(options) {
|
|
@@ -638,59 +669,93 @@ function buildLoaderFilePath(info, withExtension) {
|
|
|
638
669
|
return path.join(info.path, info.name);
|
|
639
670
|
}
|
|
640
671
|
|
|
641
|
-
|
|
672
|
+
/*
|
|
673
|
+
* Copyright (c) 2022.
|
|
674
|
+
* Author Peter Placzek (tada5hi)
|
|
675
|
+
* For the full copyright and license information,
|
|
676
|
+
* view the LICENSE file that was distributed with this source code.
|
|
677
|
+
*/
|
|
678
|
+
function getExportItem(data, filterFn) {
|
|
679
|
+
if (filterFn) {
|
|
680
|
+
var keys = Object.keys(data);
|
|
681
|
+
for (var i = 0; i < keys.length; i++) {
|
|
682
|
+
if (filterFn(keys[i], data[keys[i]])) {
|
|
683
|
+
return {
|
|
684
|
+
key: keys[i],
|
|
685
|
+
value: data[keys[i]]
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
} else {
|
|
690
|
+
return {
|
|
691
|
+
key: 'default',
|
|
692
|
+
value: hasOwnProperty(data, 'default') ? data["default"] : data
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/* istanbul ignore next */
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function loadScriptFile(_x, _x2) {
|
|
642
701
|
return _loadScriptFile.apply(this, arguments);
|
|
643
702
|
}
|
|
644
703
|
function _loadScriptFile() {
|
|
645
|
-
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
|
|
646
|
-
var locatorInfo, filePath
|
|
704
|
+
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data, options) {
|
|
705
|
+
var locatorInfo, filePath;
|
|
647
706
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
648
707
|
while (1) {
|
|
649
708
|
switch (_context.prev = _context.next) {
|
|
650
709
|
case 0:
|
|
651
710
|
if (typeof data === 'string') {
|
|
652
|
-
filePath = data;
|
|
653
711
|
locatorInfo = pathToLocatorInfo(data);
|
|
654
712
|
} else {
|
|
655
|
-
filePath = buildLoaderFilePath(data, true);
|
|
656
713
|
locatorInfo = data;
|
|
657
714
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
715
|
+
options = options || {};
|
|
716
|
+
filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
|
|
717
|
+
if (options.withFilePrefix) {
|
|
718
|
+
filePath = url.pathToFileURL(filePath).href;
|
|
719
|
+
}
|
|
720
|
+
_context.prev = 4;
|
|
721
|
+
_context.next = 7;
|
|
722
|
+
return import(filePath);
|
|
723
|
+
case 7:
|
|
724
|
+
return _context.abrupt("return", _context.sent);
|
|
725
|
+
case 10:
|
|
726
|
+
_context.prev = 10;
|
|
727
|
+
_context.t0 = _context["catch"](4);
|
|
728
|
+
if (!(isObject(_context.t0) && hasOwnProperty(_context.t0, 'code'))) {
|
|
729
|
+
_context.next = 17;
|
|
661
730
|
break;
|
|
662
731
|
}
|
|
663
|
-
_context.
|
|
664
|
-
|
|
665
|
-
case 5:
|
|
666
|
-
check = _context.sent;
|
|
667
|
-
if (!check.esm) {
|
|
668
|
-
_context.next = 10;
|
|
732
|
+
if (!(_context.t0.code === 'ERR_MODULE_NOT_FOUND' || _context.t0.code === 'MODULE_NOT_FOUND')) {
|
|
733
|
+
_context.next = 15;
|
|
669
734
|
break;
|
|
670
735
|
}
|
|
671
|
-
_context.
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
return _context.abrupt("return", _context.sent);
|
|
675
|
-
case 10:
|
|
676
|
-
_context.next = 12;
|
|
677
|
-
return import(filePath);
|
|
678
|
-
case 12:
|
|
679
|
-
return _context.abrupt("return", _context.sent);
|
|
736
|
+
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
737
|
+
withExtension: true
|
|
738
|
+
})));
|
|
680
739
|
case 15:
|
|
681
|
-
_context.
|
|
682
|
-
|
|
740
|
+
if (!(_context.t0.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || _context.t0.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
|
|
741
|
+
_context.next = 17;
|
|
742
|
+
break;
|
|
743
|
+
}
|
|
744
|
+
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
745
|
+
withFilePrefix: true
|
|
746
|
+
})));
|
|
747
|
+
case 17:
|
|
683
748
|
return _context.abrupt("return", handleFileLoadError(_context.t0));
|
|
684
749
|
case 18:
|
|
685
750
|
case "end":
|
|
686
751
|
return _context.stop();
|
|
687
752
|
}
|
|
688
753
|
}
|
|
689
|
-
}, _callee, null, [[
|
|
754
|
+
}, _callee, null, [[4, 10]]);
|
|
690
755
|
}));
|
|
691
756
|
return _loadScriptFile.apply(this, arguments);
|
|
692
757
|
}
|
|
693
|
-
function loadScriptFileExport(
|
|
758
|
+
function loadScriptFileExport(_x3, _x4) {
|
|
694
759
|
return _loadScriptFileExport.apply(this, arguments);
|
|
695
760
|
}
|
|
696
761
|
function _loadScriptFileExport() {
|
|
@@ -726,12 +791,26 @@ function _loadScriptFileExport() {
|
|
|
726
791
|
return _loadScriptFileExport.apply(this, arguments);
|
|
727
792
|
}
|
|
728
793
|
|
|
729
|
-
function loadScriptFileSync(data) {
|
|
730
|
-
var
|
|
794
|
+
function loadScriptFileSync(data, options) {
|
|
795
|
+
var locatorInfo;
|
|
796
|
+
if (typeof data === 'string') {
|
|
797
|
+
locatorInfo = pathToLocatorInfo(data);
|
|
798
|
+
} else {
|
|
799
|
+
locatorInfo = data;
|
|
800
|
+
}
|
|
801
|
+
options = options || {};
|
|
802
|
+
var filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
|
|
731
803
|
try {
|
|
732
804
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require,import/no-dynamic-require
|
|
733
805
|
return require(filePath);
|
|
734
806
|
} catch (e) {
|
|
807
|
+
if (isObject(e) && hasOwnProperty(e, 'code')) {
|
|
808
|
+
if (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND') {
|
|
809
|
+
return loadScriptFileSync(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
810
|
+
withExtension: true
|
|
811
|
+
}));
|
|
812
|
+
}
|
|
813
|
+
}
|
|
735
814
|
return handleFileLoadError(e);
|
|
736
815
|
}
|
|
737
816
|
}
|
|
@@ -847,6 +926,7 @@ exports.getExportItem = getExportItem;
|
|
|
847
926
|
exports.handleFileLoadError = handleFileLoadError;
|
|
848
927
|
exports.hasOwnProperty = hasOwnProperty;
|
|
849
928
|
exports.isLocatorInfo = isLocatorInfo;
|
|
929
|
+
exports.isObject = isObject;
|
|
850
930
|
exports.loadFile = loadFile;
|
|
851
931
|
exports.loadFileSync = loadFileSync;
|
|
852
932
|
exports.loadJsonFile = loadJsonFile;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
import isFileEsm from 'is-file-esm';
|
|
2
1
|
import { pathToFileURL } from 'url';
|
|
3
2
|
import { glob, sync } from 'glob';
|
|
4
3
|
import { promisify } from 'util';
|
|
5
4
|
import path from 'path';
|
|
6
5
|
import fs from 'fs';
|
|
7
6
|
|
|
7
|
+
function ownKeys(object, enumerableOnly) {
|
|
8
|
+
var keys = Object.keys(object);
|
|
9
|
+
if (Object.getOwnPropertySymbols) {
|
|
10
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
11
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
12
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
13
|
+
})), keys.push.apply(keys, symbols);
|
|
14
|
+
}
|
|
15
|
+
return keys;
|
|
16
|
+
}
|
|
17
|
+
function _objectSpread2(target) {
|
|
18
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
19
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
20
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
21
|
+
_defineProperty(target, key, source[key]);
|
|
22
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
23
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
8
28
|
function _regeneratorRuntime() {
|
|
9
29
|
_regeneratorRuntime = function () {
|
|
10
30
|
return exports;
|
|
@@ -345,6 +365,34 @@ function _asyncToGenerator(fn) {
|
|
|
345
365
|
});
|
|
346
366
|
};
|
|
347
367
|
}
|
|
368
|
+
function _defineProperty(obj, key, value) {
|
|
369
|
+
key = _toPropertyKey(key);
|
|
370
|
+
if (key in obj) {
|
|
371
|
+
Object.defineProperty(obj, key, {
|
|
372
|
+
value: value,
|
|
373
|
+
enumerable: true,
|
|
374
|
+
configurable: true,
|
|
375
|
+
writable: true
|
|
376
|
+
});
|
|
377
|
+
} else {
|
|
378
|
+
obj[key] = value;
|
|
379
|
+
}
|
|
380
|
+
return obj;
|
|
381
|
+
}
|
|
382
|
+
function _toPrimitive(input, hint) {
|
|
383
|
+
if (typeof input !== "object" || input === null) return input;
|
|
384
|
+
var prim = input[Symbol.toPrimitive];
|
|
385
|
+
if (prim !== undefined) {
|
|
386
|
+
var res = prim.call(input, hint || "default");
|
|
387
|
+
if (typeof res !== "object") return res;
|
|
388
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
389
|
+
}
|
|
390
|
+
return (hint === "string" ? String : Number)(input);
|
|
391
|
+
}
|
|
392
|
+
function _toPropertyKey(arg) {
|
|
393
|
+
var key = _toPrimitive(arg, "string");
|
|
394
|
+
return typeof key === "symbol" ? key : String(key);
|
|
395
|
+
}
|
|
348
396
|
|
|
349
397
|
/*
|
|
350
398
|
* Copyright (c) 2022.
|
|
@@ -393,8 +441,8 @@ function hasOwnProperty(obj, prop) {
|
|
|
393
441
|
* view the LICENSE file that was distributed with this source code.
|
|
394
442
|
*/
|
|
395
443
|
|
|
396
|
-
function
|
|
397
|
-
return
|
|
444
|
+
function isObject(item) {
|
|
445
|
+
return !!item && _typeof(item) === 'object' && !Array.isArray(item);
|
|
398
446
|
}
|
|
399
447
|
|
|
400
448
|
/*
|
|
@@ -403,26 +451,9 @@ function toArray(input) {
|
|
|
403
451
|
* For the full copyright and license information,
|
|
404
452
|
* view the LICENSE file that was distributed with this source code.
|
|
405
453
|
*/
|
|
406
|
-
function getExportItem(data, filterFn) {
|
|
407
|
-
if (filterFn) {
|
|
408
|
-
var keys = Object.keys(data);
|
|
409
|
-
for (var i = 0; i < keys.length; i++) {
|
|
410
|
-
if (filterFn(keys[i], data[keys[i]])) {
|
|
411
|
-
return {
|
|
412
|
-
key: keys[i],
|
|
413
|
-
value: data[keys[i]]
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
} else {
|
|
418
|
-
return {
|
|
419
|
-
key: 'default',
|
|
420
|
-
value: hasOwnProperty(data, 'default') ? data["default"] : data
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
454
|
|
|
424
|
-
|
|
425
|
-
return
|
|
455
|
+
function toArray(input) {
|
|
456
|
+
return Array.isArray(input) ? input : [input];
|
|
426
457
|
}
|
|
427
458
|
|
|
428
459
|
function buildLocatorOptions(options) {
|
|
@@ -636,59 +667,93 @@ function buildLoaderFilePath(info, withExtension) {
|
|
|
636
667
|
return path.join(info.path, info.name);
|
|
637
668
|
}
|
|
638
669
|
|
|
639
|
-
|
|
670
|
+
/*
|
|
671
|
+
* Copyright (c) 2022.
|
|
672
|
+
* Author Peter Placzek (tada5hi)
|
|
673
|
+
* For the full copyright and license information,
|
|
674
|
+
* view the LICENSE file that was distributed with this source code.
|
|
675
|
+
*/
|
|
676
|
+
function getExportItem(data, filterFn) {
|
|
677
|
+
if (filterFn) {
|
|
678
|
+
var keys = Object.keys(data);
|
|
679
|
+
for (var i = 0; i < keys.length; i++) {
|
|
680
|
+
if (filterFn(keys[i], data[keys[i]])) {
|
|
681
|
+
return {
|
|
682
|
+
key: keys[i],
|
|
683
|
+
value: data[keys[i]]
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
} else {
|
|
688
|
+
return {
|
|
689
|
+
key: 'default',
|
|
690
|
+
value: hasOwnProperty(data, 'default') ? data["default"] : data
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/* istanbul ignore next */
|
|
695
|
+
return undefined;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function loadScriptFile(_x, _x2) {
|
|
640
699
|
return _loadScriptFile.apply(this, arguments);
|
|
641
700
|
}
|
|
642
701
|
function _loadScriptFile() {
|
|
643
|
-
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
|
|
644
|
-
var locatorInfo, filePath
|
|
702
|
+
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data, options) {
|
|
703
|
+
var locatorInfo, filePath;
|
|
645
704
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
646
705
|
while (1) {
|
|
647
706
|
switch (_context.prev = _context.next) {
|
|
648
707
|
case 0:
|
|
649
708
|
if (typeof data === 'string') {
|
|
650
|
-
filePath = data;
|
|
651
709
|
locatorInfo = pathToLocatorInfo(data);
|
|
652
710
|
} else {
|
|
653
|
-
filePath = buildLoaderFilePath(data, true);
|
|
654
711
|
locatorInfo = data;
|
|
655
712
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
713
|
+
options = options || {};
|
|
714
|
+
filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
|
|
715
|
+
if (options.withFilePrefix) {
|
|
716
|
+
filePath = pathToFileURL(filePath).href;
|
|
717
|
+
}
|
|
718
|
+
_context.prev = 4;
|
|
719
|
+
_context.next = 7;
|
|
720
|
+
return import(filePath);
|
|
721
|
+
case 7:
|
|
722
|
+
return _context.abrupt("return", _context.sent);
|
|
723
|
+
case 10:
|
|
724
|
+
_context.prev = 10;
|
|
725
|
+
_context.t0 = _context["catch"](4);
|
|
726
|
+
if (!(isObject(_context.t0) && hasOwnProperty(_context.t0, 'code'))) {
|
|
727
|
+
_context.next = 17;
|
|
659
728
|
break;
|
|
660
729
|
}
|
|
661
|
-
_context.
|
|
662
|
-
|
|
663
|
-
case 5:
|
|
664
|
-
check = _context.sent;
|
|
665
|
-
if (!check.esm) {
|
|
666
|
-
_context.next = 10;
|
|
730
|
+
if (!(_context.t0.code === 'ERR_MODULE_NOT_FOUND' || _context.t0.code === 'MODULE_NOT_FOUND')) {
|
|
731
|
+
_context.next = 15;
|
|
667
732
|
break;
|
|
668
733
|
}
|
|
669
|
-
_context.
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
return _context.abrupt("return", _context.sent);
|
|
673
|
-
case 10:
|
|
674
|
-
_context.next = 12;
|
|
675
|
-
return import(filePath);
|
|
676
|
-
case 12:
|
|
677
|
-
return _context.abrupt("return", _context.sent);
|
|
734
|
+
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
735
|
+
withExtension: true
|
|
736
|
+
})));
|
|
678
737
|
case 15:
|
|
679
|
-
_context.
|
|
680
|
-
|
|
738
|
+
if (!(_context.t0.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || _context.t0.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
|
|
739
|
+
_context.next = 17;
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
743
|
+
withFilePrefix: true
|
|
744
|
+
})));
|
|
745
|
+
case 17:
|
|
681
746
|
return _context.abrupt("return", handleFileLoadError(_context.t0));
|
|
682
747
|
case 18:
|
|
683
748
|
case "end":
|
|
684
749
|
return _context.stop();
|
|
685
750
|
}
|
|
686
751
|
}
|
|
687
|
-
}, _callee, null, [[
|
|
752
|
+
}, _callee, null, [[4, 10]]);
|
|
688
753
|
}));
|
|
689
754
|
return _loadScriptFile.apply(this, arguments);
|
|
690
755
|
}
|
|
691
|
-
function loadScriptFileExport(
|
|
756
|
+
function loadScriptFileExport(_x3, _x4) {
|
|
692
757
|
return _loadScriptFileExport.apply(this, arguments);
|
|
693
758
|
}
|
|
694
759
|
function _loadScriptFileExport() {
|
|
@@ -724,12 +789,26 @@ function _loadScriptFileExport() {
|
|
|
724
789
|
return _loadScriptFileExport.apply(this, arguments);
|
|
725
790
|
}
|
|
726
791
|
|
|
727
|
-
function loadScriptFileSync(data) {
|
|
728
|
-
var
|
|
792
|
+
function loadScriptFileSync(data, options) {
|
|
793
|
+
var locatorInfo;
|
|
794
|
+
if (typeof data === 'string') {
|
|
795
|
+
locatorInfo = pathToLocatorInfo(data);
|
|
796
|
+
} else {
|
|
797
|
+
locatorInfo = data;
|
|
798
|
+
}
|
|
799
|
+
options = options || {};
|
|
800
|
+
var filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
|
|
729
801
|
try {
|
|
730
802
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require,import/no-dynamic-require
|
|
731
803
|
return require(filePath);
|
|
732
804
|
} catch (e) {
|
|
805
|
+
if (isObject(e) && hasOwnProperty(e, 'code')) {
|
|
806
|
+
if (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND') {
|
|
807
|
+
return loadScriptFileSync(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
808
|
+
withExtension: true
|
|
809
|
+
}));
|
|
810
|
+
}
|
|
811
|
+
}
|
|
733
812
|
return handleFileLoadError(e);
|
|
734
813
|
}
|
|
735
814
|
}
|
|
@@ -839,4 +918,4 @@ function loadFileSync(input) {
|
|
|
839
918
|
return loadScriptFileSync(info);
|
|
840
919
|
}
|
|
841
920
|
|
|
842
|
-
export { buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, isLocatorInfo, loadFile, loadFileSync, loadJsonFile, loadJsonFileSync, loadScriptFile, loadScriptFileExport, loadScriptFileExportSync, loadScriptFileSync, locateFile, locateFileSync, locateFiles, locateFilesSync, pathToLocatorInfo, removeFileNameExtension, toArray };
|
|
921
|
+
export { buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, isLocatorInfo, isObject, loadFile, loadFileSync, loadJsonFile, loadJsonFileSync, loadScriptFile, loadScriptFileExport, loadScriptFileExportSync, loadScriptFileSync, locateFile, locateFileSync, locateFiles, locateFilesSync, pathToLocatorInfo, removeFileNameExtension, toArray };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoaderFilterFn, ScriptFileExportItem } from './type';
|
|
2
1
|
import { LocatorInfo } from '../../../locator';
|
|
3
|
-
|
|
2
|
+
import { LoaderFilterFn, ScriptFileExportItem, ScriptFileLoadOptions } from './type';
|
|
3
|
+
export declare function loadScriptFile(data: LocatorInfo | string, options?: ScriptFileLoadOptions): Promise<unknown | undefined>;
|
|
4
4
|
export declare function loadScriptFileExport(data: LocatorInfo | string, filterFn?: LoaderFilterFn): Promise<ScriptFileExportItem | undefined>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoaderFilterFn, ScriptFileExportItem } from './type';
|
|
1
|
+
import { LoaderFilterFn, ScriptFileExportItem, ScriptFileLoadOptions } from './type';
|
|
2
2
|
import { LocatorInfo } from '../../../locator';
|
|
3
|
-
export declare function loadScriptFileSync(data: LocatorInfo | string): unknown | undefined;
|
|
3
|
+
export declare function loadScriptFileSync(data: LocatorInfo | string, options?: ScriptFileLoadOptions): unknown | undefined;
|
|
4
4
|
export declare function loadScriptFileExportSync(data: LocatorInfo | string, filterFn?: LoaderFilterFn): ScriptFileExportItem | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isObject(item: unknown): item is Record<string, any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locter",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "A library to locate a file by criteria and load it",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Placzek",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@types/is-file-esm": "^1.0.0",
|
|
59
59
|
"@types/jest": "^27.5.0",
|
|
60
60
|
"@types/node": "^18.11.9",
|
|
61
|
-
"@types/yargs": "^17.0.
|
|
61
|
+
"@types/yargs": "^17.0.15",
|
|
62
62
|
"coveralls": "^3.1.0",
|
|
63
63
|
"cross-env": "^7.0.3",
|
|
64
64
|
"eslint": "^8.28.0",
|
|
@@ -72,8 +72,7 @@
|
|
|
72
72
|
"typescript": "^4.9.3"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"glob": "^8.0.3"
|
|
76
|
-
"is-file-esm": "^1.0.0"
|
|
75
|
+
"glob": "^8.0.3"
|
|
77
76
|
},
|
|
78
77
|
"config": {
|
|
79
78
|
"commitizen": {
|