Skip to content

Commit 346b9ed

Browse files
Merge pull request #5 from hydro-dev/250425
2 parents ba96828 + b9194cd commit 346b9ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+634
-355
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ config.yaml
1414
config.json
1515
config.*.yaml
1616
config.*.json
17-
data/
17+
data*
1818
yarn.lock
1919
pnpm-lock.yaml
2020

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
diff --git a/lib/index.js b/lib/index.js
2+
index 2cfbc38128a6387e03e30df13422584cf51636fb..97d08d3459b6e06128955fbdd1ac56ab676c5427 100644
3+
--- a/lib/index.js
4+
+++ b/lib/index.js
5+
@@ -68,53 +68,14 @@ var getPrinters = function () { return __awaiter(void 0, void 0, void 0, functio
6+
case 0: return [4 /*yield*/, getTerminalCodepage()];
7+
case 1:
8+
codepage = _b.sent();
9+
- return [4 /*yield*/, execAsync('wmic printer list /format:list', { encoding: 'binary' })];
10+
+ return [4 /*yield*/, execAsync('powershell "Get-WmiObject -Class Win32_Printer | ConvertTo-Json"', { encoding: 'binary' })];
11+
case 2:
12+
_a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr;
13+
if (stderr.length > 0) {
14+
return [2 /*return*/, null];
15+
}
16+
result = iconv_lite_1.default.decode(Buffer.from(stdout, 'binary'), "cp".concat(codepage));
17+
- blocks = result.replace(/\r/ig, '').split('\n\n\n');
18+
- printerInfos = blocks.map(function (block) {
19+
- var obj = {};
20+
- // Split the block into lines that contain an attribute and its value.
21+
- var lines = block.trim().split('\n');
22+
- lines.forEach(function (line) {
23+
- // If the line is empty, ignore it.
24+
- if (line.trim().length < 1)
25+
- return;
26+
- // Get the index of the first equals sign.
27+
- var equalsSignIndex = line.indexOf('=');
28+
- // Extract the name and the value of the attribute.
29+
- var attributeName = line.substring(0, equalsSignIndex);
30+
- var attributeValue = line.substring(equalsSignIndex + 1);
31+
- // Ignore attributes that have blank values for compact output.
32+
- if (attributeValue.length < 1)
33+
- return;
34+
- // Array
35+
- if (attributeValue.startsWith('{') && attributeValue.endsWith('}'))
36+
- attributeValue = JSON.parse("[".concat(attributeValue.substring(1, attributeValue.length - 1), "]"));
37+
- // Boolean
38+
- if (typeof attributeValue === 'string') {
39+
- switch (attributeValue) {
40+
- case 'TRUE':
41+
- attributeValue = true;
42+
- break;
43+
- case 'FALSE':
44+
- attributeValue = false;
45+
- break;
46+
- }
47+
- }
48+
- // Numbers
49+
- if (typeof attributeValue === 'string' && !isNaN(parseFloat(attributeValue))) {
50+
- attributeValue = Number(attributeValue).valueOf();
51+
- }
52+
- // Assign the attribute value by its name into the object.
53+
- obj[attributeName] = attributeValue;
54+
- });
55+
- return obj;
56+
- });
57+
+ printerInfos = JSON.parse(result)
58+
// Ignore the empty printer info objects.
59+
printerInfos = printerInfos.filter(function (printerInfo) { return Object.keys(printerInfo).length > 0; });
60+
return [2 /*return*/, printerInfos];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/lib/http-proxy/passes/web-incoming.js b/lib/http-proxy/passes/web-incoming.js
2+
index 7ae735514190eea569c605fff7d27c045fe8d601..88953ebc549d4e56dc26e46aa32211b82e6546a1 100644
3+
--- a/lib/http-proxy/passes/web-incoming.js
4+
+++ b/lib/http-proxy/passes/web-incoming.js
5+
@@ -143,8 +143,11 @@ module.exports = {
6+
}
7+
8+
// Ensure we abort proxy if request is aborted
9+
- req.on('aborted', function () {
10+
- proxyReq.abort();
11+
+ res.on('close', function () {
12+
+ var aborted = !res.writableFinished;
13+
+ if (aborted) {
14+
+ proxyReq.abort();
15+
+ }
16+
});
17+
18+
// handle errors in proxy and incoming request, just like for forward proxy
19+
@@ -154,7 +157,7 @@ module.exports = {
20+
21+
function createErrorHandler(proxyReq, url) {
22+
return function proxyError(err) {
23+
- if (req.socket.destroyed && err.code === 'ECONNRESET') {
24+
+ if ((req.aborted || req.destroyed || req.socket?.destroyed) && err.code === 'ECONNRESET') {
25+
server.emit('econnreset', err, req, res, url);
26+
return proxyReq.abort();
27+
}

build.ts

Lines changed: 27 additions & 8 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';
@@ -10,9 +10,12 @@ const logger = new Logger('build');
1010
logger.info('Building...');
1111

1212
function encodeBinary(a: Buffer) {
13-
const file = zlib.gzipSync(a);
13+
const file = zlib.gzipSync(a, { level: 9 });
1414
return chunk([...encode(file)], 1000).map((i) => String.fromCodePoint(...i)).join('');
1515
}
16+
function size(a: string) {
17+
return `${Math.floor((Buffer.from(a).length / 1024 / 1024) * 10) / 10}MB`;
18+
}
1619

1720
const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==';
1821

@@ -24,23 +27,27 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
2427
outdir: path.join(process.cwd(), 'dist'),
2528
splitting: false,
2629
write: false,
30+
target: 'node16',
2731
tsconfig: path.resolve(process.cwd(), 'tsconfig.json'),
28-
minify: true,
32+
minify: !process.argv.includes('--debug'),
2933
entryPoints: [path.resolve(process.cwd(), 'packages/server/index.ts')],
3034
charset: 'utf8',
31-
sourcemap: 'inline',
35+
sourcemap: process.argv.includes('--debug') ? 'inline' : false,
36+
metafile: true,
3237
plugins: [{
3338
name: 'base16384',
3439
setup(b) {
3540
b.onLoad({ filter: /\.(frontend|ttf|wasm)$/, namespace: 'file' }, (t) => {
3641
const file = fs.readFileSync(path.join(t.path));
42+
const contents = `module.exports = "${process.argv.includes('--no-binary') ? '' : encodeBinary(file)}";\n${nopMap}`;
43+
console.log(t.path, size(contents));
3744
return {
38-
contents: `module.exports = "${encodeBinary(file)}";\n${nopMap}`,
45+
contents,
3946
loader: 'tsx',
4047
};
4148
});
42-
b.onLoad({ filter: /node_modules\/.+\.js$/ }, (t) => ({
43-
contents: `${fs.readFileSync(t.path, 'utf8')}\n${nopMap}`,
49+
b.onLoad({ filter: /node_modules.*\.[jt]sx?$/ }, async (t) => ({
50+
contents: `${await fs.readFile(t.path, 'utf-8')}\n${nopMap}`,
4451
loader: 'default',
4552
}));
4653
},
@@ -52,7 +59,19 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
5259
});
5360
if (res.errors.length) console.error(res.errors);
5461
if (res.warnings.length) console.warn(res.warnings);
55-
logger.info(`Resource Size: ${Math.floor((res.outputFiles[0].text.length / 1024 / 1024) * 10) / 10}MB`);
62+
logger.info(`Resource Size: ${size(res.outputFiles[0].text)}`);
5663
fs.writeFileSync(path.resolve(process.cwd(), 'dist/xcpc-tools.js'), res.outputFiles[0].text);
64+
fs.writeFileSync(path.resolve(process.cwd(), 'dist/metafile.json'), JSON.stringify(res.metafile));
5765
logger.info('Saved to dist/xcpc-tools.js');
66+
if (!process.env.SEA) return;
67+
fs.writeFileSync(path.resolve(process.cwd(), 'dist/sea-config.json'), JSON.stringify({
68+
main: 'xcpc-tools.js',
69+
output: 'sea-prep.blob',
70+
}));
71+
child.execSync('node --experimental-sea-config sea-config.json', { cwd: path.resolve(process.cwd(), 'dist') });
72+
fs.copyFileSync(path.resolve(process.cwd(), 'nanode-v22.x-icu_none-v8_opts-lto-x64'), path.resolve(process.cwd(), 'dist/nanode'));
73+
child.execSync(
74+
'npx postject nanode NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
75+
{ cwd: path.resolve(process.cwd(), 'dist') },
76+
);
5877
})();

eslint.config.mjs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* eslint-disable max-len */
2+
import { defineConfig, globalIgnores } from 'eslint/config';
3+
import globals from 'globals';
4+
import react from '@hydrooj/eslint-config';
5+
6+
export default defineConfig([globalIgnores([
7+
'**/dist',
8+
'**/*.d.ts',
9+
'**/node_modules',
10+
'**/.*.js',
11+
]), {
12+
extends: [react],
13+
14+
languageOptions: {
15+
ecmaVersion: 5,
16+
sourceType: 'module',
17+
},
18+
19+
settings: {
20+
'import/parsers': {
21+
'@typescript-eslint/parser': ['.ts', '.js', '.jsx', '.tsx'],
22+
},
23+
},
24+
25+
rules: {
26+
'@typescript-eslint/no-invalid-this': 1,
27+
28+
'simple-import-sort/imports': ['warn', {
29+
groups: [
30+
['^\\u0000'],
31+
[
32+
'^(node:)?(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)',
33+
'^(?!@?hydrooj)(@?\\w.+)',
34+
'^@?hydrooj',
35+
'^',
36+
'^\\.',
37+
]],
38+
}],
39+
},
40+
}, {
41+
files: [
42+
'**/packages/ui/**/*.{cjs,ts,tsx}',
43+
],
44+
45+
languageOptions: {
46+
globals: {
47+
...globals.browser,
48+
},
49+
parserOptions: {
50+
sourceType: 'module',
51+
ecmaVersion: 2020,
52+
ecmaFeatures: {
53+
impliedStrict: true,
54+
experimentalObjectRestSpread: true,
55+
jsx: true,
56+
defaultParams: true,
57+
legacyDecorators: true,
58+
allowImportExportEverywhere: true,
59+
},
60+
},
61+
},
62+
63+
settings: {
64+
'react-x': {
65+
version: '18.3.1',
66+
},
67+
},
68+
69+
rules: {
70+
'github/array-foreach': 0,
71+
'@typescript-eslint/no-invalid-this': 0,
72+
73+
// FIXME A bug with eslint-parser
74+
// 'template-curly-spacing': 'off',
75+
76+
'@stylistic/indent': [
77+
'warn',
78+
2,
79+
{ SwitchCase: 1 },
80+
],
81+
'function-paren-newline': 'off',
82+
'no-mixed-operators': 'off',
83+
'no-await-in-loop': 'off',
84+
'no-lonely-if': 'off',
85+
'no-script-url': 'off',
86+
},
87+
}]);

package.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
"build:pkg": "yarn build:ui && node -r ./register.js build.ts && pkg dist/xcpc-tools.js --targets linux,macos,win --out-path dist/pkg"
1616
},
1717
"devDependencies": {
18-
"@expo-google-fonts/noto-color-emoji": "^0.2.3",
19-
"@expo-google-fonts/noto-sans-sc": "^0.2.3",
20-
"@hydrooj/eslint-config": "^1.1.1",
18+
"@expo-google-fonts/noto-sans-sc": "^0.4.1",
19+
"@hydrooj/eslint-config": "^2.0.0",
2120
"@hydrooj/register": "^1.0.3",
22-
"@hydrooj/utils": "^1.4.29",
23-
"@neutralinojs/neu": "^11.3.0",
24-
"@types/node": "^20.17.1",
25-
"@yao-pkg/pkg": "^5.16.1",
21+
"@hydrooj/utils": "^1.4.34-beta.3",
22+
"@neutralinojs/neu": "^11.4.0",
23+
"@types/node": "^20.17.58",
24+
"@yao-pkg/pkg": "^6.5.1",
25+
"chardet": "^2.1.0",
2626
"dejavu-fonts-ttf": "^2.37.3",
27-
"eslint": "^8.57.1",
28-
"eslint-import-resolver-typescript": "^3.6.3",
29-
"typescript": "5.4.5"
27+
"eslint": "^9.28.0",
28+
"eslint-import-resolver-typescript": "^4.4.2",
29+
"iconv-lite": "^0.6.3",
30+
"postject": "^1.0.0-alpha.6",
31+
"typescript": "5.8.3"
3032
},
3133
"resolutions": {
32-
"formidable": "patch:formidable@npm%3A2.1.2#~/.yarn/patches/formidable-npm-2.1.2-40ba18d67f.patch"
34+
"formidable": "patch:formidable@npm%3A2.1.2#~/.yarn/patches/formidable-npm-2.1.2-40ba18d67f.patch",
35+
"http-proxy@npm:^1.18.1": "patch:http-proxy@npm%3A1.18.1#~/.yarn/patches/http-proxy-npm-1.18.1-a313c479c5.patch"
3336
}
3437
}

packages/machine-setup/frontend/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12-
"@neutralinojs/lib": "^5.4.0",
13-
"vue": "^3.5.12"
12+
"@neutralinojs/lib": "^6.1.0",
13+
"vue": "^3.5.16"
1414
},
1515
"devDependencies": {
16-
"@vitejs/plugin-vue": "^5.1.4",
17-
"naive-ui": "^2.40.1",
18-
"typescript": "5.4.5",
19-
"vite": "^5.4.10",
20-
"vue-tsc": "^2.1.8"
16+
"@vitejs/plugin-vue": "^5.2.4",
17+
"naive-ui": "^2.41.0",
18+
"typescript": "5.8.3",
19+
"vite": "^6.3.5",
20+
"vue-tsc": "^2.2.10"
2121
}
2222
}

packages/machine-setup/neutralino.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"binaryName": "hydro-xcpctools-machine-setup",
4444
"resourcesPath": "/frontend/",
4545
"extensionsPath": "/extensions/",
46-
"binaryVersion": "5.4.0",
46+
"binaryVersion": "5.5.0",
4747
"clientVersion": "5.4.0",
4848
"frontendLibrary": {
4949
"projectPath": "/frontend/",

0 commit comments

Comments
 (0)