diff --git a/docs/dgeni-package/services/tsParser.js b/docs/dgeni-package/services/tsParser.js index 70bd7b6bea..8fc74596b3 100644 --- a/docs/dgeni-package/services/tsParser.js +++ b/docs/dgeni-package/services/tsParser.js @@ -5,18 +5,23 @@ module.exports = function tsParser(createCompilerHost, log) { return { + // These are the extension that we should consider when trying to load a module + // During migration from Traceur, there is a mix of `.ts`, `.es6` and `.js` (atScript) + // files in the project and the TypeScript compiler only looks for `.ts` files when trying + // to load imports. + extensions: ['.ts', '.js', '.es6'], + + // The options for the TS compiler options: { - allowNonTsExtensions: true + allowNonTsExtensions: true, + charset: 'utf8' }, parse: function(fileNames, baseDir) { - fileNames = fileNames.map(function(fileName) { - return path.resolve(baseDir, fileName); - }); // "Compile" a program from the given module filenames, to get hold of a // typeChecker that can be used to interrogate the modules, exports and so on. - var host = createCompilerHost(this.options); + var host = createCompilerHost(this.options, baseDir, this.extensions); var program = ts.createProgram(fileNames, this.options, host); var typeChecker = program.getTypeChecker(); diff --git a/docs/dgeni-package/services/tsParser/createCompilerHost.js b/docs/dgeni-package/services/tsParser/createCompilerHost.js index 61a19d2804..5f7d672baf 100644 --- a/docs/dgeni-package/services/tsParser/createCompilerHost.js +++ b/docs/dgeni-package/services/tsParser/createCompilerHost.js @@ -1,32 +1,62 @@ var ts = require('typescript'); +var fs = require('fs'); +var path = require('canonical-path'); -// These are the extension that we should consider when trying to load a module -var extensions = ['.ts', '.js', '.es6'] - -// We need to provide our own version of CompilerHost because, at the moment, there is -// a mix of `.ts`, `.es6` and `.js` (atScript) files in the project and the TypeScript -// compiler only looks for `.ts` files when trying to load imports. +// We need to provide our own version of CompilerHost because we want to set the +// base directory and specify what extensions to consider when trying to load a source +// file module.exports = function createCompilerHost(log) { - return function createCompilerHost(options) { - var host = ts.createCompilerHost(options); + return function createCompilerHost(options, baseDir, extensions) { - // Override the `getSourceFile` implementation to also look for js and es6 files - var getSourceFile = host.getSourceFile; - host.getSourceFile = function(filename, languageVersion, onError) { - // Iterate through each possible extension and return the first source file that is actually found - for(var i=0; i