locter 1.0.11 → 1.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/README.MD +1 -0
- package/dist/index.cjs +86 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +85 -8
- package/dist/index.mjs.map +1 -1
- package/dist/loader/built-in/conf/index.d.ts +1 -0
- package/dist/loader/built-in/conf/module.d.ts +6 -0
- package/dist/loader/built-in/index.d.ts +1 -0
- package/dist/loader/constants.d.ts +2 -1
- package/dist/utils/object.d.ts +1 -0
- package/package.json +4 -1
package/README.MD
CHANGED
|
@@ -152,6 +152,7 @@ import { loadSync, locateSync } from 'locter';
|
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
Two loaders are predefined from scratch and already registered:
|
|
155
|
+
- **ConfLoader**: This loader allows to load `.conf` files.
|
|
155
156
|
- **JsonLoader**: This loader allows to load `.json` files.
|
|
156
157
|
- **ModuleLoader**: This loader allows to load modules with
|
|
157
158
|
`.js`, `.mjs`, `.mts`, `.cjs`, `.cts`, `.ts` file extensions independent of the environment (cjs or esm).
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var destr = require('destr');
|
|
4
|
+
var flat = require('flat');
|
|
5
|
+
var fs = require('node:fs');
|
|
6
|
+
var glob = require('glob');
|
|
7
|
+
var path = require('node:path');
|
|
3
8
|
var ebec = require('ebec');
|
|
4
9
|
var createJITI = require('jiti');
|
|
5
10
|
var node_url = require('node:url');
|
|
6
|
-
var glob = require('glob');
|
|
7
|
-
var path = require('node:path');
|
|
8
|
-
var fs = require('node:fs');
|
|
9
11
|
|
|
10
12
|
function hasOwnProperty(obj, prop) {
|
|
11
13
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -22,6 +24,9 @@ function hasStringProperty(obj, prop) {
|
|
|
22
24
|
*/ function isObject(item) {
|
|
23
25
|
return !!item && typeof item === 'object' && !Array.isArray(item);
|
|
24
26
|
}
|
|
27
|
+
function isSafeObjectKey(key) {
|
|
28
|
+
return key !== '__proto__' && key !== 'prototype' && key !== 'constructor';
|
|
29
|
+
}
|
|
25
30
|
|
|
26
31
|
function handleException(e) {
|
|
27
32
|
if (e instanceof Error) {
|
|
@@ -201,6 +206,62 @@ function locateSync(pattern, options) {
|
|
|
201
206
|
return undefined;
|
|
202
207
|
}
|
|
203
208
|
|
|
209
|
+
/*
|
|
210
|
+
* Copyright (c) 2022-2023.
|
|
211
|
+
* Author Peter Placzek (tada5hi)
|
|
212
|
+
* For the full copyright and license information,
|
|
213
|
+
* view the LICENSE file that was distributed with this source code.
|
|
214
|
+
*/ // Based on https://github.com/unjs/rc9 (MIT)
|
|
215
|
+
class ConfLoader {
|
|
216
|
+
async execute(input) {
|
|
217
|
+
const filePath = buildFilePath(input);
|
|
218
|
+
try {
|
|
219
|
+
const file = await fs.promises.readFile(filePath, {
|
|
220
|
+
encoding: 'utf-8'
|
|
221
|
+
});
|
|
222
|
+
return this.parse(file);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
return handleException(e);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
executeSync(input) {
|
|
228
|
+
const filePath = buildFilePath(input);
|
|
229
|
+
try {
|
|
230
|
+
const file = fs.readFileSync(filePath, {
|
|
231
|
+
encoding: 'utf-8'
|
|
232
|
+
});
|
|
233
|
+
return this.parse(file);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
return handleException(e);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
parse(contents) {
|
|
239
|
+
const config = {};
|
|
240
|
+
const lines = contents.split(/\n|\r|\r\n/);
|
|
241
|
+
for(let i = 0; i < lines.length; i++){
|
|
242
|
+
const match = lines[i].match(/^\s*([^\s=]+)\s*=\s*(.*)?\s*$/);
|
|
243
|
+
if (!match) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
// Key
|
|
247
|
+
const key = match[1];
|
|
248
|
+
if (!key || !isSafeObjectKey(key)) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const value = destr(match[2].trim());
|
|
252
|
+
if (key.endsWith('[]')) {
|
|
253
|
+
const arrKey = key.slice(0, Math.max(0, key.length - 2));
|
|
254
|
+
config[arrKey] = (config[arrKey] || []).concat(value);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
config[key] = value;
|
|
258
|
+
}
|
|
259
|
+
return flat.unflatten(config, {
|
|
260
|
+
overwrite: true
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
204
265
|
function isJestRuntimeEnvironment() {
|
|
205
266
|
return process.env && process.env.JEST_WORKER_ID !== undefined;
|
|
206
267
|
}
|
|
@@ -371,8 +432,10 @@ class JSONLoader {
|
|
|
371
432
|
async execute(input) {
|
|
372
433
|
const filePath = buildFilePath(input);
|
|
373
434
|
try {
|
|
374
|
-
const file = await fs.promises.readFile(filePath
|
|
375
|
-
|
|
435
|
+
const file = await fs.promises.readFile(filePath, {
|
|
436
|
+
encoding: 'utf-8'
|
|
437
|
+
});
|
|
438
|
+
return JSON.parse(file);
|
|
376
439
|
} catch (e) {
|
|
377
440
|
return handleException(e);
|
|
378
441
|
}
|
|
@@ -380,8 +443,10 @@ class JSONLoader {
|
|
|
380
443
|
executeSync(input) {
|
|
381
444
|
const filePath = buildFilePath(input);
|
|
382
445
|
try {
|
|
383
|
-
const file = fs.readFileSync(filePath
|
|
384
|
-
|
|
446
|
+
const file = fs.readFileSync(filePath, {
|
|
447
|
+
encoding: 'utf-8'
|
|
448
|
+
});
|
|
449
|
+
return JSON.parse(file);
|
|
385
450
|
} catch (e) {
|
|
386
451
|
return handleException(e);
|
|
387
452
|
}
|
|
@@ -397,6 +462,7 @@ class JSONLoader {
|
|
|
397
462
|
(function(LoaderId) {
|
|
398
463
|
LoaderId["MODULE"] = 'module';
|
|
399
464
|
LoaderId["JSON"] = 'json';
|
|
465
|
+
LoaderId["CONF"] = 'conf';
|
|
400
466
|
})(LoaderId || (LoaderId = {}));
|
|
401
467
|
|
|
402
468
|
class LoaderManager {
|
|
@@ -459,6 +525,11 @@ class LoaderManager {
|
|
|
459
525
|
let loader;
|
|
460
526
|
// built-in
|
|
461
527
|
switch(id){
|
|
528
|
+
case LoaderId.CONF:
|
|
529
|
+
{
|
|
530
|
+
loader = new ConfLoader();
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
462
533
|
case LoaderId.MODULE:
|
|
463
534
|
{
|
|
464
535
|
loader = new ModuleLoader();
|
|
@@ -509,6 +580,12 @@ class LoaderManager {
|
|
|
509
580
|
],
|
|
510
581
|
loader: LoaderId.MODULE
|
|
511
582
|
},
|
|
583
|
+
{
|
|
584
|
+
test: [
|
|
585
|
+
'.conf'
|
|
586
|
+
],
|
|
587
|
+
loader: LoaderId.CONF
|
|
588
|
+
},
|
|
512
589
|
{
|
|
513
590
|
test: [
|
|
514
591
|
'.json'
|
|
@@ -551,6 +628,7 @@ function loadSync(input) {
|
|
|
551
628
|
return manager.executeSync(buildFilePath(input));
|
|
552
629
|
}
|
|
553
630
|
|
|
631
|
+
exports.ConfLoader = ConfLoader;
|
|
554
632
|
exports.JSONLoader = JSONLoader;
|
|
555
633
|
exports.LoaderManager = LoaderManager;
|
|
556
634
|
exports.ModuleLoader = ModuleLoader;
|
|
@@ -565,6 +643,7 @@ exports.isFilePath = isFilePath;
|
|
|
565
643
|
exports.isJestRuntimeEnvironment = isJestRuntimeEnvironment;
|
|
566
644
|
exports.isLocatorInfo = isLocatorInfo;
|
|
567
645
|
exports.isObject = isObject;
|
|
646
|
+
exports.isSafeObjectKey = isSafeObjectKey;
|
|
568
647
|
exports.isTsNodeRuntimeEnvironment = isTsNodeRuntimeEnvironment;
|
|
569
648
|
exports.load = load;
|
|
570
649
|
exports.loadSync = loadSync;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\n\nexport function isFilePath(input: string) {\n const extension = path.extname(input);\n return extension && extension !== '';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isObject, toArray } from '../utils';\nimport type { LocatorInfo, LocatorOptions } from './type';\n\nexport function buildLocatorOptions(options?: Partial<LocatorOptions>) : LocatorOptions {\n options = options || {};\n\n options.path = options.path || [];\n options.path = toArray(options.path);\n if (options.path.length === 0) {\n options.path.push(process.cwd());\n }\n\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n\nexport function isLocatorInfo(\n input: unknown,\n) : input is LocatorInfo {\n return isObject(input) &&\n typeof input.path === 'string' &&\n typeof input.name === 'string' &&\n typeof input.extension === 'string';\n}\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport { hasOwnProperty, isObject } from '../../../utils';\nimport type { LoaderFilterFn, ModuleExport } from './type';\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n\nexport function getModuleExport(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ModuleExport {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n let value: any;\n\n if (\n hasOwnProperty(data, '__esModule') &&\n // eslint-disable-next-line no-underscore-dangle\n !!data.__esModule &&\n hasOwnProperty(data, 'default')\n ) {\n value = data.default;\n } else {\n value = data;\n }\n\n if (\n isObject(value) &&\n hasOwnProperty(value, 'default')\n ) {\n value = value.default;\n }\n\n return {\n key: 'default',\n value,\n };\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport {\n buildFilePath,\n buildFilePathWithoutExtension,\n isLocatorInfo,\n pathToLocatorInfo,\n} from '../../../locator';\nimport {\n handleException,\n hasStringProperty, isFilePath,\n isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ModuleLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : Promise<unknown> {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n }\n\n return await import(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : unknown {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleException(e);\n }\n }\n\n private build(\n data: LocatorInfo | string,\n options: ModuleLoadOptions,\n ) : [string, LocatorInfo | undefined] {\n let name : string;\n let locatorInfo : LocatorInfo | undefined;\n\n options = options || {};\n\n if (isLocatorInfo(data) || isFilePath(data)) {\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n if (options.withExtension) {\n name = buildFilePath(locatorInfo);\n } else {\n name = buildFilePathWithoutExtension(locatorInfo);\n }\n\n if (options.withFilePrefix) {\n name = pathToFileURL(name).href;\n }\n } else {\n name = data;\n }\n\n return [name, locatorInfo];\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { buildFilePath, pathToLocatorInfo } from '../locator';\nimport { isFilePath } from '../utils';\nimport { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildFilePath } from '../locator';\nimport type { LocatorInfo } from '../locator';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n"],"names":["hasOwnProperty","obj","prop","Object","prototype","call","hasStringProperty","isObject","item","Array","isArray","handleException","e","Error","error","message","stack","removeFileNameExtension","input","extensions","includes","position","lastIndexOf","extension","substring","length","indexOf","toArray","isFilePath","path","extname","buildLocatorOptions","options","push","process","cwd","ignore","pathToLocatorInfo","skipResolve","isAbsolute","resolve","info","parse","dir","split","join","sep","name","ext","isLocatorInfo","buildFilePath","buildFilePathWithoutExtension","locateMany","pattern","patterns","items","i","j","files","glob","absolute","nodir","k","locate","element","shift","undefined","locateManySync","globSync","locateSync","isJestRuntimeEnvironment","env","JEST_WORKER_ID","isTsNodeRuntimeEnvironment","Symbol","for","getModuleExport","data","filterFn","keys","key","value","BaseError","__esModule","default","ModuleLoader","execute","output","load","loadSync","jiti","executeSync","locatorInfo","build","require","withExtension","code","withFilePrefix","pathToFileURL","href","constructor","createJITI","JSONLoader","filePath","file","fs","promises","readFile","JSON","toString","readFileSync","LoaderId","MODULE","LoaderManager","register","test","loader","rules","id","findLoader","loaders","pluginPath","normalizePath","moduleLoader","startsWith","instance","useLoader","registerLoader","manager"],"mappings":";;;;;;;;;AAAO,SAASA,cAAAA,CAAqEC,GAAM,EAAEC,IAAO,EAAiC;AACjI,IAAA,OAAOC,OAAOC,SAAS,CAACJ,cAAc,CAACK,IAAI,CAACJ,GAAKC,EAAAA,IAAAA,CAAAA,CAAAA;AACrD,CAAC;AAEM,SAASI,iBAAAA,CAAwEL,GAAM,EAAEC,IAAO,EAAgC;AACnI,IAAA,OAAOF,eAAeC,GAAKC,EAAAA,IAAAA,CAAAA,IAAS,OAAOD,GAAG,CAACC,KAAK,KAAK,QAAA,CAAA;AAC7D;;ACNA;;;;;AAKC,IAEM,SAASK,QAASC,CAAAA,IAAa,EAAgC;IAClE,OACI,CAAC,CAACA,IACF,IAAA,OAAOA,SAAS,QAChB,IAAA,CAACC,KAAMC,CAAAA,OAAO,CAACF,IAAAA,CAAAA,CAAAA;AAEvB;;ACHO,SAASG,eAAgBC,CAAAA,CAAU,EAAS;AAC/C,IAAA,IAAIA,aAAaC,KAAO,EAAA;AACpB,QAAA,MAAMD,CAAE,CAAA;KACX;IAED,MAAME,KAAAA,GAAQ,IAAID,KAAM,CAAA,mCAAA,CAAA,CAAA;AAExB,IAAA,IAAIN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,CAAQ1C,OAAO,CAACpC,aAAchC,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA;AACzC,CAAC;AAEM,SAASuE,QAASvE,CAAAA,KAA2B,EAAQ;AACxD,IAAA,MAAM8G,OAAUF,GAAAA,SAAAA,EAAAA,CAAAA;IAChB,IAAI,OAAO5G,UAAU,QAAU,EAAA;QAC3B,OAAO8G,OAAAA,CAAQrC,WAAW,CAACzE,KAAAA,CAAAA,CAAAA;KAC9B;IAED,OAAO8G,OAAAA,CAAQrC,WAAW,CAACzC,aAAchC,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA;AAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/conf/module.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n\nexport function isSafeObjectKey(key: string) : boolean {\n return key !== '__proto__' &&\n key !== 'prototype' &&\n key !== 'constructor';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\n\nexport function isFilePath(input: string) {\n const extension = path.extname(input);\n return extension && extension !== '';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isObject, toArray } from '../utils';\nimport type { LocatorInfo, LocatorOptions } from './type';\n\nexport function buildLocatorOptions(options?: Partial<LocatorOptions>) : LocatorOptions {\n options = options || {};\n\n options.path = options.path || [];\n options.path = toArray(options.path);\n if (options.path.length === 0) {\n options.path.push(process.cwd());\n }\n\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n\nexport function isLocatorInfo(\n input: unknown,\n) : input is LocatorInfo {\n return isObject(input) &&\n typeof input.path === 'string' &&\n typeof input.name === 'string' &&\n typeof input.extension === 'string';\n}\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// Based on https://github.com/unjs/rc9 (MIT)\n\nimport destr from 'destr';\nimport flat from 'flat';\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException, isSafeObjectKey } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class ConfLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });\n\n return this.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath, { encoding: 'utf-8' });\n\n return this.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n\n parse(contents: string): Record<string, any> {\n const config: Record<string, any> = {};\n\n const lines = contents.split(/\\n|\\r|\\r\\n/);\n\n for (let i = 0; i < lines.length; i++) {\n const match = lines[i].match(/^\\s*([^\\s=]+)\\s*=\\s*(.*)?\\s*$/);\n if (!match) {\n continue;\n }\n\n // Key\n const key = match[1];\n\n if (!key || !isSafeObjectKey(key)) {\n continue;\n }\n\n const value = destr(match[2].trim() /* val */);\n\n if (key.endsWith('[]')) {\n const arrKey = key.slice(0, Math.max(0, key.length - 2));\n config[arrKey] = (config[arrKey] || []).concat(value);\n continue;\n }\n\n config[key] = value;\n }\n\n return flat.unflatten(config, { overwrite: true });\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport { hasOwnProperty, isObject } from '../../../utils';\nimport type { LoaderFilterFn, ModuleExport } from './type';\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n\nexport function getModuleExport(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ModuleExport {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n let value: any;\n\n if (\n hasOwnProperty(data, '__esModule') &&\n // eslint-disable-next-line no-underscore-dangle\n !!data.__esModule &&\n hasOwnProperty(data, 'default')\n ) {\n value = data.default;\n } else {\n value = data;\n }\n\n if (\n isObject(value) &&\n hasOwnProperty(value, 'default')\n ) {\n value = value.default;\n }\n\n return {\n key: 'default',\n value,\n };\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport {\n buildFilePath,\n buildFilePathWithoutExtension,\n isLocatorInfo,\n pathToLocatorInfo,\n} from '../../../locator';\nimport {\n handleException,\n hasStringProperty, isFilePath,\n isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ModuleLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : Promise<unknown> {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n }\n\n return await import(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : unknown {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleException(e);\n }\n }\n\n private build(\n data: LocatorInfo | string,\n options: ModuleLoadOptions,\n ) : [string, LocatorInfo | undefined] {\n let name : string;\n let locatorInfo : LocatorInfo | undefined;\n\n options = options || {};\n\n if (isLocatorInfo(data) || isFilePath(data)) {\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n if (options.withExtension) {\n name = buildFilePath(locatorInfo);\n } else {\n name = buildFilePathWithoutExtension(locatorInfo);\n }\n\n if (options.withFilePrefix) {\n name = pathToFileURL(name).href;\n }\n } else {\n name = data;\n }\n\n return [name, locatorInfo];\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });\n return JSON.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath, { encoding: 'utf-8' });\n return JSON.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n CONF = 'conf',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { buildFilePath, pathToLocatorInfo } from '../locator';\nimport { isFilePath } from '../utils';\nimport { ConfLoader, JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.conf'], loader: LoaderId.CONF,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.CONF: {\n loader = new ConfLoader();\n break;\n }\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildFilePath } from '../locator';\nimport type { LocatorInfo } from '../locator';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n"],"names":["hasOwnProperty","obj","prop","Object","prototype","call","hasStringProperty","isObject","item","Array","isArray","isSafeObjectKey","key","handleException","e","Error","error","message","stack","removeFileNameExtension","input","extensions","includes","position","lastIndexOf","extension","substring","length","indexOf","toArray","isFilePath","path","extname","buildLocatorOptions","options","push","process","cwd","ignore","pathToLocatorInfo","skipResolve","isAbsolute","resolve","info","parse","dir","split","join","sep","name","ext","isLocatorInfo","buildFilePath","buildFilePathWithoutExtension","locateMany","pattern","patterns","items","i","j","files","glob","absolute","nodir","k","locate","element","shift","undefined","locateManySync","globSync","locateSync","ConfLoader","execute","filePath","file","fs","promises","readFile","encoding","executeSync","readFileSync","contents","config","lines","match","value","destr","trim","endsWith","arrKey","slice","Math","max","concat","flat","unflatten","overwrite","isJestRuntimeEnvironment","env","JEST_WORKER_ID","isTsNodeRuntimeEnvironment","Symbol","for","getModuleExport","data","filterFn","keys","BaseError","__esModule","default","ModuleLoader","output","load","loadSync","jiti","locatorInfo","build","require","withExtension","code","withFilePrefix","pathToFileURL","href","constructor","createJITI","JSONLoader","JSON","LoaderId","MODULE","CONF","LoaderManager","register","test","loader","rules","id","findLoader","loaders","pluginPath","normalizePath","moduleLoader","startsWith","instance","useLoader","registerLoader","manager"],"mappings":";;;;;;;;;;;AAAO,SAASA,cAAAA,CAAqEC,GAAM,EAAEC,IAAO,EAAiC;AACjI,IAAA,OAAOC,OAAOC,SAAS,CAACJ,cAAc,CAACK,IAAI,CAACJ,GAAKC,EAAAA,IAAAA,CAAAA,CAAAA;AACrD,CAAC;AAEM,SAASI,iBAAAA,CAAwEL,GAAM,EAAEC,IAAO,EAAgC;AACnI,IAAA,OAAOF,eAAeC,GAAKC,EA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A,GAAW,IAAIZ,aAAAA,EAAAA,CAAAA;IAEf,OAAOY,QAAAA,CAAAA;AACX;;ACJO,SAASE,cAAAA,CAAeZ,IAAS,EAAEC,MAAe,EAAS;AAC9D,IAAA,MAAMY,OAAUF,GAAAA,SAAAA,EAAAA,CAAAA;IAChB,IAAI,OAAOV,WAAW,WAAa,EAAA;QAC/BY,OAAQd,CAAAA,QAAQ,CAACC,IAAMC,EAAAA,MAAAA,CAAAA,CAAAA;AAEvB,QAAA,OAAA;KACH;AAEDY,IAAAA,OAAAA,CAAQd,QAAQ,CAACC,IAAAA,CAAAA,CAAAA;AACrB,CAAC;AAEM,eAAepB,IAAK7F,CAAAA,KAA2B,EAAiB;AACnE,IAAA,MAAM8H,OAAUF,GAAAA,SAAAA,EAAAA,CAAAA;IAChB,IAAI,OAAO5H,UAAU,QAAU,EAAA;QAC3B,OAAO8H,OAAAA,CAAQzE,OAAO,CAACrD,KAAAA,CAAAA,CAAAA;KAC1B;IAED,OAAO8H,OAAAA,CAAQzE,OAAO,CAACrB,aAAchC,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA;AACzC,CAAC;AAEM,SAAS8F,QAAS9F,CAAAA,KAA2B,EAAQ;AACxD,IAAA,MAAM8H,OAAUF,GAAAA,SAAAA,EAAAA,CAAAA;IAChB,IAAI,OAAO5H,UAAU,QAAU,EAAA;QAC3B,OAAO8H,OAAAA,CAAQlE,WAAW,CAAC5D,KAAAA,CAAAA,CAAAA;KAC9B;IAED,OAAO8H,OAAAA,CAAQlE,WAAW,CAAC5B,aAAchC,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA;AAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import destr from 'destr';
|
|
2
|
+
import flat from 'flat';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { glob, globSync } from 'glob';
|
|
5
|
+
import path from 'node:path';
|
|
1
6
|
import { BaseError } from 'ebec';
|
|
2
7
|
import createJITI from 'jiti';
|
|
3
8
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { glob, globSync } from 'glob';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
import __cjs_url__ from 'url';
|
|
@@ -27,6 +29,9 @@ function hasStringProperty(obj, prop) {
|
|
|
27
29
|
*/ function isObject(item) {
|
|
28
30
|
return !!item && typeof item === 'object' && !Array.isArray(item);
|
|
29
31
|
}
|
|
32
|
+
function isSafeObjectKey(key) {
|
|
33
|
+
return key !== '__proto__' && key !== 'prototype' && key !== 'constructor';
|
|
34
|
+
}
|
|
30
35
|
|
|
31
36
|
function handleException(e) {
|
|
32
37
|
if (e instanceof Error) {
|
|
@@ -206,6 +211,62 @@ function locateSync(pattern, options) {
|
|
|
206
211
|
return undefined;
|
|
207
212
|
}
|
|
208
213
|
|
|
214
|
+
/*
|
|
215
|
+
* Copyright (c) 2022-2023.
|
|
216
|
+
* Author Peter Placzek (tada5hi)
|
|
217
|
+
* For the full copyright and license information,
|
|
218
|
+
* view the LICENSE file that was distributed with this source code.
|
|
219
|
+
*/ // Based on https://github.com/unjs/rc9 (MIT)
|
|
220
|
+
class ConfLoader {
|
|
221
|
+
async execute(input) {
|
|
222
|
+
const filePath = buildFilePath(input);
|
|
223
|
+
try {
|
|
224
|
+
const file = await fs.promises.readFile(filePath, {
|
|
225
|
+
encoding: 'utf-8'
|
|
226
|
+
});
|
|
227
|
+
return this.parse(file);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
return handleException(e);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
executeSync(input) {
|
|
233
|
+
const filePath = buildFilePath(input);
|
|
234
|
+
try {
|
|
235
|
+
const file = fs.readFileSync(filePath, {
|
|
236
|
+
encoding: 'utf-8'
|
|
237
|
+
});
|
|
238
|
+
return this.parse(file);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
return handleException(e);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
parse(contents) {
|
|
244
|
+
const config = {};
|
|
245
|
+
const lines = contents.split(/\n|\r|\r\n/);
|
|
246
|
+
for(let i = 0; i < lines.length; i++){
|
|
247
|
+
const match = lines[i].match(/^\s*([^\s=]+)\s*=\s*(.*)?\s*$/);
|
|
248
|
+
if (!match) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
// Key
|
|
252
|
+
const key = match[1];
|
|
253
|
+
if (!key || !isSafeObjectKey(key)) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const value = destr(match[2].trim());
|
|
257
|
+
if (key.endsWith('[]')) {
|
|
258
|
+
const arrKey = key.slice(0, Math.max(0, key.length - 2));
|
|
259
|
+
config[arrKey] = (config[arrKey] || []).concat(value);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
config[key] = value;
|
|
263
|
+
}
|
|
264
|
+
return flat.unflatten(config, {
|
|
265
|
+
overwrite: true
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
209
270
|
function isJestRuntimeEnvironment() {
|
|
210
271
|
return process.env && process.env.JEST_WORKER_ID !== undefined;
|
|
211
272
|
}
|
|
@@ -376,8 +437,10 @@ class JSONLoader {
|
|
|
376
437
|
async execute(input) {
|
|
377
438
|
const filePath = buildFilePath(input);
|
|
378
439
|
try {
|
|
379
|
-
const file = await fs.promises.readFile(filePath
|
|
380
|
-
|
|
440
|
+
const file = await fs.promises.readFile(filePath, {
|
|
441
|
+
encoding: 'utf-8'
|
|
442
|
+
});
|
|
443
|
+
return JSON.parse(file);
|
|
381
444
|
} catch (e) {
|
|
382
445
|
return handleException(e);
|
|
383
446
|
}
|
|
@@ -385,8 +448,10 @@ class JSONLoader {
|
|
|
385
448
|
executeSync(input) {
|
|
386
449
|
const filePath = buildFilePath(input);
|
|
387
450
|
try {
|
|
388
|
-
const file = fs.readFileSync(filePath
|
|
389
|
-
|
|
451
|
+
const file = fs.readFileSync(filePath, {
|
|
452
|
+
encoding: 'utf-8'
|
|
453
|
+
});
|
|
454
|
+
return JSON.parse(file);
|
|
390
455
|
} catch (e) {
|
|
391
456
|
return handleException(e);
|
|
392
457
|
}
|
|
@@ -402,6 +467,7 @@ class JSONLoader {
|
|
|
402
467
|
(function(LoaderId) {
|
|
403
468
|
LoaderId["MODULE"] = 'module';
|
|
404
469
|
LoaderId["JSON"] = 'json';
|
|
470
|
+
LoaderId["CONF"] = 'conf';
|
|
405
471
|
})(LoaderId || (LoaderId = {}));
|
|
406
472
|
|
|
407
473
|
class LoaderManager {
|
|
@@ -464,6 +530,11 @@ class LoaderManager {
|
|
|
464
530
|
let loader;
|
|
465
531
|
// built-in
|
|
466
532
|
switch(id){
|
|
533
|
+
case LoaderId.CONF:
|
|
534
|
+
{
|
|
535
|
+
loader = new ConfLoader();
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
467
538
|
case LoaderId.MODULE:
|
|
468
539
|
{
|
|
469
540
|
loader = new ModuleLoader();
|
|
@@ -514,6 +585,12 @@ class LoaderManager {
|
|
|
514
585
|
],
|
|
515
586
|
loader: LoaderId.MODULE
|
|
516
587
|
},
|
|
588
|
+
{
|
|
589
|
+
test: [
|
|
590
|
+
'.conf'
|
|
591
|
+
],
|
|
592
|
+
loader: LoaderId.CONF
|
|
593
|
+
},
|
|
517
594
|
{
|
|
518
595
|
test: [
|
|
519
596
|
'.json'
|
|
@@ -556,5 +633,5 @@ function loadSync(input) {
|
|
|
556
633
|
return manager.executeSync(buildFilePath(input));
|
|
557
634
|
}
|
|
558
635
|
|
|
559
|
-
export { JSONLoader, LoaderManager, ModuleLoader, buildFilePath, buildFilePathWithoutExtension, buildLocatorOptions, getModuleExport, handleException, hasOwnProperty, hasStringProperty, isFilePath, isJestRuntimeEnvironment, isLocatorInfo, isObject, isTsNodeRuntimeEnvironment, load, loadSync, locate, locateMany, locateManySync, locateSync, pathToLocatorInfo, registerLoader, removeFileNameExtension, toArray };
|
|
636
|
+
export { ConfLoader, JSONLoader, LoaderManager, ModuleLoader, buildFilePath, buildFilePathWithoutExtension, buildLocatorOptions, getModuleExport, handleException, hasOwnProperty, hasStringProperty, isFilePath, isJestRuntimeEnvironment, isLocatorInfo, isObject, isSafeObjectKey, isTsNodeRuntimeEnvironment, load, loadSync, locate, locateMany, locateManySync, locateSync, pathToLocatorInfo, registerLoader, removeFileNameExtension, toArray };
|
|
560
637
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\n\nexport function isFilePath(input: string) {\n const extension = path.extname(input);\n return extension && extension !== '';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isObject, toArray } from '../utils';\nimport type { LocatorInfo, LocatorOptions } from './type';\n\nexport function buildLocatorOptions(options?: Partial<LocatorOptions>) : LocatorOptions {\n options = options || {};\n\n options.path = options.path || [];\n options.path = toArray(options.path);\n if (options.path.length === 0) {\n options.path.push(process.cwd());\n }\n\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n\nexport function isLocatorInfo(\n input: unknown,\n) : input is LocatorInfo {\n return isObject(input) &&\n typeof input.path === 'string' &&\n typeof input.name === 'string' &&\n typeof input.extension === 'string';\n}\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport { hasOwnProperty, isObject } from '../../../utils';\nimport type { LoaderFilterFn, ModuleExport } from './type';\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n\nexport function getModuleExport(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ModuleExport {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n let value: any;\n\n if (\n hasOwnProperty(data, '__esModule') &&\n // eslint-disable-next-line no-underscore-dangle\n !!data.__esModule &&\n hasOwnProperty(data, 'default')\n ) {\n value = data.default;\n } else {\n value = data;\n }\n\n if (\n isObject(value) &&\n hasOwnProperty(value, 'default')\n ) {\n value = value.default;\n }\n\n return {\n key: 'default',\n value,\n };\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport {\n buildFilePath,\n buildFilePathWithoutExtension,\n isLocatorInfo,\n pathToLocatorInfo,\n} from '../../../locator';\nimport {\n handleException,\n hasStringProperty, isFilePath,\n isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ModuleLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : Promise<unknown> {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n }\n\n return await import(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : unknown {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleException(e);\n }\n }\n\n private build(\n data: LocatorInfo | string,\n options: ModuleLoadOptions,\n ) : [string, LocatorInfo | undefined] {\n let name : string;\n let locatorInfo : LocatorInfo | undefined;\n\n options = options || {};\n\n if (isLocatorInfo(data) || isFilePath(data)) {\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n if (options.withExtension) {\n name = buildFilePath(locatorInfo);\n } else {\n name = buildFilePathWithoutExtension(locatorInfo);\n }\n\n if (options.withFilePrefix) {\n name = pathToFileURL(name).href;\n }\n } else {\n name = data;\n }\n\n return [name, locatorInfo];\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { buildFilePath, pathToLocatorInfo } from '../locator';\nimport { isFilePath } from '../utils';\nimport { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildFilePath } from '../locator';\nimport type { LocatorInfo } from '../locator';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n"],"names":["input","options","name","extension","info","pattern","absolute","cwd","nodir","ignore","items","value","output","executeSync","withExtension","withFilePrefix","code","message","stack","locatorInfo","LoaderId","test","loader","findLoader","instance","manager"],"mappings":";;;;;;;;;;;;;;AAAO;AACH;AACJ;AAEO;AACH;AACJ;;ACNA;;;;;AAKC;;AAQD;;ACHO;AACH;AACI;;;AAKJ;AACI;;;AAOA;;;;AAQJ;AACJ;;AClCA;;;;;AAKC;;;AAQO;;;;;;AAcR;;AC3BA;;;;;AAKC;AAGG;AAAuCA;AAAM;AACjD;;ACDO;;AAEH;AACJ;;ACAO;AASHC;AARAA;AAEAA;AACAA;AACA;AACIA;;AAGJA;;AAGJ;AAEO;AAIH;AAIID;;;;;AAOAE;AACAC;AACJ;AACJ;AAEO;AAGH;AAIJ;AAEO;;;;;;;AASH;AACJ;AAEO;;;AAICC;;;;AAKJ;AACJ;;ACjEO;AAIHH;AAEA;AAEKI;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHT;AAEA;AAEKI;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;AACJ;;AAGJ;;ACzDO;AAIHR;AAEA;AAEKI;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHT;AAEA;AAEKI;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;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AACpDA;AACJ;AACA;;AACW;AAAQ;AAAEA;AACrB;AACH;AACL;AAsHJ;;AC3IA;AACO;;;;AAKHE;;AAGJ;;ACJO;AACH;;;AAII;;AAGJC;AACJ;AAEO;AACH;;;;;AAMJ;AAEO;AACH;;;;;AAMJ;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/conf/module.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n\nexport function isSafeObjectKey(key: string) : boolean {\n return key !== '__proto__' &&\n key !== 'prototype' &&\n key !== 'constructor';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\n\nexport function isFilePath(input: string) {\n const extension = path.extname(input);\n return extension && extension !== '';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isObject, toArray } from '../utils';\nimport type { LocatorInfo, LocatorOptions } from './type';\n\nexport function buildLocatorOptions(options?: Partial<LocatorOptions>) : LocatorOptions {\n options = options || {};\n\n options.path = options.path || [];\n options.path = toArray(options.path);\n if (options.path.length === 0) {\n options.path.push(process.cwd());\n }\n\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n\nexport function isLocatorInfo(\n input: unknown,\n) : input is LocatorInfo {\n return isObject(input) &&\n typeof input.path === 'string' &&\n typeof input.name === 'string' &&\n typeof input.extension === 'string';\n}\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// Based on https://github.com/unjs/rc9 (MIT)\n\nimport destr from 'destr';\nimport flat from 'flat';\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException, isSafeObjectKey } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class ConfLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });\n\n return this.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath, { encoding: 'utf-8' });\n\n return this.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n\n parse(contents: string): Record<string, any> {\n const config: Record<string, any> = {};\n\n const lines = contents.split(/\\n|\\r|\\r\\n/);\n\n for (let i = 0; i < lines.length; i++) {\n const match = lines[i].match(/^\\s*([^\\s=]+)\\s*=\\s*(.*)?\\s*$/);\n if (!match) {\n continue;\n }\n\n // Key\n const key = match[1];\n\n if (!key || !isSafeObjectKey(key)) {\n continue;\n }\n\n const value = destr(match[2].trim() /* val */);\n\n if (key.endsWith('[]')) {\n const arrKey = key.slice(0, Math.max(0, key.length - 2));\n config[arrKey] = (config[arrKey] || []).concat(value);\n continue;\n }\n\n config[key] = value;\n }\n\n return flat.unflatten(config, { overwrite: true });\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport { hasOwnProperty, isObject } from '../../../utils';\nimport type { LoaderFilterFn, ModuleExport } from './type';\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n\nexport function getModuleExport(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ModuleExport {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n let value: any;\n\n if (\n hasOwnProperty(data, '__esModule') &&\n // eslint-disable-next-line no-underscore-dangle\n !!data.__esModule &&\n hasOwnProperty(data, 'default')\n ) {\n value = data.default;\n } else {\n value = data;\n }\n\n if (\n isObject(value) &&\n hasOwnProperty(value, 'default')\n ) {\n value = value.default;\n }\n\n return {\n key: 'default',\n value,\n };\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport {\n buildFilePath,\n buildFilePathWithoutExtension,\n isLocatorInfo,\n pathToLocatorInfo,\n} from '../../../locator';\nimport {\n handleException,\n hasStringProperty, isFilePath,\n isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ModuleLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : Promise<unknown> {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n }\n\n return await import(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : unknown {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleException(e);\n }\n }\n\n private build(\n data: LocatorInfo | string,\n options: ModuleLoadOptions,\n ) : [string, LocatorInfo | undefined] {\n let name : string;\n let locatorInfo : LocatorInfo | undefined;\n\n options = options || {};\n\n if (isLocatorInfo(data) || isFilePath(data)) {\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n if (options.withExtension) {\n name = buildFilePath(locatorInfo);\n } else {\n name = buildFilePathWithoutExtension(locatorInfo);\n }\n\n if (options.withFilePrefix) {\n name = pathToFileURL(name).href;\n }\n } else {\n name = data;\n }\n\n return [name, locatorInfo];\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });\n return JSON.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath, { encoding: 'utf-8' });\n return JSON.parse(file);\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n CONF = 'conf',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { buildFilePath, pathToLocatorInfo } from '../locator';\nimport { isFilePath } from '../utils';\nimport { ConfLoader, JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.conf'], loader: LoaderId.CONF,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.CONF: {\n loader = new ConfLoader();\n break;\n }\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildFilePath } from '../locator';\nimport type { LocatorInfo } from '../locator';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n"],"names":["input","options","name","extension","info","pattern","absolute","cwd","nodir","ignore","items","executeSync","parse","config","overwrite","value","output","withExtension","withFilePrefix","code","message","stack","locatorInfo","LoaderId","test","loader","findLoader","instance","manager"],"mappings":";;;;;;;;;;;;;;;;AAAO;AACH;AACJ;AAEO;AACH;AACJ;;ACNA;;;;;AAKC;;AAQD;AAEO;AACH;AAGJ;;ACTO;AACH;AACI;;;AAKJ;AACI;;;AAOA;;;;AAQJ;AACJ;;AClCA;;;;;AAKC;;;AAQO;;;;;;AAcR;;AC3BA;;;;;AAKC;AAGG;AAAuCA;AAAM;AACjD;;ACDO;;AAEH;AACJ;;ACAO;AASHC;AARAA;AAEAA;AACAA;AACA;AACIA;;AAGJA;;AAGJ;AAEO;AAIH;AAIID;;;;;AAOAE;AACAC;AACJ;AACJ;AAEO;AAGH;AAIJ;AAEO;;;;;;;AASH;AACJ;AAEO;;;AAICC;;;;AAKJ;AACJ;;ACjEO;AAIHH;AAEA;AAEKI;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHT;AAEA;AAEKI;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;AACJ;;AAGJ;;ACzDO;AAIHR;AAEA;AAEKI;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHT;AAEA;AAEKI;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;AACJ;;AAGJ;;ACpEA;;;;;AAKC;AAWM;;AAEC;;AAGI;;AAAsE;;AAG1E;AACI;AACJ;AACJ;AAEAE;AACI;;AAGI;;AAA2D;;AAG/D;AACI;AACJ;AACJ;AAEAC;AACI;;AAIA;AACI;AACA;;;;;AAOA;;;AAIA;;;AAIIC;;;;AAKR;;AAEgCC;AAAgB;AACpD;AACJ;;AC7DO;AACH;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;AAAQ;AAAQ;AAAM;AACpDA;AACJ;AACA;;AACW;AAAQ;AAAEA;AACrB;AACA;;AACW;AAAQ;AAAEA;AACrB;AACH;AACL;AA0HJ;;AClJA;AACO;;;;AAKHE;;AAGJ;;ACJO;AACH;;;AAII;;AAGJC;AACJ;AAEO;AACH;;;;;AAMJ;AAEO;AACH;;;;;AAMJ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './module';
|
package/dist/utils/object.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locter",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A library to locate a file/module by criteria and load it!",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Placzek",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@tada5hi/commitlint-config": "^1.0.0",
|
|
63
63
|
"@tada5hi/eslint-config-typescript": "^1.1.5",
|
|
64
64
|
"@tada5hi/tsconfig": "^0.4.0",
|
|
65
|
+
"@types/flat": "^5.0.2",
|
|
65
66
|
"@types/jest": "^27.5.2",
|
|
66
67
|
"@types/node": "^18.15.7",
|
|
67
68
|
"cross-env": "^7.0.3",
|
|
@@ -77,7 +78,9 @@
|
|
|
77
78
|
"typescript": "^5.0.2"
|
|
78
79
|
},
|
|
79
80
|
"dependencies": {
|
|
81
|
+
"destr": "^1.2.2",
|
|
80
82
|
"ebec": "^1.0.0",
|
|
83
|
+
"flat": "^5.0.2",
|
|
81
84
|
"glob": "^9.3.2",
|
|
82
85
|
"jiti": "^1.18.2"
|
|
83
86
|
}
|