Skip to content

Commit f2d27ce

Browse files
authored
Editor configs (oxc-project#31)
* cfg: use ESM * cfg: format * cfg: .editorconfig * cfg: tsconfig
1 parent d325ce1 commit f2d27ce

16 files changed

+689
-525
lines changed

Diff for: .editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[*]
2+
charset = utf-8
3+
indent_style = space
4+
indent_size = 2
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.md]
10+
trim_trailing_whitespace = false

Diff for: .github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ on:
44
pull_request:
55
types: [opened, synchronize]
66
paths-ignore:
7-
- 'README.md'
7+
- "README.md"
88
push:
99
branches:
1010
- main
1111
paths-ignore:
12-
- 'README.md'
12+
- "README.md"
1313

1414
jobs:
1515
ci:
@@ -26,8 +26,8 @@ jobs:
2626

2727
- uses: actions/setup-node@v3
2828
with:
29-
node-version: '18'
30-
cache: 'pnpm'
29+
node-version: "18"
30+
cache: "pnpm"
3131

3232
- run: pnpm install --frozen-lockfile
3333

Diff for: .prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import("prettier").Options} */
2+
export default {
3+
semi: true,
4+
singleQuote: false,
5+
trailingComma: "all",
6+
printWidth: 120,
7+
};
File renamed without changes.
File renamed without changes.

Diff for: .vitepress/config.mts renamed to .vitepress/config.ts

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { dirname } from "node:path";
22
import { fileURLToPath } from "node:url";
33
import { defineConfig } from "vitepress";
4-
import { EN_LOCALE_CONFIG } from "./config.en.mjs";
5-
import { JA_LOCALE_CONFIG } from "./config.ja.mjs";
4+
import { EN_LOCALE_CONFIG } from "./config.en.js";
5+
import { JA_LOCALE_CONFIG } from "./config.ja.js";
66

77
export default defineConfig({
88
srcDir: "src",
@@ -11,8 +11,7 @@ export default defineConfig({
1111
base: "/",
1212
title: "The JavaScript Oxidation Compiler",
1313
titleTemplate: ":title | The JavaScript Oxidation Compiler",
14-
description:
15-
"A collection of high-performance JavaScript tools written in Rust",
14+
description: "A collection of high-performance JavaScript tools written in Rust",
1615
head: [
1716
[
1817
"link",
@@ -40,8 +39,7 @@ export default defineConfig({
4039
"meta",
4140
{
4241
property: "og:description",
43-
content:
44-
"A collection of high-performance JavaScript tools written in Rust",
42+
content: "A collection of high-performance JavaScript tools written in Rust",
4543
},
4644
],
4745
["meta", { property: "og:site_name", content: "OXC" }],
@@ -50,8 +48,7 @@ export default defineConfig({
5048
"meta",
5149
{
5250
property: "og:image",
53-
content:
54-
"https://github.com/oxc-project/oxc-assets/blob/main/preview-white.png?raw=true",
51+
content: "https://github.com/oxc-project/oxc-assets/blob/main/preview-white.png?raw=true",
5552
},
5653
],
5754
// Twitter (X)
@@ -67,17 +64,15 @@ export default defineConfig({
6764
"meta",
6865
{
6966
name: "twitter:description",
70-
content:
71-
"A collection of high-performance JavaScript tools written in Rust",
67+
content: "A collection of high-performance JavaScript tools written in Rust",
7268
},
7369
],
7470
["meta", { name: "twitter:card", content: "summary_large_image" }],
7571
[
7672
"meta",
7773
{
7874
name: "twitter:image",
79-
content:
80-
"https://github.com/oxc-project/oxc-assets/blob/main/preview-white.png?raw=true",
75+
content: "https://github.com/oxc-project/oxc-assets/blob/main/preview-white.png?raw=true",
8176
},
8277
],
8378
[
@@ -113,12 +108,8 @@ export default defineConfig({
113108
vite: {
114109
resolve: {
115110
alias: {
116-
"@components": `${dirname(
117-
fileURLToPath(import.meta.url),
118-
)}/theme/components`,
119-
"@constants": `${dirname(
120-
fileURLToPath(import.meta.url),
121-
)}/theme/constants`,
111+
"@components": `${dirname(fileURLToPath(import.meta.url))}/theme/components`,
112+
"@constants": `${dirname(fileURLToPath(import.meta.url))}/theme/constants`,
122113
},
123114
},
124115
},

Diff for: .vitepress/theme/components/AppBadgeList.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<script setup lang="ts">
2-
import { computed } from 'vue'
3-
import { useData } from 'vitepress'
2+
import { computed } from "vue";
3+
import { useData } from "vitepress";
44
55
interface Badge {
6-
src: string
7-
alt: string
6+
src: string;
7+
alt: string;
88
}
99
10-
const vitePressData = useData()
10+
const vitePressData = useData();
1111
12-
const badges = computed<Badge[]>(() => vitePressData.frontmatter.value.badges)
12+
const badges = computed<Badge[]>(() => vitePressData.frontmatter.value.badges);
1313
</script>
1414

1515
<template>
1616
<ul class="AppBadgeList">
1717
<li v-for="badge in badges" :key="badge.src" class="badge">
18-
<img :src="badge.src" :alt="badge.alt">
18+
<img :src="badge.src" :alt="badge.alt" />
1919
</li>
2020
</ul>
2121
</template>

Diff for: .vitepress/theme/components/AppBlogPostHeader.vue

+30-28
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
<script setup lang="ts">
2-
import { computed, onMounted, ref, watchEffect } from 'vue'
3-
import { useData } from 'vitepress'
4-
import { TEAM_MEMBERS_MAP } from '../constants/team'
5-
import type { TeamMember } from '../constants/team'
2+
import { computed, onMounted, ref, watchEffect } from "vue";
3+
import { useData } from "vitepress";
4+
import { TEAM_MEMBERS_MAP } from "../constants/team";
5+
import type { TeamMember } from "../constants/team";
66
7-
const vitePressData = useData()
8-
const title = computed<string>(() => vitePressData.frontmatter.value.title)
9-
const lang = computed<string>(() => vitePressData.lang.value)
10-
const authors = computed(() => (vitePressData.frontmatter.value.authors as TeamMember['id'][]).flatMap((id) => {
11-
const member = TEAM_MEMBERS_MAP[id]
7+
const vitePressData = useData();
8+
const title = computed<string>(() => vitePressData.frontmatter.value.title);
9+
const lang = computed<string>(() => vitePressData.lang.value);
10+
const authors = computed(() =>
11+
(vitePressData.frontmatter.value.authors as TeamMember["id"][]).flatMap((id) => {
12+
const member = TEAM_MEMBERS_MAP[id];
1213
13-
if (member) {
14-
const { avatar, links, name, title } = member
15-
const { link = '' } = links?.find((link) => link.link.startsWith('https://github.com/')) ?? {}
14+
if (member) {
15+
const { avatar, links, name, title } = member;
16+
const { link = "" } = links?.find((link) => link.link.startsWith("https://github.com/")) ?? {};
1617
17-
return [{ avatar, link, name, title }]
18-
}
18+
return [{ avatar, link, name, title }];
19+
}
1920
20-
return []
21-
}))
21+
return [];
22+
}),
23+
);
2224
const date = computed(() => {
23-
const filePath = vitePressData.page.value.filePath
24-
const result = filePath.match(/blog\/(?<date>\d{4}-\d{2}-\d{2})-.*$/)
25-
const { date } = result?.groups ?? {}
25+
const filePath = vitePressData.page.value.filePath;
26+
const result = filePath.match(/blog\/(?<date>\d{4}-\d{2}-\d{2})-.*$/);
27+
const { date } = result?.groups ?? {};
2628
2729
if (date) {
28-
return new Date(date)
30+
return new Date(date);
2931
}
30-
return null
31-
})
32-
const isoDatetime = computed(() => date.value?.toISOString() ?? null)
33-
const datetime = ref('')
32+
return null;
33+
});
34+
const isoDatetime = computed(() => date.value?.toISOString() ?? null);
35+
const datetime = ref("");
3436
3537
// set time on mounted hook to avoid hydration mismatch due to
3638
// potential differences in timezones of the server and clients
3739
onMounted(() => {
3840
watchEffect(() => {
3941
if (date.value) {
40-
datetime.value = new Intl.DateTimeFormat(lang.value, { dateStyle: 'long' }).format(date.value)
42+
datetime.value = new Intl.DateTimeFormat(lang.value, { dateStyle: "long" }).format(date.value);
4143
}
42-
})
43-
})
44+
});
45+
});
4446
</script>
4547

4648
<template>
@@ -51,7 +53,7 @@ onMounted(() => {
5153
</p>
5254
<ul class="authors">
5355
<li v-for="{ avatar, link, name, title } in authors" :key="name" class="author">
54-
<img :src="avatar" :alt="name" class="author-avatar">
56+
<img :src="avatar" :alt="name" class="author-avatar" />
5557
<p class="author-text">
5658
<a v-if="link" :href="link" target="_blank" class="author-name">{{ name }}</a>
5759
<span v-else class="author-name">{{ name }}</span>

Diff for: .vitepress/theme/constants/team.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,10 @@ export const TEAM_MEMBERS: TeamMember[] = [
4848
},
4949
];
5050

51-
export const CORE_TEAM_MEMBERS = TEAM_MEMBERS.filter(
52-
({ type }) => type === "core",
53-
) as CoreTeamMember[];
54-
55-
export const COMMUNITY_TEAM_MEMBERS = TEAM_MEMBERS.filter(
56-
({ type }) => type === "community",
57-
) as CommunityTeamMember[];
58-
59-
export const TEAM_MEMBERS_MAP: Record<TeamMember["id"], TeamMember> =
60-
Object.fromEntries(
61-
TEAM_MEMBERS.map(({ id, ...rest }) => [id, { id, ...rest }]),
62-
);
51+
export const CORE_TEAM_MEMBERS = TEAM_MEMBERS.filter(({ type }) => type === "core") as CoreTeamMember[];
52+
53+
export const COMMUNITY_TEAM_MEMBERS = TEAM_MEMBERS.filter(({ type }) => type === "community") as CommunityTeamMember[];
54+
55+
export const TEAM_MEMBERS_MAP: Record<TeamMember["id"], TeamMember> = Object.fromEntries(
56+
TEAM_MEMBERS.map(({ id, ...rest }) => [id, { id, ...rest }]),
57+
);

Diff for: .vitepress/theme/index.mts

-12
This file was deleted.

Diff for: .vitepress/theme/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Theme } from "vitepress";
2+
import DefaultTheme from "vitepress/theme";
3+
4+
// @ts-ignore
5+
import AppBadgeList from "./components/AppBadgeList.vue";
6+
7+
// @ts-ignore
8+
import AppBlogPostHeader from "./components/AppBlogPostHeader.vue";
9+
10+
export default {
11+
extends: DefaultTheme,
12+
async enhanceApp({ app }) {
13+
app.component("AppBadgeList", AppBadgeList);
14+
app.component("AppBlogPostHeader", AppBlogPostHeader);
15+
},
16+
} satisfies Theme;

Diff for: cli/commands/create-blog-post.mts renamed to cli/commands/create-blog-post.ts

+5-29
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ export default defineCommand({
3131
},
3232
async run({ args }) {
3333
const { date, title, slug, author } = args;
34-
const isValidDate =
35-
/^(?:20\d{2})\-(?:0?[1-9]|1[012])\-(?:0?[1-9]|1\d|2\d|3[0-1])$/.test(
36-
date,
37-
);
34+
const isValidDate = /^(?:20\d{2})\-(?:0?[1-9]|1[012])\-(?:0?[1-9]|1\d|2\d|3[0-1])$/.test(date);
3835

3936
if (!isValidDate) {
4037
consola.error(`date is invalid: ${date}`);
@@ -77,21 +74,10 @@ authors:
7774
await fs.writeFile(filePath, content);
7875
}
7976

80-
async function writeSidebarFile({
81-
date,
82-
title,
83-
slug,
84-
}: {
85-
date: string;
86-
title: string;
87-
slug: string;
88-
}) {
77+
async function writeSidebarFile({ date, title, slug }: { date: string; title: string; slug: string }) {
8978
const filePath = `${process.cwd()}/.vitepress/sidebar.blog.json`;
9079
const currentSidebar = await fs.readFile(filePath, "utf8");
91-
const sidebar = JSON.parse(currentSidebar) as Record<
92-
"text" | "link",
93-
string
94-
>[];
80+
const sidebar = JSON.parse(currentSidebar) as Record<"text" | "link", string>[];
9581

9682
sidebar.unshift({
9783
text: `${date}<br>${title}`,
@@ -101,16 +87,6 @@ async function writeSidebarFile({
10187
await fs.writeFile(filePath, JSON.stringify(sidebar, null, 2));
10288
}
10389

104-
function getBlogPostUrl({
105-
date,
106-
title,
107-
slug,
108-
}: {
109-
date: string;
110-
title: string;
111-
slug: string;
112-
}) {
113-
return `/blog/${date}-${(slug || title)
114-
.toLocaleLowerCase()
115-
.replace(/\s+/g, "-")}`;
90+
function getBlogPostUrl({ date, title, slug }: { date: string; title: string; slug: string }) {
91+
return `/blog/${date}-${(slug || title).toLocaleLowerCase().replace(/\s+/g, "-")}`;
11692
}

Diff for: cli/index.mts renamed to cli/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const main = defineCommand({
99
description: "CLI for OXC Documentation",
1010
},
1111
subCommands: {
12-
"create-blog-post": () =>
13-
import("./commands/create-blog-post.mjs").then(_rDefault),
12+
"create-blog-post": () => import("./commands/create-blog-post.js").then(_rDefault),
1413
},
1514
});
1615

Diff for: package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "website",
33
"version": "0.0.0",
4+
"type": "module",
45
"private": true,
56
"scripts": {
67
"prepare": "husky install",
78
"dev": "vitepress dev",
89
"build": "vitepress build",
910
"preview": "vitepress preview",
10-
"create-blog-post": "tsx ./cli/index.mts create-blog-post",
11+
"fmt": "prettier",
1112
"typecheck": "tsc",
12-
"prettier": "prettier"
13+
"create-blog-post": "tsx ./cli/index.ts create-blog-post"
1314
},
1415
"dependencies": {
1516
"vitepress": "1.0.0-rc.25",
@@ -26,7 +27,7 @@
2627
"typescript": "~5.2.2"
2728
},
2829
"lint-staged": {
29-
"*.{js,jsx,tsx,ts,css,md,json,mts}": "prettier --write"
30+
"*.{js,jsx,tsx,ts,css,md,json,mts}": "pnpm run fmt --write"
3031
},
3132
"engines": {
3233
"node": ">=18.0"

0 commit comments

Comments
 (0)