mage-obsidian 1.0.8 → 1.0.9
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.
package/package.json
CHANGED
|
@@ -144,11 +144,8 @@ async function setupResolvers(scenario) {
|
|
|
144
144
|
__esModule: true,
|
|
145
145
|
default: createMockConfigResolver(scenario).default,
|
|
146
146
|
}));
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
import('#service/moduleResolverSync.js'),
|
|
150
|
-
import('#service/themeResolverSync.js'),
|
|
151
|
-
]);
|
|
147
|
+
const moduleResolver = await import('#service/moduleResolver.js');
|
|
148
|
+
const themeResolver = await import('#service/themeResolverSync.js');
|
|
152
149
|
|
|
153
150
|
return { moduleResolver, themeResolver };
|
|
154
151
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import themeResolver from './themeResolverSync.js';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { MODULE_WEB_PATH, THEME_CSS_FOLDER, THEME_MODULE_WEB_PATH } from '../config/default.js';
|
|
4
|
-
import { resolveFileByTheme } from './
|
|
4
|
+
import { resolveFileByTheme } from './moduleResolver.js';
|
|
5
5
|
import configResolver from './configResolver.js';
|
|
6
6
|
import fs from 'node:fs/promises';
|
|
7
7
|
|
|
@@ -97,7 +97,94 @@ async function getAllJsVueFilesWithInheritance(themeName) {
|
|
|
97
97
|
return cachedModulesByTheme[themeName];
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
const moduleConfigByThemeCache = new Map();
|
|
101
|
+
|
|
102
|
+
const MODULE_CONFIG_FILE = configResolver.getMagentoConfig().MODULE_CONFIG_FILE;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Gets the theme configuration file path.
|
|
106
|
+
* @param {string} moduleSrc
|
|
107
|
+
* @returns {string} Full path to the configuration file.
|
|
108
|
+
*/
|
|
109
|
+
function getModuleConfigPath(moduleSrc) {
|
|
110
|
+
return path.join(moduleSrc, 'view/frontend/web/', MODULE_CONFIG_FILE);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function resolveFileByTheme(themeName, moduleName, filePath, includeTailwindConfigFromParentThemes) {
|
|
114
|
+
const theme = configResolver.getMagentoConfig().themes[themeName];
|
|
115
|
+
const fullFilePath = path.join(theme.src, moduleName, 'web', filePath);
|
|
116
|
+
if (fs.existsSync(fullFilePath)) {
|
|
117
|
+
return fullFilePath;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (includeTailwindConfigFromParentThemes && theme.parent) {
|
|
121
|
+
return resolveFileByTheme(theme.parent, moduleName, filePath, includeTailwindConfigFromParentThemes);
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function resolveModuleConfig(moduleName, themeName, includeTailwindConfigFromParentThemes) {
|
|
127
|
+
const module = configResolver.getMagentoConfig().modules[moduleName];
|
|
128
|
+
let moduleConfigSourcePath = resolveFileByTheme(themeName, moduleName, MODULE_CONFIG_FILE, includeTailwindConfigFromParentThemes);
|
|
129
|
+
|
|
130
|
+
if (!moduleConfigSourcePath && !module) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
if (!moduleConfigSourcePath) {
|
|
134
|
+
moduleConfigSourcePath = getModuleConfigPath(module.src);
|
|
135
|
+
}
|
|
136
|
+
if (!fs.existsSync(moduleConfigSourcePath)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Importación dinámica común en ESModules
|
|
141
|
+
const moduleConfig = await import(moduleConfigSourcePath);
|
|
142
|
+
return moduleConfig.default ?? moduleConfig;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Retrieves the Tailwind configuration for a theme synchronously.
|
|
147
|
+
* Uses a cache system to optimize performance.
|
|
148
|
+
* @param {string} themeName - Name of the theme.
|
|
149
|
+
* @param {object} themeConfig
|
|
150
|
+
* @returns {object|null} Tailwind configuration object.
|
|
151
|
+
*/
|
|
152
|
+
async function getModuleConfigByThemeConfig(themeName, themeConfig) {
|
|
153
|
+
if (moduleConfigByThemeCache.has(themeName)) {
|
|
154
|
+
return moduleConfigByThemeCache.get(themeName);
|
|
155
|
+
}
|
|
156
|
+
if (!themeConfig) return null;
|
|
157
|
+
const modules = configResolver.getAllMagentoModulesEnabled();
|
|
158
|
+
let modulesConfig = {};
|
|
159
|
+
|
|
160
|
+
for (const moduleName of modules) {
|
|
161
|
+
let moduleConfig = await resolveModuleConfig(moduleName, themeName, themeConfig.includeTailwindConfigFromParentThemes);
|
|
162
|
+
if (!moduleConfig) continue;
|
|
163
|
+
if (
|
|
164
|
+
themeConfig.ignoredTailwindConfigFromModules === 'all' ||
|
|
165
|
+
themeConfig.ignoredTailwindConfigFromModules.includes(moduleName)
|
|
166
|
+
) {
|
|
167
|
+
moduleConfig.tailwind = {};
|
|
168
|
+
} else if (moduleConfig.tailwind?.content) {
|
|
169
|
+
const moduleSrc = configResolver.getMagentoConfig().modules[moduleName].src;
|
|
170
|
+
moduleConfig.tailwind.content = moduleConfig.tailwind.content.map((content) =>
|
|
171
|
+
path.join(moduleSrc, 'view/frontend/web', content)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
modulesConfig = deepmerge(modulesConfig, moduleConfig);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
moduleConfigByThemeCache.set(themeName, modulesConfig);
|
|
179
|
+
return modulesConfig;
|
|
180
|
+
}
|
|
181
|
+
|
|
100
182
|
export default {
|
|
101
183
|
getAllJsVueFilesWithInheritance,
|
|
102
|
-
getAllJsVueFilesWithInheritanceCached
|
|
184
|
+
getAllJsVueFilesWithInheritanceCached,
|
|
185
|
+
getModuleConfigByThemeConfig,
|
|
186
|
+
resolveFileByTheme
|
|
103
187
|
};
|
|
188
|
+
|
|
189
|
+
export { getModuleConfigByThemeConfig, resolveFileByTheme };
|
|
190
|
+
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import deepmerge from 'deepmerge';
|
|
4
|
-
import configResolver from './configResolver.js';
|
|
5
|
-
|
|
6
|
-
const moduleConfigByThemeCache = new Map();
|
|
7
|
-
|
|
8
|
-
const MODULE_CONFIG_FILE = configResolver.getMagentoConfig().MODULE_CONFIG_FILE;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Gets the theme configuration file path.
|
|
12
|
-
* @param {string} moduleSrc
|
|
13
|
-
* @returns {string} Full path to the configuration file.
|
|
14
|
-
*/
|
|
15
|
-
function getModuleConfigPath(moduleSrc) {
|
|
16
|
-
return path.join(moduleSrc, 'view/frontend/web/', MODULE_CONFIG_FILE);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function resolveFileByTheme(themeName, moduleName, filePath, includeTailwindConfigFromParentThemes) {
|
|
20
|
-
const theme = configResolver.getMagentoConfig().themes[themeName];
|
|
21
|
-
const fullFilePath = path.join(theme.src, moduleName, 'web', filePath);
|
|
22
|
-
if (fs.existsSync(fullFilePath)) {
|
|
23
|
-
return fullFilePath;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (includeTailwindConfigFromParentThemes && theme.parent) {
|
|
27
|
-
return resolveFileByTheme(theme.parent, moduleName, filePath, includeTailwindConfigFromParentThemes);
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function resolveModuleConfig(moduleName, themeName, includeTailwindConfigFromParentThemes) {
|
|
33
|
-
const module = configResolver.getMagentoConfig().modules[moduleName];
|
|
34
|
-
let moduleConfigSourcePath = resolveFileByTheme(themeName, moduleName, MODULE_CONFIG_FILE, includeTailwindConfigFromParentThemes);
|
|
35
|
-
|
|
36
|
-
if (!moduleConfigSourcePath && !module) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
if (!moduleConfigSourcePath) {
|
|
40
|
-
moduleConfigSourcePath = getModuleConfigPath(module.src);
|
|
41
|
-
}
|
|
42
|
-
if (!fs.existsSync(moduleConfigSourcePath)) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Importación dinámica común en ESModules
|
|
47
|
-
const moduleConfig = await import(moduleConfigSourcePath);
|
|
48
|
-
return moduleConfig.default ?? moduleConfig;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves the Tailwind configuration for a theme synchronously.
|
|
53
|
-
* Uses a cache system to optimize performance.
|
|
54
|
-
* @param {string} themeName - Name of the theme.
|
|
55
|
-
* @param {object} themeConfig
|
|
56
|
-
* @returns {object|null} Tailwind configuration object.
|
|
57
|
-
*/
|
|
58
|
-
async function getModuleConfigByThemeConfig(themeName, themeConfig) {
|
|
59
|
-
if (moduleConfigByThemeCache.has(themeName)) {
|
|
60
|
-
return moduleConfigByThemeCache.get(themeName);
|
|
61
|
-
}
|
|
62
|
-
if (!themeConfig) return null;
|
|
63
|
-
const modules = configResolver.getAllMagentoModulesEnabled();
|
|
64
|
-
let modulesConfig = {};
|
|
65
|
-
|
|
66
|
-
for (const moduleName of modules) {
|
|
67
|
-
let moduleConfig = await resolveModuleConfig(moduleName, themeName, themeConfig.includeTailwindConfigFromParentThemes);
|
|
68
|
-
if (!moduleConfig) continue;
|
|
69
|
-
if (
|
|
70
|
-
themeConfig.ignoredTailwindConfigFromModules === 'all' ||
|
|
71
|
-
themeConfig.ignoredTailwindConfigFromModules.includes(moduleName)
|
|
72
|
-
) {
|
|
73
|
-
moduleConfig.tailwind = {};
|
|
74
|
-
} else if (moduleConfig.tailwind?.content) {
|
|
75
|
-
const moduleSrc = configResolver.getMagentoConfig().modules[moduleName].src;
|
|
76
|
-
moduleConfig.tailwind.content = moduleConfig.tailwind.content.map((content) =>
|
|
77
|
-
path.join(moduleSrc, 'view/frontend/web', content)
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
modulesConfig = deepmerge(modulesConfig, moduleConfig);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
moduleConfigByThemeCache.set(themeName, modulesConfig);
|
|
85
|
-
return modulesConfig;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { getModuleConfigByThemeConfig, resolveFileByTheme };
|
|
89
|
-
|
|
90
|
-
export default {
|
|
91
|
-
getModuleConfigByThemeConfig,
|
|
92
|
-
resolveFileByTheme
|
|
93
|
-
};
|