rn-update-cli 1.0.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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/README.zh-CN.md +167 -0
  4. package/cli.json +525 -0
  5. package/lib/api.d.ts +56 -0
  6. package/lib/api.js +671 -0
  7. package/lib/app.d.ts +107 -0
  8. package/lib/app.js +329 -0
  9. package/lib/auto-update.d.ts +35 -0
  10. package/lib/auto-update.js +507 -0
  11. package/lib/bin.d.ts +2 -0
  12. package/lib/bin.js +133 -0
  13. package/lib/bundle-pack.d.ts +6 -0
  14. package/lib/bundle-pack.js +91 -0
  15. package/lib/bundle-runner.d.ts +168 -0
  16. package/lib/bundle-runner.js +1305 -0
  17. package/lib/bundle.d.ts +45 -0
  18. package/lib/bundle.js +226 -0
  19. package/lib/cache.d.ts +10 -0
  20. package/lib/cache.js +25 -0
  21. package/lib/commands.d.ts +11 -0
  22. package/lib/commands.js +72 -0
  23. package/lib/diff.d.ts +18 -0
  24. package/lib/diff.js +690 -0
  25. package/lib/exports.d.ts +11 -0
  26. package/lib/exports.js +20 -0
  27. package/lib/install.d.ts +9 -0
  28. package/lib/install.js +51 -0
  29. package/lib/locales/en.d.ts +187 -0
  30. package/lib/locales/en.js +194 -0
  31. package/lib/locales/zh.d.ts +187 -0
  32. package/lib/locales/zh.js +194 -0
  33. package/lib/native-package.d.ts +21 -0
  34. package/lib/native-package.js +298 -0
  35. package/lib/package.d.ts +68 -0
  36. package/lib/package.js +487 -0
  37. package/lib/provider.d.ts +24 -0
  38. package/lib/provider.js +244 -0
  39. package/lib/standalone-publish.d.ts +17 -0
  40. package/lib/standalone-publish.js +433 -0
  41. package/lib/symbolicate.d.ts +35 -0
  42. package/lib/symbolicate.js +130 -0
  43. package/lib/types.d.ts +152 -0
  44. package/lib/types.js +2 -0
  45. package/lib/user.d.ts +8 -0
  46. package/lib/user.js +50 -0
  47. package/lib/utils/add-gitignore.d.ts +6 -0
  48. package/lib/utils/add-gitignore.js +44 -0
  49. package/lib/utils/app-info-parser/aab.d.ts +27 -0
  50. package/lib/utils/app-info-parser/aab.js +256 -0
  51. package/lib/utils/app-info-parser/apk.d.ts +19 -0
  52. package/lib/utils/app-info-parser/apk.js +95 -0
  53. package/lib/utils/app-info-parser/app.d.ts +9 -0
  54. package/lib/utils/app-info-parser/app.js +15 -0
  55. package/lib/utils/app-info-parser/index.d.ts +21 -0
  56. package/lib/utils/app-info-parser/index.js +51 -0
  57. package/lib/utils/app-info-parser/ipa.d.ts +19 -0
  58. package/lib/utils/app-info-parser/ipa.js +101 -0
  59. package/lib/utils/app-info-parser/resource-finder.d.ts +49 -0
  60. package/lib/utils/app-info-parser/resource-finder.js +429 -0
  61. package/lib/utils/app-info-parser/utils.d.ts +36 -0
  62. package/lib/utils/app-info-parser/utils.js +140 -0
  63. package/lib/utils/app-info-parser/xml-parser/binary.d.ts +61 -0
  64. package/lib/utils/app-info-parser/xml-parser/binary.js +577 -0
  65. package/lib/utils/app-info-parser/xml-parser/manifest.d.ts +15 -0
  66. package/lib/utils/app-info-parser/xml-parser/manifest.js +207 -0
  67. package/lib/utils/app-info-parser/zip.d.ts +29 -0
  68. package/lib/utils/app-info-parser/zip.js +97 -0
  69. package/lib/utils/check-lockfile.d.ts +6 -0
  70. package/lib/utils/check-lockfile.js +93 -0
  71. package/lib/utils/check-plugin.d.ts +12 -0
  72. package/lib/utils/check-plugin.js +36 -0
  73. package/lib/utils/command-result.d.ts +8 -0
  74. package/lib/utils/command-result.js +27 -0
  75. package/lib/utils/constants.d.ts +10 -0
  76. package/lib/utils/constants.js +39 -0
  77. package/lib/utils/dep-versions.d.ts +20 -0
  78. package/lib/utils/dep-versions.js +129 -0
  79. package/lib/utils/git.d.ts +14 -0
  80. package/lib/utils/git.js +64 -0
  81. package/lib/utils/hbcTransform.d.ts +111 -0
  82. package/lib/utils/hbcTransform.js +561 -0
  83. package/lib/utils/hermes-base.d.ts +227 -0
  84. package/lib/utils/hermes-base.js +1287 -0
  85. package/lib/utils/hermes-literals.d.ts +64 -0
  86. package/lib/utils/hermes-literals.js +260 -0
  87. package/lib/utils/http-helper.d.ts +10 -0
  88. package/lib/utils/http-helper.js +150 -0
  89. package/lib/utils/i18n.d.ts +22 -0
  90. package/lib/utils/i18n.js +46 -0
  91. package/lib/utils/index.d.ts +67 -0
  92. package/lib/utils/index.js +545 -0
  93. package/lib/utils/latest-version/index.d.ts +154 -0
  94. package/lib/utils/latest-version/index.js +331 -0
  95. package/lib/utils/options.d.ts +10 -0
  96. package/lib/utils/options.js +68 -0
  97. package/lib/utils/plugin-config.d.ts +14 -0
  98. package/lib/utils/plugin-config.js +66 -0
  99. package/lib/utils/runtime.d.ts +54 -0
  100. package/lib/utils/runtime.js +263 -0
  101. package/lib/utils/slim-sourcemap.d.ts +28 -0
  102. package/lib/utils/slim-sourcemap.js +106 -0
  103. package/lib/utils/zip-entries.d.ts +10 -0
  104. package/lib/utils/zip-entries.js +211 -0
  105. package/lib/utils/zip-options.d.ts +17 -0
  106. package/lib/utils/zip-options.js +190 -0
  107. package/lib/utils/zip-range.d.ts +148 -0
  108. package/lib/utils/zip-range.js +581 -0
  109. package/lib/utils/zip-raw-writer.d.ts +52 -0
  110. package/lib/utils/zip-raw-writer.js +209 -0
  111. package/lib/version-operations.d.ts +21 -0
  112. package/lib/version-operations.js +320 -0
  113. package/lib/versions.d.ts +66 -0
  114. package/lib/versions.js +402 -0
  115. package/package.json +113 -0
  116. package/proto/Configuration.proto +183 -0
  117. package/proto/Resources.proto +569 -0
@@ -0,0 +1,154 @@
1
+ /**
2
+ * [INPUT]: 依赖 npm/yarn 全局目录、registry HTTP、版本比较器、认证 token 与文件缓存
3
+ * [OUTPUT]: 对外提供 latestVersion 及版本类型,查询并比较 CLI 安装版本
4
+ * [POS]: CLI 自更新提示的版本解析底座,封装 registry 差异和本地全局安装布局
5
+ */
6
+ import type { Agent } from 'http';
7
+ interface RegistryVersions {
8
+ /**
9
+ * The latest version of the package found on the registry (if found).
10
+ */
11
+ latest?: string;
12
+ /**
13
+ * The next version of the package found on the registry (if found).
14
+ */
15
+ next?: string;
16
+ /**
17
+ * The latest version of the package found on the registry and satisfied by the wanted tag or version range.
18
+ */
19
+ wanted?: string;
20
+ }
21
+ interface InstalledVersions {
22
+ /**
23
+ * The current local installed version of the package (if installed).
24
+ */
25
+ local?: string;
26
+ /**
27
+ * The current npm global installed version of the package (if installed).
28
+ */
29
+ globalNpm?: string;
30
+ /**
31
+ * The current yarn global installed version of the package (if installed).
32
+ */
33
+ globalYarn?: string;
34
+ }
35
+ interface LatestVersionPackage extends InstalledVersions, RegistryVersions {
36
+ /**
37
+ * The name of the package.
38
+ */
39
+ name: string;
40
+ /**
41
+ * The tag or version range that was provided (if provided).
42
+ * @default "latest"
43
+ */
44
+ wantedTagOrRange?: string;
45
+ /**
46
+ * Whether the local or global installed versions (if any) could be upgraded or not, based on the wanted version.
47
+ */
48
+ updatesAvailable: {
49
+ local: string | false;
50
+ globalNpm: string | false;
51
+ globalYarn: string | false;
52
+ } | false;
53
+ /**
54
+ * Any error that might have occurred during the process.
55
+ */
56
+ error?: Error;
57
+ }
58
+ interface RequestOptions {
59
+ readonly ca?: string | Buffer | Array<string | Buffer>;
60
+ readonly rejectUnauthorized?: boolean;
61
+ readonly agent?: Agent | boolean;
62
+ readonly timeout?: number;
63
+ }
64
+ interface LatestVersionOptions {
65
+ /**
66
+ * Awaiting the api to return might take time, depending on the network, and might impact your package loading performance.
67
+ * You can use the cache mechanism to improve load performance and reduce unnecessary network requests.
68
+ * If `useCache` is not supplied, the api will always check for updates and wait for every requests to return before returning itself.
69
+ * If `useCache` is used (for each provided package):
70
+ * 1) a fresh cache (younger than `cacheMaxAge`, from the same registry) answers without any network request
71
+ * 2) otherwise the registry is queried and the cache refreshed; when that query fails, a stale cache (if any) is used instead.
72
+ * Combine with `unref` so a slow refresh never keeps the process alive.
73
+ * @default false
74
+ */
75
+ readonly useCache?: boolean;
76
+ /**
77
+ * How long the cache for the provided packages should be used before being refreshed (in milliseconds).
78
+ * If `useCache` is not supplied, this option has no effect.
79
+ * If `0` is used, the cache is always refreshed (a stale cache still serves as a fallback when the refresh fails).
80
+ * @default ONE_DAY
81
+ */
82
+ readonly cacheMaxAge?: number;
83
+ /**
84
+ * Do not let the registry request keep the process alive: its socket is `unref`'d, so the process may exit before the
85
+ * request completes (the returned promise then simply never settles). Use for opportunistic background checks.
86
+ * @default false
87
+ */
88
+ readonly unref?: boolean;
89
+ /**
90
+ * A JavaScript package registry url that implements the CommonJS Package Registry specification.
91
+ * @default "Looks at any registry urls in the .npmrc file or fallback to the default npm registry instead"
92
+ * @example <caption>.npmrc</caption>
93
+ * registry = 'https://custom-registry.com/'
94
+ * @pkgscope:registry = 'https://custom-registry.com/'
95
+ */
96
+ readonly registryUrl?: string;
97
+ /**
98
+ * Set of options to be passed down to Node.js http/https request.
99
+ * @example <caption>Behind a proxy with self-signed certificate</caption>
100
+ * { ca: [ fs.readFileSync('proxy-cert.pem') ] }
101
+ * @example <caption>Bypassing certificate validation</caption>
102
+ * { rejectUnauthorized: false }
103
+ */
104
+ readonly requestOptions?: RequestOptions;
105
+ }
106
+ interface LatestVersion {
107
+ /**
108
+ * Get latest versions of packages from of a package json like object.
109
+ * @param {PackageJson} item - A package json like object (with dependencies, devDependencies and peerDependencies attributes).
110
+ * @example { dependencies: { 'npm': 'latest' }, devDependencies: { 'npm': '1.3.2' }, peerDependencies: { '@scope/name': '^5.0.2' } }
111
+ * @param {LatestVersionOptions} [options] - An object optionally specifying the use of the cache, the max age of the cache, the registry url and the http or https options.
112
+ * If `useCache` is not supplied, the default of `false` is used.
113
+ * If `cacheMaxAge` is not supplied, the default of `one day` is used.
114
+ * If `registryUrl` is not supplied, the default from `.npmrc` is used or a fallback to the `npm registry url` instead.
115
+ * @returns {Promise<LatestVersionPackage[]>}
116
+ */
117
+ (item: PackageJson, options?: LatestVersionOptions): Promise<LatestVersionPackage[]>;
118
+ /**
119
+ * Get latest version of a single package.
120
+ * @param {Package} item - A single package object (represented by a string that should match the following format: `${'@' | ''}${string}@${string}`)
121
+ * @example 'npm', 'npm@1.3.2', '@scope/name@^5.0.2'
122
+ * @param {LatestVersionOptions} [options] - An object optionally specifying the use of the cache, the max age of the cache, the registry url and the http or https options.
123
+ * If `useCache` is not supplied, the default of `false` is used.
124
+ * If `cacheMaxAge` is not supplied, the default of `one day` is used.
125
+ * If `registryUrl` is not supplied, the default from `.npmrc` is used or a fallback to the npm registry url instead.
126
+ * @returns {Promise<LatestVersionPackage>}
127
+ */
128
+ (item: Package, options?: LatestVersionOptions): Promise<LatestVersionPackage>;
129
+ /**
130
+ * Get latest versions of a collection of packages.
131
+ * @param {Package[]} items - A collection of package object (represented by a string that should match the following format: `${'@' | ''}${string}@${string}`)
132
+ * @example ['npm', 'npm@1.3.2', '@scope/name@^5.0.2']
133
+ * @param {LatestVersionOptions} [options] - An object optionally specifying the use of the cache, the max age of the cache, the registry url and the http or https options.
134
+ * If `useCache` is not supplied, the default of `false` is used.
135
+ * If `cacheMaxAge` is not supplied, the default of `one day` is used.
136
+ * If `registryUrl` is not supplied, the default from `.npmrc` is used or a fallback to the npm registry url instead.
137
+ * @returns {Promise<LatestVersionPackage[]>}
138
+ */
139
+ (items: Package[], options?: LatestVersionOptions): Promise<LatestVersionPackage[]>;
140
+ }
141
+ type PackageRange = `${'@' | ''}${string}@${string}`;
142
+ type Package = PackageRange | string;
143
+ type PackageJsonDependencies = Record<string, string>;
144
+ type PackageJson = Record<string, any> & ({
145
+ dependencies: PackageJsonDependencies;
146
+ } | {
147
+ devDependencies: PackageJsonDependencies;
148
+ } | {
149
+ peerDependencies: PackageJsonDependencies;
150
+ });
151
+ export declare const ONE_DAY: number;
152
+ declare const latestVersion: LatestVersion;
153
+ export type { LatestVersion, LatestVersionOptions, LatestVersionPackage, Package, PackageJson, PackageJsonDependencies, PackageRange, RegistryVersions, RequestOptions, };
154
+ export default latestVersion;
@@ -0,0 +1,331 @@
1
+ "use strict";
2
+ /**
3
+ * [INPUT]: 依赖 npm/yarn 全局目录、registry HTTP、版本比较器、认证 token 与文件缓存
4
+ * [OUTPUT]: 对外提供 latestVersion 及版本类型,查询并比较 CLI 安装版本
5
+ * [POS]: CLI 自更新提示的版本解析底座,封装 registry 差异和本地全局安装布局
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ONE_DAY = void 0;
12
+ const compare_versions_1 = require("compare-versions");
13
+ const fs_1 = require("fs");
14
+ const global_dirs_1 = require("global-dirs");
15
+ const os_1 = require("os");
16
+ const path_1 = require("path");
17
+ const registry_auth_token_1 = __importDefault(require("registry-auth-token"));
18
+ const registry_url_1 = __importDefault(require("registry-auth-token/registry-url"));
19
+ const url_1 = require("url");
20
+ const runtime_1 = require("../runtime");
21
+ exports.ONE_DAY = 1000 * 60 * 60 * 24; // eslint-disable-line @typescript-eslint/naming-convention
22
+ const isPackageJson = (obj) => {
23
+ return (obj.dependencies !== undefined ||
24
+ obj.devDependencies !== undefined ||
25
+ obj.peerDependencies !== undefined);
26
+ };
27
+ const resolveRegistryUrl = (pkgName, options) => {
28
+ const i = pkgName.indexOf('/');
29
+ const pkgScope = i !== -1 ? pkgName.slice(0, i) : '';
30
+ return options?.registryUrl ?? (0, registry_url_1.default)(pkgScope);
31
+ };
32
+ const downloadMetadata = (pkgName, options) => {
33
+ return new Promise((resolve, reject) => {
34
+ const registryUrl = resolveRegistryUrl(pkgName, options);
35
+ const pkgUrl = new url_1.URL(encodeURIComponent(pkgName).replace(/^%40/, '@'), registryUrl);
36
+ let requestOptions = {
37
+ headers: {
38
+ accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
39
+ },
40
+ host: pkgUrl.hostname,
41
+ path: pkgUrl.pathname,
42
+ port: pkgUrl.port,
43
+ };
44
+ const authInfo = (0, registry_auth_token_1.default)(pkgUrl.toString(), { recursive: true });
45
+ if (authInfo && requestOptions.headers) {
46
+ requestOptions.headers.authorization =
47
+ `${authInfo.type} ${authInfo.token}`;
48
+ }
49
+ if (options?.requestOptions) {
50
+ requestOptions = { ...requestOptions, ...options.requestOptions };
51
+ }
52
+ if (requestOptions.agent === undefined) {
53
+ // HTTP(S)_PROXY / NO_PROXY, like every other request of the CLI
54
+ const agent = (0, runtime_1.proxyAgentFor)(pkgUrl.toString());
55
+ if (agent) {
56
+ requestOptions = { ...requestOptions, agent };
57
+ }
58
+ }
59
+ const { get } = require(pkgUrl.protocol === 'https:' ? 'https' : 'http');
60
+ const request = get(requestOptions, (res) => {
61
+ if (res.statusCode === 200) {
62
+ let rawData = '';
63
+ res.setEncoding('utf8');
64
+ res.on('data', (chunk) => (rawData += chunk));
65
+ res.once('error', (err) => {
66
+ res.removeAllListeners();
67
+ reject(`Request error (${err.message}): ${pkgUrl}`);
68
+ });
69
+ res.once('end', () => {
70
+ res.removeAllListeners();
71
+ try {
72
+ const pkgMetadata = JSON.parse(rawData);
73
+ resolve({
74
+ name: pkgName,
75
+ lastUpdateDate: Date.now(),
76
+ versions: Object.keys(pkgMetadata.versions),
77
+ distTags: pkgMetadata['dist-tags'],
78
+ registryUrl,
79
+ });
80
+ return;
81
+ }
82
+ catch (err) {
83
+ reject(err);
84
+ return;
85
+ }
86
+ });
87
+ }
88
+ else {
89
+ res.removeAllListeners();
90
+ res.resume(); // consume response data to free up memory
91
+ reject(`Request error (${res.statusCode}): ${pkgUrl}`);
92
+ return;
93
+ }
94
+ });
95
+ const abort = (error) => {
96
+ request.destroy();
97
+ reject(error);
98
+ };
99
+ request.once('timeout', () => {
100
+ abort(`Request timed out: ${pkgUrl}`);
101
+ });
102
+ request.once('error', (err) => {
103
+ abort(err);
104
+ });
105
+ request.on('close', () => {
106
+ request.removeAllListeners();
107
+ });
108
+ if (options?.unref) {
109
+ // A background check must never delay the process exit: drop the
110
+ // socket's ref (also for a pooled keep-alive socket, which the agent
111
+ // ref's again right before handing it out).
112
+ request.once('socket', (socket) => {
113
+ socket.unref?.();
114
+ });
115
+ }
116
+ });
117
+ };
118
+ const getCacheDir = (name = '@badisi/latest-version') => {
119
+ const homeDir = (0, os_1.homedir)();
120
+ if (process.env.XDG_CACHE_HOME) {
121
+ // an explicit override wins on every platform (also lets tests isolate)
122
+ return (0, path_1.join)(process.env.XDG_CACHE_HOME, name);
123
+ }
124
+ switch (process.platform) {
125
+ case 'darwin':
126
+ return (0, path_1.join)(homeDir, 'Library', 'Caches', name);
127
+ case 'win32':
128
+ return (0, path_1.join)(process.env.LOCALAPPDATA ?? (0, path_1.join)(homeDir, 'AppData', 'Local'), name, 'Cache');
129
+ default:
130
+ return (0, path_1.join)(process.env.XDG_CACHE_HOME ?? (0, path_1.join)(homeDir, '.cache'), name);
131
+ }
132
+ };
133
+ const saveMetadataToCache = (pkg) => {
134
+ try {
135
+ const filePath = (0, path_1.join)(getCacheDir(), `${pkg.name}.json`);
136
+ if (!(0, fs_1.existsSync)((0, path_1.dirname)(filePath))) {
137
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(filePath), { recursive: true });
138
+ }
139
+ (0, fs_1.writeFileSync)(filePath, JSON.stringify(pkg));
140
+ }
141
+ catch {
142
+ // a read-only or missing cache dir must not turn into an error
143
+ }
144
+ };
145
+ /**
146
+ * The cached metadata of a package (from the same registry), and whether it is
147
+ * still younger than `cacheMaxAge`. A stale entry is returned as well so it can
148
+ * serve as a fallback when the registry is unreachable.
149
+ */
150
+ const getMetadataFromCache = (pkgName, options) => {
151
+ const maxAge = options?.cacheMaxAge ?? exports.ONE_DAY;
152
+ try {
153
+ const pkgCacheFilePath = (0, path_1.join)(getCacheDir(), `${pkgName}.json`);
154
+ if (!(0, fs_1.existsSync)(pkgCacheFilePath)) {
155
+ return undefined;
156
+ }
157
+ const metadata = JSON.parse((0, fs_1.readFileSync)(pkgCacheFilePath).toString());
158
+ if (!metadata ||
159
+ typeof metadata.lastUpdateDate !== 'number' ||
160
+ !metadata.distTags ||
161
+ metadata.registryUrl !== resolveRegistryUrl(pkgName, options)) {
162
+ return undefined;
163
+ }
164
+ const age = Date.now() - metadata.lastUpdateDate;
165
+ return { metadata, fresh: maxAge !== 0 && age >= 0 && age < maxAge };
166
+ }
167
+ catch {
168
+ return undefined; // unreadable / corrupt cache is the same as no cache
169
+ }
170
+ };
171
+ const getRegistryVersions = async (pkgName, tagOrRange, options) => {
172
+ let pkgMetadata;
173
+ if (pkgName.length && options?.useCache) {
174
+ const cached = getMetadataFromCache(pkgName, options);
175
+ if (cached?.fresh) {
176
+ pkgMetadata = cached.metadata;
177
+ }
178
+ else {
179
+ try {
180
+ pkgMetadata = await downloadMetadata(pkgName, options);
181
+ saveMetadataToCache(pkgMetadata);
182
+ }
183
+ catch (err) {
184
+ if (!cached) {
185
+ throw err;
186
+ }
187
+ pkgMetadata = cached.metadata; // stale beats nothing
188
+ }
189
+ }
190
+ }
191
+ else if (pkgName.length) {
192
+ pkgMetadata = await downloadMetadata(pkgName, options);
193
+ }
194
+ const versions = {
195
+ latest: pkgMetadata?.distTags.latest,
196
+ next: pkgMetadata?.distTags.next,
197
+ };
198
+ if (tagOrRange && pkgMetadata?.distTags[tagOrRange]) {
199
+ versions.wanted = pkgMetadata.distTags[tagOrRange];
200
+ }
201
+ else if (tagOrRange && pkgMetadata?.versions.length) {
202
+ versions.wanted = maxSatisfying(pkgMetadata.versions, tagOrRange);
203
+ }
204
+ return versions;
205
+ };
206
+ /** the highest of `versions` within `range` (npm range syntax), if any */
207
+ const maxSatisfying = (versions, range) => {
208
+ const matching = versions.filter((version) => {
209
+ try {
210
+ return (0, compare_versions_1.satisfies)(version, range);
211
+ }
212
+ catch {
213
+ return false;
214
+ }
215
+ });
216
+ if (!matching.length)
217
+ return undefined;
218
+ return matching.sort(compare_versions_1.compareVersions)[matching.length - 1];
219
+ };
220
+ /** `a > b` for two versions; invalid input counts as "not newer" */
221
+ const gt = (a, b) => {
222
+ try {
223
+ return (0, compare_versions_1.compare)(a, b, '>');
224
+ }
225
+ catch {
226
+ return false;
227
+ }
228
+ };
229
+ const getInstalledVersion = (pkgName, location = 'local') => {
230
+ try {
231
+ if (location === 'globalNpm') {
232
+ return require((0, path_1.join)(global_dirs_1.npm.packages, pkgName, 'package.json'))
233
+ ?.version;
234
+ }
235
+ if (location === 'globalYarn') {
236
+ // Make sure package is globally installed by Yarn
237
+ const yarnGlobalPkg = require((0, path_1.resolve)(global_dirs_1.yarn.packages, '..', 'package.json'));
238
+ if (!yarnGlobalPkg?.dependencies?.[pkgName]) {
239
+ return undefined;
240
+ }
241
+ return require((0, path_1.join)(global_dirs_1.yarn.packages, pkgName, 'package.json'))
242
+ ?.version;
243
+ }
244
+ /**
245
+ * Compute the local paths manually as require.resolve() and require.resolve.paths()
246
+ * cannot be trusted anymore.
247
+ * @see https://github.com/nodejs/node/issues/33460
248
+ * @see https://github.com/nodejs/loaders/issues/26
249
+ */
250
+ const { root } = (0, path_1.parse)(process.cwd());
251
+ let path = process.cwd();
252
+ const localPaths = [(0, path_1.join)(path, 'node_modules')];
253
+ while (path !== root) {
254
+ path = (0, path_1.dirname)(path);
255
+ localPaths.push((0, path_1.join)(path, 'node_modules'));
256
+ }
257
+ for (const localPath of localPaths) {
258
+ const pkgPath = (0, path_1.join)(localPath, pkgName, 'package.json');
259
+ if ((0, fs_1.existsSync)(pkgPath)) {
260
+ return require(pkgPath)?.version;
261
+ }
262
+ }
263
+ return undefined;
264
+ }
265
+ catch {
266
+ return undefined;
267
+ }
268
+ };
269
+ const getInfo = async (pkg, options) => {
270
+ const i = pkg.lastIndexOf('@');
271
+ let pkgInfo = {
272
+ name: i > 1 ? pkg.slice(0, i) : pkg,
273
+ wantedTagOrRange: i > 1 ? pkg.slice(i + 1) : 'latest',
274
+ updatesAvailable: false,
275
+ };
276
+ try {
277
+ pkgInfo = {
278
+ ...pkgInfo,
279
+ local: getInstalledVersion(pkgInfo.name, 'local'),
280
+ globalNpm: getInstalledVersion(pkgInfo.name, 'globalNpm'),
281
+ globalYarn: getInstalledVersion(pkgInfo.name, 'globalYarn'),
282
+ ...(await getRegistryVersions(pkgInfo.name, pkgInfo.wantedTagOrRange, options)),
283
+ };
284
+ const local = pkgInfo.local && pkgInfo.wanted
285
+ ? gt(pkgInfo.wanted, pkgInfo.local)
286
+ ? pkgInfo.wanted
287
+ : false
288
+ : false;
289
+ const globalNpm = pkgInfo.globalNpm && pkgInfo.wanted
290
+ ? gt(pkgInfo.wanted, pkgInfo.globalNpm)
291
+ ? pkgInfo.wanted
292
+ : false
293
+ : false;
294
+ const globalYarn = pkgInfo.globalYarn && pkgInfo.wanted
295
+ ? gt(pkgInfo.wanted, pkgInfo.globalYarn)
296
+ ? pkgInfo.wanted
297
+ : false
298
+ : false;
299
+ pkgInfo.updatesAvailable =
300
+ local || globalNpm || globalYarn
301
+ ? { local, globalNpm, globalYarn }
302
+ : false;
303
+ }
304
+ catch (err) {
305
+ pkgInfo.error = err?.message ?? err;
306
+ }
307
+ return pkgInfo;
308
+ };
309
+ const latestVersion = async (arg, options) => {
310
+ const pkgs = [];
311
+ if (typeof arg === 'string') {
312
+ pkgs.push(arg);
313
+ }
314
+ else if (Array.isArray(arg)) {
315
+ pkgs.push(...arg);
316
+ }
317
+ else if (isPackageJson(arg)) {
318
+ const addDeps = (deps) => {
319
+ if (deps) {
320
+ pkgs.push(...Object.keys(deps).map((key) => `${key}@${deps[key]}`));
321
+ }
322
+ };
323
+ addDeps(arg.dependencies);
324
+ addDeps(arg.devDependencies);
325
+ addDeps(arg.peerDependencies);
326
+ }
327
+ const jobs = await Promise.allSettled(pkgs.map((pkg) => getInfo(pkg, options)));
328
+ const results = jobs.map((jobResult) => jobResult.value);
329
+ return typeof arg === 'string' ? results[0] : results;
330
+ };
331
+ exports.default = latestVersion;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * [INPUT]: 依赖 CLI 参数对象与字符串/布尔/列表的约定
3
+ * [OUTPUT]: 对外提供命令选项读取、校验和对象状态转换函数
4
+ * [POS]: CLI 参数基础设施,统一命令模块的输入边界,不了解具体命令业务
5
+ */
6
+ export declare function getBooleanOption(options: Record<string, unknown>, key: string, fallback?: boolean): boolean;
7
+ export declare function getStringOption(options: Record<string, unknown>, key: string, fallback?: string): string;
8
+ export declare function getOptionalStringOption(options: Record<string, unknown>, key: string): string | undefined;
9
+ export declare function getStringListOption(options: Record<string, unknown>, key: string): string[] | undefined;
10
+ export declare function toObjectState<T extends Record<string, unknown>>(value: unknown, fallback: T): T;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * [INPUT]: 依赖 CLI 参数对象与字符串/布尔/列表的约定
4
+ * [OUTPUT]: 对外提供命令选项读取、校验和对象状态转换函数
5
+ * [POS]: CLI 参数基础设施,统一命令模块的输入边界,不了解具体命令业务
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.getBooleanOption = getBooleanOption;
9
+ exports.getStringOption = getStringOption;
10
+ exports.getOptionalStringOption = getOptionalStringOption;
11
+ exports.getStringListOption = getStringListOption;
12
+ exports.toObjectState = toObjectState;
13
+ function getBooleanOption(options, key, fallback = false) {
14
+ const value = options[key];
15
+ if (typeof value === 'boolean') {
16
+ return value;
17
+ }
18
+ if (typeof value === 'string') {
19
+ return value.toLowerCase() === 'true';
20
+ }
21
+ if (typeof value === 'number') {
22
+ return value !== 0;
23
+ }
24
+ return fallback;
25
+ }
26
+ function getStringOption(options, key, fallback = '') {
27
+ const value = options[key];
28
+ if (typeof value === 'string') {
29
+ return value;
30
+ }
31
+ if (typeof value === 'number' || typeof value === 'boolean') {
32
+ return String(value);
33
+ }
34
+ return fallback;
35
+ }
36
+ function getOptionalStringOption(options, key) {
37
+ const value = options[key];
38
+ if (typeof value === 'string') {
39
+ return value || undefined;
40
+ }
41
+ if (typeof value === 'number' || typeof value === 'boolean') {
42
+ return String(value);
43
+ }
44
+ return undefined;
45
+ }
46
+ function getStringListOption(options, key) {
47
+ const value = options[key];
48
+ const rawValues = Array.isArray(value) ? value : [value];
49
+ const result = rawValues.flatMap((item) => {
50
+ if (typeof item === 'string') {
51
+ return item
52
+ .split(',')
53
+ .map((value) => value.trim())
54
+ .filter(Boolean);
55
+ }
56
+ if (typeof item === 'number' || typeof item === 'boolean') {
57
+ return [String(item)];
58
+ }
59
+ return [];
60
+ });
61
+ return result.length > 0 ? result : undefined;
62
+ }
63
+ function toObjectState(value, fallback) {
64
+ if (value && typeof value === 'object') {
65
+ return value;
66
+ }
67
+ return fallback;
68
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * [INPUT]: 依赖文件系统与 CLI 插件配置文件格式
3
+ * [OUTPUT]: 对外提供 plugins,声明可参与 bundle 的插件及其参数映射
4
+ * [POS]: CLI 插件注册配置,只描述已支持的集成,不执行插件逻辑
5
+ */
6
+ interface PluginConfig {
7
+ name: string;
8
+ bundleParams?: {
9
+ [key: string]: any;
10
+ };
11
+ detect: () => Promise<boolean>;
12
+ }
13
+ export declare const plugins: PluginConfig[];
14
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /**
3
+ * [INPUT]: 依赖文件系统与 CLI 插件配置文件格式
4
+ * [OUTPUT]: 对外提供 plugins,声明可参与 bundle 的插件及其参数映射
5
+ * [POS]: CLI 插件注册配置,只描述已支持的集成,不执行插件逻辑
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.plugins = void 0;
42
+ const fs = __importStar(require("fs-extra"));
43
+ exports.plugins = [
44
+ {
45
+ name: 'sentry',
46
+ bundleParams: {
47
+ sentry: true,
48
+ sourcemap: true,
49
+ },
50
+ detect: async () => {
51
+ try {
52
+ await fs.access('ios/sentry.properties');
53
+ return true;
54
+ }
55
+ catch {
56
+ try {
57
+ await fs.access('android/sentry.properties');
58
+ return true;
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ }
64
+ },
65
+ },
66
+ ];