From 3bdf47a5bb56fa2bf5ec643b884e9f58f70c8d81 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Sat, 17 Jan 2026 13:50:26 +0200 Subject: [PATCH] feature: client: migrate to ESM --- client/{client.js => client.mjs} | 46 ++++++++++++++----------------- client/cloudcmd.js | 22 +++++++++------ client/key/index.js | 2 +- client/key/set-current-by-char.js | 2 +- 4 files changed, 36 insertions(+), 36 deletions(-) rename client/{client.js => client.mjs} (93%) diff --git a/client/client.js b/client/client.mjs similarity index 93% rename from client/client.js rename to client/client.mjs index 529b904b..daf55ca5 100644 --- a/client/client.js +++ b/client/client.mjs @@ -1,30 +1,24 @@ -'use strict'; - -const process = require('node:process'); +import process from 'node:process'; /* global DOM */ -const Emitify = require('emitify'); -const inherits = require('inherits'); -const rendy = require('rendy'); -const load = require('load.js'); -const {tryToCatch} = require('try-to-catch'); -const {addSlashToEnd} = require('format-io'); -const pascalCase = require('just-pascal-case'); -const currify = require('currify'); - -const Images = require('./dom/images'); - -const {unregisterSW} = require('./sw/register'); -const {getJsonFromFileTable} = require('./get-json-from-file-table.mjs'); -const Key = require('./key'); - -const { +import Emitify from 'emitify'; +import inherits from 'inherits'; +import rendy from 'rendy'; +import load from 'load.js'; +import {tryToCatch} from 'try-to-catch'; +import {addSlashToEnd} from 'format-io'; +import pascalCase from 'just-pascal-case'; +import currify from 'currify'; +import Images from './dom/images.js'; +import {unregisterSW} from './sw/register.js'; +import {getJsonFromFileTable} from './get-json-from-file-table.mjs'; +import Key from './key/index.js'; +import { apiURL, formatMsg, buildFromJSON, -} = require('../common/cloudfunc.mjs'); - -const {loadModule} = require('./load-module.mjs'); +} from '../common/cloudfunc.mjs'; +import {loadModule} from './load-module.mjs'; const noJS = (a) => a.replace(/.js$/, ''); @@ -32,7 +26,9 @@ const isDev = process.env.NODE_ENV === 'development'; inherits(CloudCmdProto, Emitify); -module.exports = new CloudCmdProto(DOM); +export const createCloudCmd = (DOM) => { + return new CloudCmdProto(DOM); +}; load.addErrorListener((e, src) => { const msg = `file ${src} could not be loaded`; @@ -49,11 +45,9 @@ function CloudCmdProto(DOM) { const {Storage, Files} = DOM; - this.log = (...a) => { + this.log = () => { if (!isDev) return; - - console.log(...a); }; this.prefix = ''; this.prefixSocket = ''; diff --git a/client/cloudcmd.js b/client/cloudcmd.js index 8c3de848..32b3bc1a 100644 --- a/client/cloudcmd.js +++ b/client/cloudcmd.js @@ -8,15 +8,20 @@ const load = require('load.js'); const {registerSW, listenSW} = require('./sw/register'); const {initSortPanel, sortPanel} = require('./sort.mjs'); +const Util = require('../common/util'); +const CloudFunc = require('../common/cloudfunc.mjs'); +const DOM = require('./dom'); +const {createCloudCmd} = require('./client.mjs'); const isDev = process.env.NODE_ENV === 'development'; -module.exports = async (config) => { - globalThis.Util = require('../common/util'); - globalThis.CloudFunc = require('../common/cloudfunc.mjs'); - - globalThis.DOM = require('./dom'); - globalThis.CloudCmd = require('./client'); +module.exports = init; + +async function init(config) { + globalThis.CloudCmd = createCloudCmd(DOM); + globalThis.DOM = DOM; + globalThis.Util = Util; + globalThis.CloudFunc = CloudFunc; await register(config); @@ -34,8 +39,9 @@ module.exports = async (config) => { import('https://esm.sh/@putout/processor-html'); import('https://esm.sh/@putout/bundle'); }, 100); -}; -globalThis.CloudCmd = module.exports; +} + +globalThis.CloudCmd = init; function getPrefix(prefix) { if (!prefix) diff --git a/client/key/index.js b/client/key/index.js index 3e8aeeab..df55f035 100644 --- a/client/key/index.js +++ b/client/key/index.js @@ -12,7 +12,6 @@ const _vim = require('./vim'); const setCurrentByChar = require('./set-current-by-char'); const {createBinder} = require('./binder'); -const Info = DOM.CurrentInfo; const Chars = fullstore(); const toggleVim = (keyCode, overrides = {}) => { @@ -124,6 +123,7 @@ function fromCharCode(keyIdentifier) { } async function _switchKey(event) { + const Info = DOM.CurrentInfo; let i; let isSelected; let prev; diff --git a/client/key/set-current-by-char.js b/client/key/set-current-by-char.js index f54881a3..ab9329f3 100644 --- a/client/key/set-current-by-char.js +++ b/client/key/set-current-by-char.js @@ -3,9 +3,9 @@ 'use strict'; const {escapeRegExp} = require('../../common/util'); -const Info = DOM.CurrentInfo; module.exports = function setCurrentByChar(char, charStore) { + const Info = DOM.CurrentInfo; let firstByName; let skipCount = 0; let setted = false;