-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): fix Expo Go downloading indicator (#19817)
* fix(cli): fix Expo Go downloading indicator * Update packages/@expo/cli/CHANGELOG.md Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com> Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
71 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 contains 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 contains 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 contains 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 contains 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,42 +1,46 @@ | ||
import * as Log from '../../log'; | ||
import { FetchLike } from './client.types'; | ||
const debug = require('debug')('expo:api:fetch:progress') as typeof console.log; | ||
|
||
export function wrapFetchWithProgress(fetch: FetchLike): FetchLike { | ||
return async (url, init) => { | ||
const res = await fetch(url, init); | ||
if (res.ok && init?.onProgress) { | ||
const totalDownloadSize = res.headers.get('Content-Length'); | ||
const total = Number(totalDownloadSize); | ||
return (url, init) => { | ||
return fetch(url, init).then((res) => { | ||
if (res.ok && init?.onProgress) { | ||
const totalDownloadSize = res.headers.get('Content-Length'); | ||
const total = Number(totalDownloadSize); | ||
|
||
if (!totalDownloadSize || isNaN(total) || total < 0) { | ||
Log.warn( | ||
'Progress callback not supported for network request because "Content-Length" header missing or invalid in response from URL:', | ||
url.toString() | ||
); | ||
return res; | ||
} | ||
|
||
let length = 0; | ||
|
||
res.body.on('data', (chunk) => { | ||
length += chunk.length; | ||
onProgress(); | ||
}); | ||
debug(`Download size: ${totalDownloadSize}`); | ||
if (!totalDownloadSize || isNaN(total) || total < 0) { | ||
Log.warn( | ||
'Progress callback not supported for network request because "Content-Length" header missing or invalid in response from URL:', | ||
url.toString() | ||
); | ||
return res; | ||
} | ||
|
||
res.body.on('end', () => { | ||
onProgress(); | ||
}); | ||
let length = 0; | ||
|
||
const onProgress = () => { | ||
const progress = length / total; | ||
debug(`Starting progress animation for ${url}`); | ||
res.body.on('data', (chunk) => { | ||
length += Buffer.byteLength(chunk); | ||
onProgress(); | ||
}); | ||
|
||
init.onProgress?.({ | ||
progress, | ||
total, | ||
loaded: length, | ||
res.body.on('end', () => { | ||
debug(`Finished progress animation for ${url}`); | ||
onProgress(); | ||
}); | ||
}; | ||
} | ||
return res; | ||
|
||
const onProgress = () => { | ||
const progress = length / total || 0; | ||
init.onProgress?.({ | ||
progress, | ||
total, | ||
loaded: length, | ||
}); | ||
}; | ||
} | ||
return res; | ||
}); | ||
}; | ||
} |
This file contains 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 contains 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 contains 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