From 65c354969e6fe0ef6d622e8f4c545e2f717ce8c6 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 9 Aug 2023 17:06:29 +0800 Subject: [PATCH] Fix examples check hang (#7998) --- .changeset/gentle-deers-yawn.md | 5 +++++ package.json | 1 + packages/astro/src/cli/check/index.ts | 12 +++++++++++- pnpm-lock.yaml | 7 +++---- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .changeset/gentle-deers-yawn.md diff --git a/.changeset/gentle-deers-yawn.md b/.changeset/gentle-deers-yawn.md new file mode 100644 index 000000000000..30e577c69b57 --- /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 d7343da53fa5..0c75669ae0be 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 5ad031714a50..428027154a89 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 a173118c2bba..2d790f820fa1 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