Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Specify tsconfig.json file #71

Merged
merged 4 commits into from
May 23, 2017
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
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ export default function typescript ( options ) {
delete options.typescript;

// Load options from `tsconfig.json` unless explicitly asked not to.
const tsconfig = options.tsconfig === false ? {} :
compilerOptionsFromTsConfig( typescript );
const tsconfig = options.tsconfig === false
? {}
: typeof options.tsconfig === 'string'
? compilerOptionsFromTsConfig(typescript, options.tsconfig)
: compilerOptionsFromTsConfig(typescript, 'tsconfig.json');

delete options.tsconfig;

Expand Down
4 changes: 2 additions & 2 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ function findFile ( cwd, filename ) {
return null;
}

export function compilerOptionsFromTsConfig ( typescript ) {
export function compilerOptionsFromTsConfig ( typescript, filename) {
const cwd = process.cwd();

const tsconfig = typescript.readConfigFile( findFile( cwd, 'tsconfig.json' ), path => readFileSync( path, 'utf8' ) );
const tsconfig = typescript.readConfigFile( findFile( cwd, filename ), path => readFileSync( path, 'utf8' ) );

if ( !tsconfig.config || !tsconfig.config.compilerOptions ) return {};

Expand Down
2 changes: 2 additions & 0 deletions test/sample/custom-tsconfig/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const answer: number = 42;
console.log( `the answer is ${answer}` );
5 changes: 5 additions & 0 deletions test/sample/custom-tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "es6"
}
}
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ describe( 'rollup-plugin-typescript', function () {
assert.ok( map.sources.every( source => source.indexOf( 'typescript-helpers' ) === -1) );
});
});

it( 'reads in custom tsconfig files', () => {
return bundle('sample/custom-tsconfig/main.ts', {
tsconfig: 'sample/custom-tsconfig/tsconfig.json'
}).then(bundle => {
assert.equal(bundle.modules[1].code.indexOf('const answer = 42'), 0);
});
});
});

function fakeTypescript ( custom ) {
Expand Down