@oclif/core 1.8.1 → 1.8.2

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.8.2](https://github.com/oclif/core/compare/v1.8.1...v1.8.2) (2022-05-18)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * properly load index.js ES modules (cont) ([#417](https://github.com/oclif/core/issues/417)) ([77ba8b8](https://github.com/oclif/core/commit/77ba8b891f941e371bacd0dbedb32be25d6d2599))
11
+
5
12
  ### [1.8.1](https://github.com/oclif/core/compare/v1.8.0...v1.8.1) (2022-05-10)
6
13
 
7
14
 
@@ -71,4 +71,12 @@ export default class ModuleLoader {
71
71
  isESM: boolean;
72
72
  filePath: string;
73
73
  };
74
+ /**
75
+ * Try adding the different extensions from `s_EXTENSIONS` to find the file.
76
+ *
77
+ * @param {string} filePath - File path to load.
78
+ *
79
+ * @returns {string | null} Modified file path including extension or null if file is not found.
80
+ */
81
+ static findFile(filePath: string): string | null;
74
82
  }
@@ -119,6 +119,7 @@ class ModuleLoader {
119
119
  * @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
120
120
  */
121
121
  static resolvePath(config, modulePath) {
122
+ var _a, _b;
122
123
  let isESM;
123
124
  let filePath;
124
125
  try {
@@ -127,20 +128,49 @@ class ModuleLoader {
127
128
  }
128
129
  catch {
129
130
  filePath = Config.tsPath(config.root, modulePath);
130
- // Try all supported extensions.
131
- if (!fs.existsSync(filePath)) {
132
- // eslint-disable-next-line camelcase
133
- for (const extension of s_EXTENSIONS) {
134
- const testPath = `${filePath}${extension}`;
135
- if (fs.existsSync(testPath)) {
136
- filePath = testPath;
137
- break;
131
+ let fileExists = false;
132
+ let isDirectory = false;
133
+ if (fs.existsSync(filePath)) {
134
+ fileExists = true;
135
+ try {
136
+ if ((_b = (_a = fs.lstatSync(filePath)) === null || _a === void 0 ? void 0 : _a.isDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)) {
137
+ fileExists = false;
138
+ isDirectory = true;
138
139
  }
139
140
  }
141
+ catch { }
142
+ }
143
+ if (!fileExists) {
144
+ // Try all supported extensions.
145
+ let foundPath = ModuleLoader.findFile(filePath);
146
+ if (!foundPath && isDirectory) {
147
+ // Since filePath is a directory, try looking for index.js file.
148
+ foundPath = ModuleLoader.findFile(path.join(filePath, 'index'));
149
+ }
150
+ if (foundPath) {
151
+ filePath = foundPath;
152
+ }
140
153
  }
141
154
  isESM = ModuleLoader.isPathModule(filePath);
142
155
  }
143
156
  return { isESM, filePath };
144
157
  }
158
+ /**
159
+ * Try adding the different extensions from `s_EXTENSIONS` to find the file.
160
+ *
161
+ * @param {string} filePath - File path to load.
162
+ *
163
+ * @returns {string | null} Modified file path including extension or null if file is not found.
164
+ */
165
+ static findFile(filePath) {
166
+ // eslint-disable-next-line camelcase
167
+ for (const extension of s_EXTENSIONS) {
168
+ const testPath = `${filePath}${extension}`;
169
+ if (fs.existsSync(testPath)) {
170
+ return testPath;
171
+ }
172
+ }
173
+ return null;
174
+ }
145
175
  }
146
176
  exports.default = ModuleLoader;
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": "1.8.1",
4
+ "version": "1.8.2",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {