Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: useCache = true default #1125

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading