Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1780 from ZanMinKian/feat-tsconfig
feat: tsconfig.json by default if tsconfig.build.json not exist
- Loading branch information
Showing
4 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |