Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-seahorses-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/project-access': patch
---

Improve function `refreshSpecificationDistTags` - prevent caching `specification-dist-tags.json` if an error is returned in the JSON from `npm view @sap/ux-specification dist-tags --json`
4 changes: 4 additions & 0 deletions packages/project-access/src/project/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export async function refreshSpecificationDistTags(options?: { logger?: Logger }
logger
});
const distTags = JSON.parse(distTagsString) as Record<string, string>;
if ('error' in distTags) {
// Abort writing cache: received error in dist-tags response
throw new Error(distTagsString);
}
await writeFile(specificationDistTagPath, JSON.stringify(distTags, null, 4));
const uniqueVersions = new Set(Object.values(distTags));

Expand Down
10 changes: 10 additions & 0 deletions packages/project-access/test/project/specification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ describe('Test refreshSpecificationDistTags()', () => {
await refreshSpecificationDistTags({ logger });
expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('NPM_ERROR'));
});

test('Refresh specification dist tags - error in response. Contains code and summary.', async () => {
const refreshResponse = '{"error": {"code": "ENOTFOUND", "summary": "Request to uri failed."}}';
jest.spyOn(commandMock, 'execNpmCommand').mockResolvedValueOnce(refreshResponse);
const logger = getMockLogger();
await refreshSpecificationDistTags({ logger });
expect(logger.error).toHaveBeenCalledWith(
`Error refreshing specification dist-tags: Error: ${refreshResponse}`
);
});
});

function getMockLogger(): Logger {
Expand Down
Loading