Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(website): Upgrade dependencies and use StarlightPage component #1854

Merged
merged 9 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,561 changes: 1,202 additions & 1,359 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

45 changes: 5 additions & 40 deletions website/astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
import { netlifyStatic } from "@astrojs/netlify";
import netlify from "@astrojs/netlify";
import react from "@astrojs/react";
import starlight from "@astrojs/starlight";
import { defineConfig } from "astro/config";
import { h } from "hastscript";
import { escape as htmlEscape } from "html-escaper";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import { rehypeAutolink } from "./plugins/rehype-autolink";
import rehypeSlug from "rehype-slug";
import remarkToc from "remark-toc";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we weren't using "remark-toc" anywhere, so I've removed it. Also, did the same for @astrojs/vercel, which isn't being used anymore.

const anchorLinkIcon = h(
"span",
{ ariaHidden: "true", class: "anchor-icon" },
h(
"svg",
{ width: 16, height: 16, viewBox: "0 0 24 24" },
h("path", {
fill: "currentcolor",
d: "m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z",
}),
),
);

const anchorLinkSRLabel = (text: string) =>
h(
"span",
{ "is:raw": true, class: "sr-only" },
`Section titled ${htmlEscape(text)}`,
);

const autolinkConfig = {
properties: { class: "anchor-link" },
behavior: "after",
group: ({ tagName }) =>
h("div", { tabIndex: -1, class: `heading-wrapper level-${tagName}` }),
content: ({ heading }) => [anchorLinkIcon, anchorLinkSRLabel("test")],
};

const site = "https://biomejs.dev";
// https://astro.build/config
Expand All @@ -44,10 +13,6 @@ export default defineConfig({

compressHTML: true,

image: {
domains: ["avatars.githubusercontent.com"],
},

integrations: [
react(),
starlight({
Expand Down Expand Up @@ -397,11 +362,10 @@ export default defineConfig({

markdown: {
syntaxHighlight: "prism",
remarkPlugins: [remarkToc],
rehypePlugins: [rehypeSlug, [rehypeAutolinkHeadings, autolinkConfig]],
rehypePlugins: [rehypeSlug, ...rehypeAutolink()],
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the unified project had breaking changes, we now have some weird behavior clashing issue when trying to apply the remarkAutolink plugin, had to move it to an external file to make it work properly.


adapter: netlifyStatic(),
adapter: netlify(),

vite: {
resolve: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason Vite is complaining about some imported code by Astro's DevToolbar. Supposedly vite.server.fs.allow the path used should fix it, but didn't work for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to disable their remote image service, because they don't support multiple remote image domains from the config file. Their alternative is to use another configuration file

Copy link
Contributor Author

@yanthomasdev yanthomasdev Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There we go, the vite.server.fs.allow issue should be fixed, Vite now has a utility to allow workspace packages to be served, which fixes the issue with serving files from dependencies.

Expand All @@ -417,6 +381,7 @@ export default defineConfig({

server: {
fs: {
strict: false,
// https://vitejs.dev/config/server-options.html#server-fs-allow
allow: [process.cwd(), "../packages/@biomejs/wasm-web"],
},
Expand Down
33 changes: 16 additions & 17 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
"textlint:fix": "textlint --fix './src/content/docs/ja/**/*.{md,mdx}'"
},
"devDependencies": {
"@astrojs/netlify": "^3.0.4",
"@astrojs/prism": "^2.1.2",
"@astrojs/react": "^2.3.2",
"@astrojs/rss": "^2.4.4",
"@astrojs/starlight": "^0.13.0",
"@astrojs/vercel": "^5.0.1",
"@astrojs/netlify": "^5.1.2",
"@astrojs/prism": "^3.0.0",
"@astrojs/react": "^3.0.10",
"@astrojs/rss": "^4.0.5",
"@astrojs/starlight": "^0.19.0",
"@biomejs/wasm-web": "link:../packages/@biomejs/wasm-web",
"@codemirror/lang-javascript": "6.1.8",
"@codemirror/lang-json": "6.0.1",
Expand All @@ -34,25 +33,25 @@
"@types/node": "^18.18.0",
"@types/react": "^18.2.23",
"@types/react-dom": "^18.2.8",
"@uiw/react-codemirror": "4.20.2",
"@uiw/react-codemirror": "4.21.21",
Copy link
Member

@Sec-ant Sec-ant Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The playground not working anymore is caused by this bump.

This version of @uiw/react-codemirror indirectly requires the version of @codemirror/state to be in range ^0.6.4 because of its dependencies: @codemirror/view and @codemirror/commands.

However @codemirror/[email protected] is explicitly pinned in the devDependencies, so two versions of @codemirror/state are installed and hence the error occurs which you can find in the console, and it breaks the playground.

A simple fix is to bump the @codemirror/state in devDepedencies to 0.6.4.

And IMHO a future-proof fix is to try not pinning these low-level dependencies (including other codemirror tools) but use semver ranges instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks @Sec-ant - hadn't noticed the dependencies were pinned, I've moved them to ranges instead and seem to be working fine locally!

"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"codemirror-lang-rome-ast": "0.0.6",
"fast-diff": "^1.3.0",
"hast-util-to-html": "^8.0.4",
"hastscript": "^8.0.0",
"hast-util-to-html": "^9.0.0",
"hast-util-to-string": "^3.0.0",
"hastscript": "^9.0.0",
"html-escaper": "^3.0.3",
"lang-rome-formatter-ir": "0.0.2",
"mdast-util-to-hast": "^12.3.0",
"mdast-util-to-hast": "^13.1.0",
"mermaid": "^9.4.3",
"postcss": "^8.4.30",
"prettier": "^3.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rehype-autolink-headings": "^6.1.1",
"rehype-slug": "^5.1.0",
"rehype-toc": "^3.0.2",
"remark-toc": "^8.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the playground doesn't work anymore. Unless you want to spend time understanding the issue, maybe we can revert the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue doesn't seem related to updating the React dependencies, reverting them doesn't fix, nor does loading the Playground without <StarlightPage> - my best guess it might be Vite-related? But hard to know without context on how the Playground was built.

"rehype-autolink-headings": "^7.1.0",
"rehype-slug": "^6.0.0",
"remark-toc": "^9.0.0",
"rollup": "^3.29.4",
"sass": "^1.68.0",
"sharp": "^0.32.6",
Expand All @@ -67,7 +66,7 @@
"pnpm": "^8.0.0"
},
"dependencies": {
"astro": "^3.6.0",
"astro": "^4.4.0",
"astro-og-canvas": "^0.4.2",
"canvaskit-wasm": "^0.39.1"
}
Expand Down
40 changes: 40 additions & 0 deletions website/plugins/rehype-autolink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { h } from "hastscript";
import { escape as htmlEscape } from "html-escaper";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import { toString } from "hast-util-to-string";
import { RehypePlugins } from "astro";

const anchorLinkIcon = h(
"span",
{ ariaHidden: "true", class: "anchor-icon" },
h(
"svg",
{ width: 16, height: 16, viewBox: "0 0 24 24" },
h("path", {
fill: "currentcolor",
d: "m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z",
}),
),
);

const anchorLinkSRLabel = (text: string) =>
h(
"span",
{ "is:raw": true, class: "sr-only" },
`Section titled ${htmlEscape(text)}`,
);

const autolinkConfig = {
properties: { class: "anchor-link" },
behavior: "after",
group: ({ tagName }) =>
h("div", {
tabIndex: -1,
class: `heading-wrapper level-${tagName}`,
}),
content: (heading) => [anchorLinkIcon, anchorLinkSRLabel(toString(heading))],
};

export const rehypeAutolink = (): RehypePlugins => [
[rehypeAutolinkHeadings, autolinkConfig],
];
7 changes: 4 additions & 3 deletions website/src/components/InlineSVG.astro
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
export interface Props {
src: string;
src: string;
}

const { src } = Astro.props as Props;

const files = await import.meta.glob<string>("/src/assets/svg/**/*.svg", {
as: "raw",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as: "raw" was deprecated in Vite, so I've replaced it for the recommended query: "?raw"

query: "?raw",
import: "default",
});

const path = `/src/assets/svg/${src}.svg`;
const getHTML = files[path];
if (getHTML === undefined) {
throw new Error(`${src} is not valid`);
throw new Error(`${src} is not valid`);
}
const innerHTML = await getHTML();
---
Expand Down
129 changes: 0 additions & 129 deletions website/src/layouts/StarlightSplashLayout.astro

This file was deleted.

Loading
Loading