Skip to content

Commit

Permalink
TS / PnP compatibility (#8744)
Browse files Browse the repository at this point in the history
* Fixes PnP + TS support

* Uses import on the resolved TS path (since it's not a dep)

* Fixes TS
  • Loading branch information
arcanis authored and timneutkens committed Sep 24, 2019
1 parent ebb39f1 commit 62fce6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
24 changes: 13 additions & 11 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,17 +786,19 @@ export default async function getBaseWebpackConfig(
}),
!isServer &&
useTypeScript &&
new ForkTsCheckerWebpackPlugin({
typescript: typeScriptPath,
async: dev,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
tsconfig: tsConfigPath,
reportFiles: ['**', '!**/__tests__/**', '!**/?(*.)(spec|test).*'],
compilerOptions: { isolatedModules: true, noEmit: true },
silent: true,
formatter: 'codeframe',
}),
new ForkTsCheckerWebpackPlugin(
PnpWebpackPlugin.forkTsCheckerOptions({
typescript: typeScriptPath,
async: dev,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
tsconfig: tsConfigPath,
reportFiles: ['**', '!**/__tests__/**', '!**/?(*.)(spec|test).*'],
compilerOptions: { isolatedModules: true, noEmit: true },
silent: true,
formatter: 'codeframe',
})
),
config.experimental.modern &&
!isServer &&
!dev &&
Expand Down
11 changes: 7 additions & 4 deletions packages/next/lib/verifyTypeScriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ async function checkDependencies({
{ file: '@types/node/index.d.ts', pkg: '@types/node' },
]

let resolutions = new Map<string, string>()

const missingPackages = requiredPackages.filter(p => {
try {
resolveRequest(p.file, `${dir}/`)
resolutions.set(p.pkg, resolveRequest(p.file, `${dir}/`))
} catch (_) {
return true
}
})

if (missingPackages.length < 1) {
return
return resolutions.get('typescript')!
}

const packagesHuman = missingPackages
Expand Down Expand Up @@ -116,9 +118,10 @@ export async function verifyTypeScriptSetup(dir: string): Promise<void> {
}
}

await checkDependencies({ dir, isYarn })
const tsPath = await checkDependencies({ dir, isYarn })
// @ts-ignore
const ts = (await import(tsPath)) as typeof import('typescript')

const ts = await import('typescript')
const compilerOptions: any = {
// These are suggested values and will be set when not present in the
// tsconfig.json
Expand Down

0 comments on commit 62fce6f

Please sign in to comment.