feature: client: dom: load-remote: migrate to ESM

This commit is contained in:
coderiaser 2026-01-29 18:46:43 +02:00
parent 145bc48722
commit 0054cfa363
7 changed files with 62 additions and 59 deletions

View file

@ -57,6 +57,7 @@ export default {
'watch:test:client': async () => `nodemon -w client -w test/client -x ${await run('test:client')}`, '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: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: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': async () => run('6to5:*'),
'build:dev': async () => run('build:client:dev'), 'build:dev': async () => run('build:client:dev'),
'build:client': () => run('6to5:client'), 'build:client': () => run('6to5:client'),

View file

@ -1,2 +1,2 @@
[files] [files]
extend-exclude= ["ChangeLog"] extend-exclude = ["ChangeLog"]

View file

@ -53,6 +53,9 @@ const plugins = [
NODE_ENV, NODE_ENV,
}), }),
new WebpackBar(), new WebpackBar(),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
]; ];
const splitChunks = { const splitChunks = {
@ -96,6 +99,7 @@ export default {
fallback: { fallback: {
path: import.meta.resolve('path-browserify'), path: import.meta.resolve('path-browserify'),
process: import.meta.resolve('process/browser'), process: import.meta.resolve('process/browser'),
util: import.meta.resolve('util'),
}, },
}, },
devtool, devtool,

View file

@ -5,8 +5,8 @@ import * as Dialog from '#dom/dialog';
import * as Events from '#dom/events'; import * as Events from '#dom/events';
import {getExt} from '#common/util'; import {getExt} from '#common/util';
import * as Storage from '#dom/storage'; import * as Storage from '#dom/storage';
import * as Images from './images.mjs';
import * as RESTful from '#dom/rest'; import * as RESTful from '#dom/rest';
import * as Images from './images.mjs';
import renameCurrent from './operations/rename-current.js'; import renameCurrent from './operations/rename-current.js';
import * as CurrentFile from './current-file.mjs'; import * as CurrentFile from './current-file.mjs';
import * as DOMTree from './dom-tree.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 IO from './io/index.js';
import {uploadDirectory} from './directory.mjs'; import {uploadDirectory} from './directory.mjs';
import * as Buffer from './buffer.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'; import {selectByPattern} from './select-by-pattern.mjs';
const {assign} = Object; const {assign} = Object;

View file

@ -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);
});
};

View file

@ -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);
});

View file

@ -72,6 +72,7 @@
"watch:test:client": "madrun watch:test:client", "watch:test:client": "madrun watch:test:client",
"watch:test:server": "madrun watch:test:server", "watch:test:server": "madrun watch:test:server",
"watch:coverage": "madrun watch:coverage", "watch:coverage": "madrun watch:coverage",
"watch:fix:lint": "madrun watch:fix:lint",
"build": "madrun build", "build": "madrun build",
"build:dev": "madrun build:dev", "build:dev": "madrun build:dev",
"build:client": "madrun build:client", "build:client": "madrun build:client",
@ -212,6 +213,7 @@
"tar-stream": "^3.0.0", "tar-stream": "^3.0.0",
"unionfs": "^4.0.0", "unionfs": "^4.0.0",
"url-loader": "^4.0.0", "url-loader": "^4.0.0",
"util": "^0.12.5",
"webpack": "^5.99.9", "webpack": "^5.99.9",
"webpack-cli": "^6.0.1", "webpack-cli": "^6.0.1",
"webpack-merge": "^6.0.1", "webpack-merge": "^6.0.1",