Skip to content

Commit ad5e0fe

Browse files
authored
Merge pull request #75 from andibraeu/main
fix build without custom config
2 parents 850d4b5 + df9d76c commit ad5e0fe

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

.github/workflows/deploy.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ jobs:
1414
- name: Checkout code
1515
uses: actions/checkout@v5
1616

17+
- name: Create custom.config.mjs from secret
18+
run: |
19+
if [ -n "${{ secrets.CUSTOM_CONFIG }}" ]; then
20+
cat > custom.config.mjs << 'EOF'
21+
${{ secrets.CUSTOM_CONFIG }}
22+
EOF
23+
echo "custom.config.mjs created from secret"
24+
else
25+
echo "CUSTOM_CONFIG secret not set, skipping custom.config.mjs creation"
26+
fi
27+
1728
- name: Setup Node.js
1829
uses: actions/setup-node@v6
1930
with:

config-loader.mjs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,25 @@ const defaultConfig = {
101101
// Try to load custom config (optional, for forks)
102102
let customConfig = {};
103103
try {
104-
const customModule = await import('./custom.config.mjs');
105-
customConfig = customModule.default || customModule || {};
104+
// Check if file exists before importing
105+
const fs = await import('node:fs');
106+
const path = await import('node:path');
107+
const { fileURLToPath, pathToFileURL } = await import('node:url');
108+
109+
// Get the directory of the current module
110+
const __filename = fileURLToPath(import.meta.url);
111+
const __dirname = path.dirname(__filename);
112+
const customConfigPath = path.join(__dirname, 'custom.config.mjs');
113+
114+
if (fs.existsSync(customConfigPath)) {
115+
// Use dynamic import with file:// URL to prevent static analysis by Vite/Rollup
116+
const customConfigUrl = pathToFileURL(customConfigPath).href;
117+
const customModule = await import(customConfigUrl);
118+
customConfig = customModule.default || customModule || {};
119+
}
106120
} catch (error) {
107-
// custom.config.mjs doesn't exist, use defaults only
108-
// This is expected for the default repository
121+
// custom.config.mjs doesn't exist or couldn't be loaded, use defaults only
122+
// This is expected for the default repository or when file is missing
109123
}
110124

111125
// Deep merge function for nested objects

0 commit comments

Comments
 (0)