|
1 | | -import assert = require("assert"); |
2 | | -import { Logger, joinPaths, readFileAndWarn, NpmPublishClient } from "@definitelytyped/utils"; |
| 1 | +import { Logger, NpmPublishClient } from "@definitelytyped/utils"; |
3 | 2 | import { NotNeededPackage, AnyPackage } from "@definitelytyped/definitions-parser"; |
4 | | -import { updateTypeScriptVersionTags, updateLatestTag } from "@definitelytyped/retag"; |
| 3 | +import { updateTypeScriptVersionTags } from "@definitelytyped/retag"; |
| 4 | +import * as libpub from "libnpmpublish"; |
| 5 | +import * as pacote from "pacote"; |
5 | 6 | import { ChangedTyping } from "./versions"; |
6 | 7 | import { outputDirectory } from "../util/util"; |
7 | 8 |
|
| 9 | +// https://github.com/npm/types/pull/18 |
| 10 | +declare module "libnpmpublish" { |
| 11 | + function publish( |
| 12 | + manifest: Omit<import("@npm/types").PackageJson, "bundledDependencies">, |
| 13 | + tarData: Buffer, |
| 14 | + opts?: import("npm-registry-fetch").Options |
| 15 | + ): Promise<Response>; |
| 16 | +} |
| 17 | + |
8 | 18 | export async function publishTypingsPackage( |
9 | 19 | client: NpmPublishClient, |
10 | 20 | changedTyping: ChangedTyping, |
| 21 | + token: string, |
11 | 22 | dry: boolean, |
12 | 23 | log: Logger |
13 | 24 | ): Promise<void> { |
14 | | - const { pkg, version, latestVersion } = changedTyping; |
15 | | - await common(client, pkg, log, dry); |
| 25 | + const { pkg, version } = changedTyping; |
| 26 | + await common(pkg, token, dry); |
16 | 27 | if (pkg.isLatest) { |
17 | 28 | await updateTypeScriptVersionTags(pkg, version, client, log, dry); |
18 | 29 | } |
19 | | - assert((latestVersion === undefined) === pkg.isLatest); |
20 | | - if (latestVersion !== undefined) { |
21 | | - // If this is an older version of the package, we still update tags for the *latest*. |
22 | | - // NPM will update "latest" even if we are publishing an older version of a package (https://github.com/npm/npm/issues/6778), |
23 | | - // so we must undo that by re-tagging latest. |
24 | | - await updateLatestTag(pkg.fullNpmName, latestVersion, client, log, dry); |
25 | | - } |
26 | 30 | } |
27 | 31 |
|
28 | 32 | export async function publishNotNeededPackage( |
29 | | - client: NpmPublishClient, |
30 | 33 | pkg: NotNeededPackage, |
| 34 | + token: string, |
31 | 35 | dry: boolean, |
32 | 36 | log: Logger |
33 | 37 | ): Promise<void> { |
34 | 38 | log(`Deprecating ${pkg.name}`); |
35 | | - await common(client, pkg, log, dry); |
| 39 | + await common(pkg, token, dry); |
36 | 40 | } |
37 | 41 |
|
38 | | -async function common(client: NpmPublishClient, pkg: AnyPackage, log: Logger, dry: boolean): Promise<void> { |
| 42 | +async function common(pkg: AnyPackage, token: string, dry: boolean): Promise<void> { |
39 | 43 | const packageDir = outputDirectory(pkg); |
40 | | - const packageJson = await readFileAndWarn("generate", joinPaths(packageDir, "package.json")); |
41 | | - await client.publish(packageDir, packageJson, dry, log); |
| 44 | + const manifest = await pacote.manifest(packageDir).catch((reason) => { |
| 45 | + throw reason.code === "ENOENT" ? new Error("Run generate first!", { cause: reason }) : reason; |
| 46 | + }); |
| 47 | + const tarData = await pacote.tarball(packageDir); |
| 48 | + // Make sure we never assign the latest tag to an old version. |
| 49 | + if (!dry) |
| 50 | + await libpub.publish(manifest, tarData, { defaultTag: pkg.isLatest ? "latest" : "", access: "public", token }); |
42 | 51 | } |
0 commit comments