fix addon load

This commit is contained in:
undefined committed 2020-07-24 12:33:23 +08:00
1 parent 2e4c818c37
commit 92335d8529
9 files changed
+80 -38

No files matched your search

+23 -1
View File
@@ -1,8 +1,30 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable import/no-dynamic-require */
import os from 'os';
import path from 'path';
import fs from 'fs-extra';
import { argv } from 'yargs';
import { builtinModel } from './common';
import { Entry } from '../loader';
export async function load(call) {
const tmpdir = path.resolve(os.tmpdir(), 'hydro');
const lockfile = path.resolve(tmpdir, 'lock.json');
export async function load(call: Entry) {
if (fs.existsSync(lockfile) && !argv.ignorelock) {
const file = require(lockfile);
console.error(`Lockfile exists, pid=${file.pid}`);
process.exit(1);
}
const context = {
addons: global.addons,
pid: process.pid,
ppid: process.ppid,
};
await fs.writeFile(lockfile, JSON.stringify(context));
global.onDestory.push(() => {
fs.emptyDirSync(tmpdir);
});
require('../lib/i18n');
require('../utils');
require('../error');