MCPcopy Create free account
hub / github.com/serverless/serverless / getRcLocalConfig

Function getRcLocalConfig

packages/util/src/rc/index.js:101–120  ·  view source on GitHub ↗
(baseFilename)

Source from the content-addressed store, hash-verified

99 * @returns
100 */
101const getRcLocalConfig = async (baseFilename) => {
102 const localConfigPath = getRcLocalPath(baseFilename)
103 try {
104 const localConfig = await readFile(localConfigPath)
105 if (!localConfig) return null
106 return JSON.parse(localConfig)
107 } catch (error) {
108 if (error.code === 'ENOENT') return {}
109 try {
110 // try/catch to account for very unlikely race condition where file existed
111 // during readFileSync but no longer exists during rename
112 const backupRcPath = `${localConfigPath}.bak`
113 await fsp.rename(localConfigPath, backupRcPath)
114 } catch {
115 // Ignore
116 }
117 }
118
119 return {}
120}
121
122/**
123 * Gets the .{baseFilename}rc configuration file in the user's home directory, if it exists.

Callers 1

getRcConfigFunction · 0.85

Calls 2

getRcLocalPathFunction · 0.85
readFileFunction · 0.70

Tested by

no test coverage detected