Skip to content

Commit

Permalink
fix: massage depName if missing (#28831)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored May 4, 2024
1 parent 74d2bfb commit 5f1286f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/workers/repository/extract/manager-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe('workers/repository/extract/manager-files', () => {
fileMatch.getMatchingFiles.mockReturnValue(['Dockerfile']);
fs.readLocalFile.mockResolvedValueOnce('some content');
html.extractPackageFile = jest.fn(() => ({
deps: [{}, { replaceString: 'abc' }],
deps: [{}, { replaceString: 'abc', packageName: 'p' }],
})) as never;
const res = await getManagerPackageFiles(managerConfig);
expect(res).toEqual([
{
packageFile: 'Dockerfile',
deps: [{}, { replaceString: 'abc' }],
deps: [{}, { replaceString: 'abc', packageName: 'p', depName: 'p' }],
},
]);
});
Expand Down
14 changes: 14 additions & 0 deletions lib/workers/repository/extract/manager-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import type { PackageFile } from '../../../modules/manager/types';
import { readLocalFile } from '../../../util/fs';
import type { WorkerExtractConfig } from '../../types';

function massageDepNames(packageFiles: PackageFile[] | null): void {
if (packageFiles) {
for (const packageFile of packageFiles) {
for (const dep of packageFile.deps) {
if (dep.packageName && !dep.depName) {
dep.depName = dep.packageName;
}
}
}
}
}

export async function getManagerPackageFiles(
config: WorkerExtractConfig,
): Promise<PackageFile[] | null> {
Expand All @@ -35,6 +47,7 @@ export async function getManagerPackageFiles(
config,
fileList,
);
massageDepNames(allPackageFiles);
return allPackageFiles;
}
const packageFiles: PackageFile[] = [];
Expand All @@ -58,5 +71,6 @@ export async function getManagerPackageFiles(
logger.debug(`${packageFile} has no content`);
}
}
massageDepNames(packageFiles);
return packageFiles;
}

0 comments on commit 5f1286f

Please sign in to comment.