Skip to content

Commit

Permalink
refactor: useCache = true default
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 25, 2024
1 parent 1380376 commit 0cb3f20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/config/plugin-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default class PluginLoader {
const userPJSONPath = join(opts.dataDir, 'package.json')
debug('reading user plugins pjson %s', userPJSONPath)
// ignore cache because the file might have changed within the same process (e.g. during a JIT plugin install)
const pjson = await readJson<PJSON>(userPJSONPath, true)
const pjson = await readJson<PJSON>(userPJSONPath, false)
if (!pjson.oclif) pjson.oclif = {schema: 1}
if (!pjson.oclif.plugins) pjson.oclif.plugins = []
await this.loadPlugins(
Expand Down
12 changes: 6 additions & 6 deletions src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ const cache = new ProdOnlyCache()
* Will throw an error if the file does not exist.
*
* @param path file path of JSON file
* @param ignoreCache if true, ignore cache and read file from disk
* @param useCache if false, ignore cache and read file from disk
* @returns <T>
*/
export async function readJson<T = unknown>(path: string, ignoreCache = false): Promise<T> {
if (!ignoreCache && cache.has(path)) {
export async function readJson<T = unknown>(path: string, useCache = true): Promise<T> {
if (useCache && cache.has(path)) {
return JSON.parse(cache.get(path)!) as T
}

Expand All @@ -82,12 +82,12 @@ export async function readJson<T = unknown>(path: string, ignoreCache = false):
* Will return undefined if the file does not exist.
*
* @param path file path of JSON file
* @param ignoreCache if true, ignore cache and read file from disk
* @param useCache if false, ignore cache and read file from disk
* @returns <T> or undefined
*/
export async function safeReadJson<T>(path: string, ignoreCache = false): Promise<T | undefined> {
export async function safeReadJson<T>(path: string, useCache = true): Promise<T | undefined> {
try {
return await readJson<T>(path, ignoreCache)
return await readJson<T>(path, useCache)
} catch {}
}

Expand Down

0 comments on commit 0cb3f20

Please sign in to comment.