Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit 94c743b

Browse files
committed
feat: replace custom function with 'ufo' library function
The custom function 'addSlash' in 'src/utils/alias.ts' has been replaced with the 'withTrailingSlash' function from the 'ufo' library. This change simplifies the code and reduces redundancy. The 'ufo' library has also been added to the project dependencies in 'package.json' and 'pnpm-lock.yaml'.
1 parent 122190a commit 94c743b

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"svelte": "5.0.0-next.210",
4343
"svelte-parse-markup": "^0.1.5",
4444
"type-fest": "^4.23.0",
45+
"ufo": "^1.5.4",
4546
"uint8array-extras": "^1.4.0",
4647
"unconfig": "^0.5.5",
4748
"zimmerframe": "^1.1.2"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/alias.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import type { Config as SvelteKitConfig } from '@sveltejs/kit';
22
import type { UserConfig as ViteConfig } from 'vite';
33
import { loadConfig } from 'unconfig';
4-
5-
export function addSlash(str: string): string {
6-
return (str.endsWith('/') ? str : `${str}/`);
7-
}
4+
import { withTrailingSlash } from 'ufo';
85

96
export async function loadAliases(): Promise<Record<string, string>> {
107
const { config } = await loadConfig({
@@ -32,7 +29,7 @@ export async function loadAliases(): Promise<Record<string, string>> {
3229

3330
for (const [key, value] of Object.entries(_alias)) {
3431
if (typeof value === 'string' && typeof key === 'string') {
35-
alias[key] = addSlash(value);
32+
alias[key] = withTrailingSlash(value);
3633
}
3734
}
3835

src/utils/css-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { StaticImport } from 'mlly';
66
import { parseStaticImport, pathToFileURL, resolvePath } from 'mlly';
77
import { stringToUint8Array, uint8ArrayToString } from 'uint8array-extras';
88
import { betterr } from 'betterr';
9+
import { withTrailingSlash } from 'ufo';
910
import type { ResolvedOptions } from '../options';
10-
import { addSlash } from './alias';
1111

1212
type getCssModuleImportsProps = {
1313
imports: StaticImport[];
@@ -38,7 +38,7 @@ export async function getCssModuleImports(
3838
throw new Error(`Default import is required for css modules: ${specifier}`);
3939
}
4040

41-
const aliasKey = Object.keys(aliases).find(a => specifier.startsWith(addSlash(a)) || specifier === a);
41+
const aliasKey = Object.keys(aliases).find(a => specifier.startsWith(withTrailingSlash(a)) || specifier === a);
4242
if (aliasKey != null) {
4343
const alias = aliases[aliasKey];
4444
const s = new MagicString(specifier);

0 commit comments

Comments
 (0)