Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove source map output tweaks #82

Merged
merged 1 commit into from
Mar 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/ts-node.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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()
Expand Down
33 changes: 5 additions & 28 deletions src/ts-node.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
*/
Expand Down