react-native-update-cli 2.24.1 → 2.25.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.
- package/README.md +11 -4
- package/README.zh-CN.md +11 -4
- package/cli.json +7 -1
- package/lib/api.d.ts +2 -0
- package/lib/api.js +63 -18
- package/lib/app.js +25 -3
- package/lib/bin.js +39 -45
- package/lib/bundle-runner.d.ts +27 -0
- package/lib/bundle-runner.js +240 -21
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +19 -6
- package/lib/commands.d.ts +6 -0
- package/lib/commands.js +65 -0
- package/lib/locales/en.d.ts +5 -14
- package/lib/locales/en.js +5 -14
- package/lib/locales/zh.d.ts +5 -13
- package/lib/locales/zh.js +5 -13
- package/lib/package.js +4 -0
- package/lib/provider.d.ts +1 -1
- package/lib/provider.js +3 -1
- package/lib/symbolicate.js +11 -3
- package/lib/types.d.ts +1 -0
- package/lib/user.js +6 -0
- package/lib/utils/add-gitignore.js +7 -1
- package/lib/utils/dep-versions.d.ts +7 -0
- package/lib/utils/dep-versions.js +78 -26
- package/lib/utils/git.js +9 -6
- package/lib/utils/hermes-base.js +2 -1
- package/lib/utils/i18n.d.ts +5 -0
- package/lib/utils/i18n.js +14 -1
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +9 -4
- package/lib/utils/latest-version/index.js +8 -0
- package/lib/utils/runtime.d.ts +21 -0
- package/lib/utils/runtime.js +138 -5
- package/lib/utils/slim-sourcemap.d.ts +11 -0
- package/lib/utils/slim-sourcemap.js +22 -0
- package/lib/utils/zip-range.js +3 -2
- package/lib/versions.js +16 -15
- package/package.json +4 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -17
- package/src/api.ts +0 -470
- package/src/app.ts +0 -241
- package/src/auto-update.ts +0 -647
- package/src/bin-cresc.ts +0 -8
- package/src/bin.ts +0 -115
- package/src/bundle-pack.ts +0 -61
- package/src/bundle-runner.ts +0 -1430
- package/src/bundle.ts +0 -371
- package/src/cache.ts +0 -20
- package/src/diff.ts +0 -1010
- package/src/exports.ts +0 -17
- package/src/index.ts +0 -1
- package/src/install.ts +0 -50
- package/src/locales/en.ts +0 -257
- package/src/locales/zh.ts +0 -234
- package/src/native-package.ts +0 -338
- package/src/package.ts +0 -482
- package/src/provider.ts +0 -294
- package/src/symbolicate.ts +0 -159
- package/src/types.ts +0 -150
- package/src/user.ts +0 -39
- package/src/utils/add-gitignore.ts +0 -35
- package/src/utils/app-info-parser/aab.ts +0 -241
- package/src/utils/app-info-parser/apk.ts +0 -92
- package/src/utils/app-info-parser/app.ts +0 -7
- package/src/utils/app-info-parser/index.ts +0 -54
- package/src/utils/app-info-parser/ipa.ts +0 -109
- package/src/utils/app-info-parser/resource-finder.ts +0 -508
- package/src/utils/app-info-parser/utils.ts +0 -161
- package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
- package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
- package/src/utils/app-info-parser/zip.ts +0 -108
- package/src/utils/check-lockfile.ts +0 -93
- package/src/utils/check-plugin.ts +0 -38
- package/src/utils/command-result.ts +0 -24
- package/src/utils/constants.ts +0 -25
- package/src/utils/dep-versions.ts +0 -83
- package/src/utils/git.ts +0 -71
- package/src/utils/hbcTransform.ts +0 -649
- package/src/utils/hermes-base.ts +0 -1137
- package/src/utils/http-helper.ts +0 -152
- package/src/utils/i18n.ts +0 -39
- package/src/utils/index.ts +0 -698
- package/src/utils/latest-version/index.ts +0 -573
- package/src/utils/options.ts +0 -78
- package/src/utils/plugin-config.ts +0 -32
- package/src/utils/runtime.ts +0 -187
- package/src/utils/slim-sourcemap.ts +0 -83
- package/src/utils/zip-entries.ts +0 -209
- package/src/utils/zip-options.ts +0 -178
- package/src/utils/zip-range.ts +0 -727
- package/src/utils/zip-raw-writer.ts +0 -247
- package/src/versions.ts +0 -894
package/src/bundle-runner.ts
DELETED
|
@@ -1,1430 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
import { satisfies } from 'compare-versions';
|
|
3
|
-
import * as fs from 'fs-extra';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { getHermesBase } from './api';
|
|
7
|
-
import {
|
|
8
|
-
classifyHermesCommand,
|
|
9
|
-
type HermesBaseOption,
|
|
10
|
-
type HermesBaseSelection,
|
|
11
|
-
hermescArgsWithBase,
|
|
12
|
-
probeHbcVersion,
|
|
13
|
-
resolveHermesBase,
|
|
14
|
-
verifyHermesBaseEquivalence,
|
|
15
|
-
} from './utils/hermes-base';
|
|
16
|
-
import { t } from './utils/i18n';
|
|
17
|
-
import {
|
|
18
|
-
getJavaScriptRuntime,
|
|
19
|
-
spawnJavaScript,
|
|
20
|
-
spawnJavaScriptSync,
|
|
21
|
-
} from './utils/runtime';
|
|
22
|
-
|
|
23
|
-
const g2js = require('gradle-to-js/lib/parser');
|
|
24
|
-
const properties = require('properties');
|
|
25
|
-
|
|
26
|
-
export interface BundleCliOptions {
|
|
27
|
-
taro?: boolean;
|
|
28
|
-
expo?: boolean;
|
|
29
|
-
rncli?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface RunBundleCommandOptions {
|
|
33
|
-
bundleName: string;
|
|
34
|
-
dev: string;
|
|
35
|
-
entryFile: string;
|
|
36
|
-
outputFolder: string;
|
|
37
|
-
platform: string;
|
|
38
|
-
sourcemapOutput: string;
|
|
39
|
-
config?: string;
|
|
40
|
-
forceHermes?: boolean;
|
|
41
|
-
/** Hermes -base-bytecode settings; omitted → compile without a base */
|
|
42
|
-
hermesBase?: HermesBaseRequest;
|
|
43
|
-
/** pass --reset-cache to Metro (default true); false reuses its transform cache */
|
|
44
|
-
resetCache?: boolean;
|
|
45
|
-
cli: BundleCliOptions;
|
|
46
|
-
isSentry: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface HermesBaseRequest {
|
|
50
|
-
option: HermesBaseOption;
|
|
51
|
-
appId?: string;
|
|
52
|
-
verify: boolean;
|
|
53
|
-
cacheMaxMb?: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface HermesCompileResult {
|
|
57
|
-
bytecodeVersion: number | null;
|
|
58
|
-
base: HermesBaseSelection | null;
|
|
59
|
-
/** true when --verifyHermesBase ran and passed; false when it failed (base dropped) */
|
|
60
|
-
verified?: boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Outcome of picking a base: what to compile with, plus the log lines. */
|
|
64
|
-
export interface HermesBaseSelectionResult {
|
|
65
|
-
base: HermesBaseSelection | null;
|
|
66
|
-
bytecodeVersion: number | null;
|
|
67
|
-
/** messages to print when the compile phase starts (kept out of Metro's output) */
|
|
68
|
-
logs: string[];
|
|
69
|
-
/** the hermesc the selection was made with (the compile reuses it) */
|
|
70
|
-
hermesCommand?: string;
|
|
71
|
-
/** hermesc could not be resolved; the compile phase will report it */
|
|
72
|
-
commandUnavailable?: boolean;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
interface GradleConfig {
|
|
76
|
-
crunchPngs?: boolean;
|
|
77
|
-
enableHermes?: boolean;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const dependencyFields = [
|
|
81
|
-
'dependencies',
|
|
82
|
-
'devDependencies',
|
|
83
|
-
'peerDependencies',
|
|
84
|
-
'optionalDependencies',
|
|
85
|
-
] as const;
|
|
86
|
-
|
|
87
|
-
type SyncProcessResult = {
|
|
88
|
-
status: number | null;
|
|
89
|
-
signal: NodeJS.Signals | null;
|
|
90
|
-
error?: Error;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
type ResolvedExpoCli = {
|
|
94
|
-
cliPath: string;
|
|
95
|
-
usingExpo: boolean;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
type SentryUploadArtifacts = {
|
|
99
|
-
bundlePath: string;
|
|
100
|
-
sourcemapPath: string;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
type BuildSentrySourcemapsUploadArgsOptions = {
|
|
104
|
-
sentryCliPath: string;
|
|
105
|
-
bundlePath: string;
|
|
106
|
-
sourcemapPath: string;
|
|
107
|
-
release?: string;
|
|
108
|
-
dist?: string;
|
|
109
|
-
stripPrefix?: string;
|
|
110
|
-
debugIdReference?: boolean;
|
|
111
|
-
useStandaloneSourcemapsCommand?: boolean;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const ANDROID_SENTRY_BUNDLE_NAME = 'index.android.bundle';
|
|
115
|
-
|
|
116
|
-
export interface SentryUploadOptions {
|
|
117
|
-
sentryRelease?: string;
|
|
118
|
-
sentryDist?: string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
type SentryUploadMode =
|
|
122
|
-
| {
|
|
123
|
-
type: 'debug-id';
|
|
124
|
-
debugId: string;
|
|
125
|
-
}
|
|
126
|
-
| {
|
|
127
|
-
type: 'release';
|
|
128
|
-
release: string;
|
|
129
|
-
dist?: string;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export function hasProjectDependency(
|
|
133
|
-
dependencyName: string,
|
|
134
|
-
projectRoot = process.cwd(),
|
|
135
|
-
): boolean {
|
|
136
|
-
try {
|
|
137
|
-
const packageJson = JSON.parse(
|
|
138
|
-
fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'),
|
|
139
|
-
) as Record<string, unknown>;
|
|
140
|
-
|
|
141
|
-
return dependencyFields.some((field) => {
|
|
142
|
-
const dependencies = packageJson[field];
|
|
143
|
-
if (typeof dependencies !== 'object' || dependencies === null) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
return dependencyName in dependencies;
|
|
147
|
-
});
|
|
148
|
-
} catch {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function resolveExpoCli(projectRoot = process.cwd()): ResolvedExpoCli {
|
|
154
|
-
if (!hasProjectDependency('expo', projectRoot)) {
|
|
155
|
-
return {
|
|
156
|
-
cliPath: '',
|
|
157
|
-
usingExpo: false,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
const searchPaths = [projectRoot];
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
const expoPackageJsonPath = require.resolve('expo/package.json', {
|
|
166
|
-
paths: [projectRoot],
|
|
167
|
-
});
|
|
168
|
-
searchPaths.push(path.dirname(expoPackageJsonPath));
|
|
169
|
-
} catch {
|
|
170
|
-
// expo 包不存在,忽略
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const cliPath = require.resolve('@expo/cli', {
|
|
174
|
-
paths: searchPaths,
|
|
175
|
-
});
|
|
176
|
-
const expoCliVersion = JSON.parse(
|
|
177
|
-
fs.readFileSync(
|
|
178
|
-
require.resolve('@expo/cli/package.json', {
|
|
179
|
-
paths: searchPaths,
|
|
180
|
-
}),
|
|
181
|
-
'utf8',
|
|
182
|
-
),
|
|
183
|
-
).version;
|
|
184
|
-
|
|
185
|
-
if (!satisfies(expoCliVersion, '>= 0.10.17')) {
|
|
186
|
-
return {
|
|
187
|
-
cliPath: '',
|
|
188
|
-
usingExpo: false,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
cliPath,
|
|
194
|
-
usingExpo: true,
|
|
195
|
-
};
|
|
196
|
-
} catch {
|
|
197
|
-
return {
|
|
198
|
-
cliPath: '',
|
|
199
|
-
usingExpo: false,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export async function runReactNativeBundleCommand({
|
|
205
|
-
bundleName,
|
|
206
|
-
dev,
|
|
207
|
-
entryFile,
|
|
208
|
-
outputFolder,
|
|
209
|
-
platform,
|
|
210
|
-
sourcemapOutput,
|
|
211
|
-
config,
|
|
212
|
-
forceHermes,
|
|
213
|
-
hermesBase,
|
|
214
|
-
resetCache = true,
|
|
215
|
-
cli,
|
|
216
|
-
isSentry,
|
|
217
|
-
}: RunBundleCommandOptions): Promise<HermesCompileResult | null> {
|
|
218
|
-
let gradleConfig: GradleConfig = {};
|
|
219
|
-
if (platform === 'android') {
|
|
220
|
-
gradleConfig = await checkGradleConfig();
|
|
221
|
-
if (gradleConfig.crunchPngs !== false) {
|
|
222
|
-
console.warn(t('androidCrunchPngsWarning'));
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const reactNativeBundleArgs: string[] = [];
|
|
227
|
-
const envArgs = process.env.PUSHY_ENV_ARGS;
|
|
228
|
-
|
|
229
|
-
if (envArgs) {
|
|
230
|
-
reactNativeBundleArgs.push(...envArgs.trim().split(/\s+/));
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
fs.emptyDirSync(outputFolder);
|
|
234
|
-
|
|
235
|
-
let cliPath = '';
|
|
236
|
-
let usingExpo = false;
|
|
237
|
-
|
|
238
|
-
const getExpoCli = () => {
|
|
239
|
-
const resolvedExpoCli = resolveExpoCli();
|
|
240
|
-
cliPath = resolvedExpoCli.cliPath;
|
|
241
|
-
usingExpo = resolvedExpoCli.usingExpo;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const getRnCli = () => {
|
|
245
|
-
try {
|
|
246
|
-
cliPath = require.resolve('react-native/local-cli/cli.js', {
|
|
247
|
-
paths: [process.cwd()],
|
|
248
|
-
});
|
|
249
|
-
} catch {
|
|
250
|
-
cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
|
|
251
|
-
paths: [process.cwd()],
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const getTaroCli = () => {
|
|
257
|
-
try {
|
|
258
|
-
cliPath = require.resolve('@tarojs/cli/bin/taro', {
|
|
259
|
-
paths: [process.cwd()],
|
|
260
|
-
});
|
|
261
|
-
} catch {
|
|
262
|
-
// fallback 到 RN CLI
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
if (cli.expo) {
|
|
267
|
-
getExpoCli();
|
|
268
|
-
} else if (cli.taro) {
|
|
269
|
-
getTaroCli();
|
|
270
|
-
} else if (cli.rncli) {
|
|
271
|
-
getRnCli();
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (!cliPath) {
|
|
275
|
-
getExpoCli();
|
|
276
|
-
if (!usingExpo) {
|
|
277
|
-
getRnCli();
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (isSentry) {
|
|
282
|
-
if (platform === 'ios') {
|
|
283
|
-
process.env.SENTRY_PROPERTIES = 'ios/sentry.properties';
|
|
284
|
-
} else if (platform === 'android') {
|
|
285
|
-
process.env.SENTRY_PROPERTIES = 'android/sentry.properties';
|
|
286
|
-
} else if (
|
|
287
|
-
platform === 'harmony' &&
|
|
288
|
-
fs.existsSync('harmony/sentry.properties')
|
|
289
|
-
) {
|
|
290
|
-
process.env.SENTRY_PROPERTIES = 'harmony/sentry.properties';
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
let bundleCommand = 'bundle';
|
|
295
|
-
if (usingExpo) {
|
|
296
|
-
bundleCommand = 'export:embed';
|
|
297
|
-
} else if (platform === 'harmony') {
|
|
298
|
-
bundleCommand = 'bundle-harmony';
|
|
299
|
-
} else if (cli.taro) {
|
|
300
|
-
bundleCommand = 'build';
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (platform === 'harmony') {
|
|
304
|
-
bundleName = 'bundle.harmony.js';
|
|
305
|
-
if (forceHermes === undefined) {
|
|
306
|
-
forceHermes = true;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
reactNativeBundleArgs.push(
|
|
311
|
-
cliPath,
|
|
312
|
-
bundleCommand,
|
|
313
|
-
'--assets-dest',
|
|
314
|
-
outputFolder,
|
|
315
|
-
'--bundle-output',
|
|
316
|
-
path.join(outputFolder, bundleName),
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
if (platform !== 'harmony') {
|
|
320
|
-
reactNativeBundleArgs.push('--platform', platform);
|
|
321
|
-
if (resetCache) reactNativeBundleArgs.push('--reset-cache');
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (cli.taro) {
|
|
325
|
-
reactNativeBundleArgs.push('--type', 'rn');
|
|
326
|
-
} else {
|
|
327
|
-
reactNativeBundleArgs.push('--dev', dev, '--entry-file', entryFile);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (sourcemapOutput) {
|
|
331
|
-
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (config) {
|
|
335
|
-
reactNativeBundleArgs.push('--config', config);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// Decide about Hermes before Metro runs so the base lookup (server query,
|
|
339
|
-
// Range download, cache) overlaps the bundling instead of following it.
|
|
340
|
-
const hermesEnabled = await detectHermesEnabled(
|
|
341
|
-
platform,
|
|
342
|
-
forceHermes,
|
|
343
|
-
gradleConfig,
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
const jsRuntime = getJavaScriptRuntime();
|
|
347
|
-
const reactNativeBundleProcess = spawnJavaScript(reactNativeBundleArgs);
|
|
348
|
-
console.log(
|
|
349
|
-
`Running bundle command: ${jsRuntime} ${reactNativeBundleArgs.join(' ')}`,
|
|
350
|
-
);
|
|
351
|
-
// Metro is running; the synchronous head of the selection (hermesc lookup,
|
|
352
|
-
// HBC version probe) now overlaps it instead of delaying its start.
|
|
353
|
-
const pendingBase =
|
|
354
|
-
hermesEnabled && hermesBase
|
|
355
|
-
? startHermesBaseSelection(hermesBase)
|
|
356
|
-
: undefined;
|
|
357
|
-
|
|
358
|
-
let hermesResult: HermesCompileResult | null = null;
|
|
359
|
-
await new Promise<void>((resolve, reject) => {
|
|
360
|
-
reactNativeBundleProcess.stdout.on('data', (data) => {
|
|
361
|
-
console.log(data.toString().trim());
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
reactNativeBundleProcess.stderr.on('data', (data) => {
|
|
365
|
-
console.error(data.toString().trim());
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
reactNativeBundleProcess.once('error', reject);
|
|
369
|
-
|
|
370
|
-
reactNativeBundleProcess.on('close', async (exitCode) => {
|
|
371
|
-
if (exitCode) {
|
|
372
|
-
reject(new Error(t('bundleCommandError', { code: exitCode })));
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
try {
|
|
377
|
-
if (hermesEnabled) {
|
|
378
|
-
hermesResult = await compileHermesByteCode({
|
|
379
|
-
bundleName,
|
|
380
|
-
outputFolder,
|
|
381
|
-
sourcemapOutput,
|
|
382
|
-
shouldCleanSourcemap: !isSentry,
|
|
383
|
-
baseRequest: hermesBase,
|
|
384
|
-
pendingBase,
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
if (platform === 'harmony') {
|
|
389
|
-
const harmonyRawAssetsPath =
|
|
390
|
-
'harmony/entry/src/main/resources/rawfile/assets';
|
|
391
|
-
fs.ensureDirSync(harmonyRawAssetsPath);
|
|
392
|
-
fs.copySync(outputFolder, harmonyRawAssetsPath, {
|
|
393
|
-
overwrite: true,
|
|
394
|
-
// sourcemaps must not ship inside the native package
|
|
395
|
-
filter: (src) => !src.endsWith('.map'),
|
|
396
|
-
});
|
|
397
|
-
fs.moveSync(
|
|
398
|
-
`${harmonyRawAssetsPath}/bundle.harmony.js`,
|
|
399
|
-
`${harmonyRawAssetsPath}/../bundle.harmony.js`,
|
|
400
|
-
{ overwrite: true },
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
resolve();
|
|
405
|
-
} catch (error) {
|
|
406
|
-
reject(error);
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
return hermesResult;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
async function detectHermesEnabled(
|
|
414
|
-
platform: string,
|
|
415
|
-
forceHermes: boolean | undefined,
|
|
416
|
-
gradleConfig: GradleConfig,
|
|
417
|
-
): Promise<boolean> {
|
|
418
|
-
if (forceHermes) {
|
|
419
|
-
console.log(t('forceHermes'));
|
|
420
|
-
return true;
|
|
421
|
-
}
|
|
422
|
-
if (platform === 'android') {
|
|
423
|
-
const gradleProperties = await new Promise<{ hermesEnabled?: boolean }>(
|
|
424
|
-
(resolve) => {
|
|
425
|
-
properties.parse(
|
|
426
|
-
'./android/gradle.properties',
|
|
427
|
-
{ path: true },
|
|
428
|
-
(error: Error | null, props: { hermesEnabled?: boolean } = {}) => {
|
|
429
|
-
if (error) {
|
|
430
|
-
console.error(error);
|
|
431
|
-
resolve({});
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
resolve(props);
|
|
435
|
-
},
|
|
436
|
-
);
|
|
437
|
-
},
|
|
438
|
-
);
|
|
439
|
-
if (typeof gradleProperties.hermesEnabled === 'boolean') {
|
|
440
|
-
return gradleProperties.hermesEnabled;
|
|
441
|
-
}
|
|
442
|
-
return Boolean(gradleConfig.enableHermes);
|
|
443
|
-
}
|
|
444
|
-
if (platform === 'ios' && fs.existsSync('ios/Pods/hermes-engine')) {
|
|
445
|
-
return true;
|
|
446
|
-
}
|
|
447
|
-
return false;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function getHermesOSBin() {
|
|
451
|
-
if (os.platform() === 'win32') return 'win64-bin';
|
|
452
|
-
if (os.platform() === 'darwin') return 'osx-bin';
|
|
453
|
-
if (os.platform() === 'linux') return 'linux64-bin';
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function getHermesExecutableName() {
|
|
457
|
-
return os.platform() === 'win32' ? 'hermesc.exe' : 'hermesc';
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
function dirnameOfPackage(
|
|
461
|
-
packageJsonPath: string,
|
|
462
|
-
projectRoot = process.cwd(),
|
|
463
|
-
) {
|
|
464
|
-
return path.dirname(
|
|
465
|
-
require.resolve(packageJsonPath, {
|
|
466
|
-
paths: [projectRoot],
|
|
467
|
-
}),
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
function assertSuccessfulSyncProcess(
|
|
472
|
-
result: SyncProcessResult,
|
|
473
|
-
command: string,
|
|
474
|
-
) {
|
|
475
|
-
if (result.error) {
|
|
476
|
-
throw result.error;
|
|
477
|
-
}
|
|
478
|
-
if (result.status !== 0) {
|
|
479
|
-
throw new Error(
|
|
480
|
-
`${command} failed with ${
|
|
481
|
-
result.status === null
|
|
482
|
-
? `signal ${result.signal}`
|
|
483
|
-
: `exit code ${result.status}`
|
|
484
|
-
}`,
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function normalizeString(value: string | undefined): string | undefined {
|
|
490
|
-
const normalized = value?.trim();
|
|
491
|
-
return normalized ? normalized : undefined;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
export function resolveHermesCommand(projectRoot = process.cwd()): string {
|
|
495
|
-
const osBin = getHermesOSBin();
|
|
496
|
-
if (!osBin) {
|
|
497
|
-
throw new Error(
|
|
498
|
-
t('unsupportedPlatformForHermes', { platform: os.platform() }),
|
|
499
|
-
);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
const executableName = getHermesExecutableName();
|
|
503
|
-
const candidates: string[] = [];
|
|
504
|
-
|
|
505
|
-
try {
|
|
506
|
-
const rnDir = dirnameOfPackage('react-native/package.json', projectRoot);
|
|
507
|
-
candidates.push(path.join(rnDir, 'sdks', 'hermesc', osBin, executableName));
|
|
508
|
-
} catch {
|
|
509
|
-
// react-native is required for normal RN projects; keep looking so the
|
|
510
|
-
// final error can include all candidates we were able to infer.
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
try {
|
|
514
|
-
const hermesCompilerDir = dirnameOfPackage(
|
|
515
|
-
'hermes-compiler/package.json',
|
|
516
|
-
projectRoot,
|
|
517
|
-
);
|
|
518
|
-
candidates.push(
|
|
519
|
-
path.join(hermesCompilerDir, 'hermesc', osBin, executableName),
|
|
520
|
-
);
|
|
521
|
-
} catch {
|
|
522
|
-
// RN 0.85+ uses hermes-compiler, older projects may still use other paths.
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
try {
|
|
526
|
-
const hermesEngineDir = dirnameOfPackage(
|
|
527
|
-
'hermes-engine/package.json',
|
|
528
|
-
projectRoot,
|
|
529
|
-
);
|
|
530
|
-
candidates.push(
|
|
531
|
-
path.join(hermesEngineDir, osBin, executableName),
|
|
532
|
-
path.join(hermesEngineDir, 'hermesc', osBin, executableName),
|
|
533
|
-
);
|
|
534
|
-
} catch {
|
|
535
|
-
// RN 0.70-era projects commonly used hermes-engine; optional for newer RN.
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
const hermesCommand = candidates.find((candidate) =>
|
|
539
|
-
fs.existsSync(candidate),
|
|
540
|
-
);
|
|
541
|
-
if (hermesCommand) {
|
|
542
|
-
return hermesCommand;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
throw new Error(
|
|
546
|
-
`Cannot find hermesc. Tried:\n${candidates.map((candidate) => `- ${candidate}`).join('\n')}`,
|
|
547
|
-
);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
async function checkGradleConfig(): Promise<GradleConfig> {
|
|
551
|
-
let enableHermes = false;
|
|
552
|
-
let crunchPngs: boolean | undefined;
|
|
553
|
-
try {
|
|
554
|
-
const gradleConfig = await g2js.parseFile('android/app/build.gradle');
|
|
555
|
-
crunchPngs = gradleConfig.android.buildTypes.release.crunchPngs;
|
|
556
|
-
const projectConfig = gradleConfig['project.ext.react'];
|
|
557
|
-
if (projectConfig) {
|
|
558
|
-
for (const packagerConfig of projectConfig) {
|
|
559
|
-
if (
|
|
560
|
-
packagerConfig.includes('enableHermes') &&
|
|
561
|
-
packagerConfig.includes('true')
|
|
562
|
-
) {
|
|
563
|
-
enableHermes = true;
|
|
564
|
-
break;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
} catch {
|
|
569
|
-
// ignore parsing failures
|
|
570
|
-
}
|
|
571
|
-
return {
|
|
572
|
-
enableHermes,
|
|
573
|
-
crunchPngs,
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* hermesc argument policy. `-output-source-map` is always passed: hermesc then
|
|
579
|
-
* strips the debug info section from the bytecode (like React Native's own
|
|
580
|
-
* release builds, 15-40% smaller bytecode and smaller hot-update patches) and
|
|
581
|
-
* writes its own `<bundle>.map` next to the output. When the user asked for a
|
|
582
|
-
* sourcemap that file is composed with the packager map as before; otherwise it
|
|
583
|
-
* simply stays in the intermediate directory (never packed into the ppk) so
|
|
584
|
-
* `address at` stack frames can still be symbolicated later.
|
|
585
|
-
*/
|
|
586
|
-
/**
|
|
587
|
-
* hermesc echoes every diagnostic as three lines (header, the offending source
|
|
588
|
-
* line, a caret line). Minified bundles put a whole module on one line, so a
|
|
589
|
-
* single warning can be 100k+ characters and blindly keeping the tail of stderr
|
|
590
|
-
* buries the actual error under warning noise. Keep the diagnostic headers,
|
|
591
|
-
* prefer errors over warnings, and cap the length of whatever survives.
|
|
592
|
-
*/
|
|
593
|
-
export function summarizeHermescStderr(stderr: string): string {
|
|
594
|
-
const raw = String(stderr ?? '').split(/\r?\n/);
|
|
595
|
-
const kept: string[] = [];
|
|
596
|
-
for (let i = 0; i < raw.length; i++) {
|
|
597
|
-
const line = raw[i].trim();
|
|
598
|
-
if (!line) continue;
|
|
599
|
-
if (/^\^~*$/.test(line)) continue; // caret line
|
|
600
|
-
// the line before a caret is the echoed source, never the message
|
|
601
|
-
const next = raw[i + 1]?.trim();
|
|
602
|
-
if (next && /^\^~*$/.test(next)) continue;
|
|
603
|
-
kept.push(line.length > 300 ? `${line.slice(0, 300)}…` : line);
|
|
604
|
-
}
|
|
605
|
-
if (kept.length === 0) return '';
|
|
606
|
-
const isError = (line: string) =>
|
|
607
|
-
/(?::\s*|^)(?:fatal error|error)\b/i.test(line) ||
|
|
608
|
-
/^(?:Assertion|Stack dump|PLEASE submit a bug report)/i.test(line);
|
|
609
|
-
const errors = kept.filter(isError);
|
|
610
|
-
if (errors.length > 0) return errors.slice(-3).join(' ');
|
|
611
|
-
const notWarnings = kept.filter(
|
|
612
|
-
(line) => !/:\s*(?:warning|note):/i.test(line),
|
|
613
|
-
);
|
|
614
|
-
return (notWarnings.length > 0 ? notWarnings : kept).slice(-3).join(' ');
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/** hermesc arguments writing `bundlePath` from `input` (in place by default) */
|
|
618
|
-
export function buildHermescArgs(
|
|
619
|
-
bundlePath: string,
|
|
620
|
-
input: string = bundlePath,
|
|
621
|
-
): string[] {
|
|
622
|
-
return [
|
|
623
|
-
'-emit-binary',
|
|
624
|
-
'-out',
|
|
625
|
-
bundlePath,
|
|
626
|
-
input,
|
|
627
|
-
'-O',
|
|
628
|
-
'-output-source-map',
|
|
629
|
-
];
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
interface ProcessOutcome {
|
|
633
|
-
status: number | null;
|
|
634
|
-
signal: NodeJS.Signals | null;
|
|
635
|
-
stderr: string;
|
|
636
|
-
error?: Error;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/** captured stderr is bounded to this much head and this much tail */
|
|
640
|
-
const STDERR_KEEP_BYTES = 512 * 1024;
|
|
641
|
-
|
|
642
|
-
/** spawn without blocking the event loop, so two hermesc runs can overlap */
|
|
643
|
-
function runProcess(
|
|
644
|
-
command: string,
|
|
645
|
-
args: string[],
|
|
646
|
-
captureStderr: boolean,
|
|
647
|
-
): Promise<ProcessOutcome> {
|
|
648
|
-
return new Promise((resolve) => {
|
|
649
|
-
const child = spawn(command, args, {
|
|
650
|
-
stdio: ['ignore', 'ignore', captureStderr ? 'pipe' : 'ignore'],
|
|
651
|
-
});
|
|
652
|
-
// hermesc echoes whole (minified) source lines per diagnostic: keep the
|
|
653
|
-
// head and the tail, never an unbounded transcript
|
|
654
|
-
const head: Buffer[] = [];
|
|
655
|
-
const tail: Buffer[] = [];
|
|
656
|
-
let headBytes = 0;
|
|
657
|
-
let tailBytes = 0;
|
|
658
|
-
let dropped = false;
|
|
659
|
-
child.stderr?.on('data', (chunk: Buffer) => {
|
|
660
|
-
if (headBytes < STDERR_KEEP_BYTES) {
|
|
661
|
-
head.push(chunk);
|
|
662
|
-
headBytes += chunk.length;
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
tail.push(chunk);
|
|
666
|
-
tailBytes += chunk.length;
|
|
667
|
-
while (tail.length > 1 && tailBytes > STDERR_KEEP_BYTES) {
|
|
668
|
-
tailBytes -= (tail.shift() as Buffer).length;
|
|
669
|
-
dropped = true;
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
let settled = false;
|
|
673
|
-
const finish = (outcome: ProcessOutcome) => {
|
|
674
|
-
if (settled) return;
|
|
675
|
-
settled = true;
|
|
676
|
-
resolve(outcome);
|
|
677
|
-
};
|
|
678
|
-
child.once('error', (error) =>
|
|
679
|
-
finish({ status: null, signal: null, stderr: '', error }),
|
|
680
|
-
);
|
|
681
|
-
child.once('close', (status, signal) =>
|
|
682
|
-
finish({
|
|
683
|
-
status,
|
|
684
|
-
signal,
|
|
685
|
-
stderr:
|
|
686
|
-
Buffer.concat(head).toString() +
|
|
687
|
-
(dropped ? '\n[... output truncated ...]\n' : '') +
|
|
688
|
-
Buffer.concat(tail).toString(),
|
|
689
|
-
}),
|
|
690
|
-
);
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
export interface CompileHermesOptions {
|
|
695
|
-
bundleName: string;
|
|
696
|
-
outputFolder: string;
|
|
697
|
-
sourcemapOutput: string;
|
|
698
|
-
shouldCleanSourcemap: boolean;
|
|
699
|
-
baseRequest?: HermesBaseRequest;
|
|
700
|
-
/** base selection started alongside Metro (see startHermesBaseSelection) */
|
|
701
|
-
pendingBase?: Promise<HermesBaseSelectionResult>;
|
|
702
|
-
/** defaults to the hermesc the selection used, else the project's */
|
|
703
|
-
hermesCommand?: string;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/** how long the compile phase waits for a base that is still being fetched */
|
|
707
|
-
const HERMES_BASE_WAIT_MS = 60_000;
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* The selection runs while Metro bundles; when Metro is done first, wait a
|
|
711
|
-
* bounded time for it — a stalled download must never hold up the compile.
|
|
712
|
-
*/
|
|
713
|
-
async function awaitPendingBase(
|
|
714
|
-
pending: Promise<HermesBaseSelectionResult>,
|
|
715
|
-
): Promise<HermesBaseSelectionResult> {
|
|
716
|
-
const waitMs =
|
|
717
|
-
Number(process.env.PUSHY_HERMES_BASE_WAIT_MS) || HERMES_BASE_WAIT_MS;
|
|
718
|
-
let timer: NodeJS.Timeout | undefined;
|
|
719
|
-
const gaveUp = new Promise<HermesBaseSelectionResult>((resolve) => {
|
|
720
|
-
timer = setTimeout(
|
|
721
|
-
() =>
|
|
722
|
-
resolve({
|
|
723
|
-
base: null,
|
|
724
|
-
bytecodeVersion: null,
|
|
725
|
-
logs: [
|
|
726
|
-
t('hermesBaseNone', {
|
|
727
|
-
reason: `base not ready after ${Math.round(waitMs / 1000)}s`,
|
|
728
|
-
}),
|
|
729
|
-
],
|
|
730
|
-
}),
|
|
731
|
-
waitMs,
|
|
732
|
-
);
|
|
733
|
-
});
|
|
734
|
-
try {
|
|
735
|
-
return await Promise.race([pending, gaveUp]);
|
|
736
|
-
} finally {
|
|
737
|
-
clearTimeout(timer);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
/** plain compile of `input` into `out`; throws when hermesc fails */
|
|
742
|
-
async function compilePlain(
|
|
743
|
-
hermesCommand: string,
|
|
744
|
-
out: string,
|
|
745
|
-
input: string = out,
|
|
746
|
-
): Promise<void> {
|
|
747
|
-
const args = buildHermescArgs(out, input);
|
|
748
|
-
console.log(
|
|
749
|
-
t('runningHermesc', { command: hermesCommand, args: args.join(' ') }),
|
|
750
|
-
);
|
|
751
|
-
assertSuccessfulSyncProcess(
|
|
752
|
-
await runProcess(hermesCommand, args, false),
|
|
753
|
-
hermesCommand,
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
/**
|
|
758
|
-
* Merge the packager map with the hermes map into `sourcemapOutput` (which is
|
|
759
|
-
* normally the hermes map's own path). Resolves false when React Native's
|
|
760
|
-
* composer cannot be found; throws when it fails.
|
|
761
|
-
*/
|
|
762
|
-
async function composeSourceMaps(
|
|
763
|
-
packagerMap: string,
|
|
764
|
-
hermesMap: string,
|
|
765
|
-
sourcemapOutput: string,
|
|
766
|
-
): Promise<boolean> {
|
|
767
|
-
let composerPath: string;
|
|
768
|
-
try {
|
|
769
|
-
// resolve through the project so hoisted node_modules (monorepos) work.
|
|
770
|
-
// Extensionless first: RN >= 0.87 maps "./scripts/*" to "./scripts/*.js"
|
|
771
|
-
// in its exports, so the ".js" specifier resolves to ".js.js" and
|
|
772
|
-
// fails; CJS resolution adds the extension itself on older RN.
|
|
773
|
-
composerPath = require.resolve('react-native/scripts/compose-source-maps', {
|
|
774
|
-
paths: [process.cwd()],
|
|
775
|
-
});
|
|
776
|
-
} catch {
|
|
777
|
-
try {
|
|
778
|
-
composerPath = require.resolve(
|
|
779
|
-
'react-native/scripts/compose-source-maps.js',
|
|
780
|
-
{ paths: [process.cwd()] },
|
|
781
|
-
);
|
|
782
|
-
} catch {
|
|
783
|
-
console.warn(t('composeSourceMapsNotFound'));
|
|
784
|
-
return false;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
console.log(t('composingSourceMap'));
|
|
788
|
-
assertSuccessfulSyncProcess(
|
|
789
|
-
await runProcess(
|
|
790
|
-
getJavaScriptRuntime(),
|
|
791
|
-
[composerPath, packagerMap, hermesMap, '-o', sourcemapOutput],
|
|
792
|
-
false,
|
|
793
|
-
),
|
|
794
|
-
composerPath,
|
|
795
|
-
);
|
|
796
|
-
return true;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
export async function compileHermesByteCode({
|
|
800
|
-
bundleName,
|
|
801
|
-
outputFolder,
|
|
802
|
-
sourcemapOutput,
|
|
803
|
-
shouldCleanSourcemap,
|
|
804
|
-
baseRequest,
|
|
805
|
-
pendingBase,
|
|
806
|
-
hermesCommand = resolveHermesCommand(),
|
|
807
|
-
}: CompileHermesOptions): Promise<HermesCompileResult> {
|
|
808
|
-
console.log(t('hermesEnabledCompiling'));
|
|
809
|
-
|
|
810
|
-
const bundlePath = path.join(outputFolder, bundleName);
|
|
811
|
-
const hermesMap = `${bundlePath}.map`;
|
|
812
|
-
const packagerMap = path.join(outputFolder, `${bundleName}.txt.map`);
|
|
813
|
-
if (sourcemapOutput) {
|
|
814
|
-
// hermesc is about to write its own map at `<bundle>.map`, which is where
|
|
815
|
-
// the packager map normally sits: move it aside (copy only when elsewhere)
|
|
816
|
-
if (path.resolve(sourcemapOutput) === path.resolve(hermesMap)) {
|
|
817
|
-
fs.renameSync(sourcemapOutput, packagerMap);
|
|
818
|
-
} else {
|
|
819
|
-
fs.copyFileSync(sourcemapOutput, packagerMap);
|
|
820
|
-
}
|
|
821
|
-
} else {
|
|
822
|
-
console.log(t('hermesSourcemapKept', { file: hermesMap }));
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
let selection = pendingBase ? await awaitPendingBase(pendingBase) : null;
|
|
826
|
-
const command =
|
|
827
|
-
hermesCommand ?? selection?.hermesCommand ?? resolveHermesCommand();
|
|
828
|
-
if (!selection || selection.commandUnavailable) {
|
|
829
|
-
selection = await selectHermesBase(command, baseRequest);
|
|
830
|
-
}
|
|
831
|
-
for (const line of selection.logs) console.log(line);
|
|
832
|
-
const result: HermesCompileResult = {
|
|
833
|
-
bytecodeVersion: selection.bytecodeVersion,
|
|
834
|
-
base: null,
|
|
835
|
-
};
|
|
836
|
-
const base = selection.base;
|
|
837
|
-
// the packager + hermes maps merged into sourcemapOutput
|
|
838
|
-
let composed = false;
|
|
839
|
-
|
|
840
|
-
if (!base) {
|
|
841
|
-
await compilePlain(command, bundlePath);
|
|
842
|
-
} else {
|
|
843
|
-
// The JS bundle moves into a work dir and both hermesc runs read it there
|
|
844
|
-
// (no copies); the base compile writes the real output, and with
|
|
845
|
-
// verification on the plain compile the check needs runs concurrently
|
|
846
|
-
// into `plain/` — it simply becomes the result when the base is rejected,
|
|
847
|
-
// so a rejected base never costs a third compile.
|
|
848
|
-
const workDir = path.join(outputFolder, '.hermes-base');
|
|
849
|
-
const jsSource = path.join(workDir, bundleName);
|
|
850
|
-
const plainPath = path.join(workDir, 'plain', bundleName);
|
|
851
|
-
const wantPlain = Boolean(baseRequest?.verify);
|
|
852
|
-
fs.ensureDirSync(path.dirname(plainPath));
|
|
853
|
-
fs.renameSync(bundlePath, jsSource);
|
|
854
|
-
const args = hermescArgsWithBase(
|
|
855
|
-
buildHermescArgs(bundlePath, jsSource),
|
|
856
|
-
base.path,
|
|
857
|
-
);
|
|
858
|
-
console.log(t('runningHermesc', { command, args: args.join(' ') }));
|
|
859
|
-
const [attempt, plain] = await Promise.all([
|
|
860
|
-
// -w: warnings only bloat the captured stderr, errors still print
|
|
861
|
-
runProcess(command, [...args, '-w'], true),
|
|
862
|
-
wantPlain
|
|
863
|
-
? runProcess(command, buildHermescArgs(plainPath, jsSource), false)
|
|
864
|
-
: Promise.resolve<ProcessOutcome | null>(null),
|
|
865
|
-
]);
|
|
866
|
-
let usedBase = attempt.status === 0 && !attempt.error;
|
|
867
|
-
if (!usedBase) {
|
|
868
|
-
const fullStderr = attempt.error
|
|
869
|
-
? String(attempt.error.message ?? attempt.error)
|
|
870
|
-
: attempt.stderr;
|
|
871
|
-
const reason = summarizeHermescStderr(fullStderr);
|
|
872
|
-
console.warn(
|
|
873
|
-
t('hermesBaseCompileFailed', {
|
|
874
|
-
reason: reason || `exit ${attempt.status}`,
|
|
875
|
-
}),
|
|
876
|
-
);
|
|
877
|
-
if (fullStderr.trim()) {
|
|
878
|
-
// the summary drops noise; keep everything for bug reports — next to
|
|
879
|
-
// the intermediate dir, never inside it (its content is packed)
|
|
880
|
-
const logPath = hermesBaseErrorLogPath(outputFolder);
|
|
881
|
-
try {
|
|
882
|
-
fs.writeFileSync(logPath, fullStderr);
|
|
883
|
-
console.warn(t('hermesBaseCompileFailedLog', { file: logPath }));
|
|
884
|
-
} catch {}
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
const plainOk = plain !== null && plain.status === 0 && !plain.error;
|
|
888
|
-
// compose the base output's map while the disassembly compare runs; it is
|
|
889
|
-
// redone from the plain map in the rare case the base is rejected
|
|
890
|
-
const speculativeCompose =
|
|
891
|
-
usedBase && sourcemapOutput
|
|
892
|
-
? composeSourceMaps(packagerMap, hermesMap, sourcemapOutput)
|
|
893
|
-
: null;
|
|
894
|
-
if (usedBase && wantPlain) {
|
|
895
|
-
if (!plainOk) {
|
|
896
|
-
// the check could not run; that is not a verification failure
|
|
897
|
-
console.warn(
|
|
898
|
-
t('hermesBasePlainCompileFailed', {
|
|
899
|
-
reason:
|
|
900
|
-
(plain?.error && String(plain.error.message ?? plain.error)) ||
|
|
901
|
-
`exit ${plain?.status}`,
|
|
902
|
-
}),
|
|
903
|
-
);
|
|
904
|
-
} else {
|
|
905
|
-
let ok: boolean;
|
|
906
|
-
try {
|
|
907
|
-
ok = await verifyHermesBaseEquivalence(
|
|
908
|
-
command,
|
|
909
|
-
bundlePath,
|
|
910
|
-
plainPath,
|
|
911
|
-
);
|
|
912
|
-
} catch {
|
|
913
|
-
ok = false;
|
|
914
|
-
}
|
|
915
|
-
result.verified = ok;
|
|
916
|
-
if (ok) {
|
|
917
|
-
console.log(t('hermesBaseVerified'));
|
|
918
|
-
} else {
|
|
919
|
-
console.warn(t('hermesBaseVerifyFailed'));
|
|
920
|
-
usedBase = false;
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
if (speculativeCompose) {
|
|
925
|
-
const done = await speculativeCompose.catch((error) => {
|
|
926
|
-
if (usedBase) throw error;
|
|
927
|
-
return false;
|
|
928
|
-
});
|
|
929
|
-
composed = usedBase && done;
|
|
930
|
-
}
|
|
931
|
-
if (!usedBase) {
|
|
932
|
-
if (plainOk) {
|
|
933
|
-
fs.moveSync(plainPath, bundlePath, { overwrite: true });
|
|
934
|
-
if (fs.existsSync(`${plainPath}.map`)) {
|
|
935
|
-
fs.moveSync(`${plainPath}.map`, hermesMap, { overwrite: true });
|
|
936
|
-
}
|
|
937
|
-
} else {
|
|
938
|
-
await compilePlain(command, bundlePath, jsSource);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
fs.removeSync(workDir);
|
|
942
|
-
result.base = usedBase ? base : null;
|
|
943
|
-
}
|
|
944
|
-
if (sourcemapOutput && !composed) {
|
|
945
|
-
await composeSourceMaps(packagerMap, hermesMap, sourcemapOutput);
|
|
946
|
-
}
|
|
947
|
-
if (shouldCleanSourcemap) {
|
|
948
|
-
fs.removeSync(packagerMap);
|
|
949
|
-
}
|
|
950
|
-
return result;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
/** where a failed base attempt's full hermesc output goes (never packed) */
|
|
954
|
-
export function hermesBaseErrorLogPath(outputFolder: string): string {
|
|
955
|
-
return path.join(
|
|
956
|
-
path.dirname(path.resolve(outputFolder)),
|
|
957
|
-
'hermes-base-error.log',
|
|
958
|
-
);
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
/**
|
|
962
|
-
* Begin resolving the base right away (before Metro); the compile phase awaits
|
|
963
|
-
* the result. Never rejects: any failure is reported there instead.
|
|
964
|
-
*/
|
|
965
|
-
export function startHermesBaseSelection(
|
|
966
|
-
request: HermesBaseRequest,
|
|
967
|
-
): Promise<HermesBaseSelectionResult> {
|
|
968
|
-
return (async () => {
|
|
969
|
-
let hermesCommand: string;
|
|
970
|
-
try {
|
|
971
|
-
hermesCommand = resolveHermesCommand();
|
|
972
|
-
} catch {
|
|
973
|
-
return {
|
|
974
|
-
base: null,
|
|
975
|
-
bytecodeVersion: null,
|
|
976
|
-
logs: [],
|
|
977
|
-
commandUnavailable: true,
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
try {
|
|
981
|
-
return await selectHermesBase(hermesCommand, request);
|
|
982
|
-
} catch (error: any) {
|
|
983
|
-
return {
|
|
984
|
-
base: null,
|
|
985
|
-
bytecodeVersion: null,
|
|
986
|
-
logs: [
|
|
987
|
-
t('hermesBaseNone', { reason: error?.message ?? String(error) }),
|
|
988
|
-
],
|
|
989
|
-
hermesCommand,
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
})();
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
async function selectHermesBase(
|
|
996
|
-
hermesCommand: string,
|
|
997
|
-
request: HermesBaseRequest | undefined,
|
|
998
|
-
): Promise<HermesBaseSelectionResult> {
|
|
999
|
-
const logs: string[] = [];
|
|
1000
|
-
const none = (bytecodeVersion: number | null = null) => ({
|
|
1001
|
-
base: null,
|
|
1002
|
-
bytecodeVersion,
|
|
1003
|
-
logs,
|
|
1004
|
-
hermesCommand,
|
|
1005
|
-
});
|
|
1006
|
-
if (!request || request.option === 'none') {
|
|
1007
|
-
if (request) {
|
|
1008
|
-
logs.push(t('hermesBaseNone', { reason: 'disabled by option' }));
|
|
1009
|
-
}
|
|
1010
|
-
return none();
|
|
1011
|
-
}
|
|
1012
|
-
const gate = classifyHermesCommand(hermesCommand);
|
|
1013
|
-
if (!gate.allowed) {
|
|
1014
|
-
logs.push(
|
|
1015
|
-
t('hermesBaseNone', { reason: gate.reason ?? 'hermesc not eligible' }),
|
|
1016
|
-
);
|
|
1017
|
-
return none();
|
|
1018
|
-
}
|
|
1019
|
-
const bytecodeVersion = probeHbcVersion(hermesCommand);
|
|
1020
|
-
if (bytecodeVersion === null) {
|
|
1021
|
-
logs.push(t('hermesBaseNone', { reason: 'could not probe HBC version' }));
|
|
1022
|
-
return none();
|
|
1023
|
-
}
|
|
1024
|
-
try {
|
|
1025
|
-
const base = await resolveHermesBase({
|
|
1026
|
-
option: request.option,
|
|
1027
|
-
hermesCommand,
|
|
1028
|
-
bytecodeVersion,
|
|
1029
|
-
appId: request.appId,
|
|
1030
|
-
cacheMaxMb: request.cacheMaxMb,
|
|
1031
|
-
fetchBase: getHermesBase,
|
|
1032
|
-
log: (message) => logs.push(message),
|
|
1033
|
-
});
|
|
1034
|
-
return { base, bytecodeVersion, logs, hermesCommand };
|
|
1035
|
-
} catch (error: any) {
|
|
1036
|
-
logs.push(t('hermesBaseNone', { reason: error?.message ?? String(error) }));
|
|
1037
|
-
return none(bytecodeVersion);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
export async function copyDebugidForSentry(
|
|
1042
|
-
bundleName: string,
|
|
1043
|
-
outputFolder: string,
|
|
1044
|
-
sourcemapOutput: string,
|
|
1045
|
-
): Promise<void> {
|
|
1046
|
-
if (sourcemapOutput) {
|
|
1047
|
-
let copyDebugidPath: string | undefined;
|
|
1048
|
-
try {
|
|
1049
|
-
copyDebugidPath = require.resolve(
|
|
1050
|
-
'@sentry/react-native/scripts/copy-debugid.js',
|
|
1051
|
-
{
|
|
1052
|
-
paths: [process.cwd()],
|
|
1053
|
-
},
|
|
1054
|
-
);
|
|
1055
|
-
} catch {
|
|
1056
|
-
console.error(t('sentryReactNativeNotFound'));
|
|
1057
|
-
return;
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
if (!fs.existsSync(copyDebugidPath)) {
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
console.log(t('copyingDebugId'));
|
|
1064
|
-
assertSuccessfulSyncProcess(
|
|
1065
|
-
spawnJavaScriptSync(
|
|
1066
|
-
[
|
|
1067
|
-
copyDebugidPath,
|
|
1068
|
-
path.join(outputFolder, `${bundleName}.txt.map`),
|
|
1069
|
-
path.join(outputFolder, `${bundleName}.map`),
|
|
1070
|
-
],
|
|
1071
|
-
{
|
|
1072
|
-
stdio: 'ignore',
|
|
1073
|
-
},
|
|
1074
|
-
),
|
|
1075
|
-
copyDebugidPath,
|
|
1076
|
-
);
|
|
1077
|
-
}
|
|
1078
|
-
fs.removeSync(path.join(outputFolder, `${bundleName}.txt.map`));
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
export async function prepareSentryUploadArtifacts(
|
|
1082
|
-
bundleName: string,
|
|
1083
|
-
outputFolder: string,
|
|
1084
|
-
platform: string,
|
|
1085
|
-
): Promise<SentryUploadArtifacts> {
|
|
1086
|
-
const bundlePath = path.join(outputFolder, bundleName);
|
|
1087
|
-
const sourcemapPath = path.join(outputFolder, `${bundleName}.map`);
|
|
1088
|
-
|
|
1089
|
-
if (platform !== 'android' || bundleName === ANDROID_SENTRY_BUNDLE_NAME) {
|
|
1090
|
-
return {
|
|
1091
|
-
bundlePath,
|
|
1092
|
-
sourcemapPath,
|
|
1093
|
-
};
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
const androidBundlePath = path.join(outputFolder, ANDROID_SENTRY_BUNDLE_NAME);
|
|
1097
|
-
const androidSourcemapPath = path.join(
|
|
1098
|
-
outputFolder,
|
|
1099
|
-
`${ANDROID_SENTRY_BUNDLE_NAME}.map`,
|
|
1100
|
-
);
|
|
1101
|
-
await fs.promises.copyFile(bundlePath, androidBundlePath);
|
|
1102
|
-
|
|
1103
|
-
const sourcemap = JSON.parse(
|
|
1104
|
-
await fs.promises.readFile(sourcemapPath, 'utf8'),
|
|
1105
|
-
) as Record<string, unknown>;
|
|
1106
|
-
sourcemap.file = ANDROID_SENTRY_BUNDLE_NAME;
|
|
1107
|
-
await fs.promises.writeFile(androidSourcemapPath, JSON.stringify(sourcemap));
|
|
1108
|
-
|
|
1109
|
-
return {
|
|
1110
|
-
bundlePath: androidBundlePath,
|
|
1111
|
-
sourcemapPath: androidSourcemapPath,
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
export async function readSourcemapDebugId(
|
|
1116
|
-
sourcemapPath: string,
|
|
1117
|
-
): Promise<string | undefined> {
|
|
1118
|
-
try {
|
|
1119
|
-
const sourcemap = JSON.parse(
|
|
1120
|
-
await fs.promises.readFile(sourcemapPath, 'utf8'),
|
|
1121
|
-
) as Record<string, unknown>;
|
|
1122
|
-
const debugId = sourcemap.debugId ?? sourcemap.debug_id;
|
|
1123
|
-
return typeof debugId === 'string' ? normalizeString(debugId) : undefined;
|
|
1124
|
-
} catch {
|
|
1125
|
-
return undefined;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
function resolveSentryReleaseFromValues(
|
|
1130
|
-
releaseValue: string | undefined,
|
|
1131
|
-
distValue: string | undefined,
|
|
1132
|
-
): { release: string; dist?: string } | undefined {
|
|
1133
|
-
const release = normalizeString(releaseValue);
|
|
1134
|
-
if (!release) {
|
|
1135
|
-
return undefined;
|
|
1136
|
-
}
|
|
1137
|
-
return {
|
|
1138
|
-
release,
|
|
1139
|
-
dist: normalizeString(distValue),
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
export async function resolveSentryUploadMode(
|
|
1144
|
-
sourcemapPath: string,
|
|
1145
|
-
options: SentryUploadOptions = {},
|
|
1146
|
-
): Promise<SentryUploadMode> {
|
|
1147
|
-
const optionRelease = resolveSentryReleaseFromValues(
|
|
1148
|
-
options.sentryRelease,
|
|
1149
|
-
options.sentryDist,
|
|
1150
|
-
);
|
|
1151
|
-
if (optionRelease) {
|
|
1152
|
-
return {
|
|
1153
|
-
type: 'release',
|
|
1154
|
-
...optionRelease,
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
const debugId = await readSourcemapDebugId(sourcemapPath);
|
|
1159
|
-
if (debugId) {
|
|
1160
|
-
return {
|
|
1161
|
-
type: 'debug-id',
|
|
1162
|
-
debugId,
|
|
1163
|
-
};
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
const environmentRelease = resolveSentryReleaseFromValues(
|
|
1167
|
-
process.env.SENTRY_RELEASE,
|
|
1168
|
-
process.env.SENTRY_DIST,
|
|
1169
|
-
);
|
|
1170
|
-
if (environmentRelease) {
|
|
1171
|
-
return {
|
|
1172
|
-
type: 'release',
|
|
1173
|
-
...environmentRelease,
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
throw new Error(
|
|
1178
|
-
'[pushy/sentry] Generated source map does not contain a Debug ID. ' +
|
|
1179
|
-
'Add @sentry/react-native/metro to metro.config.js so the OTA bundle can be matched by Debug ID, ' +
|
|
1180
|
-
'or set --sentry-release/--sentry-dist (or SENTRY_RELEASE/SENTRY_DIST) for legacy release matching.',
|
|
1181
|
-
);
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
export function buildSentrySourcemapsUploadArgs({
|
|
1185
|
-
sentryCliPath,
|
|
1186
|
-
bundlePath,
|
|
1187
|
-
sourcemapPath,
|
|
1188
|
-
release,
|
|
1189
|
-
dist,
|
|
1190
|
-
stripPrefix = process.cwd(),
|
|
1191
|
-
debugIdReference = false,
|
|
1192
|
-
useStandaloneSourcemapsCommand = true,
|
|
1193
|
-
}: BuildSentrySourcemapsUploadArgsOptions): string[] {
|
|
1194
|
-
const uploadArgs = ['--strip-prefix', stripPrefix, bundlePath, sourcemapPath];
|
|
1195
|
-
|
|
1196
|
-
if (debugIdReference) {
|
|
1197
|
-
if (!useStandaloneSourcemapsCommand) {
|
|
1198
|
-
throw new Error(
|
|
1199
|
-
'[pushy/sentry] Debug ID upload requires sentry-cli sourcemaps upload.',
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
return [
|
|
1203
|
-
sentryCliPath,
|
|
1204
|
-
'sourcemaps',
|
|
1205
|
-
'upload',
|
|
1206
|
-
'--debug-id-reference',
|
|
1207
|
-
...uploadArgs,
|
|
1208
|
-
];
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
if (!release) {
|
|
1212
|
-
throw new Error(
|
|
1213
|
-
'[pushy/sentry] Legacy Sentry sourcemap upload requires a release.',
|
|
1214
|
-
);
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
if (!useStandaloneSourcemapsCommand) {
|
|
1218
|
-
return [
|
|
1219
|
-
sentryCliPath,
|
|
1220
|
-
'releases',
|
|
1221
|
-
'files',
|
|
1222
|
-
release,
|
|
1223
|
-
'upload-sourcemaps',
|
|
1224
|
-
...(dist ? ['--dist', dist] : []),
|
|
1225
|
-
...uploadArgs,
|
|
1226
|
-
];
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
return [
|
|
1230
|
-
sentryCliPath,
|
|
1231
|
-
'sourcemaps',
|
|
1232
|
-
'upload',
|
|
1233
|
-
'--release',
|
|
1234
|
-
release,
|
|
1235
|
-
...(dist ? ['--dist', dist] : []),
|
|
1236
|
-
...uploadArgs,
|
|
1237
|
-
];
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
function supportsStandaloneSentrySourcemapsUpload(sentryCliPath: string) {
|
|
1241
|
-
const result = spawnJavaScriptSync(
|
|
1242
|
-
[sentryCliPath, 'sourcemaps', 'upload', '--help'],
|
|
1243
|
-
{
|
|
1244
|
-
stdio: 'ignore',
|
|
1245
|
-
},
|
|
1246
|
-
);
|
|
1247
|
-
return !result.error && result.status === 0;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
function supportsSentryDebugIdReference(sentryCliPath: string) {
|
|
1251
|
-
const result = spawnJavaScriptSync(
|
|
1252
|
-
[sentryCliPath, 'sourcemaps', 'upload', '--help'],
|
|
1253
|
-
{
|
|
1254
|
-
encoding: 'utf8',
|
|
1255
|
-
},
|
|
1256
|
-
);
|
|
1257
|
-
return (
|
|
1258
|
-
!result.error &&
|
|
1259
|
-
result.status === 0 &&
|
|
1260
|
-
typeof result.stdout === 'string' &&
|
|
1261
|
-
result.stdout.includes('--debug-id-reference')
|
|
1262
|
-
);
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
function runSentryCli(args: string[]): SyncProcessResult {
|
|
1266
|
-
return spawnJavaScriptSync(args, {
|
|
1267
|
-
stdio: 'inherit',
|
|
1268
|
-
});
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
function uploadSourcemapsWithRelease({
|
|
1272
|
-
sentryCliPath,
|
|
1273
|
-
bundlePath,
|
|
1274
|
-
sourcemapPath,
|
|
1275
|
-
release,
|
|
1276
|
-
dist,
|
|
1277
|
-
useStandaloneSourcemapsCommand,
|
|
1278
|
-
}: {
|
|
1279
|
-
sentryCliPath: string;
|
|
1280
|
-
bundlePath: string;
|
|
1281
|
-
sourcemapPath: string;
|
|
1282
|
-
release: string;
|
|
1283
|
-
dist?: string;
|
|
1284
|
-
useStandaloneSourcemapsCommand: boolean;
|
|
1285
|
-
}): void {
|
|
1286
|
-
assertSuccessfulSyncProcess(
|
|
1287
|
-
runSentryCli([sentryCliPath, 'releases', 'set-commits', release, '--auto']),
|
|
1288
|
-
sentryCliPath,
|
|
1289
|
-
);
|
|
1290
|
-
console.log(t('sentryReleaseCreated', { version: release }));
|
|
1291
|
-
|
|
1292
|
-
console.log(t('uploadingSourcemap'));
|
|
1293
|
-
assertSuccessfulSyncProcess(
|
|
1294
|
-
runSentryCli(
|
|
1295
|
-
buildSentrySourcemapsUploadArgs({
|
|
1296
|
-
sentryCliPath,
|
|
1297
|
-
bundlePath,
|
|
1298
|
-
sourcemapPath,
|
|
1299
|
-
release,
|
|
1300
|
-
dist,
|
|
1301
|
-
useStandaloneSourcemapsCommand,
|
|
1302
|
-
}),
|
|
1303
|
-
),
|
|
1304
|
-
sentryCliPath,
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
export async function uploadSourcemapForSentry(
|
|
1309
|
-
bundleName: string,
|
|
1310
|
-
outputFolder: string,
|
|
1311
|
-
sourcemapOutput: string,
|
|
1312
|
-
platform = '',
|
|
1313
|
-
sentryOptions: SentryUploadOptions = {},
|
|
1314
|
-
): Promise<void> {
|
|
1315
|
-
if (!sourcemapOutput) {
|
|
1316
|
-
return;
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
let sentryCliPath: string | undefined;
|
|
1320
|
-
try {
|
|
1321
|
-
sentryCliPath = require.resolve('@sentry/cli/bin/sentry-cli', {
|
|
1322
|
-
paths: [process.cwd()],
|
|
1323
|
-
});
|
|
1324
|
-
} catch {
|
|
1325
|
-
console.error(t('sentryCliNotFound'));
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
if (!fs.existsSync(sentryCliPath)) {
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
const { bundlePath, sourcemapPath } = await prepareSentryUploadArtifacts(
|
|
1334
|
-
bundleName,
|
|
1335
|
-
outputFolder,
|
|
1336
|
-
platform,
|
|
1337
|
-
);
|
|
1338
|
-
const uploadMode = await resolveSentryUploadMode(
|
|
1339
|
-
sourcemapPath,
|
|
1340
|
-
sentryOptions,
|
|
1341
|
-
);
|
|
1342
|
-
const useStandaloneSourcemapsCommand =
|
|
1343
|
-
supportsStandaloneSentrySourcemapsUpload(sentryCliPath);
|
|
1344
|
-
|
|
1345
|
-
if (uploadMode.type === 'release') {
|
|
1346
|
-
uploadSourcemapsWithRelease({
|
|
1347
|
-
sentryCliPath,
|
|
1348
|
-
bundlePath,
|
|
1349
|
-
sourcemapPath,
|
|
1350
|
-
release: uploadMode.release,
|
|
1351
|
-
dist: uploadMode.dist,
|
|
1352
|
-
useStandaloneSourcemapsCommand,
|
|
1353
|
-
});
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
console.log(t('uploadingSourcemap'));
|
|
1358
|
-
if (
|
|
1359
|
-
!useStandaloneSourcemapsCommand ||
|
|
1360
|
-
!supportsSentryDebugIdReference(sentryCliPath)
|
|
1361
|
-
) {
|
|
1362
|
-
const explicitRelease =
|
|
1363
|
-
resolveSentryReleaseFromValues(
|
|
1364
|
-
sentryOptions.sentryRelease,
|
|
1365
|
-
sentryOptions.sentryDist,
|
|
1366
|
-
) ??
|
|
1367
|
-
resolveSentryReleaseFromValues(
|
|
1368
|
-
process.env.SENTRY_RELEASE,
|
|
1369
|
-
process.env.SENTRY_DIST,
|
|
1370
|
-
);
|
|
1371
|
-
if (!explicitRelease) {
|
|
1372
|
-
throw new Error(
|
|
1373
|
-
'[pushy/sentry] sentry-cli does not support Debug ID source map upload. ' +
|
|
1374
|
-
'Upgrade @sentry/cli, or set --sentry-release/--sentry-dist for legacy release matching.',
|
|
1375
|
-
);
|
|
1376
|
-
}
|
|
1377
|
-
uploadSourcemapsWithRelease({
|
|
1378
|
-
sentryCliPath,
|
|
1379
|
-
bundlePath,
|
|
1380
|
-
sourcemapPath,
|
|
1381
|
-
release: explicitRelease.release,
|
|
1382
|
-
dist: explicitRelease.dist,
|
|
1383
|
-
useStandaloneSourcemapsCommand,
|
|
1384
|
-
});
|
|
1385
|
-
return;
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
console.log(
|
|
1389
|
-
`[pushy/sentry] Using source map Debug ID: ${uploadMode.debugId}`,
|
|
1390
|
-
);
|
|
1391
|
-
const debugIdResult = runSentryCli(
|
|
1392
|
-
buildSentrySourcemapsUploadArgs({
|
|
1393
|
-
sentryCliPath,
|
|
1394
|
-
bundlePath,
|
|
1395
|
-
sourcemapPath,
|
|
1396
|
-
debugIdReference: true,
|
|
1397
|
-
useStandaloneSourcemapsCommand,
|
|
1398
|
-
}),
|
|
1399
|
-
);
|
|
1400
|
-
|
|
1401
|
-
if (debugIdResult.status === 0 && !debugIdResult.error) {
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
const explicitRelease =
|
|
1406
|
-
resolveSentryReleaseFromValues(
|
|
1407
|
-
sentryOptions.sentryRelease,
|
|
1408
|
-
sentryOptions.sentryDist,
|
|
1409
|
-
) ??
|
|
1410
|
-
resolveSentryReleaseFromValues(
|
|
1411
|
-
process.env.SENTRY_RELEASE,
|
|
1412
|
-
process.env.SENTRY_DIST,
|
|
1413
|
-
);
|
|
1414
|
-
if (!explicitRelease) {
|
|
1415
|
-
assertSuccessfulSyncProcess(debugIdResult, sentryCliPath);
|
|
1416
|
-
return;
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
console.warn(
|
|
1420
|
-
'[pushy/sentry] Debug ID source map upload failed; falling back to explicit release/dist upload.',
|
|
1421
|
-
);
|
|
1422
|
-
uploadSourcemapsWithRelease({
|
|
1423
|
-
sentryCliPath,
|
|
1424
|
-
bundlePath,
|
|
1425
|
-
sourcemapPath,
|
|
1426
|
-
release: explicitRelease.release,
|
|
1427
|
-
dist: explicitRelease.dist,
|
|
1428
|
-
useStandaloneSourcemapsCommand,
|
|
1429
|
-
});
|
|
1430
|
-
}
|