From f8d2857e25a1a1276edfe6dd691de68dad36e91f Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Sun, 10 Jun 2018 14:56:48 -0700 Subject: [PATCH] tsserverlibrary --- Jakefile.js | 35 ++++++++++++++++++++++++------- src/tsconfig.json | 1 + src/tsserverLibrary/empty.ts | 1 + src/tsserverLibrary/tsconfig.json | 18 ++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 src/tsserverLibrary/empty.ts create mode 100644 src/tsserverLibrary/tsconfig.json diff --git a/Jakefile.js b/Jakefile.js index b3d62dbdaf5..a5cc7c26668 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -47,9 +47,12 @@ const Paths = { builtLocalRun: "built/local/run.js", locLcg: "built/local/enu/diagnosticMessages.generated.json.lcg", typesMapOutput: "built/local/typesMap.json", + servicesFile: "built/local/typescriptServices.js", servicesDefinitionFile: "built/local/typescriptServices.d.ts", + tsserverGlobalLibraryFile: "built/local/tsserverGlobalLibrary.js", + tsserverGlobalLibraryDefinitionFile: "built/local/tsserverGlobalLibrary.d.ts", tsserverLibraryFile: "built/local/tsserverlibrary.js", tsserverLibraryDefinitionFile: "built/local/tsserverlibrary.d.ts", @@ -161,7 +164,7 @@ task(TaskNames.lkg, [ const sizeBefore = getDirSize(Paths.lkg); const localizationTargets = locales.map(f => path.join(Paths.builtLocal, f)).concat(path.dirname(Paths.locLcg)); - const copyrightContent = fs.readFileSync(Paths.copyright, { encoding: 'utf-8' }); + const copyrightContent = readFileSync(Paths.copyright); const expectedFiles = [...libraryTargets, ...ExpectedLKGFiles, ...localizationTargets]; const missingFiles = expectedFiles.filter(f => !fs.existsSync(f)); @@ -172,7 +175,7 @@ task(TaskNames.lkg, [ // Copy all the targets into the LKG directory jake.mkdirP(Paths.lkg); expectedFiles.forEach(f => { - let content = fs.readFileSync(f, { encoding: 'utf-8' }); + let content = readFileSync(f); // If this is a .d.ts file, run remove-internal on it if (f.endsWith(".d.ts")) { @@ -282,7 +285,7 @@ file(Paths.diagnosticInformationMap, [Paths.diagnosticMessagesJson], function (c }, { async: true }); file(Paths.typesMapOutput, /** @type {*} */(function () { - var content = fs.readFileSync(path.join(Paths.srcServer, 'typesMap.json')); + var content = readFileSync(path.join(Paths.srcServer, 'typesMap.json')); // Validate that it's valid JSON try { JSON.parse(content.toString()); @@ -293,18 +296,21 @@ file(Paths.typesMapOutput, /** @type {*} */(function () { })); file(Paths.tsserverLibraryFile, [TaskNames.coreBuild, Paths.copyright, ...libraryTargets], function() { - // fs.writeFileSync(Paths.tsserverLibraryFile, fs.readFileSync(path.join(Paths.builtLocal, "server.js"), { encoding: 'utf-8'})); - fs.writeFileSync(Paths.tsserverLibraryFile, "wat"); + const originalContent = readFileSync(Paths.tsserverGlobalLibraryFile); + const newContent = + readFileSync(Paths.copyright) + + originalContent; + writeFileSync(Paths.tsserverLibraryFile, newContent); }); file(Paths.tsserverLibraryDefinitionFile, [TaskNames.coreBuild, Paths.copyright, ...libraryTargets], function () { - const content = fs.readFileSync(Paths.servicesFile, { encoding: 'utf-8' }); + const content = readFileSync(Paths.tsserverGlobalLibraryDefinitionFile); const newContent = removeConstModifierFromEnumDeclarations(content) + `\nexport = ts` + `\nexport as namespace ts;`; - fs.writeFileSync(Paths.tsserverLibraryDefinitionFile, newContent, { encoding: 'utf-8' }); + writeFileSync(Paths.tsserverLibraryDefinitionFile, newContent); }); function getLibraryTargets() { @@ -657,3 +663,18 @@ function getDiffTool() { function removeConstModifierFromEnumDeclarations(text) { return text.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, '$1$2enum $3 {$4'); } + +/** + * @param {string} path + */ +function readFileSync(path) { + return fs.readFileSync(path, { encoding: "utf-8" }); +} + +/** + * @param {string} path + * @param {string} contents + */ +function writeFileSync(path, contents) { + fs.writeFileSync(path, contents, { encoding: "utf-8" }); +} diff --git a/src/tsconfig.json b/src/tsconfig.json index 0c7f0c65da0..72f9cecebac 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -4,6 +4,7 @@ "references": [ { "path": "./tsc" }, { "path": "./tsserver" }, + { "path": "./tsserverLibrary" }, { "path": "./typingsInstaller" }, { "path": "./watchGuard" }, { "path": "./cancellationToken" }, diff --git a/src/tsserverLibrary/empty.ts b/src/tsserverLibrary/empty.ts new file mode 100644 index 00000000000..80c90edcdd4 --- /dev/null +++ b/src/tsserverLibrary/empty.ts @@ -0,0 +1 @@ +// Workaround file, please delete once tsbuild understands it's not safe to skip this container diff --git a/src/tsserverLibrary/tsconfig.json b/src/tsserverLibrary/tsconfig.json new file mode 100644 index 00000000000..459504b5173 --- /dev/null +++ b/src/tsserverLibrary/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../tsconfig-base", + + "compilerOptions": { + "outFile": "../../built/local/tsserverGlobalLibrary.js", + "types": [ + "node" + ] + }, + "files": ["empty.ts"], + "references": [ + { "path": "../core", "prepend": true }, + { "path": "../parser", "prepend": true }, + { "path": "../compiler", "prepend": true }, + { "path": "../services", "prepend": true }, + { "path": "../server", "prepend": true } + ] +}