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

Build conflict #60

Merged
merged 3 commits into from
Aug 5, 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
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.7.7",
"description": "Seamless integration between Rollup and TypeScript.",
"main": "dist/rollup-plugin-typescript.cjs.js",
"jsnext:main": "dist/rollup-plugin-typescript.es6.js",
"module": "dist/rollup-plugin-typescript.es.js",
"jsnext:main": "dist/rollup-plugin-typescript.es.js",
"files": [
"dist",
"src",
Expand All @@ -22,8 +23,8 @@
"prepublish": "npm run test",
"pretest": "npm run build",
"build:cjs": "rollup -c -f cjs -o dist/rollup-plugin-typescript.cjs.js",
"build:es6": "rollup -c -o dist/rollup-plugin-typescript.es6.js",
"build": "npm run build:cjs && npm run build:es6",
"build:es": "rollup -c -o dist/rollup-plugin-typescript.es.js",
"build": "npm run build:cjs && npm run build:es",
"prebuild": "rimraf dist/*"
},
"dependencies": {
Expand All @@ -34,10 +35,10 @@
"typescript": "^1.8.9"
},
"devDependencies": {
"mocha": "^2.3.3",
"mocha": "^3.0.0",
"rimraf": "^2.5.4",
"rollup": "^0.25.7",
"rollup-plugin-typescript": "^0.5.0"
"rollup": "^0.34.3",
"rollup-plugin-buble": "^0.12.1"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typescript from 'rollup-plugin-typescript';
import buble from 'rollup-plugin-buble';

export default {
entry: 'src/index.ts',
entry: 'src/index.js',

external: [
'compare-versions',
Expand All @@ -14,6 +14,6 @@ export default {
],

plugins: [
typescript()
buble()
]
};
8 changes: 4 additions & 4 deletions src/fixExportClass.ts → src/fixExportClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ import * as tippex from 'tippex';
// export { A };
//
// The solution is to replace the previous export syntax with the latter.
export default function fix ( code: string, id: string ): string {
export default function fix ( code, id ) {

// Erase comments, strings etc. to avoid erroneous matches for the Regex.
const cleanCode = getErasedCode( code, id );

const re = /export\s+(default\s+)?((?:abstract\s+)?class)(?:\s+(\w+))?/g;
let match: RegExpExecArray;
let match;

while ( match = re.exec( cleanCode ) ) {
// To keep source maps intact, replace non-whitespace characters with spaces.
Expand All @@ -61,15 +61,15 @@ export default function fix ( code: string, id: string ): string {
return code;
}

function getErasedCode ( code: string, id: string ): string {
function getErasedCode ( code, id ) {
try {
return tippex.erase( code );
} catch (e) {
throw new Error( `rollup-plugin-typescript: ${ e.message }; when processing: '${ id }'` );
}
}

function erase ( code: string, start: number, length: number ): string {
function erase ( code, start, length ) {
const end = start + length;

return code.slice( 0, start ) +
Expand Down
36 changes: 19 additions & 17 deletions src/index.ts → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import compareVersions from 'compare-versions';

import { endsWith } from './string';
import fixExportClass from './fixExportClass';

/*
interface Options {
tsconfig?: boolean;
include?: string | string[];
exclude?: string | string[];
typescript?: typeof ts;
module?: string;
}

*/
const resolveHost = {
directoryExists ( dirPath: string ): boolean {
directoryExists ( dirPath ) {
try {
return statSync( dirPath ).isDirectory();
} catch ( err ) {
return false;
}
},
fileExists ( filePath: string ): boolean {
fileExists ( filePath ) {
try {
return statSync( filePath ).isFile();
} catch ( err ) {
Expand All @@ -37,12 +37,12 @@ const resolveHost = {
}
};

function goodErrors ( diagnostic: ts.Diagnostic ): boolean {
function goodErrors ( diagnostic ) {
// All errors except `Cannot compile modules into 'es6' when targeting 'ES5' or lower.`
return diagnostic.code !== 1204;
}

function getDefaultOptions(): any {
function getDefaultOptions() {
return {
noEmitHelpers: true,
module: 'es2015',
Expand All @@ -53,7 +53,7 @@ function getDefaultOptions(): any {
// Gratefully lifted from 'look-up', due to problems using it directly:
// https://github.com/jonschlinkert/look-up/blob/master/index.js
// MIT Licenced
function findFile( cwd: string, filename: string ): string {
function findFile( cwd, filename ) {
let fp = cwd ? ( cwd + '/' + filename ) : filename;

if ( existsSync( fp ) ) {
Expand All @@ -74,7 +74,7 @@ function findFile( cwd: string, filename: string ): string {
return null;
}

function compilerOptionsFromTsConfig( typescript: typeof ts ): ts.CompilerOptions {
function compilerOptionsFromTsConfig( typescript ) {
const cwd = process.cwd();

const tsconfig = typescript.readConfigFile( findFile( cwd, 'tsconfig.json' ), path => readFileSync( path, 'utf8' ) );
Expand All @@ -84,7 +84,7 @@ function compilerOptionsFromTsConfig( typescript: typeof ts ): ts.CompilerOption
return tsconfig.config.compilerOptions;
}

function adjustCompilerOptions( typescript: typeof ts, options: any ) {
function adjustCompilerOptions( typescript, options ) {
// Set `sourceMap` to `inlineSourceMap` if it's a boolean
// under the assumption that both are never specified simultaneously.
if ( typeof options.inlineSourceMap === 'boolean' ) {
Expand All @@ -104,7 +104,7 @@ function adjustCompilerOptions( typescript: typeof ts, options: any ) {
}
}

export default function typescript ( options: Options ) {
export default function typescript ( options ) {
options = assign( {}, options || {} );

const filter = createFilter(
Expand All @@ -115,7 +115,7 @@ export default function typescript ( options: Options ) {
delete options.exclude;

// Allow users to override the TypeScript version used for transpilation.
const typescript: typeof ts = options.typescript || ts;
const typescript = options.typescript || ts;

delete options.typescript;

Expand Down Expand Up @@ -149,19 +149,21 @@ export default function typescript ( options: Options ) {
const compilerOptions = parsed.options;

return {
resolveId ( importee: string, importer: string ): string {
resolveId ( importee, importer ) {
// Handle the special `typescript-helpers` import itself.
if ( importee === 'typescript-helpers' ) {
return path.resolve( __dirname, '../src/typescript-helpers.js' );
}

if ( !importer ) return null;

var result: ts.ResolvedModuleWithFailedLookupLocations;
var result;

importer = importer.split('\\').join('/');

if ( compareVersions( typescript.version, '1.8.0' ) < 0 ) {
// Suppress TypeScript warnings for function call.
result = (typescript as any).nodeModuleNameResolver( importee, importer, resolveHost );
result = typescript.nodeModuleNameResolver( importee, importer, resolveHost );
} else {
result = typescript.nodeModuleNameResolver( importee, importer, compilerOptions, resolveHost );
}
Expand All @@ -177,7 +179,7 @@ export default function typescript ( options: Options ) {
return null;
},

transform ( code: string, id: string ): { code: string, map: any } {
transform ( code, id ) {
if ( !filter( id ) ) return null;

const transformed = typescript.transpileModule( fixExportClass( code, id ), {
Expand Down Expand Up @@ -208,7 +210,7 @@ export default function typescript ( options: Options ) {
});

if ( fatalError ) {
throw new Error( `There were TypeScript errors transpiling "${id}"` );
throw new Error( `There were TypeScript errors transpiling` );
}

return {
Expand All @@ -217,7 +219,7 @@ export default function typescript ( options: Options ) {
`\nimport { __assign, __awaiter, __extends, __decorate, __metadata, __param } from 'typescript-helpers';`,

// Rollup expects `map` to be an object so we must parse the string
map: JSON.parse(transformed.sourceMapText as string)
map: JSON.parse(transformed.sourceMapText)
};
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function endsWith ( str, tail ) {
return !tail.length || str.slice( -tail.length ) === tail;
}
3 changes: 0 additions & 3 deletions src/string.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe( 'rollup-plugin-typescript', function () {

it( 'reports diagnostics and throws if errors occur during transpilation', function () {
return bundle( 'sample/syntax-error/missing-type.ts' ).catch( function ( error ) {
assert.ok( error.message.indexOf( 'There were TypeScript errors' ) === 0, 'Should reject erroneous code.' );
assert.ok( error.message.indexOf( 'There were TypeScript errors transpiling' ) !== -1, 'Should reject erroneous code.' );
});
});

Expand Down
44 changes: 0 additions & 44 deletions tsconfig.json

This file was deleted.