locter 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +34 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +34 -20
- package/dist/index.mjs.map +1 -1
- package/dist/loader/built-in/script/utils.d.ts +1 -2
- package/dist/loader/utils.d.ts +2 -0
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -191,6 +191,33 @@ function buildLoaderFilePath(info, withExtension) {
|
|
|
191
191
|
}
|
|
192
192
|
return path.join(info.path, info.name);
|
|
193
193
|
}
|
|
194
|
+
function getExportItem(data, filterFn) {
|
|
195
|
+
if (filterFn) {
|
|
196
|
+
const keys = Object.keys(data);
|
|
197
|
+
for(let i = 0; i < keys.length; i++){
|
|
198
|
+
if (filterFn(keys[i], data[keys[i]])) {
|
|
199
|
+
return {
|
|
200
|
+
key: keys[i],
|
|
201
|
+
value: data[keys[i]]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
throw new ebec.BaseError('Cannot find specific module export.');
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
key: 'default',
|
|
209
|
+
value: hasOwnProperty(data, 'default') ? data.default : data
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/*
|
|
214
|
+
* Copyright (c) 2022.
|
|
215
|
+
* Author Peter Placzek (tada5hi)
|
|
216
|
+
* For the full copyright and license information,
|
|
217
|
+
* view the LICENSE file that was distributed with this source code.
|
|
218
|
+
*/ function isJestEnvironment() {
|
|
219
|
+
return process.env && process.env.JEST_WORKER_ID !== undefined;
|
|
220
|
+
}
|
|
194
221
|
|
|
195
222
|
class ScriptLoader {
|
|
196
223
|
async execute(info) {
|
|
@@ -227,6 +254,12 @@ class ScriptLoader {
|
|
|
227
254
|
filePath = node_url.pathToFileURL(filePath).href;
|
|
228
255
|
}
|
|
229
256
|
try {
|
|
257
|
+
// segmentation fault
|
|
258
|
+
// issue: https://github.com/nodejs/node/issues/35889
|
|
259
|
+
if (isJestEnvironment()) {
|
|
260
|
+
// eslint-disable-next-line global-require,import/no-dynamic-require
|
|
261
|
+
return require(filePath);
|
|
262
|
+
}
|
|
230
263
|
return await import(filePath);
|
|
231
264
|
} catch (e) {
|
|
232
265
|
/* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
|
|
@@ -297,25 +330,6 @@ class ScriptLoader {
|
|
|
297
330
|
}
|
|
298
331
|
}
|
|
299
332
|
|
|
300
|
-
function getExportItem(data, filterFn) {
|
|
301
|
-
if (filterFn) {
|
|
302
|
-
const keys = Object.keys(data);
|
|
303
|
-
for(let i = 0; i < keys.length; i++){
|
|
304
|
-
if (filterFn(keys[i], data[keys[i]])) {
|
|
305
|
-
return {
|
|
306
|
-
key: keys[i],
|
|
307
|
-
value: data[keys[i]]
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
throw new ebec.BaseError('Cannot find specific module export.');
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
key: 'default',
|
|
315
|
-
value: hasOwnProperty(data, 'default') ? data.default : data
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
|
|
319
333
|
class JSONLoader {
|
|
320
334
|
async execute(input) {
|
|
321
335
|
const filePath = buildLoaderFilePath(input, true);
|
|
@@ -459,6 +473,7 @@ exports.getExportItem = getExportItem;
|
|
|
459
473
|
exports.handleFileLoadError = handleFileLoadError;
|
|
460
474
|
exports.hasOwnProperty = hasOwnProperty;
|
|
461
475
|
exports.hasStringProperty = hasStringProperty;
|
|
476
|
+
exports.isJestEnvironment = isJestEnvironment;
|
|
462
477
|
exports.isObject = isObject;
|
|
463
478
|
exports.loadFile = loadFile;
|
|
464
479
|
exports.loadFileSync = loadFileSync;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/to-array.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/utils.ts","../src/loader/built-in/script/module.ts","../src/loader/built-in/script/utils.ts","../src/loader/built-in/json/module.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["/*\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\n/* istanbul ignore next */\nexport function handleFileLoadError(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n if (typeof e === 'string') {\n throw new Error(e);\n }\n\n throw new Error('Cannot determine file loading 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","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\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [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\nimport path from 'node:path';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { toArray } from '../utils';\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.soft ??= true;\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (!skipResolve && !path.isAbsolute(input)) {\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","/*\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 { promisify } from 'node:util';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nconst globAsync = promisify(glob);\n\nexport async function locateFiles(\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 globAsync(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 locateFile(\n pattern: string | string[],\n options: Partial<LocatorOptions> & { soft: false }\n) : Promise<LocatorInfo>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<any> {\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 globAsync(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 if (!options.soft) {\n throw new Error('The file could not be located.');\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 glob from 'glob';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateFilesSync(\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 = glob.sync(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 locateFileSync(\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 = glob.sync(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 path from 'node:path';\nimport { LocatorInfo } from '../locator';\n\nexport function buildLoaderFilePath(info: LocatorInfo, withExtension?: boolean) {\n if (withExtension) {\n return path.join(info.path, info.name) + info.extension;\n }\n\n return path.join(info.path, info.name);\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 { LocatorInfo, pathToLocatorInfo } from '../../../locator';\nimport { handleFileLoadError, hasStringProperty, isObject } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\nimport { ScriptFileLoadOptions } from './type';\n\nexport class ScriptLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n /*\n const loaderMap : Record<string, ESLoader> = {\n '.mjs': 'js',\n '.js': 'js',\n '.jsx': 'jsx',\n '.ts': 'ts',\n '.tsx': 'tsx',\n };\n */\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n esmResolve: true,\n /*\n transform: (options) => {\n let loader : ESLoader = 'ts';\n if (options.filename) {\n const info = pathToLocatorInfo(options.filename, true);\n if (loaderMap[info.extension]) {\n loader = loaderMap[info.extension] as ESLoader;\n }\n }\n\n return transformSync(options.source, {\n target: 'ES2020',\n jsx: 'transform',\n format: 'cjs',\n loader,\n });\n },\n\n */\n });\n }\n\n async execute(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = await this.load(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n executeSync(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = this.loadSync(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : Promise<unknown> {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n if (options.withFilePrefix) {\n filePath = pathToFileURL(filePath).href;\n }\n\n try {\n return await import(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\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 } from '../../../utils';\nimport { LoaderFilterFn, ScriptFileExportItem } from './type';\n\nexport function getExportItem(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n) : ScriptFileExportItem {\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 return {\n key: 'default',\n value: hasOwnProperty(data, 'default') ? data.default : data,\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 { LocatorInfo } from '../../../locator';\nimport { handleFileLoadError } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\n\nexport class JSONLoader implements Loader {\n async execute(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n\n executeSync(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(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\nimport { LocatorInfo } from '../locator';\nimport { JSONLoader, ScriptLoader } from './built-in';\nimport { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\n\nexport class LoaderManager {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n { test: ['.js', '.mjs', '.cjs', '.ts'], loader: 'script' },\n { test: ['.json'], loader: 'json' },\n ];\n }\n\n register(rule: Rule) {\n this.rules.push(rule);\n }\n\n async execute(info: LocatorInfo) : Promise<any> {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.execute(info);\n }\n\n executeSync(info: LocatorInfo) : any {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.executeSync(info);\n }\n\n findRule(info: LocatorInfo) : Rule | undefined {\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];\n }\n } else if (test.test(buildLoaderFilePath(info))) {\n return this.rules[i];\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 (this.loaders[id]) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n switch (id) {\n case 'script': {\n loader = new ScriptLoader();\n break;\n }\n case 'json': {\n loader = new JSONLoader();\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\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 useLoaderManager() {\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 { LocatorInfo, pathToLocatorInfo } from '../locator';\nimport { useLoaderManager } from './singleton';\n\nexport async function loadFile(input: LocatorInfo | string) : Promise<unknown> {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.execute(info);\n}\n\nexport function loadFileSync(input: LocatorInfo | string) : unknown {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.executeSync(info);\n}\n"],"names":["handleFileLoadError","e","Error","removeFileNameExtension","input","extensions","includes","position","lastIndexOf","extension","substring","length","indexOf","hasOwnProperty","obj","prop","Object","prototype","call","hasStringProperty","isObject","item","Array","isArray","toArray","options","buildLocatorOptions","path","push","process","cwd","soft","ignore","pathToLocatorInfo","skipResolve","isAbsolute","resolve","info","parse","dir","split","join","sep","name","ext","globAsync","promisify","glob","locateFiles","pattern","patterns","items","i","j","files","absolute","nodir","k","locateFile","element","shift","undefined","locateFilesSync","sync","locateFileSync","buildLoaderFilePath","withExtension","ScriptLoader","execute","filePath","output","load","jiti","executeSync","loadSync","data","locatorInfo","withFilePrefix","pathToFileURL","href","code","BaseError","message","stack","require","constructor","createJITI","esmResolve","getExportItem","filterFn","keys","key","value","default","JSONLoader","file","fs","promises","readFile","JSON","toString","readFileSync","LoaderManager","register","rule","rules","findRule","loader","test","id","loaders","instance","useLoaderManager","loadFile","manager","loadFileSync"],"mappings":";;;;;;;;;;AAAA;;;;;AAKC,+BAGM,SAASA,mBAAAA,CAAoBC,CAAU,EAAS;AACnD,IAAA,IAAIA,aAAaC,KAAO,EAAA;AACpB,QAAA,MAAMD,CAAE,CAAA;KACX;IAED,IAAI,OAAOA,MAAM,QAAU,EAAA;QACvB,MAAM,IAAIC,MAAMD,CAAG,CAAA,CAAA;KACtB;IAED,MAAM,IAAIC,MAAM,sCAAwC,CAAA,CAAA;AAC5D;;AClBA;;;;;AAKC,IAEM,SAASC,uBAAAA,CACZC,KAAa,EACbC,UAAqB,EACvB;IACE,IAAID,KAAAA,CAAME,QAAQ,CAAC,GAAM,CAAA,EAAA;QACrB,MAAMC,QAAAA,GAAWH,KAAMI,CAAAA,WAAW,CAAC,GAAA,CAAA,CAAA;AACnC,QAAA,MAAMC,YAAYL,KAAMM,CAAAA,SAAS,CAC7BH,QAAAA,EACAH,MAAMO,MAAM,CAAA,CAAA;QAGhB,IACI,OAAON,eAAe,WACtBA,IAAAA,UAAAA,CAAWO,OAAO,CAACH,SAAAA,CAAAA,KAAe,CAAC,CACrC,EAAA;YACEL,KAAQA,GAAAA,KAAAA,CAAMM,SAAS,CAAC,CAAGH,EAAAA,QAAAA,CAAAA,CAAAA;SAC9B;KACJ;IAED,OAAOH,KAAAA,CAAAA;AACX;;AC3BO,SAASS,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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;AACG,SAASC,gBAAmB,GAAA;IAC/B,IAAI,OAAOD,aAAa,WAAa,EAAA;QACjC,OAAOA,QAAAA,CAAAA;KACV;AAEDA,IAAAA,QAAAA,GAAW,IAAIT,aAAAA,EAAAA,CAAAA;IAEf,OAAOS,QAAAA,CAAAA;AACX;;ACRO,eAAeE,QAAS7G,CAAAA,KAA2B,EAAqB;IAC3E,IAAIiC,IAAAA,CAAAA;IACJ,IAAI,OAAOjC,UAAU,QAAU,EAAA;AAC3BiC,QAAAA,IAAAA,GAAOJ,iBAAkB7B,CAAAA,KAAAA,CAAAA,CAAAA;KACtB,MAAA;QACHiC,IAAOjC,GAAAA,KAAAA,CAAAA;KACV;AAED,IAAA,MAAM8G,OAAUF,GAAAA,gBAAAA,EAAAA,CAAAA;IAEhB,OAAOE,OAAAA,CAAQ9C,OAAO,CAAC/B,IAAAA,CAAAA,CAAAA;AAC3B,CAAC;AAEM,SAAS8E,YAAa/G,CAAAA,KAA2B,EAAY;IAChE,IAAIiC,IAAAA,CAAAA;IACJ,IAAI,OAAOjC,UAAU,QAAU,EAAA;AAC3BiC,QAAAA,IAAAA,GAAOJ,iBAAkB7B,CAAAA,KAAAA,CAAAA,CAAAA;KACtB,MAAA;QACHiC,IAAOjC,GAAAA,KAAAA,CAAAA;KACV;AAED,IAAA,MAAM8G,OAAUF,GAAAA,gBAAAA,EAAAA,CAAAA;IAEhB,OAAOE,OAAAA,CAAQzC,WAAW,CAACpC,IAAAA,CAAAA,CAAAA;AAC/B;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/to-array.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/utils.ts","../src/loader/built-in/script/utils.ts","../src/loader/built-in/script/module.ts","../src/loader/built-in/json/module.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["/*\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\n/* istanbul ignore next */\nexport function handleFileLoadError(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n if (typeof e === 'string') {\n throw new Error(e);\n }\n\n throw new Error('Cannot determine file loading 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","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\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [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\nimport path from 'node:path';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { toArray } from '../utils';\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.soft ??= true;\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (!skipResolve && !path.isAbsolute(input)) {\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","/*\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 { promisify } from 'node:util';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nconst globAsync = promisify(glob);\n\nexport async function locateFiles(\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 globAsync(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 locateFile(\n pattern: string | string[],\n options: Partial<LocatorOptions> & { soft: false }\n) : Promise<LocatorInfo>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<any> {\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 globAsync(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 if (!options.soft) {\n throw new Error('The file could not be located.');\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 glob from 'glob';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateFilesSync(\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 = glob.sync(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 locateFileSync(\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 = glob.sync(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 path from 'node:path';\nimport { LocatorInfo } from '../locator';\nimport { hasOwnProperty } from '../utils';\nimport { LoaderFilterFn, ScriptFileExportItem } from './built-in';\n\nexport function buildLoaderFilePath(info: LocatorInfo, withExtension?: boolean) {\n if (withExtension) {\n return path.join(info.path, info.name) + info.extension;\n }\n\n return path.join(info.path, info.name);\n}\n\nexport function getExportItem(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ScriptFileExportItem {\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 return {\n key: 'default',\n value: hasOwnProperty(data, 'default') ? data.default : data,\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\nexport function isJestEnvironment() {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\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 { LocatorInfo, pathToLocatorInfo } from '../../../locator';\nimport { handleFileLoadError, hasStringProperty, isObject } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\nimport { ScriptFileLoadOptions } from './type';\nimport { isJestEnvironment } from './utils';\n\nexport class ScriptLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n /*\n const loaderMap : Record<string, ESLoader> = {\n '.mjs': 'js',\n '.js': 'js',\n '.jsx': 'jsx',\n '.ts': 'ts',\n '.tsx': 'tsx',\n };\n */\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n esmResolve: true,\n /*\n transform: (options) => {\n let loader : ESLoader = 'ts';\n if (options.filename) {\n const info = pathToLocatorInfo(options.filename, true);\n if (loaderMap[info.extension]) {\n loader = loaderMap[info.extension] as ESLoader;\n }\n }\n\n return transformSync(options.source, {\n target: 'ES2020',\n jsx: 'transform',\n format: 'cjs',\n loader,\n });\n },\n\n */\n });\n }\n\n async execute(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = await this.load(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n executeSync(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = this.loadSync(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : Promise<unknown> {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n if (options.withFilePrefix) {\n filePath = pathToFileURL(filePath).href;\n }\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n }\n\n return await import(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\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 { LocatorInfo } from '../../../locator';\nimport { handleFileLoadError } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\n\nexport class JSONLoader implements Loader {\n async execute(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n\n executeSync(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(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\nimport { LocatorInfo } from '../locator';\nimport { JSONLoader, ScriptLoader } from './built-in';\nimport { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\n\nexport class LoaderManager {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n { test: ['.js', '.mjs', '.cjs', '.ts'], loader: 'script' },\n { test: ['.json'], loader: 'json' },\n ];\n }\n\n register(rule: Rule) {\n this.rules.push(rule);\n }\n\n async execute(info: LocatorInfo) : Promise<any> {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.execute(info);\n }\n\n executeSync(info: LocatorInfo) : any {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.executeSync(info);\n }\n\n findRule(info: LocatorInfo) : Rule | undefined {\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];\n }\n } else if (test.test(buildLoaderFilePath(info))) {\n return this.rules[i];\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 (this.loaders[id]) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n switch (id) {\n case 'script': {\n loader = new ScriptLoader();\n break;\n }\n case 'json': {\n loader = new JSONLoader();\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\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 useLoaderManager() {\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 { LocatorInfo, pathToLocatorInfo } from '../locator';\nimport { useLoaderManager } from './singleton';\n\nexport async function loadFile(input: LocatorInfo | string) : Promise<unknown> {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.execute(info);\n}\n\nexport function loadFileSync(input: LocatorInfo | string) : unknown {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.executeSync(info);\n}\n"],"names":["handleFileLoadError","e","Error","removeFileNameExtension","input","extensions","includes","position","lastIndexOf","extension","substring","length","indexOf","hasOwnProperty","obj","prop","Object","prototype","call","hasStringProperty","isObject","item","Array","isArray","toArray","options","buildLocatorOptions","path","push","process","cwd","soft","ignore","pathToLocatorInfo","skipResolve","isAbsolute","resolve","info","parse","dir","split","join","sep","name","ext","globAsync","promisify","glob","locateFiles","pattern","patterns","items","i","j","files","absolute","nodir","k","locateFile","element","shift","undefined","locateFilesSync","sync","locateFileSync","buildLoaderFilePath","withExtension","getExportItem","data","filterFn","keys","key","value","BaseError","default","isJestEnvironment","env","JEST_WORKER_ID","ScriptLoader","execute","filePath","output","load","jiti","executeSync","loadSync","locatorInfo","withFilePrefix","pathToFileURL","href","require","code","message","stack","constructor","createJITI","esmResolve","JSONLoader","file","fs","promises","readFile","JSON","toString","readFileSync","LoaderManager","register","rule","rules","findRule","loader","test","id","loaders","instance","useLoaderManager","loadFile","manager","loadFileSync"],"mappings":";;;;;;;;;;AAAA;;;;;AAKC,+BAGM,SAASA,mBAAAA,CAAoBC,CAAU,EAAS;AACnD,IAAA,IAAIA,aAAaC,KAAO,EAAA;AACpB,QAAA,MAAMD,CAAE,CAAA;KACX;IAED,IAAI,OAAOA,MAAM,QAAU,EAAA;QACvB,MAAM,IAAIC,MAAMD,CAAG,CAAA,CAAA;KACtB;IAED,MAAM,IAAIC,MAAM,sCAAwC,CAAA,CAAA;AAC5D;;AClBA;;;;;AAKC,IAEM,SAASC,uBAAAA,CACZC,KAAa,EACbC,UAAqB,EACvB;IACE,IAAID,KAAAA,CAAME,QAAQ,CAAC,GAAM,CAAA,EAAA;QACrB,MAAMC,QAAAA,GAAWH,KAAMI,CAAAA,WAAW,CAAC,GAAA,CAAA,CAAA;AACnC,QAAA,MAAMC,YAAYL,KAAMM,CAAAA,SAAS,CAC7BH,QAAAA,EACAH,MAAMO,MAAM,CAAA,CAAA;QAGhB,IACI,OAAON,eAAe,WACtBA,IAAAA,UAAAA,CAAWO,OAAO,CAACH,SAAAA,CAAAA,KAAe,CAAC,CACrC,EAAA;YACEL,KAAQA,GAAAA,KAAAA,CAAMM,SAAS,CAAC,CAAGH,EAAAA,QAAAA,CAAAA,CAAAA;SAC9B;KACJ;IAED,OAAOH,KAAAA,CAAAA;AACX;;AC3BO,SAASS,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,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,33 @@ function buildLoaderFilePath(info, withExtension) {
|
|
|
196
196
|
}
|
|
197
197
|
return path.join(info.path, info.name);
|
|
198
198
|
}
|
|
199
|
+
function getExportItem(data, filterFn) {
|
|
200
|
+
if (filterFn) {
|
|
201
|
+
const keys = Object.keys(data);
|
|
202
|
+
for(let i = 0; i < keys.length; i++){
|
|
203
|
+
if (filterFn(keys[i], data[keys[i]])) {
|
|
204
|
+
return {
|
|
205
|
+
key: keys[i],
|
|
206
|
+
value: data[keys[i]]
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
throw new BaseError('Cannot find specific module export.');
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
key: 'default',
|
|
214
|
+
value: hasOwnProperty(data, 'default') ? data.default : data
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/*
|
|
219
|
+
* Copyright (c) 2022.
|
|
220
|
+
* Author Peter Placzek (tada5hi)
|
|
221
|
+
* For the full copyright and license information,
|
|
222
|
+
* view the LICENSE file that was distributed with this source code.
|
|
223
|
+
*/ function isJestEnvironment() {
|
|
224
|
+
return process.env && process.env.JEST_WORKER_ID !== undefined;
|
|
225
|
+
}
|
|
199
226
|
|
|
200
227
|
class ScriptLoader {
|
|
201
228
|
async execute(info) {
|
|
@@ -232,6 +259,12 @@ class ScriptLoader {
|
|
|
232
259
|
filePath = pathToFileURL(filePath).href;
|
|
233
260
|
}
|
|
234
261
|
try {
|
|
262
|
+
// segmentation fault
|
|
263
|
+
// issue: https://github.com/nodejs/node/issues/35889
|
|
264
|
+
if (isJestEnvironment()) {
|
|
265
|
+
// eslint-disable-next-line global-require,import/no-dynamic-require
|
|
266
|
+
return require(filePath);
|
|
267
|
+
}
|
|
235
268
|
return await import(filePath);
|
|
236
269
|
} catch (e) {
|
|
237
270
|
/* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
|
|
@@ -302,25 +335,6 @@ class ScriptLoader {
|
|
|
302
335
|
}
|
|
303
336
|
}
|
|
304
337
|
|
|
305
|
-
function getExportItem(data, filterFn) {
|
|
306
|
-
if (filterFn) {
|
|
307
|
-
const keys = Object.keys(data);
|
|
308
|
-
for(let i = 0; i < keys.length; i++){
|
|
309
|
-
if (filterFn(keys[i], data[keys[i]])) {
|
|
310
|
-
return {
|
|
311
|
-
key: keys[i],
|
|
312
|
-
value: data[keys[i]]
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
throw new BaseError('Cannot find specific module export.');
|
|
317
|
-
}
|
|
318
|
-
return {
|
|
319
|
-
key: 'default',
|
|
320
|
-
value: hasOwnProperty(data, 'default') ? data.default : data
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
|
|
324
338
|
class JSONLoader {
|
|
325
339
|
async execute(input) {
|
|
326
340
|
const filePath = buildLoaderFilePath(input, true);
|
|
@@ -456,5 +470,5 @@ function loadFileSync(input) {
|
|
|
456
470
|
return manager.executeSync(info);
|
|
457
471
|
}
|
|
458
472
|
|
|
459
|
-
export { JSONLoader, ScriptLoader, buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, hasStringProperty, isObject, loadFile, loadFileSync, locateFile, locateFileSync, locateFiles, locateFilesSync, pathToLocatorInfo, removeFileNameExtension, toArray };
|
|
473
|
+
export { JSONLoader, ScriptLoader, buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, hasStringProperty, isJestEnvironment, isObject, loadFile, loadFileSync, locateFile, locateFileSync, locateFiles, locateFilesSync, pathToLocatorInfo, removeFileNameExtension, toArray };
|
|
460
474
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/to-array.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/utils.ts","../src/loader/built-in/script/module.ts","../src/loader/built-in/script/utils.ts","../src/loader/built-in/json/module.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["/*\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\n/* istanbul ignore next */\nexport function handleFileLoadError(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n if (typeof e === 'string') {\n throw new Error(e);\n }\n\n throw new Error('Cannot determine file loading 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","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\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [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\nimport path from 'node:path';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { toArray } from '../utils';\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.soft ??= true;\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (!skipResolve && !path.isAbsolute(input)) {\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","/*\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 { promisify } from 'node:util';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nconst globAsync = promisify(glob);\n\nexport async function locateFiles(\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 globAsync(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 locateFile(\n pattern: string | string[],\n options: Partial<LocatorOptions> & { soft: false }\n) : Promise<LocatorInfo>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<any> {\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 globAsync(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 if (!options.soft) {\n throw new Error('The file could not be located.');\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 glob from 'glob';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateFilesSync(\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 = glob.sync(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 locateFileSync(\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 = glob.sync(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 path from 'node:path';\nimport { LocatorInfo } from '../locator';\n\nexport function buildLoaderFilePath(info: LocatorInfo, withExtension?: boolean) {\n if (withExtension) {\n return path.join(info.path, info.name) + info.extension;\n }\n\n return path.join(info.path, info.name);\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 { LocatorInfo, pathToLocatorInfo } from '../../../locator';\nimport { handleFileLoadError, hasStringProperty, isObject } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\nimport { ScriptFileLoadOptions } from './type';\n\nexport class ScriptLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n /*\n const loaderMap : Record<string, ESLoader> = {\n '.mjs': 'js',\n '.js': 'js',\n '.jsx': 'jsx',\n '.ts': 'ts',\n '.tsx': 'tsx',\n };\n */\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n esmResolve: true,\n /*\n transform: (options) => {\n let loader : ESLoader = 'ts';\n if (options.filename) {\n const info = pathToLocatorInfo(options.filename, true);\n if (loaderMap[info.extension]) {\n loader = loaderMap[info.extension] as ESLoader;\n }\n }\n\n return transformSync(options.source, {\n target: 'ES2020',\n jsx: 'transform',\n format: 'cjs',\n loader,\n });\n },\n\n */\n });\n }\n\n async execute(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = await this.load(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n executeSync(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = this.loadSync(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : Promise<unknown> {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n if (options.withFilePrefix) {\n filePath = pathToFileURL(filePath).href;\n }\n\n try {\n return await import(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\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 } from '../../../utils';\nimport { LoaderFilterFn, ScriptFileExportItem } from './type';\n\nexport function getExportItem(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n) : ScriptFileExportItem {\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 return {\n key: 'default',\n value: hasOwnProperty(data, 'default') ? data.default : data,\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 { LocatorInfo } from '../../../locator';\nimport { handleFileLoadError } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\n\nexport class JSONLoader implements Loader {\n async execute(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n\n executeSync(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(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\nimport { LocatorInfo } from '../locator';\nimport { JSONLoader, ScriptLoader } from './built-in';\nimport { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\n\nexport class LoaderManager {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n { test: ['.js', '.mjs', '.cjs', '.ts'], loader: 'script' },\n { test: ['.json'], loader: 'json' },\n ];\n }\n\n register(rule: Rule) {\n this.rules.push(rule);\n }\n\n async execute(info: LocatorInfo) : Promise<any> {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.execute(info);\n }\n\n executeSync(info: LocatorInfo) : any {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.executeSync(info);\n }\n\n findRule(info: LocatorInfo) : Rule | undefined {\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];\n }\n } else if (test.test(buildLoaderFilePath(info))) {\n return this.rules[i];\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 (this.loaders[id]) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n switch (id) {\n case 'script': {\n loader = new ScriptLoader();\n break;\n }\n case 'json': {\n loader = new JSONLoader();\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\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 useLoaderManager() {\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 { LocatorInfo, pathToLocatorInfo } from '../locator';\nimport { useLoaderManager } from './singleton';\n\nexport async function loadFile(input: LocatorInfo | string) : Promise<unknown> {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.execute(info);\n}\n\nexport function loadFileSync(input: LocatorInfo | string) : unknown {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.executeSync(info);\n}\n"],"names":["input","options","name","extension","pattern","absolute","cwd","nodir","ignore","items","output","executeSync","locatorInfo","withExtension","withFilePrefix","code","message","stack","esmResolve","value","register","findRule","loader","instance","info"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;AAKC;AAIG;AACI;;;;;;AAQR;;AClBA;;;;;AAKC;;;AAQO;;;;;;AAcR;;AC3BO;AACH;AACJ;AAEO;AACH;AACJ;;ACNA;;;;;AAKC;;AAQD;;ACbA;;;;;AAKC;AAGG;AAAuCA;AAAM;AACjD;;ACTA;;;;;AAKC;AAMM;AACHC;AAEAA;AACAA;AACA;AACIA;;AAGJA;AACAA;;AAGJ;AAEO;AAIH;AACID;;;;;AAOAE;AACAC;AACJ;AACJ;;AC7BA;AAEO;AAIHF;AAEA;AAEKG;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;A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AO;AAAQ;AAAQ;AAAM;;AAAmB;AACzD;;AAAS;AAAQ;;AAAiB;AACrC;AACL;AA0EJ;;ACxFA;AACO;;;;AAKHC;;AAGJ;;ACRO;;;AAGCC;;;;AAKJ;;AAGJ;AAEO;;;AAGCA;;;;AAKJ;;AAGJ;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/to-array.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/utils.ts","../src/loader/built-in/script/utils.ts","../src/loader/built-in/script/module.ts","../src/loader/built-in/json/module.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["/*\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\n/* istanbul ignore next */\nexport function handleFileLoadError(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n if (typeof e === 'string') {\n throw new Error(e);\n }\n\n throw new Error('Cannot determine file loading 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","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\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [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\nimport path from 'node:path';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { toArray } from '../utils';\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.soft ??= true;\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (!skipResolve && !path.isAbsolute(input)) {\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","/*\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 { promisify } from 'node:util';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nconst globAsync = promisify(glob);\n\nexport async function locateFiles(\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 globAsync(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 locateFile(\n pattern: string | string[],\n options: Partial<LocatorOptions> & { soft: false }\n) : Promise<LocatorInfo>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined>;\nexport async function locateFile(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<any> {\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 globAsync(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 if (!options.soft) {\n throw new Error('The file could not be located.');\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 glob from 'glob';\nimport { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateFilesSync(\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 = glob.sync(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 locateFileSync(\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 = glob.sync(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 path from 'node:path';\nimport { LocatorInfo } from '../locator';\nimport { hasOwnProperty } from '../utils';\nimport { LoaderFilterFn, ScriptFileExportItem } from './built-in';\n\nexport function buildLoaderFilePath(info: LocatorInfo, withExtension?: boolean) {\n if (withExtension) {\n return path.join(info.path, info.name) + info.extension;\n }\n\n return path.join(info.path, info.name);\n}\n\nexport function getExportItem(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ScriptFileExportItem {\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 return {\n key: 'default',\n value: hasOwnProperty(data, 'default') ? data.default : data,\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\nexport function isJestEnvironment() {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\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 { LocatorInfo, pathToLocatorInfo } from '../../../locator';\nimport { handleFileLoadError, hasStringProperty, isObject } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\nimport { ScriptFileLoadOptions } from './type';\nimport { isJestEnvironment } from './utils';\n\nexport class ScriptLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n /*\n const loaderMap : Record<string, ESLoader> = {\n '.mjs': 'js',\n '.js': 'js',\n '.jsx': 'jsx',\n '.ts': 'ts',\n '.tsx': 'tsx',\n };\n */\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n esmResolve: true,\n /*\n transform: (options) => {\n let loader : ESLoader = 'ts';\n if (options.filename) {\n const info = pathToLocatorInfo(options.filename, true);\n if (loaderMap[info.extension]) {\n loader = loaderMap[info.extension] as ESLoader;\n }\n }\n\n return transformSync(options.source, {\n target: 'ES2020',\n jsx: 'transform',\n format: 'cjs',\n loader,\n });\n },\n\n */\n });\n }\n\n async execute(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = await this.load(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n executeSync(info: LocatorInfo) {\n const filePath = buildLoaderFilePath(info);\n\n let output : any;\n\n try {\n output = this.loadSync(info);\n } catch (e) {\n output = this.jiti(filePath);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : Promise<unknown> {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n if (options.withFilePrefix) {\n filePath = pathToFileURL(filePath).href;\n }\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n }\n\n return await import(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\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 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 handleFileLoadError(e);\n }\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 { LocatorInfo } from '../../../locator';\nimport { handleFileLoadError } from '../../../utils';\nimport { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\n\nexport class JSONLoader implements Loader {\n async execute(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n\n executeSync(input: LocatorInfo) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(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\nimport { LocatorInfo } from '../locator';\nimport { JSONLoader, ScriptLoader } from './built-in';\nimport { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\n\nexport class LoaderManager {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n { test: ['.js', '.mjs', '.cjs', '.ts'], loader: 'script' },\n { test: ['.json'], loader: 'json' },\n ];\n }\n\n register(rule: Rule) {\n this.rules.push(rule);\n }\n\n async execute(info: LocatorInfo) : Promise<any> {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.execute(info);\n }\n\n executeSync(info: LocatorInfo) : any {\n const rule = this.findRule(info);\n if (!rule) {\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(rule.loader);\n return loader.executeSync(info);\n }\n\n findRule(info: LocatorInfo) : Rule | undefined {\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];\n }\n } else if (test.test(buildLoaderFilePath(info))) {\n return this.rules[i];\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 (this.loaders[id]) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n switch (id) {\n case 'script': {\n loader = new ScriptLoader();\n break;\n }\n case 'json': {\n loader = new JSONLoader();\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\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 useLoaderManager() {\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 { LocatorInfo, pathToLocatorInfo } from '../locator';\nimport { useLoaderManager } from './singleton';\n\nexport async function loadFile(input: LocatorInfo | string) : Promise<unknown> {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.execute(info);\n}\n\nexport function loadFileSync(input: LocatorInfo | string) : unknown {\n let info : LocatorInfo;\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n const manager = useLoaderManager();\n\n return manager.executeSync(info);\n}\n"],"names":["input","options","name","extension","pattern","absolute","cwd","nodir","ignore","items","value","output","executeSync","locatorInfo","withExtension","withFilePrefix","code","message","stack","esmResolve","register","findRule","loader","instance","info"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;AAKC;AAIG;AACI;;;;;;AAQR;;AClBA;;;;;AAKC;;;AAQO;;;;;;AAcR;;AC3BO;AACH;AACJ;AAEO;AACH;AACJ;;ACNA;;;;;AAKC;;AAQD;;ACbA;;;;;AAKC;AAGG;AAAuCA;AAAM;AACjD;;ACTA;;;;;AAKC;AAMM;AACHC;AAEAA;AACAA;AACA;AACIA;;AAGJA;AACAA;;AAGJ;AAEO;AAIH;AACID;;;;;AAOAE;AACAC;AACJ;AACJ;;AC7BA;AAEO;AAIHF;AAEA;AAEKG;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAUO;AAIHR;AAEA;AAEKG;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;AACJ;;;;;AAOJ;;ACxEO;AAIHP;AAEA;AAEKG;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHR;AAEA;AAEKG;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;AACJ;;AAGJ;;ACvDO;AACH;;;AAIA;AACJ;AAEO;AAIH;;AAEI;;;;AAIYE;AACJ;;AAER;;;;;AAOAA;AACJ;AACJ;;AC3CA;;;;;;AAQI;AAEJ;;ACQO;;AAwCC;;;AAKIC;AACJ;;AAEA;;AAGJ;AAEAC;AACI;;;;AAMA;;AAEA;;AAGJ;;AAIA;;;AAOQC;;;;AAKJZ;AAEA;;;;;;;AAQI;;AAEI;;;AAIR;AACI;AAKI;AAOI;AACI;AACAa;AACJ;;AAGJ;AAOI;AACI;AACAC;AACJ;;AAGJ;AACIC;AACAC;AACAC;;;;AAMZ;AACJ;;;;AASQL;;;;AAKJZ;AAEA;;;AAII;AACJ;AACI;AAKI;AAOI;AACI;AACAa;AACJ;;AAGJ;AACIE;AACAC;AACAC;;;AAIR;AACJ;AACJ;;AAxLI;;;;;;;;AAQA;;AAGA;AACIC;AAoBJ;AACJ;AAwJJ;;AClMO;;;;AAKK;AACA;AACJ;AACI;AACJ;AACJ;AAEAP;;;;AAKQ;AACJ;AACI;AACJ;AACJ;AACJ;;ACvBO;AAaHQ;AACI;AACJ;;AAGI;AACA;;;AAIA;;AAEJ;AAEAR;AACI;AACA;;;AAIA;;AAEJ;AAEAS;;;;AAIY;AACI;;AAER;AACI;;AAER;;AAGJ;AAEA;;;;;;;;AAUI;AACI;;;;;AAMe;AACXC;;AAEJ;;AACa;AACTA;;AAEJ;AACJ;;;;;AAOJ;;;;AA5EQ;;AAAS;AAAO;AAAQ;AAAQ;AAAM;;AAAmB;AACzD;;AAAS;AAAQ;;AAAiB;AACrC;AACL;AA0EJ;;ACxFA;AACO;;;;AAKHC;;AAGJ;;ACRO;;;AAGCC;;;;AAKJ;;AAGJ;AAEO;;;AAGCA;;;;AAKJ;;AAGJ;;"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function getExportItem(data: Record<string, any>, filterFn?: LoaderFilterFn): ScriptFileExportItem;
|
|
1
|
+
export declare function isJestEnvironment(): boolean;
|
package/dist/loader/utils.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { LocatorInfo } from '../locator';
|
|
2
|
+
import { LoaderFilterFn, ScriptFileExportItem } from './built-in';
|
|
2
3
|
export declare function buildLoaderFilePath(info: LocatorInfo, withExtension?: boolean): string;
|
|
4
|
+
export declare function getExportItem(data: Record<string, any>, filterFn?: LoaderFilterFn): ScriptFileExportItem;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A library to locate a file by criteria and load it",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Placzek",
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
"@semantic-release/github": "^8.0.7",
|
|
60
60
|
"@semantic-release/npm": "^9.0.1",
|
|
61
61
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
62
|
-
"@swc/core": "^1.3.
|
|
62
|
+
"@swc/core": "^1.3.31",
|
|
63
63
|
"@swc/jest": "^0.2.24",
|
|
64
64
|
"@tada5hi/eslint-config-typescript": "^1.1.1",
|
|
65
65
|
"@tada5hi/tsconfig": "^0.4.0",
|
|
66
66
|
"@types/glob": "^8.0.1",
|
|
67
67
|
"@types/jest": "^27.5.2",
|
|
68
68
|
"@types/node": "^18.11.18",
|
|
69
|
-
"@types/yargs": "^17.0.
|
|
69
|
+
"@types/yargs": "^17.0.21",
|
|
70
70
|
"coveralls": "^3.1.0",
|
|
71
71
|
"cross-env": "^7.0.3",
|
|
72
72
|
"eslint": "^8.32.0",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"rollup": "^3.12.0",
|
|
79
79
|
"semantic-release": "^19.0.5",
|
|
80
80
|
"sourcemap-codec": "^1.4.8",
|
|
81
|
-
"typescript": "^4.9.
|
|
81
|
+
"typescript": "^4.9.5"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"ebec": "^0.2.1",
|