@dynect/base 0.5.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 +24 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynect/base",
3
- "version": "0.5.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
@@ -71,21 +71,40 @@ export default defineNuxtModule<DynectBaseOptions>({
71
71
 
72
72
  // ── Path aliases for intra-package imports ───────────────────────────────
73
73
  // Dynect components use @/components/ui/* and @/lib/utils.
74
- // In standalone mode, @/ resolves to the consuming app's srcDir which won't
75
- // have those paths redirect them to the bundled runtime copies.
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.
76
77
 
77
78
  const srcDir = nuxt.options.srcDir;
78
79
 
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 @
80
82
  if (!existsSync(join(srcDir, 'lib', 'utils.ts'))) {
81
83
  nuxt.options.alias[join(srcDir, 'lib', 'utils')] =
82
84
  resolver.resolve('./runtime/lib/utils');
83
85
  }
84
86
 
85
- // @/components/ui/* → runtime/components/ui/* (when not present in consuming app)
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.
86
90
  if (isStandalone && !existsSync(join(srcDir, 'components', 'ui'))) {
87
- nuxt.options.alias[join(srcDir, 'components', 'ui')] =
88
- join(runtimeComponentsDir, '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
+ });
89
108
  }
90
109
 
91
110
  // ── Install required Nuxt modules ────────────────────────────────────────