@@ -13,6 +13,7 @@ import { Options } from "../options";
1313import { archiveFile } from "../archiveFile" ;
1414import { execSync } from "node:child_process" ;
1515import { Client } from "../apiv2" ;
16+ import { murmurHashV3 } from "murmurhash-es" ;
1617
1718interface CommandOptions extends Options {
1819 app ?: string ;
@@ -22,6 +23,7 @@ interface CommandOptions extends Options {
2223}
2324
2425interface 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
224230async 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