-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add extends field support #6
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,23 +89,34 @@ async function load(resolveFrom: string, options, logger): Promise<PathMapType> | |
return result; | ||
} | ||
|
||
async function loadConfig(options, resolveFrom) { | ||
async function loadConfigByName(names, options, resolveFrom) { | ||
let result = await loadConfigUtil( | ||
options.inputFS, | ||
resolveFrom, | ||
['tsconfig.json', 'tsconfig.js'], | ||
names, | ||
options.projectRoot | ||
); | ||
if (!result?.config) { | ||
throw new Error(`Missing or invalid tsconfig.json in project root (${options.projectRoot})`); | ||
throw new Error(`Missing or invalid ${names.join(',')} in project root (${options.projectRoot})`); | ||
} | ||
return result.config; | ||
} | ||
|
||
async function loadCompilerOptions(options, resolveFrom) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To reduce references to compilerOptions let's keep |
||
let baseConfig = await loadConfigByName(['tsconfig.json', 'tsconfig.js'], options, resolveFrom) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming of this variable is ambiguous. I suggest |
||
if (!baseConfig.extends) { | ||
return baseConfig.compilerOptions | ||
} | ||
let extendsConfig = await loadConfigByName([baseConfig.extends], options, resolveFrom) | ||
return extendsConfig?.compilerOptions || baseConfig?.compilerOptions ? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the project tsconfig extends another, this line drops the base config entirely. Unless items are undefined (I expect missing keys to just be missing rather than undefined, but I'll double check), it should just be: return {
...extendsConfig.compilerOptions,
...baseConfig.compilerOptions,
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
...baseConfig?.compilerOptions, | ||
...extendsConfig?.compilerOptions | ||
} : null | ||
} | ||
|
||
/** Populate a map with any paths from tsconfig.json starting from baseUrl */ | ||
async function loadTsPaths(resolveFrom: string, options, logger): Promise<PathMapType> { | ||
let config = await loadConfig(options, resolveFrom); | ||
let compilerOptions = config?.['compilerOptions']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep this line just to reduce code size |
||
let compilerOptions = await loadCompilerOptions(options, resolveFrom); | ||
if (!compilerOptions) { | ||
throw new Error(`Couldn't find compilerOptions in tsconfig`); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add space after comma