From ebabad948f7a6dff127572e06d23d8da71b945db Mon Sep 17 00:00:00 2001 From: coderiaser Date: Mon, 2 Feb 2026 22:21:24 +0200 Subject: [PATCH] feature: common: entity: migrate to ESM --- client/dom/current-file.mjs | 2 +- client/dom/rest.mjs | 2 +- client/modules/config/index.mjs | 2 +- client/modules/operation/index.mjs | 26 ++++---- client/modules/user-menu/index.mjs | 2 +- client/modules/view/index.mjs | 4 +- common/cloudfunc.mjs | 73 +++++++++++----------- common/{entity.js => entity.mjs} | 7 +-- common/{entity.spec.js => entity.spec.mjs} | 6 +- package.json | 3 +- 10 files changed, 61 insertions(+), 66 deletions(-) rename common/{entity.js => entity.mjs} (81%) rename common/{entity.spec.js => entity.spec.mjs} (87%) diff --git a/client/dom/current-file.mjs b/client/dom/current-file.mjs index 9c84a7ff..2239c991 100644 --- a/client/dom/current-file.mjs +++ b/client/dom/current-file.mjs @@ -2,7 +2,7 @@ /* global CloudCmd */ import createElement from '@cloudcmd/create-element'; import {getTitle, FS} from '#common/cloudfunc'; -import {encode, decode} from '../../common/entity.js'; +import {encode, decode} from '#common/entity'; let Title; diff --git a/client/dom/rest.mjs b/client/dom/rest.mjs index 2912621b..75562419 100644 --- a/client/dom/rest.mjs +++ b/client/dom/rest.mjs @@ -1,7 +1,7 @@ import {tryToCatch} from 'try-to-catch'; import * as Dialog from '#dom/dialog'; -import {encode} from '../../common/entity.js'; import * as Images from '#dom/images'; +import {encode} from '#common/entity'; import IO from './io/index.js'; const handleError = (promise) => async (...args) => { diff --git a/client/modules/config/index.mjs b/client/modules/config/index.mjs index 33af1d44..115e477e 100644 --- a/client/modules/config/index.mjs +++ b/client/modules/config/index.mjs @@ -11,8 +11,8 @@ import createElement from '@cloudcmd/create-element'; import * as Events from '#dom/events'; import * as Files from '#dom/files'; import {getTitle} from '#common/cloudfunc'; -import * as input from './input.mjs'; import * as Images from '#dom/images'; +import * as input from './input.mjs'; const {Dialog, setTitle} = DOM; diff --git a/client/modules/operation/index.mjs b/client/modules/operation/index.mjs index a2e7c0e7..4ee9f6f8 100644 --- a/client/modules/operation/index.mjs +++ b/client/modules/operation/index.mjs @@ -4,7 +4,7 @@ import {promisify} from 'es6-promisify'; import exec from 'execon'; import load from 'load.js'; import {tryToCatch} from 'try-to-catch'; -import {encode} from '../../../common/entity.js'; +import {encode} from '#common/entity'; import {removeExtension} from './remove-extension.mjs'; import {setListeners} from './set-listeners.mjs'; import {getNextCurrentName} from './get-next-current-name.mjs'; @@ -51,19 +51,19 @@ export const init = promisify((callback) => { exec.series([ DOM.loadSocket, async (callback) => { - if (config('dropbox')) - return callback(); - - const {prefix, prefixSocket} = CloudCmd; - - await loadAll(); - await initOperations(prefix, prefixSocket, callback); - }, + if (config('dropbox')) + return callback(); + + const {prefix, prefixSocket} = CloudCmd; + + await loadAll(); + await initOperations(prefix, prefixSocket, callback); + }, (callback) => { - Loaded = true; - Images.hide(); - callback(); - }, + Loaded = true; + Images.hide(); + callback(); + }, ], callback); }); diff --git a/client/modules/user-menu/index.mjs b/client/modules/user-menu/index.mjs index 8cb50905..0be4d123 100644 --- a/client/modules/user-menu/index.mjs +++ b/client/modules/user-menu/index.mjs @@ -1,4 +1,5 @@ /* global CloudCmd, DOM */ +import '../../../css/user-menu.css'; import currify from 'currify'; import wraptile from 'wraptile'; import {fullstore} from 'fullstore'; @@ -8,7 +9,6 @@ import {tryCatch} from 'try-catch'; import {tryToCatch} from 'try-to-catch'; import {codeFrameColumns} from '@babel/code-frame'; import * as Dialog from '#dom/dialog'; -import '../../../css/user-menu.css'; import * as Images from '#dom/images'; import {getUserMenu} from './get-user-menu.mjs'; import {navigate} from './navigate.mjs'; diff --git a/client/modules/view/index.mjs b/client/modules/view/index.mjs index aa0f6f3d..c843765c 100644 --- a/client/modules/view/index.mjs +++ b/client/modules/view/index.mjs @@ -10,13 +10,13 @@ import {time} from '#common/util'; import * as Files from '#dom/files'; import * as Events from '#dom/events'; import {FS} from '#common/cloudfunc'; +import * as Images from '#dom/images'; import { isImage, isAudio, getType, } from './types.mjs'; -import * as Images from '#dom/images'; -import {encode} from '../../../common/entity.js'; +import {encode} from '#common/entity'; const CloudCmd = globalThis.CloudCmd || {}; const DOM = globalThis.DOM || {}; diff --git a/common/cloudfunc.mjs b/common/cloudfunc.mjs index 00a48360..fa1ca806 100644 --- a/common/cloudfunc.mjs +++ b/common/cloudfunc.mjs @@ -1,7 +1,7 @@ import rendy from 'rendy'; import currify from 'currify'; import store from 'fullstore'; -import {encode} from './entity.js'; +import {encode} from '#common/entity'; export const getHeaderField = currify(_getHeaderField); @@ -168,7 +168,6 @@ export const buildFromJSON = (params) => { Path(path); fileTable += `${header}'; diff --git a/common/entity.js b/common/entity.mjs similarity index 81% rename from common/entity.js rename to common/entity.mjs index d6eeaa23..d8f4a214 100644 --- a/common/entity.js +++ b/common/entity.mjs @@ -1,7 +1,4 @@ -'use strict'; - const Entities = { - // ' ': ' ', '<': '<', '>': '>', '"': '"', @@ -9,7 +6,7 @@ const Entities = { const keys = Object.keys(Entities); -module.exports.encode = (str) => { +export const encode = (str) => { for (const code of keys) { const char = Entities[code]; const reg = RegExp(char, 'g'); @@ -20,7 +17,7 @@ module.exports.encode = (str) => { return str; }; -module.exports.decode = (str) => { +export const decode = (str) => { for (const code of keys) { const char = Entities[code]; const reg = RegExp(code, 'g'); diff --git a/common/entity.spec.js b/common/entity.spec.mjs similarity index 87% rename from common/entity.spec.js rename to common/entity.spec.mjs index e555cc0d..ca62d705 100644 --- a/common/entity.spec.js +++ b/common/entity.spec.mjs @@ -1,7 +1,5 @@ -'use strict'; - -const {test} = require('supertape'); -const entity = require('./entity'); +import {test} from 'supertape'; +import * as entity from '#common/entity'; test('cloudcmd: entity: encode', (t) => { const result = entity.encode(' '); diff --git a/package.json b/package.json index 9a937adc..e941fbc0 100644 --- a/package.json +++ b/package.json @@ -230,7 +230,8 @@ "#dom/storage": "./client/dom/storage.mjs", "#dom/rest": "./client/dom/rest.mjs", "#common/util": "./common/util.mjs", - "#common/cloudfunc": "./common/cloudfunc.mjs" + "#common/cloudfunc": "./common/cloudfunc.mjs", + "#common/entity": "./common/entity.mjs" }, "engines": { "node": ">=22"