Skip to content

Commit 5eb79f3

Browse files
committed
Add resource name and allow_missing param to source map registration
1 parent 0fb3ce5 commit 5eb79f3

4 files changed

Lines changed: 36 additions & 11 deletions

File tree

npm-shrinkwrap.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
"mime": "^2.5.2",
152152
"minimatch": "^3.0.4",
153153
"morgan": "^1.10.0",
154+
"murmurhash-es": "^0.1.1",
154155
"node-fetch": "^2.6.7",
155156
"open": "^6.3.0",
156157
"ora": "^5.4.1",

src/commands/crashlytics-sourcemap-upload.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,15 @@ describe("crashlytics:sourcemap:upload", () => {
195195
expect(clientPostStub).to.be.calledOnce;
196196
const args = clientPostStub.firstCall.args;
197197
expect(args[0]).to.match(
198-
/\/projects\/test-project\/apps\/test-app\/locations\/global\/sourceMaps/,
198+
/projects\/test-project\/apps\/test-app\/locations\/global\/sourceMaps/,
199199
);
200200
expect(args[1].sourceMap).to.deep.equal({
201+
name: "projects/test-project/apps/test-app/locations/global/sourceMaps/2109677681",
201202
version: "a".repeat(40),
202203
obfuscatedFilePath: "src-test-fixtures-mapping-files-mock_mapping.js.map",
203204
fileUri: `gs://${BUCKET_NAME}/test-object`,
204205
});
206+
expect(args[2].queryParams).to.deep.equal({ allowMissing: "true" });
205207
});
206208

207209
it("should warn if registration fails", async () => {

src/commands/crashlytics-sourcemap-upload.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Options } from "../options";
1313
import { archiveFile } from "../archiveFile";
1414
import { execSync } from "node:child_process";
1515
import { Client } from "../apiv2";
16+
import { murmurHashV3 } from "murmurhash-es";
1617

1718
interface CommandOptions extends Options {
1819
app?: string;
@@ -22,6 +23,7 @@ interface CommandOptions extends Options {
2223
}
2324

2425
interface SourceMap {
26+
name: string;
2527
version: string;
2628
obfuscatedFilePath: string;
2729
fileUri: string;
@@ -187,7 +189,11 @@ async function uploadMap(
187189
try {
188190
const filePath = path.relative(options.projectRoot ?? process.cwd(), mappingFile);
189191
const tmpArchive = await archiveFile(filePath, { archivedFileName: "mapping.js.map" });
190-
const gcsFile = `${options.app}-${appVersion}-${normalizeFileName(mappingFile)}.zip`;
192+
const obfuscatedFilePath = normalizeFileName(filePath);
193+
const gcsFile = `${options.app}-${appVersion}-${obfuscatedFilePath}.zip`;
194+
const uid = murmurHashV3(`${appVersion}-${obfuscatedFilePath}`);
195+
const parent = `projects/${projectId}/apps/${options.app}/locations/global/sourceMaps`;
196+
const name = `${parent}/${uid}`;
191197

192198
const { bucket, object } = await gcs.uploadObject(
193199
{
@@ -200,11 +206,11 @@ async function uploadMap(
200206
logger.debug(`Uploaded mapping file ${mappingFile} to ${fileUri}`);
201207

202208
await registerSourceMap(
203-
projectId,
204-
options.app!,
209+
parent,
205210
{
211+
name,
206212
version: appVersion,
207-
obfuscatedFilePath: normalizeFileName(mappingFile),
213+
obfuscatedFilePath,
208214
fileUri,
209215
},
210216
options.telemetryServerUrl!,
@@ -222,8 +228,7 @@ function normalizeFileName(fileName: string): string {
222228
}
223229

224230
async function registerSourceMap(
225-
projectId: string,
226-
appId: string,
231+
parent: string,
227232
sourceMap: SourceMap,
228233
telemetryServerUrl: string,
229234
): Promise<void> {
@@ -234,9 +239,13 @@ async function registerSourceMap(
234239
});
235240

236241
try {
237-
await client.post(`/projects/${projectId}/apps/${appId}/locations/global/sourceMaps`, {
238-
sourceMap,
239-
});
242+
await client.post(
243+
parent,
244+
{
245+
sourceMap,
246+
},
247+
{ queryParams: { allowMissing: "true" } },
248+
);
240249
logger.debug(
241250
`Registered source map ${sourceMap.obfuscatedFilePath} with Firebase Telemetry service`,
242251
);

0 commit comments

Comments
 (0)