locter 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +15 -4
- package/dist/index.mjs.map +1 -1
- package/dist/loader/built-in/script/utils.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -215,9 +215,14 @@ function getExportItem(data, filterFn) {
|
|
|
215
215
|
* Author Peter Placzek (tada5hi)
|
|
216
216
|
* For the full copyright and license information,
|
|
217
217
|
* view the LICENSE file that was distributed with this source code.
|
|
218
|
-
*/ function
|
|
218
|
+
*/ function isJestRuntimeEnvironment() {
|
|
219
219
|
return process.env && process.env.JEST_WORKER_ID !== undefined;
|
|
220
220
|
}
|
|
221
|
+
function isTsNodeRuntimeEnvironment() {
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
return !!process[Symbol.for('ts-node.register.instance')];
|
|
225
|
+
}
|
|
221
226
|
|
|
222
227
|
class ScriptLoader {
|
|
223
228
|
async execute(info) {
|
|
@@ -226,7 +231,13 @@ class ScriptLoader {
|
|
|
226
231
|
try {
|
|
227
232
|
output = await this.load(info);
|
|
228
233
|
} catch (e) {
|
|
229
|
-
|
|
234
|
+
// jiti + ts-node
|
|
235
|
+
// issue: https://github.com/nuxt/bridge/issues/228
|
|
236
|
+
if (isTsNodeRuntimeEnvironment()) {
|
|
237
|
+
output = this.loadSync(info);
|
|
238
|
+
} else {
|
|
239
|
+
output = this.jiti(filePath);
|
|
240
|
+
}
|
|
230
241
|
}
|
|
231
242
|
return output;
|
|
232
243
|
}
|
|
@@ -256,7 +267,7 @@ class ScriptLoader {
|
|
|
256
267
|
try {
|
|
257
268
|
// segmentation fault
|
|
258
269
|
// issue: https://github.com/nodejs/node/issues/35889
|
|
259
|
-
if (
|
|
270
|
+
if (isJestRuntimeEnvironment()) {
|
|
260
271
|
// eslint-disable-next-line global-require,import/no-dynamic-require
|
|
261
272
|
return require(filePath);
|
|
262
273
|
}
|
|
@@ -473,8 +484,9 @@ exports.getExportItem = getExportItem;
|
|
|
473
484
|
exports.handleFileLoadError = handleFileLoadError;
|
|
474
485
|
exports.hasOwnProperty = hasOwnProperty;
|
|
475
486
|
exports.hasStringProperty = hasStringProperty;
|
|
476
|
-
exports.
|
|
487
|
+
exports.isJestRuntimeEnvironment = isJestRuntimeEnvironment;
|
|
477
488
|
exports.isObject = isObject;
|
|
489
|
+
exports.isTsNodeRuntimeEnvironment = isTsNodeRuntimeEnvironment;
|
|
478
490
|
exports.loadFile = loadFile;
|
|
479
491
|
exports.loadFileSync = loadFileSync;
|
|
480
492
|
exports.locateFile = locateFile;
|
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/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;;;;;AAK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A;AACX;;ACRO,eAAeE,QAAShH,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,MAAMiH,OAAUF,GAAAA,gBAAAA,EAAAA,CAAAA;IAEhB,OAAOE,OAAAA,CAAQtC,OAAO,CAAC1C,IAAAA,CAAAA,CAAAA;AAC3B,CAAC;AAEM,SAASiF,YAAalH,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,MAAMiH,OAAUF,GAAAA,gBAAAA,EAAAA,CAAAA;IAEhB,OAAOE,OAAAA,CAAQjC,WAAW,CAAC/C,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 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","/*\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 { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } 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 // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(info);\n } else {\n output = this.jiti(filePath);\n }\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 (isJestRuntimeEnvironment()) {\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","isJestRuntimeEnvironment","env","JEST_WORKER_ID","isTsNodeRuntimeEnvironment","Symbol","for","ScriptLoader","execute","filePath","output","load","loadSync","jiti","executeSync","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,CAAwE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AAA,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,MAAMoH,OAAUF,GAAAA,gBAAAA,EAAAA,CAAAA;IAEhB,OAAOE,OAAAA,CAAQhC,WAAW,CAACnD,IAAAA,CAAAA,CAAAA;AAC/B;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -220,9 +220,14 @@ function getExportItem(data, filterFn) {
|
|
|
220
220
|
* Author Peter Placzek (tada5hi)
|
|
221
221
|
* For the full copyright and license information,
|
|
222
222
|
* view the LICENSE file that was distributed with this source code.
|
|
223
|
-
*/ function
|
|
223
|
+
*/ function isJestRuntimeEnvironment() {
|
|
224
224
|
return process.env && process.env.JEST_WORKER_ID !== undefined;
|
|
225
225
|
}
|
|
226
|
+
function isTsNodeRuntimeEnvironment() {
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
228
|
+
// @ts-ignore
|
|
229
|
+
return !!process[Symbol.for('ts-node.register.instance')];
|
|
230
|
+
}
|
|
226
231
|
|
|
227
232
|
class ScriptLoader {
|
|
228
233
|
async execute(info) {
|
|
@@ -231,7 +236,13 @@ class ScriptLoader {
|
|
|
231
236
|
try {
|
|
232
237
|
output = await this.load(info);
|
|
233
238
|
} catch (e) {
|
|
234
|
-
|
|
239
|
+
// jiti + ts-node
|
|
240
|
+
// issue: https://github.com/nuxt/bridge/issues/228
|
|
241
|
+
if (isTsNodeRuntimeEnvironment()) {
|
|
242
|
+
output = this.loadSync(info);
|
|
243
|
+
} else {
|
|
244
|
+
output = this.jiti(filePath);
|
|
245
|
+
}
|
|
235
246
|
}
|
|
236
247
|
return output;
|
|
237
248
|
}
|
|
@@ -261,7 +272,7 @@ class ScriptLoader {
|
|
|
261
272
|
try {
|
|
262
273
|
// segmentation fault
|
|
263
274
|
// issue: https://github.com/nodejs/node/issues/35889
|
|
264
|
-
if (
|
|
275
|
+
if (isJestRuntimeEnvironment()) {
|
|
265
276
|
// eslint-disable-next-line global-require,import/no-dynamic-require
|
|
266
277
|
return require(filePath);
|
|
267
278
|
}
|
|
@@ -470,5 +481,5 @@ function loadFileSync(input) {
|
|
|
470
481
|
return manager.executeSync(info);
|
|
471
482
|
}
|
|
472
483
|
|
|
473
|
-
export { JSONLoader, ScriptLoader, buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, hasStringProperty,
|
|
484
|
+
export { JSONLoader, ScriptLoader, buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, hasStringProperty, isJestRuntimeEnvironment, isObject, isTsNodeRuntimeEnvironment, loadFile, loadFileSync, locateFile, locateFileSync, locateFiles, locateFilesSync, pathToLocatorInfo, removeFileNameExtension, toArray };
|
|
474
485
|
//# 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/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;AA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GJ;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 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","/*\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 { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } 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 // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(info);\n } else {\n output = this.jiti(filePath);\n }\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 (isJestRuntimeEnvironment()) {\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;AAEO;;;AAGH;AACJ;;ACEO;;AAwCC;;;AAKIC;AACJ;;;AAGI;;;;;AAKJ;;AAGJ;AAEAC;AACI;;;;AA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