Skip to content

Commit

Permalink
chore(cli): make fs modules used in the CLI consistent (#9746)
Browse files Browse the repository at this point in the history
I was sizing up the CLI code as part of ESM work. Since I was looking at
it wholesale, @Josh-Walker-GM and I were exchanging notes on what we'd
like to improve about it. While a lot of what we talked about was out of
scope, there were a few things that are low hanging fruit, one of which
is this one, which amounted to a simple search and replace. We just
figured if we're using `fs-extra` half the time in the CLI, we may as
well use it everywhere to remove the overhead of why it'd be different
in one place vs another.
  • Loading branch information
jtoar authored and Tobbe committed Dec 31, 2023
1 parent a1d5e8f commit f9adcb5
Show file tree
Hide file tree
Showing 74 changed files with 90 additions and 79 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/__tests__/fs.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
jest.mock('fs')

import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'

const INITIAL_FS = {
file_a: 'content_a',
[path.join('fake_dir', 'mock_dir', 'made_up_file')]: 'made_up_content',
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/__tests__/plugin.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs'

import fs from 'fs-extra'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/buildHandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import execa from 'execa'
import fs from 'fs-extra'
import { Listr } from 'listr2'
import { rimraf } from 'rimraf'
import terminalLink from 'terminal-link'
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/consoleHandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from 'fs'
import path from 'path'
import repl from 'repl'

import fs from 'fs-extra'

import { registerApiSideBabelHook } from '@redwoodjs/babel-config'
import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/deploy/__tests__/nftPack.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'

import { buildApi } from '@redwoodjs/internal/dist/build/api'
import { findApiDistFunctions } from '@redwoodjs/internal/dist/files'

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/baremetal.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'

import toml from '@iarna/toml'
import boxen from 'boxen'
import fs from 'fs-extra'
import { Listr } from 'listr2'
import { env as envInterpolation } from 'string-env-interpolation'
import terminalLink from 'terminal-link'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/serverless.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'fs'
import path from 'path'

import boxen from 'boxen'
import chalk from 'chalk'
import { config } from 'dotenv-defaults'
import execa from 'execa'
import fs from 'fs-extra'
import { Listr } from 'listr2'
import prompts from 'prompts'
import terminalLink from 'terminal-link'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jest.mock('@redwoodjs/structure', () => {
}
})

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jest.mock('../../../../lib', () => {
}
})

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('../../../../lib', () => {
}
})

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jest.mock('../../../../lib', () => {
}
})

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jest.mock('../../../../lib', () => {
}
})

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jest.mock('../../../../lib', () => {
}
})

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
globalThis.__dirname = __dirname

import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'

import '../../../../lib/test'

import { getPaths, getDefaultArgs } from '../../../../lib'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
globalThis.__dirname = __dirname

import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'

import '../../../../lib/test'

import { getPaths, getDefaultArgs } from '../../../../lib'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
globalThis.__dirname = __dirname

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
globalThis.__dirname = __dirname
import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/devHandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import { argv } from 'process'

import concurrently from 'concurrently'
import fs from 'fs-extra'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
import { shutdownPort } from '@redwoodjs/internal/dist/dev'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import execa from 'execa'
import fs from 'fs-extra'
import { Listr } from 'listr2'

import { addApiPackages } from '@redwoodjs/cli-helpers'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'
import { Listr } from 'listr2'

import { addApiPackages } from '@redwoodjs/cli-helpers'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'
import { Listr } from 'listr2'

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'
import { Listr } from 'listr2'

import { addApiPackages } from '@redwoodjs/cli-helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/experimental/studioHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs'
import fs from 'fs-extra'

import { getConfigPath } from '@redwoodjs/project-config'

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/experimental/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import chalk from 'chalk'
import fs from 'fs-extra'
import terminalLink from 'terminal-link'

import { getPaths } from '../../lib'
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/generate/__tests__/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'

// Setup test mocks
globalThis.__dirname = __dirname
import '../../../lib/test'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'
import { Listr } from 'listr2'
import { paramCase } from 'param-case'
import terminalLink from 'terminal-link'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ global.__dirname = __dirname

jest.mock('fs')

import fs from 'fs'
import path from 'path'

// Load mocks
import '../../../../lib/test'

const realfs = jest.requireActual('fs')
import Enquirer from 'enquirer'
import fs from 'fs-extra'

import { getPaths } from '../../../../lib'
import * as dbAuth from '../dbAuth'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/generate/dbAuth/dbAuth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'

import { camelCase } from 'camel-case'
import Enquirer from 'enquirer'
import fs from 'fs-extra'
import { Listr } from 'listr2'
import terminalLink from 'terminal-link'
import { titleCase } from 'title-case'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/generate/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'
import { Listr } from 'listr2'
import { paramCase } from 'param-case'
import pascalcase from 'pascalcase'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ jest.mock('fs', () => {
}
})

import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'

// Load mocks
import '../../../../lib/test'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
globalThis.__dirname = __dirname

import fs from 'fs'
import fs from 'fs-extra'

import '../../../../lib/test'
import { shouldUseTailwindCSS } from '../scaffold'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/generate/scaffold/scaffold.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'

import camelcase from 'camelcase'
import execa from 'execa'
import fs from 'fs-extra'
import humanize from 'humanize-string'
import { Listr } from 'listr2'
import { paramCase } from 'param-case'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/generate/script/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jest.mock('fs', () => {
}
})

import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'
import prompts from 'prompts'

// Load mocks
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/lint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs'

import execa from 'execa'
import fs from 'fs-extra'
import terminalLink from 'terminal-link'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/prerenderHandler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'
import { Listr } from 'listr2'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/prismaHandler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'

import boxen from 'boxen'
import execa from 'execa'
import fs from 'fs-extra'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
import { errorTelemetry } from '@redwoodjs/telemetry'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/serve.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'

import chalk from 'chalk'
import execa from 'execa'
import fs from 'fs-extra'
import terminalLink from 'terminal-link'

import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/setup/cache/cacheHandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import chalk from 'chalk'
import fs from 'fs-extra'
import { Listr } from 'listr2'

import { addEnvVarTask } from '@redwoodjs/cli-helpers'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import chalk from 'chalk'
import fs from 'fs-extra'
import { Listr } from 'listr2'

import { errorTelemetry } from '@redwoodjs/telemetry'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Automock fs using ../..../__mocks__/fs
jest.mock('fs')

import fs from 'fs'
import path from 'path'

import fs from 'fs-extra'

import { getPaths } from '../../../../lib'
import { updateApiURLTask } from '../helpers'
// Mock telemetry and other things
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/setup/deploy/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import execa from 'execa'
import fs from 'fs-extra'
import { Listr } from 'listr2'

import { getPaths, writeFilesTask } from '../../../../lib'
Expand Down
Loading

0 comments on commit f9adcb5

Please sign in to comment.