Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
6.1 KiB
Plaintext
1 line
6.1 KiB
Plaintext
{"version":3,"sources":["../../src/config/find.ts"],"sourcesContent":["import { getTsconfig } from 'get-tsconfig'\nimport path from 'path'\n\nimport { findUpSync } from '../utilities/findUp.js'\n\n/**\n * List of all filenames to detect as a Payload configuration file.\n */\nexport const payloadConfigFileNames = ['payload.config.js', 'payload.config.ts']\n\n/**\n * Returns the source and output paths from the nearest tsconfig.json file.\n * If no tsconfig.json file is found, returns the current working directory.\n * @returns An object containing the source and output paths.\n */\nconst getTSConfigPaths = (): {\n configPath?: string\n outPath?: string\n rootPath?: string\n srcPath?: string\n tsConfigPath?: string\n} => {\n const tsConfigResult = getTsconfig()!\n const tsConfig = tsConfigResult.config\n const tsConfigDir = path.dirname(tsConfigResult.path)\n\n try {\n const rootConfigDir = path.resolve(tsConfigDir, tsConfig.compilerOptions!.baseUrl || '')\n const srcPath = tsConfig.compilerOptions?.rootDir || path.resolve(process.cwd(), 'src')\n const outPath = tsConfig.compilerOptions?.outDir || path.resolve(process.cwd(), 'dist')\n let configPath = tsConfig.compilerOptions?.paths?.['@payload-config']?.[0]\n\n if (configPath) {\n configPath = path.resolve(rootConfigDir, configPath)\n }\n return {\n configPath,\n outPath,\n rootPath: rootConfigDir,\n srcPath,\n tsConfigPath: tsConfigResult.path,\n }\n } catch (error) {\n console.error(`Error parsing tsconfig.json: ${error}`) // Do not throw the error, as we can still continue with the other config path finding methods\n return {\n rootPath: process.cwd(),\n }\n }\n}\n\n/**\n * Searches for a Payload configuration file.\n * @returns The absolute path to the Payload configuration file.\n * @throws An error if no configuration file is found.\n */\nexport const findConfig = (): string => {\n // If the developer has specified a config path,\n // format it if relative and use it directly if absolute\n if (process.env.PAYLOAD_CONFIG_PATH) {\n if (path.isAbsolute(process.env.PAYLOAD_CONFIG_PATH)) {\n return process.env.PAYLOAD_CONFIG_PATH\n }\n\n return path.resolve(process.cwd(), process.env.PAYLOAD_CONFIG_PATH)\n }\n\n const { configPath, outPath, rootPath, srcPath } = getTSConfigPaths()\n\n // if configPath is absolute file, not folder, return it\n if (configPath && (path.extname(configPath) === '.js' || path.extname(configPath) === '.ts')) {\n return configPath\n }\n\n const searchPaths =\n process.env.NODE_ENV === 'production'\n ? [configPath, outPath, srcPath, rootPath]\n : [configPath, srcPath, rootPath]\n\n for (const searchPath of searchPaths) {\n if (!searchPath) {\n continue\n }\n\n const configPath = findUpSync({\n dir: searchPath,\n fileNames: payloadConfigFileNames,\n })\n\n if (configPath) {\n return configPath\n }\n }\n\n // If no config file is found in the directories defined by tsconfig.json,\n // try searching in the 'src' and 'dist' directory as a last resort, as they are most commonly used\n if (process.env.NODE_ENV === 'production') {\n const distConfigPath = findUpSync({\n dir: path.resolve(process.cwd(), 'dist'),\n fileNames: ['payload.config.js'],\n })\n\n if (distConfigPath) {\n return distConfigPath\n }\n } else {\n const srcConfigPath = findUpSync({\n dir: path.resolve(process.cwd(), 'src'),\n fileNames: payloadConfigFileNames,\n })\n\n if (srcConfigPath) {\n return srcConfigPath\n }\n }\n\n throw new Error(\n 'Error: cannot find Payload config. Please create a configuration file located at the root of your current working directory called \"payload.config.js\" or \"payload.config.ts\".',\n )\n}\n"],"names":["getTsconfig","path","findUpSync","payloadConfigFileNames","getTSConfigPaths","tsConfigResult","tsConfig","config","tsConfigDir","dirname","rootConfigDir","resolve","compilerOptions","baseUrl","srcPath","rootDir","process","cwd","outPath","outDir","configPath","paths","rootPath","tsConfigPath","error","console","findConfig","env","PAYLOAD_CONFIG_PATH","isAbsolute","extname","searchPaths","NODE_ENV","searchPath","dir","fileNames","distConfigPath","srcConfigPath","Error"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