diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 44b65ac4..1b392900 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -9,7 +9,6 @@ jobs: strategy: matrix: node-version: - - 20.x - 22.x - 24.x - 25.x diff --git a/.putout.json b/.putout.json index 4a41dc22..d780a84c 100644 --- a/.putout.json +++ b/.putout.json @@ -46,6 +46,9 @@ }, "vim.js": { "merge-duplicate-functions": "off" + }, + "common": { + "nodejs/declare": "off" } } } diff --git a/.webpack/js.js b/.webpack/js.js index d666780d..1e3144cf 100644 --- a/.webpack/js.js +++ b/.webpack/js.js @@ -31,7 +31,7 @@ const devtool = isDev ? 'eval' : 'source-map'; const notEmpty = (a) => a; const clean = (array) => array.filter(notEmpty); -const noParse = (a) => /\.spec\.js$/.test(a); +const noParse = (a) => a.endsWith('.spec.js'); const options = { babelrc: true, }; diff --git a/bin/cloudcmd.mjs b/bin/cloudcmd.mjs index 11dabd3d..fbef881a 100755 --- a/bin/cloudcmd.mjs +++ b/bin/cloudcmd.mjs @@ -3,7 +3,7 @@ import process from 'node:process'; import {createRequire} from 'node:module'; import {promisify} from 'node:util'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import {createSimport} from 'simport'; import parse from 'yargs-parser'; import exit from '../server/exit.js'; diff --git a/bin/release.mjs b/bin/release.mjs index 694eb7da..004b908e 100755 --- a/bin/release.mjs +++ b/bin/release.mjs @@ -2,7 +2,7 @@ import {promisify} from 'node:util'; import process from 'node:process'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import {createSimport} from 'simport'; import minor from 'minor'; import _place from 'place'; diff --git a/client/client.js b/client/client.js index df121fb6..a4afddbe 100644 --- a/client/client.js +++ b/client/client.js @@ -7,7 +7,7 @@ const Emitify = require('emitify'); const inherits = require('inherits'); const rendy = require('rendy'); const load = require('load.js'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const {addSlashToEnd} = require('format-io'); const pascalCase = require('just-pascal-case'); const currify = require('currify'); diff --git a/client/dom/current-file.js b/client/dom/current-file.js index 1150de2a..3ac29ae7 100644 --- a/client/dom/current-file.js +++ b/client/dom/current-file.js @@ -296,7 +296,7 @@ module.exports.isCurrentIsDir = (currentFile) => { const path = DOM.getCurrentPath(current); const fileType = DOM.getCurrentType(current); - const isZip = /\.zip$/.test(path); + const isZip = path.endsWith('.zip'); const isDir = /^directory(-link)?/.test(fileType); return isDir || isZip; diff --git a/client/dom/current-file.spec.js b/client/dom/current-file.spec.js index de1ba2af..ec643d3d 100644 --- a/client/dom/current-file.spec.js +++ b/client/dom/current-file.spec.js @@ -291,7 +291,7 @@ function getDOM(overrides = {}) { getByDataName = stub(), isContainClass = stub(), getCurrentType = stub(), - getCurrentPath = stub(), + getCurrentPath = stub().returns(''), } = overrides; return { diff --git a/client/dom/dialog.js b/client/dom/dialog.js index f4751456..eb342221 100644 --- a/client/dom/dialog.js +++ b/client/dom/dialog.js @@ -1,6 +1,6 @@ 'use strict'; -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const { alert, diff --git a/client/dom/dom-tree.spec.js b/client/dom/dom-tree.spec.js index 044e97b0..606df179 100644 --- a/client/dom/dom-tree.spec.js +++ b/client/dom/dom-tree.spec.js @@ -2,7 +2,7 @@ const test = require('supertape'); const {create} = require('auto-globals'); -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const {isContainClass} = require('./dom-tree'); diff --git a/client/dom/load-remote.js b/client/dom/load-remote.js index 84c7e329..b1b798a8 100644 --- a/client/dom/load-remote.js +++ b/client/dom/load-remote.js @@ -4,7 +4,7 @@ const rendy = require('rendy'); const itype = require('itype'); const load = require('load.js'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const {findObjByNameInArr} = require('../../common/util'); diff --git a/client/dom/rest.js b/client/dom/rest.js index 9c638446..444fce15 100644 --- a/client/dom/rest.js +++ b/client/dom/rest.js @@ -1,6 +1,6 @@ 'use strict'; -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const {encode} = require('../../common/entity'); diff --git a/client/listeners/index.js b/client/listeners/index.js index 1e3c9edf..99206a9e 100644 --- a/client/listeners/index.js +++ b/client/listeners/index.js @@ -5,7 +5,7 @@ const exec = require('execon'); const itype = require('itype'); const currify = require('currify'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const clipboard = require('@cloudcmd/clipboard'); const getRange = require('./get-range'); diff --git a/client/load-module.js b/client/load-module.js index 0ce0cc64..3b2af5a8 100644 --- a/client/load-module.js +++ b/client/load-module.js @@ -2,7 +2,7 @@ /* global CloudCmd */ const exec = require('execon'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const loadJS = require('load.js').js; const pascalCase = require('just-pascal-case'); diff --git a/client/modules/config/index.js b/client/modules/config/index.js index 759ea85d..b0ec5187 100644 --- a/client/modules/config/index.js +++ b/client/modules/config/index.js @@ -8,7 +8,7 @@ const currify = require('currify'); const wraptile = require('wraptile'); const squad = require('squad'); const {promisify} = require('es6-promisify'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const load = require('load.js'); const createElement = require('@cloudcmd/create-element'); diff --git a/client/modules/edit.js b/client/modules/edit.js index 441aaf62..85c8b433 100644 --- a/client/modules/edit.js +++ b/client/modules/edit.js @@ -5,7 +5,7 @@ const montag = require('montag'); const {promisify} = require('es6-promisify'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const createElement = require('@cloudcmd/create-element'); const load = require('load.js'); const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc'); diff --git a/client/modules/konsole.js b/client/modules/konsole.js index 6993380d..3de160fd 100644 --- a/client/modules/konsole.js +++ b/client/modules/konsole.js @@ -8,7 +8,7 @@ CloudCmd.Konsole = exports; const exec = require('execon'); const currify = require('currify'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const loadJS = require('load.js').js; const createElement = require('@cloudcmd/create-element'); diff --git a/client/modules/operation/index.js b/client/modules/operation/index.js index bf19bda8..3cce60d8 100644 --- a/client/modules/operation/index.js +++ b/client/modules/operation/index.js @@ -10,7 +10,7 @@ const wraptile = require('wraptile'); const {promisify} = require('es6-promisify'); const exec = require('execon'); const load = require('load.js'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const {encode} = require('../../../common/entity'); const removeExtension = require('./remove-extension'); diff --git a/client/modules/operation/remove-extension.js b/client/modules/operation/remove-extension.js index a8389af3..5e98727d 100644 --- a/client/modules/operation/remove-extension.js +++ b/client/modules/operation/remove-extension.js @@ -9,10 +9,10 @@ module.exports = (name) => { }; function getExtension(name) { - if (/\.tar\.gz$/.test(name)) + if (name.endsWith('.tar.gz')) return '.tar.gz'; - if (/\.tar\.bz2$/.test(name)) + if (name.endsWith('.tar.bz2')) return '.tar.bz2'; return getExt(name); diff --git a/client/modules/terminal-run.js b/client/modules/terminal-run.js index 3e4b857d..1faf17e2 100644 --- a/client/modules/terminal-run.js +++ b/client/modules/terminal-run.js @@ -2,7 +2,7 @@ /* global CloudCmd, gritty */ const {promisify} = require('es6-promisify'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const fullstore = require('fullstore'); require('../../css/terminal.css'); diff --git a/client/modules/terminal.js b/client/modules/terminal.js index d36b700a..d7099d87 100644 --- a/client/modules/terminal.js +++ b/client/modules/terminal.js @@ -2,7 +2,7 @@ /* global CloudCmd */ /* global gritty */ -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); require('../../css/terminal.css'); diff --git a/client/modules/user-menu/index.js b/client/modules/user-menu/index.js index 47fbee39..1a348cdc 100644 --- a/client/modules/user-menu/index.js +++ b/client/modules/user-menu/index.js @@ -8,8 +8,8 @@ const wraptile = require('wraptile'); const fullstore = require('fullstore'); const load = require('load.js'); const createElement = require('@cloudcmd/create-element'); -const tryCatch = require('try-catch'); -const tryToCatch = require('try-to-catch'); +const {tryCatch} = require('try-catch'); +const {tryToCatch} = require('try-to-catch'); const {codeFrameColumns} = require('@babel/code-frame'); const Images = require('../../dom/images'); diff --git a/client/modules/view/get-type.js b/client/modules/view/get-type.js index 3ac092e0..9fc1df1d 100644 --- a/client/modules/view/get-type.js +++ b/client/modules/view/get-type.js @@ -5,7 +5,7 @@ const testRegExp = currify((name, reg) => reg.test(name)); const getRegExp = (ext) => RegExp(`\\.${ext}$`, 'i'); const isPDF = (a) => /\.pdf$/i.test(a); -const isHTML = (a) => /\.html$/.test(a); +const isHTML = (a) => a.endsWith('.html'); const isMarkdown = (a) => /.\.md$/.test(a); module.exports = (name) => { diff --git a/client/modules/view/index.js b/client/modules/view/index.js index c6d34d18..3959e21d 100644 --- a/client/modules/view/index.js +++ b/client/modules/view/index.js @@ -7,7 +7,7 @@ require('../../../css/view.css'); const rendy = require('rendy'); const currify = require('currify'); const wraptile = require('wraptile'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const load = require('load.js'); const modal = require('@cloudcmd/modal'); diff --git a/client/modules/view/types.js b/client/modules/view/types.js index e36fec4d..d94dd971 100644 --- a/client/modules/view/types.js +++ b/client/modules/view/types.js @@ -7,7 +7,7 @@ const testRegExp = currify((name, reg) => reg.test(name)); const getRegExp = (ext) => RegExp(`\\.${ext}$`, 'i'); const isPDF = (a) => /\.pdf$/i.test(a); -const isHTML = (a) => /\.html$/.test(a); +const isHTML = (a) => a.endsWith('.html'); const isMarkdown = (a) => /.\.md$/.test(a); module.exports.getType = async (path) => { diff --git a/client/sw/register.js b/client/sw/register.js index 12431a82..0e6db472 100644 --- a/client/sw/register.js +++ b/client/sw/register.js @@ -1,6 +1,6 @@ 'use strict'; -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); module.exports.registerSW = registerSW; module.exports.unregisterSW = unregisterSW; diff --git a/client/sw/register.spec.js b/client/sw/register.spec.js index c4368c94..903fef77 100644 --- a/client/sw/register.spec.js +++ b/client/sw/register.spec.js @@ -5,7 +5,7 @@ const tape = require('supertape'); const stub = require('@cloudcmd/stub'); -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const {reRequire} = require('mock-require'); const test = autoGlobals(tape); diff --git a/client/sw/sw.js b/client/sw/sw.js index 15f3e0ad..b2f66429 100644 --- a/client/sw/sw.js +++ b/client/sw/sw.js @@ -2,7 +2,7 @@ const process = require('node:process'); const codegen = require('codegen.macro'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const currify = require('currify'); const isDev = process.env.NODE_ENV === 'development'; diff --git a/common/base64.spec.js b/common/base64.spec.js index cc096ee2..cf34d540 100644 --- a/common/base64.spec.js +++ b/common/base64.spec.js @@ -1,20 +1,19 @@ 'use strict'; const {test, stub} = require('supertape'); - const {btoa, atob} = require('./base64'); test('btoa: browser', (t) => { - const btoaOriginal = global.btoa; + const btoaOriginal = globalThis.btoa; const btoaStub = stub(); const str = 'hello'; - global.btoa = btoaStub; + globalThis.btoa = btoaStub; btoa(str); - global.btoa = btoaOriginal; + globalThis.btoa = btoaOriginal; - t.calledWith(btoaStub, [str], 'should call global.btoa'); + t.calledWith(btoaStub, [str], 'should call globalThis.btoa'); t.end(); }); @@ -29,18 +28,18 @@ test('btoa: node', (t) => { }); test('atob: browser', (t) => { - const atobOriginal = global.atob; + const atobOriginal = globalThis.atob; const atobStub = stub(); const str = 'hello'; - global.atob = atobStub; + globalThis.atob = atobStub; atob(str); - global.atob = atobOriginal; + globalThis.atob = atobOriginal; - t.calledWith(atobStub, [str], 'should call global.btoa'); + t.calledWith(atobStub, [str], 'should call globalThis.btoa'); t.end(); }); diff --git a/common/callbackify.spec.js b/common/callbackify.spec.js index 1b742169..0a46d9e9 100644 --- a/common/callbackify.spec.js +++ b/common/callbackify.spec.js @@ -1,7 +1,7 @@ 'use strict'; const {promisify} = require('node:util'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const {test, stub} = require('supertape'); diff --git a/common/datetime.spec.js b/common/datetime.spec.js index db7a2483..cc321d8a 100644 --- a/common/datetime.spec.js +++ b/common/datetime.spec.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('supertape'); -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const datetime = require('./datetime'); @@ -16,11 +16,11 @@ test('common: datetime', (t) => { }); test('common: datetime: no arg', (t) => { - const {Date} = global; + const {Date} = globalThis; let called = false; - global.Date = class extends Date { + globalThis.Date = class extends Date { constructor() { super(); called = true; @@ -29,7 +29,7 @@ test('common: datetime: no arg', (t) => { datetime(); - global.Date = Date; + globalThis.Date = Date; t.ok(called, 'should call new Date'); t.end(); diff --git a/common/try-to-promise-all.js b/common/try-to-promise-all.js index 5c91b026..e839d27e 100644 --- a/common/try-to-promise-all.js +++ b/common/try-to-promise-all.js @@ -1,6 +1,6 @@ 'use strict'; -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const all = Promise.all.bind(Promise); module.exports = async (a) => { diff --git a/common/util.spec.js b/common/util.spec.js index ed15bd09..f035f392 100644 --- a/common/util.spec.js +++ b/common/util.spec.js @@ -2,7 +2,7 @@ const test = require('supertape'); const {reRequire} = require('mock-require'); -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const Util = require('./util'); const { @@ -119,13 +119,13 @@ test('util: escapeRegExp', (t) => { }); test('util: scope', (t) => { - global.window = {}; + globalThis.window = {}; reRequire('./util'); t.pass('should set window in scope'); - delete global.window; + delete globalThis.window; t.end(); }); diff --git a/server/config.js b/server/config.js index 3b180f09..1c7a3839 100644 --- a/server/config.js +++ b/server/config.js @@ -11,13 +11,13 @@ const {homedir} = require('node:os'); const currify = require('currify'); const wraptile = require('wraptile'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const pullout = require('pullout'); const ponse = require('ponse'); const jonny = require('jonny'); const jju = require('jju'); const writejson = require('writejson'); -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const criton = require('criton'); const exit = require(`${DIR_SERVER}exit`); diff --git a/server/distribute/import.spec.mjs b/server/distribute/import.spec.mjs index 9823aaff..35b0dd6c 100644 --- a/server/distribute/import.spec.mjs +++ b/server/distribute/import.spec.mjs @@ -1,7 +1,7 @@ import process from 'node:process'; import {promisify} from 'node:util'; import test from 'supertape'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import {connect} from '../../test/before.mjs'; import {createConfigManager} from '../cloudcmd.mjs'; import {distributeImport} from './import.mjs'; diff --git a/server/markdown/index.spec.mjs b/server/markdown/index.spec.mjs index 2f51262e..563442af 100644 --- a/server/markdown/index.spec.mjs +++ b/server/markdown/index.spec.mjs @@ -1,7 +1,7 @@ import fs from 'node:fs'; import {join} from 'node:path'; import {promisify} from 'node:util'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import test from 'supertape'; import serveOnce from 'serve-once'; import markdown from './index.js'; diff --git a/server/rest/index.spec.js b/server/rest/index.spec.js index 84da6a71..9ce836ef 100644 --- a/server/rest/index.spec.js +++ b/server/rest/index.spec.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('supertape'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const { _formatMsg, diff --git a/server/route.mjs b/server/route.mjs index 675a0b7a..ce7671b4 100644 --- a/server/route.mjs +++ b/server/route.mjs @@ -6,7 +6,7 @@ import rendy from 'rendy'; import format from 'format-io'; import currify from 'currify'; import wraptile from 'wraptile'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import once from 'once'; import pipe from 'pipe-io'; import {contentType} from 'mime-types'; diff --git a/server/route.spec.mjs b/server/route.spec.mjs index 433e0cdc..bee216a8 100644 --- a/server/route.spec.mjs +++ b/server/route.spec.mjs @@ -2,7 +2,7 @@ import path, {dirname} from 'node:path'; import {fileURLToPath} from 'node:url'; import {Readable} from 'node:stream'; import fs from 'node:fs'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import {test, stub} from 'supertape'; import serveOnce from 'serve-once'; import cloudcmd from './cloudcmd.mjs'; diff --git a/server/server.mjs b/server/server.mjs index 096f9f40..dc61f522 100644 --- a/server/server.mjs +++ b/server/server.mjs @@ -3,7 +3,7 @@ import {promisify} from 'node:util'; import process from 'node:process'; import currify from 'currify'; import squad from 'squad'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import opn from 'open'; import express from 'express'; import {Server} from 'socket.io'; diff --git a/server/terminal.js b/server/terminal.js index 67613f0a..918ad1c4 100644 --- a/server/terminal.js +++ b/server/terminal.js @@ -1,6 +1,6 @@ 'use strict'; -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const noop = (req, res, next) => { next && next(); diff --git a/server/user-menu.mjs b/server/user-menu.mjs index 1100e1f3..4eaa3a8c 100644 --- a/server/user-menu.mjs +++ b/server/user-menu.mjs @@ -2,7 +2,7 @@ import {homedir} from 'node:os'; import {readFile as _readFile} from 'node:fs/promises'; import {join} from 'node:path'; import montag from 'montag'; -import tryToCatch from 'try-to-catch'; +import {tryToCatch} from 'try-to-catch'; import currify from 'currify'; import {putout, codeframe} from 'putout'; diff --git a/server/validate.mjs b/server/validate.mjs index 4694ca16..3699d081 100644 --- a/server/validate.mjs +++ b/server/validate.mjs @@ -1,5 +1,5 @@ import {statSync as _statSync} from 'node:fs'; -import tryCatch from 'try-catch'; +import {tryCatch} from 'try-catch'; import _exit from './exit.js'; import {getColumns as _getColumns} from './columns.mjs'; import {getThemes as _getThemes} from './theme.mjs'; diff --git a/server/validate.spec.mjs b/server/validate.spec.mjs index 800b4395..568e55c2 100644 --- a/server/validate.spec.mjs +++ b/server/validate.spec.mjs @@ -1,5 +1,5 @@ import {test, stub} from 'supertape'; -import tryCatch from 'try-catch'; +import {tryCatch} from 'try-catch'; import * as validate from './validate.mjs'; import cloudcmd from './cloudcmd.mjs'; diff --git a/static/user-menu.spec.js b/static/user-menu.spec.js index 9c42302a..7593ce77 100644 --- a/static/user-menu.spec.js +++ b/static/user-menu.spec.js @@ -2,7 +2,7 @@ const autoGlobals = require('auto-globals'); const stub = require('@cloudcmd/stub'); -const tryToCatch = require('try-to-catch'); +const {tryToCatch} = require('try-to-catch'); const wraptile = require('wraptile'); const defaultMenu = require('./user-menu'); diff --git a/test/common/cloudfunc.js b/test/common/cloudfunc.js index b74016fb..37c56c89 100644 --- a/test/common/cloudfunc.js +++ b/test/common/cloudfunc.js @@ -2,7 +2,7 @@ const fs = require('node:fs'); -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const test = require('supertape'); const readFilesSync = require('@cloudcmd/read-files-sync'); diff --git a/test/server/show-config.js b/test/server/show-config.js index 3de1c170..d0f3c8f6 100644 --- a/test/server/show-config.js +++ b/test/server/show-config.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('supertape'); -const tryCatch = require('try-catch'); +const {tryCatch} = require('try-catch'); const showConfig = require('../../server/show-config'); diff --git a/test/static.mjs b/test/static.mjs index 8d65c384..03a57e35 100644 --- a/test/static.mjs +++ b/test/static.mjs @@ -1,3 +1,4 @@ +import {Buffer} from 'node:buffer'; import serveOnce from 'serve-once'; import test from 'supertape'; import criton from 'criton';