Skip to content

Commit

Permalink
Fix doctor type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Dec 16, 2024
1 parent 4b51e05 commit aa9eb07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/doctor/DiagnosticInfoBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ export class DiagnosticInfoBuilder {
}

async generateDiagnosticInfo(): Promise<DiagnosticInfo> {
// @ts-expect-error getProjectConfig not typed yet
this._projectConfig = await getProjectConfig();

if (this._projectConfig?.projectConfig) {
await this.fetchProjectDetails();
await this.fetchAccessToken();
}

if (this._projectConfig?.projectDir) {
await this.fetchProjectFilenames();
}

Expand Down Expand Up @@ -134,7 +136,8 @@ export class DiagnosticInfoBuilder {
try {
const { data } = await fetchProject(
this.accountId!,
this._projectConfig?.projectConfig?.name
// We check that config exists before running this function
this._projectConfig!.projectConfig!.name
);
this.projectDetails = data;
} catch (e) {
Expand All @@ -158,10 +161,11 @@ export class DiagnosticInfoBuilder {

private async fetchProjectFilenames(): Promise<void> {
try {
this.files = (await walk(this._projectConfig?.projectDir))
// We check that projectDir exists before running this function
this.files = (await walk(this._projectConfig!.projectDir!))
.filter(file => !path.dirname(file).includes('node_modules'))
.map(filename =>
path.relative(this._projectConfig?.projectDir, filename)
path.relative(this._projectConfig!.projectDir!, filename)
);
} catch (e) {
logger.debug(e);
Expand Down
10 changes: 7 additions & 3 deletions lib/doctor/Doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export class Doctor {
text: i18n(`${i18nKey}.runningDiagnostics`),
});

this.diagnosticInfo = await this.diagnosticInfoBuilder.generateDiagnosticInfo();
this.diagnosticInfo =
await this.diagnosticInfoBuilder.generateDiagnosticInfo();

this.projectConfig = this.diagnosticInfo?.project.config;

Expand Down Expand Up @@ -279,7 +280,7 @@ export class Doctor {
const packageDirName = path.dirname(packageFile);
try {
const needsInstall = await hasMissingPackages(
path.join(this.projectConfig?.projectDir, packageDirName)
path.join(this.projectConfig?.projectDir || '', packageDirName)
);

if (needsInstall) {
Expand Down Expand Up @@ -343,7 +344,10 @@ export class Doctor {
private async checkProjectConfigJsonFiles(): Promise<void> {
let foundError = false;
for (const jsonFile of this.diagnosticInfo?.jsonFiles || []) {
const fileToCheck = path.join(this.projectConfig?.projectDir, jsonFile);
const fileToCheck = path.join(
this.projectConfig?.projectDir || '',
jsonFile
);
if (!(await this.isValidJsonFile(fileToCheck))) {
foundError = true;
this.diagnosis?.addProjectSection({
Expand Down

0 comments on commit aa9eb07

Please sign in to comment.