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.
Allow
@babel/preset-typescript
to be configured (vercel#11840)
* Allow `@babel/preset-typescript` to be configured Some usages, e.g. [getting parameter decorators to work properly](WarnerHooh/babel-plugin-parameter-decorator#19), require configuring `@babel/preset-typescript`. This commit adds that functionality to `next/babel`. * Add unit test for babel/preset allowing to pass options to @babel/preset-typescript * Add integration test for onlyRemoveTypeImports * Update babel dependencies * Update to compatible typescript version and fix types * Fix linting and run pre-nccing * Update size-limit test * Add additional tests * Re-Apply delta to be calculated using -262 Co-authored-by: JJ Kasper <jj@jjsweb.site>
- Loading branch information
Showing
16 changed files
with
941 additions
and
501 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
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
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
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
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
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
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
12 changes: 12 additions & 0 deletions
12
test/integration/typescript-only-remove-type-imports/.babelrc
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,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"next/babel", | ||
{ | ||
"preset-typescript": { | ||
"onlyRemoveTypeImports": false | ||
} | ||
} | ||
] | ||
] | ||
} |
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 @@ | ||
export interface User { | ||
id: string | ||
username: string | ||
email: string | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/typescript-only-remove-type-imports/UserStatistics.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,5 @@ | ||
import type { User } from "./User"; | ||
|
||
export function getNewsletterRecipients(users: User[]) { | ||
return users.map(u => u.email); | ||
} |
30 changes: 30 additions & 0 deletions
30
test/integration/typescript-only-remove-type-imports/pages/index.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,30 @@ | ||
import type { User } from "../User"; | ||
// eslint-disable-next-line | ||
import * as UnusedUserStatisticsThatShouldNotBeElided from "../UserStatistics"; | ||
|
||
const users: User[] = [ | ||
{ | ||
id: "a", | ||
email: "a@a.de", | ||
username: "anton" | ||
}, | ||
{ | ||
id: "b", | ||
email: "b@b.de", | ||
username: "berta" | ||
} | ||
] | ||
|
||
function Index() { | ||
return ( | ||
<ul> | ||
{users.map(u => ( | ||
<li key={u.id}> | ||
{u.username}: {u.email} | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} | ||
|
||
export default Index; |
1 change: 1 addition & 0 deletions
1
test/integration/typescript-only-remove-type-imports/pages/normal.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 @@ | ||
export default () => "A normal one" |
54 changes: 54 additions & 0 deletions
54
test/integration/typescript-only-remove-type-imports/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,54 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import { | ||
nextBuild, | ||
nextStart, | ||
findPort, | ||
killApp, | ||
launchApp, | ||
renderViaHTTP, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
const appDir = join(__dirname, '../') | ||
let app | ||
let appPort | ||
|
||
const runTests = () => { | ||
it('should render a normal page correctly', async () => { | ||
const html = await renderViaHTTP(appPort, '/normal') | ||
expect(html).toContain('A normal one') | ||
}) | ||
|
||
it('should render a page with type import correctly', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
expect(html).toContain('anton') | ||
expect(html).toContain('berta') | ||
}) | ||
} | ||
|
||
describe('TypeScript onlyRemoveTypeImports', () => { | ||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
const { code } = await nextBuild(appDir) | ||
if (code !== 0) throw new Error(`build failed with code ${code}`) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |
19 changes: 19 additions & 0 deletions
19
test/integration/typescript-only-remove-type-imports/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,19 @@ | ||
{ | ||
"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 | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["next-env.d.ts", "components", "pages"] | ||
} |
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
Oops, something went wrong.