Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): add deprecation message for introspect command #8763

Merged
merged 16 commits into from Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions CONTRIBUTING.md
Expand Up @@ -226,12 +226,6 @@ Changes to `query.ts` will then be reflected when running `fixtures/blog/main.ts
1. `cd packages/migrate/fixtures/blog`
1. `ts-node ../../src/bin.ts dev`

### Developing `prisma init` Command

1. `cd packages/introspection`
1. `mkdir test && cd test`
1. `ts-node ../src/bin.ts`

### Developing `prisma` CLI

1. `cd packages/cli`
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/.gitignore
Expand Up @@ -26,4 +26,4 @@ write-test
prisma-cli*.tgz
pnpm-lock.yaml

/src/__tests__/version-test-engines
version-test-engines
2 changes: 0 additions & 2 deletions packages/cli/fixtures/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion packages/cli/fixtures/introspection-warnings/.gitignore

This file was deleted.

51 changes: 0 additions & 51 deletions packages/cli/fixtures/introspection-warnings/schema.prisma

This file was deleted.

Binary file not shown.
5 changes: 0 additions & 5 deletions packages/cli/fixtures/project/package.json

This file was deleted.

21 changes: 0 additions & 21 deletions packages/cli/fixtures/project/subdir/dynamic-denylist.prisma

This file was deleted.

134 changes: 0 additions & 134 deletions packages/cli/fixtures/test.sh

This file was deleted.

5 changes: 1 addition & 4 deletions packages/cli/package.json
Expand Up @@ -113,10 +113,7 @@
"scripts": {
"dev": "DEV=true node helpers/build.js",
"build": "node helpers/build.js",
"test:commands": "./fixtures/test.sh && jest --maxConcurrency=1",
"test-update": "pnpm run test:commands -- -u",
"test": "pnpm run test:commands",
"jest": "jest",
"test": "jest --maxConcurrency=1 --verbose",
"install": "node scripts/install-entry.js",
"format": "prettier --write .",
"lint": "eslint --cache --fix --ext .ts .",
Expand Down
23 changes: 20 additions & 3 deletions packages/cli/src/CLI.ts
Expand Up @@ -7,6 +7,7 @@ import {
format,
HelpError,
unknownCommand,
logger,
} from '@prisma/sdk'
import { Version } from './Version'
import { link } from '@prisma/sdk'
Expand Down Expand Up @@ -48,18 +49,34 @@ export class CLI implements Command {

// display help for help flag or no subcommand
if (args._.length === 0 || args['--help']) {
return CLI.help
return this.help()
}

// check if we have that subcommand
const cmdName = args._[0]
// Throw if "lift"
if (cmdName === 'lift') {
throw new Error(
`${chalk.red('prisma lift')} has been renamed to ${chalk.green(
'prisma migrate',
)}`,
)
}
// warn if "introspect"
else if (cmdName === 'introspect') {
logger.warn('')
logger.warn(
`${chalk.bold(
`The ${chalk.underline(
'prisma introspect',
)} command is deprecated. Please use ${chalk.green(
'prisma db pull',
)} instead.`,
)}`,
)
logger.warn('')
}

const cmd = this.cmds[cmdName]
if (cmd) {
// if we have that subcommand, let's ensure that the binary is there in case the command needs it
Expand Down Expand Up @@ -90,10 +107,10 @@ export class CLI implements Command {
return cmd.parse(argsForCmd)
}
// unknown command
return unknownCommand(CLI.help, args._[0])
return unknownCommand(this.help() as string, args._[0])
}

private help(error?: string): string | HelpError {
public help(error?: string) {
if (error) {
return new HelpError(`\n${chalk.bold.red(`!`)} ${error}\n${CLI.help}`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Init.ts
Expand Up @@ -15,7 +15,7 @@ import dotenv from 'dotenv'
import fs from 'fs'
import path from 'path'
import { isError } from 'util'
import { printError } from './prompt/utils/print'
import { printError } from './utils/prompt/utils/print'

export const defaultSchema = (provider: ConnectorType = 'postgresql') => {
if (provider === 'sqlserver' || provider === 'mongodb') {
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/__tests__/__helpers__/context.ts
Expand Up @@ -118,6 +118,7 @@ export const consoleContext: ContextContributorFactory<
mocked: {
'console.error': jest.SpyInstance
'console.log': jest.SpyInstance
'console.info': jest.SpyInstance
'console.warn': jest.SpyInstance
}
}
Expand All @@ -129,6 +130,9 @@ export const consoleContext: ContextContributorFactory<
ctx.mocked['console.log'] = jest
.spyOn(console, 'log')
.mockImplementation(() => {})
ctx.mocked['console.info'] = jest
.spyOn(console, 'info')
.mockImplementation(() => {})
ctx.mocked['console.warn'] = jest
.spyOn(console, 'warn')
.mockImplementation(() => {})
Expand All @@ -137,6 +141,7 @@ export const consoleContext: ContextContributorFactory<
afterEach(() => {
ctx.mocked['console.error'].mockRestore()
ctx.mocked['console.log'].mockRestore()
ctx.mocked['console.info'].mockRestore()
ctx.mocked['console.warn'].mockRestore()
})

Expand Down
15 changes: 11 additions & 4 deletions packages/cli/src/__tests__/__helpers__/snapshotSerializer.ts
Expand Up @@ -39,6 +39,11 @@ function normalizeRustError(str) {
function normalizeTmpDir(str) {
return str.replace(/\/tmp\/([a-z0-9]+)\//g, '/tmp/dir/')
}

function normalizeMs(str) {
return str.replace(/\d{1,3}ms/g, 'XXms')
}

const serializer = {
test(value) {
return typeof value === 'string' || value instanceof Error
Expand All @@ -53,10 +58,12 @@ const serializer = {
return prepareSchemaForSnapshot(
normalizeGithubLinks(
normalizeRustError(
normalizeTmpDir(
normalizeGithubLinks(
normalizeToUnixPaths(
removePlatforms(trimErrorPaths(stripAnsi(message))),
normalizeMs(
normalizeTmpDir(
normalizeGithubLinks(
normalizeToUnixPaths(
removePlatforms(trimErrorPaths(stripAnsi(message))),
),
),
),
),
Expand Down