@pnpm/pkg-manifest.commands 1100.1.12 → 1100.1.13
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/CHANGELOG.md +8 -0
- package/package.json +5 -5
- package/lib/index.d.ts +0 -2
- package/lib/pkg.d.ts +0 -18
- package/lib/pkg.js +0 -205
- package/lib/setScript.d.ts +0 -7
- package/lib/setScript.js +0 -31
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/pkg-manifest.commands",
|
|
3
|
-
"version": "1100.1.
|
|
3
|
+
"version": "1100.1.13",
|
|
4
4
|
"description": "Commands for managing package.json",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"!*.map"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pnpm/cli.utils": "1101.0.
|
|
32
|
-
"@pnpm/config.reader": "1101.12.
|
|
31
|
+
"@pnpm/cli.utils": "1101.0.15",
|
|
32
|
+
"@pnpm/config.reader": "1101.12.1",
|
|
33
33
|
"@pnpm/error": "1100.0.1",
|
|
34
34
|
"@pnpm/object.property-path": "1100.1.1",
|
|
35
35
|
"@pnpm/types": "1101.4.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@jest/globals": "30.4.1",
|
|
40
|
-
"@pnpm/pkg-manifest.commands": "1100.1.
|
|
41
|
-
"@pnpm/prepare": "1100.0.
|
|
40
|
+
"@pnpm/pkg-manifest.commands": "1100.1.13",
|
|
41
|
+
"@pnpm/prepare": "1100.0.20"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=22.13"
|
package/lib/index.d.ts
DELETED
package/lib/pkg.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const rcOptionsTypes: typeof cliOptionsTypes;
|
|
2
|
-
export declare function cliOptionsTypes(): Record<string, unknown>;
|
|
3
|
-
export declare const commandNames: string[];
|
|
4
|
-
interface PkgCommandOptions {
|
|
5
|
-
dir: string;
|
|
6
|
-
json?: boolean;
|
|
7
|
-
recursive?: boolean;
|
|
8
|
-
workspaceDir?: string;
|
|
9
|
-
selectedProjectsGraph?: Record<string, {
|
|
10
|
-
package: {
|
|
11
|
-
rootDir: string;
|
|
12
|
-
manifest: Record<string, unknown>;
|
|
13
|
-
};
|
|
14
|
-
}>;
|
|
15
|
-
}
|
|
16
|
-
export declare function handler(opts: PkgCommandOptions, params: string[]): Promise<string | void>;
|
|
17
|
-
export declare function help(): string;
|
|
18
|
-
export {};
|
package/lib/pkg.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { docsUrl, readProjectManifest, readProjectManifestOnly } from '@pnpm/cli.utils';
|
|
3
|
-
import { types as allTypes } from '@pnpm/config.reader';
|
|
4
|
-
import { PnpmError } from '@pnpm/error';
|
|
5
|
-
import { deleteObjectValueByPropertyPathString, getObjectValueByPropertyPathString, setObjectValueByPropertyPathString, } from '@pnpm/object.property-path';
|
|
6
|
-
import { renderHelp } from 'render-help';
|
|
7
|
-
export const rcOptionsTypes = cliOptionsTypes;
|
|
8
|
-
export function cliOptionsTypes() {
|
|
9
|
-
const types = allTypes;
|
|
10
|
-
return {
|
|
11
|
-
dir: types['dir'],
|
|
12
|
-
json: Boolean,
|
|
13
|
-
recursive: Boolean,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export const commandNames = ['pkg'];
|
|
17
|
-
export async function handler(opts, params) {
|
|
18
|
-
if (params.length === 0) {
|
|
19
|
-
throw new PnpmError('PKG_MISSING_SUBCOMMAND', 'Missing subcommand', {
|
|
20
|
-
hint: help(),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (params[0] === '--help' || params[0] === '-h') {
|
|
24
|
-
return help();
|
|
25
|
-
}
|
|
26
|
-
const [subcmd, ...args] = params;
|
|
27
|
-
if (opts.recursive) {
|
|
28
|
-
return handleRecursiveCommand(opts, subcmd, args);
|
|
29
|
-
}
|
|
30
|
-
return runSubcommand(opts, subcmd, args);
|
|
31
|
-
}
|
|
32
|
-
async function runSubcommand(opts, subcmd, args) {
|
|
33
|
-
switch (subcmd) {
|
|
34
|
-
case 'get':
|
|
35
|
-
return pkgGet(opts, args);
|
|
36
|
-
case 'set':
|
|
37
|
-
return pkgSet(opts, args);
|
|
38
|
-
case 'delete':
|
|
39
|
-
return pkgDelete(opts, args);
|
|
40
|
-
case 'fix':
|
|
41
|
-
return pkgFix(opts);
|
|
42
|
-
default:
|
|
43
|
-
throw new PnpmError('PKG_UNKNOWN_SUBCOMMAND', `Unknown subcommand "${subcmd}"`, {
|
|
44
|
-
hint: help(),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function handleRecursiveCommand(opts, subcmd, args) {
|
|
49
|
-
const workspaceDir = opts.workspaceDir;
|
|
50
|
-
if (!workspaceDir) {
|
|
51
|
-
throw new PnpmError('PKG_RECURSIVE_NO_ROOT', 'Cannot run recursively outside of a workspace');
|
|
52
|
-
}
|
|
53
|
-
const selectedProjects = opts.selectedProjectsGraph == null
|
|
54
|
-
? []
|
|
55
|
-
: Object.values(opts.selectedProjectsGraph);
|
|
56
|
-
if (selectedProjects.length === 0) {
|
|
57
|
-
throw new PnpmError('PKG_RECURSIVE_NO_PACKAGES', 'No workspace packages were selected');
|
|
58
|
-
}
|
|
59
|
-
if (subcmd === 'get') {
|
|
60
|
-
const entries = await Promise.all(selectedProjects.map(async ({ package: pkg }) => {
|
|
61
|
-
const manifest = await readProjectManifestOnly(pkg.rootDir);
|
|
62
|
-
const pkgName = String(manifest.name ?? path.relative(workspaceDir, pkg.rootDir));
|
|
63
|
-
return [pkgName, selectFromManifest(manifest, args)];
|
|
64
|
-
}));
|
|
65
|
-
return JSON.stringify(Object.fromEntries(entries), undefined, 2);
|
|
66
|
-
}
|
|
67
|
-
await Promise.all(selectedProjects.map(({ package: pkg }) => runSubcommand({ ...opts, dir: pkg.rootDir }, subcmd, args)));
|
|
68
|
-
}
|
|
69
|
-
async function pkgGet(opts, args) {
|
|
70
|
-
const manifest = await readProjectManifestOnly(opts.dir);
|
|
71
|
-
if (args.length === 1) {
|
|
72
|
-
const value = getObjectValueByPropertyPathString(manifest, args[0]);
|
|
73
|
-
if (value === undefined)
|
|
74
|
-
return '';
|
|
75
|
-
if (opts.json)
|
|
76
|
-
return JSON.stringify(value, undefined, 2);
|
|
77
|
-
return typeof value === 'string' ? value : JSON.stringify(value, undefined, 2);
|
|
78
|
-
}
|
|
79
|
-
return JSON.stringify(selectFromManifest(manifest, args), undefined, 2);
|
|
80
|
-
}
|
|
81
|
-
function selectFromManifest(manifest, args) {
|
|
82
|
-
if (args.length === 0)
|
|
83
|
-
return manifest;
|
|
84
|
-
const result = {};
|
|
85
|
-
for (const key of args) {
|
|
86
|
-
result[key] = getObjectValueByPropertyPathString(manifest, key);
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
async function pkgSet(opts, args) {
|
|
91
|
-
if (args.length === 0) {
|
|
92
|
-
throw new PnpmError('PKG_SET_MISSING_ARGS', 'Missing key=value pairs', {
|
|
93
|
-
hint: help(),
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
const { manifest, writeProjectManifest } = await readProjectManifest(opts.dir);
|
|
97
|
-
for (const arg of args) {
|
|
98
|
-
const eqIndex = arg.indexOf('=');
|
|
99
|
-
if (eqIndex === -1) {
|
|
100
|
-
throw new PnpmError('PKG_SET_INVALID_ARG', `Invalid argument "${arg}". Expected key=value format`, {
|
|
101
|
-
hint: 'Example: pnpm pkg set name=my-package',
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
const key = arg.slice(0, eqIndex);
|
|
105
|
-
let value = arg.slice(eqIndex + 1);
|
|
106
|
-
if (opts.json) {
|
|
107
|
-
try {
|
|
108
|
-
value = JSON.parse(value);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
throw new PnpmError('PKG_SET_JSON_PARSE', `Failed to parse value as JSON: "${value}"`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
setObjectValueByPropertyPathString(manifest, key, value);
|
|
115
|
-
}
|
|
116
|
-
await writeProjectManifest(manifest);
|
|
117
|
-
}
|
|
118
|
-
async function pkgDelete(opts, args) {
|
|
119
|
-
if (args.length === 0) {
|
|
120
|
-
throw new PnpmError('PKG_DELETE_MISSING_ARGS', 'Missing keys to delete', {
|
|
121
|
-
hint: help(),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
const { manifest, writeProjectManifest } = await readProjectManifest(opts.dir);
|
|
125
|
-
for (const key of args) {
|
|
126
|
-
deleteObjectValueByPropertyPathString(manifest, key);
|
|
127
|
-
}
|
|
128
|
-
await writeProjectManifest(manifest);
|
|
129
|
-
}
|
|
130
|
-
async function pkgFix(opts) {
|
|
131
|
-
const { manifest, writeProjectManifest } = await readProjectManifest(opts.dir);
|
|
132
|
-
const m = manifest;
|
|
133
|
-
if ('name' in m && typeof m.name !== 'string') {
|
|
134
|
-
delete m.name;
|
|
135
|
-
}
|
|
136
|
-
if ('version' in m && typeof m.version !== 'string') {
|
|
137
|
-
delete m.version;
|
|
138
|
-
}
|
|
139
|
-
for (const field of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies', 'scripts']) {
|
|
140
|
-
if (field in m && !isPlainObject(m[field])) {
|
|
141
|
-
delete m[field];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if ('bin' in m && typeof m.bin !== 'string' && !isPlainObject(m.bin)) {
|
|
145
|
-
delete m.bin;
|
|
146
|
-
}
|
|
147
|
-
await writeProjectManifest(manifest);
|
|
148
|
-
}
|
|
149
|
-
function isPlainObject(value) {
|
|
150
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
151
|
-
}
|
|
152
|
-
export function help() {
|
|
153
|
-
return renderHelp({
|
|
154
|
-
description: 'Manages your package.json',
|
|
155
|
-
descriptionLists: [
|
|
156
|
-
{
|
|
157
|
-
title: 'Commands',
|
|
158
|
-
list: [
|
|
159
|
-
{
|
|
160
|
-
description: 'Retrieves a value from package.json',
|
|
161
|
-
name: 'get [<key> [<key> ...]]',
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
description: 'Sets a value in package.json',
|
|
165
|
-
name: 'set <key>=<value> [<key>=<value> ...]',
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
description: 'Deletes a key from package.json',
|
|
169
|
-
name: 'delete <key> [<key> ...]',
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
description: 'Auto corrects common errors in package.json',
|
|
173
|
-
name: 'fix',
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
title: 'Options',
|
|
179
|
-
list: [
|
|
180
|
-
{
|
|
181
|
-
description: 'When setting, parse the value as JSON. When getting a single key, return its JSON-encoded form instead of the raw value',
|
|
182
|
-
name: '--json',
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
description: 'Run on every workspace project or every project selected by a filter',
|
|
186
|
-
name: '--recursive',
|
|
187
|
-
shortAlias: '-r',
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
url: docsUrl('pkg'),
|
|
193
|
-
usages: [
|
|
194
|
-
'pnpm pkg get [<key> [<key> ...]]',
|
|
195
|
-
'pnpm pkg set <key>=<value> [<key>=<value> ...]',
|
|
196
|
-
'pnpm pkg delete <key> [<key> ...]',
|
|
197
|
-
'pnpm pkg fix',
|
|
198
|
-
'pnpm pkg set <key>=<value> --json',
|
|
199
|
-
'pnpm -r pkg get name',
|
|
200
|
-
'pnpm --filter <selector> pkg get name',
|
|
201
|
-
'pnpm -r pkg set version=1.0.0',
|
|
202
|
-
],
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=pkg.js.map
|
package/lib/setScript.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const rcOptionsTypes: typeof cliOptionsTypes;
|
|
2
|
-
export declare function cliOptionsTypes(): Record<string, unknown>;
|
|
3
|
-
export declare const commandNames: string[];
|
|
4
|
-
export declare function handler(opts: {
|
|
5
|
-
dir: string;
|
|
6
|
-
}, params: string[]): Promise<void>;
|
|
7
|
-
export declare function help(): string;
|
package/lib/setScript.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { docsUrl, readProjectManifest } from '@pnpm/cli.utils';
|
|
2
|
-
import { types as allTypes } from '@pnpm/config.reader';
|
|
3
|
-
import { PnpmError } from '@pnpm/error';
|
|
4
|
-
import { setObjectValueByPropertyPath } from '@pnpm/object.property-path';
|
|
5
|
-
import { renderHelp } from 'render-help';
|
|
6
|
-
export const rcOptionsTypes = cliOptionsTypes;
|
|
7
|
-
export function cliOptionsTypes() {
|
|
8
|
-
const types = allTypes;
|
|
9
|
-
return { dir: types['dir'] };
|
|
10
|
-
}
|
|
11
|
-
export const commandNames = ['set-script', 'ss'];
|
|
12
|
-
export async function handler(opts, params) {
|
|
13
|
-
if (params.length < 2) {
|
|
14
|
-
throw new PnpmError('SET_SCRIPT_MISSING_ARGS', 'Missing script name or command', {
|
|
15
|
-
hint: help(),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const [name, ...commandParts] = params;
|
|
19
|
-
const command = commandParts.join(' ');
|
|
20
|
-
const { manifest, writeProjectManifest } = await readProjectManifest(opts.dir);
|
|
21
|
-
setObjectValueByPropertyPath(manifest, ['scripts', name], command);
|
|
22
|
-
await writeProjectManifest(manifest);
|
|
23
|
-
}
|
|
24
|
-
export function help() {
|
|
25
|
-
return renderHelp({
|
|
26
|
-
description: 'Set a script in package.json',
|
|
27
|
-
usages: ['pnpm set-script <name> <command>'],
|
|
28
|
-
url: docsUrl('set-script'),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=setScript.js.map
|