Skip to content

Commit

Permalink
TS plugin: warn about amp config in app (#45254)
Browse files Browse the repository at this point in the history
Asked by @ijjk in
#45228 (comment):

<img width="1171" alt="CleanShot 2023-01-25 at 10 26 15@2x"
src="https://user-images.githubusercontent.com/3676859/214526847-6481e33b-060e-4e15-bf1d-4274760068f5.png">


## 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)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
shuding and kodiakhq[bot] committed Jan 25, 2023
1 parent e868f77 commit e8b208d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/next/src/server/next-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DISALLOWED_SERVER_REACT_APIS: string[] = [
'createFactory',
]

const LEGACY_CONFIG_EXPORT = 'config'
const ALLOWED_EXPORTS = ['config', 'generateStaticParams']

const ALLOWED_PAGE_PROPS = ['params', 'searchParams']
Expand All @@ -39,6 +40,7 @@ const NEXT_TS_ERRORS = {
INVALID_OPTION_VALUE: 71003,
MISPLACED_CLIENT_ENTRY: 71004,
INVALID_PAGE_PROP: 71005,
INVALID_CONFIG_OPTION: 71006,
}

const API_DOCS: Record<
Expand Down Expand Up @@ -803,6 +805,28 @@ export function createTSPlugin(modules: {
})
}
}
} else if (name.text === LEGACY_CONFIG_EXPORT) {
// export const config = { ... }
// Error if using `amp: ...`
const value = declarartion.initializer
if (value && ts.isObjectLiteralExpression(value)) {
for (const prop of value.properties) {
if (
ts.isPropertyAssignment(prop) &&
ts.isIdentifier(prop.name) &&
prop.name.text === 'amp'
) {
prior.push({
file: source,
category: ts.DiagnosticCategory.Error,
code: NEXT_TS_ERRORS.INVALID_CONFIG_OPTION,
messageText: `AMP is not supported in the app directory. If you need to use AMP it will continue to be supported in the pages directory.`,
start: prop.getStart(),
length: prop.getWidth(),
})
}
}
}
}
}
}
Expand Down

0 comments on commit e8b208d

Please sign in to comment.