@rushstack/heft-config-file
Version:
Configuration file loader for @rushstack/heft
54 lines • 2.29 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { FileSystem, PackageJsonLookup } from '@rushstack/node-core-library';
import { ConfigurationFileBase } from './ConfigurationFileBase';
/**
* @beta
*/
export class NonProjectConfigurationFile extends ConfigurationFileBase {
/**
* Load the configuration file at the specified absolute path, automatically resolving
* `extends` properties. Will throw an error if the file cannot be found.
*/
loadConfigurationFile(terminal, filePath) {
return this._loadConfigurationFileInnerWithCache(terminal, filePath, PackageJsonLookup.instance.tryGetPackageFolderFor(filePath));
}
/**
* Load the configuration file at the specified absolute path, automatically resolving
* `extends` properties. Will throw an error if the file cannot be found.
*/
async loadConfigurationFileAsync(terminal, filePath) {
return await this._loadConfigurationFileInnerWithCacheAsync(terminal, filePath, PackageJsonLookup.instance.tryGetPackageFolderFor(filePath));
}
/**
* This function is identical to {@link NonProjectConfigurationFile.loadConfigurationFile}, except
* that it returns `undefined` instead of throwing an error if the configuration file cannot be found.
*/
tryLoadConfigurationFile(terminal, filePath) {
try {
return this.loadConfigurationFile(terminal, filePath);
}
catch (e) {
if (FileSystem.isNotExistError(e)) {
return undefined;
}
throw e;
}
}
/**
* This function is identical to {@link NonProjectConfigurationFile.loadConfigurationFileAsync}, except
* that it returns `undefined` instead of throwing an error if the configuration file cannot be found.
*/
async tryLoadConfigurationFileAsync(terminal, filePath) {
try {
return await this.loadConfigurationFileAsync(terminal, filePath);
}
catch (e) {
if (FileSystem.isNotExistError(e)) {
return undefined;
}
throw e;
}
}
}
//# sourceMappingURL=NonProjectConfigurationFile.js.map