Skip to content

Commit 1c32990

Browse files
authored
fix(typescript): allow explicity compilerOptions (#1045)
1 parent b6d6d4a commit 1c32990

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

packages/typescript/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The plugin loads any [`compilerOptions`](http://www.typescriptlang.org/docs/hand
5858
export default {
5959
input: './main.ts',
6060
plugins: [
61-
typescript({lib: ["es5", "es6", "dom"], target: "es5"})
61+
typescript({ compilerOptions: {lib: ["es5", "es6", "dom"], target: "es5"}})
6262
]
6363
}
6464
```
@@ -252,7 +252,7 @@ import commonjs from '@rollup/plugin-commonjs';
252252
export default {
253253
input: './main.ts',
254254
plugins: [
255-
typescript({ module: 'CommonJS' }),
255+
typescript({ compilerOptions: { module: 'CommonJS' } }),
256256
commonjs({ extensions: ['.js', '.ts'] }) // the ".ts" extension is required
257257
]
258258
};
@@ -282,7 +282,7 @@ import typescript from '@rollup/plugin-typescript';
282282
export default {
283283
// … other options …
284284
acornInjectPlugins: [jsx()],
285-
plugins: [typescript({ jsx: 'preserve' })]
285+
plugins: [typescript({ compilerOptions: { jsx: 'preserve' } })]
286286
};
287287
```
288288

packages/typescript/src/options/plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export const getPluginOptions = (options: RollupTypescriptOptions) => {
2424
tslib,
2525
typescript,
2626
outputToFilesystem,
27-
...compilerOptions
27+
compilerOptions,
28+
// previously was compilerOptions
29+
...extra
2830
} = options;
2931

3032
return {
@@ -33,7 +35,7 @@ export const getPluginOptions = (options: RollupTypescriptOptions) => {
3335
exclude,
3436
filterRoot,
3537
tsconfig,
36-
compilerOptions: compilerOptions as PartialCompilerOptions,
38+
compilerOptions: { ...extra, ...compilerOptions } as PartialCompilerOptions,
3739
typescript: typescript || defaultTs,
3840
tslib: tslib || getTsLibPath(),
3941
transformers,

packages/typescript/test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ test.serial('runs code through typescript', async (t) => {
2828
t.false(code.includes('const'), code);
2929
});
3030

31+
test.serial('runs code through typescript with compilerOptions', async (t) => {
32+
const bundle = await rollup({
33+
input: 'fixtures/basic/main.ts',
34+
plugins: [
35+
typescript({ tsconfig: 'fixtures/basic/tsconfig.json', compilerOptions: { target: 'es5' } })
36+
],
37+
onwarn
38+
});
39+
const code = await getCode(bundle, outputOptions);
40+
41+
t.false(code.includes('number'), code);
42+
t.false(code.includes('const'), code);
43+
});
44+
3145
test.serial('ensures outDir is located in Rollup output dir', async (t) => {
3246
const bundle = await rollup({
3347
input: 'fixtures/basic/main.ts',

packages/typescript/types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export interface RollupTypescriptPluginOptions {
7979
* If not set, will default to true with a warning.
8080
*/
8181
outputToFilesystem?: boolean;
82+
/**
83+
* Pass additional compiler options to the plugin.
84+
*/
85+
compilerOptions?: PartialCompilerOptions;
8286
}
8387

8488
export interface FlexibleCompilerOptions extends CompilerOptions {

0 commit comments

Comments
 (0)