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

Build script to setup ESM/CJS module exports #1185

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"lerna": "^6.0.3",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"tsconfig-to-dual-package": "^1.1.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
Expand Down
2 changes: 2 additions & 0 deletions packages/inquirer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
README.md
lib-*
3 changes: 3 additions & 0 deletions packages/inquirer/lib-cjs/inquirer-default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const inquirer = require("./inquirer.js").default;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file sneaked in the diff (prob added/commited before the .gitignore change)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see this is desired. Let's update the .gitignore so this file is included not ignored by Git.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend adding this file to the eslint ignore. It errors on CI now since it's using common.js syntax - and wouldn't compile as-is.


module.exports = inquirer;
4 changes: 2 additions & 2 deletions packages/inquirer/lib/objects/separator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import figures from 'figures';
import chalk from '#chalk';
import figures from '#figures';

/**
* Separator object
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const _ = {
clone,
};

import chalk from 'chalk';
import chalk from '#chalk';
import runAsync from 'run-async';
import { filter, flatMap, share, take, takeUntil } from 'rxjs';
import Choices from '../objects/choices.js';
Expand Down
6 changes: 3 additions & 3 deletions packages/inquirer/lib/prompts/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* `list` type prompt
*/

import chalk from 'chalk';
import cliCursor from 'cli-cursor';
import figures from 'figures';
import chalk from '#chalk';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there eslint rules to enforce to use the # imports if the dependency is found in the package.json import map. That would help enforce it for future collaborators.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need to fix the node/no-missing-import eslint error before merging.

import cliCursor from '#cli-cursor';
import figures from '#figures';
import { map, takeUntil } from 'rxjs';
import Base from './base.js';
import observe from '../utils/events.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* `confirm` type prompt
*/

import chalk from 'chalk';
import chalk from '#chalk';
import { take, takeUntil } from 'rxjs';
import Base from './base.js';
import observe from '../utils/events.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* `editor` type prompt
*/

import chalk from 'chalk';
import chalk from '#chalk';
import { editAsync } from 'external-editor';
import Base from './base.js';
import observe from '../utils/events.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* `rawlist` type prompt
*/

import chalk from 'chalk';
import chalk from '#chalk';
import { map, takeUntil } from 'rxjs';
import Base from './base.js';
import Separator from '../objects/separator.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* `input` type prompt
*/

import chalk from 'chalk';
import chalk from '#chalk';
import { map, takeUntil } from 'rxjs';
import Base from './base.js';
import observe from '../utils/events.js';
Expand Down
6 changes: 3 additions & 3 deletions packages/inquirer/lib/prompts/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* `list` type prompt
*/

import chalk from 'chalk';
import figures from 'figures';
import cliCursor from 'cli-cursor';
import chalk from '#chalk';
import figures from '#figures';
import cliCursor from '#cli-cursor';
import runAsync from 'run-async';
import { flatMap, map, take, takeUntil } from 'rxjs';
import Base from './base.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* `password` type prompt
*/

import chalk from 'chalk';
import chalk from '#chalk';
import { map, takeUntil } from 'rxjs';
import Base from './base.js';
import observe from '../utils/events.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/rawlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* `rawlist` type prompt
*/

import chalk from 'chalk';
import chalk from '#chalk';
import { map, takeUntil } from 'rxjs';
import Base from './base.js';
import Separator from '../objects/separator.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/utils/paginator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import chalk from '#chalk';

/**
* The paginator returns a subset of the choices if the list is too long.
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/utils/readline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ansiEscapes from 'ansi-escapes';
import ansiEscapes from '#ansi-escapes';

/**
* Move cursor left by `x`
Expand Down
8 changes: 4 additions & 4 deletions packages/inquirer/lib/utils/screen-manager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as util from './readline.js';
import cliWidth from 'cli-width';
import wrapAnsi from 'wrap-ansi';
import stripAnsi from 'strip-ansi';
import stringWidth from 'string-width';
import ora from 'ora';
import wrapAnsi from '#wrap-ansi';
import stripAnsi from '#strip-ansi';
import stringWidth from '#string-width';
import ora from '#ora';

function height(content) {
return content.split('\n').length;
Expand Down
74 changes: 71 additions & 3 deletions packages/inquirer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,67 @@
"author": "Simon Boudrias <admin@simonboudrias.com>",
"files": [
"lib",
"lib-cjs",
"README.md"
],
"main": "lib/inquirer.js",
"exports": {
".": {
"require": "./lib-cjs/inquirer-default.js",
"default": "./lib/inquirer.js"
},
"./package.json": "./package.json"
},
"imports": {
"#ansi-escapes": {
"node": {
"require": "ansi-escapes-4",
"default": "ansi-escapes"
}
},
"#chalk": {
"node": {
"require": "chalk-4",
"default": "chalk"
}
},
"#cli-cursor": {
"node": {
"require": "cli-cursor-3",
"default": "cli-cursor"
}
},
"#figures": {
"node": {
"require": "figures-3",
"default": "figures"
}
},
"#ora": {
"node": {
"require": "ora-5",
"default": "ora"
}
},
"#string-width": {
"node": {
"require": "string-width-4",
"default": "string-width"
}
},
"#strip-ansi": {
"node": {
"require": "strip-ansi-6",
"default": "strip-ansi"
}
},
"#wrap-ansi": {
"node": {
"require": "wrap-ansi-7",
"default": "wrap-ansi"
}
}
},
"keywords": [
"answer",
"answers",
Expand Down Expand Up @@ -50,7 +108,7 @@
"zsh"
],
"engines": {
"node": ">=12.0.0"
"node": ">=14.18.0"
},
"devDependencies": {
"chai": "^4.3.7",
Expand All @@ -66,26 +124,36 @@
"scripts": {
"test": "nyc mocha --es-module-specifier-resolution=node test/**/* -r ./test/before",
"posttest": "mkdir -p ../../coverage/ && nyc report --reporter=text-lcov > ../../coverage/nyc-report.lcov",
"prepublishOnly": "cp ../../README.md .",
"prebuild": "find ./lib-cjs/* ! -name 'inquirer-default.js' -exec rm -rf {} +",
"build": "tsc -p ./tsconfig.cjs.json && tsconfig-to-dual-package ./tsconfig.cjs.json",
"prepublishOnly": "cp ../../README.md . && npm run build",
"postpublish": "rm -f README.md"
},
"repository": "SBoudrias/Inquirer.js",
"license": "MIT",
"dependencies": {
"ansi-escapes": "^6.0.0",
"ansi-escapes-4": "npm:ansi-escapes@^4.3.2",
"chalk": "^5.1.2",
"chalk-4": "npm:chalk@^4.1.2",
"cli-cursor": "^4.0.0",
"cli-cursor-3": "npm:cli-cursor@^3.1.0",
"cli-width": "^4.0.0",
"external-editor": "^3.0.3",
"figures": "^5.0.0",
"figures-3": "npm:figures@^3.2.0",
"lodash": "^4.17.21",
"mute-stream": "0.0.8",
"ora": "^6.1.2",
"ora-5": "npm:ora@^5.4.1",
"run-async": "^2.4.0",
"rxjs": "^7.5.7",
"string-width": "^5.1.2",
"string-width-4": "npm:string-width@^4.2.3",
"strip-ansi": "^7.0.1",
"strip-ansi-6": "npm:strip-ansi@^6.0.1",
"through": "^2.3.6",
"wrap-ansi": "^8.0.1"
"wrap-ansi": "^8.0.1",
"wrap-ansi-7": "npm:wrap-ansi@^7.0.0"
}
}
11 changes: 11 additions & 0 deletions packages/inquirer/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"skipLibCheck": true,
"esModuleInterop": true
},
"include": [
"./lib/**/*.js"
]
}
10 changes: 10 additions & 0 deletions packages/inquirer/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.base",
"compilerOptions": {
"lib": ["ES6"],
"target": "ES6",
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "./lib-cjs"
}
}
10 changes: 10 additions & 0 deletions packages/inquirer/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.base",
"compilerOptions": {
"lib": ["ES2022"],
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "NodeNext",
"outDir": "./lib"
}
}