Explorer.js.map 7.2 KB

1
  1. {"version":3,"file":"Explorer.js","names":["Explorer","ExplorerBase","constructor","options","search","searchFrom","process","cwd","config","metaConfigFilePath","_loadFile","isEmpty","searchFromDirectory","getDirectory","dir","absoluteDir","path","resolve","run","result","searchDirectory","nextDir","nextDirectoryToSearch","transform","searchCache","cacheWrapper","place","searchPlaces","placeResult","loadSearchPlace","shouldSearchStopWithResult","filepath","join","fileContents","readFile","createCosmiconfigResult","loadFileContent","content","trim","undefined","loader","getLoaderEntryForFile","e","forceProp","fileContent","loadedContentToCosmiconfigResult","load","validateFilePath","absoluteFilePath","runLoad","throwNotFound","loadCache"],"sources":["../src/Explorer.ts"],"sourcesContent":["import path from 'path';\nimport { cacheWrapper } from './cacheWrapper';\nimport { ExplorerBase } from './ExplorerBase';\nimport { getDirectory } from './getDirectory';\nimport { readFile } from './readFile';\nimport { CosmiconfigResult, ExplorerOptions, LoadedFileContent } from './types';\n\nclass Explorer extends ExplorerBase<ExplorerOptions> {\n public constructor(options: ExplorerOptions) {\n super(options);\n }\n\n public async search(\n searchFrom: string = process.cwd(),\n ): Promise<CosmiconfigResult> {\n if (this.config.metaConfigFilePath) {\n const config = await this._loadFile(this.config.metaConfigFilePath, true);\n if (config && !config.isEmpty) {\n return config;\n }\n }\n return await this.searchFromDirectory(await getDirectory(searchFrom));\n }\n\n private async searchFromDirectory(dir: string): Promise<CosmiconfigResult> {\n const absoluteDir = path.resolve(process.cwd(), dir);\n\n const run = async (): Promise<CosmiconfigResult> => {\n const result = await this.searchDirectory(absoluteDir);\n const nextDir = this.nextDirectoryToSearch(absoluteDir, result);\n\n if (nextDir) {\n return this.searchFromDirectory(nextDir);\n }\n\n return await this.config.transform(result);\n };\n\n if (this.searchCache) {\n return cacheWrapper(this.searchCache, absoluteDir, run);\n }\n\n return run();\n }\n\n private async searchDirectory(dir: string): Promise<CosmiconfigResult> {\n for await (const place of this.config.searchPlaces) {\n const placeResult = await this.loadSearchPlace(dir, place);\n\n if (this.shouldSearchStopWithResult(placeResult)) {\n return placeResult;\n }\n }\n\n // config not found\n return null;\n }\n\n private async loadSearchPlace(\n dir: string,\n place: string,\n ): Promise<CosmiconfigResult> {\n const filepath = path.join(dir, place);\n const fileContents = await readFile(filepath);\n\n return await this.createCosmiconfigResult(filepath, fileContents, false);\n }\n\n private async loadFileContent(\n filepath: string,\n content: string | null,\n ): Promise<LoadedFileContent> {\n if (content === null) {\n return null;\n }\n if (content.trim() === '') {\n return undefined;\n }\n const loader = this.getLoaderEntryForFile(filepath);\n try {\n return await loader(filepath, content);\n } catch (e: any) {\n e.filepath = filepath;\n throw e;\n }\n }\n\n private async createCosmiconfigResult(\n filepath: string,\n content: string | null,\n forceProp: boolean,\n ): Promise<CosmiconfigResult> {\n const fileContent = await this.loadFileContent(filepath, content);\n\n return this.loadedContentToCosmiconfigResult(\n filepath,\n fileContent,\n forceProp,\n );\n }\n\n public async load(filepath: string): Promise<CosmiconfigResult> {\n return this._loadFile(filepath, false);\n }\n\n private async _loadFile(\n filepath: string,\n forceProp: boolean,\n ): Promise<CosmiconfigResult> {\n this.validateFilePath(filepath);\n const absoluteFilePath = path.resolve(process.cwd(), filepath);\n\n const runLoad = async (): Promise<CosmiconfigResult> => {\n const fileContents = await readFile(absoluteFilePath, {\n throwNotFound: true,\n });\n\n const result = await this.createCosmiconfigResult(\n absoluteFilePath,\n fileContents,\n forceProp,\n );\n\n return await this.config.transform(result);\n };\n\n if (this.loadCache) {\n return cacheWrapper(this.loadCache, absoluteFilePath, runLoad);\n }\n\n return runLoad();\n }\n}\n\nexport { Explorer };\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAGA,MAAMA,QAAN,SAAuBC,0BAAvB,CAAqD;EAC5CC,WAAW,CAACC,OAAD,EAA2B;IAC3C,MAAMA,OAAN;EACD;;EAEkB,MAANC,MAAM,CACjBC,UAAkB,GAAGC,OAAO,CAACC,GAAR,EADJ,EAEW;IAC5B,IAAI,KAAKC,MAAL,CAA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