locter 0.5.3 → 0.6.1
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
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var ebec = require('ebec');
|
|
3
4
|
var url = require('url');
|
|
4
5
|
var glob = require('glob');
|
|
5
6
|
var util = require('util');
|
|
@@ -381,6 +382,45 @@ function _defineProperty(obj, key, value) {
|
|
|
381
382
|
}
|
|
382
383
|
return obj;
|
|
383
384
|
}
|
|
385
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
386
|
+
if (typeof WeakMap !== "function") return null;
|
|
387
|
+
var cacheBabelInterop = new WeakMap();
|
|
388
|
+
var cacheNodeInterop = new WeakMap();
|
|
389
|
+
return (_getRequireWildcardCache = function (nodeInterop) {
|
|
390
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
391
|
+
})(nodeInterop);
|
|
392
|
+
}
|
|
393
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
394
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
395
|
+
return obj;
|
|
396
|
+
}
|
|
397
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
398
|
+
return {
|
|
399
|
+
default: obj
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
403
|
+
if (cache && cache.has(obj)) {
|
|
404
|
+
return cache.get(obj);
|
|
405
|
+
}
|
|
406
|
+
var newObj = {};
|
|
407
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
408
|
+
for (var key in obj) {
|
|
409
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
410
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
411
|
+
if (desc && (desc.get || desc.set)) {
|
|
412
|
+
Object.defineProperty(newObj, key, desc);
|
|
413
|
+
} else {
|
|
414
|
+
newObj[key] = obj[key];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
newObj.default = obj;
|
|
419
|
+
if (cache) {
|
|
420
|
+
cache.set(obj, newObj);
|
|
421
|
+
}
|
|
422
|
+
return newObj;
|
|
423
|
+
}
|
|
384
424
|
function _toPrimitive(input, hint) {
|
|
385
425
|
if (typeof input !== "object" || input === null) return input;
|
|
386
426
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -435,6 +475,9 @@ function removeFileNameExtension(input, extensions) {
|
|
|
435
475
|
function hasOwnProperty(obj, prop) {
|
|
436
476
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
437
477
|
}
|
|
478
|
+
function hasStringProperty(obj, prop) {
|
|
479
|
+
return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';
|
|
480
|
+
}
|
|
438
481
|
|
|
439
482
|
/*
|
|
440
483
|
* Copyright (c) 2022.
|
|
@@ -719,14 +762,16 @@ function _loadScriptFile() {
|
|
|
719
762
|
}
|
|
720
763
|
_context.prev = 4;
|
|
721
764
|
_context.next = 7;
|
|
722
|
-
return
|
|
765
|
+
return Promise.resolve("".concat(filePath)).then(function (s) {
|
|
766
|
+
return _interopRequireWildcard(require(s));
|
|
767
|
+
});
|
|
723
768
|
case 7:
|
|
724
769
|
return _context.abrupt("return", _context.sent);
|
|
725
770
|
case 10:
|
|
726
771
|
_context.prev = 10;
|
|
727
772
|
_context.t0 = _context["catch"](4);
|
|
728
|
-
if (!(isObject(_context.t0) &&
|
|
729
|
-
_context.next =
|
|
773
|
+
if (!(isObject(_context.t0) && hasStringProperty(_context.t0, 'code'))) {
|
|
774
|
+
_context.next = 18;
|
|
730
775
|
break;
|
|
731
776
|
}
|
|
732
777
|
if (!(!options.withExtension && (_context.t0.code === 'ERR_MODULE_NOT_FOUND' || _context.t0.code === 'MODULE_NOT_FOUND'))) {
|
|
@@ -745,8 +790,14 @@ function _loadScriptFile() {
|
|
|
745
790
|
withFilePrefix: true
|
|
746
791
|
})));
|
|
747
792
|
case 17:
|
|
748
|
-
|
|
793
|
+
throw new ebec.BaseError({
|
|
794
|
+
code: _context.t0.code,
|
|
795
|
+
message: hasStringProperty(_context.t0, 'message') ? _context.t0.message : undefined,
|
|
796
|
+
stack: hasStringProperty(_context.t0, 'stack') ? _context.t0.stack : undefined
|
|
797
|
+
});
|
|
749
798
|
case 18:
|
|
799
|
+
return _context.abrupt("return", handleFileLoadError(_context.t0));
|
|
800
|
+
case 19:
|
|
750
801
|
case "end":
|
|
751
802
|
return _context.stop();
|
|
752
803
|
}
|
|
@@ -805,12 +856,17 @@ function loadScriptFileSync(data, options) {
|
|
|
805
856
|
return require(filePath);
|
|
806
857
|
} catch (e) {
|
|
807
858
|
/* istanbul ignore next */
|
|
808
|
-
if (isObject(e) &&
|
|
859
|
+
if (isObject(e) && hasStringProperty(e, 'code')) {
|
|
809
860
|
if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
|
|
810
861
|
return loadScriptFileSync(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
811
862
|
withExtension: true
|
|
812
863
|
}));
|
|
813
864
|
}
|
|
865
|
+
throw new ebec.BaseError({
|
|
866
|
+
code: e.code,
|
|
867
|
+
message: hasStringProperty(e, 'message') ? e.message : undefined,
|
|
868
|
+
stack: hasStringProperty(e, 'stack') ? e.stack : undefined
|
|
869
|
+
});
|
|
814
870
|
}
|
|
815
871
|
return handleFileLoadError(e);
|
|
816
872
|
}
|
|
@@ -832,13 +888,17 @@ function loadJsonFile(_x) {
|
|
|
832
888
|
return _loadJsonFile.apply(this, arguments);
|
|
833
889
|
}
|
|
834
890
|
function _loadJsonFile() {
|
|
835
|
-
_loadJsonFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(
|
|
891
|
+
_loadJsonFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
|
836
892
|
var filePath, file;
|
|
837
893
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
838
894
|
while (1) {
|
|
839
895
|
switch (_context.prev = _context.next) {
|
|
840
896
|
case 0:
|
|
841
|
-
|
|
897
|
+
if (typeof input === 'string') {
|
|
898
|
+
filePath = path.isAbsolute(input) ? input : path.resolve(process.cwd(), input);
|
|
899
|
+
} else {
|
|
900
|
+
filePath = buildLoaderFilePath(input, true);
|
|
901
|
+
}
|
|
842
902
|
_context.prev = 1;
|
|
843
903
|
_context.next = 4;
|
|
844
904
|
return fs.promises.readFile(filePath);
|
|
@@ -858,8 +918,13 @@ function _loadJsonFile() {
|
|
|
858
918
|
}));
|
|
859
919
|
return _loadJsonFile.apply(this, arguments);
|
|
860
920
|
}
|
|
861
|
-
function loadJsonFileSync(
|
|
862
|
-
var filePath
|
|
921
|
+
function loadJsonFileSync(input) {
|
|
922
|
+
var filePath;
|
|
923
|
+
if (typeof input === 'string') {
|
|
924
|
+
filePath = path.isAbsolute(input) ? input : path.resolve(process.cwd(), input);
|
|
925
|
+
} else {
|
|
926
|
+
filePath = buildLoaderFilePath(input, true);
|
|
927
|
+
}
|
|
863
928
|
try {
|
|
864
929
|
var file = fs.readFileSync(filePath);
|
|
865
930
|
return JSON.parse(file.toString('utf-8'));
|
|
@@ -926,6 +991,7 @@ exports.buildLocatorOptions = buildLocatorOptions;
|
|
|
926
991
|
exports.getExportItem = getExportItem;
|
|
927
992
|
exports.handleFileLoadError = handleFileLoadError;
|
|
928
993
|
exports.hasOwnProperty = hasOwnProperty;
|
|
994
|
+
exports.hasStringProperty = hasStringProperty;
|
|
929
995
|
exports.isLocatorInfo = isLocatorInfo;
|
|
930
996
|
exports.isObject = isObject;
|
|
931
997
|
exports.loadFile = loadFile;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BaseError } from 'ebec';
|
|
1
2
|
import { pathToFileURL } from 'url';
|
|
2
3
|
import { glob, sync } from 'glob';
|
|
3
4
|
import { promisify } from 'util';
|
|
@@ -433,6 +434,9 @@ function removeFileNameExtension(input, extensions) {
|
|
|
433
434
|
function hasOwnProperty(obj, prop) {
|
|
434
435
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
435
436
|
}
|
|
437
|
+
function hasStringProperty(obj, prop) {
|
|
438
|
+
return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';
|
|
439
|
+
}
|
|
436
440
|
|
|
437
441
|
/*
|
|
438
442
|
* Copyright (c) 2022.
|
|
@@ -723,8 +727,8 @@ function _loadScriptFile() {
|
|
|
723
727
|
case 10:
|
|
724
728
|
_context.prev = 10;
|
|
725
729
|
_context.t0 = _context["catch"](4);
|
|
726
|
-
if (!(isObject(_context.t0) &&
|
|
727
|
-
_context.next =
|
|
730
|
+
if (!(isObject(_context.t0) && hasStringProperty(_context.t0, 'code'))) {
|
|
731
|
+
_context.next = 18;
|
|
728
732
|
break;
|
|
729
733
|
}
|
|
730
734
|
if (!(!options.withExtension && (_context.t0.code === 'ERR_MODULE_NOT_FOUND' || _context.t0.code === 'MODULE_NOT_FOUND'))) {
|
|
@@ -743,8 +747,14 @@ function _loadScriptFile() {
|
|
|
743
747
|
withFilePrefix: true
|
|
744
748
|
})));
|
|
745
749
|
case 17:
|
|
746
|
-
|
|
750
|
+
throw new BaseError({
|
|
751
|
+
code: _context.t0.code,
|
|
752
|
+
message: hasStringProperty(_context.t0, 'message') ? _context.t0.message : undefined,
|
|
753
|
+
stack: hasStringProperty(_context.t0, 'stack') ? _context.t0.stack : undefined
|
|
754
|
+
});
|
|
747
755
|
case 18:
|
|
756
|
+
return _context.abrupt("return", handleFileLoadError(_context.t0));
|
|
757
|
+
case 19:
|
|
748
758
|
case "end":
|
|
749
759
|
return _context.stop();
|
|
750
760
|
}
|
|
@@ -803,12 +813,17 @@ function loadScriptFileSync(data, options) {
|
|
|
803
813
|
return require(filePath);
|
|
804
814
|
} catch (e) {
|
|
805
815
|
/* istanbul ignore next */
|
|
806
|
-
if (isObject(e) &&
|
|
816
|
+
if (isObject(e) && hasStringProperty(e, 'code')) {
|
|
807
817
|
if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
|
|
808
818
|
return loadScriptFileSync(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
809
819
|
withExtension: true
|
|
810
820
|
}));
|
|
811
821
|
}
|
|
822
|
+
throw new BaseError({
|
|
823
|
+
code: e.code,
|
|
824
|
+
message: hasStringProperty(e, 'message') ? e.message : undefined,
|
|
825
|
+
stack: hasStringProperty(e, 'stack') ? e.stack : undefined
|
|
826
|
+
});
|
|
812
827
|
}
|
|
813
828
|
return handleFileLoadError(e);
|
|
814
829
|
}
|
|
@@ -830,13 +845,17 @@ function loadJsonFile(_x) {
|
|
|
830
845
|
return _loadJsonFile.apply(this, arguments);
|
|
831
846
|
}
|
|
832
847
|
function _loadJsonFile() {
|
|
833
|
-
_loadJsonFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(
|
|
848
|
+
_loadJsonFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
|
834
849
|
var filePath, file;
|
|
835
850
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
836
851
|
while (1) {
|
|
837
852
|
switch (_context.prev = _context.next) {
|
|
838
853
|
case 0:
|
|
839
|
-
|
|
854
|
+
if (typeof input === 'string') {
|
|
855
|
+
filePath = path.isAbsolute(input) ? input : path.resolve(process.cwd(), input);
|
|
856
|
+
} else {
|
|
857
|
+
filePath = buildLoaderFilePath(input, true);
|
|
858
|
+
}
|
|
840
859
|
_context.prev = 1;
|
|
841
860
|
_context.next = 4;
|
|
842
861
|
return fs.promises.readFile(filePath);
|
|
@@ -856,8 +875,13 @@ function _loadJsonFile() {
|
|
|
856
875
|
}));
|
|
857
876
|
return _loadJsonFile.apply(this, arguments);
|
|
858
877
|
}
|
|
859
|
-
function loadJsonFileSync(
|
|
860
|
-
var filePath
|
|
878
|
+
function loadJsonFileSync(input) {
|
|
879
|
+
var filePath;
|
|
880
|
+
if (typeof input === 'string') {
|
|
881
|
+
filePath = path.isAbsolute(input) ? input : path.resolve(process.cwd(), input);
|
|
882
|
+
} else {
|
|
883
|
+
filePath = buildLoaderFilePath(input, true);
|
|
884
|
+
}
|
|
861
885
|
try {
|
|
862
886
|
var file = fs.readFileSync(filePath);
|
|
863
887
|
return JSON.parse(file.toString('utf-8'));
|
|
@@ -919,4 +943,4 @@ function loadFileSync(input) {
|
|
|
919
943
|
return loadScriptFileSync(info);
|
|
920
944
|
}
|
|
921
945
|
|
|
922
|
-
export { buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, isLocatorInfo, isObject, loadFile, loadFileSync, loadJsonFile, loadJsonFileSync, loadScriptFile, loadScriptFileExport, loadScriptFileExportSync, loadScriptFileSync, locateFile, locateFileSync, locateFiles, locateFilesSync, pathToLocatorInfo, removeFileNameExtension, toArray };
|
|
946
|
+
export { buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, hasStringProperty, isLocatorInfo, isObject, loadFile, loadFileSync, loadJsonFile, loadJsonFileSync, loadScriptFile, loadScriptFileExport, loadScriptFileExportSync, loadScriptFileSync, locateFile, locateFileSync, locateFiles, locateFilesSync, pathToLocatorInfo, removeFileNameExtension, toArray };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { LocatorInfo } from '../../locator';
|
|
2
|
-
export declare function loadJsonFile(
|
|
3
|
-
export declare function loadJsonFileSync(
|
|
2
|
+
export declare function loadJsonFile(input: LocatorInfo | string): Promise<unknown | undefined>;
|
|
3
|
+
export declare function loadJsonFileSync(input: LocatorInfo | string): unknown | undefined;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
|
|
2
|
+
export declare function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A library to locate a file by criteria and load it",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Placzek",
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"@commitlint/config-conventional": "^17.3.0",
|
|
46
46
|
"@commitlint/cz-commitlint": "^17.3.0",
|
|
47
47
|
"@rollup/plugin-babel": "^6.0.3",
|
|
48
|
-
"@rollup/plugin-commonjs": "^23.0.2",
|
|
49
48
|
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
50
49
|
"@semantic-release/changelog": "^6.0.2",
|
|
51
50
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
@@ -57,21 +56,23 @@
|
|
|
57
56
|
"@types/glob": "^8.0.0",
|
|
58
57
|
"@types/is-file-esm": "^1.0.0",
|
|
59
58
|
"@types/jest": "^27.5.0",
|
|
60
|
-
"@types/node": "^18.11.
|
|
61
|
-
"@types/yargs": "^17.0.
|
|
59
|
+
"@types/node": "^18.11.17",
|
|
60
|
+
"@types/yargs": "^17.0.17",
|
|
61
|
+
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
62
62
|
"coveralls": "^3.1.0",
|
|
63
63
|
"cross-env": "^7.0.3",
|
|
64
|
-
"eslint": "^8.
|
|
64
|
+
"eslint": "^8.30.0",
|
|
65
65
|
"husky": "^8.0.2",
|
|
66
66
|
"jest": "^27.5.1",
|
|
67
67
|
"rimraf": "^3.0.2",
|
|
68
|
-
"rollup": "^3.5
|
|
68
|
+
"rollup": "^3.7.5",
|
|
69
69
|
"semantic-release": "^19.0.5",
|
|
70
70
|
"ts-jest": "^27.1.4",
|
|
71
71
|
"ts-node": "^10.9.1",
|
|
72
|
-
"typescript": "^4.9.
|
|
72
|
+
"typescript": "^4.9.4"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
+
"ebec": "^0.1.0",
|
|
75
76
|
"glob": "^8.0.3"
|
|
76
77
|
},
|
|
77
78
|
"config": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
|