Skip to content

Commit

Permalink
fix: tsconfig.json with extends config
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Mar 2, 2024
1 parent ba93839 commit 3826619
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 168 deletions.
13 changes: 10 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ const {
copyFilesRecursive,
output,
colors,
debug
debug,
} = require('./util');
const path = require('path');
const { replaceTscAliasPaths } = require('tsc-alias');
const chokidar = require('chokidar');

function getRelativeDir(rootDir, filePathDir) {
if (!filePathDir) {
return filePathDir;
}
return path.relative(rootDir, filePathDir);
}

function run() {
const [runCmd, tscArgs, runArgs, isCleanDirectory] = parseArgs(process.argv);
const cwd = process.cwd();
Expand Down Expand Up @@ -52,10 +59,10 @@ function run() {
}

if (tsconfig.options) {
outDir = tsconfig.options.outDir;
outDir = getRelativeDir(cwd, tsconfig.options.outDir);
// 解析出来的 tsconfig.json 中的 allowJs 优先级更高
allowJs = tsconfig.options.allowJs;
sourceDir = tsconfig.options.rootDir || sourceDir;
sourceDir = getRelativeDir(cwd, tsconfig.options.rootDir) || sourceDir;
// 判断是否需要启动 tsc-alias
hasPaths = !!(
tsconfig.options.paths && Object.keys(tsconfig.options.paths).length > 0
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mwtsc",
"version": "1.7.0",
"version": "1.7.1-beta.1",
"description": "tsc wrapper for midway development",
"main": "lib/index.js",
"bin": {
Expand All @@ -14,9 +14,9 @@
},
"devDependencies": {
"execa": "^5.1.1",
"jest": "^29.4.1",
"jest": "^29.7.0",
"mwts": "^1.3.0",
"typescript": "~4.9.0"
"typescript": "~4.9.5"
},
"engines": {
"node": ">=12.0.0"
Expand Down
155 changes: 0 additions & 155 deletions test/__snapshots__/util.test.js.snap

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/ts_config/tsconfig_extend.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"paths": {
"##/*": ["src/*"],
"#a/*": ["src/app/*"],
"#@/*": ["test/*"]
},
}
}
8 changes: 6 additions & 2 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ describe('test/util.test.js', () => {

it('should test read tsconfig file', () => {
const data = readJSONCFile(path.join(__dirname, 'fixtures/ts_config/tsconfig.json'));
expect(data).toMatchSnapshot();
expect(data.options).toBeDefined();
expect(data.raw).toBeDefined();
});

it('should test read tsconfig file with extends', () => {
const data = readJSONCFile(path.join(__dirname, 'fixtures/ts_config/tsconfig_extend.json'));
expect(data).toMatchSnapshot();
expect(data.options).toBeDefined();
expect(data.options.paths).toBeDefined();
expect(data.raw).toBeDefined();
expect(data.raw.paths).not.toBeDefined();
});

});

0 comments on commit 3826619

Please sign in to comment.