Skip to content

Commit

Permalink
Merge branch 'canary' into fix-catch-all-routes-example-link
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jul 18, 2020
2 parents 9f7f9fc + f5b186c commit e287964
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function isLikelyASyntaxError(message) {
function formatMessage(message) {
// TODO: Replace this once webpack 5 is stable
if (typeof message === 'object' && message.message) {
message = (message.file ? message.file + '\n' : '') + message.message
message =
(message.moduleName ? message.moduleName + '\n' : '') +
(message.file ? message.file + '\n' : '') +
message.message
}
let lines = message.split('\n')

Expand Down
18 changes: 16 additions & 2 deletions packages/next/lib/typescript/writeConfigurationDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { getTypeScriptConfiguration } from './getTypeScriptConfiguration'
type DesiredCompilerOptionsShape = {
[key: string]:
| { suggested: any }
| { parsedValue?: any; value: any; reason: string }
| {
parsedValue?: any
parsedValues?: Array<any>
value: any
reason: string
}
}

function getDesiredCompilerOptions(
Expand All @@ -33,6 +38,13 @@ function getDesiredCompilerOptions(
},
module: {
parsedValue: ts.ModuleKind.ESNext,
// All of these values work:
parsedValues: [
ts.ModuleKind.ES2020,
ts.ModuleKind.ESNext,
ts.ModuleKind.CommonJS,
ts.ModuleKind.AMD,
],
value: 'esnext',
reason: 'for dynamic import() support',
},
Expand Down Expand Up @@ -111,7 +123,9 @@ export async function writeConfigurationDefaults(
} else if ('value' in check) {
const ev = effectiveConfiguration.options[optionKey]
if (
!('parsedValue' in check
!('parsedValues' in check
? check.parsedValues?.includes(ev)
: 'parsedValue' in check
? check.parsedValue === ev
: check.value === ev)
) {
Expand Down
2 changes: 2 additions & 0 deletions test/integration/tsconfig-verifier/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const blah: boolean = false
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const blah2 = import('../value').then((r) => r.default)

export default () => <h3>Hello TypeScript</h3>
94 changes: 92 additions & 2 deletions test/integration/tsconfig-verifier/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('tsconfig.json verifier', () => {
"compilerOptions": {
// in-object comment
"esModuleInterop": false, // this should be true
"module": "commonjs" // should not be commonjs
"module": "umd" // should not be umd
// end-object comment
}
// in-object comment 2
Expand All @@ -134,7 +134,7 @@ describe('tsconfig.json verifier', () => {
\\"compilerOptions\\": {
// in-object comment
\\"esModuleInterop\\": true, // this should be true
\\"module\\": \\"esnext\\" // should not be commonjs
\\"module\\": \\"esnext\\" // should not be umd
// end-object comment
,
\\"target\\": \\"es5\\",
Expand Down Expand Up @@ -168,4 +168,94 @@ describe('tsconfig.json verifier', () => {
"
`)
})

it('allows you to set commonjs module mode', async () => {
expect(await exists(tsConfig)).toBe(false)

await writeFile(
tsConfig,
`{ "compilerOptions": { "esModuleInterop": false, "module": "commonjs" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { code } = await nextBuild(appDir)
expect(code).toBe(0)

expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
\\"compilerOptions\\": {
\\"esModuleInterop\\": true,
\\"module\\": \\"commonjs\\",
\\"target\\": \\"es5\\",
\\"lib\\": [
\\"dom\\",
\\"dom.iterable\\",
\\"esnext\\"
],
\\"allowJs\\": true,
\\"skipLibCheck\\": true,
\\"strict\\": false,
\\"forceConsistentCasingInFileNames\\": true,
\\"noEmit\\": true,
\\"moduleResolution\\": \\"node\\",
\\"resolveJsonModule\\": true,
\\"isolatedModules\\": true,
\\"jsx\\": \\"preserve\\"
},
\\"include\\": [
\\"next-env.d.ts\\",
\\"**/*.ts\\",
\\"**/*.tsx\\"
],
\\"exclude\\": [
\\"node_modules\\"
]
}
"
`)
})

it('allows you to set es2020 module mode', async () => {
expect(await exists(tsConfig)).toBe(false)

await writeFile(
tsConfig,
`{ "compilerOptions": { "esModuleInterop": false, "module": "es2020" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { code } = await nextBuild(appDir)
expect(code).toBe(0)

expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
\\"compilerOptions\\": {
\\"esModuleInterop\\": true,
\\"module\\": \\"es2020\\",
\\"target\\": \\"es5\\",
\\"lib\\": [
\\"dom\\",
\\"dom.iterable\\",
\\"esnext\\"
],
\\"allowJs\\": true,
\\"skipLibCheck\\": true,
\\"strict\\": false,
\\"forceConsistentCasingInFileNames\\": true,
\\"noEmit\\": true,
\\"moduleResolution\\": \\"node\\",
\\"resolveJsonModule\\": true,
\\"isolatedModules\\": true,
\\"jsx\\": \\"preserve\\"
},
\\"include\\": [
\\"next-env.d.ts\\",
\\"**/*.ts\\",
\\"**/*.tsx\\"
],
\\"exclude\\": [
\\"node_modules\\"
]
}
"
`)
})
})
1 change: 1 addition & 0 deletions test/integration/tsconfig-verifier/value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default false

0 comments on commit e287964

Please sign in to comment.