From dfcbfd632e0c91f09a88484572c999974e525e2f Mon Sep 17 00:00:00 2001 From: coderiaser Date: Tue, 3 Feb 2026 00:36:00 +0200 Subject: [PATCH] feature: client: modules: terminal: migrate to ESM --- .webpack/js.mjs | 2 +- client/cloudcmd.mjs | 2 +- client/dom/index.spec.mjs | 2 +- client/modules/terminal-run.js | 2 +- client/modules/{terminal.js => terminal.mjs} | 43 +++++++++----------- client/sort.mjs | 2 +- package.json | 1 + 7 files changed, 26 insertions(+), 28 deletions(-) rename client/modules/{terminal.js => terminal.mjs} (78%) diff --git a/.webpack/js.mjs b/.webpack/js.mjs index 52352df7..ee5a29f6 100644 --- a/.webpack/js.mjs +++ b/.webpack/js.mjs @@ -133,7 +133,7 @@ export default { [`${modules}/upload`]: `${dirModules}/upload.mjs`, [`${modules}/operation`]: `${dirModules}/operation/index.mjs`, [`${modules}/konsole`]: `${dirModules}/konsole.mjs`, - [`${modules}/terminal`]: `${dirModules}/terminal.js`, + [`${modules}/terminal`]: `${dirModules}/terminal.mjs`, [`${modules}/terminal-run`]: `${dirModules}/terminal-run.js`, [`${modules}/cloud`]: `${dirModules}/cloud.mjs`, [`${modules}/user-menu`]: `${dirModules}/user-menu/index.mjs`, diff --git a/client/cloudcmd.mjs b/client/cloudcmd.mjs index de7d3a93..746f7e74 100644 --- a/client/cloudcmd.mjs +++ b/client/cloudcmd.mjs @@ -6,7 +6,7 @@ import * as Util from '#common/util'; import * as CloudFunc from '#common/cloudfunc'; import {registerSW, listenSW} from './sw/register.mjs'; import {initSortPanel, sortPanel} from './sort.mjs'; -import DOM from './dom/index.mjs'; +import DOM from '#dom'; import {createCloudCmd} from './client.mjs'; import * as Listeners from './listeners/index.mjs'; diff --git a/client/dom/index.spec.mjs b/client/dom/index.spec.mjs index fb4de9e4..268efe5f 100644 --- a/client/dom/index.spec.mjs +++ b/client/dom/index.spec.mjs @@ -1,5 +1,5 @@ import {test, stub} from 'supertape'; -import {getCSSVar, goToDirectory} from './index.mjs'; +import {getCSSVar, goToDirectory} from '#dom'; globalThis.CloudCmd = {}; diff --git a/client/modules/terminal-run.js b/client/modules/terminal-run.js index 6daf3fd6..0f96c20c 100644 --- a/client/modules/terminal-run.js +++ b/client/modules/terminal-run.js @@ -9,7 +9,7 @@ require('../../css/terminal.css'); const exec = require('execon'); const load = require('load.js'); -const DOM = require('../dom/index.mjs'); +const DOM = require('#dom'); const Images = require('#dom/images'); const {Dialog} = DOM; diff --git a/client/modules/terminal.js b/client/modules/terminal.mjs similarity index 78% rename from client/modules/terminal.js rename to client/modules/terminal.mjs index a57c9145..186ee0b2 100644 --- a/client/modules/terminal.js +++ b/client/modules/terminal.mjs @@ -1,22 +1,22 @@ -'use strict'; - -/* global CloudCmd */ -/* global gritty */ -const {tryToCatch} = require('try-to-catch'); - -require('../../css/terminal.css'); - -const exec = require('execon'); -const load = require('load.js'); -const DOM = require('../dom/index.mjs'); -const Images = require('#dom/images'); +import '#css/terminal.css'; +import {tryToCatch} from 'try-to-catch'; +import exec from 'execon'; +import load from 'load.js'; +import * as Images from '#dom/images'; +import DOM from '#dom'; const loadParallel = load.parallel; -const {Dialog} = DOM; -const {Key, config} = CloudCmd; +const {CloudCmd} = globalThis; -CloudCmd.Terminal = exports; +const {Dialog} = DOM; +const {Key, config} = globalThis.CloudCmd; + +CloudCmd.Terminal = { + init, + show, + hide, +}; let Loaded; let Terminal; @@ -39,7 +39,7 @@ const loadAll = async () => { Loaded = true; }; -module.exports.init = async () => { +export async function init() { if (!config('terminal')) return; @@ -48,12 +48,9 @@ module.exports.init = async () => { await CloudCmd.View(); await loadAll(); create(); -}; +} -module.exports.show = show; -module.exports.hide = hide; - -function hide() { +export function hide() { CloudCmd.View.hide(); } @@ -78,7 +75,7 @@ function create() { fontFamily: 'Droid Sans Mono', }; - const {socket, terminal} = gritty(document.body, options); + const {socket, terminal} = globalThis.gritty(document.body, options); Socket = socket; Terminal = terminal; @@ -101,7 +98,7 @@ function authCheck(spawn) { }); } -function show() { +export function show() { if (!Loaded) return; diff --git a/client/sort.mjs b/client/sort.mjs index 8ac12452..ed0971f3 100644 --- a/client/sort.mjs +++ b/client/sort.mjs @@ -1,6 +1,6 @@ /* global CloudCmd */ import {fullstore} from 'fullstore'; -import DOM from './dom/index.mjs'; +import DOM from '#dom'; const sortPrevious = fullstore(); diff --git a/package.json b/package.json index 3fd81953..b2e28692 100644 --- a/package.json +++ b/package.json @@ -221,6 +221,7 @@ }, "imports": { "#css/": "./css/", + "#dom": "./client/dom/index.mjs", "#dom/events": "./client/dom/events/index.mjs", "#dom/load": "./client/dom/load.mjs", "#dom/dialog": "./client/dom/dialog.mjs",