Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"mime": "^2.5.2",
"minimatch": "^3.0.4",
"morgan": "^1.10.0",
"murmurhash-es": "^0.1.1",
"node-fetch": "^2.6.7",
"open": "^6.3.0",
"ora": "^5.4.1",
Expand Down
6 changes: 4 additions & 2 deletions src/commands/crashlytics-sourcemap-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ describe("crashlytics:sourcemap:upload", () => {
expect(clientPostStub).to.be.calledOnce;
const args = clientPostStub.firstCall.args;
expect(args[0]).to.match(
/\/projects\/test-project\/apps\/test-app\/locations\/global\/sourceMaps/,
/projects\/test-project\/apps\/test-app\/locations\/global\/sourceMaps/,
);
expect(args[1].sourceMap).to.deep.equal({
name: "projects/test-project/apps/test-app/locations/global/sourceMaps/759213742",
version: "a".repeat(40),
obfuscatedFilePath: "src-test-fixtures-mapping-files-mock_mapping.js.map",
obfuscatedFilePath: "src/test/fixtures/mapping-files/mock_mapping.js.map",
fileUri: `gs://${BUCKET_NAME}/test-object`,
});
expect(args[2].queryParams).to.deep.equal({ allowMissing: "true" });
});

it("should warn if registration fails", async () => {
Expand Down
26 changes: 17 additions & 9 deletions src/commands/crashlytics-sourcemap-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Options } from "../options";
import { archiveFile } from "../archiveFile";
import { execSync } from "node:child_process";
import { Client } from "../apiv2";
import { murmurHashV3 } from "murmurhash-es";

interface CommandOptions extends Options {
app?: string;
Expand All @@ -22,6 +23,7 @@ interface CommandOptions extends Options {
}

interface SourceMap {
name: string;
version: string;
obfuscatedFilePath: string;
fileUri: string;
Expand Down Expand Up @@ -187,7 +189,10 @@ async function uploadMap(
try {
const filePath = path.relative(options.projectRoot ?? process.cwd(), mappingFile);
const tmpArchive = await archiveFile(filePath, { archivedFileName: "mapping.js.map" });
const gcsFile = `${options.app}-${appVersion}-${normalizeFileName(mappingFile)}.zip`;
const gcsFile = `${options.app}-${appVersion}-${normalizeFileName(filePath)}.zip`;
const uid = murmurHashV3(`${appVersion}-${filePath}`);
const parent = `projects/${projectId}/apps/${options.app}/locations/global/sourceMaps`;
const name = `${parent}/${uid}`;

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

await registerSourceMap(
projectId,
options.app!,
parent,
{
name,
version: appVersion,
obfuscatedFilePath: normalizeFileName(mappingFile),
obfuscatedFilePath: filePath,
fileUri,
},
options.telemetryServerUrl!,
Expand All @@ -222,8 +227,7 @@ function normalizeFileName(fileName: string): string {
}

async function registerSourceMap(
projectId: string,
appId: string,
parent: string,
sourceMap: SourceMap,
telemetryServerUrl: string,
): Promise<void> {
Expand All @@ -234,9 +238,13 @@ async function registerSourceMap(
});

try {
await client.post(`/projects/${projectId}/apps/${appId}/locations/global/sourceMaps`, {
sourceMap,
});
await client.post(
parent,
{
sourceMap,
},
{ queryParams: { allowMissing: "true" } },
);
logger.debug(
`Registered source map ${sourceMap.obfuscatedFilePath} with Firebase Telemetry service`,
);
Expand Down
Loading