Skip to content

Commit 4e8a18e

Browse files
fix fetching auto types
1 parent f092262 commit 4e8a18e

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

packages/app/src/app/overmind/effects/vscode/SandboxFsSync/index.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import {
1010
Sandbox,
1111
SandboxFs,
1212
} from '@codesandbox/common/lib/types';
13-
import {
14-
fetchPackageJSON,
15-
isAbsoluteVersion,
16-
} from '@codesandbox/common/lib/utils/dependencies';
13+
import { isAbsoluteVersion } from '@codesandbox/common/lib/utils/dependencies';
1714
import { getGlobal } from '@codesandbox/common/lib/utils/global';
1815
import { protocolAndHost } from '@codesandbox/common/lib/utils/url-generator';
1916
import { json } from 'overmind';
@@ -339,24 +336,23 @@ class SandboxFsSync {
339336
isAbsoluteVersion(dep.version)
340337
) {
341338
const name = `@types/${dep.name}`;
342-
fetchPackageJSON(name, dep.version).then(({ version }) => {
343-
this.setAndSendPackageTypes(dep.name, {
344-
[name]: version,
339+
this.fetchDependencyTypingFiles(name, this.typesInfo[dep.name].latest)
340+
.then(files => {
341+
this.setAndSendPackageTypes(dep.name, files);
342+
})
343+
.catch(e => {
344+
if (process.env.NODE_ENV === 'development') {
345+
console.warn('Trouble fetching types for ' + name);
346+
}
345347
});
346-
});
347348
}
348349

349350
try {
350-
const fetchRequest = await fetch(
351-
`${SERVICE_URL}/${dep.name}@${dep.version}.json`
351+
const files = await this.fetchDependencyTypingFiles(
352+
dep.name,
353+
dep.version
352354
);
353355

354-
if (!fetchRequest.ok) {
355-
throw new Error('Fetch error');
356-
}
357-
358-
const { files } = await fetchRequest.json();
359-
360356
this.setAndSendPackageTypes(dep.name, files);
361357
} catch (e) {
362358
if (process.env.NODE_ENV === 'development') {
@@ -367,6 +363,18 @@ class SandboxFsSync {
367363
/* ignore */
368364
}
369365
}
366+
367+
private async fetchDependencyTypingFiles(name: string, version: string) {
368+
const fetchRequest = await fetch(`${SERVICE_URL}/${name}@${version}.json`);
369+
370+
if (!fetchRequest.ok) {
371+
throw new Error('Fetch error');
372+
}
373+
374+
const { files } = await fetchRequest.json();
375+
376+
return files;
377+
}
370378
}
371379

372380
export default SandboxFsSync;

packages/app/src/app/pages/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import React, { useEffect } from 'react';
2-
import { Route, Switch, Redirect, withRouter } from 'react-router-dom';
3-
import { DragDropContext } from 'react-dnd';
1+
import { Button } from '@codesandbox/common/lib/components/Button';
2+
import theme from '@codesandbox/common/lib/theme';
3+
import { DNT, trackPageview } from '@codesandbox/common/lib/utils/analytics';
44
import _debug from '@codesandbox/common/lib/utils/debug';
5-
import { Toasts, NotificationStatus } from '@codesandbox/notifications';
65
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
7-
import { DNT, trackPageview } from '@codesandbox/common/lib/utils/analytics';
8-
import theme from '@codesandbox/common/lib/theme';
9-
import { Button } from '@codesandbox/common/lib/components/Button';
10-
import Loadable from 'app/utils/Loadable';
6+
import { NotificationStatus, Toasts } from '@codesandbox/notifications';
117
import { useOvermind } from 'app/overmind';
8+
import Loadable from 'app/utils/Loadable';
9+
import React, { useEffect } from 'react';
10+
import { DragDropContext } from 'react-dnd';
11+
import { Redirect, Route, Switch, withRouter } from 'react-router-dom';
12+
1213
import { ErrorBoundary } from './common/ErrorBoundary';
1314
import HTML5Backend from './common/HTML5BackendWithFolderSupport';
1415
import Modals from './common/Modals';
15-
import Sandbox from './Sandbox';
16-
import { NewSandbox } from './NewSandbox';
1716
import Dashboard from './Dashboard';
1817
import { DevAuthPage } from './DevAuth';
1918
import { Container, Content } from './elements';
19+
import { NewSandbox } from './NewSandbox';
20+
import Sandbox from './Sandbox';
2021

2122
const routeDebugger = _debug('cs:app:router');
2223

0 commit comments

Comments
 (0)