BREAKING CHANGE(pypi,rubygems): Revise PyPI and RubyGems handling: normalize error payloads, fix .gem parsing/packing, adjust PyPI JSON API and tests, and export smartarchive plugin
This commit is contained in:
@@ -85,14 +85,14 @@ export class PypiRegistry extends BaseRegistry {
|
||||
return this.handleUpload(context, token);
|
||||
}
|
||||
|
||||
// Package metadata JSON API: GET /pypi/{package}/json
|
||||
const jsonMatch = path.match(/^\/pypi\/([^\/]+)\/json$/);
|
||||
// Package metadata JSON API: GET /{package}/json
|
||||
const jsonMatch = path.match(/^\/([^\/]+)\/json$/);
|
||||
if (jsonMatch && context.method === 'GET') {
|
||||
return this.handlePackageJson(jsonMatch[1]);
|
||||
}
|
||||
|
||||
// Version-specific JSON API: GET /pypi/{package}/{version}/json
|
||||
const versionJsonMatch = path.match(/^\/pypi\/([^\/]+)\/([^\/]+)\/json$/);
|
||||
// Version-specific JSON API: GET /{package}/{version}/json
|
||||
const versionJsonMatch = path.match(/^\/([^\/]+)\/([^\/]+)\/json$/);
|
||||
if (versionJsonMatch && context.method === 'GET') {
|
||||
return this.handleVersionJson(versionJsonMatch[1], versionJsonMatch[2]);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ export class PypiRegistry extends BaseRegistry {
|
||||
return {
|
||||
status: 404,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: Buffer.from(JSON.stringify({ message: 'Not Found' })),
|
||||
body: { error: 'Not Found' },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -215,11 +215,7 @@ export class PypiRegistry extends BaseRegistry {
|
||||
// Get package metadata
|
||||
const metadata = await this.storage.getPypiPackageMetadata(normalized);
|
||||
if (!metadata) {
|
||||
return {
|
||||
status: 404,
|
||||
headers: { 'Content-Type': 'text/html; charset=utf-8' },
|
||||
body: '<html><body><h1>404 Not Found</h1></body></html>',
|
||||
};
|
||||
return this.errorResponse(404, 'Package not found');
|
||||
}
|
||||
|
||||
// Build file list from all versions
|
||||
@@ -315,7 +311,7 @@ export class PypiRegistry extends BaseRegistry {
|
||||
'Content-Type': 'application/json',
|
||||
'WWW-Authenticate': 'Basic realm="PyPI"'
|
||||
},
|
||||
body: Buffer.from(JSON.stringify({ message: 'Authentication required' })),
|
||||
body: { error: 'Authentication required' },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -435,10 +431,10 @@ export class PypiRegistry extends BaseRegistry {
|
||||
return {
|
||||
status: 201,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: Buffer.from(JSON.stringify({
|
||||
body: {
|
||||
message: 'Package uploaded successfully',
|
||||
url: `${this.registryUrl}/pypi/packages/${normalized}/${filename}`
|
||||
})),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.log('error', 'Upload failed', { error: (error as Error).message });
|
||||
@@ -457,7 +453,7 @@ export class PypiRegistry extends BaseRegistry {
|
||||
return {
|
||||
status: 404,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: Buffer.from(JSON.stringify({ message: 'File not found' })),
|
||||
body: { error: 'File not found' },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -474,6 +470,7 @@ export class PypiRegistry extends BaseRegistry {
|
||||
|
||||
/**
|
||||
* Handle package JSON API (all versions)
|
||||
* Returns format compatible with official PyPI JSON API
|
||||
*/
|
||||
private async handlePackageJson(packageName: string): Promise<IResponse> {
|
||||
const normalized = helpers.normalizePypiPackageName(packageName);
|
||||
@@ -483,18 +480,67 @@ export class PypiRegistry extends BaseRegistry {
|
||||
return this.errorResponse(404, 'Package not found');
|
||||
}
|
||||
|
||||
// Find latest version for info
|
||||
const versions = Object.keys(metadata.versions || {});
|
||||
const latestVersion = versions.length > 0 ? versions[versions.length - 1] : null;
|
||||
const latestMeta = latestVersion ? metadata.versions[latestVersion] : null;
|
||||
|
||||
// Build URLs array from latest version files
|
||||
const urls = latestMeta?.files?.map((file: any) => ({
|
||||
filename: file.filename,
|
||||
url: `${this.registryUrl}/pypi/packages/${normalized}/${file.filename}`,
|
||||
digests: file.hashes,
|
||||
requires_python: file['requires-python'],
|
||||
size: file.size,
|
||||
upload_time: file['upload-time'],
|
||||
packagetype: file.filetype,
|
||||
python_version: file.python_version,
|
||||
})) || [];
|
||||
|
||||
// Build releases object
|
||||
const releases: Record<string, any[]> = {};
|
||||
for (const [ver, verMeta] of Object.entries(metadata.versions || {})) {
|
||||
releases[ver] = (verMeta as any).files?.map((file: any) => ({
|
||||
filename: file.filename,
|
||||
url: `${this.registryUrl}/pypi/packages/${normalized}/${file.filename}`,
|
||||
digests: file.hashes,
|
||||
requires_python: file['requires-python'],
|
||||
size: file.size,
|
||||
upload_time: file['upload-time'],
|
||||
packagetype: file.filetype,
|
||||
python_version: file.python_version,
|
||||
})) || [];
|
||||
}
|
||||
|
||||
const response = {
|
||||
info: {
|
||||
name: normalized,
|
||||
version: latestVersion,
|
||||
summary: latestMeta?.metadata?.summary,
|
||||
description: latestMeta?.metadata?.description,
|
||||
author: latestMeta?.metadata?.author,
|
||||
author_email: latestMeta?.metadata?.['author-email'],
|
||||
license: latestMeta?.metadata?.license,
|
||||
requires_python: latestMeta?.files?.[0]?.['requires-python'],
|
||||
...latestMeta?.metadata,
|
||||
},
|
||||
urls,
|
||||
releases,
|
||||
};
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'public, max-age=300'
|
||||
},
|
||||
body: Buffer.from(JSON.stringify(metadata)),
|
||||
body: response,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle version-specific JSON API
|
||||
* Returns format compatible with official PyPI JSON API
|
||||
*/
|
||||
private async handleVersionJson(packageName: string, version: string): Promise<IResponse> {
|
||||
const normalized = helpers.normalizePypiPackageName(packageName);
|
||||
@@ -504,13 +550,42 @@ export class PypiRegistry extends BaseRegistry {
|
||||
return this.errorResponse(404, 'Version not found');
|
||||
}
|
||||
|
||||
const verMeta = metadata.versions[version];
|
||||
|
||||
// Build URLs array from version files
|
||||
const urls = verMeta.files?.map((file: any) => ({
|
||||
filename: file.filename,
|
||||
url: `${this.registryUrl}/pypi/packages/${normalized}/${file.filename}`,
|
||||
digests: file.hashes,
|
||||
requires_python: file['requires-python'],
|
||||
size: file.size,
|
||||
upload_time: file['upload-time'],
|
||||
packagetype: file.filetype,
|
||||
python_version: file.python_version,
|
||||
})) || [];
|
||||
|
||||
const response = {
|
||||
info: {
|
||||
name: normalized,
|
||||
version,
|
||||
summary: verMeta.metadata?.summary,
|
||||
description: verMeta.metadata?.description,
|
||||
author: verMeta.metadata?.author,
|
||||
author_email: verMeta.metadata?.['author-email'],
|
||||
license: verMeta.metadata?.license,
|
||||
requires_python: verMeta.files?.[0]?.['requires-python'],
|
||||
...verMeta.metadata,
|
||||
},
|
||||
urls,
|
||||
};
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'public, max-age=300'
|
||||
},
|
||||
body: Buffer.from(JSON.stringify(metadata.versions[version])),
|
||||
body: response,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -572,11 +647,11 @@ export class PypiRegistry extends BaseRegistry {
|
||||
* Helper: Create error response
|
||||
*/
|
||||
private errorResponse(status: number, message: string): IResponse {
|
||||
const error: IPypiError = { message, status };
|
||||
const error: IPypiError = { error: message, status };
|
||||
return {
|
||||
status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: Buffer.from(JSON.stringify(error)),
|
||||
body: error,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ export interface IPypiUploadResponse {
|
||||
*/
|
||||
export interface IPypiError {
|
||||
/** Error message */
|
||||
message: string;
|
||||
error: string;
|
||||
/** HTTP status code */
|
||||
status?: number;
|
||||
/** Additional error details */
|
||||
|
||||
Reference in New Issue
Block a user