11import applicationinsights = require( "applicationinsights" ) ;
2+ import search = require( "libnpmsearch" ) ;
3+ import { graphql } from "@octokit/graphql" ;
24import * as yargs from "yargs" ;
35
46import { defaultLocalOptions } from "./lib/common" ;
@@ -52,8 +54,10 @@ if (!module.parent) {
5254 log
5355 ) ;
5456 } else {
57+ const allPackages = await AllPackages . read ( dt ) ;
5558 await publishPackages (
56- await readChangedPackages ( await AllPackages . read ( dt ) ) ,
59+ allPackages ,
60+ await readChangedPackages ( allPackages ) ,
5761 dry ,
5862 process . env . GH_API_TOKEN || "" ,
5963 new Fetcher ( )
@@ -63,6 +67,7 @@ if (!module.parent) {
6367}
6468
6569export default async function publishPackages (
70+ allPackages : AllPackages ,
6671 changedPackages : ChangedPackages ,
6772 dry : boolean ,
6873 githubAccessToken : string ,
@@ -187,6 +192,85 @@ export default async function publishPackages(
187192 cacheDirPath
188193 ) ;
189194
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+
190274 await writeLog ( "publishing.md" , logResult ( ) ) ;
191275 console . log ( "Done!" ) ;
192276}
0 commit comments