From cd6938dd6c8b6a1ee51a2e6594e795c2cec6e220 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 11 Jul 2020 11:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20salsprep=20=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=AD=A3=E7=A1=AE=E8=A2=AB=20webpack=20=E6=89=93?= =?UTF-8?q?=E5=8C=85=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/hack.js | 14 ++++++++++++++ build/webpack.js | 4 ---- hydro/service/server.ts | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/build/hack.js b/build/hack.js index 6b040a658..f2d8e27fd 100644 --- a/build/hack.js +++ b/build/hack.js @@ -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'); + } + }, }; diff --git a/build/webpack.js b/build/webpack.js index 0eb0c1f3d..5abf38f23 100644 --- a/build/webpack.js +++ b/build/webpack.js @@ -1,5 +1,4 @@ /* eslint-disable import/no-extraneous-dependencies */ -const path = require('path'); const webpack = require('webpack'); const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin'); const { root } = require('./utils'); @@ -21,9 +20,6 @@ const build = async (type) => { new FriendlyErrorsPlugin({ clearConsole: false, }), - new webpack.ProvidePlugin({ - saslprep: path.resolve(__dirname, 'node_modules/saslprep/index.js'), - }), ], }; const compiler = webpack(config); diff --git a/hydro/service/server.ts b/hydro/service/server.ts index 066cae39c..c52d7f0ad 100644 --- a/hydro/service/server.ts +++ b/hydro/service/server.ts @@ -662,5 +662,5 @@ export async function start() { } global.Hydro.service.server = { - param, Handler, ConnectionHandler, Route, Connection, Middleware, prepare, start, + Types, param, Handler, ConnectionHandler, Route, Connection, Middleware, prepare, start, };