2026-08-06 09f01778d5a034e2af50ae05da8908f7b6a871c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 * Astro registry entry.
 *
 * Astro takes the generic tag strategy, with two Astro-specific values that
 * used to sit as inline `endsWith('.astro')` branches in live-inject.mjs and
 * live-wrap.mjs:
 *
 *   injectScriptAttrs  Astro processes <script> tags by default and rewrites
 *                      src to its own bundled URL; is:inline opts out.
 *   styleMode          Astro scopes component styles, which strips preview CSS
 *                      off the generated variant wrappers, so preview rules are
 *                      authored global and prefixed instead of @scope'd.
 */
 
import { findConfigFile, hasAnyDependency, literalConfigFiles } from './detect-utils.mjs';
 
const ASTRO_CONFIG_RE = /^astro\.config\.(?:js|mjs|cjs|ts|mts|cts)$/;
 
export function detectAstroProject(cwd = process.cwd(), config = null) {
  const configFile = findConfigFile(cwd, ASTRO_CONFIG_RE);
  if (configFile) return { configFile, via: 'config' };
  if (hasAnyDependency(cwd, ['astro'])) return { configFile: null, via: 'package' };
  // A tree of .astro entry templates with no astro.config still belongs to
  // Astro; the configured injection target names it.
  const entry = literalConfigFiles(cwd, config).find((rel) => rel.endsWith('.astro'));
  if (entry) return { configFile: null, via: 'config-files', entry };
  return null;
}
 
export const astro = {
  name: 'astro',
 
  detect(cwd, config) {
    return detectAstroProject(cwd, config);
  },
 
  inject: { kind: 'tag' },
 
  source: {
    extensions: ['.astro'],
    preview: 'source',
    styleMode: 'astro-global-prefixed',
    styleTag: '<style is:inline data-impeccable-css="SESSION_ID">',
    commentSyntax: 'html',
    injectScriptAttrs: 'is:inline ',
  },
};