Skip to content

Commit

Permalink
fix: ts-build cross directory file filtering
Browse files Browse the repository at this point in the history
paths are problematic. using filePath.startsWith(directoryPath) only really works if directoryPath ends with a seperator. If it's not, filtering might catch files from a directory with a similar name (e.g. "core" and "core-test-kit").
  • Loading branch information
AviVahl committed Sep 4, 2020
1 parent 4d1cf32 commit 203da70
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/build/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, normalize, join, relative, basename } from 'path';
import { dirname, normalize, join, relative, basename, sep } from 'path';
import chalk from 'chalk';
import ts from 'typescript';
import { getCanonicalPath, getNewLine, readAndParseConfigFile } from '@ts-tools/transpile';
Expand Down Expand Up @@ -66,7 +66,7 @@ export function build({ formats, outputDirectoryPath, srcDirectoryPath, configNa
throw ts.formatDiagnosticsWithColorAndContext(errors, formatDiagnosticsHost);
}

const canonicalSrcPath = getCanonicalPath(srcDirectoryPath);
const canonicalSrcPath = ensureTrailingSep(getCanonicalPath(srcDirectoryPath));
const filesInSrcDirectory = fileNames
.map((filePath) => ({ filePath, normalizedFilePath: normalize(filePath) }))
.filter(({ normalizedFilePath }) => getCanonicalPath(normalizedFilePath).startsWith(canonicalSrcPath));
Expand Down Expand Up @@ -158,3 +158,7 @@ function getFileEmitOutput(program: ts.Program, filePath: string): ts.EmitOutput

return { outputFiles: outputFiles, emitSkipped: emitResult.emitSkipped };
}

function ensureTrailingSep(directoryPath: string) {
return directoryPath.endsWith(sep) ? directoryPath : directoryPath + sep;
}

0 comments on commit 203da70

Please sign in to comment.