From 4b0a7afadc2eafc1bfacded4d109336bb7191497 Mon Sep 17 00:00:00 2001 From: Alex Havermale Date: Wed, 12 Oct 2022 11:23:03 -0400 Subject: [PATCH] refactor: migrate to ESM closes #3, resolves #4, closes #5 BREAKING CHANGE: this package now uses native ESM modules, which means this plugin will only work with inquirer v9 and above. --- .nvmrc | 1 + .releaserc.js | 2 +- README.md | 13 ++++++++++--- index.js | 12 ++++++------ package.json | 5 +++-- 5 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..48082f7 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +12 diff --git a/.releaserc.js b/.releaserc.js index d36b976..6e08449 100644 --- a/.releaserc.js +++ b/.releaserc.js @@ -1,4 +1,4 @@ -module.exports = { +export default { plugins: [ // prettier-ignore ["@semantic-release/commit-analyzer", { diff --git a/README.md b/README.md index 2cc68f5..0582560 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,19 @@ A comprehensive date prompt plugin for Inquirer.js. npm install inquirer-date-prompt ``` +> :warning: Note that the latest version of this package uses native ESM modules, which means this plugin will only work with inquirer `v9` and above. If you cannot use ESM modules yet for whatever reason, you can rely on `v2.x` until you're ready to upgrade your environment: +> +> ```sh +> npm install --save inquirer-date-prompt@^2.0.0 +> ``` + ## Usage ```js -const inquirer = require("inquirer"); +import inquirer from "inquirer"; +import DatePrompt from "inquirer-date-prompt"; -inquirer.registerPrompt("date", require("inquirer-date-prompt")); +inquirer.registerPrompt("date", DatePrompt); inquirer.prompt({ type: "date", @@ -106,4 +113,4 @@ async function getTimestamp(date) { ## Caveats -1. Be aware that even though this plugin works with Node ≥ v10, specifying a locale other than `'en-US'` while running on any version less than 13.0.0 will fail silently. See the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#browser_compatibility) for more details. +1. Be aware that even though this plugin works with Node ≥ v12, specifying a locale other than `'en-US'` while running on any version less than 13.0.0 will fail silently. See the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#browser_compatibility) for more details. diff --git a/index.js b/index.js index dfb5801..3381e2c 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ -const chalk = require("chalk"); -const cliCursor = require("cli-cursor"); -const Prompt = require("inquirer/lib/prompts/base"); -const observe = require("inquirer/lib/utils/events"); -const { map, takeUntil } = require("rxjs/operators"); +import chalk from "chalk"; +import cliCursor from "cli-cursor"; +import Prompt from "inquirer/lib/prompts/base.js"; +import observe from "inquirer/lib/utils/events.js"; +import { map, takeUntil } from "rxjs/operators"; /** * A lookup object that maps each date part type to the corresponding @@ -262,4 +262,4 @@ class DatePrompt extends Prompt { } } -module.exports = DatePrompt; +export default DatePrompt; diff --git a/package.json b/package.json index 9efd1d3..1b9f5e3 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "inquirer-date-prompt", "version": "2.0.1", "description": "A date prompt plugin for Inquirer.js.", + "type": "module", "main": "index.js", "types": "index.d.ts", "keywords": [ @@ -20,11 +21,11 @@ }, "homepage": "https://github.com/haversnail/inquirer-date-prompt", "engines": { - "node": ">=10" + "node": ">=12" }, "license": "MIT", "peerDependencies": { - "inquirer": ">= 7.x" + "inquirer": ">= 9.x" }, "devDependencies": { "@semantic-release/git": "^9.0.0",