@typescript/vfs 1.4.0 → 1.5.0
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/dist/index.d.ts +89 -85
- package/dist/vfs.cjs.development.js +71 -57
- package/dist/vfs.cjs.development.js.map +1 -1
- package/dist/vfs.cjs.production.min.js +1 -1
- package/dist/vfs.cjs.production.min.js.map +1 -1
- package/dist/vfs.esm.js +71 -57
- package/dist/vfs.esm.js.map +1 -1
- package/dist/vfs.globals.js +71 -57
- package/package.json +13 -2
- package/CHANGELOG.md +0 -15
package/dist/vfs.globals.js
CHANGED
|
@@ -27,15 +27,15 @@ var shouldDebug = hasLocalStorage && /*#__PURE__*/localStorage.getItem("DEBUG")
|
|
|
27
27
|
var debugLog = shouldDebug ? console.log : function (_message) {
|
|
28
28
|
return "";
|
|
29
29
|
};
|
|
30
|
-
/**
|
|
31
|
-
* Makes a virtual copy of the TypeScript environment. This is the main API you want to be using with
|
|
32
|
-
* @typescript/vfs. A lot of the other exposed functions are used by this function to get set up.
|
|
33
|
-
*
|
|
34
|
-
* @param sys an object which conforms to the TS Sys (a shim over read/write access to the fs)
|
|
35
|
-
* @param rootFiles a list of files which are considered inside the project
|
|
36
|
-
* @param ts a copy pf the TypeScript module
|
|
37
|
-
* @param compilerOptions the options for this compiler run
|
|
38
|
-
* @param customTransformers custom transformers for this compiler run
|
|
30
|
+
/**
|
|
31
|
+
* Makes a virtual copy of the TypeScript environment. This is the main API you want to be using with
|
|
32
|
+
* @typescript/vfs. A lot of the other exposed functions are used by this function to get set up.
|
|
33
|
+
*
|
|
34
|
+
* @param sys an object which conforms to the TS Sys (a shim over read/write access to the fs)
|
|
35
|
+
* @param rootFiles a list of files which are considered inside the project
|
|
36
|
+
* @param ts a copy pf the TypeScript module
|
|
37
|
+
* @param compilerOptions the options for this compiler run
|
|
38
|
+
* @param customTransformers custom transformers for this compiler run
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
function createVirtualTypeScriptEnvironment(sys, rootFiles, ts, compilerOptions, customTransformers) {
|
|
@@ -89,19 +89,25 @@ function createVirtualTypeScriptEnvironment(sys, rootFiles, ts, compilerOptions,
|
|
|
89
89
|
_updateFile(newSourceFile);
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
92
|
+
} // TODO: This could be replaced by grabbing: https://github.com/microsoft/TypeScript/blob/main/src/lib/libs.json
|
|
93
|
+
// and then using that to generate the list of files from the server, but it is not included in the npm package
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Grab the list of lib files for a particular target, will return a bit more than necessary (by including
|
|
97
|
+
* the dom) but that's OK, we're really working with the constraint that you can't get a list of files
|
|
98
|
+
* when running in a browser.
|
|
99
|
+
*
|
|
100
|
+
* @param target The compiler settings target baseline
|
|
101
|
+
* @param ts A copy of the TypeScript module
|
|
99
102
|
*/
|
|
100
103
|
|
|
101
104
|
var knownLibFilesForCompilerOptions = function knownLibFilesForCompilerOptions(compilerOptions, ts) {
|
|
102
105
|
var target = compilerOptions.target || ts.ScriptTarget.ES5;
|
|
103
|
-
var lib = compilerOptions.lib || [];
|
|
104
|
-
|
|
106
|
+
var lib = compilerOptions.lib || []; // Note that this will include files which can't be found for particular versions of TS
|
|
107
|
+
// TODO: Replace this with some sort of API call if https://github.com/microsoft/TypeScript/pull/54011
|
|
108
|
+
// or similar is merged.
|
|
109
|
+
|
|
110
|
+
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"];
|
|
105
111
|
var targetToCut = ts.ScriptTarget[target];
|
|
106
112
|
var matches = files.filter(function (f) {
|
|
107
113
|
return f.startsWith("lib." + targetToCut.toLowerCase());
|
|
@@ -127,14 +133,15 @@ var knownLibFilesForCompilerOptions = function knownLibFilesForCompilerOptions(c
|
|
|
127
133
|
var finalCutIndex = Math.max(targetCutIndex, libCutIndex);
|
|
128
134
|
return files.slice(0, finalCutIndex + 1);
|
|
129
135
|
};
|
|
130
|
-
/**
|
|
131
|
-
* Sets up a Map with lib contents by grabbing the necessary files from
|
|
132
|
-
* the local copy of typescript via the file system.
|
|
136
|
+
/**
|
|
137
|
+
* Sets up a Map with lib contents by grabbing the necessary files from
|
|
138
|
+
* the local copy of typescript via the file system.
|
|
139
|
+
*
|
|
140
|
+
* The first two args are un-used, but kept around so as to not cause a
|
|
141
|
+
* semver major bump for no gain to module users.
|
|
133
142
|
*/
|
|
134
143
|
|
|
135
|
-
var createDefaultMapFromNodeModules = function createDefaultMapFromNodeModules(
|
|
136
|
-
var tsModule = ts || require("typescript");
|
|
137
|
-
|
|
144
|
+
var createDefaultMapFromNodeModules = function createDefaultMapFromNodeModules(_compilerOptions, _ts, tsLibDirectory) {
|
|
138
145
|
var path = requirePath();
|
|
139
146
|
var fs = requireFS();
|
|
140
147
|
|
|
@@ -143,15 +150,18 @@ var createDefaultMapFromNodeModules = function createDefaultMapFromNodeModules(c
|
|
|
143
150
|
return fs.readFileSync(path.join(lib, name), "utf8");
|
|
144
151
|
};
|
|
145
152
|
|
|
146
|
-
var
|
|
153
|
+
var libFiles = fs.readdirSync(tsLibDirectory || path.dirname(require.resolve("typescript")));
|
|
154
|
+
var knownLibFiles = libFiles.filter(function (f) {
|
|
155
|
+
return f.startsWith("lib.") && f.endsWith(".d.ts");
|
|
156
|
+
});
|
|
147
157
|
var fsMap = new Map();
|
|
148
|
-
|
|
158
|
+
knownLibFiles.forEach(function (lib) {
|
|
149
159
|
fsMap.set("/" + lib, getLib(lib));
|
|
150
160
|
});
|
|
151
161
|
return fsMap;
|
|
152
162
|
};
|
|
153
|
-
/**
|
|
154
|
-
* Adds recursively files from the FS into the map based on the folder
|
|
163
|
+
/**
|
|
164
|
+
* Adds recursively files from the FS into the map based on the folder
|
|
155
165
|
*/
|
|
156
166
|
|
|
157
167
|
var addAllFilesFromFolder = function addAllFilesFromFolder(map, workingDir) {
|
|
@@ -192,17 +202,17 @@ var addAllFilesFromFolder = function addAllFilesFromFolder(map, workingDir) {
|
|
|
192
202
|
var addFilesForTypesIntoFolder = function addFilesForTypesIntoFolder(map) {
|
|
193
203
|
return addAllFilesFromFolder(map, "node_modules/@types");
|
|
194
204
|
};
|
|
195
|
-
/**
|
|
196
|
-
* Create a virtual FS Map with the lib files from a particular TypeScript
|
|
197
|
-
* version based on the target, Always includes dom ATM.
|
|
198
|
-
*
|
|
199
|
-
* @param options The compiler target, which dictates the libs to set up
|
|
200
|
-
* @param version the versions of TypeScript which are supported
|
|
201
|
-
* @param cache should the values be stored in local storage
|
|
202
|
-
* @param ts a copy of the typescript import
|
|
203
|
-
* @param lzstring an optional copy of the lz-string import
|
|
204
|
-
* @param fetcher an optional replacement for the global fetch function (tests mainly)
|
|
205
|
-
* @param storer an optional replacement for the localStorage global (tests mainly)
|
|
205
|
+
/**
|
|
206
|
+
* Create a virtual FS Map with the lib files from a particular TypeScript
|
|
207
|
+
* version based on the target, Always includes dom ATM.
|
|
208
|
+
*
|
|
209
|
+
* @param options The compiler target, which dictates the libs to set up
|
|
210
|
+
* @param version the versions of TypeScript which are supported
|
|
211
|
+
* @param cache should the values be stored in local storage
|
|
212
|
+
* @param ts a copy of the typescript import
|
|
213
|
+
* @param lzstring an optional copy of the lz-string import
|
|
214
|
+
* @param fetcher an optional replacement for the global fetch function (tests mainly)
|
|
215
|
+
* @param storer an optional replacement for the localStorage global (tests mainly)
|
|
206
216
|
*/
|
|
207
217
|
|
|
208
218
|
var createDefaultMapFromCDN = function createDefaultMapFromCDN(options, version, cache, ts, lzstring, fetcher, storer) {
|
|
@@ -229,13 +239,14 @@ var createDefaultMapFromCDN = function createDefaultMapFromCDN(options, version,
|
|
|
229
239
|
contents.forEach(function (text, index) {
|
|
230
240
|
return fsMap.set("/" + files[index], text);
|
|
231
241
|
});
|
|
232
|
-
})
|
|
242
|
+
}) // Return a NOOP for .d.ts files which aren't in the current build of TypeScript
|
|
243
|
+
["catch"](function () {});
|
|
233
244
|
} // A localstorage and lzzip aware version of the lib files
|
|
234
245
|
|
|
235
246
|
|
|
236
247
|
function cached() {
|
|
237
248
|
var storelike = storer || localStorage;
|
|
238
|
-
var keys = Object.keys(
|
|
249
|
+
var keys = Object.keys(storelike);
|
|
239
250
|
keys.forEach(function (key) {
|
|
240
251
|
// Remove anything which isn't from this version
|
|
241
252
|
if (key.startsWith("ts-lib-") && !key.startsWith("ts-lib-" + version)) {
|
|
@@ -253,14 +264,17 @@ var createDefaultMapFromCDN = function createDefaultMapFromCDN(options, version,
|
|
|
253
264
|
}).then(function (t) {
|
|
254
265
|
storelike.setItem(cacheKey, zip(t));
|
|
255
266
|
return t;
|
|
256
|
-
})
|
|
267
|
+
}) // Return a NOOP for .d.ts files which aren't in the current build of TypeScript
|
|
268
|
+
["catch"](function () {});
|
|
257
269
|
} else {
|
|
258
270
|
return Promise.resolve(unzip(content));
|
|
259
271
|
}
|
|
260
272
|
})).then(function (contents) {
|
|
261
273
|
contents.forEach(function (text, index) {
|
|
262
|
-
|
|
263
|
-
|
|
274
|
+
if (text) {
|
|
275
|
+
var name = "/" + files[index];
|
|
276
|
+
fsMap.set(name, text);
|
|
277
|
+
}
|
|
264
278
|
});
|
|
265
279
|
});
|
|
266
280
|
}
|
|
@@ -308,9 +322,9 @@ var defaultCompilerOptions = function defaultCompilerOptions(ts) {
|
|
|
308
322
|
var libize = function libize(path) {
|
|
309
323
|
return path.replace("/", "/lib.").toLowerCase();
|
|
310
324
|
};
|
|
311
|
-
/**
|
|
312
|
-
* Creates an in-memory System object which can be used in a TypeScript program, this
|
|
313
|
-
* is what provides read/write aspects of the virtual fs
|
|
325
|
+
/**
|
|
326
|
+
* Creates an in-memory System object which can be used in a TypeScript program, this
|
|
327
|
+
* is what provides read/write aspects of the virtual fs
|
|
314
328
|
*/
|
|
315
329
|
|
|
316
330
|
|
|
@@ -360,10 +374,10 @@ function createSystem(files) {
|
|
|
360
374
|
}
|
|
361
375
|
};
|
|
362
376
|
}
|
|
363
|
-
/**
|
|
364
|
-
* Creates a file-system backed System object which can be used in a TypeScript program, you provide
|
|
365
|
-
* a set of virtual files which are prioritised over the FS versions, then a path to the root of your
|
|
366
|
-
* project (basically the folder your node_modules lives)
|
|
377
|
+
/**
|
|
378
|
+
* Creates a file-system backed System object which can be used in a TypeScript program, you provide
|
|
379
|
+
* a set of virtual files which are prioritised over the FS versions, then a path to the root of your
|
|
380
|
+
* project (basically the folder your node_modules lives)
|
|
367
381
|
*/
|
|
368
382
|
|
|
369
383
|
function createFSBackedSystem(files, _projectRoot, ts, tsLibDirectory) {
|
|
@@ -446,10 +460,10 @@ function createFSBackedSystem(files, _projectRoot, ts, tsLibDirectory) {
|
|
|
446
460
|
}
|
|
447
461
|
};
|
|
448
462
|
}
|
|
449
|
-
/**
|
|
450
|
-
* Creates an in-memory CompilerHost -which is essentially an extra wrapper to System
|
|
451
|
-
* which works with TypeScript objects - returns both a compiler host, and a way to add new SourceFile
|
|
452
|
-
* instances to the in-memory file system.
|
|
463
|
+
/**
|
|
464
|
+
* Creates an in-memory CompilerHost -which is essentially an extra wrapper to System
|
|
465
|
+
* which works with TypeScript objects - returns both a compiler host, and a way to add new SourceFile
|
|
466
|
+
* instances to the in-memory file system.
|
|
453
467
|
*/
|
|
454
468
|
|
|
455
469
|
function createVirtualCompilerHost(sys, compilerOptions, ts) {
|
|
@@ -491,8 +505,8 @@ function createVirtualCompilerHost(sys, compilerOptions, ts) {
|
|
|
491
505
|
};
|
|
492
506
|
return vHost;
|
|
493
507
|
}
|
|
494
|
-
/**
|
|
495
|
-
* Creates an object which can host a language service against the virtual file-system
|
|
508
|
+
/**
|
|
509
|
+
* Creates an object which can host a language service against the virtual file-system
|
|
496
510
|
*/
|
|
497
511
|
|
|
498
512
|
function createVirtualLanguageServiceHost(sys, rootFiles, compilerOptions, ts, customTransformers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript/vfs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "TypeScript team",
|
|
6
6
|
"homepage": "https://github.com/microsoft/TypeScript-Website",
|
|
@@ -24,9 +24,17 @@
|
|
|
24
24
|
"build": "tsdx build && yarn make-for-website && yarn make-global",
|
|
25
25
|
"make-for-website": "cpy src/index.ts ../sandbox/src/vendor --rename=typescript-vfs.ts",
|
|
26
26
|
"make-global": "node scripts/makeGlobals.js",
|
|
27
|
-
"test": "
|
|
27
|
+
"test": "jest",
|
|
28
28
|
"lint": "tsdx lint"
|
|
29
29
|
},
|
|
30
|
+
"jest": {
|
|
31
|
+
"preset": "ts-jest",
|
|
32
|
+
"testEnvironment": "jsdom",
|
|
33
|
+
"testPathIgnorePatterns": [
|
|
34
|
+
"/node_modules/",
|
|
35
|
+
".cache"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
30
38
|
"browser": {
|
|
31
39
|
"fs": false,
|
|
32
40
|
"lz-string": false,
|
|
@@ -39,6 +47,9 @@
|
|
|
39
47
|
"@types/jest": "^25.1.3",
|
|
40
48
|
"babel-jest": "^26.0.6",
|
|
41
49
|
"cpy-cli": "^3.1.1",
|
|
50
|
+
"jest": "^29.5.0",
|
|
51
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
52
|
+
"ts-jest": "^29.0.5",
|
|
42
53
|
"tsdx": "^0.14.1",
|
|
43
54
|
"tslib": "^1.10.0",
|
|
44
55
|
"typescript": "*"
|
package/CHANGELOG.md
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
### 1.3
|
|
2
|
-
|
|
3
|
-
- Adds a JS file into the npm tarball for using with a vanilla script tag, which sets `global.tsvfs` with exported function.
|
|
4
|
-
|
|
5
|
-
Unpkg URLS:
|
|
6
|
-
|
|
7
|
-
- https://unpkg.com/browse/@typescript/vfs@dist/vfs.globals.js
|
|
8
|
-
|
|
9
|
-
### 1.2
|
|
10
|
-
|
|
11
|
-
Updates `createFSBackedSystem` to rely more on the default TypeScript system object which should see twoslash code samples re-using the node_modules from the local project.
|
|
12
|
-
|
|
13
|
-
### 0.0 - 1.0 - 1.1
|
|
14
|
-
|
|
15
|
-
Created the lib, got it working
|