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

Commit de2a90a

Browse files
authored
Merge pull request #71 from notoriousb1t/master
Specify tsconfig.json file
2 parents cd3856e + 9874020 commit de2a90a

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ export default function typescript ( options ) {
4040
delete options.typescript;
4141

4242
// Load options from `tsconfig.json` unless explicitly asked not to.
43-
const tsconfig = options.tsconfig === false ? {} :
44-
compilerOptionsFromTsConfig( typescript );
43+
const tsconfig = options.tsconfig === false
44+
? {}
45+
: typeof options.tsconfig === 'string'
46+
? compilerOptionsFromTsConfig(typescript, options.tsconfig)
47+
: compilerOptionsFromTsConfig(typescript, 'tsconfig.json');
4548

4649
delete options.tsconfig;
4750

src/options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ function findFile ( cwd, filename ) {
3737
return null;
3838
}
3939

40-
export function compilerOptionsFromTsConfig ( typescript ) {
40+
export function compilerOptionsFromTsConfig ( typescript, filename) {
4141
const cwd = process.cwd();
4242

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

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

test/sample/custom-tsconfig/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const answer: number = 42;
2+
console.log( `the answer is ${answer}` );
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6"
4+
}
5+
}

test/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ describe( 'rollup-plugin-typescript', function () {
231231
assert.notEqual( code.indexOf( 'from \'tslib\'' ), -1, 'should import tslib' );
232232
});
233233
});
234+
235+
it( 'reads in custom tsconfig files', () => {
236+
return bundle('sample/custom-tsconfig/main.ts', {
237+
tsconfig: 'sample/custom-tsconfig/tsconfig.json'
238+
}).then(bundle => {
239+
assert.equal(bundle.modules[1].code.indexOf('const answer = 42'), 0);
240+
});
241+
});
234242
});
235243

236244
function fakeTypescript ( custom ) {

0 commit comments

Comments
 (0)