oclif 3.16.0 → 3.17.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.16.0",
2
+ "version": "3.17.1",
3
3
  "commands": {
4
4
  "generate": {
5
5
  "id": "generate",
@@ -8,6 +8,7 @@ export default class Manifest extends Command {
8
8
  jit: Interfaces.BooleanFlag<boolean>;
9
9
  };
10
10
  run(): Promise<void>;
11
- private cloneRepo;
11
+ private getVersion;
12
+ private getTarballUrl;
12
13
  private executeCommand;
13
14
  }
@@ -6,6 +6,11 @@ const path = require("path");
6
6
  const os = require("os");
7
7
  const semver = require("semver");
8
8
  const shelljs_1 = require("shelljs");
9
+ const got_1 = require("got");
10
+ const util_1 = require("util");
11
+ const stream_1 = require("stream");
12
+ const util_2 = require("../util");
13
+ const pipeline = (0, util_1.promisify)(stream_1.pipeline);
9
14
  async function fileExists(filePath) {
10
15
  try {
11
16
  await fs.access(filePath);
@@ -32,20 +37,26 @@ class Manifest extends core_1.Command {
32
37
  const tmpDir = os.tmpdir();
33
38
  const promises = Object.entries(packageJson.oclif.jitPlugins).map(async ([jitPlugin, version]) => {
34
39
  const pluginDir = jitPlugin.replace('/', '-').replace('@', '');
35
- const repo = this.executeCommand(`npm view ${jitPlugin}@latest repository --json`);
36
- const stdout = JSON.parse(repo.stdout);
37
- const repoUrl = stdout.url.replace(`${stdout.type}+`, '');
38
40
  const fullPath = path.join(tmpDir, pluginDir);
39
41
  if (await fileExists(fullPath))
40
42
  await fs.remove(fullPath);
41
- const versions = JSON.parse(this.executeCommand(`npm view ${jitPlugin}@latest versions --json`).stdout);
42
- const maxSatisfying = semver.maxSatisfying(versions, version);
43
- this.cloneRepo(repoUrl, fullPath, maxSatisfying);
44
- this.executeCommand('yarn --ignore-scripts', { cwd: fullPath });
45
- this.executeCommand('yarn tsc', { cwd: fullPath });
46
- const plugin = new core_1.Plugin({ root: fullPath, type: 'jit', ignoreManifest: true, errorOnManifestCreate: true });
47
- await plugin.load();
48
- return plugin.manifest;
43
+ await fs.mkdir(fullPath, { recursive: true });
44
+ const resolvedVersion = this.getVersion(jitPlugin, version);
45
+ const tarballUrl = this.getTarballUrl(jitPlugin, resolvedVersion);
46
+ const tarball = path.join(fullPath, path.basename(tarballUrl));
47
+ await pipeline(got_1.default.stream(tarballUrl), fs.createWriteStream(tarball));
48
+ if (process.platform === 'win32') {
49
+ await (0, util_2.checkFor7Zip)();
50
+ (0, shelljs_1.exec)(`7z x -bd -y "${tarball}"`, { cwd: fullPath });
51
+ }
52
+ else {
53
+ (0, shelljs_1.exec)(`tar -xzf "${tarball}"`, { cwd: fullPath });
54
+ }
55
+ const manifest = await fs.readJSON(path.join(fullPath, 'package', 'oclif.manifest.json'));
56
+ for (const command of Object.values(manifest.commands)) {
57
+ command.pluginType = 'jit';
58
+ }
59
+ return manifest;
49
60
  });
50
61
  core_1.ux.action.start('Generating JIT plugin manifests');
51
62
  jitPluginManifests = await Promise.all(promises);
@@ -72,18 +83,23 @@ class Manifest extends core_1.Command {
72
83
  fs.writeFileSync(file, JSON.stringify(plugin.manifest, null, 2));
73
84
  this.log(`wrote manifest to ${file}`);
74
85
  }
75
- cloneRepo(repoUrl, fullPath, tag) {
76
- try {
77
- this.executeCommand(`git clone --branch ${tag} ${repoUrl} ${fullPath} --depth 1`);
78
- }
79
- catch (_a) {
80
- try {
81
- this.executeCommand(`git clone --branch v${tag} ${repoUrl} ${fullPath} --depth 1`);
82
- }
83
- catch (_b) {
84
- throw new Error(`Unable to clone repo ${repoUrl} with tag ${tag}`);
85
- }
86
+ getVersion(plugin, version) {
87
+ var _a;
88
+ if (version.startsWith('^') || version.startsWith('~')) {
89
+ // Grab latest from npm to get all the versions so we can find the max satisfying version.
90
+ // We explicitly ask for latest since this command is typically run inside of `npm prepack`,
91
+ // which sets the npm_config_tag env var, which is used as the default anytime a tag isn't
92
+ // provided to `npm view`. This can be problematic if you're building the `nightly` version
93
+ // of a CLI and all the JIT plugins don't have a `nightly` tag themselves.
94
+ // TL;DR - always ask for latest to avoid potentially requesting a non-existent tag.
95
+ const { versions } = JSON.parse(this.executeCommand(`npm view ${plugin}@latest --json`).stdout);
96
+ return (_a = semver.maxSatisfying(versions, version)) !== null && _a !== void 0 ? _a : version.replace('^', '').replace('~', '');
86
97
  }
98
+ return version;
99
+ }
100
+ getTarballUrl(plugin, version) {
101
+ const { dist } = JSON.parse(this.executeCommand(`npm view ${plugin}@${version} --json`).stdout);
102
+ return dist.tarball;
87
103
  }
88
104
  executeCommand(command, options) {
89
105
  const debugString = (options === null || options === void 0 ? void 0 : options.cwd) ? `executing command: ${command} in ${options.cwd}` : `executing command: ${command}`;
@@ -1,29 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchNodeBinary = void 0;
4
- const core_1 = require("@oclif/core");
5
4
  const path = require("path");
6
5
  const fs = require("fs-extra");
7
- const node_stream_1 = require("node:stream");
6
+ const stream_1 = require("stream");
8
7
  const log_1 = require("../log");
9
- const node_child_process_1 = require("node:child_process");
10
- const node_util_1 = require("node:util");
8
+ const child_process_1 = require("child_process");
9
+ const util_1 = require("util");
11
10
  const got_1 = require("got");
12
11
  const retry = require("async-retry");
13
- const pipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
14
- const exec = (0, node_util_1.promisify)(node_child_process_1.exec);
12
+ const util_2 = require("../util");
13
+ const pipeline = (0, util_1.promisify)(stream_1.pipeline);
14
+ const exec = (0, util_1.promisify)(child_process_1.exec);
15
15
  const RETRY_TIMEOUT_MS = 1000;
16
- async function checkFor7Zip() {
17
- try {
18
- await exec('7z');
19
- }
20
- catch (error) {
21
- if (error.code === 127)
22
- core_1.Errors.error('install 7-zip to package windows tarball');
23
- else
24
- throw error;
25
- }
26
- }
27
16
  async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
28
17
  if (arch === 'arm')
29
18
  arch = 'armv7l';
@@ -31,7 +20,7 @@ async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
31
20
  let tarball = path.join(tmp, 'node', `${nodeBase}.tar.xz`);
32
21
  let url = `https://nodejs.org/dist/v${nodeVersion}/${nodeBase}.tar.xz`;
33
22
  if (platform === 'win32') {
34
- await checkFor7Zip();
23
+ await (0, util_2.checkFor7Zip)();
35
24
  nodeBase = `node-v${nodeVersion}-win-${arch}`;
36
25
  tarball = path.join(tmp, 'node', `${nodeBase}.7z`);
37
26
  url = `https://nodejs.org/dist/v${nodeVersion}/${nodeBase}.7z`;
package/lib/util.d.ts CHANGED
@@ -12,4 +12,5 @@ interface VersionsObject {
12
12
  export declare const sortVersionsObjectByKeysDesc: (input: VersionsObject) => VersionsObject;
13
13
  export declare const prettifyPaths: (input: string) => string;
14
14
  export declare const hash: (algo: string, fp: string | string[]) => Promise<string>;
15
+ export declare function checkFor7Zip(): Promise<void>;
15
16
  export {};
package/lib/util.js CHANGED
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hash = exports.prettifyPaths = exports.sortVersionsObjectByKeysDesc = exports.template = exports.sortBy = exports.compact = exports.uniqBy = exports.castArray = void 0;
3
+ exports.checkFor7Zip = exports.hash = exports.prettifyPaths = exports.sortVersionsObjectByKeysDesc = exports.template = exports.sortBy = exports.compact = exports.uniqBy = exports.castArray = void 0;
4
+ const core_1 = require("@oclif/core");
4
5
  const _ = require("lodash");
5
6
  const os = require("os");
6
- const crypto = require("node:crypto");
7
+ const crypto = require("crypto");
7
8
  const log_1 = require("./log");
8
9
  const fs = require("fs-extra");
10
+ const child_process_1 = require("child_process");
11
+ const util_1 = require("util");
12
+ const exec = (0, util_1.promisify)(child_process_1.exec);
9
13
  function castArray(input) {
10
14
  if (input === undefined)
11
15
  return [];
@@ -91,3 +95,15 @@ const hash = async (algo, fp) => {
91
95
  });
92
96
  };
93
97
  exports.hash = hash;
98
+ async function checkFor7Zip() {
99
+ try {
100
+ await exec('7z');
101
+ }
102
+ catch (error) {
103
+ if (error.code === 127)
104
+ core_1.Errors.error('install 7-zip to package windows tarball');
105
+ else
106
+ throw error;
107
+ }
108
+ }
109
+ exports.checkFor7Zip = checkFor7Zip;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oclif",
3
3
  "description": "oclif: create your own CLI",
4
- "version": "3.16.0",
4
+ "version": "3.17.1",
5
5
  "author": "Salesforce",
6
6
  "bin": {
7
7
  "oclif": "bin/run"
@@ -128,7 +128,7 @@
128
128
  "posttest": "yarn run lint",
129
129
  "prepack": "shx rm -rf lib && tsc && bin/dev manifest .",
130
130
  "test": "nps test && yarn test:unit && yarn test:integration",
131
- "test:integration": "mocha --forbid-only \"test/integration/*.test.ts\"",
131
+ "test:integration": "mocha --forbid-only \"test/integration/*.test.ts\" --timeout 600000",
132
132
  "test:unit": "mocha --forbid-only \"test/unit/*.test.ts\"",
133
133
  "version": "bin/dev readme && git add README.md"
134
134
  },