mirror of
https://github.com/withastro/astro.git
synced 2025-04-14 23:51:49 -05:00
feat: handle relative include/exclude
This commit is contained in:
parent
0377fb9b4c
commit
d7517e0ace
2 changed files with 36 additions and 11 deletions
|
@ -96,16 +96,41 @@ async function setupTsconfig(settings: AstroSettings, fs: typeof fsMod, logger:
|
|||
relative(fileURLToPath(settings.dotAstroDir), fileURLToPath(settings.config.outDir)),
|
||||
);
|
||||
|
||||
// TODO: handle relative include/exclude! Users will add values relative to the root,
|
||||
// but here they should be relative to dotAstroDir
|
||||
const expectedContent = JSON.stringify(
|
||||
{
|
||||
include: [...(settings.config.experimental.typescript?.include ?? []), relativeDtsPath],
|
||||
exclude: [...(settings.config.experimental.typescript?.exclude ?? []), relativeOutDirPath],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
const include = [relativeDtsPath];
|
||||
if (settings.config.experimental.typescript?.include) {
|
||||
for (const value of settings.config.experimental.typescript.include) {
|
||||
if (startsWithDotSlash(value) || startsWithDotDotSlash(value)) {
|
||||
include.push(
|
||||
normalizePath(
|
||||
relative(
|
||||
fileURLToPath(settings.dotAstroDir),
|
||||
fileURLToPath(new URL(value, settings.config.root)),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
include.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
const exclude = [relativeOutDirPath];
|
||||
if (settings.config.experimental.typescript?.exclude) {
|
||||
for (const value of settings.config.experimental.typescript.exclude) {
|
||||
if (startsWithDotSlash(value) || startsWithDotDotSlash(value)) {
|
||||
exclude.push(
|
||||
normalizePath(
|
||||
relative(
|
||||
fileURLToPath(settings.dotAstroDir),
|
||||
fileURLToPath(new URL(value, settings.config.root)),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
exclude.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
const expectedContent = JSON.stringify({ include, exclude }, null, 2);
|
||||
|
||||
if (fs.existsSync(tsconfigPath) && fs.readFileSync(tsconfigPath, 'utf-8') === expectedContent) {
|
||||
return;
|
||||
|
|
|
@ -1974,7 +1974,7 @@ export interface AstroUserConfig {
|
|||
* @version 5.0.0
|
||||
* @description
|
||||
*
|
||||
* Enables the generation of `.astro/tsconfig.json`. This allows to exclude the `distDir` by default to avoid `astro check` false positives.
|
||||
* Enables the generation of `.astro/tsconfig.json`. This allows to exclude the `outDir` by default to avoid `astro check` false positives.
|
||||
*
|
||||
* If you enable this option, you'll need to update your `tsconfig.json` with a new `extends` value:
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue