Skip to content

Commit

Permalink
chore: optimization kill app speed (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Mar 7, 2024
1 parent 027a0c7 commit 588ec2e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
36 changes: 20 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,28 @@ function run() {
debug(`hasPaths: ${hasPaths}`);

let runChild;
const restart = debounce(() => {
const restart = debounce(async () => {
if (fileChangeList.length === 0) return;
if (hasPaths) {
// 这里使用全量替换,tsc 增量编译会把老文件修改回去
replaceTscAliasPaths({
configFile: tsconfigPath,
outDir,
});
// 避免重复触发文件变化
isCompileSuccess = false;
async function aliasReplace() {
if (hasPaths) {
// 这里使用全量替换,tsc 增量编译会把老文件修改回去
await replaceTscAliasPaths({
configFile: tsconfigPath,
outDir,
});
// 避免重复触发文件变化
isCompileSuccess = false;
}
output(
`${fileChangeList.length} ${colors.dim('Files has been changed.')}`,
true
);
// 清空文件列表
fileChangeList.length = 0;
}
output(
`${fileChangeList.length} ${colors.dim('Files has been changed.')}`,
true
);
// 清空文件列表
fileChangeList.length = 0;
runChild && runChild.restart();

await Promise.all([runChild && runChild.kill(), aliasReplace()]);
runChild && runChild.forkChild();
}, 1000);

function runAfterTsc() {
Expand Down
11 changes: 9 additions & 2 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ const forkRun = (runCmdPath, runArgs = [], options = {}) => {
try {
if (data.title === 'server-ready') {
onServerReadyCallback &&
await onServerReadyCallback(data, isFirstFork, Date.now() - startTime);
(await onServerReadyCallback(
data,
isFirstFork,
Date.now() - startTime
));
runChild.removeListener('message', onServerReady);
}
} catch (err) {
Expand Down Expand Up @@ -114,7 +118,10 @@ const forkRun = (runCmdPath, runArgs = [], options = {}) => {
// 杀进程
await killRunningChild();
// 重新拉起来
innerFork();
innerFork(false);
},
forkChild() {
innerFork(false);
},
onServerReady(readyCallback) {
onServerReadyCallback = readyCallback;
Expand Down

0 comments on commit 588ec2e

Please sign in to comment.