diff --git a/.changeset/gentle-deers-yawn.md b/.changeset/gentle-deers-yawn.md new file mode 100644 index 0000000000..30e577c69b --- /dev/null +++ b/.changeset/gentle-deers-yawn.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Call `astro sync` once before calling `astro check` diff --git a/package.json b/package.json index d7343da53f..0c75669ae0 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "astro-benchmark": "workspace:*" }, "devDependencies": { + "@astrojs/check": "^0.1.0", "@changesets/changelog-github": "^0.4.8", "@changesets/cli": "^2.26.1", "@types/node": "^18.16.18", diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index 5ad031714a..428027154a 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -1,7 +1,7 @@ import path from 'node:path'; import type { Arguments } from 'yargs-parser'; import { error, info } from '../../core/logger/core.js'; -import { createLoggingFromFlags } from '../flags.js'; +import { createLoggingFromFlags, flagsToAstroInlineConfig } from '../flags.js'; import { getPackage } from '../install-package.js'; export async function check(flags: Arguments) { @@ -24,6 +24,16 @@ export async function check(flags: Arguments) { return; } + // Run sync before check to make sure types are generated. + // NOTE: In the future, `@astrojs/check` can expose a `before lint` hook so that this works during `astro check --watch` too. + // For now, we run this once as usually `astro check --watch` is ran alongside `astro dev` which also calls `astro sync`. + const { sync } = await import('../../core/sync/index.js'); + const inlineConfig = flagsToAstroInlineConfig(flags); + const exitCode = await sync(inlineConfig); + if (exitCode !== 0) { + process.exit(exitCode); + } + const { check: checker, parseArgsAsCheckConfig } = checkPackage; const config = parseArgsAsCheckConfig(process.argv); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a173118c2b..2d790f820f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,6 +18,9 @@ importers: specifier: workspace:* version: link:benchmark devDependencies: + '@astrojs/check': + specifier: ^0.1.0 + version: 0.1.0(prettier-plugin-astro@0.11.0)(prettier@3.0.1)(typescript@5.1.6) '@changesets/changelog-github': specifier: ^0.4.8 version: 0.4.8 @@ -18707,25 +18710,21 @@ packages: file:packages/astro/test/fixtures/css-assets/packages/font-awesome: resolution: {directory: packages/astro/test/fixtures/css-assets/packages/font-awesome, type: directory} name: '@test/astro-font-awesome-package' - version: 0.0.1 dev: false file:packages/astro/test/fixtures/multiple-renderers/renderers/one: resolution: {directory: packages/astro/test/fixtures/multiple-renderers/renderers/one, type: directory} name: '@test/astro-renderer-one' - version: 1.0.0 dev: false file:packages/astro/test/fixtures/multiple-renderers/renderers/two: resolution: {directory: packages/astro/test/fixtures/multiple-renderers/renderers/two, type: directory} name: '@test/astro-renderer-two' - version: 1.0.0 dev: false file:packages/astro/test/fixtures/solid-component/deps/solid-jsx-component: resolution: {directory: packages/astro/test/fixtures/solid-component/deps/solid-jsx-component, type: directory} name: '@test/solid-jsx-component' - version: 0.0.0 dependencies: solid-js: 1.7.6 dev: false