From f157c451510c0c205c488ed40fb4b2d1bfd3aa3b Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 27 Dec 2023 22:13:12 +0800 Subject: [PATCH] Remove unused mode param --- .../astro/src/content/vite-plugin-content-assets.ts | 6 +----- packages/astro/src/vite-plugin-astro-server/css.ts | 10 +--------- packages/astro/src/vite-plugin-astro-server/route.ts | 6 +----- packages/astro/test/units/dev/styles.test.js | 6 +----- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/packages/astro/src/content/vite-plugin-content-assets.ts b/packages/astro/src/content/vite-plugin-content-assets.ts index 5b79d5653ea7..6eeef1c40640 100644 --- a/packages/astro/src/content/vite-plugin-content-assets.ts +++ b/packages/astro/src/content/vite-plugin-content-assets.ts @@ -64,11 +64,7 @@ export function astroContentAssetPropagationPlugin({ if (!devModuleLoader.getModuleById(basePath)?.ssrModule) { await devModuleLoader.import(basePath); } - const { styles, urls } = await getStylesForURL( - pathToFileURL(basePath), - devModuleLoader, - 'development' - ); + const { styles, urls } = await getStylesForURL(pathToFileURL(basePath), devModuleLoader); const hoistedScripts = await getScriptsForURL( pathToFileURL(basePath), diff --git a/packages/astro/src/vite-plugin-astro-server/css.ts b/packages/astro/src/vite-plugin-astro-server/css.ts index 2034a7c9614b..0f0002907a88 100644 --- a/packages/astro/src/vite-plugin-astro-server/css.ts +++ b/packages/astro/src/vite-plugin-astro-server/css.ts @@ -1,4 +1,3 @@ -import type { RuntimeMode } from '../@types/astro.js'; import type { ModuleLoader } from '../core/module-loader/index.js'; import { viteID } from '../core/util.js'; import { isBuildableCSSRequest } from './util.js'; @@ -13,8 +12,7 @@ interface ImportedStyle { /** Given a filePath URL, crawl Vite’s module graph to find all style imports. */ export async function getStylesForURL( filePath: URL, - loader: ModuleLoader, - mode: RuntimeMode + loader: ModuleLoader ): Promise<{ urls: Set; styles: ImportedStyle[] }> { const importedCssUrls = new Set(); // Map of url to injected style object. Use a `url` key to deduplicate styles @@ -22,12 +20,6 @@ export async function getStylesForURL( for await (const importedModule of crawlGraph(loader, viteID(filePath), true)) { if (isBuildableCSSRequest(importedModule.url)) { - // In production, we can simply assign the styles as URLs - if (mode !== 'development') { - importedCssUrls.add(importedModule.url); - continue; - } - // In dev, we inline all styles if possible let css = ''; // If this is a plain CSS module, the default export should be a string diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index 3196b951a796..e37850acce24 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -436,11 +436,7 @@ async function getScriptsAndStyles({ pipeline, filePath }: GetScriptsAndStylesPa } // Pass framework CSS in as style tags to be appended to the page. - const { urls: styleUrls, styles: importedStyles } = await getStylesForURL( - filePath, - moduleLoader, - mode - ); + const { urls: styleUrls, styles: importedStyles } = await getStylesForURL(filePath, moduleLoader); let links = new Set(); [...styleUrls].forEach((href) => { links.add({ diff --git a/packages/astro/test/units/dev/styles.test.js b/packages/astro/test/units/dev/styles.test.js index 3e7d283ff69f..526b8fbef9f8 100644 --- a/packages/astro/test/units/dev/styles.test.js +++ b/packages/astro/test/units/dev/styles.test.js @@ -75,11 +75,7 @@ describe('Crawling graph for CSS', () => { it("importedModules is checked against the child's importers", async () => { // In dev mode, HMR modules tracked are added to importedModules. We use `importers` // to verify that they are true importers. - const res = await getStylesForURL( - new URL('./src/pages/index.astro', root), - loader, - 'development' - ); + const res = await getStylesForURL(new URL('./src/pages/index.astro', root), loader); expect(res.styles.length).to.equal(1); }); });