From b2528b4d13b017a04a210b1c86975e2889ba778a Mon Sep 17 00:00:00 2001 From: Jason Zhekov Date: Wed, 11 Jan 2017 12:37:19 +0200 Subject: [PATCH] Workaround boolean flags not available in TS 2.0 https://github.com/Microsoft/TypeScript/pull/11798 --- lib/compiler.js | 8 +++----- postinstall.js | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index f405445..9488bef 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -30,14 +30,12 @@ function runTypeScriptCompiler(logger, projectDir, options) { if (!options.release) { // For debugging in Chrome DevTools - nodeArgs.push( - '--sourceMap', 'false', - '--inlineSourceMap', 'true', - '--inlineSources', 'true' - ); + nodeArgs.push('--inlineSourceMap', '--inlineSources'); } + logger.trace(process.execPath, nodeArgs.join(' ')); var tsc = spawn(process.execPath, nodeArgs); + var isResolved = false; tsc.stdout.on('data', function(data) { var stringData = data.toString(); diff --git a/postinstall.js b/postinstall.js index 10eab09..4ded40e 100644 --- a/postinstall.js +++ b/postinstall.js @@ -6,7 +6,12 @@ var path = require('path'); var projectDir = hook.findProjectDir(); if (projectDir) { - createTsconfig(); + var tsconfigPath = path.join(projectDir, 'tsconfig.json'); + if (fs.existsSync(tsconfigPath)) { + migrateTsconfig(tsconfigPath); + } else { + createTsconfig(tsconfigPath); + } createReferenceFile(); installTypescript(); } @@ -20,8 +25,29 @@ function createReferenceFile() { } } -function createTsconfig() { - var tsconfigPath = path.join(projectDir, 'tsconfig.json'); +function migrateTsconfig(tsconfigPath) { + var displaybleTsconfigPath = path.relative(projectDir, tsconfigPath); + + try { + var existingConfigContents = fs.readFileSync(tsconfigPath); + var existingConfig = JSON.parse(existingConfigContents); + } catch (e) { + console.error("Invalid " + displaybleTsconfigPath + ": " + e); + return; + } + + if (existingConfig["compilerOptions"]) { + if ("sourceMap" in existingConfig["compilerOptions"]) { + delete existingConfig["compilerOptions"]["sourceMap"]; + console.warn("> Deleted \"compilerOptions.sourceMap\" setting in \"" + displaybleTsconfigPath + "\"."); + console.warn("> Inline source maps will be used when building in Debug configuration from now on."); + } + } + + fs.writeFileSync(tsconfigPath, JSON.stringify(existingConfig, null, 4)); +} + +function createTsconfig(tsconfigPath) { var tsconfig = {}; tsconfig.compilerOptions = { @@ -35,9 +61,7 @@ function createTsconfig() { tsconfig.exclude = ['node_modules', 'platforms', "**/*.aot.ts"]; - if (!fs.existsSync(tsconfigPath)) { - fs.appendFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4)); - } + fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4)); } function getProjectTypeScriptVersion() {