diff --git a/build.config.ts b/build.config.ts index f498d78420..a981cf04fb 100644 --- a/build.config.ts +++ b/build.config.ts @@ -5,6 +5,7 @@ export default defineBuildConfig({ name: "nitro", entries: [ "src/index", + "src/config", "src/cli/cli", { input: "src/runtime/", outDir: "dist/runtime", format: "esm" }, ], diff --git a/config.d.ts b/config.d.ts new file mode 100644 index 0000000000..0fe54cfd87 --- /dev/null +++ b/config.d.ts @@ -0,0 +1 @@ +export * from "./dist/config"; diff --git a/docs/content/1.guide/1.configuration.md b/docs/content/1.guide/1.configuration.md index 113e5e1803..deebbf16b0 100644 --- a/docs/content/1.guide/1.configuration.md +++ b/docs/content/1.guide/1.configuration.md @@ -12,7 +12,7 @@ If you are using [Nuxt](https://nuxt.com), use the `nitro` option in your Nuxt c ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from 'nitropack' +import { defineNitroConfig } from 'nitropack/config' export default defineNitroConfig({ // Nitro options diff --git a/docs/content/1.guide/3.routing.md b/docs/content/1.guide/3.routing.md index ee14c9b86d..4871c1ac41 100644 --- a/docs/content/1.guide/3.routing.md +++ b/docs/content/1.guide/3.routing.md @@ -117,7 +117,7 @@ When `cache` option is set, handlers matching pattern will be automatically wrap ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from 'nitropack' +import { defineNitroConfig } from 'nitropack/config' export default defineNitroConfig({ routeRules: { diff --git a/docs/content/1.guide/4.storage.md b/docs/content/1.guide/4.storage.md index 0e4ecd9d6f..b42eb3bf2b 100644 --- a/docs/content/1.guide/4.storage.md +++ b/docs/content/1.guide/4.storage.md @@ -27,7 +27,7 @@ You can mount storage drivers using the `storage` option: ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from 'nitropack' +import { defineNitroConfig } from 'nitropack/config' export default defineNitroConfig({ storage: { diff --git a/docs/content/1.guide/5.cache.md b/docs/content/1.guide/5.cache.md index d3e18de76a..e04bf81e2b 100644 --- a/docs/content/1.guide/5.cache.md +++ b/docs/content/1.guide/5.cache.md @@ -14,7 +14,7 @@ To overwrite the production storage, set the `cache` mountpoint using the `stora ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ storage: { @@ -123,7 +123,7 @@ Cache all the blog routes for 1 hour with `stale-while-revalidate` behavior: ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ routeRules: { @@ -156,7 +156,7 @@ If we want to use a custom storage mountpoint, we can use the `base` option. Let ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ storage: { diff --git a/docs/content/1.guide/6.assets.md b/docs/content/1.guide/6.assets.md index c7ecd0094c..34d02f7020 100644 --- a/docs/content/1.guide/6.assets.md +++ b/docs/content/1.guide/6.assets.md @@ -63,7 +63,7 @@ In order to add assets from a custom directory, path will need to be defined in ::code-group ```js [nitro.config.ts] -import { defineNitroConfig } from 'nitropack' +import { defineNitroConfig } from 'nitropack/config' export default defineNitroConfig({ serverAssets: [{ @@ -101,7 +101,7 @@ export default defineEventHandler(async () => { ::code-group ```js [nitro.config.ts] -import { defineNitroConfig } from 'nitropack' +import { defineNitroConfig } from 'nitropack/config' export default defineNitroConfig({ serverAssets: [{ diff --git a/docs/content/1.guide/7.plugins.md b/docs/content/1.guide/7.plugins.md index 20ff253a05..040151c3b4 100644 --- a/docs/content/1.guide/7.plugins.md +++ b/docs/content/1.guide/7.plugins.md @@ -31,7 +31,7 @@ If you have plugins in another directory, you can use the `plugins` option: ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from 'nitropack' +import { defineNitroConfig } from 'nitropack/config' export default defineNitroConfig({ plugins: ['my-plugins/hello.ts'] diff --git a/docs/content/2.deploy/0.index.md b/docs/content/2.deploy/0.index.md index d8b7472d12..96ca27c50e 100644 --- a/docs/content/2.deploy/0.index.md +++ b/docs/content/2.deploy/0.index.md @@ -38,7 +38,7 @@ NITRO_PRESET=aws-lambda nitro build **Example:** Using [nitro.config.ts](/config/) ```ts -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ preset: 'node-server' diff --git a/docs/content/3.config.md b/docs/content/3.config.md index 4d23befb3c..402883708e 100644 --- a/docs/content/3.config.md +++ b/docs/content/3.config.md @@ -11,7 +11,7 @@ In order to customize Nitro's behavior, we create a file named `nitro.config.ts` ::code-group ```ts [nitro.config.ts] -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ // options @@ -251,7 +251,7 @@ Path to a custom runtime error handler. Replacing nitro's built-in error page. **Example:** ```js [nitro.config] -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ errorHandler: "~/error", diff --git a/examples/api-routes/nitro.config.ts b/examples/api-routes/nitro.config.ts index 0d2ca51b59..c19a01864d 100644 --- a/examples/api-routes/nitro.config.ts +++ b/examples/api-routes/nitro.config.ts @@ -1,3 +1,3 @@ -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({}); diff --git a/examples/auto-imports/nitro.config.ts b/examples/auto-imports/nitro.config.ts index 0d2ca51b59..c19a01864d 100644 --- a/examples/auto-imports/nitro.config.ts +++ b/examples/auto-imports/nitro.config.ts @@ -1,3 +1,3 @@ -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({}); diff --git a/examples/cached-handler/nitro.config.ts b/examples/cached-handler/nitro.config.ts index 0d2ca51b59..c19a01864d 100644 --- a/examples/cached-handler/nitro.config.ts +++ b/examples/cached-handler/nitro.config.ts @@ -1,3 +1,3 @@ -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({}); diff --git a/examples/custom-error-handler/nitro.config.ts b/examples/custom-error-handler/nitro.config.ts index ba0adbda20..758b26de41 100644 --- a/examples/custom-error-handler/nitro.config.ts +++ b/examples/custom-error-handler/nitro.config.ts @@ -1,4 +1,4 @@ -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; import errorHandler from "./error"; export default defineNitroConfig({ diff --git a/examples/hello-world/nitro.config.ts b/examples/hello-world/nitro.config.ts index 0d2ca51b59..c19a01864d 100644 --- a/examples/hello-world/nitro.config.ts +++ b/examples/hello-world/nitro.config.ts @@ -1,3 +1,3 @@ -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({}); diff --git a/examples/middleware/nitro.config.ts b/examples/middleware/nitro.config.ts index 0d2ca51b59..c19a01864d 100644 --- a/examples/middleware/nitro.config.ts +++ b/examples/middleware/nitro.config.ts @@ -1,3 +1,3 @@ -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({}); diff --git a/examples/plugins/nitro.config.ts b/examples/plugins/nitro.config.ts index 05e210f7fe..95ae3dedf4 100644 --- a/examples/plugins/nitro.config.ts +++ b/examples/plugins/nitro.config.ts @@ -1,4 +1,4 @@ -import { defineNitroConfig } from "nitropack"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({ plugins: ["~/plugins/test"], diff --git a/package.json b/package.json index 59176e5e54..363a0cac89 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,10 @@ "types": "./dist/index.d.ts", "import": "./dist/index.mjs" }, + "./config": { + "types": "./dist/config.d.ts", + "import": "./dist/config.mjs" + }, "./cli": "./dist/cli.mjs", "./runtime/*": "./dist/runtime/*.mjs", "./dist/runtime/*": "./dist/runtime/*.mjs", @@ -22,7 +26,8 @@ "nitropack": "./dist/cli.mjs" }, "files": [ - "dist" + "dist", + "*.d.ts" ], "scripts": { "build": "unbuild", diff --git a/playground/nitro.config.ts b/playground/nitro.config.ts index 8185335729..c19a01864d 100644 --- a/playground/nitro.config.ts +++ b/playground/nitro.config.ts @@ -1,3 +1,3 @@ -import { defineNitroConfig } from "../src"; +import { defineNitroConfig } from "nitropack/config"; export default defineNitroConfig({}); diff --git a/playground/tsconfig.json b/playground/tsconfig.json index a0e3fbad2e..cc5f8fe766 100644 --- a/playground/tsconfig.json +++ b/playground/tsconfig.json @@ -3,6 +3,7 @@ "compilerOptions": { "paths": { "nitropack": ["../src/index"], + "nitropack/config": ["../src/config"], "#internal/nitro": ["../src/runtime/index"], "#internal/nitro/*": ["../src/runtime/*"] } diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000000..4e018f494e --- /dev/null +++ b/src/config.ts @@ -0,0 +1,5 @@ +import type { NitroConfig } from "./types"; + +export function defineNitroConfig(config: NitroConfig): NitroConfig { + return config; +} diff --git a/src/options.ts b/src/options.ts index f7e337f3b9..95bd8d6979 100644 --- a/src/options.ts +++ b/src/options.ts @@ -115,6 +115,7 @@ export async function loadOptions( // Load configuration and preset configOverrides = klona(configOverrides); + globalThis.defineNitroConfig = globalThis.defineNitroConfig || ((c) => c); const { config, layers } = await loadConfig({ name: "nitro", cwd: configOverrides.rootDir, @@ -128,6 +129,12 @@ export async function loadOptions( preset: detectTarget() || "node-server", }, defaults: NitroDefaults, + jitiOptions: { + alias: { + nitropack: "nitropack/config", + "nitropack/config": "nitropack/config", + }, + }, resolve(id: string) { const presets = _PRESETS as any as Map; let matchedPreset = presets[camelCase(id)] || presets[id]; @@ -369,6 +376,9 @@ export async function loadOptions( return options; } +/** + * @deprecated Please import `defineNitroConfig` from nitropack/config instead + */ export function defineNitroConfig(config: NitroConfig): NitroConfig { return config; } diff --git a/test/fixture/nitro.config.ts b/test/fixture/nitro.config.ts index f461934ae0..22e8c62a0b 100644 --- a/test/fixture/nitro.config.ts +++ b/test/fixture/nitro.config.ts @@ -1,4 +1,4 @@ -import { defineNitroConfig } from "../../src"; +import { defineNitroConfig } from "../../src/config"; export default defineNitroConfig({ compressPublicAssets: true, diff --git a/test/fixture/types.ts b/test/fixture/types.ts index 9aaaab49c6..8c655e7224 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -1,7 +1,7 @@ import { expectTypeOf } from "expect-type"; import { describe, it } from "vitest"; import { $Fetch } from "../.."; -import { defineNitroConfig } from "../../src/options"; +import { defineNitroConfig } from "../../src/config"; interface TestResponse { message: string; diff --git a/tsconfig.json b/tsconfig.json index 2702dafafc..029b104a21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,6 +12,7 @@ "resolveJsonModule": true, "paths": { "nitropack": ["./src/index"], + "nitropack/config": ["./src/config"], "#internal/nitro": ["./src/runtime/index"], "#internal/nitro/*": ["./src/runtime/*"] }