Skip to content

Commit faccab2

Browse files
committed
fix utils
1 parent be8591e commit faccab2

File tree

4 files changed

+17
-40
lines changed

4 files changed

+17
-40
lines changed

build.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable import/no-dynamic-require */
1+
import child from 'child_process';
22
import path from 'path';
33
import zlib from 'zlib';
44
import { encode } from 'base16384';
@@ -27,8 +27,9 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
2727
outdir: path.join(process.cwd(), 'dist'),
2828
splitting: false,
2929
write: false,
30+
target: 'node16',
3031
tsconfig: path.resolve(process.cwd(), 'tsconfig.json'),
31-
minify: true,
32+
minify: !process.argv.includes('--debug'),
3233
entryPoints: [path.resolve(process.cwd(), 'packages/server/index.ts')],
3334
charset: 'utf8',
3435
sourcemap: process.argv.includes('--debug') ? 'inline' : false,
@@ -60,4 +61,15 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
6061
logger.info(`Resource Size: ${size(res.outputFiles[0].text)}`);
6162
fs.writeFileSync(path.resolve(process.cwd(), 'dist/xcpc-tools.js'), res.outputFiles[0].text);
6263
logger.info('Saved to dist/xcpc-tools.js');
64+
if (!process.env.SEA) return;
65+
fs.writeFileSync(path.resolve(process.cwd(), 'dist/sea-config.json'), JSON.stringify({
66+
main: 'xcpc-tools.js',
67+
output: 'sea-prep.blob',
68+
}));
69+
child.execSync('node --experimental-sea-config sea-config.json', { cwd: path.resolve(process.cwd(), 'dist') });
70+
fs.copyFileSync(path.resolve(process.cwd(), 'nanode-v22.x-icu_none-v8_opts-lto-x64'), path.resolve(process.cwd(), 'dist/nanode'));
71+
child.execSync(
72+
'npx postject nanode NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
73+
{ cwd: path.resolve(process.cwd(), 'dist') },
74+
);
6375
})();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"eslint": "^9.28.0",
2828
"eslint-import-resolver-typescript": "^4.4.2",
2929
"iconv-lite": "^0.6.3",
30+
"postject": "^1.0.0-alpha.6",
3031
"typescript": "5.8.3"
3132
},
3233
"resolutions": {

packages/server/service/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function apply(pluginContext: Context) {
88
pluginContext.plugin(WebService, {
99
host: '0.0.0.0',
1010
port: config.port,
11-
});
11+
} as any);
1212
pluginContext.inject(['server'], ({ server }) => {
1313
server.addServerLayer('stream', async (ctx, next) => {
1414
if (!ctx.path.startsWith('/stream/')) return await next();

packages/server/utils/index.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
11
import { gunzipSync } from 'zlib';
22
import { decode } from 'base16384';
3-
import { Exporter, Factory, Logger as Reggol } from 'reggol';
43

5-
Factory.formatters['d'] = (value, exporter) => Reggol.color(exporter, 3, value);
6-
7-
const factory = new Factory();
8-
9-
factory.addExporter(new Exporter.Console({
10-
showDiff: false,
11-
showTime: 'dd hh:mm:ss',
12-
label: {
13-
align: 'right',
14-
width: 9,
15-
margin: 1,
16-
},
17-
timestamp: Date.now(),
18-
levels: { default: process.env.DEV ? 3 : 2 },
19-
}));
20-
21-
function createLogger(name: string) {
22-
return factory.createLogger(name);
23-
}
24-
25-
export type Logger = Reggol & { new(name: string): Reggol & Logger };
26-
export const Logger = createLogger as any as Logger;
27-
28-
const defaultDict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
29-
30-
export function randomstring(digit = 32, dict = defaultDict) {
31-
let str = '';
32-
for (let i = 1; i <= digit; i++) str += dict[Math.floor(Math.random() * dict.length)];
33-
return str;
34-
}
35-
36-
export function sleep(timeout: number) {
37-
return new Promise((resolve) => {
38-
setTimeout(() => resolve(true), timeout);
39-
});
40-
}
4+
export { Logger, sleep, randomstring } from '@hydrooj/utils/lib/utils';
415

426
// https://github.com/andrasq/node-mongoid-js/blob/master/mongoid.js
437
export function mongoId(idstring: string) {

0 commit comments

Comments
 (0)