Skip to content

Commit aae2d86

Browse files
author
Samuel Bodin
authored
fix: stop using unpkg (#658)
1 parent d36a77a commit aae2d86

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

src/__tests__/changelog.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ jest.mock('got', () => {
66
'https://raw.githubusercontent.com/algolia/algoliasearch-netlify/master/CHANGELOG.md',
77
'https://bitbucket.org/atlassian/aui/raw/master/changelog.md',
88
'https://raw.githubusercontent.com/expressjs/body-parser/master/HISTORY.md',
9-
'https://unpkg.com/@atlaskit/[email protected]/CHANGELOG.md',
109
]);
1110

1211
return (url: string): Promise<{ url: string; redirectUrls: string[] }> => {
@@ -134,20 +133,6 @@ it('should get changelog for github', async () => {
134133
);
135134
});
136135

137-
it('should get changelog from unpkg if there is no repository field', async () => {
138-
const pkg = {
139-
name: '@atlaskit/button',
140-
version: '13.3.7',
141-
repository: null,
142-
};
143-
144-
const [{ changelogFilename }] = await getChangelogs([pkg], []);
145-
146-
expect(changelogFilename).toBe(
147-
'https://unpkg.com/@atlaskit/[email protected]/CHANGELOG.md'
148-
);
149-
});
150-
151136
it('should get changelog for gitlab', async () => {
152137
const pkg = {
153138
name: 'foo',

src/changelog.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from 'path';
33
import race from 'promise-rat-race';
44

55
import type { RawPkg, Repo } from './@types/pkg';
6-
import { config } from './config';
76
import * as jsDelivr from './jsDelivr/index';
87
import { datadog } from './utils/datadog';
98
import { request } from './utils/request';
@@ -115,36 +114,27 @@ export async function getChangelog(
115114

116115
datadog.increment('jsdelivr.getChangelog.miss');
117116

118-
const { repository, name, version } = pkg;
117+
const { repository } = pkg;
119118

120-
// Rollback to brute-force the source code
121-
const unpkgFiles = fileOptions.map(
122-
(file) => `${config.unpkgRoot}/${name}@${version}/${file}`
123-
);
124-
125-
if (repository === null) {
126-
return await raceFromPaths(unpkgFiles);
119+
if (repository === null || !repository.host) {
120+
return { changelogFilename: null };
127121
}
128122

129-
const user = repository.user || '';
130-
const project = repository.project || '';
131123
const host = repository.host || '';
132-
if (user.length < 1 || project.length < 1) {
133-
return await raceFromPaths(unpkgFiles);
134-
}
124+
const knownHost = baseUrlMap.get(host);
135125

136-
// Check if we know how to handle this host
137-
if (!baseUrlMap.has(host)) {
138-
return await raceFromPaths(unpkgFiles);
126+
// No known git hosts
127+
if (!knownHost) {
128+
return { changelogFilename: null };
139129
}
140130

141-
const baseUrl = baseUrlMap.get(host)!(repository);
142-
131+
const baseUrl = knownHost(repository);
143132
const files = fileOptions.map((file) =>
144133
[baseUrl.replace(/\/$/, ''), file].join('/')
145134
);
146135

147-
return await raceFromPaths([...files, ...unpkgFiles]);
136+
// Brute-force from git host
137+
return await raceFromPaths([...files]);
148138
} finally {
149139
datadog.timing('changelogs.getChangelog', Date.now() - start);
150140
}

src/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export const config = {
156156
jsDelivrPackageEndpoint: 'https://data.jsdelivr.com/v1/package/npm',
157157
typescriptTypesIndex:
158158
'https://typespublisher.blob.core.windows.net/typespublisher/data/search-index-min.json',
159-
unpkgRoot: 'https://unpkg.com',
160159
maxObjSize: 450000,
161160
popularDownloadsRatio: 0.005,
162161
appId: 'OFCNCOG2CU',

0 commit comments

Comments
 (0)