oclif 3.3.1 → 3.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.
@@ -2,76 +2,74 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = void 0;
4
4
  const findYarnWorkspaceRoot = require("find-yarn-workspace-root");
5
- const path = require("path");
6
- const qq = require("qqjs");
7
5
  const log_1 = require("../log");
6
+ const path = require("path");
7
+ const fs = require("fs-extra");
8
8
  const bin_1 = require("./bin");
9
9
  const node_1 = require("./node");
10
10
  const upload_util_1 = require("../upload-util");
11
+ const util_1 = require("../util");
12
+ const child_process_1 = require("child_process");
13
+ const node_util_1 = require("node:util");
14
+ const exec = (0, node_util_1.promisify)(child_process_1.exec);
11
15
  const pack = async (from, to) => {
12
- const prevCwd = qq.cwd();
13
- qq.cd(path.dirname(from));
14
- await qq.mkdirp(path.dirname(to));
15
- (0, log_1.log)(`packing tarball from ${qq.prettifyPaths(from)} to ${qq.prettifyPaths(to)}`);
16
- await (to.endsWith('gz') ?
17
- qq.x('tar', ['czf', to, path.basename(from)]) :
18
- qq.x(`tar c "${path.basename(from)}" | xz > "${to}"`));
19
- qq.cd(prevCwd);
16
+ const cwd = path.dirname(from);
17
+ await fs.promises.mkdir(path.dirname(to), { recursive: true });
18
+ (0, log_1.log)(`packing tarball from ${(0, util_1.prettifyPaths)(path.dirname(from))} to ${(0, util_1.prettifyPaths)(to)}`);
19
+ (to.endsWith('gz') ?
20
+ await exec(`tar czf ${to} ${(path.basename(from))}`, { cwd }) :
21
+ await exec(`tar cfJ ${to} ${(path.basename(from))}`, { cwd }));
20
22
  };
21
23
  async function build(c, options = {}) {
22
24
  const { xz, config } = c;
23
- const prevCwd = qq.cwd();
24
25
  const packCLI = async () => {
25
- const stdout = await qq.x.stdout('npm', ['pack', '--unsafe-perm'], { cwd: c.root });
26
- return path.join(c.root, stdout.split('\n').pop());
26
+ const { stdout } = await exec('npm pack --unsafe-perm', { cwd: c.root });
27
+ return path.join(c.root, stdout.trim().split('\n').pop());
27
28
  };
28
29
  const extractCLI = async (tarball) => {
29
- await qq.emptyDir(c.workspace());
30
- await qq.mv(tarball, c.workspace());
31
- tarball = path.basename(tarball);
32
- tarball = qq.join([c.workspace(), tarball]);
33
- qq.cd(c.workspace());
34
- await qq.x(`tar -xzf "${tarball}"`);
35
- // eslint-disable-next-line no-await-in-loop
36
- for (const f of await qq.ls('package', { fullpath: true }))
37
- await qq.mv(f, '.');
38
- await qq.rm('package', tarball, 'bin/run.cmd');
30
+ await fs.emptyDir(c.workspace());
31
+ const tarballNewLocation = path.join(c.workspace(), path.basename(tarball));
32
+ await fs.move(tarball, tarballNewLocation);
33
+ await exec(`tar -xzf "${tarballNewLocation}"`, { cwd: c.workspace() });
34
+ await Promise.all((await fs.promises.readdir(path.join(c.workspace(), 'package'), { withFileTypes: true }))
35
+ .map(i => fs.move(path.join(c.workspace(), 'package', i.name), path.join(c.workspace(), i.name))));
36
+ await Promise.all([
37
+ fs.promises.rm(path.join(c.workspace(), 'package'), { recursive: true }),
38
+ fs.promises.rm(path.join(c.workspace(), path.basename(tarball)), { recursive: true }),
39
+ fs.remove(path.join(c.workspace(), 'bin', 'run.cmd')),
40
+ ]);
39
41
  };
40
42
  const updatePJSON = async () => {
41
- qq.cd(c.workspace());
42
- const pjson = await qq.readJSON('package.json');
43
+ const pjsonPath = path.join(c.workspace(), 'package.json');
44
+ const pjson = await fs.readJSON(pjsonPath);
43
45
  pjson.version = config.version;
44
46
  pjson.oclif.update = pjson.oclif.update || {};
45
47
  pjson.oclif.update.s3 = pjson.oclif.update.s3 || {};
46
48
  pjson.oclif.update.s3.bucket = c.s3Config.bucket;
47
- await qq.writeJSON('package.json', pjson);
49
+ await fs.writeJSON(pjsonPath, pjson);
48
50
  };
49
51
  const addDependencies = async () => {
50
- qq.cd(c.workspace());
51
52
  const yarnRoot = findYarnWorkspaceRoot(c.root) || c.root;
52
- const yarn = await qq.exists([yarnRoot, 'yarn.lock']);
53
- if (yarn) {
54
- await qq.cp([yarnRoot, 'yarn.lock'], '.');
55
- await qq.x('yarn --no-progress --production --non-interactive');
53
+ if (fs.existsSync(path.join(yarnRoot, 'yarn.lock'))) {
54
+ await fs.copy(path.join(yarnRoot, 'yarn.lock'), path.join(c.workspace(), 'yarn.lock'));
55
+ await exec('yarn --no-progress --production --non-interactive', { cwd: c.workspace() });
56
56
  }
57
57
  else {
58
- let lockpath = qq.join(c.root, 'package-lock.json');
59
- if (!await qq.exists(lockpath)) {
60
- lockpath = qq.join(c.root, 'npm-shrinkwrap.json');
61
- }
62
- await qq.cp(lockpath, '.');
63
- await qq.x('npm install --production');
58
+ const lockpath = fs.existsSync(path.join(c.root, 'package-lock.json')) ?
59
+ path.join(c.root, 'package-lock.json') :
60
+ path.join(c.root, 'npm-shrinkwrap.json');
61
+ await fs.copy(lockpath, path.join(c.workspace(), path.basename(lockpath)));
62
+ await exec('npm install --production', { cwd: c.workspace() });
64
63
  }
65
64
  };
66
65
  const pretarball = async () => {
67
- qq.cd(c.workspace());
68
- const pjson = await qq.readJSON('package.json');
66
+ const pjson = await fs.readJSON(path.join(c.workspace(), 'package.json'));
69
67
  const yarnRoot = findYarnWorkspaceRoot(c.root) || c.root;
70
- const yarn = await qq.exists([yarnRoot, 'yarn.lock']);
68
+ const yarn = fs.existsSync(path.join(yarnRoot, 'yarn.lock'));
71
69
  if (pjson.scripts.pretarball) {
72
70
  yarn ?
73
- await qq.x('yarn run pretarball') :
74
- await qq.x('npm run pretarball', {});
71
+ await exec('yarn run pretarball', { cwd: c.workspace() }) :
72
+ await exec('npm run pretarball', { cwd: c.workspace() });
75
73
  }
76
74
  };
77
75
  const buildTarget = async (target) => {
@@ -93,14 +91,14 @@ async function build(c, options = {}) {
93
91
  const base = path.basename(gzLocalKey);
94
92
  (0, log_1.log)(`building target ${base}`);
95
93
  (0, log_1.log)('copying workspace', c.workspace(), workspace);
96
- await qq.rm(workspace);
97
- await qq.cp(c.workspace(), workspace);
94
+ await fs.emptyDir(workspace);
95
+ await fs.copy(c.workspace(), workspace);
98
96
  await (0, node_1.fetchNodeBinary)({
99
97
  nodeVersion: c.nodeVersion,
100
98
  output: path.join(workspace, 'bin', 'node'),
101
99
  platform: target.platform,
102
100
  arch: target.arch,
103
- tmp: qq.join(config.root, 'tmp'),
101
+ tmp: path.join(config.root, 'tmp'),
104
102
  });
105
103
  if (options.pack === false)
106
104
  return;
@@ -118,6 +116,7 @@ async function build(c, options = {}) {
118
116
  const rollout = (typeof c.updateConfig.autoupdate === 'object' && c.updateConfig.autoupdate.rollout);
119
117
  const gzCloudKey = `${(0, upload_util_1.commitAWSDir)(config.version, c.gitSha, c.updateConfig.s3)}/${gzLocalKey}`;
120
118
  const xzCloudKey = `${(0, upload_util_1.commitAWSDir)(config.version, c.gitSha, c.updateConfig.s3)}/${xzLocalKey}`;
119
+ const [sha256gz, sha256xz] = await Promise.all([(0, util_1.hash)('sha256', c.dist(gzLocalKey))].concat(xz ? [(0, util_1.hash)('sha256', c.dist(xzLocalKey))] : []));
121
120
  const manifest = {
122
121
  rollout: rollout === false ? undefined : rollout,
123
122
  version: config.version,
@@ -125,8 +124,8 @@ async function build(c, options = {}) {
125
124
  baseDir: (0, upload_util_1.templateShortKey)('baseDir', target, { bin: c.config.bin }),
126
125
  gz: config.s3Url(gzCloudKey),
127
126
  xz: xz ? config.s3Url(xzCloudKey) : undefined,
128
- sha256gz: await qq.hash('sha256', c.dist(gzLocalKey)),
129
- sha256xz: xz ? await qq.hash('sha256', c.dist(xzLocalKey)) : undefined,
127
+ sha256gz,
128
+ sha256xz,
130
129
  node: {
131
130
  compatible: config.pjson.engines.node,
132
131
  recommended: c.nodeVersion,
@@ -139,7 +138,7 @@ async function build(c, options = {}) {
139
138
  sha: c.gitSha,
140
139
  version: config.version,
141
140
  }));
142
- await qq.writeJSON(manifestFilepath, manifest);
141
+ await fs.writeJSON(manifestFilepath, manifest);
143
142
  };
144
143
  (0, log_1.log)(`gathering workspace for ${config.bin} to ${c.workspace()}`);
145
144
  await extractCLI(options.tarball ? options.tarball : await packCLI());
@@ -158,7 +157,7 @@ async function build(c, options = {}) {
158
157
  // eslint-disable-next-line no-await-in-loop
159
158
  await buildTarget(target);
160
159
  }
160
+ (0, log_1.log)(`finished building ${targetsToBuild.length} targets sequentially`);
161
161
  }
162
- qq.cd(prevCwd);
163
162
  }
164
163
  exports.build = build;
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildConfig = exports.gitSha = exports.TARGETS = void 0;
4
4
  const core_1 = require("@oclif/core");
5
5
  const path = require("path");
6
- const qq = require("qqjs");
7
6
  const semver = require("semver");
7
+ const fs = require("fs-extra");
8
8
  const util_1 = require("../util");
9
9
  const upload_util_1 = require("../upload-util");
10
+ const child_process_1 = require("child_process");
11
+ const node_util_1 = require("node:util");
12
+ const exec = (0, node_util_1.promisify)(child_process_1.exec);
10
13
  exports.TARGETS = [
11
14
  'linux-x64',
12
15
  'linux-arm',
@@ -17,12 +20,12 @@ exports.TARGETS = [
17
20
  ];
18
21
  async function gitSha(cwd, options = {}) {
19
22
  const args = options.short ? ['rev-parse', '--short', 'HEAD'] : ['rev-parse', 'HEAD'];
20
- return qq.x.stdout('git', args, { cwd });
23
+ return (await exec(`git ${args.join(' ')}`, { cwd })).stdout.trim();
21
24
  }
22
25
  exports.gitSha = gitSha;
23
26
  async function Tmp(config) {
24
27
  const tmp = path.join(config.root, 'tmp');
25
- await qq.mkdirp(tmp);
28
+ await fs.promises.mkdir(tmp, { recursive: true });
26
29
  return tmp;
27
30
  }
28
31
  async function buildConfig(root, options = {}) {
@@ -58,10 +61,10 @@ async function buildConfig(root, options = {}) {
58
61
  s3Config: updateConfig.s3,
59
62
  nodeVersion,
60
63
  workspace(target) {
61
- const base = qq.join(config.root, 'tmp');
64
+ const base = path.join(config.root, 'tmp');
62
65
  if (target && target.platform)
63
- return qq.join(base, [target.platform, target.arch].join('-'), (0, upload_util_1.templateShortKey)('baseDir', { bin: config.bin }));
64
- return qq.join(base, (0, upload_util_1.templateShortKey)('baseDir', { bin: config.bin }));
66
+ return path.join(base, [target.platform, target.arch].join('-'), (0, upload_util_1.templateShortKey)('baseDir', { bin: config.bin }));
67
+ return path.join(base, (0, upload_util_1.templateShortKey)('baseDir', { bin: config.bin }));
65
68
  },
66
69
  targets,
67
70
  };
@@ -3,11 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchNodeBinary = void 0;
4
4
  const core_1 = require("@oclif/core");
5
5
  const path = require("path");
6
- const qq = require("qqjs");
6
+ const fs = require("fs-extra");
7
+ const node_stream_1 = require("node:stream");
7
8
  const log_1 = require("../log");
9
+ const node_child_process_1 = require("node:child_process");
10
+ const node_util_1 = require("node:util");
11
+ const got_1 = require("got");
12
+ const pipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
13
+ const exec = (0, node_util_1.promisify)(node_child_process_1.exec);
8
14
  async function checkFor7Zip() {
9
15
  try {
10
- await qq.x('7z', { stdio: [0, null, 2] });
16
+ await exec('7z');
11
17
  }
12
18
  catch (error) {
13
19
  if (error.code === 127)
@@ -34,38 +40,42 @@ async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
34
40
  cache += '.exe';
35
41
  const download = async () => {
36
42
  (0, log_1.log)(`downloading ${nodeBase}`);
43
+ await Promise.all([
44
+ fs.ensureDir(path.join(tmp, 'cache', nodeVersion)),
45
+ fs.ensureDir(path.join(tmp, 'node')),
46
+ ]);
37
47
  const shasums = path.join(tmp, 'cache', nodeVersion, 'SHASUMS256.txt.asc');
38
- if (!await qq.exists(shasums)) {
39
- await qq.download(`https://nodejs.org/dist/v${nodeVersion}/SHASUMS256.txt.asc`, shasums);
48
+ if (!fs.existsSync(shasums)) {
49
+ await pipeline(got_1.default.stream(`https://nodejs.org/dist/v${nodeVersion}/SHASUMS256.txt.asc`), fs.createWriteStream(shasums));
40
50
  }
41
51
  const basedir = path.dirname(tarball);
42
- await qq.mkdirp(basedir);
43
- await qq.download(url, tarball);
52
+ await fs.promises.mkdir(basedir, { recursive: true });
53
+ await pipeline(got_1.default.stream(url), fs.createWriteStream(tarball));
44
54
  if (platform !== 'win32')
45
- await qq.x(`grep "${path.basename(tarball)}" "${shasums}" | shasum -a 256 -c -`, { cwd: basedir });
55
+ await exec(`grep "${path.basename(tarball)}" "${shasums}" | shasum -a 256 -c -`, { cwd: basedir });
46
56
  };
47
57
  const extract = async () => {
48
58
  (0, log_1.log)(`extracting ${nodeBase}`);
49
59
  const nodeTmp = path.join(tmp, 'node');
50
- await qq.mkdirp(nodeTmp);
51
- await qq.mkdirp(path.dirname(cache));
60
+ await fs.promises.mkdir(nodeTmp, { recursive: true });
61
+ await fs.promises.mkdir(path.dirname(cache), { recursive: true });
52
62
  if (platform === 'win32') {
53
- await qq.x(`7z x -bd -y "${tarball}"`, { cwd: nodeTmp });
54
- await qq.mv([nodeTmp, nodeBase, 'node.exe'], cache);
63
+ await exec(`7z x -bd -y "${tarball}"`, { cwd: nodeTmp });
64
+ await fs.move(path.join(nodeTmp, nodeBase, 'node.exe'), path.join(cache, 'node.exe'));
55
65
  }
56
66
  else {
57
- await qq.x(`tar -C "${tmp}/node" -xJf "${tarball}"`);
58
- await qq.mv([nodeTmp, nodeBase, 'bin/node'], cache);
67
+ await exec(`tar -C "${tmp}/node" -xJf "${tarball}"`);
68
+ await fs.move(path.join(nodeTmp, nodeBase, 'bin', 'node'), path.join(cache, 'node'));
59
69
  }
60
70
  };
61
- if (await qq.exists(cache)) {
62
- await qq.cp(cache, output);
63
- }
64
- else {
71
+ if (!fs.existsSync(cache)) {
65
72
  await download();
66
73
  await extract();
67
- await qq.cp(cache, output);
68
74
  }
75
+ await fs.copy(path.join(cache, getFilename(platform)), output);
69
76
  return output;
70
77
  }
71
78
  exports.fetchNodeBinary = fetchNodeBinary;
79
+ const getFilename = (platform) => {
80
+ return platform === 'win32' ? 'node.exe' : 'node';
81
+ };
package/lib/util.d.ts CHANGED
@@ -10,4 +10,6 @@ interface VersionsObject {
10
10
  [key: string]: string;
11
11
  }
12
12
  export declare const sortVersionsObjectByKeysDesc: (input: VersionsObject) => VersionsObject;
13
+ export declare const prettifyPaths: (input: string) => string;
14
+ export declare const hash: (algo: string, fp: string | string[]) => Promise<string>;
13
15
  export {};
package/lib/util.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortVersionsObjectByKeysDesc = exports.template = exports.sortBy = exports.compact = exports.uniqBy = exports.castArray = void 0;
3
+ exports.hash = exports.prettifyPaths = exports.sortVersionsObjectByKeysDesc = exports.template = exports.sortBy = exports.compact = exports.uniqBy = exports.castArray = void 0;
4
4
  const _ = require("lodash");
5
+ const os = require("os");
6
+ const crypto = require("node:crypto");
7
+ const log_1 = require("./log");
8
+ const fs = require("fs-extra");
5
9
  function castArray(input) {
6
10
  if (input === undefined)
7
11
  return [];
@@ -71,3 +75,19 @@ const sortVersionsObjectByKeysDesc = (input) => {
71
75
  return result;
72
76
  };
73
77
  exports.sortVersionsObjectByKeysDesc = sortVersionsObjectByKeysDesc;
78
+ const homeRegexp = new RegExp(`\\B${os.homedir().replace('/', '\\/')}`, 'g');
79
+ const curRegexp = new RegExp(`\\B${process.cwd()}`, 'g');
80
+ const prettifyPaths = (input) => (input !== null && input !== void 0 ? input : '').toString().replace(curRegexp, '.').replace(homeRegexp, '~');
81
+ exports.prettifyPaths = prettifyPaths;
82
+ const hash = async (algo, fp) => {
83
+ const f = Array.isArray(fp) ? fp.join('') : fp;
84
+ (0, log_1.log)('hash', algo, f);
85
+ return new Promise((resolve, reject) => {
86
+ const hashInProgress = crypto.createHash(algo);
87
+ const stream = fs.createReadStream(f);
88
+ stream.on('error', err => reject(err));
89
+ stream.on('data', chunk => hashInProgress.update(chunk));
90
+ stream.on('end', () => resolve(hashInProgress.digest('hex')));
91
+ });
92
+ };
93
+ exports.hash = hash;
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.3.1",
4
+ "version": "3.4.0",
5
5
  "author": "Salesforce",
6
6
  "bin": {
7
7
  "oclif": "bin/run"
@@ -18,9 +18,9 @@
18
18
  "find-yarn-workspace-root": "^2.0.0",
19
19
  "fs-extra": "^8.1",
20
20
  "github-slugger": "^1.5.0",
21
+ "got": "^11",
21
22
  "lodash": "^4.17.21",
22
23
  "normalize-package-data": "^3.0.3",
23
- "qqjs": "^0.3.11",
24
24
  "semver": "^7.3.8",
25
25
  "tslib": "^2.3.1",
26
26
  "yeoman-environment": "^3.11.1",
@@ -33,10 +33,10 @@
33
33
  "@types/chai": "^4.3.4",
34
34
  "@types/execa": "^0.9.0",
35
35
  "@types/fs-extra": "^9.0",
36
- "@types/lodash": "^4.14.186",
36
+ "@types/lodash": "^4.14.191",
37
37
  "@types/lodash.template": "^4.5.0",
38
38
  "@types/mocha": "^8.2.3",
39
- "@types/node": "^14.18.33",
39
+ "@types/node": "^14.18.34",
40
40
  "@types/read-pkg": "^5.1.0",
41
41
  "@types/semver": "^7.3.13",
42
42
  "@types/shelljs": "^0.8.11",
@@ -62,12 +62,10 @@
62
62
  "typescript": "4.5.5"
63
63
  },
64
64
  "resolutions": {
65
- "colors": "1.4.0",
66
- "@oclif/core": "^1.16.1"
65
+ "colors": "1.4.0"
67
66
  },
68
67
  "overrides": {
69
- "colors": "1.4.0",
70
- "@oclif/core": "^1.16.1"
68
+ "colors": "1.4.0"
71
69
  },
72
70
  "engines": {
73
71
  "node": ">=12.0.0"
@@ -103,7 +101,7 @@
103
101
  "debounce": 60
104
102
  },
105
103
  "node": {
106
- "version": "12.12.0"
104
+ "version": "16.13.2"
107
105
  },
108
106
  "s3": {
109
107
  "bucket": "dfc-data-production",