@web/dev-server-core
Advanced tools
Comparing version 0.3.12 to 0.3.13
# @web/dev-server-core | ||
## 0.3.13 | ||
### Patch Changes | ||
- fca0a4c3: Safely stringify error messages in tests | ||
## 0.3.12 | ||
@@ -4,0 +10,0 @@ |
@@ -20,2 +20,110 @@ "use strict"; | ||
return ` | ||
/** | ||
* Code at this indent adapted from fast-safe-stringify by David Mark Clements | ||
* @license MIT | ||
* @see https://github.com/davidmarkclements/fast-safe-stringify | ||
*/ | ||
var arr = [] | ||
var replacerStack = [] | ||
// Stable-stringify | ||
function compareFunction (a, b) { | ||
if (a < b) { | ||
return -1 | ||
} | ||
if (a > b) { | ||
return 1 | ||
} | ||
return 0 | ||
} | ||
export function stable (obj, replacer, spacer) { | ||
var tmp = deterministicDecirc(obj, '', [], undefined) || obj | ||
var res | ||
if (replacerStack.length === 0) { | ||
res = JSON.stringify(tmp, replacer, spacer) | ||
} else { | ||
res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer) | ||
} | ||
while (arr.length !== 0) { | ||
var part = arr.pop() | ||
if (part.length === 4) { | ||
Object.defineProperty(part[0], part[1], part[3]) | ||
} else { | ||
part[0][part[1]] = part[2] | ||
} | ||
} | ||
return res | ||
} | ||
function deterministicDecirc (val, k, stack, parent) { | ||
var i | ||
if (typeof val === 'object' && val !== null) { | ||
for (i = 0; i < stack.length; i++) { | ||
if (stack[i] === val) { | ||
var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k) | ||
if (propertyDescriptor.get !== undefined) { | ||
if (propertyDescriptor.configurable) { | ||
Object.defineProperty(parent, k, { value: '[Circular]' }) | ||
arr.push([parent, k, val, propertyDescriptor]) | ||
} else { | ||
replacerStack.push([val, k]) | ||
} | ||
} else { | ||
parent[k] = '[Circular]' | ||
arr.push([parent, k, val]) | ||
} | ||
return | ||
} | ||
} | ||
if (typeof val.toJSON === 'function') { | ||
return | ||
} | ||
stack.push(val) | ||
// Optimize for Arrays. Big arrays could kill the performance otherwise! | ||
if (Array.isArray(val)) { | ||
for (i = 0; i < val.length; i++) { | ||
deterministicDecirc(val[i], i, stack, val) | ||
} | ||
} else { | ||
// Create a temporary object in the required way | ||
var tmp = {} | ||
var keys = Object.keys(val).sort(compareFunction) | ||
for (i = 0; i < keys.length; i++) { | ||
var key = keys[i] | ||
deterministicDecirc(val[key], key, stack, val) | ||
tmp[key] = val[key] | ||
} | ||
if (parent !== undefined) { | ||
arr.push([parent, k, val]) | ||
parent[k] = tmp | ||
} else { | ||
return tmp | ||
} | ||
} | ||
stack.pop() | ||
} | ||
} | ||
// wraps replacer function to handle values we couldn't replace | ||
// and mark them as [Circular] | ||
function replaceGetterValues (replacer) { | ||
replacer = replacer !== undefined ? replacer : function (k, v) { return v } | ||
return function (key, val) { | ||
if (replacerStack.length > 0) { | ||
for (var i = 0; i < replacerStack.length; i++) { | ||
var part = replacerStack[i] | ||
if (part[1] === key && part[0] === val) { | ||
val = '[Circular]' | ||
replacerStack.splice(i, 1) | ||
break | ||
} | ||
} | ||
} | ||
return replacer.call(this, key, val) | ||
} | ||
} | ||
const { protocol, host } = new URL(import.meta.url); | ||
@@ -31,4 +139,4 @@ const webSocketUrl = \`ws\${protocol === 'https:' ? 's' : ''}://\${host}/${WebSocketsManager_1.NAME_WEB_SOCKET_API}\`; | ||
function setupFetch() { | ||
sendMessage = (message) =>fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: JSON.stringify(message) }); | ||
sendMessageWaitForResponse = (message) => fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: JSON.stringify(message) }); | ||
sendMessage = (message) =>fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: stable(message) }); | ||
sendMessageWaitForResponse = (message) => fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: stable(message) }); | ||
} | ||
@@ -67,3 +175,3 @@ | ||
} | ||
sendMessage = async (message) => { | ||
@@ -74,5 +182,5 @@ if (!message.type) { | ||
await webSocketOpened; | ||
webSocket.send(JSON.stringify(message)); | ||
webSocket.send(stable(message)); | ||
} | ||
// sends a websocket message and expects a response from the server | ||
@@ -82,3 +190,3 @@ sendMessageWaitForResponse = async (message) => { | ||
const id = getNextMessageId(); | ||
function onResponse(e) { | ||
@@ -95,5 +203,5 @@ const message = JSON.parse(e.data); | ||
} | ||
webSocket.addEventListener('message', onResponse); | ||
setTimeout(() => { | ||
@@ -107,7 +215,7 @@ webSocket.removeEventListener('message', onResponse); | ||
}, 20000); | ||
sendMessage({ ...message, id }); | ||
}); | ||
} | ||
if (webSocket) { | ||
@@ -114,0 +222,0 @@ webSocket.addEventListener('message', async e => { |
{ | ||
"name": "@web/dev-server-core", | ||
"version": "0.3.12", | ||
"version": "0.3.13", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -118,3 +118,3 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
const parseResult = await parse(code, filePath); | ||
imports = (parseResult[0] as any) as ParsedImport[]; | ||
imports = parseResult[0] as any as ParsedImport[]; | ||
} catch (error) { | ||
@@ -121,0 +121,0 @@ if (typeof error.idx === 'number') { |
@@ -22,2 +22,110 @@ import { Plugin } from '../plugins/Plugin'; | ||
return ` | ||
/** | ||
* Code at this indent adapted from fast-safe-stringify by David Mark Clements | ||
* @license MIT | ||
* @see https://github.com/davidmarkclements/fast-safe-stringify | ||
*/ | ||
var arr = [] | ||
var replacerStack = [] | ||
// Stable-stringify | ||
function compareFunction (a, b) { | ||
if (a < b) { | ||
return -1 | ||
} | ||
if (a > b) { | ||
return 1 | ||
} | ||
return 0 | ||
} | ||
export function stable (obj, replacer, spacer) { | ||
var tmp = deterministicDecirc(obj, '', [], undefined) || obj | ||
var res | ||
if (replacerStack.length === 0) { | ||
res = JSON.stringify(tmp, replacer, spacer) | ||
} else { | ||
res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer) | ||
} | ||
while (arr.length !== 0) { | ||
var part = arr.pop() | ||
if (part.length === 4) { | ||
Object.defineProperty(part[0], part[1], part[3]) | ||
} else { | ||
part[0][part[1]] = part[2] | ||
} | ||
} | ||
return res | ||
} | ||
function deterministicDecirc (val, k, stack, parent) { | ||
var i | ||
if (typeof val === 'object' && val !== null) { | ||
for (i = 0; i < stack.length; i++) { | ||
if (stack[i] === val) { | ||
var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k) | ||
if (propertyDescriptor.get !== undefined) { | ||
if (propertyDescriptor.configurable) { | ||
Object.defineProperty(parent, k, { value: '[Circular]' }) | ||
arr.push([parent, k, val, propertyDescriptor]) | ||
} else { | ||
replacerStack.push([val, k]) | ||
} | ||
} else { | ||
parent[k] = '[Circular]' | ||
arr.push([parent, k, val]) | ||
} | ||
return | ||
} | ||
} | ||
if (typeof val.toJSON === 'function') { | ||
return | ||
} | ||
stack.push(val) | ||
// Optimize for Arrays. Big arrays could kill the performance otherwise! | ||
if (Array.isArray(val)) { | ||
for (i = 0; i < val.length; i++) { | ||
deterministicDecirc(val[i], i, stack, val) | ||
} | ||
} else { | ||
// Create a temporary object in the required way | ||
var tmp = {} | ||
var keys = Object.keys(val).sort(compareFunction) | ||
for (i = 0; i < keys.length; i++) { | ||
var key = keys[i] | ||
deterministicDecirc(val[key], key, stack, val) | ||
tmp[key] = val[key] | ||
} | ||
if (parent !== undefined) { | ||
arr.push([parent, k, val]) | ||
parent[k] = tmp | ||
} else { | ||
return tmp | ||
} | ||
} | ||
stack.pop() | ||
} | ||
} | ||
// wraps replacer function to handle values we couldn't replace | ||
// and mark them as [Circular] | ||
function replaceGetterValues (replacer) { | ||
replacer = replacer !== undefined ? replacer : function (k, v) { return v } | ||
return function (key, val) { | ||
if (replacerStack.length > 0) { | ||
for (var i = 0; i < replacerStack.length; i++) { | ||
var part = replacerStack[i] | ||
if (part[1] === key && part[0] === val) { | ||
val = '[Circular]' | ||
replacerStack.splice(i, 1) | ||
break | ||
} | ||
} | ||
} | ||
return replacer.call(this, key, val) | ||
} | ||
} | ||
const { protocol, host } = new URL(import.meta.url); | ||
@@ -33,4 +141,4 @@ const webSocketUrl = \`ws\${protocol === 'https:' ? 's' : ''}://\${host}/${NAME_WEB_SOCKET_API}\`; | ||
function setupFetch() { | ||
sendMessage = (message) =>fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: JSON.stringify(message) }); | ||
sendMessageWaitForResponse = (message) => fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: JSON.stringify(message) }); | ||
sendMessage = (message) =>fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: stable(message) }); | ||
sendMessageWaitForResponse = (message) => fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: stable(message) }); | ||
} | ||
@@ -69,3 +177,3 @@ | ||
} | ||
sendMessage = async (message) => { | ||
@@ -76,5 +184,5 @@ if (!message.type) { | ||
await webSocketOpened; | ||
webSocket.send(JSON.stringify(message)); | ||
webSocket.send(stable(message)); | ||
} | ||
// sends a websocket message and expects a response from the server | ||
@@ -84,3 +192,3 @@ sendMessageWaitForResponse = async (message) => { | ||
const id = getNextMessageId(); | ||
function onResponse(e) { | ||
@@ -97,5 +205,5 @@ const message = JSON.parse(e.data); | ||
} | ||
webSocket.addEventListener('message', onResponse); | ||
setTimeout(() => { | ||
@@ -109,7 +217,7 @@ webSocket.removeEventListener('message', onResponse); | ||
}, 20000); | ||
sendMessage({ ...message, id }); | ||
}); | ||
} | ||
if (webSocket) { | ||
@@ -116,0 +224,0 @@ webSocket.addEventListener('message', async e => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
296900
5648