react-native-update-cli 2.11.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.
Files changed (51) hide show
  1. package/README.md +4 -0
  2. package/README.zh-CN.md +4 -0
  3. package/cli.json +6 -0
  4. package/lib/api.js +10 -12
  5. package/lib/app.d.ts +1 -1
  6. package/lib/app.js +1 -1
  7. package/lib/bin.js +5 -2
  8. package/lib/bundle-runner.js +22 -12
  9. package/lib/install.js +3 -4
  10. package/lib/locales/en.d.ts +1 -0
  11. package/lib/locales/en.js +1 -0
  12. package/lib/locales/zh.d.ts +1 -0
  13. package/lib/locales/zh.js +1 -0
  14. package/lib/package.d.ts +3 -0
  15. package/lib/package.js +6 -2
  16. package/lib/provider.d.ts +2 -2
  17. package/lib/provider.js +23 -22
  18. package/lib/types.d.ts +17 -4
  19. package/lib/utils/app-info-parser/zip.d.ts +3 -3
  20. package/lib/utils/app-info-parser/zip.js +33 -19
  21. package/lib/utils/git.d.ts +2 -1
  22. package/lib/utils/git.js +82 -40
  23. package/lib/utils/http-helper.js +8 -8
  24. package/lib/utils/index.d.ts +1 -0
  25. package/lib/utils/index.js +9 -1
  26. package/lib/utils/runtime.d.ts +28 -0
  27. package/lib/utils/runtime.js +183 -0
  28. package/lib/utils/zip-entries.js +1 -2
  29. package/lib/versions.d.ts +6 -3
  30. package/lib/versions.js +80 -23
  31. package/package.json +1 -7
  32. package/src/api.ts +23 -15
  33. package/src/app.ts +1 -1
  34. package/src/bin.ts +9 -2
  35. package/src/bundle-runner.ts +91 -50
  36. package/src/install.ts +3 -1
  37. package/src/locales/en.ts +1 -0
  38. package/src/locales/zh.ts +1 -0
  39. package/src/package.ts +11 -2
  40. package/src/provider.ts +47 -40
  41. package/src/types.ts +18 -4
  42. package/src/utils/app-info-parser/zip.ts +41 -24
  43. package/src/utils/git.ts +52 -31
  44. package/src/utils/http-helper.ts +8 -3
  45. package/src/utils/index.ts +8 -1
  46. package/src/utils/runtime.ts +187 -0
  47. package/src/utils/zip-entries.ts +2 -4
  48. package/src/versions.ts +105 -32
  49. package/lib/utils/latest-version/cli.d.ts +0 -1
  50. package/lib/utils/latest-version/cli.js +0 -308
  51. package/src/utils/latest-version/cli.ts +0 -445
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
  }
@@ -22,13 +22,8 @@ _export(exports, {
22
22
  return testUrls;
23
23
  }
24
24
  });
25
- const _nodefetch = /*#__PURE__*/ _interop_require_default(require("node-fetch"));
26
25
  const _constants = require("./constants");
27
- function _interop_require_default(obj) {
28
- return obj && obj.__esModule ? obj : {
29
- default: obj
30
- };
31
- }
26
+ const _runtime = require("./runtime");
32
27
  function promiseAny(promises) {
33
28
  return new Promise((resolve, reject)=>{
34
29
  let count = 0;
@@ -45,7 +40,7 @@ function promiseAny(promises) {
45
40
  const ping = async (url)=>{
46
41
  let pingFinished = false;
47
42
  return Promise.race([
48
- (0, _nodefetch.default)(url, {
43
+ (0, _runtime.runtimeFetch)(url, {
49
44
  method: 'HEAD'
50
45
  }).then(({ status })=>{
51
46
  pingFinished = true;
@@ -72,7 +67,12 @@ const testUrls = async (urls)=>{
72
67
  if (!(urls == null ? void 0 : urls.length)) {
73
68
  return null;
74
69
  }
75
- 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
+ }
76
76
  if (ret) {
77
77
  return ret;
78
78
  }
@@ -1,4 +1,5 @@
1
1
  import { checkPlugins } from './check-plugin';
2
+ export declare function isNonInteractive(): boolean;
2
3
  export declare function question(query: string, password?: boolean): Promise<string>;
3
4
  export declare function translateOptions<T extends Record<string, unknown>>(options: T): T & Record<string, unknown>;
4
5
  export declare function getApkInfo(fn: string): Promise<{
@@ -24,6 +24,9 @@ _export(exports, {
24
24
  get getIpaInfo () {
25
25
  return getIpaInfo;
26
26
  },
27
+ get isNonInteractive () {
28
+ return isNonInteractive;
29
+ },
27
30
  get printVersionCommand () {
28
31
  return printVersionCommand;
29
32
  },
@@ -51,8 +54,13 @@ function _interop_require_default(obj) {
51
54
  default: obj
52
55
  };
53
56
  }
57
+ function isNonInteractive() {
58
+ var _process_env_NO_INTERACTIVE;
59
+ const envValue = (_process_env_NO_INTERACTIVE = process.env.NO_INTERACTIVE) == null ? void 0 : _process_env_NO_INTERACTIVE.toLowerCase();
60
+ return global.NO_INTERACTIVE === true || envValue === 'true' || envValue === '1';
61
+ }
54
62
  async function question(query, password) {
55
- if (NO_INTERACTIVE) {
63
+ if (isNonInteractive()) {
56
64
  return '';
57
65
  }
58
66
  return (0, _read.read)({
@@ -0,0 +1,28 @@
1
+ import { type ChildProcessWithoutNullStreams, type SpawnOptionsWithoutStdio, type SpawnSyncOptions } from 'child_process';
2
+ export type RuntimeRequestInit = {
3
+ method?: string;
4
+ headers?: Record<string, string>;
5
+ body?: any;
6
+ signal?: AbortSignal;
7
+ };
8
+ export type RuntimeResponse = {
9
+ status: number;
10
+ statusText: string;
11
+ text: () => Promise<string>;
12
+ };
13
+ export type PackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn';
14
+ export type JavaScriptRuntime = 'bun' | 'node';
15
+ export declare const isBunRuntime: boolean;
16
+ export declare function runtimeFetch(url: string, options?: RuntimeRequestInit): Promise<RuntimeResponse>;
17
+ export declare function measureTcpLatency(input: string, { attempts, timeout, }?: {
18
+ attempts?: number;
19
+ timeout?: number;
20
+ }): Promise<number>;
21
+ export declare function detectPackageManager(cwd?: string, env?: NodeJS.ProcessEnv): PackageManager;
22
+ export declare function getInstallCommand(installArgs: string[], cwd?: string): {
23
+ command: string;
24
+ args: string[];
25
+ };
26
+ export declare function getJavaScriptRuntime(env?: NodeJS.ProcessEnv): JavaScriptRuntime;
27
+ export declare function spawnJavaScript(args: string[], options?: SpawnOptionsWithoutStdio, env?: NodeJS.ProcessEnv): ChildProcessWithoutNullStreams;
28
+ export declare function spawnJavaScriptSync(args: string[], options?: SpawnSyncOptions, env?: NodeJS.ProcessEnv): import("node:child_process").SpawnSyncReturns<string | NonSharedBuffer>;
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
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 detectPackageManager () {
13
+ return detectPackageManager;
14
+ },
15
+ get getInstallCommand () {
16
+ return getInstallCommand;
17
+ },
18
+ get getJavaScriptRuntime () {
19
+ return getJavaScriptRuntime;
20
+ },
21
+ get isBunRuntime () {
22
+ return isBunRuntime;
23
+ },
24
+ get measureTcpLatency () {
25
+ return measureTcpLatency;
26
+ },
27
+ get runtimeFetch () {
28
+ return runtimeFetch;
29
+ },
30
+ get spawnJavaScript () {
31
+ return spawnJavaScript;
32
+ },
33
+ get spawnJavaScriptSync () {
34
+ return spawnJavaScriptSync;
35
+ }
36
+ });
37
+ const _child_process = require("child_process");
38
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
39
+ const _net = require("net");
40
+ const _nodefetch = /*#__PURE__*/ _interop_require_default(require("node-fetch"));
41
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
42
+ function _interop_require_default(obj) {
43
+ return obj && obj.__esModule ? obj : {
44
+ default: obj
45
+ };
46
+ }
47
+ const isBunRuntime = typeof process.versions.bun === 'string';
48
+ function runtimeFetch(url, options) {
49
+ const fetchImpl = typeof globalThis.fetch === 'function' ? globalThis.fetch.bind(globalThis) : _nodefetch.default;
50
+ return fetchImpl(url, options);
51
+ }
52
+ function resolveTcpTarget(input) {
53
+ try {
54
+ const parsed = new URL(input);
55
+ const port = parsed.port || (parsed.protocol === 'http:' ? '80' : '443');
56
+ return {
57
+ host: parsed.hostname,
58
+ port: Number(port)
59
+ };
60
+ } catch (unused) {
61
+ const [host, port] = input.split(':');
62
+ return {
63
+ host,
64
+ port: port ? Number(port) : 443
65
+ };
66
+ }
67
+ }
68
+ function measureTcpConnectOnce(host, port, timeout) {
69
+ return new Promise((resolve)=>{
70
+ const startedAt = Date.now();
71
+ const socket = (0, _net.createConnection)({
72
+ host,
73
+ port
74
+ });
75
+ const finish = (latency)=>{
76
+ socket.removeAllListeners();
77
+ socket.destroy();
78
+ resolve(latency);
79
+ };
80
+ socket.setTimeout(timeout);
81
+ socket.once('connect', ()=>{
82
+ finish(Date.now() - startedAt);
83
+ });
84
+ socket.once('timeout', ()=>{
85
+ finish(Number.POSITIVE_INFINITY);
86
+ });
87
+ socket.once('error', ()=>{
88
+ finish(Number.POSITIVE_INFINITY);
89
+ });
90
+ });
91
+ }
92
+ async function measureTcpLatency(input, { attempts = 4, timeout = 1000 } = {}) {
93
+ const { host, port } = resolveTcpTarget(input);
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);
99
+ if (latencies.length === 0) {
100
+ return Number.POSITIVE_INFINITY;
101
+ }
102
+ return latencies.reduce((sum, latency)=>sum + latency, 0) / latencies.length;
103
+ }
104
+ function detectPackageManager(cwd = process.cwd(), env = process.env) {
105
+ var _env_npm_config_user_agent;
106
+ const lockFiles = [
107
+ [
108
+ 'bun.lock',
109
+ 'bun'
110
+ ],
111
+ [
112
+ 'bun.lockb',
113
+ 'bun'
114
+ ],
115
+ [
116
+ 'pnpm-lock.yaml',
117
+ 'pnpm'
118
+ ],
119
+ [
120
+ 'yarn.lock',
121
+ 'yarn'
122
+ ],
123
+ [
124
+ 'package-lock.json',
125
+ 'npm'
126
+ ]
127
+ ];
128
+ for (const [lockFile, manager] of lockFiles){
129
+ if (_fs.default.existsSync(_path.default.join(cwd, lockFile))) {
130
+ return manager;
131
+ }
132
+ }
133
+ const userAgent = (_env_npm_config_user_agent = env.npm_config_user_agent) != null ? _env_npm_config_user_agent : '';
134
+ if (userAgent.startsWith('bun/')) {
135
+ return 'bun';
136
+ }
137
+ if (userAgent.startsWith('pnpm/')) {
138
+ return 'pnpm';
139
+ }
140
+ if (userAgent.startsWith('yarn/')) {
141
+ return 'yarn';
142
+ }
143
+ if (userAgent.startsWith('npm/')) {
144
+ return 'npm';
145
+ }
146
+ return isBunRuntime ? 'bun' : 'npm';
147
+ }
148
+ function getInstallCommand(installArgs, cwd = process.cwd()) {
149
+ const packageManager = detectPackageManager(cwd);
150
+ if (packageManager === 'npm') {
151
+ return {
152
+ command: 'npm',
153
+ args: [
154
+ 'install',
155
+ ...installArgs
156
+ ]
157
+ };
158
+ }
159
+ return {
160
+ command: packageManager,
161
+ args: [
162
+ 'add',
163
+ ...installArgs
164
+ ]
165
+ };
166
+ }
167
+ function getJavaScriptRuntime(env = process.env) {
168
+ var _env_RNU_JS_RUNTIME;
169
+ const configured = (_env_RNU_JS_RUNTIME = env.RNU_JS_RUNTIME) == null ? void 0 : _env_RNU_JS_RUNTIME.toLowerCase();
170
+ if (configured === 'bun') {
171
+ return 'bun';
172
+ }
173
+ if (configured === 'auto') {
174
+ return isBunRuntime ? 'bun' : 'node';
175
+ }
176
+ return 'node';
177
+ }
178
+ function spawnJavaScript(args, options, env = process.env) {
179
+ return (0, _child_process.spawn)(getJavaScriptRuntime(env), args, options != null ? options : {});
180
+ }
181
+ function spawnJavaScriptSync(args, options, env = process.env) {
182
+ return (0, _child_process.spawnSync)(getJavaScriptRuntime(env), args, options != null ? options : {});
183
+ }
@@ -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/lib/versions.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { Package, Platform } from './types';
1
+ import type { Package, Platform, Version } from './types';
2
2
  interface VersionCommandOptions {
3
+ [key: string]: unknown;
3
4
  appId?: string;
4
5
  name?: string;
5
6
  description?: string;
@@ -11,14 +12,16 @@ interface VersionCommandOptions {
11
12
  minPackageVersion?: string;
12
13
  maxPackageVersion?: string;
13
14
  packageVersionRange?: string;
14
- rollout?: string;
15
+ rollout?: number | string;
15
16
  dryRun?: boolean;
16
17
  versionDeps?: Record<string, string>;
17
18
  warnDepsChanges?: boolean;
19
+ 'no-interactive'?: boolean | string;
18
20
  }
21
+ export declare function fetchVersions(appId: string, offset?: number, limit?: number): Promise<Version[]>;
19
22
  export declare const bindVersionToPackages: ({ appId, versionId, pkgs, rollout, dryRun, }: {
20
23
  appId: string;
21
- versionId: string;
24
+ versionId: string | null;
22
25
  pkgs: Package[];
23
26
  rollout?: number;
24
27
  dryRun?: boolean;