@nxtedition/lib 22.0.10 → 22.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +68 -0
- package/ass.js +1 -1
- package/couch.js +1 -1
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -940,6 +940,74 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
940
940
|
}
|
|
941
941
|
}
|
|
942
942
|
|
|
943
|
+
if (appConfig.utils !== false && !cluster.isWorker) {
|
|
944
|
+
// TODO (fix): What about cluster?
|
|
945
|
+
|
|
946
|
+
const utilsBC = new BroadcastChannel('nxt:utils')
|
|
947
|
+
|
|
948
|
+
destroyers.unshift(() => utilsBC.close())
|
|
949
|
+
|
|
950
|
+
utilsBC.onmessage = ({ data }) => {
|
|
951
|
+
const { type } = data
|
|
952
|
+
try {
|
|
953
|
+
if (type === 'utils:gc') {
|
|
954
|
+
if (global.gc) {
|
|
955
|
+
global.gc()
|
|
956
|
+
logger.debug('gc')
|
|
957
|
+
} else {
|
|
958
|
+
logger.warn('gc not available')
|
|
959
|
+
}
|
|
960
|
+
} else if (type === 'utils:writeHeapSnapshot') {
|
|
961
|
+
const snapshotPath = `${os.tmpdir()}/heap-${Date.now()}-${serviceName}-${serviceModule}-${serviceInstanceId}-${serviceWorkerId}.heapsnapshot`
|
|
962
|
+
v8.writeHeapSnapshot(snapshotPath)
|
|
963
|
+
logger.info({ snapshotPath }, 'heap snapshot')
|
|
964
|
+
}
|
|
965
|
+
} catch (err) {
|
|
966
|
+
logger.error({ err, type })
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
if (isMainThread) {
|
|
971
|
+
// TODO (fix): Determinisitc port also in dev mode... hash of something?
|
|
972
|
+
const port =
|
|
973
|
+
appConfig.utils?.port ?? (isProduction ? 38604 : Math.floor(38000 + Math.random() * 10000))
|
|
974
|
+
|
|
975
|
+
const server = http
|
|
976
|
+
.createServer(async (req, res) => {
|
|
977
|
+
try {
|
|
978
|
+
if (req.method === 'POST' && req.url === '/gc') {
|
|
979
|
+
utilsBC.postMessage({ type: 'utils:gc' })
|
|
980
|
+
res.end()
|
|
981
|
+
return
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
if (req.method === 'POST' && req.url === '/writeHeapSnapshot') {
|
|
985
|
+
utilsBC.postMessage({ type: 'utils:writeHeapSnapshot' })
|
|
986
|
+
res.end()
|
|
987
|
+
return
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
res.statusCode = 404
|
|
991
|
+
res.end()
|
|
992
|
+
} catch (err) {
|
|
993
|
+
logger?.error({ err }, 'utils http error')
|
|
994
|
+
|
|
995
|
+
if (res.headersSent) {
|
|
996
|
+
res.destroy()
|
|
997
|
+
} else {
|
|
998
|
+
res.statusCode = 500
|
|
999
|
+
res.end()
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
})
|
|
1003
|
+
.listen(port)
|
|
1004
|
+
|
|
1005
|
+
logger.debug({ port }, 'utils listening')
|
|
1006
|
+
|
|
1007
|
+
destroyers.unshift(() => new Promise((resolve) => server.close(resolve)))
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
943
1011
|
// TODO (fix): Deprecate
|
|
944
1012
|
if (appConfig.http) {
|
|
945
1013
|
const httpConfig = { ...appConfig.http, ...config.http }
|
package/ass.js
CHANGED
|
@@ -93,7 +93,7 @@ function encASSStyles({ styles, width, height }) {
|
|
|
93
93
|
for (const [id, style] of Object.entries(styles)) {
|
|
94
94
|
scaledStyles[id] = { ...style }
|
|
95
95
|
for (const key of ['fontsize', 'marginV', 'marginL', 'marginR']) {
|
|
96
|
-
const scale = width / BASE_WIDTH
|
|
96
|
+
const scale = key === 'fontsize' ? height / BASE_HEIGHT : width / BASE_WIDTH
|
|
97
97
|
|
|
98
98
|
if (typeof style[key] === 'string') {
|
|
99
99
|
const scaled = Number(style[key]) * scale
|
package/couch.js
CHANGED
|
@@ -958,7 +958,7 @@ class StreamOutput extends stream.Readable {
|
|
|
958
958
|
if (/\[\s*$/.test(line)) {
|
|
959
959
|
this.#state = 1
|
|
960
960
|
} else {
|
|
961
|
-
throw
|
|
961
|
+
throw new Error('expected [ at end of line')
|
|
962
962
|
}
|
|
963
963
|
} else if (this.#state === 1) {
|
|
964
964
|
if (/^\s*\]/.test(line)) {
|