44 lines
2.1 KiB
JavaScript
44 lines
2.1 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const filesToPatch = [
|
|
'node_modules/node-appwrite/dist/client.mjs',
|
|
'node_modules/node-appwrite/dist/client.js',
|
|
'node_modules/appwrite/dist/cjs/sdk.js',
|
|
'node_modules/appwrite/dist/esm/sdk.js'
|
|
];
|
|
|
|
filesToPatch.forEach(file => {
|
|
const filePath = path.join(__dirname, file);
|
|
if (fs.existsSync(filePath)) {
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
// We want to replace the console.warn that outputs the warning.
|
|
// The exact code in client is: warnings.split(';').forEach((warning) => console.warn('Warning: ' + warning));
|
|
const target = "warnings.split(';').forEach((warning) => console.warn('Warning: ' + warning));";
|
|
const replacement = "warnings.split(';').forEach((warning) => { if (!warning.includes('built for Appwrite')) console.warn('Warning: ' + warning); });";
|
|
|
|
// Also try the compiled JS versions which might have different formatting
|
|
const target2 = 'warnings.split(";").forEach((warning) => console.warn("Warning: " + warning));';
|
|
const replacement2 = 'warnings.split(";").forEach((warning) => { if (!warning.includes("built for Appwrite")) console.warn("Warning: " + warning); });';
|
|
|
|
if (content.includes(target)) {
|
|
content = content.replace(target, replacement);
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
console.log(`Patched ${file}`);
|
|
} else if (content.includes(target2)) {
|
|
content = content.replace(target2, replacement2);
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
console.log(`Patched ${file}`);
|
|
} else {
|
|
// For minified files or different formats, use regex
|
|
const regex = /warnings\.split\(['"]\;['"]\)\.forEach\(\([^)]*\)\s*=>\s*console\.warn\(['"]Warning:\s*['"]\s*\+\s*warning\)\)/g;
|
|
const match = content.match(regex);
|
|
if (match) {
|
|
content = content.replace(regex, "warnings.split(';').forEach((warning) => { if (!warning.includes('built for Appwrite')) console.warn('Warning: ' + warning); })");
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
console.log(`Patched ${file} via regex`);
|
|
}
|
|
}
|
|
}
|
|
});
|