locter 1.0.6 → 1.0.8

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
@@ -7,19 +7,36 @@ var glob = require('glob');
7
7
  var path = require('node:path');
8
8
  var fs = require('node:fs');
9
9
 
10
+ function hasOwnProperty(obj, prop) {
11
+ return Object.prototype.hasOwnProperty.call(obj, prop);
12
+ }
13
+ function hasStringProperty(obj, prop) {
14
+ return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';
15
+ }
16
+
10
17
  /*
11
18
  * Copyright (c) 2022.
12
19
  * Author Peter Placzek (tada5hi)
13
20
  * For the full copyright and license information,
14
21
  * view the LICENSE file that was distributed with this source code.
15
- */ /* istanbul ignore next */ function handleFileLoadError(e) {
22
+ */ function isObject(item) {
23
+ return !!item && typeof item === 'object' && !Array.isArray(item);
24
+ }
25
+
26
+ function handleException(e) {
16
27
  if (e instanceof Error) {
17
28
  throw e;
18
29
  }
19
- if (typeof e === 'string') {
20
- throw new Error(e);
30
+ const error = new Error('Can not process thrown exception.');
31
+ if (isObject(e)) {
32
+ if (hasOwnProperty(e, 'message') && typeof e.message === 'string') {
33
+ error.message = e.message;
34
+ }
35
+ if (hasOwnProperty(e, 'stack') && typeof e.stack === 'string') {
36
+ error.stack = e.stack;
37
+ }
21
38
  }
22
- throw new Error('Cannot determine file loading error.');
39
+ throw error;
23
40
  }
24
41
 
25
42
  /*
@@ -38,22 +55,6 @@ var fs = require('node:fs');
38
55
  return input;
39
56
  }
40
57
 
41
- function hasOwnProperty(obj, prop) {
42
- return Object.prototype.hasOwnProperty.call(obj, prop);
43
- }
44
- function hasStringProperty(obj, prop) {
45
- return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';
46
- }
47
-
48
- /*
49
- * Copyright (c) 2022.
50
- * Author Peter Placzek (tada5hi)
51
- * For the full copyright and license information,
52
- * view the LICENSE file that was distributed with this source code.
53
- */ function isObject(item) {
54
- return !!item && typeof item === 'object' && !Array.isArray(item);
55
- }
56
-
57
58
  /*
58
59
  * Copyright (c) 2022.
59
60
  * Author Peter Placzek (tada5hi)
@@ -65,6 +66,11 @@ function hasStringProperty(obj, prop) {
65
66
  ];
66
67
  }
67
68
 
69
+ function isFilePath(input) {
70
+ const extension = path.extname(input);
71
+ return extension && extension !== '';
72
+ }
73
+
68
74
  /*
69
75
  * Copyright (c) 2022.
70
76
  * Author Peter Placzek (tada5hi)
@@ -81,10 +87,6 @@ function buildLocatorOptions(options) {
81
87
  (_options = options).ignore ?? (_options.ignore = []);
82
88
  return options;
83
89
  }
84
- function isFilePath(input) {
85
- const info = path.parse(input);
86
- return info.ext !== '';
87
- }
88
90
  function pathToLocatorInfo(input, skipResolve) {
89
91
  if (!skipResolve && !path.isAbsolute(input)) {
90
92
  input = path.resolve(process.cwd(), input);
@@ -96,6 +98,27 @@ function pathToLocatorInfo(input, skipResolve) {
96
98
  extension: info.ext
97
99
  };
98
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
+ }
99
122
 
100
123
  async function locateMany(pattern, options) {
101
124
  options = buildLocatorOptions(options);
@@ -183,37 +206,6 @@ function locateSync(pattern, options) {
183
206
  return undefined;
184
207
  }
185
208
 
186
- function buildLoaderFilePath(input, withExtension) {
187
- let info;
188
- if (typeof input === 'string') {
189
- info = pathToLocatorInfo(input);
190
- } else {
191
- info = input;
192
- }
193
- if (withExtension && info.extension) {
194
- return path.join(info.path, info.name) + info.extension;
195
- }
196
- return path.join(info.path, info.name);
197
- }
198
- function getExportItem(data, filterFn) {
199
- if (filterFn) {
200
- const keys = Object.keys(data);
201
- for(let i = 0; i < keys.length; i++){
202
- if (filterFn(keys[i], data[keys[i]])) {
203
- return {
204
- key: keys[i],
205
- value: data[keys[i]]
206
- };
207
- }
208
- }
209
- throw new ebec.BaseError('Cannot find specific module export.');
210
- }
211
- return {
212
- key: 'default',
213
- value: hasOwnProperty(data, 'default') ? data.default : data
214
- };
215
- }
216
-
217
209
  /*
218
210
  * Copyright (c) 2022.
219
211
  * Author Peter Placzek (tada5hi)
@@ -255,38 +247,31 @@ class ModuleLoader {
255
247
  }
256
248
  // ---------------------------------------------------------------------------
257
249
  async load(data, options) {
258
- let locatorInfo;
259
- if (typeof data === 'string') {
260
- locatorInfo = pathToLocatorInfo(data);
261
- } else {
262
- locatorInfo = data;
263
- }
264
250
  options = options || {};
265
- let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
266
- if (options.withFilePrefix) {
267
- filePath = node_url.pathToFileURL(filePath).href;
268
- }
251
+ const [name, locatorInfo] = this.build(data, options);
269
252
  try {
270
253
  // segmentation fault
271
254
  // issue: https://github.com/nodejs/node/issues/35889
272
255
  if (isJestRuntimeEnvironment()) {
273
256
  // eslint-disable-next-line global-require,import/no-dynamic-require
274
- return require(filePath);
257
+ return require(name);
275
258
  }
276
- return await import(filePath);
259
+ return await import(name);
277
260
  } catch (e) {
278
261
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
279
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
280
- return this.load(locatorInfo, {
281
- ...options,
282
- withExtension: true
283
- });
284
- }
285
- if (!options.withFilePrefix && (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || e.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
286
- return this.load(locatorInfo, {
287
- ...options,
288
- withFilePrefix: true
289
- });
262
+ if (locatorInfo) {
263
+ if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
264
+ return this.load(locatorInfo, {
265
+ ...options,
266
+ withExtension: true
267
+ });
268
+ }
269
+ if (!options.withFilePrefix && (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || e.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
270
+ return this.load(locatorInfo, {
271
+ ...options,
272
+ withFilePrefix: true
273
+ });
274
+ }
290
275
  }
291
276
  throw new ebec.BaseError({
292
277
  code: e.code,
@@ -294,28 +279,24 @@ class ModuleLoader {
294
279
  stack: hasStringProperty(e, 'stack') ? e.stack : undefined
295
280
  });
296
281
  }
297
- /* istanbul ignore next */ return handleFileLoadError(e);
282
+ /* istanbul ignore next */ return handleException(e);
298
283
  }
299
284
  }
300
285
  loadSync(data, options) {
301
- let locatorInfo;
302
- if (typeof data === 'string') {
303
- locatorInfo = pathToLocatorInfo(data);
304
- } else {
305
- locatorInfo = data;
306
- }
307
286
  options = options || {};
308
- const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
287
+ const [name, locatorInfo] = this.build(data, options);
309
288
  try {
310
289
  // eslint-disable-next-line global-require,import/no-dynamic-require
311
- return require(filePath);
290
+ return require(name);
312
291
  } catch (e) {
313
292
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
314
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
315
- return this.loadSync(locatorInfo, {
316
- ...options,
317
- withExtension: true
318
- });
293
+ if (locatorInfo) {
294
+ if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
295
+ return this.loadSync(locatorInfo, {
296
+ ...options,
297
+ withExtension: true
298
+ });
299
+ }
319
300
  }
320
301
  throw new ebec.BaseError({
321
302
  code: e.code,
@@ -323,9 +304,35 @@ class ModuleLoader {
323
304
  stack: hasStringProperty(e, 'stack') ? e.stack : undefined
324
305
  });
325
306
  }
326
- return handleFileLoadError(e);
307
+ return handleException(e);
327
308
  }
328
309
  }
310
+ build(data, options) {
311
+ let name;
312
+ let locatorInfo;
313
+ options = options || {};
314
+ if (isLocatorInfo(data) || isFilePath(data)) {
315
+ if (typeof data === 'string') {
316
+ locatorInfo = pathToLocatorInfo(data);
317
+ } else {
318
+ locatorInfo = data;
319
+ }
320
+ if (options.withExtension) {
321
+ name = buildFilePath(locatorInfo);
322
+ } else {
323
+ name = buildFilePathWithoutExtension(locatorInfo);
324
+ }
325
+ if (options.withFilePrefix) {
326
+ name = node_url.pathToFileURL(name).href;
327
+ }
328
+ } else {
329
+ name = data;
330
+ }
331
+ return [
332
+ name,
333
+ locatorInfo
334
+ ];
335
+ }
329
336
  constructor(){
330
337
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
331
338
  // @ts-ignore
@@ -344,21 +351,21 @@ class ModuleLoader {
344
351
 
345
352
  class JSONLoader {
346
353
  async execute(input) {
347
- const filePath = buildLoaderFilePath(input, true);
354
+ const filePath = buildFilePath(input);
348
355
  try {
349
356
  const file = await fs.promises.readFile(filePath);
350
357
  return JSON.parse(file.toString('utf-8'));
351
358
  } catch (e) {
352
- return handleFileLoadError(e);
359
+ return handleException(e);
353
360
  }
354
361
  }
355
362
  executeSync(input) {
356
- const filePath = buildLoaderFilePath(input, true);
363
+ const filePath = buildFilePath(input);
357
364
  try {
358
365
  const file = fs.readFileSync(filePath);
359
366
  return JSON.parse(file.toString('utf-8'));
360
367
  } catch (e) {
361
- return handleFileLoadError(e);
368
+ return handleException(e);
362
369
  }
363
370
  }
364
371
  }
@@ -414,7 +421,7 @@ class LoaderManager {
414
421
  if (test.indexOf(info.extension) !== -1) {
415
422
  return this.rules[i].loader;
416
423
  }
417
- } else if (test.test(buildLoaderFilePath(info))) {
424
+ } else if (test.test(buildFilePath(info))) {
418
425
  return this.rules[i].loader;
419
426
  }
420
427
  }
@@ -516,27 +523,48 @@ async function load(input) {
516
523
  if (typeof input === 'string') {
517
524
  return manager.execute(input);
518
525
  }
519
- return manager.execute(buildLoaderFilePath(input, true));
526
+ return manager.execute(buildFilePath(input));
520
527
  }
521
528
  function loadSync(input) {
522
529
  const manager = useLoader();
523
530
  if (typeof input === 'string') {
524
531
  return manager.executeSync(input);
525
532
  }
526
- return manager.executeSync(buildLoaderFilePath(input, true));
533
+ return manager.executeSync(buildFilePath(input));
534
+ }
535
+
536
+ function getExportItem(data, filterFn) {
537
+ if (filterFn) {
538
+ const keys = Object.keys(data);
539
+ for(let i = 0; i < keys.length; i++){
540
+ if (filterFn(keys[i], data[keys[i]])) {
541
+ return {
542
+ key: keys[i],
543
+ value: data[keys[i]]
544
+ };
545
+ }
546
+ }
547
+ throw new ebec.BaseError('Cannot find specific module export.');
548
+ }
549
+ return {
550
+ key: 'default',
551
+ value: hasOwnProperty(data, 'default') ? data.default : data
552
+ };
527
553
  }
528
554
 
529
555
  exports.JSONLoader = JSONLoader;
530
556
  exports.LoaderManager = LoaderManager;
531
557
  exports.ModuleLoader = ModuleLoader;
532
- exports.buildLoaderFilePath = buildLoaderFilePath;
558
+ exports.buildFilePath = buildFilePath;
559
+ exports.buildFilePathWithoutExtension = buildFilePathWithoutExtension;
533
560
  exports.buildLocatorOptions = buildLocatorOptions;
534
561
  exports.getExportItem = getExportItem;
535
- exports.handleFileLoadError = handleFileLoadError;
562
+ exports.handleException = handleException;
536
563
  exports.hasOwnProperty = hasOwnProperty;
537
564
  exports.hasStringProperty = hasStringProperty;
538
565
  exports.isFilePath = isFilePath;
539
566
  exports.isJestRuntimeEnvironment = isJestRuntimeEnvironment;
567
+ exports.isLocatorInfo = isLocatorInfo;
540
568
  exports.isObject = isObject;
541
569
  exports.isTsNodeRuntimeEnvironment = isTsNodeRuntimeEnvironment;
542
570
  exports.load = load;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/to-array.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/utils.ts","../src/loader/built-in/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":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/* istanbul ignore next */\nexport function handleFileLoadError(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n if (typeof e === 'string') {\n throw new Error(e);\n }\n\n throw new Error('Cannot determine file loading error.');\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport 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\nimport { BaseError } from 'ebec';\nimport path from 'node:path';\nimport type { LocatorInfo } from '../locator';\nimport { pathToLocatorInfo } from '../locator';\nimport { hasOwnProperty } from '../utils';\nimport type { LoaderFilterFn, ScriptFileExportItem } from './built-in';\n\nexport function buildLoaderFilePath(input: LocatorInfo | string, withExtension?: boolean) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n if (\n withExtension &&\n info.extension\n ) {\n return path.join(info.path, info.name) + info.extension;\n }\n\n return path.join(info.path, info.name);\n}\n\nexport function getExportItem(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ScriptFileExportItem {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n return {\n key: 'default',\n value: hasOwnProperty(data, 'default') ? data.default : data,\n };\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport { pathToLocatorInfo } from '../../../locator';\nimport { handleFileLoadError, hasStringProperty, isObject } from '../../../utils';\nimport type { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\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 let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n if (options.withFilePrefix) {\n filePath = pathToFileURL(filePath).href;\n }\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n }\n\n return await import(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleFileLoadError(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleFileLoadError(e);\n }\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { handleFileLoadError } from '../../../utils';\nimport type { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\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 { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\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(buildLoaderFilePath(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 { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\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(buildLoaderFilePath(input, true));\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(buildLoaderFilePath(input, true));\n}\n"],"names":["handleFileLoadError","e","Error","removeFileNameExtension","input","extensions","includes","position","lastIndexOf","extension","substring","length","indexOf","hasOwnProperty","obj","prop","Object","prototype","call","hasStringProperty","isObject","item","Array","isArray","toArray","options","buildLocatorOptions","path","push","process","cwd","ignore","isFilePath","info","parse","ext","pathToLocatorInfo","skipResolve","isAbsolute","resolve","dir","split","join","sep","name","locateMany","pattern","patterns","items","i","j","files","glob","absolute","nodir","k","locate","element","shift","undefined","locateManySync","globSync","locateSync","buildLoaderFilePath","withExtension","getExportItem","data","filterFn","keys","key","value","BaseError","default","isJestRuntimeEnvironment","env","JEST_WORKER_ID","isTsNodeRuntimeEnvironment","Symbol","for","ModuleLoader","execute","output","load","loadSync","jiti","executeSync","locatorInfo","filePath","withFilePrefix","pathToFileURL","href","require","code","message","stack","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"],"mappings":";;;;;;;;;AAAA;;;;;AAKC,+BAGM,SAASA,mBAAAA,CAAoBC,CAAU,EAAS;AACnD,IAAA,IAAIA,aAAaC,KAAO,EAAA;AACpB,Q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EAAAA,MAAAA,CAAAA,CAAAA;AAEvB,QAAA,OAAA;KACH;AAEDY,IAAAA,OAAAA,CAAQd,QAAQ,CAACC,IAAAA,CAAAA,CAAAA;AACrB,CAAC;AAEM,eAAe3B,IAAK9E,CAAAA,KAA2B,EAAiB;AACnE,IAAA,MAAMsH,OAAUF,GAAAA,SAAAA,EAAAA,CAAAA;IAChB,IAAI,OAAOpH,UAAU,QAAU,EAAA;QAC3B,OAAOsH,OAAAA,CAAQ1C,OAAO,CAAC5E,KAAAA,CAAAA,CAAAA;KAC1B;AAED,IAAA,OAAOsH,OAAQ1C,CAAAA,OAAO,CAACjB,mBAAAA,CAAoB3D,OAAO,IAAI,CAAA,CAAA,CAAA;AAC1D,CAAC;AAEM,SAAS+E,QAAS/E,CAAAA,KAA2B,EAAQ;AACxD,IAAA,MAAMsH,OAAUF,GAAAA,SAAAA,EAAAA,CAAAA;IAChB,IAAI,OAAOpH,UAAU,QAAU,EAAA;QAC3B,OAAOsH,OAAAA,CAAQrC,WAAW,CAACjF,KAAAA,CAAAA,CAAAA;KAC9B;AAED,IAAA,OAAOsH,OAAQrC,CAAAA,WAAW,CAACtB,mBAAAA,CAAoB3D,OAAO,IAAI,CAAA,CAAA,CAAA;AAC9D;;;;;;;;;;;;;;;;;;;;;;;;;;"}
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';\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\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 {\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 { 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 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?: ScriptFileLoadOptions,\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: ScriptFileLoadOptions,\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","/*\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","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","ModuleLoader","execute","output","load","loadSync","jiti","executeSync","data","locatorInfo","build","require","withExtension","code","withFilePrefix","BaseError","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","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,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,CAAI,CAAA,EAAA;AACb,QAAA,IACIZ,eAAeY,CAAG,EAAA,SAAA,CAAA,IAClB,OAAOA,CAAEG,CAAAA,OAAO,KAAK,QACvB,EAAA;YACED,KAAMC,CAAAA,OAAO,GAAGH,CAAAA,CAAEG,OAAO,CAAA;SAC5B;AAED,QAAA,IACIf,eAAeY,CAAG,EAAA,OAAA,CAAA,IAClB,OAAOA,CAAEI,CAAAA,KAAK,KAAK,QACrB,EAAA;YACEF,KAAME,CAAAA,KAAK,GAAGJ,CAAAA,CAAEI,KAAK,CAAA;SACxB;KACJ;AAED,IAAA,MAAMF,KAAM,CAAA;AAChB;;AClCA;;;;;AAKC,IAEM,SAASG,uBAAAA,CACZC,KAAa,EACbC,UAAqB,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,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA;AAC7C;;AC9BO,SAASwG,aAAAA,CACZvC,IAAyB,EACzBwC,QAAyB,EACL;AACpB,IAAA,IAAIA,QAAU,EAAA;QACV,MAAMC,IAAAA,GAAOzH,MAAOyH,CAAAA,IAAI,CAACzC,IAAAA,CAAAA,CAAAA;AACzB,QAAA,IAAK,IAAI3B,CAAI,GAAA,CAAA,EAAGA,IAAIoE,IAAKnG,CAAAA,MAAM,EAAE+B,CAAK,EAAA,CAAA;YAClC,IAAImE,QAAAA,CAASC,IAAI,CAACpE,CAAE,CAAA,EAAY2B,IAAI,CAACyC,IAAI,CAACpE,CAAE,CAAA,CAAW,CAAG,EAAA;gBACtD,OAAO;oBACHqE,GAAKD,EAAAA,IAAI,CAACpE,CAAE,CAAA;AACZsE,oBAAAA,KAAAA,EAAO3C,IAAI,CAACyC,IAAI,CAACpE,EAAE,CAAW;AAClC,iBAAA,CAAA;aACH;AACL,SAAA;QAEA,MAAM,IAAIkC,eAAU,qCAAuC,CAAA,CAAA;KAC9D;IAED,OAAO;QACHmC,GAAK,EAAA,SAAA;AACLC,QAAAA,KAAAA,EAAO9H,eAAemF,IAAM,EAAA,SAAA,CAAA,GAAaA,IAAK4C,CAAAA,OAAO,GAAG5C,IAAI;AAChE,KAAA,CAAA;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -12,19 +12,36 @@ import __cjs_mod__ from 'module';
12
12
  const __filename = __cjs_url__.fileURLToPath(import.meta.url);
13
13
  const __dirname = __cjs_path__.dirname(__filename);
14
14
  const require = __cjs_mod__.createRequire(import.meta.url);
15
+ function hasOwnProperty(obj, prop) {
16
+ return Object.prototype.hasOwnProperty.call(obj, prop);
17
+ }
18
+ function hasStringProperty(obj, prop) {
19
+ return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';
20
+ }
21
+
15
22
  /*
16
23
  * Copyright (c) 2022.
17
24
  * Author Peter Placzek (tada5hi)
18
25
  * For the full copyright and license information,
19
26
  * view the LICENSE file that was distributed with this source code.
20
- */ /* istanbul ignore next */ function handleFileLoadError(e) {
27
+ */ function isObject(item) {
28
+ return !!item && typeof item === 'object' && !Array.isArray(item);
29
+ }
30
+
31
+ function handleException(e) {
21
32
  if (e instanceof Error) {
22
33
  throw e;
23
34
  }
24
- if (typeof e === 'string') {
25
- throw new Error(e);
35
+ const error = new Error('Can not process thrown exception.');
36
+ if (isObject(e)) {
37
+ if (hasOwnProperty(e, 'message') && typeof e.message === 'string') {
38
+ error.message = e.message;
39
+ }
40
+ if (hasOwnProperty(e, 'stack') && typeof e.stack === 'string') {
41
+ error.stack = e.stack;
42
+ }
26
43
  }
27
- throw new Error('Cannot determine file loading error.');
44
+ throw error;
28
45
  }
29
46
 
30
47
  /*
@@ -43,22 +60,6 @@ const require = __cjs_mod__.createRequire(import.meta.url);
43
60
  return input;
44
61
  }
45
62
 
46
- function hasOwnProperty(obj, prop) {
47
- return Object.prototype.hasOwnProperty.call(obj, prop);
48
- }
49
- function hasStringProperty(obj, prop) {
50
- return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';
51
- }
52
-
53
- /*
54
- * Copyright (c) 2022.
55
- * Author Peter Placzek (tada5hi)
56
- * For the full copyright and license information,
57
- * view the LICENSE file that was distributed with this source code.
58
- */ function isObject(item) {
59
- return !!item && typeof item === 'object' && !Array.isArray(item);
60
- }
61
-
62
63
  /*
63
64
  * Copyright (c) 2022.
64
65
  * Author Peter Placzek (tada5hi)
@@ -70,6 +71,11 @@ function hasStringProperty(obj, prop) {
70
71
  ];
71
72
  }
72
73
 
74
+ function isFilePath(input) {
75
+ const extension = path.extname(input);
76
+ return extension && extension !== '';
77
+ }
78
+
73
79
  /*
74
80
  * Copyright (c) 2022.
75
81
  * Author Peter Placzek (tada5hi)
@@ -86,10 +92,6 @@ function buildLocatorOptions(options) {
86
92
  (_options = options).ignore ?? (_options.ignore = []);
87
93
  return options;
88
94
  }
89
- function isFilePath(input) {
90
- const info = path.parse(input);
91
- return info.ext !== '';
92
- }
93
95
  function pathToLocatorInfo(input, skipResolve) {
94
96
  if (!skipResolve && !path.isAbsolute(input)) {
95
97
  input = path.resolve(process.cwd(), input);
@@ -101,6 +103,27 @@ function pathToLocatorInfo(input, skipResolve) {
101
103
  extension: info.ext
102
104
  };
103
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
+ }
104
127
 
105
128
  async function locateMany(pattern, options) {
106
129
  options = buildLocatorOptions(options);
@@ -188,37 +211,6 @@ function locateSync(pattern, options) {
188
211
  return undefined;
189
212
  }
190
213
 
191
- function buildLoaderFilePath(input, withExtension) {
192
- let info;
193
- if (typeof input === 'string') {
194
- info = pathToLocatorInfo(input);
195
- } else {
196
- info = input;
197
- }
198
- if (withExtension && info.extension) {
199
- return path.join(info.path, info.name) + info.extension;
200
- }
201
- return path.join(info.path, info.name);
202
- }
203
- function getExportItem(data, filterFn) {
204
- if (filterFn) {
205
- const keys = Object.keys(data);
206
- for(let i = 0; i < keys.length; i++){
207
- if (filterFn(keys[i], data[keys[i]])) {
208
- return {
209
- key: keys[i],
210
- value: data[keys[i]]
211
- };
212
- }
213
- }
214
- throw new BaseError('Cannot find specific module export.');
215
- }
216
- return {
217
- key: 'default',
218
- value: hasOwnProperty(data, 'default') ? data.default : data
219
- };
220
- }
221
-
222
214
  /*
223
215
  * Copyright (c) 2022.
224
216
  * Author Peter Placzek (tada5hi)
@@ -260,38 +252,31 @@ class ModuleLoader {
260
252
  }
261
253
  // ---------------------------------------------------------------------------
262
254
  async load(data, options) {
263
- let locatorInfo;
264
- if (typeof data === 'string') {
265
- locatorInfo = pathToLocatorInfo(data);
266
- } else {
267
- locatorInfo = data;
268
- }
269
255
  options = options || {};
270
- let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
271
- if (options.withFilePrefix) {
272
- filePath = pathToFileURL(filePath).href;
273
- }
256
+ const [name, locatorInfo] = this.build(data, options);
274
257
  try {
275
258
  // segmentation fault
276
259
  // issue: https://github.com/nodejs/node/issues/35889
277
260
  if (isJestRuntimeEnvironment()) {
278
261
  // eslint-disable-next-line global-require,import/no-dynamic-require
279
- return require(filePath);
262
+ return require(name);
280
263
  }
281
- return await import(filePath);
264
+ return await import(name);
282
265
  } catch (e) {
283
266
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
284
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
285
- return this.load(locatorInfo, {
286
- ...options,
287
- withExtension: true
288
- });
289
- }
290
- if (!options.withFilePrefix && (e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' || e.code === 'UNSUPPORTED_ESM_URL_SCHEME')) {
291
- return this.load(locatorInfo, {
292
- ...options,
293
- withFilePrefix: true
294
- });
267
+ if (locatorInfo) {
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
+ });
279
+ }
295
280
  }
296
281
  throw new BaseError({
297
282
  code: e.code,
@@ -299,28 +284,24 @@ class ModuleLoader {
299
284
  stack: hasStringProperty(e, 'stack') ? e.stack : undefined
300
285
  });
301
286
  }
302
- /* istanbul ignore next */ return handleFileLoadError(e);
287
+ /* istanbul ignore next */ return handleException(e);
303
288
  }
304
289
  }
305
290
  loadSync(data, options) {
306
- let locatorInfo;
307
- if (typeof data === 'string') {
308
- locatorInfo = pathToLocatorInfo(data);
309
- } else {
310
- locatorInfo = data;
311
- }
312
291
  options = options || {};
313
- const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);
292
+ const [name, locatorInfo] = this.build(data, options);
314
293
  try {
315
294
  // eslint-disable-next-line global-require,import/no-dynamic-require
316
- return require(filePath);
295
+ return require(name);
317
296
  } catch (e) {
318
297
  /* istanbul ignore next */ if (isObject(e) && hasStringProperty(e, 'code')) {
319
- if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
320
- return this.loadSync(locatorInfo, {
321
- ...options,
322
- withExtension: true
323
- });
298
+ if (locatorInfo) {
299
+ if (!options.withExtension && (e.code === 'ERR_MODULE_NOT_FOUND' || e.code === 'MODULE_NOT_FOUND')) {
300
+ return this.loadSync(locatorInfo, {
301
+ ...options,
302
+ withExtension: true
303
+ });
304
+ }
324
305
  }
325
306
  throw new BaseError({
326
307
  code: e.code,
@@ -328,9 +309,35 @@ class ModuleLoader {
328
309
  stack: hasStringProperty(e, 'stack') ? e.stack : undefined
329
310
  });
330
311
  }
331
- return handleFileLoadError(e);
312
+ return handleException(e);
332
313
  }
333
314
  }
315
+ build(data, options) {
316
+ let name;
317
+ let locatorInfo;
318
+ options = options || {};
319
+ if (isLocatorInfo(data) || isFilePath(data)) {
320
+ if (typeof data === 'string') {
321
+ locatorInfo = pathToLocatorInfo(data);
322
+ } else {
323
+ locatorInfo = data;
324
+ }
325
+ if (options.withExtension) {
326
+ name = buildFilePath(locatorInfo);
327
+ } else {
328
+ name = buildFilePathWithoutExtension(locatorInfo);
329
+ }
330
+ if (options.withFilePrefix) {
331
+ name = pathToFileURL(name).href;
332
+ }
333
+ } else {
334
+ name = data;
335
+ }
336
+ return [
337
+ name,
338
+ locatorInfo
339
+ ];
340
+ }
334
341
  constructor(){
335
342
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
336
343
  // @ts-ignore
@@ -349,21 +356,21 @@ class ModuleLoader {
349
356
 
350
357
  class JSONLoader {
351
358
  async execute(input) {
352
- const filePath = buildLoaderFilePath(input, true);
359
+ const filePath = buildFilePath(input);
353
360
  try {
354
361
  const file = await fs.promises.readFile(filePath);
355
362
  return JSON.parse(file.toString('utf-8'));
356
363
  } catch (e) {
357
- return handleFileLoadError(e);
364
+ return handleException(e);
358
365
  }
359
366
  }
360
367
  executeSync(input) {
361
- const filePath = buildLoaderFilePath(input, true);
368
+ const filePath = buildFilePath(input);
362
369
  try {
363
370
  const file = fs.readFileSync(filePath);
364
371
  return JSON.parse(file.toString('utf-8'));
365
372
  } catch (e) {
366
- return handleFileLoadError(e);
373
+ return handleException(e);
367
374
  }
368
375
  }
369
376
  }
@@ -419,7 +426,7 @@ class LoaderManager {
419
426
  if (test.indexOf(info.extension) !== -1) {
420
427
  return this.rules[i].loader;
421
428
  }
422
- } else if (test.test(buildLoaderFilePath(info))) {
429
+ } else if (test.test(buildFilePath(info))) {
423
430
  return this.rules[i].loader;
424
431
  }
425
432
  }
@@ -521,15 +528,34 @@ async function load(input) {
521
528
  if (typeof input === 'string') {
522
529
  return manager.execute(input);
523
530
  }
524
- return manager.execute(buildLoaderFilePath(input, true));
531
+ return manager.execute(buildFilePath(input));
525
532
  }
526
533
  function loadSync(input) {
527
534
  const manager = useLoader();
528
535
  if (typeof input === 'string') {
529
536
  return manager.executeSync(input);
530
537
  }
531
- return manager.executeSync(buildLoaderFilePath(input, true));
538
+ return manager.executeSync(buildFilePath(input));
539
+ }
540
+
541
+ function getExportItem(data, filterFn) {
542
+ if (filterFn) {
543
+ const keys = Object.keys(data);
544
+ for(let i = 0; i < keys.length; i++){
545
+ if (filterFn(keys[i], data[keys[i]])) {
546
+ return {
547
+ key: keys[i],
548
+ value: data[keys[i]]
549
+ };
550
+ }
551
+ }
552
+ throw new BaseError('Cannot find specific module export.');
553
+ }
554
+ return {
555
+ key: 'default',
556
+ value: hasOwnProperty(data, 'default') ? data.default : data
557
+ };
532
558
  }
533
559
 
534
- export { JSONLoader, LoaderManager, ModuleLoader, buildLoaderFilePath, buildLocatorOptions, getExportItem, handleFileLoadError, hasOwnProperty, hasStringProperty, isFilePath, isJestRuntimeEnvironment, isObject, isTsNodeRuntimeEnvironment, load, loadSync, locate, locateMany, locateManySync, locateSync, pathToLocatorInfo, registerLoader, removeFileNameExtension, toArray };
560
+ export { JSONLoader, LoaderManager, ModuleLoader, buildFilePath, buildFilePathWithoutExtension, buildLocatorOptions, getExportItem, handleException, hasOwnProperty, hasStringProperty, isFilePath, isJestRuntimeEnvironment, isLocatorInfo, isObject, isTsNodeRuntimeEnvironment, load, loadSync, locate, locateMany, locateManySync, locateSync, pathToLocatorInfo, registerLoader, removeFileNameExtension, toArray };
535
561
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/utils/error.ts","../src/utils/file-name.ts","../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/to-array.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/loader/utils.ts","../src/loader/built-in/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":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n/* istanbul ignore next */\nexport function handleFileLoadError(e: unknown) : void {\n if (e instanceof Error) {\n throw e;\n }\n\n if (typeof e === 'string') {\n throw new Error(e);\n }\n\n throw new Error('Cannot determine file loading error.');\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function removeFileNameExtension(\n input: string,\n extensions?: string[],\n) {\n if (input.includes('.')) {\n const position = input.lastIndexOf('.');\n const extension = input.substring(\n position,\n input.length,\n );\n\n if (\n typeof extensions === 'undefined' ||\n extensions.indexOf(extension) !== -1\n ) {\n input = input.substring(0, position);\n }\n }\n\n return input;\n}\n","export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nexport function hasStringProperty<X extends Record<string, any>, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, string> {\n return hasOwnProperty(obj, prop) && typeof obj[prop] === 'string';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(item: unknown) : item is Record<string, any> {\n return (\n !!item &&\n typeof item === 'object' &&\n !Array.isArray(item)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function toArray(input: string | string[]) : string[] {\n return Array.isArray(input) ? input : [input];\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport 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\nimport { BaseError } from 'ebec';\nimport path from 'node:path';\nimport type { LocatorInfo } from '../locator';\nimport { pathToLocatorInfo } from '../locator';\nimport { hasOwnProperty } from '../utils';\nimport type { LoaderFilterFn, ScriptFileExportItem } from './built-in';\n\nexport function buildLoaderFilePath(input: LocatorInfo | string, withExtension?: boolean) {\n let info: LocatorInfo;\n\n if (typeof input === 'string') {\n info = pathToLocatorInfo(input);\n } else {\n info = input;\n }\n\n if (\n withExtension &&\n info.extension\n ) {\n return path.join(info.path, info.name) + info.extension;\n }\n\n return path.join(info.path, info.name);\n}\n\nexport function getExportItem(\n data: Record<string, any>,\n filterFn?: LoaderFilterFn,\n): ScriptFileExportItem {\n if (filterFn) {\n const keys = Object.keys(data);\n for (let i = 0; i < keys.length; i++) {\n if (filterFn(keys[i] as string, data[keys[i] as string])) {\n return {\n key: keys[i] as string,\n value: data[keys[i] as string],\n };\n }\n }\n\n throw new BaseError('Cannot find specific module export.');\n }\n\n return {\n key: 'default',\n value: hasOwnProperty(data, 'default') ? data.default : data,\n };\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isJestRuntimeEnvironment() : boolean {\n return process.env &&\n process.env.JEST_WORKER_ID !== undefined;\n}\n\nexport function isTsNodeRuntimeEnvironment() : boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return !!process[Symbol.for('ts-node.register.instance')];\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BaseError } from 'ebec';\nimport type { JITI } from 'jiti';\nimport createJITI from 'jiti';\nimport { pathToFileURL } from 'node:url';\nimport type { LocatorInfo } from '../../../locator';\nimport { pathToLocatorInfo } from '../../../locator';\nimport { handleFileLoadError, hasStringProperty, isObject } from '../../../utils';\nimport type { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\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 let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n let filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n if (options.withFilePrefix) {\n filePath = pathToFileURL(filePath).href;\n }\n\n try {\n // segmentation fault\n // issue: https://github.com/nodejs/node/issues/35889\n if (isJestRuntimeEnvironment()) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n }\n\n return await import(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n if (\n !options.withFilePrefix &&\n (\n e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n )\n ) {\n return this.load(locatorInfo, {\n ...options,\n withFilePrefix: true,\n });\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n /* istanbul ignore next */\n return handleFileLoadError(e);\n }\n }\n\n loadSync(\n data: LocatorInfo | string,\n options?: ScriptFileLoadOptions,\n ) : unknown {\n let locatorInfo : LocatorInfo;\n\n if (typeof data === 'string') {\n locatorInfo = pathToLocatorInfo(data);\n } else {\n locatorInfo = data;\n }\n\n options = options || {};\n\n const filePath = buildLoaderFilePath(locatorInfo, options.withExtension);\n\n try {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n return require(filePath);\n } catch (e) {\n /* istanbul ignore next */\n if (\n isObject(e) &&\n hasStringProperty(e, 'code')\n ) {\n if (\n !options.withExtension &&\n (\n e.code === 'ERR_MODULE_NOT_FOUND' ||\n e.code === 'MODULE_NOT_FOUND'\n )\n ) {\n return this.loadSync(locatorInfo, {\n ...options,\n withExtension: true,\n });\n }\n\n throw new BaseError({\n code: e.code,\n message: hasStringProperty(e, 'message') ? e.message : undefined,\n stack: hasStringProperty(e, 'stack') ? e.stack : undefined,\n });\n }\n\n return handleFileLoadError(e);\n }\n }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport fs from 'node:fs';\nimport { handleFileLoadError } from '../../../utils';\nimport type { Loader } from '../../type';\nimport { buildLoaderFilePath } from '../../utils';\n\nexport class JSONLoader implements Loader {\n async execute(input: string) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = await fs.promises.readFile(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n\n executeSync(input: string) {\n const filePath = buildLoaderFilePath(input, true);\n\n try {\n const file = fs.readFileSync(filePath);\n return JSON.parse(file.toString('utf-8'));\n } catch (e) {\n return handleFileLoadError(e);\n }\n }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\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 { JSONLoader, ModuleLoader } from './built-in';\nimport { LoaderId } from './constants';\nimport type { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\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(buildLoaderFilePath(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 { useLoader } from './singleton';\nimport type { Loader, Rule } from './type';\nimport { buildLoaderFilePath } from './utils';\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(buildLoaderFilePath(input, true));\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(buildLoaderFilePath(input, true));\n}\n"],"names":["input","options","name","extension","pattern","absolute","cwd","nodir","ignore","items","info","value","output","executeSync","locatorInfo","withExtension","withFilePrefix","code","message","stack","LoaderId","test","loader","findLoader","instance","manager"],"mappings":";;;;;;;;;;;;;;AAAA;;;;;AAKC;AAIG;AACI;;;;;;AAQR;;AClBA;;;;;AAKC;;;AAQO;;;;;;AAcR;;AC3BO;AACH;AACJ;AAEO;AACH;AACJ;;ACNA;;;;;AAKC;;AAQD;;ACbA;;;;;AAKC;AAGG;AAAuCA;AAAM;AACjD;;ACTA;;;;;;AAWO;AACHC;AAEAA;AACAA;AACA;AACIA;;AAGJA;;AAGJ;AAEO;;;AAGP;AAEO;AAIH;AAIID;;;;;AAOAE;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;;;AAGJ;AACJ;;AAGJ;;ACzDO;AAIHP;AAEA;AAEKG;AAAQ;AAEb;AAEA;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;AAEA;AACIC;AACJ;AACJ;AACJ;;AAGJ;AAEO;AAIHR;AAEA;AAEKG;AAAQ;AAEb;;AAEQ;AACIC;AACAC;AACAC;AACAC;AACJ;;AAGA;;;AAGJ;AACJ;;AAGJ;;ACtDO;;;AAICE;;;;;;;AAYJ;AACJ;AAEO;AAIH;;AAEI;;;;AAIYC;AACJ;;AAER;;;;;AAOAA;AACJ;AACJ;;ACvDA;;;;;;AAQI;AAEJ;AAEO;;;AAGH;AACJ;;ACGO;;;;AAeKC;AACJ;;;AAGI;;;;;AAKJ;;AAGJ;AAEAC;;;;AAKI;;AAEA;;AAGJ;;AAIA;;;AAOQC;;;;AAKJb;AAEA;;;;;;;AAQI;;AAEI;;;AAIR;AACI;AAKI;AAOI;AACI;AACAc;AACJ;;AAGJ;AAOI;AACI;AACAC;AACJ;;AAGJ;AACIC;AACAC;AACAC;;;;AAMZ;AACJ;;;;AASQL;;;;AAKJb;AAEA;;;AAII;AACJ;AACI;AAKI;AAOI;AACI;AACAc;AACJ;;AAGJ;AACIE;AACAC;AACAC;;;AAIR;AACJ;AACJ;;;;AA5JI;;AACiB;AAAO;AAAQ;AAAQ;AAAQ;AAAQ;AAAM;AAC9D;AACJ;AA0JJ;;AC1KO;;;;AAKK;AACA;AACJ;AACI;AACJ;AACJ;AAEAN;;;;AAKQ;AACJ;AACI;AACJ;AACJ;AACJ;;AClCA;;;;;;;AAOYO;AAAAA;;;ACOL;;;AAwBK;AAAkBC;AAAMC;AAAO;AAC/B;;AAGJ;AACJ;;AAGI;AACA;AACI;;;AAIJ;;AAEJ;AAEAT;AACI;AACA;AACI;;;AAIJ;;AAEJ;AAEAU;;AAEQ;;AAGJ;;;;AAIQ;AACI;;AAER;AACI;;AAER;;AAGJ;AAEA;;;;;;;;;AAWQ;;;;;AAOA;AAAsB;AAClBD;;AAEJ;AACA;AAAoB;AAChBA;;AAEJ;AACA;AACS;AACL;AACA;;;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;;;;AAKA;AACJ;AAEO;AACH;;;;AAKA;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","../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';\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\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 {\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 { 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 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?: ScriptFileLoadOptions,\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: ScriptFileLoadOptions,\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","/*\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","options","name","extension","info","pattern","absolute","cwd","nodir","ignore","items","output","executeSync","withExtension","withFilePrefix","code","message","stack","locatorInfo","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;;ACDO;;AAEH;AACJ;;ACXA;;;;;;AAWO;AACHC;AAEAA;AACAA;AACA;AACIA;;AAGJA;;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J;AACI;AACJ;AACJ;AACJ;;AClCA;;;;;;;AAOYO;AAAAA;;;ACOL;;;AAwBK;AAAkBC;AAAMC;AAAO;AAC/B;;AAGJ;AACJ;;AAGI;AACA;AACI;;;AAIJ;;AAEJ;AAEAT;AACI;AACA;AACI;;;AAIJ;;AAEJ;AAEAU;;AAEQ;;AAGJ;;;;AAIQ;AACI;;AAER;AACI;;AAER;;AAGJ;AAEA;;;;;;;;;AAWQ;;;;;AAOA;AAAsB;AAClBD;;AAEJ;AACA;AAAoB;AAChBA;;AAEJ;AACA;AACS;AACL;AACA;;;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;;"}
@@ -9,4 +9,5 @@ export declare class ModuleLoader implements Loader {
9
9
  executeSync(input: string): any;
10
10
  load(data: LocatorInfo | string, options?: ScriptFileLoadOptions): Promise<unknown>;
11
11
  loadSync(data: LocatorInfo | string, options?: ScriptFileLoadOptions): unknown;
12
+ private build;
12
13
  }
@@ -1,4 +1,2 @@
1
- import type { LocatorInfo } from '../locator';
2
1
  import type { LoaderFilterFn, ScriptFileExportItem } from './built-in';
3
- export declare function buildLoaderFilePath(input: LocatorInfo | string, withExtension?: boolean): string;
4
2
  export declare function getExportItem(data: Record<string, any>, filterFn?: LoaderFilterFn): ScriptFileExportItem;
@@ -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 +1 @@
1
- export declare function handleFileLoadError(e: unknown): void;
1
+ export declare function handleException(e: unknown): void;
@@ -0,0 +1 @@
1
+ export declare function isFilePath(input: string): boolean | "";
@@ -3,3 +3,4 @@ export * from './file-name';
3
3
  export * from './has-property';
4
4
  export * from './object';
5
5
  export * from './to-array';
6
+ export * from './file-path';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locter",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "A library to locate a file/module by criteria and load it!",
5
5
  "author": {
6
6
  "name": "Peter Placzek",
@@ -57,21 +57,21 @@
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.35",
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.2",
66
+ "@types/node": "^18.14.6",
67
67
  "cross-env": "^7.0.3",
68
- "eslint": "^8.34.0",
68
+ "eslint": "^8.35.0",
69
69
  "husky": "^8.0.3",
70
70
  "jest": "^27.5.1",
71
- "magic-string": "^0.29.0",
71
+ "magic-string": "^0.30.0",
72
72
  "mlly": "^1.1.1",
73
- "rimraf": "^4.1.2",
74
- "rollup": "^3.17.3",
73
+ "rimraf": "^4.4.0",
74
+ "rollup": "^3.18.0",
75
75
  "semantic-release": "^19.0.5",
76
76
  "sourcemap-codec": "^1.4.8",
77
77
  "typescript": "^4.9.5"
@@ -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
  }