Skip to content

Commit

Permalink
fix: handle compilerOptions.outDir (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Jun 28, 2022
1 parent d9b789f commit 5301e6b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/parse-tsconfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,21 @@ export function parseTsconfig(
config = merged;
}

if (config.compilerOptions?.baseUrl) {
if (config.compilerOptions) {
const { compilerOptions } = config;

compilerOptions.baseUrl = normalizePath(compilerOptions.baseUrl!);
if (compilerOptions.baseUrl) {
compilerOptions.baseUrl = normalizePath(compilerOptions.baseUrl);
}

if (compilerOptions.outDir) {
if (!Array.isArray(config.exclude)) {
config.exclude = [];
}

config.exclude.push(compilerOptions.outDir);
compilerOptions.outDir = normalizePath(compilerOptions.outDir);
}
}

if (config.files) {
Expand Down
2 changes: 1 addition & 1 deletion src/paths-matcher/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import slash from 'slash';
import type { TsConfigResult } from '../types';
import { isRelativePathPattern } from '../utils/is-relative-path-pattern';
import {
assertStarCount,
isRelativePathPattern,
parsePattern,
isPatternMatch,
} from './utils';
Expand Down
2 changes: 0 additions & 2 deletions src/paths-matcher/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { StarPattern } from './types';

export const isRelativePathPattern = /^\.{1,2}(\/.*)?$/;

const starPattern = /\*/g;

export const assertStarCount = (
Expand Down
1 change: 1 addition & 0 deletions src/utils/is-relative-path-pattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isRelativePathPattern = /^\.{1,2}(\/.*)?$/;
3 changes: 2 additions & 1 deletion src/utils/normalize-path.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import slash from 'slash';
import { isRelativePathPattern } from './is-relative-path-pattern';

export const normalizePath = (filePath: string) => slash(
/^[./]/.test(filePath)
isRelativePathPattern.test(filePath)
? filePath
: `./${filePath}`,
);
2 changes: 1 addition & 1 deletion tests/specs/get-tsconfig/parses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default testSuite(({ describe }) => {
module: 'esnext',
esModuleInterop: true,
declaration: true,
// outDir: 'dist',
outDir: 'dist',
strict: true,
target: 'esnext',
},
Expand Down

0 comments on commit 5301e6b

Please sign in to comment.