Skip to content

Commit

Permalink
Make sure the TS plugin works for src/app (vercel#43412)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
shuding authored and brvnonascimento committed Nov 28, 2022
1 parent 84ff27b commit 6df21ce
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/next/server/next-typescript.ts
Expand Up @@ -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))
)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6df21ce

Please sign in to comment.