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

[legacy-framework] Move display package to nextjs fork #2989

Merged
merged 16 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/custom-server/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import blitz from "blitz/custom-server"
import {createServer} from "http"
import {parse} from "url"
import {log} from "@blitzjs/display"
import {log} from "next/dist/server/lib/logging"

const {PORT = "3000"} = process.env
const dev = process.env.NODE_ENV !== "production"
Expand Down
4 changes: 3 additions & 1 deletion nextjs/packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"caniuse-lite": "^1.0.30001228",
"chalk": "2.4.2",
"chokidar": "3.5.1",
"console-table-printer": "^2.7.5",
"constants-browserify": "1.0.0",
"cookie-session": "^1.4.0",
"cross-spawn": "7.0.3",
Expand All @@ -111,6 +112,7 @@
"node-libs-browser": "^2.2.1",
"npm-which": "^3.0.1",
"null-loader": "4.0.1",
"ora": "^5.3.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can import from next/dist/compiled/ora

"os-browserify": "0.3.0",
"p-limit": "3.1.0",
"passport": "0.4.1",
Expand All @@ -123,6 +125,7 @@
"react-is": "17.0.2",
"react-query": "3.21.1",
"react-refresh": "0.8.3",
"readline": "1.3.0",
"resolve-from": "^5.0.0",
"secure-password": "4.0.0",
"stream-browserify": "3.0.0",
Expand Down Expand Up @@ -245,7 +248,6 @@
"mini-css-extract-plugin": "1.5.0",
"nanoid": "^3.1.20",
"neo-async": "2.6.1",
"ora": "^5.3.0",
"path-to-regexp": "6.1.0",
"postcss-flexbugs-fixes": "5.0.2",
"postcss-loader": "4.3.0",
Expand Down
149 changes: 149 additions & 0 deletions nextjs/packages/next/server/lib/logging.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ISettingsParam, Logger } from 'tslog'
import { loadConfigAtRuntime, LogLevel } from '../config-shared'
import c from 'chalk'
import { Table } from 'console-table-printer'
import ora from 'ora'
import readline from 'readline'

// eslint-disable-next-line
declare module globalThis {
Expand Down Expand Up @@ -65,3 +69,148 @@ export const baseLogger = (options?: ISettingsParam): Logger => {

return globalThis._blitz_baseLogger
}

export const table = Table
export const chalk = c

// const blitzTrueBrandColor = '6700AB'
const blitzBrightBrandColor = '8a3df0'

// Using bright brand color so it's better for dark terminals
const brandColor = blitzBrightBrandColor

const withBrand = (str: string) => {
return c.hex(brandColor).bold(str)
}

const withWarning = (str: string) => {
return `⚠️ ${c.yellow(str)}`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove in favor of tslog.warn


const withCaret = (str: string) => {
return `${c.gray('>')} ${str}`
}

const withCheck = (str: string) => {
return `${c.green('✔')} ${str}`
}

const withX = (str: string) => {
return `${c.red.bold('✕')} ${str}`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove in favor of tslog.error


const withProgress = (str: string) => {
return withCaret(str)
}

/**
* Logs a branded purple message to stdout.
*
* @param {string} msg
*/
const branded = (msg: string) => {
console.log(c.hex(brandColor).bold(msg))
}

/**
* Clears the line and optionally log a message to stdout.
*
* @param {string} msg
*/
const clearLine = (msg?: string) => {
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
msg && process.stdout.write(msg)
}

const clearConsole = () => {
if (process.platform === 'win32') {
process.stdout.write('\x1B[2J\x1B[0f')
} else {
process.stdout.write('\x1B[2J\x1B[3J\x1B[H')
}
}

/**
* Logs a red error message to stderr.
*
* @param {string} msg
*/
const warning = (msg: string) => {
console.log(withCaret(withWarning(msg)))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove in favor of tslog.warn


/**
* Logs a red error message to stderr.
*
* @param {string} msg
*/
const error = (msg: string) => {
console.error(withX(c.red.bold(msg)))
}

/**
* Logs a progress message to stdout.
*
* @param {string} msg
*/
const progress = (msg: string) => {
console.log(withProgress(msg))
}

const info = (msg: string) => {
console.log(c.bold(msg))
}

const spinner = (str: string) => {
return ora({
text: str,
color: 'blue',
spinner: {
interval: 120,
frames: ['◢', '◣', '◤', '◥'],
},
})
}

/**
* Logs a green success message to stdout.
*
* @param {string} msg
*/
const success = (msg: string) => {
console.log(withCheck(c.green(msg)))
}

/**
* Colorizes a variable for display.
*
* @param {string} val
*/
const variable = (val: any) => {
return c.cyan.bold(`${val}`)
}

/**
* If the DEBUG env var is set this will write to the console
* @param str msg
*/
const debug = require('debug')('blitz')

export const log = {
withBrand,
withWarning,
withCaret,
branded,
clearLine,
clearConsole,
error,
warning,
progress,
spinner,
success,
variable,
info,
debug,
Table,
}
12 changes: 4 additions & 8 deletions nextjs/packages/next/stdlib-server/auth-sessions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Must import this type from 'blitz'
// import { log } from '@blitzjs/display'
import { log } from '../server/lib/logging'
import { fromBase64, toBase64 } from 'b64-lite'
import cookie from 'next/dist/compiled/cookie'
import fs from 'fs'
Expand Down Expand Up @@ -95,8 +94,7 @@ const defaultConfig: SessionConfig = {
} catch (error) {
// Session doesn't exist in DB for some reason, so create it
if (error.code === 'P2016') {
// log.warning("Could not update session because it's not in the DB")
console.log("Could not update session because it's not in the DB")
log.warning("Could not update session because it's not in the DB")
} else {
throw error
}
Expand Down Expand Up @@ -693,8 +691,7 @@ async function getSessionKernel(
persistedSession.antiCSRFToken !== antiCSRFToken
) {
if (!antiCSRFToken) {
// log.warning(
console.log(
log.warning(
`This request is missing the ${HEADER_CSRF} header. You can learn about adding this here: https://blitzjs.com/docs/session-management#manual-api-requests`
)
}
Expand Down Expand Up @@ -770,8 +767,7 @@ async function getSessionKernel(

if (enableCsrfProtection && payload.antiCSRFToken !== antiCSRFToken) {
if (!antiCSRFToken) {
// log.warning(
console.log(
log.warning(
`This request is missing the ${HEADER_CSRF} header. You can learn about adding this here: https://blitzjs.com/docs/session-management#manual-api-requests`
)
}
Expand Down
19 changes: 18 additions & 1 deletion nextjs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6474,7 +6474,7 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"

caniuse-lite@1.0.30001274, caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001165, caniuse-lite@^1.0.30001202, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001228:
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001165, caniuse-lite@^1.0.30001202, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001228:
version "1.0.30001274"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001274.tgz#26ca36204d15b17601ba6fc35dbdad950a647cc7"
integrity sha512-+Nkvv0fHyhISkiMIjnyjmf5YJcQ1IQHZN6U9TLUMroWR38FNwpsC51Gb68yueafX1V6ifOisInSgP9WJFS13ew==
Expand Down Expand Up @@ -7156,6 +7156,13 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"

console-table-printer@^2.7.5:
version "2.10.0"
resolved "https://registry.yarnpkg.com/console-table-printer/-/console-table-printer-2.10.0.tgz#4a6875b95071b36542d1c55c6d9dcc6206e1e9f0"
integrity sha512-7pTsysaJs1+R+OO4cCtJbl+Lr4piHYIhi7/V1qHbOg/uiYgq2yUINFgvXZtVHqm9qpW0+Uk190qkGcKvzdunvg==
dependencies:
simple-wcswidth "^1.0.1"

constant-case@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/constant-case/-/constant-case-2.0.0.tgz#4175764d389d3fa9c8ecd29186ed6005243b6a46"
Expand Down Expand Up @@ -16554,6 +16561,11 @@ readjson@^2.0.1:
jju "^1.4.0"
try-catch "^3.0.0"

[email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/readline/-/readline-1.3.0.tgz#c580d77ef2cfc8752b132498060dc9793a7ac01c"
integrity sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=

[email protected]:
version "0.18.5"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.18.5.tgz#9d5adbc07983a3c8145f3034812374a493e0fe4d"
Expand Down Expand Up @@ -17672,6 +17684,11 @@ simple-swizzle@^0.2.2:
dependencies:
is-arrayish "^0.3.1"

simple-wcswidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/simple-wcswidth/-/simple-wcswidth-1.0.1.tgz#8ab18ac0ae342f9d9b629604e54d2aa1ecb018b2"
integrity sha512-xMO/8eNREtaROt7tJvWJqHBDTMFN4eiQ5I4JRMuilwfnFcV5W9u7RUkueNkdw0jPqGMX36iCywelS5yilTuOxg==

sinon@^1.17.6:
version "1.17.7"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-1.17.7.tgz#4542a4f49ba0c45c05eb2e9dd9d203e2b8efe0bf"
Expand Down
1 change: 0 additions & 1 deletion packages/blitz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
},
"dependencies": {
"@blitzjs/cli": "0.43.0",
"@blitzjs/display": "0.43.0",
"@blitzjs/generator": "0.43.0",
"@blitzjs/server": "0.43.0",
"@testing-library/jest-dom": "5.11.9",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"/lib"
],
"dependencies": {
"@blitzjs/display": "0.43.0",
"@blitzjs/generator": "0.43.0",
"@blitzjs/installer": "0.43.0",
"@blitzjs/server": "0.43.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {log} from "@blitzjs/display"
import {Command, flags} from "@oclif/command"
import {log} from "next/dist/server/lib/logging"
import {getPackageJson} from "../utils/get-package-json"
import {runPrisma} from "./prisma"

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Console extends Command {
async run() {
process.env.CLI_COMMAND_CONSOLE = "true"
this.parse(Console)
const {log} = require("@blitzjs/display")
const {log} = require("next/dist/server/lib/logging")
const chalk = require("chalk")
log.branded("You have entered the Blitz console")
console.log(chalk.yellow("Tips: - Exit by typing .exit or pressing Ctrl-D"))
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {log} from "@blitzjs/display"
import {Command, flags} from "@oclif/command"
import {baseLogger} from "next/dist/server/lib/logging"
import {baseLogger, log} from "next/dist/server/lib/logging"

export function getDbName(connectionString: string): string {
const dbUrlParts: string[] = connectionString!.split("/")
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Dev extends Command {
blitzConfig.cli?.clearConsoleOnBlitzDev !== false &&
!process.env.BLITZ_TEST_ENVIRONMENT
) {
const {log} = await import("@blitzjs/display")
const {log} = await import("next/dist/server/lib/logging")
log.clearConsole()
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {log} from "@blitzjs/display"
import {
capitalize,
FormGenerator,
Expand All @@ -16,6 +15,7 @@ import {
} from "@blitzjs/generator"
import {flags} from "@oclif/command"
import chalk from "chalk"
import {log} from "next/dist/server/lib/logging"
import {Command} from "../command"
import {PromptAbortedError} from "../errors/prompt-aborted"

Expand Down Expand Up @@ -180,7 +180,7 @@ export class Generate extends Command {
async handleNoContext(message: string): Promise<void> {
const shouldCreateNewRoot = await this.genericConfirmPrompt(message)
if (!shouldCreateNewRoot) {
require("@blitzjs/display").log.error(
require("next/dist/shared/lib/display").log.error(
"Could not determine proper location for files. Aborting.",
)
this.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/install.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {log} from "@blitzjs/display"
import type {RecipeCLIArgs, RecipeCLIFlags, RecipeExecutor} from "@blitzjs/installer"
import {flags} from "@oclif/command"
import {bootstrap} from "global-agent"
import {log} from "next/dist/server/lib/logging"
import {join, resolve} from "path"
import {Stream} from "stream"
import {promisify} from "util"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/new.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {log} from "@blitzjs/display"
import type {AppGeneratorOptions} from "@blitzjs/generator"
import {getLatestVersion} from "@blitzjs/generator"
import {flags} from "@oclif/command"
import chalk from "chalk"
import spawn from "cross-spawn"
import hasbin from "hasbin"
import {log} from "next/dist/server/lib/logging"
import {lt} from "semver"
const debug = require("debug")("blitz:new")

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {table as Table} from "@blitzjs/display"
import {ServerConfig} from "@blitzjs/server"
import {Command, flags} from "@oclif/command"
import {table as Table} from "next/dist/server/lib/logging"
import {newline} from "next/dist/server/lib/logging"

export class Routes extends Command {
Expand Down
4 changes: 0 additions & 4 deletions packages/display/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions packages/display/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions packages/display/jest.config.js

This file was deleted.

Empty file removed packages/display/jest.setup.js
Empty file.
Loading