Skip to content

Commit b62a816

Browse files
authored
Adds playground support for esmUrl (#5093)
1 parent 81b06fd commit b62a816

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

website/src/monaco-loader.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ export function getMonaco(): typeof monaco | undefined {
1414
return (window as any).monaco;
1515
}
1616

17-
export interface IMonacoSetup {
17+
export type IAMDMonacoSetup = {
1818
loaderUrl: string;
1919
loaderConfigPaths: Record<string, string>;
2020
codiconUrl: string;
2121
monacoTypesUrl: string | undefined;
2222
language?: string;
23-
}
23+
};
24+
25+
export type IESMMonacoSetup = {
26+
esmUrl: string;
27+
monacoTypesUrl: string | undefined;
28+
};
29+
30+
export type IMonacoSetup = IAMDMonacoSetup | IESMMonacoSetup;
2431

2532
let loading = false;
2633
let resolve: (value: typeof monaco) => void;
@@ -47,6 +54,10 @@ export async function loadMonaco(
4754
async function _loadMonaco(setup: IMonacoSetup): Promise<typeof monaco> {
4855
const global = self as any;
4956

57+
if ('esmUrl' in setup) {
58+
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.
59+
}
60+
5061
if (!(global as any).require) {
5162
await loadScript(setup.loaderUrl);
5263
}
@@ -112,7 +123,7 @@ export const prodMonacoSetup = getMonacoSetup(
112123
export function getMonacoSetup(
113124
corePath: string,
114125
language?: string
115-
): IMonacoSetup {
126+
): IAMDMonacoSetup {
116127
const loaderConfigPaths = {
117128
vs: `${corePath}`,
118129
};

website/src/website/pages/playground/SettingsModel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export function toLoaderConfig(settings: Settings): IMonacoSetup {
136136
break;
137137
}
138138

139+
if (coreUrl.endsWith('?esm')) {
140+
return {
141+
esmUrl: coreUrl,
142+
monacoTypesUrl: undefined,
143+
}
144+
}
145+
139146
let languagesUrl: string;
140147
switch (settings.languagesSource) {
141148
case "latest":

0 commit comments

Comments
 (0)