{"version":3,"file":"files.mjs","sources":["../../../../src/node/core/files.ts"],"sourcesContent":["import path from 'node:path';\nimport { access } from 'node:fs/promises';\nimport { register } from 'esbuild-register/dist/node';\n\n/**\n * @internal\n */\nconst pathExists = async (path: string) => {\n  try {\n    await access(path);\n    return true;\n  } catch (error) {\n    return false;\n  }\n};\n\n/**\n * @internal\n */\nconst loadFile = async (path: string): Promise<undefined | any> => {\n  if (await pathExists(path)) {\n    const esbuildOptions: Parameters<typeof register>[0] = {\n      extensions: ['.js', '.mjs', '.ts'],\n    };\n\n    const { unregister } = register(esbuildOptions);\n\n    // eslint-disable-next-line @typescript-eslint/no-var-requires\n    const mod = require(path);\n\n    unregister();\n\n    /**\n     * handles esm or cjs exporting.\n     */\n    const file = mod?.default || mod || undefined;\n\n    return file;\n  }\n\n  return undefined;\n};\n\n/**\n * @internal\n *\n * @description Converts a system path to a module path mainly for `Windows` systems.\n * where the path separator is `\\` instead of `/`, on linux systems the path separator\n * is identical to the module path separator.\n */\nconst convertSystemPathToModulePath = (sysPath: string) => {\n  if (process.platform === 'win32') {\n    return sysPath.split(path.sep).join(path.posix.sep);\n  }\n\n  return sysPath;\n};\n\n/**\n * @internal\n *\n * @description Converts a module path to a system path, again largely used for Windows systems.\n * The original use case was plugins where the resolve path was in module format but we want to\n * have it relative to the runtime directory.\n */\nconst convertModulePathToSystemPath = (modulePath: string) => {\n  if (process.platform === 'win32') {\n    return modulePath.split(path.posix.sep).join(path.sep);\n  }\n\n  return modulePath;\n};\n\nexport { pathExists, loadFile, convertSystemPathToModulePath, convertModulePathToSystemPath };\n"],"names":["pathExists","path","access","error","loadFile","esbuildOptions","extensions","unregister","register","mod","require","file","default","undefined","convertSystemPathToModulePath","sysPath","process","platform","split","sep","join","posix","convertModulePathToSystemPath","modulePath"],"mappings":";;;;AAIA;;IAGA,MAAMA,aAAa,OAAOC,IAAAA,GAAAA;IACxB,IAAI;AACF,QAAA,MAAMC,MAAAA,CAAOD,IAAAA,CAAAA;QACb,OA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