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

Upgrade package inquirer from 11.1.0 to 12.3 #3549

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
319 changes: 205 additions & 114 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"i18next": "^23.15.1",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-http-backend": "^2.6.1",
"inquirer": "^11.0.2",
"inquirer": "^12.4.1",
"js-cookie": "^3.0.1",
"lcov-result-merger": "^5.0.1",
"markdown-toc": "^1.2.0",
Expand Down
14 changes: 8 additions & 6 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
// Ask and set up reCAPTCHA
const askAndSetRecaptcha = async (): Promise<void> => {
try {
const { shouldUseRecaptcha } = await inquirer.prompt({
type: 'confirm',
name: 'shouldUseRecaptcha',
message: 'Would you like to set up reCAPTCHA?',
default: true,
});
const { shouldUseRecaptcha } = await inquirer.prompt([

Check warning on line 17 in setup.ts

View check run for this annotation

Codecov / codecov/patch

setup.ts#L17

Added line #L17 was not covered by tests
{
type: 'confirm',
name: 'shouldUseRecaptcha',
message: 'Would you like to set up reCAPTCHA?',
default: true,
},
]);

if (shouldUseRecaptcha) {
const { recaptchaSiteKeyInput } = await inquirer.prompt([
Expand Down
14 changes: 9 additions & 5 deletions src/setup/askAndSetDockerOption/askAndSetDockerOption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import type { Mock } from 'vitest';
import { describe, it, expect, vi, beforeEach } from 'vitest';

// Mock modules
vi.mock('inquirer', () => ({
default: {
prompt: vi.fn(),
},
}));
vi.mock('inquirer', async () => {
const actual = await vi.importActual('inquirer');
return {
default: {
...actual,
prompt: vi.fn(),
},
};
});

vi.mock('setup/updateEnvFile/updateEnvFile', () => ({
default: vi.fn(),
Expand Down
14 changes: 8 additions & 6 deletions src/setup/askAndSetDockerOption/askAndSetDockerOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { askForDocker } from 'setup/askForDocker/askForDocker';

// Function to manage Docker setup
const askAndSetDockerOption = async (): Promise<void> => {
const { useDocker } = await inquirer.prompt({
type: 'confirm',
name: 'useDocker',
message: 'Would you like to set up with Docker?',
default: false,
});
const { useDocker } = await inquirer.prompt([
{
type: 'confirm',
name: 'useDocker',
message: 'Would you like to set up with Docker?',
default: false,
},
]);

if (useDocker) {
console.log('Setting up with Docker...');
Expand Down
16 changes: 9 additions & 7 deletions src/setup/askAndUpdatePort/askAndUpdatePort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import inquirer from 'inquirer';

// Ask and update the custom port
const askAndUpdatePort = async (): Promise<void> => {
const { shouldSetCustomPortResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetCustomPortResponse',
message:
'Would you like to set up a custom port for running Talawa Admin without Docker?',
default: true,
});
const { shouldSetCustomPortResponse } = await inquirer.prompt([
{
type: 'confirm',
name: 'shouldSetCustomPortResponse',
message:
'Would you like to set up a custom port for running Talawa Admin without Docker?',
default: true,
},
]);

if (shouldSetCustomPortResponse) {
const customPort = await askForCustomPort();
Expand Down
11 changes: 10 additions & 1 deletion src/setup/askAndUpdatePort/askForUpdatePort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import inquirer from 'inquirer';

vi.mock('setup/askForCustomPort/askForCustomPort');
vi.mock('setup/updateEnvFile/updateEnvFile');
vi.mock('inquirer');
// Fix Inquirer mock for v12+
vi.mock('inquirer', async () => {
const actual = await vi.importActual('inquirer');
return {
default: {
...actual,
prompt: vi.fn(),
},
};
});

describe('askAndUpdatePort', () => {
afterEach(() => {
Expand Down
11 changes: 10 additions & 1 deletion src/setup/askForCustomPort/askForCustomPort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import inquirer from 'inquirer';
import { askForCustomPort, validatePort } from './askForCustomPort';

vi.mock('inquirer');
// ✅ Fix Inquirer Mocking for v12+
vi.mock('inquirer', async () => {
const actual = await vi.importActual('inquirer');
return {
default: {
...actual,
prompt: vi.fn(),
},
};
});

describe('askForCustomPort', () => {
beforeEach(() => {
Expand Down
8 changes: 5 additions & 3 deletions src/setup/askForCustomPort/askForCustomPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function validatePort(input: string): string | boolean {
}

export async function reservedPortWarning(port: number): Promise<boolean> {
const { confirmPort } = await inquirer.prompt<{ confirmPort: boolean }>([
const answer = await inquirer.prompt([
{
type: 'confirm',
name: 'confirmPort',
Expand All @@ -26,14 +26,14 @@ export async function reservedPortWarning(port: number): Promise<boolean> {
},
]);

return confirmPort;
return answer.confirmPort;
}

export async function askForCustomPort(): Promise<number> {
let remainingAttempts = MAX_RETRY_ATTEMPTS;

while (remainingAttempts--) {
const { customPort } = await inquirer.prompt<{ customPort: string }>([
const answer = await inquirer.prompt([
{
type: 'input',
name: 'customPort',
Expand All @@ -43,6 +43,8 @@ export async function askForCustomPort(): Promise<number> {
},
]);

const customPort = answer.customPort;

if (customPort && validatePort(customPort) === true) {
if (Number(customPort) >= 1024) {
return Number(customPort);
Expand Down
14 changes: 8 additions & 6 deletions src/setup/askForDocker/askForDocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
// Function to ask and update Talawa API URL
export const askAndUpdateTalawaApiUrl = async (): Promise<void> => {
try {
const { shouldSetTalawaApiUrlResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetTalawaApiUrlResponse',
message: 'Would you like to set up Talawa API endpoint?',
default: true,
});
const { shouldSetTalawaApiUrlResponse } = await inquirer.prompt([

Check warning on line 35 in src/setup/askForDocker/askForDocker.ts

View check run for this annotation

Codecov / codecov/patch

src/setup/askForDocker/askForDocker.ts#L35

Added line #L35 was not covered by tests
{
type: 'confirm',
name: 'shouldSetTalawaApiUrlResponse',
message: 'Would you like to set up Talawa API endpoint?',
default: true,
},
]);

if (shouldSetTalawaApiUrlResponse) {
let endpoint = '';
Expand Down
Loading