locter 1.0.7 → 1.0.9

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 CHANGED
@@ -66,23 +66,9 @@ function handleException(e) {
66
66
  ];
67
67
  }
68
68
 
69
- function buildFilePath(input) {
70
- if (typeof input === 'string') {
71
- return input;
72
- }
73
- if (input.extension) {
74
- return path.join(input.path, input.name) + input.extension;
75
- }
76
- return path.join(input.path, input.name);
77
- }
78
- function buildFilePathWithoutExtension(input) {
79
- let info;
80
- if (typeof input === 'string') {
81
- info = pathToLocatorInfo(input);
82
- } else {
83
- info = input;
84
- }
85
- return path.join(info.path, info.name);
69
+ function isFilePath(input) {
70
+ const extension = path.extname(input);
71
+ return extension && extension !== '';
86
72
  }
87
73
 
88
74
  /*
@@ -101,10 +87,6 @@ function buildLocatorOptions(options) {
101
87
  (_options = options).ignore ?? (_options.ignore = []);
102
88
  return options;
103
89
  }
104
- function isFilePath(input) {
105
- const info = path.parse(input);
106
- return info.ext !== '';
107
- }
108
90
  function pathToLocatorInfo(input, skipResolve) {
109
91
  if (!skipResolve && !path.isAbsolute(input)) {
110
92
  input = path.resolve(process.cwd(), input);
@@ -116,6 +98,27 @@ function pathToLocatorInfo(input, skipResolve) {
116
98
  extension: info.ext
117
99
  };
118
100
  }
101
+ function isLocatorInfo(input) {
102
+ return isObject(input) && typeof input.path === 'string' && typeof input.name === 'string' && typeof input.extension === 'string';
103
+ }
104
+ function buildFilePath(input) {
105
+ if (typeof input === 'string') {
106
+ return input;
107
+ }
108
+ if (input.extension) {
109
+ return path.join(input.path, input.name) + input.extension;
110
+ }
111
+ return path.join(input.path, input.name);
112
+ }
113
+ function buildFilePathWithoutExtension(input) {
114
+ let info;
115
+ if (typeof input === 'string') {
116
+ info = pathToLocatorInfo(input);
117
+ } else {
118
+ info = input;
119
+ }
120
+ return path.join(info.path, info.name);
121
+ }
119
122
 
120
123
  async function locateMany(pattern, options) {
121
124
  options = buildLocatorOptions(options);
@@ -203,12 +206,7 @@ function locateSync(pattern, options) {
203
206
  return undefined;
204
207
  }
205
208
 
206
- /*
207
- * Copyright (c) 2022.
208
- * Author Peter Placzek (tada5hi)
209
- * For the full copyright and license information,
210
- * view the LICENSE file that was distributed with this source code.
211
- */ function isJestRuntimeEnvironment() {
209
+ function isJestRuntimeEnvironment() {
212
210
  return process.env && process.env.JEST_WORKER_ID !== undefined;
213
211
  }
214
212
  function isTsNodeRuntimeEnvironment() {
@@ -216,6 +214,34 @@ function isTsNodeRuntimeEnvironment() {
216
214
  // @ts-ignore
217
215
  return !!process[Symbol.for('ts-node.register.instance')];
218
216
  }
217
+ function getModuleExport(data, filterFn) {
218
+ if (filterFn) {
219
+ const keys = Object.keys(data);
220
+ for(let i = 0; i < keys.length; i++){
221
+ if (filterFn(keys[i], data[keys[i]])) {
222
+ return {
223
+ key: keys[i],
224
+ value: data[keys[i]]
225
+ };
226
+ }
227
+ }
228
+ throw new ebec.BaseError('Cannot find specific module export.');
229
+ }
230
+ let value;
231
+ if (hasOwnProperty(data, '__esModule') && // eslint-disable-next-line no-underscore-dangle
232
+ !!data.__esModule && hasOwnProperty(data, 'default')) {
233
+ value = data.default;
234
+ } else {
235
+ value = data;
236
+ }
237
+ if (isObject(value) && hasOwnProperty(value, 'default')) {
238
+ value = value.default;
239
+ }
240
+ return {
241
+ key: 'default',
242
+ value
243
+ };
244
+ }
219
245
 
220
246
  class ModuleLoader {
221
247
  async execute(input) {
@@ -244,38 +270,31 @@ class ModuleLoader {
244
270
  }
245
271
  // ---------------------------------------------------------------------------
246
272
  async load(data, options) {
247
- const locatorInfo = this.buildLocatorInfo(data);
248
273
  options = options || {};
249
- let filePath;
250
- if (options.withExtension) {
251
- filePath = buildFilePath(locatorInfo);
252
- } else {
253
- filePath = buildFilePathWithoutExtension(locatorInfo);
254
- }
255
- if (options.withFilePrefix) {
256
- filePath = node_url.pathToFileURL(filePath).href;
257
- }
274
+ const [name, locatorInfo] = this.build(data, options);
258
275
  try {
259
276
  // segmentation fault
260
277
  // issue: https://github.com/nodejs/node/issues/35889
261
278
  if (isJestRuntimeEnvironment()) {
262
279
  // eslint-disable-next-line global-require,import/no-dynamic-require
263
- return require(filePath);
280
+ return require(name);
264
281
  }
265
- return await import(filePath);
282
+ return await import(name);
266
283
  } catch (e) {
267
284
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
268
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
269
- return this.load(locatorInfo, {
270
- ...options,
271
- withExtension: true
272
- });
273
- }
274
- if (!options.withFilePrefix && (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || e.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
275
- return this.load(locatorInfo, {
276
- ...options,
277
- withFilePrefix: true
278
- });
285
+ if (locatorInfo) {
286
+ if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
287
+ return this.load(locatorInfo, {
288
+ ...options,
289
+ withExtension: true
290
+ });
291
+ }
292
+ if (!options.withFilePrefix && (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || e.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
293
+ return this.load(locatorInfo, {
294
+ ...options,
295
+ withFilePrefix: true
296
+ });
297
+ }
279
298
  }
280
299
  throw new ebec.BaseError({
281
300
  code: e.code,
@@ -287,24 +306,20 @@ class ModuleLoader {
287
306
  }
288
307
  }
289
308
  loadSync(data, options) {
290
- const locatorInfo = this.buildLocatorInfo(data);
291
309
  options = options || {};
292
- let filePath;
293
- if (options.withExtension) {
294
- filePath = buildFilePath(locatorInfo);
295
- } else {
296
- filePath = buildFilePathWithoutExtension(locatorInfo);
297
- }
310
+ const [name, locatorInfo] = this.build(data, options);
298
311
  try {
299
312
  // eslint-disable-next-line global-require,import/no-dynamic-require
300
- return require(filePath);
313
+ return require(name);
301
314
  } catch (e) {
302
315
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
303
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
304
- return this.loadSync(locatorInfo, {
305
- ...options,
306
- withExtension: true
307
- });
316
+ if (locatorInfo) {
317
+ if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
318
+ return this.loadSync(locatorInfo, {
319
+ ...options,
320
+ withExtension: true
321
+ });
322
+ }
308
323
  }
309
324
  throw new ebec.BaseError({
310
325
  code: e.code,
@@ -315,11 +330,31 @@ class ModuleLoader {
315
330
  return handleException(e);
316
331
  }
317
332
  }
318
- buildLocatorInfo(input) {
319
- if (typeof input === 'string') {
320
- return pathToLocatorInfo(input);
333
+ build(data, options) {
334
+ let name;
335
+ let locatorInfo;
336
+ options = options || {};
337
+ if (isLocatorInfo(data) || isFilePath(data)) {
338
+ if (typeof data === 'string') {
339
+ locatorInfo = pathToLocatorInfo(data);
340
+ } else {
341
+ locatorInfo = data;
342
+ }
343
+ if (options.withExtension) {
344
+ name = buildFilePath(locatorInfo);
345
+ } else {
346
+ name = buildFilePathWithoutExtension(locatorInfo);
347
+ }
348
+ if (options.withFilePrefix) {
349
+ name = node_url.pathToFileURL(name).href;
350
+ }
351
+ } else {
352
+ name = data;
321
353
  }
322
- return input;
354
+ return [
355
+ name,
356
+ locatorInfo
357
+ ];
323
358
  }
324
359
  constructor(){
325
360
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -521,37 +556,19 @@ function loadSync(input) {
521
556
  return manager.executeSync(buildFilePath(input));
522
557
  }
523
558
 
524
- function getExportItem(data, filterFn) {
525
- if (filterFn) {
526
- const keys = Object.keys(data);
527
- for(let i = 0; i < keys.length; i++){
528
- if (filterFn(keys[i], data[keys[i]])) {
529
- return {
530
- key: keys[i],
531
- value: data[keys[i]]
532
- };
533
- }
534
- }
535
- throw new ebec.BaseError('Cannot find specific module export.');
536
- }
537
- return {
538
- key: 'default',
539
- value: hasOwnProperty(data, 'default') ? data.default : data
540
- };
541
- }
542
-
543
559
  exports.JSONLoader = JSONLoader;
544
560
  exports.LoaderManager = LoaderManager;
545
561
  exports.ModuleLoader = ModuleLoader;
546
562
  exports.buildFilePath = buildFilePath;
547
563
  exports.buildFilePathWithoutExtension = buildFilePathWithoutExtension;
548
564
  exports.buildLocatorOptions = buildLocatorOptions;
549
- exports.getExportItem = getExportItem;
565
+ exports.getModuleExport = getModuleExport;
550
566
  exports.handleException = handleException;
551
567
  exports.hasOwnProperty = hasOwnProperty;
552
568
  exports.hasStringProperty = hasStringProperty;
553
569
  exports.isFilePath = isFilePath;
554
570
  exports.isJestRuntimeEnvironment = isJestRuntimeEnvironment;
571
+ exports.isLocatorInfo = isLocatorInfo;
555
572
  exports.isObject = isObject;
556
573
  exports.isTsNodeRuntimeEnvironment = isTsNodeRuntimeEnvironment;
557
574
  exports.load = load;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts","../src/loader/utils.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\nimport type { LocatorInfo } from '../locator';\nimport { pathToLocatorInfo } from '../locator';\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport type { 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.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function isFilePath(input: string) {\n const info = path.parse(input);\n return info.ext !== '';\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\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 type { LocatorInfo } from '../../../locator';\nimport { pathToLocatorInfo } from '../../../locator';\nimport {\n buildFilePath, buildFilePathWithoutExtension, handleException, hasStringProperty, isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ScriptFileLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : Promise<unknown> {\n const locatorInfo = this.buildLocatorInfo(data);\n\n options = options || {};\n\n let filePath : string;\n if (options.withExtension) {\n filePath = buildFilePath(locatorInfo);\n } else {\n filePath = buildFilePathWithoutExtension(locatorInfo);\n }\n\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 handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n const locatorInfo = this.buildLocatorInfo(data);\n\n options = options || {};\n\n let filePath : string;\n if (options.withExtension) {\n filePath = buildFilePath(locatorInfo);\n } else {\n filePath = buildFilePathWithoutExtension(locatorInfo);\n }\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 handleException(e);\n }\n }\n\n private buildLocatorInfo(input: LocatorInfo | string) : LocatorInfo {\n if (typeof input === 'string') {\n return pathToLocatorInfo(input);\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath, handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isFilePath, pathToLocatorInfo } from '../locator';\nimport { buildFilePath } from '../utils';\nimport { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { LocatorInfo } from '../locator';\nimport { buildFilePath } from '../utils';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n","/*\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 type { LoaderFilterFn, ScriptFileExportItem } from './built-in';\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"],"names":["hasOwnProperty","obj","prop","Object","prototype","call","hasStringProperty","isObject","item","Array","isArray","handleException","e","Error","error","message","stack","removeFileNameExtension","input","extensions","includes","position","lastIndexOf","extension","substring","length","indexOf","toArray","buildFilePath","path","join","name","buildFilePathWithoutExtension","info","pathToLocatorInfo","options","buildLocatorOptions","push","process","cwd","ignore","isFilePath","parse","ext","skipResolve","isAbsolute","resolve","dir","split","sep","locateMany","pattern","patterns","items","i","j","files","glob","absolute","nodir","k","locate","element","shift","undefined","locateManySync","globSync","locateSync","isJestRuntimeEnvironment","env","JEST_WORKER_ID","isTsNodeRuntimeEnvironment","Symbol","for","ModuleLoader","execute","output","load","loadSync","jiti","executeSync","data","locatorInfo","buildLocatorInfo","filePath","withExtension","withFilePrefix","pathToFileURL","href","require","code","BaseError","constructor","createJITI","JSONLoader","file","fs","promises","readFile","JSON","toString","readFileSync","LoaderId","MODULE","LoaderManager","register","test","loader","rules","id","findLoader","loaders","pluginPath","normalizePath","moduleLoader","startsWith","instance","useLoader","registerLoader","manager","getExportItem","filterFn","keys","key","value","default"],"mappings":";;;;;;;;;AAAO,SAASA,cAAAA,CAAqEC,GAAM,EAAEC,IAAO,EAAiC;AACjI,IAAA,OAAOC,OAAOC,SAAS,CAACJ,cAAc,CAACK,IAAI,CAACJ,GAAKC,EAAAA,IAAAA,CAAAA,CAAAA;AACrD,CAAC;AAEM,SAASI,iBAAAA,CAAwEL,GAAM,EAAEC,IAAO,EAAgC;AACnI,IAAA,OAAOF,eAAeC,GAAKC,EAAAA,IAAAA,CAAAA,IAAS,OAAOD,GAAG,CAACC,KAAK,KAAK,QAAA,CA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../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\n\nexport function isFilePath(input: string) {\n const extension = path.extname(input);\n return extension && extension !== '';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isObject, toArray } from '../utils';\nimport type { LocatorInfo, LocatorOptions } from './type';\n\nexport function buildLocatorOptions(options?: Partial<LocatorOptions>) : LocatorOptions {\n options = options || {};\n\n options.path = options.path || [];\n options.path = toArray(options.path);\n if (options.path.length === 0) {\n options.path.push(process.cwd());\n }\n\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n\nexport function isLocatorInfo(\n input: unknown,\n) : input is LocatorInfo {\n return isObject(input) &&\n typeof input.path === 'string' &&\n typeof input.name === 'string' &&\n typeof input.extension === 'string';\n}\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport { hasOwnProperty, isObject } from '../../../utils';\nimport type { LoaderFilterFn, ModuleExport } from './type';\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n\nexport function getModuleExport(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ModuleExport {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n let value: any;\n\n if (\n hasOwnProperty(data, '__esModule') &&\n // eslint-disable-next-line no-underscore-dangle\n !!data.__esModule &&\n hasOwnProperty(data, 'default')\n ) {\n value = data.default;\n } else {\n value = data;\n }\n\n if (\n isObject(value) &&\n hasOwnProperty(value, 'default')\n ) {\n value = value.default;\n }\n\n return {\n key: 'default',\n value,\n };\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport {\n buildFilePath,\n buildFilePathWithoutExtension,\n isLocatorInfo,\n pathToLocatorInfo,\n} from '../../../locator';\nimport {\n handleException,\n hasStringProperty, isFilePath,\n isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ModuleLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : Promise<unknown> {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n }\n\n return await import(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : unknown {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleException(e);\n }\n }\n\n private build(\n data: LocatorInfo | string,\n options: ModuleLoadOptions,\n ) : [string, LocatorInfo | undefined] {\n let name : string;\n let locatorInfo : LocatorInfo | undefined;\n\n options = options || {};\n\n if (isLocatorInfo(data) || isFilePath(data)) {\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n if (options.withExtension) {\n name = buildFilePath(locatorInfo);\n } else {\n name = buildFilePathWithoutExtension(locatorInfo);\n }\n\n if (options.withFilePrefix) {\n name = pathToFileURL(name).href;\n }\n } else {\n name = data;\n }\n\n return [name, locatorInfo];\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { buildFilePath, pathToLocatorInfo } from '../locator';\nimport { isFilePath } from '../utils';\nimport { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildFilePath } from '../locator';\nimport type { LocatorInfo } from '../locator';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n"],"names":["hasOwnProperty","obj","prop","Object","prototype","call","hasStringProperty","isObject","item","Array","isArray","handleException","e","Error","error","message","stack","removeFileNameExtension","input","extensions","includes","position","lastIndexOf","extension","substring","length","indexOf","toArray","isFilePath","path","extname","options","buildLocatorOptions","push","process","cwd","ignore","pathToLocatorInfo","skipResolve","isAbsolute","resolve","info","parse","dir","split","join","sep","name","ext","isLocatorInfo","buildFilePath","buildFilePathWithoutExtension","locateMany","pattern","patterns","items","i","j","files","glob","absolute","nodir","k","locate","element","shift","undefined","locateManySync","globSync","locateSync","isJestRuntimeEnvironment","env","JEST_WORKER_ID","isTsNodeRuntimeEnvironment","Symbol","for","getModuleExport","data","filterFn","keys","key","value","BaseError","__esModule","default","ModuleLoader","execute","output","load","loadSync","jiti","executeSync","locatorInfo","build","require","withExtension","code","withFilePrefix","pathToFileURL","href","constructor","createJITI","JSONLoader","filePath","file","fs","promises","readFile","JSON","toString","readFileSync","LoaderId","MODULE","LoaderManager","register","test","loader","rules","id","findLoader","loaders","pluginPath","normalizePath","moduleLoader","startsWith","instance","useLoader","registerLoader","manager"],"mappings":";;;;;;;;;AAAO,SAASA,cAAAA,CAAqEC,GAAM,EAAEC,IAAO,EAAiC;AACjI,IAAA,OAAOC,OAAOC,SAAS,CAACJ,cAAc,CAACK,IAAI,CAACJ,GAAKC,EAAAA,IAAAA,CAAAA,CAAAA;AACrD,CAAC;AAEM,SAASI,iBAAAA,CAAwEL,GAAM,EAAEC,IAAO,EAAgC;AACnI,IAAA,OAAOF,eAAeC,GAAKC,EAAAA,IAAAA,CAAAA,IAAS,OAAOD,GAAG,CAACC,KAAK,KAAK,QAAA,CAAA;AAC7D;;ACNA;;;;;AAKC,IAEM,SAASK,QAASC,CAAAA,IAAa,EAAgC;IAClE,OACI,CAAC,CAACA,IACF,IAAA,OAAOA,SAAS,QAChB,IAAA,CAACC,KAAMC,CAAAA,OAAO,CAACF,IAAAA,CAAAA,CAAAA;AAEvB;;ACHO,SAASG,eAAgBC,CAAAA,CAAU,EAAS;AAC/C,IAAA,IAAIA,aAAaC,KAAO,EAAA;AACpB,QAAA,MAAMD,CAAE,CAAA;KACX;IAED,MAAME,KAAAA,GAAQ,IAAID,KAAM,CAAA,mCAAA,CAAA,CAAA;AAExB,IAAA,IAAIN,SAASK,C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,CAAQ1C,OAAO,CAACpC,aAAchC,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA;AACzC,CAAC;AAEM,SAASuE,QAASvE,CAAAA,KAA2B,EAAQ;AACxD,IAAA,MAAM8G,OAAUF,GAAAA,SAAAA,EAAAA,CAAAA;IAChB,IAAI,OAAO5G,UAAU,QAAU,EAAA;QAC3B,OAAO8G,OAAAA,CAAQrC,WAAW,CAACzE,KAAAA,CAAAA,CAAAA;KAC9B;IAED,OAAO8G,OAAAA,CAAQrC,WAAW,CAACzC,aAAchC,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA;AAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -71,23 +71,9 @@ function handleException(e) {
71
71
  ];
72
72
  }
73
73
 
74
- function buildFilePath(input) {
75
- if (typeof input === 'string') {
76
- return input;
77
- }
78
- if (input.extension) {
79
- return path.join(input.path, input.name) + input.extension;
80
- }
81
- return path.join(input.path, input.name);
82
- }
83
- function buildFilePathWithoutExtension(input) {
84
- let info;
85
- if (typeof input === 'string') {
86
- info = pathToLocatorInfo(input);
87
- } else {
88
- info = input;
89
- }
90
- return path.join(info.path, info.name);
74
+ function isFilePath(input) {
75
+ const extension = path.extname(input);
76
+ return extension && extension !== '';
91
77
  }
92
78
 
93
79
  /*
@@ -106,10 +92,6 @@ function buildLocatorOptions(options) {
106
92
  (_options = options).ignore ?? (_options.ignore = []);
107
93
  return options;
108
94
  }
109
- function isFilePath(input) {
110
- const info = path.parse(input);
111
- return info.ext !== '';
112
- }
113
95
  function pathToLocatorInfo(input, skipResolve) {
114
96
  if (!skipResolve && !path.isAbsolute(input)) {
115
97
  input = path.resolve(process.cwd(), input);
@@ -121,6 +103,27 @@ function pathToLocatorInfo(input, skipResolve) {
121
103
  extension: info.ext
122
104
  };
123
105
  }
106
+ function isLocatorInfo(input) {
107
+ return isObject(input) && typeof input.path === 'string' && typeof input.name === 'string' && typeof input.extension === 'string';
108
+ }
109
+ function buildFilePath(input) {
110
+ if (typeof input === 'string') {
111
+ return input;
112
+ }
113
+ if (input.extension) {
114
+ return path.join(input.path, input.name) + input.extension;
115
+ }
116
+ return path.join(input.path, input.name);
117
+ }
118
+ function buildFilePathWithoutExtension(input) {
119
+ let info;
120
+ if (typeof input === 'string') {
121
+ info = pathToLocatorInfo(input);
122
+ } else {
123
+ info = input;
124
+ }
125
+ return path.join(info.path, info.name);
126
+ }
124
127
 
125
128
  async function locateMany(pattern, options) {
126
129
  options = buildLocatorOptions(options);
@@ -208,12 +211,7 @@ function locateSync(pattern, options) {
208
211
  return undefined;
209
212
  }
210
213
 
211
- /*
212
- * Copyright (c) 2022.
213
- * Author Peter Placzek (tada5hi)
214
- * For the full copyright and license information,
215
- * view the LICENSE file that was distributed with this source code.
216
- */ function isJestRuntimeEnvironment() {
214
+ function isJestRuntimeEnvironment() {
217
215
  return process.env && process.env.JEST_WORKER_ID !== undefined;
218
216
  }
219
217
  function isTsNodeRuntimeEnvironment() {
@@ -221,6 +219,34 @@ function isTsNodeRuntimeEnvironment() {
221
219
  // @ts-ignore
222
220
  return !!process[Symbol.for('ts-node.register.instance')];
223
221
  }
222
+ function getModuleExport(data, filterFn) {
223
+ if (filterFn) {
224
+ const keys = Object.keys(data);
225
+ for(let i = 0; i < keys.length; i++){
226
+ if (filterFn(keys[i], data[keys[i]])) {
227
+ return {
228
+ key: keys[i],
229
+ value: data[keys[i]]
230
+ };
231
+ }
232
+ }
233
+ throw new BaseError('Cannot find specific module export.');
234
+ }
235
+ let value;
236
+ if (hasOwnProperty(data, '__esModule') && // eslint-disable-next-line no-underscore-dangle
237
+ !!data.__esModule && hasOwnProperty(data, 'default')) {
238
+ value = data.default;
239
+ } else {
240
+ value = data;
241
+ }
242
+ if (isObject(value) && hasOwnProperty(value, 'default')) {
243
+ value = value.default;
244
+ }
245
+ return {
246
+ key: 'default',
247
+ value
248
+ };
249
+ }
224
250
 
225
251
  class ModuleLoader {
226
252
  async execute(input) {
@@ -249,38 +275,31 @@ class ModuleLoader {
249
275
  }
250
276
  // ---------------------------------------------------------------------------
251
277
  async load(data, options) {
252
- const locatorInfo = this.buildLocatorInfo(data);
253
278
  options = options || {};
254
- let filePath;
255
- if (options.withExtension) {
256
- filePath = buildFilePath(locatorInfo);
257
- } else {
258
- filePath = buildFilePathWithoutExtension(locatorInfo);
259
- }
260
- if (options.withFilePrefix) {
261
- filePath = pathToFileURL(filePath).href;
262
- }
279
+ const [name, locatorInfo] = this.build(data, options);
263
280
  try {
264
281
  // segmentation fault
265
282
  // issue: https://github.com/nodejs/node/issues/35889
266
283
  if (isJestRuntimeEnvironment()) {
267
284
  // eslint-disable-next-line global-require,import/no-dynamic-require
268
- return require(filePath);
285
+ return require(name);
269
286
  }
270
- return await import(filePath);
287
+ return await import(name);
271
288
  } catch (e) {
272
289
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
273
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
274
- return this.load(locatorInfo, {
275
- ...options,
276
- withExtension: true
277
- });
278
- }
279
- if (!options.withFilePrefix && (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || e.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
280
- return this.load(locatorInfo, {
281
- ...options,
282
- withFilePrefix: true
283
- });
290
+ if (locatorInfo) {
291
+ if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
292
+ return this.load(locatorInfo, {
293
+ ...options,
294
+ withExtension: true
295
+ });
296
+ }
297
+ if (!options.withFilePrefix && (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || e.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
298
+ return this.load(locatorInfo, {
299
+ ...options,
300
+ withFilePrefix: true
301
+ });
302
+ }
284
303
  }
285
304
  throw new BaseError({
286
305
  code: e.code,
@@ -292,24 +311,20 @@ class ModuleLoader {
292
311
  }
293
312
  }
294
313
  loadSync(data, options) {
295
- const locatorInfo = this.buildLocatorInfo(data);
296
314
  options = options || {};
297
- let filePath;
298
- if (options.withExtension) {
299
- filePath = buildFilePath(locatorInfo);
300
- } else {
301
- filePath = buildFilePathWithoutExtension(locatorInfo);
302
- }
315
+ const [name, locatorInfo] = this.build(data, options);
303
316
  try {
304
317
  // eslint-disable-next-line global-require,import/no-dynamic-require
305
- return require(filePath);
318
+ return require(name);
306
319
  } catch (e) {
307
320
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
308
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
309
- return this.loadSync(locatorInfo, {
310
- ...options,
311
- withExtension: true
312
- });
321
+ if (locatorInfo) {
322
+ if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
323
+ return this.loadSync(locatorInfo, {
324
+ ...options,
325
+ withExtension: true
326
+ });
327
+ }
313
328
  }
314
329
  throw new BaseError({
315
330
  code: e.code,
@@ -320,11 +335,31 @@ class ModuleLoader {
320
335
  return handleException(e);
321
336
  }
322
337
  }
323
- buildLocatorInfo(input) {
324
- if (typeof input === 'string') {
325
- return pathToLocatorInfo(input);
338
+ build(data, options) {
339
+ let name;
340
+ let locatorInfo;
341
+ options = options || {};
342
+ if (isLocatorInfo(data) || isFilePath(data)) {
343
+ if (typeof data === 'string') {
344
+ locatorInfo = pathToLocatorInfo(data);
345
+ } else {
346
+ locatorInfo = data;
347
+ }
348
+ if (options.withExtension) {
349
+ name = buildFilePath(locatorInfo);
350
+ } else {
351
+ name = buildFilePathWithoutExtension(locatorInfo);
352
+ }
353
+ if (options.withFilePrefix) {
354
+ name = pathToFileURL(name).href;
355
+ }
356
+ } else {
357
+ name = data;
326
358
  }
327
- return input;
359
+ return [
360
+ name,
361
+ locatorInfo
362
+ ];
328
363
  }
329
364
  constructor(){
330
365
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -526,24 +561,5 @@ function loadSync(input) {
526
561
  return manager.executeSync(buildFilePath(input));
527
562
  }
528
563
 
529
- function getExportItem(data, filterFn) {
530
- if (filterFn) {
531
- const keys = Object.keys(data);
532
- for(let i = 0; i < keys.length; i++){
533
- if (filterFn(keys[i], data[keys[i]])) {
534
- return {
535
- key: keys[i],
536
- value: data[keys[i]]
537
- };
538
- }
539
- }
540
- throw new BaseError('Cannot find specific module export.');
541
- }
542
- return {
543
- key: 'default',
544
- value: hasOwnProperty(data, 'default') ? data.default : data
545
- };
546
- }
547
-
548
- export { JSONLoader, LoaderManager, ModuleLoader, buildFilePath, buildFilePathWithoutExtension, buildLocatorOptions, getExportItem, handleException, hasOwnProperty, hasStringProperty, isFilePath, isJestRuntimeEnvironment, isObject, isTsNodeRuntimeEnvironment, load, loadSync, locate, locateMany, locateManySync, locateSync, pathToLocatorInfo, registerLoader, removeFileNameExtension, toArray };
564
+ export { JSONLoader, LoaderManager, ModuleLoader, buildFilePath, buildFilePathWithoutExtension, buildLocatorOptions, getModuleExport, handleException, hasOwnProperty, hasStringProperty, isFilePath, isJestRuntimeEnvironment, isLocatorInfo, isObject, isTsNodeRuntimeEnvironment, load, loadSync, locate, locateMany, locateManySync, locateSync, pathToLocatorInfo, registerLoader, removeFileNameExtension, toArray };
549
565
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts","../src/loader/utils.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\nimport type { LocatorInfo } from '../locator';\nimport { pathToLocatorInfo } from '../locator';\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport type { 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.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function isFilePath(input: string) {\n const info = path.parse(input);\n return info.ext !== '';\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\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 type { LocatorInfo } from '../../../locator';\nimport { pathToLocatorInfo } from '../../../locator';\nimport {\n buildFilePath, buildFilePathWithoutExtension, handleException, hasStringProperty, isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ScriptFileLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : Promise<unknown> {\n const locatorInfo = this.buildLocatorInfo(data);\n\n options = options || {};\n\n let filePath : string;\n if (options.withExtension) {\n filePath = buildFilePath(locatorInfo);\n } else {\n filePath = buildFilePathWithoutExtension(locatorInfo);\n }\n\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 handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n const locatorInfo = this.buildLocatorInfo(data);\n\n options = options || {};\n\n let filePath : string;\n if (options.withExtension) {\n filePath = buildFilePath(locatorInfo);\n } else {\n filePath = buildFilePathWithoutExtension(locatorInfo);\n }\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 handleException(e);\n }\n }\n\n private buildLocatorInfo(input: LocatorInfo | string) : LocatorInfo {\n if (typeof input === 'string') {\n return pathToLocatorInfo(input);\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath, handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isFilePath, pathToLocatorInfo } from '../locator';\nimport { buildFilePath } from '../utils';\nimport { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { LocatorInfo } from '../locator';\nimport { buildFilePath } from '../utils';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n","/*\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 type { LoaderFilterFn, ScriptFileExportItem } from './built-in';\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"],"names":["input","info","options","name","extension","pattern","absolute","cwd","nodir","ignore","items","output","executeSync","filePath","withExtension","withFilePrefix","code","message","stack","buildLocatorInfo","LoaderId","test","loader","findLoader","instance","manager","value"],"mappings":";;;;;;;;;;;;;;AAAO;AACH;AACJ;AAEO;AACH;AACJ;;ACNA;;;;;AAKC;;AAQD;;ACHO;AACH;AACI;;;AAKJ;AACI;;;AAOA;;;;AAQJ;AACJ;;AClCA;;;;;AAKC;;;AAQO;;;;;;AAcR;;AC3BA;;;;;AAKC;AAGG;AAAuCA;AAAM;AACjD;;ACCO;;;;;;;AASH;AACJ;AAEO;;;AAICC;;;;AAKJ;AACJ;;AChCA;;;;;;AAWO;AACHC;AAEAA;AACAA;AACA;AACIA;;AAGJA;;AAGJ;AAEO;;;AAGP;AAEO;AAIH;AAIIF;;;;;AAOAG;AACAC;AACJ;AACJ;;ACrCO;AAIHF;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;;;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;;;AAIJ;AACJ;;AAGI;;;;AAMR;;AAII;;;;AAKI;;AAGJ;AACI;;;AAIR;;;;AA7HQ;;AACW;AAAO;AAAQ;AAAQ;AAAQ;AAAQ;AAAM;AACpDA;AACJ;AACA;;AACW;AAAQ;AAAEA;AACrB;AACH;AACL;AAsHJ;;AC3IA;AACO;;;;AAKHE;;AAGJ;;ACJO;AACH;;;AAII;;AAGJC;AACJ;AAEO;AACH;;;;;AAMJ;AAEO;AACH;;;;;AAMJ;;AC9BO;AAIH;;AAEI;;;;AAIYC;AACJ;;AAER;;;;;AAOAA;AACJ;AACJ;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/json/module.ts","../src/loader/constants.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts"],"sourcesContent":["export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from './has-property';\nimport { isObject } from './object';\n\nexport function handleException(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n const error = new Error('Can not process thrown exception.');\n\n if (isObject(e)) {\n if (\n hasOwnProperty(e, 'message') &&\n typeof e.message === 'string'\n ) {\n error.message = e.message;\n }\n\n if (\n hasOwnProperty(e, 'stack') &&\n typeof e.stack === 'string'\n ) {\n error.stack = e.stack;\n }\n }\n\n throw error;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\nimport path from 'node:path';\n\nexport function isFilePath(input: string) {\n const extension = path.extname(input);\n return extension && extension !== '';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { isObject, toArray } from '../utils';\nimport type { LocatorInfo, LocatorOptions } from './type';\n\nexport function buildLocatorOptions(options?: Partial<LocatorOptions>) : LocatorOptions {\n options = options || {};\n\n options.path = options.path || [];\n options.path = toArray(options.path);\n if (options.path.length === 0) {\n options.path.push(process.cwd());\n }\n\n options.ignore ??= [];\n\n return options as LocatorOptions;\n}\n\nexport function pathToLocatorInfo(\n input: string,\n skipResolve?: boolean,\n) : LocatorInfo {\n if (\n !skipResolve &&\n !path.isAbsolute(input)\n ) {\n input = path.resolve(process.cwd(), input);\n }\n\n const info = path.parse(input);\n\n return {\n path: info.dir.split('/').join(path.sep),\n name: info.name,\n extension: info.ext,\n };\n}\n\nexport function isLocatorInfo(\n input: unknown,\n) : input is LocatorInfo {\n return isObject(input) &&\n typeof input.path === 'string' &&\n typeof input.name === 'string' &&\n typeof input.extension === 'string';\n}\n\nexport function buildFilePath(input: LocatorInfo | string) {\n if (typeof input === 'string') {\n return input;\n }\n\n if (input.extension) {\n return path.join(input.path, input.name) + input.extension;\n }\n\n return path.join(input.path, input.name);\n}\n\nexport function buildFilePathWithoutExtension(input: LocatorInfo | string) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n return path.join(info.path, info.name);\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { glob } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo[]> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport async function locate(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : Promise<LocatorInfo | undefined> {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = await glob(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { globSync } from 'glob';\nimport type { LocatorInfo, LocatorOptions } from './type';\nimport { buildLocatorOptions, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo[] {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n const items : LocatorInfo[] = [];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n for (let k = 0; k < files.length; k++) {\n items.push(pathToLocatorInfo(files[k] as string, true));\n }\n }\n }\n\n return items;\n}\n\nexport function locateSync(\n pattern: string | string[],\n options?: Partial<LocatorOptions>,\n) : LocatorInfo | undefined {\n options = buildLocatorOptions(options);\n\n const patterns = Array.isArray(pattern) ?\n pattern :\n [pattern];\n\n for (let i = 0; i < patterns.length; i++) {\n for (let j = 0; j < (options as LocatorOptions).path.length; j++) {\n const files = globSync(patterns[i] as string, {\n absolute: true,\n cwd: (options as LocatorOptions).path[j],\n nodir: true,\n ignore: options.ignore,\n });\n\n const element = files.shift();\n if (element) {\n return pathToLocatorInfo(element, true);\n }\n }\n }\n\n return undefined;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport { hasOwnProperty, isObject } from '../../../utils';\nimport type { LoaderFilterFn, ModuleExport } from './type';\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n\nexport function getModuleExport(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ModuleExport {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n let value: any;\n\n if (\n hasOwnProperty(data, '__esModule') &&\n // eslint-disable-next-line no-underscore-dangle\n !!data.__esModule &&\n hasOwnProperty(data, 'default')\n ) {\n value = data.default;\n } else {\n value = data;\n }\n\n if (\n isObject(value) &&\n hasOwnProperty(value, 'default')\n ) {\n value = value.default;\n }\n\n return {\n key: 'default',\n value,\n };\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport {\n buildFilePath,\n buildFilePathWithoutExtension,\n isLocatorInfo,\n pathToLocatorInfo,\n} from '../../../locator';\nimport {\n handleException,\n hasStringProperty, isFilePath,\n isObject,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type { ModuleLoadOptions } from './type';\nimport { isJestRuntimeEnvironment, isTsNodeRuntimeEnvironment } from './utils';\n\nexport class ModuleLoader implements Loader {\n protected jiti : JITI;\n\n constructor() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.jiti = createJITI(undefined, {\n extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n });\n }\n\n async execute(input: string) {\n let output : any;\n\n try {\n output = await this.load(input);\n } catch (e) {\n // jiti + ts-node\n // issue: https://github.com/nuxt/bridge/issues/228\n if (isTsNodeRuntimeEnvironment()) {\n output = this.loadSync(input);\n } else {\n output = this.jiti(input);\n }\n }\n\n return output;\n }\n\n executeSync(input: string) {\n let output : any;\n\n try {\n output = this.loadSync(input);\n } catch (e) {\n output = this.jiti(input);\n }\n\n return output;\n }\n\n // ---------------------------------------------------------------------------\n\n async load(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : Promise<unknown> {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n }\n\n return await import(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleException(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ModuleLoadOptions,\n ) : unknown {\n options = options || {};\n const [name, locatorInfo] = this.build(data, options);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(name);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (locatorInfo) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleException(e);\n }\n }\n\n private build(\n data: LocatorInfo | string,\n options: ModuleLoadOptions,\n ) : [string, LocatorInfo | undefined] {\n let name : string;\n let locatorInfo : LocatorInfo | undefined;\n\n options = options || {};\n\n if (isLocatorInfo(data) || isFilePath(data)) {\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n if (options.withExtension) {\n name = buildFilePath(locatorInfo);\n } else {\n name = buildFilePathWithoutExtension(locatorInfo);\n }\n\n if (options.withFilePrefix) {\n name = pathToFileURL(name).href;\n }\n } else {\n name = data;\n }\n\n return [name, locatorInfo];\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { buildFilePath } from '../../../locator';\nimport { handleException } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildFilePath(input);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleException(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum LoaderId {\n MODULE = 'module',\n JSON = 'json',\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport { buildFilePath, pathToLocatorInfo } from '../locator';\nimport { isFilePath } from '../utils';\nimport { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\n\nexport class LoaderManager implements Loader {\n protected loaders : Record<string, Loader>;\n\n protected rules : Rule[];\n\n constructor() {\n this.loaders = {};\n this.rules = [\n {\n test: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'],\n loader: LoaderId.MODULE,\n },\n {\n test: ['.json'], loader: LoaderId.JSON,\n },\n ];\n }\n\n register(rule: Rule) : void;\n\n register(test: string[] | RegExp, loader: Loader) : void;\n\n register(test: any, loader?: Loader) : void {\n if (typeof loader !== 'undefined') {\n this.rules.push({ test, loader });\n return;\n }\n\n this.rules.push(test);\n }\n\n async execute(input: string) : Promise<any> {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: \"${info.extension}\"`);\n }\n\n const loader = this.resolve(id);\n return loader.execute(input);\n }\n\n executeSync(input: string) : any {\n const id = this.findLoader(input);\n if (!id) {\n const info = pathToLocatorInfo(input);\n throw new Error(`No loader registered for extension: ${info.extension || 'unknown'}`);\n }\n\n const loader = this.resolve(id);\n return loader.executeSync(input);\n }\n\n findLoader(input: string) : Loader | string | undefined {\n if (!isFilePath(input)) {\n return LoaderId.MODULE;\n }\n\n const info = pathToLocatorInfo(input);\n for (let i = 0; i < this.rules.length; i++) {\n const { test } = this.rules[i] as Rule;\n if (Array.isArray(test)) {\n if (test.indexOf(info.extension) !== -1) {\n return this.rules[i].loader;\n }\n } else if (test.test(buildFilePath(info))) {\n return this.rules[i].loader;\n }\n }\n\n return undefined;\n }\n\n /**\n * Resolve loader by id.\n *\n * @param id\n */\n resolve(id: string | Loader) : Loader {\n if (typeof id !== 'string') {\n return id;\n }\n\n if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n return this.loaders[id] as Loader;\n }\n\n let loader : Loader | undefined;\n\n // built-in\n switch (id) {\n case LoaderId.MODULE: {\n loader = new ModuleLoader();\n break;\n }\n case LoaderId.JSON: {\n loader = new JSONLoader();\n break;\n }\n /* istanbul ignore next */\n default: {\n const pluginPath = this.normalizePath(id);\n const moduleLoader = this.resolve(LoaderId.MODULE);\n loader = moduleLoader.executeSync(pluginPath);\n\n break;\n }\n }\n\n if (typeof loader !== 'undefined') {\n this.loaders[id] = loader;\n\n return loader;\n }\n\n throw new Error(`The loader ${id} could not be resolved.`);\n }\n\n /* istanbul ignore next */\n normalizePath(input: string) {\n if (path.isAbsolute(input) || input.startsWith('./')) {\n return input;\n }\n\n if (input.startsWith('module:')) {\n return input.substring(0, 'module:'.length);\n }\n\n if (!input.startsWith('@')) {\n return `@locter/${input}`;\n }\n\n return input;\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { LoaderManager } from './module';\n\nlet instance : LoaderManager;\nexport function useLoader() {\n if (typeof instance !== 'undefined') {\n return instance;\n }\n\n instance = new LoaderManager();\n\n return instance;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildFilePath } from '../locator';\nimport type { LocatorInfo } from '../locator';\nimport { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\n\nexport function registerLoader(rule: Rule) : void;\nexport function registerLoader(test: string[] | RegExp, loader: Loader) : void;\nexport function registerLoader(test: any, loader?: Loader) : void {\n const manager = useLoader();\n if (typeof loader !== 'undefined') {\n manager.register(test, loader);\n\n return;\n }\n\n manager.register(test);\n}\n\nexport async function load(input: LocatorInfo | string) : Promise<any> {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.execute(input);\n }\n\n return manager.execute(buildFilePath(input));\n}\n\nexport function loadSync(input: LocatorInfo | string) : any {\n const manager = useLoader();\n if (typeof input === 'string') {\n return manager.executeSync(input);\n }\n\n return manager.executeSync(buildFilePath(input));\n}\n"],"names":["input","options","name","extension","info","pattern","absolute","cwd","nodir","ignore","items","value","output","executeSync","withExtension","withFilePrefix","code","message","stack","locatorInfo","LoaderId","test","loader","findLoader","instance","manager"],"mappings":";;;;;;;;;;;;;;AAAO;AACH;AACJ;AAEO;AACH;AACJ;;ACNA;;;;;AAKC;;AAQD;;ACHO;AACH;AACI;;;AAKJ;AACI;;;AAOA;;;;AAQJ;AACJ;;AClCA;;;;;AAKC;;;AAQO;;;;;;AAcR;;AC3BA;;;;;AAKC;AAGG;AAAuCA;AAAM;AACjD;;ACDO;;AAEH;AACJ;;ACXA;;;;;;AAWO;AACHC;AAEAA;AACAA;AACA;AACIA;;AAGJA;;AAGJ;AAEO;AAIH;AAIID;;;;;AAOAE;AACAC;AACJ;AACJ;AAEO;AAGH;AAIJ;AAEO;;;;;;;AASH;AACJ;AAEO;;;AAICC;;;;AAKJ;AACJ;;ACjEO;AAIHH;AAEA;AAEKI;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHT;AAEA;AAEKI;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;AACJ;;AAGJ;;ACzDO;AAIHR;AAEA;AAEKI;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHT;AAEA;AAEKI;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;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AACpDA;AACJ;AACA;;AACW;AAAQ;AAAEA;AACrB;AACH;AACL;AAsHJ;;AC3IA;AACO;;;;AAKHE;;AAGJ;;ACJO;AACH;;;AAII;;AAGJC;AACJ;AAEO;AACH;;;;;AAMJ;AAEO;AACH;;;;;AAMJ;;"}
@@ -1,13 +1,13 @@
1
1
  import type { JITI } from 'jiti';
2
2
  import type { LocatorInfo } from '../../../locator';
3
3
  import type { Loader } from '../../type';
4
- import type { ScriptFileLoadOptions } from './type';
4
+ import type { ModuleLoadOptions } from './type';
5
5
  export declare class ModuleLoader implements Loader {
6
6
  protected jiti: JITI;
7
7
  constructor();
8
8
  execute(input: string): Promise<any>;
9
9
  executeSync(input: string): any;
10
- load(data: LocatorInfo | string, options?: ScriptFileLoadOptions): Promise<unknown>;
11
- loadSync(data: LocatorInfo | string, options?: ScriptFileLoadOptions): unknown;
12
- private buildLocatorInfo;
10
+ load(data: LocatorInfo | string, options?: ModuleLoadOptions): Promise<unknown>;
11
+ loadSync(data: LocatorInfo | string, options?: ModuleLoadOptions): unknown;
12
+ private build;
13
13
  }
@@ -1,9 +1,9 @@
1
1
  export type LoaderFilterFn = (key: string, value: unknown) => boolean;
2
- export type ScriptFileExportItem = {
2
+ export type ModuleExport = {
3
3
  key: string;
4
- value: unknown;
4
+ value: any;
5
5
  };
6
- export type ScriptFileLoadOptions = {
6
+ export type ModuleLoadOptions = {
7
7
  withExtension?: boolean;
8
8
  withFilePrefix?: boolean;
9
9
  };
@@ -1,2 +1,4 @@
1
+ import type { LoaderFilterFn, ModuleExport } from './type';
1
2
  export declare function isJestRuntimeEnvironment(): boolean;
2
3
  export declare function isTsNodeRuntimeEnvironment(): boolean;
4
+ export declare function getModuleExport(data: Record<string, any>, filterFn?: LoaderFilterFn): ModuleExport;
@@ -1,4 +1,3 @@
1
1
  export * from './built-in';
2
2
  export * from './helpers';
3
3
  export * from './module';
4
- export * from './utils';
@@ -1,4 +1,6 @@
1
1
  import type { LocatorInfo, LocatorOptions } from './type';
2
2
  export declare function buildLocatorOptions(options?: Partial<LocatorOptions>): LocatorOptions;
3
- export declare function isFilePath(input: string): boolean;
4
3
  export declare function pathToLocatorInfo(input: string, skipResolve?: boolean): LocatorInfo;
4
+ export declare function isLocatorInfo(input: unknown): input is LocatorInfo;
5
+ export declare function buildFilePath(input: LocatorInfo | string): string;
6
+ export declare function buildFilePathWithoutExtension(input: LocatorInfo | string): string;
@@ -1,3 +1 @@
1
- import type { LocatorInfo } from '../locator';
2
- export declare function buildFilePath(input: LocatorInfo | string): string;
3
- export declare function buildFilePathWithoutExtension(input: LocatorInfo | string): string;
1
+ export declare function isFilePath(input: string): boolean | "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locter",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "A library to locate a file/module by criteria and load it!",
5
5
  "author": {
6
6
  "name": "Peter Placzek",
@@ -57,20 +57,20 @@
57
57
  "@semantic-release/github": "^8.0.7",
58
58
  "@semantic-release/npm": "^9.0.1",
59
59
  "@semantic-release/release-notes-generator": "^10.0.3",
60
- "@swc/core": "^1.3.37",
60
+ "@swc/core": "^1.3.38",
61
61
  "@swc/jest": "^0.2.24",
62
62
  "@tada5hi/commitlint-config": "^1.0.0",
63
63
  "@tada5hi/eslint-config-typescript": "^1.1.4",
64
64
  "@tada5hi/tsconfig": "^0.4.0",
65
65
  "@types/jest": "^27.5.2",
66
- "@types/node": "^18.14.5",
66
+ "@types/node": "^18.14.6",
67
67
  "cross-env": "^7.0.3",
68
68
  "eslint": "^8.35.0",
69
69
  "husky": "^8.0.3",
70
70
  "jest": "^27.5.1",
71
71
  "magic-string": "^0.30.0",
72
72
  "mlly": "^1.1.1",
73
- "rimraf": "^4.2.0",
73
+ "rimraf": "^4.4.0",
74
74
  "rollup": "^3.18.0",
75
75
  "semantic-release": "^19.0.5",
76
76
  "sourcemap-codec": "^1.4.8",
@@ -79,6 +79,6 @@
79
79
  "dependencies": {
80
80
  "ebec": "^0.2.1",
81
81
  "glob": "^9.0.1",
82
- "jiti": "^1.17.1"
82
+ "jiti": "^1.17.2"
83
83
  }
84
84
  }
@@ -1,2 +0,0 @@
1
- import type { LoaderFilterFn, ScriptFileExportItem } from './built-in';
2
- export declare function getExportItem(data: Record<string, any>, filterFn?: LoaderFilterFn): ScriptFileExportItem;