Skip to content

Commit

Permalink
style: lint with prettier v3
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 4, 2023
1 parent 1f2ab64 commit 7940e9b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"github>unjs/renovate-config"
]
"extends": ["github>unjs/renovate-config"]
}
8 changes: 4 additions & 4 deletions src/dotenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function loadDotenv(options: DotenvOptions): Promise<Env> {
function interpolate(
target: Record<string, any>,
source: Record<string, any> = {},
parse = (v: any) => v
parse = (v: any) => v,
) {
function getValue(key: string) {
// Source value 'wins' over target value
Expand Down Expand Up @@ -122,8 +122,8 @@ function interpolate(
// eslint-disable-next-line no-console
console.warn(
`Please avoid recursive environment variables ( loop: ${parents.join(
" > "
)} > ${key} )`
" > ",
)} > ${key} )`,
);
return "";
}
Expand All @@ -137,7 +137,7 @@ function interpolate(
return value === undefined
? newValue
: newValue.replace(replacePart, value);
}, value)
}, value),
);
}

Expand Down
26 changes: 13 additions & 13 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {

export async function loadConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
>(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>> {
// Normalize options
options.cwd = resolve(process.cwd(), options.cwd || ".");
Expand Down Expand Up @@ -75,19 +75,19 @@ export async function loadConfig<
if (options.globalRc) {
Object.assign(
configRC,
rc9.readUser({ name: options.rcFile, dir: options.cwd })
rc9.readUser({ name: options.rcFile, dir: options.cwd }),
);
const workspaceDir = await findWorkspaceDir(options.cwd).catch(() => {});
if (workspaceDir) {
Object.assign(
configRC,
rc9.read({ name: options.rcFile, dir: workspaceDir })
rc9.read({ name: options.rcFile, dir: workspaceDir }),
);
}
}
Object.assign(
configRC,
rc9.read({ name: options.rcFile, dir: options.cwd })
rc9.read({ name: options.rcFile, dir: options.cwd }),
);
}

Expand All @@ -114,7 +114,7 @@ export async function loadConfig<
config,
configRC,
pkgJson,
options.defaultConfig
options.defaultConfig,
) as T;

// Allow extending
Expand Down Expand Up @@ -150,7 +150,7 @@ export async function loadConfig<

async function extendConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
>(config: InputConfig<T, MT>, options: LoadConfigOptions<T, MT>) {
(config as any)._layers = config._layers || [];
if (!options.extend) {
Expand All @@ -164,8 +164,8 @@ async function extendConfig<
for (const key of keys as string[]) {
extendSources.push(
...(Array.isArray(config[key]) ? config[key] : [config[key]]).filter(
Boolean
)
Boolean,
),
);
delete config[key];
}
Expand All @@ -185,8 +185,8 @@ async function extendConfig<
// eslint-disable-next-line no-console
console.warn(
`Cannot extend config from \`${JSON.stringify(
originalExtendSource
)}\` in ${options.cwd}`
originalExtendSource,
)}\` in ${options.cwd}`,
);
continue;
}
Expand All @@ -195,7 +195,7 @@ async function extendConfig<
// TODO: Use error in next major versions
// eslint-disable-next-line no-console
console.warn(
`Cannot extend config from \`${extendSource}\` in ${options.cwd}`
`Cannot extend config from \`${extendSource}\` in ${options.cwd}`,
);
continue;
}
Expand All @@ -216,11 +216,11 @@ const NPM_PACKAGE_RE =

async function resolveConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
>(
source: string,
options: LoadConfigOptions<T, MT>,
sourceOptions: SourceOptions<T, MT> = {}
sourceOptions: SourceOptions<T, MT> = {},
): Promise<ResolvedConfig<T, MT>> {
// Custom user resolver
if (options.resolve) {
Expand Down
18 changes: 9 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type UserInputConfig = Record<string, any>;

export interface C12InputConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> {
$test?: T;
$development?: T;
Expand All @@ -22,12 +22,12 @@ export interface C12InputConfig<

export type InputConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> = C12InputConfig<T, MT> & T;

export interface SourceOptions<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> {
meta?: MT;
overrides?: T;
Expand All @@ -36,7 +36,7 @@ export interface SourceOptions<

export interface ConfigLayer<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> {
config: T | null;
source?: string;
Expand All @@ -48,15 +48,15 @@ export interface ConfigLayer<

export interface ResolvedConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> extends ConfigLayer<T, MT> {
layers?: ConfigLayer<T, MT>[];
cwd?: string;
}

export interface LoadConfigOptions<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> {
name?: string;
cwd?: string;
Expand All @@ -78,7 +78,7 @@ export interface LoadConfigOptions<

resolve?: (
id: string,
options: LoadConfigOptions<T, MT>
options: LoadConfigOptions<T, MT>,
) =>
| null
| undefined
Expand All @@ -97,12 +97,12 @@ export interface LoadConfigOptions<

export type DefineConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> = (input: InputConfig<T, MT>) => InputConfig<T, MT>;

export function createDefineConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
>(): DefineConfig<T, MT> {
return (input: InputConfig<T, MT>) => input;
}
12 changes: 6 additions & 6 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { loadConfig } from "./loader";

export type ConfigWatcher<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> = ResolvedConfig<T, MT> & {
watchingFiles: string[];
unwatch: () => Promise<void>;
};

export interface WatchConfigOptions<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
> extends LoadConfigOptions<T, MT> {
chokidarOptions?: WatchOptions;
debounce?: false | number;
Expand Down Expand Up @@ -51,7 +51,7 @@ const eventMap = {

export async function watchConfig<
T extends UserInputConfig = UserInputConfig,
MT extends ConfigLayerMeta = ConfigLayerMeta
MT extends ConfigLayerMeta = ConfigLayerMeta,
>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>> {
let config = await loadConfig<T, MT>(options);

Expand All @@ -65,7 +65,7 @@ export async function watchConfig<
.filter((l) => l.cwd)
.flatMap((l) => [
...["ts", "js", "mjs", "cjs", "cts", "mts", "json"].map((ext) =>
resolve(l.cwd!, configFileName + "." + ext)
resolve(l.cwd!, configFileName + "." + ext),
),
l.source && resolve(l.cwd!, l.source),
// TODO: Support watching rc from home and workspace
Expand All @@ -74,11 +74,11 @@ export async function watchConfig<
l.cwd!,
typeof options.rcFile === "string"
? options.rcFile
: `.${configName}rc`
: `.${configName}rc`,
),
options.packageJson && resolve(l.cwd!, "package.json"),
])
.filter(Boolean)
.filter(Boolean),
),
] as string[];

Expand Down
6 changes: 3 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
reporter: ["text", "clover", "json"]
}
}
reporter: ["text", "clover", "json"],
},
},
});

0 comments on commit 7940e9b

Please sign in to comment.