@vltpkg/cli-sdk 0.0.0-16 → 0.0.0-17
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/dist/esm/commands/config.d.ts.map +1 -1
- package/dist/esm/commands/config.js +106 -35
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/init.d.ts +3 -3
- package/dist/esm/commands/init.d.ts.map +1 -1
- package/dist/esm/commands/init.js +95 -9
- package/dist/esm/commands/init.js.map +1 -1
- package/dist/esm/commands/list.d.ts.map +1 -1
- package/dist/esm/commands/list.js +88 -36
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/pack.d.ts +20 -0
- package/dist/esm/commands/pack.d.ts.map +1 -0
- package/dist/esm/commands/pack.js +81 -0
- package/dist/esm/commands/pack.js.map +1 -0
- package/dist/esm/commands/pkg.d.ts +1 -1
- package/dist/esm/commands/pkg.d.ts.map +1 -1
- package/dist/esm/commands/pkg.js +135 -35
- package/dist/esm/commands/pkg.js.map +1 -1
- package/dist/esm/commands/publish.d.ts +21 -0
- package/dist/esm/commands/publish.d.ts.map +1 -0
- package/dist/esm/commands/publish.js +168 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/query.d.ts +1 -1
- package/dist/esm/commands/query.d.ts.map +1 -1
- package/dist/esm/commands/query.js +79 -23
- package/dist/esm/commands/query.js.map +1 -1
- package/dist/esm/commands/version.d.ts +22 -0
- package/dist/esm/commands/version.d.ts.map +1 -0
- package/dist/esm/commands/version.js +151 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/esm/config/definition.d.ts +30 -2
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +28 -4
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/exec-command.js +2 -2
- package/dist/esm/exec-command.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pack-tarball.d.ts +21 -0
- package/dist/esm/pack-tarball.d.ts.map +1 -0
- package/dist/esm/pack-tarball.js +226 -0
- package/dist/esm/pack-tarball.js.map +1 -0
- package/dist/esm/start-gui.d.ts +1 -0
- package/dist/esm/start-gui.d.ts.map +1 -1
- package/dist/esm/start-gui.js +5 -3
- package/dist/esm/start-gui.js.map +1 -1
- package/package.json +28 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAGV,WAAW,EACZ,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,KAAK,EAAE,YA8ChB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAC7B,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,WAAW,CA+B1D,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import * as dotProp from '@vltpkg/dot-prop';
|
|
2
3
|
import { asRootError } from '@vltpkg/output/error';
|
|
3
4
|
import { isObject } from '@vltpkg/types';
|
|
4
5
|
import { spawnSync } from 'node:child_process';
|
|
@@ -123,7 +124,26 @@ const get = async (conf) => {
|
|
|
123
124
|
code: 'EUSAGE',
|
|
124
125
|
});
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
+
// check if this is a dot-prop path into a record field, in which case
|
|
128
|
+
// we need to get the record first and then use dot-prop to get the value
|
|
129
|
+
if (k.includes('.')) {
|
|
130
|
+
const [field, ...rest] = k.split('.');
|
|
131
|
+
const subKey = rest.join('.');
|
|
132
|
+
if (!field || !subKey) {
|
|
133
|
+
throw error('Could not read property', {
|
|
134
|
+
found: k,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// we'd need a type assertion helper from jackspeak definition
|
|
138
|
+
// options in order to cast the field to a known name type
|
|
139
|
+
// @ts-expect-error @typescript-eslint/no-unsafe-argument
|
|
140
|
+
const record = conf.getRecord(field);
|
|
141
|
+
return dotProp.get(record, subKey);
|
|
142
|
+
}
|
|
143
|
+
// otherwise just get the value directly from the config getter
|
|
144
|
+
return isRecordField(k) ?
|
|
145
|
+
conf.getRecord(k)
|
|
146
|
+
: conf.get(k);
|
|
127
147
|
};
|
|
128
148
|
const edit = async (conf) => {
|
|
129
149
|
const [command, ...args] = conf.get('editor').split(' ');
|
|
@@ -147,47 +167,98 @@ const edit = async (conf) => {
|
|
|
147
167
|
const set = async (conf) => {
|
|
148
168
|
const pairs = conf.positionals.slice(1);
|
|
149
169
|
if (!pairs.length) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
let parsed = null;
|
|
155
|
-
try {
|
|
156
|
-
parsed = conf.jack.parseRaw(pairs.map(kv => `--${kv}`)).values;
|
|
170
|
+
// Create an empty config file
|
|
171
|
+
await conf.addConfigToFile(conf.get('config'), {});
|
|
172
|
+
return;
|
|
157
173
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
174
|
+
const which = conf.get('config');
|
|
175
|
+
// separate dot-prop paths from simple keys for different handling
|
|
176
|
+
// any keys that include a dot (.) will be treated as dotPropPairs
|
|
177
|
+
// other keys/value pairs are handled as simplePairs
|
|
178
|
+
const dotPropPairs = [];
|
|
179
|
+
const simplePairs = [];
|
|
180
|
+
for (const pair of pairs) {
|
|
181
|
+
const eq = pair.indexOf('=');
|
|
182
|
+
if (eq === -1) {
|
|
183
|
+
throw error('Set arguments must contain `=`', {
|
|
184
|
+
code: 'EUSAGE',
|
|
169
185
|
});
|
|
170
186
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
187
|
+
const key = pair.substring(0, eq);
|
|
188
|
+
const value = pair.substring(eq + 1);
|
|
189
|
+
if (key.includes('.')) {
|
|
190
|
+
const [field, ...rest] = key.split('.');
|
|
191
|
+
const subKey = rest.join('.');
|
|
192
|
+
if (field && subKey) {
|
|
193
|
+
dotPropPairs.push({ key, field, subKey, value });
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
throw error('Could not read property', {
|
|
197
|
+
found: pair,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
176
200
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
code: 'ECONFIG',
|
|
180
|
-
found,
|
|
181
|
-
validOptions,
|
|
182
|
-
});
|
|
201
|
+
else {
|
|
202
|
+
simplePairs.push(pair);
|
|
183
203
|
}
|
|
184
|
-
|
|
185
|
-
|
|
204
|
+
}
|
|
205
|
+
// Handle keys that consists of a single name (e.g., `--foo`)
|
|
206
|
+
// so that it doesn't need the dot-prop logic to handle values
|
|
207
|
+
if (simplePairs.length > 0) {
|
|
208
|
+
try {
|
|
209
|
+
const parsed = conf.jack.parseRaw(simplePairs.map(kv => `--${kv}`)).values;
|
|
210
|
+
await conf.addConfigToFile(which, pairsToRecords(parsed));
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
handleSetError(simplePairs, err);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Handle dot-prop paths for record fields
|
|
217
|
+
if (dotPropPairs.length > 0) {
|
|
218
|
+
for (const { field, subKey, value } of dotPropPairs) {
|
|
219
|
+
if (isRecordField(field)) {
|
|
220
|
+
// For record fields, we add entries in the format field=key=value
|
|
221
|
+
const recordPair = `${field}=${subKey}=${value}`;
|
|
222
|
+
try {
|
|
223
|
+
const parsed = conf.jack.parseRaw([
|
|
224
|
+
`--${recordPair}`,
|
|
225
|
+
]).values;
|
|
226
|
+
await conf.addConfigToFile(which, pairsToRecords(parsed));
|
|
227
|
+
/* c8 ignore start */
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
handleSetError([recordPair], err);
|
|
231
|
+
}
|
|
232
|
+
/* c8 ignore end */
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
const handleSetError = (simplePairs, err) => {
|
|
238
|
+
const { name, found, validOptions } = asRootError(err).cause;
|
|
239
|
+
// when a boolean gets a value, it throw a parse error
|
|
240
|
+
if (isObject(found) &&
|
|
241
|
+
typeof found.name === 'string' &&
|
|
242
|
+
typeof found.value === 'string') {
|
|
243
|
+
const { name, value } = found;
|
|
244
|
+
throw error(`Boolean flag must be "${name}" or "no-${name}", not a value`, {
|
|
245
|
+
code: 'ECONFIG',
|
|
246
|
+
name,
|
|
247
|
+
found: `${name}=${value}`,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
if (Array.isArray(validOptions)) {
|
|
251
|
+
throw error(`Invalid value provided for ${name}`, {
|
|
186
252
|
code: 'ECONFIG',
|
|
187
|
-
found
|
|
188
|
-
validOptions
|
|
253
|
+
found,
|
|
254
|
+
validOptions,
|
|
189
255
|
});
|
|
190
256
|
}
|
|
191
|
-
|
|
257
|
+
// an unknown property
|
|
258
|
+
throw error('Invalid config keys', {
|
|
259
|
+
code: 'ECONFIG',
|
|
260
|
+
found: simplePairs.map(kv => kv.split('=')[0]),
|
|
261
|
+
validOptions: getSortedKeys(),
|
|
262
|
+
});
|
|
192
263
|
};
|
|
193
264
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM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;YACjD,MAAM,KAAK,CACT,yBAAyB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,EAClE;gBACE,IAAI,EAAE,SAAS;gBACf,MAAM;aACP,CACF,CAAA;QACH,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YAChC,MAAM,KAAK,CAAC,8BAA8B,IAAI,EAAE,EAAE;gBAChD,IAAI,EAAE,SAAS;gBACf,KAAK;gBACL,YAAY;aACb,CAAC,CAAA;QACJ,CAAC;QACD,sBAAsB;QACtB,MAAM,KAAK,CAAC,qBAAqB,EAAE;YACjC,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,YAAY,EAAE,aAAa,EAAE;SAC9B,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,IAAI,CAAC,eAAe,CACxB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAClB,cAAc,CAAC,MAAM,CAAC,CACvB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { asRootError } from '@vltpkg/output/error'\nimport { isObject } from '@vltpkg/types'\nimport { spawnSync } from 'node:child_process'\nimport { getSortedKeys } from '../config/definition.ts'\nimport type {\n ConfigDefinitions,\n ConfigFileData,\n LoadedConfig,\n RecordPairs,\n} from '../config/index.ts'\nimport {\n definition,\n isRecordField,\n pairsToRecords,\n recordsToPairs,\n} from '../config/index.ts'\nimport { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'config',\n usage: '<command> [flags]',\n description: 'Work with vlt configuration',\n\n subcommands: {\n get: {\n usage: '<key> [<key> ...]',\n description: 'Print the named config value',\n },\n\n list: {\n description:\n 'Print all configuration settings currently in effect',\n },\n\n set: {\n usage:\n '<key>=<value> [<key>=<value> ...] [--config=<user | project>]',\n description: `Set config values. By default, these are\n written to the project config file, \\`vlt.json\\`\n in the root of the project. To set things for all\n projects, run with \\`--config=user\\``,\n },\n\n del: {\n usage: '<key> [<key> ...] [--config=<user | project>]',\n description: `Delete the named config fields. If no values remain in\n the config file, delete the file as well. By default,\n operates on the \\`vlt.json\\` file in the root of the\n current project. To delete a config field from the user\n config file, specify \\`--config=user\\`.`,\n },\n\n edit: {\n usage: '[--config=<user | project>]',\n description: 'Edit the configuration file',\n },\n\n help: {\n usage: '[field ...]',\n description: `Get information about a config field, or show a list\n of known config field names.`,\n },\n },\n })\n\nexport const command: CommandFn<\n string | number | boolean | void | string[] | RecordPairs\n> = async conf => {\n const sub = conf.positionals[0]\n switch (sub) {\n case 'set':\n return set(conf)\n\n case 'get':\n return get(conf)\n\n case 'ls':\n case 'list':\n return list(conf)\n\n case 'edit':\n return edit(conf)\n\n case 'help':\n return help(conf)\n\n case 'del':\n return del(conf)\n\n default: {\n throw error('Unrecognized config command', {\n code: 'EUSAGE',\n found: sub,\n validOptions: ['set', 'get', 'list', 'edit', 'help', 'del'],\n })\n }\n }\n}\n\nconst help = (conf: LoadedConfig) => {\n const j = definition.toJSON()\n const fields = conf.positionals.slice(1)\n if (!fields.length) {\n return [\n 'Specify one or more options to see information:',\n ...Object.keys(j)\n .sort((a, b) => a.localeCompare(b, 'en'))\n .map(c => ` ${c}`),\n ].join('\\n')\n }\n\n // TODO: some kind of fuzzy search?\n const res: string[] = []\n for (const f of fields) {\n const def = j[f]\n if (!def) {\n res.push(`unknown config field: ${f}`)\n } else {\n const hint = def.hint ? `=<${def.hint}>` : ''\n const type =\n isRecordField(f) ?\n 'Record<string, string>'\n : def.type + (def.multiple ? '[]' : '')\n\n res.push(`--${f}${hint}`)\n res.push(` type: ${type}`)\n if (def.default) {\n res.push(` default: ${JSON.stringify(def.default)}`)\n }\n if (def.description) {\n res.push(def.description)\n }\n }\n }\n return res.join('\\n')\n}\n\nconst list = (conf: LoadedConfig) => {\n return recordsToPairs(conf.options)\n}\n\nconst del = async (conf: LoadedConfig) => {\n const fields = conf.positionals.slice(1)\n if (!fields.length) {\n throw error('At least one key is required', {\n code: 'EUSAGE',\n })\n }\n await conf.deleteConfigKeys(conf.get('config'), fields)\n}\n\nconst get = async (conf: LoadedConfig) => {\n const keys = conf.positionals.slice(1)\n const k = keys[0]\n if (!k || keys.length > 1) {\n throw error('Exactly one key is required', {\n code: 'EUSAGE',\n })\n }\n return conf.get(k as keyof ConfigDefinitions)\n}\n\nconst edit = async (conf: LoadedConfig) => {\n const [command, ...args] = conf.get('editor').split(' ')\n if (!command) {\n throw error(`editor is empty`)\n }\n await conf.editConfigFile(conf.get('config'), file => {\n args.push(file)\n const res = spawnSync(command, args, {\n stdio: 'inherit',\n })\n if (res.status !== 0) {\n throw error(`${command} command failed`, {\n ...res,\n command,\n args,\n })\n }\n })\n}\n\nconst set = async (conf: LoadedConfig) => {\n const pairs = conf.positionals.slice(1)\n if (!pairs.length) {\n throw error('At least one key=value pair is required', {\n code: 'EUSAGE',\n })\n }\n let parsed: ConfigFileData | null = null\n try {\n parsed = conf.jack.parseRaw(pairs.map(kv => `--${kv}`)).values\n } catch (er) {\n const { name, found, value, wanted, validOptions } =\n asRootError(er).cause\n // when a boolean gets a value, it throw a parse error\n if (\n isObject(found) &&\n typeof found.name === 'string' &&\n typeof found.value === 'string'\n ) {\n const { name, value } = found\n throw error(\n `Boolean flag must be \"${name}\" or \"no-${name}\", not a value`,\n {\n code: 'ECONFIG',\n name,\n found: `${name}=${value}`,\n },\n )\n }\n if (wanted && !value && typeof name === 'string') {\n throw error(\n `No value provided for ${JSON.stringify(name.replace(/^-+/, ''))}`,\n {\n code: 'ECONFIG',\n wanted,\n },\n )\n }\n if (Array.isArray(validOptions)) {\n throw error(`Invalid value provided for ${name}`, {\n code: 'ECONFIG',\n found,\n validOptions,\n })\n }\n // an unknown property\n throw error('Invalid config keys', {\n code: 'ECONFIG',\n found: pairs.map(kv => kv.split('=')[0]),\n validOptions: getSortedKeys(),\n })\n }\n await conf.addConfigToFile(\n conf.get('config'),\n pairsToRecords(parsed),\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,GACf,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAQjD,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,mBAAmB;IAC1B,WAAW,EAAE,6BAA6B;IAE1C,WAAW,EAAE;QACX,GAAG,EAAE;YACH,KAAK,EAAE,mBAAmB;YAC1B,WAAW,EAAE,8BAA8B;SAC5C;QAED,IAAI,EAAE;YACJ,WAAW,EACT,sDAAsD;SACzD;QAED,GAAG,EAAE;YACH,KAAK,EACH,+DAA+D;YACjE,WAAW,EAAE;;;2DAGsC;SACpD;QAED,GAAG,EAAE;YACH,KAAK,EAAE,+CAA+C;YACtD,WAAW,EAAE;;;;8DAIyC;SACvD;QAED,IAAI,EAAE;YACJ,KAAK,EAAE,6BAA6B;YACpC,WAAW,EAAE,6BAA6B;SAC3C;QAED,IAAI,EAAE;YACJ,KAAK,EAAE,aAAa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'@vltpkg/output/error'\nimport { isObject } from '@vltpkg/types'\nimport { spawnSync } from 'node:child_process'\nimport { getSortedKeys } from '../config/definition.ts'\nimport {\n definition,\n isRecordField,\n pairsToRecords,\n recordsToPairs,\n} from '../config/index.ts'\nimport { commandUsage } from '../config/usage.ts'\nimport type {\n ConfigDefinitions,\n LoadedConfig,\n RecordPairs,\n} from '../config/index.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'config',\n usage: '<command> [flags]',\n description: 'Work with vlt configuration',\n\n subcommands: {\n get: {\n usage: '<key> [<key> ...]',\n description: 'Print the named config value',\n },\n\n list: {\n description:\n 'Print all configuration settings currently in effect',\n },\n\n set: {\n usage:\n '<key>=<value> [<key>=<value> ...] [--config=<user | project>]',\n description: `Set config values. By default, these are\n written to the project config file, \\`vlt.json\\`\n in the root of the project. To set things for all\n projects, run with \\`--config=user\\``,\n },\n\n del: {\n usage: '<key> [<key> ...] [--config=<user | project>]',\n description: `Delete the named config fields. If no values remain in\n the config file, delete the file as well. By default,\n operates on the \\`vlt.json\\` file in the root of the\n current project. To delete a config field from the user\n config file, specify \\`--config=user\\`.`,\n },\n\n edit: {\n usage: '[--config=<user | project>]',\n description: 'Edit the configuration file',\n },\n\n help: {\n usage: '[field ...]',\n description: `Get information about a config field, or show a list\n of known config field names.`,\n },\n },\n })\n\nexport const command: CommandFn<\n string | number | boolean | void | string[] | RecordPairs\n> = async conf => {\n const sub = conf.positionals[0]\n switch (sub) {\n case 'set':\n return set(conf)\n\n case 'get':\n return get(conf)\n\n case 'ls':\n case 'list':\n return list(conf)\n\n case 'edit':\n return edit(conf)\n\n case 'help':\n return help(conf)\n\n case 'del':\n return del(conf)\n\n default: {\n throw error('Unrecognized config command', {\n code: 'EUSAGE',\n found: sub,\n validOptions: ['set', 'get', 'list', 'edit', 'help', 'del'],\n })\n }\n }\n}\n\nconst help = (conf: LoadedConfig) => {\n const j = definition.toJSON()\n const fields = conf.positionals.slice(1)\n if (!fields.length) {\n return [\n 'Specify one or more options to see information:',\n ...Object.keys(j)\n .sort((a, b) => a.localeCompare(b, 'en'))\n .map(c => ` ${c}`),\n ].join('\\n')\n }\n\n // TODO: some kind of fuzzy search?\n const res: string[] = []\n for (const f of fields) {\n const def = j[f]\n if (!def) {\n res.push(`unknown config field: ${f}`)\n } else {\n const hint = def.hint ? `=<${def.hint}>` : ''\n const type =\n isRecordField(f) ?\n 'Record<string, string>'\n : def.type + (def.multiple ? '[]' : '')\n\n res.push(`--${f}${hint}`)\n res.push(` type: ${type}`)\n if (def.default) {\n res.push(` default: ${JSON.stringify(def.default)}`)\n }\n if (def.description) {\n res.push(def.description)\n }\n }\n }\n return res.join('\\n')\n}\n\nconst list = (conf: LoadedConfig) => {\n return recordsToPairs(conf.options)\n}\n\nconst del = async (conf: LoadedConfig) => {\n const fields = conf.positionals.slice(1)\n if (!fields.length) {\n throw error('At least one key is required', {\n code: 'EUSAGE',\n })\n }\n\n await conf.deleteConfigKeys(conf.get('config'), fields)\n}\n\nconst get = async (conf: LoadedConfig) => {\n const keys = conf.positionals.slice(1)\n const k = keys[0]\n if (!k || keys.length > 1) {\n throw error('Exactly one key is required', {\n code: 'EUSAGE',\n })\n }\n // check if this is a dot-prop path into a record field, in which case\n // we need to get the record first and then use dot-prop to get the value\n if (k.includes('.')) {\n const [field, ...rest] = k.split('.')\n const subKey = rest.join('.')\n\n if (!field || !subKey) {\n throw error('Could not read property', {\n found: k,\n })\n }\n\n // we'd need a type assertion helper from jackspeak definition\n // options in order to cast the field to a known name type\n // @ts-expect-error @typescript-eslint/no-unsafe-argument\n const record = conf.getRecord(field)\n\n return dotProp.get(record, subKey) as\n | string\n | number\n | boolean\n | string[]\n | undefined\n }\n\n // otherwise just get the value directly from the config getter\n return isRecordField(k) ?\n conf.getRecord(k)\n : conf.get(k as keyof ConfigDefinitions)\n}\n\nconst edit = async (conf: LoadedConfig) => {\n const [command, ...args] = conf.get('editor').split(' ')\n if (!command) {\n throw error(`editor is empty`)\n }\n await conf.editConfigFile(conf.get('config'), file => {\n args.push(file)\n const res = spawnSync(command, args, {\n stdio: 'inherit',\n })\n if (res.status !== 0) {\n throw error(`${command} command failed`, {\n ...res,\n command,\n args,\n })\n }\n })\n}\n\nconst set = async (conf: LoadedConfig) => {\n const pairs = conf.positionals.slice(1)\n if (!pairs.length) {\n // Create an empty config file\n await conf.addConfigToFile(conf.get('config'), {})\n return\n }\n\n const which = conf.get('config')\n\n // separate dot-prop paths from simple keys for different handling\n // any keys that include a dot (.) will be treated as dotPropPairs\n // other keys/value pairs are handled as simplePairs\n const dotPropPairs: {\n key: string\n field: string\n subKey: string\n value: string\n }[] = []\n const simplePairs: string[] = []\n\n for (const pair of pairs) {\n const eq = pair.indexOf('=')\n if (eq === -1) {\n throw error('Set arguments must contain `=`', {\n code: 'EUSAGE',\n })\n }\n\n const key = pair.substring(0, eq)\n const value = pair.substring(eq + 1)\n if (key.includes('.')) {\n const [field, ...rest] = key.split('.')\n const subKey = rest.join('.')\n if (field && subKey) {\n dotPropPairs.push({ key, field, subKey, value })\n } else {\n throw error('Could not read property', {\n found: pair,\n })\n }\n } else {\n simplePairs.push(pair)\n }\n }\n\n // Handle keys that consists of a single name (e.g., `--foo`)\n // so that it doesn't need the dot-prop logic to handle values\n if (simplePairs.length > 0) {\n try {\n const parsed = conf.jack.parseRaw(\n simplePairs.map(kv => `--${kv}`),\n ).values\n await conf.addConfigToFile(which, pairsToRecords(parsed))\n } catch (err) {\n handleSetError(simplePairs, err)\n }\n }\n\n // Handle dot-prop paths for record fields\n if (dotPropPairs.length > 0) {\n for (const { field, subKey, value } of dotPropPairs) {\n if (isRecordField(field)) {\n // For record fields, we add entries in the format field=key=value\n const recordPair = `${field}=${subKey}=${value}`\n try {\n const parsed = conf.jack.parseRaw([\n `--${recordPair}`,\n ]).values\n await conf.addConfigToFile(which, pairsToRecords(parsed))\n /* c8 ignore start */\n } catch (err) {\n handleSetError([recordPair], err)\n }\n /* c8 ignore end */\n }\n }\n }\n}\n\nconst handleSetError = (simplePairs: string[], err: unknown) => {\n const { name, found, validOptions } = asRootError(err).cause\n // when a boolean gets a value, it throw a parse error\n if (\n isObject(found) &&\n typeof found.name === 'string' &&\n typeof found.value === 'string'\n ) {\n const { name, value } = found\n throw error(\n `Boolean flag must be \"${name}\" or \"no-${name}\", not a value`,\n {\n code: 'ECONFIG',\n name,\n found: `${name}=${value}`,\n },\n )\n }\n if (Array.isArray(validOptions)) {\n throw error(`Invalid value provided for ${name}`, {\n code: 'ECONFIG',\n found,\n validOptions,\n })\n }\n // an unknown property\n throw error('Invalid config keys', {\n code: 'ECONFIG',\n found: simplePairs.map(kv => kv.split('=')[0]),\n validOptions: getSortedKeys(),\n })\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
2
1
|
import type { InitFileResults } from '@vltpkg/init';
|
|
2
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
3
3
|
export declare const usage: CommandUsage;
|
|
4
4
|
export declare const views: {
|
|
5
|
-
readonly human: (results: InitFileResults
|
|
5
|
+
readonly human: (results: InitFileResults | InitFileResults[]) => string;
|
|
6
6
|
};
|
|
7
|
-
export declare const command: CommandFn<InitFileResults>;
|
|
7
|
+
export declare const command: CommandFn<InitFileResults | InitFileResults[]>;
|
|
8
8
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1D,eAAO,MAAM,KAAK,EAAE,YAKhB,CAAA;AAGJ,eAAO,MAAM,KAAK;8BACC,eAAe,GAAG,eAAe,EAAE;CAsBX,CAAA;AAE3C,eAAO,MAAM,OAAO,EAAE,SAAS,CAC7B,eAAe,GAAG,eAAe,EAAE,CAoFpC,CAAA"}
|
|
@@ -1,25 +1,111 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { minimatch } from 'minimatch';
|
|
2
4
|
import { init } from '@vltpkg/init';
|
|
5
|
+
import { load, save } from '@vltpkg/vlt-json';
|
|
6
|
+
import { assertWSConfig, asWSConfig } from '@vltpkg/workspaces';
|
|
7
|
+
import { commandUsage } from "../config/usage.js";
|
|
3
8
|
export const usage = () => commandUsage({
|
|
4
9
|
command: 'init',
|
|
5
10
|
usage: '',
|
|
6
11
|
description: `Create a new package.json file in the current directory.`,
|
|
7
12
|
});
|
|
13
|
+
// TODO: colorize the JSON if config.options.color
|
|
8
14
|
export const views = {
|
|
9
|
-
human: (results
|
|
15
|
+
human: (results) => {
|
|
10
16
|
const output = [];
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
// if results is an array, it means multiple workspaces were initialized
|
|
18
|
+
if (Array.isArray(results)) {
|
|
19
|
+
for (const result of results) {
|
|
20
|
+
for (const [type, { path }] of Object.entries(result)) {
|
|
21
|
+
output.push(`Wrote ${type} to ${path}:`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// otherwise, it's a single result
|
|
27
|
+
for (const [type, { path, data }] of Object.entries(results)) {
|
|
28
|
+
output.push(`Wrote ${type} to ${path}:
|
|
14
29
|
|
|
15
|
-
${JSON.stringify(data, null, 2)}
|
|
16
|
-
|
|
30
|
+
${JSON.stringify(data, null, 2)}`);
|
|
31
|
+
}
|
|
17
32
|
}
|
|
18
|
-
output.push(
|
|
33
|
+
output.push(`\nModify/add properties using \`vlt pkg\`. For example:
|
|
19
34
|
|
|
20
35
|
vlt pkg set "description=My new project"`);
|
|
21
36
|
return output.join('\n');
|
|
22
37
|
},
|
|
23
38
|
};
|
|
24
|
-
export const command = async () =>
|
|
39
|
+
export const command = async (conf) => {
|
|
40
|
+
if (conf.values.workspace?.length) {
|
|
41
|
+
const workspacesConfig = load('workspaces', assertWSConfig);
|
|
42
|
+
const parsedWSConfig = asWSConfig(workspacesConfig ?? {});
|
|
43
|
+
const results = [];
|
|
44
|
+
const addToConfig = [];
|
|
45
|
+
// create a new package.json file for every workspace
|
|
46
|
+
// defined as cli --workspace options
|
|
47
|
+
for (const workspace of conf.values.workspace) {
|
|
48
|
+
// cwd is the resolved location of the workspace
|
|
49
|
+
const cwd = resolve(conf.options.projectRoot, workspace);
|
|
50
|
+
// create the folder in case it's missing
|
|
51
|
+
mkdirSync(cwd, { recursive: true });
|
|
52
|
+
// run the initialization script and collect results
|
|
53
|
+
results.push(await init({ cwd }));
|
|
54
|
+
// Check if this workspace path is covered by existing workspace patterns
|
|
55
|
+
const isMatched = Object.values(parsedWSConfig).some((patterns) => {
|
|
56
|
+
return patterns.some(pattern => minimatch(workspace, pattern));
|
|
57
|
+
});
|
|
58
|
+
// When a workspace is not matched we track it for insertion later
|
|
59
|
+
if (!isMatched) {
|
|
60
|
+
addToConfig.push(relative(conf.options.projectRoot, cwd).replace(/\\/g, '/'));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// if there are workspaces that were not matched by existing
|
|
64
|
+
// patterns, we add them to the workspaces config
|
|
65
|
+
if (addToConfig.length > 0) {
|
|
66
|
+
let workspaces = workspacesConfig;
|
|
67
|
+
// if the original workspaces config is a string, we'll need
|
|
68
|
+
// to convert it to an array in order to append the recently
|
|
69
|
+
// added workspaces
|
|
70
|
+
if (typeof workspacesConfig === 'string') {
|
|
71
|
+
workspaces = [workspacesConfig, ...addToConfig];
|
|
72
|
+
}
|
|
73
|
+
else if (Array.isArray(workspacesConfig)) {
|
|
74
|
+
// if the original workspaces config is an array, we simply
|
|
75
|
+
// append the missing items to it
|
|
76
|
+
workspaces = [...workspacesConfig, ...addToConfig];
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// otherwise we assume it's an Record<string, string[]> object
|
|
80
|
+
// and we'll add the new workspaces to the `packages` keys
|
|
81
|
+
workspaces = (workspacesConfig ?? {});
|
|
82
|
+
// if the `packages` key is not being used
|
|
83
|
+
if (!workspaces.packages) {
|
|
84
|
+
workspaces.packages = addToConfig;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// if the `packages` key is defined as a string, we
|
|
88
|
+
// convert it to an array to append the new items
|
|
89
|
+
if (typeof workspaces.packages === 'string') {
|
|
90
|
+
workspaces.packages = [
|
|
91
|
+
workspaces.packages,
|
|
92
|
+
...addToConfig,
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// if it is, we simply append the new workspaces
|
|
97
|
+
workspaces.packages = [
|
|
98
|
+
...workspaces.packages,
|
|
99
|
+
...addToConfig,
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// finally, we add the new workspaces to the config file
|
|
105
|
+
save('workspaces', workspaces);
|
|
106
|
+
}
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
return init({ cwd: process.cwd() });
|
|
110
|
+
};
|
|
25
111
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,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AAA;IAChB,CAAC;IAED,OAAO,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AACrC,CAAC,CAAA","sourcesContent":["import { mkdirSync } from 'node:fs'\nimport { relative, resolve } from 'node:path'\nimport { minimatch } from 'minimatch'\nimport { init } from '@vltpkg/init'\nimport { load, save } from '@vltpkg/vlt-json'\nimport { assertWSConfig, asWSConfig } from '@vltpkg/workspaces'\nimport { commandUsage } from '../config/usage.ts'\nimport type { InitFileResults } from '@vltpkg/init'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport type { Views } from '../view.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'init',\n usage: '',\n description: `Create a new package.json file in the current directory.`,\n })\n\n// TODO: colorize the JSON if config.options.color\nexport const views = {\n human: (results: InitFileResults | InitFileResults[]) => {\n const output: string[] = []\n // if results is an array, it means multiple workspaces were initialized\n if (Array.isArray(results)) {\n for (const result of results) {\n for (const [type, { path }] of Object.entries(result)) {\n output.push(`Wrote ${type} to ${path}:`)\n }\n }\n } else {\n // otherwise, it's a single result\n for (const [type, { path, data }] of Object.entries(results)) {\n output.push(`Wrote ${type} to ${path}:\n\n${JSON.stringify(data, null, 2)}`)\n }\n }\n output.push(`\\nModify/add properties using \\`vlt pkg\\`. For example:\n\n vlt pkg set \"description=My new project\"`)\n return output.join('\\n')\n },\n} as const satisfies Views<InitFileResults>\n\nexport const command: CommandFn<\n InitFileResults | InitFileResults[]\n> = async conf => {\n if (conf.values.workspace?.length) {\n const workspacesConfig = load('workspaces', assertWSConfig)\n const parsedWSConfig = asWSConfig(workspacesConfig ?? {})\n const results: InitFileResults[] = []\n const addToConfig: string[] = []\n\n // create a new package.json file for every workspace\n // defined as cli --workspace options\n for (const workspace of conf.values.workspace) {\n // cwd is the resolved location of the workspace\n const cwd = resolve(conf.options.projectRoot, workspace)\n\n // create the folder in case it's missing\n mkdirSync(cwd, { recursive: true })\n\n // run the initialization script and collect results\n results.push(await init({ cwd }))\n\n // Check if this workspace path is covered by existing workspace patterns\n const isMatched = Object.values(parsedWSConfig).some(\n (patterns: string[]) => {\n return patterns.some(pattern =>\n minimatch(workspace, pattern),\n )\n },\n )\n\n // When a workspace is not matched we track it for insertion later\n if (!isMatched) {\n addToConfig.push(\n relative(conf.options.projectRoot, cwd).replace(/\\\\/g, '/'),\n )\n }\n }\n\n // if there are workspaces that were not matched by existing\n // patterns, we add them to the workspaces config\n if (addToConfig.length > 0) {\n let workspaces = workspacesConfig\n // if the original workspaces config is a string, we'll need\n // to convert it to an array in order to append the recently\n // added workspaces\n if (typeof workspacesConfig === 'string') {\n workspaces = [workspacesConfig, ...addToConfig]\n } else if (Array.isArray(workspacesConfig)) {\n // if the original workspaces config is an array, we simply\n // append the missing items to it\n workspaces = [...workspacesConfig, ...addToConfig]\n } else {\n // otherwise we assume it's an Record<string, string[]> object\n // and we'll add the new workspaces to the `packages` keys\n workspaces = (workspacesConfig ?? {}) as Record<\n string,\n string[]\n >\n // if the `packages` key is not being used\n if (!workspaces.packages) {\n workspaces.packages = addToConfig\n } else {\n // if the `packages` key is defined as a string, we\n // convert it to an array to append the new items\n if (typeof workspaces.packages === 'string') {\n workspaces.packages = [\n workspaces.packages,\n ...addToConfig,\n ]\n } else {\n // if it is, we simply append the new workspaces\n workspaces.packages = [\n ...workspaces.packages,\n ...addToConfig,\n ]\n }\n }\n }\n // finally, we add the new workspaces to the config file\n save('workspaces', workspaces)\n }\n return results\n }\n\n return init({ cwd: process.cwd() })\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EAEnB,MAAM,eAAe,CAAA;AACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EAEnB,MAAM,eAAe,CAAA;AACtB,OAAO,EAGL,mBAAmB,EACnB,UAAU,EACV,aAAa,EAEd,MAAM,eAAe,CAAA;AAOtB,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1D,eAAO,MAAM,KAAK,EAAE,YAyDhB,CAAA;AAEJ,MAAM,MAAM,UAAU,GAAG,eAAe,GACtC,kBAAkB,GAClB,wBAAwB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpD,eAAO,MAAM,KAAK;;;;;CAUoB,CAAA;AAEtC,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,UAAU,CAwHzC,CAAA"}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import { actual, humanReadableOutput, jsonOutput, mermaidOutput, GraphModifier, } from '@vltpkg/graph';
|
|
1
|
+
import { actual, asNode, humanReadableOutput, jsonOutput, mermaidOutput, GraphModifier, } from '@vltpkg/graph';
|
|
2
|
+
import LZString from 'lz-string';
|
|
2
3
|
import { Query } from '@vltpkg/query';
|
|
3
4
|
import { SecurityArchive } from '@vltpkg/security-archive';
|
|
5
|
+
import { error } from '@vltpkg/error-cause';
|
|
4
6
|
import { commandUsage } from "../config/usage.js";
|
|
5
7
|
import { startGUI } from "../start-gui.js";
|
|
6
8
|
export const usage = () => commandUsage({
|
|
7
9
|
command: 'ls',
|
|
8
10
|
usage: [
|
|
9
11
|
'',
|
|
10
|
-
'[
|
|
12
|
+
'[package-names...] [--view=human | json | mermaid | gui]',
|
|
13
|
+
'[--scope=<query>] [--target=<query>] [--view=human | json | mermaid | gui]',
|
|
11
14
|
],
|
|
12
|
-
description: `List installed dependencies matching given package names or
|
|
13
|
-
packages from matching a given Dependency Selector Syntax query if one
|
|
14
|
-
is provided.
|
|
15
|
+
description: `List installed dependencies matching given package names or query selectors.
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
Package names provided as positional arguments will be used to filter
|
|
18
|
+
the results to show only dependencies with those names.
|
|
19
|
+
|
|
20
|
+
The --scope and --target options accepts DSS query selectors to filter
|
|
21
|
+
packages. Using --scope, you can specify which packages to treat as the
|
|
22
|
+
top-level items in the output graph. The --target option allows you to
|
|
23
|
+
filter what dependencies to include in the output. Using both options
|
|
24
|
+
allows you to render subgraphs of the dependency graph.
|
|
19
25
|
|
|
20
26
|
Defaults to listing direct dependencies of a project and any configured
|
|
21
27
|
workspace.`,
|
|
@@ -23,20 +29,28 @@ export const usage = () => commandUsage({
|
|
|
23
29
|
'': {
|
|
24
30
|
description: 'List direct dependencies of the current project / workspace',
|
|
25
31
|
},
|
|
26
|
-
'"*"': {
|
|
27
|
-
description: 'List all dependencies for the current project / workspace',
|
|
28
|
-
},
|
|
29
32
|
'foo bar baz': {
|
|
30
33
|
description: `List all dependencies named 'foo', 'bar', or 'baz'`,
|
|
31
34
|
},
|
|
32
|
-
|
|
33
|
-
description: '
|
|
35
|
+
'--scope=":root > #dependency-name"': {
|
|
36
|
+
description: 'Defines a direct dependency as the output top-level scope',
|
|
37
|
+
},
|
|
38
|
+
'--target="*"': {
|
|
39
|
+
description: 'List all dependencies using a query selector',
|
|
34
40
|
},
|
|
35
|
-
|
|
41
|
+
'--target=":workspace > *:peer"': {
|
|
36
42
|
description: 'List all peer dependencies of all workspaces',
|
|
37
43
|
},
|
|
38
44
|
},
|
|
39
45
|
options: {
|
|
46
|
+
scope: {
|
|
47
|
+
value: '<query>',
|
|
48
|
+
description: 'Query selector to select top-level packages using the DSS query language syntax.',
|
|
49
|
+
},
|
|
50
|
+
target: {
|
|
51
|
+
value: '<query>',
|
|
52
|
+
description: 'Query selector to filter packages using the DSS query language syntax.',
|
|
53
|
+
},
|
|
40
54
|
view: {
|
|
41
55
|
value: '[human | json | mermaid | gui]',
|
|
42
56
|
description: 'Output format. Defaults to human-readable or json if no tty.',
|
|
@@ -48,7 +62,7 @@ export const views = {
|
|
|
48
62
|
mermaid: mermaidOutput,
|
|
49
63
|
human: humanReadableOutput,
|
|
50
64
|
gui: async ({ queryString }, _, conf) => {
|
|
51
|
-
await startGUI(conf,
|
|
65
|
+
await startGUI(conf, `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`);
|
|
52
66
|
},
|
|
53
67
|
};
|
|
54
68
|
export const command = async (conf) => {
|
|
@@ -62,15 +76,24 @@ export const command = async (conf) => {
|
|
|
62
76
|
monorepo,
|
|
63
77
|
loadManifests: true,
|
|
64
78
|
});
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
// Validate positional arguments - only allow package names, not direct queries
|
|
80
|
+
for (const arg of conf.positionals) {
|
|
81
|
+
if (!/^[@\w-]/.test(arg)) {
|
|
82
|
+
throw error(`Direct queries are not supported as positional arguments. Use package names only.`, {
|
|
83
|
+
code: 'EUSAGE',
|
|
84
|
+
cause: `Argument '${arg}' appears to be a query syntax. Only package names are allowed as positional arguments.`,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const positionalQueryString = conf.positionals
|
|
89
|
+
.map(k => `#${k.replace(/\//, '\\/')}`)
|
|
67
90
|
.join(', ');
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
const targetQueryString = conf.get('target');
|
|
92
|
+
const queryString = targetQueryString || positionalQueryString;
|
|
93
|
+
const securityArchive = await SecurityArchive.start({
|
|
94
|
+
graph,
|
|
95
|
+
specOptions: conf.options,
|
|
96
|
+
});
|
|
74
97
|
const query = new Query({
|
|
75
98
|
graph,
|
|
76
99
|
specOptions: conf.options,
|
|
@@ -80,27 +103,56 @@ export const command = async (conf) => {
|
|
|
80
103
|
const selectImporters = [];
|
|
81
104
|
const importers = new Set();
|
|
82
105
|
const scopeIDs = [];
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
106
|
+
// handle --scope option to add scope nodes as importers
|
|
107
|
+
const scopeQueryString = conf.get('scope');
|
|
108
|
+
let scopeNodes;
|
|
109
|
+
if (scopeQueryString) {
|
|
110
|
+
// run scope query to get all matching nodes
|
|
111
|
+
const scopeQuery = new Query({
|
|
112
|
+
graph,
|
|
113
|
+
specOptions: conf.options,
|
|
114
|
+
securityArchive,
|
|
115
|
+
});
|
|
116
|
+
const { nodes } = await scopeQuery.search(scopeQueryString, {
|
|
117
|
+
signal: new AbortController().signal,
|
|
118
|
+
});
|
|
119
|
+
scopeNodes = nodes;
|
|
120
|
+
}
|
|
121
|
+
if (scopeQueryString && scopeNodes) {
|
|
122
|
+
// Add all scope nodes to importers Set (treat them as top-level items)
|
|
123
|
+
for (const queryNode of scopeNodes) {
|
|
124
|
+
importers.add(asNode(queryNode));
|
|
92
125
|
}
|
|
93
126
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
127
|
+
else {
|
|
128
|
+
// if in a workspace environment, select only the specified
|
|
129
|
+
// workspaces as top-level items
|
|
130
|
+
if (monorepo) {
|
|
131
|
+
for (const workspace of monorepo.filter(conf.values)) {
|
|
132
|
+
const w = graph.nodes.get(workspace.id);
|
|
133
|
+
if (w) {
|
|
134
|
+
importers.add(w);
|
|
135
|
+
selectImporters.push(`[name="${w.name}"]`);
|
|
136
|
+
selectImporters.push(`[name="${w.name}"] > *`);
|
|
137
|
+
scopeIDs.push(workspace.id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// if no top-level item was set then by default
|
|
142
|
+
// we just set all importers as top-level items
|
|
143
|
+
if (importers.size === 0) {
|
|
144
|
+
for (const importer of graph.importers) {
|
|
145
|
+
importers.add(importer);
|
|
146
|
+
}
|
|
97
147
|
}
|
|
98
148
|
}
|
|
149
|
+
// build a default query string to use in the target search
|
|
99
150
|
const selectImportersQueryString = selectImporters.join(', ');
|
|
100
151
|
const defaultQueryString = (selectImporters.length &&
|
|
101
152
|
selectImporters.length < graph.importers.size) ?
|
|
102
153
|
selectImportersQueryString
|
|
103
154
|
: projectQueryString;
|
|
155
|
+
// retrieve the selected nodes and edges
|
|
104
156
|
const { edges, nodes } = await query.search(queryString || defaultQueryString, {
|
|
105
157
|
signal: new AbortController().signal,
|
|
106
158
|
scopeIDs: scopeIDs.length > 0 ? scopeIDs : undefined,
|
|
@@ -110,7 +162,7 @@ export const command = async (conf) => {
|
|
|
110
162
|
edges,
|
|
111
163
|
nodes,
|
|
112
164
|
queryString: queryString || defaultQueryString,
|
|
113
|
-
highlightSelection: !!
|
|
165
|
+
highlightSelection: !!(targetQueryString || positionalQueryString),
|
|
114
166
|
};
|
|
115
167
|
};
|
|
116
168
|
//# sourceMappingURL=list.js.map
|