Skip to content

Commit b284437

Browse files
committed
chore: logs
1 parent 68d110a commit b284437

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

core/scripts/testing/scripts.js

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,42 @@
5656

5757
async function loadThemeTokens(themeName, paletteName) {
5858
try {
59-
// Dynamically import the theme tokens
60-
const defaultTokens = await import(`/dist/themes/${themeName}/default.tokens.js`);
61-
const theme = defaultTokens.defaultTheme;
59+
// Try multiple import paths to ensure compatibility across environments
60+
let defaultTokens;
61+
let theme;
62+
63+
// Get the base URL from the current location (similar to how set-content.ts works)
64+
const baseUrl = window.location.origin;
65+
66+
console.info(`Attempting to load theme tokens for ${themeName} with palette ${paletteName}`);
67+
console.info(`Base URL: ${baseUrl}`);
68+
console.info(`Current location: ${window.location.href}`);
69+
70+
// First try the base URL path (matches how set-content.ts imports Ionic)
71+
try {
72+
const importPath = `${baseUrl}/dist/themes/${themeName}/default.tokens.js`;
73+
console.info(`Trying import path: ${importPath}`);
74+
defaultTokens = await import(importPath);
75+
theme = defaultTokens.defaultTheme;
76+
} catch (baseUrlError) {
77+
console.warn(`Failed to load from ${baseUrl}/dist/themes/${themeName}/default.tokens.js, trying relative paths:`, baseUrlError);
78+
79+
// Try the relative dist path (matches how test files import Ionic)
80+
try {
81+
defaultTokens = await import(`../../../../../dist/themes/${themeName}/default.tokens.js`);
82+
theme = defaultTokens.defaultTheme;
83+
} catch (relativeDistError) {
84+
console.warn(`Failed to load from ../../../../../dist/themes/${themeName}/default.tokens.js, trying absolute paths:`, relativeDistError);
85+
86+
// Try absolute dist path
87+
try {
88+
defaultTokens = await import(`/dist/themes/${themeName}/default.tokens.js`);
89+
theme = defaultTokens.defaultTheme;
90+
} catch (absoluteDistError) {
91+
console.warn(`Failed to load from /dist/themes/${themeName}/default.tokens.js, trying simple relative path:`, absoluteDistError);
92+
}
93+
}
94+
}
6295

6396
// If a specific palette is requested, modify the palette structure
6497
// to set the enabled property to 'always'
@@ -71,13 +104,30 @@
71104
window.Ionic.config = window.Ionic.config || {};
72105
window.Ionic.config.customTheme = theme;
73106

74-
// Re-apply the global theme
107+
// Re-apply the global theme with multiple fallback paths
75108
if (window.Ionic.config.get && window.Ionic.config.set) {
76-
import('/dist/themes/utils/theme.js').then(themeModule => {
77-
themeModule.applyGlobalTheme(theme);
78-
}).catch(() => {
79-
console.warn('Could not reapply theme - theme module not found');
80-
});
109+
const themeUtilsPaths = [
110+
`${baseUrl}/dist/themes/utils/theme.js`,
111+
'../../../../../dist/themes/utils/theme.js',
112+
'/dist/themes/utils/theme.js',
113+
'./themes/utils/theme.js'
114+
];
115+
116+
let themeUtilsLoaded = false;
117+
for (const path of themeUtilsPaths) {
118+
try {
119+
const themeModule = await import(path);
120+
themeModule.applyGlobalTheme(theme);
121+
themeUtilsLoaded = true;
122+
break;
123+
} catch (error) {
124+
// Continue to next path
125+
}
126+
}
127+
128+
if (!themeUtilsLoaded) {
129+
console.warn('Could not reapply theme - theme module not found in any path');
130+
}
81131
}
82132

83133
console.info(`Loaded ${themeName} theme with palette ${paletteName}:`, theme);

0 commit comments

Comments
 (0)