@pnpm/registry-access.commands 1100.0.0 → 1100.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/ping.d.ts +12 -0
- package/lib/ping.js +78 -0
- package/lib/search.d.ts +33 -0
- package/lib/search.js +100 -0
- package/package.json +14 -12
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as deprecate from './deprecation/deprecate.js';
|
|
2
2
|
import * as undeprecate from './deprecation/undeprecate.js';
|
|
3
3
|
import * as distTag from './distTag.js';
|
|
4
|
+
import * as ping from './ping.js';
|
|
5
|
+
import * as search from './search.js';
|
|
4
6
|
import * as unpublish from './unpublish.js';
|
|
5
|
-
export { deprecate, distTag, undeprecate, unpublish };
|
|
7
|
+
export { deprecate, distTag, ping, search, undeprecate, unpublish };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as deprecate from './deprecation/deprecate.js';
|
|
2
2
|
import * as undeprecate from './deprecation/undeprecate.js';
|
|
3
3
|
import * as distTag from './distTag.js';
|
|
4
|
+
import * as ping from './ping.js';
|
|
5
|
+
import * as search from './search.js';
|
|
4
6
|
import * as unpublish from './unpublish.js';
|
|
5
|
-
export { deprecate, distTag, undeprecate, unpublish };
|
|
7
|
+
export { deprecate, distTag, ping, search, undeprecate, unpublish };
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/lib/ping.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CreateFetchFromRegistryOptions } from '@pnpm/network.fetch';
|
|
2
|
+
import type { Registries, RegistryConfig } from '@pnpm/types';
|
|
3
|
+
export declare function cliOptionsTypes(): Record<string, unknown>;
|
|
4
|
+
export declare function rcOptionsTypes(): Record<string, unknown>;
|
|
5
|
+
export interface PingOptions extends CreateFetchFromRegistryOptions {
|
|
6
|
+
registry?: string;
|
|
7
|
+
registries?: Registries;
|
|
8
|
+
configByUri?: Record<string, RegistryConfig>;
|
|
9
|
+
}
|
|
10
|
+
export declare const commandNames: string[];
|
|
11
|
+
export declare function help(): string;
|
|
12
|
+
export declare function handler(opts: PingOptions): Promise<string>;
|
package/lib/ping.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import util from 'node:util';
|
|
2
|
+
import { docsUrl } from '@pnpm/cli.utils';
|
|
3
|
+
import { PnpmError } from '@pnpm/error';
|
|
4
|
+
import { createGetAuthHeaderByURI } from '@pnpm/network.auth-header';
|
|
5
|
+
import { createFetchFromRegistry } from '@pnpm/network.fetch';
|
|
6
|
+
import { renderHelp } from 'render-help';
|
|
7
|
+
import { rcOptionsTypes as commonRcOptionsTypes } from './common.js';
|
|
8
|
+
export function cliOptionsTypes() {
|
|
9
|
+
return {
|
|
10
|
+
...commonRcOptionsTypes(),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function rcOptionsTypes() {
|
|
14
|
+
return commonRcOptionsTypes();
|
|
15
|
+
}
|
|
16
|
+
export const commandNames = ['ping'];
|
|
17
|
+
export function help() {
|
|
18
|
+
return renderHelp({
|
|
19
|
+
description: 'Test connectivity to the configured registry.',
|
|
20
|
+
descriptionLists: [
|
|
21
|
+
{
|
|
22
|
+
title: 'Options',
|
|
23
|
+
list: [
|
|
24
|
+
{
|
|
25
|
+
description: 'Test a specific registry URL',
|
|
26
|
+
name: '--registry <url>',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
url: docsUrl('ping'),
|
|
32
|
+
usages: ['pnpm ping [--registry <url>]'],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function handler(opts) {
|
|
36
|
+
const registryUrl = opts.registry ?? opts.registries?.default ?? 'https://registry.npmjs.org/';
|
|
37
|
+
const normalizedRegistryUrl = registryUrl.endsWith('/') ? registryUrl : `${registryUrl}/`;
|
|
38
|
+
const pingUrlObject = new URL('./-/ping', normalizedRegistryUrl);
|
|
39
|
+
pingUrlObject.searchParams.set('write', 'true');
|
|
40
|
+
const pingUrl = pingUrlObject.toString();
|
|
41
|
+
const getAuthHeader = createGetAuthHeaderByURI(opts.configByUri ?? {}, normalizedRegistryUrl);
|
|
42
|
+
const authHeaderValue = getAuthHeader(normalizedRegistryUrl);
|
|
43
|
+
const fetchFromRegistry = createFetchFromRegistry(opts);
|
|
44
|
+
const start = Date.now();
|
|
45
|
+
let response;
|
|
46
|
+
try {
|
|
47
|
+
response = await fetchFromRegistry(pingUrl, {
|
|
48
|
+
retry: { retries: 0 },
|
|
49
|
+
authHeaderValue,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const errorMessage = util.types.isNativeError(err) ? err.message : String(err);
|
|
54
|
+
throw new PnpmError('PING_ERROR', `Failed to reach registry: ${errorMessage}`);
|
|
55
|
+
}
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new PnpmError('PING_ERROR', `Failed to reach registry: ${response.status} ${response.statusText}`.trimEnd());
|
|
58
|
+
}
|
|
59
|
+
const body = await response.text();
|
|
60
|
+
const time = Date.now() - start;
|
|
61
|
+
let details = '';
|
|
62
|
+
if (body) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(body);
|
|
65
|
+
if (parsed && typeof parsed === 'object' && Object.keys(parsed).length > 0) {
|
|
66
|
+
details = JSON.stringify(parsed, null, 2);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// non-JSON body — ignore
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const lines = [`PING ${registryUrl}`, `PONG ${time}ms`];
|
|
74
|
+
if (details)
|
|
75
|
+
lines.push(`PONG ${details}`);
|
|
76
|
+
return lines.join('\n');
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=ping.js.map
|
package/lib/search.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CreateFetchFromRegistryOptions } from '@pnpm/network.fetch';
|
|
2
|
+
import type { Registries, RegistryConfig } from '@pnpm/types';
|
|
3
|
+
import { rcOptionsTypes } from './common.js';
|
|
4
|
+
export { rcOptionsTypes };
|
|
5
|
+
export declare function cliOptionsTypes(): Record<string, unknown>;
|
|
6
|
+
export declare const commandNames: string[];
|
|
7
|
+
export declare function help(): string;
|
|
8
|
+
export interface SearchPackage {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
date?: string;
|
|
13
|
+
author?: {
|
|
14
|
+
name: string;
|
|
15
|
+
} | string;
|
|
16
|
+
publisher?: {
|
|
17
|
+
username: string;
|
|
18
|
+
};
|
|
19
|
+
maintainers?: Array<{
|
|
20
|
+
username: string;
|
|
21
|
+
}>;
|
|
22
|
+
keywords?: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface SearchResult {
|
|
25
|
+
package: SearchPackage;
|
|
26
|
+
}
|
|
27
|
+
export interface SearchOptions extends CreateFetchFromRegistryOptions {
|
|
28
|
+
configByUri?: Record<string, RegistryConfig>;
|
|
29
|
+
registries?: Registries;
|
|
30
|
+
json?: boolean;
|
|
31
|
+
searchLimit?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare function handler(opts: SearchOptions, params: string[]): Promise<string>;
|
package/lib/search.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { docsUrl } from '@pnpm/cli.utils';
|
|
2
|
+
import { PnpmError } from '@pnpm/error';
|
|
3
|
+
import { createGetAuthHeaderByURI } from '@pnpm/network.auth-header';
|
|
4
|
+
import { createFetchFromRegistry } from '@pnpm/network.fetch';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { renderHelp } from 'render-help';
|
|
7
|
+
import { rcOptionsTypes } from './common.js';
|
|
8
|
+
export { rcOptionsTypes };
|
|
9
|
+
export function cliOptionsTypes() {
|
|
10
|
+
return {
|
|
11
|
+
...rcOptionsTypes(),
|
|
12
|
+
json: Boolean,
|
|
13
|
+
'search-limit': Number,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export const commandNames = ['search', 's', 'se', 'find'];
|
|
17
|
+
export function help() {
|
|
18
|
+
return renderHelp({
|
|
19
|
+
description: 'Search for packages in the registry.',
|
|
20
|
+
url: docsUrl('search'),
|
|
21
|
+
usages: [
|
|
22
|
+
'pnpm search <keyword> ...',
|
|
23
|
+
],
|
|
24
|
+
descriptionLists: [
|
|
25
|
+
{
|
|
26
|
+
title: 'Options',
|
|
27
|
+
list: [
|
|
28
|
+
{
|
|
29
|
+
description: 'Show search results in JSON format',
|
|
30
|
+
name: '--json',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: 'Maximum number of results to show (default: 20)',
|
|
34
|
+
name: '--search-limit <number>',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export async function handler(opts, params) {
|
|
42
|
+
const query = params.join(' ');
|
|
43
|
+
if (!query) {
|
|
44
|
+
throw new PnpmError('MISSING_SEARCH_QUERY', 'Search query is required. Usage: pnpm search <keyword>');
|
|
45
|
+
}
|
|
46
|
+
const registry = opts.registries?.default ?? 'https://registry.npmjs.org/';
|
|
47
|
+
const registryUrl = new URL(registry);
|
|
48
|
+
if (!registryUrl.pathname.endsWith('/')) {
|
|
49
|
+
registryUrl.pathname = `${registryUrl.pathname}/`;
|
|
50
|
+
}
|
|
51
|
+
const searchUrl = new URL('./-/v1/search', registryUrl);
|
|
52
|
+
searchUrl.searchParams.set('text', query);
|
|
53
|
+
searchUrl.searchParams.set('size', (opts.searchLimit ?? 20).toString());
|
|
54
|
+
const fetchFromRegistry = createFetchFromRegistry(opts);
|
|
55
|
+
const getAuthHeader = createGetAuthHeaderByURI(opts.configByUri ?? {}, opts.registries?.default);
|
|
56
|
+
const response = await fetchFromRegistry(searchUrl.toString(), {
|
|
57
|
+
authHeaderValue: getAuthHeader(registry),
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
const errorBody = (await response.text()).trim();
|
|
61
|
+
throw new PnpmError('SEARCH_FAILED', errorBody
|
|
62
|
+
? `Search failed with status ${response.status}: ${response.statusText}. ${errorBody}`
|
|
63
|
+
: `Search failed with status ${response.status}: ${response.statusText}`);
|
|
64
|
+
}
|
|
65
|
+
const data = await response.json();
|
|
66
|
+
if (opts.json) {
|
|
67
|
+
return JSON.stringify(data.objects.map(obj => obj.package), null, 2);
|
|
68
|
+
}
|
|
69
|
+
if (data.objects.length === 0) {
|
|
70
|
+
return 'No packages found';
|
|
71
|
+
}
|
|
72
|
+
return data.objects.map(obj => formatPackage(obj.package)).join('\n\n');
|
|
73
|
+
}
|
|
74
|
+
function formatPackage(pkg) {
|
|
75
|
+
const author = typeof pkg.author === 'object'
|
|
76
|
+
? pkg.author.name
|
|
77
|
+
: (pkg.author ?? pkg.publisher?.username ?? '');
|
|
78
|
+
const date = pkg.date ? pkg.date.split('T')[0] : '';
|
|
79
|
+
const lines = [
|
|
80
|
+
chalk.bold(pkg.name),
|
|
81
|
+
];
|
|
82
|
+
if (pkg.description) {
|
|
83
|
+
lines.push(pkg.description);
|
|
84
|
+
}
|
|
85
|
+
const versionLine = [`Version ${pkg.version}`];
|
|
86
|
+
if (date)
|
|
87
|
+
versionLine.push(`published ${date}`);
|
|
88
|
+
if (author)
|
|
89
|
+
versionLine.push(`by ${author}`);
|
|
90
|
+
lines.push(versionLine.join(' '));
|
|
91
|
+
if (pkg.maintainers?.length) {
|
|
92
|
+
lines.push(`Maintainers: ${pkg.maintainers.map(m => m.username).join(', ')}`);
|
|
93
|
+
}
|
|
94
|
+
if (pkg.keywords?.length) {
|
|
95
|
+
lines.push(`Keywords: ${pkg.keywords.join(', ')}`);
|
|
96
|
+
}
|
|
97
|
+
lines.push(chalk.blueBright(`https://npmx.dev/package/${pkg.name}`));
|
|
98
|
+
return lines.join('\n');
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=search.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/registry-access.commands",
|
|
3
|
-
"version": "1100.
|
|
3
|
+
"version": "1100.1.0",
|
|
4
4
|
"description": "Commands for managing packages on the registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -25,17 +25,18 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@pnpm/npm-package-arg": "^2.0.0",
|
|
28
|
+
"chalk": "^5.6.0",
|
|
28
29
|
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
29
30
|
"render-help": "^2.0.0",
|
|
30
31
|
"semver": "^7.7.2",
|
|
31
|
-
"@pnpm/
|
|
32
|
-
"@pnpm/config.pick-registry-for-package": "1100.0.
|
|
32
|
+
"@pnpm/config.reader": "1100.0.1",
|
|
33
|
+
"@pnpm/config.pick-registry-for-package": "1100.0.1",
|
|
33
34
|
"@pnpm/error": "1100.0.0",
|
|
34
|
-
"@pnpm/network.auth-header": "1100.0.
|
|
35
|
-
"@pnpm/network.fetch": "1100.0.
|
|
36
|
-
"@pnpm/resolving.registry.types": "1100.0.
|
|
37
|
-
"@pnpm/
|
|
38
|
-
"@pnpm/
|
|
35
|
+
"@pnpm/network.auth-header": "1100.0.1",
|
|
36
|
+
"@pnpm/network.fetch": "1100.0.1",
|
|
37
|
+
"@pnpm/resolving.registry.types": "1100.0.1",
|
|
38
|
+
"@pnpm/cli.utils": "1100.0.1",
|
|
39
|
+
"@pnpm/types": "1101.0.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@jest/globals": "30.3.0",
|
|
@@ -43,10 +44,11 @@
|
|
|
43
44
|
"@types/ramda": "0.31.1",
|
|
44
45
|
"@types/semver": "7.7.1",
|
|
45
46
|
"execa": "npm:safe-execa@0.3.0",
|
|
46
|
-
"@pnpm/prepare": "1100.0.
|
|
47
|
-
"@pnpm/
|
|
48
|
-
"@pnpm/
|
|
49
|
-
"@pnpm/testing.
|
|
47
|
+
"@pnpm/prepare": "1100.0.1",
|
|
48
|
+
"@pnpm/registry-access.commands": "1100.1.0",
|
|
49
|
+
"@pnpm/testing.command-defaults": "1100.0.0",
|
|
50
|
+
"@pnpm/testing.mock-agent": "1100.0.1",
|
|
51
|
+
"@pnpm/releasing.commands": "1100.0.1"
|
|
50
52
|
},
|
|
51
53
|
"engines": {
|
|
52
54
|
"node": ">=22.13"
|