From 7ba032be3dd5a0d4ad078ad3d6a068ef4951f171 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 1 Dec 2014 15:32:52 -0800 Subject: [PATCH 1/3] Emit services as an external module. --- Jakefile | 37 ++++++++++++++++++++++++++----------- src/services/shims.ts | 6 ++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Jakefile b/Jakefile index ba82e9c3f43..9ecc126b06d 100644 --- a/Jakefile +++ b/Jakefile @@ -1,6 +1,7 @@ // This file contains the build logic for the public repo var fs = require("fs"); +var os = require("os"); var path = require("path"); var child_process = require("child_process"); @@ -145,7 +146,7 @@ var compilerFilename = "tsc.js"; * @param useBuiltCompiler: true to use the built compiler, false to use the LKG * @param noOutFile: true to compile without using --out */ -function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations) { +function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, callback) { file(outFile, prereqs, function() { var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory; var options = "-removeComments --module commonjs -noImplicitAny "; @@ -177,6 +178,11 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu prependFile(prefixes[i], outFile); } } + + if (callback) { + callback(); + } + complete(); }); ex.addListener("error", function() { @@ -221,7 +227,7 @@ compileFile(processDiagnosticMessagesJs, [processDiagnosticMessagesTs], [processDiagnosticMessagesTs], [], - false); + /*useBuiltCompiler*/ false); // The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () { @@ -241,7 +247,6 @@ file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], ex.run(); }, {async: true}) - desc("Generates a diagnostic file in TypeScript based on an input JSON file"); task("generate-diagnostics", [diagnosticInfoMapTs]) @@ -252,13 +257,24 @@ compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(co var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js"); var servicesDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts"); -compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler:*/ true, /*noOutFile:*/ false, /*generateDeclarations:*/ true); + +compileFile(servicesFile, + servicesSources, + [builtLocalDirectory, copyright].concat(servicesSources), + [copyright], + /*useBuiltCompiler*/ true, + /*noOutFile*/ false, + /*generateDeclarations*/ true, + /*callback*/ fixDeclarationFile); + +function fixDeclarationFile() { + fs.appendFileSync(servicesDefinitionsFile, os.EOL + "export = ts;") +} // Local target to build the compiler and services desc("Builds the full compiler and services"); task("local", ["generate-diagnostics", "lib", tscFile, servicesFile]); - // Local target to build the compiler and services desc("Sets release mode flag"); task("release", function() { @@ -275,7 +291,6 @@ task("clean", function() { jake.rmRf(builtDirectory); }); - // Generate Markdown spec var word2mdJs = path.join(scriptsDirectory, "word2md.js"); var word2mdTs = path.join(scriptsDirectory, "word2md.ts"); @@ -289,7 +304,7 @@ compileFile(word2mdJs, [word2mdTs], [word2mdTs], [], - false); + /*useBuiltCompiler*/ false); // The generated spec.md; built for the 'generate-spec' task file(specMd, [word2mdJs, specWord], function () { @@ -438,7 +453,7 @@ task("generate-code-coverage", ["tests", builtLocalDirectory], function () { // Browser tests var nodeServerOutFile = 'tests/webTestServer.js' var nodeServerInFile = 'tests/webTestServer.ts' -compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], true, true); +compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], /*useBuiltCompiler:*/ true, /*noOutFile*/ true); desc("Runs browserify on run.js to produce a file suitable for running tests in the browser"); task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() { @@ -513,7 +528,7 @@ task("baseline-accept-rwc", function() { // Webhost var webhostPath = "tests/webhost/webtsc.ts"; var webhostJsPath = "tests/webhost/webtsc.js"; -compileFile(webhostJsPath, [webhostPath], [tscFile, webhostPath].concat(libraryTargets), [], true); +compileFile(webhostJsPath, [webhostPath], [tscFile, webhostPath].concat(libraryTargets), [], /*useBuiltCompiler*/true); desc("Builds the tsc web host"); task("webhost", [webhostJsPath], function() { @@ -523,7 +538,7 @@ task("webhost", [webhostJsPath], function() { // Perf compiler var perftscPath = "tests/perftsc.ts"; var perftscJsPath = "built/local/perftsc.js"; -compileFile(perftscJsPath, [perftscPath], [tscFile, perftscPath, "tests/perfsys.ts"].concat(libraryTargets), [], true); +compileFile(perftscJsPath, [perftscPath], [tscFile, perftscPath, "tests/perfsys.ts"].concat(libraryTargets), [], /*useBuiltCompiler*/ true); desc("Builds augmented version of the compiler for perf tests"); task("perftsc", [perftscJsPath]); @@ -547,7 +562,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() { var instrumenterPath = harnessDirectory + 'instrumenter.ts'; var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js'; -compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], true); +compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], /*useBuiltCompiler*/ true); desc("Builds an instrumented tsc.js"); task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() { diff --git a/src/services/shims.ts b/src/services/shims.ts index 49603fd4a2e..9428e8c534f 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -920,3 +920,9 @@ module TypeScript.Services { export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory; } +module ts { + declare var module: any; + if (typeof module !== "undefined" && module.exports) { + module.exports = ts; + } +} \ No newline at end of file From 55be5300044c709cf6712fc9ef5dc34453cb803d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 1 Dec 2014 15:52:34 -0800 Subject: [PATCH 2/3] Get rid of emitted empty module. --- src/services/shims.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 9428e8c534f..64759fffc9f 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -912,6 +912,11 @@ module ts { throw new Error("Invalid operation"); } } + + declare var module: any; + if (typeof module !== "undefined" && module.exports) { + module.exports = ts; + } } @@ -919,10 +924,3 @@ module ts { module TypeScript.Services { export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory; } - -module ts { - declare var module: any; - if (typeof module !== "undefined" && module.exports) { - module.exports = ts; - } -} \ No newline at end of file From 636a466552d6018bb113858ae9ac65e33ed999b7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Dec 2014 15:16:09 -0800 Subject: [PATCH 3/3] Added comment. --- src/services/shims.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/shims.ts b/src/services/shims.ts index 64759fffc9f..86671009be2 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -913,6 +913,8 @@ module ts { } } + // Here we expose the TypeScript services as an external module + // so that it may be consumed easily like a node module. declare var module: any; if (typeof module !== "undefined" && module.exports) { module.exports = ts;