修复 salsprep 不能正确被 webpack 打包的问题

This commit is contained in:
undefined committed 2020-07-11 11:56:48 +08:00
1 parent c389d20c51
commit cd6938dd6c
3 files changed
+15 -5

No files matched your search

+14
View File
@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');
module.exports = {
formidable: () => {
@@ -34,4 +35,17 @@ module.exports = {
console.error('Cannot hack yargs');
}
},
saslprep: () => {
const q = require.resolve('saslprep');
const mem = path.join(path.dirname(q), 'code-points.mem');
const p = path.join(path.dirname(q), 'lib', 'memory-code-points.js');
const data = fs.readFileSync(mem);
const file = fs.readFileSync(p).toString().split('\n');
if (file[7].includes('fs.readFileSync')) {
file[7] = `const memory = Buffer.from('${data.toString('base64')}', 'base64');`;
fs.writeFileSync(p, file.join('\n'));
} else if (!file[7].includes('Buffer.from')) {
console.error('Cannot hack saslprep');
}
},
};