Skip to content

A command field in astro:config:setup returns build value while running check command #10876

@moose96

Description

@moose96

Astro Info

Astro                    v4.7.0
Node                     v18.18.0
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             test

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Let's assume an Astro config like below:

export default defineConfig({
  integrations: [
    {
      name: 'test',
      hooks: {
        'astro:config:setup': ({ command }) => {
          console.log(command);
        },
      },
    },
  ],
});

While running astro check the console outputs build string. This can be confusing, especially when running the command in the default pipeline: astro check & astro build. In this case, the astro:config:setup hook is called twice with command === 'build', unexpectedly triggering certain code twice during the build.
Also, this behavior isn't documented: https://docs.astro.build/en/reference/integrations-reference/#command-option

It appears to be caused by a hardcoded 'build' value in the mentioned line:https://github.com/withastro/astro/blob/main/packages/astro/src/core/sync/index.ts#L62

const settings = await runHookConfigSetup({
	settings: _settings,
	logger: logger,
	command: 'build', // <- here
});

What's the expected result?

I suggest three possible solutions:

  1. command while running astro check has check value
  2. astro check command is integrated with astro build always, so astro:config:setup calls once only (I think it's the worst option)
  3. Describe this behavior in documentation

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-yfhwgr?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P2: nice to haveNot breaking anything but nice to have (priority)feat: integration apirelated to the public integration APIs (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions