Unverified Commit b418a887 authored by Shu Ding's avatar Shu Ding Committed by GitHub

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)
parent 59466f8a
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment