feature: client: sw: register: migrate to ESM

This commit is contained in:
coderiaser 2026-01-27 13:41:21 +02:00
parent 5a16b018c5
commit 6b049d954b
7 changed files with 12 additions and 24 deletions

View file

@ -10,7 +10,7 @@ import {addSlashToEnd} from 'format-io';
import pascalCase from 'just-pascal-case';
import currify from 'currify';
import * as Images from './dom/images.mjs';
import {unregisterSW} from './sw/register.js';
import {unregisterSW} from './sw/register.mjs';
import {getJsonFromFileTable} from './get-json-from-file-table.mjs';
import {Key} from './key/index.mjs';
import {

View file

@ -2,7 +2,7 @@ import process from 'node:process';
import wraptile from 'wraptile';
import load from 'load.js';
import '../css/main.css';
import {registerSW, listenSW} from './sw/register.js';
import {registerSW, listenSW} from './sw/register.mjs';
import {initSortPanel, sortPanel} from './sort.mjs';
import Util from '../common/util.js';
import * as CloudFunc from '../common/cloudfunc.mjs';

View file

@ -8,4 +8,3 @@ export const getIndex = currify((array, item) => {
return index;
});

View file

@ -17,4 +17,3 @@ test('cloudcmd: client: listeners: getIndex: found', (t) => {
t.equal(getIndex(array, 'world'), 1, 'should return index');
t.end();
});

View file

@ -50,4 +50,3 @@ test('cloudcmd: client: listeners: getRange: one', (t) => {
t.deepEqual(result, expected, 'should return range');
t.end();
});

View file

@ -1,15 +1,10 @@
'use strict';
import {tryToCatch} from 'try-to-catch';
const {tryToCatch} = require('try-to-catch');
module.exports.registerSW = registerSW;
module.exports.unregisterSW = unregisterSW;
module.exports.listenSW = (sw, ...args) => {
export const listenSW = (sw, ...args) => {
sw?.addEventListener(...args);
};
async function registerSW(prefix) {
export async function registerSW(prefix) {
if (!navigator.serviceWorker)
return;
@ -29,7 +24,7 @@ async function registerSW(prefix) {
return sw;
}
async function unregisterSW(prefix) {
export async function unregisterSW(prefix) {
const reg = await registerSW(prefix);
reg?.unregister(prefix);
}

View file

@ -1,16 +1,12 @@
'use strict';
const autoGlobals = require('auto-globals');
const tape = require('supertape');
const {stub} = require('@cloudcmd/stub');
const {tryCatch} = require('try-catch');
const {
import autoGlobals from 'auto-globals';
import tape from 'supertape';
import {stub} from '@cloudcmd/stub';
import {tryCatch} from 'try-catch';
import {
listenSW,
registerSW,
unregisterSW,
} = require('./register');
} from './register.mjs';
const test = autoGlobals(tape);