Skip to content

Commit

Permalink
chore: improve dev server perf and formatting (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Feb 5, 2024
1 parent f0d518a commit f58e9fb
Show file tree
Hide file tree
Showing 459 changed files with 2,834 additions and 3,438 deletions.
36 changes: 18 additions & 18 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ module.exports = {
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:svelte/recommended",
"prettier"
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
parserOptions: {
sourceType: "module",
ecmaVersion: "latest",
extraFileExtensions: [".svelte"]
extraFileExtensions: [".svelte"],
},
env: {
browser: true,
es2024: true,
node: true
node: true,
},
globals: { $$Generic: "readable", NodeJS: true },
rules: {
Expand All @@ -25,8 +25,8 @@ module.exports = {
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_"
}
varsIgnorePattern: "^_",
},
],
"svelte/no-target-blank": "error",
"svelte/no-immutable-reactive-statements": "error",
Expand All @@ -37,24 +37,24 @@ module.exports = {
"svelte/require-each-key": "off",
"svelte/no-at-html-tags": "off",
"svelte/no-unused-svelte-ignore": "off",
"svelte/require-stores-init": "off"
"svelte/require-stores-init": "off",
},
overrides: [
{
files: ["*.svelte"],
parser: "svelte-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser"
parser: "@typescript-eslint/parser",
},
rules: {
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^\\$\\$(Props|Events|Slots|Generic)$"
}
]
}
varsIgnorePattern: "^\\$\\$(Props|Events|Slots|Generic)$",
},
],
},
},
{
files: ["*.ts"],
Expand All @@ -65,11 +65,11 @@ module.exports = {
{
extendDefaults: true,
types: {
"{}": false
}
}
]
}
}
]
"{}": false,
},
},
],
},
},
],
};
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"useTabs": true,
"singleQuote": false,
"trailingComma": "none",
"trailingComma": "es5",
"printWidth": 100,
"pluginSearchDirs": [
"."
Expand All @@ -15,7 +15,7 @@
"files": "*.svelte",
"options": {
"parser": "svelte",
"printWidth": 80
"printWidth": 100
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions .versionrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
bumpFiles: [
{
filename: "package.json",
type: "json"
}
]
type: "json",
},
],
};
20 changes: 10 additions & 10 deletions contentlayer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import path from "path";
const computedFields = {
slug: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/")
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
slugFull: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
fileName: {
type: "string",
resolve: (doc) => path.parse(doc._raw.sourceFilePath.split("/").slice(-1).join("/")).name
resolve: (doc) => path.parse(doc._raw.sourceFilePath.split("/").slice(-1).join("/")).name,
},
suffix: {
type: "string",
resolve: (doc) => path.parse(doc._raw.sourceFilePath.split("/").slice(-1).join("/")).ext
}
resolve: (doc) => path.parse(doc._raw.sourceFilePath.split("/").slice(-1).join("/")).ext,
},
};

export const Doc = defineDocumentType(() => ({
Expand All @@ -27,18 +27,18 @@ export const Doc = defineDocumentType(() => ({
fields: {
title: {
type: "string",
required: true
required: true,
},
description: {
type: "string",
required: true
}
required: true,
},
},
computedFields
computedFields,
}));

export default makeSource({
contentDirPath: "./content",
documentTypes: [Doc],
disableImportAliasWarning: true
disableImportAliasWarning: true,
});
28 changes: 14 additions & 14 deletions mdsvex.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const prettyCodeOptions = {
),
light: JSON.parse(
readFileSync(resolve(__dirname, "./src/styles/themes/serendipity-morning.json"))
)
),
},
keepBackground: false,
onVisitLine(node) {
Expand All @@ -35,7 +35,7 @@ const prettyCodeOptions = {
},
onVisitHighlightedWord(node) {
node.properties.className = ["word--highlighted"];
}
},
};

/** @type {import('@huntabyte/mdsvex').MdsvexOptions} */
Expand All @@ -46,7 +46,7 @@ export const mdsvexOptions = {
quotes: false,
ellipses: false,
backticks: false,
dashes: false
dashes: false,
},
remarkPlugins: [remarkGfm, remarkEscapeCode],
rehypePlugins: [
Expand All @@ -55,8 +55,8 @@ export const mdsvexOptions = {
[rehypePrettyCode, prettyCodeOptions],
rehypeHandleMetadata,
rehypeRenderCode,
rehypePreToComponentPre
]
rehypePreToComponentPre,
],
};
export function rehypeComponentExample() {
return async (tree) => {
Expand All @@ -80,23 +80,23 @@ export function rehypeComponentExample() {
const sourceCodeNode = u("element", {
tagName: "pre",
properties: {
className: ["code"]
className: ["code"],
},
children: [
u("element", {
tagName: "code",
properties: {
className: [`language-svelte`]
className: [`language-svelte`],
},
attributes: {},
children: [
{
type: "text",
value: sourceCode
}
]
})
]
value: sourceCode,
},
],
}),
],
});
if (!index) return;
parent.children.splice(index + 1, 0, sourceCodeNode);
Expand Down Expand Up @@ -127,7 +127,7 @@ const entities = [
[/</g, "&lt;"],
[/>/g, "&gt;"],
[/{/g, "&#123;"],
[/}/g, "&#125;"]
[/}/g, "&#125;"],
];

function remarkEscapeCode() {
Expand Down Expand Up @@ -199,7 +199,7 @@ function rehypeRenderCode() {
const codeString = tabsToSpaces(
toHtml(codeEl, {
allowDangerousCharacters: true,
allowDangerousHtml: true
allowDangerousHtml: true,
})
);

Expand Down
8 changes: 4 additions & 4 deletions other/code-block-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const codeBlockPrettierConfig = {
options: {
parser: "svelte",
svelteIndentScriptAndStyle: true,
svelteStrictMode: false
}
}
]
svelteStrictMode: false,
},
},
],
};
25 changes: 14 additions & 11 deletions other/setupTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// setupTest.ts
/* eslint-disable @typescript-eslint/no-empty-function */
import matchers from "@testing-library/jest-dom/matchers";
import * as matchers from "@testing-library/jest-dom/matchers";
import { expect, vi } from "vitest";
import type { Navigation, Page } from "@sveltejs/kit";
import { readable } from "svelte/store";
Expand All @@ -16,15 +16,15 @@ expect.extend(matchers);
expect.extend(toHaveNoViolations as never);

configure({
asyncUtilTimeout: 1500
asyncUtilTimeout: 1500,
});

// Mock SvelteKit runtime module $app/environment
vi.mock("$app/environment", (): typeof environment => ({
browser: false,
dev: true,
building: false,
version: "any"
version: "any",
}));

// Mock SvelteKit runtime module $app/navigation
Expand All @@ -35,9 +35,11 @@ vi.mock("$app/navigation", (): typeof navigation => ({
goto: () => Promise.resolve(),
invalidate: () => Promise.resolve(),
invalidateAll: () => Promise.resolve(),
preloadData: () => Promise.resolve(),
preloadData: () => Promise.resolve({ type: "loaded" as const, status: 200, data: {} }),
preloadCode: () => Promise.resolve(),
onNavigate: () => {}
onNavigate: () => {},
pushState: () => {},
replaceState: () => {},
}));

// Mock SvelteKit runtime module $app/stores
Expand All @@ -48,12 +50,13 @@ vi.mock("$app/stores", (): typeof stores => {
url: new URL("http://localhost"),
params: {},
route: {
id: null
id: null,
},
status: 200,
error: null,
data: {},
form: undefined
form: undefined,
state: {},
});
const updated = { subscribe: readable(false).subscribe, check: async () => false };

Expand All @@ -63,25 +66,25 @@ vi.mock("$app/stores", (): typeof stores => {
const page: typeof stores.page = {
subscribe(fn) {
return getStores().page.subscribe(fn);
}
},
};
const navigating: typeof stores.navigating = {
subscribe(fn) {
return getStores().navigating.subscribe(fn);
}
},
};
const updated: typeof stores.updated = {
subscribe(fn) {
return getStores().updated.subscribe(fn);
},
check: async () => false
check: async () => false,
};

return {
getStores,
navigating,
page,
updated
updated,
};
});

Expand Down
Loading

0 comments on commit f58e9fb

Please sign in to comment.