Skip to content

Commit

Permalink
fix: 修复子线程代码丢失
Browse files Browse the repository at this point in the history
  • Loading branch information
陶家行 authored and 桃树 committed Mar 26, 2024
1 parent e035da9 commit 03c56d8
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 82 deletions.
14 changes: 7 additions & 7 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ import("./a.js")

是否修复 flexbugs。

## forkTsChecker

- 类型:`boolean`
- 默认值:`false`

是否开启构建时 ts 校验。

## hash

- 类型:`boolean`
Expand Down Expand Up @@ -429,13 +436,6 @@ function App() {
}
```

## forkTsChecker

- 类型:`boolean`
- 默认值:`false`

是否开启构建时 ts 校验。

## umd

- 类型:`false | string`
Expand Down
17 changes: 17 additions & 0 deletions packages/bundler-okam/fork-ts-checker/child_process_fork.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { TypeChecker } = require('./ts-checker');

const projectRoot = process.argv[2];

async function runTypeCheck() {
const typeChecker = new TypeChecker(projectRoot);
return await typeChecker.check();
}

runTypeCheck()
.then(() => {
process.exit(1);
})
.catch((error) => {
console.error(error);
process.exit(0);
});
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
const { fork } = require('child_process');
const path = require('path');
const { TypeChecker } = require('./ts-checker');

class ForkTsChecker {
constructor(projectRoot) {
this.projectRoot = projectRoot;
}
async runTypeCheck() {
const typeChecker = new TypeChecker(projectRoot);
await typeChecker.check();
}

runTypeCheckInChildProcess() {
const workerScript = path.join(__dirname, 'child_process_fork.js');
const child = fork(workerScript, [projectRoot], {
const child = fork(workerScript, [this.projectRoot], {
stdio: 'inherit',
});

child.on('exit', (code) => {
if (code === 0) {
console.log('Type checking completed successfully.');
if (code === 1) {
console.log('Type checking completed.');
} else {
console.error('Type checking failed.');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/bundler-okam/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const assert = require('assert');
const { createProxy, createHttpsServer } = require('@umijs/bundler-utils');
const lodash = require('lodash');
const chalk = require('chalk');
const { ForkTsChecker } = require('./plugins/fork-ts-checker/index');
const { ForkTsChecker } = require('./fork-ts-checker/index');
const {
createProxyMiddleware,
} = require('@umijs/bundler-utils/compiled/http-proxy-middleware');
Expand Down Expand Up @@ -101,9 +101,9 @@ exports.build = async function (opts) {
}

// 后置 ts 校验,不影响打包速度
if (!!okamConfig.forkTsChecker) {
if (okamConfig.forkTsChecker) {
const forkTypeChecker = new ForkTsChecker(cwd);
forkTypeChecker.runTypeCheck();
forkTypeChecker.runTypeCheckInChildProcess();
}

const statsJsonPath = path.join(cwd, 'dist', 'stats.json');
Expand Down
5 changes: 4 additions & 1 deletion packages/bundler-okam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"publishConfig": {
"registry": "https://registry.antgroup-inc.cn"
},
"repository": "[email protected]:umijs/mako.git"
"repository": "[email protected]:umijs/mako.git",
"devDependencies": {
"typescript": "^5.4.3"
}
}
Loading

0 comments on commit 03c56d8

Please sign in to comment.