react-native-update-cli 2.14.1 → 2.15.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.
- package/cli.json +24 -0
- package/lib/bundle-runner.d.ts +17 -2
- package/lib/bundle-runner.js +52 -10
- package/lib/bundle.js +20 -5
- package/lib/diff.js +12 -1
- package/lib/provider.js +4 -1
- package/lib/types.d.ts +3 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +29 -16
- package/lib/utils/sentry-release.d.ts +15 -0
- package/lib/utils/sentry-release.js +262 -0
- package/package.json +3 -3
- package/src/api.ts +1 -2
- package/src/bundle-runner.ts +89 -20
- package/src/bundle.ts +46 -0
- package/src/diff.ts +13 -2
- package/src/locales/en.ts +2 -1
- package/src/locales/zh.ts +2 -1
- package/src/provider.ts +3 -0
- package/src/types.ts +3 -0
- package/src/utils/index.ts +31 -18
- package/src/utils/sentry-release.ts +381 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
const g2js: {
|
|
5
|
+
parseFile: (filePath: string) => Promise<unknown>;
|
|
6
|
+
} = require('gradle-to-js/lib/parser');
|
|
7
|
+
const properties: {
|
|
8
|
+
parse: (content: string) => Record<string, unknown>;
|
|
9
|
+
} = require('properties');
|
|
10
|
+
|
|
11
|
+
export interface SentryReleaseOptions {
|
|
12
|
+
sentryRelease?: string;
|
|
13
|
+
sentryDist?: string;
|
|
14
|
+
sentryFlavor?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ResolvedSentryRelease {
|
|
18
|
+
release: string;
|
|
19
|
+
dist?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type GradleObject = Record<string, unknown>;
|
|
23
|
+
|
|
24
|
+
type GradleResolveContext = {
|
|
25
|
+
appConfig: GradleObject;
|
|
26
|
+
rootConfig: GradleObject;
|
|
27
|
+
gradleProperties: GradleObject;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type AndroidVariantSelection = {
|
|
31
|
+
flavorConfig?: GradleObject;
|
|
32
|
+
buildTypeConfig?: GradleObject;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function normalizeString(value: string | undefined): string | undefined {
|
|
36
|
+
const normalized = value?.trim();
|
|
37
|
+
return normalized ? normalized : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function firstString(...values: Array<string | undefined>): string | undefined {
|
|
41
|
+
return values.map(normalizeString).find(Boolean);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function asObject(value: unknown): GradleObject | undefined {
|
|
45
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
46
|
+
return value as GradleObject;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function asGradleScalar(value: unknown): string | undefined {
|
|
52
|
+
if (typeof value === 'string') {
|
|
53
|
+
return normalizeString(value);
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
56
|
+
return String(value);
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getObjectValue(
|
|
62
|
+
object: GradleObject | undefined,
|
|
63
|
+
key: string,
|
|
64
|
+
): unknown {
|
|
65
|
+
return object?.[key];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getObjectBlock(
|
|
69
|
+
object: GradleObject | undefined,
|
|
70
|
+
key: string,
|
|
71
|
+
): GradleObject | undefined {
|
|
72
|
+
return asObject(getObjectValue(object, key));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function findKeyCaseInsensitive(
|
|
76
|
+
object: GradleObject | undefined,
|
|
77
|
+
key: string,
|
|
78
|
+
): string | undefined {
|
|
79
|
+
const normalized = key.toLowerCase();
|
|
80
|
+
return Object.keys(object ?? {}).find(
|
|
81
|
+
(candidate) => candidate.toLowerCase() === normalized,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getBlockCaseInsensitive(
|
|
86
|
+
object: GradleObject | undefined,
|
|
87
|
+
key: string | undefined,
|
|
88
|
+
): GradleObject | undefined {
|
|
89
|
+
if (!key) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const resolvedKey = findKeyCaseInsensitive(object, key);
|
|
94
|
+
return resolvedKey ? getObjectBlock(object, resolvedKey) : undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function parsePropertiesFile(filePath: string): GradleObject {
|
|
98
|
+
if (!fs.existsSync(filePath)) {
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
return properties.parse(fs.readFileSync(filePath, 'utf8'));
|
|
104
|
+
} catch {
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function parseGradleFile(filePath: string): Promise<GradleObject> {
|
|
110
|
+
if (!fs.existsSync(filePath)) {
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
return asObject(await g2js.parseFile(filePath)) ?? {};
|
|
116
|
+
} catch {
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function readGradleProperties(projectRoot: string): GradleObject {
|
|
122
|
+
return {
|
|
123
|
+
...parsePropertiesFile(path.join(projectRoot, 'gradle.properties')),
|
|
124
|
+
...parsePropertiesFile(
|
|
125
|
+
path.join(projectRoot, 'android', 'gradle.properties'),
|
|
126
|
+
),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function findExtValue(
|
|
131
|
+
propertyName: string,
|
|
132
|
+
context: GradleResolveContext,
|
|
133
|
+
): unknown {
|
|
134
|
+
const appExt = getObjectBlock(context.appConfig, 'ext');
|
|
135
|
+
const rootExt = getObjectBlock(context.rootConfig, 'ext');
|
|
136
|
+
const buildscriptExt = getObjectBlock(
|
|
137
|
+
getObjectBlock(context.rootConfig, 'buildscript'),
|
|
138
|
+
'ext',
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
getObjectValue(appExt, propertyName) ??
|
|
143
|
+
getObjectValue(rootExt, propertyName) ??
|
|
144
|
+
getObjectValue(buildscriptExt, propertyName) ??
|
|
145
|
+
getObjectValue(context.gradleProperties, propertyName)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function resolveGradleScalar(
|
|
150
|
+
value: unknown,
|
|
151
|
+
context: GradleResolveContext,
|
|
152
|
+
): string | undefined {
|
|
153
|
+
const raw = asGradleScalar(value);
|
|
154
|
+
if (!raw) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const extReference = raw.match(
|
|
159
|
+
/^(?:rootProject\.|project\.)?ext\.([A-Za-z_][\w]*)$/,
|
|
160
|
+
);
|
|
161
|
+
if (extReference) {
|
|
162
|
+
return resolveGradleScalar(findExtValue(extReference[1], context), context);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const directProperty = getObjectValue(context.gradleProperties, raw);
|
|
166
|
+
if (directProperty !== undefined) {
|
|
167
|
+
return resolveGradleScalar(directProperty, context);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (/[(){}?=]/.test(raw) || raw.includes(' ')) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return raw;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function pickAndroidVariant(
|
|
178
|
+
productFlavors: GradleObject | undefined,
|
|
179
|
+
buildTypes: GradleObject | undefined,
|
|
180
|
+
flavorOrVariant: string | undefined,
|
|
181
|
+
): AndroidVariantSelection | undefined {
|
|
182
|
+
const defaultBuildTypeName = findKeyCaseInsensitive(buildTypes, 'release');
|
|
183
|
+
|
|
184
|
+
if (!flavorOrVariant) {
|
|
185
|
+
const flavorNames = Object.keys(productFlavors ?? {});
|
|
186
|
+
const onlyFlavor = flavorNames.length === 1 ? flavorNames[0] : undefined;
|
|
187
|
+
return {
|
|
188
|
+
flavorConfig: getBlockCaseInsensitive(productFlavors, onlyFlavor),
|
|
189
|
+
buildTypeConfig: getBlockCaseInsensitive(
|
|
190
|
+
buildTypes,
|
|
191
|
+
defaultBuildTypeName,
|
|
192
|
+
),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const exactFlavor = findKeyCaseInsensitive(productFlavors, flavorOrVariant);
|
|
197
|
+
if (exactFlavor) {
|
|
198
|
+
return {
|
|
199
|
+
flavorConfig: getObjectBlock(productFlavors, exactFlavor),
|
|
200
|
+
buildTypeConfig: getBlockCaseInsensitive(
|
|
201
|
+
buildTypes,
|
|
202
|
+
defaultBuildTypeName,
|
|
203
|
+
),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const exactBuildType = findKeyCaseInsensitive(buildTypes, flavorOrVariant);
|
|
208
|
+
if (exactBuildType) {
|
|
209
|
+
return {
|
|
210
|
+
buildTypeConfig: getObjectBlock(buildTypes, exactBuildType),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
for (const buildTypeName of Object.keys(buildTypes ?? {}).sort(
|
|
215
|
+
(a, b) => b.length - a.length,
|
|
216
|
+
)) {
|
|
217
|
+
if (
|
|
218
|
+
flavorOrVariant.toLowerCase().endsWith(buildTypeName.toLowerCase()) &&
|
|
219
|
+
flavorOrVariant.length > buildTypeName.length
|
|
220
|
+
) {
|
|
221
|
+
const flavorName = flavorOrVariant.slice(
|
|
222
|
+
0,
|
|
223
|
+
flavorOrVariant.length - buildTypeName.length,
|
|
224
|
+
);
|
|
225
|
+
const variantFlavor = findKeyCaseInsensitive(productFlavors, flavorName);
|
|
226
|
+
if (variantFlavor) {
|
|
227
|
+
return {
|
|
228
|
+
flavorConfig: getObjectBlock(productFlavors, variantFlavor),
|
|
229
|
+
buildTypeConfig: getObjectBlock(buildTypes, buildTypeName),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function appendResolvedSuffix(
|
|
239
|
+
value: string,
|
|
240
|
+
suffixSource: unknown,
|
|
241
|
+
context: GradleResolveContext,
|
|
242
|
+
): string {
|
|
243
|
+
const suffix = resolveGradleScalar(suffixSource, context);
|
|
244
|
+
return suffix ? `${value}${suffix}` : value;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export async function resolveAndroidSentryReleaseAndDist({
|
|
248
|
+
projectRoot = process.cwd(),
|
|
249
|
+
flavor,
|
|
250
|
+
dist,
|
|
251
|
+
}: {
|
|
252
|
+
projectRoot?: string;
|
|
253
|
+
flavor?: string;
|
|
254
|
+
dist?: string;
|
|
255
|
+
} = {}): Promise<ResolvedSentryRelease | undefined> {
|
|
256
|
+
const appGradlePath = path.join(
|
|
257
|
+
projectRoot,
|
|
258
|
+
'android',
|
|
259
|
+
'app',
|
|
260
|
+
'build.gradle',
|
|
261
|
+
);
|
|
262
|
+
const rootGradlePath = path.join(projectRoot, 'android', 'build.gradle');
|
|
263
|
+
const appConfig = await parseGradleFile(appGradlePath);
|
|
264
|
+
const rootConfig = await parseGradleFile(rootGradlePath);
|
|
265
|
+
const androidConfig = getObjectBlock(appConfig, 'android');
|
|
266
|
+
const defaultConfig = getObjectBlock(androidConfig, 'defaultConfig');
|
|
267
|
+
if (!androidConfig || !defaultConfig) {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const context: GradleResolveContext = {
|
|
272
|
+
appConfig,
|
|
273
|
+
rootConfig,
|
|
274
|
+
gradleProperties: readGradleProperties(projectRoot),
|
|
275
|
+
};
|
|
276
|
+
const selection = pickAndroidVariant(
|
|
277
|
+
getObjectBlock(androidConfig, 'productFlavors'),
|
|
278
|
+
getObjectBlock(androidConfig, 'buildTypes'),
|
|
279
|
+
normalizeString(flavor),
|
|
280
|
+
);
|
|
281
|
+
if (!selection) {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const { flavorConfig, buildTypeConfig } = selection;
|
|
286
|
+
let applicationId =
|
|
287
|
+
resolveGradleScalar(
|
|
288
|
+
getObjectValue(flavorConfig, 'applicationId'),
|
|
289
|
+
context,
|
|
290
|
+
) ??
|
|
291
|
+
resolveGradleScalar(
|
|
292
|
+
getObjectValue(defaultConfig, 'applicationId'),
|
|
293
|
+
context,
|
|
294
|
+
) ??
|
|
295
|
+
resolveGradleScalar(getObjectValue(androidConfig, 'namespace'), context);
|
|
296
|
+
let versionName =
|
|
297
|
+
resolveGradleScalar(getObjectValue(flavorConfig, 'versionName'), context) ??
|
|
298
|
+
resolveGradleScalar(getObjectValue(defaultConfig, 'versionName'), context);
|
|
299
|
+
const versionCode =
|
|
300
|
+
normalizeString(dist) ??
|
|
301
|
+
resolveGradleScalar(getObjectValue(flavorConfig, 'versionCode'), context) ??
|
|
302
|
+
resolveGradleScalar(getObjectValue(defaultConfig, 'versionCode'), context);
|
|
303
|
+
|
|
304
|
+
if (!applicationId || !versionName || !versionCode) {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
applicationId = appendResolvedSuffix(
|
|
309
|
+
applicationId,
|
|
310
|
+
getObjectValue(flavorConfig, 'applicationIdSuffix'),
|
|
311
|
+
context,
|
|
312
|
+
);
|
|
313
|
+
applicationId = appendResolvedSuffix(
|
|
314
|
+
applicationId,
|
|
315
|
+
getObjectValue(buildTypeConfig, 'applicationIdSuffix'),
|
|
316
|
+
context,
|
|
317
|
+
);
|
|
318
|
+
versionName = appendResolvedSuffix(
|
|
319
|
+
versionName,
|
|
320
|
+
getObjectValue(flavorConfig, 'versionNameSuffix'),
|
|
321
|
+
context,
|
|
322
|
+
);
|
|
323
|
+
versionName = appendResolvedSuffix(
|
|
324
|
+
versionName,
|
|
325
|
+
getObjectValue(buildTypeConfig, 'versionNameSuffix'),
|
|
326
|
+
context,
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
release: `${applicationId}@${versionName}+${versionCode}`,
|
|
331
|
+
dist: versionCode,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export async function resolveSentryReleaseAndDist(
|
|
336
|
+
platform: string,
|
|
337
|
+
fallbackVersion: string,
|
|
338
|
+
options: SentryReleaseOptions = {},
|
|
339
|
+
projectRoot = process.cwd(),
|
|
340
|
+
): Promise<ResolvedSentryRelease> {
|
|
341
|
+
const releaseOverride = firstString(
|
|
342
|
+
options.sentryRelease,
|
|
343
|
+
process.env.SENTRY_RELEASE,
|
|
344
|
+
);
|
|
345
|
+
const distOverride = firstString(options.sentryDist, process.env.SENTRY_DIST);
|
|
346
|
+
|
|
347
|
+
if (releaseOverride) {
|
|
348
|
+
return {
|
|
349
|
+
release: releaseOverride,
|
|
350
|
+
dist: distOverride,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (platform === 'android') {
|
|
355
|
+
const androidRelease = await resolveAndroidSentryReleaseAndDist({
|
|
356
|
+
projectRoot,
|
|
357
|
+
flavor: firstString(
|
|
358
|
+
options.sentryFlavor,
|
|
359
|
+
process.env.PUSHY_SENTRY_FLAVOR,
|
|
360
|
+
process.env.SENTRY_FLAVOR,
|
|
361
|
+
),
|
|
362
|
+
dist: distOverride,
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
if (androidRelease) {
|
|
366
|
+
console.log(
|
|
367
|
+
`[pushy/sentry] Using Android native release=${androidRelease.release}, dist=${androidRelease.dist}`,
|
|
368
|
+
);
|
|
369
|
+
return androidRelease;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
console.warn(
|
|
374
|
+
`[pushy/sentry] Falling back to Pushy version "${fallbackVersion}" as Sentry release. ` +
|
|
375
|
+
'Set --sentry-release/--sentry-dist, SENTRY_RELEASE/SENTRY_DIST, or --sentry-flavor/PUSHY_SENTRY_FLAVOR for OTA symbolication.',
|
|
376
|
+
);
|
|
377
|
+
return {
|
|
378
|
+
release: fallbackVersion,
|
|
379
|
+
dist: distOverride,
|
|
380
|
+
};
|
|
381
|
+
}
|