From 0b4781e28e0070ac67a368ef78c548537439b963 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:46:41 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- packages/kit/src/context.ts | 7 ++++--- packages/kit/src/index.ts | 2 +- packages/kit/src/loader/nuxt.ts | 4 ++-- packages/kit/src/utils.ts | 4 ++-- packages/nuxt/src/core/nitro.ts | 2 +- packages/nuxt/src/core/nuxt.ts | 26 +++++++++++++------------- packages/nuxt/test/load-nuxt.test.ts | 6 +++--- test/bundle.test.ts | 2 +- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/kit/src/context.ts b/packages/kit/src/context.ts index dd4481dfdd..08eb4aebee 100644 --- a/packages/kit/src/context.ts +++ b/packages/kit/src/context.ts @@ -24,8 +24,9 @@ export function useNuxt (): Nuxt { const fallbackInstance = fallbackNuxtCtx.tryUse() if (fallbackInstance) { logger.warn('Using fallback global Nuxt instance. You may be using a @nuxt/kit composable outside of a Nuxt context, this behavior is deprecated and will be removed in v4.') - return fallbackInstance } - + return fallbackInstance + } + throw new Error('Nuxt instance is unavailable!') } return instance @@ -45,7 +46,7 @@ export function useNuxt (): Nuxt { */ export function tryUseNuxt (): Nuxt | null { const nuxt = nuxtCtx().tryUse() - if(!nuxt) { + if (!nuxt) { logger.warn('Using fallback global Nuxt instance. You may be using a @nuxt/kit composable outside of a Nuxt context, this behavior is deprecated and will be removed in v4.') return fallbackNuxtCtx.tryUse() } diff --git a/packages/kit/src/index.ts b/packages/kit/src/index.ts index 2a5531d807..b5e500202a 100644 --- a/packages/kit/src/index.ts +++ b/packages/kit/src/index.ts @@ -34,4 +34,4 @@ export { logger, useLogger } from './logger' // Internal Utils export { resolveModule, tryResolveModule, importModule, tryImportModule, requireModule, tryRequireModule } from './internal/esm' export type { ImportModuleOptions, ResolveModuleOptions } from './internal/esm' -export { asyncNameStorage } from './utils' \ No newline at end of file +export { asyncNameStorage } from './utils' diff --git a/packages/kit/src/loader/nuxt.ts b/packages/kit/src/loader/nuxt.ts index 59bec5a534..eb6ab55a45 100644 --- a/packages/kit/src/loader/nuxt.ts +++ b/packages/kit/src/loader/nuxt.ts @@ -3,8 +3,8 @@ import { readPackageJSON, resolvePackageJSON } from 'pkg-types' import type { Nuxt, NuxtConfig } from '@nuxt/schema' import { resolve } from 'pathe' import { importModule, tryImportModule } from '../internal/esm' -import type { LoadNuxtConfigOptions } from './config' import { asyncNameStorage } from '../utils' +import type { LoadNuxtConfigOptions } from './config' export interface LoadNuxtOptions extends LoadNuxtConfigOptions { /** Load nuxt with development mode */ @@ -41,5 +41,5 @@ export async function buildNuxt (nuxt: Nuxt): Promise { const rootDir = pathToFileURL(nuxt.options.rootDir).href const { build } = await tryImportModule('nuxt-nightly', { paths: rootDir }) || await importModule('nuxt', { paths: rootDir }) - return asyncNameStorage.run(nuxt.__name, () => build(nuxt)) + return asyncNameStorage.run(nuxt.__name, () => build(nuxt)) } diff --git a/packages/kit/src/utils.ts b/packages/kit/src/utils.ts index 6751269b2b..6b351a701a 100644 --- a/packages/kit/src/utils.ts +++ b/packages/kit/src/utils.ts @@ -1,4 +1,4 @@ -import { AsyncLocalStorage } from "node:async_hooks" +import { AsyncLocalStorage } from 'node:async_hooks' /** @since 3.9.0 */ export function toArray (value: T | T[]): T[] { @@ -10,4 +10,4 @@ export const MODE_RE = /\.(server|client)(\.\w+)*$/ * @internal * async local storage for the name of the current nuxt instance */ -export const asyncNameStorage = new AsyncLocalStorage() \ No newline at end of file +export const asyncNameStorage = new AsyncLocalStorage() diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 4d6c87c203..698cb04b3a 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -429,7 +429,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { tsConfig.compilerOptions.paths[alias] = [absolutePath.replace(EXTENSION_RE, '')] /* remove extension */ } } - + // Init nitro const nitro = await createNitro(nitroConfig, { compatibilityDate: nuxt.options.compatibilityDate, diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 98004c9247..9d26cb7160 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -4,7 +4,7 @@ import { join, normalize, relative, resolve } from 'pathe' import { createDebugger, createHooks } from 'hookable' import ignore from 'ignore' import type { LoadNuxtOptions } from '@nuxt/kit' -import { addBuildPlugin, addComponent, addPlugin, addPluginTemplate, addRouteMiddleware, addServerPlugin, addTypeTemplate, addVitePlugin, addWebpackPlugin, installModule, loadNuxtConfig, nuxtCtx, resolveAlias, resolveFiles, resolveIgnorePatterns, resolvePath, tryResolveModule, useNitro, asyncNameStorage, fallbackNuxtCtx } from '@nuxt/kit' +import { addBuildPlugin, addComponent, addPlugin, addPluginTemplate, addRouteMiddleware, addServerPlugin, addTypeTemplate, addVitePlugin, addWebpackPlugin, asyncNameStorage, fallbackNuxtCtx, installModule, loadNuxtConfig, nuxtCtx, resolveAlias, resolveFiles, resolveIgnorePatterns, resolvePath, tryResolveModule, useNitro } from '@nuxt/kit' import type { Nuxt, NuxtHooks, NuxtModule, NuxtOptions } from 'nuxt/schema' import type { PackageJson } from 'pkg-types' import { readPackageJSON } from 'pkg-types' @@ -22,6 +22,7 @@ import { gt, satisfies } from 'semver' import { hasTTY, isCI } from 'std-env' import { genImport } from 'knitwork' +import { randomUUID } from 'uncrypto' import { installNuxtModule } from '../core/features' import pagesModule from '../pages/module' import metaModule from '../head/module' @@ -47,9 +48,8 @@ import { ComposableKeysPlugin } from './plugins/composable-keys' import { resolveDeepImportsPlugin } from './plugins/resolve-deep-imports' import { PrehydrateTransformPlugin } from './plugins/prehydrate' import { VirtualFSPlugin } from './plugins/virtual' -import { randomUUID } from 'uncrypto' -export function createNuxt(options: NuxtOptions): Nuxt { +export function createNuxt (options: NuxtOptions): Nuxt { const hooks = createHooks() const name = randomUUID() const nuxt: Nuxt = { @@ -90,7 +90,7 @@ const keyDependencies = [ let warnedAboutCompatDate = false -async function initNuxt(nuxt: Nuxt) { +async function initNuxt (nuxt: Nuxt) { // Register user hooks for (const config of nuxt.options._layers.map(layer => layer.config).reverse()) { if (config.hooks) { @@ -110,7 +110,7 @@ async function initNuxt(nuxt: Nuxt) { logger.info(`Using \`${fallbackCompatibilityDate}\` as fallback compatibility date.`) } - async function promptAndUpdate() { + async function promptAndUpdate () { const result = await consola.prompt(`Do you want to update your ${colorize('cyan', 'nuxt.config')} to set ${colorize('cyan', `compatibilityDate: '${todaysDate}'`)}?`, { type: 'confirm', default: true, @@ -124,7 +124,7 @@ async function initNuxt(nuxt: Nuxt) { const res = await updateConfig({ configFile: 'nuxt.config', cwd: nuxt.options.rootDir, - async onCreate({ configFile }) { + async onCreate ({ configFile }) { const shallCreate = await consola.prompt(`Do you want to create ${colorize('cyan', relative(nuxt.options.rootDir, configFile))}?`, { type: 'confirm', default: true, @@ -134,7 +134,7 @@ async function initNuxt(nuxt: Nuxt) { } return _getDefaultNuxtConfig() }, - onUpdate(config) { + onUpdate (config) { config.compatibilityDate = todaysDate }, }) @@ -731,7 +731,7 @@ export default defineNuxtPlugin({ await nuxt.callHook('ready', nuxt) } -export async function loadNuxt(opts: LoadNuxtOptions): Promise { +export async function loadNuxt (opts: LoadNuxtOptions): Promise { const options = await loadNuxtConfig(opts) // Temporary until finding better placement for each @@ -804,7 +804,7 @@ export async function loadNuxt(opts: LoadNuxtOptions): Promise { configurable: false, enumerable: true, get: () => nitroOptions, - set(value) { + set (value) { Object.assign(nitroOptions, value) }, }, @@ -832,7 +832,7 @@ export async function loadNuxt(opts: LoadNuxtOptions): Promise { return nuxt } -async function checkDependencyVersion(name: string, nuxtVersion: string): Promise { +async function checkDependencyVersion (name: string, nuxtVersion: string): Promise { const path = await resolvePath(name, { fallbackToOriginal: true }).catch(() => null) if (!path || path === name) { return } @@ -845,7 +845,7 @@ async function checkDependencyVersion(name: string, nuxtVersion: string): Promis const RESTART_RE = /^(?:app|error|app\.config)\.(?:js|ts|mjs|jsx|tsx|vue)$/i -function deduplicateArray(maybeArray: T): T { +function deduplicateArray (maybeArray: T): T { if (!Array.isArray(maybeArray)) { return maybeArray } const fresh: any[] = [] @@ -860,7 +860,7 @@ function deduplicateArray(maybeArray: T): T { return fresh as T } -function createPortalProperties(sourceValue: any, options: NuxtOptions, paths: string[]) { +function createPortalProperties (sourceValue: any, options: NuxtOptions, paths: string[]) { let sharedValue = sourceValue for (const path of paths) { @@ -880,7 +880,7 @@ function createPortalProperties(sourceValue: any, options: NuxtOptions, paths: s configurable: false, enumerable: true, get: () => sharedValue, - set(value) { + set (value) { sharedValue = value }, }, diff --git a/packages/nuxt/test/load-nuxt.test.ts b/packages/nuxt/test/load-nuxt.test.ts index 2da31eccea..c151274d70 100644 --- a/packages/nuxt/test/load-nuxt.test.ts +++ b/packages/nuxt/test/load-nuxt.test.ts @@ -35,7 +35,7 @@ describe('loadNuxt', () => { ready: true, overrides: { hooks: { - ready() { + ready () { hookRan = true }, }, @@ -48,10 +48,10 @@ describe('loadNuxt', () => { await Promise.all([ loadNuxt({ cwd: repoRoot, - }), + }), loadNuxt({ cwd: repoRoot, - }) + }), ]) }) }) diff --git a/test/bundle.test.ts b/test/bundle.test.ts index ccda704541..657bc48e72 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -99,7 +99,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM const serverDir = join(rootDir, '.output-inline/server') const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"560k"`) + expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"561k"`) const modules = await analyzeSizes(['node_modules/**/*'], serverDir) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"94.4k"`)