Skip to content

Commit b5890e3

Browse files
committed
Extract publish registry from publisher
1 parent ed74841 commit b5890e3

File tree

13 files changed

+1729
-1766
lines changed

13 files changed

+1729
-1766
lines changed

.github/workflows/publish-registry.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
key: cache-${{ github.run_id }}
2323
restore-keys: cache-
2424
- name: Publish registry
25-
run: yarn workspace @definitelytyped/publisher publish-registry
25+
run: node --require source-map-support/register packages/publish-registry/
2626
env:
2727
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
2828
- if: always()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ A monorepo for formerly disparate DefinitelyTyped-related tools:
88
- [dts-critic](packages/dts-critic): [DefinitelyTyped/dts-critic](https://github.com/DefinitelyTyped/dts-critic)
99
- [header-parser](packages/header-parser): [microsoft/definitelytyped-header-parser](https://github.com/microsoft/definitelytyped-header-parser)
1010
- [perf](packages/perf): [andrewbranch/definitely-not-slow](https://github.com/andrewbranch/definitely-not-slow)
11+
- [publish-registry](packages/publish-registry): Publish the [`types-registry`](https://www.npmjs.com/package/types-registry) package to npm (a list of all @types packages in the DT repo.
1112
- [publisher](packages/publisher): the rest of [microsoft/types-publisher](https://github.com/microsoft/types-publisher)
1213
- [retag](packages/retag): [DefinitelyTyped/dt-retag](https://github.com/DefinitelyTyped/dt-retag)
1314
- [typescript-versions](packages/typescript-versions): the part of [definitelytyped-header-parser](https://github.com/microsoft/definitelytyped-header-parser) that tracked which TypeScript versions are published to npm and supported on DefinitelyTyped

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
"ts-jest": "^25.2.1",
2929
"tslint": "^6.1.2",
3030
"tslint-microsoft-contrib": "^6.2.0",
31-
"typescript": "^4.7.4"
31+
"typescript": "^4.6.4"
3232
}
3333
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# publish-registry
2+
3+
[![Publish registry](https://github.com/microsoft/DefinitelyTyped-tools/actions/workflows/publish-registry.yml/badge.svg)](https://github.com/microsoft/DefinitelyTyped-tools/actions/workflows/publish-registry.yml)
4+
5+
Publish the [`types-registry`](https://www.npmjs.com/package/types-registry) package to npm (a list of all @types packages in the DT repo.
6+
7+
## Use
8+
9+
```sh
10+
yarn workspace @definitelytyped/publisher parse
11+
node packages/publish-registry/
12+
```
13+
14+
1. [Parse declarations](../publisher/README.md#parse-the-definitions).
15+
2. Run this package's script.
16+
17+
### Options
18+
19+
<dl><dt>
20+
21+
`--dry`
22+
23+
</dt><dd>
24+
25+
Don't actually publish the package, just show what would be done.
26+
27+
</dd></dl>
28+
29+
### Environment variables
30+
31+
<dl><dt>
32+
33+
[`NPM_TOKEN`](https://docs.npmjs.com/about-access-tokens)
34+
35+
</dt><dd>
36+
37+
Not required for a dry run.
38+
Only used to actually publish the package.
39+
40+
</dd></dl>
41+
42+
## Logs
43+
44+
GitHub Actions runs this package's script weekly.
45+
You can [examine the logs](https://github.com/microsoft/DefinitelyTyped-tools/actions/workflows/publish-registry.yml).
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@definitelytyped/publish-registry",
3+
"version": "1.0.0",
4+
"description": "Publish the types-registry package to npm (a list of all @types packages in the DT repo).",
5+
"license": "MIT",
6+
"main": "dist/index.js",
7+
"scripts": {
8+
"build": "tsc --build"
9+
},
10+
"dependencies": {
11+
"@definitelytyped/definitions-parser": "^0.0.121",
12+
"@definitelytyped/utils": "^0.0.121",
13+
"fs-extra": "^10.1.0",
14+
"pacote": "^13.6.1",
15+
"semver": "^7.3.7",
16+
"yargs": "^17.5.1"
17+
},
18+
"devDependencies": {
19+
"@types/fs-extra": "^9.0.13",
20+
"@types/pacote": "^11.1.5",
21+
"@types/semver": "^7.3.10",
22+
"@types/yargs": "^17.0.10"
23+
},
24+
"private": true
25+
}

packages/publisher/src/publish-registry.ts renamed to packages/publish-registry/src/index.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import process from "process";
33
import { emptyDir } from "fs-extra";
44
import * as yargs from "yargs";
55

6-
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
7-
import { outputDirPath, validateOutputPath } from "./lib/settings";
86
import {
97
getDefinitelyTyped,
108
AllPackages,
@@ -33,21 +31,18 @@ import {
3331
} from "@definitelytyped/utils";
3432
import * as pacote from "pacote";
3533
import * 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");
4136
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).`;
4338

4439
if (!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+
136133
async 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

165162
async 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

208204
function 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

222222
interface 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
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "src/",
5+
"outDir": "dist/"
6+
},
7+
"references": [{ "path": "../definitions-parser/" }, { "path": "../utils/" }]
8+
}

packages/publisher/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ npm run upload-blobs
4343
and optionally (in production, these run once a week):
4444

4545
```
46-
npm run publish-registry
4746
npm run validate
4847
```
4948

@@ -241,13 +240,6 @@ It also indicates any errors that may have occurred during publishing.
241240
Note that unlike other steps, this log file output is *not* idempotent.
242241
Scripts should save this log under a unique filename so any errors may be reviewed.
243242

244-
# Publish registry
245-
246-
> `npm run publish -- [--dry]`
247-
248-
This step publishes the `types-registry` package on NPM, which keeps a list of all `@types` packages.
249-
This step only happens if there are some new packages to register.
250-
251243
# Settings
252244

253245
This file contains settings used by the publisher.

packages/publisher/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"validate": "node -r source-map-support/register dist/validate.js",
4949
"publish-packages": "node -r source-map-support/register dist/publish-packages.js",
5050
"publish-packages-dry": "node -r source-map-support/register dist/publish-packages.js --dry",
51-
"publish-registry": "node -r source-map-support/register dist/publish-registry.js",
5251
"full": "node -r source-map-support/register dist/full.js",
5352
"full-dry": "node -r source-map-support/register dist/full.js --dry",
5453
"test-tsNext": "node -r source-map-support/register dist/tester/test.js --all --tsNext"

packages/publisher/src/clean.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { clean as cleanParser } from "@definitelytyped/definitions-parser";
22
import { cleanLogDirectory } from "@definitelytyped/utils";
33
import { removeSync } from "fs-extra";
4-
import { outputDirPath, validateOutputPath } from "./lib/settings";
4+
import { outputDirPath } from "./lib/settings";
55

66
if (!module.parent) {
77
clean();
@@ -11,5 +11,4 @@ export function clean() {
1111
cleanParser();
1212
cleanLogDirectory();
1313
removeSync(outputDirPath);
14-
removeSync(validateOutputPath);
1514
}

0 commit comments

Comments
 (0)