Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only filter ignored paths from module specifier generation if there exists a better option #43024

Merged
merged 3 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,12 @@ namespace ts.moduleSpecifiers {
const redirects = host.redirectTargetsMap.get(importedPath) || emptyArray;
const importedFileNames = [...(referenceRedirect ? [referenceRedirect] : emptyArray), importedFileName, ...redirects];
const targets = importedFileNames.map(f => getNormalizedAbsolutePath(f, cwd));
let filterIgnoredPaths = some(targets, not(containsIgnoredPath));
andrewbranch marked this conversation as resolved.
Show resolved Hide resolved

if (!preferSymlinks) {
// Symlinks inside ignored paths are already filtered out of the symlink cache,
// so we only need to remove them from the realpath filenames.
const result = forEach(targets, p => !containsIgnoredPath(p) && cb(p, referenceRedirect === p));
const result = forEach(targets, p => !(filterIgnoredPaths && containsIgnoredPath(p)) && cb(p, referenceRedirect === p));
if (result) return result;
}
const links = host.getSymlinkCache
Expand All @@ -312,12 +314,13 @@ namespace ts.moduleSpecifiers {
for (const symlinkDirectory of symlinkDirectories) {
const option = resolvePath(symlinkDirectory, relative);
const result = cb(option, target === referenceRedirect);
filterIgnoredPaths = true; // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
if (result) return result;
}
});
});
return result || (preferSymlinks
? forEach(targets, p => containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect))
? forEach(targets, p => filterIgnoredPaths && containsIgnoredPath(p) ? undefined : cb(p, p === referenceRedirect))
: undefined);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/baselines/reference/nodeModuleReexportFromDottedPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/compiler/nodeModuleReexportFromDottedPath.ts] ////

//// [index.d.ts]
export interface PrismaClientOptions {
rejectOnNotFound?: any;
}

export class PrismaClient<T extends PrismaClientOptions = PrismaClientOptions> {
private fetcher;
}

//// [index.d.ts]
export * from ".prisma/client";

//// [index.ts]
import { PrismaClient } from "@prisma/client";
declare const enhancePrisma: <TPrismaClientCtor>(client: TPrismaClientCtor) => TPrismaClientCtor & { enhanced: unknown };
const EnhancedPrisma = enhancePrisma(PrismaClient);
export default new EnhancedPrisma();


//// [index.js]
"use strict";
exports.__esModule = true;
var client_1 = require("@prisma/client");
var EnhancedPrisma = enhancePrisma(client_1.PrismaClient);
exports["default"] = new EnhancedPrisma();


//// [index.d.ts]
import { PrismaClient } from "@prisma/client";
declare const _default: PrismaClient<import(".prisma/client").PrismaClientOptions>;
export default _default;
41 changes: 41 additions & 0 deletions tests/baselines/reference/nodeModuleReexportFromDottedPath.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== /node_modules/.prisma/client/index.d.ts ===
export interface PrismaClientOptions {
>PrismaClientOptions : Symbol(PrismaClientOptions, Decl(index.d.ts, 0, 0))

rejectOnNotFound?: any;
>rejectOnNotFound : Symbol(PrismaClientOptions.rejectOnNotFound, Decl(index.d.ts, 0, 38))
}

export class PrismaClient<T extends PrismaClientOptions = PrismaClientOptions> {
>PrismaClient : Symbol(PrismaClient, Decl(index.d.ts, 2, 1))
>T : Symbol(T, Decl(index.d.ts, 4, 26))
>PrismaClientOptions : Symbol(PrismaClientOptions, Decl(index.d.ts, 0, 0))
>PrismaClientOptions : Symbol(PrismaClientOptions, Decl(index.d.ts, 0, 0))

private fetcher;
>fetcher : Symbol(PrismaClient.fetcher, Decl(index.d.ts, 4, 80))
}

=== /node_modules/@prisma/client/index.d.ts ===
export * from ".prisma/client";
No type information for this code.
No type information for this code.=== /index.ts ===
import { PrismaClient } from "@prisma/client";
>PrismaClient : Symbol(PrismaClient, Decl(index.ts, 0, 8))

declare const enhancePrisma: <TPrismaClientCtor>(client: TPrismaClientCtor) => TPrismaClientCtor & { enhanced: unknown };
>enhancePrisma : Symbol(enhancePrisma, Decl(index.ts, 1, 13))
>TPrismaClientCtor : Symbol(TPrismaClientCtor, Decl(index.ts, 1, 30))
>client : Symbol(client, Decl(index.ts, 1, 49))
>TPrismaClientCtor : Symbol(TPrismaClientCtor, Decl(index.ts, 1, 30))
>TPrismaClientCtor : Symbol(TPrismaClientCtor, Decl(index.ts, 1, 30))
>enhanced : Symbol(enhanced, Decl(index.ts, 1, 100))

const EnhancedPrisma = enhancePrisma(PrismaClient);
>EnhancedPrisma : Symbol(EnhancedPrisma, Decl(index.ts, 2, 5))
>enhancePrisma : Symbol(enhancePrisma, Decl(index.ts, 1, 13))
>PrismaClient : Symbol(PrismaClient, Decl(index.ts, 0, 8))

export default new EnhancedPrisma();
>EnhancedPrisma : Symbol(EnhancedPrisma, Decl(index.ts, 2, 5))

35 changes: 35 additions & 0 deletions tests/baselines/reference/nodeModuleReexportFromDottedPath.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== /node_modules/.prisma/client/index.d.ts ===
export interface PrismaClientOptions {
rejectOnNotFound?: any;
>rejectOnNotFound : any
}

export class PrismaClient<T extends PrismaClientOptions = PrismaClientOptions> {
>PrismaClient : PrismaClient<T>

private fetcher;
>fetcher : any
}

=== /node_modules/@prisma/client/index.d.ts ===
export * from ".prisma/client";
No type information for this code.
No type information for this code.=== /index.ts ===
import { PrismaClient } from "@prisma/client";
>PrismaClient : typeof PrismaClient

declare const enhancePrisma: <TPrismaClientCtor>(client: TPrismaClientCtor) => TPrismaClientCtor & { enhanced: unknown };
>enhancePrisma : <TPrismaClientCtor>(client: TPrismaClientCtor) => TPrismaClientCtor & { enhanced: unknown; }
>client : TPrismaClientCtor
>enhanced : unknown

const EnhancedPrisma = enhancePrisma(PrismaClient);
>EnhancedPrisma : typeof PrismaClient & { enhanced: unknown; }
>enhancePrisma(PrismaClient) : typeof PrismaClient & { enhanced: unknown; }
>enhancePrisma : <TPrismaClientCtor>(client: TPrismaClientCtor) => TPrismaClientCtor & { enhanced: unknown; }
>PrismaClient : typeof PrismaClient

export default new EnhancedPrisma();
>new EnhancedPrisma() : PrismaClient<import("/node_modules/.prisma/client/index").PrismaClientOptions>
>EnhancedPrisma : typeof PrismaClient & { enhanced: unknown; }

19 changes: 19 additions & 0 deletions tests/cases/compiler/nodeModuleReexportFromDottedPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @declaration: true

// @Filename: /node_modules/.prisma/client/index.d.ts
export interface PrismaClientOptions {
rejectOnNotFound?: any;
}

export class PrismaClient<T extends PrismaClientOptions = PrismaClientOptions> {
private fetcher;
}

// @Filename: /node_modules/@prisma/client/index.d.ts
export * from ".prisma/client";

// @Filename: /index.ts
import { PrismaClient } from "@prisma/client";
declare const enhancePrisma: <TPrismaClientCtor>(client: TPrismaClientCtor) => TPrismaClientCtor & { enhanced: unknown };
const EnhancedPrisma = enhancePrisma(PrismaClient);
export default new EnhancedPrisma();