diff --git a/src/register.ts b/src/register.ts index d9d8dfb..610ae5c 100644 --- a/src/register.ts +++ b/src/register.ts @@ -1,7 +1,9 @@ import cluster from 'cluster'; import { debuglog } from 'util'; import TsHelper, { TsHelperOption } from './core'; -import * as util from './utils'; +import { + convertString, checkMaybeIsJsProj, writeJsConfig, cleanJs, +} from './utils'; const debug = debuglog('egg-ts-helper#register'); @@ -23,17 +25,18 @@ export default class Register { // make sure ets only run once const pid = process.env.ETS_REGISTER_PID; if (pid) { - return debug('egg-ts-helper watcher has ran in %s', pid); + debug('egg-ts-helper watcher has ran in %s', pid); + return; } - const watch = util.convertString(process.env.ETS_WATCH, process.env.NODE_ENV !== 'test'); + const watch = convertString(process.env.ETS_WATCH, process.env.NODE_ENV !== 'test'); const clazz = this.tsHelperClazz; const cwd = options?.cwd || process.cwd(); const instance = new clazz({ watch, ...options }); - if (util.checkMaybeIsJsProj(cwd)) { + if (checkMaybeIsJsProj(cwd)) { // write jsconfig if the project is wrote by js - util.writeJsConfig(cwd); + writeJsConfig(cwd); } else { const tsNodeMode = process.env.EGG_TYPESCRIPT === 'true'; @@ -41,15 +44,19 @@ export default class Register { // clean local js file at first. // because egg-loader cannot load the same property name to egg. if (tsNodeMode && instance.config.autoRemoveJs) { - util.cleanJs(cwd); + cleanJs(cwd); } } // cache pid to env, prevent child process executing ets again process.env.ETS_REGISTER_PID = `${process.pid}`; + debug('start buidling'); // exec building instance.build(); + debug('end'); + // reset ETS_REGISTER_PID + process.env.ETS_REGISTER_PID = ''; } }