Skip to content

Commit 4e9d0f9

Browse files
committed
update upload sourcemap workflow
1 parent 8803e7f commit 4e9d0f9

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

src/bundle.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ async function runReactNativeBundleCommand(
5858

5959
let usingExpo = false;
6060
try {
61-
62-
6361
cliPath = require.resolve('@expo/cli', {
6462
paths: [process.cwd()],
6563
});
@@ -199,18 +197,6 @@ async function runReactNativeBundleCommand(
199197
sourcemapOutput,
200198
!isSentry,
201199
);
202-
if (isSentry) {
203-
await copyDebugidForSentry(
204-
bundleName,
205-
outputFolder,
206-
sourcemapOutput,
207-
);
208-
await uploadSourcemapForSentry(
209-
bundleName,
210-
outputFolder,
211-
sourcemapOutput,
212-
);
213-
}
214200
}
215201
resolve(null);
216202
}
@@ -346,7 +332,9 @@ async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
346332
},
347333
);
348334
} catch (error) {
349-
console.error('无法找到 Sentry copy-debugid.js 脚本文件,请确保已正确安装 @sentry/react-native');
335+
console.error(
336+
'无法找到 Sentry copy-debugid.js 脚本文件,请确保已正确安装 @sentry/react-native',
337+
);
350338
return;
351339
}
352340

@@ -373,6 +361,7 @@ async function uploadSourcemapForSentry(
373361
bundleName,
374362
outputFolder,
375363
sourcemapOutput,
364+
version,
376365
) {
377366
if (sourcemapOutput) {
378367
let sentryCliPath;
@@ -388,19 +377,14 @@ async function uploadSourcemapForSentry(
388377
if (!fs.existsSync(sentryCliPath)) {
389378
return;
390379
}
391-
392-
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
393-
const version = packageJson.version;
394-
395-
spawnSync('node', [
396-
sentryCliPath,
397-
'releases',
398-
'set-commits',
399-
version,
400-
'--auto'
401-
], {
402-
stdio: 'inherit',
403-
});
380+
381+
spawnSync(
382+
'node',
383+
[sentryCliPath, 'releases', 'set-commits', version, '--auto'],
384+
{
385+
stdio: 'inherit',
386+
},
387+
);
404388
console.log(`Sentry release created for version: ${version}`);
405389

406390
console.log('Uploading sourcemap');
@@ -421,8 +405,6 @@ async function uploadSourcemapForSentry(
421405
stdio: 'inherit',
422406
},
423407
);
424-
425-
fs.removeSync(path.join(outputFolder, `${bundleName}.map`));
426408
}
427409
}
428410

@@ -840,6 +822,7 @@ export const commands = {
840822

841823
const bundleParams = await checkPlugins();
842824
const sourcemap = bundleParams.sourcemap;
825+
const isSentry = bundleParams.sentry;
843826

844827
const sourcemapOutput = path.join(intermediaDir, `${bundleName}.map`);
845828

@@ -866,12 +849,21 @@ export const commands = {
866849

867850
const v = await question('是否现在上传此热更包?(Y/N)');
868851
if (v.toLowerCase() === 'y') {
869-
await this.publish({
852+
const versionName = await this.publish({
870853
args: [realOutput],
871854
options: {
872855
platform,
873856
},
874857
});
858+
if (isSentry) {
859+
await copyDebugidForSentry(bundleName, intermediaDir, sourcemapOutput);
860+
await uploadSourcemapForSentry(
861+
bundleName,
862+
intermediaDir,
863+
sourcemapOutput,
864+
versionName,
865+
);
866+
}
875867
}
876868
},
877869

src/versions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ export const commands = {
9797

9898
const { hash } = await uploadFile(fn);
9999

100+
const versionName = name || (await question('输入版本名称: ')) || '(未命名)';
100101
const { id } = await post(`/app/${appId}/version/create`, {
101-
name: name || (await question('输入版本名称: ')) || '(未命名)',
102+
name: versionName,
102103
hash,
103104
description: description || (await question('输入版本描述:')),
104105
metaInfo: metaInfo || (await question('输入自定义的 meta info:')),
@@ -111,6 +112,7 @@ export const commands = {
111112
if (v.toLowerCase() === 'y') {
112113
await this.update({ args: [], options: { versionId: id, platform } });
113114
}
115+
return versionName;
114116
},
115117
versions: async ({ options }) => {
116118
const platform = checkPlatform(

0 commit comments

Comments
 (0)