forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improves baseUrl resolution in typescript monorepos
Typescript configuration can inherit from files above cwd in the filesystem. If a baseUrl was declared in such a file, it would not be picked up by the webpack config. This would force users to use the next-transpile-module and duplicate configuration with unintuitive path relations (see vercel#13197 for a detailed analysis) If baseUrl is resolved it should be used instead of dir as the root include for babel-resolve-loader.
- Loading branch information
Showing
17 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/integration/typescript-workspaces-paths/packages/lib/a/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'Hello from a' |
1 change: 1 addition & 0 deletions
1
test/integration/typescript-workspaces-paths/packages/lib/b/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'Hello from b' |
1 change: 1 addition & 0 deletions
1
test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'Hello from only b' |
1 change: 1 addition & 0 deletions
1
test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => any |
3 changes: 3 additions & 0 deletions
3
test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default () => { | ||
return <>Not aliased to d.ts file</> | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
|
||
export function Hello() { | ||
return <>Hello</> | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/typescript-workspaces-paths/packages/www/components/world.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
|
||
export function World(): JSX.Element { | ||
return <>World</> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/integration/typescript-workspaces-paths/packages/www/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
webpack: function (config) { | ||
return config | ||
}, | ||
onDemandEntries: { | ||
// Make sure entries are not getting disposed. | ||
maxInactiveAge: 1000 * 60 * 60, | ||
}, | ||
} |
10 changes: 10 additions & 0 deletions
10
test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
import NotAliasedToDTS from 'd-ts-alias' | ||
|
||
export default function HelloPage(): JSX.Element { | ||
return ( | ||
<div> | ||
<NotAliasedToDTS /> | ||
</div> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/integration/typescript-workspaces-paths/packages/www/pages/basic-alias.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import { World } from '@c/world' | ||
export default function HelloPage(): JSX.Element { | ||
return ( | ||
<div> | ||
<World /> | ||
</div> | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/typescript-workspaces-paths/packages/www/pages/resolve-fallback.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
import api from '@lib/b-only' | ||
export default function ResolveOrder(): JSX.Element { | ||
return <div>{api()}</div> | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/typescript-workspaces-paths/packages/www/pages/resolve-order.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
import api from '@lib/api' | ||
export default function ResolveOrder(): JSX.Element { | ||
return <div>{api()}</div> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/integration/typescript-workspaces-paths/packages/www/pages/single-alias.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Hello } from '@mycomponent' | ||
|
||
export default function SingleAlias() { | ||
return ( | ||
<div> | ||
<Hello /> | ||
</div> | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
test/integration/typescript-workspaces-paths/packages/www/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import cheerio from 'cheerio' | ||
import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '..') | ||
let appPort | ||
let app | ||
|
||
async function get$(path, query) { | ||
const html = await renderViaHTTP(appPort, path, query) | ||
return cheerio.load(html) | ||
} | ||
|
||
describe('TypeScript Features', () => { | ||
describe('default behavior', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort, {}) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
it('should alias components', async () => { | ||
const $ = await get$('/basic-alias') | ||
expect($('body').text()).toMatch(/World/) | ||
}) | ||
|
||
it('should resolve the first item in the array first', async () => { | ||
const $ = await get$('/resolve-order') | ||
expect($('body').text()).toMatch(/Hello from a/) | ||
}) | ||
|
||
it('should resolve the second item in as a fallback', async () => { | ||
const $ = await get$('/resolve-fallback') | ||
expect($('body').text()).toMatch(/Hello from only b/) | ||
}) | ||
|
||
it('should resolve a single matching alias', async () => { | ||
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/) | ||
}) | ||
}) | ||
}) |
6 changes: 6 additions & 0 deletions
6
test/integration/typescript-workspaces-paths/packages/www/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* This is a single line comment to check if that works */ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"exclude": ["node_modules"], | ||
"include": ["next-env.d.ts", "components", "pages"] | ||
} |
30 changes: 30 additions & 0 deletions
30
test/integration/typescript-workspaces-paths/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* This is a single line comment to check if that works */ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"isomorphic-unfetch": ["packages/www/types/unfetch.d.ts"], | ||
"@c/*": ["packages/www/components/*"], | ||
"@lib/*": ["packages/lib/a/*", "packages/lib/b/*"], | ||
"@mycomponent": ["packages/www/components/hello.tsx"], | ||
"d-ts-alias": [ | ||
"packages/www/components/alias-to-d-ts.d.ts", | ||
"packages/www/components/alias-to-d-ts.tsx" | ||
] | ||
// This is a single line comment to check if that works | ||
}, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"jsx": "preserve", | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true | ||
} | ||
} |