From 7a710fb5491e7f20b9014ec4ce9fb66ab3308dcf Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Thu, 17 Mar 2022 20:47:44 -0700 Subject: [PATCH] wip --- .../integrations-playground/astro.config.mjs | 9 +- .../src/components/Button.jsx | 6 +- packages/astro/package.json | 8 +- packages/astro/src/core/build/static-build.ts | 3 - packages/astro/src/core/config.ts | 86 ++++---- packages/astro/src/core/render/dev/index.ts | 2 +- packages/astro/src/core/util.ts | 2 +- packages/astro/src/integrations/index.ts | 2 +- packages/astro/src/runtime/server/index.ts | 18 +- .../astro/src/vite-plugin-astro/compile.ts | 8 +- packages/astro/src/vite-plugin-astro/index.ts | 9 +- packages/astro/src/vite-plugin-jsx/index.ts | 2 +- .../astro/src/vite-plugin-scripts/index.ts | 2 +- packages/astro/test/0-css.test.js | 14 +- packages/astro/test/astro-assets.test.js | 5 - packages/astro/test/astro-children.test.js | 5 +- packages/astro/test/astro-dynamic.test.js | 23 +- packages/astro/test/astro-expr.test.js | 1 - packages/astro/test/astro-fallback.test.js | 1 - packages/astro/test/astro-jsx.test.js | 43 ---- .../astro/test/astro-markdown-plugins.test.js | 1 - packages/astro/test/astro-markdown.test.js | 4 - .../astro/test/astro-partial-html.test.js | 2 +- packages/astro/test/config-validate.test.js | 3 +- packages/astro/test/config.test.js | 21 +- packages/astro/test/custom-elements.test.js | 4 +- packages/astro/test/dev-routing.test.js | 28 ++- packages/astro/test/errors.test.js | 199 +----------------- .../test/fixtures/0-css/astro.config.mjs | 15 ++ .../astro/test/fixtures/0-css/package.json | 3 + .../fixtures/astro-assets/astro.config.mjs | 11 + .../fixtures/astro-attrs/astro.config.mjs | 7 + .../test/fixtures/astro-attrs/package.json | 1 + .../fixtures/astro-basic/astro.config.mjs | 7 + .../test/fixtures/astro-basic/package.json | 1 + .../fixtures/astro-children/astro.config.mjs | 9 + .../test/fixtures/astro-children/package.json | 3 + .../astro-client-only/astro.config.mjs | 7 + .../fixtures/astro-client-only/package.json | 1 + .../fixtures/astro-dynamic/astro.config.mjs | 8 + .../test/fixtures/astro-dynamic/package.json | 2 + .../test/fixtures/astro-envs/astro.config.mjs | 7 + .../test/fixtures/astro-envs/package.json | 1 + .../test/fixtures/astro-expr/astro.config.mjs | 7 + .../test/fixtures/astro-expr/package.json | 1 + .../fixtures/astro-fallback/astro.config.mjs | 7 + .../test/fixtures/astro-fallback/package.json | 1 + .../astro-markdown-plugins/astro.config.mjs | 7 + .../astro-markdown-plugins/package.json | 1 + .../fixtures/astro-markdown/astro.config.mjs | 10 + .../test/fixtures/astro-markdown/package.json | 1 + .../astro-partial-html/astro.config.mjs | 7 + .../fixtures/astro-partial-html/package.json | 1 + .../fixtures/config-host/astro.config.mjs | 6 - .../fixtures/config-hostname/astro.config.mjs | 6 - .../fixtures/config-hostname/package.json | 8 - .../fixtures/config-port/astro.config.mjs | 5 - .../test/fixtures/config-port/package.json | 8 - .../test/fixtures/errors/astro.config.mjs | 11 + .../astro/test/fixtures/errors/package.json | 8 +- .../test/fixtures/fetch/astro.config.mjs | 10 + .../astro/test/fixtures/fetch/package.json | 3 + .../fixtures/legacy-build/astro.config.mjs | 11 +- .../test/fixtures/legacy-build/package.json | 2 +- .../fixtures/lit-element/astro.config.mjs | 7 + .../test/fixtures/lit-element/package.json | 4 +- .../test/fixtures/markdown/astro.config.mjs | 10 + .../astro/test/fixtures/markdown/package.json | 1 + .../test/fixtures/postcss/astro.config.mjs | 9 + .../astro/test/fixtures/postcss/package.json | 4 +- .../preact-component/astro.config.mjs | 7 + .../fixtures/preact-component/package.json | 1 + .../fixtures/react-component/astro.config.mjs | 8 + .../fixtures/react-component/package.json | 2 + .../fixtures/slots-preact/astro.config.mjs | 7 + .../test/fixtures/slots-preact/package.json | 1 + .../fixtures/slots-react/astro.config.mjs | 7 + .../test/fixtures/slots-react/package.json | 1 + .../fixtures/slots-solid/astro.config.mjs | 7 + .../test/fixtures/slots-solid/package.json | 4 +- .../fixtures/slots-svelte/astro.config.mjs | 7 + .../test/fixtures/slots-svelte/package.json | 1 + .../test/fixtures/slots-vue/astro.config.mjs | 7 + .../test/fixtures/slots-vue/package.json | 1 + .../fixtures/solid-component/astro.config.mjs | 7 + .../fixtures/solid-component/package.json | 4 +- .../fixtures/static build/astro.config.mjs | 13 ++ .../test/fixtures/static build/package.json | 1 + .../static-build-frameworks/astro.config.mjs | 8 + .../static-build-frameworks/package.json | 2 + .../astro.config.mjs | 9 + .../svelte-component/astro.config.mjs | 7 + .../fixtures/svelte-component/package.json | 1 + .../fixtures/tailwindcss/astro.config.mjs | 12 ++ .../test/fixtures/tailwindcss/package.json | 1 + .../fixtures/vue-component/astro.config.mjs | 7 + .../test/fixtures/vue-component/package.json | 1 + .../with-endpoint-routes/astro.config.mjs | 6 - .../astro.config copy.mjs | 8 + .../astro.config.mjs | 6 - .../with-subpath-trailing-slash/package.json | 8 - .../src/pages/[id].astro | 6 - .../src/pages/another.astro | 1 - .../src/pages/index.astro | 1 - .../fixtures/without-subpath/astro.config.mjs | 6 - .../fixtures/without-subpath/package.json | 8 - .../without-subpath/src/pages/[id].astro | 6 - .../without-subpath/src/pages/another.astro | 1 - .../without-subpath/src/pages/index.astro | 1 - packages/astro/test/lit-element.test.js | 1 - packages/astro/test/markdown.test.js | 4 - packages/astro/test/postcss.test.js | 9 - packages/astro/test/preact-component.test.js | 4 - packages/astro/test/preview-routing.test.js | 4 +- packages/astro/test/react-component.test.js | 4 - packages/astro/test/slots-preact.test.js | 2 +- packages/astro/test/slots-react.test.js | 2 +- packages/astro/test/slots-solid.test.js | 2 +- packages/astro/test/slots-svelte.test.js | 2 +- packages/astro/test/slots-vue.test.js | 2 +- packages/astro/test/solid-component.test.js | 4 - .../test/static-build-code-component.test.js | 2 - .../test/static-build-frameworks.test.js | 5 - .../test/static-build-page-url-format.test.js | 5 - packages/astro/test/static-build.test.js | 9 - packages/astro/test/svelte-component.test.js | 4 - packages/astro/test/tailwindcss.test.js | 8 - packages/astro/test/test-utils.js | 13 +- packages/astro/test/vue-component.test.js | 4 - packages/create-astro/src/config.ts | 38 ++-- packages/create-astro/src/frameworks.ts | 30 +-- packages/create-astro/src/index.ts | 34 ++- packages/create-astro/src/templates.ts | 11 +- packages/integrations/lit/client-shim.min.js | 78 ++++++- packages/integrations/lit/src/index.ts | 2 +- packages/integrations/turbolinks/client.js | 2 +- packages/integrations/turbolinks/src/index.ts | 2 +- pnpm-lock.yaml | 140 +++++++----- 138 files changed, 689 insertions(+), 680 deletions(-) delete mode 100644 packages/astro/test/astro-jsx.test.js create mode 100644 packages/astro/test/fixtures/0-css/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-assets/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-attrs/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-basic/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-children/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-client-only/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-dynamic/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-envs/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-expr/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-fallback/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-markdown-plugins/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-markdown/astro.config.mjs create mode 100644 packages/astro/test/fixtures/astro-partial-html/astro.config.mjs delete mode 100644 packages/astro/test/fixtures/config-host/astro.config.mjs delete mode 100644 packages/astro/test/fixtures/config-hostname/astro.config.mjs delete mode 100644 packages/astro/test/fixtures/config-hostname/package.json delete mode 100644 packages/astro/test/fixtures/config-port/astro.config.mjs delete mode 100644 packages/astro/test/fixtures/config-port/package.json create mode 100644 packages/astro/test/fixtures/errors/astro.config.mjs create mode 100644 packages/astro/test/fixtures/fetch/astro.config.mjs create mode 100644 packages/astro/test/fixtures/lit-element/astro.config.mjs create mode 100644 packages/astro/test/fixtures/markdown/astro.config.mjs create mode 100644 packages/astro/test/fixtures/postcss/astro.config.mjs create mode 100644 packages/astro/test/fixtures/preact-component/astro.config.mjs create mode 100644 packages/astro/test/fixtures/react-component/astro.config.mjs create mode 100644 packages/astro/test/fixtures/slots-preact/astro.config.mjs create mode 100644 packages/astro/test/fixtures/slots-react/astro.config.mjs create mode 100644 packages/astro/test/fixtures/slots-solid/astro.config.mjs create mode 100644 packages/astro/test/fixtures/slots-svelte/astro.config.mjs create mode 100644 packages/astro/test/fixtures/slots-vue/astro.config.mjs create mode 100644 packages/astro/test/fixtures/solid-component/astro.config.mjs create mode 100644 packages/astro/test/fixtures/static build/astro.config.mjs create mode 100644 packages/astro/test/fixtures/static-build-frameworks/astro.config.mjs create mode 100644 packages/astro/test/fixtures/static-build-page-url-format/astro.config.mjs create mode 100644 packages/astro/test/fixtures/svelte-component/astro.config.mjs create mode 100644 packages/astro/test/fixtures/tailwindcss/astro.config.mjs create mode 100644 packages/astro/test/fixtures/vue-component/astro.config.mjs delete mode 100644 packages/astro/test/fixtures/with-endpoint-routes/astro.config.mjs create mode 100644 packages/astro/test/fixtures/with-subpath-no-trailing-slash/astro.config copy.mjs delete mode 100644 packages/astro/test/fixtures/with-subpath-trailing-slash/astro.config.mjs delete mode 100644 packages/astro/test/fixtures/with-subpath-trailing-slash/package.json delete mode 100644 packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/[id].astro delete mode 100644 packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/another.astro delete mode 100644 packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/index.astro delete mode 100644 packages/astro/test/fixtures/without-subpath/astro.config.mjs delete mode 100644 packages/astro/test/fixtures/without-subpath/package.json delete mode 100644 packages/astro/test/fixtures/without-subpath/src/pages/[id].astro delete mode 100644 packages/astro/test/fixtures/without-subpath/src/pages/another.astro delete mode 100644 packages/astro/test/fixtures/without-subpath/src/pages/index.astro diff --git a/examples/integrations-playground/astro.config.mjs b/examples/integrations-playground/astro.config.mjs index c78799d28423e..a1f21fe0b677f 100644 --- a/examples/integrations-playground/astro.config.mjs +++ b/examples/integrations-playground/astro.config.mjs @@ -8,12 +8,5 @@ import sitemap from '@astrojs/sitemap'; import partytown from '@astrojs/partytown'; export default defineConfig({ - integrations: [ - lit(), - react(), - tailwind(), - turbolinks(), - partytown(), - sitemap(), - ], + integrations: [lit(), react(), tailwind(), turbolinks(), partytown(), sitemap()], }); diff --git a/examples/integrations-playground/src/components/Button.jsx b/examples/integrations-playground/src/components/Button.jsx index 6cf5ddf9a2061..2758df130d96e 100644 --- a/examples/integrations-playground/src/components/Button.jsx +++ b/examples/integrations-playground/src/components/Button.jsx @@ -1,3 +1,3 @@ -export default function Link({to, text}) { - return ({text}); -} \ No newline at end of file +export default function Link({ to, text }) { + return {text}; +} diff --git a/packages/astro/package.json b/packages/astro/package.json index 7deb59b63ad50..e3e1e739136c8 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -57,7 +57,7 @@ "dev": "astro-scripts dev \"src/**/*.ts\"", "postbuild": "astro-scripts copy \"src/**/*.astro\"", "benchmark": "node test/benchmark/dev.bench.js && node test/benchmark/build.bench.js", - "test": "mocha --parallel --timeout 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js", + "test": "mocha --exit --timeout 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js", "test:match": "mocha --timeout 20000 -g" }, "dependencies": { @@ -112,12 +112,6 @@ }, "devDependencies": { "@astrojs/parser": "^0.22.2", - "@astrojs/preact": "^0.0.1", - "@astrojs/react": "0.0.1", - "@astrojs/svelte": "0.0.1", - "@astrojs/solid-js": "0.0.1", - "@astrojs/tailwind": "0.0.1", - "@astrojs/vue": "0.0.1", "@babel/types": "^7.17.0", "@types/babel__core": "^7.1.18", "@types/babel__traverse": "^7.14.2", diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 20750c1eda450..9298ed6949398 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -115,7 +115,6 @@ export async function staticBuild(opts: StaticBuildOptions) { // Build internals needed by the CSS plugin const internals = createBuildInternals(); - for (const [component, pageData] of Object.entries(allPages)) { const astroModuleURL = new URL('./' + component, astroConfig.projectRoot); const astroModuleId = prependForwardSlash(component); @@ -179,7 +178,6 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp const { astroConfig, viteConfig } = opts; const ssr = astroConfig.buildOptions.experimentalSsr; const out = ssr ? getServerRoot(astroConfig) : getOutRoot(astroConfig); - // TODO: use vite.mergeConfig() here? return await vite.build({ logLevel: 'warn', @@ -245,7 +243,6 @@ async function clientBuild(opts: StaticBuildOptions, internals: BuildInternals, outDir: fileURLToPath(out), rollupOptions: { input: Array.from(input), - treeshake: true, output: { format: 'esm', entryFileNames: '[name].[hash].js', diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 9946b8f5a755a..0ad8c063d3ff9 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -284,55 +284,41 @@ export function formatConfigError(err: z.ZodError) { return `${colors.red('[config]')} Astro found issue(s) with your configuration:\n${errorList.join('\n')}`; } - -function mergeConfigRecursively( - defaults: Record, - overrides: Record, - rootPath: string - ) { - const merged: Record = { ...defaults } +function mergeConfigRecursively(defaults: Record, overrides: Record, rootPath: string) { + const merged: Record = { ...defaults }; for (const key in overrides) { - const value = overrides[key] - if (value == null) { - continue - } - - const existing = merged[key] - - if (existing == null) { - merged[key] = value - continue - } - - // fields that require special handling: - if (key === 'vite' && rootPath === '') { - merged[key] = mergeViteConfig(existing, value); - continue - } - - if (Array.isArray(existing) || Array.isArray(value)) { - merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])] - continue - } - if (isObject(existing) && isObject(value)) { - merged[key] = mergeConfigRecursively( - existing, - value, - rootPath ? `${rootPath}.${key}` : key - ) - continue - } - - merged[key] = value + const value = overrides[key]; + if (value == null) { + continue; + } + + const existing = merged[key]; + + if (existing == null) { + merged[key] = value; + continue; + } + + // fields that require special handling: + if (key === 'vite' && rootPath === '') { + merged[key] = mergeViteConfig(existing, value); + continue; + } + + if (Array.isArray(existing) || Array.isArray(value)) { + merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])]; + continue; + } + if (isObject(existing) && isObject(value)) { + merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key); + continue; + } + + merged[key] = value; } - return merged - } - - export function mergeConfig( - defaults: Record, - overrides: Record, - isRoot = true - ): Record { - return mergeConfigRecursively(defaults, overrides, isRoot ? '' : '.') - } - \ No newline at end of file + return merged; +} + +export function mergeConfig(defaults: Record, overrides: Record, isRoot = true): Record { + return mergeConfigRecursively(defaults, overrides, isRoot ? '' : '.'); +} diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index 3d263bb6dddea..09abb7d7bbb46 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -120,7 +120,7 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta origin, pathname, scripts, - // Resolves specifiers in the inline hydrated scripts, such as "@astrojs/renderer-preact/client.js" + // Resolves specifiers in the inline hydrated scripts, such as "@astrojs/preact/client.js" // TODO: Can we pass the hydration code more directly through Vite, so that we // don't need to copy-paste and maintain Vite's import resolution here? async resolve(s: string) { diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 207f159d45373..17f06854d24cc 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -32,7 +32,7 @@ export function isObject(value: unknown): value is Record { /** Wraps an object in an array. If an array is passed, ignore it. */ export function arraify(target: T | T[]): T[] { - return Array.isArray(target) ? target : [target] + return Array.isArray(target) ? target : [target]; } /** is a specifier an npm package? */ diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index a6784ee383a6e..745743f407d43 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -4,7 +4,7 @@ import { AstroConfig, AstroRenderer } from '../@types/astro.js'; import { mergeConfig } from '../core/config.js'; export async function runHookConfigSetup({ config: _config, command }: { config: AstroConfig; command: 'dev' | 'build' }): Promise { - let updatedConfig: AstroConfig = {..._config}; + let updatedConfig: AstroConfig = { ..._config }; for (const integration of _config.integrations) { if (integration.hooks['astro:config:setup']) { await integration.hooks['astro:config:setup']({ diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 2a5dd76a92cb6..f6c211592a283 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -111,14 +111,14 @@ function guessRenderers(componentUrl?: string): string[] { const extname = componentUrl?.split('.').pop(); switch (extname) { case 'svelte': - return ['@astrojs/renderer-svelte']; + return ['@astrojs/svelte']; case 'vue': - return ['@astrojs/renderer-vue']; + return ['@astrojs/vue']; case 'jsx': case 'tsx': - return ['@astrojs/renderer-react', '@astrojs/renderer-preact']; + return ['@astrojs/react', '@astrojs/preact']; default: - return ['@astrojs/renderer-react', '@astrojs/renderer-preact', '@astrojs/renderer-vue', '@astrojs/renderer-svelte']; + return ['@astrojs/react', '@astrojs/preact', '@astrojs/vue', '@astrojs/svelte']; } } @@ -166,8 +166,8 @@ export async function renderComponent(result: SSRResult, displayName: string, Co if (Array.isArray(renderers) && renderers.length === 0 && typeof Component !== 'string' && !componentIsHTMLElement(Component)) { const message = `Unable to render ${metadata.displayName}! -There are no \`renderers\` set in your \`astro.config.mjs\` file. -Did you mean to enable ${formatList(probableRendererNames.map((r) => '`' + r + '`'))}?`; +There are no \`integrations\` set in your \`astro.config.mjs\` file. +Did you mean to add ${formatList(probableRendererNames.map((r) => '`' + r + '`'))}?`; throw new Error(message); } @@ -190,7 +190,7 @@ Did you mean to enable ${formatList(probableRendererNames.map((r) => '`' + r + ' // Attempt: use explicitly passed renderer name if (metadata.hydrateArgs) { const rendererName = metadata.hydrateArgs; - renderer = renderers.filter(({ name }) => name === `@astrojs/renderer-${rendererName}` || name === rendererName)[0]; + renderer = renderers.filter(({ name }) => name === `@astrojs/${rendererName}` || name === rendererName)[0]; } // Attempt: user only has a single renderer, default to that if (!renderer && renderers.length === 1) { @@ -199,7 +199,7 @@ Did you mean to enable ${formatList(probableRendererNames.map((r) => '`' + r + ' // Attempt: can we guess the renderer from the export extension? if (!renderer) { const extname = metadata.componentUrl?.split('.').pop(); - renderer = renderers.filter(({ name }) => name === `@astrojs/renderer-${extname}` || name === extname)[0]; + renderer = renderers.filter(({ name }) => name === `@astrojs/${extname}` || name === extname)[0]; } } @@ -210,7 +210,7 @@ Did you mean to enable ${formatList(probableRendererNames.map((r) => '`' + r + ' throw new Error(`Unable to render ${metadata.displayName}! Using the \`client:only\` hydration strategy, Astro needs a hint to use the correct renderer. -Did you mean to pass <${metadata.displayName} client:only="${probableRendererNames.map((r) => r.replace('@astrojs/renderer-', '')).join('|')}" /> +Did you mean to pass <${metadata.displayName} client:only="${probableRendererNames.map((r) => r.replace('@astrojs/', '')).join('|')}" /> `); } else if (typeof Component !== 'string') { const matchingRenderers = renderers.filter((r) => probableRendererNames.includes(r.name)); diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts index ccc1f1dd6d1fc..48bada5f4865f 100644 --- a/packages/astro/src/vite-plugin-astro/compile.ts +++ b/packages/astro/src/vite-plugin-astro/compile.ts @@ -122,13 +122,7 @@ export function invalidateCompilation(config: AstroConfig, filename: string) { } } -export async function cachedCompilation( - config: AstroConfig, - filename: string, - source: string, - viteTransform: TransformHook, - opts: { ssr: boolean } -): Promise { +export async function cachedCompilation(config: AstroConfig, filename: string, source: string, viteTransform: TransformHook, opts: { ssr: boolean }): Promise { let cache: CompilationCache; if (!configCache.has(config)) { cache = new Map(); diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index a4f31acfcb52d..0f169caa117a7 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -85,15 +85,15 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu async load(id, opts) { const parsedId = parseAstroRequest(id); const query = parsedId.query; - if (!id.endsWith(".astro") && !query.astro) { - return null; + if (!id.endsWith('.astro') && !query.astro) { + return null; } const filename = normalizeFilename(parsedId.filename); const fileUrl = new URL(`file://${filename}`); - let source = await fs.promises.readFile(fileUrl, "utf-8"); + let source = await fs.promises.readFile(fileUrl, 'utf-8'); const isPage = filename.startsWith(config.pages.pathname); - if (isPage && config._ctx.scripts.some(s => s.stage === 'page')) { + if (isPage && config._ctx.scripts.some((s) => s.stage === 'page')) { source += `\n