@oclif/plugin-update 4.3.6 → 4.4.1

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.1/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',
@@ -51,15 +54,22 @@ export default class UpdateCommand extends Command {
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/tar.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import makeDebug from 'debug';
2
+ import crypto from 'node:crypto';
2
3
  import { existsSync } from 'node:fs';
3
4
  import { rename, rm } from 'node:fs/promises';
4
5
  import { join } from 'node:path';
5
- import { touch } from './util.js';
6
- const debug = makeDebug('oclif-update');
7
- import crypto from 'node:crypto';
8
6
  import zlib from 'node:zlib';
9
7
  import { extract as tarExtract } from 'tar-fs';
8
+ import { touch } from './util.js';
9
+ const debug = makeDebug('oclif-update');
10
10
  const ignore = (_name, header) => {
11
11
  switch (header?.type) {
12
12
  case 'directory':
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) {
@@ -292,8 +292,8 @@ const fetchChannelManifest = async (channel, config) => {
292
292
  return await fetchManifest(s3Key, config);
293
293
  }
294
294
  catch (error) {
295
- const { statusCode } = error;
296
- if (statusCode === 403)
295
+ const { code, statusCode } = error;
296
+ if (statusCode === 403 || code === 'ERR_NON_2XX_3XX_RESPONSE')
297
297
  throw new Error(`HTTP 403: Invalid channel ${channel}`);
298
298
  throw error;
299
299
  }
@@ -324,7 +324,7 @@ const downloadAndExtract = async (output, manifest, channel, config) => {
324
324
  stream.on('downloadProgress', (progress) => {
325
325
  ux.action.status =
326
326
  progress.percent === 1
327
- ? `${filesize(progress.transferred)}/${filesize(progress.total)} - Extracting`
327
+ ? `${filesize(progress.transferred)}/${filesize(progress.total)} - Finishing up...`
328
328
  : `${filesize(progress.transferred)}/${filesize(progress.total)}`;
329
329
  });
330
330
  }
@@ -332,6 +332,7 @@ const downloadAndExtract = async (output, manifest, channel, config) => {
332
332
  await extraction;
333
333
  };
334
334
  const determineChannel = async ({ config, version }) => {
335
+ ux.action.status = `Determining channel for ${version}`;
335
336
  const channelPath = join(config.dataDir, 'channel');
336
337
  const channel = existsSync(channelPath) ? (await readFile(channelPath, 'utf8')).trim() : 'stable';
337
338
  if (config.pjson.oclif.update?.disableNpmLookup ?? false) {
@@ -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"
@@ -88,5 +96,5 @@
88
96
  ]
89
97
  }
90
98
  },
91
- "version": "4.3.6"
99
+ "version": "4.4.1"
92
100
  }
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.1",
4
4
  "author": "Salesforce",
5
5
  "bugs": "https://github.com/oclif/plugin-update/issues",
6
6
  "dependencies": {