first commit

This commit is contained in:
2025-04-24 13:11:28 +08:00
commit ff9c54d5e4
5960 changed files with 834111 additions and 0 deletions

5
libraries/settings/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/.npmrc
/node_modules
# managed by monorepo$ bin/update_build_scripts
.npmrc

View File

@@ -0,0 +1 @@
20.18.2

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,19 @@
@overleaf/settings
===================
A small module to allow global config settings to be set for all services
within the Overleaf architecture.
Settings file location
----------------------
You can specify a custom location for the settings file by setting the
`OVERLEAF_CONFIG` environment variable. E.g.
$ export OVERLEAF_CONFIG=/home/james/config/settings.development.js
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.

View File

@@ -0,0 +1,55 @@
/* eslint-disable no-console */
const fs = require('node:fs')
const Path = require('node:path')
const { merge } = require('./merge')
const CWD = process.cwd()
const ENTRY_POINT_DIR = process.argv[1]
? Path.dirname(process.argv[1])
: undefined
const NODE_ENV = (process.env.NODE_ENV || 'development').toLowerCase()
const SHARELATEX_CONFIG = process.env.SHARELATEX_CONFIG
const OVERLEAF_CONFIG = process.env.OVERLEAF_CONFIG || SHARELATEX_CONFIG
if (SHARELATEX_CONFIG && SHARELATEX_CONFIG !== OVERLEAF_CONFIG) {
throw new Error(
'found mismatching SHARELATEX_CONFIG, rename to OVERLEAF_CONFIG'
)
}
let settings
let settingsExist = false
const defaultsPath =
pathIfExists(Path.join(CWD, 'config/settings.defaults.cjs')) ||
pathIfExists(Path.join(CWD, 'config/settings.defaults.js')) ||
pathIfExists(Path.join(ENTRY_POINT_DIR, 'config/settings.defaults.cjs')) ||
pathIfExists(Path.join(ENTRY_POINT_DIR, 'config/settings.defaults.js'))
if (defaultsPath) {
console.log(`Using default settings from ${defaultsPath}`)
settings = require(defaultsPath)
settingsExist = true
} else {
settings = {}
}
const overridesPath =
pathIfExists(OVERLEAF_CONFIG) ||
pathIfExists(Path.join(CWD, `config/settings.${NODE_ENV}.cjs`)) ||
pathIfExists(Path.join(CWD, `config/settings.${NODE_ENV}.js`))
if (overridesPath) {
console.log(`Using settings from ${overridesPath}`)
settings = merge(require(overridesPath), settings)
settingsExist = true
}
if (!settingsExist) {
console.warn("No settings or defaults found. I'm flying blind.")
}
module.exports = settings
function pathIfExists(path) {
if (path && fs.existsSync(path)) {
return path
}
return null
}

View File

@@ -0,0 +1,10 @@
settings
--dependencies=None
--docker-repos=gcr.io/overleaf-ops
--env-add=
--env-pass-through=
--esmock-loader=False
--is-library=True
--node-version=20.18.2
--public-repo=False
--script-version=4.7.0

1
libraries/settings/index.js Executable file
View File

@@ -0,0 +1 @@
module.exports = require('./Settings')

View File

@@ -0,0 +1,12 @@
function merge(settings, defaults) {
for (const [key, value] of Object.entries(settings)) {
if (typeof value === 'object' && !(value instanceof Array)) {
defaults[key] = merge(value, defaults[key] || {})
} else {
defaults[key] = value
}
}
return defaults
}
module.exports = { merge }

View File

@@ -0,0 +1,21 @@
{
"name": "@overleaf/settings",
"description": "A centralised settings system for Overleaf",
"version": "3.0.0",
"repository": "overleaf/settings-module",
"main": "index.js",
"scripts": {
"lint": "eslint --ext .js --ext .cjs --ext .ts --max-warnings 0 --format unix .",
"lint:fix": "eslint --fix --ext .js --ext .cjs --ext .ts .",
"format": "prettier --list-different $PWD/'**/*.{js,cjs,ts}'",
"format:fix": "prettier --write $PWD/'**/*.{js,cjs,ts}'",
"test": "npm run lint && npm run format && npm run types:check && npm run test:unit",
"test:ci": "npm run test:unit",
"test:unit": "mocha --exit test/**/*.{js,cjs}",
"types:check": "tsc --noEmit"
},
"devDependencies": {
"mocha": "^11.1.0",
"typescript": "^5.0.4"
}
}

View File

@@ -0,0 +1 @@
// There are no tests yet

View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.backend.json",
"include": [
"**/*.js",
"**/*.cjs"
]
}