UNPKG

1.47 kBJavaScriptView Raw
1"use strict";exports.__esModule=true;exports.findConfig=findConfig;var _findUp=_interopRequireDefault(require("next/dist/compiled/find-up"));var _fs=_interopRequireDefault(require("fs"));var _json=_interopRequireDefault(require("next/dist/compiled/json5"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}// We'll allow configuration to be typed, but we force everything provided to
2// become optional. We do not perform any schema validation. We should maybe
3// force all the types to be `unknown` as well.
4async function findConfig(directory,key){// `package.json` configuration always wins. Let's check that first.
5const packageJsonPath=await(0,_findUp.default)('package.json',{cwd:directory});if(packageJsonPath){const packageJson=require(packageJsonPath);if(packageJson[key]!=null&&typeof packageJson[key]==='object'){return packageJson[key];}}// If we didn't find the configuration in `package.json`, we should look for
6// known filenames.
7const filePath=await(0,_findUp.default)([`.${key}rc.json`,`${key}.config.json`,`.${key}rc.js`,`${key}.config.js`],{cwd:directory});if(filePath){if(filePath.endsWith('.js')){return require(filePath);}// We load JSON contents with JSON5 to allow users to comment in their
8// configuration file. This pattern was popularized by TypeScript.
9const fileContents=_fs.default.readFileSync(filePath,'utf8');return _json.default.parse(fileContents);}return null;}
10//# sourceMappingURL=find-config.js.map
\No newline at end of file