mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature: client: sw: migrate to ESM
This commit is contained in:
parent
54c89e52f8
commit
27a52d33d0
7 changed files with 19 additions and 15 deletions
|
|
@ -11,6 +11,9 @@
|
|||
"package-json/add-type": "off"
|
||||
},
|
||||
"match": {
|
||||
".filesystem.json": {
|
||||
"nodejs/rename-file-cjs-to-js": "off"
|
||||
},
|
||||
"base64": {
|
||||
"types/convert-typeof-to-is-type": "off"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ const options = {
|
|||
|
||||
const rules = clean([
|
||||
!isDev && {
|
||||
test: /\.js$/,
|
||||
test: /\.[mc]?js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
},
|
||||
isDev && {
|
||||
test: /\.js$/,
|
||||
test: /\.[mc]?js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
options,
|
||||
|
|
@ -113,7 +113,7 @@ export default {
|
|||
'config': `${dirCss}/config.css`,
|
||||
'terminal': `${dirCss}/terminal.css`,
|
||||
'user-menu': `${dirCss}/user-menu.css`,
|
||||
'sw': `${dir}/sw/sw.js`,
|
||||
'sw': `${dir}/sw/sw.mjs`,
|
||||
'cloudcmd': `${dir}/cloudcmd.mjs`,
|
||||
[`${modules}/edit`]: `${dirModules}/edit.js`,
|
||||
[`${modules}/edit-file`]: `${dirModules}/edit-file.js`,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export async function registerSW(prefix) {
|
|||
|
||||
const {serviceWorker} = navigator;
|
||||
const register = serviceWorker.register.bind(serviceWorker);
|
||||
const [e, sw] = await tryToCatch(register, `${prefix}/sw.js`);
|
||||
const [e, sw] = await tryToCatch(register, `${prefix}/sw.mjs`);
|
||||
|
||||
if (e)
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ test('sw: register: registerSW', async (t, {location, navigator}) => {
|
|||
const {register} = navigator.serviceWorker;
|
||||
await registerSW('/hello');
|
||||
|
||||
t.calledWith(register, ['/hello/sw.js'], 'should call register');
|
||||
t.calledWith(register, ['/hello/sw.mjs'], 'should call register');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -98,6 +98,6 @@ test('sw: register: unregisterSW', async (t, {location, navigator}) => {
|
|||
|
||||
await unregisterSW('/hello');
|
||||
|
||||
t.calledWith(register, ['/hello/sw.js'], 'should call register');
|
||||
t.calledWith(register, ['/hello/sw.mjs'], 'should call register');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const codegen = require('codegen.macro');
|
||||
const {tryToCatch} = require('try-to-catch');
|
||||
const currify = require('currify');
|
||||
import process from 'node:process';
|
||||
import codegen from 'codegen.macro';
|
||||
import {tryToCatch} from 'try-to-catch';
|
||||
import currify from 'currify';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
|
|
@ -98,3 +96,4 @@ async function addToCache(request, response) {
|
|||
const cache = await caches.open(NAME);
|
||||
return cache.put(request, response);
|
||||
}
|
||||
|
||||
|
|
@ -285,10 +285,12 @@ function setUrl(req, res, next) {
|
|||
|
||||
function setSW(req, res, next) {
|
||||
const {url} = req;
|
||||
const isSW = /^\/sw\.js(\.map)?$/.test(url);
|
||||
const isSW = /^\/sw\.[mc]?js(\.map)?$/.test(url);
|
||||
|
||||
if (isSW)
|
||||
if (isSW) {
|
||||
const url = req.url.replace(/[cm]js/, 'js');
|
||||
req.url = replaceDist(`/dist${url}`);
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ test('cloudcmd: getIndexPath: development', (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: sw', async (t) => {
|
||||
const {status} = await request.get('/sw.js');
|
||||
const {status} = await request.get('/sw.mjs');
|
||||
|
||||
t.equal(status, 200, 'should return sw');
|
||||
t.end();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue