mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 07:00:11 +01:00
Adds playground support for esmUrl (#5093)
This commit is contained in:
parent
81b06fd717
commit
b62a81677f
2 changed files with 21 additions and 3 deletions
|
|
@ -14,13 +14,20 @@ export function getMonaco(): typeof monaco | undefined {
|
||||||
return (window as any).monaco;
|
return (window as any).monaco;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMonacoSetup {
|
export type IAMDMonacoSetup = {
|
||||||
loaderUrl: string;
|
loaderUrl: string;
|
||||||
loaderConfigPaths: Record<string, string>;
|
loaderConfigPaths: Record<string, string>;
|
||||||
codiconUrl: string;
|
codiconUrl: string;
|
||||||
monacoTypesUrl: string | undefined;
|
monacoTypesUrl: string | undefined;
|
||||||
language?: string;
|
language?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export type IESMMonacoSetup = {
|
||||||
|
esmUrl: string;
|
||||||
|
monacoTypesUrl: string | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type IMonacoSetup = IAMDMonacoSetup | IESMMonacoSetup;
|
||||||
|
|
||||||
let loading = false;
|
let loading = false;
|
||||||
let resolve: (value: typeof monaco) => void;
|
let resolve: (value: typeof monaco) => void;
|
||||||
|
|
@ -47,6 +54,10 @@ export async function loadMonaco(
|
||||||
async function _loadMonaco(setup: IMonacoSetup): Promise<typeof monaco> {
|
async function _loadMonaco(setup: IMonacoSetup): Promise<typeof monaco> {
|
||||||
const global = self as any;
|
const global = self as any;
|
||||||
|
|
||||||
|
if ('esmUrl' in setup) {
|
||||||
|
return await import(/* webpackIgnore: true */setup.esmUrl); // CodeQL [SM01507] This is safe because the runner (that allows for dynamic paths) runs in an isolated iframe. The hosting website uses a static path configuration. // CodeQL [SM03712] This is safe because the runner (that allows for dynamic paths) runs in an isolated iframe. The hosting website uses a static path configuration.
|
||||||
|
}
|
||||||
|
|
||||||
if (!(global as any).require) {
|
if (!(global as any).require) {
|
||||||
await loadScript(setup.loaderUrl);
|
await loadScript(setup.loaderUrl);
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +123,7 @@ export const prodMonacoSetup = getMonacoSetup(
|
||||||
export function getMonacoSetup(
|
export function getMonacoSetup(
|
||||||
corePath: string,
|
corePath: string,
|
||||||
language?: string
|
language?: string
|
||||||
): IMonacoSetup {
|
): IAMDMonacoSetup {
|
||||||
const loaderConfigPaths = {
|
const loaderConfigPaths = {
|
||||||
vs: `${corePath}`,
|
vs: `${corePath}`,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,13 @@ export function toLoaderConfig(settings: Settings): IMonacoSetup {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (coreUrl.endsWith('?esm')) {
|
||||||
|
return {
|
||||||
|
esmUrl: coreUrl,
|
||||||
|
monacoTypesUrl: undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let languagesUrl: string;
|
let languagesUrl: string;
|
||||||
switch (settings.languagesSource) {
|
switch (settings.languagesSource) {
|
||||||
case "latest":
|
case "latest":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue