@vltpkg/cli-sdk 1.0.0-rc.22 → 1.0.0-rc.24
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/commands/bugs.d.ts +17 -0
- package/dist/commands/bugs.js +163 -0
- package/dist/commands/build.d.ts +24 -0
- package/dist/commands/build.js +101 -0
- package/dist/commands/cache.d.ts +64 -0
- package/dist/commands/cache.js +256 -0
- package/dist/commands/ci.d.ts +10 -0
- package/dist/commands/ci.js +40 -0
- package/dist/commands/config.d.ts +5 -0
- package/dist/commands/config.js +429 -0
- package/dist/commands/create.d.ts +8 -0
- package/dist/commands/create.js +102 -0
- package/dist/commands/docs.d.ts +17 -0
- package/dist/commands/docs.js +153 -0
- package/dist/commands/exec-cache.d.ts +48 -0
- package/dist/commands/exec-cache.js +145 -0
- package/dist/commands/exec-local.d.ts +5 -0
- package/dist/commands/exec-local.js +46 -0
- package/dist/commands/exec.d.ts +8 -0
- package/dist/commands/exec.js +161 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.js +43 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +116 -0
- package/dist/commands/install/reporter.d.ts +10 -0
- package/dist/commands/install/reporter.js +93 -0
- package/dist/commands/install.d.ts +27 -0
- package/dist/commands/install.js +80 -0
- package/dist/commands/list.d.ts +17 -0
- package/dist/commands/list.js +197 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.js +22 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.js +22 -0
- package/dist/commands/pack.d.ts +31 -0
- package/dist/commands/pack.js +205 -0
- package/dist/commands/ping.d.ts +17 -0
- package/dist/commands/ping.js +114 -0
- package/dist/commands/pkg.d.ts +6 -0
- package/dist/commands/pkg.js +232 -0
- package/dist/commands/publish.d.ts +21 -0
- package/dist/commands/publish.js +282 -0
- package/dist/commands/query.d.ts +18 -0
- package/dist/commands/query.js +216 -0
- package/dist/commands/repo.d.ts +17 -0
- package/dist/commands/repo.js +157 -0
- package/dist/commands/run-exec.d.ts +5 -0
- package/dist/commands/run-exec.js +40 -0
- package/dist/commands/run.d.ts +5 -0
- package/dist/commands/run.js +62 -0
- package/dist/commands/token.d.ts +3 -0
- package/dist/commands/token.js +39 -0
- package/dist/commands/uninstall.d.ts +15 -0
- package/dist/commands/uninstall.js +39 -0
- package/dist/commands/update.d.ts +13 -0
- package/dist/commands/update.js +46 -0
- package/dist/commands/version.d.ts +25 -0
- package/dist/commands/version.js +252 -0
- package/dist/commands/view.d.ts +22 -0
- package/dist/commands/view.js +334 -0
- package/dist/commands/whoami.d.ts +12 -0
- package/dist/commands/whoami.js +28 -0
- package/dist/config/definition.d.ts +407 -0
- package/dist/config/definition.js +684 -0
- package/dist/config/index.d.ts +218 -0
- package/dist/config/index.js +488 -0
- package/dist/config/merge.d.ts +3 -0
- package/dist/config/merge.js +27 -0
- package/dist/config/usage.d.ts +18 -0
- package/dist/config/usage.js +39 -0
- package/dist/custom-help.d.ts +8 -0
- package/dist/custom-help.js +419 -0
- package/dist/exec-command.d.ts +52 -0
- package/dist/exec-command.js +313 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +72 -0
- package/dist/load-command.d.ts +15 -0
- package/dist/load-command.js +20 -0
- package/dist/mermaid-image-view.d.ts +18 -0
- package/dist/mermaid-image-view.js +36 -0
- package/dist/output.d.ts +20 -0
- package/dist/output.js +125 -0
- package/dist/pack-tarball.d.ts +23 -0
- package/dist/pack-tarball.js +256 -0
- package/dist/parse-add-remove-args.d.ts +28 -0
- package/dist/parse-add-remove-args.js +103 -0
- package/dist/print-err.d.ts +13 -0
- package/dist/print-err.js +193 -0
- package/dist/query-diff-files.d.ts +17 -0
- package/dist/query-diff-files.js +63 -0
- package/dist/query-host-contexts.d.ts +15 -0
- package/dist/query-host-contexts.js +136 -0
- package/dist/read-password.d.ts +7 -0
- package/dist/read-password.js +32 -0
- package/dist/read-project-folders.d.ts +17 -0
- package/dist/read-project-folders.js +100 -0
- package/dist/reload-config.d.ts +2 -0
- package/dist/reload-config.js +11 -0
- package/dist/render-mermaid.d.ts +22 -0
- package/dist/render-mermaid.js +68 -0
- package/dist/view.d.ts +29 -0
- package/dist/view.js +30 -0
- package/package.json +30 -30
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { runExec, runExecFG } from '@vltpkg/run';
|
|
2
|
+
import { commandUsage } from "../config/usage.js";
|
|
3
|
+
import { ExecCommand } from "../exec-command.js";
|
|
4
|
+
export { views } from "../exec-command.js";
|
|
5
|
+
export const usage = () => commandUsage({
|
|
6
|
+
command: 'run-exec',
|
|
7
|
+
usage: '[command ...]',
|
|
8
|
+
description: `If the first argument is a defined script in package.json, then this is
|
|
9
|
+
equivalent to \`vlt run\`.
|
|
10
|
+
|
|
11
|
+
If not, then this is equivalent to \`vlt exec\`.`,
|
|
12
|
+
options: {
|
|
13
|
+
scope: {
|
|
14
|
+
value: '<query>',
|
|
15
|
+
description: 'Filter execution targets using a DSS query.',
|
|
16
|
+
},
|
|
17
|
+
workspace: {
|
|
18
|
+
value: '<path|glob>',
|
|
19
|
+
description: 'Limit execution to matching workspace paths or globs.',
|
|
20
|
+
},
|
|
21
|
+
'workspace-group': {
|
|
22
|
+
value: '<name>',
|
|
23
|
+
description: 'Limit execution to named workspace groups.',
|
|
24
|
+
},
|
|
25
|
+
recursive: {
|
|
26
|
+
description: 'Run across all selected workspaces.',
|
|
27
|
+
},
|
|
28
|
+
'if-present': {
|
|
29
|
+
description: 'When running across multiple packages, only include packages with matching scripts.',
|
|
30
|
+
},
|
|
31
|
+
bail: {
|
|
32
|
+
description: 'When running across multiple workspaces, stop on first failure.',
|
|
33
|
+
},
|
|
34
|
+
'script-shell': {
|
|
35
|
+
value: '<program>',
|
|
36
|
+
description: 'Shell to use when executing package.json scripts.',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
export const command = async (conf) => await new ExecCommand(conf, runExec, runExecFG).run();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { run, runFG } from '@vltpkg/run';
|
|
2
|
+
import { commandUsage } from "../config/usage.js";
|
|
3
|
+
import { ExecCommand } from "../exec-command.js";
|
|
4
|
+
export { views } from "../exec-command.js";
|
|
5
|
+
export const usage = () => commandUsage({
|
|
6
|
+
command: 'run',
|
|
7
|
+
usage: '<script> [args ...]',
|
|
8
|
+
description: `Run a script defined in 'package.json', passing along any extra
|
|
9
|
+
arguments. Note that vlt config values must be specified *before*
|
|
10
|
+
the script name, because everything after that is handed off to
|
|
11
|
+
the script process.`,
|
|
12
|
+
options: {
|
|
13
|
+
scope: {
|
|
14
|
+
value: '<query>',
|
|
15
|
+
description: 'Filter execution targets using a DSS query.',
|
|
16
|
+
},
|
|
17
|
+
workspace: {
|
|
18
|
+
value: '<path|glob>',
|
|
19
|
+
description: 'Limit execution to matching workspace paths or globs.',
|
|
20
|
+
},
|
|
21
|
+
'workspace-group': {
|
|
22
|
+
value: '<name>',
|
|
23
|
+
description: 'Limit execution to named workspace groups.',
|
|
24
|
+
},
|
|
25
|
+
recursive: {
|
|
26
|
+
description: 'Run across all selected workspaces.',
|
|
27
|
+
},
|
|
28
|
+
'if-present': {
|
|
29
|
+
description: 'When running across multiple packages, only include packages with matching scripts.',
|
|
30
|
+
},
|
|
31
|
+
bail: {
|
|
32
|
+
description: 'When running across multiple workspaces, stop on first failure.',
|
|
33
|
+
},
|
|
34
|
+
'script-shell': {
|
|
35
|
+
value: '<program>',
|
|
36
|
+
description: 'Shell to use when executing package.json scripts.',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
class RunCommand extends ExecCommand {
|
|
41
|
+
constructor(conf) {
|
|
42
|
+
super(conf, run, runFG);
|
|
43
|
+
}
|
|
44
|
+
// do not provide the interactive shell arg, just do nothing
|
|
45
|
+
// so that it falls back up to the noArgsSingle() method
|
|
46
|
+
defaultArg0() { }
|
|
47
|
+
noArgsSingle() {
|
|
48
|
+
// called when there's no arg0, with a single workspace or root
|
|
49
|
+
const cwd = this.getCwd();
|
|
50
|
+
const { scripts = {} } = this.conf.options.packageJson.read(cwd);
|
|
51
|
+
return scripts;
|
|
52
|
+
}
|
|
53
|
+
noArgsMulti() {
|
|
54
|
+
const scripts = {};
|
|
55
|
+
for (const { label, manifest } of this.getTargets()) {
|
|
56
|
+
if (manifest.scripts)
|
|
57
|
+
scripts[label] = manifest.scripts;
|
|
58
|
+
}
|
|
59
|
+
return scripts;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const command = async (conf) => await new RunCommand(conf).run();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { deleteToken, setToken } from '@vltpkg/registry-client';
|
|
3
|
+
import { commandUsage } from "../config/usage.js";
|
|
4
|
+
import { readPassword } from "../read-password.js";
|
|
5
|
+
export const usage = () => commandUsage({
|
|
6
|
+
command: 'token',
|
|
7
|
+
usage: ['add', 'rm'],
|
|
8
|
+
description: `Explicitly add or remove tokens in the vlt keychain`,
|
|
9
|
+
options: {
|
|
10
|
+
registry: {
|
|
11
|
+
value: '<url>',
|
|
12
|
+
description: 'Registry URL to manage tokens for.',
|
|
13
|
+
},
|
|
14
|
+
identity: {
|
|
15
|
+
value: '<name>',
|
|
16
|
+
description: 'Identity namespace used to store auth tokens.',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
export const command = async (conf) => {
|
|
21
|
+
const reg = new URL(conf.options.registry).origin;
|
|
22
|
+
switch (conf.positionals[0]) {
|
|
23
|
+
case 'add': {
|
|
24
|
+
await setToken(reg, `Bearer ${await readPassword('Paste bearer token: ')}`, conf.options.identity);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 'rm': {
|
|
28
|
+
await deleteToken(reg, conf.options.identity);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
default: {
|
|
32
|
+
throw error('Invalid token subcommand', {
|
|
33
|
+
found: conf.positionals[0],
|
|
34
|
+
validOptions: ['add', 'rm'],
|
|
35
|
+
code: 'EUSAGE',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Graph } from '@vltpkg/graph';
|
|
2
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
3
|
+
import { InstallReporter } from './install/reporter.ts';
|
|
4
|
+
export type UninstallResult = {
|
|
5
|
+
/**
|
|
6
|
+
* The resulting graph structure at the end of an uninstall.
|
|
7
|
+
*/
|
|
8
|
+
graph: Graph;
|
|
9
|
+
};
|
|
10
|
+
export declare const usage: CommandUsage;
|
|
11
|
+
export declare const views: {
|
|
12
|
+
readonly json: (i: UninstallResult) => import("@vltpkg/graph").LockfileData;
|
|
13
|
+
readonly human: typeof InstallReporter;
|
|
14
|
+
};
|
|
15
|
+
export declare const command: CommandFn<UninstallResult>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { uninstall } from '@vltpkg/graph';
|
|
2
|
+
import { commandUsage } from "../config/usage.js";
|
|
3
|
+
import { parseRemoveArgs } from "../parse-add-remove-args.js";
|
|
4
|
+
import { InstallReporter } from "./install/reporter.js";
|
|
5
|
+
export const usage = () => commandUsage({
|
|
6
|
+
command: 'uninstall',
|
|
7
|
+
usage: '[package ...]',
|
|
8
|
+
description: `The opposite of \`vlt install\`. Removes deps and updates
|
|
9
|
+
vlt-lock.json and package.json appropriately.`,
|
|
10
|
+
options: {
|
|
11
|
+
workspace: {
|
|
12
|
+
value: '<path|glob>',
|
|
13
|
+
description: 'Limit uninstall targets to matching workspaces.',
|
|
14
|
+
},
|
|
15
|
+
'workspace-group': {
|
|
16
|
+
value: '<name>',
|
|
17
|
+
description: 'Limit uninstall targets to workspace groups.',
|
|
18
|
+
},
|
|
19
|
+
'allow-scripts': {
|
|
20
|
+
value: '<query>',
|
|
21
|
+
description: 'Filter which packages are allowed to run lifecycle scripts using DSS query syntax.',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
export const views = {
|
|
26
|
+
json: i => i.graph.toJSON(),
|
|
27
|
+
human: InstallReporter,
|
|
28
|
+
};
|
|
29
|
+
export const command = async (conf) => {
|
|
30
|
+
const { monorepo, scurry } = conf.options;
|
|
31
|
+
const { remove } = parseRemoveArgs(conf, scurry, monorepo);
|
|
32
|
+
/* c8 ignore start */
|
|
33
|
+
const allowScripts = conf.get('allow-scripts') ?
|
|
34
|
+
String(conf.get('allow-scripts'))
|
|
35
|
+
: ':not(*)';
|
|
36
|
+
/* c8 ignore stop */
|
|
37
|
+
const { graph } = await uninstall({ ...conf.options, allowScripts }, remove);
|
|
38
|
+
return { graph };
|
|
39
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
2
|
+
import { InstallReporter } from './install/reporter.ts';
|
|
3
|
+
import type { InstallResult } from './install.ts';
|
|
4
|
+
export declare const usage: CommandUsage;
|
|
5
|
+
export declare const views: {
|
|
6
|
+
readonly json: (i: InstallResult) => {
|
|
7
|
+
graph: import("@vltpkg/graph").LockfileData;
|
|
8
|
+
buildQueue?: import("@vltpkg/dep-id").DepID[] | undefined;
|
|
9
|
+
message?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
readonly human: typeof InstallReporter;
|
|
12
|
+
};
|
|
13
|
+
export declare const command: CommandFn<InstallResult>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { update } from '@vltpkg/graph';
|
|
2
|
+
import { error } from '@vltpkg/error-cause';
|
|
3
|
+
import { commandUsage } from "../config/usage.js";
|
|
4
|
+
import { InstallReporter } from "./install/reporter.js";
|
|
5
|
+
export const usage = () => commandUsage({
|
|
6
|
+
command: 'update',
|
|
7
|
+
usage: '',
|
|
8
|
+
description: `Update dependencies to their latest in-range versions.
|
|
9
|
+
Discards the lockfile and resolves dependencies from scratch.`,
|
|
10
|
+
options: {
|
|
11
|
+
'allow-scripts': {
|
|
12
|
+
value: '<query>',
|
|
13
|
+
description: 'Filter which packages are allowed to run lifecycle scripts using DSS query syntax.',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
export const views = {
|
|
18
|
+
json: i => ({
|
|
19
|
+
...(i.buildQueue?.length ?
|
|
20
|
+
{
|
|
21
|
+
buildQueue: i.buildQueue,
|
|
22
|
+
message: `${i.buildQueue.length} packages that will need to be built, run "vlt build" to complete the update.`,
|
|
23
|
+
}
|
|
24
|
+
: null),
|
|
25
|
+
graph: i.graph.toJSON(),
|
|
26
|
+
}),
|
|
27
|
+
human: InstallReporter,
|
|
28
|
+
};
|
|
29
|
+
export const command = async (conf) => {
|
|
30
|
+
// Throw error if any arguments are provided
|
|
31
|
+
if (conf.positionals.length > 0) {
|
|
32
|
+
throw error('Arguments are not yet supported for vlt update', {
|
|
33
|
+
code: 'EUSAGE',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/* c8 ignore start */
|
|
37
|
+
const allowScripts = conf.get('allow-scripts') ?
|
|
38
|
+
String(conf.get('allow-scripts'))
|
|
39
|
+
: ':not(*)';
|
|
40
|
+
/* c8 ignore stop */
|
|
41
|
+
const { buildQueue, graph } = await update({
|
|
42
|
+
...conf.options,
|
|
43
|
+
allowScripts,
|
|
44
|
+
});
|
|
45
|
+
return { buildQueue, graph };
|
|
46
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
2
|
+
export type VersionOptions = {
|
|
3
|
+
prereleaseId?: string;
|
|
4
|
+
commit?: boolean;
|
|
5
|
+
tag?: boolean;
|
|
6
|
+
message?: string;
|
|
7
|
+
tagMessage?: string;
|
|
8
|
+
includeNameInCommit?: boolean;
|
|
9
|
+
includeNameInTag?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type CommandResultSingle = {
|
|
12
|
+
name: string;
|
|
13
|
+
oldVersion: string;
|
|
14
|
+
newVersion: string;
|
|
15
|
+
dir: string;
|
|
16
|
+
committed?: string[];
|
|
17
|
+
tag?: string;
|
|
18
|
+
};
|
|
19
|
+
export type CommandResult = CommandResultSingle | CommandResultSingle[];
|
|
20
|
+
export declare const usage: CommandUsage;
|
|
21
|
+
export declare const views: {
|
|
22
|
+
readonly json: (result: CommandResult) => CommandResult;
|
|
23
|
+
readonly human: (results: CommandResult) => string;
|
|
24
|
+
};
|
|
25
|
+
export declare const command: CommandFn<CommandResult>;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { inc, parse as parseVersion, versionIncrements, } from '@vltpkg/semver';
|
|
2
|
+
import { is as isGit, spawn as spawn_, isClean } from '@vltpkg/git';
|
|
3
|
+
import { error } from '@vltpkg/error-cause';
|
|
4
|
+
import { asError } from '@vltpkg/types';
|
|
5
|
+
import { commandUsage } from "../config/usage.js";
|
|
6
|
+
import { dirname, resolve } from 'node:path';
|
|
7
|
+
import assert from 'node:assert';
|
|
8
|
+
import { actual } from '@vltpkg/graph';
|
|
9
|
+
import { Query } from '@vltpkg/query';
|
|
10
|
+
import { createHostContextsMap } from "../query-host-contexts.js";
|
|
11
|
+
import { minimatch } from 'minimatch';
|
|
12
|
+
const isValidVersionIncrement = (value) => versionIncrements.includes(value);
|
|
13
|
+
const version = async (conf, increment, cwd, {
|
|
14
|
+
// Hardcode happy path options for now.
|
|
15
|
+
// TODO: make these config definitions
|
|
16
|
+
prereleaseId = 'pre', commit = true, tag = true, message = 'v%s', tagMessage = 'v%s', includeNameInCommit = false, includeNameInTag = false, } = {}) => {
|
|
17
|
+
assert(increment, error('Version increment argument is required', {
|
|
18
|
+
code: 'EUSAGE',
|
|
19
|
+
validOptions: versionIncrements,
|
|
20
|
+
}));
|
|
21
|
+
const manifestPath = conf.options.packageJson.find(cwd);
|
|
22
|
+
assert(manifestPath, error('No package.json found', {
|
|
23
|
+
code: 'ENOENT',
|
|
24
|
+
path: cwd,
|
|
25
|
+
}));
|
|
26
|
+
const spawn = (args, opts) => spawn_(args, { cwd: manifestDir, ...opts });
|
|
27
|
+
const manifestDir = dirname(manifestPath);
|
|
28
|
+
const manifest = conf.options.packageJson.read(manifestDir);
|
|
29
|
+
assert(manifest.name, error('No name field found in package.json', {
|
|
30
|
+
path: manifestPath,
|
|
31
|
+
}));
|
|
32
|
+
assert(manifest.version, error('No version field found in package.json', {
|
|
33
|
+
path: manifestPath,
|
|
34
|
+
}));
|
|
35
|
+
const oldVersion = manifest.version;
|
|
36
|
+
let newVersion;
|
|
37
|
+
// Check if increment is a valid semver version string
|
|
38
|
+
const parsedIncrement = parseVersion(increment);
|
|
39
|
+
if (parsedIncrement) {
|
|
40
|
+
newVersion = parsedIncrement.toString();
|
|
41
|
+
}
|
|
42
|
+
else if (isValidVersionIncrement(increment)) {
|
|
43
|
+
// Use semver increment
|
|
44
|
+
const incrementType = increment;
|
|
45
|
+
try {
|
|
46
|
+
const result = inc(oldVersion, incrementType, prereleaseId);
|
|
47
|
+
newVersion = result.toString();
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
throw error(`Failed to increment version from ${oldVersion} with ${increment}`, { version: oldVersion, wanted: increment, cause: err });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw error(`Invalid version increment: ${increment}. Must be a valid semver version or one of: major, minor, patch, premajor, preminor, prepatch, prerelease`, {
|
|
55
|
+
found: increment,
|
|
56
|
+
validOptions: versionIncrements,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// Update the manifest
|
|
60
|
+
manifest.version = newVersion;
|
|
61
|
+
conf.options.packageJson.write(manifestDir, manifest);
|
|
62
|
+
const result = {
|
|
63
|
+
name: manifest.name,
|
|
64
|
+
oldVersion,
|
|
65
|
+
newVersion,
|
|
66
|
+
dir: manifestDir,
|
|
67
|
+
};
|
|
68
|
+
// Handle git operations if we're in a git repository
|
|
69
|
+
if (
|
|
70
|
+
/* c8 ignore next -- commit and tag are always true for now */
|
|
71
|
+
(commit || tag) &&
|
|
72
|
+
(await isGit({ cwd: conf.options.projectRoot }))) {
|
|
73
|
+
// Check for uncommitted changes (excluding package.json since we just modified it)
|
|
74
|
+
if (!(await isClean({ cwd: conf.options.projectRoot }))) {
|
|
75
|
+
try {
|
|
76
|
+
// Check if there are changes other than package.json
|
|
77
|
+
const gitResult = await spawn([
|
|
78
|
+
'diff',
|
|
79
|
+
'--name-only',
|
|
80
|
+
'HEAD',
|
|
81
|
+
'--',
|
|
82
|
+
'.',
|
|
83
|
+
]);
|
|
84
|
+
const changedFiles = gitResult.stdout
|
|
85
|
+
.trim()
|
|
86
|
+
.split('\n')
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
.map(f => resolve(conf.options.projectRoot, f));
|
|
89
|
+
const nonPackageJsonChanges = changedFiles.filter(file => file !== resolve(manifestDir, 'package.json'));
|
|
90
|
+
assert(nonPackageJsonChanges.length === 0, error('Git working directory not clean. Please commit or stash your changes first.', { found: nonPackageJsonChanges }));
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
throw error('Git working directory not clean. Please commit or stash your changes first.', asError(err));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (commit) {
|
|
97
|
+
try {
|
|
98
|
+
// Stage package.json
|
|
99
|
+
const files = ['package.json'];
|
|
100
|
+
await spawn(['add', ...files]);
|
|
101
|
+
await spawn([
|
|
102
|
+
'commit',
|
|
103
|
+
'-m',
|
|
104
|
+
`${includeNameInCommit ? `${manifest.name}: ` : ''}${message.replace('%s', newVersion)}`,
|
|
105
|
+
]);
|
|
106
|
+
result.committed = files.map(f => resolve(manifestDir, f));
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
throw error('Failed to commit version changes', {
|
|
110
|
+
version: newVersion,
|
|
111
|
+
cause: err,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (tag) {
|
|
116
|
+
try {
|
|
117
|
+
const tagName = (includeNameInTag ?
|
|
118
|
+
`${manifest.name.replace('/', '-').replace('@', '')}-`
|
|
119
|
+
: '') + `v${newVersion}`;
|
|
120
|
+
await spawn([
|
|
121
|
+
'tag',
|
|
122
|
+
tagName,
|
|
123
|
+
'-m',
|
|
124
|
+
(includeNameInTag ? `${manifest.name}: ` : '') +
|
|
125
|
+
tagMessage.replace('%s', newVersion),
|
|
126
|
+
]);
|
|
127
|
+
result.tag = tagName;
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
throw error('Failed to create git tag', {
|
|
131
|
+
version: newVersion,
|
|
132
|
+
cause: err,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
};
|
|
139
|
+
export const usage = () => {
|
|
140
|
+
return commandUsage({
|
|
141
|
+
command: 'version',
|
|
142
|
+
usage: '[<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease]',
|
|
143
|
+
description: `Bump a package's version.
|
|
144
|
+
|
|
145
|
+
Run in a package directory to bump the version and write the new data back to package.json.
|
|
146
|
+
|
|
147
|
+
The \`<newversion>\` argument should be a valid semver string or a valid increment type (one of patch, minor, major, prepatch, preminor, premajor, prerelease).
|
|
148
|
+
|
|
149
|
+
If run in a git repository, it will also create a version commit and tag.`,
|
|
150
|
+
options: {
|
|
151
|
+
scope: {
|
|
152
|
+
value: '<query>',
|
|
153
|
+
description: 'Filter version bump targets using a DSS query.',
|
|
154
|
+
},
|
|
155
|
+
workspace: {
|
|
156
|
+
value: '<path|glob>',
|
|
157
|
+
description: 'Limit version bump targets to matching workspaces.',
|
|
158
|
+
},
|
|
159
|
+
'workspace-group': {
|
|
160
|
+
value: '<name>',
|
|
161
|
+
description: 'Limit version bump targets to workspace groups.',
|
|
162
|
+
},
|
|
163
|
+
recursive: {
|
|
164
|
+
description: 'Run version bump across all workspaces in the monorepo.',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
export const views = {
|
|
170
|
+
json: result => result,
|
|
171
|
+
human: results => {
|
|
172
|
+
const item = (result) => {
|
|
173
|
+
let output = `${result.name}: v${result.newVersion}`;
|
|
174
|
+
if (result.committed) {
|
|
175
|
+
output += ` +commit`;
|
|
176
|
+
}
|
|
177
|
+
if (result.tag) {
|
|
178
|
+
output += ` +tag`;
|
|
179
|
+
}
|
|
180
|
+
return output;
|
|
181
|
+
};
|
|
182
|
+
return Array.isArray(results) ?
|
|
183
|
+
results.map(item).join('\n')
|
|
184
|
+
: item(results);
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
export const command = async (conf) => {
|
|
188
|
+
const { positionals, options, projectRoot } = conf;
|
|
189
|
+
const queryString = conf.get('scope');
|
|
190
|
+
const paths = conf.get('workspace');
|
|
191
|
+
const groups = conf.get('workspace-group');
|
|
192
|
+
const recursive = conf.get('recursive');
|
|
193
|
+
const locations = [];
|
|
194
|
+
if (queryString) {
|
|
195
|
+
const mainManifest = options.packageJson.maybeRead(projectRoot);
|
|
196
|
+
let graph;
|
|
197
|
+
if (mainManifest) {
|
|
198
|
+
graph = actual.load({
|
|
199
|
+
...options,
|
|
200
|
+
mainManifest,
|
|
201
|
+
monorepo: options.monorepo,
|
|
202
|
+
loadManifests: false,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const hostContexts = await createHostContextsMap(conf);
|
|
206
|
+
const query = new Query({
|
|
207
|
+
/* c8 ignore next */
|
|
208
|
+
nodes: graph ? new Set(graph.nodes.values()) : new Set(),
|
|
209
|
+
edges: graph?.edges ?? new Set(),
|
|
210
|
+
importers: graph?.importers ?? new Set(),
|
|
211
|
+
securityArchive: undefined,
|
|
212
|
+
hostContexts,
|
|
213
|
+
});
|
|
214
|
+
const { nodes } = await query.search(queryString, {
|
|
215
|
+
signal: new AbortController().signal,
|
|
216
|
+
});
|
|
217
|
+
for (const node of nodes) {
|
|
218
|
+
const location = node.location;
|
|
219
|
+
assert(location, error(`node ${node.id} has no location`, {
|
|
220
|
+
found: node,
|
|
221
|
+
}));
|
|
222
|
+
locations.push(resolve(node.projectRoot, location));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else if (paths?.length || groups?.length || recursive) {
|
|
226
|
+
for (const workspace of options.monorepo ?? []) {
|
|
227
|
+
if (paths?.length) {
|
|
228
|
+
const matches = paths.some((p) => workspace.path === p ||
|
|
229
|
+
workspace.name === p ||
|
|
230
|
+
workspace.fullpath === p ||
|
|
231
|
+
resolve(projectRoot, p) === workspace.fullpath ||
|
|
232
|
+
minimatch(workspace.path, p));
|
|
233
|
+
if (!matches)
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
locations.push(workspace.fullpath);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const cwd = options.packageJson.find(process.cwd()) ?? projectRoot;
|
|
241
|
+
return version(conf, positionals[0], cwd);
|
|
242
|
+
}
|
|
243
|
+
assert(locations.length > 0, error('No workspaces or query results found'));
|
|
244
|
+
const results = [];
|
|
245
|
+
for (const location of locations) {
|
|
246
|
+
results.push(await version(conf, positionals[0], location, {
|
|
247
|
+
includeNameInCommit: true,
|
|
248
|
+
includeNameInTag: true,
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
return results;
|
|
252
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Manifest, Packument } from '@vltpkg/types';
|
|
2
|
+
import type { PackageReportData } from '@vltpkg/security-archive';
|
|
3
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
4
|
+
import type { ViewOptions } from '../view.ts';
|
|
5
|
+
export declare const usage: CommandUsage;
|
|
6
|
+
export type ViewResult = {
|
|
7
|
+
/** The full packument data from the registry */
|
|
8
|
+
packument: Packument;
|
|
9
|
+
/** The resolved manifest for the requested version */
|
|
10
|
+
manifest: Manifest;
|
|
11
|
+
/** Security report data, if available */
|
|
12
|
+
security?: PackageReportData;
|
|
13
|
+
/** The specific field value if a field was requested */
|
|
14
|
+
fieldValue?: unknown;
|
|
15
|
+
/** The field path that was requested */
|
|
16
|
+
fieldPath?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const views: {
|
|
19
|
+
readonly human: (result: ViewResult, _options: ViewOptions, _conf: import("../config/index.ts").ParsedConfig) => string;
|
|
20
|
+
readonly json: (result: ViewResult, _options: ViewOptions, _conf: import("../config/index.ts").ParsedConfig) => unknown;
|
|
21
|
+
};
|
|
22
|
+
export declare const command: CommandFn<ViewResult>;
|