Skip to content

Commit

Permalink
feat: ProjectOptions::defaultCompilerOptions (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojpawlik committed Nov 25, 2023
1 parent a90dc91 commit b5dee3d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/options/CompilerOptionsContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { SettingsContainer } from "./SettingsContainer";
* Holds the compiler options.
*/
export class CompilerOptionsContainer extends SettingsContainer<ts.CompilerOptions> {
constructor() {
super({});
constructor(defaultSettings: ts.CompilerOptions = {}) {
super(defaultSettings);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/ts-morph/src/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface ProjectOptions {
compilerOptions?: CompilerOptions;
/** File path to the tsconfig.json file. */
tsConfigFilePath?: string;
/** Can be overriden by `tsConfigFilePath` or `compilerOptions`. */
defaultCompilerOptions?: CompilerOptions;
/** Whether to skip adding the source files from the specified tsconfig.json. @default false */
skipAddingFilesFromTsConfig?: boolean;
/** Skip resolving file dependencies when providing a ts config file path and adding the files from tsconfig. @default false */
Expand Down Expand Up @@ -99,7 +101,7 @@ export class Project {

// compiler options initialization
const compilerOptions = getCompilerOptions();
const compilerOptionsContainer = new CompilerOptionsContainer();
const compilerOptionsContainer = new CompilerOptionsContainer(options.defaultCompilerOptions);
compilerOptionsContainer.set(compilerOptions);

// setup context
Expand Down
3 changes: 3 additions & 0 deletions packages/ts-morph/src/tests/projectTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ describe("Project", () => {
tsConfigFilePath: "tsconfig.json",
compilerOptions: {
target: 2,
},
defaultCompilerOptions: {
target: 1,
allowJs: true,
},
skipAddingFilesFromTsConfig, // the behaviour changes based on this value so it's good to test both of these
Expand Down

0 comments on commit b5dee3d

Please sign in to comment.