From 551eef00fbacac579875e60421b791d7a02e2a4d Mon Sep 17 00:00:00 2001 From: decaffeinate Date: Wed, 26 May 2021 14:24:23 +0100 Subject: [PATCH 1/5] decaffeinate: Rename Settings.coffee from .coffee to .js --- libraries/settings/{Settings.coffee => Settings.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libraries/settings/{Settings.coffee => Settings.js} (100%) diff --git a/libraries/settings/Settings.coffee b/libraries/settings/Settings.js similarity index 100% rename from libraries/settings/Settings.coffee rename to libraries/settings/Settings.js From 2787cd615283884bf62b86726bc5dc4639d329e0 Mon Sep 17 00:00:00 2001 From: decaffeinate Date: Wed, 26 May 2021 14:24:24 +0100 Subject: [PATCH 2/5] decaffeinate: Convert Settings.coffee to JS --- libraries/settings/Settings.js | 101 +++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 42 deletions(-) mode change 100755 => 100644 libraries/settings/Settings.js diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js old mode 100755 new mode 100644 index 7b32d24d27..106de03f13 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -1,50 +1,67 @@ -fs = require "fs" -path = require "path" -env = (process.env.NODE_ENV or "development").toLowerCase() +/* + * decaffeinate suggestions: + * DS101: Remove unnecessary use of Array.from + * DS207: Consider shorter variations of null checks + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +let defaults, possibleConfigFiles, settingsExist; +const fs = require("fs"); +const path = require("path"); +const env = (process.env.NODE_ENV || "development").toLowerCase(); -merge = (settings, defaults) -> - for key, value of settings - if typeof(value) == "object" and value not instanceof Array - defaults[key] = merge(settings[key], defaults[key] or {}) - else - defaults[key] = value - return defaults +var merge = function(settings, defaults) { + for (let key in settings) { + const value = settings[key]; + if ((typeof(value) === "object") && !(value instanceof Array)) { + defaults[key] = merge(settings[key], defaults[key] || {}); + } else { + defaults[key] = value; + } + } + return defaults; +}; -defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults") +const defaultSettingsPath = path.normalize(__dirname + "/../../config/settings.defaults"); -if fs.existsSync("#{defaultSettingsPath}.js") - console.log "Using default settings from #{defaultSettingsPath}.js" - defaults = require("#{defaultSettingsPath}.js") - settingsExist = true -else if fs.existsSync("#{defaultSettingsPath}.coffee") - console.warn "CoffeeScript settings file #{defaultSettingsPath}.coffee is deprecated, please convert to JavaScript" - console.log "Using default settings from #{defaultSettingsPath}.coffee" - defaults = require("#{defaultSettingsPath}.coffee") - settingsExist = true -else - defaults = {} - settingsExist = false +if (fs.existsSync(`${defaultSettingsPath}.js`)) { + console.log(`Using default settings from ${defaultSettingsPath}.js`); + defaults = require(`${defaultSettingsPath}.js`); + settingsExist = true; +} else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) { + console.warn(`CoffeeScript settings file ${defaultSettingsPath}.coffee is deprecated, please convert to JavaScript`); + console.log(`Using default settings from ${defaultSettingsPath}.coffee`); + defaults = require(`${defaultSettingsPath}.coffee`); + settingsExist = true; +} else { + defaults = {}; + settingsExist = false; +} -if process.env.SHARELATEX_CONFIG? - possibleConfigFiles = [process.env.SHARELATEX_CONFIG] -else +if (process.env.SHARELATEX_CONFIG != null) { + possibleConfigFiles = [process.env.SHARELATEX_CONFIG]; +} else { possibleConfigFiles = [ - process.cwd() + "/config/settings.#{env}.js" - path.normalize(__dirname + "/../../config/settings.#{env}.js") - process.cwd() + "/config/settings.#{env}.coffee" - path.normalize(__dirname + "/../../config/settings.#{env}.coffee") - ] + process.cwd() + `/config/settings.${env}.js`, + path.normalize(__dirname + `/../../config/settings.${env}.js`), + process.cwd() + `/config/settings.${env}.coffee`, + path.normalize(__dirname + `/../../config/settings.${env}.coffee`) + ]; +} -for file in possibleConfigFiles - if fs.existsSync(file) - if file.endsWith('.coffee') - console.warn "CoffeeScript settings file #{file} is deprecated, please convert to JavaScript" - console.log "Using settings from " + file - module.exports = merge(require(file), defaults) - settingsExist = true - break +for (let file of Array.from(possibleConfigFiles)) { + if (fs.existsSync(file)) { + if (file.endsWith('.coffee')) { + console.warn(`CoffeeScript settings file ${file} is deprecated, please convert to JavaScript`); + } + console.log("Using settings from " + file); + module.exports = merge(require(file), defaults); + settingsExist = true; + break; + } +} -if !settingsExist - console.warn "No settings or defaults found. I'm flying blind." +if (!settingsExist) { + console.warn("No settings or defaults found. I'm flying blind."); +} -module.exports = defaults +module.exports = defaults; From 93f618a98055ffa1c7ffad2bcc531dc65fe1dafe Mon Sep 17 00:00:00 2001 From: decaffeinate Date: Wed, 26 May 2021 14:24:24 +0100 Subject: [PATCH 3/5] decaffeinate: Run post-processing cleanups on Settings.coffee --- libraries/settings/Settings.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js index 106de03f13..f29cf16832 100644 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -1,3 +1,5 @@ +// TODO: This file was created by bulk-decaffeinate. +// Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from From 9c0dbbc5c8fa33245ab69692de27a485ebe84345 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 26 May 2021 15:06:24 +0100 Subject: [PATCH 4/5] Remove CoffeeScript --- libraries/settings/LICENSE | 2 +- libraries/settings/README.md | 8 ++++---- libraries/settings/Settings.js | 29 ++++++++++------------------- libraries/settings/index.js | 1 - libraries/settings/package.json | 15 ++++----------- 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/libraries/settings/LICENSE b/libraries/settings/LICENSE index f49ce1ac14..54a584e24f 100644 --- a/libraries/settings/LICENSE +++ b/libraries/settings/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 ShareLaTeX +Copyright (c) 2014-2021 Overleaf Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/settings/README.md b/libraries/settings/README.md index fd2284a51a..fee9f78d90 100644 --- a/libraries/settings/README.md +++ b/libraries/settings/README.md @@ -1,4 +1,4 @@ -overleaf/settings-module +@overleaf/settings-module =================== A small module to allow global config settings to be set for all services @@ -10,10 +10,10 @@ Settings file location You can specify a custom location for the settings file by setting the `SHARELATEX_CONFIG` environment variable. E.g. - $ export SHARELATEX_CONFIG=/home/james/config/settings.development.coffee + $ export SHARELATEX_CONFIG=/home/james/config/settings.development.js -Otherwise, the settings will be loaded from `config/settings.NODE_ENV.coffee`, -where `NODE_ENV` is another evnironment variable, or defaults to `development`. +Otherwise, the settings will be loaded from `config/settings.NODE_ENV.js`, +where `NODE_ENV` is another environment variable, or defaults to `development`. The config directory is first looked for in the current directory, and then relative to the settings module directory. diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js index f29cf16832..202fc26494 100644 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -1,21 +1,12 @@ -// TODO: This file was created by bulk-decaffeinate. -// Sanity-check the conversion and remove this comment. -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS207: Consider shorter variations of null checks - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ let defaults, possibleConfigFiles, settingsExist; const fs = require("fs"); const path = require("path"); const env = (process.env.NODE_ENV || "development").toLowerCase(); -var merge = function(settings, defaults) { - for (let key in settings) { - const value = settings[key]; +const merge = function(settings, defaults) { + for (const [key, value] of Object.entries(settings)) { if ((typeof(value) === "object") && !(value instanceof Array)) { - defaults[key] = merge(settings[key], defaults[key] || {}); + defaults[key] = merge(value, defaults[key] || {}); } else { defaults[key] = value; } @@ -30,30 +21,30 @@ if (fs.existsSync(`${defaultSettingsPath}.js`)) { defaults = require(`${defaultSettingsPath}.js`); settingsExist = true; } else if (fs.existsSync(`${defaultSettingsPath}.coffee`)) { - console.warn(`CoffeeScript settings file ${defaultSettingsPath}.coffee is deprecated, please convert to JavaScript`); - console.log(`Using default settings from ${defaultSettingsPath}.coffee`); - defaults = require(`${defaultSettingsPath}.coffee`); - settingsExist = true; + // TODO: remove this in the next major version + throw new Error(`CoffeeScript settings file ${defaultSettingsPath}.coffee is no longer supported, please convert to JavaScript`); } else { defaults = {}; settingsExist = false; } -if (process.env.SHARELATEX_CONFIG != null) { +if (process.env.SHARELATEX_CONFIG) { possibleConfigFiles = [process.env.SHARELATEX_CONFIG]; } else { possibleConfigFiles = [ process.cwd() + `/config/settings.${env}.js`, path.normalize(__dirname + `/../../config/settings.${env}.js`), + // TODO: remove these in the next major version process.cwd() + `/config/settings.${env}.coffee`, path.normalize(__dirname + `/../../config/settings.${env}.coffee`) ]; } -for (let file of Array.from(possibleConfigFiles)) { +for (let file of possibleConfigFiles) { if (fs.existsSync(file)) { + // TODO: remove this in the next major version if (file.endsWith('.coffee')) { - console.warn(`CoffeeScript settings file ${file} is deprecated, please convert to JavaScript`); + throw new Error(`CoffeeScript settings file ${file} is no longer supported, please convert to JavaScript`); } console.log("Using settings from " + file); module.exports = merge(require(file), defaults); diff --git a/libraries/settings/index.js b/libraries/settings/index.js index 2d248c73df..1a9043cdaf 100755 --- a/libraries/settings/index.js +++ b/libraries/settings/index.js @@ -1,2 +1 @@ -require("coffee-script") module.exports = require('./Settings'); diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 3bf1f7ce8e..37de0d57fd 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -1,13 +1,6 @@ { - "name": "settings-sharelatex", - "homepage": "www.sharelatex.com", - "description": "A centralised settings system for ShareLaTeX", - "version": "1.3.0", - "repository": { - "type": "git", - "url": "https://github.com/sharelatex/settings-sharelatex.git" - }, - "dependencies": { - "coffee-script": "1.6.0" - } + "name": "@overleaf/settings-module", + "description": "A centralised settings system for Overleaf", + "version": "2.0.0", + "repository": "overleaf/settings-module" } From 955c9162c07e0b064f243ca1596dd3310f72c1e0 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 28 May 2021 09:15:24 +0100 Subject: [PATCH 5/5] Rename to @overleaf/settings --- libraries/settings/README.md | 2 +- libraries/settings/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/settings/README.md b/libraries/settings/README.md index fee9f78d90..ac5adfc14f 100644 --- a/libraries/settings/README.md +++ b/libraries/settings/README.md @@ -1,4 +1,4 @@ -@overleaf/settings-module +@overleaf/settings =================== A small module to allow global config settings to be set for all services diff --git a/libraries/settings/package.json b/libraries/settings/package.json index 37de0d57fd..dd598c373d 100644 --- a/libraries/settings/package.json +++ b/libraries/settings/package.json @@ -1,5 +1,5 @@ { - "name": "@overleaf/settings-module", + "name": "@overleaf/settings", "description": "A centralised settings system for Overleaf", "version": "2.0.0", "repository": "overleaf/settings-module"