mirror of
https://github.com/LostCityRS/Client-TS.git
synced 2026-05-06 08:56:53 -04:00
feat: Minify output further
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
"jiti": "^2.6.1",
|
||||
"node-forge": "^1.3.2",
|
||||
"prettier": "^3.7.1",
|
||||
"terser": "^5.46.0",
|
||||
"typescript-eslint": "^8.53.0",
|
||||
},
|
||||
"peerDependencies": {
|
||||
@@ -50,6 +51,16 @@
|
||||
|
||||
"@humanwhocodes/retry": ["@humanwhocodes/retry@0.4.3", "", {}, "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ=="],
|
||||
|
||||
"@jridgewell/gen-mapping": ["@jridgewell/gen-mapping@0.3.13", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA=="],
|
||||
|
||||
"@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.2", "", {}, "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw=="],
|
||||
|
||||
"@jridgewell/source-map": ["@jridgewell/source-map@0.3.11", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25" } }, "sha512-ZMp1V8ZFcPG5dIWnQLr3NSI1MiCU7UETdS/A0G8V/XWHvJv3ZsFqutJn1Y5RPmAPX6F3BiE397OqveU/9NCuIA=="],
|
||||
|
||||
"@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.5.5", "", {}, "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og=="],
|
||||
|
||||
"@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="],
|
||||
|
||||
"@types/bun": ["@types/bun@1.2.23", "", { "dependencies": { "bun-types": "1.2.23" } }, "sha512-le8ueOY5b6VKYf19xT3McVbXqLqmxzPXHsQT/q9JHgikJ2X22wyTW3g3ohz2ZMnp7dod6aduIiq8A14Xyimm0A=="],
|
||||
|
||||
"@types/estree": ["@types/estree@1.0.8", "", {}, "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w=="],
|
||||
@@ -96,6 +107,8 @@
|
||||
|
||||
"brace-expansion": ["brace-expansion@1.1.12", "", { "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg=="],
|
||||
|
||||
"buffer-from": ["buffer-from@1.1.2", "", {}, "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="],
|
||||
|
||||
"bun-types": ["bun-types@1.2.23", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-R9f0hKAZXgFU3mlrA0YpE/fiDvwV0FT9rORApt2aQVWSuJDzZOyB5QLc0N/4HF57CS8IXJ6+L5E4W1bW6NS2Aw=="],
|
||||
|
||||
"callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="],
|
||||
@@ -106,6 +119,8 @@
|
||||
|
||||
"color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="],
|
||||
|
||||
"commander": ["commander@2.20.3", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="],
|
||||
|
||||
"concat-map": ["concat-map@0.0.1", "", {}, "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="],
|
||||
|
||||
"cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="],
|
||||
@@ -224,10 +239,16 @@
|
||||
|
||||
"shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="],
|
||||
|
||||
"source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="],
|
||||
|
||||
"source-map-support": ["source-map-support@0.5.21", "", { "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w=="],
|
||||
|
||||
"strip-json-comments": ["strip-json-comments@3.1.1", "", {}, "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig=="],
|
||||
|
||||
"supports-color": ["supports-color@7.2.0", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw=="],
|
||||
|
||||
"terser": ["terser@5.46.0", "", { "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.15.0", "commander": "^2.20.0", "source-map-support": "~0.5.20" }, "bin": { "terser": "bin/terser" } }, "sha512-jTwoImyr/QbOWFFso3YoU3ik0jBBDJ6JTOQiy/J2YxVJdZCc+5u7skhNwiOR3FQIygFqVUPHl7qbbxtjW2K3Qg=="],
|
||||
|
||||
"tinyglobby": ["tinyglobby@0.2.15", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.3" } }, "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ=="],
|
||||
|
||||
"ts-api-utils": ["ts-api-utils@2.4.0", "", { "peerDependencies": { "typescript": ">=4.8.4" } }, "sha512-3TaVTaAv2gTiMB35i3FiGJaRfwb3Pyn/j3m/bfAvGe8FB7CF6u+LMYqYlDh7reQf7UNvoTvdfAqHGmPGOSsPmA=="],
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { minify } from 'terser';
|
||||
|
||||
import { nth_identifier } from './identifier.js';
|
||||
|
||||
const define = {
|
||||
'process.env.SECURE_ORIGIN': JSON.stringify(process.env.SECURE_ORIGIN ?? 'false'),
|
||||
// original key, used 2003-2010
|
||||
@@ -27,7 +31,7 @@ async function bunBuild(entry: string, external: string[] = [], minify = true, d
|
||||
});
|
||||
|
||||
if (!build.success) {
|
||||
build.logs.forEach(x => console.log(x));
|
||||
build.logs.forEach((x: any) => console.log(x));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -37,6 +41,52 @@ async function bunBuild(entry: string, external: string[] = [], minify = true, d
|
||||
};
|
||||
}
|
||||
|
||||
async function applyTerser(script: BunOutput): Promise<boolean> {
|
||||
const mini = await minify(script.source, {
|
||||
sourceMap: {
|
||||
content: script.sourcemap
|
||||
},
|
||||
toplevel: true,
|
||||
// format: {
|
||||
// beautify: true
|
||||
// },
|
||||
compress: {
|
||||
ecma: 2020
|
||||
},
|
||||
mangle: {
|
||||
nth_identifier: nth_identifier,
|
||||
properties: {
|
||||
reserved: [
|
||||
// stdlib
|
||||
'willReadFrequently',
|
||||
'usedJSHeapSize',
|
||||
|
||||
// wasm
|
||||
// must be callable:
|
||||
'_abort_js',
|
||||
'emscripten_resize_heap',
|
||||
'fd_close',
|
||||
'fd_seek',
|
||||
'fd_write',
|
||||
// must be an object:
|
||||
'env',
|
||||
'wasi_snapshot_preview1',
|
||||
// is not an object:
|
||||
'instance',
|
||||
// is not a function:
|
||||
'emscripten_stack_init',
|
||||
'emscripten_stack_get_end',
|
||||
'__wasm_call_ctors'
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
script.source = mini.code ?? '';
|
||||
script.sourcemap = mini.map?.toString() ?? '';
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
if (!fs.existsSync('out')) {
|
||||
@@ -58,6 +108,10 @@ for (const file of entrypoints) {
|
||||
|
||||
const script = await bunBuild(file, [], prod, prod ? ['console'] : []);
|
||||
if (script) {
|
||||
if (prod) {
|
||||
await applyTerser(script);
|
||||
}
|
||||
|
||||
fs.writeFileSync(`out/${output}`, script.source);
|
||||
fs.writeFileSync(`out/${output}.map`, script.sourcemap);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
function mergeSort(array, cmp) {
|
||||
if (array.length < 2) return array.slice();
|
||||
function merge(a, b) {
|
||||
var r = [],
|
||||
ai = 0,
|
||||
bi = 0,
|
||||
i = 0;
|
||||
while (ai < a.length && bi < b.length) {
|
||||
cmp(a[ai], b[bi]) <= 0 ? (r[i++] = a[ai++]) : (r[i++] = b[bi++]);
|
||||
}
|
||||
if (ai < a.length) r.push.apply(r, a.slice(ai));
|
||||
if (bi < b.length) r.push.apply(r, b.slice(bi));
|
||||
return r;
|
||||
}
|
||||
function _ms(a) {
|
||||
if (a.length <= 1) return a;
|
||||
var m = Math.floor(a.length / 2),
|
||||
left = a.slice(0, m),
|
||||
right = a.slice(m);
|
||||
left = _ms(left);
|
||||
right = _ms(right);
|
||||
return merge(left, right);
|
||||
}
|
||||
return _ms(array);
|
||||
}
|
||||
|
||||
function shuffle(arr) {
|
||||
for (let i = arr.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[arr[i], arr[j]] = [arr[j], arr[i]];
|
||||
}
|
||||
}
|
||||
|
||||
export const nth_identifier = (() => {
|
||||
let leading = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'.split('');
|
||||
let digits = '0123456789'.split('');
|
||||
shuffle(leading);
|
||||
shuffle(digits);
|
||||
|
||||
let chars;
|
||||
let frequency;
|
||||
function reset() {
|
||||
frequency = new Map();
|
||||
leading.forEach(ch => frequency.set(ch, 0));
|
||||
digits.forEach(ch => frequency.set(ch, 0));
|
||||
}
|
||||
function consider(str, delta) {
|
||||
for (var i = str.length; --i >= 0; ) {
|
||||
frequency.set(str[i], frequency.get(str[i]) + delta);
|
||||
}
|
||||
}
|
||||
function compare(a, b) {
|
||||
return frequency.get(b) - frequency.get(a);
|
||||
}
|
||||
function sort() {
|
||||
chars = mergeSort(leading, compare).concat(mergeSort(digits, compare));
|
||||
}
|
||||
|
||||
reset();
|
||||
sort();
|
||||
|
||||
function baseN(num) {
|
||||
// comment out this code if you want stability between runs
|
||||
if (num === 0) {
|
||||
reset();
|
||||
sort();
|
||||
}
|
||||
|
||||
var ret = '',
|
||||
base = 54;
|
||||
num++;
|
||||
|
||||
do {
|
||||
num--;
|
||||
ret += chars[num % base];
|
||||
num = Math.floor(num / base);
|
||||
base = 64;
|
||||
} while (num > 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return {
|
||||
get: baseN,
|
||||
consider,
|
||||
reset,
|
||||
sort
|
||||
};
|
||||
})();
|
||||
@@ -22,6 +22,7 @@
|
||||
"jiti": "^2.6.1",
|
||||
"node-forge": "^1.3.2",
|
||||
"prettier": "^3.7.1",
|
||||
"terser": "^5.46.0",
|
||||
"typescript-eslint": "^8.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
window.AudioContext = window.AudioContext || window.webkitAudioContext;
|
||||
if (window.AudioContext) {
|
||||
window.audioContext = new window.AudioContext();
|
||||
window.audioContext = new window.AudioContext({ sampleRate: 22050 });
|
||||
}
|
||||
var fixAudioContext = function (e) {
|
||||
if (window.audioContext) {
|
||||
|
||||
+2
-2
@@ -150,8 +150,8 @@ var loadTinyMidiPCM = (() => {
|
||||
throw new Error('environment detection error');
|
||||
}
|
||||
|
||||
var out = Module['print'] || console.log.bind(console);
|
||||
var err = Module['printErr'] || console.error.bind(console);
|
||||
var out = Module['print'] || console.log.bind(console) || (() => {});
|
||||
var err = Module['printErr'] || console.error.bind(console) || (() => {});
|
||||
|
||||
// Merge back in the overrides
|
||||
Object.assign(Module, moduleOverrides);
|
||||
|
||||
Reference in New Issue
Block a user