@volar/monaco 1.3.0-alpha.3 → 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 CHANGED
@@ -51,7 +51,7 @@ createLanguageService({
51
51
  },
52
52
  },
53
53
  // Enable auto fetch node_modules types
54
- dtsHost: createDtsHost('https://unpkg.com/'),
54
+ dtsHost: createDtsHost('https://unpkg.com/', { typescript: '4.9.5' }),
55
55
  });
56
56
  ```
57
57
 
package/out/worker.d.ts CHANGED
@@ -10,15 +10,22 @@ 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
- private cdn;
16
- private onFetch?;
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, url: string): Promise<string | undefined>;
22
+ readFile(fileName: string): string | Promise<string | undefined> | undefined;
23
+ fetch(fileName: string): Promise<string | undefined>;
24
+ resolveRequestFileName(fileName: string): string;
25
+ /**
26
+ * save / load with json
27
+ */
28
+ toJson(): Promise<Record<string, string | null>>;
29
+ fromJson(json: Record<string, string | null>): void;
23
30
  }
24
31
  export {};
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 (!this.files.has(fileName)) {
194
- this.files.set(fileName, undefined);
195
- if (fileName.startsWith('/node_modules/')
196
- // ignore .js because it's no help for intellisense
197
- && (fileName.endsWith('.d.ts') || fileName.endsWith('/package.json'))) {
198
- const url = this.cdn + fileName.slice('/node_modules/'.length);
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 this.files.get(fileName);
203
+ return undefined;
203
204
  }
204
- fetch(fileName, url) {
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,33 @@ 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
+ }
234
+ /**
235
+ * save / load with json
236
+ */
237
+ toJson() {
238
+ var _a;
239
+ return __awaiter(this, void 0, void 0, function* () {
240
+ const json = {};
241
+ for (const [fileName, file] of this.files) {
242
+ json[fileName] = (_a = (yield file)) !== null && _a !== void 0 ? _a : null;
243
+ }
244
+ return json;
245
+ });
246
+ }
247
+ fromJson(json) {
248
+ for (const [fileName, file] of Object.entries(json)) {
249
+ this.files.set(fileName, file !== null && file !== void 0 ? file : undefined);
250
+ }
251
+ }
222
252
  }
223
253
  function createDtsClient(server) {
224
254
  const fetchTasks = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/monaco",
3
- "version": "1.3.0-alpha.3",
3
+ "version": "1.3.0-alpha.3-patch.2",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -20,6 +20,5 @@
20
20
  "monaco-editor-core": "^0.36.0",
21
21
  "vscode-languageserver-protocol": "^3.17.3",
22
22
  "vscode-uri": "^3.0.7"
23
- },
24
- "gitHead": "03c8fff84531d8740863da5f9350e0d9382b5784"
23
+ }
25
24
  }
package/out/dts.d.ts DELETED
File without changes
package/out/dts.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=dts.js.map