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

Commit 1f9622b

Browse files
committed
feat(options): add defu for options resolution and update types
This commit introduces the 'defu' library for options resolution in 'src/options.ts'. It also updates the types for options, making some fields optional and others required. The 'package.json' and 'pnpm-lock.yaml' files are updated to include the new dependency.
1 parent 44e41b1 commit 1f9622b

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"await-to-js": "^3.0.0",
1919
"camelcase-keys": "^9.1.3",
20+
"defu": "^6.1.4",
2021
"knitwork": "^1.1.0",
2122
"lightningcss": "^1.25.1",
2223
"magic-string": "^0.30.11",

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/options.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { SetRequired } from 'type-fest';
1+
import type { RequiredDeep, SetOptional, SetRequired } from 'type-fest';
2+
import { defu } from 'defu';
23

34
/**
45
* Options for the cssModules preprocessor
@@ -23,11 +24,13 @@ export type Options = {
2324
convertToCamelCase?: boolean;
2425
};
2526

26-
export type ResolvedOptions = SetRequired<Options, 'includeOriginalPath'>;
27+
export type ResolvedOptions = SetOptional<RequiredDeep<Options>, 'moduleNameingPattern'>;
2728

28-
export function resolveOptions(options: Options): ResolvedOptions {
29-
return {
30-
moduleNameingPattern: options.moduleNameingPattern,
31-
includeOriginalPath: options.includeOriginalPath ?? true,
32-
};
29+
const defaultOptions = {
30+
includeOriginalPath: true,
31+
convertToCamelCase: true,
32+
} as const satisfies ResolvedOptions;
33+
34+
export function resolveOptions(options: Options): Readonly<ResolvedOptions> {
35+
return defu(options, defaultOptions);
3336
}

0 commit comments

Comments
 (0)