Repository: thelounge/thelounge (ts)

Issue:
`log.warn is not a function` in v3.0.0-pre.7
<!-- Have a question? Join #thelounge on freenode -->

* *Node version:* Node.js 8.11.3 on linux x64
* *The Lounge version:* v3.0.0-pre.7

---

For a reason I can't explain, I got the following right after upgrading to v3.0.0-pre.7:

```
TypeError: log.warn is not a function
    at Object.setHome (/usr/lib/node_modules/thelounge/src/helper.js:126:8)
    at Object.<anonymous> (/usr/lib/node_modules/thelounge/src/command-line/index.js:35:8)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/thelounge/index.js:38:1)
```

That's this line: https://github.com/thelounge/thelounge/blob/master/src/helper.js#L126

My config was indeed saying `"theme": "example"` and, sure enough, after changing it to `"default"`, it started fine, but... why did that even break?!
Possibly related to #2563.

Pull request description:
Fix circular dependency in Helper+log
Fixes #2568

Patch:
diff --git a/src/helper.js b/src/helper.js
index 919b9ead..7fb2a9d7 100644
--- a/src/helper.js
+++ b/src/helper.js
@@ -9,7 +9,6 @@ const fs = require("fs");
 const net = require("net");
 const bcrypt = require("bcryptjs");
 const colors = require("chalk");
-const moment = require("moment");
 
 let homePath;
 let configPath;
@@ -32,7 +31,6 @@ const Helper = {
 	setHome,
 	getVersion,
 	getGitCommit,
-	getHumanDate,
 	ip2hex,
 	mergeConfig,
 	getDefaultNick,
@@ -208,10 +206,6 @@ function passwordCompare(password, expected) {
 	return bcrypt.compare(password, expected);
 }
 
-function getHumanDate() {
-	return moment().format("YYYY-MM-DD HH:mm:ss");
-}
-
 function getDefaultNick() {
 	if (!this.config.defaults.nick) {
 		return "thelounge";
diff --git a/src/log.js b/src/log.js
index 9011623d..3c58b85b 100644
--- a/src/log.js
+++ b/src/log.js
@@ -2,10 +2,10 @@
 
 const colors = require("chalk");
 const read = require("read");
-const Helper = require("./helper");
+const moment = require("moment");
 
 function timestamp() {
-	return colors.dim(Helper.getHumanDate());
+	return colors.dim(module.exports.getHumanDate());
 }
 
 module.exports = {
@@ -31,4 +31,8 @@ module.exports = {
 		options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
 		read(options, callback);
 	},
+
+	getHumanDate() {
+		return moment().format("YYYY-MM-DD HH:mm:ss");
+	},
 };
diff --git a/src/plugins/messageStorage/text.js b/src/plugins/messageStorage/text.js
index ce1e63a4..212ad752 100644
--- a/src/plugins/messageStorage/text.js
+++ b/src/plugins/messageStorage/text.js
@@ -41,7 +41,7 @@ class TextFileMessageStorage {
 			return;
 		}
 
-		let line = `[${Helper.getHumanDate()}] `;
+		let line = `[${log.getHumanDate()}] `;
 
 		// message types from src/models/msg.js
 		switch (msg.type) {


Test patch:
diff --git a/test/src/helperTest.js b/test/src/helperTest.js
index 54ae3264..93574639 100644
--- a/test/src/helperTest.js
+++ b/test/src/helperTest.js
@@ -4,6 +4,7 @@ const expect = require("chai").expect;
 const os = require("os");
 const moment = require("moment");
 const Helper = require("../../src/helper");
+const log = require("../../src/log");
 
 describe("Helper", function() {
 	describe("#expandHome", function() {
@@ -55,6 +56,6 @@ describe("Helper", function() {
 	});
 
 	describe("#getHumanDate()", function() {
-		expect(Helper.getHumanDate()).to.equal(moment().format("YYYY-MM-DD HH:mm:ss"));
+		expect(log.getHumanDate()).to.equal(moment().format("YYYY-MM-DD HH:mm:ss"));
 	});
 });