@@ -3,8 +3,6 @@ import process from "process";
3
3
import { emptyDir } from "fs-extra" ;
4
4
import * as yargs from "yargs" ;
5
5
6
- import { defaultLocalOptions , defaultRemoteOptions } from "./lib/common" ;
7
- import { outputDirPath , validateOutputPath } from "./lib/settings" ;
8
6
import {
9
7
getDefinitelyTyped ,
10
8
AllPackages ,
@@ -33,21 +31,18 @@ import {
33
31
} from "@definitelytyped/utils" ;
34
32
import * as pacote from "pacote" ;
35
33
import * as semver from "semver" ;
36
- // @ts -ignore
37
- import pkg from "../package.json" ;
38
34
39
- const typesRegistry = "types-registry" ;
40
- const registryOutputPath = joinPaths ( outputDirPath , typesRegistry ) ;
35
+ const registryOutputPath = joinPaths ( __dirname , ".." , "output" , "types-registry" ) ;
41
36
const 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 ).` ;
43
38
44
39
if ( ! module . parent ) {
45
- const dry = ! ! yargs . argv . dry ;
40
+ const { dry } = yargs . argv as never ;
46
41
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 ] ) ;
51
46
await publishRegistry ( dt , await AllPackages . read ( dt ) , dry ) ;
52
47
} ) ;
53
48
}
@@ -56,7 +51,7 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
56
51
const [ log , logResult ] = logger ( ) ;
57
52
log ( "=== Publishing types-registry ===" ) ;
58
53
59
- const { latestVersion, maxVersion, latestContentHash } = await fetchAndProcessNpmInfo ( typesRegistry ) ;
54
+ const { latestVersion, maxVersion, latestContentHash } = await fetchAndProcessNpmInfo ( "types-registry" ) ;
60
55
assert ( semver . satisfies ( latestVersion , "~0.1" ) ) ;
61
56
62
57
// Don't include not-needed packages in the registry.
@@ -69,7 +64,7 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
69
64
await writeLog ( "publish-registry.md" , logResult ( ) ) ;
70
65
71
66
async function publishToRegistry ( ) {
72
- const packageJson = generatePackageJson ( typesRegistry , newVersion , newContentHash ) ;
67
+ const packageJson = generatePackageJson ( "types-registry" , newVersion , newContentHash ) ;
73
68
await generate ( registry , packageJson ) ;
74
69
75
70
const token = process . env . NPM_TOKEN ! ;
@@ -81,10 +76,10 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
81
76
// If so, we should just update it to "latest" now.
82
77
log ( "Old version of types-registry was never tagged latest, so updating" ) ;
83
78
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 ) ;
85
80
} else if ( latestContentHash !== newContentHash ) {
86
81
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 ) ;
88
83
} else {
89
84
log ( "No new packages published, so no need to publish new registry." ) ;
90
85
// Just making sure...
@@ -133,6 +128,8 @@ async function publish(
133
128
await client . tag ( packageName , version , "latest" , dry , log ) ;
134
129
}
135
130
131
+ const validateOutputPath = joinPaths ( __dirname , ".." , "validateOutput" ) ;
132
+
136
133
async function installForValidate ( log : Logger ) : Promise < void > {
137
134
await emptyDir ( validateOutputPath ) ;
138
135
await writeJson ( joinPaths ( validateOutputPath , "package.json" ) , {
@@ -164,9 +161,8 @@ async function validate(log: Logger): Promise<void> {
164
161
165
162
async function validateIsSubset ( notNeeded : readonly NotNeededPackage [ ] , log : Logger ) : Promise < void > {
166
163
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 ;
170
166
for ( const key of Object . keys ( actual . entries ) ) {
171
167
if ( ! ( key in expected . entries ) && ! notNeeded . some ( ( p ) => p . name === key ) ) {
172
168
throw new Error ( `Actual types-registry has unexpected key ${ key } ` ) ;
@@ -206,17 +202,21 @@ function assertJsonNewer(newer: { [s: string]: any }, older: { [s: string]: any
206
202
}
207
203
208
204
function generatePackageJson ( name : string , version : string , typesPublisherContentHash : string ) : object {
209
- const json = {
205
+ return {
210
206
name,
211
207
version,
212
208
description : "A registry of TypeScript declaration file packages published within the @types scope." ,
213
- repository : pkg . repository ,
214
209
keywords : [ "TypeScript" , "declaration" , "files" , "types" , "packages" ] ,
215
- author : "Microsoft Corp. " ,
210
+ homepage : "https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/publish-registry#readme " ,
216
211
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
+ } ,
217
218
typesPublisherContentHash,
218
219
} ;
219
- return json ;
220
220
}
221
221
222
222
interface Registry {
@@ -256,5 +256,6 @@ async function fetchAndProcessNpmInfo(packageName: string): Promise<ProcessedNpm
256
256
const latestVersion = info [ "dist-tags" ] . latest ;
257
257
const maxVersion = semver . maxSatisfying ( Object . keys ( info . versions ) , "*" ) ;
258
258
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 } ;
260
261
}
0 commit comments