mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
feat(next): better tsconfig (#11859)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
parent
5a39da87d3
commit
38047119ff
80 changed files with 207 additions and 184 deletions
19
.changeset/old-zebras-teach.md
Normal file
19
.changeset/old-zebras-teach.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
'astro': major
|
||||
---
|
||||
|
||||
Changes the default `tsconfig.json` with better defaults, and makes `src/env.d.ts` optional
|
||||
|
||||
Astro's default `tsconfig.json` in starter examples has been updated to include generated types and exclude your build output. This means that `src/env.d.ts` is only necessary if you have added custom type declarations or if you're not using a `tsconfig.json` file.
|
||||
|
||||
Additionally, running `astro sync` no longer creates, nor updates, `src/env.d.ts` as it is not required for type-checking standard Astro projects.
|
||||
|
||||
To update your project to Astro's recommended TypeScript settings, please add the following `include` and `exclude` properties to `tsconfig.json`:
|
||||
|
||||
```diff
|
||||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
+ "include": ["**/*", ".astro/types.d.ts"],
|
||||
+ "exclude": ["dist"]
|
||||
}
|
||||
```
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/blog/src/env.d.ts
vendored
1
examples/blog/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": true
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
"jsx": "preserve"
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/framework-alpine/src/env.d.ts
vendored
1
examples/framework-alpine/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/framework-multiple/src/env.d.ts
vendored
1
examples/framework-multiple/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
// Needed for TypeScript intellisense in the template inside Vue files
|
||||
"jsx": "preserve"
|
||||
|
|
1
examples/framework-preact/src/env.d.ts
vendored
1
examples/framework-preact/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
// Preact specific settings
|
||||
"jsx": "react-jsx",
|
||||
|
|
1
examples/framework-react/src/env.d.ts
vendored
1
examples/framework-react/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
|
|
1
examples/framework-solid/src/env.d.ts
vendored
1
examples/framework-solid/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
// Solid specific settings
|
||||
"jsx": "preserve",
|
||||
|
|
1
examples/framework-svelte/src/env.d.ts
vendored
1
examples/framework-svelte/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/framework-vue/src/env.d.ts
vendored
1
examples/framework-vue/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
// Needed for TypeScript intellisense in the template inside Vue files
|
||||
"jsx": "preserve"
|
||||
|
|
1
examples/hackernews/src/env.d.ts
vendored
1
examples/hackernews/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/middleware/src/env.d.ts
vendored
1
examples/middleware/src/env.d.ts
vendored
|
@ -1,4 +1,3 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
||||
declare namespace App {
|
||||
interface Locals {
|
||||
user: {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/minimal/src/env.d.ts
vendored
1
examples/minimal/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/non-html-pages/src/env.d.ts
vendored
1
examples/non-html-pages/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/portfolio/src/env.d.ts
vendored
1
examples/portfolio/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/ssr/src/env.d.ts
vendored
1
examples/ssr/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/strict",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
|
|
1
examples/with-markdoc/src/env.d.ts
vendored
1
examples/with-markdoc/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": true
|
||||
}
|
||||
|
|
1
examples/with-markdown-plugins/src/env.d.ts
vendored
1
examples/with-markdown-plugins/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/with-markdown-shiki/src/env.d.ts
vendored
1
examples/with-markdown-shiki/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/with-mdx/src/env.d.ts
vendored
1
examples/with-mdx/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
1
examples/with-nanostores/src/env.d.ts
vendored
1
examples/with-nanostores/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
// Preact specific settings
|
||||
"jsx": "react-jsx",
|
||||
|
|
1
examples/with-tailwindcss/src/env.d.ts
vendored
1
examples/with-tailwindcss/src/env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -4,5 +4,7 @@
|
|||
"strictNullChecks": true,
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -4,5 +4,7 @@
|
|||
"strictNullChecks": true,
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"importsNotUsedAsValues": "error"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -4,5 +4,6 @@
|
|||
// This is only needed because we link Astro locally.
|
||||
"preserveSymlinks": true
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
"include": ["./src/**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
/// <reference path="../../.astro/types.d.ts" />
|
||||
/// <reference path="../.astro/types.d.ts" />
|
||||
/// <reference types="astro/client" />
|
|
@ -3,5 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -3,5 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -3,5 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -2,5 +2,7 @@
|
|||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
// TODO: use types.d.ts for backward compatibility. Use astro.d.ts in Astro 5.0
|
||||
export const REFERENCE_FILE = './types.d.ts';
|
|
@ -30,7 +30,8 @@ import {
|
|||
import type { Logger } from '../logger/core.js';
|
||||
import { formatErrorMessage } from '../messages.js';
|
||||
import { ensureProcessNodeEnv } from '../util.js';
|
||||
import { writeFiles } from './write-files.js';
|
||||
import { dirname, relative } from 'node:path';
|
||||
import { normalizePath } from 'vite';
|
||||
|
||||
export type SyncOptions = {
|
||||
/**
|
||||
|
@ -135,7 +136,7 @@ export async function syncInternal({
|
|||
}
|
||||
syncAstroEnv(settings);
|
||||
|
||||
await writeFiles(settings, fs, logger);
|
||||
writeInjectedTypes(settings, fs);
|
||||
logger.info('types', `Generated ${dim(getTimeStat(timerStart, performance.now()))}`);
|
||||
} catch (err) {
|
||||
const error = createSafeError(err);
|
||||
|
@ -148,6 +149,33 @@ export async function syncInternal({
|
|||
}
|
||||
}
|
||||
|
||||
function getTsReference(type: 'path' | 'types', value: string) {
|
||||
return `/// <reference ${type}=${JSON.stringify(value)} />`;
|
||||
}
|
||||
|
||||
const CLIENT_TYPES_REFERENCE = getTsReference('types', 'astro/client');
|
||||
|
||||
function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
|
||||
const references: Array<string> = [];
|
||||
|
||||
for (const { filename, content } of settings.injectedTypes) {
|
||||
const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
|
||||
fs.mkdirSync(dirname(filepath), { recursive: true });
|
||||
fs.writeFileSync(filepath, content, 'utf-8');
|
||||
references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
|
||||
}
|
||||
|
||||
const astroDtsContent = `${CLIENT_TYPES_REFERENCE}\n${references.map((reference) => getTsReference('path', reference)).join('\n')}`;
|
||||
if (references.length === 0) {
|
||||
fs.mkdirSync(settings.dotAstroDir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(
|
||||
fileURLToPath(new URL('./types.d.ts', settings.dotAstroDir)),
|
||||
astroDtsContent,
|
||||
'utf-8',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate content collection types, and then returns the process exit signal.
|
||||
*
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
import type fsMod from 'node:fs';
|
||||
import { dirname, relative } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { bold } from 'kleur/colors';
|
||||
import { normalizePath } from 'vite';
|
||||
import type { AstroSettings } from '../../types/astro.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
import type { Logger } from '../logger/core.js';
|
||||
import { REFERENCE_FILE } from './constants.js';
|
||||
|
||||
export async function writeFiles(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
|
||||
try {
|
||||
writeInjectedTypes(settings, fs);
|
||||
await setUpEnvTs(settings, fs, logger);
|
||||
} catch (e) {
|
||||
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: e });
|
||||
}
|
||||
}
|
||||
|
||||
function getTsReference(type: 'path' | 'types', value: string) {
|
||||
return `/// <reference ${type}=${JSON.stringify(value)} />`;
|
||||
}
|
||||
|
||||
const CLIENT_TYPES_REFERENCE = getTsReference('types', 'astro/client');
|
||||
|
||||
function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
|
||||
const references: Array<string> = [];
|
||||
|
||||
for (const { filename, content } of settings.injectedTypes) {
|
||||
const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
|
||||
fs.mkdirSync(dirname(filepath), { recursive: true });
|
||||
fs.writeFileSync(filepath, content, 'utf-8');
|
||||
references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
|
||||
}
|
||||
|
||||
const astroDtsContent = `${CLIENT_TYPES_REFERENCE}\n${references.map((reference) => getTsReference('path', reference)).join('\n')}`;
|
||||
if (references.length === 0) {
|
||||
fs.mkdirSync(settings.dotAstroDir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(
|
||||
fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir)),
|
||||
astroDtsContent,
|
||||
'utf-8',
|
||||
);
|
||||
}
|
||||
|
||||
async function setUpEnvTs(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
|
||||
const envTsPath = fileURLToPath(new URL('env.d.ts', settings.config.srcDir));
|
||||
const envTsPathRelativetoRoot = relative(fileURLToPath(settings.config.root), envTsPath);
|
||||
const relativePath = normalizePath(
|
||||
relative(
|
||||
fileURLToPath(settings.config.srcDir),
|
||||
fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir)),
|
||||
),
|
||||
);
|
||||
const expectedTypeReference = getTsReference('path', relativePath);
|
||||
|
||||
if (fs.existsSync(envTsPath)) {
|
||||
const initialEnvContents = await fs.promises.readFile(envTsPath, 'utf-8');
|
||||
let typesEnvContents = initialEnvContents;
|
||||
|
||||
if (!typesEnvContents.includes(expectedTypeReference)) {
|
||||
typesEnvContents = `${expectedTypeReference}\n${typesEnvContents}`;
|
||||
}
|
||||
|
||||
if (initialEnvContents !== typesEnvContents) {
|
||||
logger.info('types', `Updated ${bold(envTsPathRelativetoRoot)} type declarations.`);
|
||||
await fs.promises.writeFile(envTsPath, typesEnvContents, 'utf-8');
|
||||
}
|
||||
} else {
|
||||
// Otherwise, inject the `env.d.ts` file
|
||||
await fs.promises.mkdir(settings.config.srcDir, { recursive: true });
|
||||
await fs.promises.writeFile(envTsPath, expectedTypeReference, 'utf-8');
|
||||
logger.info('types', `Added ${bold(envTsPathRelativetoRoot)} type declarations`);
|
||||
}
|
||||
}
|
|
@ -24,10 +24,6 @@ const createFixture = () => {
|
|||
return astroFixture.config;
|
||||
},
|
||||
clean() {
|
||||
const envPath = new URL('env.d.ts', astroFixture.config.srcDir);
|
||||
if (fs.existsSync(envPath)) {
|
||||
fs.unlinkSync(new URL('env.d.ts', astroFixture.config.srcDir));
|
||||
}
|
||||
fs.rmSync(new URL('./.astro/', astroFixture.config.root), { force: true, recursive: true });
|
||||
},
|
||||
async whenSyncing() {
|
||||
|
@ -108,40 +104,15 @@ describe('astro sync', () => {
|
|||
fixture = createFixture();
|
||||
});
|
||||
|
||||
describe('References', () => {
|
||||
it('Writes `src/env.d.ts` if none exists', async () => {
|
||||
await fixture.load('./fixtures/astro-basic/');
|
||||
fixture.clean();
|
||||
await fixture.whenSyncing();
|
||||
fixture.thenFileShouldExist('src/env.d.ts');
|
||||
fixture.thenFileContentShouldInclude(
|
||||
'src/env.d.ts',
|
||||
`/// <reference path="../.astro/types.d.ts" />`,
|
||||
);
|
||||
});
|
||||
|
||||
it('Updates `src/env.d.ts` if one exists', async () => {
|
||||
const config = await fixture.load('./fixtures/astro-basic/');
|
||||
fixture.clean();
|
||||
fs.writeFileSync(new URL('./env.d.ts', config.srcDir), '// whatever', 'utf-8');
|
||||
await fixture.whenSyncing();
|
||||
fixture.thenFileShouldExist('src/env.d.ts');
|
||||
fixture.thenFileContentShouldInclude(
|
||||
'src/env.d.ts',
|
||||
`/// <reference path="../.astro/types.d.ts" />`,
|
||||
);
|
||||
});
|
||||
|
||||
it('Writes `src/types.d.ts`', async () => {
|
||||
await fixture.load('./fixtures/astro-basic/');
|
||||
fixture.clean();
|
||||
await fixture.whenSyncing();
|
||||
fixture.thenFileShouldExist('.astro/types.d.ts');
|
||||
fixture.thenFileContentShouldInclude(
|
||||
'.astro/types.d.ts',
|
||||
`/// <reference types="astro/client" />`,
|
||||
);
|
||||
});
|
||||
it('Writes `.astro/types.d.ts`', async () => {
|
||||
await fixture.load('./fixtures/astro-basic/');
|
||||
fixture.clean();
|
||||
await fixture.whenSyncing();
|
||||
fixture.thenFileShouldExist('.astro/types.d.ts');
|
||||
fixture.thenFileContentShouldInclude(
|
||||
'.astro/types.d.ts',
|
||||
`/// <reference types="astro/client" />`,
|
||||
);
|
||||
});
|
||||
|
||||
describe('Content collections', () => {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./src"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -13,5 +13,7 @@
|
|||
"src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{
|
||||
"extends": "astro/tsconfigs/base"
|
||||
"extends": "astro/tsconfigs/base",
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -7,5 +7,7 @@
|
|||
"src/assets/*"
|
||||
]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -5,5 +5,7 @@
|
|||
"paths": {
|
||||
"~/assets/*": ["src/assets/*"]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -2,5 +2,7 @@
|
|||
"extends": "astro/tsconfigs/base",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -2,5 +2,7 @@
|
|||
"extends": "astro/tsconfigs/base",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -5,5 +5,7 @@
|
|||
"paths": {
|
||||
"~/assets/*": ["src/assets/*"]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -5,5 +5,7 @@
|
|||
"paths": {
|
||||
"~/assets/*": ["src/assets/*"]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -7,5 +7,7 @@
|
|||
"src/assets/*"
|
||||
]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -3,5 +3,7 @@
|
|||
"strict": true,
|
||||
"jsxImportSource": "solid-js",
|
||||
"types": ["astro/client"]
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -3,5 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -3,5 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -5,5 +5,7 @@
|
|||
"paths": {
|
||||
"~/assets/*": ["src/assets/*"]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
|
@ -3,5 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
|
@ -5,5 +5,7 @@
|
|||
"paths": {
|
||||
"~/assets/*": ["src/assets/*"]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["**/*", ".astro/types.d.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue