diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2020-08-05 20:44:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-05 20:44:03 +0200 |
commit | ce7808baf092e130ba1c5f073544072c5db958e7 (patch) | |
tree | cc8f9a167973aed549194c4ac5c8291a82c17cdf /cli/tsc | |
parent | 91ed614aa80f5a08669be3fe5031a95e6e75f194 (diff) |
feat(cli): custom http client for fetch (#6918)
Diffstat (limited to 'cli/tsc')
-rw-r--r-- | cli/tsc/99_main_compiler.js | 128 |
1 files changed, 29 insertions, 99 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 04638d60c..9481f2ba0 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -100,6 +100,8 @@ delete Object.prototype.__proto__; "PermissionStatus", "hostname", "ppid", + "HttpClient", + "createHttpClient", ]; function transformMessageText(messageText, code) { @@ -139,9 +141,7 @@ delete Object.prototype.__proto__; return messageText; } - function fromDiagnosticCategory( - category, - ) { + function fromDiagnosticCategory(category) { switch (category) { case ts.DiagnosticCategory.Error: return DiagnosticCategory.Error; @@ -160,11 +160,7 @@ delete Object.prototype.__proto__; } } - function getSourceInformation( - sourceFile, - start, - length, - ) { + function getSourceInformation(sourceFile, start, length) { const scriptResourceName = sourceFile.fileName; const { line: lineNumber, @@ -196,9 +192,7 @@ delete Object.prototype.__proto__; }; } - function fromDiagnosticMessageChain( - messageChain, - ) { + function fromDiagnosticMessageChain(messageChain) { if (!messageChain) { return undefined; } @@ -214,9 +208,7 @@ delete Object.prototype.__proto__; }); } - function parseDiagnostic( - item, - ) { + function parseDiagnostic(item) { const { messageText, category: sourceCategory, @@ -254,9 +246,7 @@ delete Object.prototype.__proto__; return sourceInfo ? { ...base, ...sourceInfo } : base; } - function parseRelatedInformation( - relatedInformation, - ) { + function parseRelatedInformation(relatedInformation) { const result = []; for (const item of relatedInformation) { result.push(parseDiagnostic(item)); @@ -264,9 +254,7 @@ delete Object.prototype.__proto__; return result; } - function fromTypeScriptDiagnostic( - diagnostics, - ) { + function fromTypeScriptDiagnostic(diagnostics) { const items = []; for (const sourceDiagnostic of diagnostics) { const item = parseDiagnostic(sourceDiagnostic); @@ -489,12 +477,7 @@ delete Object.prototype.__proto__; */ const RESOLVED_SPECIFIER_CACHE = new Map(); - function configure( - defaultOptions, - source, - path, - cwd, - ) { + function configure(defaultOptions, source, path, cwd) { const { config, error } = ts.parseConfigFileTextToJson(path, source); if (error) { return { diagnostics: [error], options: defaultOptions }; @@ -540,11 +523,7 @@ delete Object.prototype.__proto__; return SOURCE_FILE_CACHE.get(url); } - static cacheResolvedUrl( - resolvedUrl, - rawModuleSpecifier, - containingFile, - ) { + static cacheResolvedUrl(resolvedUrl, rawModuleSpecifier, containingFile) { containingFile = containingFile || ""; let innerCache = RESOLVED_SPECIFIER_CACHE.get(containingFile); if (!innerCache) { @@ -554,10 +533,7 @@ delete Object.prototype.__proto__; innerCache.set(rawModuleSpecifier, resolvedUrl); } - static getResolvedUrl( - moduleSpecifier, - containingFile, - ) { + static getResolvedUrl(moduleSpecifier, containingFile) { const containingCache = RESOLVED_SPECIFIER_CACHE.get(containingFile); if (containingCache) { return containingCache.get(moduleSpecifier); @@ -621,11 +597,7 @@ delete Object.prototype.__proto__; return this.#options; } - configure( - cwd, - path, - configurationText, - ) { + configure(cwd, path, configurationText) { log("compiler::host.configure", path); const { options, ...result } = configure( this.#options, @@ -718,10 +690,7 @@ delete Object.prototype.__proto__; return notImplemented(); } - resolveModuleNames( - moduleNames, - containingFile, - ) { + resolveModuleNames(moduleNames, containingFile) { log("compiler::host.resolveModuleNames", { moduleNames, containingFile, @@ -760,13 +729,7 @@ delete Object.prototype.__proto__; return true; } - writeFile( - fileName, - data, - _writeByteOrderMark, - _onError, - sourceFiles, - ) { + writeFile(fileName, data, _writeByteOrderMark, _onError, sourceFiles) { log("compiler::host.writeFile", fileName); this.#writeFile(fileName, data, sourceFiles); } @@ -848,9 +811,7 @@ delete Object.prototype.__proto__; const SYSTEM_LOADER = getAsset("system_loader.js"); const SYSTEM_LOADER_ES5 = getAsset("system_loader_es5.js"); - function buildLocalSourceFileCache( - sourceFileMap, - ) { + function buildLocalSourceFileCache(sourceFileMap) { for (const entry of Object.values(sourceFileMap)) { assert(entry.sourceCode.length > 0); SourceFile.addToCache({ @@ -902,9 +863,7 @@ delete Object.prototype.__proto__; } } - function buildSourceFileCache( - sourceFileMap, - ) { + function buildSourceFileCache(sourceFileMap) { for (const entry of Object.values(sourceFileMap)) { SourceFile.addToCache({ url: entry.url, @@ -974,11 +933,7 @@ delete Object.prototype.__proto__; }; function createBundleWriteFile(state) { - return function writeFile( - _fileName, - data, - sourceFiles, - ) { + return function writeFile(_fileName, data, sourceFiles) { assert(sourceFiles != null); assert(state.host); // we only support single root names for bundles @@ -992,14 +947,8 @@ delete Object.prototype.__proto__; }; } - function createCompileWriteFile( - state, - ) { - return function writeFile( - fileName, - data, - sourceFiles, - ) { + function createCompileWriteFile(state) { + return function writeFile(fileName, data, sourceFiles) { const isBuildInfo = fileName === TS_BUILD_INFO; if (isBuildInfo) { @@ -1017,14 +966,8 @@ delete Object.prototype.__proto__; }; } - function createRuntimeCompileWriteFile( - state, - ) { - return function writeFile( - fileName, - data, - sourceFiles, - ) { + function createRuntimeCompileWriteFile(state) { + return function writeFile(fileName, data, sourceFiles) { assert(sourceFiles); assert(sourceFiles.length === 1); state.emitMap[fileName] = { @@ -1169,10 +1112,7 @@ delete Object.prototype.__proto__; ts.performance.enable(); } - function performanceProgram({ - program, - fileCount, - }) { + function performanceProgram({ program, fileCount }) { if (program) { if ("getProgram" in program) { program = program.getProgram(); @@ -1211,15 +1151,14 @@ delete Object.prototype.__proto__; } // TODO(Bartlomieju): this check should be done in Rust; there should be no - function processConfigureResponse( - configResult, - configPath, - ) { + function processConfigureResponse(configResult, configPath) { const { ignoredOptions, diagnostics } = configResult; if (ignoredOptions) { const msg = `Unsupported compiler options in "${configPath}"\n The following options were ignored:\n ${ - ignoredOptions.map((value) => value).join(", ") + ignoredOptions + .map((value) => value) + .join(", ") }\n`; core.print(msg, true); } @@ -1319,12 +1258,7 @@ delete Object.prototype.__proto__; } } - function buildBundle( - rootName, - data, - sourceFiles, - target, - ) { + function buildBundle(rootName, data, sourceFiles, target) { // when outputting to AMD and a single outfile, TypeScript makes up the module // specifiers which are used to define the modules, and doesn't expose them // publicly, so we have to try to replicate @@ -1664,9 +1598,7 @@ delete Object.prototype.__proto__; return result; } - function runtimeCompile( - request, - ) { + function runtimeCompile(request) { const { options, rootNames, target, unstable, sourceFileMap } = request; log(">>> runtime compile start", { @@ -1808,9 +1740,7 @@ delete Object.prototype.__proto__; }; } - function runtimeTranspile( - request, - ) { + function runtimeTranspile(request) { const result = {}; const { sources, options } = request; const compilerOptions = options |