Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 5a20da2

Browse files
authored
fix: handle empty cases for all manifests (#184)
Fixes fabric8-analytics/fabric8-analytics-vscode-extension#493
1 parent 158b1b1 commit 5a20da2

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/collector/package.json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class DependencyCollector implements IDependencyCollector {
77
constructor(public classes: Array<string> = ["dependencies"]) {}
88

99
async collect(contents: string): Promise<Array<IDependency>> {
10-
const ast = jsonAst(contents);
10+
const ast = jsonAst(contents || '{}');
1111
return ast.children.
1212
filter(c => this.classes.includes(c.key.value)).
1313
flatMap(c => c.value.children).

test/collector/go.mod.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ github.com/stretchr/testify`);
7272
});
7373
});
7474

75+
it('tests empty go.mod', async () => {
76+
fake(getGoLangImportsCmd(), `github.com/alecthomas/units
77+
github.com/stretchr/testify`);
78+
const deps = await collector.collect(``);
79+
expect(deps).is.eql([]);
80+
});
81+
7582
it('tests empty lines in go.mod', async () => {
7683
fake(getGoLangImportsCmd(), `github.com/alecthomas/units
7784
github.com/stretchr/testify`);

test/collector/package.json.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { DependencyCollector } from '../../src/collector/package.json';
44
describe('npm package.json parser test', () => {
55
const collector = new DependencyCollector();
66

7+
it('tests empty package.json file content', async () => {
8+
const deps = await collector.collect(``);
9+
expect(deps.length).equal(0);
10+
});
11+
712
it('tests empty package.json', async () => {
813
const deps = await collector.collect(`
914
{}

test/collector/requirements.txt.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ describe('PyPi requirements.txt parser test', () => {
4545
}]);
4646
});
4747

48+
it('tests empty requirements.txt', async () => {
49+
const deps = await collector.collect(``);
50+
expect(deps).is.eql([]);
51+
});
52+
4853
it('tests empty lines', async () => {
4954
const deps = await collector.collect(`
5055

0 commit comments

Comments
 (0)