({
schemaPathFromConfig,
baseDir,
}: {
schemaPathFromConfig?: string
baseDir: string
})
| 27 | * https://pris.ly/d/telemetry |
| 28 | */ |
| 29 | export async function runCheckpointClientCheck({ |
| 30 | schemaPathFromConfig, |
| 31 | baseDir, |
| 32 | }: { |
| 33 | schemaPathFromConfig?: string |
| 34 | baseDir: string |
| 35 | }): Promise<Check.Result | 0> { |
| 36 | // If the user has disabled telemetry, we can stop here already. |
| 37 | if (process.env['CHECKPOINT_DISABLE']) { |
| 38 | // TODO: this breaks checkpoint-client abstraction, ideally it would export a reusable isGloballyDisabled() function |
| 39 | debug('runCheckpointClientCheck() is disabled by the CHECKPOINT_DISABLE env var.') |
| 40 | return 0 |
| 41 | } |
| 42 | |
| 43 | const commandArray = process.argv.slice(2) |
| 44 | const args = arg( |
| 45 | commandArray, |
| 46 | { |
| 47 | '--schema': String, |
| 48 | '--telemetry-information': String, |
| 49 | }, |
| 50 | false, |
| 51 | true, |
| 52 | ) |
| 53 | |
| 54 | const schemaPathFromArgs = typeof args['--schema'] === 'string' ? args['--schema'] : undefined |
| 55 | |
| 56 | try { |
| 57 | const startGetInfo = performance.now() |
| 58 | const schemaPath = createSchemaPathInput({ schemaPathFromArgs, schemaPathFromConfig, baseDir }) |
| 59 | // Get some info about the project |
| 60 | const [projectPathHash, { schemaProvider, schemaPreviewFeatures, schemaGeneratorsProviders }] = await Promise.all([ |
| 61 | // SHA256 identifier for the project based on the Prisma schema path |
| 62 | getProjectHash(schemaPath), |
| 63 | // Read schema and extract some data |
| 64 | tryToReadDataFromSchema(schemaPath), |
| 65 | ]) |
| 66 | // SHA256 of the cli path |
| 67 | const cliPathHash = getCLIPathHash() |
| 68 | |
| 69 | const endGetInfo = performance.now() |
| 70 | const getInfoElapsedTime = endGetInfo - startGetInfo |
| 71 | debug(`runCheckpointClientCheck(): Execution time for getting info: ${getInfoElapsedTime} ms`) |
| 72 | |
| 73 | const data: Check.Input = { |
| 74 | // Name of the product |
| 75 | product: 'prisma', |
| 76 | // Currently installed version of the CLI |
| 77 | version: packageJson.version, |
| 78 | // A unique hash of the path in which the CLI is installed |
| 79 | cli_path_hash: cliPathHash, |
| 80 | // A unique hash of the project's path, i.e.. the `schema.prisma`'s path |
| 81 | project_hash: projectPathHash, |
| 82 | // The first datasource provider (e.g. postgresql) |
| 83 | schema_providers: schemaProvider ? [schemaProvider] : undefined, |
| 84 | // previewFeatures from the prisma-client-js generator |
| 85 | schema_preview_features: schemaPreviewFeatures, |
| 86 | // Generator providers (e.g. prisma-client-js) |
no test coverage detected