@oclif/core 4.0.6 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -169,7 +169,8 @@ class PluginLoader {
169
169
  try {
170
170
  const userPJSONPath = (0, node_path_1.join)(opts.dataDir, 'package.json');
171
171
  debug('reading user plugins pjson %s', userPJSONPath);
172
- const pjson = await (0, fs_1.readJson)(userPJSONPath);
172
+ // ignore cache because the file might have changed within the same process (e.g. during a JIT plugin install)
173
+ const pjson = await (0, fs_1.readJson)(userPJSONPath, false);
173
174
  if (!pjson.oclif)
174
175
  pjson.oclif = { schema: 1 };
175
176
  if (!pjson.oclif.plugins)
package/lib/util/fs.d.ts CHANGED
@@ -12,8 +12,24 @@ export declare const dirExists: (input: string) => Promise<string>;
12
12
  * @returns Promise<string>
13
13
  */
14
14
  export declare const fileExists: (input: string) => Promise<string>;
15
- export declare function readJson<T = unknown>(path: string): Promise<T>;
16
- export declare function readJsonSync(path: string, parse: false): string;
17
- export declare function readJsonSync<T = unknown>(path: string, parse?: true): T;
18
- export declare function safeReadJson<T>(path: string): Promise<T | undefined>;
15
+ /**
16
+ * Read a file from disk and cache its contents if in production environment.
17
+ *
18
+ * Will throw an error if the file does not exist.
19
+ *
20
+ * @param path file path of JSON file
21
+ * @param useCache if false, ignore cache and read file from disk
22
+ * @returns <T>
23
+ */
24
+ export declare function readJson<T = unknown>(path: string, useCache?: boolean): Promise<T>;
25
+ /**
26
+ * Safely read a file from disk and cache its contents if in production environment.
27
+ *
28
+ * Will return undefined if the file does not exist.
29
+ *
30
+ * @param path file path of JSON file
31
+ * @param useCache if false, ignore cache and read file from disk
32
+ * @returns <T> or undefined
33
+ */
34
+ export declare function safeReadJson<T>(path: string, useCache?: boolean): Promise<T | undefined>;
19
35
  export declare function existsSync(path: string): boolean;
package/lib/util/fs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.existsSync = exports.safeReadJson = exports.readJsonSync = exports.readJson = exports.fileExists = exports.dirExists = void 0;
3
+ exports.existsSync = exports.safeReadJson = exports.readJson = exports.fileExists = exports.dirExists = void 0;
4
4
  const node_fs_1 = require("node:fs");
5
5
  const promises_1 = require("node:fs/promises");
6
6
  const util_1 = require("./util");
@@ -53,8 +53,17 @@ class ProdOnlyCache extends Map {
53
53
  }
54
54
  }
55
55
  const cache = new ProdOnlyCache();
56
- async function readJson(path) {
57
- if (cache.has(path)) {
56
+ /**
57
+ * Read a file from disk and cache its contents if in production environment.
58
+ *
59
+ * Will throw an error if the file does not exist.
60
+ *
61
+ * @param path file path of JSON file
62
+ * @param useCache if false, ignore cache and read file from disk
63
+ * @returns <T>
64
+ */
65
+ async function readJson(path, useCache = true) {
66
+ if (useCache && cache.has(path)) {
58
67
  return JSON.parse(cache.get(path));
59
68
  }
60
69
  const contents = await (0, promises_1.readFile)(path, 'utf8');
@@ -62,21 +71,18 @@ async function readJson(path) {
62
71
  return JSON.parse(contents);
63
72
  }
64
73
  exports.readJson = readJson;
65
- function readJsonSync(path, parse = true) {
66
- if (cache.has(path)) {
67
- return JSON.parse(cache.get(path));
68
- }
69
- const contents = (0, node_fs_1.readFileSync)(path, 'utf8');
70
- cache.set(path, contents);
71
- return parse ? JSON.parse(contents) : contents;
72
- }
73
- exports.readJsonSync = readJsonSync;
74
- async function safeReadJson(path) {
75
- if (cache.has(path)) {
76
- return JSON.parse(cache.get(path));
77
- }
74
+ /**
75
+ * Safely read a file from disk and cache its contents if in production environment.
76
+ *
77
+ * Will return undefined if the file does not exist.
78
+ *
79
+ * @param path file path of JSON file
80
+ * @param useCache if false, ignore cache and read file from disk
81
+ * @returns <T> or undefined
82
+ */
83
+ async function safeReadJson(path, useCache = true) {
78
84
  try {
79
- return await readJson(path);
85
+ return await readJson(path, useCache);
80
86
  }
81
87
  catch { }
82
88
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "4.0.6",
4
+ "version": "4.0.7",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -50,18 +50,18 @@
50
50
  "cross-env": "^7.0.3",
51
51
  "eslint": "^8.57.0",
52
52
  "eslint-config-oclif": "^5.2.0",
53
- "eslint-config-oclif-typescript": "^3.1.7",
53
+ "eslint-config-oclif-typescript": "^3.1.8",
54
54
  "eslint-config-prettier": "^9.1.0",
55
55
  "husky": "^9",
56
56
  "lint-staged": "^15",
57
57
  "madge": "^6.1.0",
58
58
  "mocha": "^10.4.0",
59
59
  "nyc": "^15.1.0",
60
- "prettier": "^3.2.5",
60
+ "prettier": "^3.3.2",
61
61
  "shx": "^0.3.4",
62
62
  "sinon": "^18",
63
63
  "ts-node": "^10.9.2",
64
- "tsd": "^0.31.0",
64
+ "tsd": "^0.31.1",
65
65
  "typescript": "^5"
66
66
  },
67
67
  "engines": {