Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix): respect tsconfig esModuleInterop flag #327

Merged
merged 1 commit into from
Dec 13, 2019
Merged
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
17 changes: 14 additions & 3 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { safeVariableName, safePackageName, external } from './utils';
import {
safeVariableName,
safePackageName,
external,
resolveApp,
} from './utils';
import { paths } from './constants';
import { terser } from 'rollup-plugin-terser';
import { DEFAULT_EXTENSIONS } from '@babel/core';
Expand All @@ -12,6 +17,7 @@ import typescript from 'rollup-plugin-typescript2';
import { extractErrors } from './errors/extractErrors';
import { babelPluginTsdx } from './babelPluginTsdx';
import { TsdxOptions } from './types';
import * as fs from 'fs-extra';

const errorCodeOpts = {
errorMapFilePath: paths.appErrorsJson,
Expand Down Expand Up @@ -39,6 +45,11 @@ export function createRollupConfig(opts: TsdxOptions) {
.filter(Boolean)
.join('.');

let tsconfigJSON;
try {
tsconfigJSON = fs.readJSONSync(resolveApp('tsconfig.json'));
} catch (e) {}

return {
// Tell Rollup the entry point to the package
input: opts.input,
Expand All @@ -58,8 +69,8 @@ export function createRollupConfig(opts: TsdxOptions) {
// Do not let Rollup call Object.freeze() on namespace import objects
// (i.e. import * as namespaceImportObject from...) that are accessed dynamically.
freeze: false,
// Do not let Rollup add a `__esModule: true` property when generating exports for non-ESM formats.
esModule: false,
// Respect tsconfig esModuleInterop when setting __esModule.
esModule: tsconfigJSON ? tsconfigJSON.esModuleInterop : false,
// Rollup has treeshaking by default, but we can optimize it further...
treeshake: {
// We assume reading a property of an object never has side-effects.
Expand Down