mage-obsidian 1.0.4 → 1.0.5
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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import configResolver from "./configResolver.cjs";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
export default function customAssetsResolverPlugin() {
|
|
6
|
+
const CURRENT_THEME = process.env.CURRENT_THEME;
|
|
7
|
+
const THEME_ASSETS_PATH = 'web';
|
|
8
|
+
const MODULE_ASSETS_PATH = 'view/frontend/web';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function tryResolveAssetPathByTheme(themeName, filePath) {
|
|
12
|
+
const themeDefinition = configResolver.getThemeDefinition(themeName);
|
|
13
|
+
if (!themeDefinition) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const themeAssetPath = path.join(themeDefinition.src, filePath);
|
|
18
|
+
|
|
19
|
+
if (fs.existsSync(themeAssetPath)) {
|
|
20
|
+
return themeAssetPath;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (themeDefinition.parent) {
|
|
24
|
+
return tryResolveAssetPathByTheme(themeDefinition.parent, filePath);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function tryResolveAssetPathByModule(moduleName, filePath) {
|
|
31
|
+
const moduleDefinition = configResolver.getModuleDefinition(moduleName);
|
|
32
|
+
const assetPath = path.join(moduleDefinition.src, MODULE_ASSETS_PATH, filePath);
|
|
33
|
+
if (fs.existsSync(assetPath)) {
|
|
34
|
+
return assetPath;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const resolveAssetPath = (moduleName, filePath) => {
|
|
41
|
+
if (!filePath.startsWith("assets/")) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
let assetSrc = null;
|
|
45
|
+
if (moduleName === "Theme") {
|
|
46
|
+
assetSrc = tryResolveAssetPathByTheme(CURRENT_THEME, path.join(THEME_ASSETS_PATH, filePath));
|
|
47
|
+
} else {
|
|
48
|
+
assetSrc = tryResolveAssetPathByTheme(CURRENT_THEME, path.join(moduleName, THEME_ASSETS_PATH, filePath));
|
|
49
|
+
}
|
|
50
|
+
if (!assetSrc) {
|
|
51
|
+
assetSrc = tryResolveAssetPathByModule(moduleName, filePath);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return assetSrc;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
name: "inherit-assets-resolver",
|
|
59
|
+
resolveId: {
|
|
60
|
+
order: 'pre',
|
|
61
|
+
handler(id) {
|
|
62
|
+
if (!id) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const idParts = id.split("::");
|
|
66
|
+
if (idParts.length === 1) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const [moduleName, filePath] = idParts;
|
|
70
|
+
const assetSrc = resolveAssetPath(moduleName, filePath);
|
|
71
|
+
if (!assetSrc) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return assetSrc;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -5,13 +5,6 @@ import configResolver from "./configResolver.cjs";
|
|
|
5
5
|
export default function customResolverPlugin() {
|
|
6
6
|
const allComponents = moduleResolver.getAllJsVueFilesWithInheritanceCached();
|
|
7
7
|
const validComponentExtensions = configResolver.getMagentoConfig().ALLOWED_EXTENSIONS;
|
|
8
|
-
const extensionsPattern = validComponentExtensions.map((ext) =>
|
|
9
|
-
ext.replace('.', '')
|
|
10
|
-
).join("|");
|
|
11
|
-
const dynamicRegex = new RegExp(
|
|
12
|
-
`(["'])([\\w\\d]+::[\\w\\d/]+\\.(${extensionsPattern}))\\1`,
|
|
13
|
-
"g"
|
|
14
|
-
);
|
|
15
8
|
|
|
16
9
|
const hasValidExtension = (filePath) =>
|
|
17
10
|
validComponentExtensions.some((ext) => filePath.endsWith(ext));
|