From aa0f5247f89cdf14a491347e5aeb0075d21ebc03 Mon Sep 17 00:00:00 2001
From: Jure Triglav <juretriglav@gmail.com>
Date: Mon, 15 Mar 2021 03:12:14 +0100
Subject: [PATCH] fix: correctly load and use .env files, use node v15
 compatible pg version

---
 FAQ.md                    |  2 +-
 README.md                 |  2 +-
 cypress/plugins/index.js  |  8 +++++--
 package.json              |  3 ++-
 server/app.js             |  2 +-
 webpack/webpack.config.js |  2 +-
 yarn.lock                 | 50 +++++++--------------------------------
 7 files changed, 20 insertions(+), 49 deletions(-)

diff --git a/FAQ.md b/FAQ.md
index b28fd919c5..ca59fd30bc 100644
--- a/FAQ.md
+++ b/FAQ.md
@@ -100,4 +100,4 @@ And then install the `pgcrypto` extension to the `kotahidev` database:
 kotahidev=# create extension pgcrypto;
 ```
 
-Migrate the test database using `yarn dotenv pubsweet migrate`.
\ No newline at end of file
+Migrate the test database using `yarn dotenv yarn pubsweet migrate`.
diff --git a/README.md b/README.md
index b4ba341943..8f2c80f2b0 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ This will:
 If you're using `docker-compose` to stand up a PostgreSQL database, everything will already be configured and you only need to
 
 ```
-> yarn dotenv yarn test:chrome
+> yarn test:chrome
 ```
 
 This will load the test runner in your local environment and using the correct environment variables (set in your `.env` file).
diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js
index 92a3a481f3..514280d0f7 100644
--- a/cypress/plugins/index.js
+++ b/cypress/plugins/index.js
@@ -11,11 +11,12 @@
 // This function is called when a project is opened or re-opened (e.g. due to
 // the project's config changing)
 
-const seed = require('../../scripts/clearAndSeed')
-
 const { execSync } = require('child_process')
 const path = require('path')
+require('dotenv').config({ path: path.join(__dirname, '../../.env') })
+
 const { readFileSync } = require('fs')
+const seed = require('../../scripts/clearAndSeed')
 
 const dumpFile = name => path.join(__dirname, '..', 'dumps', `${name}.sql`)
 
@@ -38,15 +39,18 @@ module.exports = (on, config) => {
           `pg_dump --column-inserts -d simplej > ${dumpFile(name)}`,
         )
       }
+
       return true
     },
     restore: async name => seed(readFileSync(dumpFile(name), 'utf-8')),
     createToken: async name => {
       const { User } = require('@pubsweet/models')
       const authentication = require('pubsweet-server/src/authentication')
+
       const user = await User.query()
         .where({ username: testUsers[name] })
         .first()
+
       return authentication.token.create(user)
     },
   })
diff --git a/package.json b/package.json
index d2fc73e702..d02b5540f0 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,8 @@
     "formik": "^2.0.0",
     "prettier": "2.2.1",
     "prosemirror-gapcursor": "^1.1.3",
-    "prosemirror-model": "1.11.2"
+    "prosemirror-model": "1.11.2",
+    "pg": "8.4.0"
   },
   "dependencies": {
     "@apollo/client": "3.2.2",
diff --git a/server/app.js b/server/app.js
index 58ac0761d9..83a00c011b 100644
--- a/server/app.js
+++ b/server/app.js
@@ -2,7 +2,7 @@
 // The global requires here are used to avoid cyclical dependencies
 // The param reassigns are intentional, used as a way to set Express routes
 const path = require('path')
-require('dotenv').config()
+require('dotenv').config({ path: path.join(__dirname, '../.env') })
 
 const config = require('config')
 const express = require('express')
diff --git a/webpack/webpack.config.js b/webpack/webpack.config.js
index 4b471dce06..4a35e3b8ba 100644
--- a/webpack/webpack.config.js
+++ b/webpack/webpack.config.js
@@ -1,7 +1,7 @@
 const path = require('path')
 const fs = require('fs-extra')
 const { pick } = require('lodash')
-require('dotenv').config()
+require('dotenv').config({ path: path.join(__dirname, '../.env') })
 const config = require('config')
 
 const rules = require('./common-rules')
diff --git a/yarn.lock b/yarn.lock
index f7a5a83af1..62ba5986cf 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -17083,11 +17083,6 @@ pg-boss@^5.2.0:
     pg "^8.5.1"
     uuid "^8.3.2"
 
-pg-connection-string@0.1.3:
-  version "0.1.3"
-  resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-0.1.3.tgz#da1847b20940e42ee1492beaf65d49d91b245df7"
-  integrity sha1-2hhHsglA5C7hSSvq9l1J2RskXfc=
-
 pg-connection-string@2.4.0, pg-connection-string@^2.4.0:
   version "2.4.0"
   resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.4.0.tgz#c979922eb47832999a204da5dbe1ebf2341b6a10"
@@ -17103,22 +17098,12 @@ pg-ipc@^1.0.4:
   resolved "https://registry.yarnpkg.com/pg-ipc/-/pg-ipc-1.0.5.tgz#9aad40e51a123c41b635f97748372578ddf8de94"
   integrity sha512-nF4uB5vuqvPCeyWGLRVCOLxGaXq8tVMVZ+rCkX0XGbErlUUCwpb6+uME6s6vkB2T3n8lhZwojn5frFl67I5Ugg==
 
-pg-packet-stream@^1.1.0:
-  version "1.1.0"
-  resolved "https://registry.yarnpkg.com/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz#e45c3ae678b901a2873af1e17b92d787962ef914"
-  integrity sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg==
-
-pg-pool@^2.0.10:
-  version "2.0.10"
-  resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.10.tgz#842ee23b04e86824ce9d786430f8365082d81c4a"
-  integrity sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg==
-
-pg-pool@^3.2.2:
+pg-pool@^3.2.1:
   version "3.2.2"
   resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.2.2.tgz#a560e433443ed4ad946b84d774b3f22452694dff"
   integrity sha512-ORJoFxAlmmros8igi608iVEbQNNZlp89diFVx6yV5v+ehmpMY9sK6QgpmgoXbmkNaBAx8cOOZh9g80kJv1ooyA==
 
-pg-protocol@^1.4.0:
+pg-protocol@^1.3.0:
   version "1.4.0"
   resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.4.0.tgz#43a71a92f6fe3ac559952555aa3335c8cb4908be"
   integrity sha512-El+aXWcwG/8wuFICMQjM5ZSAm6OWiJicFdNYo+VY3QP+8vI4SvLIWVe51PppTzMhikUJR+PsyIFKqfdXPz/yxA==
@@ -17134,30 +17119,16 @@ pg-types@^2.1.0:
     postgres-date "~1.0.4"
     postgres-interval "^1.1.0"
 
-pg@^7.4.1, pg@^7.8.0:
-  version "7.18.2"
-  resolved "https://registry.yarnpkg.com/pg/-/pg-7.18.2.tgz#4e219f05a00aff4db6aab1ba02f28ffa4513b0bb"
-  integrity sha512-Mvt0dGYMwvEADNKy5PMQGlzPudKcKKzJds/VbOeZJpb6f/pI3mmoXX0JksPgI3l3JPP/2Apq7F36O63J7mgveA==
-  dependencies:
-    buffer-writer "2.0.0"
-    packet-reader "1.0.0"
-    pg-connection-string "0.1.3"
-    pg-packet-stream "^1.1.0"
-    pg-pool "^2.0.10"
-    pg-types "^2.1.0"
-    pgpass "1.x"
-    semver "4.3.2"
-
-pg@^8.5.1:
-  version "8.5.1"
-  resolved "https://registry.yarnpkg.com/pg/-/pg-8.5.1.tgz#34dcb15f6db4a29c702bf5031ef2e1e25a06a120"
-  integrity sha512-9wm3yX9lCfjvA98ybCyw2pADUivyNWT/yIP4ZcDVpMN0og70BUWYEGXPCTAQdGTAqnytfRADb7NERrY1qxhIqw==
+pg@8.4.0, pg@^7.4.1, pg@^7.8.0, pg@^8.5.1:
+  version "8.4.0"
+  resolved "https://registry.yarnpkg.com/pg/-/pg-8.4.0.tgz#7c754e0b907e8dae3af6fff0a0014c77f1418842"
+  integrity sha512-01LcNrAf+mBI46c78mE86I5o5KkOM942lLiSBdiCfgHTR+oUNIjh1fKClWeoPNHJz2oXe/VUSqtk1vwAQYwWEg==
   dependencies:
     buffer-writer "2.0.0"
     packet-reader "1.0.0"
     pg-connection-string "^2.4.0"
-    pg-pool "^3.2.2"
-    pg-protocol "^1.4.0"
+    pg-pool "^3.2.1"
+    pg-protocol "^1.3.0"
     pg-types "^2.1.0"
     pgpass "1.x"
 
@@ -19961,11 +19932,6 @@ semver-regex@^2.0.0:
   resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
   integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
 
-semver@4.3.2:
-  version "4.3.2"
-  resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.2.tgz#c7a07158a80bedd052355b770d82d6640f803be7"
-  integrity sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c=
-
 semver@6.3.0, semver@^6.0.0, semver@^6.1.0, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0:
   version "6.3.0"
   resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
-- 
GitLab