Skip to content

Commit

Permalink
- fix for #131
Browse files Browse the repository at this point in the history
  • Loading branch information
ezolenko committed Jan 16, 2019
1 parent 8dcdfb8 commit d1082d8
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 79 deletions.
2 changes: 1 addition & 1 deletion dist/check-tsconfig.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions dist/get-option-defaults.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/get-option-defaults.d.ts.map

This file was deleted.

2 changes: 1 addition & 1 deletion dist/get-options-overrides.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/parse-tsconfig.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 7 additions & 20 deletions dist/rollup-plugin-typescript2.cjs.js
Expand Up @@ -24957,38 +24957,25 @@ function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }, preParsed
allowNonTsExtensions: true,
};
if (preParsedTsconfig) {
if (preParsedTsconfig.options.module === undefined)
overrides.module = tsModule.ModuleKind.ES2015;
const declaration = preParsedTsconfig.options.declaration;
if (!declaration)
overrides.declarationDir = null;
overrides.declarationDir = undefined;
if (declaration && !useTsconfigDeclarationDir)
overrides.declarationDir = process.cwd();
// unsetting sourceRoot if sourceMap is not enabled (in case original tsconfig had inlineSourceMap set that is being unset and would cause TS5051)
const sourceMap = preParsedTsconfig.options.sourceMap;
if (!sourceMap)
overrides.sourceRoot = null;
overrides.sourceRoot = undefined;
}
return overrides;
}

function checkTsConfig(parsedConfig) {
const module = parsedConfig.options.module;
switch (module) {
case tsModule.ModuleKind.ES2015:
case tsModule.ModuleKind.ESNext:
break;
case undefined:
throw new Error(`Incompatible tsconfig option. Missing module option. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
default:
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}
}

function getOptionsDefaults() {
return {
compilerOptions: {
module: "ES2015",
},
};
if (module !== tsModule.ModuleKind.ES2015 && module !== tsModule.ModuleKind.ESNext)
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}

function parseTsConfig(context, pluginOptions) {
Expand All @@ -25015,7 +25002,7 @@ function parseTsConfig(context, pluginOptions) {
configFileName = fileName;
}
const mergedConfig = {};
lodash_14(mergedConfig, getOptionsDefaults(), pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
lodash_14(mergedConfig, pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
const preParsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, getOptionsOverrides(pluginOptions), configFileName);
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, preParsedTsConfig);
const parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.cjs.js.map

Large diffs are not rendered by default.

27 changes: 7 additions & 20 deletions dist/rollup-plugin-typescript2.es.js
Expand Up @@ -24953,38 +24953,25 @@ function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }, preParsed
allowNonTsExtensions: true,
};
if (preParsedTsconfig) {
if (preParsedTsconfig.options.module === undefined)
overrides.module = tsModule.ModuleKind.ES2015;
const declaration = preParsedTsconfig.options.declaration;
if (!declaration)
overrides.declarationDir = null;
overrides.declarationDir = undefined;
if (declaration && !useTsconfigDeclarationDir)
overrides.declarationDir = process.cwd();
// unsetting sourceRoot if sourceMap is not enabled (in case original tsconfig had inlineSourceMap set that is being unset and would cause TS5051)
const sourceMap = preParsedTsconfig.options.sourceMap;
if (!sourceMap)
overrides.sourceRoot = null;
overrides.sourceRoot = undefined;
}
return overrides;
}

function checkTsConfig(parsedConfig) {
const module = parsedConfig.options.module;
switch (module) {
case tsModule.ModuleKind.ES2015:
case tsModule.ModuleKind.ESNext:
break;
case undefined:
throw new Error(`Incompatible tsconfig option. Missing module option. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
default:
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}
}

function getOptionsDefaults() {
return {
compilerOptions: {
module: "ES2015",
},
};
if (module !== tsModule.ModuleKind.ES2015 && module !== tsModule.ModuleKind.ESNext)
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}

function parseTsConfig(context, pluginOptions) {
Expand All @@ -25011,7 +24998,7 @@ function parseTsConfig(context, pluginOptions) {
configFileName = fileName;
}
const mergedConfig = {};
lodash_14(mergedConfig, getOptionsDefaults(), pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
lodash_14(mergedConfig, pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
const preParsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, getOptionsOverrides(pluginOptions), configFileName);
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, preParsedTsConfig);
const parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.es.js.map

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions src/check-tsconfig.ts
Expand Up @@ -3,16 +3,8 @@ import * as tsTypes from "typescript";

export function checkTsConfig(parsedConfig: tsTypes.ParsedCommandLine): void
{
const module = parsedConfig.options.module;
const module = parsedConfig.options.module!;

switch (module)
{
case tsModule.ModuleKind.ES2015:
case tsModule.ModuleKind.ESNext:
break;
case undefined:
throw new Error(`Incompatible tsconfig option. Missing module option. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
default:
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}
if (module !== tsModule.ModuleKind.ES2015 && module !== tsModule.ModuleKind.ESNext)
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}
9 changes: 0 additions & 9 deletions src/get-option-defaults.ts

This file was deleted.

11 changes: 7 additions & 4 deletions src/get-options-overrides.ts
Expand Up @@ -5,7 +5,7 @@ import * as _ from "lodash";

export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions
{
const overrides = {
const overrides: tsTypes.CompilerOptions = {
noEmitHelpers: false,
importHelpers: true,
noResolve: false,
Expand All @@ -18,16 +18,19 @@ export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IO

if (preParsedTsconfig)
{
if (preParsedTsconfig.options.module === undefined)
overrides.module = tsModule.ModuleKind.ES2015;

const declaration = preParsedTsconfig.options.declaration;
if (!declaration)
(overrides as any).declarationDir = null;
overrides.declarationDir = undefined;
if (declaration && !useTsconfigDeclarationDir)
(overrides as any).declarationDir = process.cwd();
overrides.declarationDir = process.cwd();

// unsetting sourceRoot if sourceMap is not enabled (in case original tsconfig had inlineSourceMap set that is being unset and would cause TS5051)
const sourceMap = preParsedTsconfig.options.sourceMap;
if (!sourceMap)
(overrides as any).sourceRoot = null;
overrides.sourceRoot = undefined;
}

return overrides;
Expand Down
3 changes: 1 addition & 2 deletions src/parse-tsconfig.ts
Expand Up @@ -8,7 +8,6 @@ import { getOptionsOverrides } from "./get-options-overrides";
import { IOptions } from "./ioptions";
import * as _ from "lodash";
import { checkTsConfig } from "./check-tsconfig";
import { getOptionsDefaults } from "./get-option-defaults";

export function parseTsConfig(context: IContext, pluginOptions: IOptions): tsTypes.ParsedCommandLine
{
Expand Down Expand Up @@ -43,7 +42,7 @@ export function parseTsConfig(context: IContext, pluginOptions: IOptions): tsTyp
}

const mergedConfig = {};
_.merge(mergedConfig, getOptionsDefaults(), pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
_.merge(mergedConfig, pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);

const preParsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, getOptionsOverrides(pluginOptions), configFileName);
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, preParsedTsConfig);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.base",
"extends": "./tsconfig.base",
"compilerOptions": {
"target": "es6",
"noImplicitAny": true,
Expand Down

0 comments on commit d1082d8

Please sign in to comment.