Skip to content

Commit

Permalink
Major(inquirer): Migrate to Typescript and dual module package
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jul 7, 2024
1 parent 093c565 commit 532a740
Show file tree
Hide file tree
Showing 75 changed files with 1,335 additions and 1,031 deletions.
8 changes: 8 additions & 0 deletions integration/cjs/integration.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const assert = require('node:assert');
const { input } = require('@inquirer/prompts');
const { createPrompt } = require('@inquirer/core');
const defaultInput = require('@inquirer/input').default;
const inquirer = require('inquirer').default;
const { createPromptModule } = require('inquirer');

describe('CommonJS Integration', () => {
it('@inquirer/prompts should be exported', () => {
Expand All @@ -17,4 +19,10 @@ describe('CommonJS Integration', () => {
it('@inquirer/core should export createPrompt', () => {
assert(createPrompt instanceof Function);
});

it('inquirer should be exported', () => {
assert(inquirer.prompt instanceof Function);
assert(inquirer.createPromptModule instanceof Function);
assert(createPromptModule instanceof Function);
});
});
20 changes: 2 additions & 18 deletions integration/esm/integration.test.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/* eslint-disable n/no-unsupported-features/node-builtins */
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { input } from '@inquirer/prompts';
import defaultInput from '@inquirer/input';
import { createPrompt } from '@inquirer/core';
import inquirer, { createPromptModule } from 'inquirer';
import { describe, it } from 'node:test';
import assert from 'node:assert';

import Base from 'inquirer/lib/prompts/base.js';
import Choices from 'inquirer/lib/objects/choices.js';
import Separator from 'inquirer/lib/objects/separator.js';
import observe from 'inquirer/lib/utils/events.js';
import * as utils from 'inquirer/lib/utils/readline.js';
import Paginator from 'inquirer/lib/utils/paginator.js';

describe('ESM Integration', () => {
it('@inquirer/prompts should be exported', () => {
Expand All @@ -31,13 +24,4 @@ describe('ESM Integration', () => {
assert(inquirer.createPromptModule instanceof Function);
assert(createPromptModule instanceof Function);
});

it('inquirer custom prompts util paths are stable', () => {
assert(Base != null);
assert(Choices != null);
assert(Separator != null);
assert(observe != null);
assert(utils != null);
assert(Paginator != null);
});
});
15 changes: 1 addition & 14 deletions packages/inquirer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,7 @@ inquirer
});
```

> [!WARNING]
> Inquirer v9 and higher are native esm modules, this mean you cannot use the commonjs syntax `require('inquirer')` anymore. If you want to learn more about using native esm in Node, I'd recommend reading [the following guide](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
Alternatively, if you require a commonjs module, you should rely on an older version until you're ready to upgrade your environment:

```sh
npm install --save inquirer@^8.0.0
```

This will then allow import inquirer with the commonjs `require`:

```js
const inquirer = require('inquirer');
```
If you're using Typescript, you'll also want to [add `@types/inquirer`](https://www.npmjs.com/package/@types/inquirer).

<a name="examples"></a>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn } from 'node:child_process';
import BottomBar from '../lib/ui/bottom-bar.js';
import BottomBar from '../src/ui/bottom-bar.mjs';

const loader = ['/ Installing', '| Installing', String.raw`\ Installing`, '- Installing'];
let i = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Checkbox list examples
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Editor prompt example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Expand list examples
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Filter and validate progress example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Heirarchical conversation example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const directionsPrompt = {
type: 'list',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Input prompt example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* List prompt example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Paginated list
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const choices = Array.apply(0, Array.from({ length: 26 })).map((x, y) =>
String.fromCodePoint(y + 65),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nested Inquirer call
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

inquirer
.prompt({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Password prompt example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const requireLetterAndNumber = (value) => {
if (/\w/.test(value) && /\d/.test(value)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Pizza delivery prompt example
* run example by writing `node pizza.js` in your console
* run example by writing `node pizza.mjs` in your console
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

console.log('Hi, welcome to Node Pizza');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Raw List prompt example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Allows user to choose when to exit prompt
*/

import inquirer from '../lib/index.js';
const output = [];
import inquirer from '../src/index.mjs';

const questions = [
{
Expand All @@ -21,6 +20,8 @@ const questions = [
];

function ask() {
const output: string[] = [];

inquirer.prompt(questions).then((answers) => {
output.push(answers.tvShow);
if (answers.askAgain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Filter and validate progress example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { from } from 'rxjs';
import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const questions = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable } from 'rxjs';
import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const observe = new Observable((subscriber) => {
subscriber.next({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawn } from 'node:child_process';

spawn('node', ['input.js'], {
spawn('node', ['input.mjs'], {
cwd: import.meta.dirname,
stdio: 'inherit',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import terminalLink from 'terminal-link';
import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

inquirer
.prompt([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* When example
*/

import inquirer from '../lib/index.js';
import inquirer from '../src/index.mjs';

const questions = [
{
Expand Down
31 changes: 0 additions & 31 deletions packages/inquirer/lib/objects/choice.js

This file was deleted.

Loading

0 comments on commit 532a740

Please sign in to comment.