@oclif/plugin-update 1.4.0-1 → 1.5.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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ## [1.5.0](https://github.com/oclif/plugin-update/compare/v1.4.0...v1.5.0) (2021-08-05)
6
+
7
+ ## [1.4.0](https://github.com/oclif/plugin-update/compare/v1.4.0-3...v1.4.0) (2021-08-05)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * allow 6 weeks before deleting CLIs ([#286](https://github.com/oclif/plugin-update/issues/286)) ([2ffc92a](https://github.com/oclif/plugin-update/commit/2ffc92a3687fd8e9ed939c59c6721d08ec7e6fa1))
13
+
1
14
  ## [1.3.9](https://github.com/oclif/plugin-update/compare/v1.3.8...v1.3.9) (2018-11-26)
2
15
 
3
16
 
package/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  [![Version](https://img.shields.io/npm/v/@oclif/plugin-update.svg)](https://npmjs.org/package/@oclif/plugin-update)
5
5
  [![CircleCI](https://circleci.com/gh/oclif/plugin-update/tree/master.svg?style=shield)](https://circleci.com/gh/oclif/plugin-update/tree/master)
6
6
  [![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/plugin-update?branch=master&svg=true)](https://ci.appveyor.com/project/oclif/plugin-update/branch/master)
7
- [![Codecov](https://codecov.io/gh/oclif/plugin-update/branch/master/graph/badge.svg)](https://codecov.io/gh/oclif/plugin-update)
8
7
  [![Downloads/week](https://img.shields.io/npm/dw/@oclif/plugin-update.svg)](https://npmjs.org/package/@oclif/plugin-update)
9
8
  [![License](https://img.shields.io/npm/l/@oclif/plugin-update.svg)](https://github.com/oclif/plugin-update/blob/master/package.json)
10
9
 
@@ -26,7 +25,10 @@ update the oclif-example CLI
26
25
  ```
27
26
  USAGE
28
27
  $ oclif-example update [CHANNEL]
28
+
29
+ OPTIONS
30
+ --from-local interactively choose an already installed version
29
31
  ```
30
32
 
31
- _See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/v1.4.0-1/src/commands/update.ts)_
33
+ _See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/v1.5.0/src/commands/update.ts)_
32
34
  <!-- commandsstop -->
@@ -14,7 +14,9 @@ export default class UpdateCommand extends Command {
14
14
  private readonly clientBin;
15
15
  run(): Promise<void>;
16
16
  private fetchManifest;
17
+ private downloadAndExtract;
17
18
  private update;
19
+ private updateToExistingVersion;
18
20
  private skipUpdate;
19
21
  private determineChannel;
20
22
  private determineCurrentVersion;
@@ -20,25 +20,48 @@ class UpdateCommand extends command_1.default {
20
20
  this.autoupdate = Boolean(flags.autoupdate);
21
21
  if (this.autoupdate)
22
22
  await this.debounce();
23
- cli_ux_1.default.action.start(`${this.config.name}: Updating CLI`);
24
23
  this.channel = args.channel || await this.determineChannel();
25
- await this.config.runHook('preupdate', { channel: this.channel });
26
- const manifest = await this.fetchManifest();
27
- this.currentVersion = await this.determineCurrentVersion();
28
- this.updatedVersion = manifest.sha ? `${manifest.version}-${manifest.sha}` : manifest.version;
29
- const reason = await this.skipUpdate();
30
- if (reason)
31
- cli_ux_1.default.action.stop(reason || 'done');
32
- else
33
- await this.update(manifest);
34
- this.debug('tidy');
35
- await this.tidy();
36
- await this.config.runHook('update', { channel: this.channel });
24
+ if (flags['from-local']) {
25
+ await this.ensureClientDir();
26
+ this.debug(`Looking for locally installed versions at ${this.clientRoot}`);
27
+ // Do not show known non-local version folder names, bin and current.
28
+ const versions = fs.readdirSync(this.clientRoot).filter(dirOrFile => dirOrFile !== 'bin' && dirOrFile !== 'current');
29
+ if (versions.length === 0)
30
+ throw new Error('No locally installed versions found.');
31
+ this.log(`Found versions: \n${versions.map(version => ` ${version}`).join('\n')}\n`);
32
+ const pinToVersion = await cli_ux_1.default.prompt('Enter a version to update to');
33
+ if (!versions.includes(pinToVersion))
34
+ throw new Error(`Version ${pinToVersion} not found in the locally installed versions.`);
35
+ if (!await fs.pathExists(path.join(this.clientRoot, pinToVersion))) {
36
+ throw new Error(`Version ${pinToVersion} is not already installed at ${this.clientRoot}.`);
37
+ }
38
+ cli_ux_1.default.action.start(`${this.config.name}: Updating CLI`);
39
+ this.debug(`switching to existing version ${pinToVersion}`);
40
+ this.updateToExistingVersion(pinToVersion);
41
+ this.log();
42
+ this.log(`Updating to an already installed version will not update the channel. If autoupdate is enabled, the CLI will eventually be updated back to ${this.channel}.`);
43
+ }
44
+ else {
45
+ cli_ux_1.default.action.start(`${this.config.name}: Updating CLI`);
46
+ await this.config.runHook('preupdate', { channel: this.channel });
47
+ const manifest = await this.fetchManifest();
48
+ this.currentVersion = await this.determineCurrentVersion();
49
+ this.updatedVersion = manifest.sha ? `${manifest.version}-${manifest.sha}` : manifest.version;
50
+ const reason = await this.skipUpdate();
51
+ if (reason)
52
+ cli_ux_1.default.action.stop(reason || 'done');
53
+ else
54
+ await this.update(manifest);
55
+ this.debug('tidy');
56
+ await this.tidy();
57
+ await this.config.runHook('update', { channel: this.channel });
58
+ }
37
59
  this.debug('done');
38
60
  cli_ux_1.default.action.stop();
39
61
  }
40
62
  async fetchManifest() {
41
63
  const http = require('http-call').HTTP;
64
+ cli_ux_1.default.action.status = 'fetching manifest';
42
65
  if (!this.config.scopedEnvVarTrue('USE_LEGACY_UPDATE')) {
43
66
  try {
44
67
  const newManifestUrl = this.config.s3Url(this.s3ChannelManifestKey(this.config.bin, this.config.platform, this.config.arch, this.config.pjson.oclif.update.s3.folder));
@@ -72,18 +95,13 @@ class UpdateCommand extends command_1.default {
72
95
  throw error;
73
96
  }
74
97
  }
75
- async update(manifest, channel = 'stable') {
76
- const { version, channel: manifestChannel } = manifest;
77
- if (manifestChannel)
78
- channel = manifestChannel;
79
- cli_ux_1.default.action.start(`${this.config.name}: Updating CLI from ${color_1.default.green(this.currentVersion)} to ${color_1.default.green(this.updatedVersion)}${channel === 'stable' ? '' : ' (' + color_1.default.yellow(channel) + ')'}`);
80
- const http = require('http-call').HTTP;
98
+ async downloadAndExtract(output, manifest, channel) {
99
+ const { version } = manifest;
81
100
  const filesize = (n) => {
82
101
  const [num, suffix] = require('filesize')(n, { output: 'array' });
83
102
  return num.toFixed(1) + ` ${suffix}`;
84
103
  };
85
- await this.ensureClientDir();
86
- const output = path.join(this.clientRoot, this.updatedVersion);
104
+ const http = require('http-call').HTTP;
87
105
  const gzUrl = manifest.gz || this.config.s3Url(this.config.s3Key('versioned', {
88
106
  version,
89
107
  channel,
@@ -117,11 +135,26 @@ class UpdateCommand extends command_1.default {
117
135
  }
118
136
  stream.resume();
119
137
  await extraction;
138
+ }
139
+ async update(manifest, channel = 'stable') {
140
+ const { channel: manifestChannel } = manifest;
141
+ if (manifestChannel)
142
+ channel = manifestChannel;
143
+ cli_ux_1.default.action.start(`${this.config.name}: Updating CLI from ${color_1.default.green(this.currentVersion)} to ${color_1.default.green(this.updatedVersion)}${channel === 'stable' ? '' : ' (' + color_1.default.yellow(channel) + ')'}`);
144
+ await this.ensureClientDir();
145
+ const output = path.join(this.clientRoot, this.updatedVersion);
146
+ if (!await fs.pathExists(output)) {
147
+ await this.downloadAndExtract(output, manifest, channel);
148
+ }
120
149
  await this.setChannel();
121
150
  await this.createBin(this.updatedVersion);
122
151
  await this.touch();
123
152
  await this.reexec();
124
153
  }
154
+ async updateToExistingVersion(version) {
155
+ await this.createBin(version);
156
+ await this.touch();
157
+ }
125
158
  async skipUpdate() {
126
159
  if (!this.config.binPath) {
127
160
  const instructions = this.config.scopedEnvVar('UPDATE_INSTRUCTIONS');
@@ -146,7 +179,7 @@ class UpdateCommand extends command_1.default {
146
179
  }
147
180
  async determineCurrentVersion() {
148
181
  try {
149
- const currentVersion = await fs.readlink(path.join(this.clientRoot, 'current'));
182
+ const currentVersion = await fs.readFile(this.clientBin, 'utf8');
150
183
  const matches = currentVersion.match(/\.\.[/|\\](.+)[/|\\]bin/);
151
184
  return matches ? matches[1] : this.config.version;
152
185
  }
@@ -210,7 +243,7 @@ class UpdateCommand extends command_1.default {
210
243
  if (['bin', 'current', this.config.version].includes(path.basename(f.path)))
211
244
  return;
212
245
  const mtime = f.stat.mtime;
213
- mtime.setHours(mtime.getHours() + (14 * 24));
246
+ mtime.setHours(mtime.getHours() + (42 * 24));
214
247
  if (mtime < new Date()) {
215
248
  await fs.remove(f.path);
216
249
  }
@@ -247,7 +280,8 @@ class UpdateCommand extends command_1.default {
247
280
  .on('error', reject)
248
281
  .on('close', (status) => {
249
282
  try {
250
- this.exit(status);
283
+ if (status > 0)
284
+ this.exit(status);
251
285
  }
252
286
  catch (error) {
253
287
  reject(error);
@@ -318,4 +352,5 @@ UpdateCommand.description = 'update the <%= config.bin %> CLI';
318
352
  UpdateCommand.args = [{ name: 'channel', optional: true }];
319
353
  UpdateCommand.flags = {
320
354
  autoupdate: command_1.flags.boolean({ hidden: true }),
355
+ 'from-local': command_1.flags.boolean({ description: 'interactively choose an already installed version' }),
321
356
  };
@@ -1 +1 @@
1
- {"version":"1.4.0-1","commands":{"update":{"id":"update","description":"update the <%= config.bin %> CLI","pluginName":"@oclif/plugin-update","pluginType":"core","aliases":[],"flags":{"autoupdate":{"name":"autoupdate","type":"boolean","hidden":true,"allowNo":false}},"args":[{"name":"channel"}]}}}
1
+ {"version":"1.5.0","commands":{"update":{"id":"update","description":"update the <%= config.bin %> CLI","pluginName":"@oclif/plugin-update","pluginType":"core","aliases":[],"flags":{"autoupdate":{"name":"autoupdate","type":"boolean","hidden":true,"allowNo":false},"from-local":{"name":"from-local","type":"boolean","description":"interactively choose an already installed version","allowNo":false}},"args":[{"name":"channel"}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oclif/plugin-update",
3
- "version": "1.4.0-1",
3
+ "version": "1.5.0",
4
4
  "author": "Jeff Dickey @jdxcode",
5
5
  "bugs": "https://github.com/oclif/plugin-update/issues",
6
6
  "dependencies": {
@@ -15,31 +15,31 @@
15
15
  "filesize": "^6.1.0",
16
16
  "fs-extra": "^9.0.1",
17
17
  "http-call": "^5.3.0",
18
- "lodash": "^4.17.20",
18
+ "lodash": "^4.17.21",
19
19
  "log-chopper": "^1.0.2",
20
- "semver": "^7.3.4",
20
+ "semver": "^7.3.5",
21
21
  "tar-fs": "^2.1.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@oclif/dev-cli": "^1.26.0",
25
25
  "@oclif/plugin-help": "^3",
26
26
  "@oclif/test": "^1.2.8",
27
- "@types/chai": "^4.2.14",
27
+ "@types/chai": "^4.2.15",
28
28
  "@types/cross-spawn": "^6.0.2",
29
29
  "@types/execa": "^0.9.0",
30
30
  "@types/fs-extra": "^8.0.1",
31
31
  "@types/glob": "^7.1.3",
32
32
  "@types/lodash": "^4.14.168",
33
- "@types/mocha": "^8.2.0",
34
- "@types/node": "^14.14.24",
33
+ "@types/mocha": "^8.2.2",
34
+ "@types/node": "^14.14.31",
35
35
  "@types/supports-color": "^7.2.0",
36
36
  "@types/write-json-file": "^3.2.1",
37
- "chai": "^4.2.0",
38
- "eslint": "^7.19.0",
37
+ "chai": "^4.3.4",
38
+ "eslint": "^7.21.0",
39
39
  "eslint-config-oclif": "^3.1.0",
40
40
  "eslint-config-oclif-typescript": "^0.2.0",
41
41
  "globby": "^11.0.2",
42
- "mocha": "^5.2.0",
42
+ "mocha": "^8.3.2",
43
43
  "qqjs": "^0.3.11",
44
44
  "ts-node": "^9.1.1",
45
45
  "tslib": "^2.1.0",