@dynect/base 0.12.0 → 0.13.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 +26 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynect/base",
3
- "version": "0.12.0",
3
+ "version": "0.13.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,28 +69,41 @@ export default defineNuxtModule<DynectBaseOptions>({
69
69
 
70
70
  const srcDir = nuxt.options.srcDir;
71
71
 
72
- // @/lib/utils runtime/lib/utils (when not present in consuming app)
73
- // This one works via nuxt.options.alias because lib/utils is not prefixed with @
74
- if (!existsSync(join(srcDir, 'lib', 'utils.ts'))) {
75
- nuxt.options.alias[join(srcDir, 'lib', 'utils')] = resolver.resolve('./runtime/lib/utils');
76
- }
77
-
78
- // @/components/ui/* → runtime/components/ui/*
79
- // Must run BEFORE @ is resolved, so we use a regex alias in vite:extendConfig.
80
- // Only applied when the consuming app has no own components/ui directory.
81
- if (isStandalone && !existsSync(join(srcDir, 'components', 'ui'))) {
72
+ // In standalone mode, intercept @/lib/utils and @/components/ui BEFORE Vite
73
+ // expands the @ alias to srcDir. nuxt.options.alias cannot do this because
74
+ // Vite resolves @ → srcDir in a single pass and never checks aliases again.
75
+ // We prepend regex aliases via vite:extendConfig so they fire first.
76
+ if (isStandalone) {
82
77
  const uiRuntimePath = join(runtimeComponentsDir, 'ui');
78
+ const libUtilsRuntimePath = resolver.resolve('./runtime/lib/utils');
79
+
80
+ // Only redirect @/lib/utils when the consuming app has no own lib/utils
81
+ const hasOwnLibUtils = existsSync(join(srcDir, 'lib', 'utils.ts'));
82
+ // Only redirect @/components/ui when the consuming app has no own components/ui
83
+ const hasOwnComponentsUi = existsSync(join(srcDir, 'components', 'ui'));
83
84
 
84
85
  nuxt.hook('vite:extendConfig', (config) => {
85
86
  config.resolve ??= {};
86
87
 
87
- const entry = { find: /^[@~]\/components\/ui/, replacement: uiRuntimePath };
88
+ const entries: { find: RegExp; replacement: string }[] = [];
89
+
90
+ if (!hasOwnComponentsUi) {
91
+ entries.push({ find: /^[@~]\/components\/ui/, replacement: uiRuntimePath });
92
+ }
93
+ if (!hasOwnLibUtils) {
94
+ entries.push({ find: /^[@~]\/lib\/utils/, replacement: libUtilsRuntimePath });
95
+ }
96
+
97
+ if (entries.length === 0) return;
88
98
 
89
99
  if (Array.isArray(config.resolve.alias)) {
90
- config.resolve.alias.unshift(entry);
100
+ config.resolve.alias.unshift(...entries);
91
101
  } else {
92
102
  const existing = config.resolve.alias ?? {};
93
- config.resolve.alias = [entry, ...Object.entries(existing).map(([find, replacement]) => ({ find, replacement }))];
103
+ config.resolve.alias = [
104
+ ...entries,
105
+ ...Object.entries(existing).map(([find, replacement]) => ({ find, replacement })),
106
+ ];
94
107
  }
95
108
  });
96
109
  }