Skip to content

Commit

Permalink
feat: tsconfig.json by default if tsconfig.build.json not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Sep 8, 2022
1 parent 1aac05e commit 9bf163d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/configuration/defaults.ts
@@ -1,4 +1,5 @@
import { Configuration } from './configuration';
import { getDefaultTsconfigPath } from '../utils/get-default-tsconfig-path';

export const defaultConfiguration: Required<Configuration> = {
language: 'ts',
Expand All @@ -8,7 +9,7 @@ export const defaultConfiguration: Required<Configuration> = {
projects: {},
monorepo: false,
compilerOptions: {
tsConfigPath: 'tsconfig.build.json',
tsConfigPath: getDefaultTsconfigPath(),
webpack: false,
webpackConfigPath: 'webpack.config.js',
plugins: [],
Expand Down
11 changes: 11 additions & 0 deletions lib/utils/get-default-tsconfig-path.ts
@@ -0,0 +1,11 @@
import * as fs from 'fs';
import { join } from 'path';

const TSCONFIG_BUILD_JSON = 'tsconfig.build.json';
const TSCONFIG_JSON = 'tsconfig.json';

export function getDefaultTsconfigPath() {
return fs.existsSync(join(process.cwd(), TSCONFIG_BUILD_JSON))
? TSCONFIG_BUILD_JSON
: TSCONFIG_JSON;
}
24 changes: 24 additions & 0 deletions test/lib/utils/get-default-tsconfig-path.spec.ts
@@ -0,0 +1,24 @@
import * as fs from 'fs';
import { getDefaultTsconfigPath } from '../../../lib/utils/get-default-tsconfig-path';

jest.mock('fs', () => {
return {
existsSync: jest.fn(),
};
});

describe('get default tsconfig path', () => {
afterAll(() => {
jest.clearAllMocks();
});
it('should get tsconfig.json when tsconfig.build.json not exist', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
const result = getDefaultTsconfigPath();
expect(result).toBe('tsconfig.json');
});
it('should get tsconfig.build.json when tsconfig.build.json exist', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
const result = getDefaultTsconfigPath();
expect(result).toBe('tsconfig.build.json');
});
});

0 comments on commit 9bf163d

Please sign in to comment.