-
Notifications
You must be signed in to change notification settings - Fork 4
Add ZIP upload of sourcemaps. #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bcfb124
sourcmap tools: replace SourceMapUploader with SymbolUploader
perf2711 759b95a
sourcmap tools: add ZipArchive
perf2711 4a22731
webpack plugin: change uploading of sourcemaps to ZIP upload
perf2711 4af87c2
build: update webpack tsconfig.json path
perf2711 aaffdb5
sourcemap tools: fix ZipArchive test missing dir
perf2711 7ca7bf2
webpack plugin: fix zipping sourcemaps by passing stream instead of s…
perf2711 0a25e5b
sourcemap tools: minor type fixes in ZipArchive
perf2711 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import http from 'http'; | ||
| import https from 'https'; | ||
| import { Readable } from 'stream'; | ||
|
|
||
| interface CoronerUploadResponse { | ||
| response: 'ok' | string; | ||
| _rxid: string; | ||
| } | ||
|
|
||
| export interface UploadResult { | ||
| rxid: string; | ||
| } | ||
|
|
||
| export interface SymbolUploaderOptions { | ||
| ignoreSsl?: boolean; | ||
| headers?: http.OutgoingHttpHeaders; | ||
| } | ||
|
|
||
| /** | ||
| * Class responsible for uploading symbols to Backtrace. | ||
| * | ||
| * Expects symbol upload responses. | ||
| */ | ||
| export class SymbolUploader { | ||
| private readonly _url: URL; | ||
|
|
||
| constructor(url: string | URL, private readonly _options?: SymbolUploaderOptions) { | ||
| this._url = new URL(url); | ||
| } | ||
|
|
||
| /** | ||
| * Uploads the symbol to Backtrace. | ||
| * @param content Symbol stream. | ||
| */ | ||
| public async uploadSymbol(readable: Readable): Promise<UploadResult> { | ||
| const protocol = this._url.protocol === 'https:' ? https : http; | ||
|
|
||
| return new Promise<UploadResult>((resolve, reject) => { | ||
| const request = protocol.request( | ||
| this._url, | ||
| { | ||
| method: 'POST', | ||
| rejectUnauthorized: !this._options?.ignoreSsl, | ||
| headers: this._options?.headers, | ||
| }, | ||
| (response) => { | ||
| if (!response.statusCode) { | ||
| return reject(new Error('Failed to upload symbol: failed to make the request.')); | ||
| } | ||
|
|
||
| const data: Buffer[] = []; | ||
| response.on('data', (chunk) => { | ||
| data.push(chunk); | ||
| }); | ||
|
|
||
| response.on('end', () => { | ||
| const rawResponse = Buffer.concat(data).toString('utf-8'); | ||
| if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 300) { | ||
| return reject( | ||
| new Error( | ||
| `Failed to upload symbol: ${response.statusCode}. Response data: ${rawResponse}`, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const responseData = JSON.parse(rawResponse) as CoronerUploadResponse; | ||
| if (responseData.response === 'ok') { | ||
| return resolve({ | ||
| rxid: responseData._rxid, | ||
| }); | ||
| } else { | ||
| return reject(new Error(`Non-OK response received from Coroner: ${rawResponse}`)); | ||
| } | ||
| } catch (err) { | ||
| return reject(new Error(`Cannot parse response from Coroner: ${rawResponse}`)); | ||
| } | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| request.on('error', reject); | ||
| readable.pipe(request); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import archiver from 'archiver'; | ||
| import { Readable, Transform, TransformCallback, TransformOptions } from 'stream'; | ||
|
|
||
| export class ZipArchive extends Transform { | ||
| private readonly _archive: archiver.Archiver; | ||
|
|
||
| constructor(opts?: TransformOptions) { | ||
| super(opts); | ||
| this._archive = archiver('zip'); | ||
| } | ||
|
|
||
| public append(name: string, sourceMap: string | Readable | Buffer) { | ||
| this._archive.append(sourceMap, { name }); | ||
| return this; | ||
| } | ||
|
|
||
| public finalize() { | ||
| return this._archive.finalize(); | ||
| } | ||
|
|
||
| public override pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean }): T { | ||
| return this._archive.pipe(destination, options); | ||
| } | ||
|
|
||
| public override _transform(chunk: unknown, encoding: BufferEncoding, callback: TransformCallback): void { | ||
| return this._archive._transform(chunk, encoding, callback); | ||
| } | ||
|
|
||
| public override _flush(callback: TransformCallback): void { | ||
| return this._archive._flush(callback); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from './ContentAppender'; | ||
| export * from './DebugIdGenerator'; | ||
| export * from './SourceMapUploader'; | ||
| export * from './SourceProcessor'; | ||
| export * from './SymbolUploader'; | ||
| export * from './ZipArchive'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| testOutput/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.