diff --git a/src/bundle-generator.ts b/src/bundle-generator.ts index f9af1b3..f031e35 100644 --- a/src/bundle-generator.ts +++ b/src/bundle-generator.ts @@ -52,6 +52,11 @@ export interface CompilationOptions { * Path to the tsconfig file that will be used for the compilation. */ preferredConfigPath?: string; + /** + * Override properties under "compilerOptions" of tsconfig.json. + * For example:{"removeComments": false} + */ + compilerOptions?:{[key:string]:any} } export interface OutputOptions { @@ -136,7 +141,7 @@ export interface EntryPointConfig { export function generateDtsBundle(entries: readonly EntryPointConfig[], options: CompilationOptions = {}): string[] { normalLog('Compiling input files...'); - const { program, rootFilesRemapping } = compileDts(entries.map((entry: EntryPointConfig) => entry.filePath), options.preferredConfigPath, options.followSymlinks); + const { program, rootFilesRemapping } = compileDts(entries.map((entry: EntryPointConfig) => entry.filePath), options.preferredConfigPath, options.followSymlinks,options.compilerOptions); const typeChecker = program.getTypeChecker(); const typeRoots = ts.getEffectiveTypeRoots(program.getCompilerOptions(), {}); diff --git a/src/compile-dts.ts b/src/compile-dts.ts index b84c42c..2418ee7 100644 --- a/src/compile-dts.ts +++ b/src/compile-dts.ts @@ -12,8 +12,8 @@ export interface CompileDtsResult { rootFilesRemapping: Map; } -export function compileDts(rootFiles: readonly string[], preferredConfigPath?: string, followSymlinks: boolean = true): CompileDtsResult { - const compilerOptions = getCompilerOptions(rootFiles, preferredConfigPath); +export function compileDts(rootFiles: readonly string[], preferredConfigPath?: string, followSymlinks: boolean = true,_compilerOptions?:{[key:string]:any}): CompileDtsResult { + const compilerOptions = getCompilerOptions(rootFiles, preferredConfigPath,_compilerOptions); // currently we don't support these compiler options // and removing them shouldn't affect generated code diff --git a/src/config-file/README.md b/src/config-file/README.md index 1bb1293..738811f 100644 --- a/src/config-file/README.md +++ b/src/config-file/README.md @@ -21,6 +21,11 @@ Config file might be either JSON file or JS file with CommonJS export of the con * Must be set if entries count more than 1. */ preferredConfigPath: './tsconfig.json', + /** + * Override properties under "compilerOptions" of tsconfig.json. + * For example:{"removeComments": false} + */ + compilerOptions:{} }, // non-empty array of entries diff --git a/src/get-compiler-options.ts b/src/get-compiler-options.ts index 02721b2..7ba7cb0 100644 --- a/src/get-compiler-options.ts +++ b/src/get-compiler-options.ts @@ -16,7 +16,7 @@ const parseConfigHost: ts.ParseConfigHost = { readFile: ts.sys.readFile, }; -export function getCompilerOptions(inputFileNames: readonly string[], preferredConfigPath?: string): ts.CompilerOptions { +export function getCompilerOptions(inputFileNames: readonly string[], preferredConfigPath?: string,compilerOptions?:{[key:string]:any}): ts.CompilerOptions { const configFileName = preferredConfigPath !== undefined ? preferredConfigPath : findConfig(inputFileNames); verboseLog(`Using config: ${configFileName}`); @@ -24,6 +24,8 @@ export function getCompilerOptions(inputFileNames: readonly string[], preferredC const configParseResult = ts.readConfigFile(configFileName, ts.sys.readFile); checkDiagnosticsErrors(configParseResult.error !== undefined ? [configParseResult.error] : [], 'Error while processing tsconfig file'); + if(compilerOptions) Object.assign(configParseResult.config.compilerOptions,compilerOptions); + const compilerOptionsParseResult = ts.parseJsonConfigFileContent( configParseResult.config, parseConfigHost,