Skip to content

Commit 82e6edf

Browse files
committed
fix: remove side-effect
1 parent 992204a commit 82e6edf

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/hoist.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import defu from "defu";
1+
import { defu } from "defu";
22
import { type PackageJson, readPackageJSON, resolvePackageJSON } from "pkg-types";
33
import { resolveModulePath } from "exsolve";
44
import { dirname } from "pathe";
55
import { directoryToURL, tryUseNuxt, useNuxt } from "@nuxt/kit";
6-
import { version } from "nuxt/package.json";
7-
const isVersion4 = version.startsWith("4");
86

97
/**
108
* @see [Nuxt source](https://github.com/nuxt/nuxt/blob/a0f9ddfe241bcf555f6305aa10c087a1fe64af87/packages/nuxt/src/core/utils/types.ts#L6)
@@ -38,6 +36,7 @@ async function resolveTypePath(path: string, subpath: string, searchPaths = tryU
3836
* @see [Nuxt source](https://github.com/nuxt/nuxt/blob/5146bed75eb1a6617e2fb17ea97b3d121cd94930/packages/nuxt/src/core/nuxt.ts#L188-L290)
3937
*/
4038
export async function hoistDependencies(hoist: string[], nuxt = useNuxt()) {
39+
const isVersion4 = (await readPackageJSON("nuxt"))?.version?.startsWith("4");
4140
const packageJSON = await readPackageJSON(nuxt.options.rootDir).catch(() => ({} as PackageJson));
4241
const NESTED_PKG_RE = /^[^@]+\//;
4342
const dependencies = new Set([

src/layers.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { NuxtConfigLayer } from "@nuxt/schema";
22
import { defu } from "defu";
33

4-
type GetModuleOptions<
5-
T,
6-
K extends keyof NuxtConfigLayer["config"],
7-
> = [T] extends [never] ? NuxtConfigLayer["config"][K] : T;
4+
type GetModuleOptions<T, K extends keyof NuxtConfigLayer["config"]> = [T] extends [never]
5+
? NuxtConfigLayer["config"][K]
6+
: T;
87

98
/**
109
* Get module options from a given Nuxt layer
@@ -21,21 +20,14 @@ type GetModuleOptions<
2120
*/
2221
export function getLayerModuleOptions<
2322
T = never,
24-
K extends keyof NuxtConfigLayer["config"] = keyof NuxtConfigLayer["config"],
25-
>(
26-
layer: NuxtConfigLayer,
27-
configKey: K,
28-
name: string,
29-
): GetModuleOptions<T, K> | undefined {
23+
K extends keyof NuxtConfigLayer["config"] = keyof NuxtConfigLayer["config"]
24+
>(layer: NuxtConfigLayer, configKey: K, name: string): GetModuleOptions<T, K> | undefined {
3025
type Options = GetModuleOptions<T, K>;
3126

3227
const matchInlineOptions = (mod: any): mod is [string, Options] =>
3328
Array.isArray(mod) && typeof mod[0] === "string" && mod[0] === name;
3429

35-
const modules = (layer.config.modules || []) as [
36-
string,
37-
unknown | undefined,
38-
][];
30+
const modules = (layer.config.modules || []) as [string, unknown | undefined][];
3931
const inlineOptions = modules.find(matchInlineOptions)?.[1];
4032
const keyOptions = layer.config[configKey] as Options | undefined;
4133

0 commit comments

Comments
 (0)