From 2d20d65819ad8a474ce37d5310da233d4b51426b Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Sat, 19 Mar 2016 17:27:49 -0700 Subject: [PATCH] Remove source map output tweaks --- src/ts-node.spec.ts | 11 ++++++----- src/ts-node.ts | 33 +++++---------------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/ts-node.spec.ts b/src/ts-node.spec.ts index 39a1f44f9..3c656da6f 100644 --- a/src/ts-node.spec.ts +++ b/src/ts-node.spec.ts @@ -1,11 +1,12 @@ import { expect } from 'chai' import { exec } from 'child_process' -import { join } from 'path' +import { join, normalize } from 'path' import proxyquire = require('proxyquire') import { register, VERSION } from './ts-node' const cwd = join(__dirname, '../src') -const BIN_EXEC = `node ${join(__dirname, '../dist/bin/ts-node')} --project "${cwd}"` +const EXEC_PATH = join(__dirname, '../dist/bin/ts-node') +const BIN_EXEC = `node ${EXEC_PATH} --project "${cwd}"` describe('ts-node', function () { this.timeout(10000) @@ -63,7 +64,7 @@ describe('ts-node', function () { it('should work with source maps', function (done) { exec(`${BIN_EXEC} tests/throw`, function (err) { expect(err.message).to.contain([ - `${join(__dirname, '../tests/throw.ts')}:3`, + `${normalize('../../tests/throw.ts')}:3`, ' bar () { throw new Error(\'this is a demo\') }', ' ^', 'Error: this is a demo' @@ -76,7 +77,7 @@ describe('ts-node', function () { it('eval should work with source maps', function (done) { exec(`${BIN_EXEC} -p "import './tests/throw'"`, function (err) { expect(err.message).to.contain([ - `${join(__dirname, '../tests/throw.ts')}:3`, + `${normalize('../../tests/throw.ts')}:3`, ' bar () { throw new Error(\'this is a demo\') }', ' ^', 'Error: this is a demo' @@ -151,7 +152,7 @@ describe('ts-node', function () { } catch (error) { expect(error.stack).to.contain([ 'Error: this is a demo', - ` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:3:18)` + ` at Foo.bar (${normalize('../../tests/throw.ts')}:3:18)` ].join('\n')) done() diff --git a/src/ts-node.ts b/src/ts-node.ts index cd38e60ac..07bae83fe 100644 --- a/src/ts-node.ts +++ b/src/ts-node.ts @@ -1,4 +1,4 @@ -import { relative, basename, resolve, dirname } from 'path' +import { relative, resolve, dirname } from 'path' import { readFileSync, statSync } from 'fs' import { EOL } from 'os' import sourceMapSupport = require('source-map-support') @@ -85,9 +85,9 @@ function readConfig (options: Options, cwd: string, ts: TSCommon) { }, result.config.compilerOptions, { - sourceMap: true, - inlineSourceMap: false, - inlineSources: false, + sourceMap: false, + inlineSourceMap: true, + inlineSources: true, declaration: false, noEmit: false } @@ -209,18 +209,7 @@ export function register (opts?: Options) { throw new TSError(diagnostics) } - const result = output.outputFiles[1].text - const sourceText = service.getSourceFile(fileName).text - const sourceMapText = output.outputFiles[0].text - const sourceMapFileName = output.outputFiles[0].name - const sourceMap = getSourceMap(sourceMapText, fileName, sourceText) - const base64SourceMapText = new Buffer(sourceMap).toString('base64') - - return result - .replace( - '//# sourceMappingURL=' + basename(sourceMapFileName), - `//# sourceMappingURL=data:application/json;base64,${base64SourceMapText}` - ) + return output.outputFiles[0].text } function compile (fileName: string) { @@ -304,18 +293,6 @@ function formatDiagnostic (diagnostic: any, ts: TSCommon, cwd: string = '.'): st return `${message} (${diagnostic.code})` } -/** - * Sanitize the source map content. - */ -function getSourceMap (map: string, fileName: string, code: string): string { - const sourceMap = JSON.parse(map) - sourceMap.file = fileName - sourceMap.sources = [fileName] - sourceMap.sourcesContent = [code] - delete sourceMap.sourceRoot - return JSON.stringify(sourceMap) -} - /** * TypeScript diagnostics error. */