Skip to content

Commit e80b160

Browse files
committed
refactor: module utils and improves CLI output
1 parent 6b45d71 commit e80b160

8 files changed

Lines changed: 13 additions & 32 deletions

File tree

AGENTS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Use FormKit to build forms
21
When db0 is used in the queryies if the ${var} format gives an error try using {${var}}

package.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,19 @@
4545
},
4646
"main": "./dist/module.mjs",
4747
"types": "./dist/types.d.mts",
48-
"typesVersions": {
49-
"*": {
50-
".": [
51-
"./dist/types.d.mts"
52-
],
53-
"utils": [
54-
"./dist/utils.d.mts"
55-
]
56-
}
57-
},
5848
"files": [
5949
"dist"
6050
],
6151
"bin": {
6252
"nuxt-users": "./dist/cli.mjs"
6353
},
64-
"engines": {
65-
"node": ">=22.0.0"
66-
},
67-
6854
"scripts": {
6955
"prepack": "nuxt-module-build build",
7056
"postinstall": "node -e \"try { require('fs').chmodSync('./dist/cli.mjs', '755') } catch(e) {}\"",
7157
"predev": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for development' && exit 1)",
7258
"dev": "yarn dev:prepare && nuxi dev playground",
7359
"dev:build": "nuxi build playground",
74-
"dev:prepare": "yarn nuxt-module-build build && yarn nuxt-module-build prepare && nuxi prepare playground",
60+
"dev:prepare": "yarn nuxt-module-build build --stub && yarn nuxt-module-build prepare && nuxi prepare playground",
7561
"build": "nuxt-module-build build",
7662
"prerelease": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
7763
"release": "yarn lint && yarn test && yarn build && changelogen --release && yarn publish && git push --follow-tags",

src/cli/project-info.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineCommand } from 'citty'
22
import { loadNuxt } from '@nuxt/kit'
3+
import type { ModuleOptions } from '../types'
34

45
export default defineCommand({
56
meta: {
@@ -16,7 +17,7 @@ export default defineCommand({
1617
console.log('🌐 Base URL:', nuxt.options.app?.baseURL || '/')
1718

1819
// Check if nuxt-users module is configured
19-
const nuxtUsersConfig = nuxt.options.runtimeConfig?.nuxtUsers
20+
const nuxtUsersConfig = nuxt.options.runtimeConfig?.nuxtUsers as ModuleOptions
2021
if (nuxtUsersConfig) {
2122
console.log('🔧 Nuxt Users module configuration:')
2223
console.log(' Database connector:', nuxtUsersConfig.connector?.name)
@@ -29,7 +30,7 @@ export default defineCommand({
2930
}
3031

3132
// Check public runtime config
32-
const publicConfig = nuxt.options.runtimeConfig?.public?.nuxtUsers
33+
const publicConfig = nuxt.options.runtimeConfig?.public?.nuxtUsers as ModuleOptions
3334
if (publicConfig) {
3435
console.log('🌍 Public runtime config:')
3536
console.log(' Users table exists:', publicConfig.tables?.users)

src/runtime/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineNuxtPlugin, useRuntimeConfig } from '#app'
22
import type { ModuleOptions } from '../types'
3-
import { checkTableExists } from 'nuxt-users/utils'
3+
import { checkTableExists } from '../utils'
44

55
export default defineNuxtPlugin(async (_nuxtApp) => {
66
// Only run on server side since we're checking database tables

src/runtime/server/api/login.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 '../../../types'
55
import { useRuntimeConfig } from '#imports'
6-
import { useDb } from 'nuxt-users/utils'
6+
import { useDb } from '../../../utils'
77

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

src/runtime/server/services/password.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { createTransport } from 'nodemailer'
22
import crypto from 'node:crypto'
33
import bcrypt from 'bcrypt'
4-
import { findUserByEmail, updateUserPassword } from 'nuxt-users/utils'
5-
import { useDb } from 'nuxt-users/utils'
4+
import { findUserByEmail, updateUserPassword, useDb } from '../../../utils'
65
import type { ModuleOptions } from '../../../types'
76

87
const TOKEN_EXPIRATION_HOURS = 1

src/utils/db.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export const getConnector = async (name: string) => {
1313
default:
1414
throw new Error(`Unsupported database connector: ${name}`)
1515
}
16-
} catch (error) {
16+
}
17+
catch (error) {
1718
if (error instanceof Error && error.message.includes('Cannot resolve')) {
18-
throw new Error(`Database connector "${name}" not found. Please install the required peer dependency:\n` +
19-
`- For sqlite: yarn add better-sqlite3\n` +
20-
`- For mysql: yarn add mysql2\n` +
21-
`- For postgresql: yarn add pg`)
19+
throw new Error(`Database connector "${name}" not found. Please install the required peer dependency:\n`
20+
+ '- For sqlite: yarn add better-sqlite3\n'
21+
+ '- For mysql: yarn add mysql2\n'
22+
+ '- For postgresql: yarn add pg')
2223
}
2324
throw error
2425
}

tsconfig.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
22
"extends": "./.nuxt/tsconfig.json",
3-
"compilerOptions": {
4-
"paths": {
5-
"nuxt-users/utils": ["./src/utils/index"]
6-
}
7-
},
83
"exclude": [
94
"dist",
105
"node_modules",

0 commit comments

Comments
 (0)