Skip to content

Commit

Permalink
fix: should reset ETS_REGISTER_PID env after build (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Feb 13, 2023
1 parent 3b2a63d commit d706a31
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/register.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -23,33 +25,38 @@ 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';

// no need to clean in js project
// 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 = '';
}
}

Expand Down

0 comments on commit d706a31

Please sign in to comment.