@@ -3,8 +3,6 @@ import process from "process";
33import { emptyDir } from "fs-extra" ;
44import * as yargs from "yargs" ;
55
6- import { defaultLocalOptions , defaultRemoteOptions } from "./lib/common" ;
7- import { outputDirPath , validateOutputPath } from "./lib/settings" ;
86import {
97 getDefinitelyTyped ,
108 AllPackages ,
@@ -33,21 +31,18 @@ import {
3331} from "@definitelytyped/utils" ;
3432import * as pacote from "pacote" ;
3533import * as semver from "semver" ;
36- // @ts -ignore
37- import pkg from "../package.json" ;
3834
39- const typesRegistry = "types-registry" ;
40- const registryOutputPath = joinPaths ( outputDirPath , typesRegistry ) ;
35+ const registryOutputPath = joinPaths ( __dirname , ".." , "output" , "types-registry" ) ;
4136const readme = `This package contains a listing of all packages published to the @types scope on NPM.
42- Generated by [types-publisher](${ pkg . homepage } ).` ;
37+ Generated by [types-publisher](https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/publish-registry#readme ).` ;
4338
4439if ( ! module . parent ) {
45- const dry = ! ! yargs . argv . dry ;
40+ const { dry } = yargs . argv as never ;
4641 logUncaughtErrors ( async ( ) => {
47- const dt = await getDefinitelyTyped (
48- process . env . GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions ,
49- loggerWithErrors ( ) [ 0 ]
50- ) ;
42+ const options = process . env . GITHUB_ACTIONS
43+ ? { definitelyTypedPath : undefined , progress : false , parseInParallel : false }
44+ : { definitelyTypedPath : "../../../DefinitelyTyped" , progress : true , parseInParallel : true } ;
45+ const dt = await getDefinitelyTyped ( options , loggerWithErrors ( ) [ 0 ] ) ;
5146 await publishRegistry ( dt , await AllPackages . read ( dt ) , dry ) ;
5247 } ) ;
5348}
@@ -56,7 +51,7 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
5651 const [ log , logResult ] = logger ( ) ;
5752 log ( "=== Publishing types-registry ===" ) ;
5853
59- const { latestVersion, maxVersion, latestContentHash } = await fetchAndProcessNpmInfo ( typesRegistry ) ;
54+ const { latestVersion, maxVersion, latestContentHash } = await fetchAndProcessNpmInfo ( "types-registry" ) ;
6055 assert ( semver . satisfies ( latestVersion , "~0.1" ) ) ;
6156
6257 // Don't include not-needed packages in the registry.
@@ -69,7 +64,7 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
6964 await writeLog ( "publish-registry.md" , logResult ( ) ) ;
7065
7166 async function publishToRegistry ( ) {
72- const packageJson = generatePackageJson ( typesRegistry , newVersion , newContentHash ) ;
67+ const packageJson = generatePackageJson ( "types-registry" , newVersion , newContentHash ) ;
7368 await generate ( registry , packageJson ) ;
7469
7570 const token = process . env . NPM_TOKEN ! ;
@@ -81,10 +76,10 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
8176 // If so, we should just update it to "latest" now.
8277 log ( "Old version of types-registry was never tagged latest, so updating" ) ;
8378 await validateIsSubset ( readNotNeededPackages ( dt ) , log ) ;
84- await ( await publishClient ( ) ) . tag ( typesRegistry , maxVersion , "latest" , dry , log ) ;
79+ await ( await publishClient ( ) ) . tag ( "types-registry" , maxVersion , "latest" , dry , log ) ;
8580 } else if ( latestContentHash !== newContentHash ) {
8681 log ( "New packages have been added, so publishing a new registry." ) ;
87- await publish ( await publishClient ( ) , typesRegistry , packageJson , newVersion , dry , log ) ;
82+ await publish ( await publishClient ( ) , "types-registry" , packageJson , newVersion , dry , log ) ;
8883 } else {
8984 log ( "No new packages published, so no need to publish new registry." ) ;
9085 // Just making sure...
@@ -133,6 +128,8 @@ async function publish(
133128 await client . tag ( packageName , version , "latest" , dry , log ) ;
134129}
135130
131+ const validateOutputPath = joinPaths ( __dirname , ".." , "validateOutput" ) ;
132+
136133async function installForValidate ( log : Logger ) : Promise < void > {
137134 await emptyDir ( validateOutputPath ) ;
138135 await writeJson ( joinPaths ( validateOutputPath , "package.json" ) , {
@@ -164,9 +161,8 @@ async function validate(log: Logger): Promise<void> {
164161
165162async function validateIsSubset ( notNeeded : readonly NotNeededPackage [ ] , log : Logger ) : Promise < void > {
166163 await installForValidate ( log ) ;
167- const indexJson = "index.json" ;
168- const actual = ( await readJson ( joinPaths ( validateTypesRegistryPath , indexJson ) ) ) as Registry ;
169- const expected = ( await readJson ( joinPaths ( registryOutputPath , indexJson ) ) ) as Registry ;
164+ const actual = ( await readJson ( joinPaths ( validateTypesRegistryPath , "index.json" ) ) ) as Registry ;
165+ const expected = ( await readJson ( joinPaths ( registryOutputPath , "index.json" ) ) ) as Registry ;
170166 for ( const key of Object . keys ( actual . entries ) ) {
171167 if ( ! ( key in expected . entries ) && ! notNeeded . some ( ( p ) => p . name === key ) ) {
172168 throw new Error ( `Actual types-registry has unexpected key ${ key } ` ) ;
@@ -206,17 +202,21 @@ function assertJsonNewer(newer: { [s: string]: any }, older: { [s: string]: any
206202}
207203
208204function generatePackageJson ( name : string , version : string , typesPublisherContentHash : string ) : object {
209- const json = {
205+ return {
210206 name,
211207 version,
212208 description : "A registry of TypeScript declaration file packages published within the @types scope." ,
213- repository : pkg . repository ,
214209 keywords : [ "TypeScript" , "declaration" , "files" , "types" , "packages" ] ,
215- author : "Microsoft Corp. " ,
210+ homepage : "https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/publish-registry#readme " ,
216211 license : "MIT" ,
212+ author : "Microsoft Corp." ,
213+ repository : {
214+ type : "git" ,
215+ url : "https://github.com/microsoft/DefinitelyTyped-tools.git" ,
216+ directory : "packages/publish-registry" ,
217+ } ,
217218 typesPublisherContentHash,
218219 } ;
219- return json ;
220220}
221221
222222interface Registry {
@@ -256,5 +256,6 @@ async function fetchAndProcessNpmInfo(packageName: string): Promise<ProcessedNpm
256256 const latestVersion = info [ "dist-tags" ] . latest ;
257257 const maxVersion = semver . maxSatisfying ( Object . keys ( info . versions ) , "*" ) ;
258258 assert . strictEqual ( maxVersion , info [ "dist-tags" ] . next ) ;
259- return { latestVersion, maxVersion, latestContentHash : info . versions [ latestVersion ] . typesPublisherContentHash } ;
259+ const latestContentHash = info . versions [ latestVersion ] . typesPublisherContentHash ;
260+ return { latestVersion, maxVersion, latestContentHash } ;
260261}
0 commit comments