From b418a88757f5a27e258dc5b6b9d84993c5a9239b Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Mon, 28 Nov 2022 13:14:20 +0100 Subject: [PATCH] Make sure the TS plugin works for src/app (#43412) Reported [here](https://twitter.com/iShiibi/status/1596515959397027843). ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- packages/next/server/next-typescript.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/next/server/next-typescript.ts b/packages/next/server/next-typescript.ts index 9ff0c6612ac5..6ae023d79c46 100644 --- a/packages/next/server/next-typescript.ts +++ b/packages/next/server/next-typescript.ts @@ -196,16 +196,20 @@ export function createTSPlugin(modules: { } function create(info: ts.server.PluginCreateInfo) { - const appDir = path.join(info.project.getCurrentDirectory(), 'app') + const projectDir = info.project.getCurrentDirectory() + const appDir = new RegExp( + '^' + (projectDir + '(/src)?/app').replace(/[\\/]/g, '[\\/]') + ) + const isAppEntryFile = (filePath: string) => { return ( - filePath.startsWith(appDir) && + appDir.test(filePath) && /^(page|layout)\.(mjs|js|jsx|ts|tsx)$/.test(path.basename(filePath)) ) } const isPageFile = (filePath: string) => { return ( - filePath.startsWith(appDir) && + appDir.test(filePath) && /^page\.(mjs|js|jsx|ts|tsx)$/.test(path.basename(filePath)) ) } @@ -292,7 +296,7 @@ export function createTSPlugin(modules: { info.project.projectService.logger.info(message) } - log('Starting Next.js TypeScript plugin: ' + appDir) + log('Starting Next.js TypeScript plugin: ' + projectDir) // Set up decorator object const proxy = Object.create(null)