Skip to content

Commit

Permalink
fix: removed @ungap/structured-clone for performance after cpupro
Browse files Browse the repository at this point in the history
… analysis
  • Loading branch information
titanism committed Dec 18, 2024
1 parent 31d4c77 commit 60f7257
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
14 changes: 4 additions & 10 deletions helpers/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ const _ = require('lodash');
// in order to make the client-side payload less kb
const mongoose = require('mongoose');

// this package is ignored in `browser` config in `package.json`
// in order to make the client-side payload less kb
let structuredClone = require('@ungap/structured-clone');

if (structuredClone) structuredClone = structuredClone.default;

const loggerConfig = require('../config/logger');
const isCodeBug = require('./is-code-bug');

Expand Down Expand Up @@ -284,23 +278,23 @@ for (const level of logger.config.levels) {
// NOTE: we can't use `superjson` because they don't export CJS right now
// <https://github.com/blitz-js/superjson/issues/268#issuecomment-1863659516>
//
if (typeof message === 'object' && structuredClone) {
if (typeof message === 'object' && global.structuredClone) {
// clone the data so that we don't mutate it
// <https://nodejs.org/api/globals.html#structuredclonevalue-options>
// <https://github.com/ungap/structured-clone>
message = structuredClone(message, {
message = global.structuredClone(message, {
// avoid throwing
lossy: true,
// avoid throwing *and* looks for toJSON
json: true
});
}

if (typeof meta === 'object' && structuredClone) {
if (typeof meta === 'object' && global.structuredClone) {
// clone the data so that we don't mutate it
// <https://nodejs.org/api/globals.html#structuredclonevalue-options>
// <https://github.com/ungap/structured-clone>
meta = structuredClone(meta, {
meta = global.structuredClone(meta, {
// avoid throwing
lossy: true,
// avoid throwing *and* looks for toJSON
Expand Down
1 change: 0 additions & 1 deletion helpers/parse-host-from-domain-or-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { isIP } = require('node:net');

const URLParse = require('url-parse');
const isFQDN = require('is-fqdn');
const isSANB = require('is-string-and-not-blank');
const { isURL } = require('@forwardemail/validator');

const SMTPError = require('#helpers/smtp-error');
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"ioredis": false,
"ioredis/built/utils": false,
"lodash": false,
"@ungap/structured-clone": false,
"signale": false,
"mongoose": false,
"#models": false,
Expand Down Expand Up @@ -63,7 +62,6 @@
"@shopify/semaphore": "3.1.0",
"@sidoshi/random-string": "1.0.0",
"@tkrotoff/bootstrap-floating-label": "0.8",
"@ungap/structured-clone": "1.2.1",
"@zainundin/mongoose-factory": "1.1.1",
"@zxcvbn-ts/core": "3.0.4",
"@zxcvbn-ts/language-ar": "3.1.0",
Expand Down Expand Up @@ -269,7 +267,7 @@
"striptags": "3.2.0",
"superagent": "8.1.2",
"sweetalert2": "8.19.1",
"tangerine": "1.5.9",
"tangerine": "1.6.0",
"titleize": "2",
"tlds": "1.255.0",
"tsdav": "2.1.2",
Expand Down

0 comments on commit 60f7257

Please sign in to comment.