格式化:Prettier统一代码风格(仅格式,无逻辑变化)
仅为 npm run format 的输出;黄金对照、旧库兼容、浏览器流程与单元测试全部通过且零差异。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3743d687e7
commit
28c64814f0
221 files changed
+116943
-26708
No files matched your search
@@ -1,29 +1,49 @@
|
||||
'use strict';
|
||||
// 由 lib/server.js 以 fork + --require fake-clock.cjs 启动;只通过 IPC 接受启动/停止指令。
|
||||
// 启动参数来自环境变量 E2E_SERVER_OPTIONS(JSON):{mode,dataDir,startup:'create'|'production'}
|
||||
const path=require('node:path');
|
||||
const appDir=path.join(__dirname,'..','..');
|
||||
const options=JSON.parse(process.env.E2E_SERVER_OPTIONS||'{}');
|
||||
const send=message=>process.send&&process.send(message);
|
||||
let app=null;
|
||||
async function start(){
|
||||
const server=require(path.join(appDir,'server.js'));
|
||||
let startup={};
|
||||
if(options.startup==='production'){
|
||||
const path = require('node:path');
|
||||
const appDir = path.join(__dirname, '..', '..');
|
||||
const options = JSON.parse(process.env.E2E_SERVER_OPTIONS || '{}');
|
||||
const send = message => process.send && process.send(message);
|
||||
let app = null;
|
||||
async function start() {
|
||||
const server = require(path.join(appDir, 'server.js'));
|
||||
let startup = {};
|
||||
if (options.startup === 'production') {
|
||||
// 与 server.js 正式入口一致:先备份升级前旧库,再 createApp,再显式迁移,最后监听。
|
||||
startup.team=await server.prepareTeamStartupDatabase(options.dataDir);
|
||||
app=server.createApp({mode:options.mode,dataDir:options.dataDir,host:'127.0.0.1',port:0});
|
||||
startup.migration=await server.prepareStartupMigrations(app);
|
||||
}else{
|
||||
app=server.createApp({mode:options.mode||'trial',dataDir:options.dataDir,host:'127.0.0.1',port:0,inventorySnapshotLogger:()=>{}});
|
||||
startup.team = await server.prepareTeamStartupDatabase(options.dataDir);
|
||||
app = server.createApp({ mode: options.mode, dataDir: options.dataDir, host: '127.0.0.1', port: 0 });
|
||||
startup.migration = await server.prepareStartupMigrations(app);
|
||||
} else {
|
||||
app = server.createApp({
|
||||
mode: options.mode || 'trial',
|
||||
dataDir: options.dataDir,
|
||||
host: '127.0.0.1',
|
||||
port: 0,
|
||||
inventorySnapshotLogger: () => {},
|
||||
});
|
||||
}
|
||||
await new Promise((resolve,reject)=>{app.server.once('error',reject);app.server.listen(0,'127.0.0.1',resolve);});
|
||||
send({type:'ready',port:app.server.address().port,startup});
|
||||
await new Promise((resolve, reject) => {
|
||||
app.server.once('error', reject);
|
||||
app.server.listen(0, '127.0.0.1', resolve);
|
||||
});
|
||||
send({ type: 'ready', port: app.server.address().port, startup });
|
||||
}
|
||||
process.on('message',async message=>{
|
||||
if(message?.type!=='stop')return;
|
||||
try{if(app){app.stop();app.ledger.close();}}catch(error){send({type:'log',message:'stop: '+error.message});}
|
||||
send({type:'stopped'});setTimeout(()=>process.exit(0),20);
|
||||
process.on('message', async message => {
|
||||
if (message?.type !== 'stop') return;
|
||||
try {
|
||||
if (app) {
|
||||
app.stop();
|
||||
app.ledger.close();
|
||||
}
|
||||
} catch (error) {
|
||||
send({ type: 'log', message: 'stop: ' + error.message });
|
||||
}
|
||||
send({ type: 'stopped' });
|
||||
setTimeout(() => process.exit(0), 20);
|
||||
});
|
||||
process.on('disconnect', () => process.exit(0));
|
||||
start().catch(error => {
|
||||
send({ type: 'fatal', message: error.stack || String(error) });
|
||||
setTimeout(() => process.exit(1), 20);
|
||||
});
|
||||
process.on('disconnect',()=>process.exit(0));
|
||||
start().catch(error=>{send({type:'fatal',message:error.stack||String(error)});setTimeout(()=>process.exit(1),20);});
|
||||
Reference in new issue
Block a user