mirror of
https://github.com/withastro/astro.git
synced 2025-03-31 23:31:30 -05:00
feat: excludeOutDir
This commit is contained in:
parent
24888f39e7
commit
b683018be3
4 changed files with 54 additions and 7 deletions
|
@ -95,6 +95,9 @@ export const ASTRO_CONFIG_DEFAULTS = {
|
|||
serverIslands: false,
|
||||
contentIntellisense: false,
|
||||
contentLayer: false,
|
||||
typescript: {
|
||||
excludeOutDir: true,
|
||||
},
|
||||
},
|
||||
} satisfies AstroUserConfig & { server: { open: boolean } };
|
||||
|
||||
|
@ -544,6 +547,10 @@ export const AstroConfigSchema = z.object({
|
|||
.object({
|
||||
include: z.array(z.string()).optional(),
|
||||
exclude: z.array(z.string()).optional(),
|
||||
excludeOutDir: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.default(ASTRO_CONFIG_DEFAULTS.experimental.typescript.excludeOutDir),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
|
|
|
@ -82,6 +82,8 @@ async function setupEnvDts(settings: AstroSettings, fs: typeof fsMod, logger: Lo
|
|||
}
|
||||
|
||||
async function setupTsconfig(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
|
||||
const typescript = settings.config.experimental.typescript!;
|
||||
|
||||
const tsconfigPath = normalizePath(fileURLToPath(new URL('tsconfig.json', settings.dotAstroDir)));
|
||||
let relativeDtsPath = normalizePath(
|
||||
relative(
|
||||
|
@ -97,8 +99,8 @@ async function setupTsconfig(settings: AstroSettings, fs: typeof fsMod, logger:
|
|||
);
|
||||
|
||||
const include = [relativeDtsPath];
|
||||
if (settings.config.experimental.typescript?.include) {
|
||||
for (const value of settings.config.experimental.typescript.include) {
|
||||
if (typescript.include) {
|
||||
for (const value of typescript.include) {
|
||||
if (startsWithDotSlash(value) || startsWithDotDotSlash(value)) {
|
||||
include.push(
|
||||
normalizePath(
|
||||
|
@ -113,9 +115,9 @@ async function setupTsconfig(settings: AstroSettings, fs: typeof fsMod, logger:
|
|||
}
|
||||
}
|
||||
}
|
||||
const exclude = [relativeOutDirPath];
|
||||
if (settings.config.experimental.typescript?.exclude) {
|
||||
for (const value of settings.config.experimental.typescript.exclude) {
|
||||
const exclude = typescript.excludeOutDir ? [relativeOutDirPath] : [];
|
||||
if (typescript.exclude) {
|
||||
for (const value of typescript.exclude) {
|
||||
if (startsWithDotSlash(value) || startsWithDotDotSlash(value)) {
|
||||
exclude.push(
|
||||
normalizePath(
|
||||
|
|
|
@ -2067,6 +2067,30 @@ export interface AstroUserConfig {
|
|||
* ```
|
||||
*/
|
||||
exclude?: Array<string>;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
* @name experimental.typescript.excludeOutDir
|
||||
* @type {boolean}
|
||||
* @default `true`
|
||||
* @version 5.0.0
|
||||
* @description
|
||||
*
|
||||
* By default, `outDir` will be added to excluded typescript files. You can opt-out of this behavior by setting this option to `false`:
|
||||
*
|
||||
* ```js title="astro.config.*" ins={6}
|
||||
* import { defineConfig } from 'astro/config'
|
||||
*
|
||||
* export default defineConfig({
|
||||
* experimental: {
|
||||
* typescript: {
|
||||
* excludeOutDir: false
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
excludeOutDir?: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -126,15 +126,29 @@ describe('experimental.typescript', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should add outDir to .astro/tsconfig.json', async () => {
|
||||
it('should add outDir to .astro/tsconfig.json if excludeOutDir is enabled', async () => {
|
||||
for (const outDir of ['dist', 'custom']) {
|
||||
const fixture = await createFixture({ experimental: { typescript: {} }, outDir });
|
||||
await fixture.sync();
|
||||
const tsconfig = JSON.parse(await fixture.readFile(GENERATED_TSCONFIG_PATH));
|
||||
const raw = await fixture.readFile(GENERATED_TSCONFIG_PATH);
|
||||
const tsconfig = JSON.parse(raw);
|
||||
assert.equal(tsconfig.exclude.includes(`../${outDir}`), true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should not add outDir to .astro/tsconfig.json if excludeOutDir is disabled', async () => {
|
||||
for (const outDir of ['dist', 'custom']) {
|
||||
const fixture = await createFixture({
|
||||
experimental: { typescript: { excludeOutDir: false } },
|
||||
outDir,
|
||||
});
|
||||
await fixture.sync();
|
||||
const raw = await fixture.readFile(GENERATED_TSCONFIG_PATH);
|
||||
const tsconfig = JSON.parse(raw);
|
||||
assert.equal(tsconfig.exclude.includes(`../${outDir}`), false);
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle include/exclude relative paths', async () => {
|
||||
const dirs = [
|
||||
{ outDir: 'dist', exclude: '../dist' },
|
||||
|
|
Loading…
Add table
Reference in a new issue