@typescript/vfs 1.4.0 → 1.5.1

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.
@@ -3,64 +3,53 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _extends() {
6
- _extends = Object.assign || function (target) {
6
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
7
7
  for (var i = 1; i < arguments.length; i++) {
8
8
  var source = arguments[i];
9
-
10
9
  for (var key in source) {
11
10
  if (Object.prototype.hasOwnProperty.call(source, key)) {
12
11
  target[key] = source[key];
13
12
  }
14
13
  }
15
14
  }
16
-
17
15
  return target;
18
16
  };
19
-
20
17
  return _extends.apply(this, arguments);
21
18
  }
22
19
 
23
20
  var hasLocalStorage = false;
24
-
25
21
  try {
26
22
  hasLocalStorage = typeof localStorage !== "undefined";
27
23
  } catch (error) {}
28
-
29
24
  var hasProcess = typeof process !== "undefined";
30
25
  var shouldDebug = hasLocalStorage && /*#__PURE__*/localStorage.getItem("DEBUG") || hasProcess && process.env.DEBUG;
31
26
  var debugLog = shouldDebug ? console.log : function (_message) {
32
27
  return "";
33
28
  };
34
- /**
35
- * Makes a virtual copy of the TypeScript environment. This is the main API you want to be using with
36
- * @typescript/vfs. A lot of the other exposed functions are used by this function to get set up.
37
- *
38
- * @param sys an object which conforms to the TS Sys (a shim over read/write access to the fs)
39
- * @param rootFiles a list of files which are considered inside the project
40
- * @param ts a copy pf the TypeScript module
41
- * @param compilerOptions the options for this compiler run
42
- * @param customTransformers custom transformers for this compiler run
29
+ /**
30
+ * Makes a virtual copy of the TypeScript environment. This is the main API you want to be using with
31
+ * @typescript/vfs. A lot of the other exposed functions are used by this function to get set up.
32
+ *
33
+ * @param sys an object which conforms to the TS Sys (a shim over read/write access to the fs)
34
+ * @param rootFiles a list of files which are considered inside the project
35
+ * @param ts a copy pf the TypeScript module
36
+ * @param compilerOptions the options for this compiler run
37
+ * @param customTransformers custom transformers for this compiler run
43
38
  */
44
-
45
39
  function createVirtualTypeScriptEnvironment(sys, rootFiles, ts, compilerOptions, customTransformers) {
46
40
  if (compilerOptions === void 0) {
47
41
  compilerOptions = {};
48
42
  }
49
-
50
43
  var mergedCompilerOpts = _extends({}, defaultCompilerOptions(ts), compilerOptions);
51
-
52
44
  var _createVirtualLanguag = createVirtualLanguageServiceHost(sys, rootFiles, mergedCompilerOpts, ts, customTransformers),
53
- languageServiceHost = _createVirtualLanguag.languageServiceHost,
54
- _updateFile = _createVirtualLanguag.updateFile;
55
-
45
+ languageServiceHost = _createVirtualLanguag.languageServiceHost,
46
+ _updateFile = _createVirtualLanguag.updateFile;
56
47
  var languageService = ts.createLanguageService(languageServiceHost);
57
48
  var diagnostics = languageService.getCompilerOptionsDiagnostics();
58
-
59
49
  if (diagnostics.length) {
60
50
  var compilerHost = createVirtualCompilerHost(sys, compilerOptions, ts);
61
51
  throw new Error(ts.formatDiagnostics(diagnostics, compilerHost.compilerHost));
62
52
  }
63
-
64
53
  return {
65
54
  // @ts-ignore
66
55
  name: "vfs",
@@ -68,7 +57,6 @@ function createVirtualTypeScriptEnvironment(sys, rootFiles, ts, compilerOptions,
68
57
  languageService: languageService,
69
58
  getSourceFile: function getSourceFile(fileName) {
70
59
  var _languageService$getP;
71
-
72
60
  return (_languageService$getP = languageService.getProgram()) == null ? void 0 : _languageService$getP.getSourceFile(fileName);
73
61
  },
74
62
  createFile: function createFile(fileName, content) {
@@ -76,49 +64,49 @@ function createVirtualTypeScriptEnvironment(sys, rootFiles, ts, compilerOptions,
76
64
  },
77
65
  updateFile: function updateFile(fileName, content, optPrevTextSpan) {
78
66
  var prevSourceFile = languageService.getProgram().getSourceFile(fileName);
79
-
80
67
  if (!prevSourceFile) {
81
68
  throw new Error("Did not find a source file for " + fileName);
82
69
  }
83
-
84
- var prevFullContents = prevSourceFile.text; // TODO: Validate if the default text span has a fencepost error?
85
-
70
+ var prevFullContents = prevSourceFile.text;
71
+ // TODO: Validate if the default text span has a fencepost error?
86
72
  var prevTextSpan = optPrevTextSpan != null ? optPrevTextSpan : ts.createTextSpan(0, prevFullContents.length);
87
73
  var newText = prevFullContents.slice(0, prevTextSpan.start) + content + prevFullContents.slice(prevTextSpan.start + prevTextSpan.length);
88
74
  var newSourceFile = ts.updateSourceFile(prevSourceFile, newText, {
89
75
  span: prevTextSpan,
90
76
  newLength: content.length
91
77
  });
92
-
93
78
  _updateFile(newSourceFile);
94
79
  }
95
80
  };
96
81
  }
97
- /**
98
- * Grab the list of lib files for a particular target, will return a bit more than necessary (by including
99
- * the dom) but that's OK
100
- *
101
- * @param target The compiler settings target baseline
102
- * @param ts A copy of the TypeScript module
82
+ // TODO: This could be replaced by grabbing: https://github.com/microsoft/TypeScript/blob/main/src/lib/libs.json
83
+ // and then using that to generate the list of files from the server, but it is not included in the npm package
84
+ /**
85
+ * Grab the list of lib files for a particular target, will return a bit more than necessary (by including
86
+ * the dom) but that's OK, we're really working with the constraint that you can't get a list of files
87
+ * when running in a browser.
88
+ *
89
+ * @param target The compiler settings target baseline
90
+ * @param ts A copy of the TypeScript module
103
91
  */
104
-
105
92
  var knownLibFilesForCompilerOptions = function knownLibFilesForCompilerOptions(compilerOptions, ts) {
106
93
  var target = compilerOptions.target || ts.ScriptTarget.ES5;
107
94
  var lib = compilerOptions.lib || [];
108
- var files = ["lib.d.ts", "lib.dom.d.ts", "lib.dom.iterable.d.ts", "lib.webworker.d.ts", "lib.webworker.importscripts.d.ts", "lib.scripthost.d.ts", "lib.es5.d.ts", "lib.es6.d.ts", "lib.es2015.collection.d.ts", "lib.es2015.core.d.ts", "lib.es2015.d.ts", "lib.es2015.generator.d.ts", "lib.es2015.iterable.d.ts", "lib.es2015.promise.d.ts", "lib.es2015.proxy.d.ts", "lib.es2015.reflect.d.ts", "lib.es2015.symbol.d.ts", "lib.es2015.symbol.wellknown.d.ts", "lib.es2016.array.include.d.ts", "lib.es2016.d.ts", "lib.es2016.full.d.ts", "lib.es2017.d.ts", "lib.es2017.full.d.ts", "lib.es2017.intl.d.ts", "lib.es2017.object.d.ts", "lib.es2017.sharedmemory.d.ts", "lib.es2017.string.d.ts", "lib.es2017.typedarrays.d.ts", "lib.es2018.asyncgenerator.d.ts", "lib.es2018.asynciterable.d.ts", "lib.es2018.d.ts", "lib.es2018.full.d.ts", "lib.es2018.intl.d.ts", "lib.es2018.promise.d.ts", "lib.es2018.regexp.d.ts", "lib.es2019.array.d.ts", "lib.es2019.d.ts", "lib.es2019.full.d.ts", "lib.es2019.object.d.ts", "lib.es2019.string.d.ts", "lib.es2019.symbol.d.ts", "lib.es2020.d.ts", "lib.es2020.full.d.ts", "lib.es2020.string.d.ts", "lib.es2020.symbol.wellknown.d.ts", "lib.es2020.bigint.d.ts", "lib.es2020.promise.d.ts", "lib.es2020.sharedmemory.d.ts", "lib.es2020.intl.d.ts", "lib.es2021.d.ts", "lib.es2021.full.d.ts", "lib.es2021.promise.d.ts", "lib.es2021.string.d.ts", "lib.es2021.weakref.d.ts", "lib.esnext.d.ts", "lib.esnext.full.d.ts", "lib.esnext.intl.d.ts", "lib.esnext.promise.d.ts", "lib.esnext.string.d.ts", "lib.esnext.weakref.d.ts"];
95
+ // Note that this will include files which can't be found for particular versions of TS
96
+ // TODO: Replace this with some sort of API call if https://github.com/microsoft/TypeScript/pull/54011
97
+ // or similar is merged.
98
+ var files = ["lib.d.ts", "lib.decorators.d.ts", "lib.decorators.legacy.d.ts", "lib.dom.d.ts", "lib.dom.iterable.d.ts", "lib.webworker.d.ts", "lib.webworker.importscripts.d.ts", "lib.webworker.iterable.d.ts", "lib.scripthost.d.ts", "lib.es5.d.ts", "lib.es6.d.ts", "lib.es2015.collection.d.ts", "lib.es2015.core.d.ts", "lib.es2015.d.ts", "lib.es2015.generator.d.ts", "lib.es2015.iterable.d.ts", "lib.es2015.promise.d.ts", "lib.es2015.proxy.d.ts", "lib.es2015.reflect.d.ts", "lib.es2015.symbol.d.ts", "lib.es2015.symbol.wellknown.d.ts", "lib.es2016.array.include.d.ts", "lib.es2016.d.ts", "lib.es2016.full.d.ts", "lib.es2017.d.ts", "lib.es2017.date.d.ts", "lib.es2017.full.d.ts", "lib.es2017.intl.d.ts", "lib.es2017.object.d.ts", "lib.es2017.sharedmemory.d.ts", "lib.es2017.string.d.ts", "lib.es2017.typedarrays.d.ts", "lib.es2018.asyncgenerator.d.ts", "lib.es2018.asynciterable.d.ts", "lib.es2018.d.ts", "lib.es2018.full.d.ts", "lib.es2018.intl.d.ts", "lib.es2018.promise.d.ts", "lib.es2018.regexp.d.ts", "lib.es2019.array.d.ts", "lib.es2019.d.ts", "lib.es2019.full.d.ts", "lib.es2019.intl.d.ts", "lib.es2019.object.d.ts", "lib.es2019.string.d.ts", "lib.es2019.symbol.d.ts", "lib.es2020.bigint.d.ts", "lib.es2020.d.ts", "lib.es2020.date.d.ts", "lib.es2020.full.d.ts", "lib.es2020.intl.d.ts", "lib.es2020.number.d.ts", "lib.es2020.promise.d.ts", "lib.es2020.sharedmemory.d.ts", "lib.es2020.string.d.ts", "lib.es2020.symbol.wellknown.d.ts", "lib.es2021.d.ts", "lib.es2021.full.d.ts", "lib.es2021.intl.d.ts", "lib.es2021.promise.d.ts", "lib.es2021.string.d.ts", "lib.es2021.weakref.d.ts", "lib.es2022.array.d.ts", "lib.es2022.d.ts", "lib.es2022.error.d.ts", "lib.es2022.full.d.ts", "lib.es2022.intl.d.ts", "lib.es2022.object.d.ts", "lib.es2022.regexp.d.ts", "lib.es2022.sharedmemory.d.ts", "lib.es2022.string.d.ts", "lib.es2023.array.d.ts", "lib.es2023.collection.d.ts", "lib.es2023.d.ts", "lib.es2023.full.d.ts", "lib.esnext.array.d.ts", "lib.esnext.asynciterable.d.ts", "lib.esnext.bigint.d.ts", "lib.esnext.d.ts", "lib.esnext.decorators.d.ts", "lib.esnext.disposable.d.ts", "lib.esnext.full.d.ts", "lib.esnext.intl.d.ts", "lib.esnext.promise.d.ts", "lib.esnext.string.d.ts", "lib.esnext.symbol.d.ts", "lib.esnext.weakref.d.ts"];
109
99
  var targetToCut = ts.ScriptTarget[target];
110
100
  var matches = files.filter(function (f) {
111
101
  return f.startsWith("lib." + targetToCut.toLowerCase());
112
102
  });
113
103
  var targetCutIndex = files.indexOf(matches.pop());
114
-
115
104
  var getMax = function getMax(array) {
116
105
  return array && array.length ? array.reduce(function (max, current) {
117
106
  return current > max ? current : max;
118
107
  }) : undefined;
119
- }; // Find the index for everything in
120
-
121
-
108
+ };
109
+ // Find the index for everything in
122
110
  var indexesForCutting = lib.map(function (lib) {
123
111
  var matches = files.filter(function (f) {
124
112
  return f.startsWith("lib." + lib.toLowerCase());
@@ -131,44 +119,42 @@ var knownLibFilesForCompilerOptions = function knownLibFilesForCompilerOptions(c
131
119
  var finalCutIndex = Math.max(targetCutIndex, libCutIndex);
132
120
  return files.slice(0, finalCutIndex + 1);
133
121
  };
134
- /**
135
- * Sets up a Map with lib contents by grabbing the necessary files from
136
- * the local copy of typescript via the file system.
122
+ /**
123
+ * Sets up a Map with lib contents by grabbing the necessary files from
124
+ * the local copy of typescript via the file system.
125
+ *
126
+ * The first two args are un-used, but kept around so as to not cause a
127
+ * semver major bump for no gain to module users.
137
128
  */
138
-
139
- var createDefaultMapFromNodeModules = function createDefaultMapFromNodeModules(compilerOptions, ts, tsLibDirectory) {
140
- var tsModule = ts || require("typescript");
141
-
129
+ var createDefaultMapFromNodeModules = function createDefaultMapFromNodeModules(_compilerOptions, _ts, tsLibDirectory) {
142
130
  var path = requirePath();
143
131
  var fs = requireFS();
144
-
145
132
  var getLib = function getLib(name) {
146
133
  var lib = tsLibDirectory || path.dirname(require.resolve("typescript"));
147
134
  return fs.readFileSync(path.join(lib, name), "utf8");
148
135
  };
149
-
150
- var libs = knownLibFilesForCompilerOptions(compilerOptions, tsModule);
136
+ var libFiles = fs.readdirSync(tsLibDirectory || path.dirname(require.resolve("typescript")));
137
+ var knownLibFiles = libFiles.filter(function (f) {
138
+ return f.startsWith("lib.") && f.endsWith(".d.ts");
139
+ });
151
140
  var fsMap = new Map();
152
- libs.forEach(function (lib) {
141
+ knownLibFiles.forEach(function (lib) {
153
142
  fsMap.set("/" + lib, getLib(lib));
154
143
  });
155
144
  return fsMap;
156
145
  };
157
- /**
158
- * Adds recursively files from the FS into the map based on the folder
146
+ /**
147
+ * Adds recursively files from the FS into the map based on the folder
159
148
  */
160
-
161
149
  var addAllFilesFromFolder = function addAllFilesFromFolder(map, workingDir) {
162
150
  var path = requirePath();
163
151
  var fs = requireFS();
164
-
165
152
  var walk = function walk(dir) {
166
153
  var results = [];
167
154
  var list = fs.readdirSync(dir);
168
155
  list.forEach(function (file) {
169
156
  file = path.join(dir, file);
170
157
  var stat = fs.statSync(file);
171
-
172
158
  if (stat && stat.isDirectory()) {
173
159
  /* Recurse into a subdirectory */
174
160
  results = results.concat(walk(file));
@@ -179,51 +165,44 @@ var addAllFilesFromFolder = function addAllFilesFromFolder(map, workingDir) {
179
165
  });
180
166
  return results;
181
167
  };
182
-
183
168
  var allFiles = walk(workingDir);
184
169
  allFiles.forEach(function (lib) {
185
170
  var fsPath = "/node_modules/@types" + lib.replace(workingDir, "");
186
171
  var content = fs.readFileSync(lib, "utf8");
187
172
  var validExtensions = [".ts", ".tsx"];
188
-
189
173
  if (validExtensions.includes(path.extname(fsPath))) {
190
174
  map.set(fsPath, content);
191
175
  }
192
176
  });
193
177
  };
194
178
  /** Adds all files from node_modules/@types into the FS Map */
195
-
196
179
  var addFilesForTypesIntoFolder = function addFilesForTypesIntoFolder(map) {
197
180
  return addAllFilesFromFolder(map, "node_modules/@types");
198
181
  };
199
- /**
200
- * Create a virtual FS Map with the lib files from a particular TypeScript
201
- * version based on the target, Always includes dom ATM.
202
- *
203
- * @param options The compiler target, which dictates the libs to set up
204
- * @param version the versions of TypeScript which are supported
205
- * @param cache should the values be stored in local storage
206
- * @param ts a copy of the typescript import
207
- * @param lzstring an optional copy of the lz-string import
208
- * @param fetcher an optional replacement for the global fetch function (tests mainly)
209
- * @param storer an optional replacement for the localStorage global (tests mainly)
182
+ /**
183
+ * Create a virtual FS Map with the lib files from a particular TypeScript
184
+ * version based on the target, Always includes dom ATM.
185
+ *
186
+ * @param options The compiler target, which dictates the libs to set up
187
+ * @param version the versions of TypeScript which are supported
188
+ * @param cache should the values be stored in local storage
189
+ * @param ts a copy of the typescript import
190
+ * @param lzstring an optional copy of the lz-string import
191
+ * @param fetcher an optional replacement for the global fetch function (tests mainly)
192
+ * @param storer an optional replacement for the localStorage global (tests mainly)
210
193
  */
211
-
212
194
  var createDefaultMapFromCDN = function createDefaultMapFromCDN(options, version, cache, ts, lzstring, fetcher, storer) {
213
195
  var fetchlike = fetcher || fetch;
214
196
  var fsMap = new Map();
215
197
  var files = knownLibFilesForCompilerOptions(options, ts);
216
198
  var prefix = "https://typescript.azureedge.net/cdn/" + version + "/typescript/lib/";
217
-
218
199
  function zip(str) {
219
200
  return lzstring ? lzstring.compressToUTF16(str) : str;
220
201
  }
221
-
222
202
  function unzip(str) {
223
203
  return lzstring ? lzstring.decompressFromUTF16(str) : str;
224
- } // Map the known libs to a node fetch promise, then return the contents
225
-
226
-
204
+ }
205
+ // Map the known libs to a node fetch promise, then return the contents
227
206
  function uncached() {
228
207
  return Promise.all(files.map(function (lib) {
229
208
  return fetchlike(prefix + lib).then(function (resp) {
@@ -233,13 +212,14 @@ var createDefaultMapFromCDN = function createDefaultMapFromCDN(options, version,
233
212
  contents.forEach(function (text, index) {
234
213
  return fsMap.set("/" + files[index], text);
235
214
  });
236
- });
237
- } // A localstorage and lzzip aware version of the lib files
238
-
239
-
215
+ })
216
+ // Return a NOOP for .d.ts files which aren't in the current build of TypeScript
217
+ ["catch"](function () {});
218
+ }
219
+ // A localstorage and lzzip aware version of the lib files
240
220
  function cached() {
241
221
  var storelike = storer || localStorage;
242
- var keys = Object.keys(localStorage);
222
+ var keys = Object.keys(storelike);
243
223
  keys.forEach(function (key) {
244
224
  // Remove anything which isn't from this version
245
225
  if (key.startsWith("ts-lib-") && !key.startsWith("ts-lib-" + version)) {
@@ -249,7 +229,6 @@ var createDefaultMapFromCDN = function createDefaultMapFromCDN(options, version,
249
229
  return Promise.all(files.map(function (lib) {
250
230
  var cacheKey = "ts-lib-" + version + "-" + lib;
251
231
  var content = storelike.getItem(cacheKey);
252
-
253
232
  if (!content) {
254
233
  // Make the API call and store the text concent in the cache
255
234
  return fetchlike(prefix + lib).then(function (resp) {
@@ -257,34 +236,34 @@ var createDefaultMapFromCDN = function createDefaultMapFromCDN(options, version,
257
236
  }).then(function (t) {
258
237
  storelike.setItem(cacheKey, zip(t));
259
238
  return t;
260
- });
239
+ })
240
+ // Return a NOOP for .d.ts files which aren't in the current build of TypeScript
241
+ ["catch"](function () {});
261
242
  } else {
262
243
  return Promise.resolve(unzip(content));
263
244
  }
264
245
  })).then(function (contents) {
265
246
  contents.forEach(function (text, index) {
266
- var name = "/" + files[index];
267
- fsMap.set(name, text);
247
+ if (text) {
248
+ var name = "/" + files[index];
249
+ fsMap.set(name, text);
250
+ }
268
251
  });
269
252
  });
270
253
  }
271
-
272
254
  var func = cache ? cached : uncached;
273
255
  return func().then(function () {
274
256
  return fsMap;
275
257
  });
276
258
  };
277
-
278
259
  function notImplemented(methodName) {
279
260
  throw new Error("Method '" + methodName + "' is not implemented.");
280
261
  }
281
-
282
262
  function audit(name, fn) {
283
263
  return function () {
284
264
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
285
265
  args[_key] = arguments[_key];
286
266
  }
287
-
288
267
  var res = fn.apply(void 0, args);
289
268
  var smallres = typeof res === "string" ? res.slice(0, 80) + "..." : res;
290
269
  debugLog.apply(void 0, ["> " + name].concat(args));
@@ -293,8 +272,6 @@ function audit(name, fn) {
293
272
  };
294
273
  }
295
274
  /** The default compiler options if TypeScript could ever change the compiler options */
296
-
297
-
298
275
  var defaultCompilerOptions = function defaultCompilerOptions(ts) {
299
276
  return _extends({}, ts.getDefaultCompilerOptions(), {
300
277
  jsx: ts.JsxEmit.React,
@@ -306,18 +283,15 @@ var defaultCompilerOptions = function defaultCompilerOptions(ts) {
306
283
  skipDefaultLibCheck: true,
307
284
  moduleResolution: ts.ModuleResolutionKind.NodeJs
308
285
  });
309
- }; // "/DOM.d.ts" => "/lib.dom.d.ts"
310
-
311
-
286
+ };
287
+ // "/DOM.d.ts" => "/lib.dom.d.ts"
312
288
  var libize = function libize(path) {
313
289
  return path.replace("/", "/lib.").toLowerCase();
314
290
  };
315
- /**
316
- * Creates an in-memory System object which can be used in a TypeScript program, this
317
- * is what provides read/write aspects of the virtual fs
291
+ /**
292
+ * Creates an in-memory System object which can be used in a TypeScript program, this
293
+ * is what provides read/write aspects of the virtual fs
318
294
  */
319
-
320
-
321
295
  function createSystem(files) {
322
296
  return {
323
297
  args: [],
@@ -364,18 +338,17 @@ function createSystem(files) {
364
338
  }
365
339
  };
366
340
  }
367
- /**
368
- * Creates a file-system backed System object which can be used in a TypeScript program, you provide
369
- * a set of virtual files which are prioritised over the FS versions, then a path to the root of your
370
- * project (basically the folder your node_modules lives)
341
+ /**
342
+ * Creates a file-system backed System object which can be used in a TypeScript program, you provide
343
+ * a set of virtual files which are prioritised over the FS versions, then a path to the root of your
344
+ * project (basically the folder your node_modules lives)
371
345
  */
372
-
373
346
  function createFSBackedSystem(files, _projectRoot, ts, tsLibDirectory) {
374
347
  // We need to make an isolated folder for the tsconfig, but also need to be able to resolve the
375
348
  // existing node_modules structures going back through the history
376
349
  var root = _projectRoot + "/vfs";
377
- var path = requirePath(); // The default System in TypeScript
378
-
350
+ var path = requirePath();
351
+ // The default System in TypeScript
379
352
  var nodeSys = ts.sys;
380
353
  var tsLib = tsLibDirectory != null ? tsLibDirectory : path.dirname(require.resolve("typescript"));
381
354
  return {
@@ -394,15 +367,13 @@ function createFSBackedSystem(files, _projectRoot, ts, tsLibDirectory) {
394
367
  }),
395
368
  exit: nodeSys.exit,
396
369
  fileExists: audit("fileExists", function (fileName) {
397
- if (files.has(fileName)) return true; // Don't let other tsconfigs end up touching the vfs
398
-
370
+ if (files.has(fileName)) return true;
371
+ // Don't let other tsconfigs end up touching the vfs
399
372
  if (fileName.includes("tsconfig.json") || fileName.includes("tsconfig.json")) return false;
400
-
401
373
  if (fileName.startsWith("/lib")) {
402
374
  var tsLibName = tsLib + "/" + fileName.replace("/", "");
403
375
  return nodeSys.fileExists(tsLibName);
404
376
  }
405
-
406
377
  return nodeSys.fileExists(fileName);
407
378
  }),
408
379
  getCurrentDirectory: function getCurrentDirectory() {
@@ -421,19 +392,15 @@ function createFSBackedSystem(files, _projectRoot, ts, tsLibDirectory) {
421
392
  }),
422
393
  readFile: audit("readFile", function (fileName) {
423
394
  if (files.has(fileName)) return files.get(fileName);
424
-
425
395
  if (fileName.startsWith("/lib")) {
426
396
  var tsLibName = tsLib + "/" + fileName.replace("/", "");
427
397
  var result = nodeSys.readFile(tsLibName);
428
-
429
398
  if (!result) {
430
399
  var libs = nodeSys.readDirectory(tsLib);
431
400
  throw new Error("TSVFS: A request was made for " + tsLibName + " but there wasn't a file found in the file map. You likely have a mismatch in the compiler options for the CDN download vs the compiler program. Existing Libs: " + libs + ".");
432
401
  }
433
-
434
402
  return result;
435
403
  }
436
-
437
404
  return nodeSys.readFile(fileName);
438
405
  }),
439
406
  resolvePath: function resolvePath(path) {
@@ -450,20 +417,17 @@ function createFSBackedSystem(files, _projectRoot, ts, tsLibDirectory) {
450
417
  }
451
418
  };
452
419
  }
453
- /**
454
- * Creates an in-memory CompilerHost -which is essentially an extra wrapper to System
455
- * which works with TypeScript objects - returns both a compiler host, and a way to add new SourceFile
456
- * instances to the in-memory file system.
420
+ /**
421
+ * Creates an in-memory CompilerHost -which is essentially an extra wrapper to System
422
+ * which works with TypeScript objects - returns both a compiler host, and a way to add new SourceFile
423
+ * instances to the in-memory file system.
457
424
  */
458
-
459
425
  function createVirtualCompilerHost(sys, compilerOptions, ts) {
460
426
  var sourceFiles = new Map();
461
-
462
427
  var save = function save(sourceFile) {
463
428
  sourceFiles.set(sourceFile.fileName, sourceFile);
464
429
  return sourceFile;
465
430
  };
466
-
467
431
  var vHost = {
468
432
  compilerHost: _extends({}, sys, {
469
433
  getCanonicalFileName: function getCanonicalFileName(fileName) {
@@ -472,6 +436,7 @@ function createVirtualCompilerHost(sys, compilerOptions, ts) {
472
436
  getDefaultLibFileName: function getDefaultLibFileName() {
473
437
  return "/" + ts.getDefaultLibFileName(compilerOptions);
474
438
  },
439
+ // '/lib.d.ts',
475
440
  // getDefaultLibLocation: () => '/',
476
441
  getDirectories: function getDirectories() {
477
442
  return [];
@@ -495,20 +460,16 @@ function createVirtualCompilerHost(sys, compilerOptions, ts) {
495
460
  };
496
461
  return vHost;
497
462
  }
498
- /**
499
- * Creates an object which can host a language service against the virtual file-system
463
+ /**
464
+ * Creates an object which can host a language service against the virtual file-system
500
465
  */
501
-
502
466
  function createVirtualLanguageServiceHost(sys, rootFiles, compilerOptions, ts, customTransformers) {
503
467
  var fileNames = [].concat(rootFiles);
504
-
505
468
  var _createVirtualCompile = createVirtualCompilerHost(sys, compilerOptions, ts),
506
- compilerHost = _createVirtualCompile.compilerHost,
507
- _updateFile2 = _createVirtualCompile.updateFile;
508
-
469
+ compilerHost = _createVirtualCompile.compilerHost,
470
+ _updateFile2 = _createVirtualCompile.updateFile;
509
471
  var fileVersions = new Map();
510
472
  var projectVersion = 0;
511
-
512
473
  var languageServiceHost = _extends({}, compilerHost, {
513
474
  getProjectVersion: function getProjectVersion() {
514
475
  return projectVersion.toString();
@@ -532,11 +493,9 @@ function createVirtualLanguageServiceHost(sys, rootFiles, compilerOptions, ts, c
532
493
  },
533
494
  getScriptSnapshot: function getScriptSnapshot(fileName) {
534
495
  var contents = sys.readFile(fileName);
535
-
536
- if (contents) {
496
+ if (contents && typeof contents === "string") {
537
497
  return ts.ScriptSnapshot.fromString(contents);
538
498
  }
539
-
540
499
  return;
541
500
  },
542
501
  getScriptVersion: function getScriptVersion(fileName) {
@@ -544,27 +503,22 @@ function createVirtualLanguageServiceHost(sys, rootFiles, compilerOptions, ts, c
544
503
  },
545
504
  writeFile: sys.writeFile
546
505
  });
547
-
548
506
  var lsHost = {
549
507
  languageServiceHost: languageServiceHost,
550
508
  updateFile: function updateFile(sourceFile) {
551
509
  projectVersion++;
552
510
  fileVersions.set(sourceFile.fileName, projectVersion.toString());
553
-
554
511
  if (!fileNames.includes(sourceFile.fileName)) {
555
512
  fileNames.push(sourceFile.fileName);
556
513
  }
557
-
558
514
  _updateFile2(sourceFile);
559
515
  }
560
516
  };
561
517
  return lsHost;
562
518
  }
563
-
564
519
  var requirePath = function requirePath() {
565
520
  return require(String.fromCharCode(112, 97, 116, 104));
566
521
  };
567
-
568
522
  var requireFS = function requireFS() {
569
523
  return require(String.fromCharCode(102, 115));
570
524
  };