Skip to content

Commit

Permalink
fix: prefer explicit import paths over #imports
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Dec 7, 2024
1 parent 34afb2e commit f3a292e
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { resolve } from 'node:path'
import { startSubprocess } from '@nuxt/devtools-kit'
import {createResolver, defineNuxtModule} from '@nuxt/kit'
import { createResolver, defineNuxtModule } from '@nuxt/kit'
import { defineNuxtConfig } from 'nuxt/config'
import NuxtSitConfig from '../packages/module/src/module'

const resolver = createResolver(import.meta.url)

process.env.playground = true
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"vitest": "^2.1.8"
},
"resolutions": {
"vue": "3.5.13",
"typescript": "5.6.3"
"typescript": "5.6.3",
"vue": "3.5.13"
}
}
2 changes: 1 addition & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"scripts": {
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare",
"release": "bumpp package.json --commit --push --tag",
"test": "vitest",
"typecheck": "tsc --noEmit"
Expand Down
3 changes: 1 addition & 2 deletions packages/module/src/runtime/app/component/SiteLink.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts" setup>
import type { CreateSitePathResolverOptions } from '../../types'
import { resolveComponent } from '#imports'
import { computed, toRefs } from 'vue'
import { computed, resolveComponent, toRefs } from 'vue'
import { createSitePathResolver } from '../composables/utils'
const props = defineProps<CreateSitePathResolverOptions & {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type {
SiteConfigInput,
} from 'site-config-stack'
import { useRequestEvent } from '#imports'
import { consola } from 'consola'
import { useRequestEvent } from 'nuxt/app'

export function updateSiteConfig(input: SiteConfigInput = {}): void {
if (process.server) {
const stack = useRequestEvent().context.siteConfig
stack.push(input)
const stack = useRequestEvent()?.context.siteConfig
stack?.push(input)
return
}
if (process.dev)
Expand Down
4 changes: 2 additions & 2 deletions packages/module/src/runtime/app/composables/useNitroOrigin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { H3Event } from 'h3'
import { useRequestEvent } from '#imports'
import { useRequestEvent } from 'nuxt/app'

export function useNitroOrigin(e?: H3Event): string {
if (process.server) {
e = e || useRequestEvent()
return e.context.siteConfigNitroOrigin
return e?.context?.siteConfigNitroOrigin || ''
}
if (process.client)
return window.location.origin
Expand Down
4 changes: 2 additions & 2 deletions packages/module/src/runtime/app/composables/useSiteConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { GetSiteConfigOptions, SiteConfigResolved } from 'site-config-stack'
import type { NuxtSiteConfig } from '../../types'
import { defu } from 'defu'
import {
useNuxtApp,
useRequestEvent,
} from '#imports'
import { defu } from 'defu'
} from 'nuxt/app'

export function useSiteConfig(options?: GetSiteConfigOptions): NuxtSiteConfig {
let stack: Omit<SiteConfigResolved, '_context'>
Expand Down
3 changes: 2 additions & 1 deletion packages/module/src/runtime/app/composables/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ComputedRef, MaybeRef, Ref } from 'vue'
import type { VueCreateSitePathResolverOptions } from '../../types'
import { computed, unref, useRuntimeConfig } from '#imports'
import { useRuntimeConfig } from 'nuxt/app'
import { fixSlashes, resolveSitePath } from 'site-config-stack/urls'
import { computed, unref } from 'vue'
import { useNitroOrigin } from './useNitroOrigin'
import { useSiteConfig } from './useSiteConfig'

Expand Down
3 changes: 1 addition & 2 deletions packages/module/src/runtime/app/plugins/0.siteConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { SiteConfigResolved } from 'site-config-stack'
import { useRequestEvent, useRuntimeConfig, useState } from '#imports'
import { defineNuxtPlugin } from 'nuxt/app'
import { defineNuxtPlugin, useRequestEvent, useRuntimeConfig, useState } from 'nuxt/app'

export default defineNuxtPlugin({
name: 'nuxt-site-config:init',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { H3Event } from 'h3'
import type { GetSiteConfigOptions } from 'site-config-stack'
import type { NuxtSiteConfig } from '../../types'
import { useRuntimeConfig } from '#imports'
import { defu } from 'defu'
import { useRuntimeConfig } from 'nitropack/runtime'
import { createSiteConfigStack } from 'site-config-stack'

export function useSiteConfig(e: H3Event, _options?: GetSiteConfigOptions): NuxtSiteConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SiteConfigInput } from 'site-config-stack'
import { useNitroOrigin, useRuntimeConfig, useSiteConfig } from '#imports'
import { useNitroOrigin } from '#site-config/server/composables/useNitroOrigin'
import { useSiteConfig } from '#site-config/server/composables/useSiteConfig'
import { defineEventHandler, setHeader } from 'h3'
import { useRuntimeConfig } from 'nitropack/runtime'

export default defineEventHandler(async (e) => {
const siteConfig = useSiteConfig(e)
Expand Down

0 comments on commit f3a292e

Please sign in to comment.