@oclif/plugin-update 4.3.6 → 4.4.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/README.md CHANGED
@@ -26,7 +26,7 @@ update the oclif-example CLI
26
26
 
27
27
  ```
28
28
  USAGE
29
- $ oclif-example update [CHANNEL] [-a] [--force] [-i | -v <value>]
29
+ $ oclif-example update [CHANNEL] [--force | | [-a | -v <value> | -i]]
30
30
 
31
31
  FLAGS
32
32
  -a, --available See available versions.
@@ -55,7 +55,7 @@ EXAMPLES
55
55
  $ oclif-example update --available
56
56
  ```
57
57
 
58
- _See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/v4.3.6/src/commands/update.ts)_
58
+ _See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/v4.4.0/src/commands/update.ts)_
59
59
  <!-- commandsstop -->
60
60
 
61
61
  # Contributing
@@ -1,7 +1,7 @@
1
- import { Command } from '@oclif/core';
1
+ import { Command, Interfaces } from '@oclif/core';
2
2
  export default class UpdateCommand extends Command {
3
3
  static args: {
4
- channel: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
4
+ channel: Interfaces.Arg<string | undefined, Record<string, unknown>>;
5
5
  };
6
6
  static description: string;
7
7
  static examples: {
@@ -9,11 +9,11 @@ export default class UpdateCommand extends Command {
9
9
  description: string;
10
10
  }[];
11
11
  static flags: {
12
- autoupdate: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
- available: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
- force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
- interactive: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
- version: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ autoupdate: Interfaces.BooleanFlag<boolean>;
13
+ available: Interfaces.BooleanFlag<boolean>;
14
+ force: Interfaces.BooleanFlag<boolean>;
15
+ interactive: Interfaces.BooleanFlag<boolean>;
16
+ version: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
17
17
  };
18
18
  run(): Promise<void>;
19
19
  }
@@ -1,5 +1,6 @@
1
1
  import select from '@inquirer/select';
2
2
  import { Args, Command, Flags, ux } from '@oclif/core';
3
+ import { got } from 'got';
3
4
  import { basename } from 'node:path';
4
5
  import { sort } from 'semver';
5
6
  import TtyTable from 'tty-table';
@@ -32,9 +33,11 @@ export default class UpdateCommand extends Command {
32
33
  available: Flags.boolean({
33
34
  char: 'a',
34
35
  description: 'See available versions.',
36
+ exclusive: ['version', 'interactive'],
35
37
  }),
36
38
  force: Flags.boolean({
37
39
  description: 'Force a re-download of the requested version.',
40
+ exclusive: ['interactive', 'available'],
38
41
  }),
39
42
  interactive: Flags.boolean({
40
43
  char: 'i',
@@ -44,22 +47,29 @@ export default class UpdateCommand extends Command {
44
47
  version: Flags.string({
45
48
  char: 'v',
46
49
  description: 'Install a specific version.',
47
- exclusive: ['interactive'],
50
+ exclusive: ['interactive', 'force'],
48
51
  }),
49
52
  };
50
53
  async run() {
51
54
  const { args, flags } = await this.parse(UpdateCommand);
52
55
  const updater = new Updater(this.config);
53
56
  if (flags.available) {
54
- const [index, localVersions] = await Promise.all([updater.fetchVersionIndex(), updater.findLocalVersions()]);
55
- // eslint-disable-next-line new-cap
56
- const t = TtyTable([
57
+ const { distTags, index, localVersions } = await lookupVersions(updater, this.config);
58
+ const headers = [
57
59
  { align: 'left', value: 'Location' },
58
60
  { align: 'left', value: 'Version' },
59
- ], sort(Object.keys(index))
61
+ ];
62
+ if (distTags) {
63
+ headers.push({ align: 'left', value: 'Channel' });
64
+ }
65
+ // eslint-disable-next-line new-cap
66
+ const t = TtyTable(headers, sort(Object.keys(index))
60
67
  .reverse()
61
68
  .map((version) => {
62
69
  const location = localVersions.find((l) => basename(l).startsWith(version)) || index[version];
70
+ if (distTags) {
71
+ return [location, version, distTags[version] ?? ''];
72
+ }
63
73
  return [location, version];
64
74
  }), { compact: true });
65
75
  ux.stdout(t.render());
@@ -72,14 +82,43 @@ export default class UpdateCommand extends Command {
72
82
  autoUpdate: flags.autoupdate,
73
83
  channel: args.channel,
74
84
  force: flags.force,
75
- version: flags.interactive ? await promptForVersion(updater) : flags.version,
85
+ version: flags.interactive ? await promptForVersion(updater, this.config) : flags.version,
76
86
  });
77
87
  }
78
88
  }
79
- const promptForVersion = async (updater) => select({
80
- choices: sort(Object.keys(await updater.fetchVersionIndex()))
81
- .reverse()
82
- .map((v) => ({ value: v })),
83
- loop: false,
84
- message: 'Select a version to update to',
85
- });
89
+ const lookupVersions = async (updater, config) => {
90
+ ux.action.start('Looking up versions');
91
+ const [index, localVersions, distTags] = await Promise.all([
92
+ updater.fetchVersionIndex(),
93
+ updater.findLocalVersions(),
94
+ fetchDistTags(config),
95
+ ]);
96
+ ux.action.stop(`Found ${Object.keys(index).length} versions`);
97
+ return {
98
+ distTags,
99
+ index,
100
+ localVersions,
101
+ };
102
+ };
103
+ const fetchDistTags = async (config) => {
104
+ const distTags = config.pjson.oclif.update?.disableNpmLookup
105
+ ? {}
106
+ : await got
107
+ .get(`${config.npmRegistry ?? 'https://registry.npmjs.org'}/${config.pjson.name}`)
108
+ .json()
109
+ .then((r) => r['dist-tags']);
110
+ // Invert the distTags object so we can look up the channel by version
111
+ return Object.fromEntries(Object.entries(distTags ?? {}).map(([k, v]) => [v, k]));
112
+ };
113
+ const displayName = (value, distTags) => `${value} ${distTags[value] ? `(${distTags[value]})` : ''}`;
114
+ const promptForVersion = async (updater, config) => {
115
+ const { distTags, index } = await lookupVersions(updater, config);
116
+ return select({
117
+ choices: sort(Object.keys(index))
118
+ .reverse()
119
+ .map((v) => ({ name: displayName(v, distTags), value: v })),
120
+ loop: false,
121
+ message: 'Select a version to update to',
122
+ pageSize: 10,
123
+ });
124
+ };
package/dist/update.js CHANGED
@@ -23,7 +23,6 @@ export class Updater {
23
23
  this.clientBin = join(this.clientRoot, 'bin', config.windows ? `${config.bin}.cmd` : config.bin);
24
24
  }
25
25
  async fetchVersionIndex() {
26
- ux.action.status = 'fetching version index';
27
26
  const newIndexUrl = this.config.s3Url(s3VersionIndexKey(this.config));
28
27
  try {
29
28
  const { body } = await got.get(newIndexUrl);
@@ -64,6 +63,7 @@ export class Updater {
64
63
  await this.updateToExistingVersion(current, localVersion);
65
64
  }
66
65
  else {
66
+ ux.action.status = 'fetching version index';
67
67
  const index = await this.fetchVersionIndex();
68
68
  const url = index[version];
69
69
  if (!url) {
@@ -36,12 +36,20 @@
36
36
  "available": {
37
37
  "char": "a",
38
38
  "description": "See available versions.",
39
+ "exclusive": [
40
+ "version",
41
+ "interactive"
42
+ ],
39
43
  "name": "available",
40
44
  "allowNo": false,
41
45
  "type": "boolean"
42
46
  },
43
47
  "force": {
44
48
  "description": "Force a re-download of the requested version.",
49
+ "exclusive": [
50
+ "interactive",
51
+ "available"
52
+ ],
45
53
  "name": "force",
46
54
  "allowNo": false,
47
55
  "type": "boolean"
@@ -60,7 +68,8 @@
60
68
  "char": "v",
61
69
  "description": "Install a specific version.",
62
70
  "exclusive": [
63
- "interactive"
71
+ "interactive",
72
+ "force"
64
73
  ],
65
74
  "name": "version",
66
75
  "hasDynamicHelp": false,
@@ -88,5 +97,5 @@
88
97
  ]
89
98
  }
90
99
  },
91
- "version": "4.3.6"
100
+ "version": "4.4.0"
92
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oclif/plugin-update",
3
- "version": "4.3.6",
3
+ "version": "4.4.0",
4
4
  "author": "Salesforce",
5
5
  "bugs": "https://github.com/oclif/plugin-update/issues",
6
6
  "dependencies": {