diff --git a/biome.json b/biome.json index 5df67f43a2..76b29540c8 100644 --- a/biome.json +++ b/biome.json @@ -5,10 +5,35 @@ "ignore": ["**/*.gen.ts", "./package.json"] }, "linter": { - "enabled": false + "enabled": true, + "rules": { + "suspicious": { + "noExplicitAny": "off", + "noImplicitAnyLet": "off", + "noAssignInExpressions": "off", + "noConfusingVoidType": "off", + "noEmptyInterface": "off" + }, + "style": { + "noNonNullAssertion": "off", + "noArguments": "off", + "useTemplate": "off", + "noUnusedTemplateLiteral": "off", + "noParameterAssign": "off", + "useShorthandFunctionType": "off" + }, + "complexity": { + "noBannedTypes": "off", + "useArrowFunction": "off", + "noUselessEmptyExport": "off" + }, + "performance": { + "noDelete": "off" + } + } }, "organizeImports": { - "enabled": false + "enabled": true }, "javascript": { "formatter": { diff --git a/build.config.ts b/build.config.ts index 46fa8d8db1..7cb0aff7a3 100644 --- a/build.config.ts +++ b/build.config.ts @@ -1,8 +1,8 @@ -import { defineBuildConfig } from "unbuild"; -import { resolve } from "pathe"; +import { writeFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; +import { resolve } from "pathe"; import { normalize } from "pathe"; -import { writeFile } from "node:fs/promises"; +import { defineBuildConfig } from "unbuild"; const srcDir = fileURLToPath(new URL("src", import.meta.url)); diff --git a/package.json b/package.json index 0e72da811e..b4a9202cf0 100644 --- a/package.json +++ b/package.json @@ -76,8 +76,8 @@ "dev": "pnpm nitro dev playground", "dev:build": "pnpm nitro build playground", "dev:start": "node playground/.output/server/index.mjs", - "lint": "eslint --cache . && biome format .", - "lint:fix": "eslint --cache --fix . && biome format . --write", + "lint": "eslint --cache . && biome check .", + "lint:fix": "eslint --cache --fix . && biome check . --write", "nitro": "JITI_ESM_RESOLVE=1 NODE_OPTIONS=\"--enable-source-maps\" jiti ./src/cli/index.ts", "prepack": "pnpm build", "gen-mirror": "JITI_ESM_RESOLVE=1 pnpm jiti scripts/gen-mirror.ts", diff --git a/scripts/bump-nightly.ts b/scripts/bump-nightly.ts index fa77357f1b..7e7be26a3d 100755 --- a/scripts/bump-nightly.ts +++ b/scripts/bump-nightly.ts @@ -1,7 +1,7 @@ import { promises as fsp } from "node:fs"; import { execaCommand } from "execa"; -import { resolve } from "pathe"; import { globby } from "globby"; +import { resolve } from "pathe"; const nightlyPackages = { h3: "h3-nightly", diff --git a/scripts/gen-mirror.ts b/scripts/gen-mirror.ts index 49e105a3b3..683eba4807 100644 --- a/scripts/gen-mirror.ts +++ b/scripts/gen-mirror.ts @@ -1,9 +1,8 @@ -import { subpaths } from "../build.config"; +import { cp, mkdir, rm, writeFile } from "node:fs/promises"; import { fileURLToPath } from "mlly"; -import { PackageJson, readPackageJSON } from "pkg-types"; -import { writeFile, mkdir, rm, cp } from "node:fs/promises"; import { join } from "pathe"; -import { e } from "crossws/dist/shared/crossws.381454fe"; +import { type PackageJson, readPackageJSON } from "pkg-types"; +import { subpaths } from "../build.config"; const copyPkgFields = [ "description", diff --git a/scripts/gen-presets.ts b/scripts/gen-presets.ts index 930d065ac3..ef47db9d90 100644 --- a/scripts/gen-presets.ts +++ b/scripts/gen-presets.ts @@ -1,11 +1,11 @@ -import createJITI from "jiti"; -import { consola } from "consola"; -import { kebabCase, camelCase, pascalCase, snakeCase } from "scule"; -import { readdirSync, existsSync, writeFileSync, readFileSync } from "node:fs"; +import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; -import type { NitroPreset, NitroPresetMeta } from "nitropack/types"; +import { consola } from "consola"; +import createJITI from "jiti"; import { findTypeExports } from "mlly"; +import type { NitroPreset, NitroPresetMeta } from "nitropack/types"; +import { camelCase, kebabCase, pascalCase, snakeCase } from "scule"; import { subpaths } from "../build.config"; const autoGenHeader = /* ts */ `// Auto-generated using gen-presets script\n`; diff --git a/src/cli/commands/build.ts b/src/cli/commands/build.ts index 6c4c6365bb..343f6dd052 100644 --- a/src/cli/commands/build.ts +++ b/src/cli/commands/build.ts @@ -1,14 +1,14 @@ import { defineCommand } from "citty"; -import { resolve } from "pathe"; +import type { DateString } from "compatx"; import { - createNitro, - prerender, build, - prepare, copyPublicAssets, + createNitro, + prepare, + prerender, } from "nitropack/core"; +import { resolve } from "pathe"; import { commonArgs } from "../common"; -import type { DateString } from "compatx"; export default defineCommand({ meta: { diff --git a/src/cli/commands/dev.ts b/src/cli/commands/dev.ts index 191db56e90..23b09caa2f 100644 --- a/src/cli/commands/dev.ts +++ b/src/cli/commands/dev.ts @@ -1,10 +1,10 @@ import { defineCommand } from "citty"; -import { resolve } from "pathe"; import { consola } from "consola"; import { getArgs, parseArgs } from "listhen/cli"; -import { createNitro, build, prepare, createDevServer } from "nitropack/core"; -import { commonArgs } from "../common"; +import { build, createDevServer, createNitro, prepare } from "nitropack/core"; import type { Nitro } from "nitropack/types"; +import { resolve } from "pathe"; +import { commonArgs } from "../common"; const hmrKeyRe = /^runtimeConfig\.|routeRules\./; diff --git a/src/cli/commands/prepare.ts b/src/cli/commands/prepare.ts index 6d812590bd..a7cb559571 100644 --- a/src/cli/commands/prepare.ts +++ b/src/cli/commands/prepare.ts @@ -1,6 +1,6 @@ import { defineCommand } from "citty"; -import { resolve } from "pathe"; import { createNitro, writeTypes } from "nitropack/core"; +import { resolve } from "pathe"; import { commonArgs } from "../common"; export default defineCommand({ diff --git a/src/cli/commands/task/list.ts b/src/cli/commands/task/list.ts index 6aab75d967..07f1d57ee5 100644 --- a/src/cli/commands/task/list.ts +++ b/src/cli/commands/task/list.ts @@ -1,7 +1,7 @@ import { defineCommand } from "citty"; -import { resolve } from "pathe"; import { consola } from "consola"; import { listTasks } from "nitropack/core"; +import { resolve } from "pathe"; export default defineCommand({ meta: { diff --git a/src/cli/commands/task/run.ts b/src/cli/commands/task/run.ts index e01440f2ee..2f5ae6b47f 100644 --- a/src/cli/commands/task/run.ts +++ b/src/cli/commands/task/run.ts @@ -1,8 +1,8 @@ import { defineCommand } from "citty"; -import { resolve } from "pathe"; -import destr from "destr"; import { consola } from "consola"; +import destr from "destr"; import { runTask } from "nitropack/core"; +import { resolve } from "pathe"; export default defineCommand({ meta: { diff --git a/src/core/build/assets.ts b/src/core/build/assets.ts index 1d622ee693..a6f0c7b255 100644 --- a/src/core/build/assets.ts +++ b/src/core/build/assets.ts @@ -1,8 +1,8 @@ import { existsSync, promises as fsp } from "node:fs"; -import { relative, resolve, join } from "pathe"; import { globby } from "globby"; -import { prettyPath, isDirectory } from "nitropack/kit"; +import { isDirectory, prettyPath } from "nitropack/kit"; import type { Nitro } from "nitropack/types"; +import { join, relative, resolve } from "pathe"; import { compressPublicAssets } from "../utils/compress"; const NEGATION_RE = /^(!?)(.*)$/; diff --git a/src/core/build/dev.ts b/src/core/build/dev.ts index 817f3da03a..bc19cd005a 100644 --- a/src/core/build/dev.ts +++ b/src/core/build/dev.ts @@ -1,13 +1,13 @@ -import { join } from "pathe"; -import * as rollup from "rollup"; import { watch } from "chokidar"; +import defu from "defu"; +import type { Nitro, RollupConfig } from "nitropack/types"; +import { join } from "pathe"; import { debounce } from "perfect-debounce"; +import * as rollup from "rollup"; import { GLOB_SCAN_PATTERN, scanHandlers } from "../scan"; -import type { Nitro, RollupConfig } from "nitropack/types"; -import { writeTypes } from "./types"; -import defu from "defu"; -import { formatRollupError } from "./error"; import { nitroServerName } from "../utils/nitro"; +import { formatRollupError } from "./error"; +import { writeTypes } from "./types"; export async function watchDev(nitro: Nitro, rollupConfig: RollupConfig) { let rollupWatcher: rollup.RollupWatcher; diff --git a/src/core/build/prod.ts b/src/core/build/prod.ts index 8db1ddec27..8ba27e0138 100644 --- a/src/core/build/prod.ts +++ b/src/core/build/prod.ts @@ -1,16 +1,16 @@ import { promises as fsp } from "node:fs"; -import { relative, resolve, join, dirname } from "pathe"; -import * as rollup from "rollup"; -import { generateFSTree } from "../utils/fs-tree"; +import { formatCompatibilityDate } from "compatx"; import { writeFile } from "nitropack/kit"; -import { scanHandlers } from "../scan"; -import type { Nitro, NitroBuildInfo, RollupConfig } from "nitropack/types"; import { version as nitroVersion } from "nitropack/meta"; +import type { Nitro, NitroBuildInfo, RollupConfig } from "nitropack/types"; +import { dirname, join, relative, resolve } from "pathe"; +import * as rollup from "rollup"; +import { scanHandlers } from "../scan"; +import { generateFSTree } from "../utils/fs-tree"; +import { nitroServerName } from "../utils/nitro"; import { snapshotStorage } from "../utils/storage"; import { formatRollupError } from "./error"; import { writeTypes } from "./types"; -import { nitroServerName } from "../utils/nitro"; -import { formatCompatibilityDate } from "compatx"; export async function buildProduction( nitro: Nitro, diff --git a/src/core/build/types.ts b/src/core/build/types.ts index 2527a20d75..3154720e8f 100644 --- a/src/core/build/types.ts +++ b/src/core/build/types.ts @@ -1,19 +1,19 @@ import { existsSync, promises as fsp } from "node:fs"; -import { resolve, join, dirname, isAbsolute } from "pathe"; -import { resolveAlias } from "pathe/utils"; import { defu } from "defu"; import { genTypeImport } from "knitwork"; -import type { TSConfig } from "pkg-types"; import { lookupNodeModuleSubpath, parseNodeModulePath, resolvePath, } from "mlly"; -import { JSValue, generateTypes, resolveSchema } from "untyped"; -import { writeFile, isDirectory, resolveNitroPath } from "nitropack/kit"; -import type { Nitro, NitroTypes } from "nitropack/types"; +import { isDirectory, resolveNitroPath, writeFile } from "nitropack/kit"; import { runtimeDir } from "nitropack/runtime/meta"; +import type { Nitro, NitroTypes } from "nitropack/types"; +import { dirname, isAbsolute, join, resolve } from "pathe"; import { relative } from "pathe"; +import { resolveAlias } from "pathe/utils"; +import type { TSConfig } from "pkg-types"; +import { type JSValue, generateTypes, resolveSchema } from "untyped"; export async function writeTypes(nitro: Nitro) { const types: NitroTypes = { @@ -43,7 +43,7 @@ export async function writeTypes(nitro: Nitro) { } let autoImportedTypes: string[] = []; - let autoImportExports: string = ""; + let autoImportExports = ""; if (nitro.unimport) { await nitro.unimport.init(); diff --git a/src/core/config/defaults.ts b/src/core/config/defaults.ts index 2d4c34ef7a..b69f439ed8 100644 --- a/src/core/config/defaults.ts +++ b/src/core/config/defaults.ts @@ -1,7 +1,7 @@ -import { isTest, isDebug } from "std-env"; -import type { NitroConfig } from "nitropack/types"; -import { resolve, join } from "pathe"; import { runtimeDir } from "nitropack/runtime/meta"; +import type { NitroConfig } from "nitropack/types"; +import { join, resolve } from "pathe"; +import { isDebug, isTest } from "std-env"; export const NitroDefaults: NitroConfig = { // General diff --git a/src/core/config/loader.ts b/src/core/config/loader.ts index 3aef437c56..768614c786 100644 --- a/src/core/config/loader.ts +++ b/src/core/config/loader.ts @@ -1,30 +1,30 @@ import { loadConfig, watchConfig } from "c12"; +import { type CompatibilityDateSpec, resolveCompatibilityDates } from "compatx"; import { klona } from "klona/full"; -import { CompatibilityDateSpec, resolveCompatibilityDates } from "compatx"; +import type { PresetName } from "nitropack/presets"; import type { LoadConfigOptions, NitroConfig, NitroOptions, NitroPresetMeta, } from "nitropack/types"; -import type { PresetName } from "nitropack/presets"; import { NitroDefaults } from "./defaults"; +import { resolveAssetsOptions } from "./resolvers/assets"; // Resolvers import { fallbackCompatibilityDate, resolveCompatibilityOptions, } from "./resolvers/compatibility"; -import { resolvePathOptions } from "./resolvers/paths"; -import { resolveImportsOptions } from "./resolvers/imports"; -import { resolveRouteRulesOptions } from "./resolvers/route-rules"; import { resolveDatabaseOptions } from "./resolvers/database"; -import { resolveFetchOptions } from "./resolvers/fetch"; import { resolveExportConditionsOptions } from "./resolvers/export-conditions"; -import { resolveRuntimeConfigOptions } from "./resolvers/runtime-config"; +import { resolveFetchOptions } from "./resolvers/fetch"; +import { resolveImportsOptions } from "./resolvers/imports"; import { resolveOpenAPIOptions } from "./resolvers/open-api"; -import { resolveAssetsOptions } from "./resolvers/assets"; +import { resolvePathOptions } from "./resolvers/paths"; +import { resolveRouteRulesOptions } from "./resolvers/route-rules"; +import { resolveRuntimeConfigOptions } from "./resolvers/runtime-config"; import { resolveURLOptions } from "./resolvers/url"; const configResolvers = [ diff --git a/src/core/config/resolvers/assets.ts b/src/core/config/resolvers/assets.ts index 9ca4560025..69cd2f37a4 100644 --- a/src/core/config/resolvers/assets.ts +++ b/src/core/config/resolvers/assets.ts @@ -1,8 +1,8 @@ -import { resolve } from "pathe"; import { existsSync } from "node:fs"; -import { withLeadingSlash, withoutTrailingSlash } from "ufo"; import { defu } from "defu"; import type { NitroOptions } from "nitropack/types"; +import { resolve } from "pathe"; +import { withLeadingSlash, withoutTrailingSlash } from "ufo"; export async function resolveAssetsOptions(options: NitroOptions) { // Public Assets diff --git a/src/core/config/resolvers/compatibility.ts b/src/core/config/resolvers/compatibility.ts index 019f0f4063..dd635d8d53 100644 --- a/src/core/config/resolvers/compatibility.ts +++ b/src/core/config/resolvers/compatibility.ts @@ -1,7 +1,7 @@ import { - resolveCompatibilityDatesFromEnv, + type DateString, formatDate, - DateString, + resolveCompatibilityDatesFromEnv, } from "compatx"; import _consola from "consola"; import { colorize } from "consola/utils"; @@ -26,8 +26,8 @@ export async function resolveCompatibilityOptions(options: NitroOptions) { } } -let _fallbackInfoShown: boolean = false; -let _promptedUserToUpdate: boolean = false; +let _fallbackInfoShown = false; +let _promptedUserToUpdate = false; async function _resolveDefault(options: NitroOptions): Promise { const _todayDate = formatDate(new Date()); diff --git a/src/core/config/resolvers/export-conditions.ts b/src/core/config/resolvers/export-conditions.ts index e88d8f6af7..785ae620fc 100644 --- a/src/core/config/resolvers/export-conditions.ts +++ b/src/core/config/resolvers/export-conditions.ts @@ -2,13 +2,13 @@ import type { NitroOptions } from "nitropack/types"; export async function resolveExportConditionsOptions(options: NitroOptions) { options.exportConditions = _resolveExportConditions( - options.exportConditions, + options.exportConditions || [], { dev: options.dev, node: options.node, wasm: options.experimental.wasm } ); } function _resolveExportConditions( - conditions: string[] = [], + conditions: string[], opts: { dev: boolean; node: boolean; wasm?: boolean } ) { const resolvedConditions: string[] = []; diff --git a/src/core/config/resolvers/imports.ts b/src/core/config/resolvers/imports.ts index 4dd2566f22..96bced8264 100644 --- a/src/core/config/resolvers/imports.ts +++ b/src/core/config/resolvers/imports.ts @@ -1,6 +1,6 @@ -import type { NitroOptions } from "nitropack/types"; import escapeRE from "escape-string-regexp"; import { resolveModuleExportNames } from "mlly"; +import type { NitroOptions } from "nitropack/types"; import { join } from "pathe"; import type { Preset } from "unimport"; diff --git a/src/core/config/resolvers/open-api.ts b/src/core/config/resolvers/open-api.ts index 4f82e171d3..88fb464030 100644 --- a/src/core/config/resolvers/open-api.ts +++ b/src/core/config/resolvers/open-api.ts @@ -1,5 +1,5 @@ -import type { NitroOptions } from "nitropack/types"; import { runtimeDir } from "nitropack/runtime/meta"; +import type { NitroOptions } from "nitropack/types"; import { join } from "pathe"; export async function resolveOpenAPIOptions(options: NitroOptions) { diff --git a/src/core/config/resolvers/paths.ts b/src/core/config/resolvers/paths.ts index 8f71d784d1..1729ab98ea 100644 --- a/src/core/config/resolvers/paths.ts +++ b/src/core/config/resolvers/paths.ts @@ -1,10 +1,10 @@ -import { findWorkspaceDir } from "pkg-types"; +import { existsSync } from "node:fs"; import { resolveNitroPath } from "nitropack/kit"; +import { pkgDir } from "nitropack/runtime/meta"; import type { NitroOptions } from "nitropack/types"; -import { resolve, join } from "pathe"; +import { join, resolve } from "pathe"; +import { findWorkspaceDir } from "pkg-types"; import { NitroDefaults } from "../defaults"; -import { pkgDir } from "nitropack/runtime/meta"; -import { existsSync } from "node:fs"; export async function resolvePathOptions(options: NitroOptions) { options.rootDir = resolve(options.rootDir || "."); diff --git a/src/core/config/resolvers/runtime-config.ts b/src/core/config/resolvers/runtime-config.ts index aaa385ad58..ec19ccb4b8 100644 --- a/src/core/config/resolvers/runtime-config.ts +++ b/src/core/config/resolvers/runtime-config.ts @@ -1,7 +1,7 @@ import defu from "defu"; import type { - NitroOptions, NitroConfig, + NitroOptions, NitroRuntimeConfig, } from "nitropack/types"; diff --git a/src/core/config/update.ts b/src/core/config/update.ts index 42d3093e5c..3702a0db76 100644 --- a/src/core/config/update.ts +++ b/src/core/config/update.ts @@ -1,7 +1,7 @@ +import consola from "consola"; import type { Nitro, NitroDynamicConfig } from "nitropack/types"; import { normalizeRouteRules } from "./resolvers/route-rules"; import { normalizeRuntimeConfig } from "./resolvers/runtime-config"; -import consola from "consola"; export async function updateNitroConfig( nitro: Nitro, diff --git a/src/core/dev-server/error.ts b/src/core/dev-server/error.ts index 1b60610fe1..9ec1ad71f4 100644 --- a/src/core/dev-server/error.ts +++ b/src/core/dev-server/error.ts @@ -1,12 +1,12 @@ import { - H3Event, - setResponseHeader, - setResponseStatus, + type H3Event, getResponseStatus, getResponseStatusText, send, + setResponseHeader, + setResponseStatus, } from "h3"; -import { NitroErrorHandler } from "nitropack/types"; +import type { NitroErrorHandler } from "nitropack/types"; function errorHandler(error: any, event: H3Event) { setResponseHeader(event, "Content-Type", "text/html; charset=UTF-8"); diff --git a/src/core/dev-server/server.ts b/src/core/dev-server/server.ts index 55bc7d45ed..ab5044fabb 100644 --- a/src/core/dev-server/server.ts +++ b/src/core/dev-server/server.ts @@ -1,35 +1,35 @@ -import { Worker } from "node:worker_threads"; -import { existsSync, accessSync, promises as fsp } from "node:fs"; +import { accessSync, existsSync, promises as fsp } from "node:fs"; import { writeFile } from "node:fs/promises"; -import { TLSSocket } from "node:tls"; -import { debounce } from "perfect-debounce"; +import type { IncomingMessage, OutgoingMessage } from "node:http"; +import type { Duplex } from "node:stream"; +import type { TLSSocket } from "node:tls"; +import { Worker } from "node:worker_threads"; +import { type FSWatcher, watch } from "chokidar"; import { + type H3Error, + type H3Event, createApp, createError, eventHandler, fromNodeMiddleware, - H3Error, - H3Event, toNodeListener, } from "h3"; -import { createProxyServer, ProxyServerOptions } from "httpxy"; -import { listen, Listener } from "listhen"; -import { servePlaceholder } from "serve-placeholder"; -import serveStatic from "serve-static"; -import { resolve } from "pathe"; -import { joinURL } from "ufo"; -import { FSWatcher, watch } from "chokidar"; +import { type ProxyServerOptions, createProxyServer } from "httpxy"; +import { type Listener, listen } from "listhen"; +import { version as nitroVersion } from "nitropack/meta"; import type { Nitro, NitroBuildInfo, NitroDevServer, NitroWorker, } from "nitropack/types"; -import { createVFSHandler } from "./vfs"; +import { resolve } from "pathe"; +import { debounce } from "perfect-debounce"; +import { servePlaceholder } from "serve-placeholder"; +import serveStatic from "serve-static"; +import { joinURL } from "ufo"; import defaultErrorHandler from "./error"; -import type { IncomingMessage, OutgoingMessage } from "node:http"; -import type { Duplex } from "node:stream"; -import { version as nitroVersion } from "nitropack/meta"; +import { createVFSHandler } from "./vfs"; function initWorker(filename: string): Promise | undefined { if (!existsSync(filename)) { diff --git a/src/core/nitro.ts b/src/core/nitro.ts index 594ac959f4..62f4bade0c 100644 --- a/src/core/nitro.ts +++ b/src/core/nitro.ts @@ -1,20 +1,20 @@ -import { createHooks, createDebugger } from "hookable"; -import { createUnimport } from "unimport"; import { consola } from "consola"; +import { createDebugger, createHooks } from "hookable"; +import { runtimeDir } from "nitropack/runtime/meta"; import type { + LoadConfigOptions, + Nitro, NitroConfig, NitroDynamicConfig, - Nitro, - LoadConfigOptions, } from "nitropack/types"; +import { join } from "pathe"; +import { createUnimport } from "unimport"; import { loadOptions } from "./config/loader"; -import { createStorage } from "./utils/storage"; -import { installModules } from "./module"; import { updateNitroConfig } from "./config/update"; -import { addNitroTasksVirtualFile } from "./task"; +import { installModules } from "./module"; import { scanAndSyncOptions } from "./scan"; -import { join } from "pathe"; -import { runtimeDir } from "nitropack/runtime/meta"; +import { addNitroTasksVirtualFile } from "./task"; +import { createStorage } from "./utils/storage"; export async function createNitro( config: NitroConfig = {}, diff --git a/src/core/prerender/prerender.ts b/src/core/prerender/prerender.ts index 40d5372f32..52fc493bfb 100644 --- a/src/core/prerender/prerender.ts +++ b/src/core/prerender/prerender.ts @@ -1,15 +1,15 @@ import { pathToFileURL } from "node:url"; -import { resolve, join, relative } from "pathe"; -import { joinURL, withBase, withoutBase } from "ufo"; import chalk from "chalk"; -import { createRouter as createRadixRouter, toRouteMatcher } from "radix3"; import { defu } from "defu"; import mime from "mime"; +import { writeFile } from "nitropack/kit"; +import type { Nitro, NitroRouteRules, PrerenderRoute } from "nitropack/types"; import type { $Fetch } from "ofetch"; -import { createNitro } from "../nitro"; +import { join, relative, resolve } from "pathe"; +import { createRouter as createRadixRouter, toRouteMatcher } from "radix3"; +import { joinURL, withBase, withoutBase } from "ufo"; import { build } from "../build/build"; -import type { Nitro, NitroRouteRules, PrerenderRoute } from "nitropack/types"; -import { writeFile } from "nitropack/kit"; +import { createNitro } from "../nitro"; import { compressPublicAssets } from "../utils/compress"; import { extractLinks, diff --git a/src/core/prerender/utils.ts b/src/core/prerender/utils.ts index a2ca04e212..1aa3439e68 100644 --- a/src/core/prerender/utils.ts +++ b/src/core/prerender/utils.ts @@ -1,6 +1,6 @@ -import { parseURL } from "ufo"; import chalk from "chalk"; import type { PrerenderRoute } from "nitropack/types"; +import { parseURL } from "ufo"; const allowedExtensions = new Set(["", ".json"]); diff --git a/src/core/scan.ts b/src/core/scan.ts index dcae4024c5..8439e6562c 100644 --- a/src/core/scan.ts +++ b/src/core/scan.ts @@ -1,7 +1,7 @@ -import { relative, join } from "pathe"; import { globby } from "globby"; -import { withBase, withLeadingSlash, withoutTrailingSlash } from "ufo"; import type { Nitro } from "nitropack/types"; +import { join, relative } from "pathe"; +import { withBase, withLeadingSlash, withoutTrailingSlash } from "ufo"; export const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}"; type FileInfo = { path: string; fullPath: string }; diff --git a/src/core/task.ts b/src/core/task.ts index bf1528724c..b4da412cf5 100644 --- a/src/core/task.ts +++ b/src/core/task.ts @@ -1,13 +1,13 @@ import { existsSync } from "node:fs"; import { readFile } from "node:fs/promises"; -import { resolve, normalize } from "pathe"; -import { ofetch } from "ofetch"; import type { + Nitro, NitroBuildInfo, - TaskRunnerOptions, TaskEvent, - Nitro, + TaskRunnerOptions, } from "nitropack/types"; +import { ofetch } from "ofetch"; +import { normalize, resolve } from "pathe"; /** @experimental */ export async function runTask( diff --git a/src/core/utils/compress.ts b/src/core/utils/compress.ts index a9d96d4a87..c11f1babc6 100644 --- a/src/core/utils/compress.ts +++ b/src/core/utils/compress.ts @@ -1,10 +1,10 @@ -import zlib from "node:zlib"; -import fsp from "node:fs/promises"; import { existsSync } from "node:fs"; +import fsp from "node:fs/promises"; +import zlib from "node:zlib"; import { globby } from "globby"; -import { resolve } from "pathe"; import mime from "mime"; import type { Nitro } from "nitropack/types"; +import { resolve } from "pathe"; export async function compressPublicAssets(nitro: Nitro) { const publicFiles = await globby("**", { diff --git a/src/core/utils/fs-tree.ts b/src/core/utils/fs-tree.ts index a2f3391e9d..55d24c33a7 100644 --- a/src/core/utils/fs-tree.ts +++ b/src/core/utils/fs-tree.ts @@ -1,9 +1,9 @@ import { promises as fsp } from "node:fs"; -import { resolve, dirname, relative } from "pathe"; +import chalk from "chalk"; import { globby } from "globby"; -import prettyBytes from "pretty-bytes"; import { gzipSize } from "gzip-size"; -import chalk from "chalk"; +import { dirname, relative, resolve } from "pathe"; +import prettyBytes from "pretty-bytes"; import { isTest } from "std-env"; export async function generateFSTree( diff --git a/src/core/utils/nitro.ts b/src/core/utils/nitro.ts index 1240a6cea8..4cc8aafd6b 100644 --- a/src/core/utils/nitro.ts +++ b/src/core/utils/nitro.ts @@ -1,5 +1,5 @@ +import type { Nitro } from "nitropack/types"; import { upperFirst } from "scule"; -import { Nitro } from "nitropack/types"; export function nitroServerName(nitro: Nitro) { return nitro.options.framework.name === "nitro" diff --git a/src/core/utils/storage.ts b/src/core/utils/storage.ts index e7f796de6b..476531e5e5 100644 --- a/src/core/utils/storage.ts +++ b/src/core/utils/storage.ts @@ -1,5 +1,5 @@ -import { createStorage as _createStorage, builtinDrivers } from "unstorage"; import type { Nitro } from "nitropack/types"; +import { createStorage as _createStorage, builtinDrivers } from "unstorage"; export async function createStorage(nitro: Nitro) { const storage = _createStorage(); diff --git a/src/kit/fs.ts b/src/kit/fs.ts index 4b6c0a3b2d..7d3d50ce8a 100644 --- a/src/kit/fs.ts +++ b/src/kit/fs.ts @@ -1,6 +1,6 @@ import fsp from "node:fs/promises"; -import { dirname } from "pathe"; import { consola } from "consola"; +import { dirname } from "pathe"; import { prettyPath } from "./path"; export async function writeFile( diff --git a/src/kit/module.ts b/src/kit/module.ts index a6a8cdfa8e..76f524975c 100644 --- a/src/kit/module.ts +++ b/src/kit/module.ts @@ -1,4 +1,4 @@ -import { NitroModule } from "../types/module"; +import type { NitroModule } from "../types/module"; export function defineNitroModule(def: NitroModule): NitroModule { if (typeof def?.setup !== "function") { diff --git a/src/kit/path.ts b/src/kit/path.ts index 4ca7dfde0d..930978aed1 100644 --- a/src/kit/path.ts +++ b/src/kit/path.ts @@ -1,8 +1,8 @@ -import { relative, resolve } from "pathe"; -import { Nitro } from "nitropack/types"; -import { getProperty } from "dot-prop"; import consola from "consola"; import { colorize } from "consola/utils"; +import { getProperty } from "dot-prop"; +import type { Nitro } from "nitropack/types"; +import { relative, resolve } from "pathe"; export function prettyPath(p: string, highlight = true) { p = relative(process.cwd(), p); diff --git a/src/kit/preset.ts b/src/kit/preset.ts index 427f75cdb7..8a10b39740 100644 --- a/src/kit/preset.ts +++ b/src/kit/preset.ts @@ -1,5 +1,5 @@ -import type { NitroPreset, NitroPresetMeta } from "nitropack/types"; import { fileURLToPath } from "node:url"; +import type { NitroPreset, NitroPresetMeta } from "nitropack/types"; export function defineNitroPreset< P extends NitroPreset, diff --git a/src/presets/_nitro/runtime/nitro-dev.ts b/src/presets/_nitro/runtime/nitro-dev.ts index fd68d21ad6..be1ecd83f5 100644 --- a/src/presets/_nitro/runtime/nitro-dev.ts +++ b/src/presets/_nitro/runtime/nitro-dev.ts @@ -1,24 +1,24 @@ import "#nitro-internal-pollyfills"; import { useNitroApp } from "nitropack/runtime"; -import { trapUnhandledNodeErrors } from "nitropack/runtime/internal"; import { runTask } from "nitropack/runtime"; +import { trapUnhandledNodeErrors } from "nitropack/runtime/internal"; import { startScheduleRunner } from "nitropack/runtime/internal"; -import { tasks, scheduledTasks } from "#nitro-internal-virtual/tasks"; +import { scheduledTasks, tasks } from "#nitro-internal-virtual/tasks"; +import { mkdirSync } from "node:fs"; import { Server } from "node:http"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { mkdirSync } from "node:fs"; -import { threadId, parentPort } from "node:worker_threads"; -import { isWindows, provider } from "std-env"; +import { parentPort, threadId } from "node:worker_threads"; +import wsAdapter from "crossws/adapters/node"; import { defineEventHandler, getQuery, getRouterParam, - toNodeListener, readBody, + toNodeListener, } from "h3"; -import wsAdapter from "crossws/adapters/node"; +import { isWindows, provider } from "std-env"; const nitroApp = useNitroApp(); @@ -40,11 +40,10 @@ function getAddress() { const socketName = `worker-${process.pid}-${threadId}.sock`; if (isWindows) { return join(String.raw`\\.\pipe\nitro`, socketName); - } else { - const socketDir = join(tmpdir(), "nitro"); - mkdirSync(socketDir, { recursive: true }); - return join(socketDir, socketName); } + const socketDir = join(tmpdir(), "nitro"); + mkdirSync(socketDir, { recursive: true }); + return join(socketDir, socketName); } const listenAddress = getAddress(); diff --git a/src/presets/_nitro/service-worker.ts b/src/presets/_nitro/service-worker.ts index 5206d4962a..92fc15e0e8 100644 --- a/src/presets/_nitro/service-worker.ts +++ b/src/presets/_nitro/service-worker.ts @@ -1,8 +1,8 @@ import { existsSync, promises as fsp } from "node:fs"; -import { resolve } from "pathe"; -import { joinURL } from "ufo"; import { defineNitroPreset } from "nitropack/kit"; import type { Nitro } from "nitropack/types"; +import { resolve } from "pathe"; +import { joinURL } from "ufo"; const serviceWorker = defineNitroPreset( () => { diff --git a/src/presets/_resolve.ts b/src/presets/_resolve.ts index 2fa31421bf..07e7fb26d2 100644 --- a/src/presets/_resolve.ts +++ b/src/presets/_resolve.ts @@ -1,12 +1,12 @@ -import type { NitroPreset, NitroPresetMeta } from "nitropack/types"; -import { kebabCase } from "scule"; -import { provider, type ProviderName } from "std-env"; -import allPresets from "./_all.gen"; import { - resolveCompatibilityDatesFromEnv, type CompatibilityDateSpec, type PlatformName, + resolveCompatibilityDatesFromEnv, } from "compatx"; +import type { NitroPreset, NitroPresetMeta } from "nitropack/types"; +import { kebabCase } from "scule"; +import { type ProviderName, provider } from "std-env"; +import allPresets from "./_all.gen"; // std-env has more specific keys for providers than compatx const _stdProviderMap: Partial> = { diff --git a/src/presets/_static/preset.ts b/src/presets/_static/preset.ts index b914abfbaf..e3e039fd63 100644 --- a/src/presets/_static/preset.ts +++ b/src/presets/_static/preset.ts @@ -1,5 +1,5 @@ -import { defineNitroPreset } from "nitropack/kit"; import fsp from "node:fs/promises"; +import { defineNitroPreset } from "nitropack/kit"; import { join } from "pathe"; const _static = defineNitroPreset( diff --git a/src/presets/_types.gen.ts b/src/presets/_types.gen.ts index c63dde81d4..3ee32c8a66 100644 --- a/src/presets/_types.gen.ts +++ b/src/presets/_types.gen.ts @@ -1,11 +1,11 @@ // Auto-generated using gen-presets script -import { PresetOptions as AwsAmplifyOptions } from "./aws-amplify/preset"; -import { PresetOptions as AzureOptions } from "./azure/preset"; -import { PresetOptions as CloudflareOptions } from "./cloudflare/preset"; -import { PresetOptions as FirebaseOptions } from "./firebase/preset"; -import { PresetOptions as NetlifyOptions } from "./netlify/preset"; -import { PresetOptions as VercelOptions } from "./vercel/preset"; +import type { PresetOptions as AwsAmplifyOptions } from "./aws-amplify/preset"; +import type { PresetOptions as AzureOptions } from "./azure/preset"; +import type { PresetOptions as CloudflareOptions } from "./cloudflare/preset"; +import type { PresetOptions as FirebaseOptions } from "./firebase/preset"; +import type { PresetOptions as NetlifyOptions } from "./netlify/preset"; +import type { PresetOptions as VercelOptions } from "./vercel/preset"; export interface PresetOptions { awsAmplify: AwsAmplifyOptions; diff --git a/src/presets/aws-amplify/utils.ts b/src/presets/aws-amplify/utils.ts index 1e8f17535d..02430f56ed 100644 --- a/src/presets/aws-amplify/utils.ts +++ b/src/presets/aws-amplify/utils.ts @@ -1,7 +1,7 @@ -import { resolve } from "node:path"; import { writeFile } from "node:fs/promises"; -import { joinURL } from "ufo"; +import { resolve } from "node:path"; import type { Nitro } from "nitropack/types"; +import { joinURL } from "ufo"; import type { AmplifyDeployManifest, AmplifyRoute, diff --git a/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts b/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts index 2d493e6b46..50f54f33fa 100644 --- a/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts +++ b/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts @@ -1,15 +1,15 @@ import type { APIGatewayProxyEventV2, - Context, APIGatewayProxyStructuredResultV2, + Context, } from "aws-lambda"; import "#nitro-internal-pollyfills"; -import { withQuery } from "ufo"; import { useNitroApp } from "nitropack/runtime"; import { normalizeLambdaIncomingHeaders, normalizeLambdaOutgoingHeaders, } from "nitropack/runtime/internal"; +import { withQuery } from "ufo"; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace diff --git a/src/presets/aws-lambda/runtime/aws-lambda.ts b/src/presets/aws-lambda/runtime/aws-lambda.ts index 67424fce2c..d9d3372515 100644 --- a/src/presets/aws-lambda/runtime/aws-lambda.ts +++ b/src/presets/aws-lambda/runtime/aws-lambda.ts @@ -6,14 +6,14 @@ import type { Context, } from "aws-lambda"; import "#nitro-internal-pollyfills"; -import { withQuery } from "ufo"; import { useNitroApp } from "nitropack/runtime"; import { + normalizeCookieHeader, normalizeLambdaIncomingHeaders, normalizeLambdaOutgoingBody, normalizeLambdaOutgoingHeaders, - normalizeCookieHeader, } from "nitropack/runtime/internal"; +import { withQuery } from "ufo"; const nitroApp = useNitroApp(); diff --git a/src/presets/azure/runtime/azure-swa.ts b/src/presets/azure/runtime/azure-swa.ts index 2658e5bdb4..861c9ab9e9 100644 --- a/src/presets/azure/runtime/azure-swa.ts +++ b/src/presets/azure/runtime/azure-swa.ts @@ -5,7 +5,7 @@ import { normalizeLambdaOutgoingHeaders, } from "nitropack/runtime/internal"; -import type { HttpResponse, HttpRequest } from "@azure/functions"; +import type { HttpRequest, HttpResponse } from "@azure/functions"; import { parseURL } from "ufo"; const nitroApp = useNitroApp(); diff --git a/src/presets/azure/utils.ts b/src/presets/azure/utils.ts index 83e869966e..dcb9c03b65 100644 --- a/src/presets/azure/utils.ts +++ b/src/presets/azure/utils.ts @@ -1,9 +1,9 @@ import { createWriteStream } from "node:fs"; +import fsp from "node:fs/promises"; import archiver from "archiver"; -import { join, resolve } from "pathe"; import { writeFile } from "nitropack/kit"; import type { Nitro } from "nitropack/types"; -import fsp from "node:fs/promises"; +import { join, resolve } from "pathe"; export async function writeFunctionsRoutes(nitro: Nitro) { const host = { diff --git a/src/presets/cloudflare/preset.ts b/src/presets/cloudflare/preset.ts index 8a2f44a175..0aad2c5a41 100644 --- a/src/presets/cloudflare/preset.ts +++ b/src/presets/cloudflare/preset.ts @@ -1,8 +1,8 @@ import { defineNitroPreset } from "nitropack/kit"; -import type { Nitro } from "nitropack/types"; -import { writeCFPagesFiles, writeCFPagesStaticFiles } from "./utils"; import { writeFile } from "nitropack/kit"; +import type { Nitro } from "nitropack/types"; import { resolve } from "pathe"; +import { writeCFPagesFiles, writeCFPagesStaticFiles } from "./utils"; export type { CloudflareOptions as PresetOptions } from "./types"; diff --git a/src/presets/cloudflare/runtime/cloudflare-module.ts b/src/presets/cloudflare/runtime/cloudflare-module.ts index c0bc0d3ca6..c84a625f40 100644 --- a/src/presets/cloudflare/runtime/cloudflare-module.ts +++ b/src/presets/cloudflare/runtime/cloudflare-module.ts @@ -1,15 +1,15 @@ import "#nitro-internal-pollyfills"; -import { requestHasBody, runCronTasks } from "nitropack/runtime/internal"; import { useNitroApp, useRuntimeConfig } from "nitropack/runtime"; +import { requestHasBody, runCronTasks } from "nitropack/runtime/internal"; import { getPublicAssetMeta } from "#nitro-internal-virtual/public-assets"; -import { withoutBase } from "ufo"; -import wsAdapter from "crossws/adapters/cloudflare"; -import type { ExecutionContext } from "@cloudflare/workers-types"; import { getAssetFromKV, mapRequestToAsset, } from "@cloudflare/kv-asset-handler"; +import type { ExecutionContext } from "@cloudflare/workers-types"; +import wsAdapter from "crossws/adapters/cloudflare"; +import { withoutBase } from "ufo"; import type { CloudflareEmailContext, CloudflareMessageBatch } from "../types"; diff --git a/src/presets/cloudflare/runtime/cloudflare-pages.ts b/src/presets/cloudflare/runtime/cloudflare-pages.ts index 4745391fd3..acef0e57b9 100644 --- a/src/presets/cloudflare/runtime/cloudflare-pages.ts +++ b/src/presets/cloudflare/runtime/cloudflare-pages.ts @@ -1,14 +1,14 @@ import "#nitro-internal-pollyfills"; -import { runCronTasks, requestHasBody } from "nitropack/runtime/internal"; import { useNitroApp } from "nitropack/runtime"; +import { requestHasBody, runCronTasks } from "nitropack/runtime/internal"; import { isPublicAssetURL } from "#nitro-internal-virtual/public-assets"; -import wsAdapter from "crossws/adapters/cloudflare"; import type { Request as CFRequest, EventContext, ExecutionContext, } from "@cloudflare/workers-types"; +import wsAdapter from "crossws/adapters/cloudflare"; /** * Reference: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#parameters diff --git a/src/presets/cloudflare/runtime/cloudflare-worker.ts b/src/presets/cloudflare/runtime/cloudflare-worker.ts index 494a5ae3c2..54a14ed276 100644 --- a/src/presets/cloudflare/runtime/cloudflare-worker.ts +++ b/src/presets/cloudflare/runtime/cloudflare-worker.ts @@ -1,14 +1,14 @@ import "#nitro-internal-pollyfills"; -import { requestHasBody } from "nitropack/runtime/internal"; import { useNitroApp, useRuntimeConfig } from "nitropack/runtime"; +import { requestHasBody } from "nitropack/runtime/internal"; import { getPublicAssetMeta } from "#nitro-internal-virtual/public-assets"; -import { withoutBase } from "ufo"; -import wsAdapter from "crossws/adapters/cloudflare"; import { getAssetFromKV, mapRequestToAsset, } from "@cloudflare/kv-asset-handler"; +import wsAdapter from "crossws/adapters/cloudflare"; +import { withoutBase } from "ufo"; addEventListener("fetch", (event: any) => { event.respondWith(handleEvent(event)); diff --git a/src/presets/cloudflare/types.ts b/src/presets/cloudflare/types.ts index b8176c30e0..1edc926141 100644 --- a/src/presets/cloudflare/types.ts +++ b/src/presets/cloudflare/types.ts @@ -1,5 +1,5 @@ -import type { Config as WranglerConfig } from "./types.wrangler"; import type { ExecutionContext } from "@cloudflare/workers-types"; +import type { Config as WranglerConfig } from "./types.wrangler"; /** * https://developers.cloudflare.com/pages/platform/functions/routing/#functions-invocation-routes diff --git a/src/presets/cloudflare/utils.ts b/src/presets/cloudflare/utils.ts index 38f45207d5..743c00e106 100644 --- a/src/presets/cloudflare/utils.ts +++ b/src/presets/cloudflare/utils.ts @@ -1,16 +1,16 @@ import { existsSync, promises as fsp } from "node:fs"; -import { resolve, join } from "pathe"; +import { parseTOML, stringifyTOML } from "confbox"; +import defu from "defu"; +import { globby } from "globby"; +import type { Nitro } from "nitropack/types"; +import { join, resolve } from "pathe"; +import { isCI } from "std-env"; import { joinURL, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, } from "ufo"; -import { parseTOML, stringifyTOML } from "confbox"; -import { globby } from "globby"; -import type { Nitro } from "nitropack/types"; -import defu from "defu"; -import { isCI } from "std-env"; import type { CloudflarePagesRoutes } from "./types"; export async function writeCFPagesFiles(nitro: Nitro) { diff --git a/src/presets/deno/preset.ts b/src/presets/deno/preset.ts index 81ebc22b42..93e66dc1b0 100644 --- a/src/presets/deno/preset.ts +++ b/src/presets/deno/preset.ts @@ -1,9 +1,9 @@ import { builtinModules } from "node:module"; -import { isAbsolute, resolve } from "pathe"; import MagicString from "magic-string"; import { findStaticImports } from "mlly"; import { defineNitroPreset } from "nitropack/kit"; import { writeFile } from "nitropack/kit"; +import { isAbsolute, resolve } from "pathe"; // nitro/src/rollup/plugin/import-meta.ts const ImportMetaRe = /import\.meta|globalThis._importMeta_/; diff --git a/src/presets/deno/runtime/deno-deploy.ts b/src/presets/deno/runtime/deno-deploy.ts index b4245821b4..daa3e28160 100644 --- a/src/presets/deno/runtime/deno-deploy.ts +++ b/src/presets/deno/runtime/deno-deploy.ts @@ -2,8 +2,8 @@ import "#nitro-internal-pollyfills"; import "./_deno-env-polyfill"; import { useNitroApp } from "nitropack/runtime"; -import wsAdapter from "crossws/adapters/deno"; import type { Deno as _Deno } from "@deno/types"; +import wsAdapter from "crossws/adapters/deno"; const nitroApp = useNitroApp(); diff --git a/src/presets/deno/runtime/deno-server.ts b/src/presets/deno/runtime/deno-server.ts index 06ac843d47..352b531066 100644 --- a/src/presets/deno/runtime/deno-server.ts +++ b/src/presets/deno/runtime/deno-server.ts @@ -4,9 +4,9 @@ import { useNitroApp } from "nitropack/runtime"; import { useRuntimeConfig } from "nitropack/runtime"; import { startScheduleRunner } from "nitropack/runtime/internal"; -import destr from "destr"; -import wsAdapter from "crossws/adapters/deno"; import type { Deno as _Deno } from "@deno/types"; +import wsAdapter from "crossws/adapters/deno"; +import destr from "destr"; // TODO: Declare conflict with crossws // declare global { diff --git a/src/presets/edgio/preset.ts b/src/presets/edgio/preset.ts index f3c8a5fa8d..c44dbc9ac0 100644 --- a/src/presets/edgio/preset.ts +++ b/src/presets/edgio/preset.ts @@ -1,7 +1,7 @@ import { promises as fsp } from "node:fs"; -import { resolve, dirname } from "pathe"; -import type { PackageJson } from "pkg-types"; import { defineNitroPreset } from "nitropack/kit"; +import { dirname, resolve } from "pathe"; +import type { PackageJson } from "pkg-types"; const edgio = defineNitroPreset( { diff --git a/src/presets/firebase/preset.ts b/src/presets/firebase/preset.ts index 9c19b254d8..f7af8a5345 100644 --- a/src/presets/firebase/preset.ts +++ b/src/presets/firebase/preset.ts @@ -1,6 +1,6 @@ +import { defineNitroPreset } from "nitropack/kit"; import { basename } from "pathe"; import type { Plugin } from "rollup"; -import { defineNitroPreset } from "nitropack/kit"; import { updatePackageJSON, writeFirebaseConfig } from "./utils"; export type { FirebaseOptions as PresetOptions } from "./types"; diff --git a/src/presets/firebase/types.ts b/src/presets/firebase/types.ts index 722331b946..3fe683cdd3 100644 --- a/src/presets/firebase/types.ts +++ b/src/presets/firebase/types.ts @@ -1,5 +1,5 @@ -import type { HttpsOptions } from "firebase-functions/v2/https"; import type { RuntimeOptions, region } from "firebase-functions"; +import type { HttpsOptions } from "firebase-functions/v2/https"; export type FirebaseOptions = FirebaseOptionsGen1 | FirebaseOptionsGen2; diff --git a/src/presets/firebase/utils.ts b/src/presets/firebase/utils.ts index 2c47b526b7..eafac0b0c4 100644 --- a/src/presets/firebase/utils.ts +++ b/src/presets/firebase/utils.ts @@ -1,8 +1,8 @@ import { existsSync } from "node:fs"; -import { join, relative } from "pathe"; -import { readPackageJSON, writePackageJSON } from "pkg-types"; import { writeFile } from "nitropack/kit"; import type { Nitro } from "nitropack/types"; +import { join, relative } from "pathe"; +import { readPackageJSON, writePackageJSON } from "pkg-types"; export async function writeFirebaseConfig(nitro: Nitro) { const firebaseConfigPath = join(nitro.options.rootDir, "firebase.json"); diff --git a/src/presets/iis/utils.ts b/src/presets/iis/utils.ts index 7cb5a408d0..28ecb015d8 100644 --- a/src/presets/iis/utils.ts +++ b/src/presets/iis/utils.ts @@ -1,9 +1,9 @@ +import { existsSync } from "node:fs"; import { readFile } from "node:fs/promises"; import { defu } from "defu"; -import type { Nitro } from "nitropack/types"; import { writeFile } from "nitropack/kit"; +import type { Nitro } from "nitropack/types"; import { resolve } from "pathe"; -import { existsSync } from "node:fs"; export async function writeIISFiles(nitro: Nitro) { await writeFile( @@ -106,7 +106,8 @@ async function iisnodeXmlTemplate(nitro: Nitro) { if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) { return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig)); - } else if (nitro.options.iis?.overrideConfig) { + } + if (nitro.options.iis?.overrideConfig) { return buildNewXmlDoc({ ...fileWebConfig }); } } @@ -139,7 +140,8 @@ async function iisXmlTemplate(nitro: Nitro) { if (nitro.options.iis?.mergeConfig && !nitro.options.iis.overrideConfig) { return buildNewXmlDoc(defu(fileWebConfig, originalWebConfig)); - } else if (nitro.options.iis?.overrideConfig) { + } + if (nitro.options.iis?.overrideConfig) { return buildNewXmlDoc({ ...fileWebConfig }); } } diff --git a/src/presets/netlify/legacy/preset.ts b/src/presets/netlify/legacy/preset.ts index e442566a1a..bb6768c0d4 100644 --- a/src/presets/netlify/legacy/preset.ts +++ b/src/presets/netlify/legacy/preset.ts @@ -1,7 +1,7 @@ import { existsSync, promises as fsp } from "node:fs"; -import { join, dirname } from "pathe"; import { defineNitroPreset } from "nitropack/kit"; import type { Nitro } from "nitropack/types"; +import { dirname, join } from "pathe"; import { deprecateSWR, writeHeaders, writeRedirects } from "./utils"; // Netlify functions diff --git a/src/presets/netlify/legacy/runtime/netlify-lambda.ts b/src/presets/netlify/legacy/runtime/netlify-lambda.ts index b56680a78c..1ea3d34aca 100644 --- a/src/presets/netlify/legacy/runtime/netlify-lambda.ts +++ b/src/presets/netlify/legacy/runtime/netlify-lambda.ts @@ -8,12 +8,12 @@ import { normalizeLambdaOutgoingHeaders, } from "nitropack/runtime/internal"; -import { withQuery } from "ufo"; import type { - HandlerResponse, HandlerContext, HandlerEvent, + HandlerResponse, } from "@netlify/functions"; +import { withQuery } from "ufo"; const nitroApp = useNitroApp(); diff --git a/src/presets/netlify/legacy/runtime/netlify.ts b/src/presets/netlify/legacy/runtime/netlify.ts index c753f0052b..e920e125f7 100644 --- a/src/presets/netlify/legacy/runtime/netlify.ts +++ b/src/presets/netlify/legacy/runtime/netlify.ts @@ -1,8 +1,8 @@ import "#nitro-internal-pollyfills"; import "./_deno-env-polyfill"; +import type { Handler } from "@netlify/functions/dist/main"; import { getRouteRulesForPath } from "nitropack/runtime/internal"; import { withQuery } from "ufo"; -import type { Handler } from "@netlify/functions/dist/main"; import { lambda } from "./netlify-lambda"; export const handler: Handler = async function handler(event, context) { diff --git a/src/presets/netlify/legacy/utils.ts b/src/presets/netlify/legacy/utils.ts index f67c93ea83..107f0c0d87 100644 --- a/src/presets/netlify/legacy/utils.ts +++ b/src/presets/netlify/legacy/utils.ts @@ -1,6 +1,6 @@ import { existsSync, promises as fsp } from "node:fs"; -import { join } from "pathe"; import type { Nitro } from "nitropack/types"; +import { join } from "pathe"; export async function writeRedirects(nitro: Nitro) { const redirectsPath = join(nitro.options.output.publicDir, "_redirects"); @@ -119,7 +119,7 @@ export function deprecateSWR(nitro: Nitro) { value.isr = !(value as { static: boolean }).static; hasLegacyOptions = true; } - if (value && value.cache && _hasProp(value.cache, "swr")) { + if (value?.cache && _hasProp(value.cache, "swr")) { value.isr = value.cache.swr; hasLegacyOptions = true; } diff --git a/src/presets/netlify/preset.ts b/src/presets/netlify/preset.ts index 7c5f4ce657..e8d2001b56 100644 --- a/src/presets/netlify/preset.ts +++ b/src/presets/netlify/preset.ts @@ -1,14 +1,14 @@ import { promises as fsp } from "node:fs"; -import { join, dirname } from "pathe"; import { defineNitroPreset } from "nitropack/kit"; import type { Nitro } from "nitropack/types"; +import { dirname, join } from "pathe"; +import netlifyLegacyPresets from "./legacy/preset"; import { generateNetlifyFunction, getGeneratorString, writeHeaders, writeRedirects, } from "./utils"; -import netlifyLegacyPresets from "./legacy/preset"; export type { NetlifyOptions as PresetOptions } from "./types"; diff --git a/src/presets/netlify/utils.ts b/src/presets/netlify/utils.ts index 25bfe265dc..b5c9d3ba8e 100644 --- a/src/presets/netlify/utils.ts +++ b/src/presets/netlify/utils.ts @@ -1,6 +1,6 @@ import { existsSync, promises as fsp } from "node:fs"; -import { join } from "pathe"; import type { Nitro } from "nitropack/types"; +import { join } from "pathe"; export async function writeRedirects(nitro: Nitro) { const redirectsPath = join(nitro.options.output.publicDir, "_redirects"); diff --git a/src/presets/node/runtime/cluster.ts b/src/presets/node/runtime/cluster.ts index aa81e9c1f2..1b6cfe5499 100644 --- a/src/presets/node/runtime/cluster.ts +++ b/src/presets/node/runtime/cluster.ts @@ -1,8 +1,8 @@ -import os from "node:os"; import cluster from "node:cluster"; +import os from "node:os"; import { - trapUnhandledNodeErrors, getGracefulShutdownConfig, + trapUnhandledNodeErrors, } from "nitropack/runtime/internal"; function runMaster() { diff --git a/src/presets/node/runtime/node-server.ts b/src/presets/node/runtime/node-server.ts index 708e74ef30..bddc8b28fa 100644 --- a/src/presets/node/runtime/node-server.ts +++ b/src/presets/node/runtime/node-server.ts @@ -1,10 +1,10 @@ import "#nitro-internal-pollyfills"; import { Server as HttpServer } from "node:http"; -import type { AddressInfo } from "node:net"; import { Server as HttpsServer } from "node:https"; +import type { AddressInfo } from "node:net"; +import wsAdapter from "crossws/adapters/node"; import destr from "destr"; import { toNodeListener } from "h3"; -import wsAdapter from "crossws/adapters/node"; import { useNitroApp, useRuntimeConfig } from "nitropack/runtime"; import { setupGracefulShutdown, diff --git a/src/presets/vercel/runtime/vercel.ts b/src/presets/vercel/runtime/vercel.ts index fb9c06e005..0547cf356d 100644 --- a/src/presets/vercel/runtime/vercel.ts +++ b/src/presets/vercel/runtime/vercel.ts @@ -1,7 +1,7 @@ import "#nitro-internal-pollyfills"; import { useNitroApp } from "nitropack/runtime"; -import { toNodeListener, NodeListener } from "h3"; +import { type NodeListener, toNodeListener } from "h3"; import { parseQuery } from "ufo"; const nitroApp = useNitroApp(); diff --git a/src/presets/vercel/utils.ts b/src/presets/vercel/utils.ts index 10b82a17aa..f574d9d2d1 100644 --- a/src/presets/vercel/utils.ts +++ b/src/presets/vercel/utils.ts @@ -1,8 +1,8 @@ -import type { Nitro } from "nitropack/types"; import fsp from "node:fs/promises"; -import { dirname, relative, resolve } from "pathe"; -import { writeFile } from "nitropack/kit"; import { defu } from "defu"; +import { writeFile } from "nitropack/kit"; +import type { Nitro } from "nitropack/types"; +import { dirname, relative, resolve } from "pathe"; import { joinURL, withoutLeadingSlash } from "ufo"; import type { VercelBuildConfigV3, diff --git a/src/presets/winterjs/runtime/winterjs.ts b/src/presets/winterjs/runtime/winterjs.ts index daf92d9577..43ea4826a7 100644 --- a/src/presets/winterjs/runtime/winterjs.ts +++ b/src/presets/winterjs/runtime/winterjs.ts @@ -1,8 +1,8 @@ // @ts-nocheck TODO: Remove after removing polyfills import "#nitro-internal-pollyfills"; -import { toBuffer } from "nitropack/runtime/internal"; -import { useNitroApp } from "nitropack/runtime"; import { toPlainHandler } from "h3"; +import { useNitroApp } from "nitropack/runtime"; +import { toBuffer } from "nitropack/runtime/internal"; import { hasProtocol, joinURL } from "ufo"; // Types are reverse engineered from runtime diff --git a/src/presets/zeabur/preset.ts b/src/presets/zeabur/preset.ts index dfda5dacf6..2dd84f9e62 100644 --- a/src/presets/zeabur/preset.ts +++ b/src/presets/zeabur/preset.ts @@ -1,8 +1,8 @@ import fsp from "node:fs/promises"; -import { dirname, relative, resolve } from "pathe"; import { writeFile } from "nitropack/kit"; import { defineNitroPreset } from "nitropack/kit"; import type { Nitro } from "nitropack/types"; +import { dirname, relative, resolve } from "pathe"; // https://zeabur.com/docs/advanced/serverless-output-format diff --git a/src/presets/zeabur/runtime/zeabur.ts b/src/presets/zeabur/runtime/zeabur.ts index b570e6146a..ab00d73a03 100644 --- a/src/presets/zeabur/runtime/zeabur.ts +++ b/src/presets/zeabur/runtime/zeabur.ts @@ -1,6 +1,6 @@ import "#nitro-internal-pollyfills"; +import { type NodeListener, toNodeListener } from "h3"; import { useNitroApp } from "nitropack/runtime"; -import { NodeListener, toNodeListener } from "h3"; const handler = toNodeListener(useNitroApp().h3App); diff --git a/src/rollup/config.ts b/src/rollup/config.ts index f1c84bc3ef..41ca109d53 100644 --- a/src/rollup/config.ts +++ b/src/rollup/config.ts @@ -1,47 +1,47 @@ +import { builtinModules, createRequire } from "node:module"; import { pathToFileURL } from "node:url"; -import { createRequire, builtinModules } from "node:module"; -import { dirname, join, normalize, resolve } from "pathe"; -import type { Plugin } from "rollup"; -import { defu } from "defu"; +import alias from "@rollup/plugin-alias"; // import terser from "@rollup/plugin-terser"; // TODO: Investigate jiti issue import commonjs from "@rollup/plugin-commonjs"; -import alias from "@rollup/plugin-alias"; -import json from "@rollup/plugin-json"; import inject from "@rollup/plugin-inject"; +import json from "@rollup/plugin-json"; import { nodeResolve } from "@rollup/plugin-node-resolve"; -import { isWindows } from "std-env"; -import { visualizer } from "rollup-plugin-visualizer"; -import * as unenv from "unenv"; -import type { Preset } from "unenv"; -import { sanitizeFilePath, resolvePath } from "mlly"; -import unimportPlugin from "unimport/unplugin"; -import { hash } from "ohash"; -import { rollup as unwasm } from "unwasm/plugin"; +import { defu } from "defu"; +import { resolvePath, sanitizeFilePath } from "mlly"; +import { runtimeDependencies, runtimeDir } from "nitropack/runtime/meta"; import type { Nitro, NitroStaticBuildFlags, NodeExternalsOptions, RollupConfig, } from "nitropack/types"; -import { resolveAliases } from "./utils"; -import { replace } from "./plugins/replace"; -import { virtual } from "./plugins/virtual"; +import { hash } from "ohash"; +import { dirname, join, normalize, resolve } from "pathe"; +import type { Plugin } from "rollup"; +import { visualizer } from "rollup-plugin-visualizer"; +import { isWindows } from "std-env"; +import * as unenv from "unenv"; +import type { Preset } from "unenv"; +import unimportPlugin from "unimport/unplugin"; +import { rollup as unwasm } from "unwasm/plugin"; +import { appConfig } from "./plugins/app-config"; +import { database } from "./plugins/database"; import { dynamicRequire } from "./plugins/dynamic-require"; +import { esbuild } from "./plugins/esbuild"; import { externals } from "./plugins/externals"; import { externals as legacyExternals } from "./plugins/externals-legacy"; -import { timing } from "./plugins/timing"; -import { publicAssets } from "./plugins/public-assets"; -import { serverAssets } from "./plugins/server-assets"; import { handlers } from "./plugins/handlers"; import { handlersMeta } from "./plugins/handlers-meta"; -import { esbuild } from "./plugins/esbuild"; -import { raw } from "./plugins/raw"; -import { storage } from "./plugins/storage"; -import { database } from "./plugins/database"; import { importMeta } from "./plugins/import-meta"; -import { appConfig } from "./plugins/app-config"; +import { publicAssets } from "./plugins/public-assets"; +import { raw } from "./plugins/raw"; +import { replace } from "./plugins/replace"; +import { serverAssets } from "./plugins/server-assets"; import { sourcemapMininify } from "./plugins/sourcemap-min"; -import { runtimeDependencies, runtimeDir } from "nitropack/runtime/meta"; +import { storage } from "./plugins/storage"; +import { timing } from "./plugins/timing"; +import { virtual } from "./plugins/virtual"; +import { resolveAliases } from "./utils"; export const getRollupConfig = (nitro: Nitro): RollupConfig => { const extensions: string[] = [ diff --git a/src/rollup/plugins/database.ts b/src/rollup/plugins/database.ts index af79f46955..6a055be043 100644 --- a/src/rollup/plugins/database.ts +++ b/src/rollup/plugins/database.ts @@ -1,6 +1,6 @@ import { connectors } from "db0"; -import { camelCase } from "scule"; import type { Nitro } from "nitropack/types"; +import { camelCase } from "scule"; import { virtual } from "./virtual"; export function database(nitro: Nitro) { diff --git a/src/rollup/plugins/dynamic-require.ts b/src/rollup/plugins/dynamic-require.ts index eb30e936b4..d5548c4057 100644 --- a/src/rollup/plugins/dynamic-require.ts +++ b/src/rollup/plugins/dynamic-require.ts @@ -1,8 +1,8 @@ import { pathToFileURL } from "node:url"; -import { resolve } from "pathe"; import { globby } from "globby"; -import type { Plugin } from "rollup"; import { genSafeVariableName } from "knitwork"; +import { resolve } from "pathe"; +import type { Plugin } from "rollup"; const PLUGIN_NAME = "dynamic-require"; const HELPER_DYNAMIC = `\0${PLUGIN_NAME}.mjs`; diff --git a/src/rollup/plugins/esbuild.ts b/src/rollup/plugins/esbuild.ts index 71b830344b..e0e0542e59 100644 --- a/src/rollup/plugins/esbuild.ts +++ b/src/rollup/plugins/esbuild.ts @@ -1,10 +1,10 @@ // Based on https://github.com/egoist/rollup-plugin-esbuild (MIT) +import { createFilter } from "@rollup/pluginutils"; +import { type Loader, type TransformResult, transform } from "esbuild"; +import type { EsbuildOptions } from "nitropack/types"; import { extname, relative } from "pathe"; import type { Plugin, PluginContext } from "rollup"; -import { Loader, TransformResult, transform } from "esbuild"; -import { createFilter } from "@rollup/pluginutils"; -import { EsbuildOptions } from "nitropack/types"; const defaultLoaders: { [ext: string]: Loader } = { ".ts": "ts", diff --git a/src/rollup/plugins/externals-legacy.ts b/src/rollup/plugins/externals-legacy.ts index 99b002fe47..be0dd201e0 100644 --- a/src/rollup/plugins/externals-legacy.ts +++ b/src/rollup/plugins/externals-legacy.ts @@ -1,11 +1,11 @@ import { existsSync, promises as fsp } from "node:fs"; -import { resolve, dirname, normalize, join, isAbsolute } from "pathe"; +import { type NodeFileTraceOptions, nodeFileTrace } from "@vercel/nft"; import { consola } from "consola"; -import { nodeFileTrace, NodeFileTraceOptions } from "@vercel/nft"; +import { isValidNodeImport, normalizeid, resolvePath } from "mlly"; +import { isDirectory } from "nitropack/kit"; +import { dirname, isAbsolute, join, normalize, resolve } from "pathe"; import type { Plugin } from "rollup"; -import { resolvePath, isValidNodeImport, normalizeid } from "mlly"; import semver from "semver"; -import { isDirectory } from "nitropack/kit"; import { normalizeMatcher } from "./externals"; interface NodeExternalsOptions { diff --git a/src/rollup/plugins/externals.ts b/src/rollup/plugins/externals.ts index 394e9e946a..188d06f990 100644 --- a/src/rollup/plugins/externals.ts +++ b/src/rollup/plugins/externals.ts @@ -1,20 +1,20 @@ import { existsSync, promises as fsp } from "node:fs"; import { platform } from "node:os"; -import { resolve, dirname, normalize, join, isAbsolute, relative } from "pathe"; -import type { PackageJson } from "pkg-types"; -import { readPackageJSON, writePackageJSON } from "pkg-types"; import { nodeFileTrace } from "@vercel/nft"; -import type { Plugin } from "rollup"; import { - resolvePath, isValidNodeImport, lookupNodeModuleSubpath, normalizeid, parseNodeModulePath, + resolvePath, } from "mlly"; -import semver from "semver"; import { isDirectory } from "nitropack/kit"; import type { NodeExternalsOptions } from "nitropack/types"; +import { dirname, isAbsolute, join, normalize, relative, resolve } from "pathe"; +import type { PackageJson } from "pkg-types"; +import { readPackageJSON, writePackageJSON } from "pkg-types"; +import type { Plugin } from "rollup"; +import semver from "semver"; export function externals(opts: NodeExternalsOptions): Plugin { const trackedExternals = new Set(); @@ -345,7 +345,7 @@ export function externals(opts: NodeExternalsOptions): Plugin { const src = join(opts.outDir, "node_modules", from); const dst = join(opts.outDir, "node_modules", to); const dstStat = await fsp.lstat(dst).catch(() => null); - const exists = dstStat && dstStat.isSymbolicLink(); + const exists = dstStat?.isSymbolicLink(); // console.log("Linking", from, "to", to, exists ? "!!!!" : ""); if (exists) { return; diff --git a/src/rollup/plugins/handlers-meta.ts b/src/rollup/plugins/handlers-meta.ts index 28eb7ed040..5a840c875c 100644 --- a/src/rollup/plugins/handlers-meta.ts +++ b/src/rollup/plugins/handlers-meta.ts @@ -1,9 +1,9 @@ import { readFile } from "node:fs/promises"; import { transform } from "esbuild"; -import type { Plugin } from "rollup"; -import type { Literal, Expression } from "estree"; +import type { Expression, Literal } from "estree"; +import type { Nitro, NitroEventHandler } from "nitropack/types"; import { extname } from "pathe"; -import { Nitro, NitroEventHandler } from "nitropack/types"; +import type { Plugin } from "rollup"; const virtualPrefix = "\0nitro-handler-meta:"; diff --git a/src/rollup/plugins/handlers.ts b/src/rollup/plugins/handlers.ts index 6c77d31461..87108a1123 100644 --- a/src/rollup/plugins/handlers.ts +++ b/src/rollup/plugins/handlers.ts @@ -1,12 +1,12 @@ -import { hash } from "ohash"; +import { runtimeDir } from "nitropack/runtime/meta"; import type { Nitro, - NitroRouteRules, NitroEventHandler, + NitroRouteRules, } from "nitropack/types"; -import { virtual } from "./virtual"; +import { hash } from "ohash"; import { join } from "pathe"; -import { runtimeDir } from "nitropack/runtime/meta"; +import { virtual } from "./virtual"; export function handlers(nitro: Nitro) { const getHandlers = () => { diff --git a/src/rollup/plugins/import-meta.ts b/src/rollup/plugins/import-meta.ts index 3638c11506..cb50db9018 100644 --- a/src/rollup/plugins/import-meta.ts +++ b/src/rollup/plugins/import-meta.ts @@ -1,5 +1,5 @@ +import type { Nitro } from "nitropack/types"; import type { Plugin } from "rollup"; -import { Nitro } from "nitropack/types"; export const ImportMetaRe = /import\.meta|globalThis._importMeta_/; diff --git a/src/rollup/plugins/public-assets.ts b/src/rollup/plugins/public-assets.ts index dc0b9d945e..37619f9cbe 100644 --- a/src/rollup/plugins/public-assets.ts +++ b/src/rollup/plugins/public-assets.ts @@ -1,13 +1,13 @@ import { promises as fsp } from "node:fs"; -import { relative, resolve } from "pathe"; -import { withTrailingSlash } from "ufo"; import createEtag from "etag"; -import mime from "mime"; import { globby } from "globby"; -import type { Plugin } from "rollup"; +import mime from "mime"; import type { Nitro } from "nitropack/types"; -import { virtual } from "./virtual"; import type { PublicAsset } from "nitropack/types"; +import { relative, resolve } from "pathe"; +import type { Plugin } from "rollup"; +import { withTrailingSlash } from "ufo"; +import { virtual } from "./virtual"; const readAssetHandler: Record< Exclude, diff --git a/src/rollup/plugins/raw.ts b/src/rollup/plugins/raw.ts index 705516b89d..df11ef8d54 100644 --- a/src/rollup/plugins/raw.ts +++ b/src/rollup/plugins/raw.ts @@ -1,8 +1,8 @@ import { promises as fsp } from "node:fs"; -import { extname } from "pathe"; import mime from "mime"; +import type { RawOptions } from "nitropack/types"; +import { extname } from "pathe"; import type { Plugin } from "rollup"; -import { RawOptions } from "nitropack/types"; const HELPER_ID = "\0raw-helpers"; @@ -67,14 +67,11 @@ export function raw(opts: RawOptions = {}): Plugin { code: `// ROLLUP_NO_REPLACE \n import {base64ToUint8Array } from "${HELPER_ID}" \n export default base64ToUint8Array("${serialized}")`, map: null, }; - } else { - return { - code: `// ROLLUP_NO_REPLACE \n export default ${JSON.stringify( - code - )}`, - map: null, - }; } + return { + code: `// ROLLUP_NO_REPLACE \n export default ${JSON.stringify(code)}`, + map: null, + }; }, }; } diff --git a/src/rollup/plugins/server-assets.ts b/src/rollup/plugins/server-assets.ts index dc5a98b3da..b5471525fb 100644 --- a/src/rollup/plugins/server-assets.ts +++ b/src/rollup/plugins/server-assets.ts @@ -1,11 +1,11 @@ import { promises as fsp } from "node:fs"; -import type { Plugin } from "rollup"; import createEtag from "etag"; +import { globby } from "globby"; import mime from "mime"; +import type { Nitro } from "nitropack/types"; import { resolve } from "pathe"; +import type { Plugin } from "rollup"; import { normalizeKey } from "unstorage"; -import { globby } from "globby"; -import type { Nitro } from "nitropack/types"; import { virtual } from "./virtual"; interface ResolvedAsset { diff --git a/src/rollup/plugins/sourcemap-min.ts b/src/rollup/plugins/sourcemap-min.ts index 2e2594bcb2..cf22ae88a8 100644 --- a/src/rollup/plugins/sourcemap-min.ts +++ b/src/rollup/plugins/sourcemap-min.ts @@ -1,4 +1,4 @@ -import type { Plugin, ExistingRawSourceMap } from "rollup"; +import type { ExistingRawSourceMap, Plugin } from "rollup"; export function sourcemapMininify() { return { diff --git a/src/rollup/plugins/storage.ts b/src/rollup/plugins/storage.ts index e4d5f301d9..23bf568543 100644 --- a/src/rollup/plugins/storage.ts +++ b/src/rollup/plugins/storage.ts @@ -1,6 +1,6 @@ -import { builtinDrivers } from "unstorage"; import { genImport, genSafeVariableName } from "knitwork"; import type { Nitro } from "nitropack/types"; +import { builtinDrivers } from "unstorage"; import { virtual } from "./virtual"; export function storage(nitro: Nitro) { diff --git a/src/rollup/plugins/virtual.ts b/src/rollup/plugins/virtual.ts index c8ed425ca8..8d5b3b5426 100644 --- a/src/rollup/plugins/virtual.ts +++ b/src/rollup/plugins/virtual.ts @@ -1,6 +1,6 @@ -import { resolve, dirname } from "pathe"; -import type { Plugin } from "rollup"; import type { RollupVirtualOptions, VirtualModule } from "nitropack/types"; +import { dirname, resolve } from "pathe"; +import type { Plugin } from "rollup"; // Based on https://github.com/rollup/plugins/blob/master/packages/virtual/src/index.ts diff --git a/src/runtime/internal/app.ts b/src/runtime/internal/app.ts index 98b4761bd7..adeb3f65eb 100644 --- a/src/runtime/internal/app.ts +++ b/src/runtime/internal/app.ts @@ -1,36 +1,36 @@ +import destr from "destr"; import { + type H3Error, + type H3Event, createApp, createRouter, eventHandler, - lazyEventHandler, - toNodeListener, fetchWithEvent, - H3Error, isEvent, - H3Event, + lazyEventHandler, + toNodeListener, } from "h3"; -import { createFetch, Headers } from "ofetch"; -import destr from "destr"; -import { - createCall, - createFetch as createLocalFetch, -} from "unenv/runtime/fetch/index"; import { createHooks } from "hookable"; import type { - NitroRuntimeHooks, CaptureError, NitroApp, + NitroRuntimeHooks, } from "nitropack/types"; -import { useRuntimeConfig } from "./config"; -import { cachedEventHandler } from "./cache"; -import { normalizeFetchResponse } from "./utils"; -import { createRouteRulesHandler, getRouteRulesForPath } from "./route-rules"; -import { nitroAsyncContext } from "./context"; import type { NitroAsyncContext } from "nitropack/types"; import type { $Fetch, NitroFetchRequest } from "nitropack/types"; -import { plugins } from "#nitro-internal-virtual/plugins"; +import { Headers, createFetch } from "ofetch"; +import { + createCall, + createFetch as createLocalFetch, +} from "unenv/runtime/fetch/index"; import errorHandler from "#nitro-internal-virtual/error-handler"; +import { plugins } from "#nitro-internal-virtual/plugins"; import { handlers } from "#nitro-internal-virtual/server-handlers"; +import { cachedEventHandler } from "./cache"; +import { useRuntimeConfig } from "./config"; +import { nitroAsyncContext } from "./context"; +import { createRouteRulesHandler, getRouteRulesForPath } from "./route-rules"; +import { normalizeFetchResponse } from "./utils"; function createNitroApp(): NitroApp { const config = useRuntimeConfig(); diff --git a/src/runtime/internal/cache.ts b/src/runtime/internal/cache.ts index 7a63eba22e..03f72a1d01 100644 --- a/src/runtime/internal/cache.ts +++ b/src/runtime/internal/cache.ts @@ -1,25 +1,25 @@ -import { hash } from "ohash"; import { - handleCacheHeaders, - defineEventHandler, + type EventHandler, createEvent, - EventHandler, + defineEventHandler, + fetchWithEvent, + handleCacheHeaders, isEvent, splitCookiesString, - fetchWithEvent, } from "h3"; import type { EventHandlerRequest, EventHandlerResponse, H3Event } from "h3"; -import { parseURL } from "ufo"; -import { useStorage } from "./storage"; -import { useNitroApp } from "./app"; import type { $Fetch, - CacheOptions, CacheEntry, + CacheOptions, CachedEventHandlerOptions, - ResponseCacheEntry, NitroFetchRequest, + ResponseCacheEntry, } from "nitropack/types"; +import { hash } from "ohash"; +import { parseURL } from "ufo"; +import { useNitroApp } from "./app"; +import { useStorage } from "./storage"; const defaultCacheOptions = { name: "_", @@ -116,7 +116,7 @@ export function defineCachedFunction( console.error(`[nitro] [cache] Cache write error.`, error); useNitroApp().captureError(error, { event, tags: ["cache"] }); }); - if (event && event.waitUntil) { + if (event?.waitUntil) { event.waitUntil(promise); } } diff --git a/src/runtime/internal/client.ts b/src/runtime/internal/client.ts index 1a07c1c41e..368c9e3806 100644 --- a/src/runtime/internal/client.ts +++ b/src/runtime/internal/client.ts @@ -1,6 +1,6 @@ +import type { $Fetch, NitroFetchRequest } from "nitropack/types"; // Client polyfill import { $fetch } from "ofetch"; -import { $Fetch, NitroFetchRequest } from "nitropack/types"; if (!globalThis.$fetch) { globalThis.$fetch = $fetch as $Fetch; diff --git a/src/runtime/internal/config.ts b/src/runtime/internal/config.ts index d398a233bf..eadaf89ead 100644 --- a/src/runtime/internal/config.ts +++ b/src/runtime/internal/config.ts @@ -1,8 +1,8 @@ +import type { H3Event } from "h3"; import { klona } from "klona"; -import { H3Event } from "h3"; -import { type EnvOptions, applyEnv } from "./utils.env"; -import { appConfig as _inlineAppConfig } from "#nitro-internal-virtual/app-config"; import type { NitroRuntimeConfig } from "nitropack/types"; +import { appConfig as _inlineAppConfig } from "#nitro-internal-virtual/app-config"; +import { type EnvOptions, applyEnv } from "./utils.env"; // Static runtime config inlined by nitro build const _inlineRuntimeConfig = process.env.RUNTIME_CONFIG as any; diff --git a/src/runtime/internal/context.ts b/src/runtime/internal/context.ts index 11e4996e3b..e8dfca194a 100644 --- a/src/runtime/internal/context.ts +++ b/src/runtime/internal/context.ts @@ -1,7 +1,7 @@ import { AsyncLocalStorage } from "node:async_hooks"; -import { H3Event, createError } from "h3"; -import { getContext } from "unctx"; +import { type H3Event, createError } from "h3"; import type { NitroAsyncContext } from "nitropack/types"; +import { getContext } from "unctx"; export const nitroAsyncContext = getContext("nitro-app", { asyncContext: import.meta._asyncContext, diff --git a/src/runtime/internal/error.ts b/src/runtime/internal/error.ts index 0fd28150f2..f8a8a02c54 100644 --- a/src/runtime/internal/error.ts +++ b/src/runtime/internal/error.ts @@ -1,7 +1,7 @@ // import ansiHTML from 'ansi-html' -import { setResponseHeader, setResponseStatus, send } from "h3"; +import { send, setResponseHeader, setResponseStatus } from "h3"; import type { NitroErrorHandler } from "nitropack/types"; -import { normalizeError, isJsonRequest } from "./utils"; +import { isJsonRequest, normalizeError } from "./utils"; export function defineNitroErrorHandler( handler: NitroErrorHandler @@ -54,10 +54,9 @@ export default defineNitroErrorHandler( if (isJsonRequest(event)) { setResponseHeader(event, "Content-Type", "application/json"); return send(event, JSON.stringify(errorObject)); - } else { - setResponseHeader(event, "Content-Type", "text/html"); - return send(event, renderHTMLError(errorObject)); } + setResponseHeader(event, "Content-Type", "text/html"); + return send(event, renderHTMLError(errorObject)); } ); diff --git a/src/runtime/internal/lib/http-graceful-shutdown.ts b/src/runtime/internal/lib/http-graceful-shutdown.ts index fd03f871e4..e8f2e05656 100644 --- a/src/runtime/internal/lib/http-graceful-shutdown.ts +++ b/src/runtime/internal/lib/http-graceful-shutdown.ts @@ -155,19 +155,19 @@ function GracefulShutdown(server, opts) { // set up server/process events // ---------------------------------- - server.on("request", function (req, res) { + server.on("request", (req, res) => { req.socket._isIdle = false; if (isShuttingDown && !res.headersSent) { res.setHeader("connection", "close"); } - res.on("finish", function () { + res.on("finish", () => { req.socket._isIdle = true; destroy(req.socket); }); }); - server.on("connection", function (socket) { + server.on("connection", (socket) => { if (isShuttingDown) { socket.destroy(); } else { @@ -197,7 +197,7 @@ function GracefulShutdown(server, opts) { } }); - process.on("close", function () { + process.on("close", () => { debug("closed"); }); diff --git a/src/runtime/internal/renderer.ts b/src/runtime/internal/renderer.ts index 5cf701cba2..59f9808ccd 100644 --- a/src/runtime/internal/renderer.ts +++ b/src/runtime/internal/renderer.ts @@ -7,8 +7,8 @@ import { setResponseHeaders, setResponseStatus, } from "h3"; -import { useNitroApp } from "./app"; import type { RenderHandler } from "nitropack/types"; +import { useNitroApp } from "./app"; export function defineRenderHandler(handler: RenderHandler) { return eventHandler(async (event) => { diff --git a/src/runtime/internal/route-rules.ts b/src/runtime/internal/route-rules.ts index cbbf2eadbc..4e392ad269 100644 --- a/src/runtime/internal/route-rules.ts +++ b/src/runtime/internal/route-rules.ts @@ -1,15 +1,15 @@ +import defu from "defu"; import { + type H3Event, eventHandler, - H3Event, + proxyRequest, sendRedirect, setHeaders, - proxyRequest, } from "h3"; -import defu from "defu"; +import type { NitroRouteRules } from "nitropack/types"; import { createRouter as createRadixRouter, toRouteMatcher } from "radix3"; -import { joinURL, withQuery, getQuery, withoutBase } from "ufo"; +import { getQuery, joinURL, withQuery, withoutBase } from "ufo"; import { useRuntimeConfig } from "./config"; -import type { NitroRouteRules } from "nitropack/types"; const config = useRuntimeConfig(); const _routeRulesMatcher = toRouteMatcher( diff --git a/src/runtime/internal/routes/openapi.ts b/src/runtime/internal/routes/openapi.ts index b537f1a0b8..b4a9b21b89 100644 --- a/src/runtime/internal/routes/openapi.ts +++ b/src/runtime/internal/routes/openapi.ts @@ -1,9 +1,9 @@ -import { HTTPMethod, eventHandler, getRequestURL } from "h3"; +import { type HTTPMethod, eventHandler, getRequestURL } from "h3"; import type { OpenAPI3, - PathItemObject, OperationObject, ParameterObject, + PathItemObject, PathsObject, } from "openapi-typescript"; import { joinURL } from "ufo"; diff --git a/src/runtime/internal/routes/scalar.ts b/src/runtime/internal/routes/scalar.ts index be7f8430e4..f44563ee6a 100644 --- a/src/runtime/internal/routes/scalar.ts +++ b/src/runtime/internal/routes/scalar.ts @@ -1,5 +1,5 @@ -import { eventHandler } from "h3"; import type { ReferenceConfiguration } from "@scalar/api-reference"; +import { eventHandler } from "h3"; import { useRuntimeConfig } from "../config"; // Served as /_nitro/scalar diff --git a/src/runtime/internal/shutdown.ts b/src/runtime/internal/shutdown.ts index d0a3d93fe2..91411a93f9 100644 --- a/src/runtime/internal/shutdown.ts +++ b/src/runtime/internal/shutdown.ts @@ -1,6 +1,6 @@ import type { Server as HttpServer } from "node:http"; -import gracefulShutdown from "./lib/http-graceful-shutdown"; import type { NitroApp } from "nitropack/types"; +import gracefulShutdown from "./lib/http-graceful-shutdown"; export function getGracefulShutdownConfig() { return { diff --git a/src/runtime/internal/static.ts b/src/runtime/internal/static.ts index c4c10e1744..81db44b068 100644 --- a/src/runtime/internal/static.ts +++ b/src/runtime/internal/static.ts @@ -1,13 +1,14 @@ import { - eventHandler, + type HTTPMethod, createError, + eventHandler, getRequestHeader, getResponseHeader, + removeResponseHeader, setResponseHeader, setResponseStatus, - removeResponseHeader, - type HTTPMethod, } from "h3"; +import type { PublicAsset } from "nitropack/types"; import { decodePath, joinURL, @@ -17,10 +18,9 @@ import { } from "ufo"; import { getAsset, - readAsset, isPublicAssetURL, + readAsset, } from "#nitro-internal-virtual/public-assets"; -import type { PublicAsset } from "nitropack/types"; const METHODS = new Set(["HEAD", "GET"] as HTTPMethod[]); diff --git a/src/runtime/internal/task.ts b/src/runtime/internal/task.ts index fa1be52446..e758cc80f9 100644 --- a/src/runtime/internal/task.ts +++ b/src/runtime/internal/task.ts @@ -1,14 +1,14 @@ -import { createError } from "h3"; import { Cron } from "croner"; -import { isTest } from "std-env"; -import { tasks, scheduledTasks } from "#nitro-internal-virtual/tasks"; +import { createError } from "h3"; import type { Task, - TaskResult, - TaskPayload, TaskContext, TaskEvent, + TaskPayload, + TaskResult, } from "nitropack/types"; +import { isTest } from "std-env"; +import { scheduledTasks, tasks } from "#nitro-internal-virtual/tasks"; /** @experimental */ export function defineTask(def: Task): Task { diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 244f2dd4dd..17bf39bef9 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -22,14 +22,15 @@ export async function useRequestBody( body[entry[0]] = entry[1]; } return body; - } else if (JSON_MIME_RE.test(contentType)) { + } + if (JSON_MIME_RE.test(contentType)) { return request.json(); - } else if (TEXT_MIME_RE.test(contentType)) { + } + if (TEXT_MIME_RE.test(contentType)) { return request.text(); - } else { - const blob = await request.blob(); - return URL.createObjectURL(blob); } + const blob = await request.blob(); + return URL.createObjectURL(blob); } export function hasReqHeader(event: H3Event, name: string, includes: string) { diff --git a/src/types/config.ts b/src/types/config.ts index 412987521b..02f7b87ebe 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -1,38 +1,38 @@ -import type { Preset as UnenvPreset } from "unenv"; -import type { UnimportPluginOptions } from "unimport/unplugin"; -import type { PluginVisualizerOptions } from "rollup-plugin-visualizer"; -import type { NestedHooks } from "hookable"; -import type { LogLevel } from "consola"; -import type { WatchOptions } from "chokidar"; import type { RollupCommonJSOptions } from "@rollup/plugin-commonjs"; -import type { ProxyServerOptions } from "httpxy"; -import type { ResolvedConfig, ConfigWatcher, C12InputConfig } from "c12"; -import type { UnwasmPluginOptions } from "unwasm/plugin"; -import type { TSConfig } from "pkg-types"; import type { ReferenceConfiguration } from "@scalar/api-reference"; +import type { C12InputConfig, ConfigWatcher, ResolvedConfig } from "c12"; import type { WatchConfigOptions } from "c12"; -import type { NodeExternalsOptions, EsbuildOptions } from "./rollup"; -import type { - NitroErrorHandler, - NitroDevEventHandler, - NitroEventHandler, -} from "./handler"; +import type { WatchOptions } from "chokidar"; +import type { CompatibilityDateSpec, CompatibilityDates } from "compatx"; +import type { LogLevel } from "consola"; +import type { ConnectorName } from "db0"; +import type { NestedHooks } from "hookable"; +import type { ProxyServerOptions } from "httpxy"; import type { PresetName, PresetNameInput, PresetOptions, } from "nitropack/presets"; -import type { NitroModuleInput } from "./module"; -import type { DeepPartial } from "./_utils"; -import type { RollupConfig } from "./rollup"; +import type { TSConfig } from "pkg-types"; +import type { PluginVisualizerOptions } from "rollup-plugin-visualizer"; +import type { Preset as UnenvPreset } from "unenv"; +import type { UnimportPluginOptions } from "unimport/unplugin"; import type { BuiltinDriverName } from "unstorage"; -import type { NitroRouteConfig, NitroRouteRules } from "./route-rules"; -import type { NitroPreset } from "./preset"; +import type { UnwasmPluginOptions } from "unwasm/plugin"; +import type { DeepPartial } from "./_utils"; +import type { DevServerOptions } from "./dev"; +import type { + NitroDevEventHandler, + NitroErrorHandler, + NitroEventHandler, +} from "./handler"; import type { NitroHooks } from "./hooks"; -import type { ConnectorName } from "db0"; +import type { NitroModuleInput } from "./module"; import type { NitroFrameworkInfo } from "./nitro"; -import type { DevServerOptions } from "./dev"; -import type { CompatibilityDateSpec, CompatibilityDates } from "compatx"; +import type { NitroPreset } from "./preset"; +import type { EsbuildOptions, NodeExternalsOptions } from "./rollup"; +import type { RollupConfig } from "./rollup"; +import type { NitroRouteConfig, NitroRouteRules } from "./route-rules"; /** * Nitro normalized options (nitro.options) diff --git a/src/types/dev.ts b/src/types/dev.ts index 0e2a312b3d..a9a13655f2 100644 --- a/src/types/dev.ts +++ b/src/types/dev.ts @@ -1,9 +1,9 @@ -import type { Worker } from "node:worker_threads"; -import type { App } from "h3"; -import type { Listener, ListenOptions } from "listhen"; -import type { FSWatcher } from "chokidar"; import type { IncomingMessage, OutgoingMessage } from "node:http"; import type { Duplex } from "node:stream"; +import type { Worker } from "node:worker_threads"; +import type { FSWatcher } from "chokidar"; +import type { App } from "h3"; +import type { ListenOptions, Listener } from "listhen"; export interface DevServerOptions { watch: string[]; diff --git a/src/types/fetch/fetch.ts b/src/types/fetch/fetch.ts index 3a6b72fb46..ca5aabf1e4 100644 --- a/src/types/fetch/fetch.ts +++ b/src/types/fetch/fetch.ts @@ -1,5 +1,5 @@ import type { RouterMethod } from "h3"; -import type { FetchRequest, FetchOptions, FetchResponse } from "ofetch"; +import type { FetchOptions, FetchRequest, FetchResponse } from "ofetch"; import type { MatchedRoutes } from "./_match"; // An interface to extend in a local project @@ -105,4 +105,4 @@ declare global { } } -export {}; +export type {}; diff --git a/src/types/global.ts b/src/types/global.ts index 894bad17c5..e2d15b130d 100644 --- a/src/types/global.ts +++ b/src/types/global.ts @@ -30,4 +30,4 @@ declare global { const defineNitroModule: (definition: NitroModule) => NitroModule; } -export {}; +export type {}; diff --git a/src/types/h3.ts b/src/types/h3.ts index 651d025ace..4938bd5fa6 100644 --- a/src/types/h3.ts +++ b/src/types/h3.ts @@ -1,9 +1,9 @@ import type { + CacheOptions, CaptureError, CapturedErrorContext, - CacheOptions, } from "nitropack/types"; -import type { NitroFetchRequest, $Fetch } from "./fetch/fetch"; +import type { $Fetch, NitroFetchRequest } from "./fetch/fetch"; export type H3EventFetch = ( request: NitroFetchRequest, @@ -36,4 +36,4 @@ declare module "h3" { } } -export {}; +export type {}; diff --git a/src/types/handler.ts b/src/types/handler.ts index 6797656194..0494e1e2c6 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -1,6 +1,6 @@ import type { EventHandler, H3Error, H3Event, RouterMethod } from "h3"; -import type { OperationObject } from "openapi-typescript"; import type { PresetName } from "nitropack/presets"; +import type { OperationObject } from "openapi-typescript"; type MaybeArray = T | T[]; diff --git a/src/types/hooks.ts b/src/types/hooks.ts index 54a5d0b47c..24d7def9e9 100644 --- a/src/types/hooks.ts +++ b/src/types/hooks.ts @@ -1,5 +1,5 @@ import type { NitroConfig } from "./config"; -import type { NitroTypes, Nitro } from "./nitro"; +import type { Nitro, NitroTypes } from "./nitro"; import type { PrerenderRoute } from "./prerender"; import type { RollupConfig } from "./rollup"; diff --git a/src/types/nitro.ts b/src/types/nitro.ts index 8877770ede..bad67e9811 100644 --- a/src/types/nitro.ts +++ b/src/types/nitro.ts @@ -1,11 +1,11 @@ -import type { Unimport } from "unimport"; -import type { Hookable } from "hookable"; import type { ConsolaInstance } from "consola"; -import type { Storage } from "unstorage"; import type { RouterMethod } from "h3"; -import type { NitroEventHandler } from "./handler"; +import type { Hookable } from "hookable"; import type { PresetName } from "nitropack/presets"; +import type { Unimport } from "unimport"; +import type { Storage } from "unstorage"; import type { NitroConfig, NitroOptions } from "./config"; +import type { NitroEventHandler } from "./handler"; import type { NitroHooks } from "./hooks"; import type { PrerenderRoute } from "./prerender"; diff --git a/src/types/preset.ts b/src/types/preset.ts index 66463aee54..9f9744f03a 100644 --- a/src/types/preset.ts +++ b/src/types/preset.ts @@ -1,6 +1,6 @@ +import type { DateString } from "compatx"; import type { ProviderName } from "std-env"; import type { NitroConfig } from "./config"; -import type { DateString } from "compatx"; export type NitroPreset = NitroConfig | (() => NitroConfig); diff --git a/src/types/rollup.ts b/src/types/rollup.ts index 1a02404664..206e0b768e 100644 --- a/src/types/rollup.ts +++ b/src/types/rollup.ts @@ -1,7 +1,7 @@ -import type { Loader as ESBuildLoader } from "esbuild"; import type { FilterPattern } from "@rollup/pluginutils"; -import type { TransformOptions as ESBuildTransformOptions } from "esbuild"; import type { NodeFileTraceOptions } from "@vercel/nft"; +import type { Loader as ESBuildLoader } from "esbuild"; +import type { TransformOptions as ESBuildTransformOptions } from "esbuild"; import type { InputOptions as RollupInputOptions, OutputOptions as RollupOutputOptions, diff --git a/src/types/route-rules.ts b/src/types/route-rules.ts index 3ebcfd9668..53b788763b 100644 --- a/src/types/route-rules.ts +++ b/src/types/route-rules.ts @@ -1,5 +1,5 @@ import type { ProxyOptions, RouterMethod } from "h3"; -import type { IntRange, ExcludeFunctions } from "./_utils"; +import type { ExcludeFunctions, IntRange } from "./_utils"; import type { CachedEventHandlerOptions } from "./runtime"; export type HTTPStatusCode = IntRange<100, 600>; diff --git a/src/types/runtime/nitro.ts b/src/types/runtime/nitro.ts index 50157efc09..fc176c77d5 100644 --- a/src/types/runtime/nitro.ts +++ b/src/types/runtime/nitro.ts @@ -1,4 +1,4 @@ -import type { H3Event, AppOptions, App as H3App, Router } from "h3"; +import type { AppOptions, App as H3App, H3Event, Router } from "h3"; import type { Hookable } from "hookable"; import type { createCall, diff --git a/test/fixture/types.ts b/test/fixture/types.ts index 1b55234df8..e7a82c3fae 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -1,9 +1,13 @@ import { expectTypeOf } from "expect-type"; -import { describe, it } from "vitest"; -import { EventHandler, EventHandlerRequest, defineEventHandler } from "h3"; -import type { $Fetch } from "nitropack/types"; +import { + type EventHandler, + type EventHandlerRequest, + defineEventHandler, +} from "h3"; import { defineNitroConfig } from "nitropack/config"; +import type { $Fetch } from "nitropack/types"; import type { Serialize, Simplify } from "nitropack/types"; +import { describe, it } from "vitest"; interface TestResponse { message: string; diff --git a/test/presets/aws-lambda.test.ts b/test/presets/aws-lambda.test.ts index 5a249ff67c..2717fedd32 100644 --- a/test/presets/aws-lambda.test.ts +++ b/test/presets/aws-lambda.test.ts @@ -1,7 +1,7 @@ +import type { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from "aws-lambda"; +import destr from "destr"; import { resolve } from "pathe"; import { describe } from "vitest"; -import destr from "destr"; -import type { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from "aws-lambda"; import { setupTest, testNitro } from "../tests"; describe("nitro:preset:aws-lambda", async () => { diff --git a/test/presets/azure.test.ts b/test/presets/azure.test.ts index 30e66ab5a0..cac5e3c1df 100644 --- a/test/presets/azure.test.ts +++ b/test/presets/azure.test.ts @@ -1,8 +1,8 @@ -import { promises as fsp, existsSync } from "node:fs"; -import { resolve } from "pathe"; -import { describe, it, expect } from "vitest"; +import { existsSync, promises as fsp } from "node:fs"; import { execa } from "execa"; import { getRandomPort, waitForPort } from "get-port-please"; +import { resolve } from "pathe"; +import { describe, expect, it } from "vitest"; import { setupTest, testNitro } from "../tests"; describe( diff --git a/test/presets/bun.test.ts b/test/presets/bun.test.ts index 1b98380670..95745eca43 100644 --- a/test/presets/bun.test.ts +++ b/test/presets/bun.test.ts @@ -1,7 +1,7 @@ -import { resolve } from "pathe"; -import { describe } from "vitest"; import { execa, execaCommandSync } from "execa"; import { getRandomPort, waitForPort } from "get-port-please"; +import { resolve } from "pathe"; +import { describe } from "vitest"; import { setupTest, testNitro } from "../tests"; const hasBun = diff --git a/test/presets/cloudflare-module.test.ts b/test/presets/cloudflare-module.test.ts index 5856100e1c..c1f1842edc 100644 --- a/test/presets/cloudflare-module.test.ts +++ b/test/presets/cloudflare-module.test.ts @@ -1,7 +1,7 @@ -import { resolve } from "pathe"; import { Miniflare } from "miniflare"; -import { describe } from "vitest"; +import { resolve } from "pathe"; import { Response as _Response } from "undici"; +import { describe } from "vitest"; import { setupTest, testNitro } from "../tests"; diff --git a/test/presets/cloudflare-pages.test.ts b/test/presets/cloudflare-pages.test.ts index c6432cccc2..b5b364e2f5 100644 --- a/test/presets/cloudflare-pages.test.ts +++ b/test/presets/cloudflare-pages.test.ts @@ -1,8 +1,8 @@ import { promises as fsp } from "node:fs"; -import { resolve } from "pathe"; import { Miniflare } from "miniflare"; -import { describe, it, expect } from "vitest"; +import { resolve } from "pathe"; import { Response as _Response } from "undici"; +import { describe, expect, it } from "vitest"; import { isWindows } from "std-env"; import { setupTest, testNitro } from "../tests"; diff --git a/test/presets/cloudflare-worker.test.ts b/test/presets/cloudflare-worker.test.ts index 7423e77aaf..7c2a587845 100644 --- a/test/presets/cloudflare-worker.test.ts +++ b/test/presets/cloudflare-worker.test.ts @@ -1,5 +1,5 @@ -import { resolve } from "pathe"; import { Miniflare } from "miniflare"; +import { resolve } from "pathe"; import { describe } from "vitest"; import { setupTest, testNitro } from "../tests"; diff --git a/test/presets/deno-server.test.ts b/test/presets/deno-server.test.ts index 5afdccbb33..650c9433f8 100644 --- a/test/presets/deno-server.test.ts +++ b/test/presets/deno-server.test.ts @@ -1,7 +1,7 @@ -import { resolve } from "pathe"; -import { describe } from "vitest"; import { execa, execaCommandSync } from "execa"; import { getRandomPort, waitForPort } from "get-port-please"; +import { resolve } from "pathe"; +import { describe } from "vitest"; import { setupTest, testNitro } from "../tests"; const hasDeno = diff --git a/test/presets/netlify-legacy.test.ts b/test/presets/netlify-legacy.test.ts index 24f32b76f2..bbd68c48f2 100644 --- a/test/presets/netlify-legacy.test.ts +++ b/test/presets/netlify-legacy.test.ts @@ -1,8 +1,8 @@ import { promises as fsp } from "node:fs"; -import { resolve } from "pathe"; +import type { APIGatewayEvent, Handler } from "aws-lambda"; import destr from "destr"; -import { describe, it, expect } from "vitest"; -import { Handler, APIGatewayEvent } from "aws-lambda"; +import { resolve } from "pathe"; +import { describe, expect, it } from "vitest"; import { getPresetTmpDir, setupTest, testNitro } from "../tests"; describe("nitro:preset:netlify-legacy", async () => { diff --git a/test/presets/netlify.test.ts b/test/presets/netlify.test.ts index 053fb96bf0..7ed26707e8 100644 --- a/test/presets/netlify.test.ts +++ b/test/presets/netlify.test.ts @@ -1,7 +1,7 @@ import { promises as fsp } from "node:fs"; -import { resolve } from "pathe"; -import { describe, it, expect } from "vitest"; import type { Context } from "@netlify/functions"; +import { resolve } from "pathe"; +import { describe, expect, it } from "vitest"; import { getPresetTmpDir, setupTest, testNitro } from "../tests"; describe("nitro:preset:netlify", async () => { diff --git a/test/presets/nitro-dev.test.ts b/test/presets/nitro-dev.test.ts index 3922586a01..0e98ed7c91 100644 --- a/test/presets/nitro-dev.test.ts +++ b/test/presets/nitro-dev.test.ts @@ -1,6 +1,6 @@ -import { describe, it, expect } from "vitest"; -import { isCI } from "std-env"; import type { OpenAPI3 } from "openapi-typescript"; +import { isCI } from "std-env"; +import { describe, expect, it } from "vitest"; import { setupTest, testNitro } from "../tests"; describe.skipIf(isCI)("nitro:preset:nitro-dev", async () => { diff --git a/test/presets/node.test.ts b/test/presets/node.test.ts index 63c8cffc49..01122dd155 100644 --- a/test/presets/node.test.ts +++ b/test/presets/node.test.ts @@ -1,8 +1,8 @@ import { existsSync } from "node:fs"; import { resolve } from "pathe"; -import { describe, it, expect } from "vitest"; import { isWindows } from "std-env"; -import { startServer, setupTest, testNitro } from "../tests"; +import { describe, expect, it } from "vitest"; +import { setupTest, startServer, testNitro } from "../tests"; describe("nitro:preset:node-listener", async () => { const ctx = await setupTest("node-listener"); diff --git a/test/presets/static.test.ts b/test/presets/static.test.ts index 6301d9f462..579e43a722 100644 --- a/test/presets/static.test.ts +++ b/test/presets/static.test.ts @@ -1,6 +1,6 @@ import fsp from "node:fs/promises"; import { resolve } from "pathe"; -import { describe, it, expect } from "vitest"; +import { describe, expect, it } from "vitest"; import { setupTest } from "../tests"; describe("nitro:preset:static", async () => { diff --git a/test/presets/vercel-edge.test.ts b/test/presets/vercel-edge.test.ts index 44d3b2e792..95a3baf0d6 100644 --- a/test/presets/vercel-edge.test.ts +++ b/test/presets/vercel-edge.test.ts @@ -1,6 +1,6 @@ import { promises as fsp } from "node:fs"; -import { resolve } from "pathe"; import { EdgeRuntime } from "edge-runtime"; +import { resolve } from "pathe"; import { isWindows } from "std-env"; import { describeIf, setupTest, testNitro } from "../tests"; diff --git a/test/presets/vercel.test.ts b/test/presets/vercel.test.ts index b71f32e2a8..31c5691b0d 100644 --- a/test/presets/vercel.test.ts +++ b/test/presets/vercel.test.ts @@ -1,6 +1,6 @@ import { promises as fsp } from "node:fs"; import { resolve } from "pathe"; -import { describe, it, expect } from "vitest"; +import { describe, expect, it } from "vitest"; import { setupTest, startServer, testNitro } from "../tests"; describe("nitro:preset:vercel", async () => { diff --git a/test/presets/winterjs.test.ts b/test/presets/winterjs.test.ts index d1b2484df1..8ab0d24451 100644 --- a/test/presets/winterjs.test.ts +++ b/test/presets/winterjs.test.ts @@ -1,6 +1,6 @@ -import { describe } from "vitest"; import { execa, execaCommandSync } from "execa"; -import { waitForPort, getRandomPort } from "get-port-please"; +import { getRandomPort, waitForPort } from "get-port-please"; +import { describe } from "vitest"; import { setupTest, testNitro } from "../tests"; const hasWasmer = false; diff --git a/test/scripts/gen-fixture-types.ts b/test/scripts/gen-fixture-types.ts index 8a15fa8d66..91773ef18c 100644 --- a/test/scripts/gen-fixture-types.ts +++ b/test/scripts/gen-fixture-types.ts @@ -1,6 +1,6 @@ import { fileURLToPath } from "mlly"; -import { resolve } from "pathe"; import { createNitro, scanHandlers, writeTypes } from "nitropack/core"; +import { resolve } from "pathe"; const prepare = async () => { const fixtureDir = fileURLToPath(new URL("../fixture", import.meta.url).href); diff --git a/test/tests.ts b/test/tests.ts index 6297b947b2..3d6a549b40 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -1,25 +1,25 @@ -import { tmpdir } from "node:os"; -import type { RequestListener } from "node:http"; import { promises as fsp } from "node:fs"; -import { join, resolve } from "pathe"; -import { listen, Listener } from "listhen"; +import type { RequestListener } from "node:http"; +import { tmpdir } from "node:os"; +import { type DateString, formatDate } from "compatx"; +import { defu } from "defu"; import destr from "destr"; -import { fetch, FetchOptions } from "ofetch"; -import { expect, it, afterAll, beforeAll, describe } from "vitest"; +import { type Listener, listen } from "listhen"; import { fileURLToPath } from "mlly"; -import { joinURL } from "ufo"; -import { defu } from "defu"; import { - createNitro, build, - prepare, copyPublicAssets, - prerender, createDevServer, + createNitro, + prepare, + prerender, } from "nitropack/core"; import type { Nitro, NitroConfig } from "nitropack/types"; -import { nodeMajorVersion, isWindows } from "std-env"; -import { type DateString, formatDate } from "compatx"; +import { type FetchOptions, fetch } from "ofetch"; +import { join, resolve } from "pathe"; +import { isWindows, nodeMajorVersion } from "std-env"; +import { joinURL } from "ufo"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; export interface Context { preset: string; @@ -495,13 +495,7 @@ export function testNitro( "server-config": true, }, sharedRuntimeConfig: { - dynamic: - // TODO - ctx.preset.includes("cloudflare") || - ctx.preset === "vercel-edge" || - ctx.preset === "nitro-dev" - ? "initial" - : "from-env", + dynamic: "from-env", // url: "https://test.com", app: { baseURL: "/", diff --git a/test/unit/azure.utils.test.ts b/test/unit/azure.utils.test.ts index 6a3b251a39..984e2f8975 100644 --- a/test/unit/azure.utils.test.ts +++ b/test/unit/azure.utils.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, expect, it } from "vitest"; import { getAzureParsedCookiesFromHeaders } from "../../src/runtime/internal/utils.azure"; describe("getAzureParsedCookiesFromHeaders", () => { diff --git a/test/unit/externals.test.ts b/test/unit/externals.test.ts index 47d8008cfb..ee2377ff6c 100644 --- a/test/unit/externals.test.ts +++ b/test/unit/externals.test.ts @@ -1,4 +1,4 @@ -import { expect, describe, it } from "vitest"; +import { describe, expect, it } from "vitest"; import { applyProductionCondition } from "../../src/rollup/plugins/externals"; describe("externals:applyProductionCondition", () => { diff --git a/test/unit/utils.env.test.ts b/test/unit/utils.env.test.ts index f807cd9a23..f4375a1c4c 100644 --- a/test/unit/utils.env.test.ts +++ b/test/unit/utils.env.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, expect, it } from "vitest"; import { applyEnv } from "../../src/runtime/internal/utils.env"; describe("env utils", () => {