Skip to content

Commit dd8e8df

Browse files
committed
fix: imports setup
1 parent 3982c0c commit dd8e8df

16 files changed

+48
-20
lines changed

build.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export default defineBuildConfig({
1818
declaration: true,
1919
clean: true,
2020
failOnWarn: false,
21+
// Configure alias resolution for build process
22+
alias: {
23+
'nuxt-users/utils': fileURLToPath(new URL('./src/utils/index.ts', import.meta.url))
24+
},
2125
rollup: {
2226
inlineDependencies: ['citty', 'defu'],
2327
alias: {

nuxt.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { BASE_CONFIG } from './src/constants'
2+
3+
export default defineNuxtConfig({
4+
...BASE_CONFIG,
5+
devtools: { enabled: true },
6+
modules: ['./src/module'],
7+
nitro: {
8+
experimental: {
9+
database: true,
10+
},
11+
},
12+
})

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@
5353
"nuxt-users": "./dist/cli.mjs"
5454
},
5555
"scripts": {
56-
"prepack": "nuxt-module-build build --stub && node scripts/post-build.js",
56+
"prepack": "nuxt-module-build build && node scripts/post-build.js",
5757
"postinstall": "node -e \"try { require('fs').chmodSync('./dist/cli.mjs', '755') } catch(e) {}\"",
5858
"predev": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for development' && exit 1)",
5959
"dev": "yarn dev:prepare && nuxi dev playground",
6060
"dev:build": "nuxi build playground",
6161
"dev:prepare": "yarn nuxt-module-build build --stub && yarn nuxt-module-build prepare && nuxi prepare playground",
62-
"build": "nuxt-module-build build --stub",
62+
"build": "nuxt-module-build build",
6363
"postbuild": "node scripts/post-build.js",
6464
"prerelease": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
6565
"release": "yarn lint && yarn test && changelogen --release && yarn build && yarn publish && git push --follow-tags",
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:types": "yarn dev:prepare && vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
69+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
7070
"test:unit": "./scripts/test-unit.sh",
7171
"test:sqlite": "./scripts/test-sqlite.sh",
7272
"test:mysql": "./scripts/test-mysql.sh",

scripts/post-build.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,27 @@ function fixImportPaths(dir) {
4444
if (item.isDirectory()) {
4545
fixImportPaths(fullPath)
4646
}
47-
else if (item.isFile() && (item.name.endsWith('.js') || item.name.endsWith('.vue'))) {
47+
else if (item.isFile() && (item.name.endsWith('.js') || item.name.endsWith('.mjs') || item.name.endsWith('.vue') || item.name.endsWith('.ts'))) {
4848
let content = readFileSync(fullPath, 'utf8')
4949
let modified = false
5050

51-
// Note: nuxt-users/utils imports are already correct for consumers
51+
// Transform relative imports to utils/imports back to nuxt-users/utils for consumers
52+
const relativeImportsRegex = /from\s+["'](\.\.[/\\])*utils[/\\]imports["']/g
53+
if (relativeImportsRegex.test(content)) {
54+
content = content.replace(relativeImportsRegex, 'from "nuxt-users/utils"')
55+
modified = true
56+
}
5257

53-
// Fix remaining relative imports to utils (add .js extensions)
54-
const utilsImportRegex = /from\s+["'](\.\.[/\\]){2,}utils\.js["']/g
58+
// Transform other relative utils imports
59+
const utilsImportRegex = /from\s+["']\.\.[/\\]utils[/\\]imports["']/g
5560
if (utilsImportRegex.test(content)) {
56-
content = content.replace(utilsImportRegex, match => match.replace(/utils\.js["']$/, 'utils.js"'))
61+
content = content.replace(utilsImportRegex, 'from "nuxt-users/utils"')
5762
modified = true
5863
}
5964

6065
if (modified) {
6166
writeFileSync(fullPath, content)
62-
console.log(`[Nuxt Users] Fixed import paths in ${fullPath}`)
67+
console.log(`[Nuxt Users] Transformed import paths in ${fullPath}`)
6368
}
6469
}
6570
}

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 'nuxt-users/utils'
3+
import type { RuntimeModuleOptions, ModuleOptions } from './types'
44

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

src/runtime/components/NUsersList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { ref, onMounted } from 'vue'
33
import { useRuntimeConfig } from '#imports'
4-
import { defaultDisplayFields, defaultFieldLabels, type DisplayFieldsProps, type User } from 'nuxt-users/utils'
4+
import { defaultDisplayFields, defaultFieldLabels, type DisplayFieldsProps, type User } from "nuxt-users/utils"
55
66
interface Pagination {
77
page: number

src/runtime/components/NUsersLoginForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { ref, computed } from 'vue'
33
import { navigateTo } from '#app'
4-
import type { LoginFormData, LoginFormProps, UserWithoutPassword, ModuleOptions } from 'nuxt-users/utils'
4+
import type { LoginFormData, LoginFormProps, UserWithoutPassword, ModuleOptions } from "nuxt-users/utils"
55
import { useRuntimeConfig } from '#imports'
66
77
const { public: { nuxtUsers } } = useRuntimeConfig()

src/runtime/components/NUsersPasswordStrengthIndicator.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { computed } from 'vue'
33
import type { PasswordValidationResult } from '../../utils'
44
import { useRuntimeConfig } from '#imports'
5-
import type { ModuleOptions } from 'nuxt-users/utils'
5+
import type { ModuleOptions } from "nuxt-users/utils"
66
77
interface Props {
88
password: string

src/runtime/components/NUsersResetPasswordForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* For password change: requires user to be logged in and provide current password
1212
*/
1313
import { ref, watch, computed } from 'vue'
14-
import type { UserWithoutPassword, ModuleOptions, ResetPasswordFormProps } from 'nuxt-users/utils'
14+
import type { UserWithoutPassword, ModuleOptions, ResetPasswordFormProps } from "nuxt-users/utils"
1515
import { usePasswordValidation } from '../composables/usePasswordValidation'
1616
import { useRuntimeConfig, useRoute, useRouter } from '#imports'
1717
import NUsersPasswordStrengthIndicator from './NUsersPasswordStrengthIndicator.vue'

src/runtime/components/NUsersUserCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { computed } from 'vue'
33
import { useAuthentication } from '../composables/useAuthentication'
44
import { useRuntimeConfig } from '#imports'
5-
import { defaultDisplayFields, defaultFieldLabels, type DisplayFieldsProps, type User } from 'nuxt-users/utils'
5+
import { defaultDisplayFields, defaultFieldLabels, type DisplayFieldsProps, type User } from "nuxt-users/utils"
66
77
interface Props extends DisplayFieldsProps {
88
user: User

0 commit comments

Comments
 (0)