react-native-update-cli 2.12.0 → 2.13.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.
@@ -3,6 +3,7 @@ export interface CommitInfo {
3
3
  message: string;
4
4
  author: string;
5
5
  timestamp: string;
6
- origin: string;
6
+ origin?: string;
7
7
  }
8
+ export declare function getCurrentCommit(): string;
8
9
  export declare function getCommitInfo(): Promise<CommitInfo | undefined>;
package/lib/utils/git.js CHANGED
@@ -2,57 +2,99 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "getCommitInfo", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get getCommitInfo () {
8
13
  return getCommitInfo;
14
+ },
15
+ get getCurrentCommit () {
16
+ return getCurrentCommit;
9
17
  }
10
18
  });
11
- const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
- const _isomorphicgit = /*#__PURE__*/ _interop_require_default(require("isomorphic-git"));
13
- const _path = /*#__PURE__*/ _interop_require_default(require("path"));
14
- function _interop_require_default(obj) {
15
- return obj && obj.__esModule ? obj : {
16
- default: obj
17
- };
19
+ const _child_process = require("child_process");
20
+ const _util = require("util");
21
+ const execFile = (0, _util.promisify)(_child_process.execFile);
22
+ function getCurrentCommit() {
23
+ const result = (0, _child_process.spawnSync)('git', [
24
+ 'rev-parse',
25
+ 'HEAD'
26
+ ]);
27
+ if (result.status !== 0) {
28
+ throw new Error('Not a git repository');
29
+ }
30
+ return result.stdout.toString().trim();
31
+ }
32
+ async function gitOutput(args, cwd = process.cwd()) {
33
+ const { stdout } = await execFile('git', args, {
34
+ cwd,
35
+ encoding: 'utf8',
36
+ windowsHide: true
37
+ });
38
+ return stdout.trimEnd();
18
39
  }
19
- function findGitRoot(dir = process.cwd()) {
20
- const gitRoot = _fs.default.readdirSync(dir).find((dir)=>dir === '.git');
21
- if (gitRoot) {
22
- // console.log({ gitRoot });
23
- return _path.default.join(dir, gitRoot);
40
+ async function getRemoteOrigin(cwd) {
41
+ const origin = await gitOutput([
42
+ 'remote',
43
+ 'get-url',
44
+ 'origin'
45
+ ], cwd).catch(()=>'');
46
+ if (origin) {
47
+ return origin;
24
48
  }
25
- const parentDir = _path.default.dirname(dir);
26
- if (parentDir === dir) {
27
- return null;
49
+ const remotes = await gitOutput([
50
+ 'remote'
51
+ ], cwd).catch(()=>'');
52
+ const firstRemote = remotes.split(/\r?\n/).find(Boolean);
53
+ if (!firstRemote) {
54
+ return undefined;
28
55
  }
29
- return findGitRoot(parentDir);
56
+ return gitOutput([
57
+ 'remote',
58
+ 'get-url',
59
+ firstRemote
60
+ ], cwd).catch(()=>undefined);
30
61
  }
31
- const gitRoot = findGitRoot();
32
62
  async function getCommitInfo() {
33
- if (!gitRoot) {
34
- return;
35
- }
36
63
  try {
37
- const remotes = await _isomorphicgit.default.listRemotes({
38
- fs: _fs.default,
39
- gitdir: gitRoot
40
- });
41
- const origin = remotes.find((remote)=>remote.remote === 'origin') || remotes[0];
42
- const { commit, oid } = (await _isomorphicgit.default.log({
43
- fs: _fs.default,
44
- gitdir: gitRoot,
45
- depth: 1
46
- }))[0];
64
+ const gitRoot = await gitOutput([
65
+ 'rev-parse',
66
+ '--show-toplevel'
67
+ ]);
68
+ const [hash, message, author, timestamp, origin] = await Promise.all([
69
+ gitOutput([
70
+ 'rev-parse',
71
+ 'HEAD'
72
+ ], gitRoot),
73
+ gitOutput([
74
+ 'log',
75
+ '-1',
76
+ '--format=%B'
77
+ ], gitRoot),
78
+ gitOutput([
79
+ 'log',
80
+ '-1',
81
+ '--format=%an'
82
+ ], gitRoot),
83
+ gitOutput([
84
+ 'log',
85
+ '-1',
86
+ '--format=%ct'
87
+ ], gitRoot),
88
+ getRemoteOrigin(gitRoot)
89
+ ]);
47
90
  return {
48
- hash: oid,
49
- message: commit.message,
50
- author: commit.author.name || commit.committer.name,
51
- timestamp: String(commit.committer.timestamp),
52
- origin: origin == null ? void 0 : origin.url
91
+ hash,
92
+ message,
93
+ author,
94
+ timestamp,
95
+ origin
53
96
  };
54
- } catch (error) {
55
- console.error(error);
97
+ } catch (_error) {
56
98
  return;
57
99
  }
58
100
  }
@@ -67,7 +67,12 @@ const testUrls = async (urls)=>{
67
67
  if (!(urls == null ? void 0 : urls.length)) {
68
68
  return null;
69
69
  }
70
- const ret = await promiseAny(urls.map(ping));
70
+ let ret = null;
71
+ try {
72
+ ret = await promiseAny(urls.map(ping));
73
+ } catch (_e) {
74
+ // fallback to urls[0]
75
+ }
71
76
  if (ret) {
72
77
  return ret;
73
78
  }
@@ -91,13 +91,11 @@ function measureTcpConnectOnce(host, port, timeout) {
91
91
  }
92
92
  async function measureTcpLatency(input, { attempts = 4, timeout = 1000 } = {}) {
93
93
  const { host, port } = resolveTcpTarget(input);
94
- const latencies = [];
95
- for(let i = 0; i < attempts; i++){
96
- const latency = await measureTcpConnectOnce(host, port, timeout);
97
- if (Number.isFinite(latency)) {
98
- latencies.push(latency);
99
- }
100
- }
94
+ const promises = Array.from({
95
+ length: attempts
96
+ }, ()=>measureTcpConnectOnce(host, port, timeout));
97
+ const results = await Promise.all(promises);
98
+ const latencies = results.filter(Number.isFinite);
101
99
  if (latencies.length === 0) {
102
100
  return Number.POSITIVE_INFINITY;
103
101
  }
@@ -175,8 +175,7 @@ async function enumZipEntries(zipFn, callback, nestedPath = '') {
175
175
  const fullPath = nestedPath + entry.fileName;
176
176
  try {
177
177
  if (!entry.fileName.endsWith('/') && entry.fileName.toLowerCase().endsWith('.hap')) {
178
- const tempDir = _path.default.join(_os.default.tmpdir(), `nested_zip_${Date.now()}`);
179
- await _fsextra.ensureDir(tempDir);
178
+ const tempDir = await _fsextra.mkdtemp(_path.default.join(_os.default.tmpdir(), 'nested_zip_'));
180
179
  const tempZipPath = _path.default.join(tempDir, 'temp.zip');
181
180
  await new Promise((res, rej)=>{
182
181
  zipfile.openReadStream(entry, async (err, readStream)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.12.0",
3
+ "version": "2.13.0",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "lib/exports.js",
6
6
  "types": "lib/exports.d.ts",
@@ -71,7 +71,6 @@
71
71
  "global-dirs": "^4.0.0",
72
72
  "gradle-to-js": "^2.0.1",
73
73
  "i18next": "^26.0.4",
74
- "isomorphic-git": "^1.37.5",
75
74
  "node-fetch": "^2.6.1",
76
75
  "plist": "^3.1.0",
77
76
  "progress": "^2.0.3",
package/src/utils/git.ts CHANGED
@@ -1,50 +1,71 @@
1
- import fs from 'fs';
2
- import git from 'isomorphic-git';
3
- import path from 'path';
1
+ import { execFile as execFileCallback, spawnSync } from 'child_process';
2
+ import { promisify } from 'util';
4
3
 
5
4
  export interface CommitInfo {
6
5
  hash: string;
7
6
  message: string;
8
7
  author: string;
9
8
  timestamp: string;
10
- origin: string;
9
+ origin?: string;
11
10
  }
12
11
 
13
- function findGitRoot(dir = process.cwd()) {
14
- const gitRoot = fs.readdirSync(dir).find((dir) => dir === '.git');
15
- if (gitRoot) {
16
- // console.log({ gitRoot });
17
- return path.join(dir, gitRoot);
18
- }
19
- const parentDir = path.dirname(dir);
20
- if (parentDir === dir) {
21
- return null;
12
+ const execFile = promisify(execFileCallback);
13
+
14
+ export function getCurrentCommit() {
15
+ const result = spawnSync('git', ['rev-parse', 'HEAD']);
16
+ if (result.status !== 0) {
17
+ throw new Error('Not a git repository');
22
18
  }
23
- return findGitRoot(parentDir);
19
+ return result.stdout.toString().trim();
24
20
  }
25
21
 
26
- const gitRoot = findGitRoot();
22
+ async function gitOutput(args: string[], cwd = process.cwd()): Promise<string> {
23
+ const { stdout } = await execFile('git', args, {
24
+ cwd,
25
+ encoding: 'utf8',
26
+ windowsHide: true,
27
+ });
28
+ return stdout.trimEnd();
29
+ }
27
30
 
28
- export async function getCommitInfo(): Promise<CommitInfo | undefined> {
29
- if (!gitRoot) {
30
- return;
31
+ async function getRemoteOrigin(cwd: string) {
32
+ const origin = await gitOutput(['remote', 'get-url', 'origin'], cwd).catch(
33
+ () => '',
34
+ );
35
+ if (origin) {
36
+ return origin;
37
+ }
38
+
39
+ const remotes = await gitOutput(['remote'], cwd).catch(() => '');
40
+ const firstRemote = remotes.split(/\r?\n/).find(Boolean);
41
+ if (!firstRemote) {
42
+ return undefined;
31
43
  }
44
+
45
+ return gitOutput(['remote', 'get-url', firstRemote], cwd).catch(
46
+ () => undefined,
47
+ );
48
+ }
49
+
50
+ export async function getCommitInfo(): Promise<CommitInfo | undefined> {
32
51
  try {
33
- const remotes = await git.listRemotes({ fs, gitdir: gitRoot });
34
- const origin =
35
- remotes.find((remote) => remote.remote === 'origin') || remotes[0];
36
- const { commit, oid } = (
37
- await git.log({ fs, gitdir: gitRoot, depth: 1 })
38
- )[0];
52
+ const gitRoot = await gitOutput(['rev-parse', '--show-toplevel']);
53
+ const [hash, message, author, timestamp, origin] = await Promise.all([
54
+ gitOutput(['rev-parse', 'HEAD'], gitRoot),
55
+ gitOutput(['log', '-1', '--format=%B'], gitRoot),
56
+ gitOutput(['log', '-1', '--format=%an'], gitRoot),
57
+ gitOutput(['log', '-1', '--format=%ct'], gitRoot),
58
+ getRemoteOrigin(gitRoot),
59
+ ]);
60
+
39
61
  return {
40
- hash: oid,
41
- message: commit.message,
42
- author: commit.author.name || commit.committer.name,
43
- timestamp: String(commit.committer.timestamp),
44
- origin: origin?.url,
62
+ hash,
63
+ message,
64
+ author,
65
+ timestamp,
66
+ origin,
45
67
  };
46
- } catch (error) {
47
- console.error(error);
68
+ } catch (_error) {
48
69
  return;
49
70
  }
50
71
  }
@@ -57,7 +57,12 @@ export const testUrls = async (urls?: string[]) => {
57
57
  if (!urls?.length) {
58
58
  return null;
59
59
  }
60
- const ret = await promiseAny(urls.map(ping));
60
+ let ret: string | null = null;
61
+ try {
62
+ ret = await promiseAny(urls.map(ping));
63
+ } catch (_e) {
64
+ // fallback to urls[0]
65
+ }
61
66
  if (ret) {
62
67
  return ret;
63
68
  }
@@ -98,14 +98,11 @@ export async function measureTcpLatency(
98
98
  } = {},
99
99
  ): Promise<number> {
100
100
  const { host, port } = resolveTcpTarget(input);
101
- const latencies: number[] = [];
102
-
103
- for (let i = 0; i < attempts; i++) {
104
- const latency = await measureTcpConnectOnce(host, port, timeout);
105
- if (Number.isFinite(latency)) {
106
- latencies.push(latency);
107
- }
108
- }
101
+ const promises = Array.from({ length: attempts }, () =>
102
+ measureTcpConnectOnce(host, port, timeout),
103
+ );
104
+ const results = await Promise.all(promises);
105
+ const latencies = results.filter(Number.isFinite);
109
106
 
110
107
  if (latencies.length === 0) {
111
108
  return Number.POSITIVE_INFINITY;
@@ -143,11 +143,9 @@ export async function enumZipEntries(
143
143
  !entry.fileName.endsWith('/') &&
144
144
  entry.fileName.toLowerCase().endsWith('.hap')
145
145
  ) {
146
- const tempDir = path.join(
147
- os.tmpdir(),
148
- `nested_zip_${Date.now()}`,
146
+ const tempDir = await fs.mkdtemp(
147
+ path.join(os.tmpdir(), 'nested_zip_'),
149
148
  );
150
- await fs.ensureDir(tempDir);
151
149
  const tempZipPath = path.join(tempDir, 'temp.zip');
152
150
 
153
151
  await new Promise((res, rej) => {