Skip to content

Commit

Permalink
fix: types in nitro and aliases on Windows (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
dulnan authored Dec 17, 2024
1 parent 4e79df1 commit ef944a7
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'url'
import type { Types } from '@graphql-codegen/plugin-helpers'
import { type SchemaASTConfig } from '@graphql-codegen/schema-ast'
import { relative, resolve, parse as pathParse, join as pathJoin } from 'pathe'
import { relative, resolve } from 'pathe'
import { defu } from 'defu'
import { type BirpcGroup } from 'birpc'
import {
Expand Down Expand Up @@ -36,11 +36,6 @@ import { type ClientFunctions, type ServerFunctions } from './rpc-types'
import { type GraphqlMiddlewareDocument } from './types'
export type { GraphqlMiddlewareServerOptions } from './types'

function pathWithoutExtension(fullPath: string): string {
const parsed = pathParse(fullPath)
return pathJoin(parsed.dir, parsed.name)
}

export interface ModuleOptions {
/**
* File glob patterns for the auto import feature.
Expand Down Expand Up @@ -243,6 +238,10 @@ export default defineNuxtModule<ModuleOptions>({
async setup(passedOptions, nuxt) {
const options = defu({}, passedOptions, defaultOptions) as ModuleOptions

function addAlias(name: string, aliasPath: string) {
nuxt.options.alias[name] = aliasPath
}

const isModuleBuild =
process.env.MODULE_BUILD === 'true' && nuxt.options._prepare

Expand Down Expand Up @@ -470,20 +469,15 @@ export default defineNuxtModule<ModuleOptions>({
})

if (result.dst.includes(GraphqlMiddlewareTemplate.Documents)) {
nuxt.options.alias['#graphql-documents'] = pathWithoutExtension(
result.dst,
)
addAlias('#graphql-documents', result.dst)
} else if (
result.dst.includes(GraphqlMiddlewareTemplate.OperationTypes)
) {
nuxt.options.alias['#graphql-operations'] = pathWithoutExtension(
result.dst,
)
addAlias('#graphql-operations', result.dst)
} else if (
result.dst.includes(GraphqlMiddlewareTemplate.ComposableContext)
) {
nuxt.options.alias['#nuxt-graphql-middleware/generated-types'] =
pathWithoutExtension(result.dst)
addAlias('#nuxt-graphql-middleware/generated-types', result.dst)
}
})

Expand Down Expand Up @@ -644,17 +638,16 @@ export type GraphqlClientContext = {}
},
})

nuxt.options.alias['#graphql-middleware-client-options'] =
pathWithoutExtension(clientOptionsTemplate.dst)
addAlias('#graphql-middleware-client-options', clientOptionsTemplate.dst)

nuxt.options.nitro.externals = nuxt.options.nitro.externals || {}
nuxt.options.nitro.externals.inline =
nuxt.options.nitro.externals.inline || []
nuxt.options.nitro.externals.inline.push(template.dst)
nuxt.options.alias['#graphql-middleware-server-options-build'] =
pathWithoutExtension(template.dst)
addAlias('#graphql-middleware-server-options-build', template.dst)

nuxt.options.alias['#graphql-middleware/types'] = pathWithoutExtension(
addAlias(
'#graphql-middleware/types',
moduleResolver.resolve('./runtime/types.ts'),
)

Expand Down

0 comments on commit ef944a7

Please sign in to comment.