diff --git a/services/web/migrations/20230817081910_back_fill_gitBridge_feature_server_pro.mjs b/services/web/migrations/20230817081910_back_fill_gitBridge_feature_server_pro.mjs index 2325394c76..3090d66d88 100644 --- a/services/web/migrations/20230817081910_back_fill_gitBridge_feature_server_pro.mjs +++ b/services/web/migrations/20230817081910_back_fill_gitBridge_feature_server_pro.mjs @@ -3,7 +3,7 @@ const tags = ['server-ce', 'server-pro'] const migrate = async () => { // Run-time import as SaaS does not ship with the server-ce-scripts module const { default: runScript } = await import( - '../modules/server-ce-scripts/scripts/upgrade-user-features.mjs' + '../modules/server-ce-scripts/scripts/upgrade-user-features.js' ) await runScript(false, { gitBridge: 1, diff --git a/services/web/modules/server-ce-scripts/index.mjs b/services/web/modules/server-ce-scripts/index.js similarity index 75% rename from services/web/modules/server-ce-scripts/index.mjs rename to services/web/modules/server-ce-scripts/index.js index e6df0f30af..28c3d81419 100644 --- a/services/web/modules/server-ce-scripts/index.mjs +++ b/services/web/modules/server-ce-scripts/index.js @@ -3,4 +3,4 @@ /** @type {WebModule} */ const ServerCeScriptsModule = {} -export default ServerCeScriptsModule +module.exports = ServerCeScriptsModule diff --git a/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.mjs b/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.js similarity index 91% rename from services/web/modules/server-ce-scripts/scripts/change-compile-timeout.mjs rename to services/web/modules/server-ce-scripts/scripts/change-compile-timeout.js index 3a2d982688..ca99e6233f 100644 --- a/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.mjs +++ b/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.js @@ -1,9 +1,9 @@ -import minimist from 'minimist' -import { +const minimist = require('minimist') +const { db, ObjectId, waitForDb, -} from '../../../app/src/infrastructure/mongodb.js' +} = require('../../../app/src/infrastructure/mongodb') async function main() { await waitForDb() diff --git a/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs b/services/web/modules/server-ce-scripts/scripts/check-mongodb.js similarity index 84% rename from services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs rename to services/web/modules/server-ce-scripts/scripts/check-mongodb.js index 401e780632..3dd9f33b61 100644 --- a/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs +++ b/services/web/modules/server-ce-scripts/scripts/check-mongodb.js @@ -1,9 +1,6 @@ -import mongodb from 'mongodb-legacy' -import { waitForDb, db } from '../../../app/src/infrastructure/mongodb.js' -import mongoose from '../../../app/src/infrastructure/Mongoose.js' - -const { ObjectId } = mongodb -const { getMongoClient } = mongoose +const { ObjectId } = require('mongodb-legacy') +const { waitForDb, db } = require('../../../app/src/infrastructure/mongodb') +const { getMongoClient } = require('../../../app/src/infrastructure/Mongoose') const MIN_MONGO_VERSION = [5, 0] diff --git a/services/web/modules/server-ce-scripts/scripts/check-redis.mjs b/services/web/modules/server-ce-scripts/scripts/check-redis.js similarity index 82% rename from services/web/modules/server-ce-scripts/scripts/check-redis.mjs rename to services/web/modules/server-ce-scripts/scripts/check-redis.js index 213bcc9714..6402619eaa 100644 --- a/services/web/modules/server-ce-scripts/scripts/check-redis.mjs +++ b/services/web/modules/server-ce-scripts/scripts/check-redis.js @@ -1,4 +1,4 @@ -import RedisWrapper from '../../../app/src/infrastructure/RedisWrapper.js' +const RedisWrapper = require('../../../app/src/infrastructure/RedisWrapper') const rclient = RedisWrapper.client('health_check') rclient.on('error', err => { console.error('Cannot connect to redis.') diff --git a/services/web/modules/server-ce-scripts/scripts/check-texlive-images.mjs b/services/web/modules/server-ce-scripts/scripts/check-texlive-images.js similarity index 97% rename from services/web/modules/server-ce-scripts/scripts/check-texlive-images.mjs rename to services/web/modules/server-ce-scripts/scripts/check-texlive-images.js index 7765b278cc..4f474650ff 100644 --- a/services/web/modules/server-ce-scripts/scripts/check-texlive-images.mjs +++ b/services/web/modules/server-ce-scripts/scripts/check-texlive-images.js @@ -1,4 +1,4 @@ -import { waitForDb, db } from '../../../app/src/infrastructure/mongodb.js' +const { waitForDb, db } = require('../../../app/src/infrastructure/mongodb') async function readImagesInUse() { await waitForDb() diff --git a/services/web/modules/server-ce-scripts/scripts/create-user.mjs b/services/web/modules/server-ce-scripts/scripts/create-user.js similarity index 84% rename from services/web/modules/server-ce-scripts/scripts/create-user.mjs rename to services/web/modules/server-ce-scripts/scripts/create-user.js index 2ec64081fc..031c78fff2 100644 --- a/services/web/modules/server-ce-scripts/scripts/create-user.mjs +++ b/services/web/modules/server-ce-scripts/scripts/create-user.js @@ -1,6 +1,6 @@ -import minimist from 'minimist' -import { db, waitForDb } from '../../../app/src/infrastructure/mongodb.js' -import UserRegistrationHandler from '../../../app/src/Features/User/UserRegistrationHandler.js' +const minimist = require('minimist') +const { db, waitForDb } = require('../../../app/src/infrastructure/mongodb') +const UserRegistrationHandler = require('../../../app/src/Features/User/UserRegistrationHandler') async function main() { await waitForDb() diff --git a/services/web/modules/server-ce-scripts/scripts/delete-user.mjs b/services/web/modules/server-ce-scripts/scripts/delete-user.js similarity index 80% rename from services/web/modules/server-ce-scripts/scripts/delete-user.mjs rename to services/web/modules/server-ce-scripts/scripts/delete-user.js index 68f060c386..ff1060984a 100644 --- a/services/web/modules/server-ce-scripts/scripts/delete-user.mjs +++ b/services/web/modules/server-ce-scripts/scripts/delete-user.js @@ -1,6 +1,6 @@ -import { waitForDb } from '../../../app/src/infrastructure/mongodb.js' -import UserGetter from '../../../app/src/Features/User/UserGetter.js' -import UserDeleter from '../../../app/src/Features/User/UserDeleter.js' +const { waitForDb } = require('../../../app/src/infrastructure/mongodb') +const UserGetter = require('../../../app/src/Features/User/UserGetter') +const UserDeleter = require('../../../app/src/Features/User/UserDeleter') async function main() { await waitForDb() diff --git a/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.mjs b/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.js similarity index 91% rename from services/web/modules/server-ce-scripts/scripts/migrate-user-emails.mjs rename to services/web/modules/server-ce-scripts/scripts/migrate-user-emails.js index 39d44f5369..d266ad46d2 100644 --- a/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.mjs +++ b/services/web/modules/server-ce-scripts/scripts/migrate-user-emails.js @@ -9,16 +9,16 @@ // Intended for Server Pro customers migrating user emails from one domain to // another. -import minimist from 'minimist' +const minimist = require('minimist') +const { waitForDb } = require('../../../app/src/infrastructure/mongodb') -import { waitForDb } from '../../../app/src/infrastructure/mongodb.js' -import os from 'node:os' -import fs from 'node:fs' -import * as csv from 'csv/sync' -import { parseEmail } from '../../../app/src/Features/Helpers/EmailHelper.js' -import UserGetter from '../../../app/src/Features/User/UserGetter.js' -import UserUpdater from '../../../app/src/Features/User/UserUpdater.js' -import UserSessionsManager from '../../../app/src/Features/User/UserSessionsManager.js' +const os = require('os') +const fs = require('fs') +const csv = require('csv/sync') +const { parseEmail } = require('../../../app/src/Features/Helpers/EmailHelper') +const UserGetter = require('../../../app/src/Features/User/UserGetter') +const UserUpdater = require('../../../app/src/Features/User/UserUpdater') +const UserSessionsManager = require('../../../app/src/Features/User/UserSessionsManager') const hostname = os.hostname() const scriptTimestamp = new Date().toISOString() diff --git a/services/web/modules/server-ce-scripts/scripts/rename-tag.mjs b/services/web/modules/server-ce-scripts/scripts/rename-tag.js similarity index 85% rename from services/web/modules/server-ce-scripts/scripts/rename-tag.mjs rename to services/web/modules/server-ce-scripts/scripts/rename-tag.js index 28501a3674..51fa4377b6 100644 --- a/services/web/modules/server-ce-scripts/scripts/rename-tag.mjs +++ b/services/web/modules/server-ce-scripts/scripts/rename-tag.js @@ -1,5 +1,5 @@ -import minimist from 'minimist' -import { db, waitForDb } from '../../../app/src/infrastructure/mongodb.js' +const minimist = require('minimist') +const { db, waitForDb } = require('../../../app/src/infrastructure/mongodb') async function main() { await waitForDb() diff --git a/services/web/modules/server-ce-scripts/scripts/upgrade-user-features.mjs b/services/web/modules/server-ce-scripts/scripts/upgrade-user-features.js similarity index 77% rename from services/web/modules/server-ce-scripts/scripts/upgrade-user-features.mjs rename to services/web/modules/server-ce-scripts/scripts/upgrade-user-features.js index 7cbef16dd7..eb511fc298 100644 --- a/services/web/modules/server-ce-scripts/scripts/upgrade-user-features.mjs +++ b/services/web/modules/server-ce-scripts/scripts/upgrade-user-features.js @@ -1,11 +1,10 @@ -import { fileURLToPath } from 'node:url' -import Settings from '@overleaf/settings' -import logger from '@overleaf/logger' -import { db, waitForDb } from '../../../app/src/infrastructure/mongodb.js' -import { +const Settings = require('@overleaf/settings') +const logger = require('@overleaf/logger') +const { db, waitForDb } = require('../../../app/src/infrastructure/mongodb') +const { mergeFeatures, compareFeatures, -} from '../../../app/src/Features/Subscription/FeaturesHelper.js' +} = require('../../../app/src/Features/Subscription/FeaturesHelper') const DRY_RUN = !process.argv.includes('--dry-run=false') async function main(DRY_RUN, defaultFeatures) { @@ -41,9 +40,9 @@ async function main(DRY_RUN, defaultFeatures) { } } -export default main +module.exports = main -if (fileURLToPath(import.meta.url) === process.argv[1]) { +if (require.main === module) { if (DRY_RUN) { console.error('---') console.error('Dry-run enabled, use --dry-run=false to commit changes') diff --git a/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs b/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.js similarity index 91% rename from services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs rename to services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.js index 0069a46105..0c304e14f1 100644 --- a/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs +++ b/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.js @@ -1,11 +1,9 @@ -import { execSync } from 'node:child_process' -import fs from 'node:fs' -import Settings from '@overleaf/settings' -import { expect } from 'chai' -import { db } from '../../../../../app/src/infrastructure/mongodb.js' -import UserHelper from '../../../../../test/acceptance/src/helpers/User.js' - -const { promises: User } = UserHelper +const { execSync } = require('child_process') +const fs = require('fs') +const Settings = require('@overleaf/settings') +const { expect } = require('chai') +const { db } = require('../../../../../app/src/infrastructure/mongodb') +const User = require('../../../../../test/acceptance/src/helpers/User').promises /** * @param {string} cmd @@ -44,7 +42,7 @@ async function getUser(email) { describe('ServerCEScripts', function () { describe('check-mongodb', function () { it('should exit with code 0 on success', function () { - run('node modules/server-ce-scripts/scripts/check-mongodb.mjs') + run('node modules/server-ce-scripts/scripts/check-mongodb') }) it('should exit with code 1 on error', function () { @@ -52,7 +50,7 @@ describe('ServerCEScripts', function () { run( 'MONGO_SERVER_SELECTION_TIMEOUT=1' + 'MONGO_CONNECTION_STRING=mongodb://127.0.0.1:4242 ' + - 'node modules/server-ce-scripts/scripts/check-mongodb.mjs' + 'node modules/server-ce-scripts/scripts/check-mongodb' ) } catch (e) { expect(e.status).to.equal(1) @@ -64,14 +62,12 @@ describe('ServerCEScripts', function () { describe('check-redis', function () { it('should exit with code 0 on success', function () { - run('node modules/server-ce-scripts/scripts/check-redis.mjs') + run('node modules/server-ce-scripts/scripts/check-redis') }) it('should exit with code 1 on error', function () { try { - run( - 'REDIS_PORT=42 node modules/server-ce-scripts/scripts/check-redis.mjs' - ) + run('REDIS_PORT=42 node modules/server-ce-scripts/scripts/check-redis') } catch (e) { expect(e.status).to.equal(1) return @@ -83,28 +79,28 @@ describe('ServerCEScripts', function () { describe('create-user', function () { it('should exit with code 0 on success', function () { const out = run( - 'node modules/server-ce-scripts/scripts/create-user.mjs --email=foo@bar.com' + 'node modules/server-ce-scripts/scripts/create-user --email=foo@bar.com' ) expect(out).to.include('/user/activate?token=') }) it('should create a regular user by default', async function () { run( - 'node modules/server-ce-scripts/scripts/create-user.mjs --email=foo@bar.com' + 'node modules/server-ce-scripts/scripts/create-user --email=foo@bar.com' ) expect(await getUser('foo@bar.com')).to.deep.equal({ isAdmin: false }) }) it('should create an admin user with --admin flag', async function () { run( - 'node modules/server-ce-scripts/scripts/create-user.mjs --admin --email=foo@bar.com' + 'node modules/server-ce-scripts/scripts/create-user --admin --email=foo@bar.com' ) expect(await getUser('foo@bar.com')).to.deep.equal({ isAdmin: true }) }) it('should exit with code 1 on missing email', function () { try { - run('node modules/server-ce-scripts/scripts/create-user.mjs') + run('node modules/server-ce-scripts/scripts/create-user') } catch (e) { expect(e.status).to.equal(1) return @@ -123,26 +119,19 @@ describe('ServerCEScripts', function () { it('should log missing user', function () { const email = 'does-not-exist@example.com' const out = run( - 'node modules/server-ce-scripts/scripts/delete-user.mjs --email=' + - email + 'node modules/server-ce-scripts/scripts/delete-user --email=' + email ) expect(out).to.include('not in database, potentially already deleted') }) it('should exit with code 0 on success', function () { const email = user.email - run( - 'node modules/server-ce-scripts/scripts/delete-user.mjs --email=' + - email - ) + run('node modules/server-ce-scripts/scripts/delete-user --email=' + email) }) it('should have deleted the user on success', async function () { const email = user.email - run( - 'node modules/server-ce-scripts/scripts/delete-user.mjs --email=' + - email - ) + run('node modules/server-ce-scripts/scripts/delete-user --email=' + email) const dbEntry = await user.get() expect(dbEntry).to.not.exist const softDeletedEntry = await db.deletedUsers.findOne({ @@ -154,7 +143,7 @@ describe('ServerCEScripts', function () { it('should exit with code 1 on missing email', function () { try { - run('node modules/server-ce-scripts/scripts/delete-user.mjs') + run('node modules/server-ce-scripts/scripts/delete-user') } catch (e) { expect(e.status).to.equal(1) return @@ -210,7 +199,7 @@ describe('ServerCEScripts', function () { it('should do a dry run by default', async function () { run( - `node modules/server-ce-scripts/scripts/migrate-user-emails.mjs ${csv}` + `node modules/server-ce-scripts/scripts/migrate-user-emails.js ${csv}` ) for (const user of usersToMigrate) { const dbEntry = await user.get() @@ -224,13 +213,13 @@ describe('ServerCEScripts', function () { it('should exit with code 0 when successfully migrating user emails', function () { run( - `node modules/server-ce-scripts/scripts/migrate-user-emails.mjs --commit ${csv}` + `node modules/server-ce-scripts/scripts/migrate-user-emails.js --commit ${csv}` ) }) it('should migrate the user emails with the --commit option', async function () { run( - `node modules/server-ce-scripts/scripts/migrate-user-emails.mjs --commit ${csv}` + `node modules/server-ce-scripts/scripts/migrate-user-emails.js --commit ${csv}` ) for (const user of usersToMigrate) { const dbEntry = await user.get() @@ -244,7 +233,7 @@ describe('ServerCEScripts', function () { it('should leave other user emails unchanged', async function () { run( - `node modules/server-ce-scripts/scripts/migrate-user-emails.mjs --commit ${csv}` + `node modules/server-ce-scripts/scripts/migrate-user-emails.js --commit ${csv}` ) for (const user of otherUsers) { const dbEntry = await user.get() @@ -255,7 +244,7 @@ describe('ServerCEScripts', function () { it('should exit with code 1 when there are failures migrating user emails', function () { try { run( - `node modules/server-ce-scripts/scripts/migrate-user-emails.mjs --commit ${csvfail}` + `node modules/server-ce-scripts/scripts/migrate-user-emails.js --commit ${csvfail}` ) } catch (e) { expect(e.status).to.equal(1) @@ -267,12 +256,12 @@ describe('ServerCEScripts', function () { it('should migrate other users when there are failures with the --continue option', async function () { try { run( - `node modules/server-ce-scripts/scripts/migrate-user-emails.mjs --commit ${csvfail}` + `node modules/server-ce-scripts/scripts/migrate-user-emails.js --commit ${csvfail}` ) } catch (e) { expect(e.status).to.equal(1) run( - `node modules/server-ce-scripts/scripts/migrate-user-emails.mjs --commit --continue ${csvfail}` + `node modules/server-ce-scripts/scripts/migrate-user-emails.js --commit --continue ${csvfail}` ) for (const user of usersToMigrate) { const dbEntry = await user.get() @@ -312,7 +301,7 @@ describe('ServerCEScripts', function () { expect(await getTagNames()).to.deep.equal([oldName]) run( - `node modules/server-ce-scripts/scripts/rename-tag.mjs --user-id=${user.id} --old-name=${oldName} --new-name=${newName}` + `node modules/server-ce-scripts/scripts/rename-tag --user-id=${user.id} --old-name=${oldName} --new-name=${newName}` ) expect(await getTagNames()).to.deep.equal([newName]) @@ -345,7 +334,7 @@ describe('ServerCEScripts', function () { beforeEach('run script on user a', function () { newUserATimeout = userATimeout - 1 run( - `node modules/server-ce-scripts/scripts/change-compile-timeout.mjs --user-id=${userA.id} --compile-timeout=${newUserATimeout}` + `node modules/server-ce-scripts/scripts/change-compile-timeout --user-id=${userA.id} --compile-timeout=${newUserATimeout}` ) }) @@ -364,7 +353,7 @@ describe('ServerCEScripts', function () { it('should reject zero timeout', async function () { try { run( - `node modules/server-ce-scripts/scripts/change-compile-timeout.mjs --user-id=${userA.id} --compile-timeout=0` + `node modules/server-ce-scripts/scripts/change-compile-timeout --user-id=${userA.id} --compile-timeout=0` ) expect.fail('should error out') } catch (err) { @@ -377,7 +366,7 @@ describe('ServerCEScripts', function () { it('should reject a 20min timeout', async function () { try { run( - `node modules/server-ce-scripts/scripts/change-compile-timeout.mjs --user-id=${userA.id} --compile-timeout=1200` + `node modules/server-ce-scripts/scripts/change-compile-timeout --user-id=${userA.id} --compile-timeout=1200` ) expect.fail('should error out') } catch (err) { @@ -421,13 +410,13 @@ describe('ServerCEScripts', function () { beforeEach('downgrade userCustomTimeoutLower', async function () { run( - `node modules/server-ce-scripts/scripts/change-compile-timeout.mjs --user-id=${userCustomTimeoutLower.id} --compile-timeout=42` + `node modules/server-ce-scripts/scripts/change-compile-timeout --user-id=${userCustomTimeoutLower.id} --compile-timeout=42` ) }) beforeEach('upgrade userCustomTimeoutHigher', async function () { run( - `node modules/server-ce-scripts/scripts/change-compile-timeout.mjs --user-id=${userCustomTimeoutHigher.id} --compile-timeout=360` + `node modules/server-ce-scripts/scripts/change-compile-timeout --user-id=${userCustomTimeoutHigher.id} --compile-timeout=360` ) }) @@ -462,7 +451,7 @@ describe('ServerCEScripts', function () { let output beforeEach('run script', function () { output = run( - `node modules/server-ce-scripts/scripts/upgrade-user-features.mjs` + `node modules/server-ce-scripts/scripts/upgrade-user-features` ) }) @@ -491,7 +480,7 @@ describe('ServerCEScripts', function () { let output beforeEach('run script', function () { output = run( - `node modules/server-ce-scripts/scripts/upgrade-user-features.mjs --dry-run=false` + `node modules/server-ce-scripts/scripts/upgrade-user-features --dry-run=false` ) }) @@ -548,7 +537,7 @@ describe('ServerCEScripts', function () { cmd += ` OVERLEAF_IS_SERVER_PRO=${OVERLEAF_IS_SERVER_PRO}` } return ( - cmd + ' node modules/server-ce-scripts/scripts/check-texlive-images.mjs' + cmd + ' node modules/server-ce-scripts/scripts/check-texlive-images' ) }