Skip to content

Commit 2a5e5a5

Browse files
agilgur5jaredpalmer
authored andcommitted
(types/fix): explicit Rollup typing, fix treeshake location (#371)
- treeshake was in output, but it's not a config of output :/ :/ :/ - once explicit types were added, this was a big red underline :/ :/
1 parent ee4b307 commit 2a5e5a5

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

src/createRollupConfig.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
resolveApp,
66
} from './utils';
77
import { paths } from './constants';
8+
import { RollupOptions } from 'rollup';
89
import { terser } from 'rollup-plugin-terser';
910
import { DEFAULT_EXTENSIONS } from '@babel/core';
1011
// import babel from 'rollup-plugin-babel';
@@ -26,7 +27,9 @@ const errorCodeOpts = {
2627
// shebang cache map thing because the transform only gets run once
2728
let shebang: any = {};
2829

29-
export async function createRollupConfig(opts: TsdxOptions) {
30+
export async function createRollupConfig(
31+
opts: TsdxOptions
32+
): Promise<RollupOptions> {
3033
const findAndRecordErrorCodes = await extractErrors({
3134
...errorCodeOpts,
3235
...opts,
@@ -60,6 +63,27 @@ export async function createRollupConfig(opts: TsdxOptions) {
6063
}
6164
return external(id);
6265
},
66+
// Rollup has treeshaking by default, but we can optimize it further...
67+
treeshake: {
68+
// We assume reading a property of an object never has side-effects.
69+
// This means tsdx WILL remove getters and setters defined directly on objects.
70+
// Any getters or setters defined on classes will not be effected.
71+
//
72+
// @example
73+
//
74+
// const foo = {
75+
// get bar() {
76+
// console.log('effect');
77+
// return 'bar';
78+
// }
79+
// }
80+
//
81+
// const result = foo.bar;
82+
// const illegalAccess = foo.quux.tooDeep;
83+
//
84+
// Punchline....Don't use getters and setters
85+
propertyReadSideEffects: false,
86+
},
6387
// Establish Rollup output
6488
output: {
6589
// Set filenames of the consumer's package
@@ -71,27 +95,6 @@ export async function createRollupConfig(opts: TsdxOptions) {
7195
freeze: false,
7296
// Respect tsconfig esModuleInterop when setting __esModule.
7397
esModule: tsconfigJSON ? tsconfigJSON.esModuleInterop : false,
74-
// Rollup has treeshaking by default, but we can optimize it further...
75-
treeshake: {
76-
// We assume reading a property of an object never has side-effects.
77-
// This means tsdx WILL remove getters and setters defined directly on objects.
78-
// Any getters or setters defined on classes will not be effected.
79-
//
80-
// @example
81-
//
82-
// const foo = {
83-
// get bar() {
84-
// console.log('effect');
85-
// return 'bar';
86-
// }
87-
// }
88-
//
89-
// const result = foo.bar;
90-
// const illegalAccess = foo.quux.tooDeep;
91-
//
92-
// Punchline....Don't use getters and setters
93-
propertyReadSideEffects: false,
94-
},
9598
name: opts.name || safeVariableName(opts.name),
9699
sourcemap: true,
97100
globals: { react: 'React', 'react-native': 'ReactNative' },

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ try {
4949

5050
// check for custom tsdx.config.js
5151
let tsdxConfig = {
52-
rollup(config: any, _options: any) {
52+
rollup(config: RollupOptions, _options: TsdxOptions): RollupOptions {
5353
return config;
5454
},
5555
};

0 commit comments

Comments
 (0)