mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
chore(web): update PostCSS and MSW worker
- Bump PostCSS to 8.5.10 and refresh the pnpm lockfile - Regenerate the MSW service worker for msw 2.12.10 - Add pnpm build approvals for frontend tooling
This commit is contained in:
@@ -61,7 +61,7 @@
|
|||||||
"eslint-plugin-react-refresh": "^0.4.26",
|
"eslint-plugin-react-refresh": "^0.4.26",
|
||||||
"globals": "^17.3.0",
|
"globals": "^17.3.0",
|
||||||
"msw": "^2.12.10",
|
"msw": "^2.12.10",
|
||||||
"postcss": "^8.5.6",
|
"postcss": "^8.5.10",
|
||||||
"prettier": "^3.8.1",
|
"prettier": "^3.8.1",
|
||||||
"prettier-plugin-tailwindcss": "^0.6.14",
|
"prettier-plugin-tailwindcss": "^0.6.14",
|
||||||
"tailwindcss": "^3.4.19",
|
"tailwindcss": "^3.4.19",
|
||||||
|
|||||||
20
web/pnpm-lock.yaml
generated
20
web/pnpm-lock.yaml
generated
@@ -128,7 +128,7 @@ importers:
|
|||||||
version: 4.7.0(vite@7.3.2(@types/node@25.3.2)(jiti@1.21.7)(lightningcss@1.32.0)(yaml@2.8.3))
|
version: 4.7.0(vite@7.3.2(@types/node@25.3.2)(jiti@1.21.7)(lightningcss@1.32.0)(yaml@2.8.3))
|
||||||
autoprefixer:
|
autoprefixer:
|
||||||
specifier: ^10.4.27
|
specifier: ^10.4.27
|
||||||
version: 10.4.27(postcss@8.5.6)
|
version: 10.4.27(postcss@8.5.10)
|
||||||
eslint:
|
eslint:
|
||||||
specifier: ^9.39.4
|
specifier: ^9.39.4
|
||||||
version: 9.39.4(jiti@1.21.7)
|
version: 9.39.4(jiti@1.21.7)
|
||||||
@@ -151,8 +151,8 @@ importers:
|
|||||||
specifier: ^2.12.10
|
specifier: ^2.12.10
|
||||||
version: 2.12.10(@types/node@25.3.2)(typescript@5.9.3)
|
version: 2.12.10(@types/node@25.3.2)(typescript@5.9.3)
|
||||||
postcss:
|
postcss:
|
||||||
specifier: ^8.5.6
|
specifier: ^8.5.10
|
||||||
version: 8.5.6
|
version: 8.5.10
|
||||||
prettier:
|
prettier:
|
||||||
specifier: ^3.8.1
|
specifier: ^3.8.1
|
||||||
version: 3.8.1
|
version: 3.8.1
|
||||||
@@ -2520,10 +2520,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-pMMHxBOZKFU6HgAZ4eyGnwXF/EvPGGqUr0MnZ5+99485wwW41kW91A4LOGxSHhgugZmSChL5AlElNdwlNgcnLQ==}
|
resolution: {integrity: sha512-pMMHxBOZKFU6HgAZ4eyGnwXF/EvPGGqUr0MnZ5+99485wwW41kW91A4LOGxSHhgugZmSChL5AlElNdwlNgcnLQ==}
|
||||||
engines: {node: ^10 || ^12 || >=14}
|
engines: {node: ^10 || ^12 || >=14}
|
||||||
|
|
||||||
postcss@8.5.6:
|
|
||||||
resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==}
|
|
||||||
engines: {node: ^10 || ^12 || >=14}
|
|
||||||
|
|
||||||
prelude-ls@1.2.1:
|
prelude-ls@1.2.1:
|
||||||
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
|
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
|
||||||
engines: {node: '>= 0.8.0'}
|
engines: {node: '>= 0.8.0'}
|
||||||
@@ -4536,13 +4532,13 @@ snapshots:
|
|||||||
|
|
||||||
asynckit@0.4.0: {}
|
asynckit@0.4.0: {}
|
||||||
|
|
||||||
autoprefixer@10.4.27(postcss@8.5.6):
|
autoprefixer@10.4.27(postcss@8.5.10):
|
||||||
dependencies:
|
dependencies:
|
||||||
browserslist: 4.28.1
|
browserslist: 4.28.1
|
||||||
caniuse-lite: 1.0.30001774
|
caniuse-lite: 1.0.30001774
|
||||||
fraction.js: 5.3.4
|
fraction.js: 5.3.4
|
||||||
picocolors: 1.1.1
|
picocolors: 1.1.1
|
||||||
postcss: 8.5.6
|
postcss: 8.5.10
|
||||||
postcss-value-parser: 4.2.0
|
postcss-value-parser: 4.2.0
|
||||||
|
|
||||||
available-typed-arrays@1.0.7:
|
available-typed-arrays@1.0.7:
|
||||||
@@ -6099,12 +6095,6 @@ snapshots:
|
|||||||
picocolors: 1.1.1
|
picocolors: 1.1.1
|
||||||
source-map-js: 1.2.1
|
source-map-js: 1.2.1
|
||||||
|
|
||||||
postcss@8.5.6:
|
|
||||||
dependencies:
|
|
||||||
nanoid: 3.3.11
|
|
||||||
picocolors: 1.1.1
|
|
||||||
source-map-js: 1.2.1
|
|
||||||
|
|
||||||
prelude-ls@1.2.1: {}
|
prelude-ls@1.2.1: {}
|
||||||
|
|
||||||
prettier-plugin-tailwindcss@0.6.14(@ianvs/prettier-plugin-sort-imports@4.7.1(prettier@3.8.1))(prettier@3.8.1):
|
prettier-plugin-tailwindcss@0.6.14(@ianvs/prettier-plugin-sort-imports@4.7.1(prettier@3.8.1))(prettier@3.8.1):
|
||||||
|
|||||||
6
web/pnpm-workspace.yaml
Normal file
6
web/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
allowBuilds:
|
||||||
|
bufferutil: true
|
||||||
|
es5-ext: true
|
||||||
|
esbuild: true
|
||||||
|
msw: true
|
||||||
|
utf-8-validate: true
|
||||||
@@ -5,24 +5,23 @@
|
|||||||
* Mock Service Worker.
|
* Mock Service Worker.
|
||||||
* @see https://github.com/mswjs/msw
|
* @see https://github.com/mswjs/msw
|
||||||
* - Please do NOT modify this file.
|
* - Please do NOT modify this file.
|
||||||
* - Please do NOT serve this file on production.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const PACKAGE_VERSION = '2.6.0'
|
const PACKAGE_VERSION = '2.12.10'
|
||||||
const INTEGRITY_CHECKSUM = '07a8241b182f8a246a7cd39894799a9e'
|
const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
|
||||||
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
||||||
const activeClientIds = new Set()
|
const activeClientIds = new Set()
|
||||||
|
|
||||||
self.addEventListener('install', function () {
|
addEventListener('install', function () {
|
||||||
self.skipWaiting()
|
self.skipWaiting()
|
||||||
})
|
})
|
||||||
|
|
||||||
self.addEventListener('activate', function (event) {
|
addEventListener('activate', function (event) {
|
||||||
event.waitUntil(self.clients.claim())
|
event.waitUntil(self.clients.claim())
|
||||||
})
|
})
|
||||||
|
|
||||||
self.addEventListener('message', async function (event) {
|
addEventListener('message', async function (event) {
|
||||||
const clientId = event.source.id
|
const clientId = Reflect.get(event.source || {}, 'id')
|
||||||
|
|
||||||
if (!clientId || !self.clients) {
|
if (!clientId || !self.clients) {
|
||||||
return
|
return
|
||||||
@@ -72,11 +71,6 @@ self.addEventListener('message', async function (event) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'MOCK_DEACTIVATE': {
|
|
||||||
activeClientIds.delete(clientId)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'CLIENT_CLOSED': {
|
case 'CLIENT_CLOSED': {
|
||||||
activeClientIds.delete(clientId)
|
activeClientIds.delete(clientId)
|
||||||
|
|
||||||
@@ -94,69 +88,92 @@ self.addEventListener('message', async function (event) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
self.addEventListener('fetch', function (event) {
|
addEventListener('fetch', function (event) {
|
||||||
const { request } = event
|
const requestInterceptedAt = Date.now()
|
||||||
|
|
||||||
// Bypass navigation requests.
|
// Bypass navigation requests.
|
||||||
if (request.mode === 'navigate') {
|
if (event.request.mode === 'navigate') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opening the DevTools triggers the "only-if-cached" request
|
// Opening the DevTools triggers the "only-if-cached" request
|
||||||
// that cannot be handled by the worker. Bypass such requests.
|
// that cannot be handled by the worker. Bypass such requests.
|
||||||
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
|
if (
|
||||||
|
event.request.cache === 'only-if-cached' &&
|
||||||
|
event.request.mode !== 'same-origin'
|
||||||
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bypass all requests when there are no active clients.
|
// Bypass all requests when there are no active clients.
|
||||||
// Prevents the self-unregistered worked from handling requests
|
// Prevents the self-unregistered worked from handling requests
|
||||||
// after it's been deleted (still remains active until the next reload).
|
// after it's been terminated (still remains active until the next reload).
|
||||||
if (activeClientIds.size === 0) {
|
if (activeClientIds.size === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate unique request ID.
|
|
||||||
const requestId = crypto.randomUUID()
|
const requestId = crypto.randomUUID()
|
||||||
event.respondWith(handleRequest(event, requestId))
|
event.respondWith(handleRequest(event, requestId, requestInterceptedAt))
|
||||||
})
|
})
|
||||||
|
|
||||||
async function handleRequest(event, requestId) {
|
/**
|
||||||
|
* @param {FetchEvent} event
|
||||||
|
* @param {string} requestId
|
||||||
|
* @param {number} requestInterceptedAt
|
||||||
|
*/
|
||||||
|
async function handleRequest(event, requestId, requestInterceptedAt) {
|
||||||
const client = await resolveMainClient(event)
|
const client = await resolveMainClient(event)
|
||||||
const response = await getResponse(event, client, requestId)
|
const requestCloneForEvents = event.request.clone()
|
||||||
|
const response = await getResponse(
|
||||||
|
event,
|
||||||
|
client,
|
||||||
|
requestId,
|
||||||
|
requestInterceptedAt,
|
||||||
|
)
|
||||||
|
|
||||||
// Send back the response clone for the "response:*" life-cycle events.
|
// Send back the response clone for the "response:*" life-cycle events.
|
||||||
// Ensure MSW is active and ready to handle the message, otherwise
|
// Ensure MSW is active and ready to handle the message, otherwise
|
||||||
// this message will pend indefinitely.
|
// this message will pend indefinitely.
|
||||||
if (client && activeClientIds.has(client.id)) {
|
if (client && activeClientIds.has(client.id)) {
|
||||||
;(async function () {
|
const serializedRequest = await serializeRequest(requestCloneForEvents)
|
||||||
const responseClone = response.clone()
|
|
||||||
|
|
||||||
sendToClient(
|
// Clone the response so both the client and the library could consume it.
|
||||||
client,
|
const responseClone = response.clone()
|
||||||
{
|
|
||||||
type: 'RESPONSE',
|
sendToClient(
|
||||||
payload: {
|
client,
|
||||||
requestId,
|
{
|
||||||
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
type: 'RESPONSE',
|
||||||
|
payload: {
|
||||||
|
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
||||||
|
request: {
|
||||||
|
id: requestId,
|
||||||
|
...serializedRequest,
|
||||||
|
},
|
||||||
|
response: {
|
||||||
type: responseClone.type,
|
type: responseClone.type,
|
||||||
status: responseClone.status,
|
status: responseClone.status,
|
||||||
statusText: responseClone.statusText,
|
statusText: responseClone.statusText,
|
||||||
body: responseClone.body,
|
|
||||||
headers: Object.fromEntries(responseClone.headers.entries()),
|
headers: Object.fromEntries(responseClone.headers.entries()),
|
||||||
|
body: responseClone.body,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[responseClone.body],
|
},
|
||||||
)
|
responseClone.body ? [serializedRequest.body, responseClone.body] : [],
|
||||||
})()
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve the main client for the given event.
|
/**
|
||||||
// Client that issues a request doesn't necessarily equal the client
|
* Resolve the main client for the given event.
|
||||||
// that registered the worker. It's with the latter the worker should
|
* Client that issues a request doesn't necessarily equal the client
|
||||||
// communicate with during the response resolving phase.
|
* that registered the worker. It's with the latter the worker should
|
||||||
|
* communicate with during the response resolving phase.
|
||||||
|
* @param {FetchEvent} event
|
||||||
|
* @returns {Promise<Client | undefined>}
|
||||||
|
*/
|
||||||
async function resolveMainClient(event) {
|
async function resolveMainClient(event) {
|
||||||
const client = await self.clients.get(event.clientId)
|
const client = await self.clients.get(event.clientId)
|
||||||
|
|
||||||
@@ -184,20 +201,39 @@ async function resolveMainClient(event) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getResponse(event, client, requestId) {
|
/**
|
||||||
const { request } = event
|
* @param {FetchEvent} event
|
||||||
|
* @param {Client | undefined} client
|
||||||
|
* @param {string} requestId
|
||||||
|
* @param {number} requestInterceptedAt
|
||||||
|
* @returns {Promise<Response>}
|
||||||
|
*/
|
||||||
|
async function getResponse(event, client, requestId, requestInterceptedAt) {
|
||||||
// Clone the request because it might've been already used
|
// Clone the request because it might've been already used
|
||||||
// (i.e. its body has been read and sent to the client).
|
// (i.e. its body has been read and sent to the client).
|
||||||
const requestClone = request.clone()
|
const requestClone = event.request.clone()
|
||||||
|
|
||||||
function passthrough() {
|
function passthrough() {
|
||||||
const headers = Object.fromEntries(requestClone.headers.entries())
|
// Cast the request headers to a new Headers instance
|
||||||
|
// so the headers can be manipulated with.
|
||||||
|
const headers = new Headers(requestClone.headers)
|
||||||
|
|
||||||
// Remove internal MSW request header so the passthrough request
|
// Remove the "accept" header value that marked this request as passthrough.
|
||||||
// complies with any potential CORS preflight checks on the server.
|
// This prevents request alteration and also keeps it compliant with the
|
||||||
// Some servers forbid unknown request headers.
|
// user-defined CORS policies.
|
||||||
delete headers['x-msw-intention']
|
const acceptHeader = headers.get('accept')
|
||||||
|
if (acceptHeader) {
|
||||||
|
const values = acceptHeader.split(',').map((value) => value.trim())
|
||||||
|
const filteredValues = values.filter(
|
||||||
|
(value) => value !== 'msw/passthrough',
|
||||||
|
)
|
||||||
|
|
||||||
|
if (filteredValues.length > 0) {
|
||||||
|
headers.set('accept', filteredValues.join(', '))
|
||||||
|
} else {
|
||||||
|
headers.delete('accept')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fetch(requestClone, { headers })
|
return fetch(requestClone, { headers })
|
||||||
}
|
}
|
||||||
@@ -216,29 +252,18 @@ async function getResponse(event, client, requestId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notify the client that a request has been intercepted.
|
// Notify the client that a request has been intercepted.
|
||||||
const requestBuffer = await request.arrayBuffer()
|
const serializedRequest = await serializeRequest(event.request)
|
||||||
const clientMessage = await sendToClient(
|
const clientMessage = await sendToClient(
|
||||||
client,
|
client,
|
||||||
{
|
{
|
||||||
type: 'REQUEST',
|
type: 'REQUEST',
|
||||||
payload: {
|
payload: {
|
||||||
id: requestId,
|
id: requestId,
|
||||||
url: request.url,
|
interceptedAt: requestInterceptedAt,
|
||||||
mode: request.mode,
|
...serializedRequest,
|
||||||
method: request.method,
|
|
||||||
headers: Object.fromEntries(request.headers.entries()),
|
|
||||||
cache: request.cache,
|
|
||||||
credentials: request.credentials,
|
|
||||||
destination: request.destination,
|
|
||||||
integrity: request.integrity,
|
|
||||||
redirect: request.redirect,
|
|
||||||
referrer: request.referrer,
|
|
||||||
referrerPolicy: request.referrerPolicy,
|
|
||||||
body: requestBuffer,
|
|
||||||
keepalive: request.keepalive,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[requestBuffer],
|
[serializedRequest.body],
|
||||||
)
|
)
|
||||||
|
|
||||||
switch (clientMessage.type) {
|
switch (clientMessage.type) {
|
||||||
@@ -254,6 +279,12 @@ async function getResponse(event, client, requestId) {
|
|||||||
return passthrough()
|
return passthrough()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Client} client
|
||||||
|
* @param {any} message
|
||||||
|
* @param {Array<Transferable>} transferrables
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
function sendToClient(client, message, transferrables = []) {
|
function sendToClient(client, message, transferrables = []) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const channel = new MessageChannel()
|
const channel = new MessageChannel()
|
||||||
@@ -266,14 +297,18 @@ function sendToClient(client, message, transferrables = []) {
|
|||||||
resolve(event.data)
|
resolve(event.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
client.postMessage(
|
client.postMessage(message, [
|
||||||
message,
|
channel.port2,
|
||||||
[channel.port2].concat(transferrables.filter(Boolean)),
|
...transferrables.filter(Boolean),
|
||||||
)
|
])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function respondWithMock(response) {
|
/**
|
||||||
|
* @param {Response} response
|
||||||
|
* @returns {Response}
|
||||||
|
*/
|
||||||
|
function respondWithMock(response) {
|
||||||
// Setting response status code to 0 is a no-op.
|
// Setting response status code to 0 is a no-op.
|
||||||
// However, when responding with a "Response.error()", the produced Response
|
// However, when responding with a "Response.error()", the produced Response
|
||||||
// instance will have status code set to 0. Since it's not possible to create
|
// instance will have status code set to 0. Since it's not possible to create
|
||||||
@@ -291,3 +326,24 @@ async function respondWithMock(response) {
|
|||||||
|
|
||||||
return mockedResponse
|
return mockedResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Request} request
|
||||||
|
*/
|
||||||
|
async function serializeRequest(request) {
|
||||||
|
return {
|
||||||
|
url: request.url,
|
||||||
|
mode: request.mode,
|
||||||
|
method: request.method,
|
||||||
|
headers: Object.fromEntries(request.headers.entries()),
|
||||||
|
cache: request.cache,
|
||||||
|
credentials: request.credentials,
|
||||||
|
destination: request.destination,
|
||||||
|
integrity: request.integrity,
|
||||||
|
redirect: request.redirect,
|
||||||
|
referrer: request.referrer,
|
||||||
|
referrerPolicy: request.referrerPolicy,
|
||||||
|
body: await request.arrayBuffer(),
|
||||||
|
keepalive: request.keepalive,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user