feature: client: migrate to ESM

This commit is contained in:
coderiaser 2026-02-03 13:35:24 +02:00
parent f8a941bdd9
commit 457c83dba9
7 changed files with 28 additions and 35 deletions

View file

@ -11,7 +11,7 @@ import renameCurrent from './operations/rename-current.mjs';
import * as CurrentFile from './current-file.mjs';
import * as DOMTree from './dom-tree.mjs';
import * as Cmd from './cmd.mjs';
import IO from './io/index.js';
import * as IO from './io/index.mjs';
import {uploadDirectory} from './directory.mjs';
import * as Buffer from './buffer.mjs';
import {loadRemote as _loadRemote} from './load-remote.mjs';

View file

@ -1,13 +1,11 @@
'use strict';
const {FS} = require('#common/cloudfunc');
const _sendRequest = require('./send-request');
import {FS} from '#common/cloudfunc';
import {sendRequest as _sendRequest} from './send-request.mjs';
const imgPosition = {
top: true,
};
module.exports.delete = async (url, data) => {
export const remove = async (url, data) => {
return await _sendRequest({
method: 'DELETE',
url: FS + url,
@ -18,7 +16,7 @@ module.exports.delete = async (url, data) => {
});
};
module.exports.patch = async (url, data) => {
export const patch = async (url, data) => {
return await _sendRequest({
method: 'PATCH',
url: FS + url,
@ -27,7 +25,7 @@ module.exports.patch = async (url, data) => {
});
};
module.exports.write = async (url, data) => {
export const write = async (url, data) => {
return await _sendRequest({
method: 'PUT',
url: FS + url,
@ -36,7 +34,7 @@ module.exports.write = async (url, data) => {
});
};
module.exports.createDirectory = async (url, overrides = {}) => {
export const createDirectory = async (url, overrides = {}) => {
const {
sendRequest = _sendRequest,
} = overrides;
@ -48,7 +46,7 @@ module.exports.createDirectory = async (url, overrides = {}) => {
});
};
module.exports.read = async (url, dataType = 'text') => {
export const read = async (url, dataType = 'text') => {
const notLog = !url.includes('?');
return await _sendRequest({
@ -59,7 +57,7 @@ module.exports.read = async (url, dataType = 'text') => {
});
};
module.exports.copy = async (from, to, names) => {
export const copy = async (from, to, names) => {
return await _sendRequest({
method: 'PUT',
url: '/copy',
@ -72,7 +70,7 @@ module.exports.copy = async (from, to, names) => {
});
};
module.exports.pack = async (data) => {
export const pack = async (data) => {
return await _sendRequest({
method: 'PUT',
url: '/pack',
@ -80,7 +78,7 @@ module.exports.pack = async (data) => {
});
};
module.exports.extract = async (data) => {
export const extract = async (data) => {
return await _sendRequest({
method: 'PUT',
url: '/extract',
@ -88,7 +86,7 @@ module.exports.extract = async (data) => {
});
};
module.exports.move = async (from, to, names) => {
export const move = async (from, to, names) => {
return await _sendRequest({
method: 'PUT',
url: '/move',
@ -101,7 +99,7 @@ module.exports.move = async (from, to, names) => {
});
};
module.exports.rename = async (from, to) => {
export const rename = async (from, to) => {
return await _sendRequest({
method: 'PUT',
url: '/rename',
@ -113,7 +111,7 @@ module.exports.rename = async (from, to) => {
});
};
module.exports.Config = {
export const Config = {
read: async () => {
return await _sendRequest({
method: 'GET',
@ -133,7 +131,7 @@ module.exports.Config = {
},
};
module.exports.Markdown = {
export const Markdown = {
read: async (url) => {
return await _sendRequest({
method: 'GET',

View file

@ -1,7 +1,5 @@
'use strict';
const {test, stub} = require('supertape');
const io = require('.');
import {test, stub} from 'supertape';
import * as io from './index.mjs';
test('client: dom: io', (t) => {
const sendRequest = stub();

View file

@ -1,12 +1,9 @@
'use strict';
/* global CloudCmd */
const {promisify} = require('es6-promisify');
import {promisify} from 'es6-promisify';
import * as Images from '#dom/images';
import * as load from '#dom/load';
const Images = require('#dom/images');
const load = require('#dom/load');
module.exports = promisify((params, callback) => {
export const sendRequest = promisify((params, callback) => {
const p = params;
const {prefixURL} = CloudCmd;
@ -40,7 +37,8 @@ module.exports = promisify((params, callback) => {
});
});
module.exports._replaceHash = replaceHash;
export const _replaceHash = replaceHash;
function replaceHash(url) {
/*
* if we send ajax request -

View file

@ -1,7 +1,5 @@
'use strict';
const {test} = require('supertape');
const {_replaceHash} = require('./send-request');
import {test} from 'supertape';
import {_replaceHash} from './send-request.mjs';
test('cloudcmd: client: io: replaceHash', (t) => {
const url = '/hello/####world';

View file

@ -2,7 +2,7 @@ import {tryToCatch} from 'try-to-catch';
import * as Dialog from '#dom/dialog';
import * as Images from '#dom/images';
import {encode} from '#common/entity';
import IO from './io/index.js';
import * as IO from './io/index.mjs';
const handleError = (promise) => async (...args) => {
const [e, data] = await tryToCatch(promise, ...args);
@ -18,7 +18,7 @@ const handleError = (promise) => async (...args) => {
return [e, data];
};
export const remove = handleError(IO.delete);
export const remove = handleError(IO.remove);
export const patch = handleError(IO.patch);
export const write = handleError(IO.write);
export const createDirectory = handleError(IO.createDirectory);

View file

@ -4,6 +4,7 @@ import {Markdown} from '#dom/rest';
import {alert} from '#dom/dialog';
const {CloudCmd} = globalThis;
CloudCmd.Markdown = {
init,
show,