diff --git a/install/install.ts b/install/install.ts index c7b3f373..68e7679a 100644 --- a/install/install.ts +++ b/install/install.ts @@ -191,7 +191,7 @@ function removeOptionalEsbuildDeps() { if (!yarnGlobalPath) return false; const pkgjson = `${yarnGlobalPath}/package.json`; const data = existsSync(pkgjson) ? require(pkgjson) : {}; - data.resolutions = data.resolutions || {}; + data.resolutions ||= {}; Object.assign(data.resolutions, Object.fromEntries([ '@esbuild/linux-loong64', 'esbuild-windows-32', @@ -326,12 +326,20 @@ connect-timeout = 10`); operations: [ 'pm2 start mongod', () => sleep(3000), - () => writeFileSync(tmpFile, `db.createUser(${JSON.stringify({ - user: 'hydro', - pwd: password, - roles: [{ role: 'readWrite', db: 'hydro' }], - })})`), - [`mongosh 127.0.0.1:27017/hydro ${tmpFile}`, { retry: true }], + async () => { + // eslint-disable-next-line import/no-absolute-path + const { MongoClient } = require('/usr/local/share/.config/yarn/global/node_modules/mongodb'); + const client = await MongoClient.connect('mongodb://127.0.0.1', { + useNewUrlParser: true, + useUnifiedTopology: true, + readPreference: 'nearest', + writeConcern: 'majority', + }); + await client.db('hydro').addUser('hydro', password, { + roles: [{ role: 'readWrite', db: 'hydro' }], + }); + await client.close(); + }, () => writeFileSync(`${process.env.HOME}/.hydro/config.json`, JSON.stringify({ uri: `mongodb://hydro:${password}@127.0.0.1:27017/hydro`, })),