From da7b41f5b8eb6d3a3e3a765be447e03ef5691979 Mon Sep 17 00:00:00 2001 From: Drew Powers <1369770+drwpow@users.noreply.github.com> Date: Mon, 6 Dec 2021 16:01:32 -0700 Subject: [PATCH] Fix build missing styles (affecting docs) (#2112) * Revert "remove odd docs regression caused by Astro.fetchContent()" This reverts commit df4707797821060228454acf7f9fb316dd953e8a. * Fix build missing styles --- .changeset/popular-roses-ring.md | 5 ++ docs/src/config.ts | 1 + .../pages/es/guides/markdown-content.astro | 13 +++++ docs/src/pages/es/guides/pagination.astro | 13 +++++ docs/src/pages/es/guides/publish-to-npm.astro | 13 +++++ docs/src/pages/es/guides/styling.astro | 13 +++++ .../es/reference/renderer-reference.astro | 13 +++++ docs/src/pages/zh-TW/themes.astro | 52 +++++++++++++++++++ netlify.toml | 2 +- packages/astro/src/core/ssr/css.ts | 32 +++++++----- packages/astro/src/core/ssr/index.ts | 4 +- packages/astro/src/core/util.ts | 13 +++-- 12 files changed, 151 insertions(+), 23 deletions(-) create mode 100644 .changeset/popular-roses-ring.md create mode 100644 docs/src/pages/es/guides/markdown-content.astro create mode 100644 docs/src/pages/es/guides/pagination.astro create mode 100644 docs/src/pages/es/guides/publish-to-npm.astro create mode 100644 docs/src/pages/es/guides/styling.astro create mode 100644 docs/src/pages/es/reference/renderer-reference.astro create mode 100644 docs/src/pages/zh-TW/themes.astro diff --git a/.changeset/popular-roses-ring.md b/.changeset/popular-roses-ring.md new file mode 100644 index 000000000..b7401f61b --- /dev/null +++ b/.changeset/popular-roses-ring.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Bugfix: fix missing styles in build diff --git a/docs/src/config.ts b/docs/src/config.ts index 50132d16d..3cd88714a 100644 --- a/docs/src/config.ts +++ b/docs/src/config.ts @@ -135,6 +135,7 @@ export const SIDEBAR = { { text: '新手上路', link: 'zh-TW/getting-started' }, { text: '快速開始', link: 'zh-TW/quick-start' }, { text: '安裝', link: 'zh-TW/installation' }, + { text: '佈景主題', link: 'zh-TW/themes' }, ], bg: [ { text: 'Главни', header: true }, diff --git a/docs/src/pages/es/guides/markdown-content.astro b/docs/src/pages/es/guides/markdown-content.astro new file mode 100644 index 000000000..562511baf --- /dev/null +++ b/docs/src/pages/es/guides/markdown-content.astro @@ -0,0 +1,13 @@ +--- +import { Markdown } from 'astro/components'; +import MainLayout from '~/layouts/MainLayout.astro'; +const [content] = Astro.fetchContent('/src/pages/guides/markdown-content.md'); +--- + + + + > Esta página todavía no está disponible en Español. Se muestra la versión en inglés. + + {content.astro.html} + + diff --git a/docs/src/pages/es/guides/pagination.astro b/docs/src/pages/es/guides/pagination.astro new file mode 100644 index 000000000..65c0fe3c4 --- /dev/null +++ b/docs/src/pages/es/guides/pagination.astro @@ -0,0 +1,13 @@ +--- +import { Markdown } from 'astro/components'; +import MainLayout from '~/layouts/MainLayout.astro'; +const [content] = Astro.fetchContent('/src/pages/guides/pagination.md'); +--- + + + + > Esta página todavía no está disponible en Español. Se muestra la versión en inglés. + + {content.astro.html} + + diff --git a/docs/src/pages/es/guides/publish-to-npm.astro b/docs/src/pages/es/guides/publish-to-npm.astro new file mode 100644 index 000000000..a1ffac93c --- /dev/null +++ b/docs/src/pages/es/guides/publish-to-npm.astro @@ -0,0 +1,13 @@ +--- +import { Markdown } from 'astro/components'; +import MainLayout from '~/layouts/MainLayout.astro'; +const [content] = Astro.fetchContent('/src/pages/guides/publish-to-npm.md'); +--- + + + + > Esta página todavía no está disponible en Español. Se muestra la versión en inglés. + + {content.astro.html} + + diff --git a/docs/src/pages/es/guides/styling.astro b/docs/src/pages/es/guides/styling.astro new file mode 100644 index 000000000..d15e6298f --- /dev/null +++ b/docs/src/pages/es/guides/styling.astro @@ -0,0 +1,13 @@ +--- +import { Markdown } from 'astro/components'; +import MainLayout from '~/layouts/MainLayout.astro'; +const [content] = Astro.fetchContent('/src/pages/guides/styling.md'); +--- + + + + > Esta página todavía no está disponible en Español. Se muestra la versión en inglés. + + {content.astro.html} + + diff --git a/docs/src/pages/es/reference/renderer-reference.astro b/docs/src/pages/es/reference/renderer-reference.astro new file mode 100644 index 000000000..f3c703a60 --- /dev/null +++ b/docs/src/pages/es/reference/renderer-reference.astro @@ -0,0 +1,13 @@ +--- +import { Markdown } from 'astro/components'; +import MainLayout from '~/layouts/MainLayout.astro'; +const [content] = Astro.fetchContent('/src/pages/reference/renderer-reference.md'); +--- + + + + > Esta página todavía no está disponible en Español. Se muestra la versión en inglés. + + {content.astro.html} + + diff --git a/docs/src/pages/zh-TW/themes.astro b/docs/src/pages/zh-TW/themes.astro new file mode 100644 index 000000000..3c2a6cfa8 --- /dev/null +++ b/docs/src/pages/zh-TW/themes.astro @@ -0,0 +1,52 @@ +--- +import Layout from '../../layouts/MainLayout.astro'; +import Card from '../../components/Card.astro'; +import {Markdown} from 'astro/components'; +import themes from '../../data/themes.json'; +import components from '../../data/components.json'; +--- + + + + ## 精選佈景主題 + +
+ {themes.featured.map((item)=>())} +
+ + ## 官方佈景主題 + + Astro 維護的文件網站、作品集⋯等官方佈景主題。 + +
+ {themes.official.map((item)=>())} +
+ + ## 社群佈景主題 + + 趕緊來看看社群開發的佈景主題! + +
+ {themes.community.map((item)=>())} +
+ + ## 精選套件 + + 我們的套件生態持續成長!所有精選社群套件都可以在 [npm](https://www.npmjs.com/search?q=keywords%3Aastro-component) 發掘。 + +
+ {components.community.map((item)=>())} +
+ + > 想要讓自己的作品成為精選嗎?[在 Discord 分享!](https://astro.build/chat) + 我們常在 `#showcase` 頻道取材,把深受喜愛的在這裡發布。 + +
diff --git a/netlify.toml b/netlify.toml index 402f958ec..fd6fa2029 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,2 +1,2 @@ [build] - ignore = "git diff --quiet $COMMIT_REF $CACHED_COMMIT_REF -- docs/ www/" + ignore = "git diff --quiet $COMMIT_REF $CACHED_COMMIT_REF -- packages/astro/src docs/ www/" diff --git a/packages/astro/src/core/ssr/css.ts b/packages/astro/src/core/ssr/css.ts index 0f2ffb00a..2a2fa24a7 100644 --- a/packages/astro/src/core/ssr/css.ts +++ b/packages/astro/src/core/ssr/css.ts @@ -1,34 +1,40 @@ import type vite from '../vite'; import path from 'path'; -import { viteifyURL } from '../util.js'; +import { viteID } from '../util.js'; // https://vitejs.dev/guide/features.html#css-pre-processors export const STYLE_EXTENSIONS = new Set(['.css', '.pcss', '.postcss', '.scss', '.sass', '.styl', '.stylus', '.less']); -/** find unloaded styles */ +/** + * getStylesForURL + * Given a filePath URL, crawl Vite’s module graph to find style files + */ export function getStylesForURL(filePath: URL, viteServer: vite.ViteDevServer): Set { const css = new Set(); - const rootID = viteifyURL(filePath); // recursively crawl module graph to get all style files imported by parent id - function crawlCSS(entryModule: string, scanned = new Set()) { - const moduleName = viteServer.moduleGraph.urlToModuleMap.get(entryModule); + function crawlCSS(id: string, scanned = new Set()) { + // note: use .idToModuleMap() for lookups (.urlToModuleMap() may produce different + // URLs for modules depending on conditions, making resolution difficult) + const moduleName = viteServer.moduleGraph.idToModuleMap.get(id); if (!moduleName || !moduleName.id) return; - // mark the entrypoint as scanned to avoid an infinite loop - scanned.add(moduleName.url); + + scanned.add(moduleName.id); + + // scan importedModules for (const importedModule of moduleName.importedModules) { - if (!importedModule.url || scanned.has(importedModule.url)) continue; + if (!importedModule.id || scanned.has(importedModule.id)) continue; const ext = path.extname(importedModule.url.toLowerCase()); if (STYLE_EXTENSIONS.has(ext)) { - css.add(importedModule.url); // if style file, add to list - } else { - crawlCSS(importedModule.url, scanned); // otherwise, crawl file to see if it imports any CSS + css.add(importedModule.url); // note: return `url`s for HTML (not .id, which will break Windows) } - scanned.add(importedModule.url); + crawlCSS(importedModule.id, scanned); + scanned.add(importedModule.id); } } - crawlCSS(rootID); + + crawlCSS(viteID(filePath)); return css; } diff --git a/packages/astro/src/core/ssr/index.ts b/packages/astro/src/core/ssr/index.ts index 499039a56..4b979a182 100644 --- a/packages/astro/src/core/ssr/index.ts +++ b/packages/astro/src/core/ssr/index.ts @@ -23,7 +23,7 @@ import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; import { renderPage, renderSlot } from '../../runtime/server/index.js'; -import { canonicalURL as getCanonicalURL, codeFrame, resolveDependency, viteifyURL } from '../util.js'; +import { canonicalURL as getCanonicalURL, codeFrame, resolveDependency } from '../util.js'; import { getStylesForURL } from './css.js'; import { injectTags } from './html.js'; import { generatePaginateFunction } from './paginate.js'; @@ -133,7 +133,7 @@ export async function preload({ astroConfig, filePath, viteServer }: SSROptions) // Important: This needs to happen first, in case a renderer provides polyfills. const renderers = await resolveRenderers(viteServer, astroConfig); // Load the module from the Vite SSR Runtime. - const mod = (await viteServer.ssrLoadModule(viteifyURL(filePath))) as ComponentInstance; + const mod = (await viteServer.ssrLoadModule(fileURLToPath(filePath))) as ComponentInstance; return [renderers, mod]; } diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index df93938bc..51ba0db8a 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -74,12 +74,11 @@ export function resolveDependency(dep: string, astroConfig: AstroConfig) { } /** - * Vite-ify URL - * Given a file URL, return an ID that matches Vite’s module graph. Needed for resolution and stack trace fixing. - * Must match the following format: - * Linux/Mac: /@fs/Users/astro/code/my-project/src/pages/index.astro - * Windows: /@fs/C:/Users/astro/code/my-project/src/pages/index.astro + * Convert file URL to ID for viteServer.moduleGraph.idToModuleMap.get(:viteID) + * Format: + * Linux/Mac: /Users/astro/code/my-project/src/pages/index.astro + * Windows: C:/Users/astro/code/my-project/src/pages/index.astro */ -export function viteifyURL(filePath: URL): string { - return `/@fs${slash(fileURLToPath(filePath)).replace(/^\/?/, '/')}`; +export function viteID(filePath: URL): string { + return slash(fileURLToPath(filePath)); }