From 5c0346b0531c46e18b74cc915b173565eb2bb110 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Sat, 26 Nov 2022 18:23:00 +0100 Subject: [PATCH] make sure ts plugin works for src/app --- 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)