chore: 后端首次基线提交
运行必须源码:app/(controller/model/service/middleware/lib/utils/validate/router)、config/、database/(migrations/seeders/sql)、启动脚本、app/public/templates 模板。 已忽略运行非必须:node_modules/、logs/、run/、app/public 运行时上传数据、.env*、构建/缓存产物。
This commit is contained in:
87
egg-compat-patch.js
Normal file
87
egg-compat-patch.js
Normal file
@@ -0,0 +1,87 @@
|
||||
// egg-compat-patch.js
|
||||
// 批量扫描并修复 egg.js v3 在 Node 22 下的全部缺失依赖
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const BASE = path.resolve(__dirname, 'node_modules');
|
||||
|
||||
// === 已知缺失依赖 + shim 内容 ===
|
||||
const SHIMS = {
|
||||
'serialize-json': {
|
||||
package: { name: 'serialize-json', version: '2.0.0', main: 'index.js' },
|
||||
index: `'use strict';
|
||||
// shim: serialize-json → native JSON
|
||||
module.exports = JSON;
|
||||
module.exports.parse = JSON.parse;
|
||||
module.exports.stringify = JSON.stringify;
|
||||
`
|
||||
},
|
||||
'sdk-base': {
|
||||
package: { name: 'sdk-base', version: '4.0.0', main: 'index.js' },
|
||||
index: `'use strict';
|
||||
const EventEmitter = require('events');
|
||||
class Base extends EventEmitter {
|
||||
constructor(opts) { super(); this.options = opts || {}; }
|
||||
ready(cb) { if (cb) cb(); return Promise.resolve(); }
|
||||
}
|
||||
module.exports = Base;
|
||||
`
|
||||
},
|
||||
'tcp-base': {
|
||||
package: { name: 'tcp-base', version: '4.0.0', main: 'index.js' },
|
||||
index: `'use strict';
|
||||
const sdkBase = require('sdk-base');
|
||||
class TCPBase extends sdkBase {
|
||||
constructor(opts) { super(opts); }
|
||||
async close() {}
|
||||
async connect() {}
|
||||
}
|
||||
module.exports = TCPBase;
|
||||
`
|
||||
},
|
||||
'await-first': {
|
||||
package: { name: 'await-first', version: '1.0.0', main: 'index.js' },
|
||||
index: `'use strict';
|
||||
module.exports = async function awaitFirst(emitter, event) {
|
||||
return new Promise((resolve) => {
|
||||
emitter.once(event, resolve);
|
||||
});
|
||||
};
|
||||
`
|
||||
},
|
||||
'co': {
|
||||
package: { name: 'co', version: '4.6.0', main: 'index.js' },
|
||||
index: `'use strict';
|
||||
// co shim: use Promise for basic generator support
|
||||
module.exports = function co(gen) {
|
||||
if (typeof gen === 'function') gen = gen();
|
||||
if (!gen || typeof gen.next !== 'function') return Promise.resolve(gen);
|
||||
return new Promise((resolve, reject) => {
|
||||
function step(next) {
|
||||
try {
|
||||
const result = next();
|
||||
if (result.done) return resolve(result.value);
|
||||
Promise.resolve(result.value).then(v => step(() => gen.next(v)), e => step(() => gen.throw(e)));
|
||||
} catch (e) { reject(e); }
|
||||
}
|
||||
step(() => gen.next());
|
||||
});
|
||||
};
|
||||
`
|
||||
},
|
||||
};
|
||||
|
||||
// 创建所有 shim
|
||||
for (const [name, files] of Object.entries(SHIMS)) {
|
||||
const dir = path.join(BASE, name);
|
||||
if (fs.existsSync(dir)) {
|
||||
console.log(`[SKIP] ${name} already exists`);
|
||||
continue;
|
||||
}
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(files.package, null, 2));
|
||||
fs.writeFileSync(path.join(dir, 'index.js'), files.index);
|
||||
console.log(`[CREATED] ${name}`);
|
||||
}
|
||||
|
||||
console.log('\n=== 补丁应用完成 ===');
|
||||
Reference in New Issue
Block a user