diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 1d94e7482d159..fa8a89d656c20 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -15,6 +15,7 @@ import { } from '../lib/constants' import { fileExists } from '../lib/file-exists' import { resolveRequest } from '../lib/resolve-request' +import { getTypeScriptConfiguration } from '../lib/typescript/getTypeScriptConfiguration' import { CLIENT_STATIC_FILES_RUNTIME_MAIN, CLIENT_STATIC_FILES_RUNTIME_POLYFILLS, @@ -261,7 +262,9 @@ export default async function getBaseWebpackConfig( let jsConfig // jsconfig is a subset of tsconfig if (useTypeScript) { - jsConfig = parseJsonFile(tsConfigPath) + const ts = (await import(typeScriptPath)) as typeof import('typescript') + const tsConfig = await getTypeScriptConfiguration(ts, tsConfigPath) + jsConfig = { compilerOptions: tsConfig.options } } const jsConfigPath = path.join(dir, 'jsconfig.json') diff --git a/test/integration/typescript-workspaces-paths/packages/lib/a/api.ts b/test/integration/typescript-workspaces-paths/packages/lib/a/api.ts new file mode 100644 index 0000000000000..6644e65afa29e --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/lib/a/api.ts @@ -0,0 +1,5 @@ +//this line uses typescript specific syntax +//to demonstrate that transpilation occurs +export type API = () => string +const api: API = () => 'Hello from a' +export default api diff --git a/test/integration/typescript-workspaces-paths/packages/lib/b/api.ts b/test/integration/typescript-workspaces-paths/packages/lib/b/api.ts new file mode 100644 index 0000000000000..0d1aa87ee59e5 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/lib/b/api.ts @@ -0,0 +1,4 @@ +import { API } from '@lib/api' + +const b: API = () => 'Hello from b' +export default b diff --git a/test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts b/test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts new file mode 100644 index 0000000000000..7837c03d9919d --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts @@ -0,0 +1,4 @@ +import { API } from '@lib/api' + +const b: API = () => 'Hello from only b' +export default b diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts new file mode 100644 index 0000000000000..02906bf403120 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts @@ -0,0 +1 @@ +export default () => any diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx new file mode 100644 index 0000000000000..5af0d17928ece --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx @@ -0,0 +1,4 @@ +const Named = () => { + return <>Not aliased to d.ts file> +} +export default Named diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx b/test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx new file mode 100644 index 0000000000000..49c8de26f6c50 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx @@ -0,0 +1,5 @@ +import React from 'react' + +export function Hello() { + return <>Hello> +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/components/world.tsx b/test/integration/typescript-workspaces-paths/packages/www/components/world.tsx new file mode 100644 index 0000000000000..d7d1f66258c77 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/components/world.tsx @@ -0,0 +1,5 @@ +import React from 'react' + +export function World(): JSX.Element { + return <>World> +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/next.config.js b/test/integration/typescript-workspaces-paths/packages/www/next.config.js new file mode 100644 index 0000000000000..1de16e790d34b --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/next.config.js @@ -0,0 +1,23 @@ +const path = require('path') +module.exports = { + webpack: function (config, { defaultLoaders }) { + const resolvedBaseUrl = path.resolve(config.context, '../../') + config.module.rules = [ + ...config.module.rules, + { + test: /\.(tsx|ts|js|mjs|jsx)$/, + include: [resolvedBaseUrl], + use: defaultLoaders.babel, + exclude: (excludePath) => { + return /node_modules/.test(excludePath) + }, + }, + ] + return config + }, + + onDemandEntries: { + // Make sure entries are not getting disposed. + maxInactiveAge: 1000 * 60 * 60, + }, +} diff --git a/test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx b/test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx new file mode 100644 index 0000000000000..d24ac047d2f73 --- /dev/null +++ b/test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx @@ -0,0 +1,10 @@ +import React from 'react' +import NotAliasedToDTS from 'd-ts-alias' + +export default function HelloPage(): JSX.Element { + return ( +