@@ -3,7 +3,6 @@ import path from 'path';
3
3
import race from 'promise-rat-race' ;
4
4
5
5
import type { RawPkg , Repo } from './@types/pkg' ;
6
- import { config } from './config' ;
7
6
import * as jsDelivr from './jsDelivr/index' ;
8
7
import { datadog } from './utils/datadog' ;
9
8
import { request } from './utils/request' ;
@@ -115,36 +114,27 @@ export async function getChangelog(
115
114
116
115
datadog . increment ( 'jsdelivr.getChangelog.miss' ) ;
117
116
118
- const { repository, name , version } = pkg ;
117
+ const { repository } = pkg ;
119
118
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 } ;
127
121
}
128
122
129
- const user = repository . user || '' ;
130
- const project = repository . project || '' ;
131
123
const host = repository . host || '' ;
132
- if ( user . length < 1 || project . length < 1 ) {
133
- return await raceFromPaths ( unpkgFiles ) ;
134
- }
124
+ const knownHost = baseUrlMap . get ( host ) ;
135
125
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 } ;
139
129
}
140
130
141
- const baseUrl = baseUrlMap . get ( host ) ! ( repository ) ;
142
-
131
+ const baseUrl = knownHost ( repository ) ;
143
132
const files = fileOptions . map ( ( file ) =>
144
133
[ baseUrl . replace ( / \/ $ / , '' ) , file ] . join ( '/' )
145
134
) ;
146
135
147
- return await raceFromPaths ( [ ...files , ...unpkgFiles ] ) ;
136
+ // Brute-force from git host
137
+ return await raceFromPaths ( [ ...files ] ) ;
148
138
} finally {
149
139
datadog . timing ( 'changelogs.getChangelog' , Date . now ( ) - start ) ;
150
140
}
0 commit comments