Skip to content

Commit

Permalink
fix(gradle): fix tasksFileLines might be undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Aug 20, 2024
1 parent fdb488b commit 5781d6f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/gradle/src/utils/get-gradle-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function processProjectReports(
}
const [_, file] = projectReportLines[index].split(fileSeparator);
const propertyReportLines = existsSync(file)
? readFileSync(file).toString().split(newLineSeparator)
? readFileSync(file)?.toString()?.split(newLineSeparator)
: [];

let projectName: string,
Expand All @@ -191,7 +191,7 @@ export function processProjectReports(
const childProjects = line.substring('childProjects: {'.length); // remove curly braces {} around childProjects
gradleProjectToChildProjects.set(
gradleProject,
childProjects.split(',').map((c) => c.trim().split('=')[0]) // e.g. get project name from text like "app=project ':app', mylibrary=project ':mylibrary'"
childProjects?.split(',').map((c) => c?.trim()?.split('=')?.[0]) // e.g. get project name from text like "app=project ':app', mylibrary=project ':mylibrary'"
);
}
if (line.includes('Dir: ')) {
Expand Down Expand Up @@ -240,7 +240,7 @@ export function processProjectReports(
const [_, file] = projectReportLines[index].split(fileSeparator);
const taskTypeMap = new Map<string, string>();
const tasksFileLines = existsSync(file)
? readFileSync(file).toString().split(newLineSeparator)
? readFileSync(file)?.toString()?.split(newLineSeparator)
: [];

let i = 0;
Expand All @@ -252,7 +252,11 @@ export function processProjectReports(
if (tasksFileLines[i + 1] === dashes) {
const type = line.substring(0, line.length - ' tasks'.length);
i++;
while (tasksFileLines[++i] !== '') {
while (
tasksFileLines[++i] !== '' &&
i < tasksFileLines.length &&
tasksFileLines[i]?.includes(' - ')
) {
const [taskName] = tasksFileLines[i].split(' - ');
taskTypeMap.set(taskName, type);
}
Expand Down

0 comments on commit 5781d6f

Please sign in to comment.