Skip to content

Commit

Permalink
Skip paths that are routed to a .d.ts file (#11322)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Mar 24, 2020
1 parent ed06434 commit 7774101
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/next/build/webpack/plugins/jsconfig-paths-plugin.ts
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

0 comments on commit 7774101

Please sign in to comment.