Skip to content

Commit

Permalink
fix(imports): use explicit imports (#2839)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Nov 2, 2024
1 parent 51faaf3 commit 615cc05
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
55 changes: 41 additions & 14 deletions src/core/config/resolvers/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,53 @@ export async function resolveImportsOptions(options: NitroOptions) {
function getNitroImportsPreset(): Preset[] {
return [
{
from: "nitropack/runtime",
from: "nitropack/runtime/internal/app",
imports: ["useNitroApp"],
},
{
from: "nitropack/runtime/internal/config",
imports: ["useRuntimeConfig", "useAppConfig"],
},
{
from: "nitropack/runtime/internal/plugin",
imports: ["defineNitroPlugin", "nitroPlugin"],
},
{
from: "nitropack/runtime/internal/cache",
imports: [
"defineCachedFunction",
"defineCachedEventHandler",
"cachedFunction",
"cachedEventHandler",
"useRuntimeConfig",
"useStorage",
"useNitroApp",
"defineNitroPlugin",
"nitroPlugin",
"defineRenderHandler",
"defineRouteMeta",
"getRouteRules",
"useAppConfig",
"useEvent",
"defineTask",
"runTask",
"defineNitroErrorHandler",
],
},
{
from: "nitropack/runtime/internal/storage",
imports: ["useStorage"],
},
{
from: "nitropack/runtime/internal/renderer",
imports: ["defineRenderHandler"],
},
{
from: "nitropack/runtime/internal/meta",
imports: ["defineRouteMeta"],
},
{
from: "nitropack/runtime/internal/route-rules",
imports: ["getRouteRules"],
},
{
from: "nitropack/runtime/internal/context",
imports: ["useEvent"],
},
{
from: "nitropack/runtime/internal/task",
imports: ["defineTask", "runTask"],
},
{
from: "nitropack/runtime/internal/error",
imports: ["defineNitroErrorHandler"],
},
];
}
1 change: 1 addition & 0 deletions test/fixture/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
APP_DOMAIN=test.com
NITRO_DYNAMIC=from-env
8 changes: 7 additions & 1 deletion test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export async function setupTest(
CUSTOM_HELLO_THERE: "general",
SECRET: "secret",
APP_DOMAIN: "test.com",
NITRO_DYNAMIC: "from-env",
},
fetch: (url, opts) =>
fetch(joinURL(ctx.server!.url, url.slice(1)), {
Expand Down Expand Up @@ -503,7 +504,12 @@ export function testNitro(
"server-config": true,
},
sharedRuntimeConfig: {
dynamic: "from-env",
// Cloudflare environment variables are set after first request
dynamic:
ctx.preset.includes("cloudflare") &&
ctx.preset !== "cloudflare-worker"
? "initial"
: "from-env",
// url: "https://test.com",
app: {
baseURL: "/",
Expand Down

0 comments on commit 615cc05

Please sign in to comment.