Skip to content

Commit 8d75930

Browse files
committed
chore: lint fix
1 parent 8a3aa38 commit 8d75930

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

src/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ export default defineNuxtModule<RuntimeModuleOptions>({
243243
// Automatically exclude nuxt-users API routes from prerendering to prevent build hangs
244244
nitroConfig.prerender = nitroConfig.prerender || {}
245245
nitroConfig.prerender.ignore = nitroConfig.prerender.ignore || []
246-
246+
247247
const apiBasePath = (nuxt.options.runtimeConfig.nuxtUsers as ModuleOptions).apiBasePath || defaultOptions.apiBasePath
248248
const ignorePattern = `${apiBasePath}/**`
249-
249+
250250
if (!nitroConfig.prerender.ignore.includes(ignorePattern)) {
251251
nitroConfig.prerender.ignore.push(ignorePattern)
252252
console.log(`[Nuxt Users] 🔧 Automatically excluding "${ignorePattern}" from prerendering to prevent build hangs`)

src/runtime/plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
1717
if (!hasMigrationsTable) {
1818
console.warn('[Nuxt Users] ⚠️ Migrations table does not exist, you should run the migration script to create it by running: npx nuxt-users migrate')
1919
}
20-
} catch (error) {
20+
}
21+
catch (error) {
2122
// If database connection fails during runtime, warn but don't crash
2223
console.warn('[Nuxt Users] ⚠️ Database connection failed during initialization:', error instanceof Error ? error.message : 'Unknown error')
2324
}

src/runtime/server/utils/build-time.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ export const isBuildTime = (): boolean => {
77
if (process.env.NITRO_PRESET === 'nitro-prerender' || process.env.NUXT_ENV === 'prerender') {
88
return true
99
}
10-
10+
1111
// Check if we're in a prerendering context
1212
if (process.env.NODE_ENV === 'production' && process.argv.includes('--prerender')) {
1313
return true
1414
}
15-
15+
1616
// Check for common build/prerender indicators
1717
const buildIndicators = ['prerender', 'build', 'generate']
18-
return buildIndicators.some(indicator =>
19-
process.argv.join(' ').toLowerCase().includes(indicator) ||
20-
process.env.npm_lifecycle_event?.includes(indicator)
18+
return buildIndicators.some(indicator =>
19+
process.argv.join(' ').toLowerCase().includes(indicator)
20+
|| process.env.npm_lifecycle_event?.includes(indicator)
2121
)
22-
}
22+
}

src/runtime/server/utils/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { createDatabase } from 'db0'
22
import type { Database } from 'db0'
33
import type { ModuleOptions } from 'nuxt-users/utils'
44

5+
import { isBuildTime } from './build-time'
6+
57
const dbCache = new Map<string, Database>()
68

79
// Type for databases that have a disconnect method
@@ -42,8 +44,6 @@ export const getConnector = async (name: string) => {
4244
}
4345
}
4446

45-
import { isBuildTime } from './build-time'
46-
4747
export const useDb = async (options: ModuleOptions): Promise<Database> => {
4848
// During build/prerendering, throw an error to prevent hanging
4949
if (isBuildTime()) {

test/unit/build-time-detection.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
22
import { isBuildTime } from '../../src/runtime/server/utils/build-time'
33

44
describe('Build-time Detection', () => {
@@ -44,7 +44,7 @@ describe('Build-time Detection', () => {
4444
delete process.env.NUXT_ENV
4545
delete process.env.npm_lifecycle_event
4646
process.argv = ['node', 'server.js']
47-
47+
4848
expect(isBuildTime()).toBe(false)
4949
})
5050
})
@@ -53,10 +53,10 @@ describe('Build-time Detection', () => {
5353
it('should prevent database connections during build time', async () => {
5454
// Set build-time environment
5555
process.env.NITRO_PRESET = 'nitro-prerender'
56-
56+
5757
// Import the db module
5858
const { useDb } = await import('../../src/runtime/server/utils/db')
59-
59+
6060
const mockOptions = {
6161
connector: { name: 'sqlite' as const, options: { path: './test.db' } },
6262
tables: { migrations: 'migrations', users: 'users', personalAccessTokens: 'tokens', passwordResetTokens: 'reset_tokens' },
@@ -74,7 +74,7 @@ describe('Build-time Detection', () => {
7474
},
7575
hardDelete: false
7676
}
77-
77+
7878
// Should throw an error indicating build-time detection
7979
await expect(useDb(mockOptions))
8080
.rejects
@@ -86,22 +86,22 @@ describe('Build-time Detection', () => {
8686
it('should detect production builds with prerender flag', () => {
8787
process.env.NODE_ENV = 'production'
8888
process.argv = ['node', 'nuxt', 'build', '--prerender']
89-
89+
9090
expect(isBuildTime()).toBe(true)
9191
})
9292

9393
it('should detect generate command', () => {
9494
process.argv = ['node', 'nuxt', 'generate']
95-
95+
9696
expect(isBuildTime()).toBe(true)
9797
})
9898

9999
it('should not detect regular production server', () => {
100100
process.env.NODE_ENV = 'production'
101101
process.argv = ['node', 'server.js']
102102
delete process.env.npm_lifecycle_event
103-
103+
104104
expect(isBuildTime()).toBe(false)
105105
})
106106
})
107-
})
107+
})

0 commit comments

Comments
 (0)