Skip to content

Commit f944914

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 9da972b + e9b2a9f commit f944914

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/transformer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export default function transformer(
2828

2929
if (!pathsBasePath || !compilerOptions.paths) return (sourceFile: ts.SourceFile) => sourceFile;
3030

31+
const { configFile, paths } = compilerOptions;
32+
// TODO - Remove typecast when tryParsePatterns is recognized (probably after ts v4.4)
33+
const { tryParsePatterns } = tsInstance as any;
34+
3135
const tsTransformPathsContext: TsTransformPathsContext = {
3236
compilerOptions,
3337
config,
@@ -43,6 +47,11 @@ export default function transformer(
4347
excludeMatchers: config.exclude?.map((globPattern) => new Minimatch(globPattern, { matchBase: true })),
4448
parsedCommandLine: createParsedCommandLineForProgram(tsInstance, program),
4549
outputFileNamesCache: new Map(),
50+
// Get paths patterns appropriate for TS compiler version
51+
pathsPatterns: tryParsePatterns
52+
// TODO - Remove typecast when pathPatterns is recognized (probably after ts v4.4)
53+
? (configFile?.configFileSpecs as any)?.pathPatterns || tryParsePatterns(paths)
54+
: tsInstance.getOwnKeys(paths)
4655
};
4756

4857
return (sourceFile: ts.SourceFile) => {

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tsThree from "./declarations/typescript3";
2-
import ts, { CompilerOptions, GetCanonicalFileName, ParsedCommandLine } from "typescript";
2+
import ts, { CompilerOptions, GetCanonicalFileName, ParsedCommandLine, Pattern } from "typescript";
33
import { PluginConfig } from "ts-patch";
44
import { HarmonyFactory } from "./utils/harmony-factory";
55
import { IMinimatch } from "minimatch";
@@ -51,6 +51,7 @@ export interface TsTransformPathsContext {
5151
readonly outputFileNamesCache: Map<string, string>;
5252
readonly pathsBasePath: string;
5353
readonly getCanonicalFileName: GetCanonicalFileName;
54+
readonly pathsPatterns: (string | Pattern)[]
5455
}
5556

5657
export interface VisitorContext extends TsTransformPathsContext {

src/utils/ts-helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ export function getOutputFile(context: VisitorContext, fileName: string): string
6565
* Determine if moduleName matches config in paths
6666
*/
6767
export function isModulePathsMatch(context: VisitorContext, moduleName: string): boolean {
68-
const { matchPatternOrExact, getOwnKeys } = context.tsInstance;
69-
return !!matchPatternOrExact(getOwnKeys(context.compilerOptions.paths!), moduleName);
68+
const { pathsPatterns, tsInstance: { matchPatternOrExact }} = context
69+
// TODO - Remove typecast after ts v4.4
70+
return !!matchPatternOrExact((pathsPatterns as any), moduleName);
7071
}
7172

7273
export function isTsProjectSourceFile(context: VisitorContext, filePath: string): boolean {

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4574,9 +4574,9 @@ [email protected]:
45744574
signal-exit "^3.0.2"
45754575

45764576
ws@^5.2.0:
4577-
version "5.2.2"
4578-
resolved "https://registry.yarnpkg.com/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f"
4579-
integrity sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==
4577+
version "5.2.3"
4578+
resolved "https://registry.yarnpkg.com/ws/-/ws-5.2.3.tgz#05541053414921bc29c63bee14b8b0dd50b07b3d"
4579+
integrity sha512-jZArVERrMsKUatIdnLzqvcfydI85dvd/Fp1u/VOpfdDWQ4c9qWXe+VIeAbQ5FrDwciAkr+lzofXLz3Kuf26AOA==
45804580
dependencies:
45814581
async-limiter "~1.0.0"
45824582

0 commit comments

Comments
 (0)