@@ -3,7 +3,7 @@ import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker'
3
3
import type * as monaco from 'monaco-editor-core'
4
4
import {
5
5
type LanguageServiceEnvironment ,
6
- activateAutomaticTypeAcquisition ,
6
+ createJsDelivrNpmFileSystem ,
7
7
createTypeScriptWorkerService ,
8
8
} from '@volar/monaco/worker'
9
9
import {
@@ -37,17 +37,31 @@ self.onmessage = async (msg: MessageEvent<WorkerMessage>) => {
37
37
worker . initialize (
38
38
(
39
39
ctx : monaco . worker . IWorkerContext < WorkerHost > ,
40
- {
41
- tsconfig,
42
- // TODO
43
- dependencies,
44
- } : CreateData ,
40
+ { tsconfig, dependencies } : CreateData ,
45
41
) => {
46
42
const asFileName = ( uri : URI ) => uri . path
47
43
const asUri = ( fileName : string ) : URI => URI . file ( fileName )
48
44
const env : LanguageServiceEnvironment = {
49
45
workspaceFolders : [ URI . file ( '/' ) ] ,
50
46
locale,
47
+ fs : createJsDelivrNpmFileSystem (
48
+ ( uri ) => {
49
+ if ( uri . scheme === 'file' ) {
50
+ if ( uri . path === '/node_modules' ) {
51
+ return ''
52
+ } else if ( uri . path . startsWith ( '/node_modules/' ) ) {
53
+ return uri . path . slice ( '/node_modules/' . length )
54
+ }
55
+ }
56
+ } ,
57
+ ( pkgName ) => dependencies [ pkgName ] ,
58
+ ( path , content ) => {
59
+ ctx . host . onFetchCdnFile (
60
+ asUri ( '/node_modules/' + path ) . toString ( ) ,
61
+ content ,
62
+ )
63
+ } ,
64
+ ) ,
51
65
}
52
66
53
67
const { options : compilerOptions } = ts . convertCompilerOptionsFromJson (
@@ -58,13 +72,6 @@ self.onmessage = async (msg: MessageEvent<WorkerMessage>) => {
58
72
tsconfig . vueCompilerOptions || { } ,
59
73
)
60
74
61
- activateAutomaticTypeAcquisition ( env , { asFileName } , ( path , content ) => {
62
- ctx . host . onFetchCdnFile (
63
- asUri ( '/node_modules/' + path ) . toString ( ) ,
64
- content ,
65
- )
66
- } )
67
-
68
75
return createTypeScriptWorkerService ( {
69
76
typescript : ts ,
70
77
compilerOptions,
0 commit comments