diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..90623a1 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,45 @@ +import { Plugin } from 'rollup'; +import { CompilerOptionsValue, TsConfigSourceFile } from 'typescript'; + +interface RollupTypescriptOptions { + /** + * Determine which files are transpiled by Typescript (all `.ts` and + * `.tsx` files by default). + */ + include?: string | RegExp | ReadonlyArray | null; + /** + * Determine which files are transpiled by Typescript (all `.ts` and + * `.tsx` files by default). + */ + exclude?: string | RegExp | ReadonlyArray | null; + /** + * When set to false, ignores any options specified in the config file. + * If set to a string that corresponds to a file path, the specified file + * will be used as config file. + */ + tsconfig?: string | false; + /** + * Overrides TypeScript used for transpilation + */ + typescript?: typeof import('typescript'); + /** + * Overrides the injected TypeScript helpers with a custom version + */ + tslib?: typeof import('tslib'); + + /** + * Other Typescript compiler options + */ + [option: string]: + | CompilerOptionsValue + | TsConfigSourceFile + | RollupTypescriptOptions['include'] + | RollupTypescriptOptions['typescript'] + | RollupTypescriptOptions['tslib'] + | undefined; +} + +/** + * Seamless integration between Rollup and Typescript. + */ +export default function typescript(options?: RollupTypescriptOptions): Plugin; diff --git a/package.json b/package.json index be9d361..0f02abb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "jsnext:main": "dist/rollup-plugin-typescript.es.js", "files": [ "dist", - "src" + "src", + "index.d.ts" ], "keywords": [ "rollup-plugin", @@ -22,7 +23,7 @@ "build": "rollup -c", "lint": "eslint src test/*.js", "pretest": "npm run build", - "test": "mocha", + "test": "mocha && tsc", "posttest": "npm run lint", "prepublishOnly": "npm run test", "prepare": "npm run build" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..842f6de --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strict": true, + "noEmit": true, + "allowJs": true + }, + "files": [ + "index.d.ts", + "typings-test.js" + ] +} diff --git a/typings-test.js b/typings-test.js new file mode 100644 index 0000000..698c433 --- /dev/null +++ b/typings-test.js @@ -0,0 +1,21 @@ +// @ts-check +import typescript from '.'; + +/** @type {import("rollup").RollupOptions} */ +const config = { + input: 'main.js', + output: { + file: 'bundle.js', + format: 'iife' + }, + plugins: [ + typescript({ + lib: ["es5", "es6", "dom"], + target: "es5", + include: 'node_modules/**', + exclude: ['node_modules/foo/**', 'node_modules/bar/**', /node_modules/], + }) + ] +}; + +export default config;