Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): throw error on caching platforms (#18437)
- Loading branch information
Showing
29 changed files
with
260 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/client/src/runtime/core/init/checkPlatformCaching.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { checkPlatformCaching } from './checkPlatformCaching' | ||
|
||
test('generated via postinstall on vercel', () => { | ||
expect(() => checkPlatformCaching({ postinstall: true, ciName: 'Vercel', clientVersion: '0.0.0' })) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
We have detected that you've built your project on Vercel, which caches dependencies. | ||
This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. | ||
To fix this, make sure to run the \`prisma generate\` command during your build process. | ||
Learn how: https://pris.ly/d/vercel-build | ||
`) | ||
}) | ||
|
||
test('generated on vercel', () => { | ||
expect(() => checkPlatformCaching({ postinstall: false, ciName: 'Vercel', clientVersion: '0.0.0' })).not.toThrow() | ||
}) | ||
|
||
test('generated via postinstall on netlify', () => { | ||
expect(() => checkPlatformCaching({ postinstall: true, ciName: 'Netlify CI', clientVersion: '0.0.0' })) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
We have detected that you've built your project on Netlify CI, which caches dependencies. | ||
This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. | ||
To fix this, make sure to run the \`prisma generate\` command during your build process. | ||
Learn how: https://pris.ly/d/netlify-build | ||
`) | ||
}) | ||
|
||
test('generated on netlify', () => { | ||
expect(() => checkPlatformCaching({ postinstall: false, ciName: 'Netlify CI', clientVersion: '0.0.0' })).not.toThrow() | ||
}) | ||
|
||
export {} |
43 changes: 43 additions & 0 deletions
43
packages/client/src/runtime/core/init/checkPlatformCaching.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Debug from '@prisma/debug' | ||
import { PrismaClientInitializationError } from '@prisma/engine-core' | ||
|
||
import type { GetPrismaClientConfig } from '../../getPrismaClient' | ||
|
||
const debug = Debug('prisma:client') | ||
|
||
/** | ||
* Known platforms that have caching issues. Updating this list will also update | ||
* the error message and the link to the docs, so add docs/links as needed. The | ||
* key from this map comes from the `ciName` property of the `ci-info` package. | ||
*/ | ||
const cachingPlatforms = { | ||
Vercel: 'vercel', | ||
'Netlify CI': 'netlify', | ||
} as const | ||
|
||
type Config = Pick<GetPrismaClientConfig, 'postinstall' | 'ciName' | 'clientVersion'> | ||
|
||
/** | ||
* Throws an error if the client has been generated via auto-install and the | ||
* platform is known to have caching issues. In that case, we will display a | ||
* useful error message, and ask the user to run `prisma generate` manually. | ||
* @returns | ||
*/ | ||
export function checkPlatformCaching({ postinstall, ciName, clientVersion }: Config) { | ||
debug('checkPlatformCaching:postinstall', postinstall) | ||
debug('checkPlatformCaching:ciName', ciName) | ||
|
||
// if client was not generated manually | ||
if (postinstall !== true) return | ||
|
||
// and we generated on one a caching CI | ||
if (ciName && ciName in cachingPlatforms) { | ||
throw new PrismaClientInitializationError( | ||
`We have detected that you've built your project on ${ciName}, which caches dependencies. | ||
This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. | ||
To fix this, make sure to run the \`prisma generate\` command during your build process. | ||
Learn how: https://pris.ly/d/${cachingPlatforms[ciName]}-build`, | ||
clientVersion, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.