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

Add compilerOptions #189

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/bundle-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(), {});
Expand Down
4 changes: 2 additions & 2 deletions src/compile-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export interface CompileDtsResult {
rootFilesRemapping: Map<string, string>;
}

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
Expand Down
5 changes: 5 additions & 0 deletions src/config-file/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/get-compiler-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ 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}`);

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,
Expand Down