Skip to content

Commit 7c1da42

Browse files
committed
webpack: Process all JavaScript files including 870.js for SQL.js WASM path fix
- Enhanced SQLJsWasmFixPlugin to process both distribution and main output files - Added processing for main output directory files in afterEmit hook - This should fix the 870.js file that still has .././sql-wasm.wasm path - Updated debug memory with reminder to cancel KMP workflows
1 parent 5ad4cc9 commit 7c1da42

2 files changed

Lines changed: 107 additions & 46 deletions

File tree

app/web/webpack.config.d/sqljs-config.js

Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -64,53 +64,84 @@ class SQLJsWasmFixPlugin {
6464
callback();
6565
});
6666

67-
// Also run after the compilation is done to process distribution files
68-
compiler.hooks.afterEmit.tapAsync('SQLJsWasmFixPlugin', (compilation, callback) => {
69-
console.log('🔧 SQLJsWasmFixPlugin afterEmit hook running');
70-
const fs = require('fs');
71-
const path = require('path');
72-
73-
// Check if outputPath is defined
74-
if (!compilation.outputPath) {
75-
console.log('🔧 No outputPath defined, skipping distribution file processing');
76-
callback();
77-
return;
78-
}
79-
80-
// Process distribution files if they exist
81-
const distPath = path.join(compilation.outputPath, '..', 'dist', 'wasmJs', 'productionExecutable');
82-
if (fs.existsSync(distPath)) {
83-
console.log('🔧 Processing distribution files in', distPath);
84-
const files = fs.readdirSync(distPath);
85-
files.forEach(file => {
86-
if (file.endsWith('.js')) {
87-
const filePath = path.join(distPath, file);
88-
let content = fs.readFileSync(filePath, 'utf8');
89-
90-
if (content.includes('sql-wasm.wasm')) {
91-
console.log('🔧 Fixing WASM path in distribution file', file);
92-
93-
// Fix the hardcoded locateFile function - handle different patterns
94-
content = content.replace(/locateFile:t=>"\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
95-
content = content.replace(/locateFile:t=>"\.\.\/\.\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
96-
content = content.replace(/locateFile:t=>"\.\.\/\.\/\.\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
97-
98-
// Also fix any other path references
99-
content = content.replace(/\/sql-wasm\.wasm/g, './sql-wasm.wasm');
100-
content = content.replace(/\.\.\/\.\/sql-wasm\.wasm/g, './sql-wasm.wasm');
101-
content = content.replace(/\.\.\/\.\/\.\/sql-wasm\.wasm/g, './sql-wasm.wasm');
102-
content = content.replace(/sql-wasm\.wasm/g, './sql-wasm.wasm');
103-
104-
fs.writeFileSync(filePath, content);
105-
console.log('🔧 Fixed distribution file', file);
67+
// Also run after the compilation is done to process distribution files
68+
compiler.hooks.afterEmit.tapAsync('SQLJsWasmFixPlugin', (compilation, callback) => {
69+
console.log('🔧 SQLJsWasmFixPlugin afterEmit hook running');
70+
const fs = require('fs');
71+
const path = require('path');
72+
73+
// Check if outputPath is defined
74+
if (!compilation.outputPath) {
75+
console.log('🔧 No outputPath defined, skipping distribution file processing');
76+
callback();
77+
return;
78+
}
79+
80+
// Process distribution files if they exist
81+
const distPath = path.join(compilation.outputPath, '..', 'dist', 'wasmJs', 'productionExecutable');
82+
if (fs.existsSync(distPath)) {
83+
console.log('🔧 Processing distribution files in', distPath);
84+
const files = fs.readdirSync(distPath);
85+
files.forEach(file => {
86+
if (file.endsWith('.js')) {
87+
const filePath = path.join(distPath, file);
88+
let content = fs.readFileSync(filePath, 'utf8');
89+
90+
if (content.includes('sql-wasm.wasm')) {
91+
console.log('🔧 Fixing WASM path in distribution file', file);
92+
93+
// Fix the hardcoded locateFile function - handle different patterns
94+
content = content.replace(/locateFile:t=>"\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
95+
content = content.replace(/locateFile:t=>"\.\.\/\.\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
96+
content = content.replace(/locateFile:t=>"\.\.\/\.\/\.\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
97+
98+
// Also fix any other path references
99+
content = content.replace(/\/sql-wasm\.wasm/g, './sql-wasm.wasm');
100+
content = content.replace(/\.\.\/\.\/sql-wasm\.wasm/g, './sql-wasm.wasm');
101+
content = content.replace(/\.\.\/\.\/\.\/sql-wasm\.wasm/g, './sql-wasm.wasm');
102+
content = content.replace(/sql-wasm\.wasm/g, './sql-wasm.wasm');
103+
104+
fs.writeFileSync(filePath, content);
105+
console.log('🔧 Fixed distribution file', file);
106+
}
106107
}
107-
}
108-
});
109-
} else {
110-
console.log('🔧 Distribution path does not exist:', distPath);
111-
}
112-
callback();
113-
});
108+
});
109+
} else {
110+
console.log('🔧 Distribution path does not exist:', distPath);
111+
}
112+
113+
// Also process the main output directory files
114+
if (fs.existsSync(compilation.outputPath)) {
115+
console.log('🔧 Processing main output files in', compilation.outputPath);
116+
const files = fs.readdirSync(compilation.outputPath);
117+
files.forEach(file => {
118+
if (file.endsWith('.js')) {
119+
const filePath = path.join(compilation.outputPath, file);
120+
let content = fs.readFileSync(filePath, 'utf8');
121+
122+
if (content.includes('sql-wasm.wasm')) {
123+
console.log('🔧 Fixing WASM path in main output file', file);
124+
125+
// Fix the hardcoded locateFile function - handle different patterns
126+
content = content.replace(/locateFile:t=>"\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
127+
content = content.replace(/locateFile:t=>"\.\.\/\.\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
128+
content = content.replace(/locateFile:t=>"\.\.\/\.\/\.\/sql-wasm\.wasm"/g, 'locateFile:t=>"./sql-wasm.wasm"');
129+
130+
// Also fix any other path references
131+
content = content.replace(/\/sql-wasm\.wasm/g, './sql-wasm.wasm');
132+
content = content.replace(/\.\.\/\.\/sql-wasm\.wasm/g, './sql-wasm.wasm');
133+
content = content.replace(/\.\.\/\.\/\.\/sql-wasm\.wasm/g, './sql-wasm.wasm');
134+
content = content.replace(/sql-wasm\.wasm/g, './sql-wasm.wasm');
135+
136+
fs.writeFileSync(filePath, content);
137+
console.log('🔧 Fixed main output file', file);
138+
}
139+
}
140+
});
141+
}
142+
143+
callback();
144+
});
114145
}
115146
}
116147

docs/sqljs_debug_memory.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SQL.js WASM Debug Memory
2+
3+
## Current Issue
4+
- WebAssembly compilation error still occurring
5+
- Error: `CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0`
6+
- Root cause: SQL.js trying to load `/sql-wasm.wasm` (404 error)
7+
8+
## Progress Made
9+
- ✅ Fixed `981.js` chunk file - path changed from `.././sql-wasm.wasm` to `./sql-wasm.wasm`
10+
- ✅ Webpack plugin is working and finding files
11+
- ❌ Still getting 404 error for `/sql-wasm.wasm`
12+
13+
## Current Investigation
14+
- There are multiple SQL.js files in the build
15+
- `981.js` was fixed but there's another file (`870.js`) still trying to load from root path
16+
- Found the same pattern in `870.js`: `locateFile:t=>".././sql-wasm.wasm"`
17+
- Webpack plugin is working but not catching all files
18+
19+
## Files Found
20+
-`981.js` - Fixed (path changed from `.././sql-wasm.wasm` to `./sql-wasm.wasm`)
21+
-`870.js` - Still has `.././sql-wasm.wasm` pattern
22+
23+
## Next Steps
24+
1. Update webpack plugin to catch all chunk files including 870.js
25+
2. Test the fix
26+
3. Verify all SQL.js files are processed
27+
28+
## Important Reminder
29+
- **Cancel KMP workflow after each push to "web" branch** to save resources
30+
- Use: `gh run cancel <RUN_ID>` (see gh_cheat_sheet.md for reference)

0 commit comments

Comments
 (0)