Skip to content

Commit 8861750

Browse files
committed
Registry API no longer needs %2f-encoding
1 parent b7953cb commit 8861750

File tree

7 files changed

+22
-38
lines changed

7 files changed

+22
-38
lines changed

packages/definitions-parser/src/packages.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@ export abstract class PackageBase {
227227
return getFullNpmName(this.name);
228228
}
229229

230-
/** '@types%2ffoo' for a package 'foo'. */
231-
get fullEscapedNpmName(): string {
232-
return `@${scopeName}%2f${this.name}`;
233-
}
234-
235230
abstract readonly major: number;
236231
abstract readonly minor: number;
237232

packages/definitions-parser/test/packages.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ describe(TypingsData, () => {
190190
expect(data.fullNpmName).toBe("@types/foo__bar");
191191
});
192192
});
193-
194-
describe("fullEscapedNpmName", () => {
195-
it("returns escaped name", () => {
196-
expect(data.fullEscapedNpmName).toBe("@types%2fknown");
197-
});
198-
});
199193
});
200194

201195
describe(getMangledNameForScopedPackage, () => {

packages/publisher/src/calculate-versions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ async function isAlreadyDeprecated(
9898
client: CachedNpmInfoClient,
9999
log: LoggerWithErrors
100100
): Promise<boolean> {
101-
const cachedInfo = client.getNpmInfoFromCache(pkg.fullEscapedNpmName);
101+
const cachedInfo = client.getNpmInfoFromCache(pkg.fullNpmName);
102102
let latestVersion = cachedInfo && assertDefined(cachedInfo.distTags.get("latest"));
103103
let latestVersionInfo = cachedInfo && latestVersion && assertDefined(cachedInfo.versions.get(latestVersion));
104104
if (!latestVersionInfo || !latestVersionInfo.deprecated) {
105105
log.info(`Version info not cached for deprecated package ${pkg.desc}`);
106-
const info = assertDefined(await client.fetchAndCacheNpmInfo(pkg.fullEscapedNpmName));
106+
const info = assertDefined(await client.fetchAndCacheNpmInfo(pkg.fullNpmName));
107107
latestVersion = assertDefined(info.distTags.get("latest"));
108108
latestVersionInfo = assertDefined(info.versions.get(latestVersion));
109109
}

packages/publisher/src/lib/npm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as semver from "semver";
99
*/
1010
export function skipBadPublishes(pkg: NotNeededPackage, client: CachedNpmInfoClient, log: Logger) {
1111
// because this is called right after isAlreadyDeprecated, we can rely on the cache being up-to-date
12-
const info = assertDefined(client.getNpmInfoFromCache(pkg.fullEscapedNpmName));
12+
const info = assertDefined(client.getNpmInfoFromCache(pkg.fullNpmName));
1313
const notNeeded = pkg.version;
1414
const latest = new semver.SemVer(findActualLatest(info.time));
1515
if (semver.lte(notNeeded, latest)) {

packages/publisher/src/publish-registry.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,9 @@ async function generateRegistry(typings: readonly TypingsData[], client: CachedN
253253
const entries: { [packageName: string]: { [distTags: string]: string } } = {};
254254
for (const typing of typings) {
255255
// Unconditionally use cached info, this should have been set in calculate-versions so should be recent enough.
256-
const info = client.getNpmInfoFromCache(typing.fullEscapedNpmName);
256+
const info = client.getNpmInfoFromCache(typing.fullNpmName);
257257
if (!info) {
258-
const missings = typings
259-
.filter((t) => !client.getNpmInfoFromCache(t.fullEscapedNpmName))
260-
.map((t) => t.fullEscapedNpmName);
258+
const missings = typings.filter((t) => !client.getNpmInfoFromCache(t.fullNpmName)).map((t) => t.fullNpmName);
261259
throw new Error(`${missings.toString()} not found in cached npm info.`);
262260
}
263261
entries[typing.name] = filterTags(info.distTags);
@@ -284,11 +282,8 @@ interface ProcessedNpmInfo {
284282
readonly lastModified: Date;
285283
}
286284

287-
async function fetchAndProcessNpmInfo(
288-
escapedPackageName: string,
289-
client: UncachedNpmInfoClient
290-
): Promise<ProcessedNpmInfo> {
291-
const info = assertDefined(await client.fetchNpmInfo(escapedPackageName));
285+
async function fetchAndProcessNpmInfo(packageName: string, client: UncachedNpmInfoClient): Promise<ProcessedNpmInfo> {
286+
const info = assertDefined(await client.fetchNpmInfo(packageName));
292287
const npmVersion = new semver.SemVer(assertDefined(info.distTags.get("latest")));
293288
const { distTags, versions, time } = info;
294289
const highestSemverVersion = max(

packages/retag/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ export async function fetchTypesPackageVersionInfo(
124124
canPublish: boolean,
125125
log?: LoggerWithErrors
126126
): Promise<{ version: string; needsPublish: boolean }> {
127-
let info = client.getNpmInfoFromCache(pkg.fullEscapedNpmName);
127+
let info = client.getNpmInfoFromCache(pkg.fullNpmName);
128128
let latestVersion = info && getHighestVersionForMajor(info.versions, pkg);
129129
let latestVersionInfo = latestVersion && assertDefined(info!.versions.get(latestVersion));
130130
if (!latestVersionInfo || latestVersionInfo.typesPublisherContentHash !== pkg.contentHash) {
131131
if (log) {
132132
log.info(`Version info not cached for ${pkg.desc}@${latestVersion || "(no latest version)"}`);
133133
}
134-
info = await client.fetchAndCacheNpmInfo(pkg.fullEscapedNpmName);
134+
info = await client.fetchAndCacheNpmInfo(pkg.fullNpmName);
135135
latestVersion = info && getHighestVersionForMajor(info.versions, pkg);
136136
if (!latestVersion) {
137137
return { version: `${pkg.major}.${pkg.minor}.0`, needsPublish: true };

packages/utils/src/npm.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export interface NpmInfoVersion {
4444
}
4545

4646
export interface CachedNpmInfoClient {
47-
getNpmInfoFromCache(escapedPackageName: string): NpmInfo | undefined;
48-
fetchAndCacheNpmInfo(escapedPackageName: string): Promise<NpmInfo | undefined>;
47+
getNpmInfoFromCache(packageName: string): NpmInfo | undefined;
48+
fetchAndCacheNpmInfo(packageName: string): Promise<NpmInfo | undefined>;
4949
}
5050

5151
export async function withNpmCache<T>(
@@ -75,15 +75,15 @@ export async function withNpmCache<T>(
7575
return res;
7676

7777
/** May return old info -- caller should check that this looks up-to-date. */
78-
function getNpmInfoFromCache(escapedPackageName: string): NpmInfo | undefined {
79-
return unroll.get(escapedPackageName);
78+
function getNpmInfoFromCache(packageName: string): NpmInfo | undefined {
79+
return unroll.get(packageName);
8080
}
8181

8282
/** Call this when the result of getNpmInfoFromCache looks potentially out-of-date. */
83-
async function fetchAndCacheNpmInfo(escapedPackageName: string): Promise<NpmInfo | undefined> {
84-
const info = await uncachedClient.fetchNpmInfo(escapedPackageName);
83+
async function fetchAndCacheNpmInfo(packageName: string): Promise<NpmInfo | undefined> {
84+
const info = await uncachedClient.fetchNpmInfo(packageName);
8585
if (info) {
86-
unroll.set(escapedPackageName, info);
86+
unroll.set(packageName, info);
8787
}
8888
return info;
8989
}
@@ -92,23 +92,23 @@ export async function withNpmCache<T>(
9292
export class UncachedNpmInfoClient {
9393
private readonly fetcher = new Fetcher();
9494

95-
async fetchNpmInfo(escapedPackageName: string): Promise<NpmInfo | undefined> {
96-
const raw = await this.fetchRawNpmInfo(escapedPackageName);
95+
async fetchNpmInfo(packageName: string): Promise<NpmInfo | undefined> {
96+
const raw = await this.fetchRawNpmInfo(packageName);
9797
await sleep(0.01); // If we don't do this, npm resets the connection?
9898
return raw === undefined ? undefined : npmInfoFromJson(raw);
9999
}
100100

101-
async fetchRawNpmInfo(escapedPackageName: string): Promise<NpmInfoRaw | undefined> {
101+
async fetchRawNpmInfo(packageName: string): Promise<NpmInfoRaw | undefined> {
102102
const info = (await this.fetcher.fetchJson({
103103
hostname: npmRegistryHostName,
104-
path: escapedPackageName,
104+
path: packageName,
105105
retries: true,
106106
})) as { readonly error: string } | NpmInfoRaw;
107107
if ("error" in info) {
108108
if (info.error === "Not found") {
109109
return undefined;
110110
}
111-
throw new Error(`Error getting version at ${escapedPackageName}: ${info.error}`);
111+
throw new Error(`Error getting version at ${packageName}: ${info.error}`);
112112
}
113113
if (!info["dist-tags"] && !info.versions) {
114114
// Unpublished
@@ -205,7 +205,7 @@ export class NpmPublishClient {
205205
}
206206

207207
deprecate(packageName: string, version: string, message: string): Promise<void> {
208-
const url = resolveUrl(npmRegistry, packageName.replace("/", "%2f"));
208+
const url = resolveUrl(npmRegistry, packageName);
209209
const params = {
210210
message,
211211
version,

0 commit comments

Comments
 (0)