-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70400ea
commit c1d5359
Showing
10 changed files
with
97 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
"prebundle": "1.2.2", | ||
"rslib": "npm:@rslib/[email protected]", | ||
"rslog": "^1.2.3", | ||
"tsconfck": "3.1.3", | ||
"typescript": "^5.5.4" | ||
}, | ||
"peerDependencies": { | ||
|
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import path from 'node:path'; | ||
import ts from 'typescript'; | ||
import { basename, join } from 'node:path'; | ||
import { find, parse } from 'tsconfck'; | ||
|
||
export function loadTsconfig(tsconfigPath: string): ts.ParsedCommandLine { | ||
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile); | ||
const configFileContent = ts.parseJsonConfigFileContent( | ||
configFile.config, | ||
ts.sys, | ||
path.dirname(tsconfigPath), | ||
); | ||
export async function loadTsconfig( | ||
root: string, | ||
tsconfigPath = 'tsconfig.json', | ||
): Promise<{ | ||
compilerOptions?: Record<string, any>; | ||
}> { | ||
const tsconfigFileName = await find(join(root, tsconfigPath), { | ||
root, | ||
configName: basename(tsconfigPath), | ||
}); | ||
|
||
return configFileContent; | ||
} | ||
|
||
export function getTsconfigCompilerOptions( | ||
tsconfigPath: string, | ||
): ts.CompilerOptions { | ||
const { options } = loadTsconfig(tsconfigPath); | ||
if (tsconfigFileName) { | ||
const { tsconfig } = await parse(tsconfigFileName); | ||
return tsconfig; | ||
} | ||
|
||
return options; | ||
return {}; | ||
} |
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
5 changes: 5 additions & 0 deletions
5
packages/core/tests/fixtures/tsconfig/exist/tsconfig.custom.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "custom" | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "./" | ||
} | ||
} |
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 @@ | ||
export const foo = 'foo'; |
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,33 @@ | ||
import { join } from 'node:path'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { loadTsconfig } from '../src/utils/tsconfig'; | ||
|
||
describe('loadTsconfig', () => { | ||
it('should return tsconfig when a valid tsconfig file is found', async () => { | ||
const fixtureDir = join(__dirname, 'fixtures/tsconfig/exist'); | ||
const result1 = await loadTsconfig(fixtureDir); | ||
const result2 = await loadTsconfig(fixtureDir, './tsconfig.custom.json'); | ||
|
||
expect(result1).toMatchInlineSnapshot(` | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "./", | ||
}, | ||
} | ||
`); | ||
expect(result2).toMatchInlineSnapshot(` | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "custom", | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it('should return an empty object when no tsconfig file is found', async () => { | ||
const fixtureDir = join(__dirname, 'fixtures/tsconfig/no-exist'); | ||
const result = await loadTsconfig(fixtureDir); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -118,6 +118,7 @@ templating | |
transpiling | ||
treeshaking | ||
tsbuildinfo | ||
tsconfck | ||
tsdoc | ||
tsup | ||
unocss | ||
|