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

Version 0.7.6 #47

Merged
merged 2 commits into from
Jun 19, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master

## 0.7.6
* Ignore the `declaration` option ([#45](https://github.com/rollup/rollup-plugin-typescript/issues/45))
* Disable `strictNullChecks` with a warning for TypeScript versions that don't support it ([#46](https://github.com/rollup/rollup-plugin-typescript/issues/46))

## 0.7.5
* Ensure NPM doesn't ignore typescript-helpers

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-typescript",
"version": "0.7.5",
"version": "0.7.6",
"description": "Seamless integration between Rollup and TypeScript.",
"main": "dist/rollup-plugin-typescript.cjs.js",
"jsnext:main": "dist/rollup-plugin-typescript.es6.js",
Expand Down
39 changes: 30 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ interface Options {
}

const resolveHost = {
directoryExists ( dirPath: string ): boolean {
try {
return statSync( dirPath ).isDirectory();
} catch ( err ) {
return false;
}
},
fileExists ( filePath: string ): boolean {
try {
return statSync( filePath ).isFile();
Expand Down Expand Up @@ -63,6 +70,7 @@ function findFile( cwd: string, filename: string ): string {
return fp;
}
}

return null;
}

Expand All @@ -76,13 +84,24 @@ function compilerOptionsFromTsConfig( typescript: typeof ts ): ts.CompilerOption
return tsconfig.config.compilerOptions;
}

// Set `sourceMap` to `inlineSourceMap` if it's a boolean,
// under the assumption that both are never specified simultaneously.
function fixSourceMapOption( options: any ) {
function adjustCompilerOptions( typescript: typeof ts, options: any ) {
// Set `sourceMap` to `inlineSourceMap` if it's a boolean
// under the assumption that both are never specified simultaneously.
if ( typeof options.inlineSourceMap === 'boolean' ) {
options.sourceMap = options.inlineSourceMap;
delete options.inlineSourceMap;
}

// Delete the `declaration` option to prevent compilation error.
// See: https://github.com/rollup/rollup-plugin-typescript/issues/45
delete options.declaration;

const tsVersion = typescript.version.split('-')[0];
if ( 'strictNullChecks' in options && compareVersions( tsVersion, '1.9.0' ) < 0 ) {
delete options.strictNullChecks;

console.warn( `rollup-plugin-typescript: 'strictNullChecks' is not supported; disabling it` );
}
}

export default function typescript ( options: Options ) {
Expand All @@ -106,10 +125,10 @@ export default function typescript ( options: Options ) {

delete options.tsconfig;

// Since Rollup handles the source maps; we equate the
// `sourceMap` and `inlineSourceMap` options.
fixSourceMapOption( tsconfig );
fixSourceMapOption( options );
// Since the CompilerOptions aren't designed for the Rollup
// use case, we'll adjust them for use with Rollup.
adjustCompilerOptions( typescript, tsconfig );
adjustCompilerOptions( typescript, options );

// Merge all options.
options = assign( tsconfig, getDefaultOptions(), options );
Expand Down Expand Up @@ -167,7 +186,9 @@ export default function typescript ( options: Options ) {
compilerOptions
});

const diagnostics = transformed.diagnostics.filter( goodErrors );
const diagnostics = transformed.diagnostics ?
transformed.diagnostics.filter( goodErrors ) : [];

let fatalError = false;

diagnostics.forEach( diagnostic => {
Expand Down Expand Up @@ -196,7 +217,7 @@ export default function typescript ( options: Options ) {
`\nimport { __extends, __decorate, __metadata, __param, __awaiter } from 'typescript-helpers';`,

// Rollup expects `map` to be an object so we must parse the string
map: JSON.parse(transformed.sourceMapText)
map: JSON.parse(transformed.sourceMapText as string)
};
}
};
Expand Down
106 changes: 87 additions & 19 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var assert = require( 'assert' );
var rollup = require( 'rollup' );
var assign = require( 'object-assign' );
var typescript = require( '..' );

process.chdir( __dirname );
Expand Down Expand Up @@ -33,6 +34,10 @@ describe( 'rollup-plugin-typescript', function () {
});
});

it( 'ignores the declaration option', function () {
return bundle( 'sample/basic/main.ts', { declaration: true });
});

it( 'handles async functions', function () {
return bundle( 'sample/async/main.ts' )
.then( function ( bundle ) {
Expand Down Expand Up @@ -103,36 +108,69 @@ describe( 'rollup-plugin-typescript', function () {
tsconfig: false,

// test with a mocked version of TypeScript
typescript: {
typescript: fakeTypescript({
version: '1.8.0-fake',

transpileModule: function ( code ) {
// Ignore the code to transpile. Always return the same thing.
return {
outputText: 'export default 1337;',
diagnostics: [],
sourceMapText: JSON.stringify({ mappings: '' })
};
},

// return empty compiler options
convertCompilerOptionsFromJson: function ( options ) {
[
'include',
'exclude',
'typescript',
'tsconfig',
].forEach( function ( option ) {
if ( option in options ) {
throw new Error( 'unrecognized compiler option "' + option + '"' );
}
});

return { options: {}, errors: [] };
}
}
})
})
]
}).then( function ( bundle ) {
assert.equal( bundle.generate().code.indexOf( 'var main = 1337;' ), 0 );
assert.equal( evaluate( bundle ), 1337 );
});
});

describe( 'strictNullChecks', function () {
it( 'is enabled for versions >= 1.9.0', function () {
return bundle( 'sample/overriding-typescript/main.ts', {
tsconfig: false,
strictNullChecks: true,

typescript: fakeTypescript({
version: '1.9.0-fake',
transpileModule: function ( code, options ) {
assert.ok( options.compilerOptions.strictNullChecks,
'strictNullChecks should be passed through' );

return {
outputText: '',
diagnostics: [],
sourceMapText: JSON.stringify({ mappings: '' })
};
}
}),
});
});

it( 'is disabled with a warning < 1.9.0', function () {
var warning = '';

console.warn = function (msg) {
warning = msg;
};

return rollup.rollup({
entry: 'sample/overriding-typescript/main.ts',
plugins: [
typescript({
tsconfig: false,
strictNullChecks: true,

typescript: fakeTypescript({
version: '1.8.0-fake',
})
})
]
}).then( function () {
assert.notEqual( warning.indexOf( "'strictNullChecks' is not supported" ), -1 );
});
});
});

Expand Down Expand Up @@ -164,3 +202,33 @@ describe( 'rollup-plugin-typescript', function () {
});
});
});

function fakeTypescript( custom ) {
return assign({
transpileModule: function ( code, options ) {
return {
outputText: '',
diagnostics: [],
sourceMapText: JSON.stringify({ mappings: '' })
};
},

convertCompilerOptionsFromJson: function ( options ) {
[
'include',
'exclude',
'typescript',
'tsconfig',
].forEach( function ( option ) {
if ( option in options ) {
throw new Error( 'unrecognized compiler option "' + option + '"' );
}
});

return {
options: options,
errors: []
};
}
}, custom);
}