Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 6b1426f

Browse files
authored
fix: resolve imports in a windows-friendly way (#13)
1 parent d6ea714 commit 6b1426f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/module.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { resolve } from 'path'
2-
import { fileURLToPath } from 'url'
3-
import { addImportsDir, addServerHandler, defineNuxtModule, useLogger } from '@nuxt/kit'
1+
import { addImportsDir, addServerHandler, createResolver, defineNuxtModule, useLogger } from '@nuxt/kit'
42
import { CreateStorageOptions } from 'unstorage'
53
import { defu } from 'defu'
64

@@ -139,10 +137,10 @@ export default defineNuxtModule<ModuleOptions>({
139137
nuxt.options.runtimeConfig.public = defu(nuxt.options.runtimeConfig.public, { session: { api: options.api } })
140138

141139
// 3. Locate runtime directory and transpile module
142-
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
140+
const { resolve } = createResolver(import.meta.url)
143141

144142
// 4. Setup middleware, use `.unshift` to ensure (reasonably well) that the session middleware is first
145-
const handler = resolve(runtimeDir, 'server/middleware/session')
143+
const handler = resolve('./runtime/server/middleware/session')
146144
const serverHandler = {
147145
middleware: true,
148146
handler
@@ -152,7 +150,7 @@ export default defineNuxtModule<ModuleOptions>({
152150
// 5. Register desired session API endpoints
153151
if (options.api.isEnabled) {
154152
for (const apiMethod of options.api.methods) {
155-
const handler = resolve(runtimeDir, `server/api/session.${apiMethod}`)
153+
const handler = resolve(`./runtime/server/api/session.${apiMethod}`)
156154
addServerHandler({ handler, route: options.api.basePath })
157155
}
158156
logger.info(`Session API "${options.api.methods.join(', ')}" endpoints registered at "${options.api.basePath}"`)
@@ -161,7 +159,7 @@ export default defineNuxtModule<ModuleOptions>({
161159
}
162160

163161
// 6. Add nuxt-session composables
164-
const composables = resolve(runtimeDir, 'composables')
162+
const composables = resolve('./runtime/composables')
165163
addImportsDir(composables)
166164

167165
logger.success('Session setup complete')

0 commit comments

Comments
 (0)