src/index.js
async function(fileName, fileExt, resolve, parse, cwd) {

	// Get an array of paths to tell the location of potential files
	const locations = resolve(fileName, fileExt)

	// Look for the data in the same directory as filePath
	const relativePath = await locatePath(locations, { cwd })

	// Only continue with files
	if (relativePath == null) return null

	// Path to data must be absolute to read it
	const absolutePath = path.resolve(cwd, relativePath)

	// Load the file
	const contents = util.promisify(fs.readFile)(absolutePath, 'utf8')

	// Parse file contents with the given parser
	if (parse != null) {
		try { return parse(contents, absolutePath) } catch (err) { throw new Error(`Failed to parse '${ relativePath }'`) }
	}

	return contents

}
async function(fileName, fileExt, resolve, parse, cwd) {

	// Get an array of paths to tell the location of potential files
	const locations = resolve(fileName, fileExt)

	// Look for the data in the same directory as filePath
	const relativePath = await locatePath(locations, { cwd })

	// Only continue with files
	if (relativePath == null) return null

	// Path to data must be absolute to read it
	const absolutePath = path.resolve(cwd, relativePath)

	// Load the file
	const contents = util.promisify(fs.readFile)(absolutePath, 'utf8')

	// Parse file contents with the given parser
	if (parse != null) {
		try { return parse(contents, absolutePath) } catch (err) { throw new Error(`Failed to parse '${ relativePath }'`) }
	}

	return contents

}
async function ( fileName , fileExt , resolve , parse , cwd ) { // Get an array of paths to tell the location of potential files const locations = resolve ( fileName , fileExt ) // Look for the data in the same directory as filePath const relativePath = await locatePath ( locations , { cwd } ) // Only continue with files if ( relativePath == null ) return null // Path to data must be absolute to read it const absolutePath = path . resolve ( cwd , relativePath ) // Load the file const contents = util . promisify ( fs . readFile ) ( absolutePath , 'utf8' ) // Parse file contents with the given parser if ( parse != null ) { try { return parse ( contents , absolutePath ) } catch ( err ) { throw new Error ( ` ${ relativePath } ` ) } } return contents }
Locate and load a file.
@public
@param {String} fileName - File name of the component.
@param {String} fileExt - File extension of the component.
@param {Function} resolve - Function that returns an array of paths to tell the potential location of a file.
@param {?Function} parse - Function that parses the contents of the file resolved by the resolve function.
@param {String} cwd - The directory in which to search. Must be absolute.
@returns {Promise<?String>} Contents of a file.
Locate and load a file .