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

feat: tsconfig.json by default if tsconfig.build.json not exist #1780

Merged
merged 2 commits into from
Sep 12, 2022
Merged
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
3 changes: 2 additions & 1 deletion lib/configuration/defaults.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 3 additions & 2 deletions test/lib/configuration/nest-configuration.loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Configuration, ConfigurationLoader } from '../../../lib/configuration';
import { NestConfigurationLoader } from '../../../lib/configuration/nest-configuration.loader';
import { Reader } from '../../../lib/readers';
import { getDefaultTsconfigPath } from '../../../lib/utils/get-default-tsconfig-path';

describe('Nest Configuration Loader', () => {
let reader: Reader;
Expand Down Expand Up @@ -48,7 +49,7 @@ describe('Nest Configuration Loader', () => {
compilerOptions: {
assets: [],
plugins: [],
tsConfigPath: 'tsconfig.build.json',
tsConfigPath: getDefaultTsconfigPath(),
webpack: false,
webpackConfigPath: 'webpack.config.js',
},
Expand All @@ -71,7 +72,7 @@ describe('Nest Configuration Loader', () => {
compilerOptions: {
assets: [],
plugins: [],
tsConfigPath: 'tsconfig.build.json',
tsConfigPath: getDefaultTsconfigPath(),
webpack: false,
webpackConfigPath: 'webpack.config.js',
},
Expand Down
24 changes: 24 additions & 0 deletions test/lib/utils/get-default-tsconfig-path.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});