diff --git a/src/node/utils/AbsolutePaths.ts b/src/node/utils/AbsolutePaths.ts index 6423ae4d7..cd5a97649 100644 --- a/src/node/utils/AbsolutePaths.ts +++ b/src/node/utils/AbsolutePaths.ts @@ -21,6 +21,12 @@ import log4js from 'log4js'; import path from 'path'; import _ from 'underscore'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; +import findRoot from 'find-root'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const absPathLogger = log4js.getLogger('AbsolutePaths'); @@ -79,7 +85,6 @@ export const findEtherpadRoot = () => { return etherpadRoot; } - const findRoot = require('find-root'); const foundRoot = findRoot(__dirname); const splitFoundRoot = foundRoot.split(path.sep); diff --git a/src/node/utils/Cleanup.ts b/src/node/utils/Cleanup.ts index 30967654f..2dbad6232 100644 --- a/src/node/utils/Cleanup.ts +++ b/src/node/utils/Cleanup.ts @@ -1,13 +1,13 @@ 'use strict' -import {AChangeSet} from "../types/PadType"; -import {Revision} from "../types/Revision"; +import {AChangeSet} from "../types/PadType.js"; +import {Revision} from "../types/Revision.js"; -import {timesLimit, firstSatisfies} from './promises'; -const padManager = require('ep_etherpad-lite/node/db/PadManager'); -const db = require('ep_etherpad-lite/node/db/DB'); -const Changeset = require('ep_etherpad-lite/static/js/Changeset'); -const padMessageHandler = require('ep_etherpad-lite/node/handler/PadMessageHandler'); +import {timesLimit, firstSatisfies} from './promises.js'; +import padManager from 'ep_etherpad-lite/node/db/PadManager.js'; +import db from 'ep_etherpad-lite/node/db/DB.js'; +import * as Changeset from 'ep_etherpad-lite/static/js/Changeset.js'; +import padMessageHandler from 'ep_etherpad-lite/node/handler/PadMessageHandler.js'; import log4js from 'log4js'; const logger = log4js.getLogger('cleanup'); diff --git a/src/node/utils/ExportHelper.ts b/src/node/utils/ExportHelper.ts index 4c29534f4..79793d59c 100644 --- a/src/node/utils/ExportHelper.ts +++ b/src/node/utils/ExportHelper.ts @@ -19,16 +19,15 @@ * limitations under the License. */ -import AttributeMap from '../../static/js/AttributeMap'; -import AttributePool from "../../static/js/AttributePool"; -import {deserializeOps, splitAttributionLines, subattribution} from '../../static/js/Changeset'; -const { checkValidRev } = require('./checkValidRev'); +import AttributeMap from '../../static/js/AttributeMap.js'; +import AttributePool from "../../static/js/AttributePool.js"; +import {deserializeOps, splitAttributionLines, subattribution} from '../../static/js/Changeset.js'; +import { checkValidRev } from './checkValidRev.js'; /* * This method seems unused in core and no plugins depend on it */ -exports.getPadPlainText = (pad: { getInternalRevisionAText: (arg0: any) => any; atext: any; pool: any; }, revNum: undefined) => { - const _analyzeLine = exports._analyzeLine; +export const getPadPlainText = (pad: { getInternalRevisionAText: (arg0: any) => any; atext: any; pool: any; }, revNum: undefined) => { const atext = ((revNum !== undefined) ? pad.getInternalRevisionAText(checkValidRev(revNum)) : pad.atext); const textLines = atext.text.slice(0, -1).split('\n'); const attribLines = splitAttributionLines(atext.attribs, atext.text); @@ -52,7 +51,7 @@ type LineModel = { [id:string]:string|number|LineModel } -exports._analyzeLine = (text:string, aline: string, apool: AttributePool) => { +export const _analyzeLine = (text:string, aline: string, apool: AttributePool) => { const line: LineModel = {}; // identify list @@ -88,5 +87,5 @@ exports._analyzeLine = (text:string, aline: string, apool: AttributePool) => { }; -exports._encodeWhitespace = +export const _encodeWhitespace = (s:string) => s.replace(/[^\x21-\x7E\s\t\n\r]/gu, (c) => `&#${c.codePointAt(0)};`); diff --git a/src/node/utils/ExportTxt.ts b/src/node/utils/ExportTxt.ts index 587468228..b906b5e62 100644 --- a/src/node/utils/ExportTxt.ts +++ b/src/node/utils/ExportTxt.ts @@ -19,15 +19,15 @@ * limitations under the License. */ -import {AText, PadType} from "../types/PadType"; -import {MapType} from "../types/MapType"; +import {AText, PadType} from "../types/PadType.js"; +import {MapType} from "../types/MapType.js"; -import {deserializeOps, splitAttributionLines, subattribution} from '../../static/js/Changeset'; -import {StringIterator} from "../../static/js/StringIterator"; -import {StringAssembler} from "../../static/js/StringAssembler"; -const attributes = require('../../static/js/attributes'); -const padManager = require('../db/PadManager'); -const _analyzeLine = require('./ExportHelper')._analyzeLine; +import {deserializeOps, splitAttributionLines, subattribution} from '../../static/js/Changeset.js'; +import {StringIterator} from "../../static/js/StringIterator.js"; +import {StringAssembler} from "../../static/js/StringAssembler.js"; +import * as attributes from '../../static/js/attributes.js'; +import padManager from '../db/PadManager.js'; +import { _analyzeLine } from './ExportHelper.js'; // This is slightly different than the HTML method as it passes the output to getTXTFromAText const getPadTXT = async (pad: PadType, revNum: string) => { @@ -262,9 +262,9 @@ const getTXTFromAtext = (pad: PadType, atext: AText, authorColors?:string) => { return pieces.join(''); }; -exports.getTXTFromAtext = getTXTFromAtext; +export { getTXTFromAtext }; -exports.getPadTXTDocument = async (padId:string, revNum:string) => { +export const getPadTXTDocument = async (padId:string, revNum:string) => { const pad = await padManager.getPad(padId); return getPadTXT(pad, revNum); }; diff --git a/src/node/utils/ImportHtml.ts b/src/node/utils/ImportHtml.ts index 941aa767a..94caf118e 100644 --- a/src/node/utils/ImportHtml.ts +++ b/src/node/utils/ImportHtml.ts @@ -16,16 +16,16 @@ */ import log4js from 'log4js'; -import {deserializeOps} from '../../static/js/Changeset'; -const contentcollector = require('../../static/js/contentcollector'); +import {deserializeOps} from '../../static/js/Changeset.js'; +import * as contentcollector from '../../static/js/contentcollector.js'; import jsdom from 'jsdom'; -import {PadType} from "../types/PadType"; -import {Builder} from "../../static/js/Builder"; +import {PadType} from "../types/PadType.js"; +import {Builder} from "../../static/js/Builder.js"; const apiLogger = log4js.getLogger('ImportHtml'); let processor:any; -exports.setPadHTML = async (pad: PadType, html:string, authorId = '') => { +export const setPadHTML = async (pad: PadType, html:string, authorId = '') => { if (processor == null) { const [{rehype}, {default: minifyWhitespace}] = await Promise.all([import('rehype'), import('rehype-minify-whitespace')]); diff --git a/src/node/utils/LibreOffice.ts b/src/node/utils/LibreOffice.ts index e73fd144c..56768caf1 100644 --- a/src/node/utils/LibreOffice.ts +++ b/src/node/utils/LibreOffice.ts @@ -17,13 +17,13 @@ * limitations under the License. */ -const async = require('async'); -const fs = require('fs').promises; -const log4js = require('log4js'); -const os = require('os'); -const path = require('path'); -const runCmd = require('./run_cmd'); -import settings from './Settings'; +import async from 'async'; +import { promises as fs } from 'fs'; +import log4js from 'log4js'; +import os from 'os'; +import path from 'path'; +import runCmd from './run_cmd.js'; +import settings from './Settings.js'; const logger = log4js.getLogger('LibreOffice'); @@ -89,7 +89,7 @@ const queue = async.queue(doConvertTask, 1); * @param {String} type The type to convert into * @param {Function} callback Standard callback function */ -exports.convertFile = async (srcFile: string, destFile: string, type:string) => { +export const convertFile = async (srcFile: string, destFile: string, type:string) => { // Used for the moving of the file, not the conversion const fileExtension = type; diff --git a/src/node/utils/NodeVersion.ts b/src/node/utils/NodeVersion.ts index f24bf1831..811ce9792 100644 --- a/src/node/utils/NodeVersion.ts +++ b/src/node/utils/NodeVersion.ts @@ -19,7 +19,7 @@ * limitations under the License. */ -const semver = require('semver'); +import semver from 'semver'; /** * Quits if Etherpad is not running on a given minimum Node version diff --git a/src/node/utils/Stream.ts b/src/node/utils/Stream.ts index 36fde1ac7..115ac6ef7 100644 --- a/src/node/utils/Stream.ts +++ b/src/node/utils/Stream.ts @@ -136,4 +136,4 @@ class Stream { [Symbol.iterator]() { return this._iter; } } -module.exports = Stream; +export default Stream; diff --git a/src/node/utils/UpdateCheck.ts b/src/node/utils/UpdateCheck.ts index da292e373..2c984b196 100644 --- a/src/node/utils/UpdateCheck.ts +++ b/src/node/utils/UpdateCheck.ts @@ -1,6 +1,6 @@ 'use strict'; import semver from 'semver'; -import settings, {getEpVersion} from './Settings'; +import settings, {getEpVersion} from './Settings.js'; import axios from 'axios'; const headers = { 'User-Agent': 'Etherpad/' + getEpVersion(), diff --git a/src/node/utils/checkValidRev.ts b/src/node/utils/checkValidRev.ts index 5367ddf99..bf6bb4bbf 100644 --- a/src/node/utils/checkValidRev.ts +++ b/src/node/utils/checkValidRev.ts @@ -1,6 +1,6 @@ 'use strict'; -const CustomError = require('../utils/customError'); +import CustomError from './customError.js'; // checks if a rev is a legal number // pre-condition is that `rev` is not undefined @@ -30,5 +30,4 @@ const checkValidRev = (rev: number|string) => { // checks if a number is an int const isInt = (value:number) => (parseFloat(String(value)) === parseInt(String(value), 10)) && !isNaN(value); -exports.isInt = isInt; -exports.checkValidRev = checkValidRev; +export { isInt, checkValidRev }; diff --git a/src/node/utils/customError.ts b/src/node/utils/customError.ts index c58360269..fe58624d8 100644 --- a/src/node/utils/customError.ts +++ b/src/node/utils/customError.ts @@ -21,4 +21,4 @@ class CustomError extends Error { } } -module.exports = CustomError; +export default CustomError; diff --git a/src/node/utils/padDiff.ts b/src/node/utils/padDiff.ts index b6407e65b..4e0026b16 100644 --- a/src/node/utils/padDiff.ts +++ b/src/node/utils/padDiff.ts @@ -1,17 +1,17 @@ 'use strict'; -import {PadAuthor, PadType} from "../types/PadType"; -import {MapArrayType} from "../types/MapType"; +import {PadAuthor, PadType} from "../types/PadType.js"; +import {MapArrayType} from "../types/MapType.js"; -import AttributeMap from '../../static/js/AttributeMap'; -import {applyToAText, checkRep, compose, deserializeOps, pack, splitAttributionLines, splitTextLines, unpack} from '../../static/js/Changeset'; -import {Builder} from "../../static/js/Builder"; -import {OpAssembler} from "../../static/js/OpAssembler"; -import {numToString} from "../../static/js/ChangesetUtils"; -import Op from "../../static/js/Op"; -import {StringAssembler} from "../../static/js/StringAssembler"; -const attributes = require('../../static/js/attributes'); -const exportHtml = require('./ExportHtml'); +import AttributeMap from '../../static/js/AttributeMap.js'; +import {applyToAText, checkRep, compose, deserializeOps, pack, splitAttributionLines, splitTextLines, unpack} from '../../static/js/Changeset.js'; +import {Builder} from "../../static/js/Builder.js"; +import {OpAssembler} from "../../static/js/OpAssembler.js"; +import {numToString} from "../../static/js/ChangesetUtils.js"; +import Op from "../../static/js/Op.js"; +import {StringAssembler} from "../../static/js/StringAssembler.js"; +import * as attributes from '../../static/js/attributes.js'; +import * as exportHtml from './ExportHtml.js'; class PadDiff { @@ -456,4 +456,4 @@ class PadDiff { // export the constructor -module.exports = PadDiff; +export default PadDiff; diff --git a/src/node/utils/run_cmd.ts b/src/node/utils/run_cmd.ts index c7e37b78c..eca4febf5 100644 --- a/src/node/utils/run_cmd.ts +++ b/src/node/utils/run_cmd.ts @@ -1,14 +1,14 @@ 'use strict'; -import {ErrorExtended, RunCMDOptions, RunCMDPromise} from "../types/RunCMDOptions"; +import {ErrorExtended, RunCMDOptions, RunCMDPromise} from "../types/RunCMDOptions.js"; import {ChildProcess} from "node:child_process"; -import {PromiseWithStd} from "../types/PromiseWithStd"; +import {PromiseWithStd} from "../types/PromiseWithStd.js"; import {Readable} from "node:stream"; import spawn from 'cross-spawn'; import log4js from 'log4js'; import path from 'path'; -import settings from './Settings'; +import settings from './Settings.js'; const logger = log4js.getLogger('runCmd'); @@ -74,7 +74,7 @@ const logLines = (readable: undefined | Readable | null, logLineFn: (arg0: (stri * - `stderr`: Similar to `stdout` but for stderr. * - `child`: The ChildProcess object. */ -module.exports = exports = (args: string[], opts:RunCMDOptions = {}) => { +const runCmd = (args: string[], opts:RunCMDOptions = {}) => { logger.debug(`Executing command: ${args.join(' ')}`); opts = {cwd: settings.root, ...opts}; @@ -161,3 +161,5 @@ module.exports = exports = (args: string[], opts:RunCMDOptions = {}) => { }); return p; }; + +export default runCmd;