Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

Fix path #49

Merged
merged 5 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
matrix:
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "5"
- nodejs_version: "6"

# Install scripts. (runs after repo cloning)
install:
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare namespace tss {
private createService();
private getTypeScriptBinDir();
private getDefaultLibFileName(options);
private getFile(outputFiles, fileName);
private toJavaScript(service, fileName);
private normalizeSlashes(path);
private formatDiagnostics(diagnostics);
Expand Down
12 changes: 10 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ namespace tss {
return JSON.stringify(sourceMap);
}

private getFile (outputFiles: ts.OutputFile[], fileName: string): ts.OutputFile {
const files = outputFiles.filter((file) => {
const full = path.resolve(process.cwd(), fileName);
return file.name === fileName || file.name === full;
});
return files[0];
}

private toJavaScript(service: ts.LanguageService, fileName: string): string {
let output = service.getEmitOutput(fileName);

Expand All @@ -166,13 +174,13 @@ namespace tss {
}
// for Windows #37
outputFileName = this.normalizeSlashes(outputFileName);
let file = output.outputFiles.filter((file) => file.name === outputFileName)[0];
let file = this.getFile(output.outputFiles, outputFileName);
let text = file.text;

// If we have sourceMaps convert them to inline sourceMaps
if (this.options.sourceMap) {
let sourceMapFileName = outputFileName + '.map';
let sourceMapFile = output.outputFiles.filter((file) => file.name === sourceMapFileName)[0];
let sourceMapFile = this.getFile(output.outputFiles, sourceMapFileName)

// Transform sourcemap
let sourceMapText = sourceMapFile.text;
Expand Down
10 changes: 9 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ describe('typescript-simple', function() {
var tss = new TypeScriptSimple();
var src = "let x: number = 1;";
var expected = 'var x = 1;' + eol;
assert.equal(tss.compile(src, __dirname + '/fixtures/module1.ts'), expected);
assert.equal(tss.compile(src, path.join(__dirname, 'module.ts')), expected);
});

it('compiles source multiple times with relative and absolute path (#47)', function() {
var tss = new TypeScriptSimple({});
var src = "var x: number = 1;";
var expected = 'var x = 1;' + eol;
assert.equal(tss.compile(src, path.join(__dirname, 'module.ts')), expected);
assert.equal(tss.compile(src, path.join('test', 'module.ts')), expected);
});
});