|
1 |
| -import * as require_ from 'require'; |
| 1 | +import * as require from 'require'; |
2 | 2 |
|
3 | 3 | self.MonacoEnvironment = {
|
4 | 4 | getWorker: function (_moduleId, label) {
|
5 |
| - const require = require_; |
6 |
| - if (!require) { |
7 |
| - label = label; // NOOP |
8 |
| - } |
9 | 5 | if (label === 'json') {
|
10 |
| - return new Worker(new URL('../../../src/language/json/json.worker.ts', import.meta.url), { |
11 |
| - type: 'module' |
12 |
| - }); |
| 6 | + return new Worker( |
| 7 | + getWorkerBootstrapUrl( |
| 8 | + new URL('../../../src/language/json/json.worker.ts?worker', import.meta.url) |
| 9 | + ) |
| 10 | + ); |
13 | 11 | }
|
14 | 12 | if (label === 'css' || label === 'scss' || label === 'less') {
|
15 |
| - return new Worker(new URL('../../../src/language/css/css.worker.ts', import.meta.url), { |
16 |
| - type: 'module' |
17 |
| - }); |
| 13 | + return new Worker( |
| 14 | + getWorkerBootstrapUrl( |
| 15 | + new URL('../../../src/language/css/css.worker.ts?worker', import.meta.url) |
| 16 | + ) |
| 17 | + ); |
18 | 18 | }
|
19 | 19 | if (label === 'html' || label === 'handlebars' || label === 'razor') {
|
20 |
| - return new Worker(new URL('../../../src/language/html/html.worker.ts', import.meta.url), { |
21 |
| - type: 'module' |
22 |
| - }); |
| 20 | + return new Worker( |
| 21 | + getWorkerBootstrapUrl( |
| 22 | + new URL('../../../src/language/html/html.worker.ts?worker', import.meta.url) |
| 23 | + ) |
| 24 | + ); |
23 | 25 | }
|
24 | 26 | if (label === 'typescript' || label === 'javascript') {
|
25 |
| - return new Worker(new URL('../../../src/language/typescript/ts.worker.ts', import.meta.url), { |
26 |
| - type: 'module' |
27 |
| - }); |
| 27 | + return new Worker( |
| 28 | + getWorkerBootstrapUrl( |
| 29 | + new URL('../../../src/language/typescript/ts.worker.ts?worker', import.meta.url) |
| 30 | + ) |
| 31 | + ); |
28 | 32 | }
|
29 |
| - return new Worker(new URL('../../../src/editor/editor.worker.ts', import.meta.url), { |
30 |
| - type: 'module' |
31 |
| - }); |
| 33 | + return new Worker( |
| 34 | + getWorkerBootstrapUrl(new URL('../../../src/editor/editor.worker.ts?worker', import.meta.url)) |
| 35 | + ); |
32 | 36 | }
|
33 | 37 | };
|
34 | 38 |
|
| 39 | +function getWorkerBootstrapUrl(workerScriptUrl) { |
| 40 | + const blob = new Blob( |
| 41 | + [ |
| 42 | + [ |
| 43 | + `const ttPolicy = globalThis.trustedTypes?.createPolicy('defaultWorkerFactory', { createScriptURL: value => value });`, |
| 44 | + `globalThis.workerttPolicy = ttPolicy;`, |
| 45 | + `importScripts(ttPolicy?.createScriptURL(${JSON.stringify( |
| 46 | + workerScriptUrl |
| 47 | + )}) ?? ${JSON.stringify(workerScriptUrl)});`, |
| 48 | + `globalThis.postMessage({ type: 'vscode-worker-ready' });` |
| 49 | + ].join('') |
| 50 | + ], |
| 51 | + { type: 'application/javascript' } |
| 52 | + ); |
| 53 | + return URL.createObjectURL(blob); |
| 54 | +} |
| 55 | + |
35 | 56 | import 'vs/nls.messages-loader!';
|
36 | 57 | import '../../../src/basic-languages/monaco.contribution';
|
37 | 58 | import '../../../src/language/css/monaco.contribution';
|
38 | 59 | import '../../../src/language/html/monaco.contribution';
|
39 | 60 | import '../../../src/language/json/monaco.contribution';
|
40 | 61 | import '../../../src/language/typescript/monaco.contribution';
|
41 | 62 |
|
42 |
| -const styleSheetUrl = require_.toUrl('vs/style.css'); |
| 63 | +const styleSheetUrl = require.toUrl('vs/style.css'); |
43 | 64 |
|
44 | 65 | const link = document.createElement('link');
|
45 | 66 | link.rel = 'stylesheet';
|
|
0 commit comments