Skip to content

Commit 7dd48f6

Browse files
committed
refactor: utils directory and fixes import paths
Updates import paths to align with the new utils directory structure. Specifically, it moves user-related utilities into a dedicated 'user' subdirectory and database utilities into a 'db' subdirectory within 'src/runtime/server/utils'. Also standardizes import paths and ensures proper module resolution by addressing inconsistencies in file extensions.
1 parent 9f1cdfb commit 7dd48f6

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

build.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default defineBuildConfig({
2222
inlineDependencies: ['citty', 'defu'],
2323
alias: {
2424
entries: [
25-
{ find: '#nuxt-users/types', replacement: fileURLToPath(new URL('./src/types.ts', import.meta.url)) }
25+
{ find: 'nuxt-users/utils', replacement: fileURLToPath(new URL('./src/utils/index.ts', import.meta.url)) }
2626
]
2727
}
2828
},

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@
6666
"lint": "eslint .",
6767
"lint:fix": "eslint . --fix",
6868
"pretest": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for testing' && exit 1)",
69-
"test": "yarn test:types && yarn test:unit && yarn test:sqlite && yarn test:mysql && yarn test:postgresql",
70-
"test:watch": "vitest watch",
69+
"test:types": "yarn dev:prepare && vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
7170
"test:unit": "./scripts/test-unit.sh",
7271
"test:sqlite": "./scripts/test-sqlite.sh",
7372
"test:mysql": "./scripts/test-mysql.sh",
7473
"test:postgresql": "./scripts/test-postgresql.sh",
75-
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
74+
"test": "yarn test:types && yarn test:unit && yarn test:sqlite && yarn test:mysql && yarn test:postgresql",
75+
"test:watch": "vitest watch",
7676
"db:create-users-table": "tsx src/cli/create-users-table.ts",
7777
"db:create-user": "tsx src/cli/create-user.ts",
7878
"db:create-personal-access-tokens-table": "tsx src/cli/create-personal-access-tokens-table.ts",

scripts/post-build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ function fixImportPaths(dir) {
4848
let content = readFileSync(fullPath, 'utf8')
4949
let modified = false
5050

51-
// Note: #nuxt-users/types imports are now handled by TypeScript module resolution
51+
// Note: nuxt-users/utils imports are already correct for consumers
5252

53-
// Fix relative imports to utils (../../../utils -> ../../../utils.js)
54-
const utilsImportRegex = /from\s+["'](\.\.[/\\]){2,}utils["']/g
53+
// Fix remaining relative imports to utils (add .js extensions)
54+
const utilsImportRegex = /from\s+["'](\.\.[/\\]){2,}utils\.js["']/g
5555
if (utilsImportRegex.test(content)) {
56-
content = content.replace(utilsImportRegex, match => match.replace(/utils["']$/, 'utils.js"'))
56+
content = content.replace(utilsImportRegex, match => match.replace(/utils\.js["']$/, 'utils.js"'))
5757
modified = true
5858
}
5959

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineNuxtModule, createResolver, addServerHandler, addComponent, addPlugin, addImportsDir, addRouteMiddleware, addServerImportsDir } from '@nuxt/kit'
22
import { defu } from 'defu'
3-
import type { RuntimeModuleOptions, ModuleOptions } from './types'
3+
import type { RuntimeModuleOptions, ModuleOptions } from 'nuxt-users/utils'
44

55
export const defaultOptions: ModuleOptions = {
66
connector: {

src/runtime/server/api/nuxt-users/password/index.patch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createError, defineEventHandler, getCookie, readBody } from 'h3'
22
import bcrypt from 'bcrypt'
33
import type { ModuleOptions } from 'nuxt-users/utils'
44
import { useRuntimeConfig } from '#imports'
5-
import { getCurrentUserFromToken, updateUserPassword } from '../../../utils'
5+
import { getCurrentUserFromToken, updateUserPassword } from '../../../utils/user'
66
import { validatePassword, getPasswordValidationOptions } from '../../../../../utils'
77

88
export default defineEventHandler(async (event) => {

src/runtime/server/api/nuxt-users/session/index.delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineEventHandler, getCookie, setCookie } from 'h3'
22
import type { ModuleOptions } from 'nuxt-users/utils'
33
import { useRuntimeConfig } from '#imports'
4-
import { useDb } from '../../../utils'
4+
import { useDb } from '../../../utils/db'
55

66
export default defineEventHandler(async (event) => {
77
const { nuxtUsers } = useRuntimeConfig()

src/runtime/server/api/nuxt-users/session/index.post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import bcrypt from 'bcrypt'
33
import crypto from 'node:crypto'
44
import type { ModuleOptions, User } from 'nuxt-users/utils'
55
import { useRuntimeConfig } from '#imports'
6-
import { useDb } from '../../../utils'
6+
import { useDb } from '../../../utils/db'
77

88
export default defineEventHandler(async (event) => {
99
const body = await readBody(event)

src/runtime/server/utils/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useDb } from './db'
22
import bcrypt from 'bcrypt'
3-
import { validatePassword, getPasswordValidationOptions } from '../../../utils'
3+
import { validatePassword, getPasswordValidationOptions } from 'nuxt-users/utils'
44
import type { ModuleOptions, User, UserWithoutPassword } from 'nuxt-users/utils'
55

66
interface CreateUserParams {

0 commit comments

Comments
 (0)