@volar/monaco 1.3.0-alpha.3-patch.1 → 1.3.0-alpha.3-patch.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/out/worker.d.ts +8 -6
- package/out/worker.js +24 -12
- package/package.json +1 -1
package/README.md
CHANGED
package/out/worker.d.ts
CHANGED
|
@@ -10,16 +10,18 @@ export declare function createLanguageService(options: {
|
|
|
10
10
|
compilerOptions: ts.CompilerOptions;
|
|
11
11
|
};
|
|
12
12
|
}): {};
|
|
13
|
-
export declare function createDtsHost(cdn: string, onFetch?: (fileName: string, text: string) => void): CdnDtsHost;
|
|
13
|
+
export declare function createDtsHost(cdn: string, versions?: Record<string, string>, onFetch?: (fileName: string, text: string) => void): CdnDtsHost;
|
|
14
14
|
declare class CdnDtsHost {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
cdn: string;
|
|
16
|
+
versions: Record<string, string>;
|
|
17
|
+
onFetch?: ((fileName: string, text: string) => void) | undefined;
|
|
17
18
|
files: Map<string, string | Promise<string | undefined> | undefined>;
|
|
18
19
|
lastUpdateFilesSize: number;
|
|
19
|
-
constructor(cdn: string, onFetch?: ((fileName: string, text: string) => void) | undefined);
|
|
20
|
+
constructor(cdn: string, versions?: Record<string, string>, onFetch?: ((fileName: string, text: string) => void) | undefined);
|
|
20
21
|
getVersion(): Promise<number>;
|
|
21
|
-
readFile(fileName: string): string | Promise<string | undefined
|
|
22
|
-
fetch(fileName: string
|
|
22
|
+
readFile(fileName: string): string | Promise<string | undefined> | undefined;
|
|
23
|
+
fetch(fileName: string): Promise<string | undefined>;
|
|
24
|
+
resolveRequestFileName(fileName: string): string;
|
|
23
25
|
/**
|
|
24
26
|
* save / load with json
|
|
25
27
|
*/
|
package/out/worker.js
CHANGED
|
@@ -169,13 +169,14 @@ function createLanguageService(options) {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
exports.createLanguageService = createLanguageService;
|
|
172
|
-
function createDtsHost(cdn, onFetch) {
|
|
173
|
-
return new CdnDtsHost(cdn, onFetch);
|
|
172
|
+
function createDtsHost(cdn, versions = {}, onFetch) {
|
|
173
|
+
return new CdnDtsHost(cdn, versions, onFetch);
|
|
174
174
|
}
|
|
175
175
|
exports.createDtsHost = createDtsHost;
|
|
176
176
|
class CdnDtsHost {
|
|
177
|
-
constructor(cdn, onFetch) {
|
|
177
|
+
constructor(cdn, versions = {}, onFetch) {
|
|
178
178
|
this.cdn = cdn;
|
|
179
|
+
this.versions = versions;
|
|
179
180
|
this.onFetch = onFetch;
|
|
180
181
|
this.files = new Map();
|
|
181
182
|
this.lastUpdateFilesSize = 0;
|
|
@@ -190,20 +191,22 @@ class CdnDtsHost {
|
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
193
|
readFile(fileName) {
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
this.files.set(fileName, this.fetch(fileName, url));
|
|
194
|
+
if (fileName.startsWith('/node_modules/')
|
|
195
|
+
// ignore .js because it's no help for intellisense
|
|
196
|
+
&& (fileName.endsWith('.d.ts') || fileName.endsWith('/package.json'))) {
|
|
197
|
+
if (!this.files.has(fileName)) {
|
|
198
|
+
this.files.set(fileName, undefined);
|
|
199
|
+
this.files.set(fileName, this.fetch(fileName));
|
|
200
200
|
}
|
|
201
|
+
return this.files.get(fileName);
|
|
201
202
|
}
|
|
202
|
-
return
|
|
203
|
+
return undefined;
|
|
203
204
|
}
|
|
204
|
-
fetch(fileName
|
|
205
|
+
fetch(fileName) {
|
|
205
206
|
var _a, _b;
|
|
206
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
const requestFileName = this.resolveRequestFileName(fileName);
|
|
209
|
+
const url = this.cdn + requestFileName.slice('/node_modules/'.length);
|
|
207
210
|
try {
|
|
208
211
|
const text = (_a = (yield axios_1.default.get(url, {
|
|
209
212
|
transformResponse: (res) => {
|
|
@@ -219,6 +222,15 @@ class CdnDtsHost {
|
|
|
219
222
|
}
|
|
220
223
|
});
|
|
221
224
|
}
|
|
225
|
+
resolveRequestFileName(fileName) {
|
|
226
|
+
for (const [key, version] of Object.entries(this.versions)) {
|
|
227
|
+
if (fileName.startsWith(`/node_modules/${key}/`)) {
|
|
228
|
+
fileName = fileName.replace(`/node_modules/${key}/`, `/node_modules/${key}@${version}/`);
|
|
229
|
+
return fileName;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return fileName;
|
|
233
|
+
}
|
|
222
234
|
/**
|
|
223
235
|
* save / load with json
|
|
224
236
|
*/
|