Skip to content

Commit 873299f

Browse files
Merge pull request #14 from contentstack/enh/dx-362-inquirer-v12
migrate inquirer usage to v12 syntax
2 parents edb8c34 + f56b588 commit 873299f

File tree

16 files changed

+1435
-1364
lines changed

16 files changed

+1435
-1364
lines changed

packages/contentstack-bootstrap/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
"@contentstack/cli-config": "~2.0.0-beta.3",
2323
"@oclif/core": "^4.3.0",
2424
"@oclif/plugin-help": "^6.2.37",
25-
"inquirer": "8.2.7",
25+
"inquirer": "12.11.1",
2626
"mkdirp": "^1.0.4",
2727
"tar": "^7.5.11"
2828
},
2929
"devDependencies": {
3030
"@oclif/test": "^4.1.13",
3131
"@types/inquirer": "^9.0.8",
3232
"@types/mkdirp": "^1.0.2",
33-
"@types/node": "^14.18.63",
33+
"@types/node": "^18.11.9",
3434
"@types/tar": "^6.1.13",
3535
"chai": "^4.5.0",
3636
"eslint": "^8.57.1",
@@ -41,7 +41,7 @@
4141
"oclif": "^4.17.46",
4242
"tmp": "^0.2.5",
4343
"ts-node": "^8.10.2",
44-
"typescript": "^4.9.5"
44+
"typescript": "^5.9.3"
4545
},
4646
"engines": {
4747
"node": ">=14.0.0"

packages/contentstack-bootstrap/src/bootstrap/interactive.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const inquirer = require('inquirer');
1+
import inquirer from 'inquirer';
22
import { cliux, pathValidator } from '@contentstack/cli-utilities';
33

44
import messageHandler from '../messages';
@@ -50,15 +50,14 @@ export async function inquireCloneDirectory(): Promise<string> {
5050
}
5151

5252
// Ask for the custom path
53-
let selectedCustomPath = await inquirer.prompt([
53+
const selectedCustomPath = await inquirer.prompt([
5454
{
55-
type: 'string',
55+
type: 'input',
5656
name: 'path',
5757
message: messageHandler.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY'),
5858
},
5959
]);
60-
selectedCustomPath = pathValidator(selectedCustomPath.path);
61-
return selectedCustomPath;
60+
return pathValidator(selectedCustomPath.path);
6261
}
6362

6463
export async function inquireGithubAccessToken(): Promise<any> {

packages/contentstack-bootstrap/test/bootstrap.test.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Bootstrapping an app', () => {
7575
configHandlerTokens = { 'test-alias': { token: aliasToken } },
7676
} = options;
7777

78-
// configHandler stub
78+
// configHandler stub (tokens only when hasAlias; do not stub get for auth - use configHandler.set('authorisationType', 'OAUTH') in tests instead)
7979
if (hasAlias) {
8080
sandbox.stub(configHandler, 'get').withArgs('tokens').returns(configHandlerTokens);
8181
}
@@ -371,9 +371,8 @@ describe('Bootstrapping an app', () => {
371371
},
372372
});
373373

374-
// Mock region and cmaHost
375-
command.region = mock.region;
376-
command.cmaHost = mock.region.cma;
374+
// Mock region and cmaHost (base class getter uses _region, then cmaHost uses region)
375+
command._region = mock.region;
377376

378377
// Mock managementSDKClient
379378
const managementAPIClientStub = {
@@ -408,6 +407,7 @@ describe('Bootstrapping an app', () => {
408407
sandbox.restore();
409408
sandbox = sinon.createSandbox();
410409
setupStubs();
410+
configHandler.set('authorisationType', 'OAUTH');
411411

412412
const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
413413
const command = new BootstrapCommand([], {});
@@ -417,6 +417,8 @@ describe('Bootstrapping an app', () => {
417417
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
418418
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
419419
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
420+
sandbox.stub(interactive, 'inquireLivePreviewSupport');
421+
sandbox.stub(interactive, 'inquireRunDevServer');
420422

421423
// Mock config
422424
const config = require('../lib/config');
@@ -462,6 +464,7 @@ describe('Bootstrapping an app', () => {
462464
sandbox.restore();
463465
sandbox = sinon.createSandbox();
464466
setupStubs();
467+
configHandler.set('authorisationType', 'OAUTH');
465468

466469
const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
467470
const command = new BootstrapCommand([], {});
@@ -471,6 +474,8 @@ describe('Bootstrapping an app', () => {
471474
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
472475
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
473476
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
477+
sandbox.stub(interactive, 'inquireLivePreviewSupport');
478+
sandbox.stub(interactive, 'inquireRunDevServer');
474479

475480
// Mock config
476481
const config = require('../lib/config');
@@ -516,6 +521,7 @@ describe('Bootstrapping an app', () => {
516521
sandbox.restore();
517522
sandbox = sinon.createSandbox();
518523
setupStubs();
524+
configHandler.set('authorisationType', 'OAUTH');
519525

520526
const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
521527
const command = new BootstrapCommand([], {});
@@ -572,6 +578,7 @@ describe('Bootstrapping an app', () => {
572578
sandbox.restore();
573579
sandbox = sinon.createSandbox();
574580
setupStubs();
581+
configHandler.set('authorisationType', 'OAUTH');
575582

576583
const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
577584
const command = new BootstrapCommand([], {});
@@ -619,21 +626,23 @@ describe('Bootstrapping an app', () => {
619626
// Verify that appType is set correctly
620627
expect(bootstrapOptions).to.not.be.null;
621628
expect(bootstrapOptions.appType).to.equal('sampleapp');
622-
// Verify that inquireApp was called with sampleApps
623-
expect(interactive.inquireApp.calledWith(config.sampleApps)).to.be.true;
629+
// Verify that inquireApp was called with sampleApps (config.default in compiled CJS)
630+
expect(interactive.inquireApp.calledWith(config.default.sampleApps)).to.be.true;
624631
});
625632

626633
it('should handle app-name flag correctly', async () => {
627634
sandbox.restore();
628635
sandbox = sinon.createSandbox();
629636
setupStubs();
637+
configHandler.set('authorisationType', 'OAUTH');
630638

631639
const BootstrapCommand = require('../lib/commands/cm/bootstrap').default;
632640
const command = new BootstrapCommand([], {});
633641

634-
// Mock interactive functions
642+
// Mock interactive functions (stub inquireApp so .called exists for assertion)
635643
const interactive = require('../lib/bootstrap/interactive');
636644
sandbox.stub(interactive, 'inquireAppType').resolves('starterapp');
645+
sandbox.stub(interactive, 'inquireApp').resolves(mock.appConfig);
637646
sandbox.stub(interactive, 'inquireCloneDirectory').resolves('/test/path');
638647
sandbox.stub(interactive, 'inquireLivePreviewSupport').resolves(false);
639648
sandbox.stub(interactive, 'inquireRunDevServer').resolves(false);

packages/contentstack-bootstrap/test/interactive-dev-server.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { createRequire } from 'module';
2+
const require = createRequire(import.meta.url);
13
const { expect } = require('chai');
24
const sinon = require('sinon');
3-
const inquirer = require('inquirer');
5+
// Inquirer v12 CJS export is { default: { prompt, ... } }; use default so stubs apply to what lib uses
6+
const inquirer = require('inquirer').default || require('inquirer');
47
const { inquireRunDevServer } = require('../lib/bootstrap/interactive');
58
const messages = require('../messages/index.json');
69

packages/contentstack-bootstrap/test/interactive.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { createRequire } from 'module';
2+
const require = createRequire(import.meta.url);
13
const { expect } = require('chai');
24
const sinon = require('sinon');
3-
const inquirer = require('inquirer');
5+
// Inquirer v12 CJS export is { default: { prompt, ... } }; use default so stubs apply to what lib uses
6+
const inquirer = require('inquirer').default || require('inquirer');
47
const {
58
inquireApp,
69
inquireCloneDirectory,
@@ -11,6 +14,7 @@ const {
1114
continueBootstrapCommand,
1215
} = require('../lib/bootstrap/interactive');
1316
const messages = require('../messages/index.json');
17+
const { pathValidator } = require('@contentstack/cli-utilities');
1418

1519
describe('Interactive Functions Tests', () => {
1620
let sandbox;
@@ -101,30 +105,25 @@ describe('Interactive Functions Tests', () => {
101105
.resolves({ path: 'Other' })
102106
.onSecondCall()
103107
.resolves({ path: customPath });
104-
const pathValidatorStub = sandbox.stub(require('@contentstack/cli-utilities'), 'pathValidator').returns(customPath);
105108

106109
const result = await inquireCloneDirectory();
107110

108-
expect(result).to.equal(customPath);
111+
expect(result).to.equal(pathValidator(customPath));
109112
expect(inquirer.prompt.calledTwice).to.be.true;
110-
expect(pathValidatorStub.calledOnce).to.be.true;
111113
});
112114

113115
it('should validate custom path using pathValidator', async () => {
114116
const rawPath = '/some/path';
115-
const validatedPath = '/validated/path';
116117
sandbox
117118
.stub(inquirer, 'prompt')
118119
.onFirstCall()
119120
.resolves({ path: 'Other' })
120121
.onSecondCall()
121122
.resolves({ path: rawPath });
122-
const pathValidatorStub = sandbox.stub(require('@contentstack/cli-utilities'), 'pathValidator').returns(validatedPath);
123123

124124
const result = await inquireCloneDirectory();
125125

126-
expect(pathValidatorStub.calledWith(rawPath)).to.be.true;
127-
expect(result).to.equal(validatedPath);
126+
expect(result).to.equal(pathValidator(rawPath));
128127
});
129128
});
130129

packages/contentstack-clone/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@oclif/core": "^4.3.0",
1414
"@oclif/plugin-help": "^6.2.28",
1515
"chalk": "^4.1.2",
16-
"inquirer": "8.2.7",
16+
"inquirer": "12.11.1",
1717
"lodash": "^4.17.23",
1818
"merge": "^2.1.1",
1919
"ora": "^5.4.1",
@@ -24,7 +24,7 @@
2424
"@oclif/test": "^4.1.13",
2525
"@types/chai": "^4.3.0",
2626
"@types/mocha": "^10.0.0",
27-
"@types/node": "^14.18.63",
27+
"@types/node": "^18.11.9",
2828
"@types/sinon": "^10.0.0",
2929
"@typescript-eslint/eslint-plugin": "^5.62.0",
3030
"chai": "^4.5.0",
@@ -35,7 +35,7 @@
3535
"oclif": "^4.17.46",
3636
"sinon": "^21.0.1",
3737
"ts-node": "^10.9.2",
38-
"typescript": "^4.9.5"
38+
"typescript": "^5.9.3"
3939
},
4040
"engines": {
4141
"node": ">=14.0.0"

packages/contentstack-clone/src/core/util/clone-handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ export class CloneHandler {
170170
}
171171

172172
displayBackOptionMessage(): void {
173-
const ui = new inquirer.ui.BottomBar();
174-
ui.updateBottomBar(chalk.cyan('\nPress shift & left arrow together to undo the operation\n'));
173+
process.stdout.write(chalk.cyan('\nPress shift & left arrow together to undo the operation\n'));
175174
}
176175

177176
setBackKeyPressHandler(backKeyPressHandler: (...args: any[]) => void): void {

packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,6 @@ describe('CloneHandler - Commands', () => {
399399
const configHandler = require('@contentstack/cli-utilities').configHandler;
400400
configHandlerGetStub = sandbox.stub(configHandler, 'get').returns(undefined);
401401

402-
// Stub inquirer.ui.BottomBar to prevent hanging in displayBackOptionMessage
403-
sandbox.stub(inquirer.ui, 'BottomBar').returns({
404-
updateBottomBar: sandbox.stub(),
405-
} as any);
406-
407402
// Stub ora spinner - following import plugin pattern
408403
const oraModule = require('ora');
409404
const mockSpinner = {

packages/contentstack-clone/test/lib/util/clone-handler.execution.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,6 @@ describe('CloneHandler - Execution', () => {
425425
stack: sandbox.stub(),
426426
};
427427
handler.setClient(mockClient);
428-
// Stub inquirer.ui.BottomBar to prevent hanging
429-
sandbox.stub(inquirer.ui, 'BottomBar').returns({
430-
updateBottomBar: sandbox.stub(),
431-
} as any);
432428
});
433429

434430
afterEach(() => {

packages/contentstack-clone/test/lib/util/clone-handler.helpers.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ describe('CloneHandler - Helpers', () => {
2626
});
2727

2828
it('should display back option message', () => {
29-
const uiStub = {
30-
updateBottomBar: sandbox.stub(),
31-
};
32-
sandbox.stub(inquirer.ui, 'BottomBar').returns(uiStub as any);
33-
29+
const writeStub = sandbox.stub(process.stdout, 'write');
3430
handler.displayBackOptionMessage();
35-
36-
expect(uiStub.updateBottomBar.calledOnce).to.be.true;
31+
expect(writeStub.calledOnce).to.be.true;
32+
expect(writeStub.firstCall.args[0]).to.include('Press shift & left arrow together to undo');
33+
writeStub.restore();
3734
});
3835
});
3936

0 commit comments

Comments
 (0)