@typescript/vfs
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -69,3 +69,3 @@ /// <reference types="lz-string" /> | ||
*/ | ||
export declare function createFSBackedSystem(files: Map<string, string>, projectRoot: string): System; | ||
export declare function createFSBackedSystem(files: Map<string, string>, _projectRoot: string, ts: TS): System; | ||
/** | ||
@@ -72,0 +72,0 @@ * Creates an in-memory CompilerHost -which is essentially an extra wrapper to System |
@@ -278,3 +278,3 @@ 'use strict'; | ||
}); | ||
}; // TODO: Add some kind of debug logger (needs to be compat with sandbox's deployment, not just via npm) | ||
}; | ||
@@ -376,7 +376,12 @@ function notImplemented(methodName) { | ||
function createFSBackedSystem(files, projectRoot) { | ||
var fs = require("fs"); | ||
function createFSBackedSystem(files, _projectRoot, ts) { | ||
// We need to make an isolated folder for the tsconfig, but also need to be able to resolve the | ||
// existing node_modules structures going back through the history | ||
var root = _projectRoot + "/vfs"; | ||
var path = require("path"); | ||
var path = require("path"); // The default System in TypeScript | ||
var nodeSys = ts.sys; | ||
var tsLib = path.dirname(require.resolve("typescript")); | ||
return { | ||
@@ -391,47 +396,44 @@ args: [], | ||
return path.startsWith(directory); | ||
}) || fs.existsSync(path.join(projectRoot, directory)); | ||
}) || nodeSys.directoryExists(directory); | ||
}), | ||
exit: function exit() { | ||
return notImplemented("exit"); | ||
}, | ||
exit: nodeSys.exit, | ||
fileExists: audit("fileExists", function (fileName) { | ||
if (files.has(fileName)) return true; | ||
var fsPath = path.join(projectRoot, fileName); | ||
var libPath = path.join(projectRoot, "node_modules", "typescript", "lib", fileName); | ||
if (files.has(fileName)) return true; // Don't let other tsconfigs end up touching the vfs | ||
for (var _i = 0, _arr = [fsPath, libPath]; _i < _arr.length; _i++) { | ||
var filepath = _arr[_i]; | ||
if (fs.existsSync(filepath)) return true; | ||
if (fileName.includes("tsconfig.json") || fileName.includes("tsconfig.json")) return false; | ||
if (fileName.startsWith("/lib")) { | ||
var tsLibName = tsLib + "/" + fileName.replace("/", ""); | ||
return nodeSys.fileExists(tsLibName); | ||
} | ||
return false; | ||
return nodeSys.fileExists(fileName); | ||
}), | ||
getCurrentDirectory: function getCurrentDirectory() { | ||
return "/"; | ||
return root; | ||
}, | ||
getDirectories: function getDirectories() { | ||
return []; | ||
}, | ||
getDirectories: nodeSys.getDirectories, | ||
getExecutingFilePath: function getExecutingFilePath() { | ||
return notImplemented("getExecutingFilePath"); | ||
}, | ||
readDirectory: audit("readDirectory", function (directory) { | ||
return directory === "/" ? Array.from(files.keys()) : []; | ||
readDirectory: audit("readDirectory", function () { | ||
if ((arguments.length <= 0 ? undefined : arguments[0]) === "/") { | ||
return Array.from(files.keys()); | ||
} else { | ||
return nodeSys.readDirectory.apply(nodeSys, arguments); | ||
} | ||
}), | ||
readFile: audit("readFile", function (fileName) { | ||
if (files.has(fileName)) return files.get(fileName); | ||
var fsPath = path.join(projectRoot, fileName); | ||
var libPath = path.join(projectRoot, "node_modules", "typescript", "lib", fileName); | ||
for (var _i2 = 0, _arr2 = [fsPath, libPath]; _i2 < _arr2.length; _i2++) { | ||
var filepath = _arr2[_i2]; | ||
if (fs.existsSync(filepath)) return fs.readFileSync(filepath, { | ||
encoding: "utf-8" | ||
}); | ||
if (fileName.startsWith("/lib")) { | ||
var tsLibName = tsLib + "/" + fileName.replace("/", ""); | ||
return nodeSys.readFile(tsLibName); | ||
} | ||
return undefined; | ||
return nodeSys.readFile(fileName); | ||
}), | ||
resolvePath: function resolvePath(path) { | ||
return path; | ||
if (files.has(path)) return path; | ||
return nodeSys.resolvePath(path); | ||
}, | ||
@@ -438,0 +440,0 @@ newLine: "\n", |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0});var t=!1;try{t="undefined"!=typeof localStorage}catch(e){}var r="undefined"!=typeof process,i=t&&localStorage.getItem("DEBUG")||r&&process.env.DEBUG?console.log:function(e){return""},n=function(e,t){var r,i=e.lib||[],n=["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.intl.d.ts","lib.esnext.array.d.ts","lib.esnext.asynciterable.d.ts","lib.esnext.bigint.d.ts","lib.esnext.d.ts","lib.esnext.full.d.ts","lib.esnext.intl.d.ts","lib.esnext.symbol.d.ts"],s=t.ScriptTarget[e.target||t.ScriptTarget.ES5],o=n.filter((function(e){return e.startsWith("lib."+s.toLowerCase())})),u=n.indexOf(o.pop()),l=((r=i.map((function(e){var t=n.filter((function(t){return t.startsWith("lib."+e.toLowerCase())}));return 0===t.length?0:n.indexOf(t.pop())})))&&r.length?r.reduce((function(e,t){return t>e?t:e})):void 0)||0,a=Math.max(u,l);return n.slice(0,a+1)},s=function(e,t){var r=require("path"),i=require("fs");(function e(t){var n=[];return i.readdirSync(t).forEach((function(s){s=r.join(t,s);var o=i.statSync(s);o&&o.isDirectory()?n=n.concat(e(s)):n.push(s)})),n})(t).forEach((function(n){var s="/node_modules/@types"+n.replace(t,""),o=i.readFileSync(n,"utf8");[".ts",".tsx"].includes(r.extname(s))&&e.set(s,o)}))};function o(e){throw new Error("Method '"+e+"' is not implemented.")}function u(e,t){return function(){for(var r=arguments.length,n=new Array(r),s=0;s<r;s++)n[s]=arguments[s];var o=t.apply(void 0,n),u="string"==typeof o?o.slice(0,80)+"...":o;return i.apply(void 0,["> "+e].concat(n)),i("< "+u),o}}var l=function(t){return e({},t.getDefaultCompilerOptions(),{jsx:t.JsxEmit.React,strict:!0,esModuleInterop:!0,module:t.ModuleKind.ESNext,suppressOutputPathCheck:!0,skipLibCheck:!0,skipDefaultLibCheck:!0,moduleResolution:t.ModuleResolutionKind.NodeJs})},a=function(e){return e.replace("/","/lib.").toLowerCase()};function c(t,r,i){var n=new Map;return{compilerHost:e({},t,{getCanonicalFileName:function(e){return e},getDefaultLibFileName:function(){return"/"+i.getDefaultLibFileName(r)},getDirectories:function(){return[]},getNewLine:function(){return t.newLine},getSourceFile:function(e){return n.get(e)||(s=i.createSourceFile(e,t.readFile(e),r.target||l(i).target,!1),n.set(s.fileName,s),s);var s},useCaseSensitiveFileNames:function(){return t.useCaseSensitiveFileNames}}),updateFile:function(e){var r=n.has(e.fileName);return t.writeFile(e.fileName,e.text),n.set(e.fileName,e),r}}}function f(t,r,i,n,s){var o=[].concat(r),u=c(t,i,n),l=u.compilerHost,a=u.updateFile,f=new Map,d=0;return{languageServiceHost:e({},l,{getProjectVersion:function(){return d.toString()},getCompilationSettings:function(){return i},getCustomTransformers:function(){return s},getScriptFileNames:function(){return o},getScriptSnapshot:function(e){var r=t.readFile(e);if(r)return n.ScriptSnapshot.fromString(r)},getScriptVersion:function(e){return f.get(e)||"0"},writeFile:t.writeFile}),updateFile:function(e){d++,f.set(e.fileName,d.toString()),o.includes(e.fileName)||o.push(e.fileName),a(e)}}}exports.addAllFilesFromFolder=s,exports.addFilesForTypesIntoFolder=function(e){return s(e,"node_modules/@types")},exports.createDefaultMapFromCDN=function(e,t,r,i,s,o,u){var l=o||fetch,a=u||localStorage,c=new Map,f=n(e,i),d="https://typescript.azureedge.net/cdn/"+t+"/typescript/lib/";return(r?function(){return Object.keys(localStorage).forEach((function(e){e.startsWith("ts-lib-")&&!e.startsWith("ts-lib-"+t)&&a.removeItem(e)})),Promise.all(f.map((function(e){var r,i="ts-lib-"+t+"-"+e,n=a.getItem(i);return n?Promise.resolve((r=n,s?s.decompressFromUTF16(r):r)):l(d+e).then((function(e){return e.text()})).then((function(e){var t;return a.setItem(i,(t=e,s?s.compressToUTF16(t):t)),e}))}))).then((function(e){e.forEach((function(e,t){c.set("/"+f[t],e)}))}))}:function(){return Promise.all(f.map((function(e){return l(d+e).then((function(e){return e.text()}))}))).then((function(e){e.forEach((function(e,t){return c.set("/"+f[t],e)}))}))})().then((function(){return c}))},exports.createDefaultMapFromNodeModules=function(e,t){var r=t||require("typescript"),i=require("path"),s=require("fs"),o=n(e,r),u=new Map;return o.forEach((function(e){u.set("/"+e,function(e){var t=i.dirname(require.resolve("typescript"));return s.readFileSync(i.join(t,e),"utf8")}(e))})),u},exports.createFSBackedSystem=function(e,t){var r=require("fs"),i=require("path");return{args:[],createDirectory:function(){return o("createDirectory")},directoryExists:u("directoryExists",(function(n){return Array.from(e.keys()).some((function(e){return e.startsWith(n)}))||r.existsSync(i.join(t,n))})),exit:function(){return o("exit")},fileExists:u("fileExists",(function(n){if(e.has(n))return!0;for(var s=0,o=[i.join(t,n),i.join(t,"node_modules","typescript","lib",n)];s<o.length;s++)if(r.existsSync(o[s]))return!0;return!1})),getCurrentDirectory:function(){return"/"},getDirectories:function(){return[]},getExecutingFilePath:function(){return o("getExecutingFilePath")},readDirectory:u("readDirectory",(function(t){return"/"===t?Array.from(e.keys()):[]})),readFile:u("readFile",(function(n){if(e.has(n))return e.get(n);for(var s=0,o=[i.join(t,n),i.join(t,"node_modules","typescript","lib",n)];s<o.length;s++){var u=o[s];if(r.existsSync(u))return r.readFileSync(u,{encoding:"utf-8"})}})),resolvePath:function(e){return e},newLine:"\n",useCaseSensitiveFileNames:!0,write:function(){return o("write")},writeFile:function(t,r){e.set(t,r)}}},exports.createSystem=function(e){return{args:[],createDirectory:function(){return o("createDirectory")},directoryExists:u("directoryExists",(function(t){return Array.from(e.keys()).some((function(e){return e.startsWith(t)}))})),exit:function(){return o("exit")},fileExists:u("fileExists",(function(t){return e.has(t)||e.has(a(t))})),getCurrentDirectory:function(){return"/"},getDirectories:function(){return[]},getExecutingFilePath:function(){return o("getExecutingFilePath")},readDirectory:u("readDirectory",(function(t){return"/"===t?Array.from(e.keys()):[]})),readFile:u("readFile",(function(t){return e.get(t)||e.get(a(t))})),resolvePath:function(e){return e},newLine:"\n",useCaseSensitiveFileNames:!0,write:function(){return o("write")},writeFile:function(t,r){e.set(t,r)}}},exports.createVirtualCompilerHost=c,exports.createVirtualLanguageServiceHost=f,exports.createVirtualTypeScriptEnvironment=function(t,r,i,n,s){void 0===n&&(n={});var o=e({},l(i),{},n),u=f(t,r,o,i,s),a=u.updateFile,d=i.createLanguageService(u.languageServiceHost),p=d.getCompilerOptionsDiagnostics();if(p.length){var g=c(t,n,i);throw new Error(i.formatDiagnostics(p,g.compilerHost))}return{sys:t,languageService:d,getSourceFile:function(e){var t;return null===(t=d.getProgram())||void 0===t?void 0:t.getSourceFile(e)},createFile:function(e,t){a(i.createSourceFile(e,t,o.target,!1))},updateFile:function(e,t,r){var n=d.getProgram().getSourceFile(e);if(!n)throw new Error("Did not find a source file for "+e);var s=n.text,o=null!=r?r:i.createTextSpan(0,s.length),u=s.slice(0,o.start)+t+s.slice(o.start+o.length),l=i.updateSourceFile(n,u,{span:o,newLength:t.length});a(l)}}},exports.knownLibFilesForCompilerOptions=n; | ||
"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0});var t=!1;try{t="undefined"!=typeof localStorage}catch(e){}var r="undefined"!=typeof process,i=t&&localStorage.getItem("DEBUG")||r&&process.env.DEBUG?console.log:function(e){return""},n=function(e,t){var r,i=e.lib||[],n=["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.intl.d.ts","lib.esnext.array.d.ts","lib.esnext.asynciterable.d.ts","lib.esnext.bigint.d.ts","lib.esnext.d.ts","lib.esnext.full.d.ts","lib.esnext.intl.d.ts","lib.esnext.symbol.d.ts"],s=t.ScriptTarget[e.target||t.ScriptTarget.ES5],o=n.filter((function(e){return e.startsWith("lib."+s.toLowerCase())})),l=n.indexOf(o.pop()),u=((r=i.map((function(e){var t=n.filter((function(t){return t.startsWith("lib."+e.toLowerCase())}));return 0===t.length?0:n.indexOf(t.pop())})))&&r.length?r.reduce((function(e,t){return t>e?t:e})):void 0)||0,a=Math.max(l,u);return n.slice(0,a+1)},s=function(e,t){var r=require("path"),i=require("fs");(function e(t){var n=[];return i.readdirSync(t).forEach((function(s){s=r.join(t,s);var o=i.statSync(s);o&&o.isDirectory()?n=n.concat(e(s)):n.push(s)})),n})(t).forEach((function(n){var s="/node_modules/@types"+n.replace(t,""),o=i.readFileSync(n,"utf8");[".ts",".tsx"].includes(r.extname(s))&&e.set(s,o)}))};function o(e){throw new Error("Method '"+e+"' is not implemented.")}function l(e,t){return function(){for(var r=arguments.length,n=new Array(r),s=0;s<r;s++)n[s]=arguments[s];var o=t.apply(void 0,n),l="string"==typeof o?o.slice(0,80)+"...":o;return i.apply(void 0,["> "+e].concat(n)),i("< "+l),o}}var u=function(t){return e({},t.getDefaultCompilerOptions(),{jsx:t.JsxEmit.React,strict:!0,esModuleInterop:!0,module:t.ModuleKind.ESNext,suppressOutputPathCheck:!0,skipLibCheck:!0,skipDefaultLibCheck:!0,moduleResolution:t.ModuleResolutionKind.NodeJs})},a=function(e){return e.replace("/","/lib.").toLowerCase()};function c(t,r,i){var n=new Map;return{compilerHost:e({},t,{getCanonicalFileName:function(e){return e},getDefaultLibFileName:function(){return"/"+i.getDefaultLibFileName(r)},getDirectories:function(){return[]},getNewLine:function(){return t.newLine},getSourceFile:function(e){return n.get(e)||(s=i.createSourceFile(e,t.readFile(e),r.target||u(i).target,!1),n.set(s.fileName,s),s);var s},useCaseSensitiveFileNames:function(){return t.useCaseSensitiveFileNames}}),updateFile:function(e){var r=n.has(e.fileName);return t.writeFile(e.fileName,e.text),n.set(e.fileName,e),r}}}function f(t,r,i,n,s){var o=[].concat(r),l=c(t,i,n),u=l.compilerHost,a=l.updateFile,f=new Map,d=0;return{languageServiceHost:e({},u,{getProjectVersion:function(){return d.toString()},getCompilationSettings:function(){return i},getCustomTransformers:function(){return s},getScriptFileNames:function(){return o},getScriptSnapshot:function(e){var r=t.readFile(e);if(r)return n.ScriptSnapshot.fromString(r)},getScriptVersion:function(e){return f.get(e)||"0"},writeFile:t.writeFile}),updateFile:function(e){d++,f.set(e.fileName,d.toString()),o.includes(e.fileName)||o.push(e.fileName),a(e)}}}exports.addAllFilesFromFolder=s,exports.addFilesForTypesIntoFolder=function(e){return s(e,"node_modules/@types")},exports.createDefaultMapFromCDN=function(e,t,r,i,s,o,l){var u=o||fetch,a=l||localStorage,c=new Map,f=n(e,i),d="https://typescript.azureedge.net/cdn/"+t+"/typescript/lib/";return(r?function(){return Object.keys(localStorage).forEach((function(e){e.startsWith("ts-lib-")&&!e.startsWith("ts-lib-"+t)&&a.removeItem(e)})),Promise.all(f.map((function(e){var r,i="ts-lib-"+t+"-"+e,n=a.getItem(i);return n?Promise.resolve((r=n,s?s.decompressFromUTF16(r):r)):u(d+e).then((function(e){return e.text()})).then((function(e){var t;return a.setItem(i,(t=e,s?s.compressToUTF16(t):t)),e}))}))).then((function(e){e.forEach((function(e,t){c.set("/"+f[t],e)}))}))}:function(){return Promise.all(f.map((function(e){return u(d+e).then((function(e){return e.text()}))}))).then((function(e){e.forEach((function(e,t){return c.set("/"+f[t],e)}))}))})().then((function(){return c}))},exports.createDefaultMapFromNodeModules=function(e,t){var r=t||require("typescript"),i=require("path"),s=require("fs"),o=n(e,r),l=new Map;return o.forEach((function(e){l.set("/"+e,function(e){var t=i.dirname(require.resolve("typescript"));return s.readFileSync(i.join(t,e),"utf8")}(e))})),l},exports.createFSBackedSystem=function(e,t,r){var i=t+"/vfs",n=require("path"),s=r.sys,u=n.dirname(require.resolve("typescript"));return{args:[],createDirectory:function(){return o("createDirectory")},directoryExists:l("directoryExists",(function(t){return Array.from(e.keys()).some((function(e){return e.startsWith(t)}))||s.directoryExists(t)})),exit:s.exit,fileExists:l("fileExists",(function(t){if(e.has(t))return!0;if(t.includes("tsconfig.json")||t.includes("tsconfig.json"))return!1;if(t.startsWith("/lib")){var r=u+"/"+t.replace("/","");return s.fileExists(r)}return s.fileExists(t)})),getCurrentDirectory:function(){return i},getDirectories:s.getDirectories,getExecutingFilePath:function(){return o("getExecutingFilePath")},readDirectory:l("readDirectory",(function(){return"/"===(arguments.length<=0?void 0:arguments[0])?Array.from(e.keys()):s.readDirectory.apply(s,arguments)})),readFile:l("readFile",(function(t){if(e.has(t))return e.get(t);if(t.startsWith("/lib")){var r=u+"/"+t.replace("/","");return s.readFile(r)}return s.readFile(t)})),resolvePath:function(t){return e.has(t)?t:s.resolvePath(t)},newLine:"\n",useCaseSensitiveFileNames:!0,write:function(){return o("write")},writeFile:function(t,r){e.set(t,r)}}},exports.createSystem=function(e){return{args:[],createDirectory:function(){return o("createDirectory")},directoryExists:l("directoryExists",(function(t){return Array.from(e.keys()).some((function(e){return e.startsWith(t)}))})),exit:function(){return o("exit")},fileExists:l("fileExists",(function(t){return e.has(t)||e.has(a(t))})),getCurrentDirectory:function(){return"/"},getDirectories:function(){return[]},getExecutingFilePath:function(){return o("getExecutingFilePath")},readDirectory:l("readDirectory",(function(t){return"/"===t?Array.from(e.keys()):[]})),readFile:l("readFile",(function(t){return e.get(t)||e.get(a(t))})),resolvePath:function(e){return e},newLine:"\n",useCaseSensitiveFileNames:!0,write:function(){return o("write")},writeFile:function(t,r){e.set(t,r)}}},exports.createVirtualCompilerHost=c,exports.createVirtualLanguageServiceHost=f,exports.createVirtualTypeScriptEnvironment=function(t,r,i,n,s){void 0===n&&(n={});var o=e({},u(i),{},n),l=f(t,r,o,i,s),a=l.updateFile,d=i.createLanguageService(l.languageServiceHost),p=d.getCompilerOptionsDiagnostics();if(p.length){var g=c(t,n,i);throw new Error(i.formatDiagnostics(p,g.compilerHost))}return{sys:t,languageService:d,getSourceFile:function(e){var t;return null===(t=d.getProgram())||void 0===t?void 0:t.getSourceFile(e)},createFile:function(e,t){a(i.createSourceFile(e,t,o.target,!1))},updateFile:function(e,t,r){var n=d.getProgram().getSourceFile(e);if(!n)throw new Error("Did not find a source file for "+e);var s=n.text,o=null!=r?r:i.createTextSpan(0,s.length),l=s.slice(0,o.start)+t+s.slice(o.start+o.length),u=i.updateSourceFile(n,l,{span:o,newLength:t.length});a(u)}}},exports.knownLibFilesForCompilerOptions=n; | ||
//# sourceMappingURL=vfs.cjs.production.min.js.map |
@@ -274,3 +274,3 @@ function _extends() { | ||
}); | ||
}; // TODO: Add some kind of debug logger (needs to be compat with sandbox's deployment, not just via npm) | ||
}; | ||
@@ -372,7 +372,12 @@ function notImplemented(methodName) { | ||
function createFSBackedSystem(files, projectRoot) { | ||
var fs = require("fs"); | ||
function createFSBackedSystem(files, _projectRoot, ts) { | ||
// We need to make an isolated folder for the tsconfig, but also need to be able to resolve the | ||
// existing node_modules structures going back through the history | ||
var root = _projectRoot + "/vfs"; | ||
var path = require("path"); | ||
var path = require("path"); // The default System in TypeScript | ||
var nodeSys = ts.sys; | ||
var tsLib = path.dirname(require.resolve("typescript")); | ||
return { | ||
@@ -387,47 +392,44 @@ args: [], | ||
return path.startsWith(directory); | ||
}) || fs.existsSync(path.join(projectRoot, directory)); | ||
}) || nodeSys.directoryExists(directory); | ||
}), | ||
exit: function exit() { | ||
return notImplemented("exit"); | ||
}, | ||
exit: nodeSys.exit, | ||
fileExists: audit("fileExists", function (fileName) { | ||
if (files.has(fileName)) return true; | ||
var fsPath = path.join(projectRoot, fileName); | ||
var libPath = path.join(projectRoot, "node_modules", "typescript", "lib", fileName); | ||
if (files.has(fileName)) return true; // Don't let other tsconfigs end up touching the vfs | ||
for (var _i = 0, _arr = [fsPath, libPath]; _i < _arr.length; _i++) { | ||
var filepath = _arr[_i]; | ||
if (fs.existsSync(filepath)) return true; | ||
if (fileName.includes("tsconfig.json") || fileName.includes("tsconfig.json")) return false; | ||
if (fileName.startsWith("/lib")) { | ||
var tsLibName = tsLib + "/" + fileName.replace("/", ""); | ||
return nodeSys.fileExists(tsLibName); | ||
} | ||
return false; | ||
return nodeSys.fileExists(fileName); | ||
}), | ||
getCurrentDirectory: function getCurrentDirectory() { | ||
return "/"; | ||
return root; | ||
}, | ||
getDirectories: function getDirectories() { | ||
return []; | ||
}, | ||
getDirectories: nodeSys.getDirectories, | ||
getExecutingFilePath: function getExecutingFilePath() { | ||
return notImplemented("getExecutingFilePath"); | ||
}, | ||
readDirectory: audit("readDirectory", function (directory) { | ||
return directory === "/" ? Array.from(files.keys()) : []; | ||
readDirectory: audit("readDirectory", function () { | ||
if ((arguments.length <= 0 ? undefined : arguments[0]) === "/") { | ||
return Array.from(files.keys()); | ||
} else { | ||
return nodeSys.readDirectory.apply(nodeSys, arguments); | ||
} | ||
}), | ||
readFile: audit("readFile", function (fileName) { | ||
if (files.has(fileName)) return files.get(fileName); | ||
var fsPath = path.join(projectRoot, fileName); | ||
var libPath = path.join(projectRoot, "node_modules", "typescript", "lib", fileName); | ||
for (var _i2 = 0, _arr2 = [fsPath, libPath]; _i2 < _arr2.length; _i2++) { | ||
var filepath = _arr2[_i2]; | ||
if (fs.existsSync(filepath)) return fs.readFileSync(filepath, { | ||
encoding: "utf-8" | ||
}); | ||
if (fileName.startsWith("/lib")) { | ||
var tsLibName = tsLib + "/" + fileName.replace("/", ""); | ||
return nodeSys.readFile(tsLibName); | ||
} | ||
return undefined; | ||
return nodeSys.readFile(fileName); | ||
}), | ||
resolvePath: function resolvePath(path) { | ||
return path; | ||
if (files.has(path)) return path; | ||
return nodeSys.resolvePath(path); | ||
}, | ||
@@ -434,0 +436,0 @@ newLine: "\n", |
{ | ||
"name": "@typescript/vfs", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -16,3 +16,2 @@ "author": "TypeScript team", | ||
"build": "tsdx build && cpy src/index.ts ../sandbox/src/vendor --rename=typescript-vfs.ts", | ||
"bootstrap": "yarn build", | ||
"test": "tsdx test", | ||
@@ -19,0 +18,0 @@ "lint": "tsdx lint" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169656
12
11