Skip to content

Commit

Permalink
feat: exports for ./utils instead of composable
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrotule committed Jun 25, 2024
1 parent f53bb80 commit 75c259d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 16 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
},
"./types": {
"types": "./src/types.d.ts"
},
"./utils": {
"types": "./dist/runtime/utils.d.ts",
"import": "./dist/runtime/utils.js"
}
},
"main": "./dist/module.cjs",
Expand Down
3 changes: 1 addition & 2 deletions playground/composables/useUrqlClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DocumentNode } from 'graphql'
import { provideClient, useQuery } from '@urql/vue'
import type { AnyVariables } from '@urql/vue'
import { getQueryTimelineName } from 'nuxt-request-timeline/utils'

export const URQL_CLIENT_NUXT_APP_KEY = 'urql'

Expand All @@ -13,9 +14,7 @@ export function useUrqlQuery<T = any, V extends AnyVariables = AnyVariables>(
options: Omit<Parameters<typeof useQuery<T, V>>[0], 'query'> & { query: DocumentNode }
) {
const { query, variables } = options

const timeline = useRequestTimeline()
const { getQueryTimelineName } = useRequestTimelineUtils()

const client = useUrqlClient()
provideClient(client)
Expand Down
9 changes: 2 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
REQUEST_TIMELINE_IMPORT_ALIAS,
REQUEST_TIMELINE_ROUTE_NAME,
REQUEST_TIMELINE_ROUTE_PATH,
} from './constants.js'
} from './runtime/constants.js'
import type { RequestTimeline } from './runtime/RequestTimeline'
import type { ModuleOptions } from './types'

Expand Down Expand Up @@ -69,12 +69,7 @@ export default defineNuxtModule<ModuleOptions>({
].join('\n'),
})

addImports([
...['useRequestTimeline', 'useRequestTimelineUtils'].map(name => ({
name,
from: resolve('runtime/composables'),
})),
])
addImports([{ name: 'useRequestTimeline', from: resolve('runtime/composables') }])

nuxt.options.alias[REQUEST_TIMELINE_IMPORT_ALIAS] = resolve(
nuxt.options.buildDir,
Expand Down
6 changes: 1 addition & 5 deletions src/runtime/composables.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { useNuxtApp } from '#imports'
import { getRequestTimeline, getQueryTimelineName } from './utils.js'
import { getRequestTimeline } from './utils.js'

export function useRequestTimeline() {
return getRequestTimeline(useNuxtApp())
}

export function useRequestTimelineUtils() {
return { getQueryTimelineName }
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineNuxtPlugin, useRouter } from '#imports'
import { options } from '#requestTimeline'
import { RequestTimeline } from './RequestTimeline.js'
import { generateUrl } from './utils.js'
import { REQUEST_TIMELINE_KEY } from '../constants.js'
import { REQUEST_TIMELINE_KEY } from './constants.js'

const LOG_STYLES = 'background-color: darkblue; border: 3px solid darkblue; color: white;'

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
REQUEST_TIMELINE_KEY,
REQUEST_TIMELINE_ROUTE_PATH,
REQUEST_TIMELINE_ROUTE_QUERY,
} from '../constants'
} from './constants'
import type { RequestTimeline } from '../types'

type AnyObject = Record<string, unknown>
Expand Down

0 comments on commit 75c259d

Please sign in to comment.