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

Skip paths that are routed to a .d.ts file #11322

Merged
merged 1 commit into from Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -174,6 +174,12 @@ export class JsConfigPathsPlugin implements ResolvePlugin {

for (const subst of paths[matchedPatternText]) {
const path = matchedStar ? subst.replace('*', matchedStar) : subst

// Ensure .d.ts is not matched
if (path.endsWith('.d.ts')) {
continue
}

const candidate = join(baseDirectory, path)
const [err, result] = await new Promise((resolve, reject) => {
const obj = Object.assign({}, request, {
Expand Down
@@ -0,0 +1 @@
export default () => any
@@ -0,0 +1,3 @@
export default () => {
return <>Not aliased to d.ts file</>
}
10 changes: 10 additions & 0 deletions test/integration/typescript-paths/pages/alias-to-d-ts.tsx
@@ -0,0 +1,10 @@
import React from 'react'
import NotAliasedToDTS from 'd-ts-alias'

export default function HelloPage(): JSX.Element {
return (
<div>
<NotAliasedToDTS />
</div>
)
}
5 changes: 5 additions & 0 deletions test/integration/typescript-paths/test/index.test.js
Expand Up @@ -42,5 +42,10 @@ describe('TypeScript Features', () => {
const $ = await get$('/single-alias')
expect($('body').text()).toMatch(/Hello/)
})

it('should not resolve to .d.ts files', async () => {
const $ = await get$('/alias-to-d-ts')
expect($('body').text()).toMatch(/Not aliased to d\.ts file/)
})
})
})
7 changes: 6 additions & 1 deletion test/integration/typescript-paths/tsconfig.json
Expand Up @@ -2,9 +2,14 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"isomorphic-unfetch": ["types/unfetch.d.ts"],
"@c/*": ["components/*"],
"@lib/*": ["lib/a/*", "lib/b/*"],
"@mycomponent": ["components/hello.tsx"]
"@mycomponent": ["components/hello.tsx"],
"d-ts-alias": [
"components/alias-to-d-ts.d.ts",
"components/alias-to-d-ts.tsx"
]
},
"esModuleInterop": true,
"module": "esnext",
Expand Down