Skip to content

Commit 6cddb68

Browse files
author
c1401964
committed
Set request timeout instead of deadline timeout.
1 parent 771a242 commit 6cddb68

6 files changed

Lines changed: 13 additions & 12 deletions

File tree

packages/cli-plugin-cordova/src/commands/resources.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ export class ResourcesCommand extends Command implements CommandPreRun {
190190

191191
// Upload images to service to prepare for resource transformations
192192
let imageUploadResponses: ImageUploadResponse[];
193-
const timeout = config.cliFlags.timeout ? 25000 : 0;
193+
const timeout = config.cliFlags.timeout;
194+
194195
imageUploadResponses = await uploadSourceImages(srcImagesAvailable, timeout);
195196
this.env.log.debug(`${chalk.green('uploadSourceImages')} completed - responses=${JSON.stringify(imageUploadResponses, null, 2)}`);
196197

packages/cli-plugin-cordova/src/lib/__tests__/resources.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('@ionic/cli-plugin-cordova', () => {
303303
imageId: '60278b0fa1d5abf43d07c5ae0f8a0b41'
304304
}];
305305

306-
const response = await resources.uploadSourceImages(sourceImages, 0);
306+
const response = await resources.uploadSourceImages(sourceImages, false);
307307
expect(response).toEqual([{
308308
Error: '',
309309
Width: 337,
@@ -340,7 +340,7 @@ describe('@ionic/cli-plugin-cordova', () => {
340340
dest: path.join(__dirname, 'fixtures', 'drawable-land-ldpi-screen.png')
341341
};
342342

343-
await resources.transformResourceImage(imgResource, 0);
343+
await resources.transformResourceImage(imgResource, false);
344344

345345
expect(cliUtils.writeStreamToFile).toHaveBeenCalledWith(
346346
createRequestMock, imgResource.dest

packages/cli-plugin-cordova/src/lib/resources.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ export function findMostSpecificImage(imageResource: ImageResource, srcImagesAva
159159
* Upload the provided source image through the resources web service. This will make it available
160160
* for transforms for the next 5 minutes.
161161
*/
162-
export async function uploadSourceImages(srcImages: SourceImage[], timeout: number): Promise<ImageUploadResponse[]> {
162+
export async function uploadSourceImages(srcImages: SourceImage[], timeout: boolean | undefined): Promise<ImageUploadResponse[]> {
163163
return Promise.all(
164164
srcImages.map(async (srcImage) => {
165165
const res = await createRequest('POST', UPLOAD_URL)
166-
.timeout(timeout)
166+
.timeout({ response: timeout ? 120000 : 0 })
167167
.type('form')
168168
.attach('src', srcImage.path)
169169
.field('image_id', srcImage.imageId || '');
@@ -176,10 +176,10 @@ export async function uploadSourceImages(srcImages: SourceImage[], timeout: numb
176176
* Using the transformation web service transform the provided image resource
177177
* into the appropiate w x h and then write this file to the provided destination directory.
178178
*/
179-
export function transformResourceImage(imageResource: ImageResource, timeout: number) {
179+
export function transformResourceImage(imageResource: ImageResource, timeout: boolean | undefined) {
180180
return new Promise<void>((resolve, reject) => {
181181
const req = createRequest('POST', TRANSFORM_URL)
182-
.timeout(timeout)
182+
.timeout({ response: timeout ? 120000 : 0 })
183183
.type('form')
184184
.send({
185185
'name': imageResource.name,

packages/ionic/src/commands/start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class StartCommand extends Command implements CommandPreRun {
273273
this.env.tasks.end();
274274
this.env.log.info(`Fetching app base (${chalk.dim(wrapperBranchPath)})`);
275275
const d1Task = this.env.tasks.next('Downloading');
276-
const timeout = config.cliFlags.timeout ? 25000 : 0;
276+
const timeout = config.cliFlags.timeout;
277277

278278
await tarXvfFromUrl(wrapperBranchPath, projectRoot, timeout, { progress: (loaded, total) => {
279279
d1Task.progress(loaded, total);

packages/ionic/src/lib/start.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {
1717

1818
import { StarterTemplate, StarterTemplateType } from '../definitions';
1919

20-
export function tarXvfFromUrl(url: string, destination: string, timeout: number, { progress }: { progress?: (loaded: number, total: number) => void }) {
20+
export function tarXvfFromUrl(url: string, destination: string, timeout: boolean | undefined, { progress }: { progress?: (loaded: number, total: number) => void }) {
2121
return new Promise<void>((resolve, reject) => {
2222
const archiveRequest = createRequest('get', url)
23-
.timeout(timeout)
23+
.timeout({ response: timeout ? 120000 : 0 })
2424
.on('response', (res) => {
2525
if (res.statusCode !== 200) {
2626
reject(new Error(`Encountered bad status code (${res.statusCode}) for ${url}\n` +

types/superagent.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for SuperAgent v2.0.0
1+
// Type definitions for SuperAgent v3.5.1
22
// Project: https://github.com/visionmedia/superagent
33
// Definitions by: Alex Varju <https://github.com/varju/>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -118,7 +118,7 @@ declare module "superagent" {
118118
send(): this;
119119
set(field: string, val: string): this;
120120
set(field: Object): this;
121-
timeout(ms: number): this;
121+
timeout(ms: number | Object | { response: number, read: number, deadline: number }): this;
122122
type(val: string): this;
123123
unset(field: string): this;
124124
use(fn: Function): this;

0 commit comments

Comments
 (0)