Skip to content

Commit ee6ebec

Browse files
committed
Import node fs and path functions directly
1 parent 614824d commit ee6ebec

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

packages/cli-menu/src/command-prompt.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'node:fs';
2-
import path from 'node:path';
1+
import { readdirSync } from 'node:fs';
2+
import { dirname, join } from 'node:path';
33
import {
44
Client,
55
type CommandModule,
@@ -68,15 +68,15 @@ export async function commandPrompt(
6868
});
6969
}
7070

71-
const commandDirItems = fs.readdirSync(commandsDir);
71+
const commandDirItems = readdirSync(commandsDir);
7272
const choicesByName = new Map<string, Choice>();
7373

7474
for (const filename of commandDirItems) {
7575
const commandName = removeFileExtension(filename);
7676
let description: string | undefined;
7777

7878
if (showDescriptions) {
79-
const filepath = path.join(commandsDir, filename);
79+
const filepath = join(commandsDir, filename);
8080
const { default: command }: { default: CommandModule } = await import(
8181
filepath
8282
).catch(() => {
@@ -131,7 +131,7 @@ export async function commandPrompt(
131131
return await commandPrompt({
132132
...options,
133133
title: undefined,
134-
commandsDir: path.dirname(lastCommand.commandPath),
134+
commandsDir: dirname(lastCommand.commandPath),
135135
selectionHistory,
136136
});
137137
}

packages/cli/src/utils/testing/command-modules.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'node:path';
1+
import { basename, dirname, join } from 'node:path';
22
import type { CommandModule } from 'src/core/command';
33
import { NotFoundError } from 'src/core/errors';
44
import { parseCommand } from 'src/core/parse';
@@ -79,7 +79,7 @@ vi.mock('node:fs', async (importOriginal) => {
7979
export function unmockAllCommandModules() {
8080
for (const [commandDir, commandNames] of mockCommandDirs.entries()) {
8181
for (const commandName of commandNames) {
82-
vi.doMock(path.join(commandDir, commandName), () => {
82+
vi.doMock(join(commandDir, commandName), () => {
8383
const mod = {
8484
handler: vi.fn(() => {
8585
throw new NotFoundError(commandName, commandDir);
@@ -111,8 +111,8 @@ export function mockCommandModule<T extends CommandModule | undefined>(
111111
unmock: () => void;
112112
} {
113113
const formattedFilePath = formatFileName(commandPath);
114-
const commandDir = path.dirname(commandPath);
115-
const commandName = path.basename(commandPath);
114+
const commandDir = dirname(commandPath);
115+
const commandName = basename(commandPath);
116116

117117
// Keep track of the command directories and names that have been mocked
118118
if (mockCommandDirs.has(commandDir)) {
@@ -184,7 +184,7 @@ export function mockCommandStringModules<TCommandString extends string>(
184184

185185
// mock each command in the command string
186186
for (const token of tokens) {
187-
commandPath = path.join(commandPath, token);
187+
commandPath = join(commandPath, token);
188188
const { mock, unmock } = mockCommandModule(commandPath, {
189189
handler: vi.fn(({ next, data }) => next(data)),
190190
});

0 commit comments

Comments
 (0)