-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Experimental feature for allowing importing Typescript files outside of the root directory #22867
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6bc158d
add experimental.externalDir option
shuding 0096d0b
add test
shuding 7d13000
remove when enabling the flag
shuding 83ee858
do not expose env var
shuding e4fb242
Merge branch 'canary' into feat-external-dir
kodiakhq[bot] ed289be
Merge branch 'canary' into feat-external-dir
kodiakhq[bot] 3064eb3
Merge branch 'canary' into feat-external-dir
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
test/integration/typescript-external-dir/project/components/world.tsx
This file contains hidden or 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-external-dir/project/next.config.js
This file contains hidden or 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 = { | ||
| onDemandEntries: { | ||
| // Make sure entries are not getting disposed. | ||
| maxInactiveAge: 1000 * 60 * 60, | ||
| }, | ||
| experimental: { | ||
| externalDir: '../shared', | ||
| }, | ||
| } |
16 changes: 16 additions & 0 deletions
16
test/integration/typescript-external-dir/project/pages/index.tsx
This file contains hidden or 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,16 @@ | ||
| import React from 'react' | ||
|
|
||
| import { World } from 'components/world' | ||
|
|
||
| // External | ||
| import { Counter } from '../../shared/components/counter' | ||
|
|
||
| export default function HelloPage(): JSX.Element { | ||
| return ( | ||
| <div> | ||
| Hello <World />! | ||
| <br /> | ||
| <Counter /> | ||
| </div> | ||
| ) | ||
| } |
31 changes: 31 additions & 0 deletions
31
test/integration/typescript-external-dir/project/test/index.test.js
This file contains hidden or 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,31 @@ | ||
| /* 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 render the page with external TS/TSX dependencies', async () => { | ||
| const $ = await get$('/') | ||
| expect($('body').text()).toMatch(/Hello World!Counter: 0/) | ||
| }) | ||
| }) | ||
| }) |
20 changes: 20 additions & 0 deletions
20
test/integration/typescript-external-dir/project/tsconfig.json
This file contains hidden or 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,20 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "baseUrl": ".", | ||
| "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 | ||
| }, | ||
| "exclude": ["node_modules"], | ||
| "include": ["next-env.d.ts", "components", "pages"] | ||
| } |
12 changes: 12 additions & 0 deletions
12
test/integration/typescript-external-dir/shared/components/counter.tsx
This file contains hidden or 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,12 @@ | ||
| import React, { useState } from 'react' | ||
|
|
||
| import inc from '../libs/inc' | ||
|
|
||
| export function Counter(): JSX.Element { | ||
| const [x, setX] = useState(0) | ||
| return ( | ||
| <button id="counter" onClick={() => setX(inc(x))}> | ||
| Counter: {x} | ||
| </button> | ||
| ) | ||
| } |
This file contains hidden or 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 function inc(x: number) { | ||
| return x + 1 | ||
| } |
18 changes: 18 additions & 0 deletions
18
test/integration/typescript-external-dir/shared/tsconfig.json
This file contains hidden or 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,18 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "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 | ||
| }, | ||
| "include": ["components", "libs"] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.