()
| 283 | } |
| 284 | |
| 285 | async _readConfigFile() { |
| 286 | const configPath = this._configPath; |
| 287 | let configFile; |
| 288 | if (path.isAbsolute(configPath)) { |
| 289 | // Handle absolute file paths with the native FS module |
| 290 | try { |
| 291 | configFile = await readFile(configPath, {encoding: "utf8"}); |
| 292 | } catch (err) { |
| 293 | // TODO: Caller might wants to ignore exceptions for ENOENT errors for non-root projects |
| 294 | // However, this decision should not be made here |
| 295 | throw new Error("Failed to read configuration for module " + |
| 296 | `${this.getId()} at '${configPath}'. Error: ${err.message}`); |
| 297 | } |
| 298 | } else { |
| 299 | // Handle relative file paths with the @ui5/fs (virtual) file system |
| 300 | const reader = this.getReader(); |
| 301 | let configResource; |
| 302 | try { |
| 303 | configResource = await reader.byPath(path.posix.join("/", configPath)); |
| 304 | } catch (err) { |
| 305 | throw new Error("Failed to read configuration for module " + |
| 306 | `${this.getId()} at "${configPath}". Error: ${err.message}`); |
| 307 | } |
| 308 | if (!configResource) { |
| 309 | if (configPath !== DEFAULT_CONFIG_PATH) { |
| 310 | throw new Error("Failed to read configuration for module " + |
| 311 | `${this.getId()}: Could not find configuration file in module at path '${configPath}'`); |
| 312 | } |
| 313 | return null; |
| 314 | } |
| 315 | configFile = await configResource.getString(); |
| 316 | } |
| 317 | |
| 318 | let configs; |
| 319 | |
| 320 | try { |
| 321 | // Using loadAll with DEFAULT_SAFE_SCHEMA instead of safeLoadAll to pass "filename". |
| 322 | // safeLoadAll doesn't handle its parameters properly. |
| 323 | // See https://github.com/nodeca/js-yaml/issues/456 and https://github.com/nodeca/js-yaml/pull/381 |
| 324 | configs = jsyaml.loadAll(configFile, undefined, { |
| 325 | filename: configPath, |
| 326 | schema: jsyaml.DEFAULT_SAFE_SCHEMA |
| 327 | }); |
| 328 | } catch (err) { |
| 329 | if (err.name === "YAMLException") { |
| 330 | throw new Error("Failed to parse configuration for project " + |
| 331 | `${this.getId()} at '${configPath}'\nError: ${err.message}`); |
| 332 | } else { |
| 333 | throw err; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if (!configs || !configs.length) { |
| 338 | // No configs found => exit here |
| 339 | return configs; |
| 340 | } |
| 341 | |
| 342 | // Validate found configurations with schema |
no test coverage detected