1
1
import applicationinsights = require( "applicationinsights" ) ;
2
+ import search = require( "libnpmsearch" ) ;
3
+ import { graphql } from "@octokit/graphql" ;
2
4
import * as yargs from "yargs" ;
3
5
4
6
import { defaultLocalOptions } from "./lib/common" ;
@@ -52,8 +54,10 @@ if (!module.parent) {
52
54
log
53
55
) ;
54
56
} else {
57
+ const allPackages = await AllPackages . read ( dt ) ;
55
58
await publishPackages (
56
- await readChangedPackages ( await AllPackages . read ( dt ) ) ,
59
+ allPackages ,
60
+ await readChangedPackages ( allPackages ) ,
57
61
dry ,
58
62
process . env . GH_API_TOKEN || "" ,
59
63
new Fetcher ( )
@@ -63,6 +67,7 @@ if (!module.parent) {
63
67
}
64
68
65
69
export default async function publishPackages (
70
+ allPackages : AllPackages ,
66
71
changedPackages : ChangedPackages ,
67
72
dry : boolean ,
68
73
githubAccessToken : string ,
@@ -187,6 +192,85 @@ export default async function publishPackages(
187
192
cacheDirPath
188
193
) ;
189
194
195
+ // Loop over the @types packages in npm and mark any that no longer
196
+ // exist in HEAD as deprecated.
197
+ let from = 0 ;
198
+ let objects ;
199
+ do {
200
+ const opts = {
201
+ limit : 250 ,
202
+ from
203
+ } ;
204
+ objects = await search ( "@types" , opts ) ;
205
+ for ( const { name : fullNpmName } of objects ) {
206
+ const name = fullNpmName . slice ( "@types/" . length ) ;
207
+ // If they don't exist in the types directory or in
208
+ // notNeededPackages.json then mark them deprecated. Reference the
209
+ // commit/pull request that removed them.
210
+ if ( ! allPackages . tryGetLatestVersion ( name ) && ! allPackages . getNotNeededPackage ( name ) ) {
211
+ log ( `Deprecating ${ name } ` ) ;
212
+ const {
213
+ repository : {
214
+ ref : {
215
+ target : {
216
+ history : {
217
+ nodes : [ commit ]
218
+ }
219
+ }
220
+ }
221
+ }
222
+ } = await graphql (
223
+ `
224
+ query($path: String!) {
225
+ repository(name: "DefinitelyTyped", owner: "DefinitelyTyped") {
226
+ ref(qualifiedName: "master") {
227
+ target {
228
+ ... on Commit {
229
+ history(first: 1, path: $path) {
230
+ nodes {
231
+ associatedPullRequests(first: 1) {
232
+ nodes {
233
+ url
234
+ }
235
+ }
236
+ messageHeadline
237
+ }
238
+ }
239
+ }
240
+ }
241
+ }
242
+ }
243
+ }
244
+ ` ,
245
+ {
246
+ headers : { authorization : `token ${ githubAccessToken } ` } ,
247
+ path : `types/${ name } `
248
+ }
249
+ ) ;
250
+ let deprecatedMessage ;
251
+ if ( commit ) {
252
+ const {
253
+ associatedPullRequests : {
254
+ nodes : [ pullRequest ]
255
+ } ,
256
+ messageHeadline
257
+ } = commit ;
258
+ deprecatedMessage = messageHeadline ;
259
+ if ( pullRequest ) {
260
+ deprecatedMessage += ` (${ pullRequest . url } )` ;
261
+ }
262
+ }
263
+ if ( dry ) {
264
+ log ( `(dry) Skip deprecate removed package ${ fullNpmName } ` ) ;
265
+ } else {
266
+ log ( `Deprecating ${ fullNpmName } with message: ${ deprecatedMessage } ` ) ;
267
+ await client . deprecate ( fullNpmName , "" , deprecatedMessage ) ;
268
+ }
269
+ }
270
+ }
271
+ from += objects . length ;
272
+ } while ( objects . length >= 250 && from <= 5000 ) ;
273
+
190
274
await writeLog ( "publishing.md" , logResult ( ) ) ;
191
275
console . log ( "Done!" ) ;
192
276
}
0 commit comments