Skip to content

Commit

Permalink
[CLI]: Upgrade from Listr to Listr2 (#6444)
Browse files Browse the repository at this point in the history
* initial listr to listr2 refactor pass through commands

* updated package.json to use listr2 and remove listr and the verbose render

* updated some lib functions which used listr

* Fixed renderOptions to rendererOptions

* Updated generator files

* Updated destroy files

* Update tests with listr2 changes

* Updated createYargsForComponentGeneration.test.js mock

* Replaced manual mock with automatic one

* Removed caret (^) from listr2 package dependency

* Updated test project fixture

* tracking yarn.lock

* updated yarn.lock

* Remove duplicate test-project migrations

* Remove TODO's for greater verbose output support

Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
  • Loading branch information
Josh-Walker-GM and Tobbe committed Oct 3, 2022
1 parent fc8ee95 commit 61286e4
Show file tree
Hide file tree
Showing 61 changed files with 927 additions and 851 deletions.
3 changes: 1 addition & 2 deletions packages/cli/package.json
Expand Up @@ -49,8 +49,7 @@
"fast-glob": "3.2.12",
"fs-extra": "10.1.0",
"latest-version": "5.1.0",
"listr": "0.14.3",
"listr-verbose-renderer": "0.6.0",
"listr2": "5.0.5",
"lodash": "4.17.21",
"param-case": "3.0.4",
"pascalcase": "1.0.0",
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/commands/__tests__/build.test.js
Expand Up @@ -20,12 +20,8 @@ jest.mock('@redwoodjs/internal/dist/config', () => {
}
})

import Listr from 'listr'
jest.mock('listr', () => {
return jest.fn().mockImplementation(function FakeListr() {
return { run: jest.fn() }
})
})
import { Listr } from 'listr2'
jest.mock('listr2')

// Make sure prerender doesn't get triggered
jest.mock('execa', () =>
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/commands/buildHandler.js
Expand Up @@ -2,8 +2,7 @@ import fs from 'fs'
import path from 'path'

import execa from 'execa'
import Listr from 'listr'
import VerboseRenderer from 'listr-verbose-renderer'
import { Listr } from 'listr2'
import rimraf from 'rimraf'
import terminalLink from 'terminal-link'

Expand Down Expand Up @@ -137,7 +136,7 @@ export const handler = async ({
}

const jobs = new Listr(tasks, {
renderer: verbose && VerboseRenderer,
renderer: verbose && 'verbose',
})

try {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/dataMigrate/install.js
Expand Up @@ -2,7 +2,7 @@ import path from 'path'

import execa from 'execa'
import fs from 'fs-extra'
import Listr from 'listr'
import { Listr } from 'listr2'
import terminalLink from 'terminal-link'

import { errorTelemetry } from '@redwoodjs/telemetry'
Expand Down Expand Up @@ -86,7 +86,7 @@ export const handler = async () => {
},
},
],
{ collapse: false, exitOnError: true }
{ rendererOptions: { collapse: false }, exitOnError: true }
)

try {
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/commands/dataMigrate/up.js
@@ -1,8 +1,7 @@
import fs from 'fs'
import path from 'path'

import Listr from 'listr'
import VerboseRenderer from 'listr-verbose-renderer'
import { Listr } from 'listr2'
import terminalLink from 'terminal-link'

import { registerApiSideBabelHook } from '@redwoodjs/internal/dist/build/babel/api'
Expand Down Expand Up @@ -160,8 +159,8 @@ export const handler = async () => {
})

const tasks = new Listr(migrationTasks, {
collapse: false,
renderer: VerboseRenderer,
rendererOptions: { collapse: false },
renderer: 'verbose',
})

try {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/commands/deploy/__tests__/baremetal.test.js
@@ -1,4 +1,4 @@
import Listr from 'listr'
import { Listr } from 'listr2'

jest.mock('@redwoodjs/internal/dist/paths', () => {
return {
Expand Down Expand Up @@ -738,7 +738,7 @@ describe('commands', () => {
{ environment: 'staging', releaseDir: '2022051120000' },
{}
)
const tasks = servers[0].task()._tasks
const tasks = servers[0].task().tasks

expect(tasks[0].title).toMatch('Connecting')
expect(tasks[9].title).toMatch('Disconnecting')
Expand All @@ -749,7 +749,7 @@ describe('commands', () => {
{ environment: 'staging', releaseDir: '2022051120000' },
{}
)
const tasks = servers[0].task()._tasks
const tasks = servers[0].task().tasks

expect(tasks[1].title).toMatch('Cloning')
})
Expand All @@ -763,7 +763,7 @@ describe('commands', () => {
},
{}
)
const tasks = servers[0].task()._tasks
const tasks = servers[0].task().tasks

expect(tasks.length).toEqual(3)
expect(tasks[1].title).toMatch('Enabling maintenance')
Expand All @@ -778,7 +778,7 @@ describe('commands', () => {
},
{}
)
const tasks = servers[0].task()._tasks
const tasks = servers[0].task().tasks

expect(tasks.length).toEqual(3)
expect(tasks[1].title).toMatch('Rolling back 2 release(s)')
Expand All @@ -792,7 +792,7 @@ describe('commands', () => {
},
{}
)
const tasks = servers[0].task()._tasks
const tasks = servers[0].task().tasks

expect(tasks[1].title).toEqual('Before update: `touch update`')
expect(tasks[5].title).toEqual('After install: `touch install`')
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/commands/deploy/baremetal.js
Expand Up @@ -3,8 +3,7 @@ import path from 'path'

import toml from '@iarna/toml'
import boxen from 'boxen'
import Listr from 'listr'
import VerboseRenderer from 'listr-verbose-renderer'
import { Listr } from 'listr2'
import terminalLink from 'terminal-link'
import { titleCase } from 'title-case'

Expand Down Expand Up @@ -684,7 +683,7 @@ export const handler = async (yargs) => {
const tasks = new Listr(commands(yargs, ssh), {
concurrent: true,
exitOnError: true,
renderer: yargs.verbose && VerboseRenderer,
renderer: yargs.verbose && 'verbose',
})
await tasks.run()
} catch (e) {
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/commands/deploy/serverless.js
Expand Up @@ -5,8 +5,7 @@ import boxen from 'boxen'
import chalk from 'chalk'
import { config } from 'dotenv-defaults'
import execa from 'execa'
import Listr from 'listr'
import VerboseRenderer from 'listr-verbose-renderer'
import { Listr } from 'listr2'
import prompts from 'prompts'
import terminalLink from 'terminal-link'

Expand Down Expand Up @@ -142,7 +141,7 @@ export const handler = async (yargs) => {
],
{
exitOnError: true,
renderer: yargs.verbose && VerboseRenderer,
renderer: yargs.verbose && 'verbose',
}
)
try {
Expand Down Expand Up @@ -205,7 +204,7 @@ export const handler = async (yargs) => {
],
{
exitOnError: true,
renderer: yargs.verbose && VerboseRenderer,
renderer: yargs.verbose && 'verbose',
}
)

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/destroy/cell/__tests__/cell.test.js
Expand Up @@ -36,7 +36,7 @@ test('destroys cell files', async () => {
filesFn: files,
name: 'User',
})
t.setRenderer('silent')
t.options.renderer = 'silent'

await t.run()

Expand All @@ -55,7 +55,7 @@ test('destroys cell files with stories and tests', async () => {
stories: true,
tests: true,
})
t.setRenderer('silent')
t.options.renderer = 'silent'

await t.run()

Expand Down
Expand Up @@ -26,7 +26,7 @@ afterEach(() => {
test('destroys component files', async () => {
const unlinkSpy = jest.spyOn(fs, 'unlinkSync')
const t = tasks({ componentName: 'component', filesFn: files, name: 'About' })
t.setRenderer('silent')
t.options.renderer = 'silent'

return t.run().then(() => {
const generatedFiles = Object.keys(files({ name: 'About' }))
Expand All @@ -45,7 +45,7 @@ test('destroys component files including stories and tests', async () => {
stories: true,
tests: true,
})
t.setRenderer('silent')
t.options.renderer = 'silent'

return t.run().then(() => {
const generatedFiles = Object.keys(
Expand Down
Expand Up @@ -33,7 +33,7 @@ test('destroys directive files', async () => {
filesFn: (args) => files({ ...args, type: 'validator' }),
name: 'require-admin',
})
t.setRenderer('silent')
t.options.renderer = 'silent'

return t.run().then(() => {
const generatedFiles = Object.keys(
Expand Down
Expand Up @@ -30,7 +30,7 @@ test('destroys service files', async () => {
filesFn: files,
name: 'sendMail',
})
t.setRenderer('silent')
t.options.renderer = 'silent'

return t.run().then(async () => {
const generatedFiles = Object.keys(files({ name: 'sendMail' }))
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/destroy/graphiql/graphiql.js
@@ -1,4 +1,4 @@
import Listr from 'listr'
import { Listr } from 'listr2'

import {
existsAnyExtensionSync,
Expand Down Expand Up @@ -46,7 +46,7 @@ export const handler = () => {
task: removeGraphiqlFromGraphqlHandler,
},
],
{ collapse: false, exitOnError: true }
{ rendererOptions: { collapse: false }, exitOnError: true }
)
try {
tasks.run()
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/destroy/helpers.js
@@ -1,4 +1,4 @@
import Listr from 'listr'
import { Listr } from 'listr2'

import { deleteFilesTask } from '../../lib'
import c from '../../lib/colors'
Expand All @@ -14,7 +14,7 @@ const tasks = ({ componentName, filesFn, name }) =>
},
},
],
{ collapse: false, exitOnError: true }
{ rendererOptions: { collapse: false }, exitOnError: true }
)

export const createYargsForComponentDestroy = ({
Expand Down
Expand Up @@ -26,7 +26,7 @@ afterEach(() => {
test('destroys layout files', async () => {
const unlinkSpy = jest.spyOn(fs, 'unlinkSync')
const t = tasks({ componentName: 'layout', filesFn: files, name: 'Blog' })
t.setRenderer('silent')
t.options.renderer = 'silent'

return t.run().then(() => {
const generatedFiles = Object.keys(files({ name: 'Blog' }))
Expand All @@ -45,7 +45,7 @@ test('destroys layout files with stories and tests', async () => {
stories: true,
tests: true,
})
t.setRenderer('silent')
t.options.renderer = 'silent'

return t.run().then(() => {
const generatedFiles = Object.keys(
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/commands/destroy/page/__tests__/page.test.js
Expand Up @@ -36,9 +36,9 @@ afterEach(() => {
test('destroys page files', async () => {
const unlinkSpy = jest.spyOn(fs, 'unlinkSync')
const t = tasks({ name: 'About' })
t.setRenderer('silent')
t.options.renderer = 'silent'

return t._tasks[0].run().then(() => {
return t.tasks[0].run().then(() => {
const generatedFiles = Object.keys(files({ name: 'About' }))
expect(generatedFiles.length).toEqual(unlinkSpy.mock.calls.length)
generatedFiles.forEach((f) => expect(unlinkSpy).toHaveBeenCalledWith(f))
Expand All @@ -60,9 +60,9 @@ test('destroys page files with stories and tests', async () => {

const unlinkSpy = jest.spyOn(fs, 'unlinkSync')
const t = tasks(fileOptions)
t.setRenderer('silent')
t.options.renderer = 'silent'

return t._tasks[0].run().then(() => {
return t.tasks[0].run().then(() => {
const generatedFiles = Object.keys(files(fileOptions))
expect(generatedFiles.length).toEqual(unlinkSpy.mock.calls.length)
generatedFiles.forEach((f) => expect(unlinkSpy).toHaveBeenCalledWith(f))
Expand All @@ -71,9 +71,9 @@ test('destroys page files with stories and tests', async () => {

test('cleans up route from Routes.js', async () => {
const t = tasks({ name: 'About' })
t.setRenderer('silent')
t.options.renderer = 'silent'

return t._tasks[1].run().then(() => {
return t.tasks[1].run().then(() => {
const routes = fs.readFileSync(getPaths().web.routes)
expect(routes).toEqual(
[
Expand All @@ -88,9 +88,9 @@ test('cleans up route from Routes.js', async () => {

test('cleans up route with a custom path from Routes.js', async () => {
const t = tasks({ name: 'About', path: '/about-us' })
t.setRenderer('silent')
t.options.renderer = 'silent'

return t._tasks[1].run().then(() => {
return t.tasks[1].run().then(() => {
const routes = fs.readFileSync(getPaths().web.routes)
expect(routes).toEqual(
[
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/destroy/page/page.js
@@ -1,5 +1,5 @@
import camelcase from 'camelcase'
import Listr from 'listr'
import { Listr } from 'listr2'

import { deleteFilesTask, removeRoutesFromRouterTask } from '../../../lib'
import c from '../../../lib/colors'
Expand Down Expand Up @@ -44,7 +44,7 @@ export const tasks = ({ name, path }) =>
task: async () => removeRoutesFromRouterTask([camelcase(name)]),
},
],
{ collapse: false, exitOnError: true }
{ rendererOptions: { collapse: false }, exitOnError: true }
)

export const handler = async ({ name, path }) => {
Expand Down

0 comments on commit 61286e4

Please sign in to comment.