From 0054cfa3633be3a1f262e2f59b2ef14d4b9ed868 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Thu, 29 Jan 2026 18:46:43 +0200 Subject: [PATCH] feature: client: dom: load-remote: migrate to ESM --- .madrun.mjs | 1 + .typos.toml | 2 +- .webpack/js.mjs | 4 +++ client/dom/index.mjs | 4 +-- client/dom/load-remote.js | 56 -------------------------------------- client/dom/load-remote.mjs | 52 +++++++++++++++++++++++++++++++++++ package.json | 2 ++ 7 files changed, 62 insertions(+), 59 deletions(-) delete mode 100644 client/dom/load-remote.js create mode 100644 client/dom/load-remote.mjs diff --git a/.madrun.mjs b/.madrun.mjs index 930d468b..733499f3 100644 --- a/.madrun.mjs +++ b/.madrun.mjs @@ -57,6 +57,7 @@ export default { 'watch:test:client': async () => `nodemon -w client -w test/client -x ${await run('test:client')}`, 'watch:test:server': async () => `nodemon -w client -w test/client -x ${await run('test:server')}`, 'watch:coverage': async () => [testEnv, `nodemon -w server -w test -w common -x ${await cutEnv('coverage')}`], + 'watch:fix:lint': async () => `nodemon -w client -w server -w test -w common -x '${await run('fix:lint')}'`, 'build': async () => run('6to5:*'), 'build:dev': async () => run('build:client:dev'), 'build:client': () => run('6to5:client'), diff --git a/.typos.toml b/.typos.toml index 3ad7d5ef..dc8af253 100644 --- a/.typos.toml +++ b/.typos.toml @@ -1,2 +1,2 @@ [files] -extend-exclude= ["ChangeLog"] +extend-exclude = ["ChangeLog"] diff --git a/.webpack/js.mjs b/.webpack/js.mjs index f67b120c..8063fbc4 100644 --- a/.webpack/js.mjs +++ b/.webpack/js.mjs @@ -53,6 +53,9 @@ const plugins = [ NODE_ENV, }), new WebpackBar(), + new webpack.ProvidePlugin({ + process: 'process/browser', + }), ]; const splitChunks = { @@ -96,6 +99,7 @@ export default { fallback: { path: import.meta.resolve('path-browserify'), process: import.meta.resolve('process/browser'), + util: import.meta.resolve('util'), }, }, devtool, diff --git a/client/dom/index.mjs b/client/dom/index.mjs index 9b4d23a0..471f3b7c 100644 --- a/client/dom/index.mjs +++ b/client/dom/index.mjs @@ -5,8 +5,8 @@ import * as Dialog from '#dom/dialog'; import * as Events from '#dom/events'; import {getExt} from '#common/util'; import * as Storage from '#dom/storage'; -import * as Images from './images.mjs'; import * as RESTful from '#dom/rest'; +import * as Images from './images.mjs'; import renameCurrent from './operations/rename-current.js'; import * as CurrentFile from './current-file.mjs'; import * as DOMTree from './dom-tree.mjs'; @@ -14,7 +14,7 @@ import * as Cmd from './cmd.mjs'; import IO from './io/index.js'; import {uploadDirectory} from './directory.mjs'; import * as Buffer from './buffer.mjs'; -import _loadRemote from './load-remote.js'; +import {loadRemote as _loadRemote} from './load-remote.mjs'; import {selectByPattern} from './select-by-pattern.mjs'; const {assign} = Object; diff --git a/client/dom/load-remote.js b/client/dom/load-remote.js deleted file mode 100644 index 77a7d244..00000000 --- a/client/dom/load-remote.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -/* global CloudCmd */ -const rendy = require('rendy'); -const itype = require('itype'); -const load = require('load.js'); -const {tryToCatch} = require('try-to-catch'); - -const {findObjByNameInArr} = require('#common/util'); - -const Files = require('#dom/files'); - -module.exports = (name, options, callback = options) => { - const {prefix, config} = CloudCmd; - const o = options; - - if (o.name && window[o.name]) - return callback(); - - Files.get('modules').then(async (modules) => { - const online = config('online') && navigator.onLine; - const module = findObjByNameInArr(modules.remote, name); - - const isArray = itype.array(module.local); - const {version} = module; - - let remoteTmpls; - let local; - - if (isArray) { - remoteTmpls = module.remote; - ({local} = module); - } else { - remoteTmpls = [module.remote]; - local = [module.local]; - } - - const localURL = local.map((url) => prefix + url); - - const remoteURL = remoteTmpls.map((tmpl) => { - return rendy(tmpl, { - version, - }); - }); - - if (online) { - const [e] = await tryToCatch(load.parallel, remoteURL); - - if (!e) - return callback(); - } - - const [e] = await tryToCatch(load.parallel, localURL); - callback(e); - }); -}; diff --git a/client/dom/load-remote.mjs b/client/dom/load-remote.mjs new file mode 100644 index 00000000..974763e0 --- /dev/null +++ b/client/dom/load-remote.mjs @@ -0,0 +1,52 @@ +/* global CloudCmd */ +import {callbackify} from 'node:util'; +import rendy from 'rendy'; +import itype from 'itype'; +import load from 'load.js'; +import {tryToCatch} from 'try-to-catch'; +import {findObjByNameInArr} from '#common/util'; +import * as Files from '#dom/files'; + +export const loadRemote = callbackify(async (name, options) => { + const {prefix, config} = CloudCmd; + const o = options; + + if (o.name && window[o.name]) + return; + + const modules = await Files.get('modules'); + + const online = config('online') && navigator.onLine; + const module = findObjByNameInArr(modules.remote, name); + + const isArray = itype.array(module.local); + const {version} = module; + + let remoteTmpls; + let local; + + if (isArray) { + remoteTmpls = module.remote; + ({local} = module); + } else { + remoteTmpls = [module.remote]; + local = [module.local]; + } + + const localURL = local.map((url) => prefix + url); + + const remoteURL = remoteTmpls.map((tmpl) => { + return rendy(tmpl, { + version, + }); + }); + + if (online) { + const [e] = await tryToCatch(load.parallel, remoteURL); + + if (!e) + return; + } + + await load.parallel(localURL); +}); diff --git a/package.json b/package.json index 4c3cb32a..83289da9 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "watch:test:client": "madrun watch:test:client", "watch:test:server": "madrun watch:test:server", "watch:coverage": "madrun watch:coverage", + "watch:fix:lint": "madrun watch:fix:lint", "build": "madrun build", "build:dev": "madrun build:dev", "build:client": "madrun build:client", @@ -212,6 +213,7 @@ "tar-stream": "^3.0.0", "unionfs": "^4.0.0", "url-loader": "^4.0.0", + "util": "^0.12.5", "webpack": "^5.99.9", "webpack-cli": "^6.0.1", "webpack-merge": "^6.0.1",