mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 22:57:11 -04:00
Converted imports to es
This commit is contained in:
parent
078324c0d1
commit
4b8911dfee
33 changed files with 111 additions and 98 deletions
|
@ -22,10 +22,10 @@
|
|||
import {ChildProcess} from "node:child_process";
|
||||
import {AsyncQueueTask} from "../types/AsyncQueueTask";
|
||||
|
||||
const spawn = require('child_process').spawn;
|
||||
const async = require('async');
|
||||
import {spawn} from 'child_process'
|
||||
import async from 'async';
|
||||
const settings = require('./Settings');
|
||||
const os = require('os');
|
||||
import os from 'os';
|
||||
|
||||
// on windows we have to spawn a process for each convertion,
|
||||
// cause the plugin abicommand doesn't exist on this platform
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const log4js = require('log4js');
|
||||
const path = require('path');
|
||||
const _ = require('underscore');
|
||||
import log4js from 'log4js';
|
||||
import path from 'path';
|
||||
import _ from 'underscore';
|
||||
|
||||
const absPathLogger = log4js.getLogger('AbsolutePaths');
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
*/
|
||||
|
||||
const Stream = require('./Stream');
|
||||
const assert = require('assert').strict;
|
||||
import {strict as assert} from "assert";
|
||||
|
||||
const authorManager = require('../db/AuthorManager');
|
||||
const hooks = require('../../static/js/pluginfw/hooks');
|
||||
const padManager = require('../db/PadManager');
|
||||
|
|
|
@ -21,7 +21,7 @@ import {MapArrayType} from "../types/MapType";
|
|||
const Changeset = require('../../static/js/Changeset');
|
||||
const attributes = require('../../static/js/attributes');
|
||||
const padManager = require('../db/PadManager');
|
||||
const _ = require('underscore');
|
||||
import _ from 'underscore';
|
||||
const Security = require('../../static/js/security');
|
||||
const hooks = require('../../static/js/pluginfw/hooks');
|
||||
const eejs = require('../eejs');
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
* 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');
|
||||
import async from 'async';
|
||||
import {promises as fs} from 'fs';
|
||||
import log4js from 'log4js';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
const runCmd = require('./run_cmd');
|
||||
const settings = require('./Settings');
|
||||
|
||||
|
@ -87,7 +87,6 @@ const queue = async.queue(doConvertTask, 1);
|
|||
* @param {String} srcFile The path on disk to convert
|
||||
* @param {String} destFile The path on disk where the converted file should be stored
|
||||
* @param {String} type The type to convert into
|
||||
* @param {Function} callback Standard callback function
|
||||
*/
|
||||
exports.convertFile = async (srcFile: string, destFile: string, type:string) => {
|
||||
// Used for the moving of the file, not the conversion
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -28,17 +28,16 @@
|
|||
*/
|
||||
|
||||
const absolutePaths = require('./AbsolutePaths');
|
||||
const deepEqual = require('fast-deep-equal/es6');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
const argv = require('./Cli').argv;
|
||||
const jsonminify = require('jsonminify');
|
||||
const log4js = require('log4js');
|
||||
import jsonminify from 'jsonminify';
|
||||
import log4js from 'log4js';
|
||||
const randomString = require('./randomstring');
|
||||
const suppressDisableMsg = ' -- To suppress these warning messages change ' +
|
||||
'suppressErrorsInPadText to true in your settings.json\n';
|
||||
const _ = require('underscore');
|
||||
import _ from 'underscore';
|
||||
|
||||
const logger = log4js.getLogger('settings');
|
||||
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Buffer = require('buffer').Buffer;
|
||||
const fs = require('fs');
|
||||
const fsp = fs.promises;
|
||||
const path = require('path');
|
||||
const zlib = require('zlib');
|
||||
import {Buffer} from "buffer";
|
||||
import fs, {promises as fsp} from 'fs';
|
||||
import path from 'path';
|
||||
import zlib from 'zlib';
|
||||
const settings = require('./Settings');
|
||||
const existsSync = require('./path_exists');
|
||||
const util = require('util');
|
||||
import existsSync from './path_exists';
|
||||
import util from 'util';
|
||||
|
||||
/*
|
||||
* The crypto module can be absent on reduced node installations.
|
||||
|
@ -37,10 +36,11 @@ const util = require('util');
|
|||
*/
|
||||
|
||||
|
||||
const _crypto = require('crypto');
|
||||
import _crypto from 'crypto';
|
||||
import {createReadStream} from "node:fs";
|
||||
|
||||
|
||||
let CACHE_DIR = path.join(settings.root, 'var/');
|
||||
let CACHE_DIR:string|boolean|fs.Stats|undefined = path.join(settings.root, 'var/');
|
||||
CACHE_DIR = existsSync(CACHE_DIR) ? CACHE_DIR : undefined;
|
||||
|
||||
type Headers = {
|
||||
|
@ -141,7 +141,7 @@ module.exports = class CachingMiddleware {
|
|||
res.writeHead(304, headers);
|
||||
res.end();
|
||||
} else if (req.method === 'GET') {
|
||||
const readStream = fs.createReadStream(pathStr);
|
||||
const readStream = createReadStream(pathStr);
|
||||
res.writeHead(statusCode, headers);
|
||||
readStream.pipe(res);
|
||||
} else {
|
||||
|
@ -188,6 +188,7 @@ module.exports = class CachingMiddleware {
|
|||
await Promise.all([
|
||||
fsp.writeFile(`${CACHE_DIR}minified_${cacheKey}`, buffer).catch(() => {}),
|
||||
util.promisify(zlib.gzip)(buffer)
|
||||
// @ts-ignore
|
||||
.then((content: string) => fsp.writeFile(`${CACHE_DIR}minified_${cacheKey}.gz`, content))
|
||||
.catch(() => {}),
|
||||
]);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
'use strict';
|
||||
const fs = require('fs');
|
||||
import fs from 'fs';
|
||||
|
||||
const check = (path:string) => {
|
||||
const check = (path:string):false|fs.Stats => {
|
||||
const existsSync = fs.statSync || fs.existsSync;
|
||||
|
||||
let result;
|
||||
let result:false|fs.Stats;
|
||||
try {
|
||||
result = existsSync(path);
|
||||
} catch (e) {
|
||||
|
@ -13,4 +13,4 @@ const check = (path:string) => {
|
|||
return result;
|
||||
};
|
||||
|
||||
module.exports = check;
|
||||
export default check;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Generates a random String with the given length. Is needed to generate the
|
||||
* Author, Group, readonly, session Ids
|
||||
*/
|
||||
const cryptoMod = require('crypto');
|
||||
import cryptoMod from 'crypto';
|
||||
|
||||
const randomString = (len: number) => cryptoMod.randomBytes(len).toString('hex');
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
import {ErrorExtended, RunCMDOptions, RunCMDPromise} from "../types/RunCMDOptions";
|
||||
import {ChildProcess} from "node:child_process";
|
||||
import {ChildProcess, SpawnOptions} from "node:child_process";
|
||||
import {PromiseWithStd} from "../types/PromiseWithStd";
|
||||
import {Readable} from "node:stream";
|
||||
|
||||
const spawn = require('cross-spawn');
|
||||
const log4js = require('log4js');
|
||||
const path = require('path');
|
||||
import spawn from 'cross-spawn';
|
||||
import log4js from 'log4js';
|
||||
import path from 'path';
|
||||
const settings = require('./Settings');
|
||||
|
||||
const logger = log4js.getLogger('runCmd');
|
||||
|
@ -32,6 +32,8 @@ const logLines = (readable: undefined | Readable | null, logLineFn: (arg0: (stri
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Runs a command, logging its output to Etherpad's logs by default.
|
||||
*
|
||||
|
@ -74,7 +76,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 = {}) => {
|
||||
module.exports = exports = (args: string[], opts:SpawnOptions= {}) => {
|
||||
logger.debug(`Executing command: ${args.join(' ')}`);
|
||||
|
||||
opts = {cwd: settings.root, ...opts};
|
||||
|
@ -84,7 +86,8 @@ module.exports = exports = (args: string[], opts:RunCMDOptions = {}) => {
|
|||
const stdio =
|
||||
Array.isArray(opts.stdio) ? opts.stdio.slice() // Copy to avoid mutating the caller's array.
|
||||
: typeof opts.stdio === 'function' ? [null, opts.stdio, opts.stdio]
|
||||
: opts.stdio === 'string' ? [null, 'string', 'string']
|
||||
// @ts-ignore
|
||||
: opts.stdio === 'string' ? [null, 'string', 'string']
|
||||
: Array(3).fill(opts.stdio);
|
||||
const cmdLogger = log4js.getLogger(`runCmd|${args[0]}`);
|
||||
if (stdio[1] == null) stdio[1] = (line: string) => cmdLogger.info(line);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
import path from 'path';
|
||||
|
||||
// Normalizes p and ensures that it is a relative path that does not reach outside. See
|
||||
// https://nvd.nist.gov/vuln/detail/CVE-2015-3297 for additional context.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue