Skip to content

Commit

Permalink
refactor: Configure path aliases for more consistent imports (#100)
Browse files Browse the repository at this point in the history
* Configure path aliases for `$server` and `$src` imports

* Add include patterns to ensure all source files are considered

* Replace kit aliases with paths in tsconfig
  • Loading branch information
OLILHR authored Nov 4, 2024
1 parent ffaf9f5 commit 354882e
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/auth/authService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { LogoutOptions } from "@auth0/auth0-spa-js";
import { Auth0Client, createAuth0Client, User } from "@auth0/auth0-spa-js";

import { isAuthenticated, user } from "../store";
import config from "./auth_config";
import config from "$src/auth/auth_config";
import { isAuthenticated, user } from "$src/store";

let auth0Client: Auth0Client;

Expand Down
22 changes: 11 additions & 11 deletions src/lib/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// shared components
export { default as Footer } from "./shared/footer.svelte";
export { default as Header } from "./shared/header.svelte";
export { default as IconLogin } from "./shared/icon-login.svelte";
export { default as IconLogo } from "./shared/icon-logo.svelte";
export { default as IconLogout } from "./shared/icon-logout.svelte";
export { default as LoginButton } from "./shared/login-button.svelte";
export { default as ToolsBanner } from "./shared/tools-banner.svelte";
export { default as Footer } from "$lib/components/shared/footer.svelte";
export { default as Header } from "$lib/components/shared/header.svelte";
export { default as IconLogin } from "$lib/components/shared/icon-login.svelte";
export { default as IconLogo } from "$lib/components/shared/icon-logo.svelte";
export { default as IconLogout } from "$lib/components/shared/icon-logout.svelte";
export { default as LoginButton } from "$lib/components/shared/login-button.svelte";
export { default as ToolsBanner } from "$lib/components/shared/tools-banner.svelte";

// features
export { default as EbdFormHeader } from "./features/ebd-form-header.svelte";
export { default as EbdSelect } from "./features/ebd-select.svelte";
export { default as ExportButton } from "./features/export-button.svelte";
export { default as FormatVersionSelect } from "./features/format-version-select.svelte";
export { default as EbdFormHeader } from "$lib/components/features/ebd-form-header.svelte";
export { default as EbdSelect } from "$lib/components/features/ebd-select.svelte";
export { default as ExportButton } from "$lib/components/features/export-button.svelte";
export { default as FormatVersionSelect } from "$lib/components/features/format-version-select.svelte";
5 changes: 2 additions & 3 deletions src/lib/components/shared/login-button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import { onMount } from "svelte";
import { IconLogin, IconLogout } from "$lib/components";
import auth from "../../../auth/authService";
import { isAuthenticated, user } from "../../../store";
import auth from "$src/auth/authService";
import { isAuthenticated, user } from "$src/store";
let userEmail: string = "";
Expand Down
4 changes: 2 additions & 2 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getEbds } from "../server/ebd-loader";
import { getFormatVersions } from "../server/format-version-loader";
import { getEbds } from "$server/ebd-loader";
import { getFormatVersions } from "$server/format-version-loader";

export const load = async () => {
const formatVersions = getFormatVersions();
Expand Down
9 changes: 4 additions & 5 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<script lang="ts">
import "../app.scss";
import "$src/app.scss";
import { onMount } from "svelte";
import { goto } from "$app/navigation";
import { base } from "$app/paths";
import { page } from "$app/stores";
import { Footer } from "$lib/components";
import auth from "../auth/authService";
import { isAuthenticated } from "../store";
import auth from "$src/auth/authService";
import { isAuthenticated } from "$src/store";
let isLoading = true;
Expand All @@ -27,7 +26,7 @@
await auth.checkAuth();
isLoading = false;
isAuthenticated.subscribe((value) => {
isAuthenticated.subscribe((value: boolean) => {
if (!value && !isLoading && $page.url.pathname !== `${base}/`) {
goto(`${base}/`);
}
Expand Down
7 changes: 3 additions & 4 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script lang="ts">
import "../app.scss";
import "$src/app.scss";
import { goto } from "$app/navigation";
import { base } from "$app/paths";
import { LoginButton, ToolsBanner } from "$lib/components";
import auth from "../auth/authService";
import { isAuthenticated } from "../store";
import auth from "$src/auth/authService";
import { isAuthenticated } from "$src/store";
async function checkAuthentication() {
if ($isAuthenticated) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/ebd/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import "../../app.scss";
import "$src/app.scss";
</script>

<div class="flex flex-col flex-grow hfill">
Expand Down
5 changes: 3 additions & 2 deletions src/routes/ebd/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getEbds } from "../../server/ebd-loader";
import { getFormatVersions } from "../../server/format-version-loader";
import { getEbds } from "$server/ebd-loader";
import { getFormatVersions } from "$server/format-version-loader";

import type { PageServerLoad } from "./$types";

export const load: PageServerLoad = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/ebd/[...ebd]/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import "../../../app.scss";
import "$src/app.scss";
import { page } from "$app/stores";
import { EbdFormHeader } from "$lib/components";
Expand Down
16 changes: 12 additions & 4 deletions src/routes/ebd/[...ebd]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { getFormatVersions } from "../../../server/format-version-loader";
import { prerenderEntries } from "../../../server/prerender-entries";
import { getFormatVersions } from "$server/format-version-loader";
import { prerenderEntries } from "$server/prerender-entries";

import type { PageServerLoad } from "./$types";

interface RouteEntry {
ebd: string;
filePath: string;
}

export function entries() {
const routes = prerenderEntries();
return routes.map((route) => ({
return routes.map((route: RouteEntry) => ({
ebd: route.ebd,
}));
}

export const load: PageServerLoad = async ({ params }) => {
const [formatVersion, ebdFile] = params.ebd.split("/");
const availableVersions = getFormatVersions();
const version = availableVersions.find((v) => v.code === formatVersion);
const version = availableVersions.find(
(v: { code: string }) => v.code === formatVersion,
);

return {
formatVersion: version,
Expand Down
4 changes: 2 additions & 2 deletions src/server/prerender-entries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from "path";

import { getEbds } from "./ebd-loader";
import { getFormatVersions } from "./format-version-loader";
import { getEbds } from "$server/ebd-loader";
import { getFormatVersions } from "$server/format-version-loader";

export function prerenderEntries() {
const staticPath = join(process.cwd(), "static", "ebd");
Expand Down
11 changes: 9 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"paths": {
"$lib/*": ["src/lib/*"],
"$src/*": ["src/*"],
"$server/*": ["src/server/*"]
},
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "node",
"types": ["node"]
}
},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
}
7 changes: 7 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
import path from "path";

export default defineConfig({
plugins: [sveltekit()],
resolve: {
alias: {
$server: path.resolve("./src/server"),
$src: path.resolve("./src"),
},
},
});

0 comments on commit 354882e

Please sign in to comment.