@dynect/base 0.10.4 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/module.ts +45 -58
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynect/base",
3
- "version": "0.10.4",
3
+ "version": "0.11.0",
4
4
  "description": "Reusable Nuxt base module — components, composables, utils, plugins and i18n from the Dynect design system.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/module.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { addComponentsDir, addImports, addImportsDir, addPlugin, createResolver, defineNuxtModule, installModule } from '@nuxt/kit';
2
- import { defu } from 'defu';
3
2
  import { existsSync } from 'node:fs';
4
3
  import { join } from 'node:path';
5
4
 
@@ -46,7 +45,7 @@ export default defineNuxtModule<DynectBaseOptions>({
46
45
  veeValidate: {},
47
46
  colorMode: {},
48
47
  i18n: {},
49
- shadcn: { prefix: '' },
48
+ shadcn: {},
50
49
  icon: {},
51
50
  plugins: { toast: true, ssrWidth: true },
52
51
  },
@@ -97,78 +96,66 @@ export default defineNuxtModule<DynectBaseOptions>({
97
96
  }
98
97
 
99
98
  // ── Install required Nuxt modules ────────────────────────────────────────
100
- // installModule is marked @deprecated in @nuxt/kit but is the only practical
101
- // API for installing sub-modules with dynamic options during a module's setup.
102
99
  if (options.shadcn !== false) {
103
- // Extract componentDir separately keeping it out of defaults prevents
104
- // defu from always populating it, which would override the computed path.
105
- const { componentDir: userComponentDir, ...shadcnRest } = (options.shadcn ?? {}) as { prefix?: string; componentDir?: string };
106
- const shadcnComponentDir = userComponentDir ?? (isStandalone ? join(runtimeComponentsDir, 'ui') : '~/components/ui');
100
+ const shadcnComponentDir = isStandalone ? join(runtimeComponentsDir, 'ui') : '~/components/ui';
107
101
 
108
- await installModule('shadcn-nuxt', { prefix: '', ...shadcnRest, componentDir: shadcnComponentDir }); // NOSONAR
102
+ await installModule('shadcn-nuxt', {
103
+ prefix: '',
104
+ componentDir: shadcnComponentDir,
105
+ });
109
106
  }
110
107
 
111
108
  if (options.veeValidate !== false) {
112
- await installModule('@vee-validate/nuxt', options.veeValidate ?? {}); // NOSONAR
109
+ await installModule('@vee-validate/nuxt', options.veeValidate ?? {});
113
110
  }
114
111
 
115
112
  if (options.colorMode !== false) {
116
- // defu(user, defaults): user keys win; nested objects are deep-merged, not replaced
117
- await installModule(
118
- '@nuxtjs/color-mode',
119
- defu(options.colorMode ?? {}, {
120
- // NOSONAR
121
- preference: 'system',
122
- fallback: 'light',
123
- classPrefix: '',
124
- classSuffix: '',
125
- storage: 'cookie',
126
- storageKey: 'dynect_color_mode',
127
- })
128
- );
113
+ await installModule('@nuxtjs/color-mode', {
114
+ preference: 'system',
115
+ fallback: 'light',
116
+ classPrefix: '',
117
+ classSuffix: '',
118
+ storage: 'cookie',
119
+ storageKey: 'dynect_color_mode',
120
+ ...options.colorMode,
121
+ });
129
122
  }
130
123
 
131
124
  if (options.i18n !== false) {
132
125
  const langDir = isStandalone ? resolver.resolve('./runtime/assets/lang') : resolver.resolve('../../../app/assets/lang');
133
126
 
134
- await installModule(
135
- '@nuxtjs/i18n',
136
- defu(options.i18n ?? {}, {
137
- // NOSONAR
138
- locales: [
139
- { code: 'en', iso: 'en_US', file: 'en.json', name: 'English' },
140
- { code: 'ms', iso: 'ms_MY', file: 'ms.json', name: 'Bahasa' },
141
- ],
142
- langDir,
143
- defaultLocale: 'en',
144
- strategy: 'no_prefix',
145
- detectBrowserLanguage: {
146
- useCookie: true,
147
- cookieKey: 'dynect_language',
148
- cookieSecure: true,
149
- redirectOn: 'root',
150
- alwaysRedirect: true,
151
- },
152
- })
153
- );
127
+ await installModule('@nuxtjs/i18n', {
128
+ locales: [
129
+ { code: 'en', iso: 'en_US', file: 'en.json', name: 'English' },
130
+ { code: 'ms', iso: 'ms_MY', file: 'ms.json', name: 'Bahasa' },
131
+ ],
132
+ langDir,
133
+ defaultLocale: 'en',
134
+ strategy: 'no_prefix',
135
+ detectBrowserLanguage: {
136
+ useCookie: true,
137
+ cookieKey: 'dynect_language',
138
+ cookieSecure: true,
139
+ redirectOn: 'root',
140
+ alwaysRedirect: true,
141
+ },
142
+ ...options.i18n,
143
+ });
154
144
  }
155
145
 
156
146
  if (options.icon !== false) {
157
- await installModule(
158
- '@nuxt/icon',
159
- defu(options.icon ?? {}, {
160
- // NOSONAR
161
- provider: 'server',
162
- mode: 'svg',
163
- serverBundle: {
164
- collections: ['heroicons', 'lucide', 'mdi'],
165
- remote: false,
166
- },
167
- })
168
- );
147
+ await installModule('@nuxt/icon', {
148
+ provider: 'server',
149
+ mode: 'svg',
150
+ serverBundle: {
151
+ collections: ['heroicons', 'lucide', 'mdi'],
152
+ remote: false,
153
+ },
154
+ ...options.icon,
155
+ });
169
156
  }
170
157
 
171
- await installModule('@pinia/nuxt'); // NOSONAR
158
+ await installModule('@pinia/nuxt');
172
159
 
173
160
  // ── CSS ──────────────────────────────────────────────────────────────────
174
161
  const cssPath = isStandalone ? resolver.resolve('./runtime/assets/css/main.css') : resolver.resolve('../../../app/assets/css/main.css');
@@ -178,13 +165,13 @@ export default defineNuxtModule<DynectBaseOptions>({
178
165
  }
179
166
 
180
167
  // ── Components ───────────────────────────────────────────────────────────
181
- for (const dir of options.dirs) {
168
+ for (const dir of options.dirs!) {
182
169
  const dirPath = join(componentsBase, dir);
183
170
  if (!existsSync(dirPath)) continue;
184
171
 
185
172
  addComponentsDir({
186
173
  path: dirPath,
187
- prefix: DIR_CONFIGS[dir].prefix,
174
+ prefix: DIR_CONFIGS[dir]!.prefix,
188
175
  pathPrefix: false,
189
176
  global: options.global,
190
177
  });