1 |
- {"version":3,"file":"ExplorerSync.js","names":["ExplorerSync","ExplorerBase","constructor","options","searchSync","searchFrom","process","cwd","config","metaConfigFilePath","_loadFileSync","isEmpty","searchFromDirectorySync","getDirectorySync","dir","absoluteDir","path","resolve","run","result","searchDirectorySync","nextDir","nextDirectoryToSearch","transform","searchCache","cacheWrapperSync","place","searchPlaces","placeResult","loadSearchPlaceSync","shouldSearchStopWithResult","filepath","join","content","readFileSync","createCosmiconfigResultSync","loadFileContentSync","trim","undefined","loader","getLoaderEntryForFile","e","forceProp","fileContent","loadedContentToCosmiconfigResult","loadSync","validateFilePath","absoluteFilePath","runLoadSync","throwNotFound","cosmiconfigResult","loadCache"],"sources":["../src/ExplorerSync.ts"],"sourcesContent":["import path from 'path';\nimport { cacheWrapperSync } from './cacheWrapper';\nimport { ExplorerBase } from './ExplorerBase';\nimport { getDirectorySync } from './getDirectory';\nimport { readFileSync } from './readFile';\nimport {\n CosmiconfigResult,\n ExplorerOptionsSync,\n LoadedFileContent,\n} from './types';\n\nclass ExplorerSync extends ExplorerBase<ExplorerOptionsSync> {\n public constructor(options: ExplorerOptionsSync) {\n super(options);\n }\n\n public searchSync(searchFrom: string = process.cwd()): CosmiconfigResult {\n if (this.config.metaConfigFilePath) {\n const config = this._loadFileSync(this.config.metaConfigFilePath, true);\n if (config && !config.isEmpty) {\n return config;\n }\n }\n return this.searchFromDirectorySync(getDirectorySync(searchFrom));\n }\n\n private searchFromDirectorySync(dir: string): CosmiconfigResult {\n const absoluteDir = path.resolve(process.cwd(), dir);\n\n const run = (): CosmiconfigResult => {\n const result = this.searchDirectorySync(absoluteDir);\n const nextDir = this.nextDirectoryToSearch(absoluteDir, result);\n\n if (nextDir) {\n return this.searchFromDirectorySync(nextDir);\n }\n\n return this.config.transform(result);\n };\n\n if (this.searchCache) {\n return cacheWrapperSync(this.searchCache, absoluteDir, run);\n }\n\n return run();\n }\n\n private searchDirectorySync(dir: string): CosmiconfigResult {\n for (const place of this.config.searchPlaces) {\n const placeResult = this.loadSearchPlaceSync(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 loadSearchPlaceSync(dir: string, place: string): CosmiconfigResult {\n const filepath = path.join(dir, place);\n const content = readFileSync(filepath);\n\n return this.createCosmiconfigResultSync(filepath, content, false);\n }\n\n private loadFileContentSync(\n filepath: string,\n content: string | null,\n ): 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 loader(filepath, content);\n } catch (e: any) {\n e.filepath = filepath;\n throw e;\n }\n }\n\n private createCosmiconfigResultSync(\n filepath: string,\n content: string | null,\n forceProp: boolean,\n ): CosmiconfigResult {\n const fileContent = this.loadFileContentSync(filepath, content);\n\n return this.loadedContentToCosmiconfigResult(\n filepath,\n fileContent,\n forceProp,\n );\n }\n\n public loadSync(filepath: string): CosmiconfigResult {\n return this._loadFileSync(filepath, false);\n }\n\n private _loadFileSync(\n filepath: string,\n forceProp: boolean,\n ): CosmiconfigResult {\n this.validateFilePath(filepath);\n const absoluteFilePath = path.resolve(process.cwd(), filepath);\n\n const runLoadSync = (): CosmiconfigResult => {\n const content = readFileSync(absoluteFilePath, { throwNotFound: true });\n const cosmiconfigResult = this.createCosmiconfigResultSync(\n absoluteFilePath,\n content,\n forceProp,\n );\n\n return this.config.transform(cosmiconfigResult);\n };\n\n if (this.loadCache) {\n return cacheWrapperSync(this.loadCache, absoluteFilePath, runLoadSync);\n }\n\n return runLoadSync();\n }\n}\n\nexport { ExplorerSync };\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAOA,MAAMA,YAAN,SAA2BC,0BAA3B,CAA6D;EACpDC,WAAW,CAACC,OAAD,EAA+B;IAC/C,MAAMA,OAAN;EACD;;EAEMC,UAAU,CAACC,UAAkB,GAAGC,OAAO,CAACC,GAAR,EAAtB,EAAwD;IACvE,IAAI,KA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