in tsdoc-config/src/TSDocConfigFile.ts [346:439]
private _loadWithExtends(
configFilePath: string,
referencingConfigFile: TSDocConfigFile | undefined,
alreadyVisitedPaths: Set<string>
): void {
// In case an exception is thrown, start by assuming that the file was not found; we'll revise
// this later upon success
this._fileNotFound = true;
if (!configFilePath) {
this._reportError({
messageId: TSDocMessageId.ConfigFileNotFound,
messageText: 'File not found',
textRange: TextRange.empty,
});
return;
}
this._filePath = path.resolve(configFilePath);
if (!fs.existsSync(this._filePath)) {
this._reportError({
messageId: TSDocMessageId.ConfigFileNotFound,
messageText: 'File not found',
textRange: TextRange.empty,
});
return;
}
const configJsonContent: string = fs.readFileSync(this._filePath).toString();
this._fileMTime = fs.statSync(this._filePath).mtimeMs;
this._fileNotFound = false;
const hashKey: string = fs.realpathSync(this._filePath);
if (referencingConfigFile && alreadyVisitedPaths.has(hashKey)) {
this._reportError({
messageId: TSDocMessageId.ConfigFileCyclicExtends,
messageText: `Circular reference encountered for "extends" field of "${referencingConfigFile.filePath}"`,
textRange: TextRange.empty,
});
return;
}
alreadyVisitedPaths.add(hashKey);
let configJson: IConfigJson;
try {
configJson = jju.parse(configJsonContent, { mode: 'cjson' });
} catch (e) {
this._reportError({
messageId: TSDocMessageId.ConfigInvalidJson,
messageText: 'Error parsing JSON input: ' + e.message,
textRange: TextRange.empty,
});
return;
}
this._loadJsonObject(configJson);
const configFileFolder: string = path.dirname(this.filePath);
for (const extendsField of this.extendsPaths) {
let resolvedExtendsPath: string;
try {
resolvedExtendsPath = resolve.sync(extendsField, { basedir: configFileFolder });
} catch (e) {
this._reportError({
messageId: TSDocMessageId.ConfigFileUnresolvedExtends,
messageText: `Unable to resolve "extends" reference to "${extendsField}": ` + e.message,
textRange: TextRange.empty,
});
return;
}
const baseConfigFile: TSDocConfigFile = new TSDocConfigFile();
baseConfigFile._loadWithExtends(resolvedExtendsPath, this, alreadyVisitedPaths);
if (baseConfigFile.fileNotFound) {
this._reportError({
messageId: TSDocMessageId.ConfigFileUnresolvedExtends,
messageText: `Unable to resolve "extends" reference to "${extendsField}"`,
textRange: TextRange.empty,
});
}
this._extendsFiles.push(baseConfigFile);
if (baseConfigFile.hasErrors) {
this._hasErrors = true;
}
}
}