core: loader: set addon prio

This commit is contained in:
undefined committed 2021-05-24 22:06:12 +08:00
1 parent 27ef93a1d0
commit eaa03e594b
4 files changed
+17 -14

No files matched your search

+4 -3
View File
@@ -15,12 +15,13 @@
"lint:ci": "eslint packages --ext ts", "lint:ci": "eslint packages --ext ts",
"lint:ui": "yarn run --cwd=packages/ui-default eslint . --fix", "lint:ui": "yarn run --cwd=packages/ui-default eslint . --fix",
"lint:ui:ci": "yarn run --cwd=packages/ui-default eslint .", "lint:ui:ci": "yarn run --cwd=packages/ui-default eslint .",
"snowpack": "cd packages/ui-default && snowpack dev",
"pub": "node build/publish", "pub": "node build/publish",
"jest": "node build/jest", "jest": "node build/jest",
"typedoc": "cross-env NODE_OPTIONS=--max_old_space_size=8192 typedoc", "typedoc": "cross-env NODE_OPTIONS=--max_old_space_size=8192 typedoc",
"debug": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start --debug --template", "debug:all": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start --debug --template",
"start": "node build/start", "debug": "node --async-stack-traces --trace-deprecation --enable-source-maps node_modules/.bin/hydrooj --debug --template",
"start:all": "node build/start",
"start": "node node_modules/.bin/hydrooj",
"clean": "zsh -c \"rm -rf tsconfig.build.tsbuildinfo ./packages/*/tsconfig.tsbuildinfo ./packages/*/dist ./.coverage\"" "clean": "zsh -c \"rm -rf tsconfig.build.tsbuildinfo ./packages/*/tsconfig.tsbuildinfo ./packages/*/dist ./.coverage\""
}, },
"version": "1.0.0", "version": "1.0.0",
+8 -7
View File
@@ -7,6 +7,14 @@ const fs = require('fs-extra');
const { argv } = require('yargs'); const { argv } = require('yargs');
const child = require('child_process'); const child = require('child_process');
function buildUrl(opts) {
let mongourl = `${opts.protocol || 'mongodb'}://`;
if (opts.username) mongourl += `${opts.username}:${opts.password}@`;
mongourl += `${opts.host}:${opts.port}/${opts.name}`;
if (opts.url) mongourl = opts.url;
return mongourl;
}
if (!cluster.isMaster) { if (!cluster.isMaster) {
const hydro = require('../dist/loader'); const hydro = require('../dist/loader');
// Forked by hydro // Forked by hydro
@@ -22,13 +30,6 @@ if (!cluster.isMaster) {
let addons = JSON.parse(fs.readFileSync(addonPath).toString()); let addons = JSON.parse(fs.readFileSync(addonPath).toString());
if (argv._[0] === 'db') { if (argv._[0] === 'db') {
function buildUrl(opts) {
let mongourl = `${opts.protocol || 'mongodb'}://`;
if (opts.username) mongourl += `${opts.username}:${opts.password}@`;
mongourl += `${opts.host}:${opts.port}/${opts.name}`;
if (opts.url) mongourl = opts.url;
return mongourl;
}
const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8'); const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8');
const url = buildUrl(JSON.parse(dbConfig)); const url = buildUrl(JSON.parse(dbConfig));
return child.spawn('mongo', [url], { stdio: 'inherit' }); return child.spawn('mongo', [url], { stdio: 'inherit' });
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.26.28", "version": "2.26.29",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+4 -3
View File
@@ -135,7 +135,7 @@ process.on('uncaughtException', logger.error);
const publicTemp = path.resolve(os.tmpdir(), 'hydro', 'public'); const publicTemp = path.resolve(os.tmpdir(), 'hydro', 'public');
export function addon(addonPath: string) { export function addon(addonPath: string, prepend = false) {
if (!(fs.existsSync(addonPath) && fs.statSync(addonPath).isFile())) { if (!(fs.existsSync(addonPath) && fs.statSync(addonPath).isFile())) {
try { try {
// Is a npm package // Is a npm package
@@ -143,7 +143,8 @@ export function addon(addonPath: string) {
const modulePath = path.dirname(packagejson); const modulePath = path.dirname(packagejson);
const publicPath = path.resolve(modulePath, 'public'); const publicPath = path.resolve(modulePath, 'public');
if (fs.existsSync(publicPath)) fs.copySync(publicPath, publicTemp); if (fs.existsSync(publicPath)) fs.copySync(publicPath, publicTemp);
global.addons.push(modulePath); if (prepend) global.addons.unshift(modulePath);
else global.addons.push(modulePath);
} catch (e) { } catch (e) {
logger.error(`Addon not found: ${addonPath}`); logger.error(`Addon not found: ${addonPath}`);
} }
@@ -151,7 +152,7 @@ export function addon(addonPath: string) {
} }
export async function load() { export async function load() {
addon(path.resolve(__dirname, '..')); addon(path.resolve(__dirname, '..'), true);
Error.stackTraceLimit = 50; Error.stackTraceLimit = 50;
if (cluster.isMaster || argv.startAsMaster) { if (cluster.isMaster || argv.startAsMaster) {
logger.info(`Master ${process.pid} Starting`); logger.info(`Master ${process.pid} Starting`);