Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: export defineNitroConfig from nitro/config #1174

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
],
Expand Down
1 change: 1 addition & 0 deletions config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/config";
2 changes: 1 addition & 1 deletion docs/content/1.guide/1.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.guide/3.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.guide/4.storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 3 additions & 3 deletions docs/content/1.guide/5.cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions docs/content/1.guide/6.assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down Expand Up @@ -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: [{
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.guide/7.plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.deploy/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions docs/content/3.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineNitroConfig } from "nitropack";
import { defineNitroConfig } from "nitropack/config";

export default defineNitroConfig({});
2 changes: 1 addition & 1 deletion examples/auto-imports/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineNitroConfig } from "nitropack";
import { defineNitroConfig } from "nitropack/config";

export default defineNitroConfig({});
2 changes: 1 addition & 1 deletion examples/cached-handler/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineNitroConfig } from "nitropack";
import { defineNitroConfig } from "nitropack/config";

export default defineNitroConfig({});
2 changes: 1 addition & 1 deletion examples/custom-error-handler/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNitroConfig } from "nitropack";
import { defineNitroConfig } from "nitropack/config";
import errorHandler from "./error";

export default defineNitroConfig({
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineNitroConfig } from "nitropack";
import { defineNitroConfig } from "nitropack/config";

export default defineNitroConfig({});
2 changes: 1 addition & 1 deletion examples/middleware/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineNitroConfig } from "nitropack";
import { defineNitroConfig } from "nitropack/config";

export default defineNitroConfig({});
2 changes: 1 addition & 1 deletion examples/plugins/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNitroConfig } from "nitropack";
import { defineNitroConfig } from "nitropack/config";

export default defineNitroConfig({
plugins: ["~/plugins/test"],
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -22,7 +26,8 @@
"nitropack": "./dist/cli.mjs"
},
"files": [
"dist"
"dist",
"*.d.ts"
],
"scripts": {
"build": "unbuild",
Expand Down
2 changes: 1 addition & 1 deletion playground/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineNitroConfig } from "../src";
import { defineNitroConfig } from "nitropack/config";

export default defineNitroConfig({});
1 change: 1 addition & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"paths": {
"nitropack": ["../src/index"],
"nitropack/config": ["../src/config"],
"#internal/nitro": ["../src/runtime/index"],
"#internal/nitro/*": ["../src/runtime/*"]
}
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { NitroConfig } from "./types";

export function defineNitroConfig(config: NitroConfig): NitroConfig {
return config;
}
10 changes: 10 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string, NitroConfig>;
let matchedPreset = presets[camelCase(id)] || presets[id];
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion test/fixture/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNitroConfig } from "../../src";
import { defineNitroConfig } from "../../src/config";

export default defineNitroConfig({
compressPublicAssets: true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"resolveJsonModule": true,
"paths": {
"nitropack": ["./src/index"],
"nitropack/config": ["./src/config"],
"#internal/nitro": ["./src/runtime/index"],
"#internal/nitro/*": ["./src/runtime/*"]
}
Expand Down