Skip to content

Commit 25f4583

Browse files
author
Ives van Hoorne
committed
Make sure typings are fetched
1 parent 24106c7 commit 25f4583

File tree

1 file changed

+28
-24
lines changed
  • packages/app/src/app/components/CodeEditor/Monaco

1 file changed

+28
-24
lines changed

packages/app/src/app/components/CodeEditor/Monaco/index.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
163163
setTimeout(() => {
164164
this.fetchDependencyTypings(dependencies);
165165
this.getConfigSchemas();
166-
}, this.hasNativeTypescript() ? 0 : 5000);
166+
}, this.hasNativeTypescript() ? 500 : 5000);
167167
}
168168
}
169169

@@ -286,7 +286,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
286286
newSandbox: Sandbox,
287287
newCurrentModule: Module,
288288
dependencies: $PropertyType<Props, 'dependencies'>
289-
) =>
289+
): Promise<null> =>
290290
new Promise(resolve => {
291291
const oldSandbox = this.sandbox;
292292

@@ -482,32 +482,36 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
482482
this.typingsFetcherWorker = new TypingsFetcherWorker();
483483
const regex = /node_modules\/(@types\/.*?)\//;
484484

485-
this.typingsFetcherWorker.addEventListener('message', event => {
486-
const sandbox = this.sandbox;
487-
const dependencies = this.dependencies || sandbox.npmDependencies;
488-
489-
Object.keys(event.data).forEach((path: string) => {
490-
const typings = event.data[path];
491-
if (
492-
path.startsWith('node_modules/@types') &&
493-
this.hasNativeTypescript()
494-
) {
495-
const match = path.match(regex);
496-
if (match && match[1]) {
497-
const dependency = match[1];
498-
499-
if (
500-
!Object.keys(dependencies).includes(dependency) &&
501-
this.props.onNpmDependencyAdded
502-
) {
503-
this.props.onNpmDependencyAdded(dependency);
485+
this.fetchDependencyTypings(this.dependencies || {});
486+
487+
if (this.typingsFetcherWorker) {
488+
this.typingsFetcherWorker.addEventListener('message', event => {
489+
const sandbox = this.sandbox;
490+
const dependencies = this.dependencies || sandbox.npmDependencies;
491+
492+
Object.keys(event.data).forEach((path: string) => {
493+
const typings = event.data[path];
494+
if (
495+
path.startsWith('node_modules/@types') &&
496+
this.hasNativeTypescript()
497+
) {
498+
const match = path.match(regex);
499+
if (match && match[1]) {
500+
const dependency = match[1];
501+
502+
if (
503+
!Object.keys(dependencies).includes(dependency) &&
504+
this.props.onNpmDependencyAdded
505+
) {
506+
this.props.onNpmDependencyAdded(dependency);
507+
}
504508
}
505509
}
506-
}
507510

508-
this.addLib(typings, '/' + path);
511+
this.addLib(typings, '/' + path);
512+
});
509513
});
510-
});
514+
}
511515
};
512516

513517
setupLintWorker = () => {

0 commit comments

Comments
 (0)