From 9029ed05f7f6edad2b4699564e63124ff38927ec Mon Sep 17 00:00:00 2001 From: Martin Schuhfuss Date: Thu, 9 Feb 2023 12:02:02 +0100 Subject: [PATCH] fix: inline code-samples for faster loading --- examples/playground/src/init-editor.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/playground/src/init-editor.ts b/examples/playground/src/init-editor.ts index dd652d0..68aac24 100644 --- a/examples/playground/src/init-editor.ts +++ b/examples/playground/src/init-editor.ts @@ -14,23 +14,23 @@ import {configureMonacoWorkers} from './configure-monaco-workers'; * dependencies (Google Maps and our marker library). */ async function initEditorFilesystem() { - const markerLibFiles = import.meta.glob(`../../../dist/*.d.ts`, {as: 'raw'}); + const markerLibFiles = import.meta.glob(`../../../dist/*.d.ts`, { + as: 'raw', + eager: true + }); languages.typescript.typescriptDefaults.addExtraLib( (await import('../node_modules/@types/google.maps/index.d.ts?raw')).default, `file:///node_modules/@types/google.maps/index.d.ts` ); - for (const [path, loadFile] of Object.entries(markerLibFiles)) { + for (const [path, content] of Object.entries(markerLibFiles)) { const editorPath = path.replace( /^.*\/dist\//, `file:///node_modules/${packageName}/` ); - languages.typescript.typescriptDefaults.addExtraLib( - await loadFile(), - editorPath - ); + languages.typescript.typescriptDefaults.addExtraLib(content, editorPath); } } @@ -41,14 +41,17 @@ type CodeSample = { }; async function loadCodeSamples(): Promise> { - const exampleFiles = import.meta.glob('./code-samples/*.ts', {as: 'raw'}); + const exampleFiles = import.meta.glob('./code-samples/*.ts', { + as: 'raw', + eager: true + }); const codeSamples: Record = {}; - for (const [path, loadFile] of Object.entries(exampleFiles)) { + for (const [path, content] of Object.entries(exampleFiles)) { const filename = path.replace('./code-samples/', ''); const editorPath = `file:///${filename}`; const model = editor.createModel( - await loadFile(), + content, 'typescript', Uri.parse(editorPath) );