{"version":3,"file":"index.mjs","names":[],"sources":["../src/errors/base.ts","../src/errors/load.ts","../src/errors/not-found.ts","../src/errors/unknown-extension.ts","../src/utils/file-name.ts","../src/utils/has-property.ts","../src/utils/object.ts","../src/utils/to-array.ts","../src/utils/file-path.ts","../src/utils/runtime.ts","../src/utils/typescript.ts","../src/errors/wrap.ts","../src/locator/utils.ts","../src/locator/async.ts","../src/locator/sync.ts","../src/locator/up.ts","../src/loader/built-in/conf/module.ts","../src/loader/built-in/json/module.ts","../src/loader/built-in/module/utils.ts","../src/loader/built-in/module/module.ts","../src/loader/built-in/yaml/module.ts","../src/loader/module.ts","../src/loader/singleton.ts","../src/loader/helpers.ts","../src/loader/package-field.ts"],"sourcesContent":["/*\n * Copyright (c) 2026.\n * Author Peter 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 {\n    BaseError,\n    type ErrorOptions,\n    hasInstanceof,\n    markInstanceof,\n} from '@ebec/core';\n\nexport type LocterErrorOptions = ErrorOptions & {\n    path?: string,\n};\n\nexport type LocterErrorInput = string | LocterErrorOptions;\n\nexport const LOCTER_ERROR_MARKER = Symbol.for('@locter/error');\n\nexport class LocterError extends BaseError {\n    static override [Symbol.hasInstance](input: unknown) : boolean {\n        return hasInstanceof(input, LOCTER_ERROR_MARKER);\n    }\n\n    public readonly path?: string;\n\n    constructor(input: LocterErrorInput = {}) {\n        if (typeof input === 'string') {\n            super(input);\n        } else {\n            const { path, ...rest } = input;\n            super(rest);\n            this.path = path;\n        }\n\n        markInstanceof(this, LOCTER_ERROR_MARKER);\n    }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter 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 { hasInstanceof, markInstanceof } from '@ebec/core';\nimport { LocterError, type LocterErrorInput } from './base';\n\nexport const LOCTER_LOAD_ERROR_MARKER = Symbol.for('@locter/load-error');\n\nexport class LocterLoadError extends LocterError {\n    static override [Symbol.hasInstance](input: unknown) : boolean {\n        return hasInstanceof(input, LOCTER_LOAD_ERROR_MARKER);\n    }\n\n    constructor(input: LocterErrorInput = {}) {\n        super(input);\n        markInstanceof(this, LOCTER_LOAD_ERROR_MARKER);\n    }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter 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 { hasInstanceof, markInstanceof } from '@ebec/core';\nimport { LocterError, type LocterErrorInput } from './base';\n\nexport const LOCTER_NOT_FOUND_ERROR_MARKER = Symbol.for('@locter/not-found-error');\n\nexport class LocterNotFoundError extends LocterError {\n    static override [Symbol.hasInstance](input: unknown) : boolean {\n        return hasInstanceof(input, LOCTER_NOT_FOUND_ERROR_MARKER);\n    }\n\n    constructor(input: LocterErrorInput = {}) {\n        super(input);\n        markInstanceof(this, LOCTER_NOT_FOUND_ERROR_MARKER);\n    }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter 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 { hasInstanceof, markInstanceof } from '@ebec/core';\nimport { LocterError, type LocterErrorInput } from './base';\n\nexport const LOCTER_UNKNOWN_EXTENSION_ERROR_MARKER = Symbol.for('@locter/unknown-extension-error');\n\nexport class LocterUnknownExtensionError extends LocterError {\n    static override [Symbol.hasInstance](input: unknown) : boolean {\n        return hasInstanceof(input, LOCTER_UNKNOWN_EXTENSION_ERROR_MARKER);\n    }\n\n    constructor(input: LocterErrorInput = {}) {\n        super(input);\n        markInstanceof(this, LOCTER_UNKNOWN_EXTENSION_ERROR_MARKER);\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 path from 'node:path';\n\nexport function getFileNameExtension(\n    input: string,\n    allowed?: string[],\n) : string | undefined {\n    const extension = path.extname(input);\n    if (extension === '' || extension === '.') {\n        return undefined;\n    }\n\n    if (\n        typeof allowed === 'undefined' ||\n        allowed.includes(extension)\n    ) {\n        return extension;\n    }\n\n    return undefined;\n}\n\nexport function removeFileNameExtension(\n    input: string,\n    extensions?: string[],\n) {\n    const extension = getFileNameExtension(input, extensions);\n    if (extension) {\n        return input.substring(0, input.length - extension.length);\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\nexport function isSafeObjectKey(key: string) : boolean {\n    return key !== '__proto__' &&\n        key !== 'prototype' &&\n        key !== 'constructor';\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\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) 2024.\n * Author Peter 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 isVitestRuntimeEnvironment() : boolean {\n    return typeof process !== 'undefined' &&\n        process.env.VITEST === 'true';\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) 2024.\n * Author Peter 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 { isObject } from './object';\n\nexport function isTypeScriptError(input: unknown) : input is Error {\n    if (!isObject(input)) {\n        return false;\n    }\n\n    if (typeof input.diagnosticCodes !== 'undefined') {\n        return true;\n    }\n\n    return typeof input.message === 'string' &&\n        /TS\\d+/.test(input.message);\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter 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 { hasStringProperty, isObject } from '../utils';\nimport { LocterError } from './base';\nimport { LocterLoadError } from './load';\nimport { LocterNotFoundError } from './not-found';\n\nconst NOT_FOUND_CODES = new Set([\n    'ENOENT',\n    'MODULE_NOT_FOUND',\n    'ERR_MODULE_NOT_FOUND',\n]);\n\nexport function wrapLoaderError(input: unknown, path: string) : LocterError {\n    if (input instanceof LocterError) {\n        return input;\n    }\n\n    const code = isObject(input) && hasStringProperty(input, 'code') ?\n        input.code :\n        undefined;\n\n    const message = isObject(input) && hasStringProperty(input, 'message') ?\n        input.message :\n        `Failed to load: ${path}`;\n\n    if (code && NOT_FOUND_CODES.has(code)) {\n        return new LocterNotFoundError({\n            message,\n            code,\n            cause: input,\n            path,\n        });\n    }\n\n    return new LocterLoadError({\n        message,\n        code,\n        cause: input,\n        path,\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 path from 'node:path';\nimport { isObject, toArray } from '../utils';\nimport type { LocatorInfo, LocatorOptions, LocatorOptionsInput } from './types';\n\nexport function buildLocatorPatterns(pattern: string | string[]) : string[] {\n    return Array.isArray(pattern) ?\n        pattern :\n        [pattern];\n}\n\nexport function buildLocatorOptions(options: LocatorOptionsInput = {}) : LocatorOptions {\n    const cwd = options.cwd ?\n        toArray(options.cwd) :\n        [];\n\n    const ignore = options.ignore ?\n        toArray(options.ignore) :\n        [];\n\n    if (cwd.length === 0) {\n        cwd.push(process.cwd());\n    }\n\n    let onlyFiles : boolean;\n    let onlyDirectories : boolean;\n\n    if (options.onlyDirectories === options.onlyFiles) {\n        onlyDirectories = false;\n        onlyFiles = !options.onlyDirectories;\n    } else if (typeof options.onlyFiles === 'undefined') {\n        onlyDirectories = options.onlyDirectories ?? false;\n        onlyFiles = !options.onlyDirectories;\n    } else {\n        onlyFiles = options.onlyFiles ?? true;\n        onlyDirectories = !options.onlyFiles;\n    }\n\n    return {\n        cwd,\n        ignore,\n        onlyDirectories,\n        onlyFiles,\n        dot: options.dot ?? false,\n    };\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    const directory = info.dir.split('/').join(path.sep);\n    const extension = info.ext ? info.ext : undefined;\n    const filePath = extension ?\n        path.join(directory, info.name) + extension :\n        path.join(directory, info.name);\n\n    return {\n        directory,\n        name: info.name,\n        extension,\n        path: filePath,\n    };\n}\n\nexport function isLocatorInfo(\n    input: unknown,\n) : input is LocatorInfo {\n    return isObject(input) &&\n        typeof input.directory === 'string' &&\n        typeof input.name === 'string' &&\n        (typeof input.extension === 'undefined' || typeof input.extension === 'string') &&\n        typeof input.path === 'string';\n}\n\nexport function buildFilePath(input: LocatorInfo | string) {\n    if (typeof input === 'string') {\n        return input;\n    }\n\n    return input.path;\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.directory, 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 fg from 'fast-glob';\nimport type { LocatorInfo, LocatorOptionsInput } from './types';\nimport { buildLocatorOptions, buildLocatorPatterns, pathToLocatorInfo } from './utils';\n\nexport async function locateMany(\n    pattern: string | string[],\n    options?: LocatorOptionsInput,\n) : Promise<LocatorInfo[]> {\n    const patterns = buildLocatorPatterns(pattern);\n    const opts = buildLocatorOptions(options);\n\n    const items : LocatorInfo[] = [];\n\n    for (const p of patterns) {\n        for (const cwd of opts.cwd) {\n            const files = await fg(p, {\n                absolute: true,\n                cwd,\n                ignore: opts.ignore,\n                onlyFiles: opts.onlyFiles,\n                onlyDirectories: opts.onlyDirectories,\n                dot: opts.dot,\n            });\n\n            for (const file of files) {\n                items.push(pathToLocatorInfo(file, true));\n            }\n        }\n    }\n\n    return items;\n}\n\nexport async function locate(\n    pattern: string | string[],\n    options?: LocatorOptionsInput,\n) : Promise<LocatorInfo | undefined> {\n    const patterns = buildLocatorPatterns(pattern);\n    const opts = buildLocatorOptions(options);\n\n    for (const p of patterns) {\n        for (const cwd of opts.cwd) {\n            const files = await fg(p, {\n                absolute: true,\n                cwd,\n                ignore: opts.ignore,\n                onlyFiles: opts.onlyFiles,\n                onlyDirectories: opts.onlyDirectories,\n                dot: opts.dot,\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 fg from 'fast-glob';\nimport type { LocatorInfo, LocatorOptionsInput } from './types';\nimport { buildLocatorOptions, buildLocatorPatterns, pathToLocatorInfo } from './utils';\n\nexport function locateManySync(\n    pattern: string | string[],\n    options?: LocatorOptionsInput,\n) : LocatorInfo[] {\n    const patterns = buildLocatorPatterns(pattern);\n    const opts = buildLocatorOptions(options);\n\n    const items : LocatorInfo[] = [];\n\n    for (const p of patterns) {\n        for (const cwd of opts.cwd) {\n            const files = fg.sync(p, {\n                absolute: true,\n                cwd,\n                ignore: opts.ignore,\n                onlyFiles: opts.onlyFiles,\n                onlyDirectories: opts.onlyDirectories,\n                dot: opts.dot,\n            });\n\n            for (const file of files) {\n                items.push(pathToLocatorInfo(file, true));\n            }\n        }\n    }\n\n    return items;\n}\n\nexport function locateSync(\n    pattern: string | string[],\n    options?: LocatorOptionsInput,\n) : LocatorInfo | undefined {\n    const patterns = buildLocatorPatterns(pattern);\n    const opts = buildLocatorOptions(options);\n\n    for (const p of patterns) {\n        for (const cwd of opts.cwd) {\n            const files = fg.sync(p, {\n                absolute: true,\n                cwd,\n                ignore: opts.ignore,\n                onlyFiles: opts.onlyFiles,\n                onlyDirectories: opts.onlyDirectories,\n                dot: opts.dot,\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) 2026.\n * Author Peter 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 { locate } from './async';\nimport { locateSync } from './sync';\nimport type { LocatorInfo, LocatorOptionsInput } from './types';\n\nexport type LocatorUpOptionsInput = Omit<LocatorOptionsInput, 'cwd'> & {\n    cwd?: string,\n    stopAt?: string,\n};\n\ntype WalkStep = {\n    current: string,\n    stopAt: string,\n    baseOptions: Omit<LocatorOptionsInput, 'cwd'>,\n};\n\nfunction startWalk(options: LocatorUpOptionsInput) : WalkStep {\n    const {\n        cwd,\n        stopAt,\n        ...baseOptions\n    } = options;\n    const current = path.resolve(cwd ?? process.cwd());\n    const ceiling = stopAt ?\n        path.resolve(current, stopAt) :\n        path.parse(current).root;\n\n    return {\n        current,\n        stopAt: ceiling,\n        baseOptions,\n    };\n}\n\nfunction nextDirectory(current: string, stopAt: string) : string | undefined {\n    if (current === stopAt) {\n        return undefined;\n    }\n\n    const parent = path.dirname(current);\n    if (parent === current) {\n        return undefined;\n    }\n\n    return parent;\n}\n\nexport async function locateUp(\n    pattern: string | string[],\n    options: LocatorUpOptionsInput = {},\n) : Promise<LocatorInfo | undefined> {\n    let walk = startWalk(options);\n\n    while (true) {\n        const found = await locate(pattern, { ...walk.baseOptions, cwd: walk.current });\n        if (found) {\n            return found;\n        }\n\n        const next = nextDirectory(walk.current, walk.stopAt);\n        if (!next) {\n            return undefined;\n        }\n\n        walk = { ...walk, current: next };\n    }\n}\n\nexport function locateUpSync(\n    pattern: string | string[],\n    options: LocatorUpOptionsInput = {},\n) : LocatorInfo | undefined {\n    let walk = startWalk(options);\n\n    while (true) {\n        const found = locateSync(pattern, { ...walk.baseOptions, cwd: walk.current });\n        if (found) {\n            return found;\n        }\n\n        const next = nextDirectory(walk.current, walk.stopAt);\n        if (!next) {\n            return undefined;\n        }\n\n        walk = { ...walk, current: next };\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\n// Based on https://github.com/unjs/rc9 (MIT)\n\nimport { destr } from 'destr';\nimport { unflatten } from 'flat';\nimport fs from 'node:fs';\nimport { wrapLoaderError } from '../../../errors';\nimport { buildFilePath } from '../../../locator';\nimport { isSafeObjectKey } from '../../../utils';\nimport type { Loader } from '../../type';\n\nexport class ConfLoader implements Loader {\n    async execute(input: string) {\n        const filePath = buildFilePath(input);\n\n        try {\n            const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });\n\n            return this.parse(file);\n        } catch (e) {\n            throw wrapLoaderError(e, filePath);\n        }\n    }\n\n    executeSync(input: string) {\n        const filePath = buildFilePath(input);\n\n        try {\n            const file = fs.readFileSync(filePath, { encoding: 'utf-8' });\n\n            return this.parse(file);\n        } catch (e) {\n            throw wrapLoaderError(e, filePath);\n        }\n    }\n\n    parse(contents: string): Record<string, any> {\n        const config: Record<string, any> = {};\n\n        const lines = contents.split(/\\n|\\r|\\r\\n/);\n\n        for (const line of lines) {\n            const match = line.match(/^\\s*([^\\s=]+)\\s*=\\s*(.*)?\\s*$/);\n            if (!match) {\n                continue;\n            }\n\n            const key = match[1];\n            const rawValue = match[2];\n\n            if (!key || !isSafeObjectKey(key)) {\n                continue;\n            }\n\n            const value = destr(rawValue ? rawValue.trim() : '');\n\n            if (key.endsWith('[]')) {\n                const arrKey = key.slice(0, Math.max(0, key.length - 2));\n                config[arrKey] = (config[arrKey] || []).concat(value);\n                continue;\n            }\n\n            config[key] = value;\n        }\n\n        return unflatten(config, { overwrite: true });\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 { wrapLoaderError } from '../../../errors';\nimport { buildFilePath } from '../../../locator';\nimport type { Loader } from '../../type';\n\nexport class JSONLoader implements Loader {\n    async execute(input: string) {\n        const filePath = buildFilePath(input);\n\n        try {\n            const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });\n            return JSON.parse(file);\n        } catch (e) {\n            throw wrapLoaderError(e, filePath);\n        }\n    }\n\n    executeSync(input: string) {\n        const filePath = buildFilePath(input);\n\n        try {\n            const file = fs.readFileSync(filePath, { encoding: 'utf-8' });\n            return JSON.parse(file);\n        } catch (e) {\n            throw wrapLoaderError(e, filePath);\n        }\n    }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty, isObject } from '../../../utils';\nimport type { LoaderFilterFn, ModuleExport } from './type';\n\ntype ESModule = { [key: string]: any, __esModule: boolean };\nexport function isESModule(input: unknown) : input is ESModule {\n    return isObject(input) &&\n        typeof input.__esModule !== 'undefined';\n}\n\n// https://2ality.com/2017/01/babel-esm-spec-mode.html\nexport function toModuleRecord(\n    data: unknown,\n) {\n    if (isESModule(data)) {\n        // @see https://github.com/testing-library/user-event/issues/813\n        // @see https://stackoverflow.com/questions/62717394/export-default-class-exports-double-nested-default\n        if (\n            isESModule(data.default) &&\n            data.default.default\n        ) {\n            return {\n                ...data,\n                default: data.default.default,\n            };\n        }\n\n        return data;\n    }\n\n    const output = Object.create(null, {\n        __esModule: { value: true },\n        [Symbol.toStringTag]: { value: 'Module' },\n    });\n\n    if (isObject(data)) {\n        for (const key in data) {\n            if (hasOwnProperty(output, key)) {\n                continue;\n            }\n\n            let descriptor = Object.getOwnPropertyDescriptor(data, key);\n            if (\n                !descriptor ||\n                ('get' in descriptor || descriptor.writable || descriptor.configurable)\n            ) {\n                descriptor = {\n                    enumerable: true,\n                    get() {\n                        return data[key];\n                    },\n                };\n            }\n\n            Object.defineProperty(output, key, descriptor);\n        }\n    }\n\n    if (!hasOwnProperty(output, 'default')) {\n        Object.defineProperty(output, 'default', {\n            value: data,\n            enumerable: true,\n        });\n    }\n\n    return Object.freeze(output);\n}\n\nexport function getModuleExport(\n    data: Record<string, any>,\n    filterFn: LoaderFilterFn,\n): ModuleExport | undefined {\n    const keys = Object.keys(data);\n    for (const key of keys) {\n        if (filterFn(key as string, data[key as string])) {\n            return {\n                key: key as string,\n                value: data[key as string],\n            };\n        }\n    }\n\n    return undefined;\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createJiti } from 'jiti';\nimport { createRequire } from 'node:module';\nimport { pathToFileURL } from 'node:url';\nimport { LocterError, wrapLoaderError } from '../../../errors';\nimport type { LocatorInfo } from '../../../locator';\nimport {\n    buildFilePath,\n    isLocatorInfo,\n} from '../../../locator';\nimport {\n    hasStringProperty,\n    isFilePath,\n    isJestRuntimeEnvironment,\n    isObject,\n    isTsNodeRuntimeEnvironment,\n    isTypeScriptError,\n} from '../../../utils';\nimport type { Loader } from '../../type';\nimport type {\n    ModuleLoadFn,\n    ModuleLoadOptions,\n    ModuleLoadSyncFn,\n    ModuleLoaderOptions,\n} from './type';\nimport { toModuleRecord } from './utils';\n\nconst require = createRequire(import.meta.url);\n\ntype Jiti = ReturnType<typeof createJiti>;\n\nfunction originalPath(data: LocatorInfo | string) : string {\n    return typeof data === 'string' ? data : buildFilePath(data);\n}\n\nfunction isUnrecoverableError(error: unknown) : boolean {\n    const underlying = error instanceof LocterError ? error.cause : error;\n    return underlying instanceof SyntaxError ||\n        underlying instanceof ReferenceError ||\n        isTypeScriptError(underlying);\n}\n\nexport class ModuleLoader implements Loader {\n    protected instance : Jiti;\n\n    protected loadFn?: ModuleLoadFn;\n\n    protected loadSyncFn?: ModuleLoadSyncFn;\n\n    constructor(options: ModuleLoaderOptions = {}) {\n        // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n        // @ts-ignore\n        this.instance = createJiti(undefined, { extensions: ['.js', '.mjs', '.mts', '.cjs', '.cts', '.ts'] });\n        this.loadFn = options.load;\n        this.loadSyncFn = options.loadSync;\n    }\n\n    configure(options: ModuleLoaderOptions) : void {\n        if ('load' in options) {\n            this.loadFn = options.load;\n        }\n        if ('loadSync' in options) {\n            this.loadSyncFn = options.loadSync;\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            if (isUnrecoverableError(e)) {\n                throw e;\n            }\n\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.instance(input);\n            }\n        }\n\n        return toModuleRecord(output);\n    }\n\n    executeSync(input: string) {\n        let output : any;\n\n        try {\n            output = this.loadSync(input);\n        } catch (e) {\n            if (isUnrecoverableError(e)) {\n                throw e;\n            }\n\n            output = this.instance(input);\n        }\n\n        return toModuleRecord(output);\n    }\n\n    // ---------------------------------------------------------------------------\n\n    async load(\n        data: LocatorInfo | string,\n        options: ModuleLoadOptions = {},\n    ) : Promise<unknown> {\n        const id = this.build(data, options);\n\n        try {\n            if (this.loadFn) {\n                return await this.loadFn(id);\n            }\n\n            // segmentation fault\n            // issue: https://github.com/nodejs/node/issues/35889\n            if (isJestRuntimeEnvironment()) {\n                return require(id);\n            }\n\n            return await import(id);\n        } catch (e) {\n            /* istanbul ignore next */\n            if (\n                !options.withFilePrefix &&\n                isObject(e) &&\n                hasStringProperty(e, 'code') &&\n                (\n                    e.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME' ||\n                    e.code === 'UNSUPPORTED_ESM_URL_SCHEME'\n                )\n            ) {\n                return this.load(data, {\n                    ...options,\n                    withFilePrefix: true,\n                });\n            }\n\n            throw wrapLoaderError(e, originalPath(data));\n        }\n    }\n\n    loadSync(\n        data: LocatorInfo | string,\n        options: ModuleLoadOptions = {},\n    ) : unknown {\n        const id = this.build(data, options);\n\n        try {\n            if (this.loadSyncFn) {\n                return this.loadSyncFn(id);\n            }\n\n            return require(id);\n        } catch (e) {\n            throw wrapLoaderError(e, originalPath(data));\n        }\n    }\n\n    private build(\n        data: LocatorInfo | string,\n        options: ModuleLoadOptions = {},\n    ) : string {\n        if (isLocatorInfo(data) || isFilePath(data)) {\n            if (typeof data !== 'string') {\n                data = buildFilePath(data);\n            }\n\n            if (options.withFilePrefix) {\n                data = pathToFileURL(data).href;\n            }\n        }\n\n        return data;\n    }\n}\n","/*\n * Copyright (c) 2022-2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { parse } from 'yaml';\nimport fs from 'node:fs';\nimport { wrapLoaderError } from '../../../errors';\nimport { buildFilePath } from '../../../locator';\nimport type { Loader } from '../../type';\n\nexport class YAMLLoader implements Loader {\n    async execute(input: string) {\n        const filePath = buildFilePath(input);\n\n        try {\n            const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });\n            return parse(file);\n        } catch (e) {\n            throw wrapLoaderError(e, filePath);\n        }\n    }\n\n    executeSync(input: string) {\n        const filePath = buildFilePath(input);\n\n        try {\n            const file = fs.readFileSync(filePath, { encoding: 'utf-8' });\n            return parse(file);\n        } catch (e) {\n            throw wrapLoaderError(e, filePath);\n        }\n    }\n}\n","/*\n * Copyright (c) 2023.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport {\n    LocterError,\n    LocterUnknownExtensionError,\n    wrapLoaderError,\n} from '../errors';\nimport { buildFilePath, pathToLocatorInfo } from '../locator';\nimport { isFilePath } from '../utils';\nimport { ConfLoader, JSONLoader, ModuleLoader } from './built-in';\nimport { YAMLLoader } from './built-in/yaml';\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            { test: ['.conf'], loader: LoaderId.CONF },\n            { test: ['.json'], loader: LoaderId.JSON },\n            { test: ['.yml', '.yaml'], loader: LoaderId.YAML },\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            throw this.unknownExtensionError(input);\n        }\n\n        const loader = this.resolve(id);\n        try {\n            return await loader.execute(input);\n        } catch (e) {\n            throw wrapLoaderError(e, input);\n        }\n    }\n\n    executeSync(input: string) : any {\n        const id = this.findLoader(input);\n        if (!id) {\n            throw this.unknownExtensionError(input);\n        }\n\n        const loader = this.resolve(id);\n        try {\n            return loader.executeSync(input);\n        } catch (e) {\n            throw wrapLoaderError(e, input);\n        }\n    }\n\n    protected unknownExtensionError(input: string) : LocterUnknownExtensionError {\n        const info = pathToLocatorInfo(input);\n        return new LocterUnknownExtensionError({\n            message: `No loader registered for extension: ${info.extension ?? 'unknown'}`,\n            path: input,\n        });\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 (const rule of this.rules) {\n            const { test } = rule;\n            if (Array.isArray(test)) {\n                if (\n                    info.extension &&\n                    test.includes(info.extension)\n                ) {\n                    return rule.loader;\n                }\n            } else if (test.test(buildFilePath(info))) {\n                return rule.loader;\n            }\n        }\n\n        return undefined;\n    }\n\n    /**\n     * Resolve loader by id.\n     *\n     * @param id\n     */\n    resolve(id: string | Loader) : Loader {\n        if (typeof id !== 'string') {\n            return id;\n        }\n\n        if (Object.prototype.hasOwnProperty.call(this.loaders, id)) {\n            return this.loaders[id] as Loader;\n        }\n\n        let loader : Loader | undefined;\n\n        // built-in\n        switch (id) {\n            case LoaderId.CONF: {\n                loader = new ConfLoader();\n                break;\n            }\n            case LoaderId.MODULE: {\n                loader = new ModuleLoader();\n                break;\n            }\n            case LoaderId.JSON: {\n                loader = new JSONLoader();\n                break;\n            }\n            case LoaderId.YAML: {\n                loader = new YAMLLoader();\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 LocterError({ message: `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 type { ModuleLoader } from './built-in/module';\nimport type { ModuleLoaderOptions } from './built-in/module/type';\nimport { LoaderId } from './constants';\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/**\n * Override the built-in module loader's `import` / `require` calls.\n *\n * Useful for test runners (e.g. Vitest) where the dynamic `import()` inside\n * `node_modules/locter` would bypass the runner's module graph. Calling this\n * from user code (e.g. a Vitest setup file) lets the runner rewrite the\n * `import()` so loaded modules share identity with statically imported ones.\n *\n * @example\n * ```ts\n * // vitest setup file\n * import { setModuleLoader } from 'locter';\n *\n * setModuleLoader({\n *     load: (id) => import(id),\n * });\n * ```\n */\nexport function setModuleLoader(options: ModuleLoaderOptions) : void {\n    const manager = useLoader();\n    const loader = manager.resolve(LoaderId.MODULE) as ModuleLoader;\n    loader.configure(options);\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter 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 { LocterNotFoundError } from '../errors';\nimport type { LocatorInfo } from '../locator';\nimport {\n    locate,\n    locateSync,\n    locateUp,\n    locateUpSync,\n} from '../locator';\nimport { hasOwnProperty, isObject } from '../utils';\nimport { load, loadSync } from './helpers';\n\nexport type LoadPackageFieldOptions = {\n    cwd?: string,\n    walkUp?: boolean,\n    stopAt?: string,\n};\n\nfunction extractField<T>(pkg: unknown, field: string) : T | undefined {\n    if (!isObject(pkg) || !hasOwnProperty(pkg, field)) {\n        return undefined;\n    }\n    return pkg[field] as T;\n}\n\nexport async function loadPackageField<T = unknown>(\n    field: string,\n    options: LoadPackageFieldOptions = {},\n) : Promise<T | undefined> {\n    let info: LocatorInfo | undefined;\n    if (options.walkUp) {\n        info = await locateUp('package.json', {\n            cwd: options.cwd,\n            stopAt: options.stopAt,\n        });\n    } else {\n        info = await locate('package.json', { cwd: options.cwd });\n    }\n\n    if (!info) {\n        return undefined;\n    }\n\n    try {\n        const pkg = await load(info);\n        return extractField<T>(pkg, field);\n    } catch (e) {\n        if (e instanceof LocterNotFoundError) {\n            return undefined;\n        }\n        throw e;\n    }\n}\n\nexport function loadPackageFieldSync<T = unknown>(\n    field: string,\n    options: LoadPackageFieldOptions = {},\n) : T | undefined {\n    let info: LocatorInfo | undefined;\n    if (options.walkUp) {\n        info = locateUpSync('package.json', {\n            cwd: options.cwd,\n            stopAt: options.stopAt,\n        });\n    } else {\n        info = locateSync('package.json', { cwd: options.cwd });\n    }\n\n    if (!info) {\n        return undefined;\n    }\n\n    try {\n        const pkg = loadSync(info);\n        return extractField<T>(pkg, field);\n    } catch (e) {\n        if (e instanceof LocterNotFoundError) {\n            return undefined;\n        }\n        throw e;\n    }\n}\n"],"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