Skip to content

Commit

Permalink
fix(cli): warn on min ts version (#7857)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamluke4 committed Jun 25, 2021
1 parent 76a05ae commit bec42f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/packages/sdk/src/index.ts
Expand Up @@ -49,13 +49,13 @@ export {
canConnectToDatabase,
createDatabase,
dropDatabase,
MigrateEngineLogLine,
MigrateEngineExitCode,
MigrateEngineLogLine,
} from './migrateEngineCommands'
export { ErrorArea, RustPanic } from './panic'
export { pick } from './pick'
export { GeneratorPaths } from './predefinedGeneratorResolvers'
export { engineEnvVarMap, resolveBinary, BinaryType } from './resolveBinary'
export { BinaryType, engineEnvVarMap, resolveBinary } from './resolveBinary'
export { sendPanic } from './sendPanic'
export { DatabaseCredentials } from './types'
export { extractPreviewFeatures } from './utils/extractPreviewFeatures'
Expand All @@ -64,8 +64,8 @@ export { mapPreviewFeatures } from './utils/mapPreviewFeatures'
export { maskSchema } from './utils/maskSchema'
export { missingGeneratorMessage } from './utils/missingGeneratorMessage'
export {
parseEnvValue,
parseBinaryTargetsEnvValue,
parseEnvValue,
} from './utils/parseEnvValue'
export { printConfigWarnings } from './utils/printConfigWarnings'
export {
Expand Down
35 changes: 18 additions & 17 deletions src/packages/sdk/src/predefinedGeneratorResolvers.ts
Expand Up @@ -160,32 +160,33 @@ function checkYarnVersion() {
}

/**
* Warn, if typescript is below `4.1.0` or if it is not install locally or globally
* Warn, if typescript is below `4.1.0` and is install locally
* Because Template Literal Types are required for generating Prisma Client types.
*/
function checkTypeScriptVersion() {
const minVersion = '4.1.0'
let output
try {
output = execa.sync('tsc', ['-v'], {
preferLocal: true,
})
const typescriptPath = resolvePkg('typescript', { cwd: process.cwd() })
const typescriptPkg =
typescriptPath && path.join(typescriptPath, 'package.json')
if (typescriptPkg && fs.existsSync(typescriptPkg)) {
const pjson = require(typescriptPkg)
const currentVersion = pjson.version
if (semverLt(currentVersion, minVersion)) {
logger.warn(
`Your ${chalk.bold(
'typescript',
)} version is ${currentVersion}, which is outdated. Please update it to ${chalk.bold(
minVersion,
)} or ${chalk.bold('newer')} in order to use Prisma Client.`,
)
}
}
} catch (e) {
// They do not have TS installed, we ignore (example: JS project)
}
if (output?.stdout) {
const currentVersion = output.stdout.split(' ')[1]
if (semverLt(currentVersion, minVersion)) {
throw new Error(
`Your ${chalk.bold(
'typescript',
)} version is ${currentVersion}, which is outdated. Please update it to ${chalk.bold(
minVersion,
)} or ${chalk.bold('newer')} in order to use Prisma Client.`,
)
}
}
}

/**
* Returns true, if semver version `a` is lower than `b`
* Note: This obviously doesn't support the full semver spec.
Expand Down

0 comments on commit bec42f6

Please sign in to comment.