From 844d870405971b9ec105f27ca219c40b51c8f154 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 6 Jan 2025 15:15:49 +0000 Subject: [PATCH 1/2] fix(cli): use `@nuxt/kit` to load nuxt config --- package.json | 1 - pnpm-lock.yaml | 3 --- src/cli.ts | 23 ++++++++++------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 570824f..f7c1a2b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "dotenv": "^16.4.7", "git-url-parse": "^16.0.0", "is-docker": "^3.0.0", - "jiti": "^2.4.2", "ofetch": "^1.4.1", "package-manager-detector": "^0.2.8", "parse-git-config": "^3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8fe0903..fa4aaa2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,9 +32,6 @@ importers: is-docker: specifier: ^3.0.0 version: 3.0.0 - jiti: - specifier: ^2.4.2 - version: 2.4.2 ofetch: specifier: ^1.4.1 version: 1.4.1 diff --git a/src/cli.ts b/src/cli.ts index 26d273f..a3b5565 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -6,7 +6,7 @@ import { destr } from 'destr' import * as rc from 'rc9' import { colors as c } from 'consola/utils' import { consola } from 'consola' -import { createJiti } from 'jiti' +import { loadNuxtConfig } from '@nuxt/kit' import { isTest } from 'std-env' import { parse as parseDotenv } from 'dotenv' import { createMain, defineCommand } from 'citty' @@ -115,13 +115,14 @@ async function _checkDisabled(dir: string): Promise } } - const disabledByConf = (conf: any) => conf.telemetry === false - || (conf.telemetry && conf.telemetry.enabled === false) + const disabledByConf = (conf: any) => conf.telemetry === false || (conf.telemetry && conf.telemetry.enabled === false) try { - const configPath = resolveNuxtConfigPath(dir) - if (configPath && disabledByConf(createJiti(dir).import(configPath, { default: true }))) { - return 'by ' + configPath + const config = await loadNuxtConfig({ cwd: dir }) + for (const layer of config._layers) { + if (disabledByConf(layer.config)) { + return 'by ' + config._layers[0].configFile + } } } catch { @@ -157,17 +158,13 @@ function setRC(dir: string, key: any, val: any, global: boolean) { } } -function resolveNuxtConfigPath(dir: string) { - const jiti = createJiti(dir) - return jiti.esmResolve('./nuxt.config', { try: true }) || jiti.esmResolve('./.config/nuxt', { try: true }) -} - -function ensureNuxtProject(args: { global: boolean, dir: string }) { +async function ensureNuxtProject(args: { global: boolean, dir: string }) { if (args.global) { return } const dir = resolve(args.dir) - if (!resolveNuxtConfigPath(dir)) { + const nuxtConfig = await loadNuxtConfig({ cwd: dir }) + if (!nuxtConfig) { consola.error('You are not in a Nuxt project.') consola.info('You can try specifying a directory or by using the `--global` flag to configure telemetry for your machine.') process.exit() From 65eb7509fb39893ba725964be69930d2a9d6dcae Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 6 Jan 2025 15:19:22 +0000 Subject: [PATCH 2/2] fix: correctly warn if not in nuxt project --- src/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index a3b5565..d9dcb3e 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -164,7 +164,7 @@ async function ensureNuxtProject(args: { global: boolean, dir: string }) { } const dir = resolve(args.dir) const nuxtConfig = await loadNuxtConfig({ cwd: dir }) - if (!nuxtConfig) { + if (!nuxtConfig || !nuxtConfig._layers[0]?.configFile) { consola.error('You are not in a Nuxt project.') consola.info('You can try specifying a directory or by using the `--global` flag to configure telemetry for your machine.') process.exit()