-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish old versions without touching latest tag
- Loading branch information
Showing
18 changed files
with
120 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,51 @@ | ||
import assert = require("assert"); | ||
import { Logger, joinPaths, readFileAndWarn, NpmPublishClient } from "@definitelytyped/utils"; | ||
import { Logger, NpmPublishClient } from "@definitelytyped/utils"; | ||
import { NotNeededPackage, AnyPackage } from "@definitelytyped/definitions-parser"; | ||
import { updateTypeScriptVersionTags, updateLatestTag } from "@definitelytyped/retag"; | ||
import { updateTypeScriptVersionTags } from "@definitelytyped/retag"; | ||
import * as libpub from "libnpmpublish"; | ||
import * as pacote from "pacote"; | ||
import { ChangedTyping } from "./versions"; | ||
import { outputDirectory } from "../util/util"; | ||
|
||
// https://github.com/npm/types/pull/18 | ||
declare module "libnpmpublish" { | ||
function publish( | ||
manifest: Omit<import("@npm/types").PackageJson, "bundledDependencies">, | ||
tarData: Buffer, | ||
opts?: import("npm-registry-fetch").Options | ||
): Promise<Response>; | ||
} | ||
|
||
export async function publishTypingsPackage( | ||
client: NpmPublishClient, | ||
changedTyping: ChangedTyping, | ||
token: string, | ||
dry: boolean, | ||
log: Logger | ||
): Promise<void> { | ||
const { pkg, version, latestVersion } = changedTyping; | ||
await common(client, pkg, log, dry); | ||
const { pkg, version } = changedTyping; | ||
await common(pkg, token, dry); | ||
if (pkg.isLatest) { | ||
await updateTypeScriptVersionTags(pkg, version, client, log, dry); | ||
} | ||
assert((latestVersion === undefined) === pkg.isLatest); | ||
if (latestVersion !== undefined) { | ||
// If this is an older version of the package, we still update tags for the *latest*. | ||
// NPM will update "latest" even if we are publishing an older version of a package (https://github.com/npm/npm/issues/6778), | ||
// so we must undo that by re-tagging latest. | ||
await updateLatestTag(pkg.fullNpmName, latestVersion, client, log, dry); | ||
} | ||
} | ||
|
||
export async function publishNotNeededPackage( | ||
client: NpmPublishClient, | ||
pkg: NotNeededPackage, | ||
token: string, | ||
dry: boolean, | ||
log: Logger | ||
): Promise<void> { | ||
log(`Deprecating ${pkg.name}`); | ||
await common(client, pkg, log, dry); | ||
await common(pkg, token, dry); | ||
} | ||
|
||
async function common(client: NpmPublishClient, pkg: AnyPackage, log: Logger, dry: boolean): Promise<void> { | ||
async function common(pkg: AnyPackage, token: string, dry: boolean): Promise<void> { | ||
const packageDir = outputDirectory(pkg); | ||
const packageJson = await readFileAndWarn("generate", joinPaths(packageDir, "package.json")); | ||
await client.publish(packageDir, packageJson, dry, log); | ||
const manifest = await pacote.manifest(packageDir).catch((reason) => { | ||
throw reason.code === "ENOENT" ? new Error("Run generate first!", { cause: reason }) : reason; | ||
}); | ||
const tarData = await pacote.tarball(packageDir); | ||
// Make sure we never assign the latest tag to an old version. | ||
if (!dry) | ||
await libpub.publish(manifest, tarData, { defaultTag: pkg.isLatest ? "latest" : "", access: "public", token }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { NotNeededPackage, TypingsData } from "@definitelytyped/definitions-parser"; | ||
import * as libpub from "libnpmpublish"; | ||
import { publishNotNeededPackage, publishTypingsPackage } from "../src/lib/package-publisher"; | ||
|
||
jest.mock("libnpmpublish"); | ||
jest.mock("pacote", () => ({ async manifest() {}, async tarball() {} })); | ||
|
||
const client = { async tag() {} }; | ||
|
||
const latestVersion = { | ||
pkg: new TypingsData({ typingsPackageName: "some-package" } as never, /*isLatest*/ true), | ||
version: "1.2.3", | ||
}; | ||
const oldVersion = { | ||
pkg: new TypingsData({ typingsPackageName: "some-package" } as never, /*isLatest*/ false), | ||
version: "1.2.3", | ||
}; | ||
const notNeeded = new NotNeededPackage("not-needed", "not-needed", "1.2.3"); | ||
|
||
function log() {} | ||
|
||
test("Latest version gets latest tag", async () => { | ||
await publishTypingsPackage(client as never, latestVersion, /*token*/ "", /*dry*/ false, log); | ||
expect(libpub.publish).toHaveBeenLastCalledWith(/*manifest*/ undefined, /*tarData*/ undefined, { | ||
defaultTag: "latest", | ||
access: "public", | ||
token: "", | ||
}); | ||
}); | ||
|
||
test("Publishing old versions doesn't change the latest tag", async () => { | ||
await publishTypingsPackage(client as never, oldVersion, /*token*/ "", /*dry*/ false, log); | ||
expect(libpub.publish).toHaveBeenLastCalledWith(/*manifest*/ undefined, /*tarData*/ undefined, { | ||
defaultTag: "", | ||
access: "public", | ||
token: "", | ||
}); | ||
}); | ||
|
||
test("Not-needed package gets latest tag", async () => { | ||
await publishNotNeededPackage(notNeeded, /*token*/ "", /*dry*/ false, log); | ||
expect(libpub.publish).toHaveBeenLastCalledWith(/*manifest*/ undefined, /*tarData*/ undefined, { | ||
defaultTag: "latest", | ||
access: "public", | ||
token: "", | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
logs | ||
test/data/pack.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.