@dynect/base 0.4.0 → 0.6.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 +35 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynect/base",
3
- "version": "0.4.0",
3
+ "version": "0.6.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
@@ -69,15 +69,44 @@ export default defineNuxtModule<DynectBaseOptions>({
69
69
  const isStandalone = existsSync(join(runtimeComponentsDir, 'dynect'));
70
70
  const componentsBase = isStandalone ? runtimeComponentsDir : monorepoComponentsDir;
71
71
 
72
- // ── Ensure ~/lib/utils is available in the consuming app ─────────────────
73
- // Components import { cn } from '~/lib/utils'. If the consuming app does
74
- // not have that file we point the resolver at the bundled copy.
75
- const consumingLibUtils = join(nuxt.options.srcDir, 'lib', 'utils.ts');
76
- if (!existsSync(consumingLibUtils)) {
77
- nuxt.options.alias[join(nuxt.options.srcDir, 'lib', 'utils')] =
72
+ // ── Path aliases for intra-package imports ───────────────────────────────
73
+ // Dynect components use @/components/ui/* and @/lib/utils.
74
+ // nuxt.options.alias cannot intercept these because Vite first expands @→srcDir
75
+ // and stops alias processing. We must hook into vite:extendConfig and prepend
76
+ // regex aliases so they match *before* the @ alias fires.
77
+
78
+ const srcDir = nuxt.options.srcDir;
79
+
80
+ // @/lib/utils → runtime/lib/utils (when not present in consuming app)
81
+ // This one works via nuxt.options.alias because lib/utils is not prefixed with @
82
+ if (!existsSync(join(srcDir, 'lib', 'utils.ts'))) {
83
+ nuxt.options.alias[join(srcDir, 'lib', 'utils')] =
78
84
  resolver.resolve('./runtime/lib/utils');
79
85
  }
80
86
 
87
+ // @/components/ui/* → runtime/components/ui/*
88
+ // Must run BEFORE @ is resolved, so we use a regex alias in vite:extendConfig.
89
+ // Only applied when the consuming app has no own components/ui directory.
90
+ if (isStandalone && !existsSync(join(srcDir, 'components', 'ui'))) {
91
+ const uiRuntimePath = join(runtimeComponentsDir, 'ui');
92
+
93
+ nuxt.hook('vite:extendConfig', (config) => {
94
+ config.resolve ??= {};
95
+
96
+ const entry = { find: /^[@~]\/components\/ui/, replacement: uiRuntimePath };
97
+
98
+ if (Array.isArray(config.resolve.alias)) {
99
+ (config.resolve.alias as any[]).unshift(entry);
100
+ } else {
101
+ const existing = config.resolve.alias ?? {};
102
+ config.resolve.alias = [
103
+ entry,
104
+ ...Object.entries(existing).map(([find, replacement]) => ({ find, replacement })),
105
+ ];
106
+ }
107
+ });
108
+ }
109
+
81
110
  // ── Install required Nuxt modules ────────────────────────────────────────
82
111
  if (options.shadcn !== false) {
83
112
  await installModule('shadcn-nuxt', {